Debian Codegraph @

src/plugins/imageformats/webp/qwebphandler.cpp

raw symbols SCIP
1 /****************************************************************************
2 **
3 ** Copyright (C) 2019 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the WebP plugins in the Qt ImageFormats module.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39
40 #include "qwebphandler_p.h"cxx . . $ `<file>/src/plugins/imageformats/webp/qwebphandler_p.h`/
41 #include "webp/mux.h"
42 #include "webp/encode.h"
43 #include <qcolor.h>
44 #include <qimage.h>
45 #include <qdebug.h>
46 #include <qpainter.h>
47 #include <qvariant.h>
48
49 static const int riffHeaderSizecxx . . $ riffHeaderSize. = 12; // RIFF_HEADER_SIZE from webp/format_constants.h
50
51 QWebpHandlercxx . . $ QWebpHandler#::QWebpHandlercxx . . $ QWebpHandler#QWebpHandler(49f6e7a06ebc5aa8).() :
52 m_qualitycxx . . $ QWebpHandler#m_quality.(75),
53 m_scanStatecxx . . $ QWebpHandler#m_scanState.(ScanNotScannedcxx . . $ QWebpHandler#ScanNotScanned.),
54 m_featurescxx . . $ QWebpHandler#m_features.(),
55 m_formatFlagscxx . . $ QWebpHandler#m_formatFlags.(0),
56 m_loopcxx . . $ QWebpHandler#m_loop.(0),
57 m_frameCountcxx . . $ QWebpHandler#m_frameCount.(0),
58 m_demuxercxx . . $ QWebpHandler#m_demuxer.(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!),
59 m_compositedcxx . . $ QWebpHandler#m_composited.(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)
60 {
61 memset(&m_itercxx . . $ QWebpHandler#m_iter., 0, sizeof(m_itercxx . . $ QWebpHandler#m_iter.));
62 }
63
64 QWebpHandlercxx . . $ QWebpHandler#::~cxx . . $ QWebpHandler#`~QWebpHandler`(ced63f7c635d850d).QWebpHandlercxx . . $ QWebpHandler#()
65 {
66 WebPDemuxReleaseIterator(&m_itercxx . . $ QWebpHandler#m_iter.);
67 WebPDemuxDelete(m_demuxercxx . . $ QWebpHandler#m_demuxer.);
68 delete m_compositedcxx . . $ QWebpHandler#m_composited.;
69 }
70
71 bool QWebpHandlercxx . . $ QWebpHandler#::canReadcxx . . $ QWebpHandler#canRead(50ce9a9e25b4a850).() const
72 {
73 if (m_scanStatecxx . . $ QWebpHandler#m_scanState. == ScanNotScannedcxx . . $ QWebpHandler#ScanNotScanned. && !canReadcxx . . $ QWebpHandler#canRead(33ee36428ee918e7).(devicecxx . . $ QImageIOHandler#device(84cdc49e7936af4f).()))
74 return false;
75
76 if (m_scanStatecxx . . $ QWebpHandler#m_scanState. != ScanErrorcxx . . $ QWebpHandler#ScanError.) {
77 setFormatcxx . . $ QImageIOHandler#setFormat(7c8dc563d715d744).(QByteArrayLiteralcxx . . $ `<external>/11057416899157294643/qbytearray.h:146:11`!("webp"));
78
79 if (m_featurescxx . . $ QWebpHandler#m_features..has_animationcxx . . $ WebPBitstreamFeatures#has_animation. && m_itercxx . . $ QWebpHandler#m_iter..frame_numcxx . . $ WebPIterator#frame_num. >= m_frameCountcxx . . $ QWebpHandler#m_frameCount.)
80 return false;
81
82 return true;
83 }
84 return false;
85 }
86
87 bool QWebpHandlercxx . . $ QWebpHandler#::canReadcxx . . $ QWebpHandler#canRead(33ee36428ee918e7).(QIODevicecxx . . $ QIODevice# *device)
88 {
89 if (!device) {
90 qWarningcxx . . $ `<external>/10450329605257866924/qlogging.h:166:9`!("QWebpHandler::canRead() called with no device");
91 return false;
92 }
93
94 QByteArraycxx . . $ QByteArray# header = device->peekcxx . . $ QIODevice#peek(1117a85f2fd4e5c8).(riffHeaderSizecxx . . $ riffHeaderSize.);
95 return header.startsWithcxx . . $ QByteArray#startsWith(7d4bdb1abc417636).("RIFF") && header.endsWithcxx . . $ QByteArray#endsWith(7d4bdb1abc417636).("WEBP");
96 }
97
98 bool QWebpHandlercxx . . $ QWebpHandler#::ensureScannedcxx . . $ QWebpHandler#ensureScanned(50ce9a9e25b4a850).() const
99 {
100 if (m_scanStatecxx . . $ QWebpHandler#m_scanState. != ScanNotScannedcxx . . $ QWebpHandler#ScanNotScanned.)
101 return m_scanStatecxx . . $ QWebpHandler#m_scanState. == ScanSuccesscxx . . $ QWebpHandler#ScanSuccess.;
102
103 m_scanStatecxx . . $ QWebpHandler#m_scanState. = ScanErrorcxx . . $ QWebpHandler#ScanError.;
104
105 if (devicecxx . . $ QImageIOHandler#device(84cdc49e7936af4f).()->isSequentialcxx . . $ QIODevice#isSequential(50ce9a9e25b4a850).()) {
106 qWarningcxx . . $ `<external>/10450329605257866924/qlogging.h:166:9`!() <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "Sequential devices are not supported";
107 return false;
108 }
109
110 qint64cxx . . $ qint64# oldPos = devicecxx . . $ QImageIOHandler#device(84cdc49e7936af4f).()->poscxx . . $ QIODevice#pos(98833e9ab7de59a4).();
111 devicecxx . . $ QImageIOHandler#device(84cdc49e7936af4f).()->seekcxx . . $ QIODevice#seek(49597d8fcab147c1).(0);
112
113 QWebpHandlercxx . . $ QWebpHandler# *that = const_cast<QWebpHandlercxx . . $ QWebpHandler# *>(this);
114 QByteArraycxx . . $ QByteArray# header = devicecxx . . $ QImageIOHandler#device(84cdc49e7936af4f).()->peekcxx . . $ QIODevice#peek(1117a85f2fd4e5c8).(sizeof(WebPBitstreamFeatures));
115 if (WebPGetFeatures((const uint8_tcxx . . $ uint8_t#*)header.constDatacxx . . $ QByteArray#constData(a9f41ea0e82d88cf).(), header.sizecxx . . $ QByteArray#size(455f465bc33b4cdf).(), &(that->m_featurescxx . . $ QWebpHandler#m_features.)) == VP8_STATUS_OK) {
116 if (m_featurescxx . . $ QWebpHandler#m_features..has_animationcxx . . $ WebPBitstreamFeatures#has_animation.) {
117 // For animation, we have to read and scan whole file to determine loop count and images count
118 devicecxx . . $ QImageIOHandler#device(84cdc49e7936af4f).()->seekcxx . . $ QIODevice#seek(49597d8fcab147c1).(oldPos);
119
120 if (that->ensureDemuxercxx . . $ QWebpHandler#ensureDemuxer(c9857a73d68e59ba).()) {
121 that->m_loopcxx . . $ QWebpHandler#m_loop. = WebPDemuxGetI(m_demuxercxx . . $ QWebpHandler#m_demuxer., WEBP_FF_LOOP_COUNT);
122 that->m_frameCountcxx . . $ QWebpHandler#m_frameCount. = WebPDemuxGetI(m_demuxercxx . . $ QWebpHandler#m_demuxer., WEBP_FF_FRAME_COUNT);
123 that->m_bgColorcxx . . $ QWebpHandler#m_bgColor. =cxx . . $ QColor#`operator=`(fd1b853fb77c9003). QColorcxx . . $ QColor#::fromRgbacxx . . $ QColor#fromRgba(473e583fa190149).(QRgbcxx . . $ QRgb#(WebPDemuxGetI(m_demuxercxx . . $ QWebpHandler#m_demuxer., WEBP_FF_BACKGROUND_COLOR)));
124
125 that->m_compositedcxx . . $ QWebpHandler#m_composited. = new QImagecxx . . $ QImage#QImage(bf9e47a5364bf007).(that->m_featurescxx . . $ QWebpHandler#m_features..widthcxx . . $ WebPBitstreamFeatures#width., that->m_featurescxx . . $ QWebpHandler#m_features..heightcxx . . $ WebPBitstreamFeatures#height., QImagecxx . . $ QImage#::Format_ARGB32cxx . . $ QImage#Format_ARGB32.);
126 if (that->m_featurescxx . . $ QWebpHandler#m_features..has_alphacxx . . $ WebPBitstreamFeatures#has_alpha.)
127 that->m_compositedcxx . . $ QWebpHandler#m_composited.->fillcxx . . $ QImage#fill(cd98eb3c6d110ca7).(Qtcxx . . $ Qt/::transparentcxx . . $ Qt/transparent.);
128
129 // We do not reset device position since we have read in all data
130 m_scanStatecxx . . $ QWebpHandler#m_scanState. = ScanSuccesscxx . . $ QWebpHandler#ScanSuccess.;
131 return true;
132 }
133 } else {
134 m_scanStatecxx . . $ QWebpHandler#m_scanState. = ScanSuccesscxx . . $ QWebpHandler#ScanSuccess.;
135 }
136 }
137
138 devicecxx . . $ QImageIOHandler#device(84cdc49e7936af4f).()->seekcxx . . $ QIODevice#seek(49597d8fcab147c1).(oldPos);
139
140 return m_scanStatecxx . . $ QWebpHandler#m_scanState. == ScanSuccesscxx . . $ QWebpHandler#ScanSuccess.;
141 }
142
143 bool QWebpHandlercxx . . $ QWebpHandler#::ensureDemuxercxx . . $ QWebpHandler#ensureDemuxer(c9857a73d68e59ba).()
144 {
145 if (m_demuxercxx . . $ QWebpHandler#m_demuxer.)
146 return true;
147
148 m_rawDatacxx . . $ QWebpHandler#m_rawData. =cxx . . $ QByteArray#`operator=`(c3d647c78c52d790). devicecxx . . $ QImageIOHandler#device(84cdc49e7936af4f).()->readAllcxx . . $ QIODevice#readAll(b3c286cec66e09f4).();
149 m_webpDatacxx . . $ QWebpHandler#m_webpData..bytescxx . . $ WebPData#bytes. = reinterpret_cast<const uint8_tcxx . . $ uint8_t# *>(m_rawDatacxx . . $ QWebpHandler#m_rawData..constDatacxx . . $ QByteArray#constData(a9f41ea0e82d88cf).());
150 m_webpDatacxx . . $ QWebpHandler#m_webpData..sizecxx . . $ WebPData#size. = m_rawDatacxx . . $ QWebpHandler#m_rawData..sizecxx . . $ QByteArray#size(455f465bc33b4cdf).();
151
152 m_demuxercxx . . $ QWebpHandler#m_demuxer. = WebPDemux(&m_webpDatacxx . . $ QWebpHandler#m_webpData.);
153 if (m_demuxercxx . . $ QWebpHandler#m_demuxer. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)
154 return false;
155
156 m_formatFlagscxx . . $ QWebpHandler#m_formatFlags. = WebPDemuxGetI(m_demuxercxx . . $ QWebpHandler#m_demuxer., WEBP_FF_FORMAT_FLAGS);
157 return true;
158 }
159
160 bool QWebpHandlercxx . . $ QWebpHandler#::readcxx . . $ QWebpHandler#read(5a6f164356166ee6).(QImagecxx . . $ QImage# *image)
161 {
162 if (!ensureScannedcxx . . $ QWebpHandler#ensureScanned(50ce9a9e25b4a850).() || devicecxx . . $ QImageIOHandler#device(84cdc49e7936af4f).()->isSequentialcxx . . $ QIODevice#isSequential(50ce9a9e25b4a850).() || !ensureDemuxercxx . . $ QWebpHandler#ensureDemuxer(c9857a73d68e59ba).())
163 return false;
164
165 QRectcxx . . $ QRect# prevFrameRectcxx . . $ QRect#QRect(ced63f7c635d850d).;
166 if (m_itercxx . . $ QWebpHandler#m_iter..frame_numcxx . . $ WebPIterator#frame_num. == 0) {
167 // Read global meta-data chunks first
168 WebPChunkIterator metaDataIter;
169 if ((m_formatFlagscxx . . $ QWebpHandler#m_formatFlags. & ICCP_FLAG) && WebPDemuxGetChunk(m_demuxercxx . . $ QWebpHandler#m_demuxer., "ICCP", 1, &metaDataIter)) {
170 QByteArraycxx . . $ QByteArray# iccProfile = QByteArraycxx . . $ QByteArray#::fromRawDatacxx . . $ QByteArray#fromRawData(15fabfc13d71455).(reinterpret_cast<const char *>(metaDataIter.chunkcxx . . $ WebPChunkIterator#chunk..bytescxx . . $ WebPData#bytes.),
171 metaDataIter.chunkcxx . . $ WebPChunkIterator#chunk..sizecxx . . $ WebPData#size.);
172 // Ensure the profile is 4-byte aligned.
173 if (reinterpret_cast<qintptrcxx . . $ qintptr#>(iccProfile.constDatacxx . . $ QByteArray#constData(a9f41ea0e82d88cf).()) & 0x3)
174 iccProfile.detachcxx . . $ QByteArray#detach(49f6e7a06ebc5aa8).();
175 m_colorSpacecxx . . $ QWebpHandler#m_colorSpace. =cxx . . $ QColorSpace#`operator=`(b56ba85a5f096005). QColorSpacecxx . . $ QColorSpace#::fromIccProfilecxx . . $ QColorSpace#fromIccProfile(6f53d2c777ddbb7d).(iccProfile);
176 // ### consider parsing EXIF and/or XMP metadata too.
177 WebPDemuxReleaseChunkIterator(&metaDataIter);
178 }
179
180 // Go to first frame
181 if (!WebPDemuxGetFrame(m_demuxercxx . . $ QWebpHandler#m_demuxer., 1, &m_itercxx . . $ QWebpHandler#m_iter.))
182 return false;
183 } else {
184 if (m_itercxx . . $ QWebpHandler#m_iter..has_alphacxx . . $ WebPIterator#has_alpha. && m_itercxx . . $ QWebpHandler#m_iter..dispose_methodcxx . . $ WebPIterator#dispose_method. == WEBP_MUX_DISPOSE_BACKGROUND)
185 prevFrameRect =cxx . . $ QRect#`operator=`(2f0950bc81ec7a1b). currentImageRectcxx . . $ QWebpHandler#currentImageRect(d857385bac04cbf7).();
186
187 // Go to next frame
188 if (!WebPDemuxNextFrame(&m_itercxx . . $ QWebpHandler#m_iter.))
189 return false;
190 }
191
192 WebPBitstreamFeatures features;
193 VP8StatusCode status = WebPGetFeatures(m_itercxx . . $ QWebpHandler#m_iter..fragmentcxx . . $ WebPIterator#fragment..bytescxx . . $ WebPData#bytes., m_itercxx . . $ QWebpHandler#m_iter..fragmentcxx . . $ WebPIterator#fragment..sizecxx . . $ WebPData#size., &features);
194 if (status != VP8_STATUS_OK)
195 return false;
196
197 QImagecxx . . $ QImage#::Formatcxx . . $ QImage#Format# format = m_featurescxx . . $ QWebpHandler#m_features..has_alphacxx . . $ WebPBitstreamFeatures#has_alpha. ? QImagecxx . . $ QImage#::Format_ARGB32cxx . . $ QImage#Format_ARGB32. : QImagecxx . . $ QImage#::Format_RGB32cxx . . $ QImage#Format_RGB32.;
198 QImagecxx . . $ QImage# framecxx . . $ QImage#QImage(bf9e47a5364bf007).(m_itercxx . . $ QWebpHandler#m_iter..widthcxx . . $ WebPIterator#width., m_itercxx . . $ QWebpHandler#m_iter..heightcxx . . $ WebPIterator#height., format);
199 uint8_tcxx . . $ uint8_t# *output = frame.bitscxx . . $ QImage#bits(37d8967d10cb1e7b).();
200 size_t output_size = frame.sizeInBytescxx . . $ QImage#sizeInBytes(98833e9ab7de59a4).();
201 #if Q_BYTE_ORDERcxx . . $ `<external>/10968711952321115821/qprocessordetection.h:213:11`! == Q_LITTLE_ENDIANcxx . . $ `<external>/10968711952321115821/qprocessordetection.h:77:11`!
202 if (!WebPDecodeBGRAInto(
203 reinterpret_cast<const uint8_tcxx . . $ uint8_t#*>(m_itercxx . . $ QWebpHandler#m_iter..fragmentcxx . . $ WebPIterator#fragment..bytescxx . . $ WebPData#bytes.), m_itercxx . . $ QWebpHandler#m_iter..fragmentcxx . . $ WebPIterator#fragment..sizecxx . . $ WebPData#size.,
204 output, output_size, frame.bytesPerLinecxx . . $ QImage#bytesPerLine(455f465bc33b4cdf).()))
205 #else
206 if (!WebPDecodeARGBInto(
207 reinterpret_cast<const uint8_t*>(m_iter.fragment.bytes), m_iter.fragment.size,
208 output, output_size, frame.bytesPerLine()))
209 #endif
210 return false;
211
212 if (!m_featurescxx . . $ QWebpHandler#m_features..has_animationcxx . . $ WebPBitstreamFeatures#has_animation.) {
213 // Single image
214 *image =cxx . . $ QImage#`operator=`(acb38987752f17f1). frame;
215 } else {
216 // Animation
217 QPaintercxx . . $ QPainter# paintercxx . . $ QPainter#QPainter(dd2eedc069b0ab5f).(m_compositedcxx . . $ QWebpHandler#m_composited.);
218 if (!prevFrameRect.isEmptycxx . . $ QRect#isEmpty(3482b152b9333168).()) {
219 painter.setCompositionModecxx . . $ QPainter#setCompositionMode(233e5f91a307c5b).(QPaintercxx . . $ QPainter#::CompositionMode_Clearcxx . . $ QPainter#CompositionMode_Clear.);
220 painter.fillRectcxx . . $ QPainter#fillRect(26a0210a6d40746b).(prevFrameRect, Qtcxx . . $ Qt/::blackcxx . . $ Qt/black.);
221 }
222 if (m_featurescxx . . $ QWebpHandler#m_features..has_alphacxx . . $ WebPBitstreamFeatures#has_alpha.) {
223 if (m_itercxx . . $ QWebpHandler#m_iter..blend_methodcxx . . $ WebPIterator#blend_method. == WEBP_MUX_NO_BLEND)
224 painter.setCompositionModecxx . . $ QPainter#setCompositionMode(233e5f91a307c5b).(QPaintercxx . . $ QPainter#::CompositionMode_Sourcecxx . . $ QPainter#CompositionMode_Source.);
225 else
226 painter.setCompositionModecxx . . $ QPainter#setCompositionMode(233e5f91a307c5b).(QPaintercxx . . $ QPainter#::CompositionMode_SourceOvercxx . . $ QPainter#CompositionMode_SourceOver.);
227 }
228 painter.drawImagecxx . . $ QPainter#drawImage(2eae8db60707222a).(currentImageRectcxx . . $ QWebpHandler#currentImageRect(d857385bac04cbf7).(), frame);
229
230 *image =cxx . . $ QImage#`operator=`(acb38987752f17f1). *m_compositedcxx . . $ QWebpHandler#m_composited.;
231 }
232 image->setColorSpacecxx . . $ QImage#setColorSpace(2de784921415d79f).(m_colorSpacecxx . . $ QWebpHandler#m_colorSpace.);
233
234 return true;
235 }
236
237 bool QWebpHandlercxx . . $ QWebpHandler#::writecxx . . $ QWebpHandler#write(73afe20316494619).(const QImagecxx . . $ QImage# &image)
238 {
239 if (image.isNullcxx . . $ QImage#isNull(50ce9a9e25b4a850).()) {
240 qWarningcxx . . $ `<external>/10450329605257866924/qlogging.h:166:9`!() <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "source image is null.";
241 return false;
242 }
243 if (stdcxx . . $ std/::maxcxx . . $ std/max(2a338fce5842aa6a).(image.widthcxx . . $ QImage#width(455f465bc33b4cdf).(), image.heightcxx . . $ QImage#height(455f465bc33b4cdf).()) > WEBP_MAX_DIMENSIONcxx . . $ `<external>/7818783442293489312/encode.h:296:9`!) {
244 qWarningcxx . . $ `<external>/10450329605257866924/qlogging.h:166:9`!() <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "QWebpHandler::write() source image too large for WebP: " <<cxx . . $ `operator<<`(592d53aaa30fc207). image.sizecxx . . $ QImage#size(4b3b776e5ee2b367).();
245 return false;
246 }
247
248 QImagecxx . . $ QImage# srcImage = imagecxx . . $ QImage#QImage(9ff1334af0ec69dd).;
249 bool alpha = srcImage.hasAlphaChannelcxx . . $ QImage#hasAlphaChannel(50ce9a9e25b4a850).();
250 QImagecxx . . $ QImage#::Formatcxx . . $ QImage#Format# newFormat = alpha ? QImagecxx . . $ QImage#::Format_RGBA8888cxx . . $ QImage#Format_RGBA8888. : QImagecxx . . $ QImage#::Format_RGB888cxx . . $ QImage#Format_RGB888.;
251 if (srcImage.formatcxx . . $ QImage#format(18a95330327ec5b8).() != newFormat)
252 srcImage =cxx . . $ QImage#`operator=`(e6308d6f8c10e1d2). srcImage.convertToFormatcxx . . $ QImage#convertToFormat(2da09223ee5c8d93).(newFormat);
253
254 WebPPicture picture;
255 WebPConfig config;
256
257 if (!WebPPictureInit(&picture) || !WebPConfigInit(&config)) {
258 qWarningcxx . . $ `<external>/10450329605257866924/qlogging.h:166:9`!() <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "failed to init webp picture and config";
259 return false;
260 }
261
262 picture.width = srcImage.widthcxx . . $ QImage#width(455f465bc33b4cdf).();
263 picture.height = srcImage.heightcxx . . $ QImage#height(455f465bc33b4cdf).();
264 picture.use_argb = 1;
265 bool failed = false;
266 if (alpha)
267 failed = !WebPPictureImportRGBA(&picture, srcImage.bitscxx . . $ QImage#bits(37d8967d10cb1e7b).(), srcImage.bytesPerLinecxx . . $ QImage#bytesPerLine(455f465bc33b4cdf).());
268 else
269 failed = !WebPPictureImportRGB(&picture, srcImage.bitscxx . . $ QImage#bits(37d8967d10cb1e7b).(), srcImage.bytesPerLinecxx . . $ QImage#bytesPerLine(455f465bc33b4cdf).());
270
271 if (failed) {
272 qWarningcxx . . $ `<external>/10450329605257866924/qlogging.h:166:9`!() <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "failed to import image data to webp picture.";
273 WebPPictureFree(&picture);
274 return false;
275 }
276
277 int reqQuality = m_qualitycxx . . $ QWebpHandler#m_quality. < 0 ? 75 : qMincxx . . $ qMin(2a338fce5842aa6a).(m_qualitycxx . . $ QWebpHandler#m_quality., 100);
278 if (reqQuality < 100) {
279 config.lossless = 0;
280 config.quality = reqQuality;
281 } else {
282 config.lossless = 1;
283 config.quality = 70; // For lossless, specifies compression effort; 70 is libwebp default
284 }
285 config.alpha_quality = config.quality;
286 WebPMemoryWriter writer;
287 WebPMemoryWriterInit(&writer);
288 picture.writer = WebPMemoryWrite;
289 picture.custom_ptr = &writer;
290
291 if (!WebPEncode(&config, &picture)) {
292 qWarningcxx . . $ `<external>/10450329605257866924/qlogging.h:166:9`!() <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "failed to encode webp picture, error code: " <<cxx . . $ QDebug#`operator<<`(6e3b7ae53f380c3). picture.error_code;
293 WebPPictureFree(&picture);
294 WebPMemoryWriterClear(&writer);
295 return false;
296 }
297
298 bool res = false;
299 if (image.colorSpacecxx . . $ QImage#colorSpace(c90390460279a559).().isValidcxx . . $ QColorSpace#isValid(3482b152b9333168).()) {
300 int copy_data = 0;
301 WebPMux *mux = WebPMuxNew();
302 WebPData image_data = { writer.memcxx . . $ WebPMemoryWriter#mem., writer.sizecxx . . $ WebPMemoryWriter#size. };
303 WebPMuxSetImage(mux, &image_data, copy_data);
304 uint8_tcxx . . $ uint8_t# vp8xChunk[10];
305 uint8_tcxx . . $ uint8_t# flags = 0x20; // Has ICCP chunk, no XMP, EXIF or animation.
306 if (image.hasAlphaChannelcxx . . $ QImage#hasAlphaChannel(50ce9a9e25b4a850).())
307 flags |= 0x10;
308 vp8xChunk[0] = flags;
309 vp8xChunk[1] = 0;
310 vp8xChunk[2] = 0;
311 vp8xChunk[3] = 0;
312 const unsigned width = image.widthcxx . . $ QImage#width(455f465bc33b4cdf).() - 1;
313 const unsigned height = image.heightcxx . . $ QImage#height(455f465bc33b4cdf).() - 1;
314 vp8xChunk[4] = width & 0xff;
315 vp8xChunk[5] = (width >> 8) & 0xff;
316 vp8xChunk[6] = (width >> 16) & 0xff;
317 vp8xChunk[7] = height & 0xff;
318 vp8xChunk[8] = (height >> 8) & 0xff;
319 vp8xChunk[9] = (height >> 16) & 0xff;
320 WebPData vp8x_data = { vp8xChunk, 10 };
321 if (WebPMuxSetChunk(mux, "VP8X", &vp8x_data, copy_data) == WEBP_MUX_OK) {
322 QByteArraycxx . . $ QByteArray# iccProfile = image.colorSpacecxx . . $ QImage#colorSpace(c90390460279a559).().iccProfilecxx . . $ QColorSpace#iccProfile(a96750bfbcb1fbe9).();
323 WebPData iccp_data = {
324 reinterpret_cast<const uint8_tcxx . . $ uint8_t# *>(iccProfile.constDatacxx . . $ QByteArray#constData(a9f41ea0e82d88cf).()),
325 static_cast<size_t>(iccProfile.sizecxx . . $ QByteArray#size(455f465bc33b4cdf).())
326 };
327 if (WebPMuxSetChunk(mux, "ICCP", &iccp_data, copy_data) == WEBP_MUX_OK) {
328 WebPData output_data;
329 if (WebPMuxAssemble(mux, &output_data) == WEBP_MUX_OK) {
330 res = (output_data.sizecxx . . $ WebPData#size. ==
331 static_cast<size_t>(devicecxx . . $ QImageIOHandler#device(84cdc49e7936af4f).()->writecxx . . $ QIODevice#write(93d4069f65218ea4).(reinterpret_cast<const char *>(output_data.bytescxx . . $ WebPData#bytes.), output_data.sizecxx . . $ WebPData#size.)));
332 }
333 WebPDataClear(&output_data);
334 }
335 }
336 WebPMuxDelete(mux);
337 }
338 if (!res) {
339 res = (writer.sizecxx . . $ WebPMemoryWriter#size. ==
340 static_cast<size_t>(devicecxx . . $ QImageIOHandler#device(84cdc49e7936af4f).()->writecxx . . $ QIODevice#write(93d4069f65218ea4).(reinterpret_cast<const char *>(writer.memcxx . . $ WebPMemoryWriter#mem.), writer.sizecxx . . $ WebPMemoryWriter#size.)));
341 }
342 WebPPictureFree(&picture);
343 WebPMemoryWriterClear(&writer);
344
345 return res;
346 }
347
348 QVariantcxx . . $ QVariant# QWebpHandlercxx . . $ QWebpHandler#::optioncxx . . $ QWebpHandler#option(5e4f138555277744).(ImageOptioncxx . . $ QImageIOHandler#ImageOption# option) const
349 {
350 if (!supportsOptioncxx . . $ QWebpHandler#supportsOption(55c593ff6d26ae20).(option) || !ensureScannedcxx . . $ QWebpHandler#ensureScanned(50ce9a9e25b4a850).())
351 return QVariantcxx . . $ QVariant#QVariant(ced63f7c635d850d).();
352
353 switch (option) {
354 case Qualitycxx . . $ QImageIOHandler#Quality.:
355 return m_qualitycxx . . $ QVariant#QVariant(d4f767463ce0a6b3).;
356 case Sizecxx . . $ QImageIOHandler#Size.:
357 return QSizecxx . . $ QVariant#QVariant(1c5f201b4c2f0aba).(m_featurescxx . . $ QWebpHandler#m_features..widthcxx . . $ WebPBitstreamFeatures#width., m_featurescxx . . $ QWebpHandler#m_features..heightcxx . . $ WebPBitstreamFeatures#height.);
358 case Animationcxx . . $ QImageIOHandler#Animation.:
359 return m_featurescxx . . $ QVariant#QVariant(d4f767463ce0a6b3)..has_animationcxx . . $ WebPBitstreamFeatures#has_animation.;
360 case BackgroundColorcxx . . $ QImageIOHandler#BackgroundColor.:
361 return m_bgColorcxx . . $ QWebpHandler#m_bgColor.;
362 default:
363 return QVariantcxx . . $ QVariant#QVariant(ced63f7c635d850d).();
364 }
365 }
366
367 void QWebpHandlercxx . . $ QWebpHandler#::setOptioncxx . . $ QWebpHandler#setOption(eb42a208eb11d98f).(ImageOptioncxx . . $ QImageIOHandler#ImageOption# option, const QVariantcxx . . $ QVariant# &value)
368 {
369 switch (option) {
370 case Qualitycxx . . $ QImageIOHandler#Quality.:
371 m_qualitycxx . . $ QWebpHandler#m_quality. = value.toIntcxx . . $ QVariant#toInt(5bd9a3493f6a7a21).();
372 return;
373 default:
374 break;
375 }
376 QImageIOHandlercxx . . $ QImageIOHandler#::setOptioncxx . . $ QImageIOHandler#setOption(eb42a208eb11d98f).(option, value);
377 }
378
379 bool QWebpHandlercxx . . $ QWebpHandler#::supportsOptioncxx . . $ QWebpHandler#supportsOption(55c593ff6d26ae20).(ImageOptioncxx . . $ QImageIOHandler#ImageOption# option) const
380 {
381 return option == Qualitycxx . . $ QImageIOHandler#Quality.
382 || option == Sizecxx . . $ QImageIOHandler#Size.
383 || option == Animationcxx . . $ QImageIOHandler#Animation.
384 || option == BackgroundColorcxx . . $ QImageIOHandler#BackgroundColor.;
385 }
386
387 int QWebpHandlercxx . . $ QWebpHandler#::imageCountcxx . . $ QWebpHandler#imageCount(455f465bc33b4cdf).() const
388 {
389 if (!ensureScannedcxx . . $ QWebpHandler#ensureScanned(50ce9a9e25b4a850).())
390 return 0;
391
392 if (!m_featurescxx . . $ QWebpHandler#m_features..has_animationcxx . . $ WebPBitstreamFeatures#has_animation.)
393 return 1;
394
395 return m_frameCountcxx . . $ QWebpHandler#m_frameCount.;
396 }
397
398 int QWebpHandlercxx . . $ QWebpHandler#::currentImageNumbercxx . . $ QWebpHandler#currentImageNumber(455f465bc33b4cdf).() const
399 {
400 if (!ensureScannedcxx . . $ QWebpHandler#ensureScanned(50ce9a9e25b4a850).() || !m_featurescxx . . $ QWebpHandler#m_features..has_animationcxx . . $ WebPBitstreamFeatures#has_animation.)
401 return 0;
402
403 // Frame number in WebP starts from 1
404 return m_itercxx . . $ QWebpHandler#m_iter..frame_numcxx . . $ WebPIterator#frame_num. - 1;
405 }
406
407 QRectcxx . . $ QRect# QWebpHandlercxx . . $ QWebpHandler#::currentImageRectcxx . . $ QWebpHandler#currentImageRect(d857385bac04cbf7).() const
408 {
409 if (!ensureScannedcxx . . $ QWebpHandler#ensureScanned(50ce9a9e25b4a850).())
410 return QRectcxx . . $ QRect#QRect(ced63f7c635d850d).();
411
412 return QRectcxx . . $ QRect#QRect(2261ffe5112eab06).(m_itercxx . . $ QWebpHandler#m_iter..x_offsetcxx . . $ WebPIterator#x_offset., m_itercxx . . $ QWebpHandler#m_iter..y_offsetcxx . . $ WebPIterator#y_offset., m_itercxx . . $ QWebpHandler#m_iter..widthcxx . . $ WebPIterator#width., m_itercxx . . $ QWebpHandler#m_iter..heightcxx . . $ WebPIterator#height.);
413 }
414
415 int QWebpHandlercxx . . $ QWebpHandler#::loopCountcxx . . $ QWebpHandler#loopCount(455f465bc33b4cdf).() const
416 {
417 if (!ensureScannedcxx . . $ QWebpHandler#ensureScanned(50ce9a9e25b4a850).() || !m_featurescxx . . $ QWebpHandler#m_features..has_animationcxx . . $ WebPBitstreamFeatures#has_animation.)
418 return 0;
419
420 // Loop count in WebP starts from 0
421 return m_loopcxx . . $ QWebpHandler#m_loop. - 1;
422 }
423
424 int QWebpHandlercxx . . $ QWebpHandler#::nextImageDelaycxx . . $ QWebpHandler#nextImageDelay(455f465bc33b4cdf).() const
425 {
426 if (!ensureScannedcxx . . $ QWebpHandler#ensureScanned(50ce9a9e25b4a850).() || !m_featurescxx . . $ QWebpHandler#m_features..has_animationcxx . . $ WebPBitstreamFeatures#has_animation.)
427 return 0;
428
429 return m_itercxx . . $ QWebpHandler#m_iter..durationcxx . . $ WebPIterator#duration.;
430 }