Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1897 | serge | 1 | |
2 | * |
||
3 | * Last changed in libpng 1.5.1 [$RDATE%] |
||
4 | * Copyright (c) 1998-2011 Glenn Randers-Pehrson |
||
5 | * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) |
||
6 | * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) |
||
7 | * |
||
8 | * This code is released under the libpng license. |
||
9 | * For conditions of distribution and use, see the disclaimer |
||
10 | * and license in png.h |
||
11 | * |
||
12 | * This file contains routines that an application calls directly to |
||
13 | * read a PNG file or stream. |
||
14 | */ |
||
15 | |||
16 | |||
17 | |||
18 | |||
19 | |||
20 | |||
21 | PNG_FUNCTION(png_structp,PNGAPI |
||
22 | png_create_read_struct,(png_const_charp user_png_ver, png_voidp error_ptr, |
||
23 | png_error_ptr error_fn, png_error_ptr warn_fn),PNG_ALLOCATED) |
||
24 | { |
||
25 | |||
26 | |||
27 | return (png_create_read_struct_2(user_png_ver, error_ptr, error_fn, |
||
28 | warn_fn, NULL, NULL, NULL)); |
||
29 | } |
||
30 | |||
31 | |||
32 | * needed. |
||
33 | */ |
||
34 | PNG_FUNCTION(png_structp,PNGAPI |
||
35 | png_create_read_struct_2,(png_const_charp user_png_ver, png_voidp error_ptr, |
||
36 | png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr, |
||
37 | png_malloc_ptr malloc_fn, png_free_ptr free_fn),PNG_ALLOCATED) |
||
38 | { |
||
39 | #endif /* PNG_USER_MEM_SUPPORTED */ |
||
40 | |||
41 | |||
42 | volatile |
||
43 | #endif |
||
44 | png_structp png_ptr; |
||
45 | volatile int png_cleanup_needed = 0; |
||
46 | |||
47 | |||
48 | #ifdef USE_FAR_KEYWORD |
||
49 | jmp_buf png_jmpbuf; |
||
50 | #endif |
||
51 | #endif |
||
52 | |||
53 | |||
54 | |||
55 | |||
56 | |||
57 | |||
58 | png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG, |
||
59 | malloc_fn, mem_ptr); |
||
60 | #else |
||
61 | png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG); |
||
62 | #endif |
||
63 | if (png_ptr == NULL) |
||
64 | return (NULL); |
||
65 | |||
66 | |||
67 | #ifdef PNG_USER_LIMITS_SUPPORTED |
||
68 | png_ptr->user_width_max = PNG_USER_WIDTH_MAX; |
||
69 | png_ptr->user_height_max = PNG_USER_HEIGHT_MAX; |
||
70 | |||
71 | |||
72 | /* Added at libpng-1.2.43 and 1.4.0 */ |
||
73 | png_ptr->user_chunk_cache_max = PNG_USER_CHUNK_CACHE_MAX; |
||
74 | # endif |
||
75 | |||
76 | |||
77 | /* Added at libpng-1.2.43 and 1.4.1 */ |
||
78 | png_ptr->user_chunk_malloc_max = PNG_USER_CHUNK_MALLOC_MAX; |
||
79 | # endif |
||
80 | #endif |
||
81 | |||
82 | |||
83 | /* Applications that neglect to set up their own setjmp() and then |
||
84 | encounter a png_error() will longjmp here. Since the jmpbuf is |
||
85 | then meaningless we abort instead of returning. */ |
||
86 | #ifdef USE_FAR_KEYWORD |
||
87 | if (setjmp(png_jmpbuf)) |
||
88 | #else |
||
89 | if (setjmp(png_jmpbuf(png_ptr))) /* Sets longjmp to match setjmp */ |
||
90 | #endif |
||
91 | PNG_ABORT(); |
||
92 | #ifdef USE_FAR_KEYWORD |
||
93 | png_memcpy(png_jmpbuf(png_ptr), png_jmpbuf, png_sizeof(jmp_buf)); |
||
94 | #endif |
||
95 | #endif /* PNG_SETJMP_SUPPORTED */ |
||
96 | |||
97 | |||
98 | png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn); |
||
99 | #endif |
||
100 | |||
101 | |||
102 | |||
103 | |||
104 | { |
||
105 | i = 0; |
||
106 | |||
107 | |||
108 | { |
||
109 | if (user_png_ver[i] != png_libpng_ver[i]) |
||
110 | png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH; |
||
111 | } while (png_libpng_ver[i++]); |
||
112 | } |
||
113 | |||
114 | |||
115 | png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH; |
||
116 | |||
117 | |||
118 | |||
119 | { |
||
120 | /* Libpng 0.90 and later are binary incompatible with libpng 0.89, so |
||
121 | * we must recompile any applications that use any older library version. |
||
122 | * For versions after libpng 1.0, we will be compatible, so we need |
||
123 | * only check the first digit. |
||
124 | */ |
||
125 | if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] || |
||
126 | (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) || |
||
127 | (user_png_ver[0] == '0' && user_png_ver[2] < '9')) |
||
128 | { |
||
129 | #ifdef PNG_CONSOLE_IO_SUPPORTED |
||
130 | char msg[80]; |
||
131 | if (user_png_ver) |
||
132 | { |
||
133 | png_snprintf2(msg, 80, |
||
134 | "Application built with libpng-%.20s" |
||
135 | " but running with %.20s", |
||
136 | user_png_ver, |
||
137 | png_libpng_ver); |
||
138 | png_warning(png_ptr, msg); |
||
139 | } |
||
140 | #else |
||
141 | png_warning(png_ptr, |
||
142 | "Incompatible libpng version in application and library"); |
||
143 | #endif |
||
144 | #ifdef PNG_ERROR_NUMBERS_SUPPORTED |
||
145 | png_ptr->flags = 0; |
||
146 | #endif |
||
147 | |||
148 | |||
149 | } |
||
150 | } |
||
151 | |||
152 | |||
153 | { |
||
154 | /* Initialize zbuf - compression buffer */ |
||
155 | png_ptr->zbuf_size = PNG_ZBUF_SIZE; |
||
156 | png_ptr->zbuf = (png_bytep)png_malloc_warn(png_ptr, png_ptr->zbuf_size); |
||
157 | |||
158 | |||
159 | png_cleanup_needed = 1; |
||
160 | } |
||
161 | |||
162 | |||
163 | png_ptr->zstream.zfree = png_zfree; |
||
164 | png_ptr->zstream.opaque = (voidpf)png_ptr; |
||
165 | |||
166 | |||
167 | { |
||
168 | switch (inflateInit(&png_ptr->zstream)) |
||
169 | { |
||
170 | case Z_OK: |
||
171 | break; /* Do nothing */ |
||
172 | |||
173 | |||
174 | png_warning(png_ptr, "zlib memory error"); |
||
175 | png_cleanup_needed = 1; |
||
176 | break; |
||
177 | |||
178 | |||
179 | png_warning(png_ptr, "zlib stream error"); |
||
180 | png_cleanup_needed = 1; |
||
181 | break; |
||
182 | |||
183 | |||
184 | png_warning(png_ptr, "zlib version error"); |
||
185 | png_cleanup_needed = 1; |
||
186 | break; |
||
187 | |||
188 | |||
189 | png_cleanup_needed = 1; |
||
190 | } |
||
191 | } |
||
192 | |||
193 | |||
194 | { |
||
195 | /* Clean up PNG structure and deallocate any memory. */ |
||
196 | png_free(png_ptr, png_ptr->zbuf); |
||
197 | png_ptr->zbuf = NULL; |
||
198 | #ifdef PNG_USER_MEM_SUPPORTED |
||
199 | png_destroy_struct_2((png_voidp)png_ptr, |
||
200 | (png_free_ptr)free_fn, (png_voidp)mem_ptr); |
||
201 | #else |
||
202 | png_destroy_struct((png_voidp)png_ptr); |
||
203 | #endif |
||
204 | return (NULL); |
||
205 | } |
||
206 | |||
207 | |||
208 | png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; |
||
209 | |||
210 | |||
211 | |||
212 | |||
213 | |||
214 | } |
||
215 | |||
216 | |||
217 | |||
218 | /* Read the information before the actual image data. This has been |
||
219 | * changed in v0.90 to allow reading a file that already has the magic |
||
220 | * bytes read from the stream. You can tell libpng how many bytes have |
||
221 | * been read from the beginning of the stream (up to the maximum of 8) |
||
222 | * via png_set_sig_bytes(), and we will only check the remaining bytes |
||
223 | * here. The application can then have access to the signature bytes we |
||
224 | * read if it is determined that this isn't a valid PNG file. |
||
225 | */ |
||
226 | void PNGAPI |
||
227 | png_read_info(png_structp png_ptr, png_infop info_ptr) |
||
228 | { |
||
229 | png_debug(1, "in png_read_info"); |
||
230 | |||
231 | |||
232 | return; |
||
233 | |||
234 | |||
235 | png_read_sig(png_ptr, info_ptr); |
||
236 | |||
237 | |||
238 | { |
||
239 | PNG_IHDR; |
||
240 | PNG_IDAT; |
||
241 | PNG_IEND; |
||
242 | PNG_PLTE; |
||
243 | #ifdef PNG_READ_bKGD_SUPPORTED |
||
244 | PNG_bKGD; |
||
245 | #endif |
||
246 | #ifdef PNG_READ_cHRM_SUPPORTED |
||
247 | PNG_cHRM; |
||
248 | #endif |
||
249 | #ifdef PNG_READ_gAMA_SUPPORTED |
||
250 | PNG_gAMA; |
||
251 | #endif |
||
252 | #ifdef PNG_READ_hIST_SUPPORTED |
||
253 | PNG_hIST; |
||
254 | #endif |
||
255 | #ifdef PNG_READ_iCCP_SUPPORTED |
||
256 | PNG_iCCP; |
||
257 | #endif |
||
258 | #ifdef PNG_READ_iTXt_SUPPORTED |
||
259 | PNG_iTXt; |
||
260 | #endif |
||
261 | #ifdef PNG_READ_oFFs_SUPPORTED |
||
262 | PNG_oFFs; |
||
263 | #endif |
||
264 | #ifdef PNG_READ_pCAL_SUPPORTED |
||
265 | PNG_pCAL; |
||
266 | #endif |
||
267 | #ifdef PNG_READ_pHYs_SUPPORTED |
||
268 | PNG_pHYs; |
||
269 | #endif |
||
270 | #ifdef PNG_READ_sBIT_SUPPORTED |
||
271 | PNG_sBIT; |
||
272 | #endif |
||
273 | #ifdef PNG_READ_sCAL_SUPPORTED |
||
274 | PNG_sCAL; |
||
275 | #endif |
||
276 | #ifdef PNG_READ_sPLT_SUPPORTED |
||
277 | PNG_sPLT; |
||
278 | #endif |
||
279 | #ifdef PNG_READ_sRGB_SUPPORTED |
||
280 | PNG_sRGB; |
||
281 | #endif |
||
282 | #ifdef PNG_READ_tEXt_SUPPORTED |
||
283 | PNG_tEXt; |
||
284 | #endif |
||
285 | #ifdef PNG_READ_tIME_SUPPORTED |
||
286 | PNG_tIME; |
||
287 | #endif |
||
288 | #ifdef PNG_READ_tRNS_SUPPORTED |
||
289 | PNG_tRNS; |
||
290 | #endif |
||
291 | #ifdef PNG_READ_zTXt_SUPPORTED |
||
292 | PNG_zTXt; |
||
293 | #endif |
||
294 | png_uint_32 length = png_read_chunk_header(png_ptr); |
||
295 | PNG_CONST png_bytep chunk_name = png_ptr->chunk_name; |
||
296 | |||
297 | |||
298 | * matching the chunk name rather than a linear search. |
||
299 | */ |
||
300 | if (!png_memcmp(chunk_name, png_IDAT, 4)) |
||
301 | if (png_ptr->mode & PNG_AFTER_IDAT) |
||
302 | png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT; |
||
303 | |||
304 | |||
305 | png_handle_IHDR(png_ptr, info_ptr, length); |
||
306 | |||
307 | |||
308 | png_handle_IEND(png_ptr, info_ptr, length); |
||
309 | |||
310 | |||
311 | else if (png_handle_as_unknown(png_ptr, chunk_name)) |
||
312 | { |
||
313 | if (!png_memcmp(chunk_name, png_IDAT, 4)) |
||
314 | png_ptr->mode |= PNG_HAVE_IDAT; |
||
315 | |||
316 | |||
317 | |||
318 | |||
319 | png_ptr->mode |= PNG_HAVE_PLTE; |
||
320 | |||
321 | |||
322 | { |
||
323 | if (!(png_ptr->mode & PNG_HAVE_IHDR)) |
||
324 | png_error(png_ptr, "Missing IHDR before IDAT"); |
||
325 | |||
326 | |||
327 | !(png_ptr->mode & PNG_HAVE_PLTE)) |
||
328 | png_error(png_ptr, "Missing PLTE before IDAT"); |
||
329 | |||
330 | |||
331 | } |
||
332 | } |
||
333 | #endif |
||
334 | else if (!png_memcmp(chunk_name, png_PLTE, 4)) |
||
335 | png_handle_PLTE(png_ptr, info_ptr, length); |
||
336 | |||
337 | |||
338 | { |
||
339 | if (!(png_ptr->mode & PNG_HAVE_IHDR)) |
||
340 | png_error(png_ptr, "Missing IHDR before IDAT"); |
||
341 | |||
342 | |||
343 | !(png_ptr->mode & PNG_HAVE_PLTE)) |
||
344 | png_error(png_ptr, "Missing PLTE before IDAT"); |
||
345 | |||
346 | |||
347 | png_ptr->mode |= PNG_HAVE_IDAT; |
||
348 | break; |
||
349 | } |
||
350 | |||
351 | |||
352 | else if (!png_memcmp(chunk_name, png_bKGD, 4)) |
||
353 | png_handle_bKGD(png_ptr, info_ptr, length); |
||
354 | #endif |
||
355 | |||
356 | |||
357 | else if (!png_memcmp(chunk_name, png_cHRM, 4)) |
||
358 | png_handle_cHRM(png_ptr, info_ptr, length); |
||
359 | #endif |
||
360 | |||
361 | |||
362 | else if (!png_memcmp(chunk_name, png_gAMA, 4)) |
||
363 | png_handle_gAMA(png_ptr, info_ptr, length); |
||
364 | #endif |
||
365 | |||
366 | |||
367 | else if (!png_memcmp(chunk_name, png_hIST, 4)) |
||
368 | png_handle_hIST(png_ptr, info_ptr, length); |
||
369 | #endif |
||
370 | |||
371 | |||
372 | else if (!png_memcmp(chunk_name, png_oFFs, 4)) |
||
373 | png_handle_oFFs(png_ptr, info_ptr, length); |
||
374 | #endif |
||
375 | |||
376 | |||
377 | else if (!png_memcmp(chunk_name, png_pCAL, 4)) |
||
378 | png_handle_pCAL(png_ptr, info_ptr, length); |
||
379 | #endif |
||
380 | |||
381 | |||
382 | else if (!png_memcmp(chunk_name, png_sCAL, 4)) |
||
383 | png_handle_sCAL(png_ptr, info_ptr, length); |
||
384 | #endif |
||
385 | |||
386 | |||
387 | else if (!png_memcmp(chunk_name, png_pHYs, 4)) |
||
388 | png_handle_pHYs(png_ptr, info_ptr, length); |
||
389 | #endif |
||
390 | |||
391 | |||
392 | else if (!png_memcmp(chunk_name, png_sBIT, 4)) |
||
393 | png_handle_sBIT(png_ptr, info_ptr, length); |
||
394 | #endif |
||
395 | |||
396 | |||
397 | else if (!png_memcmp(chunk_name, png_sRGB, 4)) |
||
398 | png_handle_sRGB(png_ptr, info_ptr, length); |
||
399 | #endif |
||
400 | |||
401 | |||
402 | else if (!png_memcmp(chunk_name, png_iCCP, 4)) |
||
403 | png_handle_iCCP(png_ptr, info_ptr, length); |
||
404 | #endif |
||
405 | |||
406 | |||
407 | else if (!png_memcmp(chunk_name, png_sPLT, 4)) |
||
408 | png_handle_sPLT(png_ptr, info_ptr, length); |
||
409 | #endif |
||
410 | |||
411 | |||
412 | else if (!png_memcmp(chunk_name, png_tEXt, 4)) |
||
413 | png_handle_tEXt(png_ptr, info_ptr, length); |
||
414 | #endif |
||
415 | |||
416 | |||
417 | else if (!png_memcmp(chunk_name, png_tIME, 4)) |
||
418 | png_handle_tIME(png_ptr, info_ptr, length); |
||
419 | #endif |
||
420 | |||
421 | |||
422 | else if (!png_memcmp(chunk_name, png_tRNS, 4)) |
||
423 | png_handle_tRNS(png_ptr, info_ptr, length); |
||
424 | #endif |
||
425 | |||
426 | |||
427 | else if (!png_memcmp(chunk_name, png_zTXt, 4)) |
||
428 | png_handle_zTXt(png_ptr, info_ptr, length); |
||
429 | #endif |
||
430 | |||
431 | |||
432 | else if (!png_memcmp(chunk_name, png_iTXt, 4)) |
||
433 | png_handle_iTXt(png_ptr, info_ptr, length); |
||
434 | #endif |
||
435 | |||
436 | |||
437 | png_handle_unknown(png_ptr, info_ptr, length); |
||
438 | } |
||
439 | } |
||
440 | #endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ |
||
441 | |||
442 | |||
443 | void PNGAPI |
||
444 | png_read_update_info(png_structp png_ptr, png_infop info_ptr) |
||
445 | { |
||
446 | png_debug(1, "in png_read_update_info"); |
||
447 | |||
448 | |||
449 | return; |
||
450 | |||
451 | |||
452 | png_read_start_row(png_ptr); |
||
453 | |||
454 | |||
455 | png_warning(png_ptr, |
||
456 | "Ignoring extra png_read_update_info() call;" |
||
457 | " row buffer not reallocated"); |
||
458 | |||
459 | |||
460 | } |
||
461 | |||
462 | |||
463 | /* Initialize palette, background, etc, after transformations |
||
464 | * are set, but before any reading takes place. This allows |
||
465 | * the user to obtain a gamma-corrected palette, for example. |
||
466 | * If the user doesn't call this, we will do it ourselves. |
||
467 | */ |
||
468 | void PNGAPI |
||
469 | png_start_read_image(png_structp png_ptr) |
||
470 | { |
||
471 | png_debug(1, "in png_start_read_image"); |
||
472 | |||
473 | |||
474 | return; |
||
475 | |||
476 | |||
477 | png_read_start_row(png_ptr); |
||
478 | else |
||
479 | png_warning(png_ptr, |
||
480 | "Ignoring extra png_start_read_image() call;" |
||
481 | " row buffer not reallocated"); |
||
482 | } |
||
483 | #endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ |
||
484 | |||
485 | |||
486 | void PNGAPI |
||
487 | png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row) |
||
488 | { |
||
489 | PNG_IDAT; |
||
490 | PNG_CONST int png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, |
||
491 | 0xff}; |
||
492 | PNG_CONST int png_pass_mask[7] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff}; |
||
493 | int ret; |
||
494 | |||
495 | |||
496 | return; |
||
497 | |||
498 | |||
499 | (unsigned long)png_ptr->row_number, png_ptr->pass); |
||
500 | |||
501 | |||
502 | png_read_start_row(png_ptr); |
||
503 | |||
504 | |||
505 | { |
||
506 | /* Check for transforms that have been set but were defined out */ |
||
507 | #if defined(PNG_WRITE_INVERT_SUPPORTED) && !defined(PNG_READ_INVERT_SUPPORTED) |
||
508 | if (png_ptr->transformations & PNG_INVERT_MONO) |
||
509 | png_warning(png_ptr, "PNG_READ_INVERT_SUPPORTED is not defined"); |
||
510 | #endif |
||
511 | |||
512 | |||
513 | if (png_ptr->transformations & PNG_FILLER) |
||
514 | png_warning(png_ptr, "PNG_READ_FILLER_SUPPORTED is not defined"); |
||
515 | #endif |
||
516 | |||
517 | |||
518 | !defined(PNG_READ_PACKSWAP_SUPPORTED) |
||
519 | if (png_ptr->transformations & PNG_PACKSWAP) |
||
520 | png_warning(png_ptr, "PNG_READ_PACKSWAP_SUPPORTED is not defined"); |
||
521 | #endif |
||
522 | |||
523 | |||
524 | if (png_ptr->transformations & PNG_PACK) |
||
525 | png_warning(png_ptr, "PNG_READ_PACK_SUPPORTED is not defined"); |
||
526 | #endif |
||
527 | |||
528 | |||
529 | if (png_ptr->transformations & PNG_SHIFT) |
||
530 | png_warning(png_ptr, "PNG_READ_SHIFT_SUPPORTED is not defined"); |
||
531 | #endif |
||
532 | |||
533 | |||
534 | if (png_ptr->transformations & PNG_BGR) |
||
535 | png_warning(png_ptr, "PNG_READ_BGR_SUPPORTED is not defined"); |
||
536 | #endif |
||
537 | |||
538 | |||
539 | if (png_ptr->transformations & PNG_SWAP_BYTES) |
||
540 | png_warning(png_ptr, "PNG_READ_SWAP_SUPPORTED is not defined"); |
||
541 | #endif |
||
542 | } |
||
543 | |||
544 | |||
545 | /* If interlaced and we do not need a new row, combine row and return */ |
||
546 | if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE)) |
||
547 | { |
||
548 | switch (png_ptr->pass) |
||
549 | { |
||
550 | case 0: |
||
551 | if (png_ptr->row_number & 0x07) |
||
552 | { |
||
553 | if (dsp_row != NULL) |
||
554 | png_combine_row(png_ptr, dsp_row, |
||
555 | png_pass_dsp_mask[png_ptr->pass]); |
||
556 | png_read_finish_row(png_ptr); |
||
557 | return; |
||
558 | } |
||
559 | break; |
||
560 | |||
561 | |||
562 | if ((png_ptr->row_number & 0x07) || png_ptr->width < 5) |
||
563 | { |
||
564 | if (dsp_row != NULL) |
||
565 | png_combine_row(png_ptr, dsp_row, |
||
566 | png_pass_dsp_mask[png_ptr->pass]); |
||
567 | |||
568 | |||
569 | return; |
||
570 | } |
||
571 | break; |
||
572 | |||
573 | |||
574 | if ((png_ptr->row_number & 0x07) != 4) |
||
575 | { |
||
576 | if (dsp_row != NULL && (png_ptr->row_number & 4)) |
||
577 | png_combine_row(png_ptr, dsp_row, |
||
578 | png_pass_dsp_mask[png_ptr->pass]); |
||
579 | |||
580 | |||
581 | return; |
||
582 | } |
||
583 | break; |
||
584 | |||
585 | |||
586 | if ((png_ptr->row_number & 3) || png_ptr->width < 3) |
||
587 | { |
||
588 | if (dsp_row != NULL) |
||
589 | png_combine_row(png_ptr, dsp_row, |
||
590 | png_pass_dsp_mask[png_ptr->pass]); |
||
591 | |||
592 | |||
593 | return; |
||
594 | } |
||
595 | break; |
||
596 | |||
597 | |||
598 | if ((png_ptr->row_number & 3) != 2) |
||
599 | { |
||
600 | if (dsp_row != NULL && (png_ptr->row_number & 2)) |
||
601 | png_combine_row(png_ptr, dsp_row, |
||
602 | png_pass_dsp_mask[png_ptr->pass]); |
||
603 | |||
604 | |||
605 | return; |
||
606 | } |
||
607 | break; |
||
608 | case 5: |
||
609 | if ((png_ptr->row_number & 1) || png_ptr->width < 2) |
||
610 | { |
||
611 | if (dsp_row != NULL) |
||
612 | png_combine_row(png_ptr, dsp_row, |
||
613 | png_pass_dsp_mask[png_ptr->pass]); |
||
614 | |||
615 | |||
616 | return; |
||
617 | } |
||
618 | break; |
||
619 | |||
620 | |||
621 | case 6: |
||
622 | if (!(png_ptr->row_number & 1)) |
||
623 | { |
||
624 | png_read_finish_row(png_ptr); |
||
625 | return; |
||
626 | } |
||
627 | break; |
||
628 | } |
||
629 | } |
||
630 | #endif |
||
631 | |||
632 | |||
633 | png_error(png_ptr, "Invalid attempt to read row data"); |
||
634 | |||
635 | |||
636 | png_ptr->zstream.avail_out = |
||
637 | (uInt)(PNG_ROWBYTES(png_ptr->pixel_depth, |
||
638 | png_ptr->iwidth) + 1); |
||
639 | |||
640 | |||
641 | { |
||
642 | if (!(png_ptr->zstream.avail_in)) |
||
643 | { |
||
644 | while (!png_ptr->idat_size) |
||
645 | { |
||
646 | png_crc_finish(png_ptr, 0); |
||
647 | |||
648 | |||
649 | if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) |
||
650 | png_error(png_ptr, "Not enough image data"); |
||
651 | } |
||
652 | png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size; |
||
653 | png_ptr->zstream.next_in = png_ptr->zbuf; |
||
654 | if (png_ptr->zbuf_size > png_ptr->idat_size) |
||
655 | png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size; |
||
656 | png_crc_read(png_ptr, png_ptr->zbuf, |
||
657 | (png_size_t)png_ptr->zstream.avail_in); |
||
658 | png_ptr->idat_size -= png_ptr->zstream.avail_in; |
||
659 | } |
||
660 | |||
661 | |||
662 | |||
663 | |||
664 | { |
||
665 | if (png_ptr->zstream.avail_out || png_ptr->zstream.avail_in || |
||
666 | png_ptr->idat_size) |
||
667 | png_benign_error(png_ptr, "Extra compressed data"); |
||
668 | png_ptr->mode |= PNG_AFTER_IDAT; |
||
669 | png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED; |
||
670 | break; |
||
671 | } |
||
672 | |||
673 | |||
674 | png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg : |
||
675 | "Decompression error"); |
||
676 | |||
677 | |||
678 | |||
679 | |||
680 | png_ptr->row_info.width = png_ptr->iwidth; |
||
681 | png_ptr->row_info.channels = png_ptr->channels; |
||
682 | png_ptr->row_info.bit_depth = png_ptr->bit_depth; |
||
683 | png_ptr->row_info.pixel_depth = png_ptr->pixel_depth; |
||
684 | png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth, |
||
685 | png_ptr->row_info.width); |
||
686 | |||
687 | |||
688 | png_read_filter_row(png_ptr, &(png_ptr->row_info), |
||
689 | png_ptr->row_buf + 1, png_ptr->prev_row + 1, |
||
690 | (int)(png_ptr->row_buf[0])); |
||
691 | |||
692 | |||
693 | |||
694 | |||
695 | if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && |
||
696 | (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING)) |
||
697 | { |
||
698 | /* Intrapixel differencing */ |
||
699 | png_do_read_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1); |
||
700 | } |
||
701 | #endif |
||
702 | |||
703 | |||
704 | |||
705 | png_do_read_transformations(png_ptr); |
||
706 | |||
707 | |||
708 | /* Blow up interlaced rows to full size */ |
||
709 | if (png_ptr->interlaced && |
||
710 | (png_ptr->transformations & PNG_INTERLACE)) |
||
711 | { |
||
712 | if (png_ptr->pass < 6) |
||
713 | /* Old interface (pre-1.0.9): |
||
714 | * png_do_read_interlace(&(png_ptr->row_info), |
||
715 | * png_ptr->row_buf + 1, png_ptr->pass, png_ptr->transformations); |
||
716 | */ |
||
717 | png_do_read_interlace(png_ptr); |
||
718 | |||
719 | |||
720 | png_combine_row(png_ptr, dsp_row, png_pass_dsp_mask[png_ptr->pass]); |
||
721 | |||
722 | |||
723 | png_combine_row(png_ptr, row, png_pass_mask[png_ptr->pass]); |
||
724 | } |
||
725 | |||
726 | |||
727 | #endif |
||
728 | { |
||
729 | if (row != NULL) |
||
730 | png_combine_row(png_ptr, row, 0xff); |
||
731 | |||
732 | |||
733 | png_combine_row(png_ptr, dsp_row, 0xff); |
||
734 | } |
||
735 | png_read_finish_row(png_ptr); |
||
736 | |||
737 | |||
738 | (*(png_ptr->read_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass); |
||
739 | } |
||
740 | #endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ |
||
741 | |||
742 | |||
743 | /* Read one or more rows of image data. If the image is interlaced, |
||
744 | * and png_set_interlace_handling() has been called, the rows need to |
||
745 | * contain the contents of the rows from the previous pass. If the |
||
746 | * image has alpha or transparency, and png_handle_alpha()[*] has been |
||
747 | * called, the rows contents must be initialized to the contents of the |
||
748 | * screen. |
||
749 | * |
||
750 | * "row" holds the actual image, and pixels are placed in it |
||
751 | * as they arrive. If the image is displayed after each pass, it will |
||
752 | * appear to "sparkle" in. "display_row" can be used to display a |
||
753 | * "chunky" progressive image, with finer detail added as it becomes |
||
754 | * available. If you do not want this "chunky" display, you may pass |
||
755 | * NULL for display_row. If you do not want the sparkle display, and |
||
756 | * you have not called png_handle_alpha(), you may pass NULL for rows. |
||
757 | * If you have called png_handle_alpha(), and the image has either an |
||
758 | * alpha channel or a transparency chunk, you must provide a buffer for |
||
759 | * rows. In this case, you do not have to provide a display_row buffer |
||
760 | * also, but you may. If the image is not interlaced, or if you have |
||
761 | * not called png_set_interlace_handling(), the display_row buffer will |
||
762 | * be ignored, so pass NULL to it. |
||
763 | * |
||
764 | * [*] png_handle_alpha() does not exist yet, as of this version of libpng |
||
765 | */ |
||
766 | |||
767 | |||
768 | png_read_rows(png_structp png_ptr, png_bytepp row, |
||
769 | png_bytepp display_row, png_uint_32 num_rows) |
||
770 | { |
||
771 | png_uint_32 i; |
||
772 | png_bytepp rp; |
||
773 | png_bytepp dp; |
||
774 | |||
775 | |||
776 | |||
777 | |||
778 | return; |
||
779 | |||
780 | |||
781 | dp = display_row; |
||
782 | if (rp != NULL && dp != NULL) |
||
783 | for (i = 0; i < num_rows; i++) |
||
784 | { |
||
785 | png_bytep rptr = *rp++; |
||
786 | png_bytep dptr = *dp++; |
||
787 | |||
788 | |||
789 | } |
||
790 | |||
791 | |||
792 | for (i = 0; i < num_rows; i++) |
||
793 | { |
||
794 | png_bytep rptr = *rp; |
||
795 | png_read_row(png_ptr, rptr, NULL); |
||
796 | rp++; |
||
797 | } |
||
798 | |||
799 | |||
800 | for (i = 0; i < num_rows; i++) |
||
801 | { |
||
802 | png_bytep dptr = *dp; |
||
803 | png_read_row(png_ptr, NULL, dptr); |
||
804 | dp++; |
||
805 | } |
||
806 | } |
||
807 | #endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ |
||
808 | |||
809 | |||
810 | /* Read the entire image. If the image has an alpha channel or a tRNS |
||
811 | * chunk, and you have called png_handle_alpha()[*], you will need to |
||
812 | * initialize the image to the current image that PNG will be overlaying. |
||
813 | * We set the num_rows again here, in case it was incorrectly set in |
||
814 | * png_read_start_row() by a call to png_read_update_info() or |
||
815 | * png_start_read_image() if png_set_interlace_handling() wasn't called |
||
816 | * prior to either of these functions like it should have been. You can |
||
817 | * only call this function once. If you desire to have an image for |
||
818 | * each pass of a interlaced image, use png_read_rows() instead. |
||
819 | * |
||
820 | * [*] png_handle_alpha() does not exist yet, as of this version of libpng |
||
821 | */ |
||
822 | void PNGAPI |
||
823 | png_read_image(png_structp png_ptr, png_bytepp image) |
||
824 | { |
||
825 | png_uint_32 i, image_height; |
||
826 | int pass, j; |
||
827 | png_bytepp rp; |
||
828 | |||
829 | |||
830 | |||
831 | |||
832 | return; |
||
833 | |||
834 | |||
835 | if (!(png_ptr->flags & PNG_FLAG_ROW_INIT)) |
||
836 | { |
||
837 | pass = png_set_interlace_handling(png_ptr); |
||
838 | /* And make sure transforms are initialized. */ |
||
839 | png_start_read_image(png_ptr); |
||
840 | } |
||
841 | else |
||
842 | { |
||
843 | if (png_ptr->interlaced && !(png_ptr->transformations & PNG_INTERLACE)) |
||
844 | { |
||
845 | /* Caller called png_start_read_image or png_read_update_info without |
||
846 | * first turning on the PNG_INTERLACE transform. We can fix this here, |
||
847 | * but the caller should do it! |
||
848 | */ |
||
849 | png_warning(png_ptr, "Interlace handling should be turned on when " |
||
850 | "using png_read_image"); |
||
851 | /* Make sure this is set correctly */ |
||
852 | png_ptr->num_rows = png_ptr->height; |
||
853 | } |
||
854 | |||
855 | |||
856 | * the above error case. |
||
857 | */ |
||
858 | pass = png_set_interlace_handling(png_ptr); |
||
859 | } |
||
860 | #else |
||
861 | if (png_ptr->interlaced) |
||
862 | png_error(png_ptr, |
||
863 | "Cannot read interlaced image -- interlace handler disabled"); |
||
864 | |||
865 | |||
866 | #endif |
||
867 | |||
868 | |||
869 | |||
870 | |||
871 | { |
||
872 | rp = image; |
||
873 | for (i = 0; i < image_height; i++) |
||
874 | { |
||
875 | png_read_row(png_ptr, *rp, NULL); |
||
876 | rp++; |
||
877 | } |
||
878 | } |
||
879 | } |
||
880 | #endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ |
||
881 | |||
882 | |||
883 | /* Read the end of the PNG file. Will not read past the end of the |
||
884 | * file, will verify the end is accurate, and will read any comments |
||
885 | * or time information at the end of the file, if info is not NULL. |
||
886 | */ |
||
887 | void PNGAPI |
||
888 | png_read_end(png_structp png_ptr, png_infop info_ptr) |
||
889 | { |
||
890 | png_debug(1, "in png_read_end"); |
||
891 | |||
892 | |||
893 | return; |
||
894 | |||
895 | |||
896 | |||
897 | |||
898 | { |
||
899 | PNG_IHDR; |
||
900 | PNG_IDAT; |
||
901 | PNG_IEND; |
||
902 | PNG_PLTE; |
||
903 | #ifdef PNG_READ_bKGD_SUPPORTED |
||
904 | PNG_bKGD; |
||
905 | #endif |
||
906 | #ifdef PNG_READ_cHRM_SUPPORTED |
||
907 | PNG_cHRM; |
||
908 | #endif |
||
909 | #ifdef PNG_READ_gAMA_SUPPORTED |
||
910 | PNG_gAMA; |
||
911 | #endif |
||
912 | #ifdef PNG_READ_hIST_SUPPORTED |
||
913 | PNG_hIST; |
||
914 | #endif |
||
915 | #ifdef PNG_READ_iCCP_SUPPORTED |
||
916 | PNG_iCCP; |
||
917 | #endif |
||
918 | #ifdef PNG_READ_iTXt_SUPPORTED |
||
919 | PNG_iTXt; |
||
920 | #endif |
||
921 | #ifdef PNG_READ_oFFs_SUPPORTED |
||
922 | PNG_oFFs; |
||
923 | #endif |
||
924 | #ifdef PNG_READ_pCAL_SUPPORTED |
||
925 | PNG_pCAL; |
||
926 | #endif |
||
927 | #ifdef PNG_READ_pHYs_SUPPORTED |
||
928 | PNG_pHYs; |
||
929 | #endif |
||
930 | #ifdef PNG_READ_sBIT_SUPPORTED |
||
931 | PNG_sBIT; |
||
932 | #endif |
||
933 | #ifdef PNG_READ_sCAL_SUPPORTED |
||
934 | PNG_sCAL; |
||
935 | #endif |
||
936 | #ifdef PNG_READ_sPLT_SUPPORTED |
||
937 | PNG_sPLT; |
||
938 | #endif |
||
939 | #ifdef PNG_READ_sRGB_SUPPORTED |
||
940 | PNG_sRGB; |
||
941 | #endif |
||
942 | #ifdef PNG_READ_tEXt_SUPPORTED |
||
943 | PNG_tEXt; |
||
944 | #endif |
||
945 | #ifdef PNG_READ_tIME_SUPPORTED |
||
946 | PNG_tIME; |
||
947 | #endif |
||
948 | #ifdef PNG_READ_tRNS_SUPPORTED |
||
949 | PNG_tRNS; |
||
950 | #endif |
||
951 | #ifdef PNG_READ_zTXt_SUPPORTED |
||
952 | PNG_zTXt; |
||
953 | #endif |
||
954 | png_uint_32 length = png_read_chunk_header(png_ptr); |
||
955 | PNG_CONST png_bytep chunk_name = png_ptr->chunk_name; |
||
956 | |||
957 | |||
958 | png_handle_IHDR(png_ptr, info_ptr, length); |
||
959 | |||
960 | |||
961 | png_handle_IEND(png_ptr, info_ptr, length); |
||
962 | |||
963 | |||
964 | else if (png_handle_as_unknown(png_ptr, chunk_name)) |
||
965 | { |
||
966 | if (!png_memcmp(chunk_name, png_IDAT, 4)) |
||
967 | { |
||
968 | if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT)) |
||
969 | png_benign_error(png_ptr, "Too many IDATs found"); |
||
970 | } |
||
971 | png_handle_unknown(png_ptr, info_ptr, length); |
||
972 | if (!png_memcmp(chunk_name, png_PLTE, 4)) |
||
973 | png_ptr->mode |= PNG_HAVE_PLTE; |
||
974 | } |
||
975 | #endif |
||
976 | |||
977 | |||
978 | { |
||
979 | /* Zero length IDATs are legal after the last IDAT has been |
||
980 | * read, but not after other chunks have been read. |
||
981 | */ |
||
982 | if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT)) |
||
983 | png_benign_error(png_ptr, "Too many IDATs found"); |
||
984 | |||
985 | |||
986 | } |
||
987 | else if (!png_memcmp(chunk_name, png_PLTE, 4)) |
||
988 | png_handle_PLTE(png_ptr, info_ptr, length); |
||
989 | |||
990 | |||
991 | else if (!png_memcmp(chunk_name, png_bKGD, 4)) |
||
992 | png_handle_bKGD(png_ptr, info_ptr, length); |
||
993 | #endif |
||
994 | |||
995 | |||
996 | else if (!png_memcmp(chunk_name, png_cHRM, 4)) |
||
997 | png_handle_cHRM(png_ptr, info_ptr, length); |
||
998 | #endif |
||
999 | |||
1000 | |||
1001 | else if (!png_memcmp(chunk_name, png_gAMA, 4)) |
||
1002 | png_handle_gAMA(png_ptr, info_ptr, length); |
||
1003 | #endif |
||
1004 | |||
1005 | |||
1006 | else if (!png_memcmp(chunk_name, png_hIST, 4)) |
||
1007 | png_handle_hIST(png_ptr, info_ptr, length); |
||
1008 | #endif |
||
1009 | |||
1010 | |||
1011 | else if (!png_memcmp(chunk_name, png_oFFs, 4)) |
||
1012 | png_handle_oFFs(png_ptr, info_ptr, length); |
||
1013 | #endif |
||
1014 | |||
1015 | |||
1016 | else if (!png_memcmp(chunk_name, png_pCAL, 4)) |
||
1017 | png_handle_pCAL(png_ptr, info_ptr, length); |
||
1018 | #endif |
||
1019 | |||
1020 | |||
1021 | else if (!png_memcmp(chunk_name, png_sCAL, 4)) |
||
1022 | png_handle_sCAL(png_ptr, info_ptr, length); |
||
1023 | #endif |
||
1024 | |||
1025 | |||
1026 | else if (!png_memcmp(chunk_name, png_pHYs, 4)) |
||
1027 | png_handle_pHYs(png_ptr, info_ptr, length); |
||
1028 | #endif |
||
1029 | |||
1030 | |||
1031 | else if (!png_memcmp(chunk_name, png_sBIT, 4)) |
||
1032 | png_handle_sBIT(png_ptr, info_ptr, length); |
||
1033 | #endif |
||
1034 | |||
1035 | |||
1036 | else if (!png_memcmp(chunk_name, png_sRGB, 4)) |
||
1037 | png_handle_sRGB(png_ptr, info_ptr, length); |
||
1038 | #endif |
||
1039 | |||
1040 | |||
1041 | else if (!png_memcmp(chunk_name, png_iCCP, 4)) |
||
1042 | png_handle_iCCP(png_ptr, info_ptr, length); |
||
1043 | #endif |
||
1044 | |||
1045 | |||
1046 | else if (!png_memcmp(chunk_name, png_sPLT, 4)) |
||
1047 | png_handle_sPLT(png_ptr, info_ptr, length); |
||
1048 | #endif |
||
1049 | |||
1050 | |||
1051 | else if (!png_memcmp(chunk_name, png_tEXt, 4)) |
||
1052 | png_handle_tEXt(png_ptr, info_ptr, length); |
||
1053 | #endif |
||
1054 | |||
1055 | |||
1056 | else if (!png_memcmp(chunk_name, png_tIME, 4)) |
||
1057 | png_handle_tIME(png_ptr, info_ptr, length); |
||
1058 | #endif |
||
1059 | |||
1060 | |||
1061 | else if (!png_memcmp(chunk_name, png_tRNS, 4)) |
||
1062 | png_handle_tRNS(png_ptr, info_ptr, length); |
||
1063 | #endif |
||
1064 | |||
1065 | |||
1066 | else if (!png_memcmp(chunk_name, png_zTXt, 4)) |
||
1067 | png_handle_zTXt(png_ptr, info_ptr, length); |
||
1068 | #endif |
||
1069 | |||
1070 | |||
1071 | else if (!png_memcmp(chunk_name, png_iTXt, 4)) |
||
1072 | png_handle_iTXt(png_ptr, info_ptr, length); |
||
1073 | #endif |
||
1074 | |||
1075 | |||
1076 | png_handle_unknown(png_ptr, info_ptr, length); |
||
1077 | } while (!(png_ptr->mode & PNG_HAVE_IEND)); |
||
1078 | } |
||
1079 | #endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ |
||
1080 | |||
1081 | |||
1082 | void PNGAPI |
||
1083 | png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr, |
||
1084 | png_infopp end_info_ptr_ptr) |
||
1085 | { |
||
1086 | png_structp png_ptr = NULL; |
||
1087 | png_infop info_ptr = NULL, end_info_ptr = NULL; |
||
1088 | #ifdef PNG_USER_MEM_SUPPORTED |
||
1089 | png_free_ptr free_fn = NULL; |
||
1090 | png_voidp mem_ptr = NULL; |
||
1091 | #endif |
||
1092 | |||
1093 | |||
1094 | |||
1095 | |||
1096 | png_ptr = *png_ptr_ptr; |
||
1097 | if (png_ptr == NULL) |
||
1098 | return; |
||
1099 | |||
1100 | |||
1101 | free_fn = png_ptr->free_fn; |
||
1102 | mem_ptr = png_ptr->mem_ptr; |
||
1103 | #endif |
||
1104 | |||
1105 | |||
1106 | info_ptr = *info_ptr_ptr; |
||
1107 | |||
1108 | |||
1109 | end_info_ptr = *end_info_ptr_ptr; |
||
1110 | |||
1111 | |||
1112 | |||
1113 | |||
1114 | { |
||
1115 | #ifdef PNG_TEXT_SUPPORTED |
||
1116 | png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, -1); |
||
1117 | #endif |
||
1118 | |||
1119 | |||
1120 | png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn, |
||
1121 | (png_voidp)mem_ptr); |
||
1122 | #else |
||
1123 | png_destroy_struct((png_voidp)info_ptr); |
||
1124 | #endif |
||
1125 | *info_ptr_ptr = NULL; |
||
1126 | } |
||
1127 | |||
1128 | |||
1129 | { |
||
1130 | #ifdef PNG_READ_TEXT_SUPPORTED |
||
1131 | png_free_data(png_ptr, end_info_ptr, PNG_FREE_TEXT, -1); |
||
1132 | #endif |
||
1133 | #ifdef PNG_USER_MEM_SUPPORTED |
||
1134 | png_destroy_struct_2((png_voidp)end_info_ptr, (png_free_ptr)free_fn, |
||
1135 | (png_voidp)mem_ptr); |
||
1136 | #else |
||
1137 | png_destroy_struct((png_voidp)end_info_ptr); |
||
1138 | #endif |
||
1139 | *end_info_ptr_ptr = NULL; |
||
1140 | } |
||
1141 | |||
1142 | |||
1143 | { |
||
1144 | #ifdef PNG_USER_MEM_SUPPORTED |
||
1145 | png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn, |
||
1146 | (png_voidp)mem_ptr); |
||
1147 | #else |
||
1148 | png_destroy_struct((png_voidp)png_ptr); |
||
1149 | #endif |
||
1150 | *png_ptr_ptr = NULL; |
||
1151 | } |
||
1152 | } |
||
1153 | |||
1154 | |||
1155 | void /* PRIVATE */ |
||
1156 | png_read_destroy(png_structp png_ptr, png_infop info_ptr, |
||
1157 | png_infop end_info_ptr) |
||
1158 | { |
||
1159 | #ifdef PNG_SETJMP_SUPPORTED |
||
1160 | jmp_buf tmp_jmp; |
||
1161 | #endif |
||
1162 | png_error_ptr error_fn; |
||
1163 | png_error_ptr warning_fn; |
||
1164 | png_voidp error_ptr; |
||
1165 | #ifdef PNG_USER_MEM_SUPPORTED |
||
1166 | png_free_ptr free_fn; |
||
1167 | #endif |
||
1168 | |||
1169 | |||
1170 | |||
1171 | |||
1172 | png_info_destroy(png_ptr, info_ptr); |
||
1173 | |||
1174 | |||
1175 | png_info_destroy(png_ptr, end_info_ptr); |
||
1176 | |||
1177 | |||
1178 | png_free(png_ptr, png_ptr->big_row_buf); |
||
1179 | png_free(png_ptr, png_ptr->prev_row); |
||
1180 | png_free(png_ptr, png_ptr->chunkdata); |
||
1181 | |||
1182 | |||
1183 | png_free(png_ptr, png_ptr->palette_lookup); |
||
1184 | png_free(png_ptr, png_ptr->quantize_index); |
||
1185 | #endif |
||
1186 | |||
1187 | |||
1188 | png_free(png_ptr, png_ptr->gamma_table); |
||
1189 | #endif |
||
1190 | |||
1191 | |||
1192 | png_free(png_ptr, png_ptr->gamma_from_1); |
||
1193 | png_free(png_ptr, png_ptr->gamma_to_1); |
||
1194 | #endif |
||
1195 | |||
1196 | |||
1197 | png_zfree(png_ptr, png_ptr->palette); |
||
1198 | png_ptr->free_me &= ~PNG_FREE_PLTE; |
||
1199 | |||
1200 | |||
1201 | defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) |
||
1202 | if (png_ptr->free_me & PNG_FREE_TRNS) |
||
1203 | png_free(png_ptr, png_ptr->trans_alpha); |
||
1204 | png_ptr->free_me &= ~PNG_FREE_TRNS; |
||
1205 | #endif |
||
1206 | |||
1207 | |||
1208 | if (png_ptr->free_me & PNG_FREE_HIST) |
||
1209 | png_free(png_ptr, png_ptr->hist); |
||
1210 | png_ptr->free_me &= ~PNG_FREE_HIST; |
||
1211 | #endif |
||
1212 | |||
1213 | |||
1214 | if (png_ptr->gamma_16_table != NULL) |
||
1215 | { |
||
1216 | int i; |
||
1217 | int istop = (1 << (8 - png_ptr->gamma_shift)); |
||
1218 | for (i = 0; i < istop; i++) |
||
1219 | { |
||
1220 | png_free(png_ptr, png_ptr->gamma_16_table[i]); |
||
1221 | } |
||
1222 | png_free(png_ptr, png_ptr->gamma_16_table); |
||
1223 | } |
||
1224 | |||
1225 | |||
1226 | if (png_ptr->gamma_16_from_1 != NULL) |
||
1227 | { |
||
1228 | int i; |
||
1229 | int istop = (1 << (8 - png_ptr->gamma_shift)); |
||
1230 | for (i = 0; i < istop; i++) |
||
1231 | { |
||
1232 | png_free(png_ptr, png_ptr->gamma_16_from_1[i]); |
||
1233 | } |
||
1234 | png_free(png_ptr, png_ptr->gamma_16_from_1); |
||
1235 | } |
||
1236 | if (png_ptr->gamma_16_to_1 != NULL) |
||
1237 | { |
||
1238 | int i; |
||
1239 | int istop = (1 << (8 - png_ptr->gamma_shift)); |
||
1240 | for (i = 0; i < istop; i++) |
||
1241 | { |
||
1242 | png_free(png_ptr, png_ptr->gamma_16_to_1[i]); |
||
1243 | } |
||
1244 | png_free(png_ptr, png_ptr->gamma_16_to_1); |
||
1245 | } |
||
1246 | #endif |
||
1247 | #endif |
||
1248 | |||
1249 | |||
1250 | png_free(png_ptr, png_ptr->time_buffer); |
||
1251 | #endif |
||
1252 | |||
1253 | |||
1254 | |||
1255 | |||
1256 | png_free(png_ptr, png_ptr->save_buffer); |
||
1257 | #endif |
||
1258 | |||
1259 | |||
1260 | #ifdef PNG_TEXT_SUPPORTED |
||
1261 | png_free(png_ptr, png_ptr->current_text); |
||
1262 | #endif /* PNG_TEXT_SUPPORTED */ |
||
1263 | #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */ |
||
1264 | |||
1265 | |||
1266 | * being used again. |
||
1267 | */ |
||
1268 | #ifdef PNG_SETJMP_SUPPORTED |
||
1269 | png_memcpy(tmp_jmp, png_ptr->png_jmpbuf, png_sizeof(jmp_buf)); |
||
1270 | #endif |
||
1271 | |||
1272 | |||
1273 | warning_fn = png_ptr->warning_fn; |
||
1274 | error_ptr = png_ptr->error_ptr; |
||
1275 | #ifdef PNG_USER_MEM_SUPPORTED |
||
1276 | free_fn = png_ptr->free_fn; |
||
1277 | #endif |
||
1278 | |||
1279 | |||
1280 | |||
1281 | |||
1282 | png_ptr->warning_fn = warning_fn; |
||
1283 | png_ptr->error_ptr = error_ptr; |
||
1284 | #ifdef PNG_USER_MEM_SUPPORTED |
||
1285 | png_ptr->free_fn = free_fn; |
||
1286 | #endif |
||
1287 | |||
1288 | |||
1289 | png_memcpy(png_ptr->png_jmpbuf, tmp_jmp, png_sizeof(jmp_buf)); |
||
1290 | #endif |
||
1291 | |||
1292 | |||
1293 | |||
1294 | |||
1295 | png_set_read_status_fn(png_structp png_ptr, png_read_status_ptr read_row_fn) |
||
1296 | { |
||
1297 | if (png_ptr == NULL) |
||
1298 | return; |
||
1299 | |||
1300 | |||
1301 | } |
||
1302 | |||
1303 | |||
1304 | |||
1305 | #ifdef PNG_INFO_IMAGE_SUPPORTED |
||
1306 | void PNGAPI |
||
1307 | png_read_png(png_structp png_ptr, png_infop info_ptr, |
||
1308 | int transforms, |
||
1309 | voidp params) |
||
1310 | { |
||
1311 | int row; |
||
1312 | |||
1313 | |||
1314 | return; |
||
1315 | |||
1316 | |||
1317 | * PNG file before the first IDAT (image data chunk). |
||
1318 | */ |
||
1319 | png_read_info(png_ptr, info_ptr); |
||
1320 | if (info_ptr->height > PNG_UINT_32_MAX/png_sizeof(png_bytep)) |
||
1321 | png_error(png_ptr, "Image is too high to process with png_read_png()"); |
||
1322 | |||
1323 | |||
1324 | |||
1325 | |||
1326 | /* Tell libpng to strip 16 bit/color files down to 8 bits per color. |
||
1327 | */ |
||
1328 | if (transforms & PNG_TRANSFORM_STRIP_16) |
||
1329 | png_set_strip_16(png_ptr); |
||
1330 | #endif |
||
1331 | |||
1332 | |||
1333 | /* Strip alpha bytes from the input data without combining with |
||
1334 | * the background (not recommended). |
||
1335 | */ |
||
1336 | if (transforms & PNG_TRANSFORM_STRIP_ALPHA) |
||
1337 | png_set_strip_alpha(png_ptr); |
||
1338 | #endif |
||
1339 | |||
1340 | |||
1341 | /* Extract multiple pixels with bit depths of 1, 2, or 4 from a single |
||
1342 | * byte into separate bytes (useful for paletted and grayscale images). |
||
1343 | */ |
||
1344 | if (transforms & PNG_TRANSFORM_PACKING) |
||
1345 | png_set_packing(png_ptr); |
||
1346 | #endif |
||
1347 | |||
1348 | |||
1349 | /* Change the order of packed pixels to least significant bit first |
||
1350 | * (not useful if you are using png_set_packing). |
||
1351 | */ |
||
1352 | if (transforms & PNG_TRANSFORM_PACKSWAP) |
||
1353 | png_set_packswap(png_ptr); |
||
1354 | #endif |
||
1355 | |||
1356 | |||
1357 | /* Expand paletted colors into true RGB triplets |
||
1358 | * Expand grayscale images to full 8 bits from 1, 2, or 4 bits/pixel |
||
1359 | * Expand paletted or RGB images with transparency to full alpha |
||
1360 | * channels so the data will be available as RGBA quartets. |
||
1361 | */ |
||
1362 | if (transforms & PNG_TRANSFORM_EXPAND) |
||
1363 | if ((png_ptr->bit_depth < 8) || |
||
1364 | (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) || |
||
1365 | (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))) |
||
1366 | png_set_expand(png_ptr); |
||
1367 | #endif |
||
1368 | |||
1369 | |||
1370 | */ |
||
1371 | |||
1372 | |||
1373 | /* Invert monochrome files to have 0 as white and 1 as black |
||
1374 | */ |
||
1375 | if (transforms & PNG_TRANSFORM_INVERT_MONO) |
||
1376 | png_set_invert_mono(png_ptr); |
||
1377 | #endif |
||
1378 | |||
1379 | |||
1380 | /* If you want to shift the pixel values from the range [0,255] or |
||
1381 | * [0,65535] to the original [0,7] or [0,31], or whatever range the |
||
1382 | * colors were originally in: |
||
1383 | */ |
||
1384 | if ((transforms & PNG_TRANSFORM_SHIFT) |
||
1385 | && png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT)) |
||
1386 | { |
||
1387 | png_color_8p sig_bit; |
||
1388 | |||
1389 | |||
1390 | png_set_shift(png_ptr, sig_bit); |
||
1391 | } |
||
1392 | #endif |
||
1393 | |||
1394 | |||
1395 | /* Flip the RGB pixels to BGR (or RGBA to BGRA) */ |
||
1396 | if (transforms & PNG_TRANSFORM_BGR) |
||
1397 | png_set_bgr(png_ptr); |
||
1398 | #endif |
||
1399 | |||
1400 | |||
1401 | /* Swap the RGBA or GA data to ARGB or AG (or BGRA to ABGR) */ |
||
1402 | if (transforms & PNG_TRANSFORM_SWAP_ALPHA) |
||
1403 | png_set_swap_alpha(png_ptr); |
||
1404 | #endif |
||
1405 | |||
1406 | |||
1407 | /* Swap bytes of 16 bit files to least significant byte first */ |
||
1408 | if (transforms & PNG_TRANSFORM_SWAP_ENDIAN) |
||
1409 | png_set_swap(png_ptr); |
||
1410 | #endif |
||
1411 | |||
1412 | |||
1413 | #ifdef PNG_READ_INVERT_ALPHA_SUPPORTED |
||
1414 | /* Invert the alpha channel from opacity to transparency */ |
||
1415 | if (transforms & PNG_TRANSFORM_INVERT_ALPHA) |
||
1416 | png_set_invert_alpha(png_ptr); |
||
1417 | #endif |
||
1418 | |||
1419 | |||
1420 | #ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED |
||
1421 | /* Expand grayscale image to RGB */ |
||
1422 | if (transforms & PNG_TRANSFORM_GRAY_TO_RGB) |
||
1423 | png_set_gray_to_rgb(png_ptr); |
||
1424 | #endif |
||
1425 | |||
1426 | |||
1427 | |||
1428 | |||
1429 | * and update info structure. REQUIRED if you are expecting libpng to |
||
1430 | * update the palette for you (i.e., you selected such a transform above). |
||
1431 | */ |
||
1432 | png_read_update_info(png_ptr, info_ptr); |
||
1433 | |||
1434 | |||
1435 | |||
1436 | |||
1437 | if (info_ptr->row_pointers == NULL) |
||
1438 | { |
||
1439 | png_uint_32 iptr; |
||
1440 | |||
1441 | |||
1442 | info_ptr->height * png_sizeof(png_bytep)); |
||
1443 | for (iptr=0; iptr |
||
1444 | info_ptr->row_pointers[iptr] = NULL; |
||
1445 | |||
1446 | |||
1447 | |||
1448 | |||
1449 | info_ptr->row_pointers[row] = (png_bytep)png_malloc(png_ptr, |
||
1450 | png_get_rowbytes(png_ptr, info_ptr)); |
||
1451 | } |
||
1452 | |||
1453 | |||
1454 | info_ptr->valid |= PNG_INFO_IDAT; |
||
1455 | |||
1456 | |||
1457 | png_read_end(png_ptr, info_ptr); |
||
1458 | |||
1459 | |||
1460 | PNG_UNUSED(params) |
||
1461 | |||
1462 | |||
1463 | #endif /* PNG_INFO_IMAGE_SUPPORTED */ |
||
1464 | #endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ |
||
1465 | #endif /* PNG_READ_SUPPORTED */>>>><>>><>>><>>>>>>>>>>> |
||
1466 |