image/qpnghandler.cpp

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
1/**************************************************************************** -
2** -
3** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -
4** Contact: http://www.qt-project.org/legal -
5** -
6** This file is part of the QtGui module of the Qt Toolkit. -
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 Digia. For licensing terms and -
14** conditions see http://qt.digia.com/licensing. For further information -
15** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software -
20** Foundation and appearing in the file LICENSE.LGPL included in the -
21** packaging of this file. Please review the following information to -
22** ensure the GNU Lesser General Public License version 2.1 requirements -
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -
24** -
25** In addition, as a special exception, Digia gives you certain additional -
26** rights. These rights are described in the Digia Qt LGPL Exception -
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -
28** -
29** GNU General Public License Usage -
30** Alternatively, this file may be used under the terms of the GNU -
31** General Public License version 3.0 as published by the Free Software -
32** Foundation and appearing in the file LICENSE.GPL included in the -
33** packaging of this file. Please review the following information to -
34** ensure the GNU General Public License version 3.0 requirements will be -
35** met: http://www.gnu.org/copyleft/gpl.html. -
36** -
37** -
38** $QT_END_LICENSE$ -
39** -
40****************************************************************************/ -
41 -
42#include "private/qpnghandler_p.h" -
43 -
44#ifndef QT_NO_IMAGEFORMAT_PNG -
45#include <qcoreapplication.h> -
46#include <qiodevice.h> -
47#include <qimage.h> -
48#include <qlist.h> -
49#include <qtextcodec.h> -
50#include <qvariant.h> -
51#include <qvector.h> -
52 -
53#ifdef QT_USE_BUNDLED_LIBPNG -
54#include <../../3rdparty/libpng/png.h> -
55#include <../../3rdparty/libpng/pngconf.h> -
56#else -
57#include <png.h> -
58#include <pngconf.h> -
59#endif -
60 -
61#if PNG_LIBPNG_VER >= 10400 && PNG_LIBPNG_VER <= 10502 \ -
62 && defined(PNG_PEDANTIC_WARNINGS_SUPPORTED) -
63/* -
64 Versions 1.4.0 to 1.5.2 of libpng declare png_longjmp_ptr to -
65 have a noreturn attribute if PNG_PEDANTIC_WARNINGS_SUPPORTED -
66 is enabled, but most declarations of longjmp in the wild do -
67 not add this attribute. This causes problems when the png_jmpbuf -
68 macro expands to calling png_set_longjmp_fn with a mismatched -
69 longjmp, as compilers such as Clang will treat this as an error. -
70 -
71 To work around this we override the png_jmpbuf macro to cast -
72 longjmp to a png_longjmp_ptr. -
73*/ -
74# undef png_jmpbuf -
75# ifdef PNG_SETJMP_SUPPORTED -
76# define png_jmpbuf(png_ptr) \ -
77 (*png_set_longjmp_fn((png_ptr), (png_longjmp_ptr)longjmp, sizeof(jmp_buf))) -
78# else -
79# define png_jmpbuf(png_ptr) \ -
80 (LIBPNG_WAS_COMPILED_WITH__PNG_NO_SETJMP) -
81# endif -
82#endif -
83 -
84#ifdef Q_OS_WINCE -
85#define CALLBACK_CALL_TYPE __cdecl -
86#else -
87#define CALLBACK_CALL_TYPE -
88#endif -
89 -
90QT_BEGIN_NAMESPACE -
91 -
92#if defined(Q_OS_WINCE) && defined(STANDARDSHELL_UI_MODEL) -
93# define Q_INTERNAL_WIN_NO_THROW __declspec(nothrow) -
94#else -
95# define Q_INTERNAL_WIN_NO_THROW -
96#endif -
97 -
98// avoid going through QImage::scanLine() which calls detach -
99#define FAST_SCAN_LINE(data, bpl, y) (data + (y) * bpl) -
100 -
101/* -
102 All PNG files load to the minimal QImage equivalent. -
103 -
104 All QImage formats output to reasonably efficient PNG equivalents. -
105*/ -
106 -
107class QPngHandlerPrivate -
108{ -
109public: -
110 enum State { -
111 Ready, -
112 ReadHeader, -
113 ReadingEnd, -
114 Error -
115 }; -
116 -
117 QPngHandlerPrivate(QPngHandler *qq) -
118 : gamma(0.0), quality(2), png_ptr(0), info_ptr(0), end_info(0), state(Ready), q(qq) -
119 { }
executed: }
Execution Count:577
577
120 -
121 float gamma; -
122 int quality; -
123 QString description; -
124 QSize scaledSize; -
125 QStringList readTexts; -
126 -
127 png_struct *png_ptr; -
128 png_info *info_ptr; -
129 png_info *end_info; -
130 -
131 bool readPngHeader(); -
132 bool readPngImage(QImage *image); -
133 void readPngTexts(png_info *info); -
134 -
135 QImage::Format readImageFormat(); -
136 -
137 struct AllocatedMemoryPointers { -
138 AllocatedMemoryPointers() -
139 : row_pointers(0), accRow(0), inRow(0), outRow(0) -
140 { }
executed: }
Execution Count:577
577
141 void deallocate() -
142 { -
143 delete [] row_pointers;
executed (the execution status of this line is deduced): delete [] row_pointers;
-
144 row_pointers = 0;
executed (the execution status of this line is deduced): row_pointers = 0;
-
145 delete [] accRow;
executed (the execution status of this line is deduced): delete [] accRow;
-
146 accRow = 0;
executed (the execution status of this line is deduced): accRow = 0;
-
147 delete [] inRow;
executed (the execution status of this line is deduced): delete [] inRow;
-
148 inRow = 0;
executed (the execution status of this line is deduced): inRow = 0;
-
149 delete [] outRow;
executed (the execution status of this line is deduced): delete [] outRow;
-
150 outRow = 0;
executed (the execution status of this line is deduced): outRow = 0;
-
151 }
executed: }
Execution Count:847
847
152 -
153 png_byte **row_pointers; -
154 quint32 *accRow; -
155 png_byte *inRow; -
156 uchar *outRow; -
157 }; -
158 -
159 AllocatedMemoryPointers amp; -
160 -
161 State state; -
162 -
163 QPngHandler *q; -
164}; -
165 -
166 -
167#if defined(Q_C_CALLBACKS) -
168extern "C" { -
169#endif -
170 -
171class QPNGImageWriter { -
172public: -
173 explicit QPNGImageWriter(QIODevice*); -
174 ~QPNGImageWriter(); -
175 -
176 enum DisposalMethod { Unspecified, NoDisposal, RestoreBackground, RestoreImage }; -
177 void setDisposalMethod(DisposalMethod); -
178 void setLooping(int loops=0); // 0 == infinity -
179 void setFrameDelay(int msecs); -
180 void setGamma(float); -
181 -
182 bool writeImage(const QImage& img, int x, int y); -
183 bool writeImage(const QImage& img, volatile int quality, const QString &description, int x, int y); -
184 bool writeImage(const QImage& img) -
185 { return writeImage(img, 0, 0); }
never executed: return writeImage(img, 0, 0);
0
186 bool writeImage(const QImage& img, int quality, const QString &description) -
187 { return writeImage(img, quality, description, 0, 0); }
executed: return writeImage(img, quality, description, 0, 0);
Execution Count:123
123
188 -
189 QIODevice* device() { return dev; }
executed: return dev;
Execution Count:2489
2489
190 -
191private: -
192 QIODevice* dev; -
193 int frames_written; -
194 DisposalMethod disposal; -
195 int looping; -
196 int ms_delay; -
197 float gamma; -
198}; -
199 -
200static -
201void CALLBACK_CALL_TYPE iod_read_fn(png_structp png_ptr, png_bytep data, png_size_t length) -
202{ -
203 QPngHandlerPrivate *d = (QPngHandlerPrivate *)png_get_io_ptr(png_ptr);
executed (the execution status of this line is deduced): QPngHandlerPrivate *d = (QPngHandlerPrivate *)png_get_io_ptr(png_ptr);
-
204 QIODevice *in = d->q->device();
executed (the execution status of this line is deduced): QIODevice *in = d->q->device();
-
205 -
206 if (d->state == QPngHandlerPrivate::ReadingEnd && !in->isSequential() && (in->size() - in->pos()) < 4 && length == 4) {
evaluated: d->state == QPngHandlerPrivate::ReadingEnd
TRUEFALSE
yes
Evaluation Count:1287
yes
Evaluation Count:9047
evaluated: !in->isSequential()
TRUEFALSE
yes
Evaluation Count:1284
yes
Evaluation Count:3
partially evaluated: (in->size() - in->pos()) < 4
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1284
never evaluated: length == 4
0-9047
207 // Workaround for certain malformed PNGs that lack the final crc bytes -
208 uchar endcrc[4] = { 0xae, 0x42, 0x60, 0x82 };
never executed (the execution status of this line is deduced): uchar endcrc[4] = { 0xae, 0x42, 0x60, 0x82 };
-
209 memcpy(data, endcrc, 4);
never executed (the execution status of this line is deduced): memcpy(data, endcrc, 4);
-
210 in->seek(in->size());
never executed (the execution status of this line is deduced): in->seek(in->size());
-
211 return;
never executed: return;
0
212 } -
213 -
214 while (length) {
evaluated: length
TRUEFALSE
yes
Evaluation Count:10347
yes
Evaluation Count:10321
10321-10347
215 int nr = in->read((char*)data, length);
executed (the execution status of this line is deduced): int nr = in->read((char*)data, length);
-
216 if (nr <= 0) {
evaluated: nr <= 0
TRUEFALSE
yes
Evaluation Count:13
yes
Evaluation Count:10334
13-10334
217 png_error(png_ptr, "Read Error");
never executed (the execution status of this line is deduced): png_error(png_ptr, "Read Error");
-
218 return;
never executed: return;
0
219 } -
220 length -= nr;
executed (the execution status of this line is deduced): length -= nr;
-
221 }
executed: }
Execution Count:10334
10334
222}
executed: }
Execution Count:10321
10321
223 -
224 -
225static -
226void CALLBACK_CALL_TYPE qpiw_write_fn(png_structp png_ptr, png_bytep data, png_size_t length) -
227{ -
228 QPNGImageWriter* qpiw = (QPNGImageWriter*)png_get_io_ptr(png_ptr);
executed (the execution status of this line is deduced): QPNGImageWriter* qpiw = (QPNGImageWriter*)png_get_io_ptr(png_ptr);
-
229 QIODevice* out = qpiw->device();
executed (the execution status of this line is deduced): QIODevice* out = qpiw->device();
-
230 -
231 uint nr = out->write((char*)data, length);
executed (the execution status of this line is deduced): uint nr = out->write((char*)data, length);
-
232 if (nr != length) {
partially evaluated: nr != length
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2489
0-2489
233 png_error(png_ptr, "Write Error");
never executed (the execution status of this line is deduced): png_error(png_ptr, "Write Error");
-
234 return;
never executed: return;
0
235 } -
236}
executed: }
Execution Count:2489
2489
237 -
238 -
239static -
240void CALLBACK_CALL_TYPE qpiw_flush_fn(png_structp /* png_ptr */) -
241{ -
242} -
243 -
244#if defined(Q_C_CALLBACKS) -
245} -
246#endif -
247 -
248static -
249void setup_qt(QImage& image, png_structp png_ptr, png_infop info_ptr, QSize scaledSize, bool *doScaledRead, float screen_gamma=0.0) -
250{ -
251 if (screen_gamma != 0.0 && png_get_valid(png_ptr, info_ptr, PNG_INFO_gAMA)) {
partially evaluated: screen_gamma != 0.0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:430
never evaluated: png_get_valid(png_ptr, info_ptr, 0x0001)
0-430
252 double file_gamma;
never executed (the execution status of this line is deduced): double file_gamma;
-
253 png_get_gAMA(png_ptr, info_ptr, &file_gamma);
never executed (the execution status of this line is deduced): png_get_gAMA(png_ptr, info_ptr, &file_gamma);
-
254 png_set_gamma(png_ptr, screen_gamma, file_gamma);
never executed (the execution status of this line is deduced): png_set_gamma(png_ptr, screen_gamma, file_gamma);
-
255 }
never executed: }
0
256 -
257 png_uint_32 width;
executed (the execution status of this line is deduced): png_uint_32 width;
-
258 png_uint_32 height;
executed (the execution status of this line is deduced): png_uint_32 height;
-
259 int bit_depth;
executed (the execution status of this line is deduced): int bit_depth;
-
260 int color_type;
executed (the execution status of this line is deduced): int color_type;
-
261 png_bytep trans_alpha = 0;
executed (the execution status of this line is deduced): png_bytep trans_alpha = 0;
-
262 png_color_16p trans_color_p = 0;
executed (the execution status of this line is deduced): png_color_16p trans_color_p = 0;
-
263 int num_trans;
executed (the execution status of this line is deduced): int num_trans;
-
264 png_colorp palette = 0;
executed (the execution status of this line is deduced): png_colorp palette = 0;
-
265 int num_palette;
executed (the execution status of this line is deduced): int num_palette;
-
266 int interlace_method;
executed (the execution status of this line is deduced): int interlace_method;
-
267 png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_method, 0, 0);
executed (the execution status of this line is deduced): png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_method, 0, 0);
-
268 png_set_interlace_handling(png_ptr);
executed (the execution status of this line is deduced): png_set_interlace_handling(png_ptr);
-
269 -
270 if (color_type == PNG_COLOR_TYPE_GRAY) {
partially evaluated: color_type == 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:430
0-430
271 // Black & White or 8-bit grayscale -
272 if (bit_depth == 1 && png_get_channels(png_ptr, info_ptr) == 1) {
never evaluated: bit_depth == 1
never evaluated: png_get_channels(png_ptr, info_ptr) == 1
0
273 png_set_invert_mono(png_ptr);
never executed (the execution status of this line is deduced): png_set_invert_mono(png_ptr);
-
274 png_read_update_info(png_ptr, info_ptr);
never executed (the execution status of this line is deduced): png_read_update_info(png_ptr, info_ptr);
-
275 if (image.size() != QSize(width, height) || image.format() != QImage::Format_Mono) {
never evaluated: image.size() != QSize(width, height)
never evaluated: image.format() != QImage::Format_Mono
0
276 image = QImage(width, height, QImage::Format_Mono);
never executed (the execution status of this line is deduced): image = QImage(width, height, QImage::Format_Mono);
-
277 if (image.isNull())
never evaluated: image.isNull()
0
278 return;
never executed: return;
0
279 }
never executed: }
0
280 image.setColorCount(2);
never executed (the execution status of this line is deduced): image.setColorCount(2);
-
281 image.setColor(1, qRgb(0,0,0));
never executed (the execution status of this line is deduced): image.setColor(1, qRgb(0,0,0));
-
282 image.setColor(0, qRgb(255,255,255));
never executed (the execution status of this line is deduced): image.setColor(0, qRgb(255,255,255));
-
283 } else if (bit_depth == 16 && png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
never executed: }
never evaluated: bit_depth == 16
never evaluated: png_get_valid(png_ptr, info_ptr, 0x0010)
0
284 png_set_expand(png_ptr);
never executed (the execution status of this line is deduced): png_set_expand(png_ptr);
-
285 png_set_strip_16(png_ptr);
never executed (the execution status of this line is deduced): png_set_strip_16(png_ptr);
-
286 png_set_gray_to_rgb(png_ptr);
never executed (the execution status of this line is deduced): png_set_gray_to_rgb(png_ptr);
-
287 if (image.size() != QSize(width, height) || image.format() != QImage::Format_ARGB32) {
never evaluated: image.size() != QSize(width, height)
never evaluated: image.format() != QImage::Format_ARGB32
0
288 image = QImage(width, height, QImage::Format_ARGB32);
never executed (the execution status of this line is deduced): image = QImage(width, height, QImage::Format_ARGB32);
-
289 if (image.isNull())
never evaluated: image.isNull()
0
290 return;
never executed: return;
0
291 }
never executed: }
0
292 if (QSysInfo::ByteOrder == QSysInfo::BigEndian)
never evaluated: QSysInfo::ByteOrder == QSysInfo::BigEndian
0
293 png_set_swap_alpha(png_ptr);
never executed: png_set_swap_alpha(png_ptr);
0
294 -
295 png_read_update_info(png_ptr, info_ptr);
never executed (the execution status of this line is deduced): png_read_update_info(png_ptr, info_ptr);
-
296 } else {
never executed: }
0
297 if (bit_depth == 16)
never evaluated: bit_depth == 16
0
298 png_set_strip_16(png_ptr);
never executed: png_set_strip_16(png_ptr);
0
299 else if (bit_depth < 8)
never evaluated: bit_depth < 8
0
300 png_set_packing(png_ptr);
never executed: png_set_packing(png_ptr);
0
301 int ncols = bit_depth < 8 ? 1 << bit_depth : 256;
never evaluated: bit_depth < 8
0
302 png_read_update_info(png_ptr, info_ptr);
never executed (the execution status of this line is deduced): png_read_update_info(png_ptr, info_ptr);
-
303 if (image.size() != QSize(width, height) || image.format() != QImage::Format_Indexed8) {
never evaluated: image.size() != QSize(width, height)
never evaluated: image.format() != QImage::Format_Indexed8
0
304 image = QImage(width, height, QImage::Format_Indexed8);
never executed (the execution status of this line is deduced): image = QImage(width, height, QImage::Format_Indexed8);
-
305 if (image.isNull())
never evaluated: image.isNull()
0
306 return;
never executed: return;
0
307 }
never executed: }
0
308 image.setColorCount(ncols);
never executed (the execution status of this line is deduced): image.setColorCount(ncols);
-
309 for (int i=0; i<ncols; i++) {
never evaluated: i<ncols
0
310 int c = i*255/(ncols-1);
never executed (the execution status of this line is deduced): int c = i*255/(ncols-1);
-
311 image.setColor(i, qRgba(c,c,c,0xff));
never executed (the execution status of this line is deduced): image.setColor(i, qRgba(c,c,c,0xff));
-
312 }
never executed: }
0
313 if (png_get_tRNS(png_ptr, info_ptr, &trans_alpha, &num_trans, &trans_color_p) && trans_color_p) {
never evaluated: png_get_tRNS(png_ptr, info_ptr, &trans_alpha, &num_trans, &trans_color_p)
never evaluated: trans_color_p
0
314 const int g = trans_color_p->gray;
never executed (the execution status of this line is deduced): const int g = trans_color_p->gray;
-
315 if (g < ncols) {
never evaluated: g < ncols
0
316 image.setColor(g, 0);
never executed (the execution status of this line is deduced): image.setColor(g, 0);
-
317 }
never executed: }
0
318 }
never executed: }
0
319 }
never executed: }
0
320 } else if (color_type == PNG_COLOR_TYPE_PALETTE
evaluated: color_type == (2 | 1)
TRUEFALSE
yes
Evaluation Count:75
yes
Evaluation Count:355
75-355
321 && png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette)
partially evaluated: png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette)
TRUEFALSE
yes
Evaluation Count:75
no
Evaluation Count:0
0-75
322 && num_palette <= 256)
partially evaluated: num_palette <= 256
TRUEFALSE
yes
Evaluation Count:75
no
Evaluation Count:0
0-75
323 { -
324 // 1-bit and 8-bit color -
325 if (bit_depth != 1)
evaluated: bit_depth != 1
TRUEFALSE
yes
Evaluation Count:58
yes
Evaluation Count:17
17-58
326 png_set_packing(png_ptr);
executed: png_set_packing(png_ptr);
Execution Count:58
58
327 png_read_update_info(png_ptr, info_ptr);
executed (the execution status of this line is deduced): png_read_update_info(png_ptr, info_ptr);
-
328 png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, 0, 0, 0);
executed (the execution status of this line is deduced): png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, 0, 0, 0);
-
329 QImage::Format format = bit_depth == 1 ? QImage::Format_Mono : QImage::Format_Indexed8;
evaluated: bit_depth == 1
TRUEFALSE
yes
Evaluation Count:17
yes
Evaluation Count:58
17-58
330 if (image.size() != QSize(width, height) || image.format() != format) {
partially evaluated: image.size() != QSize(width, height)
TRUEFALSE
yes
Evaluation Count:75
no
Evaluation Count:0
never evaluated: image.format() != format
0-75
331 image = QImage(width, height, format);
executed (the execution status of this line is deduced): image = QImage(width, height, format);
-
332 if (image.isNull())
partially evaluated: image.isNull()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:75
0-75
333 return;
never executed: return;
0
334 }
executed: }
Execution Count:75
75
335 png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette);
executed (the execution status of this line is deduced): png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette);
-
336 image.setColorCount(num_palette);
executed (the execution status of this line is deduced): image.setColorCount(num_palette);
-
337 int i = 0;
executed (the execution status of this line is deduced): int i = 0;
-
338 if (png_get_tRNS(png_ptr, info_ptr, &trans_alpha, &num_trans, &trans_color_p) && trans_alpha) {
evaluated: png_get_tRNS(png_ptr, info_ptr, &trans_alpha, &num_trans, &trans_color_p)
TRUEFALSE
yes
Evaluation Count:50
yes
Evaluation Count:25
partially evaluated: trans_alpha
TRUEFALSE
yes
Evaluation Count:50
no
Evaluation Count:0
0-50
339 while (i < num_trans) {
evaluated: i < num_trans
TRUEFALSE
yes
Evaluation Count:1059
yes
Evaluation Count:50
50-1059
340 image.setColor(i, qRgba(
executed (the execution status of this line is deduced): image.setColor(i, qRgba(
-
341 palette[i].red,
executed (the execution status of this line is deduced): palette[i].red,
-
342 palette[i].green,
executed (the execution status of this line is deduced): palette[i].green,
-
343 palette[i].blue,
executed (the execution status of this line is deduced): palette[i].blue,
-
344 trans_alpha[i]
executed (the execution status of this line is deduced): trans_alpha[i]
-
345 )
executed (the execution status of this line is deduced): )
-
346 );
executed (the execution status of this line is deduced): );
-
347 i++;
executed (the execution status of this line is deduced): i++;
-
348 }
executed: }
Execution Count:1059
1059
349 }
executed: }
Execution Count:50
50
350 while (i < num_palette) {
evaluated: i < num_palette
TRUEFALSE
yes
Evaluation Count:2819
yes
Evaluation Count:75
75-2819
351 image.setColor(i, qRgba(
executed (the execution status of this line is deduced): image.setColor(i, qRgba(
-
352 palette[i].red,
executed (the execution status of this line is deduced): palette[i].red,
-
353 palette[i].green,
executed (the execution status of this line is deduced): palette[i].green,
-
354 palette[i].blue,
executed (the execution status of this line is deduced): palette[i].blue,
-
355 0xff
executed (the execution status of this line is deduced): 0xff
-
356 )
executed (the execution status of this line is deduced): )
-
357 );
executed (the execution status of this line is deduced): );
-
358 i++;
executed (the execution status of this line is deduced): i++;
-
359 }
executed: }
Execution Count:2819
2819
360 } else {
executed: }
Execution Count:75
75
361 // 32-bit -
362 if (bit_depth == 16)
partially evaluated: bit_depth == 16
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:355
0-355
363 png_set_strip_16(png_ptr);
never executed: png_set_strip_16(png_ptr);
0
364 -
365 png_set_expand(png_ptr);
executed (the execution status of this line is deduced): png_set_expand(png_ptr);
-
366 -
367 if (color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
partially evaluated: color_type == (4)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:355
0-355
368 png_set_gray_to_rgb(png_ptr);
never executed: png_set_gray_to_rgb(png_ptr);
0
369 -
370 QImage::Format format = QImage::Format_ARGB32;
executed (the execution status of this line is deduced): QImage::Format format = QImage::Format_ARGB32;
-
371 // Only add filler if no alpha, or we can get 5 channel data. -
372 if (!(color_type & PNG_COLOR_MASK_ALPHA)
evaluated: !(color_type & 4)
TRUEFALSE
yes
Evaluation Count:67
yes
Evaluation Count:288
67-288
373 && !png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
partially evaluated: !png_get_valid(png_ptr, info_ptr, 0x0010)
TRUEFALSE
yes
Evaluation Count:67
no
Evaluation Count:0
0-67
374 png_set_filler(png_ptr, 0xff, QSysInfo::ByteOrder == QSysInfo::BigEndian ?
executed (the execution status of this line is deduced): png_set_filler(png_ptr, 0xff, QSysInfo::ByteOrder == QSysInfo::BigEndian ?
-
375 PNG_FILLER_BEFORE : PNG_FILLER_AFTER);
executed (the execution status of this line is deduced): 0 : 1);
-
376 // We want 4 bytes, but it isn't an alpha channel -
377 format = QImage::Format_RGB32;
executed (the execution status of this line is deduced): format = QImage::Format_RGB32;
-
378 }
executed: }
Execution Count:67
67
379 QSize outSize(width,height);
executed (the execution status of this line is deduced): QSize outSize(width,height);
-
380 if (!scaledSize.isEmpty() && quint32(scaledSize.width()) <= width &&
evaluated: !scaledSize.isEmpty()
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:352
partially evaluated: quint32(scaledSize.width()) <= width
TRUEFALSE
yes
Evaluation Count:3
no
Evaluation Count:0
0-352
381 quint32(scaledSize.height()) <= height && interlace_method == PNG_INTERLACE_NONE) {
partially evaluated: quint32(scaledSize.height()) <= height
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:3
never evaluated: interlace_method == 0
0-3
382 // Do inline downscaling -
383 outSize = scaledSize;
never executed (the execution status of this line is deduced): outSize = scaledSize;
-
384 if (doScaledRead)
never evaluated: doScaledRead
0
385 *doScaledRead = true;
never executed: *doScaledRead = true;
0
386 }
never executed: }
0
387 if (image.size() != outSize || image.format() != format) {
partially evaluated: image.size() != outSize
TRUEFALSE
yes
Evaluation Count:355
no
Evaluation Count:0
never evaluated: image.format() != format
0-355
388 image = QImage(outSize, format);
executed (the execution status of this line is deduced): image = QImage(outSize, format);
-
389 if (image.isNull())
partially evaluated: image.isNull()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:355
0-355
390 return;
never executed: return;
0
391 }
executed: }
Execution Count:355
355
392 -
393 if (QSysInfo::ByteOrder == QSysInfo::BigEndian)
partially evaluated: QSysInfo::ByteOrder == QSysInfo::BigEndian
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:355
0-355
394 png_set_swap_alpha(png_ptr);
never executed: png_set_swap_alpha(png_ptr);
0
395 -
396 png_read_update_info(png_ptr, info_ptr);
executed (the execution status of this line is deduced): png_read_update_info(png_ptr, info_ptr);
-
397 }
executed: }
Execution Count:355
355
398 -
399 // Qt==ARGB==Big(ARGB)==Little(BGRA) -
400 if (QSysInfo::ByteOrder == QSysInfo::LittleEndian) {
partially evaluated: QSysInfo::ByteOrder == QSysInfo::LittleEndian
TRUEFALSE
yes
Evaluation Count:430
no
Evaluation Count:0
0-430
401 png_set_bgr(png_ptr);
executed (the execution status of this line is deduced): png_set_bgr(png_ptr);
-
402 }
executed: }
Execution Count:430
430
403}
executed: }
Execution Count:430
430
404 -
405static void read_image_scaled(QImage *outImage, png_structp png_ptr, png_infop info_ptr, -
406 QPngHandlerPrivate::AllocatedMemoryPointers &amp, QSize scaledSize) -
407{ -
408 -
409 png_uint_32 width;
never executed (the execution status of this line is deduced): png_uint_32 width;
-
410 png_uint_32 height;
never executed (the execution status of this line is deduced): png_uint_32 height;
-
411 int bit_depth;
never executed (the execution status of this line is deduced): int bit_depth;
-
412 int color_type;
never executed (the execution status of this line is deduced): int color_type;
-
413 png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, 0, 0, 0);
never executed (the execution status of this line is deduced): png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, 0, 0, 0);
-
414 uchar *data = outImage->bits();
never executed (the execution status of this line is deduced): uchar *data = outImage->bits();
-
415 int bpl = outImage->bytesPerLine();
never executed (the execution status of this line is deduced): int bpl = outImage->bytesPerLine();
-
416 -
417 if (scaledSize.isEmpty() || !width || !height)
never evaluated: scaledSize.isEmpty()
never evaluated: !width
never evaluated: !height
0
418 return;
never executed: return;
0
419 -
420 const quint32 iysz = height;
never executed (the execution status of this line is deduced): const quint32 iysz = height;
-
421 const quint32 ixsz = width;
never executed (the execution status of this line is deduced): const quint32 ixsz = width;
-
422 const quint32 oysz = scaledSize.height();
never executed (the execution status of this line is deduced): const quint32 oysz = scaledSize.height();
-
423 const quint32 oxsz = scaledSize.width();
never executed (the execution status of this line is deduced): const quint32 oxsz = scaledSize.width();
-
424 const quint32 ibw = 4*width;
never executed (the execution status of this line is deduced): const quint32 ibw = 4*width;
-
425 amp.accRow = new quint32[ibw];
never executed (the execution status of this line is deduced): amp.accRow = new quint32[ibw];
-
426 memset(amp.accRow, 0, ibw*sizeof(quint32));
never executed (the execution status of this line is deduced): memset(amp.accRow, 0, ibw*sizeof(quint32));
-
427 amp.inRow = new png_byte[ibw];
never executed (the execution status of this line is deduced): amp.inRow = new png_byte[ibw];
-
428 memset(amp.inRow, 0, ibw*sizeof(png_byte));
never executed (the execution status of this line is deduced): memset(amp.inRow, 0, ibw*sizeof(png_byte));
-
429 amp.outRow = new uchar[ibw];
never executed (the execution status of this line is deduced): amp.outRow = new uchar[ibw];
-
430 memset(amp.outRow, 0, ibw*sizeof(uchar));
never executed (the execution status of this line is deduced): memset(amp.outRow, 0, ibw*sizeof(uchar));
-
431 qint32 rval = 0;
never executed (the execution status of this line is deduced): qint32 rval = 0;
-
432 for (quint32 oy=0; oy<oysz; oy++) {
never evaluated: oy<oysz
0
433 // Store the rest of the previous input row, if any -
434 for (quint32 i=0; i < ibw; i++)
never evaluated: i < ibw
0
435 amp.accRow[i] = rval*amp.inRow[i];
never executed: amp.accRow[i] = rval*amp.inRow[i];
0
436 // Accumulate the next input rows -
437 for (rval = iysz-rval; rval > 0; rval-=oysz) {
never evaluated: rval > 0
0
438 png_read_row(png_ptr, amp.inRow, NULL);
never executed (the execution status of this line is deduced): png_read_row(png_ptr, amp.inRow, __null);
-
439 quint32 fact = qMin(oysz, quint32(rval));
never executed (the execution status of this line is deduced): quint32 fact = qMin(oysz, quint32(rval));
-
440 for (quint32 i=0; i < ibw; i++)
never evaluated: i < ibw
0
441 amp.accRow[i] += fact*amp.inRow[i];
never executed: amp.accRow[i] += fact*amp.inRow[i];
0
442 }
never executed: }
0
443 rval *= -1;
never executed (the execution status of this line is deduced): rval *= -1;
-
444 -
445 // We have a full output row, store it -
446 for (quint32 i=0; i < ibw; i++)
never evaluated: i < ibw
0
447 amp.outRow[i] = uchar(amp.accRow[i]/iysz);
never executed: amp.outRow[i] = uchar(amp.accRow[i]/iysz);
0
448 -
449 quint32 a[4] = {0, 0, 0, 0};
never executed (the execution status of this line is deduced): quint32 a[4] = {0, 0, 0, 0};
-
450 qint32 cval = oxsz;
never executed (the execution status of this line is deduced): qint32 cval = oxsz;
-
451 quint32 ix = 0;
never executed (the execution status of this line is deduced): quint32 ix = 0;
-
452 for (quint32 ox=0; ox<oxsz; ox++) {
never evaluated: ox<oxsz
0
453 for (quint32 i=0; i < 4; i++)
never evaluated: i < 4
0
454 a[i] = cval * amp.outRow[ix+i];
never executed: a[i] = cval * amp.outRow[ix+i];
0
455 for (cval = ixsz - cval; cval > 0; cval-=oxsz) {
never evaluated: cval > 0
0
456 ix += 4;
never executed (the execution status of this line is deduced): ix += 4;
-
457 if (ix >= ibw)
never evaluated: ix >= ibw
0
458 break; // Safety belt, should not happen
never executed: break;
0
459 quint32 fact = qMin(oxsz, quint32(cval));
never executed (the execution status of this line is deduced): quint32 fact = qMin(oxsz, quint32(cval));
-
460 for (quint32 i=0; i < 4; i++)
never evaluated: i < 4
0
461 a[i] += fact * amp.outRow[ix+i];
never executed: a[i] += fact * amp.outRow[ix+i];
0
462 }
never executed: }
0
463 cval *= -1;
never executed (the execution status of this line is deduced): cval *= -1;
-
464 for (quint32 i=0; i < 4; i++)
never evaluated: i < 4
0
465 data[(4*ox)+i] = uchar(a[i]/ixsz);
never executed: data[(4*ox)+i] = uchar(a[i]/ixsz);
0
466 }
never executed: }
0
467 data += bpl;
never executed (the execution status of this line is deduced): data += bpl;
-
468 }
never executed: }
0
469 amp.deallocate();
never executed (the execution status of this line is deduced): amp.deallocate();
-
470 -
471 outImage->setDotsPerMeterX((png_get_x_pixels_per_meter(png_ptr,info_ptr)*oxsz)/ixsz);
never executed (the execution status of this line is deduced): outImage->setDotsPerMeterX((png_get_x_pixels_per_meter(png_ptr,info_ptr)*oxsz)/ixsz);
-
472 outImage->setDotsPerMeterY((png_get_y_pixels_per_meter(png_ptr,info_ptr)*oysz)/iysz);
never executed (the execution status of this line is deduced): outImage->setDotsPerMeterY((png_get_y_pixels_per_meter(png_ptr,info_ptr)*oysz)/iysz);
-
473}
never executed: }
0
474 -
475#if defined(Q_C_CALLBACKS) -
476extern "C" { -
477#endif -
478static void CALLBACK_CALL_TYPE qt_png_warning(png_structp /*png_ptr*/, png_const_charp message) -
479{ -
480 qWarning("libpng warning: %s", message);
never executed (the execution status of this line is deduced): QMessageLogger("image/qpnghandler.cpp", 480, __PRETTY_FUNCTION__).warning("libpng warning: %s", message);
-
481}
never executed: }
0
482 -
483#if defined(Q_C_CALLBACKS) -
484} -
485#endif -
486 -
487 -
488void Q_INTERNAL_WIN_NO_THROW QPngHandlerPrivate::readPngTexts(png_info *info) -
489{ -
490 png_textp text_ptr;
executed (the execution status of this line is deduced): png_textp text_ptr;
-
491 int num_text=0;
executed (the execution status of this line is deduced): int num_text=0;
-
492 png_get_text(png_ptr, info, &text_ptr, &num_text);
executed (the execution status of this line is deduced): png_get_text(png_ptr, info, &text_ptr, &num_text);
-
493 -
494 while (num_text--) {
evaluated: num_text--
TRUEFALSE
yes
Evaluation Count:144
yes
Evaluation Count:857
144-857
495 QString key, value;
executed (the execution status of this line is deduced): QString key, value;
-
496 key = QString::fromLatin1(text_ptr->key);
executed (the execution status of this line is deduced): key = QString::fromLatin1(text_ptr->key);
-
497#if defined(PNG_iTXt_SUPPORTED) -
498 if (text_ptr->itxt_length) { -
499 value = QString::fromUtf8(text_ptr->text, int(text_ptr->itxt_length)); -
500 } else -
501#endif -
502 { -
503 value = QString::fromLatin1(text_ptr->text, int(text_ptr->text_length));
executed (the execution status of this line is deduced): value = QString::fromLatin1(text_ptr->text, int(text_ptr->text_length));
-
504 } -
505 if (!description.isEmpty())
evaluated: !description.isEmpty()
TRUEFALSE
yes
Evaluation Count:34
yes
Evaluation Count:110
34-110
506 description += QLatin1String("\n\n");
executed: description += QLatin1String("\n\n");
Execution Count:34
34
507 description += key + QLatin1String(": ") + value.simplified();
executed (the execution status of this line is deduced): description += key + QLatin1String(": ") + value.simplified();
-
508 readTexts.append(key);
executed (the execution status of this line is deduced): readTexts.append(key);
-
509 readTexts.append(value);
executed (the execution status of this line is deduced): readTexts.append(value);
-
510 text_ptr++;
executed (the execution status of this line is deduced): text_ptr++;
-
511 }
executed: }
Execution Count:144
144
512}
executed: }
Execution Count:857
857
513 -
514 -
515bool Q_INTERNAL_WIN_NO_THROW QPngHandlerPrivate::readPngHeader() -
516{ -
517 state = Error;
executed (the execution status of this line is deduced): state = Error;
-
518 png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,0,0,0);
executed (the execution status of this line is deduced): png_ptr = png_create_read_struct("1.2.44",0,0,0);
-
519 if (!png_ptr)
partially evaluated: !png_ptr
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:440
0-440
520 return false;
never executed: return false;
0
521 -
522 png_set_error_fn(png_ptr, 0, 0, qt_png_warning);
executed (the execution status of this line is deduced): png_set_error_fn(png_ptr, 0, 0, qt_png_warning);
-
523 -
524 info_ptr = png_create_info_struct(png_ptr);
executed (the execution status of this line is deduced): info_ptr = png_create_info_struct(png_ptr);
-
525 if (!info_ptr) {
partially evaluated: !info_ptr
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:440
0-440
526 png_destroy_read_struct(&png_ptr, 0, 0);
never executed (the execution status of this line is deduced): png_destroy_read_struct(&png_ptr, 0, 0);
-
527 png_ptr = 0;
never executed (the execution status of this line is deduced): png_ptr = 0;
-
528 return false;
never executed: return false;
0
529 } -
530 -
531 end_info = png_create_info_struct(png_ptr);
executed (the execution status of this line is deduced): end_info = png_create_info_struct(png_ptr);
-
532 if (!end_info) {
partially evaluated: !end_info
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:440
0-440
533 png_destroy_read_struct(&png_ptr, &info_ptr, 0);
never executed (the execution status of this line is deduced): png_destroy_read_struct(&png_ptr, &info_ptr, 0);
-
534 png_ptr = 0;
never executed (the execution status of this line is deduced): png_ptr = 0;
-
535 return false;
never executed: return false;
0
536 } -
537 -
538 if (setjmp(png_jmpbuf(png_ptr))) {
partially evaluated: _setjmp (((png_ptr)->jmpbuf))
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:440
0-440
539 png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
never executed (the execution status of this line is deduced): png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
-
540 png_ptr = 0;
never executed (the execution status of this line is deduced): png_ptr = 0;
-
541 return false;
never executed: return false;
0
542 } -
543 -
544 png_set_read_fn(png_ptr, this, iod_read_fn);
executed (the execution status of this line is deduced): png_set_read_fn(png_ptr, this, iod_read_fn);
-
545 png_read_info(png_ptr, info_ptr);
executed (the execution status of this line is deduced): png_read_info(png_ptr, info_ptr);
-
546 -
547 readPngTexts(info_ptr);
executed (the execution status of this line is deduced): readPngTexts(info_ptr);
-
548 -
549 state = ReadHeader;
executed (the execution status of this line is deduced): state = ReadHeader;
-
550 return true;
executed: return true;
Execution Count:440
440
551} -
552 -
553 -
554bool Q_INTERNAL_WIN_NO_THROW QPngHandlerPrivate::readPngImage(QImage *outImage) -
555{ -
556 if (state == Error)
partially evaluated: state == Error
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:430
0-430
557 return false;
never executed: return false;
0
558 -
559 if (state == Ready && !readPngHeader()) {
evaluated: state == Ready
TRUEFALSE
yes
Evaluation Count:428
yes
Evaluation Count:2
partially evaluated: !readPngHeader()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:428
0-428
560 state = Error;
never executed (the execution status of this line is deduced): state = Error;
-
561 return false;
never executed: return false;
0
562 } -
563 -
564 if (setjmp(png_jmpbuf(png_ptr))) {
evaluated: _setjmp (((png_ptr)->jmpbuf))
TRUEFALSE
yes
Evaluation Count:13
yes
Evaluation Count:430
13-430
565 png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
executed (the execution status of this line is deduced): png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
-
566 png_ptr = 0;
executed (the execution status of this line is deduced): png_ptr = 0;
-
567 amp.deallocate();
executed (the execution status of this line is deduced): amp.deallocate();
-
568 state = Error;
executed (the execution status of this line is deduced): state = Error;
-
569 return false;
executed: return false;
Execution Count:13
13
570 } -
571 -
572 bool doScaledRead = false;
executed (the execution status of this line is deduced): bool doScaledRead = false;
-
573 setup_qt(*outImage, png_ptr, info_ptr, scaledSize, &doScaledRead, gamma);
executed (the execution status of this line is deduced): setup_qt(*outImage, png_ptr, info_ptr, scaledSize, &doScaledRead, gamma);
-
574 -
575 if (outImage->isNull()) {
partially evaluated: outImage->isNull()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:430
0-430
576 png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
never executed (the execution status of this line is deduced): png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
-
577 png_ptr = 0;
never executed (the execution status of this line is deduced): png_ptr = 0;
-
578 amp.deallocate();
never executed (the execution status of this line is deduced): amp.deallocate();
-
579 state = Error;
never executed (the execution status of this line is deduced): state = Error;
-
580 return false;
never executed: return false;
0
581 } -
582 -
583 if (doScaledRead) {
partially evaluated: doScaledRead
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:430
0-430
584 read_image_scaled(outImage, png_ptr, info_ptr, amp, scaledSize);
never executed (the execution status of this line is deduced): read_image_scaled(outImage, png_ptr, info_ptr, amp, scaledSize);
-
585 } else {
never executed: }
0
586 png_uint_32 width;
executed (the execution status of this line is deduced): png_uint_32 width;
-
587 png_uint_32 height;
executed (the execution status of this line is deduced): png_uint_32 height;
-
588 int bit_depth;
executed (the execution status of this line is deduced): int bit_depth;
-
589 int color_type;
executed (the execution status of this line is deduced): int color_type;
-
590 png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, 0, 0, 0);
executed (the execution status of this line is deduced): png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, 0, 0, 0);
-
591 uchar *data = outImage->bits();
executed (the execution status of this line is deduced): uchar *data = outImage->bits();
-
592 int bpl = outImage->bytesPerLine();
executed (the execution status of this line is deduced): int bpl = outImage->bytesPerLine();
-
593 amp.row_pointers = new png_bytep[height];
executed (the execution status of this line is deduced): amp.row_pointers = new png_bytep[height];
-
594 -
595 for (uint y = 0; y < height; y++)
evaluated: y < height
TRUEFALSE
yes
Evaluation Count:33768
yes
Evaluation Count:430
430-33768
596 amp.row_pointers[y] = data + y * bpl;
executed: amp.row_pointers[y] = data + y * bpl;
Execution Count:33768
33768
597 -
598 png_read_image(png_ptr, amp.row_pointers);
executed (the execution status of this line is deduced): png_read_image(png_ptr, amp.row_pointers);
-
599 amp.deallocate();
executed (the execution status of this line is deduced): amp.deallocate();
-
600 -
601 outImage->setDotsPerMeterX(png_get_x_pixels_per_meter(png_ptr,info_ptr));
executed (the execution status of this line is deduced): outImage->setDotsPerMeterX(png_get_x_pixels_per_meter(png_ptr,info_ptr));
-
602 outImage->setDotsPerMeterY(png_get_y_pixels_per_meter(png_ptr,info_ptr));
executed (the execution status of this line is deduced): outImage->setDotsPerMeterY(png_get_y_pixels_per_meter(png_ptr,info_ptr));
-
603 -
604 // sanity check palette entries -
605 if (color_type == PNG_COLOR_TYPE_PALETTE && outImage->format() == QImage::Format_Indexed8) {
evaluated: color_type == (2 | 1)
TRUEFALSE
yes
Evaluation Count:75
yes
Evaluation Count:342
evaluated: outImage->format() == QImage::Format_Indexed8
TRUEFALSE
yes
Evaluation Count:58
yes
Evaluation Count:17
17-342
606 int color_table_size = outImage->colorCount();
executed (the execution status of this line is deduced): int color_table_size = outImage->colorCount();
-
607 for (int y=0; y<(int)height; ++y) {
evaluated: y<(int)height
TRUEFALSE
yes
Evaluation Count:2620
yes
Evaluation Count:58
58-2620
608 uchar *p = FAST_SCAN_LINE(data, bpl, y);
executed (the execution status of this line is deduced): uchar *p = (data + (y) * bpl);
-
609 uchar *end = p + width;
executed (the execution status of this line is deduced): uchar *end = p + width;
-
610 while (p < end) {
evaluated: p < end
TRUEFALSE
yes
Evaluation Count:335084
yes
Evaluation Count:2620
2620-335084
611 if (*p >= color_table_size)
partially evaluated: *p >= color_table_size
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:335084
0-335084
612 *p = 0;
never executed: *p = 0;
0
613 ++p;
executed (the execution status of this line is deduced): ++p;
-
614 }
executed: }
Execution Count:335084
335084
615 }
executed: }
Execution Count:2620
2620
616 }
executed: }
Execution Count:58
58
617 }
executed: }
Execution Count:417
417
618 -
619 state = ReadingEnd;
executed (the execution status of this line is deduced): state = ReadingEnd;
-
620 png_read_end(png_ptr, end_info);
executed (the execution status of this line is deduced): png_read_end(png_ptr, end_info);
-
621 -
622 readPngTexts(end_info);
executed (the execution status of this line is deduced): readPngTexts(end_info);
-
623 for (int i = 0; i < readTexts.size()-1; i+=2)
evaluated: i < readTexts.size()-1
TRUEFALSE
yes
Evaluation Count:126
yes
Evaluation Count:417
126-417
624 outImage->setText(readTexts.at(i), readTexts.at(i+1));
executed: outImage->setText(readTexts.at(i), readTexts.at(i+1));
Execution Count:126
126
625 -
626 png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
executed (the execution status of this line is deduced): png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
-
627 png_ptr = 0;
executed (the execution status of this line is deduced): png_ptr = 0;
-
628 amp.deallocate();
executed (the execution status of this line is deduced): amp.deallocate();
-
629 state = Ready;
executed (the execution status of this line is deduced): state = Ready;
-
630 -
631 if (scaledSize.isValid() && outImage->size() != scaledSize)
evaluated: scaledSize.isValid()
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:413
partially evaluated: outImage->size() != scaledSize
TRUEFALSE
yes
Evaluation Count:4
no
Evaluation Count:0
0-413
632 *outImage = outImage->scaled(scaledSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
executed: *outImage = outImage->scaled(scaledSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
Execution Count:4
4
633 -
634 return true;
executed: return true;
Execution Count:417
417
635} -
636 -
637QImage::Format QPngHandlerPrivate::readImageFormat() -
638{ -
639 QImage::Format format = QImage::Format_Invalid;
executed (the execution status of this line is deduced): QImage::Format format = QImage::Format_Invalid;
-
640 png_uint_32 width, height;
executed (the execution status of this line is deduced): png_uint_32 width, height;
-
641 int bit_depth, color_type;
executed (the execution status of this line is deduced): int bit_depth, color_type;
-
642 png_colorp palette;
executed (the execution status of this line is deduced): png_colorp palette;
-
643 int num_palette;
executed (the execution status of this line is deduced): int num_palette;
-
644 png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, 0, 0, 0);
executed (the execution status of this line is deduced): png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, 0, 0, 0);
-
645 if (color_type == PNG_COLOR_TYPE_GRAY) {
partially evaluated: color_type == 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
0-2
646 // Black & White or 8-bit grayscale -
647 if (bit_depth == 1 && png_get_channels(png_ptr, info_ptr) == 1) {
never evaluated: bit_depth == 1
never evaluated: png_get_channels(png_ptr, info_ptr) == 1
0
648 format = QImage::Format_Mono;
never executed (the execution status of this line is deduced): format = QImage::Format_Mono;
-
649 } else if (bit_depth == 16 && png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
never executed: }
never evaluated: bit_depth == 16
never evaluated: png_get_valid(png_ptr, info_ptr, 0x0010)
0
650 format = QImage::Format_ARGB32;
never executed (the execution status of this line is deduced): format = QImage::Format_ARGB32;
-
651 } else {
never executed: }
0
652 format = QImage::Format_Indexed8;
never executed (the execution status of this line is deduced): format = QImage::Format_Indexed8;
-
653 }
never executed: }
0
654 } else if (color_type == PNG_COLOR_TYPE_PALETTE
partially evaluated: color_type == (2 | 1)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
0-2
655 && png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette)
never evaluated: png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette)
0
656 && num_palette <= 256)
never evaluated: num_palette <= 256
0
657 { -
658 // 1-bit and 8-bit color -
659 if (bit_depth != 1)
never evaluated: bit_depth != 1
0
660 png_set_packing(png_ptr);
never executed: png_set_packing(png_ptr);
0
661 png_read_update_info(png_ptr, info_ptr);
never executed (the execution status of this line is deduced): png_read_update_info(png_ptr, info_ptr);
-
662 png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, 0, 0, 0);
never executed (the execution status of this line is deduced): png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, 0, 0, 0);
-
663 format = bit_depth == 1 ? QImage::Format_Mono : QImage::Format_Indexed8;
never evaluated: bit_depth == 1
0
664 } else {
never executed: }
0
665 // 32-bit -
666 if (bit_depth == 16)
partially evaluated: bit_depth == 16
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
0-2
667 png_set_strip_16(png_ptr);
never executed: png_set_strip_16(png_ptr);
0
668 -
669 format = QImage::Format_ARGB32;
executed (the execution status of this line is deduced): format = QImage::Format_ARGB32;
-
670 // Only add filler if no alpha, or we can get 5 channel data. -
671 if (!(color_type & PNG_COLOR_MASK_ALPHA)
evaluated: !(color_type & 4)
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:1
1
672 && !png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
partially evaluated: !png_get_valid(png_ptr, info_ptr, 0x0010)
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
0-1
673 // We want 4 bytes, but it isn't an alpha channel -
674 format = QImage::Format_RGB32;
executed (the execution status of this line is deduced): format = QImage::Format_RGB32;
-
675 }
executed: }
Execution Count:1
1
676 }
executed: }
Execution Count:2
2
677 -
678 return format;
executed: return format;
Execution Count:2
2
679} -
680 -
681QPNGImageWriter::QPNGImageWriter(QIODevice* iod) : -
682 dev(iod), -
683 frames_written(0), -
684 disposal(Unspecified), -
685 looping(-1), -
686 ms_delay(-1), -
687 gamma(0.0) -
688{ -
689}
executed: }
Execution Count:123
123
690 -
691QPNGImageWriter::~QPNGImageWriter() -
692{ -
693} -
694 -
695void QPNGImageWriter::setDisposalMethod(DisposalMethod dm) -
696{ -
697 disposal = dm;
never executed (the execution status of this line is deduced): disposal = dm;
-
698}
never executed: }
0
699 -
700void QPNGImageWriter::setLooping(int loops) -
701{ -
702 looping = loops;
never executed (the execution status of this line is deduced): looping = loops;
-
703}
never executed: }
0
704 -
705void QPNGImageWriter::setFrameDelay(int msecs) -
706{ -
707 ms_delay = msecs;
never executed (the execution status of this line is deduced): ms_delay = msecs;
-
708}
never executed: }
0
709 -
710void QPNGImageWriter::setGamma(float g) -
711{ -
712 gamma = g;
executed (the execution status of this line is deduced): gamma = g;
-
713}
executed: }
Execution Count:123
123
714 -
715 -
716static void set_text(const QImage &image, png_structp png_ptr, png_infop info_ptr, -
717 const QString &description) -
718{ -
719 QMap<QString, QString> text;
executed (the execution status of this line is deduced): QMap<QString, QString> text;
-
720 foreach (const QString &key, image.textKeys()) {
executed (the execution status of this line is deduced): for (QForeachContainer<__typeof__(image.textKeys())> _container_(image.textKeys()); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (const QString &key = *_container_.i;; __extension__ ({--_container_.brk; break;})) {
-
721 if (!key.isEmpty())
partially evaluated: !key.isEmpty()
TRUEFALSE
yes
Evaluation Count:29
no
Evaluation Count:0
0-29
722 text.insert(key, image.text(key));
executed: text.insert(key, image.text(key));
Execution Count:29
29
723 }
executed: }
Execution Count:29
29
724 foreach (const QString &pair, description.split(QLatin1String("\n\n"))) {
executed (the execution status of this line is deduced): for (QForeachContainer<__typeof__(description.split(QLatin1String("\n\n")))> _container_(description.split(QLatin1String("\n\n"))); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (const QString &pair = *_container_.i;; __extension__ ({--_container_.brk; break;})) {
-
725 int index = pair.indexOf(QLatin1Char(':'));
executed (the execution status of this line is deduced): int index = pair.indexOf(QLatin1Char(':'));
-
726 if (index >= 0 && pair.indexOf(QLatin1Char(' ')) < index) {
evaluated: index >= 0
TRUEFALSE
yes
Evaluation Count:12
yes
Evaluation Count:117
partially evaluated: pair.indexOf(QLatin1Char(' ')) < index
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:12
0-117
727 QString s = pair.simplified();
never executed (the execution status of this line is deduced): QString s = pair.simplified();
-
728 if (!s.isEmpty())
never evaluated: !s.isEmpty()
0
729 text.insert(QLatin1String("Description"), s);
never executed: text.insert(QLatin1String("Description"), s);
0
730 } else {
never executed: }
0
731 QString key = pair.left(index);
executed (the execution status of this line is deduced): QString key = pair.left(index);
-
732 if (!key.simplified().isEmpty())
evaluated: !key.simplified().isEmpty()
TRUEFALSE
yes
Evaluation Count:12
yes
Evaluation Count:117
12-117
733 text.insert(key, pair.mid(index + 2).simplified());
executed: text.insert(key, pair.mid(index + 2).simplified());
Execution Count:12
12
734 }
executed: }
Execution Count:129
129
735 } -
736 -
737 if (text.isEmpty())
evaluated: text.isEmpty()
TRUEFALSE
yes
Evaluation Count:100
yes
Evaluation Count:23
23-100
738 return;
executed: return;
Execution Count:100
100
739 -
740 png_textp text_ptr = new png_text[text.size()];
executed (the execution status of this line is deduced): png_textp text_ptr = new png_text[text.size()];
-
741 memset(text_ptr, 0, text.size() * sizeof(png_text));
executed (the execution status of this line is deduced): memset(text_ptr, 0, text.size() * sizeof(png_text));
-
742 -
743 QMap<QString, QString>::ConstIterator it = text.constBegin();
executed (the execution status of this line is deduced): QMap<QString, QString>::ConstIterator it = text.constBegin();
-
744 int i = 0;
executed (the execution status of this line is deduced): int i = 0;
-
745 while (it != text.constEnd()) {
evaluated: it != text.constEnd()
TRUEFALSE
yes
Evaluation Count:41
yes
Evaluation Count:23
23-41
746 text_ptr[i].key = qstrdup(it.key().left(79).toLatin1().constData());
executed (the execution status of this line is deduced): text_ptr[i].key = qstrdup(it.key().left(79).toLatin1().constData());
-
747 bool noCompress = (it.value().length() < 40);
executed (the execution status of this line is deduced): bool noCompress = (it.value().length() < 40);
-
748 -
749#ifdef PNG_iTXt_SUPPORTED -
750 bool needsItxt = false; -
751 foreach(const QChar c, it.value()) { -
752 uchar ch = c.cell(); -
753 if (c.row() || (ch < 0x20 && ch != '\n') || (ch > 0x7e && ch < 0xa0)) { -
754 needsItxt = true; -
755 break; -
756 } -
757 } -
758 -
759 if (needsItxt) { -
760 text_ptr[i].compression = noCompress ? PNG_ITXT_COMPRESSION_NONE : PNG_ITXT_COMPRESSION_zTXt; -
761 QByteArray value = it.value().toUtf8(); -
762 text_ptr[i].text = qstrdup(value.constData()); -
763 text_ptr[i].itxt_length = value.size(); -
764 text_ptr[i].lang = const_cast<char*>("UTF-8"); -
765 text_ptr[i].lang_key = qstrdup(it.key().toUtf8().constData()); -
766 } -
767 else -
768#endif -
769 { -
770 text_ptr[i].compression = noCompress ? PNG_TEXT_COMPRESSION_NONE : PNG_TEXT_COMPRESSION_zTXt;
evaluated: noCompress
TRUEFALSE
yes
Evaluation Count:37
yes
Evaluation Count:4
4-37
771 QByteArray value = it.value().toLatin1();
executed (the execution status of this line is deduced): QByteArray value = it.value().toLatin1();
-
772 text_ptr[i].text = qstrdup(value.constData());
executed (the execution status of this line is deduced): text_ptr[i].text = qstrdup(value.constData());
-
773 text_ptr[i].text_length = value.size();
executed (the execution status of this line is deduced): text_ptr[i].text_length = value.size();
-
774 } -
775 ++i;
executed (the execution status of this line is deduced): ++i;
-
776 ++it;
executed (the execution status of this line is deduced): ++it;
-
777 }
executed: }
Execution Count:41
41
778 -
779 png_set_text(png_ptr, info_ptr, text_ptr, i);
executed (the execution status of this line is deduced): png_set_text(png_ptr, info_ptr, text_ptr, i);
-
780 for (i = 0; i < text.size(); ++i) {
evaluated: i < text.size()
TRUEFALSE
yes
Evaluation Count:41
yes
Evaluation Count:23
23-41
781 delete [] text_ptr[i].key;
executed (the execution status of this line is deduced): delete [] text_ptr[i].key;
-
782 delete [] text_ptr[i].text;
executed (the execution status of this line is deduced): delete [] text_ptr[i].text;
-
783#ifdef PNG_iTXt_SUPPORTED -
784 delete [] text_ptr[i].lang_key; -
785#endif -
786 }
executed: }
Execution Count:41
41
787 delete [] text_ptr;
executed (the execution status of this line is deduced): delete [] text_ptr;
-
788}
executed: }
Execution Count:23
23
789 -
790bool QPNGImageWriter::writeImage(const QImage& image, int off_x, int off_y) -
791{ -
792 return writeImage(image, -1, QString(), off_x, off_y);
never executed: return writeImage(image, -1, QString(), off_x, off_y);
0
793} -
794 -
795bool Q_INTERNAL_WIN_NO_THROW QPNGImageWriter::writeImage(const QImage& image, volatile int quality_in, const QString &description, -
796 int off_x_in, int off_y_in) -
797{ -
798 QPoint offset = image.offset();
executed (the execution status of this line is deduced): QPoint offset = image.offset();
-
799 int off_x = off_x_in + offset.x();
executed (the execution status of this line is deduced): int off_x = off_x_in + offset.x();
-
800 int off_y = off_y_in + offset.y();
executed (the execution status of this line is deduced): int off_y = off_y_in + offset.y();
-
801 -
802 png_structp png_ptr;
executed (the execution status of this line is deduced): png_structp png_ptr;
-
803 png_infop info_ptr;
executed (the execution status of this line is deduced): png_infop info_ptr;
-
804 -
805 png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,0,0,0);
executed (the execution status of this line is deduced): png_ptr = png_create_write_struct("1.2.44",0,0,0);
-
806 if (!png_ptr) {
partially evaluated: !png_ptr
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:123
0-123
807 return false;
never executed: return false;
0
808 } -
809 -
810 png_set_error_fn(png_ptr, 0, 0, qt_png_warning);
executed (the execution status of this line is deduced): png_set_error_fn(png_ptr, 0, 0, qt_png_warning);
-
811 -
812 info_ptr = png_create_info_struct(png_ptr);
executed (the execution status of this line is deduced): info_ptr = png_create_info_struct(png_ptr);
-
813 if (!info_ptr) {
partially evaluated: !info_ptr
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:123
0-123
814 png_destroy_write_struct(&png_ptr, 0);
never executed (the execution status of this line is deduced): png_destroy_write_struct(&png_ptr, 0);
-
815 return false;
never executed: return false;
0
816 } -
817 -
818 if (setjmp(png_jmpbuf(png_ptr))) {
partially evaluated: _setjmp (((png_ptr)->jmpbuf))
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:123
0-123
819 png_destroy_write_struct(&png_ptr, &info_ptr);
never executed (the execution status of this line is deduced): png_destroy_write_struct(&png_ptr, &info_ptr);
-
820 return false;
never executed: return false;
0
821 } -
822 -
823 int quality = quality_in;
executed (the execution status of this line is deduced): int quality = quality_in;
-
824 if (quality >= 0) {
partially evaluated: quality >= 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:123
0-123
825 if (quality > 9) {
never evaluated: quality > 9
0
826 qWarning("PNG: Quality %d out of range", quality);
never executed (the execution status of this line is deduced): QMessageLogger("image/qpnghandler.cpp", 826, __PRETTY_FUNCTION__).warning("PNG: Quality %d out of range", quality);
-
827 quality = 9;
never executed (the execution status of this line is deduced): quality = 9;
-
828 }
never executed: }
0
829 png_set_compression_level(png_ptr, quality);
never executed (the execution status of this line is deduced): png_set_compression_level(png_ptr, quality);
-
830 }
never executed: }
0
831 -
832 png_set_write_fn(png_ptr, (void*)this, qpiw_write_fn, qpiw_flush_fn);
executed (the execution status of this line is deduced): png_set_write_fn(png_ptr, (void*)this, qpiw_write_fn, qpiw_flush_fn);
-
833 -
834 -
835 int color_type = 0;
executed (the execution status of this line is deduced): int color_type = 0;
-
836 if (image.colorCount()) {
evaluated: image.colorCount()
TRUEFALSE
yes
Evaluation Count:25
yes
Evaluation Count:98
25-98
837 if (image.isGrayscale())
partially evaluated: image.isGrayscale()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:25
0-25
838 color_type = PNG_COLOR_TYPE_GRAY;
never executed: color_type = 0;
0
839 else -
840 color_type = PNG_COLOR_TYPE_PALETTE;
executed: color_type = (2 | 1);
Execution Count:25
25
841 } -
842 else if (image.hasAlphaChannel())
evaluated: image.hasAlphaChannel()
TRUEFALSE
yes
Evaluation Count:79
yes
Evaluation Count:19
19-79
843 color_type = PNG_COLOR_TYPE_RGB_ALPHA;
executed: color_type = (2 | 4);
Execution Count:79
79
844 else -
845 color_type = PNG_COLOR_TYPE_RGB;
executed: color_type = (2);
Execution Count:19
19
846 -
847 png_set_IHDR(png_ptr, info_ptr, image.width(), image.height(),
executed (the execution status of this line is deduced): png_set_IHDR(png_ptr, info_ptr, image.width(), image.height(),
-
848 image.depth() == 1 ? 1 : 8, // per channel
executed (the execution status of this line is deduced): image.depth() == 1 ? 1 : 8,
-
849 color_type, 0, 0, 0); // sets #channels
executed (the execution status of this line is deduced): color_type, 0, 0, 0);
-
850 -
851 if (gamma != 0.0) {
partially evaluated: gamma != 0.0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:123
0-123
852 png_set_gAMA(png_ptr, info_ptr, 1.0/gamma);
never executed (the execution status of this line is deduced): png_set_gAMA(png_ptr, info_ptr, 1.0/gamma);
-
853 }
never executed: }
0
854 -
855 if (image.format() == QImage::Format_MonoLSB)
evaluated: image.format() == QImage::Format_MonoLSB
TRUEFALSE
yes
Evaluation Count:15
yes
Evaluation Count:108
15-108
856 png_set_packswap(png_ptr);
executed: png_set_packswap(png_ptr);
Execution Count:15
15
857 -
858 if (color_type == PNG_COLOR_TYPE_PALETTE) {
evaluated: color_type == (2 | 1)
TRUEFALSE
yes
Evaluation Count:25
yes
Evaluation Count:98
25-98
859 // Paletted -
860 int num_palette = qMin(256, image.colorCount());
executed (the execution status of this line is deduced): int num_palette = qMin(256, image.colorCount());
-
861 png_color palette[256];
executed (the execution status of this line is deduced): png_color palette[256];
-
862 png_byte trans[256];
executed (the execution status of this line is deduced): png_byte trans[256];
-
863 int num_trans = 0;
executed (the execution status of this line is deduced): int num_trans = 0;
-
864 for (int i=0; i<num_palette; i++) {
evaluated: i<num_palette
TRUEFALSE
yes
Evaluation Count:582
yes
Evaluation Count:25
25-582
865 QRgb rgba=image.color(i);
executed (the execution status of this line is deduced): QRgb rgba=image.color(i);
-
866 palette[i].red = qRed(rgba);
executed (the execution status of this line is deduced): palette[i].red = qRed(rgba);
-
867 palette[i].green = qGreen(rgba);
executed (the execution status of this line is deduced): palette[i].green = qGreen(rgba);
-
868 palette[i].blue = qBlue(rgba);
executed (the execution status of this line is deduced): palette[i].blue = qBlue(rgba);
-
869 trans[i] = qAlpha(rgba);
executed (the execution status of this line is deduced): trans[i] = qAlpha(rgba);
-
870 if (trans[i] < 255) {
evaluated: trans[i] < 255
TRUEFALSE
yes
Evaluation Count:84
yes
Evaluation Count:498
84-498
871 num_trans = i+1;
executed (the execution status of this line is deduced): num_trans = i+1;
-
872 }
executed: }
Execution Count:84
84
873 }
executed: }
Execution Count:582
582
874 png_set_PLTE(png_ptr, info_ptr, palette, num_palette);
executed (the execution status of this line is deduced): png_set_PLTE(png_ptr, info_ptr, palette, num_palette);
-
875 -
876 if (num_trans) {
evaluated: num_trans
TRUEFALSE
yes
Evaluation Count:8
yes
Evaluation Count:17
8-17
877 png_set_tRNS(png_ptr, info_ptr, trans, num_trans, 0);
executed (the execution status of this line is deduced): png_set_tRNS(png_ptr, info_ptr, trans, num_trans, 0);
-
878 }
executed: }
Execution Count:8
8
879 }
executed: }
Execution Count:25
25
880 -
881 // Swap ARGB to RGBA (normal PNG format) before saving on -
882 // BigEndian machines -
883 if (QSysInfo::ByteOrder == QSysInfo::BigEndian) {
partially evaluated: QSysInfo::ByteOrder == QSysInfo::BigEndian
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:123
0-123
884 png_set_swap_alpha(png_ptr);
never executed (the execution status of this line is deduced): png_set_swap_alpha(png_ptr);
-
885 }
never executed: }
0
886 -
887 // Qt==ARGB==Big(ARGB)==Little(BGRA). But RGB888 is RGB regardless -
888 if (QSysInfo::ByteOrder == QSysInfo::LittleEndian
partially evaluated: QSysInfo::ByteOrder == QSysInfo::LittleEndian
TRUEFALSE
yes
Evaluation Count:123
no
Evaluation Count:0
0-123
889 && image.format() != QImage::Format_RGB888) {
evaluated: image.format() != QImage::Format_RGB888
TRUEFALSE
yes
Evaluation Count:121
yes
Evaluation Count:2
2-121
890 png_set_bgr(png_ptr);
executed (the execution status of this line is deduced): png_set_bgr(png_ptr);
-
891 }
executed: }
Execution Count:121
121
892 -
893 if (off_x || off_y) {
partially evaluated: off_x
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:123
partially evaluated: off_y
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:123
0-123
894 png_set_oFFs(png_ptr, info_ptr, off_x, off_y, PNG_OFFSET_PIXEL);
never executed (the execution status of this line is deduced): png_set_oFFs(png_ptr, info_ptr, off_x, off_y, 0);
-
895 }
never executed: }
0
896 -
897 if (frames_written > 0)
partially evaluated: frames_written > 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:123
0-123
898 png_set_sig_bytes(png_ptr, 8);
never executed: png_set_sig_bytes(png_ptr, 8);
0
899 -
900 if (image.dotsPerMeterX() > 0 || image.dotsPerMeterY() > 0) {
partially evaluated: image.dotsPerMeterX() > 0
TRUEFALSE
yes
Evaluation Count:123
no
Evaluation Count:0
never evaluated: image.dotsPerMeterY() > 0
0-123
901 png_set_pHYs(png_ptr, info_ptr,
executed (the execution status of this line is deduced): png_set_pHYs(png_ptr, info_ptr,
-
902 image.dotsPerMeterX(), image.dotsPerMeterY(),
executed (the execution status of this line is deduced): image.dotsPerMeterX(), image.dotsPerMeterY(),
-
903 PNG_RESOLUTION_METER);
executed (the execution status of this line is deduced): 1);
-
904 }
executed: }
Execution Count:123
123
905 -
906 set_text(image, png_ptr, info_ptr, description);
executed (the execution status of this line is deduced): set_text(image, png_ptr, info_ptr, description);
-
907 -
908 png_write_info(png_ptr, info_ptr);
executed (the execution status of this line is deduced): png_write_info(png_ptr, info_ptr);
-
909 -
910 if (image.depth() != 1)
evaluated: image.depth() != 1
TRUEFALSE
yes
Evaluation Count:106
yes
Evaluation Count:17
17-106
911 png_set_packing(png_ptr);
executed: png_set_packing(png_ptr);
Execution Count:106
106
912 -
913 if (color_type == PNG_COLOR_TYPE_RGB && image.format() != QImage::Format_RGB888)
evaluated: color_type == (2)
TRUEFALSE
yes
Evaluation Count:19
yes
Evaluation Count:104
evaluated: image.format() != QImage::Format_RGB888
TRUEFALSE
yes
Evaluation Count:17
yes
Evaluation Count:2
2-104
914 png_set_filler(png_ptr, 0,
executed: png_set_filler(png_ptr, 0, QSysInfo::ByteOrder == QSysInfo::BigEndian ? 0 : 1);
Execution Count:17
17
915 QSysInfo::ByteOrder == QSysInfo::BigEndian ?
executed: png_set_filler(png_ptr, 0, QSysInfo::ByteOrder == QSysInfo::BigEndian ? 0 : 1);
Execution Count:17
17
916 PNG_FILLER_BEFORE : PNG_FILLER_AFTER);
executed: png_set_filler(png_ptr, 0, QSysInfo::ByteOrder == QSysInfo::BigEndian ? 0 : 1);
Execution Count:17
17
917 -
918 if (looping >= 0 && frames_written == 0) {
partially evaluated: looping >= 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:123
never evaluated: frames_written == 0
0-123
919 uchar data[13] = "NETSCAPE2.0";
never executed (the execution status of this line is deduced): uchar data[13] = "NETSCAPE2.0";
-
920 // 0123456789aBC -
921 data[0xB] = looping%0x100;
never executed (the execution status of this line is deduced): data[0xB] = looping%0x100;
-
922 data[0xC] = looping/0x100;
never executed (the execution status of this line is deduced): data[0xC] = looping/0x100;
-
923 png_write_chunk(png_ptr, (png_byte*)"gIFx", data, 13);
never executed (the execution status of this line is deduced): png_write_chunk(png_ptr, (png_byte*)"gIFx", data, 13);
-
924 }
never executed: }
0
925 if (ms_delay >= 0 || disposal!=Unspecified) {
partially evaluated: ms_delay >= 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:123
partially evaluated: disposal!=Unspecified
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:123
0-123
926 uchar data[4];
never executed (the execution status of this line is deduced): uchar data[4];
-
927 data[0] = disposal;
never executed (the execution status of this line is deduced): data[0] = disposal;
-
928 data[1] = 0;
never executed (the execution status of this line is deduced): data[1] = 0;
-
929 data[2] = (ms_delay/10)/0x100; // hundredths
never executed (the execution status of this line is deduced): data[2] = (ms_delay/10)/0x100;
-
930 data[3] = (ms_delay/10)%0x100;
never executed (the execution status of this line is deduced): data[3] = (ms_delay/10)%0x100;
-
931 png_write_chunk(png_ptr, (png_byte*)"gIFg", data, 4);
never executed (the execution status of this line is deduced): png_write_chunk(png_ptr, (png_byte*)"gIFg", data, 4);
-
932 }
never executed: }
0
933 -
934 int height = image.height();
executed (the execution status of this line is deduced): int height = image.height();
-
935 int width = image.width();
executed (the execution status of this line is deduced): int width = image.width();
-
936 switch (image.format()) { -
937 case QImage::Format_Mono: -
938 case QImage::Format_MonoLSB: -
939 case QImage::Format_Indexed8: -
940 case QImage::Format_RGB32: -
941 case QImage::Format_ARGB32: -
942 case QImage::Format_RGB888: -
943 { -
944 png_bytep* row_pointers = new png_bytep[height];
executed (the execution status of this line is deduced): png_bytep* row_pointers = new png_bytep[height];
-
945 for (int y=0; y<height; y++)
evaluated: y<height
TRUEFALSE
yes
Evaluation Count:5384
yes
Evaluation Count:60
60-5384
946 row_pointers[y] = (png_bytep)image.constScanLine(y);
executed: row_pointers[y] = (png_bytep)image.constScanLine(y);
Execution Count:5384
5384
947 png_write_image(png_ptr, row_pointers);
executed (the execution status of this line is deduced): png_write_image(png_ptr, row_pointers);
-
948 delete [] row_pointers;
executed (the execution status of this line is deduced): delete [] row_pointers;
-
949 } -
950 break;
executed: break;
Execution Count:60
60
951 default: -
952 { -
953 QImage::Format fmt = image.hasAlphaChannel() ? QImage::Format_ARGB32 : QImage::Format_RGB32;
evaluated: image.hasAlphaChannel()
TRUEFALSE
yes
Evaluation Count:55
yes
Evaluation Count:8
8-55
954 QImage row;
executed (the execution status of this line is deduced): QImage row;
-
955 png_bytep row_pointers[1];
executed (the execution status of this line is deduced): png_bytep row_pointers[1];
-
956 for (int y=0; y<height; y++) {
evaluated: y<height
TRUEFALSE
yes
Evaluation Count:3913
yes
Evaluation Count:63
63-3913
957 row = image.copy(0, y, width, 1).convertToFormat(fmt);
executed (the execution status of this line is deduced): row = image.copy(0, y, width, 1).convertToFormat(fmt);
-
958 row_pointers[0] = png_bytep(row.constScanLine(0));
executed (the execution status of this line is deduced): row_pointers[0] = png_bytep(row.constScanLine(0));
-
959 png_write_rows(png_ptr, row_pointers, 1);
executed (the execution status of this line is deduced): png_write_rows(png_ptr, row_pointers, 1);
-
960 }
executed: }
Execution Count:3913
3913
961 } -
962 break;
executed: break;
Execution Count:63
63
963 } -
964 -
965 png_write_end(png_ptr, info_ptr);
executed (the execution status of this line is deduced): png_write_end(png_ptr, info_ptr);
-
966 frames_written++;
executed (the execution status of this line is deduced): frames_written++;
-
967 -
968 png_destroy_write_struct(&png_ptr, &info_ptr);
executed (the execution status of this line is deduced): png_destroy_write_struct(&png_ptr, &info_ptr);
-
969 -
970 return true;
executed: return true;
Execution Count:123
123
971} -
972 -
973static bool write_png_image(const QImage &image, QIODevice *device, -
974 int quality, float gamma, const QString &description) -
975{ -
976 QPNGImageWriter writer(device);
executed (the execution status of this line is deduced): QPNGImageWriter writer(device);
-
977 if (quality >= 0) {
partially evaluated: quality >= 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:123
0-123
978 quality = qMin(quality, 100);
never executed (the execution status of this line is deduced): quality = qMin(quality, 100);
-
979 quality = (100-quality) * 9 / 91; // map [0,100] -> [9,0]
never executed (the execution status of this line is deduced): quality = (100-quality) * 9 / 91;
-
980 }
never executed: }
0
981 writer.setGamma(gamma);
executed (the execution status of this line is deduced): writer.setGamma(gamma);
-
982 return writer.writeImage(image, quality, description);
executed: return writer.writeImage(image, quality, description);
Execution Count:123
123
983} -
984 -
985QPngHandler::QPngHandler() -
986 : d(new QPngHandlerPrivate(this)) -
987{ -
988}
executed: }
Execution Count:577
577
989 -
990QPngHandler::~QPngHandler() -
991{ -
992 if (d->png_ptr)
evaluated: d->png_ptr
TRUEFALSE
yes
Evaluation Count:10
yes
Evaluation Count:567
10-567
993 png_destroy_read_struct(&d->png_ptr, &d->info_ptr, &d->end_info);
executed: png_destroy_read_struct(&d->png_ptr, &d->info_ptr, &d->end_info);
Execution Count:10
10
994 delete d;
executed (the execution status of this line is deduced): delete d;
-
995}
executed: }
Execution Count:577
577
996 -
997bool QPngHandler::canRead() const -
998{ -
999 if (d->state == QPngHandlerPrivate::Ready && !canRead(device()))
evaluated: d->state == QPngHandlerPrivate::Ready
TRUEFALSE
yes
Evaluation Count:469
yes
Evaluation Count:6
evaluated: !canRead(device())
TRUEFALSE
yes
Evaluation Count:8
yes
Evaluation Count:461
6-469
1000 return false;
executed: return false;
Execution Count:8
8
1001 -
1002 if (d->state != QPngHandlerPrivate::Error) {
partially evaluated: d->state != QPngHandlerPrivate::Error
TRUEFALSE
yes
Evaluation Count:467
no
Evaluation Count:0
0-467
1003 setFormat("png");
executed (the execution status of this line is deduced): setFormat("png");
-
1004 return true;
executed: return true;
Execution Count:467
467
1005 } -
1006 -
1007 return false;
never executed: return false;
0
1008} -
1009 -
1010bool QPngHandler::canRead(QIODevice *device) -
1011{ -
1012 if (!device) {
partially evaluated: !device
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:688
0-688
1013 qWarning("QPngHandler::canRead() called with no device");
never executed (the execution status of this line is deduced): QMessageLogger("image/qpnghandler.cpp", 1013, __PRETTY_FUNCTION__).warning("QPngHandler::canRead() called with no device");
-
1014 return false;
never executed: return false;
0
1015 } -
1016 -
1017 return device->peek(8) == "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A";
executed: return device->peek(8) == "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A";
Execution Count:688
688
1018} -
1019 -
1020bool QPngHandler::read(QImage *image) -
1021{ -
1022 if (!canRead())
evaluated: !canRead()
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:430
2-430
1023 return false;
executed: return false;
Execution Count:2
2
1024 return d->readPngImage(image);
executed: return d->readPngImage(image);
Execution Count:430
430
1025} -
1026 -
1027bool QPngHandler::write(const QImage &image) -
1028{ -
1029 return write_png_image(image, device(), d->quality, d->gamma, d->description);
executed: return write_png_image(image, device(), d->quality, d->gamma, d->description);
Execution Count:123
123
1030} -
1031 -
1032bool QPngHandler::supportsOption(ImageOption option) const -
1033{ -
1034 return option == Gamma
executed: return option == Gamma || option == Description || option == ImageFormat || option == Quality || option == Size || option == ScaledSize;
Execution Count:3403
3403
1035 || option == Description
executed: return option == Gamma || option == Description || option == ImageFormat || option == Quality || option == Size || option == ScaledSize;
Execution Count:3403
3403
1036 || option == ImageFormat
executed: return option == Gamma || option == Description || option == ImageFormat || option == Quality || option == Size || option == ScaledSize;
Execution Count:3403
3403
1037 || option == Quality
executed: return option == Gamma || option == Description || option == ImageFormat || option == Quality || option == Size || option == ScaledSize;
Execution Count:3403
3403
1038 || option == Size
executed: return option == Gamma || option == Description || option == ImageFormat || option == Quality || option == Size || option == ScaledSize;
Execution Count:3403
3403
1039 || option == ScaledSize;
executed: return option == Gamma || option == Description || option == ImageFormat || option == Quality || option == Size || option == ScaledSize;
Execution Count:3403
3403
1040} -
1041 -
1042QVariant QPngHandler::option(ImageOption option) const -
1043{ -
1044 if (d->state == QPngHandlerPrivate::Error)
partially evaluated: d->state == QPngHandlerPrivate::Error
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:12
0-12
1045 return QVariant();
never executed: return QVariant();
0
1046 if (d->state == QPngHandlerPrivate::Ready && !d->readPngHeader())
partially evaluated: d->state == QPngHandlerPrivate::Ready
TRUEFALSE
yes
Evaluation Count:12
no
Evaluation Count:0
partially evaluated: !d->readPngHeader()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:12
0-12
1047 return QVariant();
never executed: return QVariant();
0
1048 -
1049 if (option == Gamma)
partially evaluated: option == Gamma
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:12
0-12
1050 return d->gamma;
never executed: return d->gamma;
0
1051 else if (option == Quality)
partially evaluated: option == Quality
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:12
0-12
1052 return d->quality;
never executed: return d->quality;
0
1053 else if (option == Description)
evaluated: option == Description
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:6
6
1054 return d->description;
executed: return d->description;
Execution Count:6
6
1055 else if (option == Size)
evaluated: option == Size
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:2
2-4
1056 return QSize(png_get_image_width(d->png_ptr, d->info_ptr),
executed: return QSize(png_get_image_width(d->png_ptr, d->info_ptr), png_get_image_height(d->png_ptr, d->info_ptr));
Execution Count:4
4
1057 png_get_image_height(d->png_ptr, d->info_ptr));
executed: return QSize(png_get_image_width(d->png_ptr, d->info_ptr), png_get_image_height(d->png_ptr, d->info_ptr));
Execution Count:4
4
1058 else if (option == ScaledSize)
partially evaluated: option == ScaledSize
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
0-2
1059 return d->scaledSize;
never executed: return d->scaledSize;
0
1060 else if (option == ImageFormat)
partially evaluated: option == ImageFormat
TRUEFALSE
yes
Evaluation Count:2
no
Evaluation Count:0
0-2
1061 return d->readImageFormat();
executed: return d->readImageFormat();
Execution Count:2
2
1062 return QVariant();
never executed: return QVariant();
0
1063} -
1064 -
1065void QPngHandler::setOption(ImageOption option, const QVariant &value) -
1066{ -
1067 if (option == Gamma)
evaluated: option == Gamma
TRUEFALSE
yes
Evaluation Count:123
yes
Evaluation Count:565
123-565
1068 d->gamma = value.toFloat();
executed: d->gamma = value.toFloat();
Execution Count:123
123
1069 else if (option == Quality)
evaluated: option == Quality
TRUEFALSE
yes
Evaluation Count:555
yes
Evaluation Count:10
10-555
1070 d->quality = value.toInt();
executed: d->quality = value.toInt();
Execution Count:555
555
1071 else if (option == Description)
evaluated: option == Description
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:4
4-6
1072 d->description = value.toString();
executed: d->description = value.toString();
Execution Count:6
6
1073 else if (option == ScaledSize)
partially evaluated: option == ScaledSize
TRUEFALSE
yes
Evaluation Count:4
no
Evaluation Count:0
0-4
1074 d->scaledSize = value.toSize();
executed: d->scaledSize = value.toSize();
Execution Count:4
4
1075} -
1076 -
1077QByteArray QPngHandler::name() const -
1078{ -
1079 return "png";
never executed: return "png";
0
1080} -
1081 -
1082QT_END_NAMESPACE -
1083 -
1084#endif // QT_NO_IMAGEFORMAT_PNG -
1085 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial