rev |
line source |
nuclear@14
|
1
|
nuclear@14
|
2 /* pngpread.c - read a png file in push mode
|
nuclear@14
|
3 *
|
nuclear@14
|
4 * Last changed in libpng 1.2.32 [September 18, 2008]
|
nuclear@14
|
5 * For conditions of distribution and use, see copyright notice in png.h
|
nuclear@14
|
6 * Copyright (c) 1998-2008 Glenn Randers-Pehrson
|
nuclear@14
|
7 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
|
nuclear@14
|
8 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
|
nuclear@14
|
9 */
|
nuclear@14
|
10
|
nuclear@14
|
11 #define PNG_INTERNAL
|
nuclear@14
|
12 #include "png.h"
|
nuclear@14
|
13 #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
|
nuclear@14
|
14
|
nuclear@14
|
15 /* push model modes */
|
nuclear@14
|
16 #define PNG_READ_SIG_MODE 0
|
nuclear@14
|
17 #define PNG_READ_CHUNK_MODE 1
|
nuclear@14
|
18 #define PNG_READ_IDAT_MODE 2
|
nuclear@14
|
19 #define PNG_SKIP_MODE 3
|
nuclear@14
|
20 #define PNG_READ_tEXt_MODE 4
|
nuclear@14
|
21 #define PNG_READ_zTXt_MODE 5
|
nuclear@14
|
22 #define PNG_READ_DONE_MODE 6
|
nuclear@14
|
23 #define PNG_READ_iTXt_MODE 7
|
nuclear@14
|
24 #define PNG_ERROR_MODE 8
|
nuclear@14
|
25
|
nuclear@14
|
26 void PNGAPI
|
nuclear@14
|
27 png_process_data(png_structp png_ptr, png_infop info_ptr,
|
nuclear@14
|
28 png_bytep buffer, png_size_t buffer_size)
|
nuclear@14
|
29 {
|
nuclear@14
|
30 if (png_ptr == NULL || info_ptr == NULL) return;
|
nuclear@14
|
31 png_push_restore_buffer(png_ptr, buffer, buffer_size);
|
nuclear@14
|
32
|
nuclear@14
|
33 while (png_ptr->buffer_size)
|
nuclear@14
|
34 {
|
nuclear@14
|
35 png_process_some_data(png_ptr, info_ptr);
|
nuclear@14
|
36 }
|
nuclear@14
|
37 }
|
nuclear@14
|
38
|
nuclear@14
|
39 /* What we do with the incoming data depends on what we were previously
|
nuclear@14
|
40 * doing before we ran out of data...
|
nuclear@14
|
41 */
|
nuclear@14
|
42 void /* PRIVATE */
|
nuclear@14
|
43 png_process_some_data(png_structp png_ptr, png_infop info_ptr)
|
nuclear@14
|
44 {
|
nuclear@14
|
45 if (png_ptr == NULL) return;
|
nuclear@14
|
46 switch (png_ptr->process_mode)
|
nuclear@14
|
47 {
|
nuclear@14
|
48 case PNG_READ_SIG_MODE:
|
nuclear@14
|
49 {
|
nuclear@14
|
50 png_push_read_sig(png_ptr, info_ptr);
|
nuclear@14
|
51 break;
|
nuclear@14
|
52 }
|
nuclear@14
|
53 case PNG_READ_CHUNK_MODE:
|
nuclear@14
|
54 {
|
nuclear@14
|
55 png_push_read_chunk(png_ptr, info_ptr);
|
nuclear@14
|
56 break;
|
nuclear@14
|
57 }
|
nuclear@14
|
58 case PNG_READ_IDAT_MODE:
|
nuclear@14
|
59 {
|
nuclear@14
|
60 png_push_read_IDAT(png_ptr);
|
nuclear@14
|
61 break;
|
nuclear@14
|
62 }
|
nuclear@14
|
63 #if defined(PNG_READ_tEXt_SUPPORTED)
|
nuclear@14
|
64 case PNG_READ_tEXt_MODE:
|
nuclear@14
|
65 {
|
nuclear@14
|
66 png_push_read_tEXt(png_ptr, info_ptr);
|
nuclear@14
|
67 break;
|
nuclear@14
|
68 }
|
nuclear@14
|
69 #endif
|
nuclear@14
|
70 #if defined(PNG_READ_zTXt_SUPPORTED)
|
nuclear@14
|
71 case PNG_READ_zTXt_MODE:
|
nuclear@14
|
72 {
|
nuclear@14
|
73 png_push_read_zTXt(png_ptr, info_ptr);
|
nuclear@14
|
74 break;
|
nuclear@14
|
75 }
|
nuclear@14
|
76 #endif
|
nuclear@14
|
77 #if defined(PNG_READ_iTXt_SUPPORTED)
|
nuclear@14
|
78 case PNG_READ_iTXt_MODE:
|
nuclear@14
|
79 {
|
nuclear@14
|
80 png_push_read_iTXt(png_ptr, info_ptr);
|
nuclear@14
|
81 break;
|
nuclear@14
|
82 }
|
nuclear@14
|
83 #endif
|
nuclear@14
|
84 case PNG_SKIP_MODE:
|
nuclear@14
|
85 {
|
nuclear@14
|
86 png_push_crc_finish(png_ptr);
|
nuclear@14
|
87 break;
|
nuclear@14
|
88 }
|
nuclear@14
|
89 default:
|
nuclear@14
|
90 {
|
nuclear@14
|
91 png_ptr->buffer_size = 0;
|
nuclear@14
|
92 break;
|
nuclear@14
|
93 }
|
nuclear@14
|
94 }
|
nuclear@14
|
95 }
|
nuclear@14
|
96
|
nuclear@14
|
97 /* Read any remaining signature bytes from the stream and compare them with
|
nuclear@14
|
98 * the correct PNG signature. It is possible that this routine is called
|
nuclear@14
|
99 * with bytes already read from the signature, either because they have been
|
nuclear@14
|
100 * checked by the calling application, or because of multiple calls to this
|
nuclear@14
|
101 * routine.
|
nuclear@14
|
102 */
|
nuclear@14
|
103 void /* PRIVATE */
|
nuclear@14
|
104 png_push_read_sig(png_structp png_ptr, png_infop info_ptr)
|
nuclear@14
|
105 {
|
nuclear@14
|
106 png_size_t num_checked = png_ptr->sig_bytes,
|
nuclear@14
|
107 num_to_check = 8 - num_checked;
|
nuclear@14
|
108
|
nuclear@14
|
109 if (png_ptr->buffer_size < num_to_check)
|
nuclear@14
|
110 {
|
nuclear@14
|
111 num_to_check = png_ptr->buffer_size;
|
nuclear@14
|
112 }
|
nuclear@14
|
113
|
nuclear@14
|
114 png_push_fill_buffer(png_ptr, &(info_ptr->signature[num_checked]),
|
nuclear@14
|
115 num_to_check);
|
nuclear@14
|
116 png_ptr->sig_bytes = (png_byte)(png_ptr->sig_bytes + num_to_check);
|
nuclear@14
|
117
|
nuclear@14
|
118 if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
|
nuclear@14
|
119 {
|
nuclear@14
|
120 if (num_checked < 4 &&
|
nuclear@14
|
121 png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
|
nuclear@14
|
122 png_error(png_ptr, "Not a PNG file");
|
nuclear@14
|
123 else
|
nuclear@14
|
124 png_error(png_ptr, "PNG file corrupted by ASCII conversion");
|
nuclear@14
|
125 }
|
nuclear@14
|
126 else
|
nuclear@14
|
127 {
|
nuclear@14
|
128 if (png_ptr->sig_bytes >= 8)
|
nuclear@14
|
129 {
|
nuclear@14
|
130 png_ptr->process_mode = PNG_READ_CHUNK_MODE;
|
nuclear@14
|
131 }
|
nuclear@14
|
132 }
|
nuclear@14
|
133 }
|
nuclear@14
|
134
|
nuclear@14
|
135 void /* PRIVATE */
|
nuclear@14
|
136 png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
|
nuclear@14
|
137 {
|
nuclear@14
|
138 #ifdef PNG_USE_LOCAL_ARRAYS
|
nuclear@14
|
139 PNG_CONST PNG_IHDR;
|
nuclear@14
|
140 PNG_CONST PNG_IDAT;
|
nuclear@14
|
141 PNG_CONST PNG_IEND;
|
nuclear@14
|
142 PNG_CONST PNG_PLTE;
|
nuclear@14
|
143 #if defined(PNG_READ_bKGD_SUPPORTED)
|
nuclear@14
|
144 PNG_CONST PNG_bKGD;
|
nuclear@14
|
145 #endif
|
nuclear@14
|
146 #if defined(PNG_READ_cHRM_SUPPORTED)
|
nuclear@14
|
147 PNG_CONST PNG_cHRM;
|
nuclear@14
|
148 #endif
|
nuclear@14
|
149 #if defined(PNG_READ_gAMA_SUPPORTED)
|
nuclear@14
|
150 PNG_CONST PNG_gAMA;
|
nuclear@14
|
151 #endif
|
nuclear@14
|
152 #if defined(PNG_READ_hIST_SUPPORTED)
|
nuclear@14
|
153 PNG_CONST PNG_hIST;
|
nuclear@14
|
154 #endif
|
nuclear@14
|
155 #if defined(PNG_READ_iCCP_SUPPORTED)
|
nuclear@14
|
156 PNG_CONST PNG_iCCP;
|
nuclear@14
|
157 #endif
|
nuclear@14
|
158 #if defined(PNG_READ_iTXt_SUPPORTED)
|
nuclear@14
|
159 PNG_CONST PNG_iTXt;
|
nuclear@14
|
160 #endif
|
nuclear@14
|
161 #if defined(PNG_READ_oFFs_SUPPORTED)
|
nuclear@14
|
162 PNG_CONST PNG_oFFs;
|
nuclear@14
|
163 #endif
|
nuclear@14
|
164 #if defined(PNG_READ_pCAL_SUPPORTED)
|
nuclear@14
|
165 PNG_CONST PNG_pCAL;
|
nuclear@14
|
166 #endif
|
nuclear@14
|
167 #if defined(PNG_READ_pHYs_SUPPORTED)
|
nuclear@14
|
168 PNG_CONST PNG_pHYs;
|
nuclear@14
|
169 #endif
|
nuclear@14
|
170 #if defined(PNG_READ_sBIT_SUPPORTED)
|
nuclear@14
|
171 PNG_CONST PNG_sBIT;
|
nuclear@14
|
172 #endif
|
nuclear@14
|
173 #if defined(PNG_READ_sCAL_SUPPORTED)
|
nuclear@14
|
174 PNG_CONST PNG_sCAL;
|
nuclear@14
|
175 #endif
|
nuclear@14
|
176 #if defined(PNG_READ_sRGB_SUPPORTED)
|
nuclear@14
|
177 PNG_CONST PNG_sRGB;
|
nuclear@14
|
178 #endif
|
nuclear@14
|
179 #if defined(PNG_READ_sPLT_SUPPORTED)
|
nuclear@14
|
180 PNG_CONST PNG_sPLT;
|
nuclear@14
|
181 #endif
|
nuclear@14
|
182 #if defined(PNG_READ_tEXt_SUPPORTED)
|
nuclear@14
|
183 PNG_CONST PNG_tEXt;
|
nuclear@14
|
184 #endif
|
nuclear@14
|
185 #if defined(PNG_READ_tIME_SUPPORTED)
|
nuclear@14
|
186 PNG_CONST PNG_tIME;
|
nuclear@14
|
187 #endif
|
nuclear@14
|
188 #if defined(PNG_READ_tRNS_SUPPORTED)
|
nuclear@14
|
189 PNG_CONST PNG_tRNS;
|
nuclear@14
|
190 #endif
|
nuclear@14
|
191 #if defined(PNG_READ_zTXt_SUPPORTED)
|
nuclear@14
|
192 PNG_CONST PNG_zTXt;
|
nuclear@14
|
193 #endif
|
nuclear@14
|
194 #endif /* PNG_USE_LOCAL_ARRAYS */
|
nuclear@14
|
195 /* First we make sure we have enough data for the 4 byte chunk name
|
nuclear@14
|
196 * and the 4 byte chunk length before proceeding with decoding the
|
nuclear@14
|
197 * chunk data. To fully decode each of these chunks, we also make
|
nuclear@14
|
198 * sure we have enough data in the buffer for the 4 byte CRC at the
|
nuclear@14
|
199 * end of every chunk (except IDAT, which is handled separately).
|
nuclear@14
|
200 */
|
nuclear@14
|
201 if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
|
nuclear@14
|
202 {
|
nuclear@14
|
203 png_byte chunk_length[4];
|
nuclear@14
|
204
|
nuclear@14
|
205 if (png_ptr->buffer_size < 8)
|
nuclear@14
|
206 {
|
nuclear@14
|
207 png_push_save_buffer(png_ptr);
|
nuclear@14
|
208 return;
|
nuclear@14
|
209 }
|
nuclear@14
|
210
|
nuclear@14
|
211 png_push_fill_buffer(png_ptr, chunk_length, 4);
|
nuclear@14
|
212 png_ptr->push_length = png_get_uint_31(png_ptr, chunk_length);
|
nuclear@14
|
213 png_reset_crc(png_ptr);
|
nuclear@14
|
214 png_crc_read(png_ptr, png_ptr->chunk_name, 4);
|
nuclear@14
|
215 png_check_chunk_name(png_ptr, png_ptr->chunk_name);
|
nuclear@14
|
216 png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
|
nuclear@14
|
217 }
|
nuclear@14
|
218
|
nuclear@14
|
219 if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
|
nuclear@14
|
220 if (png_ptr->mode & PNG_AFTER_IDAT)
|
nuclear@14
|
221 png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
|
nuclear@14
|
222
|
nuclear@14
|
223 if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
|
nuclear@14
|
224 {
|
nuclear@14
|
225 if (png_ptr->push_length != 13)
|
nuclear@14
|
226 png_error(png_ptr, "Invalid IHDR length");
|
nuclear@14
|
227 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
nuclear@14
|
228 {
|
nuclear@14
|
229 png_push_save_buffer(png_ptr);
|
nuclear@14
|
230 return;
|
nuclear@14
|
231 }
|
nuclear@14
|
232 png_handle_IHDR(png_ptr, info_ptr, png_ptr->push_length);
|
nuclear@14
|
233 }
|
nuclear@14
|
234 else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
|
nuclear@14
|
235 {
|
nuclear@14
|
236 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
nuclear@14
|
237 {
|
nuclear@14
|
238 png_push_save_buffer(png_ptr);
|
nuclear@14
|
239 return;
|
nuclear@14
|
240 }
|
nuclear@14
|
241 png_handle_IEND(png_ptr, info_ptr, png_ptr->push_length);
|
nuclear@14
|
242
|
nuclear@14
|
243 png_ptr->process_mode = PNG_READ_DONE_MODE;
|
nuclear@14
|
244 png_push_have_end(png_ptr, info_ptr);
|
nuclear@14
|
245 }
|
nuclear@14
|
246 #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
|
nuclear@14
|
247 else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
|
nuclear@14
|
248 {
|
nuclear@14
|
249 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
nuclear@14
|
250 {
|
nuclear@14
|
251 png_push_save_buffer(png_ptr);
|
nuclear@14
|
252 return;
|
nuclear@14
|
253 }
|
nuclear@14
|
254 if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
|
nuclear@14
|
255 png_ptr->mode |= PNG_HAVE_IDAT;
|
nuclear@14
|
256 png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length);
|
nuclear@14
|
257 if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
|
nuclear@14
|
258 png_ptr->mode |= PNG_HAVE_PLTE;
|
nuclear@14
|
259 else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
|
nuclear@14
|
260 {
|
nuclear@14
|
261 if (!(png_ptr->mode & PNG_HAVE_IHDR))
|
nuclear@14
|
262 png_error(png_ptr, "Missing IHDR before IDAT");
|
nuclear@14
|
263 else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
|
nuclear@14
|
264 !(png_ptr->mode & PNG_HAVE_PLTE))
|
nuclear@14
|
265 png_error(png_ptr, "Missing PLTE before IDAT");
|
nuclear@14
|
266 }
|
nuclear@14
|
267 }
|
nuclear@14
|
268 #endif
|
nuclear@14
|
269 else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
|
nuclear@14
|
270 {
|
nuclear@14
|
271 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
nuclear@14
|
272 {
|
nuclear@14
|
273 png_push_save_buffer(png_ptr);
|
nuclear@14
|
274 return;
|
nuclear@14
|
275 }
|
nuclear@14
|
276 png_handle_PLTE(png_ptr, info_ptr, png_ptr->push_length);
|
nuclear@14
|
277 }
|
nuclear@14
|
278 else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
|
nuclear@14
|
279 {
|
nuclear@14
|
280 /* If we reach an IDAT chunk, this means we have read all of the
|
nuclear@14
|
281 * header chunks, and we can start reading the image (or if this
|
nuclear@14
|
282 * is called after the image has been read - we have an error).
|
nuclear@14
|
283 */
|
nuclear@14
|
284 if (!(png_ptr->mode & PNG_HAVE_IHDR))
|
nuclear@14
|
285 png_error(png_ptr, "Missing IHDR before IDAT");
|
nuclear@14
|
286 else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
|
nuclear@14
|
287 !(png_ptr->mode & PNG_HAVE_PLTE))
|
nuclear@14
|
288 png_error(png_ptr, "Missing PLTE before IDAT");
|
nuclear@14
|
289
|
nuclear@14
|
290 if (png_ptr->mode & PNG_HAVE_IDAT)
|
nuclear@14
|
291 {
|
nuclear@14
|
292 if (!(png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
|
nuclear@14
|
293 if (png_ptr->push_length == 0)
|
nuclear@14
|
294 return;
|
nuclear@14
|
295
|
nuclear@14
|
296 if (png_ptr->mode & PNG_AFTER_IDAT)
|
nuclear@14
|
297 png_error(png_ptr, "Too many IDAT's found");
|
nuclear@14
|
298 }
|
nuclear@14
|
299
|
nuclear@14
|
300 png_ptr->idat_size = png_ptr->push_length;
|
nuclear@14
|
301 png_ptr->mode |= PNG_HAVE_IDAT;
|
nuclear@14
|
302 png_ptr->process_mode = PNG_READ_IDAT_MODE;
|
nuclear@14
|
303 png_push_have_info(png_ptr, info_ptr);
|
nuclear@14
|
304 png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
|
nuclear@14
|
305 png_ptr->zstream.next_out = png_ptr->row_buf;
|
nuclear@14
|
306 return;
|
nuclear@14
|
307 }
|
nuclear@14
|
308 #if defined(PNG_READ_gAMA_SUPPORTED)
|
nuclear@14
|
309 else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
|
nuclear@14
|
310 {
|
nuclear@14
|
311 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
nuclear@14
|
312 {
|
nuclear@14
|
313 png_push_save_buffer(png_ptr);
|
nuclear@14
|
314 return;
|
nuclear@14
|
315 }
|
nuclear@14
|
316 png_handle_gAMA(png_ptr, info_ptr, png_ptr->push_length);
|
nuclear@14
|
317 }
|
nuclear@14
|
318 #endif
|
nuclear@14
|
319 #if defined(PNG_READ_sBIT_SUPPORTED)
|
nuclear@14
|
320 else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
|
nuclear@14
|
321 {
|
nuclear@14
|
322 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
nuclear@14
|
323 {
|
nuclear@14
|
324 png_push_save_buffer(png_ptr);
|
nuclear@14
|
325 return;
|
nuclear@14
|
326 }
|
nuclear@14
|
327 png_handle_sBIT(png_ptr, info_ptr, png_ptr->push_length);
|
nuclear@14
|
328 }
|
nuclear@14
|
329 #endif
|
nuclear@14
|
330 #if defined(PNG_READ_cHRM_SUPPORTED)
|
nuclear@14
|
331 else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
|
nuclear@14
|
332 {
|
nuclear@14
|
333 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
nuclear@14
|
334 {
|
nuclear@14
|
335 png_push_save_buffer(png_ptr);
|
nuclear@14
|
336 return;
|
nuclear@14
|
337 }
|
nuclear@14
|
338 png_handle_cHRM(png_ptr, info_ptr, png_ptr->push_length);
|
nuclear@14
|
339 }
|
nuclear@14
|
340 #endif
|
nuclear@14
|
341 #if defined(PNG_READ_sRGB_SUPPORTED)
|
nuclear@14
|
342 else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
|
nuclear@14
|
343 {
|
nuclear@14
|
344 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
nuclear@14
|
345 {
|
nuclear@14
|
346 png_push_save_buffer(png_ptr);
|
nuclear@14
|
347 return;
|
nuclear@14
|
348 }
|
nuclear@14
|
349 png_handle_sRGB(png_ptr, info_ptr, png_ptr->push_length);
|
nuclear@14
|
350 }
|
nuclear@14
|
351 #endif
|
nuclear@14
|
352 #if defined(PNG_READ_iCCP_SUPPORTED)
|
nuclear@14
|
353 else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
|
nuclear@14
|
354 {
|
nuclear@14
|
355 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
nuclear@14
|
356 {
|
nuclear@14
|
357 png_push_save_buffer(png_ptr);
|
nuclear@14
|
358 return;
|
nuclear@14
|
359 }
|
nuclear@14
|
360 png_handle_iCCP(png_ptr, info_ptr, png_ptr->push_length);
|
nuclear@14
|
361 }
|
nuclear@14
|
362 #endif
|
nuclear@14
|
363 #if defined(PNG_READ_sPLT_SUPPORTED)
|
nuclear@14
|
364 else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
|
nuclear@14
|
365 {
|
nuclear@14
|
366 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
nuclear@14
|
367 {
|
nuclear@14
|
368 png_push_save_buffer(png_ptr);
|
nuclear@14
|
369 return;
|
nuclear@14
|
370 }
|
nuclear@14
|
371 png_handle_sPLT(png_ptr, info_ptr, png_ptr->push_length);
|
nuclear@14
|
372 }
|
nuclear@14
|
373 #endif
|
nuclear@14
|
374 #if defined(PNG_READ_tRNS_SUPPORTED)
|
nuclear@14
|
375 else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
|
nuclear@14
|
376 {
|
nuclear@14
|
377 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
nuclear@14
|
378 {
|
nuclear@14
|
379 png_push_save_buffer(png_ptr);
|
nuclear@14
|
380 return;
|
nuclear@14
|
381 }
|
nuclear@14
|
382 png_handle_tRNS(png_ptr, info_ptr, png_ptr->push_length);
|
nuclear@14
|
383 }
|
nuclear@14
|
384 #endif
|
nuclear@14
|
385 #if defined(PNG_READ_bKGD_SUPPORTED)
|
nuclear@14
|
386 else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
|
nuclear@14
|
387 {
|
nuclear@14
|
388 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
nuclear@14
|
389 {
|
nuclear@14
|
390 png_push_save_buffer(png_ptr);
|
nuclear@14
|
391 return;
|
nuclear@14
|
392 }
|
nuclear@14
|
393 png_handle_bKGD(png_ptr, info_ptr, png_ptr->push_length);
|
nuclear@14
|
394 }
|
nuclear@14
|
395 #endif
|
nuclear@14
|
396 #if defined(PNG_READ_hIST_SUPPORTED)
|
nuclear@14
|
397 else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
|
nuclear@14
|
398 {
|
nuclear@14
|
399 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
nuclear@14
|
400 {
|
nuclear@14
|
401 png_push_save_buffer(png_ptr);
|
nuclear@14
|
402 return;
|
nuclear@14
|
403 }
|
nuclear@14
|
404 png_handle_hIST(png_ptr, info_ptr, png_ptr->push_length);
|
nuclear@14
|
405 }
|
nuclear@14
|
406 #endif
|
nuclear@14
|
407 #if defined(PNG_READ_pHYs_SUPPORTED)
|
nuclear@14
|
408 else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
|
nuclear@14
|
409 {
|
nuclear@14
|
410 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
nuclear@14
|
411 {
|
nuclear@14
|
412 png_push_save_buffer(png_ptr);
|
nuclear@14
|
413 return;
|
nuclear@14
|
414 }
|
nuclear@14
|
415 png_handle_pHYs(png_ptr, info_ptr, png_ptr->push_length);
|
nuclear@14
|
416 }
|
nuclear@14
|
417 #endif
|
nuclear@14
|
418 #if defined(PNG_READ_oFFs_SUPPORTED)
|
nuclear@14
|
419 else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
|
nuclear@14
|
420 {
|
nuclear@14
|
421 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
nuclear@14
|
422 {
|
nuclear@14
|
423 png_push_save_buffer(png_ptr);
|
nuclear@14
|
424 return;
|
nuclear@14
|
425 }
|
nuclear@14
|
426 png_handle_oFFs(png_ptr, info_ptr, png_ptr->push_length);
|
nuclear@14
|
427 }
|
nuclear@14
|
428 #endif
|
nuclear@14
|
429 #if defined(PNG_READ_pCAL_SUPPORTED)
|
nuclear@14
|
430 else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
|
nuclear@14
|
431 {
|
nuclear@14
|
432 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
nuclear@14
|
433 {
|
nuclear@14
|
434 png_push_save_buffer(png_ptr);
|
nuclear@14
|
435 return;
|
nuclear@14
|
436 }
|
nuclear@14
|
437 png_handle_pCAL(png_ptr, info_ptr, png_ptr->push_length);
|
nuclear@14
|
438 }
|
nuclear@14
|
439 #endif
|
nuclear@14
|
440 #if defined(PNG_READ_sCAL_SUPPORTED)
|
nuclear@14
|
441 else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
|
nuclear@14
|
442 {
|
nuclear@14
|
443 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
nuclear@14
|
444 {
|
nuclear@14
|
445 png_push_save_buffer(png_ptr);
|
nuclear@14
|
446 return;
|
nuclear@14
|
447 }
|
nuclear@14
|
448 png_handle_sCAL(png_ptr, info_ptr, png_ptr->push_length);
|
nuclear@14
|
449 }
|
nuclear@14
|
450 #endif
|
nuclear@14
|
451 #if defined(PNG_READ_tIME_SUPPORTED)
|
nuclear@14
|
452 else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
|
nuclear@14
|
453 {
|
nuclear@14
|
454 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
nuclear@14
|
455 {
|
nuclear@14
|
456 png_push_save_buffer(png_ptr);
|
nuclear@14
|
457 return;
|
nuclear@14
|
458 }
|
nuclear@14
|
459 png_handle_tIME(png_ptr, info_ptr, png_ptr->push_length);
|
nuclear@14
|
460 }
|
nuclear@14
|
461 #endif
|
nuclear@14
|
462 #if defined(PNG_READ_tEXt_SUPPORTED)
|
nuclear@14
|
463 else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
|
nuclear@14
|
464 {
|
nuclear@14
|
465 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
nuclear@14
|
466 {
|
nuclear@14
|
467 png_push_save_buffer(png_ptr);
|
nuclear@14
|
468 return;
|
nuclear@14
|
469 }
|
nuclear@14
|
470 png_push_handle_tEXt(png_ptr, info_ptr, png_ptr->push_length);
|
nuclear@14
|
471 }
|
nuclear@14
|
472 #endif
|
nuclear@14
|
473 #if defined(PNG_READ_zTXt_SUPPORTED)
|
nuclear@14
|
474 else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
|
nuclear@14
|
475 {
|
nuclear@14
|
476 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
nuclear@14
|
477 {
|
nuclear@14
|
478 png_push_save_buffer(png_ptr);
|
nuclear@14
|
479 return;
|
nuclear@14
|
480 }
|
nuclear@14
|
481 png_push_handle_zTXt(png_ptr, info_ptr, png_ptr->push_length);
|
nuclear@14
|
482 }
|
nuclear@14
|
483 #endif
|
nuclear@14
|
484 #if defined(PNG_READ_iTXt_SUPPORTED)
|
nuclear@14
|
485 else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
|
nuclear@14
|
486 {
|
nuclear@14
|
487 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
nuclear@14
|
488 {
|
nuclear@14
|
489 png_push_save_buffer(png_ptr);
|
nuclear@14
|
490 return;
|
nuclear@14
|
491 }
|
nuclear@14
|
492 png_push_handle_iTXt(png_ptr, info_ptr, png_ptr->push_length);
|
nuclear@14
|
493 }
|
nuclear@14
|
494 #endif
|
nuclear@14
|
495 else
|
nuclear@14
|
496 {
|
nuclear@14
|
497 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
nuclear@14
|
498 {
|
nuclear@14
|
499 png_push_save_buffer(png_ptr);
|
nuclear@14
|
500 return;
|
nuclear@14
|
501 }
|
nuclear@14
|
502 png_push_handle_unknown(png_ptr, info_ptr, png_ptr->push_length);
|
nuclear@14
|
503 }
|
nuclear@14
|
504
|
nuclear@14
|
505 png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
|
nuclear@14
|
506 }
|
nuclear@14
|
507
|
nuclear@14
|
508 void /* PRIVATE */
|
nuclear@14
|
509 png_push_crc_skip(png_structp png_ptr, png_uint_32 skip)
|
nuclear@14
|
510 {
|
nuclear@14
|
511 png_ptr->process_mode = PNG_SKIP_MODE;
|
nuclear@14
|
512 png_ptr->skip_length = skip;
|
nuclear@14
|
513 }
|
nuclear@14
|
514
|
nuclear@14
|
515 void /* PRIVATE */
|
nuclear@14
|
516 png_push_crc_finish(png_structp png_ptr)
|
nuclear@14
|
517 {
|
nuclear@14
|
518 if (png_ptr->skip_length && png_ptr->save_buffer_size)
|
nuclear@14
|
519 {
|
nuclear@14
|
520 png_size_t save_size;
|
nuclear@14
|
521
|
nuclear@14
|
522 if (png_ptr->skip_length < (png_uint_32)png_ptr->save_buffer_size)
|
nuclear@14
|
523 save_size = (png_size_t)png_ptr->skip_length;
|
nuclear@14
|
524 else
|
nuclear@14
|
525 save_size = png_ptr->save_buffer_size;
|
nuclear@14
|
526
|
nuclear@14
|
527 png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size);
|
nuclear@14
|
528
|
nuclear@14
|
529 png_ptr->skip_length -= save_size;
|
nuclear@14
|
530 png_ptr->buffer_size -= save_size;
|
nuclear@14
|
531 png_ptr->save_buffer_size -= save_size;
|
nuclear@14
|
532 png_ptr->save_buffer_ptr += save_size;
|
nuclear@14
|
533 }
|
nuclear@14
|
534 if (png_ptr->skip_length && png_ptr->current_buffer_size)
|
nuclear@14
|
535 {
|
nuclear@14
|
536 png_size_t save_size;
|
nuclear@14
|
537
|
nuclear@14
|
538 if (png_ptr->skip_length < (png_uint_32)png_ptr->current_buffer_size)
|
nuclear@14
|
539 save_size = (png_size_t)png_ptr->skip_length;
|
nuclear@14
|
540 else
|
nuclear@14
|
541 save_size = png_ptr->current_buffer_size;
|
nuclear@14
|
542
|
nuclear@14
|
543 png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size);
|
nuclear@14
|
544
|
nuclear@14
|
545 png_ptr->skip_length -= save_size;
|
nuclear@14
|
546 png_ptr->buffer_size -= save_size;
|
nuclear@14
|
547 png_ptr->current_buffer_size -= save_size;
|
nuclear@14
|
548 png_ptr->current_buffer_ptr += save_size;
|
nuclear@14
|
549 }
|
nuclear@14
|
550 if (!png_ptr->skip_length)
|
nuclear@14
|
551 {
|
nuclear@14
|
552 if (png_ptr->buffer_size < 4)
|
nuclear@14
|
553 {
|
nuclear@14
|
554 png_push_save_buffer(png_ptr);
|
nuclear@14
|
555 return;
|
nuclear@14
|
556 }
|
nuclear@14
|
557
|
nuclear@14
|
558 png_crc_finish(png_ptr, 0);
|
nuclear@14
|
559 png_ptr->process_mode = PNG_READ_CHUNK_MODE;
|
nuclear@14
|
560 }
|
nuclear@14
|
561 }
|
nuclear@14
|
562
|
nuclear@14
|
563 void PNGAPI
|
nuclear@14
|
564 png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length)
|
nuclear@14
|
565 {
|
nuclear@14
|
566 png_bytep ptr;
|
nuclear@14
|
567
|
nuclear@14
|
568 if (png_ptr == NULL) return;
|
nuclear@14
|
569 ptr = buffer;
|
nuclear@14
|
570 if (png_ptr->save_buffer_size)
|
nuclear@14
|
571 {
|
nuclear@14
|
572 png_size_t save_size;
|
nuclear@14
|
573
|
nuclear@14
|
574 if (length < png_ptr->save_buffer_size)
|
nuclear@14
|
575 save_size = length;
|
nuclear@14
|
576 else
|
nuclear@14
|
577 save_size = png_ptr->save_buffer_size;
|
nuclear@14
|
578
|
nuclear@14
|
579 png_memcpy(ptr, png_ptr->save_buffer_ptr, save_size);
|
nuclear@14
|
580 length -= save_size;
|
nuclear@14
|
581 ptr += save_size;
|
nuclear@14
|
582 png_ptr->buffer_size -= save_size;
|
nuclear@14
|
583 png_ptr->save_buffer_size -= save_size;
|
nuclear@14
|
584 png_ptr->save_buffer_ptr += save_size;
|
nuclear@14
|
585 }
|
nuclear@14
|
586 if (length && png_ptr->current_buffer_size)
|
nuclear@14
|
587 {
|
nuclear@14
|
588 png_size_t save_size;
|
nuclear@14
|
589
|
nuclear@14
|
590 if (length < png_ptr->current_buffer_size)
|
nuclear@14
|
591 save_size = length;
|
nuclear@14
|
592 else
|
nuclear@14
|
593 save_size = png_ptr->current_buffer_size;
|
nuclear@14
|
594
|
nuclear@14
|
595 png_memcpy(ptr, png_ptr->current_buffer_ptr, save_size);
|
nuclear@14
|
596 png_ptr->buffer_size -= save_size;
|
nuclear@14
|
597 png_ptr->current_buffer_size -= save_size;
|
nuclear@14
|
598 png_ptr->current_buffer_ptr += save_size;
|
nuclear@14
|
599 }
|
nuclear@14
|
600 }
|
nuclear@14
|
601
|
nuclear@14
|
602 void /* PRIVATE */
|
nuclear@14
|
603 png_push_save_buffer(png_structp png_ptr)
|
nuclear@14
|
604 {
|
nuclear@14
|
605 if (png_ptr->save_buffer_size)
|
nuclear@14
|
606 {
|
nuclear@14
|
607 if (png_ptr->save_buffer_ptr != png_ptr->save_buffer)
|
nuclear@14
|
608 {
|
nuclear@14
|
609 png_size_t i, istop;
|
nuclear@14
|
610 png_bytep sp;
|
nuclear@14
|
611 png_bytep dp;
|
nuclear@14
|
612
|
nuclear@14
|
613 istop = png_ptr->save_buffer_size;
|
nuclear@14
|
614 for (i = 0, sp = png_ptr->save_buffer_ptr, dp = png_ptr->save_buffer;
|
nuclear@14
|
615 i < istop; i++, sp++, dp++)
|
nuclear@14
|
616 {
|
nuclear@14
|
617 *dp = *sp;
|
nuclear@14
|
618 }
|
nuclear@14
|
619 }
|
nuclear@14
|
620 }
|
nuclear@14
|
621 if (png_ptr->save_buffer_size + png_ptr->current_buffer_size >
|
nuclear@14
|
622 png_ptr->save_buffer_max)
|
nuclear@14
|
623 {
|
nuclear@14
|
624 png_size_t new_max;
|
nuclear@14
|
625 png_bytep old_buffer;
|
nuclear@14
|
626
|
nuclear@14
|
627 if (png_ptr->save_buffer_size > PNG_SIZE_MAX -
|
nuclear@14
|
628 (png_ptr->current_buffer_size + 256))
|
nuclear@14
|
629 {
|
nuclear@14
|
630 png_error(png_ptr, "Potential overflow of save_buffer");
|
nuclear@14
|
631 }
|
nuclear@14
|
632 new_max = png_ptr->save_buffer_size + png_ptr->current_buffer_size + 256;
|
nuclear@14
|
633 old_buffer = png_ptr->save_buffer;
|
nuclear@14
|
634 png_ptr->save_buffer = (png_bytep)png_malloc(png_ptr,
|
nuclear@14
|
635 (png_uint_32)new_max);
|
nuclear@14
|
636 png_memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size);
|
nuclear@14
|
637 png_free(png_ptr, old_buffer);
|
nuclear@14
|
638 png_ptr->save_buffer_max = new_max;
|
nuclear@14
|
639 }
|
nuclear@14
|
640 if (png_ptr->current_buffer_size)
|
nuclear@14
|
641 {
|
nuclear@14
|
642 png_memcpy(png_ptr->save_buffer + png_ptr->save_buffer_size,
|
nuclear@14
|
643 png_ptr->current_buffer_ptr, png_ptr->current_buffer_size);
|
nuclear@14
|
644 png_ptr->save_buffer_size += png_ptr->current_buffer_size;
|
nuclear@14
|
645 png_ptr->current_buffer_size = 0;
|
nuclear@14
|
646 }
|
nuclear@14
|
647 png_ptr->save_buffer_ptr = png_ptr->save_buffer;
|
nuclear@14
|
648 png_ptr->buffer_size = 0;
|
nuclear@14
|
649 }
|
nuclear@14
|
650
|
nuclear@14
|
651 void /* PRIVATE */
|
nuclear@14
|
652 png_push_restore_buffer(png_structp png_ptr, png_bytep buffer,
|
nuclear@14
|
653 png_size_t buffer_length)
|
nuclear@14
|
654 {
|
nuclear@14
|
655 png_ptr->current_buffer = buffer;
|
nuclear@14
|
656 png_ptr->current_buffer_size = buffer_length;
|
nuclear@14
|
657 png_ptr->buffer_size = buffer_length + png_ptr->save_buffer_size;
|
nuclear@14
|
658 png_ptr->current_buffer_ptr = png_ptr->current_buffer;
|
nuclear@14
|
659 }
|
nuclear@14
|
660
|
nuclear@14
|
661 void /* PRIVATE */
|
nuclear@14
|
662 png_push_read_IDAT(png_structp png_ptr)
|
nuclear@14
|
663 {
|
nuclear@14
|
664 #ifdef PNG_USE_LOCAL_ARRAYS
|
nuclear@14
|
665 PNG_CONST PNG_IDAT;
|
nuclear@14
|
666 #endif
|
nuclear@14
|
667 if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
|
nuclear@14
|
668 {
|
nuclear@14
|
669 png_byte chunk_length[4];
|
nuclear@14
|
670
|
nuclear@14
|
671 if (png_ptr->buffer_size < 8)
|
nuclear@14
|
672 {
|
nuclear@14
|
673 png_push_save_buffer(png_ptr);
|
nuclear@14
|
674 return;
|
nuclear@14
|
675 }
|
nuclear@14
|
676
|
nuclear@14
|
677 png_push_fill_buffer(png_ptr, chunk_length, 4);
|
nuclear@14
|
678 png_ptr->push_length = png_get_uint_31(png_ptr, chunk_length);
|
nuclear@14
|
679 png_reset_crc(png_ptr);
|
nuclear@14
|
680 png_crc_read(png_ptr, png_ptr->chunk_name, 4);
|
nuclear@14
|
681 png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
|
nuclear@14
|
682
|
nuclear@14
|
683 if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
|
nuclear@14
|
684 {
|
nuclear@14
|
685 png_ptr->process_mode = PNG_READ_CHUNK_MODE;
|
nuclear@14
|
686 if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
|
nuclear@14
|
687 png_error(png_ptr, "Not enough compressed data");
|
nuclear@14
|
688 return;
|
nuclear@14
|
689 }
|
nuclear@14
|
690
|
nuclear@14
|
691 png_ptr->idat_size = png_ptr->push_length;
|
nuclear@14
|
692 }
|
nuclear@14
|
693 if (png_ptr->idat_size && png_ptr->save_buffer_size)
|
nuclear@14
|
694 {
|
nuclear@14
|
695 png_size_t save_size;
|
nuclear@14
|
696
|
nuclear@14
|
697 if (png_ptr->idat_size < (png_uint_32)png_ptr->save_buffer_size)
|
nuclear@14
|
698 {
|
nuclear@14
|
699 save_size = (png_size_t)png_ptr->idat_size;
|
nuclear@14
|
700 /* check for overflow */
|
nuclear@14
|
701 if ((png_uint_32)save_size != png_ptr->idat_size)
|
nuclear@14
|
702 png_error(png_ptr, "save_size overflowed in pngpread");
|
nuclear@14
|
703 }
|
nuclear@14
|
704 else
|
nuclear@14
|
705 save_size = png_ptr->save_buffer_size;
|
nuclear@14
|
706
|
nuclear@14
|
707 png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size);
|
nuclear@14
|
708 if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
|
nuclear@14
|
709 png_process_IDAT_data(png_ptr, png_ptr->save_buffer_ptr, save_size);
|
nuclear@14
|
710 png_ptr->idat_size -= save_size;
|
nuclear@14
|
711 png_ptr->buffer_size -= save_size;
|
nuclear@14
|
712 png_ptr->save_buffer_size -= save_size;
|
nuclear@14
|
713 png_ptr->save_buffer_ptr += save_size;
|
nuclear@14
|
714 }
|
nuclear@14
|
715 if (png_ptr->idat_size && png_ptr->current_buffer_size)
|
nuclear@14
|
716 {
|
nuclear@14
|
717 png_size_t save_size;
|
nuclear@14
|
718
|
nuclear@14
|
719 if (png_ptr->idat_size < (png_uint_32)png_ptr->current_buffer_size)
|
nuclear@14
|
720 {
|
nuclear@14
|
721 save_size = (png_size_t)png_ptr->idat_size;
|
nuclear@14
|
722 /* check for overflow */
|
nuclear@14
|
723 if ((png_uint_32)save_size != png_ptr->idat_size)
|
nuclear@14
|
724 png_error(png_ptr, "save_size overflowed in pngpread");
|
nuclear@14
|
725 }
|
nuclear@14
|
726 else
|
nuclear@14
|
727 save_size = png_ptr->current_buffer_size;
|
nuclear@14
|
728
|
nuclear@14
|
729 png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size);
|
nuclear@14
|
730 if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
|
nuclear@14
|
731 png_process_IDAT_data(png_ptr, png_ptr->current_buffer_ptr, save_size);
|
nuclear@14
|
732
|
nuclear@14
|
733 png_ptr->idat_size -= save_size;
|
nuclear@14
|
734 png_ptr->buffer_size -= save_size;
|
nuclear@14
|
735 png_ptr->current_buffer_size -= save_size;
|
nuclear@14
|
736 png_ptr->current_buffer_ptr += save_size;
|
nuclear@14
|
737 }
|
nuclear@14
|
738 if (!png_ptr->idat_size)
|
nuclear@14
|
739 {
|
nuclear@14
|
740 if (png_ptr->buffer_size < 4)
|
nuclear@14
|
741 {
|
nuclear@14
|
742 png_push_save_buffer(png_ptr);
|
nuclear@14
|
743 return;
|
nuclear@14
|
744 }
|
nuclear@14
|
745
|
nuclear@14
|
746 png_crc_finish(png_ptr, 0);
|
nuclear@14
|
747 png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
|
nuclear@14
|
748 png_ptr->mode |= PNG_AFTER_IDAT;
|
nuclear@14
|
749 }
|
nuclear@14
|
750 }
|
nuclear@14
|
751
|
nuclear@14
|
752 void /* PRIVATE */
|
nuclear@14
|
753 png_process_IDAT_data(png_structp png_ptr, png_bytep buffer,
|
nuclear@14
|
754 png_size_t buffer_length)
|
nuclear@14
|
755 {
|
nuclear@14
|
756 int ret;
|
nuclear@14
|
757
|
nuclear@14
|
758 if ((png_ptr->flags & PNG_FLAG_ZLIB_FINISHED) && buffer_length)
|
nuclear@14
|
759 png_error(png_ptr, "Extra compression data");
|
nuclear@14
|
760
|
nuclear@14
|
761 png_ptr->zstream.next_in = buffer;
|
nuclear@14
|
762 png_ptr->zstream.avail_in = (uInt)buffer_length;
|
nuclear@14
|
763 for (;;)
|
nuclear@14
|
764 {
|
nuclear@14
|
765 ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
|
nuclear@14
|
766 if (ret != Z_OK)
|
nuclear@14
|
767 {
|
nuclear@14
|
768 if (ret == Z_STREAM_END)
|
nuclear@14
|
769 {
|
nuclear@14
|
770 if (png_ptr->zstream.avail_in)
|
nuclear@14
|
771 png_error(png_ptr, "Extra compressed data");
|
nuclear@14
|
772 if (!(png_ptr->zstream.avail_out))
|
nuclear@14
|
773 {
|
nuclear@14
|
774 png_push_process_row(png_ptr);
|
nuclear@14
|
775 }
|
nuclear@14
|
776
|
nuclear@14
|
777 png_ptr->mode |= PNG_AFTER_IDAT;
|
nuclear@14
|
778 png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
|
nuclear@14
|
779 break;
|
nuclear@14
|
780 }
|
nuclear@14
|
781 else if (ret == Z_BUF_ERROR)
|
nuclear@14
|
782 break;
|
nuclear@14
|
783 else
|
nuclear@14
|
784 png_error(png_ptr, "Decompression Error");
|
nuclear@14
|
785 }
|
nuclear@14
|
786 if (!(png_ptr->zstream.avail_out))
|
nuclear@14
|
787 {
|
nuclear@14
|
788 if ((
|
nuclear@14
|
789 #if defined(PNG_READ_INTERLACING_SUPPORTED)
|
nuclear@14
|
790 png_ptr->interlaced && png_ptr->pass > 6) ||
|
nuclear@14
|
791 (!png_ptr->interlaced &&
|
nuclear@14
|
792 #endif
|
nuclear@14
|
793 png_ptr->row_number == png_ptr->num_rows))
|
nuclear@14
|
794 {
|
nuclear@14
|
795 if (png_ptr->zstream.avail_in)
|
nuclear@14
|
796 png_warning(png_ptr, "Too much data in IDAT chunks");
|
nuclear@14
|
797 png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
|
nuclear@14
|
798 break;
|
nuclear@14
|
799 }
|
nuclear@14
|
800 png_push_process_row(png_ptr);
|
nuclear@14
|
801 png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
|
nuclear@14
|
802 png_ptr->zstream.next_out = png_ptr->row_buf;
|
nuclear@14
|
803 }
|
nuclear@14
|
804 else
|
nuclear@14
|
805 break;
|
nuclear@14
|
806 }
|
nuclear@14
|
807 }
|
nuclear@14
|
808
|
nuclear@14
|
809 void /* PRIVATE */
|
nuclear@14
|
810 png_push_process_row(png_structp png_ptr)
|
nuclear@14
|
811 {
|
nuclear@14
|
812 png_ptr->row_info.color_type = png_ptr->color_type;
|
nuclear@14
|
813 png_ptr->row_info.width = png_ptr->iwidth;
|
nuclear@14
|
814 png_ptr->row_info.channels = png_ptr->channels;
|
nuclear@14
|
815 png_ptr->row_info.bit_depth = png_ptr->bit_depth;
|
nuclear@14
|
816 png_ptr->row_info.pixel_depth = png_ptr->pixel_depth;
|
nuclear@14
|
817
|
nuclear@14
|
818 png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
|
nuclear@14
|
819 png_ptr->row_info.width);
|
nuclear@14
|
820
|
nuclear@14
|
821 png_read_filter_row(png_ptr, &(png_ptr->row_info),
|
nuclear@14
|
822 png_ptr->row_buf + 1, png_ptr->prev_row + 1,
|
nuclear@14
|
823 (int)(png_ptr->row_buf[0]));
|
nuclear@14
|
824
|
nuclear@14
|
825 png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf,
|
nuclear@14
|
826 png_ptr->rowbytes + 1);
|
nuclear@14
|
827
|
nuclear@14
|
828 if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
|
nuclear@14
|
829 png_do_read_transformations(png_ptr);
|
nuclear@14
|
830
|
nuclear@14
|
831 #if defined(PNG_READ_INTERLACING_SUPPORTED)
|
nuclear@14
|
832 /* blow up interlaced rows to full size */
|
nuclear@14
|
833 if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
|
nuclear@14
|
834 {
|
nuclear@14
|
835 if (png_ptr->pass < 6)
|
nuclear@14
|
836 /* old interface (pre-1.0.9):
|
nuclear@14
|
837 png_do_read_interlace(&(png_ptr->row_info),
|
nuclear@14
|
838 png_ptr->row_buf + 1, png_ptr->pass, png_ptr->transformations);
|
nuclear@14
|
839 */
|
nuclear@14
|
840 png_do_read_interlace(png_ptr);
|
nuclear@14
|
841
|
nuclear@14
|
842 switch (png_ptr->pass)
|
nuclear@14
|
843 {
|
nuclear@14
|
844 case 0:
|
nuclear@14
|
845 {
|
nuclear@14
|
846 int i;
|
nuclear@14
|
847 for (i = 0; i < 8 && png_ptr->pass == 0; i++)
|
nuclear@14
|
848 {
|
nuclear@14
|
849 png_push_have_row(png_ptr, png_ptr->row_buf + 1);
|
nuclear@14
|
850 png_read_push_finish_row(png_ptr); /* updates png_ptr->pass */
|
nuclear@14
|
851 }
|
nuclear@14
|
852 if (png_ptr->pass == 2) /* pass 1 might be empty */
|
nuclear@14
|
853 {
|
nuclear@14
|
854 for (i = 0; i < 4 && png_ptr->pass == 2; i++)
|
nuclear@14
|
855 {
|
nuclear@14
|
856 png_push_have_row(png_ptr, png_bytep_NULL);
|
nuclear@14
|
857 png_read_push_finish_row(png_ptr);
|
nuclear@14
|
858 }
|
nuclear@14
|
859 }
|
nuclear@14
|
860 if (png_ptr->pass == 4 && png_ptr->height <= 4)
|
nuclear@14
|
861 {
|
nuclear@14
|
862 for (i = 0; i < 2 && png_ptr->pass == 4; i++)
|
nuclear@14
|
863 {
|
nuclear@14
|
864 png_push_have_row(png_ptr, png_bytep_NULL);
|
nuclear@14
|
865 png_read_push_finish_row(png_ptr);
|
nuclear@14
|
866 }
|
nuclear@14
|
867 }
|
nuclear@14
|
868 if (png_ptr->pass == 6 && png_ptr->height <= 4)
|
nuclear@14
|
869 {
|
nuclear@14
|
870 png_push_have_row(png_ptr, png_bytep_NULL);
|
nuclear@14
|
871 png_read_push_finish_row(png_ptr);
|
nuclear@14
|
872 }
|
nuclear@14
|
873 break;
|
nuclear@14
|
874 }
|
nuclear@14
|
875 case 1:
|
nuclear@14
|
876 {
|
nuclear@14
|
877 int i;
|
nuclear@14
|
878 for (i = 0; i < 8 && png_ptr->pass == 1; i++)
|
nuclear@14
|
879 {
|
nuclear@14
|
880 png_push_have_row(png_ptr, png_ptr->row_buf + 1);
|
nuclear@14
|
881 png_read_push_finish_row(png_ptr);
|
nuclear@14
|
882 }
|
nuclear@14
|
883 if (png_ptr->pass == 2) /* skip top 4 generated rows */
|
nuclear@14
|
884 {
|
nuclear@14
|
885 for (i = 0; i < 4 && png_ptr->pass == 2; i++)
|
nuclear@14
|
886 {
|
nuclear@14
|
887 png_push_have_row(png_ptr, png_bytep_NULL);
|
nuclear@14
|
888 png_read_push_finish_row(png_ptr);
|
nuclear@14
|
889 }
|
nuclear@14
|
890 }
|
nuclear@14
|
891 break;
|
nuclear@14
|
892 }
|
nuclear@14
|
893 case 2:
|
nuclear@14
|
894 {
|
nuclear@14
|
895 int i;
|
nuclear@14
|
896 for (i = 0; i < 4 && png_ptr->pass == 2; i++)
|
nuclear@14
|
897 {
|
nuclear@14
|
898 png_push_have_row(png_ptr, png_ptr->row_buf + 1);
|
nuclear@14
|
899 png_read_push_finish_row(png_ptr);
|
nuclear@14
|
900 }
|
nuclear@14
|
901 for (i = 0; i < 4 && png_ptr->pass == 2; i++)
|
nuclear@14
|
902 {
|
nuclear@14
|
903 png_push_have_row(png_ptr, png_bytep_NULL);
|
nuclear@14
|
904 png_read_push_finish_row(png_ptr);
|
nuclear@14
|
905 }
|
nuclear@14
|
906 if (png_ptr->pass == 4) /* pass 3 might be empty */
|
nuclear@14
|
907 {
|
nuclear@14
|
908 for (i = 0; i < 2 && png_ptr->pass == 4; i++)
|
nuclear@14
|
909 {
|
nuclear@14
|
910 png_push_have_row(png_ptr, png_bytep_NULL);
|
nuclear@14
|
911 png_read_push_finish_row(png_ptr);
|
nuclear@14
|
912 }
|
nuclear@14
|
913 }
|
nuclear@14
|
914 break;
|
nuclear@14
|
915 }
|
nuclear@14
|
916 case 3:
|
nuclear@14
|
917 {
|
nuclear@14
|
918 int i;
|
nuclear@14
|
919 for (i = 0; i < 4 && png_ptr->pass == 3; i++)
|
nuclear@14
|
920 {
|
nuclear@14
|
921 png_push_have_row(png_ptr, png_ptr->row_buf + 1);
|
nuclear@14
|
922 png_read_push_finish_row(png_ptr);
|
nuclear@14
|
923 }
|
nuclear@14
|
924 if (png_ptr->pass == 4) /* skip top two generated rows */
|
nuclear@14
|
925 {
|
nuclear@14
|
926 for (i = 0; i < 2 && png_ptr->pass == 4; i++)
|
nuclear@14
|
927 {
|
nuclear@14
|
928 png_push_have_row(png_ptr, png_bytep_NULL);
|
nuclear@14
|
929 png_read_push_finish_row(png_ptr);
|
nuclear@14
|
930 }
|
nuclear@14
|
931 }
|
nuclear@14
|
932 break;
|
nuclear@14
|
933 }
|
nuclear@14
|
934 case 4:
|
nuclear@14
|
935 {
|
nuclear@14
|
936 int i;
|
nuclear@14
|
937 for (i = 0; i < 2 && png_ptr->pass == 4; i++)
|
nuclear@14
|
938 {
|
nuclear@14
|
939 png_push_have_row(png_ptr, png_ptr->row_buf + 1);
|
nuclear@14
|
940 png_read_push_finish_row(png_ptr);
|
nuclear@14
|
941 }
|
nuclear@14
|
942 for (i = 0; i < 2 && png_ptr->pass == 4; i++)
|
nuclear@14
|
943 {
|
nuclear@14
|
944 png_push_have_row(png_ptr, png_bytep_NULL);
|
nuclear@14
|
945 png_read_push_finish_row(png_ptr);
|
nuclear@14
|
946 }
|
nuclear@14
|
947 if (png_ptr->pass == 6) /* pass 5 might be empty */
|
nuclear@14
|
948 {
|
nuclear@14
|
949 png_push_have_row(png_ptr, png_bytep_NULL);
|
nuclear@14
|
950 png_read_push_finish_row(png_ptr);
|
nuclear@14
|
951 }
|
nuclear@14
|
952 break;
|
nuclear@14
|
953 }
|
nuclear@14
|
954 case 5:
|
nuclear@14
|
955 {
|
nuclear@14
|
956 int i;
|
nuclear@14
|
957 for (i = 0; i < 2 && png_ptr->pass == 5; i++)
|
nuclear@14
|
958 {
|
nuclear@14
|
959 png_push_have_row(png_ptr, png_ptr->row_buf + 1);
|
nuclear@14
|
960 png_read_push_finish_row(png_ptr);
|
nuclear@14
|
961 }
|
nuclear@14
|
962 if (png_ptr->pass == 6) /* skip top generated row */
|
nuclear@14
|
963 {
|
nuclear@14
|
964 png_push_have_row(png_ptr, png_bytep_NULL);
|
nuclear@14
|
965 png_read_push_finish_row(png_ptr);
|
nuclear@14
|
966 }
|
nuclear@14
|
967 break;
|
nuclear@14
|
968 }
|
nuclear@14
|
969 case 6:
|
nuclear@14
|
970 {
|
nuclear@14
|
971 png_push_have_row(png_ptr, png_ptr->row_buf + 1);
|
nuclear@14
|
972 png_read_push_finish_row(png_ptr);
|
nuclear@14
|
973 if (png_ptr->pass != 6)
|
nuclear@14
|
974 break;
|
nuclear@14
|
975 png_push_have_row(png_ptr, png_bytep_NULL);
|
nuclear@14
|
976 png_read_push_finish_row(png_ptr);
|
nuclear@14
|
977 }
|
nuclear@14
|
978 }
|
nuclear@14
|
979 }
|
nuclear@14
|
980 else
|
nuclear@14
|
981 #endif
|
nuclear@14
|
982 {
|
nuclear@14
|
983 png_push_have_row(png_ptr, png_ptr->row_buf + 1);
|
nuclear@14
|
984 png_read_push_finish_row(png_ptr);
|
nuclear@14
|
985 }
|
nuclear@14
|
986 }
|
nuclear@14
|
987
|
nuclear@14
|
988 void /* PRIVATE */
|
nuclear@14
|
989 png_read_push_finish_row(png_structp png_ptr)
|
nuclear@14
|
990 {
|
nuclear@14
|
991 #ifdef PNG_USE_LOCAL_ARRAYS
|
nuclear@14
|
992 /* arrays to facilitate easy interlacing - use pass (0 - 6) as index */
|
nuclear@14
|
993
|
nuclear@14
|
994 /* start of interlace block */
|
nuclear@14
|
995 PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
|
nuclear@14
|
996
|
nuclear@14
|
997 /* offset to next interlace block */
|
nuclear@14
|
998 PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
|
nuclear@14
|
999
|
nuclear@14
|
1000 /* start of interlace block in the y direction */
|
nuclear@14
|
1001 PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
|
nuclear@14
|
1002
|
nuclear@14
|
1003 /* offset to next interlace block in the y direction */
|
nuclear@14
|
1004 PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
|
nuclear@14
|
1005
|
nuclear@14
|
1006 /* Height of interlace block. This is not currently used - if you need
|
nuclear@14
|
1007 * it, uncomment it here and in png.h
|
nuclear@14
|
1008 PNG_CONST int FARDATA png_pass_height[] = {8, 8, 4, 4, 2, 2, 1};
|
nuclear@14
|
1009 */
|
nuclear@14
|
1010 #endif
|
nuclear@14
|
1011
|
nuclear@14
|
1012 png_ptr->row_number++;
|
nuclear@14
|
1013 if (png_ptr->row_number < png_ptr->num_rows)
|
nuclear@14
|
1014 return;
|
nuclear@14
|
1015
|
nuclear@14
|
1016 if (png_ptr->interlaced)
|
nuclear@14
|
1017 {
|
nuclear@14
|
1018 png_ptr->row_number = 0;
|
nuclear@14
|
1019 png_memset_check(png_ptr, png_ptr->prev_row, 0,
|
nuclear@14
|
1020 png_ptr->rowbytes + 1);
|
nuclear@14
|
1021 do
|
nuclear@14
|
1022 {
|
nuclear@14
|
1023 png_ptr->pass++;
|
nuclear@14
|
1024 if ((png_ptr->pass == 1 && png_ptr->width < 5) ||
|
nuclear@14
|
1025 (png_ptr->pass == 3 && png_ptr->width < 3) ||
|
nuclear@14
|
1026 (png_ptr->pass == 5 && png_ptr->width < 2))
|
nuclear@14
|
1027 png_ptr->pass++;
|
nuclear@14
|
1028
|
nuclear@14
|
1029 if (png_ptr->pass > 7)
|
nuclear@14
|
1030 png_ptr->pass--;
|
nuclear@14
|
1031 if (png_ptr->pass >= 7)
|
nuclear@14
|
1032 break;
|
nuclear@14
|
1033
|
nuclear@14
|
1034 png_ptr->iwidth = (png_ptr->width +
|
nuclear@14
|
1035 png_pass_inc[png_ptr->pass] - 1 -
|
nuclear@14
|
1036 png_pass_start[png_ptr->pass]) /
|
nuclear@14
|
1037 png_pass_inc[png_ptr->pass];
|
nuclear@14
|
1038
|
nuclear@14
|
1039 png_ptr->irowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,
|
nuclear@14
|
1040 png_ptr->iwidth) + 1;
|
nuclear@14
|
1041
|
nuclear@14
|
1042 if (png_ptr->transformations & PNG_INTERLACE)
|
nuclear@14
|
1043 break;
|
nuclear@14
|
1044
|
nuclear@14
|
1045 png_ptr->num_rows = (png_ptr->height +
|
nuclear@14
|
1046 png_pass_yinc[png_ptr->pass] - 1 -
|
nuclear@14
|
1047 png_pass_ystart[png_ptr->pass]) /
|
nuclear@14
|
1048 png_pass_yinc[png_ptr->pass];
|
nuclear@14
|
1049
|
nuclear@14
|
1050 } while (png_ptr->iwidth == 0 || png_ptr->num_rows == 0);
|
nuclear@14
|
1051 }
|
nuclear@14
|
1052 }
|
nuclear@14
|
1053
|
nuclear@14
|
1054 #if defined(PNG_READ_tEXt_SUPPORTED)
|
nuclear@14
|
1055 void /* PRIVATE */
|
nuclear@14
|
1056 png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
|
nuclear@14
|
1057 length)
|
nuclear@14
|
1058 {
|
nuclear@14
|
1059 if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
|
nuclear@14
|
1060 {
|
nuclear@14
|
1061 png_error(png_ptr, "Out of place tEXt");
|
nuclear@14
|
1062 info_ptr = info_ptr; /* to quiet some compiler warnings */
|
nuclear@14
|
1063 }
|
nuclear@14
|
1064
|
nuclear@14
|
1065 #ifdef PNG_MAX_MALLOC_64K
|
nuclear@14
|
1066 png_ptr->skip_length = 0; /* This may not be necessary */
|
nuclear@14
|
1067
|
nuclear@14
|
1068 if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */
|
nuclear@14
|
1069 {
|
nuclear@14
|
1070 png_warning(png_ptr, "tEXt chunk too large to fit in memory");
|
nuclear@14
|
1071 png_ptr->skip_length = length - (png_uint_32)65535L;
|
nuclear@14
|
1072 length = (png_uint_32)65535L;
|
nuclear@14
|
1073 }
|
nuclear@14
|
1074 #endif
|
nuclear@14
|
1075
|
nuclear@14
|
1076 png_ptr->current_text = (png_charp)png_malloc(png_ptr,
|
nuclear@14
|
1077 (png_uint_32)(length + 1));
|
nuclear@14
|
1078 png_ptr->current_text[length] = '\0';
|
nuclear@14
|
1079 png_ptr->current_text_ptr = png_ptr->current_text;
|
nuclear@14
|
1080 png_ptr->current_text_size = (png_size_t)length;
|
nuclear@14
|
1081 png_ptr->current_text_left = (png_size_t)length;
|
nuclear@14
|
1082 png_ptr->process_mode = PNG_READ_tEXt_MODE;
|
nuclear@14
|
1083 }
|
nuclear@14
|
1084
|
nuclear@14
|
1085 void /* PRIVATE */
|
nuclear@14
|
1086 png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr)
|
nuclear@14
|
1087 {
|
nuclear@14
|
1088 if (png_ptr->buffer_size && png_ptr->current_text_left)
|
nuclear@14
|
1089 {
|
nuclear@14
|
1090 png_size_t text_size;
|
nuclear@14
|
1091
|
nuclear@14
|
1092 if (png_ptr->buffer_size < png_ptr->current_text_left)
|
nuclear@14
|
1093 text_size = png_ptr->buffer_size;
|
nuclear@14
|
1094 else
|
nuclear@14
|
1095 text_size = png_ptr->current_text_left;
|
nuclear@14
|
1096 png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
|
nuclear@14
|
1097 png_ptr->current_text_left -= text_size;
|
nuclear@14
|
1098 png_ptr->current_text_ptr += text_size;
|
nuclear@14
|
1099 }
|
nuclear@14
|
1100 if (!(png_ptr->current_text_left))
|
nuclear@14
|
1101 {
|
nuclear@14
|
1102 png_textp text_ptr;
|
nuclear@14
|
1103 png_charp text;
|
nuclear@14
|
1104 png_charp key;
|
nuclear@14
|
1105 int ret;
|
nuclear@14
|
1106
|
nuclear@14
|
1107 if (png_ptr->buffer_size < 4)
|
nuclear@14
|
1108 {
|
nuclear@14
|
1109 png_push_save_buffer(png_ptr);
|
nuclear@14
|
1110 return;
|
nuclear@14
|
1111 }
|
nuclear@14
|
1112
|
nuclear@14
|
1113 png_push_crc_finish(png_ptr);
|
nuclear@14
|
1114
|
nuclear@14
|
1115 #if defined(PNG_MAX_MALLOC_64K)
|
nuclear@14
|
1116 if (png_ptr->skip_length)
|
nuclear@14
|
1117 return;
|
nuclear@14
|
1118 #endif
|
nuclear@14
|
1119
|
nuclear@14
|
1120 key = png_ptr->current_text;
|
nuclear@14
|
1121
|
nuclear@14
|
1122 for (text = key; *text; text++)
|
nuclear@14
|
1123 /* empty loop */ ;
|
nuclear@14
|
1124
|
nuclear@14
|
1125 if (text < key + png_ptr->current_text_size)
|
nuclear@14
|
1126 text++;
|
nuclear@14
|
1127
|
nuclear@14
|
1128 text_ptr = (png_textp)png_malloc(png_ptr,
|
nuclear@14
|
1129 (png_uint_32)png_sizeof(png_text));
|
nuclear@14
|
1130 text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
|
nuclear@14
|
1131 text_ptr->key = key;
|
nuclear@14
|
1132 #ifdef PNG_iTXt_SUPPORTED
|
nuclear@14
|
1133 text_ptr->lang = NULL;
|
nuclear@14
|
1134 text_ptr->lang_key = NULL;
|
nuclear@14
|
1135 #endif
|
nuclear@14
|
1136 text_ptr->text = text;
|
nuclear@14
|
1137
|
nuclear@14
|
1138 ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
|
nuclear@14
|
1139
|
nuclear@14
|
1140 png_free(png_ptr, key);
|
nuclear@14
|
1141 png_free(png_ptr, text_ptr);
|
nuclear@14
|
1142 png_ptr->current_text = NULL;
|
nuclear@14
|
1143
|
nuclear@14
|
1144 if (ret)
|
nuclear@14
|
1145 png_warning(png_ptr, "Insufficient memory to store text chunk.");
|
nuclear@14
|
1146 }
|
nuclear@14
|
1147 }
|
nuclear@14
|
1148 #endif
|
nuclear@14
|
1149
|
nuclear@14
|
1150 #if defined(PNG_READ_zTXt_SUPPORTED)
|
nuclear@14
|
1151 void /* PRIVATE */
|
nuclear@14
|
1152 png_push_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
|
nuclear@14
|
1153 length)
|
nuclear@14
|
1154 {
|
nuclear@14
|
1155 if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
|
nuclear@14
|
1156 {
|
nuclear@14
|
1157 png_error(png_ptr, "Out of place zTXt");
|
nuclear@14
|
1158 info_ptr = info_ptr; /* to quiet some compiler warnings */
|
nuclear@14
|
1159 }
|
nuclear@14
|
1160
|
nuclear@14
|
1161 #ifdef PNG_MAX_MALLOC_64K
|
nuclear@14
|
1162 /* We can't handle zTXt chunks > 64K, since we don't have enough space
|
nuclear@14
|
1163 * to be able to store the uncompressed data. Actually, the threshold
|
nuclear@14
|
1164 * is probably around 32K, but it isn't as definite as 64K is.
|
nuclear@14
|
1165 */
|
nuclear@14
|
1166 if (length > (png_uint_32)65535L)
|
nuclear@14
|
1167 {
|
nuclear@14
|
1168 png_warning(png_ptr, "zTXt chunk too large to fit in memory");
|
nuclear@14
|
1169 png_push_crc_skip(png_ptr, length);
|
nuclear@14
|
1170 return;
|
nuclear@14
|
1171 }
|
nuclear@14
|
1172 #endif
|
nuclear@14
|
1173
|
nuclear@14
|
1174 png_ptr->current_text = (png_charp)png_malloc(png_ptr,
|
nuclear@14
|
1175 (png_uint_32)(length + 1));
|
nuclear@14
|
1176 png_ptr->current_text[length] = '\0';
|
nuclear@14
|
1177 png_ptr->current_text_ptr = png_ptr->current_text;
|
nuclear@14
|
1178 png_ptr->current_text_size = (png_size_t)length;
|
nuclear@14
|
1179 png_ptr->current_text_left = (png_size_t)length;
|
nuclear@14
|
1180 png_ptr->process_mode = PNG_READ_zTXt_MODE;
|
nuclear@14
|
1181 }
|
nuclear@14
|
1182
|
nuclear@14
|
1183 void /* PRIVATE */
|
nuclear@14
|
1184 png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
|
nuclear@14
|
1185 {
|
nuclear@14
|
1186 if (png_ptr->buffer_size && png_ptr->current_text_left)
|
nuclear@14
|
1187 {
|
nuclear@14
|
1188 png_size_t text_size;
|
nuclear@14
|
1189
|
nuclear@14
|
1190 if (png_ptr->buffer_size < (png_uint_32)png_ptr->current_text_left)
|
nuclear@14
|
1191 text_size = png_ptr->buffer_size;
|
nuclear@14
|
1192 else
|
nuclear@14
|
1193 text_size = png_ptr->current_text_left;
|
nuclear@14
|
1194 png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
|
nuclear@14
|
1195 png_ptr->current_text_left -= text_size;
|
nuclear@14
|
1196 png_ptr->current_text_ptr += text_size;
|
nuclear@14
|
1197 }
|
nuclear@14
|
1198 if (!(png_ptr->current_text_left))
|
nuclear@14
|
1199 {
|
nuclear@14
|
1200 png_textp text_ptr;
|
nuclear@14
|
1201 png_charp text;
|
nuclear@14
|
1202 png_charp key;
|
nuclear@14
|
1203 int ret;
|
nuclear@14
|
1204 png_size_t text_size, key_size;
|
nuclear@14
|
1205
|
nuclear@14
|
1206 if (png_ptr->buffer_size < 4)
|
nuclear@14
|
1207 {
|
nuclear@14
|
1208 png_push_save_buffer(png_ptr);
|
nuclear@14
|
1209 return;
|
nuclear@14
|
1210 }
|
nuclear@14
|
1211
|
nuclear@14
|
1212 png_push_crc_finish(png_ptr);
|
nuclear@14
|
1213
|
nuclear@14
|
1214 key = png_ptr->current_text;
|
nuclear@14
|
1215
|
nuclear@14
|
1216 for (text = key; *text; text++)
|
nuclear@14
|
1217 /* empty loop */ ;
|
nuclear@14
|
1218
|
nuclear@14
|
1219 /* zTXt can't have zero text */
|
nuclear@14
|
1220 if (text >= key + png_ptr->current_text_size)
|
nuclear@14
|
1221 {
|
nuclear@14
|
1222 png_ptr->current_text = NULL;
|
nuclear@14
|
1223 png_free(png_ptr, key);
|
nuclear@14
|
1224 return;
|
nuclear@14
|
1225 }
|
nuclear@14
|
1226
|
nuclear@14
|
1227 text++;
|
nuclear@14
|
1228
|
nuclear@14
|
1229 if (*text != PNG_TEXT_COMPRESSION_zTXt) /* check compression byte */
|
nuclear@14
|
1230 {
|
nuclear@14
|
1231 png_ptr->current_text = NULL;
|
nuclear@14
|
1232 png_free(png_ptr, key);
|
nuclear@14
|
1233 return;
|
nuclear@14
|
1234 }
|
nuclear@14
|
1235
|
nuclear@14
|
1236 text++;
|
nuclear@14
|
1237
|
nuclear@14
|
1238 png_ptr->zstream.next_in = (png_bytep )text;
|
nuclear@14
|
1239 png_ptr->zstream.avail_in = (uInt)(png_ptr->current_text_size -
|
nuclear@14
|
1240 (text - key));
|
nuclear@14
|
1241 png_ptr->zstream.next_out = png_ptr->zbuf;
|
nuclear@14
|
1242 png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
|
nuclear@14
|
1243
|
nuclear@14
|
1244 key_size = text - key;
|
nuclear@14
|
1245 text_size = 0;
|
nuclear@14
|
1246 text = NULL;
|
nuclear@14
|
1247 ret = Z_STREAM_END;
|
nuclear@14
|
1248
|
nuclear@14
|
1249 while (png_ptr->zstream.avail_in)
|
nuclear@14
|
1250 {
|
nuclear@14
|
1251 ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
|
nuclear@14
|
1252 if (ret != Z_OK && ret != Z_STREAM_END)
|
nuclear@14
|
1253 {
|
nuclear@14
|
1254 inflateReset(&png_ptr->zstream);
|
nuclear@14
|
1255 png_ptr->zstream.avail_in = 0;
|
nuclear@14
|
1256 png_ptr->current_text = NULL;
|
nuclear@14
|
1257 png_free(png_ptr, key);
|
nuclear@14
|
1258 png_free(png_ptr, text);
|
nuclear@14
|
1259 return;
|
nuclear@14
|
1260 }
|
nuclear@14
|
1261 if (!(png_ptr->zstream.avail_out) || ret == Z_STREAM_END)
|
nuclear@14
|
1262 {
|
nuclear@14
|
1263 if (text == NULL)
|
nuclear@14
|
1264 {
|
nuclear@14
|
1265 text = (png_charp)png_malloc(png_ptr,
|
nuclear@14
|
1266 (png_uint_32)(png_ptr->zbuf_size
|
nuclear@14
|
1267 - png_ptr->zstream.avail_out + key_size + 1));
|
nuclear@14
|
1268 png_memcpy(text + key_size, png_ptr->zbuf,
|
nuclear@14
|
1269 png_ptr->zbuf_size - png_ptr->zstream.avail_out);
|
nuclear@14
|
1270 png_memcpy(text, key, key_size);
|
nuclear@14
|
1271 text_size = key_size + png_ptr->zbuf_size -
|
nuclear@14
|
1272 png_ptr->zstream.avail_out;
|
nuclear@14
|
1273 *(text + text_size) = '\0';
|
nuclear@14
|
1274 }
|
nuclear@14
|
1275 else
|
nuclear@14
|
1276 {
|
nuclear@14
|
1277 png_charp tmp;
|
nuclear@14
|
1278
|
nuclear@14
|
1279 tmp = text;
|
nuclear@14
|
1280 text = (png_charp)png_malloc(png_ptr, text_size +
|
nuclear@14
|
1281 (png_uint_32)(png_ptr->zbuf_size
|
nuclear@14
|
1282 - png_ptr->zstream.avail_out + 1));
|
nuclear@14
|
1283 png_memcpy(text, tmp, text_size);
|
nuclear@14
|
1284 png_free(png_ptr, tmp);
|
nuclear@14
|
1285 png_memcpy(text + text_size, png_ptr->zbuf,
|
nuclear@14
|
1286 png_ptr->zbuf_size - png_ptr->zstream.avail_out);
|
nuclear@14
|
1287 text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out;
|
nuclear@14
|
1288 *(text + text_size) = '\0';
|
nuclear@14
|
1289 }
|
nuclear@14
|
1290 if (ret != Z_STREAM_END)
|
nuclear@14
|
1291 {
|
nuclear@14
|
1292 png_ptr->zstream.next_out = png_ptr->zbuf;
|
nuclear@14
|
1293 png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
|
nuclear@14
|
1294 }
|
nuclear@14
|
1295 }
|
nuclear@14
|
1296 else
|
nuclear@14
|
1297 {
|
nuclear@14
|
1298 break;
|
nuclear@14
|
1299 }
|
nuclear@14
|
1300
|
nuclear@14
|
1301 if (ret == Z_STREAM_END)
|
nuclear@14
|
1302 break;
|
nuclear@14
|
1303 }
|
nuclear@14
|
1304
|
nuclear@14
|
1305 inflateReset(&png_ptr->zstream);
|
nuclear@14
|
1306 png_ptr->zstream.avail_in = 0;
|
nuclear@14
|
1307
|
nuclear@14
|
1308 if (ret != Z_STREAM_END)
|
nuclear@14
|
1309 {
|
nuclear@14
|
1310 png_ptr->current_text = NULL;
|
nuclear@14
|
1311 png_free(png_ptr, key);
|
nuclear@14
|
1312 png_free(png_ptr, text);
|
nuclear@14
|
1313 return;
|
nuclear@14
|
1314 }
|
nuclear@14
|
1315
|
nuclear@14
|
1316 png_ptr->current_text = NULL;
|
nuclear@14
|
1317 png_free(png_ptr, key);
|
nuclear@14
|
1318 key = text;
|
nuclear@14
|
1319 text += key_size;
|
nuclear@14
|
1320
|
nuclear@14
|
1321 text_ptr = (png_textp)png_malloc(png_ptr,
|
nuclear@14
|
1322 (png_uint_32)png_sizeof(png_text));
|
nuclear@14
|
1323 text_ptr->compression = PNG_TEXT_COMPRESSION_zTXt;
|
nuclear@14
|
1324 text_ptr->key = key;
|
nuclear@14
|
1325 #ifdef PNG_iTXt_SUPPORTED
|
nuclear@14
|
1326 text_ptr->lang = NULL;
|
nuclear@14
|
1327 text_ptr->lang_key = NULL;
|
nuclear@14
|
1328 #endif
|
nuclear@14
|
1329 text_ptr->text = text;
|
nuclear@14
|
1330
|
nuclear@14
|
1331 ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
|
nuclear@14
|
1332
|
nuclear@14
|
1333 png_free(png_ptr, key);
|
nuclear@14
|
1334 png_free(png_ptr, text_ptr);
|
nuclear@14
|
1335
|
nuclear@14
|
1336 if (ret)
|
nuclear@14
|
1337 png_warning(png_ptr, "Insufficient memory to store text chunk.");
|
nuclear@14
|
1338 }
|
nuclear@14
|
1339 }
|
nuclear@14
|
1340 #endif
|
nuclear@14
|
1341
|
nuclear@14
|
1342 #if defined(PNG_READ_iTXt_SUPPORTED)
|
nuclear@14
|
1343 void /* PRIVATE */
|
nuclear@14
|
1344 png_push_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
|
nuclear@14
|
1345 length)
|
nuclear@14
|
1346 {
|
nuclear@14
|
1347 if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
|
nuclear@14
|
1348 {
|
nuclear@14
|
1349 png_error(png_ptr, "Out of place iTXt");
|
nuclear@14
|
1350 info_ptr = info_ptr; /* to quiet some compiler warnings */
|
nuclear@14
|
1351 }
|
nuclear@14
|
1352
|
nuclear@14
|
1353 #ifdef PNG_MAX_MALLOC_64K
|
nuclear@14
|
1354 png_ptr->skip_length = 0; /* This may not be necessary */
|
nuclear@14
|
1355
|
nuclear@14
|
1356 if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */
|
nuclear@14
|
1357 {
|
nuclear@14
|
1358 png_warning(png_ptr, "iTXt chunk too large to fit in memory");
|
nuclear@14
|
1359 png_ptr->skip_length = length - (png_uint_32)65535L;
|
nuclear@14
|
1360 length = (png_uint_32)65535L;
|
nuclear@14
|
1361 }
|
nuclear@14
|
1362 #endif
|
nuclear@14
|
1363
|
nuclear@14
|
1364 png_ptr->current_text = (png_charp)png_malloc(png_ptr,
|
nuclear@14
|
1365 (png_uint_32)(length + 1));
|
nuclear@14
|
1366 png_ptr->current_text[length] = '\0';
|
nuclear@14
|
1367 png_ptr->current_text_ptr = png_ptr->current_text;
|
nuclear@14
|
1368 png_ptr->current_text_size = (png_size_t)length;
|
nuclear@14
|
1369 png_ptr->current_text_left = (png_size_t)length;
|
nuclear@14
|
1370 png_ptr->process_mode = PNG_READ_iTXt_MODE;
|
nuclear@14
|
1371 }
|
nuclear@14
|
1372
|
nuclear@14
|
1373 void /* PRIVATE */
|
nuclear@14
|
1374 png_push_read_iTXt(png_structp png_ptr, png_infop info_ptr)
|
nuclear@14
|
1375 {
|
nuclear@14
|
1376
|
nuclear@14
|
1377 if (png_ptr->buffer_size && png_ptr->current_text_left)
|
nuclear@14
|
1378 {
|
nuclear@14
|
1379 png_size_t text_size;
|
nuclear@14
|
1380
|
nuclear@14
|
1381 if (png_ptr->buffer_size < png_ptr->current_text_left)
|
nuclear@14
|
1382 text_size = png_ptr->buffer_size;
|
nuclear@14
|
1383 else
|
nuclear@14
|
1384 text_size = png_ptr->current_text_left;
|
nuclear@14
|
1385 png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
|
nuclear@14
|
1386 png_ptr->current_text_left -= text_size;
|
nuclear@14
|
1387 png_ptr->current_text_ptr += text_size;
|
nuclear@14
|
1388 }
|
nuclear@14
|
1389 if (!(png_ptr->current_text_left))
|
nuclear@14
|
1390 {
|
nuclear@14
|
1391 png_textp text_ptr;
|
nuclear@14
|
1392 png_charp key;
|
nuclear@14
|
1393 int comp_flag;
|
nuclear@14
|
1394 png_charp lang;
|
nuclear@14
|
1395 png_charp lang_key;
|
nuclear@14
|
1396 png_charp text;
|
nuclear@14
|
1397 int ret;
|
nuclear@14
|
1398
|
nuclear@14
|
1399 if (png_ptr->buffer_size < 4)
|
nuclear@14
|
1400 {
|
nuclear@14
|
1401 png_push_save_buffer(png_ptr);
|
nuclear@14
|
1402 return;
|
nuclear@14
|
1403 }
|
nuclear@14
|
1404
|
nuclear@14
|
1405 png_push_crc_finish(png_ptr);
|
nuclear@14
|
1406
|
nuclear@14
|
1407 #if defined(PNG_MAX_MALLOC_64K)
|
nuclear@14
|
1408 if (png_ptr->skip_length)
|
nuclear@14
|
1409 return;
|
nuclear@14
|
1410 #endif
|
nuclear@14
|
1411
|
nuclear@14
|
1412 key = png_ptr->current_text;
|
nuclear@14
|
1413
|
nuclear@14
|
1414 for (lang = key; *lang; lang++)
|
nuclear@14
|
1415 /* empty loop */ ;
|
nuclear@14
|
1416
|
nuclear@14
|
1417 if (lang < key + png_ptr->current_text_size - 3)
|
nuclear@14
|
1418 lang++;
|
nuclear@14
|
1419
|
nuclear@14
|
1420 comp_flag = *lang++;
|
nuclear@14
|
1421 lang++; /* skip comp_type, always zero */
|
nuclear@14
|
1422
|
nuclear@14
|
1423 for (lang_key = lang; *lang_key; lang_key++)
|
nuclear@14
|
1424 /* empty loop */ ;
|
nuclear@14
|
1425 lang_key++; /* skip NUL separator */
|
nuclear@14
|
1426
|
nuclear@14
|
1427 text=lang_key;
|
nuclear@14
|
1428 if (lang_key < key + png_ptr->current_text_size - 1)
|
nuclear@14
|
1429 {
|
nuclear@14
|
1430 for (; *text; text++)
|
nuclear@14
|
1431 /* empty loop */ ;
|
nuclear@14
|
1432 }
|
nuclear@14
|
1433
|
nuclear@14
|
1434 if (text < key + png_ptr->current_text_size)
|
nuclear@14
|
1435 text++;
|
nuclear@14
|
1436
|
nuclear@14
|
1437 text_ptr = (png_textp)png_malloc(png_ptr,
|
nuclear@14
|
1438 (png_uint_32)png_sizeof(png_text));
|
nuclear@14
|
1439 text_ptr->compression = comp_flag + 2;
|
nuclear@14
|
1440 text_ptr->key = key;
|
nuclear@14
|
1441 text_ptr->lang = lang;
|
nuclear@14
|
1442 text_ptr->lang_key = lang_key;
|
nuclear@14
|
1443 text_ptr->text = text;
|
nuclear@14
|
1444 text_ptr->text_length = 0;
|
nuclear@14
|
1445 text_ptr->itxt_length = png_strlen(text);
|
nuclear@14
|
1446
|
nuclear@14
|
1447 ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
|
nuclear@14
|
1448
|
nuclear@14
|
1449 png_ptr->current_text = NULL;
|
nuclear@14
|
1450
|
nuclear@14
|
1451 png_free(png_ptr, text_ptr);
|
nuclear@14
|
1452 if (ret)
|
nuclear@14
|
1453 png_warning(png_ptr, "Insufficient memory to store iTXt chunk.");
|
nuclear@14
|
1454 }
|
nuclear@14
|
1455 }
|
nuclear@14
|
1456 #endif
|
nuclear@14
|
1457
|
nuclear@14
|
1458 /* This function is called when we haven't found a handler for this
|
nuclear@14
|
1459 * chunk. If there isn't a problem with the chunk itself (ie a bad chunk
|
nuclear@14
|
1460 * name or a critical chunk), the chunk is (currently) silently ignored.
|
nuclear@14
|
1461 */
|
nuclear@14
|
1462 void /* PRIVATE */
|
nuclear@14
|
1463 png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32
|
nuclear@14
|
1464 length)
|
nuclear@14
|
1465 {
|
nuclear@14
|
1466 png_uint_32 skip = 0;
|
nuclear@14
|
1467
|
nuclear@14
|
1468 if (!(png_ptr->chunk_name[0] & 0x20))
|
nuclear@14
|
1469 {
|
nuclear@14
|
1470 #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
|
nuclear@14
|
1471 if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
|
nuclear@14
|
1472 PNG_HANDLE_CHUNK_ALWAYS
|
nuclear@14
|
1473 #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
|
nuclear@14
|
1474 && png_ptr->read_user_chunk_fn == NULL
|
nuclear@14
|
1475 #endif
|
nuclear@14
|
1476 )
|
nuclear@14
|
1477 #endif
|
nuclear@14
|
1478 png_chunk_error(png_ptr, "unknown critical chunk");
|
nuclear@14
|
1479
|
nuclear@14
|
1480 info_ptr = info_ptr; /* to quiet some compiler warnings */
|
nuclear@14
|
1481 }
|
nuclear@14
|
1482
|
nuclear@14
|
1483 #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
|
nuclear@14
|
1484 if (png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS)
|
nuclear@14
|
1485 {
|
nuclear@14
|
1486 #ifdef PNG_MAX_MALLOC_64K
|
nuclear@14
|
1487 if (length > (png_uint_32)65535L)
|
nuclear@14
|
1488 {
|
nuclear@14
|
1489 png_warning(png_ptr, "unknown chunk too large to fit in memory");
|
nuclear@14
|
1490 skip = length - (png_uint_32)65535L;
|
nuclear@14
|
1491 length = (png_uint_32)65535L;
|
nuclear@14
|
1492 }
|
nuclear@14
|
1493 #endif
|
nuclear@14
|
1494 png_memcpy((png_charp)png_ptr->unknown_chunk.name,
|
nuclear@14
|
1495 (png_charp)png_ptr->chunk_name,
|
nuclear@14
|
1496 png_sizeof(png_ptr->unknown_chunk.name));
|
nuclear@14
|
1497 png_ptr->unknown_chunk.name[png_sizeof(png_ptr->unknown_chunk.name) - 1]
|
nuclear@14
|
1498 = '\0';
|
nuclear@14
|
1499
|
nuclear@14
|
1500 png_ptr->unknown_chunk.size = (png_size_t)length;
|
nuclear@14
|
1501 if (length == 0)
|
nuclear@14
|
1502 png_ptr->unknown_chunk.data = NULL;
|
nuclear@14
|
1503 else
|
nuclear@14
|
1504 {
|
nuclear@14
|
1505 png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr,
|
nuclear@14
|
1506 (png_uint_32)length);
|
nuclear@14
|
1507 png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
|
nuclear@14
|
1508 }
|
nuclear@14
|
1509 #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
|
nuclear@14
|
1510 if (png_ptr->read_user_chunk_fn != NULL)
|
nuclear@14
|
1511 {
|
nuclear@14
|
1512 /* callback to user unknown chunk handler */
|
nuclear@14
|
1513 int ret;
|
nuclear@14
|
1514 ret = (*(png_ptr->read_user_chunk_fn))
|
nuclear@14
|
1515 (png_ptr, &png_ptr->unknown_chunk);
|
nuclear@14
|
1516 if (ret < 0)
|
nuclear@14
|
1517 png_chunk_error(png_ptr, "error in user chunk");
|
nuclear@14
|
1518 if (ret == 0)
|
nuclear@14
|
1519 {
|
nuclear@14
|
1520 if (!(png_ptr->chunk_name[0] & 0x20))
|
nuclear@14
|
1521 if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
|
nuclear@14
|
1522 PNG_HANDLE_CHUNK_ALWAYS)
|
nuclear@14
|
1523 png_chunk_error(png_ptr, "unknown critical chunk");
|
nuclear@14
|
1524 png_set_unknown_chunks(png_ptr, info_ptr,
|
nuclear@14
|
1525 &png_ptr->unknown_chunk, 1);
|
nuclear@14
|
1526 }
|
nuclear@14
|
1527 }
|
nuclear@14
|
1528 else
|
nuclear@14
|
1529 #endif
|
nuclear@14
|
1530 png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
|
nuclear@14
|
1531 png_free(png_ptr, png_ptr->unknown_chunk.data);
|
nuclear@14
|
1532 png_ptr->unknown_chunk.data = NULL;
|
nuclear@14
|
1533 }
|
nuclear@14
|
1534 else
|
nuclear@14
|
1535 #endif
|
nuclear@14
|
1536 skip=length;
|
nuclear@14
|
1537 png_push_crc_skip(png_ptr, skip);
|
nuclear@14
|
1538 }
|
nuclear@14
|
1539
|
nuclear@14
|
1540 void /* PRIVATE */
|
nuclear@14
|
1541 png_push_have_info(png_structp png_ptr, png_infop info_ptr)
|
nuclear@14
|
1542 {
|
nuclear@14
|
1543 if (png_ptr->info_fn != NULL)
|
nuclear@14
|
1544 (*(png_ptr->info_fn))(png_ptr, info_ptr);
|
nuclear@14
|
1545 }
|
nuclear@14
|
1546
|
nuclear@14
|
1547 void /* PRIVATE */
|
nuclear@14
|
1548 png_push_have_end(png_structp png_ptr, png_infop info_ptr)
|
nuclear@14
|
1549 {
|
nuclear@14
|
1550 if (png_ptr->end_fn != NULL)
|
nuclear@14
|
1551 (*(png_ptr->end_fn))(png_ptr, info_ptr);
|
nuclear@14
|
1552 }
|
nuclear@14
|
1553
|
nuclear@14
|
1554 void /* PRIVATE */
|
nuclear@14
|
1555 png_push_have_row(png_structp png_ptr, png_bytep row)
|
nuclear@14
|
1556 {
|
nuclear@14
|
1557 if (png_ptr->row_fn != NULL)
|
nuclear@14
|
1558 (*(png_ptr->row_fn))(png_ptr, row, png_ptr->row_number,
|
nuclear@14
|
1559 (int)png_ptr->pass);
|
nuclear@14
|
1560 }
|
nuclear@14
|
1561
|
nuclear@14
|
1562 void PNGAPI
|
nuclear@14
|
1563 png_progressive_combine_row (png_structp png_ptr,
|
nuclear@14
|
1564 png_bytep old_row, png_bytep new_row)
|
nuclear@14
|
1565 {
|
nuclear@14
|
1566 #ifdef PNG_USE_LOCAL_ARRAYS
|
nuclear@14
|
1567 PNG_CONST int FARDATA png_pass_dsp_mask[7] =
|
nuclear@14
|
1568 {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
|
nuclear@14
|
1569 #endif
|
nuclear@14
|
1570 if (png_ptr == NULL) return;
|
nuclear@14
|
1571 if (new_row != NULL) /* new_row must == png_ptr->row_buf here. */
|
nuclear@14
|
1572 png_combine_row(png_ptr, old_row, png_pass_dsp_mask[png_ptr->pass]);
|
nuclear@14
|
1573 }
|
nuclear@14
|
1574
|
nuclear@14
|
1575 void PNGAPI
|
nuclear@14
|
1576 png_set_progressive_read_fn(png_structp png_ptr, png_voidp progressive_ptr,
|
nuclear@14
|
1577 png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
|
nuclear@14
|
1578 png_progressive_end_ptr end_fn)
|
nuclear@14
|
1579 {
|
nuclear@14
|
1580 if (png_ptr == NULL) return;
|
nuclear@14
|
1581 png_ptr->info_fn = info_fn;
|
nuclear@14
|
1582 png_ptr->row_fn = row_fn;
|
nuclear@14
|
1583 png_ptr->end_fn = end_fn;
|
nuclear@14
|
1584
|
nuclear@14
|
1585 png_set_read_fn(png_ptr, progressive_ptr, png_push_fill_buffer);
|
nuclear@14
|
1586 }
|
nuclear@14
|
1587
|
nuclear@14
|
1588 png_voidp PNGAPI
|
nuclear@14
|
1589 png_get_progressive_ptr(png_structp png_ptr)
|
nuclear@14
|
1590 {
|
nuclear@14
|
1591 if (png_ptr == NULL) return (NULL);
|
nuclear@14
|
1592 return png_ptr->io_ptr;
|
nuclear@14
|
1593 }
|
nuclear@14
|
1594 #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
|