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