2 /* pngpread.c - read a png file in push mode
4 * libpng 1.2.4 - July 8, 2002
5 * For conditions of distribution and use, see copyright notice in png.h
6 * Copyright (c) 1998-2002 Glenn Randers-Pehrson
7 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
8 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
14 #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
16 /* push model modes */
17 #define PNG_READ_SIG_MODE 0
18 #define PNG_READ_CHUNK_MODE 1
19 #define PNG_READ_IDAT_MODE 2
20 #define PNG_SKIP_MODE 3
21 #define PNG_READ_tEXt_MODE 4
22 #define PNG_READ_zTXt_MODE 5
23 #define PNG_READ_DONE_MODE 6
24 #define PNG_READ_iTXt_MODE 7
25 #define PNG_ERROR_MODE 8
28 png_process_data(png_structp png_ptr
, png_infop info_ptr
,
29 png_bytep buffer
, png_size_t buffer_size
)
31 png_push_restore_buffer(png_ptr
, buffer
, buffer_size
);
33 while (png_ptr
->buffer_size
)
35 png_process_some_data(png_ptr
, info_ptr
);
39 /* What we do with the incoming data depends on what we were previously
40 * doing before we ran out of data...
43 png_process_some_data(png_structp png_ptr
, png_infop info_ptr
)
45 switch (png_ptr
->process_mode
)
47 case PNG_READ_SIG_MODE
:
49 png_push_read_sig(png_ptr
, info_ptr
);
52 case PNG_READ_CHUNK_MODE
:
54 png_push_read_chunk(png_ptr
, info_ptr
);
57 case PNG_READ_IDAT_MODE
:
59 png_push_read_IDAT(png_ptr
);
62 #if defined(PNG_READ_tEXt_SUPPORTED)
63 case PNG_READ_tEXt_MODE
:
65 png_push_read_tEXt(png_ptr
, info_ptr
);
69 #if defined(PNG_READ_zTXt_SUPPORTED)
70 case PNG_READ_zTXt_MODE
:
72 png_push_read_zTXt(png_ptr
, info_ptr
);
76 #if defined(PNG_READ_iTXt_SUPPORTED)
77 case PNG_READ_iTXt_MODE
:
79 png_push_read_iTXt(png_ptr
, info_ptr
);
85 png_push_crc_finish(png_ptr
);
90 png_ptr
->buffer_size
= 0;
96 /* Read any remaining signature bytes from the stream and compare them with
97 * the correct PNG signature. It is possible that this routine is called
98 * with bytes already read from the signature, either because they have been
99 * checked by the calling application, or because of multiple calls to this
103 png_push_read_sig(png_structp png_ptr
, png_infop info_ptr
)
105 png_size_t num_checked
= png_ptr
->sig_bytes
,
106 num_to_check
= 8 - num_checked
;
108 if (png_ptr
->buffer_size
< num_to_check
)
110 num_to_check
= png_ptr
->buffer_size
;
113 png_push_fill_buffer(png_ptr
, &(info_ptr
->signature
[num_checked
]),
115 png_ptr
->sig_bytes
= (png_byte
)(png_ptr
->sig_bytes
+num_to_check
);
117 if (png_sig_cmp(info_ptr
->signature
, num_checked
, num_to_check
))
119 if (num_checked
< 4 &&
120 png_sig_cmp(info_ptr
->signature
, num_checked
, num_to_check
- 4))
121 png_error(png_ptr
, "Not a PNG file");
123 png_error(png_ptr
, "PNG file corrupted by ASCII conversion");
127 if (png_ptr
->sig_bytes
>= 8)
129 png_ptr
->process_mode
= PNG_READ_CHUNK_MODE
;
135 png_push_read_chunk(png_structp png_ptr
, png_infop info_ptr
)
137 #ifdef PNG_USE_LOCAL_ARRAYS
142 #if defined(PNG_READ_bKGD_SUPPORTED)
145 #if defined(PNG_READ_cHRM_SUPPORTED)
148 #if defined(PNG_READ_gAMA_SUPPORTED)
151 #if defined(PNG_READ_hIST_SUPPORTED)
154 #if defined(PNG_READ_iCCP_SUPPORTED)
157 #if defined(PNG_READ_iTXt_SUPPORTED)
160 #if defined(PNG_READ_oFFs_SUPPORTED)
163 #if defined(PNG_READ_pCAL_SUPPORTED)
166 #if defined(PNG_READ_pHYs_SUPPORTED)
169 #if defined(PNG_READ_sBIT_SUPPORTED)
172 #if defined(PNG_READ_sCAL_SUPPORTED)
175 #if defined(PNG_READ_sRGB_SUPPORTED)
178 #if defined(PNG_READ_sPLT_SUPPORTED)
181 #if defined(PNG_READ_tEXt_SUPPORTED)
184 #if defined(PNG_READ_tIME_SUPPORTED)
187 #if defined(PNG_READ_tRNS_SUPPORTED)
190 #if defined(PNG_READ_zTXt_SUPPORTED)
193 #endif /* PNG_USE_LOCAL_ARRAYS */
194 /* First we make sure we have enough data for the 4 byte chunk name
195 * and the 4 byte chunk length before proceeding with decoding the
196 * chunk data. To fully decode each of these chunks, we also make
197 * sure we have enough data in the buffer for the 4 byte CRC at the
198 * end of every chunk (except IDAT, which is handled separately).
200 if (!(png_ptr
->mode
& PNG_HAVE_CHUNK_HEADER
))
202 png_byte chunk_length
[4];
204 if (png_ptr
->buffer_size
< 8)
206 png_push_save_buffer(png_ptr
);
210 png_push_fill_buffer(png_ptr
, chunk_length
, 4);
211 png_ptr
->push_length
= png_get_uint_32(chunk_length
);
212 png_reset_crc(png_ptr
);
213 png_crc_read(png_ptr
, png_ptr
->chunk_name
, 4);
214 png_ptr
->mode
|= PNG_HAVE_CHUNK_HEADER
;
217 if (!png_memcmp(png_ptr
->chunk_name
, png_IHDR
, 4))
219 if (png_ptr
->push_length
+ 4 > png_ptr
->buffer_size
)
221 png_push_save_buffer(png_ptr
);
224 png_handle_IHDR(png_ptr
, info_ptr
, png_ptr
->push_length
);
226 else if (!png_memcmp(png_ptr
->chunk_name
, png_PLTE
, 4))
228 if (png_ptr
->push_length
+ 4 > png_ptr
->buffer_size
)
230 png_push_save_buffer(png_ptr
);
233 png_handle_PLTE(png_ptr
, info_ptr
, png_ptr
->push_length
);
235 else if (!png_memcmp(png_ptr
->chunk_name
, (png_bytep
)png_IDAT
, 4))
237 /* If we reach an IDAT chunk, this means we have read all of the
238 * header chunks, and we can start reading the image (or if this
239 * is called after the image has been read - we have an error).
241 if (!(png_ptr
->mode
& PNG_HAVE_IHDR
))
242 png_error(png_ptr
, "Missing IHDR before IDAT");
243 else if (png_ptr
->color_type
== PNG_COLOR_TYPE_PALETTE
&&
244 !(png_ptr
->mode
& PNG_HAVE_PLTE
))
245 png_error(png_ptr
, "Missing PLTE before IDAT");
247 if (png_ptr
->mode
& PNG_HAVE_IDAT
)
249 if (png_ptr
->push_length
== 0)
252 if (png_ptr
->mode
& PNG_AFTER_IDAT
)
253 png_error(png_ptr
, "Too many IDAT's found");
256 png_ptr
->idat_size
= png_ptr
->push_length
;
257 png_ptr
->mode
|= PNG_HAVE_IDAT
;
258 png_ptr
->process_mode
= PNG_READ_IDAT_MODE
;
259 png_push_have_info(png_ptr
, info_ptr
);
260 png_ptr
->zstream
.avail_out
= (uInt
)png_ptr
->irowbytes
;
261 png_ptr
->zstream
.next_out
= png_ptr
->row_buf
;
264 else if (!png_memcmp(png_ptr
->chunk_name
, png_IEND
, 4))
266 if (png_ptr
->push_length
+ 4 > png_ptr
->buffer_size
)
268 png_push_save_buffer(png_ptr
);
271 png_handle_IEND(png_ptr
, info_ptr
, png_ptr
->push_length
);
273 png_ptr
->process_mode
= PNG_READ_DONE_MODE
;
274 png_push_have_end(png_ptr
, info_ptr
);
276 #if defined(PNG_READ_gAMA_SUPPORTED)
277 else if (!png_memcmp(png_ptr
->chunk_name
, png_gAMA
, 4))
279 if (png_ptr
->push_length
+ 4 > png_ptr
->buffer_size
)
281 png_push_save_buffer(png_ptr
);
284 png_handle_gAMA(png_ptr
, info_ptr
, png_ptr
->push_length
);
287 #if defined(PNG_READ_sBIT_SUPPORTED)
288 else if (!png_memcmp(png_ptr
->chunk_name
, png_sBIT
, 4))
290 if (png_ptr
->push_length
+ 4 > png_ptr
->buffer_size
)
292 png_push_save_buffer(png_ptr
);
295 png_handle_sBIT(png_ptr
, info_ptr
, png_ptr
->push_length
);
298 #if defined(PNG_READ_cHRM_SUPPORTED)
299 else if (!png_memcmp(png_ptr
->chunk_name
, png_cHRM
, 4))
301 if (png_ptr
->push_length
+ 4 > png_ptr
->buffer_size
)
303 png_push_save_buffer(png_ptr
);
306 png_handle_cHRM(png_ptr
, info_ptr
, png_ptr
->push_length
);
309 #if defined(PNG_READ_sRGB_SUPPORTED)
310 else if (!png_memcmp(png_ptr
->chunk_name
, png_sRGB
, 4))
312 if (png_ptr
->push_length
+ 4 > png_ptr
->buffer_size
)
314 png_push_save_buffer(png_ptr
);
317 png_handle_sRGB(png_ptr
, info_ptr
, png_ptr
->push_length
);
320 #if defined(PNG_READ_iCCP_SUPPORTED)
321 else if (!png_memcmp(png_ptr
->chunk_name
, png_iCCP
, 4))
323 if (png_ptr
->push_length
+ 4 > png_ptr
->buffer_size
)
325 png_push_save_buffer(png_ptr
);
328 png_handle_iCCP(png_ptr
, info_ptr
, png_ptr
->push_length
);
331 #if defined(PNG_READ_sPLT_SUPPORTED)
332 else if (!png_memcmp(png_ptr
->chunk_name
, png_sPLT
, 4))
334 if (png_ptr
->push_length
+ 4 > png_ptr
->buffer_size
)
336 png_push_save_buffer(png_ptr
);
339 png_handle_sPLT(png_ptr
, info_ptr
, png_ptr
->push_length
);
342 #if defined(PNG_READ_tRNS_SUPPORTED)
343 else if (!png_memcmp(png_ptr
->chunk_name
, png_tRNS
, 4))
345 if (png_ptr
->push_length
+ 4 > png_ptr
->buffer_size
)
347 png_push_save_buffer(png_ptr
);
350 png_handle_tRNS(png_ptr
, info_ptr
, png_ptr
->push_length
);
353 #if defined(PNG_READ_bKGD_SUPPORTED)
354 else if (!png_memcmp(png_ptr
->chunk_name
, png_bKGD
, 4))
356 if (png_ptr
->push_length
+ 4 > png_ptr
->buffer_size
)
358 png_push_save_buffer(png_ptr
);
361 png_handle_bKGD(png_ptr
, info_ptr
, png_ptr
->push_length
);
364 #if defined(PNG_READ_hIST_SUPPORTED)
365 else if (!png_memcmp(png_ptr
->chunk_name
, png_hIST
, 4))
367 if (png_ptr
->push_length
+ 4 > png_ptr
->buffer_size
)
369 png_push_save_buffer(png_ptr
);
372 png_handle_hIST(png_ptr
, info_ptr
, png_ptr
->push_length
);
375 #if defined(PNG_READ_pHYs_SUPPORTED)
376 else if (!png_memcmp(png_ptr
->chunk_name
, png_pHYs
, 4))
378 if (png_ptr
->push_length
+ 4 > png_ptr
->buffer_size
)
380 png_push_save_buffer(png_ptr
);
383 png_handle_pHYs(png_ptr
, info_ptr
, png_ptr
->push_length
);
386 #if defined(PNG_READ_oFFs_SUPPORTED)
387 else if (!png_memcmp(png_ptr
->chunk_name
, png_oFFs
, 4))
389 if (png_ptr
->push_length
+ 4 > png_ptr
->buffer_size
)
391 png_push_save_buffer(png_ptr
);
394 png_handle_oFFs(png_ptr
, info_ptr
, png_ptr
->push_length
);
397 #if defined(PNG_READ_pCAL_SUPPORTED)
398 else if (!png_memcmp(png_ptr
->chunk_name
, png_pCAL
, 4))
400 if (png_ptr
->push_length
+ 4 > png_ptr
->buffer_size
)
402 png_push_save_buffer(png_ptr
);
405 png_handle_pCAL(png_ptr
, info_ptr
, png_ptr
->push_length
);
408 #if defined(PNG_READ_sCAL_SUPPORTED)
409 else if (!png_memcmp(png_ptr
->chunk_name
, png_sCAL
, 4))
411 if (png_ptr
->push_length
+ 4 > png_ptr
->buffer_size
)
413 png_push_save_buffer(png_ptr
);
416 png_handle_sCAL(png_ptr
, info_ptr
, png_ptr
->push_length
);
419 #if defined(PNG_READ_tIME_SUPPORTED)
420 else if (!png_memcmp(png_ptr
->chunk_name
, png_tIME
, 4))
422 if (png_ptr
->push_length
+ 4 > png_ptr
->buffer_size
)
424 png_push_save_buffer(png_ptr
);
427 png_handle_tIME(png_ptr
, info_ptr
, png_ptr
->push_length
);
430 #if defined(PNG_READ_tEXt_SUPPORTED)
431 else if (!png_memcmp(png_ptr
->chunk_name
, png_tEXt
, 4))
433 if (png_ptr
->push_length
+ 4 > png_ptr
->buffer_size
)
435 png_push_save_buffer(png_ptr
);
438 png_push_handle_tEXt(png_ptr
, info_ptr
, png_ptr
->push_length
);
441 #if defined(PNG_READ_zTXt_SUPPORTED)
442 else if (!png_memcmp(png_ptr
->chunk_name
, png_zTXt
, 4))
444 if (png_ptr
->push_length
+ 4 > png_ptr
->buffer_size
)
446 png_push_save_buffer(png_ptr
);
449 png_push_handle_zTXt(png_ptr
, info_ptr
, png_ptr
->push_length
);
452 #if defined(PNG_READ_iTXt_SUPPORTED)
453 else if (!png_memcmp(png_ptr
->chunk_name
, png_iTXt
, 4))
455 if (png_ptr
->push_length
+ 4 > png_ptr
->buffer_size
)
457 png_push_save_buffer(png_ptr
);
460 png_push_handle_iTXt(png_ptr
, info_ptr
, png_ptr
->push_length
);
465 if (png_ptr
->push_length
+ 4 > png_ptr
->buffer_size
)
467 png_push_save_buffer(png_ptr
);
470 png_push_handle_unknown(png_ptr
, info_ptr
, png_ptr
->push_length
);
473 png_ptr
->mode
&= ~PNG_HAVE_CHUNK_HEADER
;
477 png_push_crc_skip(png_structp png_ptr
, png_uint_32 skip
)
479 png_ptr
->process_mode
= PNG_SKIP_MODE
;
480 png_ptr
->skip_length
= skip
;
484 png_push_crc_finish(png_structp png_ptr
)
486 if (png_ptr
->skip_length
&& png_ptr
->save_buffer_size
)
488 png_size_t save_size
;
490 if (png_ptr
->skip_length
< (png_uint_32
)png_ptr
->save_buffer_size
)
491 save_size
= (png_size_t
)png_ptr
->skip_length
;
493 save_size
= png_ptr
->save_buffer_size
;
495 png_calculate_crc(png_ptr
, png_ptr
->save_buffer_ptr
, save_size
);
497 png_ptr
->skip_length
-= save_size
;
498 png_ptr
->buffer_size
-= save_size
;
499 png_ptr
->save_buffer_size
-= save_size
;
500 png_ptr
->save_buffer_ptr
+= save_size
;
502 if (png_ptr
->skip_length
&& png_ptr
->current_buffer_size
)
504 png_size_t save_size
;
506 if (png_ptr
->skip_length
< (png_uint_32
)png_ptr
->current_buffer_size
)
507 save_size
= (png_size_t
)png_ptr
->skip_length
;
509 save_size
= png_ptr
->current_buffer_size
;
511 png_calculate_crc(png_ptr
, png_ptr
->current_buffer_ptr
, save_size
);
513 png_ptr
->skip_length
-= save_size
;
514 png_ptr
->buffer_size
-= save_size
;
515 png_ptr
->current_buffer_size
-= save_size
;
516 png_ptr
->current_buffer_ptr
+= save_size
;
518 if (!png_ptr
->skip_length
)
520 if (png_ptr
->buffer_size
< 4)
522 png_push_save_buffer(png_ptr
);
526 png_crc_finish(png_ptr
, 0);
527 png_ptr
->process_mode
= PNG_READ_CHUNK_MODE
;
532 png_push_fill_buffer(png_structp png_ptr
, png_bytep buffer
, png_size_t length
)
537 if (png_ptr
->save_buffer_size
)
539 png_size_t save_size
;
541 if (length
< png_ptr
->save_buffer_size
)
544 save_size
= png_ptr
->save_buffer_size
;
546 png_memcpy(ptr
, png_ptr
->save_buffer_ptr
, save_size
);
549 png_ptr
->buffer_size
-= save_size
;
550 png_ptr
->save_buffer_size
-= save_size
;
551 png_ptr
->save_buffer_ptr
+= save_size
;
553 if (length
&& png_ptr
->current_buffer_size
)
555 png_size_t save_size
;
557 if (length
< png_ptr
->current_buffer_size
)
560 save_size
= png_ptr
->current_buffer_size
;
562 png_memcpy(ptr
, png_ptr
->current_buffer_ptr
, save_size
);
563 png_ptr
->buffer_size
-= save_size
;
564 png_ptr
->current_buffer_size
-= save_size
;
565 png_ptr
->current_buffer_ptr
+= save_size
;
570 png_push_save_buffer(png_structp png_ptr
)
572 if (png_ptr
->save_buffer_size
)
574 if (png_ptr
->save_buffer_ptr
!= png_ptr
->save_buffer
)
580 istop
= png_ptr
->save_buffer_size
;
581 for (i
= 0, sp
= png_ptr
->save_buffer_ptr
, dp
= png_ptr
->save_buffer
;
582 i
< istop
; i
++, sp
++, dp
++)
588 if (png_ptr
->save_buffer_size
+ png_ptr
->current_buffer_size
>
589 png_ptr
->save_buffer_max
)
592 png_bytep old_buffer
;
594 new_max
= png_ptr
->save_buffer_size
+ png_ptr
->current_buffer_size
+ 256;
595 old_buffer
= png_ptr
->save_buffer
;
596 png_ptr
->save_buffer
= (png_bytep
)png_malloc(png_ptr
,
597 (png_uint_32
)new_max
);
598 png_memcpy(png_ptr
->save_buffer
, old_buffer
, png_ptr
->save_buffer_size
);
599 png_free(png_ptr
, old_buffer
);
600 png_ptr
->save_buffer_max
= new_max
;
602 if (png_ptr
->current_buffer_size
)
604 png_memcpy(png_ptr
->save_buffer
+ png_ptr
->save_buffer_size
,
605 png_ptr
->current_buffer_ptr
, png_ptr
->current_buffer_size
);
606 png_ptr
->save_buffer_size
+= png_ptr
->current_buffer_size
;
607 png_ptr
->current_buffer_size
= 0;
609 png_ptr
->save_buffer_ptr
= png_ptr
->save_buffer
;
610 png_ptr
->buffer_size
= 0;
614 png_push_restore_buffer(png_structp png_ptr
, png_bytep buffer
,
615 png_size_t buffer_length
)
617 png_ptr
->current_buffer
= buffer
;
618 png_ptr
->current_buffer_size
= buffer_length
;
619 png_ptr
->buffer_size
= buffer_length
+ png_ptr
->save_buffer_size
;
620 png_ptr
->current_buffer_ptr
= png_ptr
->current_buffer
;
624 png_push_read_IDAT(png_structp png_ptr
)
626 #ifdef PNG_USE_LOCAL_ARRAYS
629 if (!(png_ptr
->mode
& PNG_HAVE_CHUNK_HEADER
))
631 png_byte chunk_length
[4];
633 if (png_ptr
->buffer_size
< 8)
635 png_push_save_buffer(png_ptr
);
639 png_push_fill_buffer(png_ptr
, chunk_length
, 4);
640 png_ptr
->push_length
= png_get_uint_32(chunk_length
);
642 png_reset_crc(png_ptr
);
643 png_crc_read(png_ptr
, png_ptr
->chunk_name
, 4);
644 png_ptr
->mode
|= PNG_HAVE_CHUNK_HEADER
;
646 if (png_memcmp(png_ptr
->chunk_name
, (png_bytep
)png_IDAT
, 4))
648 png_ptr
->process_mode
= PNG_READ_CHUNK_MODE
;
649 if (!(png_ptr
->flags
& PNG_FLAG_ZLIB_FINISHED
))
650 png_error(png_ptr
, "Not enough compressed data");
654 png_ptr
->idat_size
= png_ptr
->push_length
;
656 if (png_ptr
->idat_size
&& png_ptr
->save_buffer_size
)
658 png_size_t save_size
;
660 if (png_ptr
->idat_size
< (png_uint_32
)png_ptr
->save_buffer_size
)
662 save_size
= (png_size_t
)png_ptr
->idat_size
;
663 /* check for overflow */
664 if((png_uint_32
)save_size
!= png_ptr
->idat_size
)
665 png_error(png_ptr
, "save_size overflowed in pngpread");
668 save_size
= png_ptr
->save_buffer_size
;
670 png_calculate_crc(png_ptr
, png_ptr
->save_buffer_ptr
, save_size
);
671 png_process_IDAT_data(png_ptr
, png_ptr
->save_buffer_ptr
, save_size
);
673 png_ptr
->idat_size
-= save_size
;
674 png_ptr
->buffer_size
-= save_size
;
675 png_ptr
->save_buffer_size
-= save_size
;
676 png_ptr
->save_buffer_ptr
+= save_size
;
678 if (png_ptr
->idat_size
&& png_ptr
->current_buffer_size
)
680 png_size_t save_size
;
682 if (png_ptr
->idat_size
< (png_uint_32
)png_ptr
->current_buffer_size
)
684 save_size
= (png_size_t
)png_ptr
->idat_size
;
685 /* check for overflow */
686 if((png_uint_32
)save_size
!= png_ptr
->idat_size
)
687 png_error(png_ptr
, "save_size overflowed in pngpread");
690 save_size
= png_ptr
->current_buffer_size
;
692 png_calculate_crc(png_ptr
, png_ptr
->current_buffer_ptr
, save_size
);
693 png_process_IDAT_data(png_ptr
, png_ptr
->current_buffer_ptr
, save_size
);
695 png_ptr
->idat_size
-= save_size
;
696 png_ptr
->buffer_size
-= save_size
;
697 png_ptr
->current_buffer_size
-= save_size
;
698 png_ptr
->current_buffer_ptr
+= save_size
;
700 if (!png_ptr
->idat_size
)
702 if (png_ptr
->buffer_size
< 4)
704 png_push_save_buffer(png_ptr
);
708 png_crc_finish(png_ptr
, 0);
709 png_ptr
->mode
&= ~PNG_HAVE_CHUNK_HEADER
;
714 png_process_IDAT_data(png_structp png_ptr
, png_bytep buffer
,
715 png_size_t buffer_length
)
719 if ((png_ptr
->flags
& PNG_FLAG_ZLIB_FINISHED
) && buffer_length
)
720 png_error(png_ptr
, "Extra compression data");
722 png_ptr
->zstream
.next_in
= buffer
;
723 png_ptr
->zstream
.avail_in
= (uInt
)buffer_length
;
726 ret
= inflate(&png_ptr
->zstream
, Z_PARTIAL_FLUSH
);
729 if (ret
== Z_STREAM_END
)
731 if (png_ptr
->zstream
.avail_in
)
732 png_error(png_ptr
, "Extra compressed data");
733 if (!(png_ptr
->zstream
.avail_out
))
735 png_push_process_row(png_ptr
);
738 png_ptr
->mode
|= PNG_AFTER_IDAT
;
739 png_ptr
->flags
|= PNG_FLAG_ZLIB_FINISHED
;
742 else if (ret
== Z_BUF_ERROR
)
745 png_error(png_ptr
, "Decompression Error");
747 if (!(png_ptr
->zstream
.avail_out
))
750 #if defined(PNG_READ_INTERLACING_SUPPORTED)
751 png_ptr
->interlaced
&& png_ptr
->pass
> 6) ||
752 (!png_ptr
->interlaced
&&
754 png_ptr
->row_number
== png_ptr
->num_rows
-1))
755 png_error(png_ptr
, "Too much data in IDAT chunks");
756 png_push_process_row(png_ptr
);
757 png_ptr
->zstream
.avail_out
= (uInt
)png_ptr
->irowbytes
;
758 png_ptr
->zstream
.next_out
= png_ptr
->row_buf
;
766 png_push_process_row(png_structp png_ptr
)
768 png_ptr
->row_info
.color_type
= png_ptr
->color_type
;
769 png_ptr
->row_info
.width
= png_ptr
->iwidth
;
770 png_ptr
->row_info
.channels
= png_ptr
->channels
;
771 png_ptr
->row_info
.bit_depth
= png_ptr
->bit_depth
;
772 png_ptr
->row_info
.pixel_depth
= png_ptr
->pixel_depth
;
774 png_ptr
->row_info
.rowbytes
= ((png_ptr
->row_info
.width
*
775 (png_uint_32
)png_ptr
->row_info
.pixel_depth
+ 7) >> 3);
777 png_read_filter_row(png_ptr
, &(png_ptr
->row_info
),
778 png_ptr
->row_buf
+ 1, png_ptr
->prev_row
+ 1,
779 (int)(png_ptr
->row_buf
[0]));
781 png_memcpy_check(png_ptr
, png_ptr
->prev_row
, png_ptr
->row_buf
,
782 png_ptr
->rowbytes
+ 1);
784 if (png_ptr
->transformations
)
785 png_do_read_transformations(png_ptr
);
787 #if defined(PNG_READ_INTERLACING_SUPPORTED)
788 /* blow up interlaced rows to full size */
789 if (png_ptr
->interlaced
&& (png_ptr
->transformations
& PNG_INTERLACE
))
791 if (png_ptr
->pass
< 6)
792 /* old interface (pre-1.0.9):
793 png_do_read_interlace(&(png_ptr->row_info),
794 png_ptr->row_buf + 1, png_ptr->pass, png_ptr->transformations);
796 png_do_read_interlace(png_ptr
);
798 switch (png_ptr
->pass
)
803 for (i
= 0; i
< 8 && png_ptr
->pass
== 0; i
++)
805 png_push_have_row(png_ptr
, png_ptr
->row_buf
+ 1);
806 png_read_push_finish_row(png_ptr
); /* updates png_ptr->pass */
808 if (png_ptr
->pass
== 2) /* pass 1 might be empty */
810 for (i
= 0; i
< 4 && png_ptr
->pass
== 2; i
++)
812 png_push_have_row(png_ptr
, png_bytep_NULL
);
813 png_read_push_finish_row(png_ptr
);
816 if (png_ptr
->pass
== 4 && png_ptr
->height
<= 4)
818 for (i
= 0; i
< 2 && png_ptr
->pass
== 4; i
++)
820 png_push_have_row(png_ptr
, png_bytep_NULL
);
821 png_read_push_finish_row(png_ptr
);
824 if (png_ptr
->pass
== 6 && png_ptr
->height
<= 4)
826 png_push_have_row(png_ptr
, png_bytep_NULL
);
827 png_read_push_finish_row(png_ptr
);
834 for (i
= 0; i
< 8 && png_ptr
->pass
== 1; i
++)
836 png_push_have_row(png_ptr
, png_ptr
->row_buf
+ 1);
837 png_read_push_finish_row(png_ptr
);
839 if (png_ptr
->pass
== 2) /* skip top 4 generated rows */
841 for (i
= 0; i
< 4 && png_ptr
->pass
== 2; i
++)
843 png_push_have_row(png_ptr
, png_bytep_NULL
);
844 png_read_push_finish_row(png_ptr
);
852 for (i
= 0; i
< 4 && png_ptr
->pass
== 2; i
++)
854 png_push_have_row(png_ptr
, png_ptr
->row_buf
+ 1);
855 png_read_push_finish_row(png_ptr
);
857 for (i
= 0; i
< 4 && png_ptr
->pass
== 2; i
++)
859 png_push_have_row(png_ptr
, png_bytep_NULL
);
860 png_read_push_finish_row(png_ptr
);
862 if (png_ptr
->pass
== 4) /* pass 3 might be empty */
864 for (i
= 0; i
< 2 && png_ptr
->pass
== 4; i
++)
866 png_push_have_row(png_ptr
, png_bytep_NULL
);
867 png_read_push_finish_row(png_ptr
);
875 for (i
= 0; i
< 4 && png_ptr
->pass
== 3; i
++)
877 png_push_have_row(png_ptr
, png_ptr
->row_buf
+ 1);
878 png_read_push_finish_row(png_ptr
);
880 if (png_ptr
->pass
== 4) /* skip top two generated rows */
882 for (i
= 0; i
< 2 && png_ptr
->pass
== 4; i
++)
884 png_push_have_row(png_ptr
, png_bytep_NULL
);
885 png_read_push_finish_row(png_ptr
);
893 for (i
= 0; i
< 2 && png_ptr
->pass
== 4; i
++)
895 png_push_have_row(png_ptr
, png_ptr
->row_buf
+ 1);
896 png_read_push_finish_row(png_ptr
);
898 for (i
= 0; i
< 2 && png_ptr
->pass
== 4; i
++)
900 png_push_have_row(png_ptr
, png_bytep_NULL
);
901 png_read_push_finish_row(png_ptr
);
903 if (png_ptr
->pass
== 6) /* pass 5 might be empty */
905 png_push_have_row(png_ptr
, png_bytep_NULL
);
906 png_read_push_finish_row(png_ptr
);
913 for (i
= 0; i
< 2 && png_ptr
->pass
== 5; i
++)
915 png_push_have_row(png_ptr
, png_ptr
->row_buf
+ 1);
916 png_read_push_finish_row(png_ptr
);
918 if (png_ptr
->pass
== 6) /* skip top generated row */
920 png_push_have_row(png_ptr
, png_bytep_NULL
);
921 png_read_push_finish_row(png_ptr
);
927 png_push_have_row(png_ptr
, png_ptr
->row_buf
+ 1);
928 png_read_push_finish_row(png_ptr
);
929 if (png_ptr
->pass
!= 6)
931 png_push_have_row(png_ptr
, png_bytep_NULL
);
932 png_read_push_finish_row(png_ptr
);
939 png_push_have_row(png_ptr
, png_ptr
->row_buf
+ 1);
940 png_read_push_finish_row(png_ptr
);
945 png_read_push_finish_row(png_structp png_ptr
)
947 #ifdef PNG_USE_LOCAL_ARRAYS
948 /* arrays to facilitate easy interlacing - use pass (0 - 6) as index */
950 /* start of interlace block */
951 const int FARDATA png_pass_start
[] = {0, 4, 0, 2, 0, 1, 0};
953 /* offset to next interlace block */
954 const int FARDATA png_pass_inc
[] = {8, 8, 4, 4, 2, 2, 1};
956 /* start of interlace block in the y direction */
957 const int FARDATA png_pass_ystart
[] = {0, 0, 4, 0, 2, 0, 1};
959 /* offset to next interlace block in the y direction */
960 const int FARDATA png_pass_yinc
[] = {8, 8, 8, 4, 4, 2, 2};
962 /* Width of interlace block. This is not currently used - if you need
963 * it, uncomment it here and in png.h
964 const int FARDATA png_pass_width[] = {8, 4, 4, 2, 2, 1, 1};
967 /* Height of interlace block. This is not currently used - if you need
968 * it, uncomment it here and in png.h
969 const int FARDATA png_pass_height[] = {8, 8, 4, 4, 2, 2, 1};
973 png_ptr
->row_number
++;
974 if (png_ptr
->row_number
< png_ptr
->num_rows
)
977 if (png_ptr
->interlaced
)
979 png_ptr
->row_number
= 0;
980 png_memset_check(png_ptr
, png_ptr
->prev_row
, 0,
981 png_ptr
->rowbytes
+ 1);
985 if ((png_ptr
->pass
== 1 && png_ptr
->width
< 5) ||
986 (png_ptr
->pass
== 3 && png_ptr
->width
< 3) ||
987 (png_ptr
->pass
== 5 && png_ptr
->width
< 2))
990 if (png_ptr
->pass
>= 7)
993 png_ptr
->iwidth
= (png_ptr
->width
+
994 png_pass_inc
[png_ptr
->pass
] - 1 -
995 png_pass_start
[png_ptr
->pass
]) /
996 png_pass_inc
[png_ptr
->pass
];
998 png_ptr
->irowbytes
= ((png_ptr
->iwidth
*
999 png_ptr
->pixel_depth
+ 7) >> 3) + 1;
1001 if (png_ptr
->transformations
& PNG_INTERLACE
)
1004 png_ptr
->num_rows
= (png_ptr
->height
+
1005 png_pass_yinc
[png_ptr
->pass
] - 1 -
1006 png_pass_ystart
[png_ptr
->pass
]) /
1007 png_pass_yinc
[png_ptr
->pass
];
1009 } while (png_ptr
->iwidth
== 0 || png_ptr
->num_rows
== 0);
1013 #if defined(PNG_READ_tEXt_SUPPORTED)
1015 png_push_handle_tEXt(png_structp png_ptr
, png_infop info_ptr
, png_uint_32
1018 if (!(png_ptr
->mode
& PNG_HAVE_IHDR
) || (png_ptr
->mode
& PNG_HAVE_IEND
))
1020 png_error(png_ptr
, "Out of place tEXt");
1021 /* to quiet some compiler warnings */
1022 if(info_ptr
== NULL
) return;
1025 #ifdef PNG_MAX_MALLOC_64K
1026 png_ptr
->skip_length
= 0; /* This may not be necessary */
1028 if (length
> (png_uint_32
)65535L) /* Can't hold entire string in memory */
1030 png_warning(png_ptr
, "tEXt chunk too large to fit in memory");
1031 png_ptr
->skip_length
= length
- (png_uint_32
)65535L;
1032 length
= (png_uint_32
)65535L;
1036 png_ptr
->current_text
= (png_charp
)png_malloc(png_ptr
,
1037 (png_uint_32
)(length
+1));
1038 png_ptr
->current_text
[length
] = '\0';
1039 png_ptr
->current_text_ptr
= png_ptr
->current_text
;
1040 png_ptr
->current_text_size
= (png_size_t
)length
;
1041 png_ptr
->current_text_left
= (png_size_t
)length
;
1042 png_ptr
->process_mode
= PNG_READ_tEXt_MODE
;
1046 png_push_read_tEXt(png_structp png_ptr
, png_infop info_ptr
)
1048 if (png_ptr
->buffer_size
&& png_ptr
->current_text_left
)
1050 png_size_t text_size
;
1052 if (png_ptr
->buffer_size
< png_ptr
->current_text_left
)
1053 text_size
= png_ptr
->buffer_size
;
1055 text_size
= png_ptr
->current_text_left
;
1056 png_crc_read(png_ptr
, (png_bytep
)png_ptr
->current_text_ptr
, text_size
);
1057 png_ptr
->current_text_left
-= text_size
;
1058 png_ptr
->current_text_ptr
+= text_size
;
1060 if (!(png_ptr
->current_text_left
))
1067 if (png_ptr
->buffer_size
< 4)
1069 png_push_save_buffer(png_ptr
);
1073 png_push_crc_finish(png_ptr
);
1075 #if defined(PNG_MAX_MALLOC_64K)
1076 if (png_ptr
->skip_length
)
1080 key
= png_ptr
->current_text
;
1082 for (text
= key
; *text
; text
++)
1085 if (text
!= key
+ png_ptr
->current_text_size
)
1088 text_ptr
= (png_textp
)png_malloc(png_ptr
, (png_uint_32
)sizeof(png_text
));
1089 text_ptr
->compression
= PNG_TEXT_COMPRESSION_NONE
;
1090 text_ptr
->key
= key
;
1091 #ifdef PNG_iTXt_SUPPORTED
1092 text_ptr
->lang
= NULL
;
1093 text_ptr
->lang_key
= NULL
;
1095 text_ptr
->text
= text
;
1097 ret
= png_set_text_2(png_ptr
, info_ptr
, text_ptr
, 1);
1099 png_free(png_ptr
, key
);
1100 png_free(png_ptr
, text_ptr
);
1101 png_ptr
->current_text
= NULL
;
1104 png_warning(png_ptr
, "Insufficient memory to store text chunk.");
1109 #if defined(PNG_READ_zTXt_SUPPORTED)
1111 png_push_handle_zTXt(png_structp png_ptr
, png_infop info_ptr
, png_uint_32
1114 if (!(png_ptr
->mode
& PNG_HAVE_IHDR
) || (png_ptr
->mode
& PNG_HAVE_IEND
))
1116 png_error(png_ptr
, "Out of place zTXt");
1117 /* to quiet some compiler warnings */
1118 if(info_ptr
== NULL
) return;
1121 #ifdef PNG_MAX_MALLOC_64K
1122 /* We can't handle zTXt chunks > 64K, since we don't have enough space
1123 * to be able to store the uncompressed data. Actually, the threshold
1124 * is probably around 32K, but it isn't as definite as 64K is.
1126 if (length
> (png_uint_32
)65535L)
1128 png_warning(png_ptr
, "zTXt chunk too large to fit in memory");
1129 png_push_crc_skip(png_ptr
, length
);
1134 png_ptr
->current_text
= (png_charp
)png_malloc(png_ptr
,
1135 (png_uint_32
)(length
+1));
1136 png_ptr
->current_text
[length
] = '\0';
1137 png_ptr
->current_text_ptr
= png_ptr
->current_text
;
1138 png_ptr
->current_text_size
= (png_size_t
)length
;
1139 png_ptr
->current_text_left
= (png_size_t
)length
;
1140 png_ptr
->process_mode
= PNG_READ_zTXt_MODE
;
1144 png_push_read_zTXt(png_structp png_ptr
, png_infop info_ptr
)
1146 if (png_ptr
->buffer_size
&& png_ptr
->current_text_left
)
1148 png_size_t text_size
;
1150 if (png_ptr
->buffer_size
< (png_uint_32
)png_ptr
->current_text_left
)
1151 text_size
= png_ptr
->buffer_size
;
1153 text_size
= png_ptr
->current_text_left
;
1154 png_crc_read(png_ptr
, (png_bytep
)png_ptr
->current_text_ptr
, text_size
);
1155 png_ptr
->current_text_left
-= text_size
;
1156 png_ptr
->current_text_ptr
+= text_size
;
1158 if (!(png_ptr
->current_text_left
))
1164 png_size_t text_size
, key_size
;
1166 if (png_ptr
->buffer_size
< 4)
1168 png_push_save_buffer(png_ptr
);
1172 png_push_crc_finish(png_ptr
);
1174 key
= png_ptr
->current_text
;
1176 for (text
= key
; *text
; text
++)
1179 /* zTXt can't have zero text */
1180 if (text
== key
+ png_ptr
->current_text_size
)
1182 png_ptr
->current_text
= NULL
;
1183 png_free(png_ptr
, key
);
1189 if (*text
!= PNG_TEXT_COMPRESSION_zTXt
) /* check compression byte */
1191 png_ptr
->current_text
= NULL
;
1192 png_free(png_ptr
, key
);
1198 png_ptr
->zstream
.next_in
= (png_bytep
)text
;
1199 png_ptr
->zstream
.avail_in
= (uInt
)(png_ptr
->current_text_size
-
1201 png_ptr
->zstream
.next_out
= png_ptr
->zbuf
;
1202 png_ptr
->zstream
.avail_out
= (uInt
)png_ptr
->zbuf_size
;
1204 key_size
= text
- key
;
1209 while (png_ptr
->zstream
.avail_in
)
1211 ret
= inflate(&png_ptr
->zstream
, Z_PARTIAL_FLUSH
);
1212 if (ret
!= Z_OK
&& ret
!= Z_STREAM_END
)
1214 inflateReset(&png_ptr
->zstream
);
1215 png_ptr
->zstream
.avail_in
= 0;
1216 png_ptr
->current_text
= NULL
;
1217 png_free(png_ptr
, key
);
1218 png_free(png_ptr
, text
);
1221 if (!(png_ptr
->zstream
.avail_out
) || ret
== Z_STREAM_END
)
1225 text
= (png_charp
)png_malloc(png_ptr
,
1226 (png_uint_32
)(png_ptr
->zbuf_size
- png_ptr
->zstream
.avail_out
1228 png_memcpy(text
+ key_size
, png_ptr
->zbuf
,
1229 png_ptr
->zbuf_size
- png_ptr
->zstream
.avail_out
);
1230 png_memcpy(text
, key
, key_size
);
1231 text_size
= key_size
+ png_ptr
->zbuf_size
-
1232 png_ptr
->zstream
.avail_out
;
1233 *(text
+ text_size
) = '\0';
1240 text
= (png_charp
)png_malloc(png_ptr
, text_size
+
1241 (png_uint_32
)(png_ptr
->zbuf_size
- png_ptr
->zstream
.avail_out
1243 png_memcpy(text
, tmp
, text_size
);
1244 png_free(png_ptr
, tmp
);
1245 png_memcpy(text
+ text_size
, png_ptr
->zbuf
,
1246 png_ptr
->zbuf_size
- png_ptr
->zstream
.avail_out
);
1247 text_size
+= png_ptr
->zbuf_size
- png_ptr
->zstream
.avail_out
;
1248 *(text
+ text_size
) = '\0';
1250 if (ret
!= Z_STREAM_END
)
1252 png_ptr
->zstream
.next_out
= png_ptr
->zbuf
;
1253 png_ptr
->zstream
.avail_out
= (uInt
)png_ptr
->zbuf_size
;
1261 if (ret
== Z_STREAM_END
)
1265 inflateReset(&png_ptr
->zstream
);
1266 png_ptr
->zstream
.avail_in
= 0;
1268 if (ret
!= Z_STREAM_END
)
1270 png_ptr
->current_text
= NULL
;
1271 png_free(png_ptr
, key
);
1272 png_free(png_ptr
, text
);
1276 png_ptr
->current_text
= NULL
;
1277 png_free(png_ptr
, key
);
1281 text_ptr
= (png_textp
)png_malloc(png_ptr
, (png_uint_32
)sizeof(png_text
));
1282 text_ptr
->compression
= PNG_TEXT_COMPRESSION_zTXt
;
1283 text_ptr
->key
= key
;
1284 #ifdef PNG_iTXt_SUPPORTED
1285 text_ptr
->lang
= NULL
;
1286 text_ptr
->lang_key
= NULL
;
1288 text_ptr
->text
= text
;
1290 ret
= png_set_text_2(png_ptr
, info_ptr
, text_ptr
, 1);
1292 png_free(png_ptr
, key
);
1293 png_free(png_ptr
, text_ptr
);
1296 png_warning(png_ptr
, "Insufficient memory to store text chunk.");
1301 #if defined(PNG_READ_iTXt_SUPPORTED)
1303 png_push_handle_iTXt(png_structp png_ptr
, png_infop info_ptr
, png_uint_32
1306 if (!(png_ptr
->mode
& PNG_HAVE_IHDR
) || (png_ptr
->mode
& PNG_HAVE_IEND
))
1308 png_error(png_ptr
, "Out of place iTXt");
1309 /* to quiet some compiler warnings */
1310 if(info_ptr
== NULL
) return;
1313 #ifdef PNG_MAX_MALLOC_64K
1314 png_ptr
->skip_length
= 0; /* This may not be necessary */
1316 if (length
> (png_uint_32
)65535L) /* Can't hold entire string in memory */
1318 png_warning(png_ptr
, "iTXt chunk too large to fit in memory");
1319 png_ptr
->skip_length
= length
- (png_uint_32
)65535L;
1320 length
= (png_uint_32
)65535L;
1324 png_ptr
->current_text
= (png_charp
)png_malloc(png_ptr
,
1325 (png_uint_32
)(length
+1));
1326 png_ptr
->current_text
[length
] = '\0';
1327 png_ptr
->current_text_ptr
= png_ptr
->current_text
;
1328 png_ptr
->current_text_size
= (png_size_t
)length
;
1329 png_ptr
->current_text_left
= (png_size_t
)length
;
1330 png_ptr
->process_mode
= PNG_READ_iTXt_MODE
;
1334 png_push_read_iTXt(png_structp png_ptr
, png_infop info_ptr
)
1337 if (png_ptr
->buffer_size
&& png_ptr
->current_text_left
)
1339 png_size_t text_size
;
1341 if (png_ptr
->buffer_size
< png_ptr
->current_text_left
)
1342 text_size
= png_ptr
->buffer_size
;
1344 text_size
= png_ptr
->current_text_left
;
1345 png_crc_read(png_ptr
, (png_bytep
)png_ptr
->current_text_ptr
, text_size
);
1346 png_ptr
->current_text_left
-= text_size
;
1347 png_ptr
->current_text_ptr
+= text_size
;
1349 if (!(png_ptr
->current_text_left
))
1359 if (png_ptr
->buffer_size
< 4)
1361 png_push_save_buffer(png_ptr
);
1365 png_push_crc_finish(png_ptr
);
1367 #if defined(PNG_MAX_MALLOC_64K)
1368 if (png_ptr
->skip_length
)
1372 key
= png_ptr
->current_text
;
1374 for (lang
= key
; *lang
; lang
++)
1377 if (lang
!= key
+ png_ptr
->current_text_size
)
1380 comp_flag
= *lang
++;
1381 lang
++; /* skip comp_type, always zero */
1383 for (lang_key
= lang
; *lang_key
; lang_key
++)
1385 lang_key
++; /* skip NUL separator */
1387 for (text
= lang_key
; *text
; text
++)
1390 if (text
!= key
+ png_ptr
->current_text_size
)
1393 text_ptr
= (png_textp
)png_malloc(png_ptr
, (png_uint_32
)sizeof(png_text
));
1394 text_ptr
->compression
= comp_flag
+ 2;
1395 text_ptr
->key
= key
;
1396 text_ptr
->lang
= lang
;
1397 text_ptr
->lang_key
= lang_key
;
1398 text_ptr
->text
= text
;
1399 text_ptr
->text_length
= 0;
1400 text_ptr
->itxt_length
= png_strlen(text
);
1402 ret
= png_set_text_2(png_ptr
, info_ptr
, text_ptr
, 1);
1404 png_ptr
->current_text
= NULL
;
1406 png_free(png_ptr
, text_ptr
);
1408 png_warning(png_ptr
, "Insufficient memory to store iTXt chunk.");
1413 /* This function is called when we haven't found a handler for this
1414 * chunk. If there isn't a problem with the chunk itself (ie a bad chunk
1415 * name or a critical chunk), the chunk is (currently) silently ignored.
1418 png_push_handle_unknown(png_structp png_ptr
, png_infop info_ptr
, png_uint_32
1422 png_check_chunk_name(png_ptr
, png_ptr
->chunk_name
);
1424 if (!(png_ptr
->chunk_name
[0] & 0x20))
1426 #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
1427 if(png_handle_as_unknown(png_ptr
, png_ptr
->chunk_name
) !=
1429 #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
1430 && png_ptr
->read_user_chunk_fn
== NULL
1434 png_chunk_error(png_ptr
, "unknown critical chunk");
1436 /* to quiet compiler warnings about unused info_ptr */
1437 if (info_ptr
== NULL
)
1441 #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
1442 if (png_ptr
->flags
& PNG_FLAG_KEEP_UNKNOWN_CHUNKS
)
1444 png_unknown_chunk chunk
;
1446 #ifdef PNG_MAX_MALLOC_64K
1447 if (length
> (png_uint_32
)65535L)
1449 png_warning(png_ptr
, "unknown chunk too large to fit in memory");
1450 skip
= length
- (png_uint_32
)65535L;
1451 length
= (png_uint_32
)65535L;
1455 png_strcpy((png_charp
)chunk
.name
, (png_charp
)png_ptr
->chunk_name
);
1456 chunk
.data
= (png_bytep
)png_malloc(png_ptr
, length
);
1457 png_crc_read(png_ptr
, chunk
.data
, length
);
1458 chunk
.size
= length
;
1459 #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
1460 if(png_ptr
->read_user_chunk_fn
!= NULL
)
1462 /* callback to user unknown chunk handler */
1463 if ((*(png_ptr
->read_user_chunk_fn
)) (png_ptr
, &chunk
) <= 0)
1465 if (!(png_ptr
->chunk_name
[0] & 0x20))
1466 if(png_handle_as_unknown(png_ptr
, png_ptr
->chunk_name
) !=
1467 HANDLE_CHUNK_ALWAYS
)
1468 png_chunk_error(png_ptr
, "unknown critical chunk");
1470 png_set_unknown_chunks(png_ptr
, info_ptr
, &chunk
, 1);
1474 png_set_unknown_chunks(png_ptr
, info_ptr
, &chunk
, 1);
1475 png_free(png_ptr
, chunk
.data
);
1480 png_push_crc_skip(png_ptr
, skip
);
1484 png_push_have_info(png_structp png_ptr
, png_infop info_ptr
)
1486 if (png_ptr
->info_fn
!= NULL
)
1487 (*(png_ptr
->info_fn
))(png_ptr
, info_ptr
);
1491 png_push_have_end(png_structp png_ptr
, png_infop info_ptr
)
1493 if (png_ptr
->end_fn
!= NULL
)
1494 (*(png_ptr
->end_fn
))(png_ptr
, info_ptr
);
1498 png_push_have_row(png_structp png_ptr
, png_bytep row
)
1500 if (png_ptr
->row_fn
!= NULL
)
1501 (*(png_ptr
->row_fn
))(png_ptr
, row
, png_ptr
->row_number
,
1502 (int)png_ptr
->pass
);
1506 png_progressive_combine_row (png_structp png_ptr
,
1507 png_bytep old_row
, png_bytep new_row
)
1509 #ifdef PNG_USE_LOCAL_ARRAYS
1510 const int FARDATA png_pass_dsp_mask
[7] =
1511 {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
1513 if (new_row
!= NULL
) /* new_row must == png_ptr->row_buf here. */
1514 png_combine_row(png_ptr
, old_row
, png_pass_dsp_mask
[png_ptr
->pass
]);
1518 png_set_progressive_read_fn(png_structp png_ptr
, png_voidp progressive_ptr
,
1519 png_progressive_info_ptr info_fn
, png_progressive_row_ptr row_fn
,
1520 png_progressive_end_ptr end_fn
)
1522 png_ptr
->info_fn
= info_fn
;
1523 png_ptr
->row_fn
= row_fn
;
1524 png_ptr
->end_fn
= end_fn
;
1526 png_set_read_fn(png_ptr
, progressive_ptr
, png_push_fill_buffer
);
1530 png_get_progressive_ptr(png_structp png_ptr
)
1532 return png_ptr
->io_ptr
;
1534 #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */