image/qpnghandler.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3 -
4 -
5 -
6 -
7 -
8 -
9class QPngHandlerPrivate -
10{ -
11public: -
12 enum State { -
13 Ready, -
14 ReadHeader, -
15 ReadingEnd, -
16 Error -
17 }; -
18 -
19 QPngHandlerPrivate(QPngHandler *qq) -
20 : gamma(0.0), quality(2), png_ptr(0), info_ptr(0), end_info(0), state(Ready), q(qq) -
21 { }
executed: }
Execution Count:577
577
22 -
23 float gamma; -
24 int quality; -
25 QString description; -
26 QSize scaledSize; -
27 QStringList readTexts; -
28 -
29 png_struct *png_ptr; -
30 png_info *info_ptr; -
31 png_info *end_info; -
32 -
33 bool readPngHeader(); -
34 bool readPngImage(QImage *image); -
35 void readPngTexts(png_info *info); -
36 -
37 QImage::Format readImageFormat(); -
38 -
39 struct AllocatedMemoryPointers { -
40 AllocatedMemoryPointers() -
41 : row_pointers(0), accRow(0), inRow(0), outRow(0) -
42 { }
executed: }
Execution Count:577
577
43 void deallocate() -
44 { -
45 delete [] row_pointers; -
46 row_pointers = 0; -
47 delete [] accRow; -
48 accRow = 0; -
49 delete [] inRow; -
50 inRow = 0; -
51 delete [] outRow; -
52 outRow = 0; -
53 }
executed: }
Execution Count:847
847
54 -
55 png_byte **row_pointers; -
56 quint32 *accRow; -
57 png_byte *inRow; -
58 uchar *outRow; -
59 }; -
60 -
61 AllocatedMemoryPointers amp; -
62 -
63 State state; -
64 -
65 QPngHandler *q; -
66}; -
67 -
68 -
69 -
70extern "C" { -
71 -
72 -
73class QPNGImageWriter { -
74public: -
75 explicit QPNGImageWriter(QIODevice*); -
76 ~QPNGImageWriter(); -
77 -
78 enum DisposalMethod { Unspecified, NoDisposal, RestoreBackground, RestoreImage }; -
79 void setDisposalMethod(DisposalMethod); -
80 void setLooping(int loops=0); -
81 void setFrameDelay(int msecs); -
82 void setGamma(float); -
83 -
84 bool writeImage(const QImage& img, int x, int y); -
85 bool writeImage(const QImage& img, volatile int quality, const QString &description, int x, int y); -
86 bool writeImage(const QImage& img) -
87 { return writeImage(img, 0, 0); }
never executed: return writeImage(img, 0, 0);
0
88 bool writeImage(const QImage& img, int quality, const QString &description) -
89 { return writeImage(img, quality, description, 0, 0); }
executed: return writeImage(img, quality, description, 0, 0);
Execution Count:123
123
90 -
91 QIODevice* device() { return dev; }
executed: return dev;
Execution Count:2489
2489
92 -
93private: -
94 QIODevice* dev; -
95 int frames_written; -
96 DisposalMethod disposal; -
97 int looping; -
98 int ms_delay; -
99 float gamma; -
100}; -
101 -
102static -
103void iod_read_fn(png_structp png_ptr, png_bytep data, png_size_t length) -
104{ -
105 QPngHandlerPrivate *d = (QPngHandlerPrivate *)png_get_io_ptr(png_ptr); -
106 QIODevice *in = d->q->device(); -
107 -
108 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
109 -
110 uchar endcrc[4] = { 0xae, 0x42, 0x60, 0x82 }; -
111 memcpy(data, endcrc, 4); -
112 in->seek(in->size()); -
113 return;
never executed: return;
0
114 } -
115 -
116 while (length) {
evaluated: length
TRUEFALSE
yes
Evaluation Count:10347
yes
Evaluation Count:10321
10321-10347
117 int nr = in->read((char*)data, length); -
118 if (nr <= 0) {
evaluated: nr <= 0
TRUEFALSE
yes
Evaluation Count:13
yes
Evaluation Count:10334
13-10334
119 png_error(png_ptr, "Read Error"); -
120 return;
never executed: return;
0
121 } -
122 length -= nr; -
123 }
executed: }
Execution Count:10334
10334
124}
executed: }
Execution Count:10321
10321
125 -
126 -
127static -
128void qpiw_write_fn(png_structp png_ptr, png_bytep data, png_size_t length) -
129{ -
130 QPNGImageWriter* qpiw = (QPNGImageWriter*)png_get_io_ptr(png_ptr); -
131 QIODevice* out = qpiw->device(); -
132 -
133 uint nr = out->write((char*)data, length); -
134 if (nr != length) {
partially evaluated: nr != length
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2489
0-2489
135 png_error(png_ptr, "Write Error"); -
136 return;
never executed: return;
0
137 } -
138}
executed: }
Execution Count:2489
2489
139 -
140 -
141static -
142void qpiw_flush_fn(png_structp ) -
143{ -
144} -
145 -
146 -
147} -
148 -
149 -
150static -
151void setup_qt(QImage& image, png_structp png_ptr, png_infop info_ptr, QSize scaledSize, bool *doScaledRead, float screen_gamma=0.0) -
152{ -
153 if (screen_gamma != 0.0 && png_get_valid(png_ptr, info_ptr, 0x0001)) {
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
154 double file_gamma; -
155 png_get_gAMA(png_ptr, info_ptr, &file_gamma); -
156 png_set_gamma(png_ptr, screen_gamma, file_gamma); -
157 }
never executed: }
0
158 -
159 png_uint_32 width; -
160 png_uint_32 height; -
161 int bit_depth; -
162 int color_type; -
163 png_bytep trans_alpha = 0; -
164 png_color_16p trans_color_p = 0; -
165 int num_trans; -
166 png_colorp palette = 0; -
167 int num_palette; -
168 int interlace_method; -
169 png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_method, 0, 0); -
170 png_set_interlace_handling(png_ptr); -
171 -
172 if (color_type == 0) {
partially evaluated: color_type == 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:430
0-430
173 -
174 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
175 png_set_invert_mono(png_ptr); -
176 png_read_update_info(png_ptr, info_ptr); -
177 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
178 image = QImage(width, height, QImage::Format_Mono); -
179 if (image.isNull())
never evaluated: image.isNull()
0
180 return;
never executed: return;
0
181 }
never executed: }
0
182 image.setColorCount(2); -
183 image.setColor(1, qRgb(0,0,0)); -
184 image.setColor(0, qRgb(255,255,255)); -
185 } else if (bit_depth == 16 && png_get_valid(png_ptr, info_ptr, 0x0010)) {
never executed: }
never evaluated: bit_depth == 16
never evaluated: png_get_valid(png_ptr, info_ptr, 0x0010)
0
186 png_set_expand(png_ptr); -
187 png_set_strip_16(png_ptr); -
188 png_set_gray_to_rgb(png_ptr); -
189 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
190 image = QImage(width, height, QImage::Format_ARGB32); -
191 if (image.isNull())
never evaluated: image.isNull()
0
192 return;
never executed: return;
0
193 }
never executed: }
0
194 if (QSysInfo::ByteOrder == QSysInfo::BigEndian)
never evaluated: QSysInfo::ByteOrder == QSysInfo::BigEndian
0
195 png_set_swap_alpha(png_ptr);
never executed: png_set_swap_alpha(png_ptr);
0
196 -
197 png_read_update_info(png_ptr, info_ptr); -
198 } else {
never executed: }
0
199 if (bit_depth == 16)
never evaluated: bit_depth == 16
0
200 png_set_strip_16(png_ptr);
never executed: png_set_strip_16(png_ptr);
0
201 else if (bit_depth < 8)
never evaluated: bit_depth < 8
0
202 png_set_packing(png_ptr);
never executed: png_set_packing(png_ptr);
0
203 int ncols = bit_depth < 8 ? 1 << bit_depth : 256;
never evaluated: bit_depth < 8
0
204 png_read_update_info(png_ptr, info_ptr); -
205 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
206 image = QImage(width, height, QImage::Format_Indexed8); -
207 if (image.isNull())
never evaluated: image.isNull()
0
208 return;
never executed: return;
0
209 }
never executed: }
0
210 image.setColorCount(ncols); -
211 for (int i=0; i<ncols; i++) {
never evaluated: i<ncols
0
212 int c = i*255/(ncols-1); -
213 image.setColor(i, qRgba(c,c,c,0xff)); -
214 }
never executed: }
0
215 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
216 const int g = trans_color_p->gray; -
217 if (g < ncols) {
never evaluated: g < ncols
0
218 image.setColor(g, 0); -
219 }
never executed: }
0
220 }
never executed: }
0
221 }
never executed: }
0
222 } else if (color_type == (2 | 1)
evaluated: color_type == (2 | 1)
TRUEFALSE
yes
Evaluation Count:75
yes
Evaluation Count:355
75-355
223 && 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
224 && num_palette <= 256)
partially evaluated: num_palette <= 256
TRUEFALSE
yes
Evaluation Count:75
no
Evaluation Count:0
0-75
225 { -
226 -
227 if (bit_depth != 1)
evaluated: bit_depth != 1
TRUEFALSE
yes
Evaluation Count:58
yes
Evaluation Count:17
17-58
228 png_set_packing(png_ptr);
executed: png_set_packing(png_ptr);
Execution Count:58
58
229 png_read_update_info(png_ptr, info_ptr); -
230 png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, 0, 0, 0); -
231 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
232 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
233 image = QImage(width, height, format); -
234 if (image.isNull())
partially evaluated: image.isNull()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:75
0-75
235 return;
never executed: return;
0
236 }
executed: }
Execution Count:75
75
237 png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette); -
238 image.setColorCount(num_palette); -
239 int i = 0; -
240 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
241 while (i < num_trans) {
evaluated: i < num_trans
TRUEFALSE
yes
Evaluation Count:1059
yes
Evaluation Count:50
50-1059
242 image.setColor(i, qRgba( -
243 palette[i].red, -
244 palette[i].green, -
245 palette[i].blue, -
246 trans_alpha[i] -
247 ) -
248 ); -
249 i++; -
250 }
executed: }
Execution Count:1059
1059
251 }
executed: }
Execution Count:50
50
252 while (i < num_palette) {
evaluated: i < num_palette
TRUEFALSE
yes
Evaluation Count:2819
yes
Evaluation Count:75
75-2819
253 image.setColor(i, qRgba( -
254 palette[i].red, -
255 palette[i].green, -
256 palette[i].blue, -
257 0xff -
258 ) -
259 ); -
260 i++; -
261 }
executed: }
Execution Count:2819
2819
262 } else {
executed: }
Execution Count:75
75
263 -
264 if (bit_depth == 16)
partially evaluated: bit_depth == 16
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:355
0-355
265 png_set_strip_16(png_ptr);
never executed: png_set_strip_16(png_ptr);
0
266 -
267 png_set_expand(png_ptr); -
268 -
269 if (color_type == (4))
partially evaluated: color_type == (4)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:355
0-355
270 png_set_gray_to_rgb(png_ptr);
never executed: png_set_gray_to_rgb(png_ptr);
0
271 -
272 QImage::Format format = QImage::Format_ARGB32; -
273 -
274 if (!(color_type & 4)
evaluated: !(color_type & 4)
TRUEFALSE
yes
Evaluation Count:67
yes
Evaluation Count:288
67-288
275 && !png_get_valid(png_ptr, info_ptr, 0x0010)) {
partially evaluated: !png_get_valid(png_ptr, info_ptr, 0x0010)
TRUEFALSE
yes
Evaluation Count:67
no
Evaluation Count:0
0-67
276 png_set_filler(png_ptr, 0xff, QSysInfo::ByteOrder == QSysInfo::BigEndian ? -
277 0 : 1); -
278 -
279 format = QImage::Format_RGB32; -
280 }
executed: }
Execution Count:67
67
281 QSize outSize(width,height); -
282 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
283 quint32(scaledSize.height()) <= height && interlace_method == 0) {
partially evaluated: quint32(scaledSize.height()) <= height
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:3
never evaluated: interlace_method == 0
0-3
284 -
285 outSize = scaledSize; -
286 if (doScaledRead)
never evaluated: doScaledRead
0
287 *doScaledRead = true;
never executed: *doScaledRead = true;
0
288 }
never executed: }
0
289 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
290 image = QImage(outSize, format); -
291 if (image.isNull())
partially evaluated: image.isNull()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:355
0-355
292 return;
never executed: return;
0
293 }
executed: }
Execution Count:355
355
294 -
295 if (QSysInfo::ByteOrder == QSysInfo::BigEndian)
partially evaluated: QSysInfo::ByteOrder == QSysInfo::BigEndian
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:355
0-355
296 png_set_swap_alpha(png_ptr);
never executed: png_set_swap_alpha(png_ptr);
0
297 -
298 png_read_update_info(png_ptr, info_ptr); -
299 }
executed: }
Execution Count:355
355
300 -
301 -
302 if (QSysInfo::ByteOrder == QSysInfo::LittleEndian) {
partially evaluated: QSysInfo::ByteOrder == QSysInfo::LittleEndian
TRUEFALSE
yes
Evaluation Count:430
no
Evaluation Count:0
0-430
303 png_set_bgr(png_ptr); -
304 }
executed: }
Execution Count:430
430
305}
executed: }
Execution Count:430
430
306 -
307static void read_image_scaled(QImage *outImage, png_structp png_ptr, png_infop info_ptr, -
308 QPngHandlerPrivate::AllocatedMemoryPointers &amp, QSize scaledSize) -
309{ -
310 -
311 png_uint_32 width; -
312 png_uint_32 height; -
313 int bit_depth; -
314 int color_type; -
315 png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, 0, 0, 0); -
316 uchar *data = outImage->bits(); -
317 int bpl = outImage->bytesPerLine(); -
318 -
319 if (scaledSize.isEmpty() || !width || !height)
never evaluated: scaledSize.isEmpty()
never evaluated: !width
never evaluated: !height
0
320 return;
never executed: return;
0
321 -
322 const quint32 iysz = height; -
323 const quint32 ixsz = width; -
324 const quint32 oysz = scaledSize.height(); -
325 const quint32 oxsz = scaledSize.width(); -
326 const quint32 ibw = 4*width; -
327 amp.accRow = new quint32[ibw]; -
328 memset(amp.accRow, 0, ibw*sizeof(quint32)); -
329 amp.inRow = new png_byte[ibw]; -
330 memset(amp.inRow, 0, ibw*sizeof(png_byte)); -
331 amp.outRow = new uchar[ibw]; -
332 memset(amp.outRow, 0, ibw*sizeof(uchar)); -
333 qint32 rval = 0; -
334 for (quint32 oy=0; oy<oysz; oy++) {
never evaluated: oy<oysz
0
335 -
336 for (quint32 i=0; i < ibw; i++)
never evaluated: i < ibw
0
337 amp.accRow[i] = rval*amp.inRow[i];
never executed: amp.accRow[i] = rval*amp.inRow[i];
0
338 -
339 for (rval = iysz-rval; rval > 0; rval-=oysz) {
never evaluated: rval > 0
0
340 png_read_row(png_ptr, amp.inRow, __null); -
341 quint32 fact = qMin(oysz, quint32(rval)); -
342 for (quint32 i=0; i < ibw; i++)
never evaluated: i < ibw
0
343 amp.accRow[i] += fact*amp.inRow[i];
never executed: amp.accRow[i] += fact*amp.inRow[i];
0
344 }
never executed: }
0
345 rval *= -1; -
346 -
347 -
348 for (quint32 i=0; i < ibw; i++)
never evaluated: i < ibw
0
349 amp.outRow[i] = uchar(amp.accRow[i]/iysz);
never executed: amp.outRow[i] = uchar(amp.accRow[i]/iysz);
0
350 -
351 quint32 a[4] = {0, 0, 0, 0}; -
352 qint32 cval = oxsz; -
353 quint32 ix = 0; -
354 for (quint32 ox=0; ox<oxsz; ox++) {
never evaluated: ox<oxsz
0
355 for (quint32 i=0; i < 4; i++)
never evaluated: i < 4
0
356 a[i] = cval * amp.outRow[ix+i];
never executed: a[i] = cval * amp.outRow[ix+i];
0
357 for (cval = ixsz - cval; cval > 0; cval-=oxsz) {
never evaluated: cval > 0
0
358 ix += 4; -
359 if (ix >= ibw)
never evaluated: ix >= ibw
0
360 break;
never executed: break;
0
361 quint32 fact = qMin(oxsz, quint32(cval)); -
362 for (quint32 i=0; i < 4; i++)
never evaluated: i < 4
0
363 a[i] += fact * amp.outRow[ix+i];
never executed: a[i] += fact * amp.outRow[ix+i];
0
364 }
never executed: }
0
365 cval *= -1; -
366 for (quint32 i=0; i < 4; i++)
never evaluated: i < 4
0
367 data[(4*ox)+i] = uchar(a[i]/ixsz);
never executed: data[(4*ox)+i] = uchar(a[i]/ixsz);
0
368 }
never executed: }
0
369 data += bpl; -
370 }
never executed: }
0
371 amp.deallocate(); -
372 -
373 outImage->setDotsPerMeterX((png_get_x_pixels_per_meter(png_ptr,info_ptr)*oxsz)/ixsz); -
374 outImage->setDotsPerMeterY((png_get_y_pixels_per_meter(png_ptr,info_ptr)*oysz)/iysz); -
375}
never executed: }
0
376 -
377 -
378extern "C" { -
379 -
380static void qt_png_warning(png_structp , png_const_charp message) -
381{ -
382 QMessageLogger("image/qpnghandler.cpp", 480, __PRETTY_FUNCTION__).warning("libpng warning: %s", message); -
383}
never executed: }
0
384 -
385 -
386} -
387 -
388 -
389 -
390void QPngHandlerPrivate::readPngTexts(png_info *info) -
391{ -
392 png_textp text_ptr; -
393 int num_text=0; -
394 png_get_text(png_ptr, info, &text_ptr, &num_text); -
395 -
396 while (num_text--) {
evaluated: num_text--
TRUEFALSE
yes
Evaluation Count:144
yes
Evaluation Count:857
144-857
397 QString key, value; -
398 key = QString::fromLatin1(text_ptr->key); -
399 -
400 -
401 -
402 -
403 -
404 { -
405 value = QString::fromLatin1(text_ptr->text, int(text_ptr->text_length)); -
406 } -
407 if (!description.isEmpty())
evaluated: !description.isEmpty()
TRUEFALSE
yes
Evaluation Count:34
yes
Evaluation Count:110
34-110
408 description += QLatin1String("\n\n");
executed: description += QLatin1String("\n\n");
Execution Count:34
34
409 description += key + QLatin1String(": ") + value.simplified(); -
410 readTexts.append(key); -
411 readTexts.append(value); -
412 text_ptr++; -
413 }
executed: }
Execution Count:144
144
414}
executed: }
Execution Count:857
857
415 -
416 -
417bool QPngHandlerPrivate::readPngHeader() -
418{ -
419 state = Error; -
420 png_ptr = png_create_read_struct("1.2.44",0,0,0); -
421 if (!png_ptr)
partially evaluated: !png_ptr
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:440
0-440
422 return false;
never executed: return false;
0
423 -
424 png_set_error_fn(png_ptr, 0, 0, qt_png_warning); -
425 -
426 info_ptr = png_create_info_struct(png_ptr); -
427 if (!info_ptr) {
partially evaluated: !info_ptr
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:440
0-440
428 png_destroy_read_struct(&png_ptr, 0, 0); -
429 png_ptr = 0; -
430 return false;
never executed: return false;
0
431 } -
432 -
433 end_info = png_create_info_struct(png_ptr); -
434 if (!end_info) {
partially evaluated: !end_info
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:440
0-440
435 png_destroy_read_struct(&png_ptr, &info_ptr, 0); -
436 png_ptr = 0; -
437 return false;
never executed: return false;
0
438 } -
439 -
440 if (_setjmp (((png_ptr)->jmpbuf))) {
partially evaluated: _setjmp (((png_ptr)->jmpbuf))
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:440
0-440
441 png_destroy_read_struct(&png_ptr, &info_ptr, &end_info); -
442 png_ptr = 0; -
443 return false;
never executed: return false;
0
444 } -
445 -
446 png_set_read_fn(png_ptr, this, iod_read_fn); -
447 png_read_info(png_ptr, info_ptr); -
448 -
449 readPngTexts(info_ptr); -
450 -
451 state = ReadHeader; -
452 return true;
executed: return true;
Execution Count:440
440
453} -
454 -
455 -
456bool QPngHandlerPrivate::readPngImage(QImage *outImage) -
457{ -
458 if (state == Error)
partially evaluated: state == Error
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:430
0-430
459 return false;
never executed: return false;
0
460 -
461 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
462 state = Error; -
463 return false;
never executed: return false;
0
464 } -
465 -
466 if (_setjmp (((png_ptr)->jmpbuf))) {
evaluated: _setjmp (((png_ptr)->jmpbuf))
TRUEFALSE
yes
Evaluation Count:13
yes
Evaluation Count:430
13-430
467 png_destroy_read_struct(&png_ptr, &info_ptr, &end_info); -
468 png_ptr = 0; -
469 amp.deallocate(); -
470 state = Error; -
471 return false;
executed: return false;
Execution Count:13
13
472 } -
473 -
474 bool doScaledRead = false; -
475 setup_qt(*outImage, png_ptr, info_ptr, scaledSize, &doScaledRead, gamma); -
476 -
477 if (outImage->isNull()) {
partially evaluated: outImage->isNull()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:430
0-430
478 png_destroy_read_struct(&png_ptr, &info_ptr, &end_info); -
479 png_ptr = 0; -
480 amp.deallocate(); -
481 state = Error; -
482 return false;
never executed: return false;
0
483 } -
484 -
485 if (doScaledRead) {
partially evaluated: doScaledRead
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:430
0-430
486 read_image_scaled(outImage, png_ptr, info_ptr, amp, scaledSize); -
487 } else {
never executed: }
0
488 png_uint_32 width; -
489 png_uint_32 height; -
490 int bit_depth; -
491 int color_type; -
492 png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, 0, 0, 0); -
493 uchar *data = outImage->bits(); -
494 int bpl = outImage->bytesPerLine(); -
495 amp.row_pointers = new png_bytep[height]; -
496 -
497 for (uint y = 0; y < height; y++)
evaluated: y < height
TRUEFALSE
yes
Evaluation Count:33768
yes
Evaluation Count:430
430-33768
498 amp.row_pointers[y] = data + y * bpl;
executed: amp.row_pointers[y] = data + y * bpl;
Execution Count:33768
33768
499 -
500 png_read_image(png_ptr, amp.row_pointers); -
501 amp.deallocate(); -
502 -
503 outImage->setDotsPerMeterX(png_get_x_pixels_per_meter(png_ptr,info_ptr)); -
504 outImage->setDotsPerMeterY(png_get_y_pixels_per_meter(png_ptr,info_ptr)); -
505 -
506 -
507 if (color_type == (2 | 1) && 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
508 int color_table_size = outImage->colorCount(); -
509 for (int y=0; y<(int)height; ++y) {
evaluated: y<(int)height
TRUEFALSE
yes
Evaluation Count:2620
yes
Evaluation Count:58
58-2620
510 uchar *p = (data + (y) * bpl); -
511 uchar *end = p + width; -
512 while (p < end) {
evaluated: p < end
TRUEFALSE
yes
Evaluation Count:335084
yes
Evaluation Count:2620
2620-335084
513 if (*p >= color_table_size)
partially evaluated: *p >= color_table_size
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:335084
0-335084
514 *p = 0;
never executed: *p = 0;
0
515 ++p; -
516 }
executed: }
Execution Count:335084
335084
517 }
executed: }
Execution Count:2620
2620
518 }
executed: }
Execution Count:58
58
519 }
executed: }
Execution Count:417
417
520 -
521 state = ReadingEnd; -
522 png_read_end(png_ptr, end_info); -
523 -
524 readPngTexts(end_info); -
525 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
526 outImage->setText(readTexts.at(i), readTexts.at(i+1));
executed: outImage->setText(readTexts.at(i), readTexts.at(i+1));
Execution Count:126
126
527 -
528 png_destroy_read_struct(&png_ptr, &info_ptr, &end_info); -
529 png_ptr = 0; -
530 amp.deallocate(); -
531 state = Ready; -
532 -
533 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
534 *outImage = outImage->scaled(scaledSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
executed: *outImage = outImage->scaled(scaledSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
Execution Count:4
4
535 -
536 return true;
executed: return true;
Execution Count:417
417
537} -
538 -
539QImage::Format QPngHandlerPrivate::readImageFormat() -
540{ -
541 QImage::Format format = QImage::Format_Invalid; -
542 png_uint_32 width, height; -
543 int bit_depth, color_type; -
544 png_colorp palette; -
545 int num_palette; -
546 png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, 0, 0, 0); -
547 if (color_type == 0) {
partially evaluated: color_type == 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
0-2
548 -
549 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
550 format = QImage::Format_Mono; -
551 } else if (bit_depth == 16 && png_get_valid(png_ptr, info_ptr, 0x0010)) {
never evaluated: bit_depth == 16
never evaluated: png_get_valid(png_ptr, info_ptr, 0x0010)
never executed: }
0
552 format = QImage::Format_ARGB32; -
553 } else {
never executed: }
0
554 format = QImage::Format_Indexed8; -
555 }
never executed: }
0
556 } else if (color_type == (2 | 1)
partially evaluated: color_type == (2 | 1)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
0-2
557 && png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette)
never evaluated: png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette)
0
558 && num_palette <= 256)
never evaluated: num_palette <= 256
0
559 { -
560 -
561 if (bit_depth != 1)
never evaluated: bit_depth != 1
0
562 png_set_packing(png_ptr);
never executed: png_set_packing(png_ptr);
0
563 png_read_update_info(png_ptr, info_ptr); -
564 png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, 0, 0, 0); -
565 format = bit_depth == 1 ? QImage::Format_Mono : QImage::Format_Indexed8;
never evaluated: bit_depth == 1
0
566 } else {
never executed: }
0
567 -
568 if (bit_depth == 16)
partially evaluated: bit_depth == 16
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
0-2
569 png_set_strip_16(png_ptr);
never executed: png_set_strip_16(png_ptr);
0
570 -
571 format = QImage::Format_ARGB32; -
572 -
573 if (!(color_type & 4)
evaluated: !(color_type & 4)
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:1
1
574 && !png_get_valid(png_ptr, info_ptr, 0x0010)) {
partially evaluated: !png_get_valid(png_ptr, info_ptr, 0x0010)
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
0-1
575 -
576 format = QImage::Format_RGB32; -
577 }
executed: }
Execution Count:1
1
578 }
executed: }
Execution Count:2
2
579 -
580 return format;
executed: return format;
Execution Count:2
2
581} -
582 -
583QPNGImageWriter::QPNGImageWriter(QIODevice* iod) : -
584 dev(iod), -
585 frames_written(0), -
586 disposal(Unspecified), -
587 looping(-1), -
588 ms_delay(-1), -
589 gamma(0.0) -
590{ -
591}
executed: }
Execution Count:123
123
592 -
593QPNGImageWriter::~QPNGImageWriter() -
594{ -
595} -
596 -
597void QPNGImageWriter::setDisposalMethod(DisposalMethod dm) -
598{ -
599 disposal = dm; -
600}
never executed: }
0
601 -
602void QPNGImageWriter::setLooping(int loops) -
603{ -
604 looping = loops; -
605}
never executed: }
0
606 -
607void QPNGImageWriter::setFrameDelay(int msecs) -
608{ -
609 ms_delay = msecs; -
610}
never executed: }
0
611 -
612void QPNGImageWriter::setGamma(float g) -
613{ -
614 gamma = g; -
615}
executed: }
Execution Count:123
123
616 -
617 -
618static void set_text(const QImage &image, png_structp png_ptr, png_infop info_ptr, -
619 const QString &description) -
620{ -
621 QMap<QString, QString> text; -
622 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;})) { -
623 if (!key.isEmpty())
partially evaluated: !key.isEmpty()
TRUEFALSE
yes
Evaluation Count:29
no
Evaluation Count:0
0-29
624 text.insert(key, image.text(key));
executed: text.insert(key, image.text(key));
Execution Count:29
29
625 }
executed: }
Execution Count:29
29
626 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;})) { -
627 int index = pair.indexOf(QLatin1Char(':')); -
628 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
629 QString s = pair.simplified(); -
630 if (!s.isEmpty())
never evaluated: !s.isEmpty()
0
631 text.insert(QLatin1String("Description"), s);
never executed: text.insert(QLatin1String("Description"), s);
0
632 } else {
never executed: }
0
633 QString key = pair.left(index); -
634 if (!key.simplified().isEmpty())
evaluated: !key.simplified().isEmpty()
TRUEFALSE
yes
Evaluation Count:12
yes
Evaluation Count:117
12-117
635 text.insert(key, pair.mid(index + 2).simplified());
executed: text.insert(key, pair.mid(index + 2).simplified());
Execution Count:12
12
636 }
executed: }
Execution Count:129
129
637 } -
638 -
639 if (text.isEmpty())
evaluated: text.isEmpty()
TRUEFALSE
yes
Evaluation Count:100
yes
Evaluation Count:23
23-100
640 return;
executed: return;
Execution Count:100
100
641 -
642 png_textp text_ptr = new png_text[text.size()]; -
643 memset(text_ptr, 0, text.size() * sizeof(png_text)); -
644 -
645 QMap<QString, QString>::ConstIterator it = text.constBegin(); -
646 int i = 0; -
647 while (it != text.constEnd()) {
evaluated: it != text.constEnd()
TRUEFALSE
yes
Evaluation Count:41
yes
Evaluation Count:23
23-41
648 text_ptr[i].key = qstrdup(it.key().left(79).toLatin1().constData()); -
649 bool noCompress = (it.value().length() < 40); -
650 { -
651 text_ptr[i].compression = noCompress ? -1 : 0;
evaluated: noCompress
TRUEFALSE
yes
Evaluation Count:37
yes
Evaluation Count:4
4-37
652 QByteArray value = it.value().toLatin1(); -
653 text_ptr[i].text = qstrdup(value.constData()); -
654 text_ptr[i].text_length = value.size(); -
655 } -
656 ++i; -
657 ++it; -
658 }
executed: }
Execution Count:41
41
659 -
660 png_set_text(png_ptr, info_ptr, text_ptr, i); -
661 for (i = 0; i < text.size(); ++i) {
evaluated: i < text.size()
TRUEFALSE
yes
Evaluation Count:41
yes
Evaluation Count:23
23-41
662 delete [] text_ptr[i].key; -
663 delete [] text_ptr[i].text; -
664 -
665 -
666 -
667 }
executed: }
Execution Count:41
41
668 delete [] text_ptr; -
669}
executed: }
Execution Count:23
23
670 -
671bool QPNGImageWriter::writeImage(const QImage& image, int off_x, int off_y) -
672{ -
673 return writeImage(image, -1, QString(), off_x, off_y);
never executed: return writeImage(image, -1, QString(), off_x, off_y);
0
674} -
675 -
676bool QPNGImageWriter::writeImage(const QImage& image, volatile int quality_in, const QString &description, -
677 int off_x_in, int off_y_in) -
678{ -
679 QPoint offset = image.offset(); -
680 int off_x = off_x_in + offset.x(); -
681 int off_y = off_y_in + offset.y(); -
682 -
683 png_structp png_ptr; -
684 png_infop info_ptr; -
685 -
686 png_ptr = png_create_write_struct("1.2.44",0,0,0); -
687 if (!png_ptr) {
partially evaluated: !png_ptr
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:123
0-123
688 return false;
never executed: return false;
0
689 } -
690 -
691 png_set_error_fn(png_ptr, 0, 0, qt_png_warning); -
692 -
693 info_ptr = png_create_info_struct(png_ptr); -
694 if (!info_ptr) {
partially evaluated: !info_ptr
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:123
0-123
695 png_destroy_write_struct(&png_ptr, 0); -
696 return false;
never executed: return false;
0
697 } -
698 -
699 if (_setjmp (((png_ptr)->jmpbuf))) {
partially evaluated: _setjmp (((png_ptr)->jmpbuf))
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:123
0-123
700 png_destroy_write_struct(&png_ptr, &info_ptr); -
701 return false;
never executed: return false;
0
702 } -
703 -
704 int quality = quality_in; -
705 if (quality >= 0) {
partially evaluated: quality >= 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:123
0-123
706 if (quality > 9) {
never evaluated: quality > 9
0
707 QMessageLogger("image/qpnghandler.cpp", 826, __PRETTY_FUNCTION__).warning("PNG: Quality %d out of range", quality); -
708 quality = 9; -
709 }
never executed: }
0
710 png_set_compression_level(png_ptr, quality); -
711 }
never executed: }
0
712 -
713 png_set_write_fn(png_ptr, (void*)this, qpiw_write_fn, qpiw_flush_fn); -
714 -
715 -
716 int color_type = 0; -
717 if (image.colorCount()) {
evaluated: image.colorCount()
TRUEFALSE
yes
Evaluation Count:25
yes
Evaluation Count:98
25-98
718 if (image.isGrayscale())
partially evaluated: image.isGrayscale()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:25
0-25
719 color_type = 0;
never executed: color_type = 0;
0
720 else -
721 color_type = (2 | 1);
executed: color_type = (2 | 1);
Execution Count:25
25
722 } -
723 else if (image.hasAlphaChannel())
evaluated: image.hasAlphaChannel()
TRUEFALSE
yes
Evaluation Count:79
yes
Evaluation Count:19
19-79
724 color_type = (2 | 4);
executed: color_type = (2 | 4);
Execution Count:79
79
725 else -
726 color_type = (2);
executed: color_type = (2);
Execution Count:19
19
727 -
728 png_set_IHDR(png_ptr, info_ptr, image.width(), image.height(), -
729 image.depth() == 1 ? 1 : 8, -
730 color_type, 0, 0, 0); -
731 -
732 if (gamma != 0.0) {
partially evaluated: gamma != 0.0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:123
0-123
733 png_set_gAMA(png_ptr, info_ptr, 1.0/gamma); -
734 }
never executed: }
0
735 -
736 if (image.format() == QImage::Format_MonoLSB)
evaluated: image.format() == QImage::Format_MonoLSB
TRUEFALSE
yes
Evaluation Count:15
yes
Evaluation Count:108
15-108
737 png_set_packswap(png_ptr);
executed: png_set_packswap(png_ptr);
Execution Count:15
15
738 -
739 if (color_type == (2 | 1)) {
evaluated: color_type == (2 | 1)
TRUEFALSE
yes
Evaluation Count:25
yes
Evaluation Count:98
25-98
740 -
741 int num_palette = qMin(256, image.colorCount()); -
742 png_color palette[256]; -
743 png_byte trans[256]; -
744 int num_trans = 0; -
745 for (int i=0; i<num_palette; i++) {
evaluated: i<num_palette
TRUEFALSE
yes
Evaluation Count:582
yes
Evaluation Count:25
25-582
746 QRgb rgba=image.color(i); -
747 palette[i].red = qRed(rgba); -
748 palette[i].green = qGreen(rgba); -
749 palette[i].blue = qBlue(rgba); -
750 trans[i] = qAlpha(rgba); -
751 if (trans[i] < 255) {
evaluated: trans[i] < 255
TRUEFALSE
yes
Evaluation Count:84
yes
Evaluation Count:498
84-498
752 num_trans = i+1; -
753 }
executed: }
Execution Count:84
84
754 }
executed: }
Execution Count:582
582
755 png_set_PLTE(png_ptr, info_ptr, palette, num_palette); -
756 -
757 if (num_trans) {
evaluated: num_trans
TRUEFALSE
yes
Evaluation Count:8
yes
Evaluation Count:17
8-17
758 png_set_tRNS(png_ptr, info_ptr, trans, num_trans, 0); -
759 }
executed: }
Execution Count:8
8
760 }
executed: }
Execution Count:25
25
761 -
762 -
763 -
764 if (QSysInfo::ByteOrder == QSysInfo::BigEndian) {
partially evaluated: QSysInfo::ByteOrder == QSysInfo::BigEndian
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:123
0-123
765 png_set_swap_alpha(png_ptr); -
766 }
never executed: }
0
767 -
768 -
769 if (QSysInfo::ByteOrder == QSysInfo::LittleEndian
partially evaluated: QSysInfo::ByteOrder == QSysInfo::LittleEndian
TRUEFALSE
yes
Evaluation Count:123
no
Evaluation Count:0
0-123
770 && image.format() != QImage::Format_RGB888) {
evaluated: image.format() != QImage::Format_RGB888
TRUEFALSE
yes
Evaluation Count:121
yes
Evaluation Count:2
2-121
771 png_set_bgr(png_ptr); -
772 }
executed: }
Execution Count:121
121
773 -
774 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
775 png_set_oFFs(png_ptr, info_ptr, off_x, off_y, 0); -
776 }
never executed: }
0
777 -
778 if (frames_written > 0)
partially evaluated: frames_written > 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:123
0-123
779 png_set_sig_bytes(png_ptr, 8);
never executed: png_set_sig_bytes(png_ptr, 8);
0
780 -
781 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
782 png_set_pHYs(png_ptr, info_ptr, -
783 image.dotsPerMeterX(), image.dotsPerMeterY(), -
784 1); -
785 }
executed: }
Execution Count:123
123
786 -
787 set_text(image, png_ptr, info_ptr, description); -
788 -
789 png_write_info(png_ptr, info_ptr); -
790 -
791 if (image.depth() != 1)
evaluated: image.depth() != 1
TRUEFALSE
yes
Evaluation Count:106
yes
Evaluation Count:17
17-106
792 png_set_packing(png_ptr);
executed: png_set_packing(png_ptr);
Execution Count:106
106
793 -
794 if (color_type == (2) && 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
795 png_set_filler(png_ptr, 0, 17
796 QSysInfo::ByteOrder == QSysInfo::BigEndian ? 17
797 0 : 1);
executed: png_set_filler(png_ptr, 0, QSysInfo::ByteOrder == QSysInfo::BigEndian ? 0 : 1);
Execution Count:17
17
798 -
799 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
800 uchar data[13] = "NETSCAPE2.0"; -
801 -
802 data[0xB] = looping%0x100; -
803 data[0xC] = looping/0x100; -
804 png_write_chunk(png_ptr, (png_byte*)"gIFx", data, 13); -
805 }
never executed: }
0
806 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
807 uchar data[4]; -
808 data[0] = disposal; -
809 data[1] = 0; -
810 data[2] = (ms_delay/10)/0x100; -
811 data[3] = (ms_delay/10)%0x100; -
812 png_write_chunk(png_ptr, (png_byte*)"gIFg", data, 4); -
813 }
never executed: }
0
814 -
815 int height = image.height(); -
816 int width = image.width(); -
817 switch (image.format()) { -
818 case QImage::Format_Mono: -
819 case QImage::Format_MonoLSB: -
820 case QImage::Format_Indexed8: -
821 case QImage::Format_RGB32: -
822 case QImage::Format_ARGB32: -
823 case QImage::Format_RGB888: -
824 { -
825 png_bytep* row_pointers = new png_bytep[height]; -
826 for (int y=0; y<height; y++)
evaluated: y<height
TRUEFALSE
yes
Evaluation Count:5384
yes
Evaluation Count:60
60-5384
827 row_pointers[y] = (png_bytep)image.constScanLine(y);
executed: row_pointers[y] = (png_bytep)image.constScanLine(y);
Execution Count:5384
5384
828 png_write_image(png_ptr, row_pointers); -
829 delete [] row_pointers; -
830 } -
831 break;
executed: break;
Execution Count:60
60
832 default: -
833 { -
834 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
835 QImage row; -
836 png_bytep row_pointers[1]; -
837 for (int y=0; y<height; y++) {
evaluated: y<height
TRUEFALSE
yes
Evaluation Count:3913
yes
Evaluation Count:63
63-3913
838 row = image.copy(0, y, width, 1).convertToFormat(fmt); -
839 row_pointers[0] = png_bytep(row.constScanLine(0)); -
840 png_write_rows(png_ptr, row_pointers, 1); -
841 }
executed: }
Execution Count:3913
3913
842 } -
843 break;
executed: break;
Execution Count:63
63
844 } -
845 -
846 png_write_end(png_ptr, info_ptr); -
847 frames_written++; -
848 -
849 png_destroy_write_struct(&png_ptr, &info_ptr); -
850 -
851 return true;
executed: return true;
Execution Count:123
123
852} -
853 -
854static bool write_png_image(const QImage &image, QIODevice *device, -
855 int quality, float gamma, const QString &description) -
856{ -
857 QPNGImageWriter writer(device); -
858 if (quality >= 0) {
partially evaluated: quality >= 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:123
0-123
859 quality = qMin(quality, 100); -
860 quality = (100-quality) * 9 / 91; -
861 }
never executed: }
0
862 writer.setGamma(gamma); -
863 return writer.writeImage(image, quality, description);
executed: return writer.writeImage(image, quality, description);
Execution Count:123
123
864} -
865 -
866QPngHandler::QPngHandler() -
867 : d(new QPngHandlerPrivate(this)) -
868{ -
869}
executed: }
Execution Count:577
577
870 -
871QPngHandler::~QPngHandler() -
872{ -
873 if (d->png_ptr)
evaluated: d->png_ptr
TRUEFALSE
yes
Evaluation Count:10
yes
Evaluation Count:567
10-567
874 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
875 delete d; -
876}
executed: }
Execution Count:577
577
877 -
878bool QPngHandler::canRead() const -
879{ -
880 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
881 return false;
executed: return false;
Execution Count:8
8
882 -
883 if (d->state != QPngHandlerPrivate::Error) {
partially evaluated: d->state != QPngHandlerPrivate::Error
TRUEFALSE
yes
Evaluation Count:467
no
Evaluation Count:0
0-467
884 setFormat("png"); -
885 return true;
executed: return true;
Execution Count:467
467
886 } -
887 -
888 return false;
never executed: return false;
0
889} -
890 -
891bool QPngHandler::canRead(QIODevice *device) -
892{ -
893 if (!device) {
partially evaluated: !device
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:688
0-688
894 QMessageLogger("image/qpnghandler.cpp", 1013, __PRETTY_FUNCTION__).warning("QPngHandler::canRead() called with no device"); -
895 return false;
never executed: return false;
0
896 } -
897 -
898 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
899} -
900 -
901bool QPngHandler::read(QImage *image) -
902{ -
903 if (!canRead())
evaluated: !canRead()
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:430
2-430
904 return false;
executed: return false;
Execution Count:2
2
905 return d->readPngImage(image);
executed: return d->readPngImage(image);
Execution Count:430
430
906} -
907 -
908bool QPngHandler::write(const QImage &image) -
909{ -
910 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
911} -
912 -
913bool QPngHandler::supportsOption(ImageOption option) const -
914{ -
915 return option == Gamma 3403
916 || option == Description 3403
917 || option == ImageFormat 3403
918 || option == Quality 3403
919 || option == Size 3403
920 || option == ScaledSize;
executed: return option == Gamma || option == Description || option == ImageFormat || option == Quality || option == Size || option == ScaledSize;
Execution Count:3403
3403
921} -
922 -
923QVariant QPngHandler::option(ImageOption option) const -
924{ -
925 if (d->state == QPngHandlerPrivate::Error)
partially evaluated: d->state == QPngHandlerPrivate::Error
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:12
0-12
926 return QVariant();
never executed: return QVariant();
0
927 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
928 return QVariant();
never executed: return QVariant();
0
929 -
930 if (option == Gamma)
partially evaluated: option == Gamma
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:12
0-12
931 return d->gamma;
never executed: return d->gamma;
0
932 else if (option == Quality)
partially evaluated: option == Quality
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:12
0-12
933 return d->quality;
never executed: return d->quality;
0
934 else if (option == Description)
evaluated: option == Description
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:6
6
935 return d->description;
executed: return d->description;
Execution Count:6
6
936 else if (option == Size)
evaluated: option == Size
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:2
2-4
937 return QSize(png_get_image_width(d->png_ptr, d->info_ptr), 4
938 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
939 else if (option == ScaledSize)
partially evaluated: option == ScaledSize
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
0-2
940 return d->scaledSize;
never executed: return d->scaledSize;
0
941 else if (option == ImageFormat)
partially evaluated: option == ImageFormat
TRUEFALSE
yes
Evaluation Count:2
no
Evaluation Count:0
0-2
942 return d->readImageFormat();
executed: return d->readImageFormat();
Execution Count:2
2
943 return QVariant();
never executed: return QVariant();
0
944} -
945 -
946void QPngHandler::setOption(ImageOption option, const QVariant &value) -
947{ -
948 if (option == Gamma)
evaluated: option == Gamma
TRUEFALSE
yes
Evaluation Count:123
yes
Evaluation Count:565
123-565
949 d->gamma = value.toFloat();
executed: d->gamma = value.toFloat();
Execution Count:123
123
950 else if (option == Quality)
evaluated: option == Quality
TRUEFALSE
yes
Evaluation Count:555
yes
Evaluation Count:10
10-555
951 d->quality = value.toInt();
executed: d->quality = value.toInt();
Execution Count:555
555
952 else if (option == Description)
evaluated: option == Description
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:4
4-6
953 d->description = value.toString();
executed: d->description = value.toString();
Execution Count:6
6
954 else if (option == ScaledSize)
partially evaluated: option == ScaledSize
TRUEFALSE
yes
Evaluation Count:4
no
Evaluation Count:0
0-4
955 d->scaledSize = value.toSize();
executed: d->scaledSize = value.toSize();
Execution Count:4
4
956} -
957 -
958QByteArray QPngHandler::name() const -
959{ -
960 return "png";
never executed: return "png";
0
961} -
962 -
963 -
964 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial