2 /* pngpread.c - read a png file in push mode
4 * Last changed in libpng 1.4.1 [February 25, 2010]
5 * Copyright (c) 1998-2010 Glenn Randers-Pehrson
6 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
7 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
9 * This code is released under the libpng license.
10 * For conditions of distribution and use, see the disclaimer
11 * and license in png.h
14 #define PNG_NO_PEDANTIC_WARNINGS
16 #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
19 /* Push model modes */
20 #define PNG_READ_SIG_MODE 0
21 #define PNG_READ_CHUNK_MODE 1
22 #define PNG_READ_IDAT_MODE 2
23 #define PNG_SKIP_MODE 3
24 #define PNG_READ_tEXt_MODE 4
25 #define PNG_READ_zTXt_MODE 5
26 #define PNG_READ_DONE_MODE 6
27 #define PNG_READ_iTXt_MODE 7
28 #define PNG_ERROR_MODE 8
31 png_process_data(png_structp png_ptr, png_infop info_ptr,
32 png_bytep buffer, png_size_t buffer_size)
34 if (png_ptr == NULL || info_ptr == NULL)
37 png_push_restore_buffer(png_ptr, buffer, buffer_size);
39 while (png_ptr->buffer_size)
41 png_process_some_data(png_ptr, info_ptr);
45 /* What we do with the incoming data depends on what we were previously
46 * doing before we ran out of data...
49 png_process_some_data(png_structp png_ptr, png_infop info_ptr)
54 switch (png_ptr->process_mode)
56 case PNG_READ_SIG_MODE:
58 png_push_read_sig(png_ptr, info_ptr);
62 case PNG_READ_CHUNK_MODE:
64 png_push_read_chunk(png_ptr, info_ptr);
68 case PNG_READ_IDAT_MODE:
70 png_push_read_IDAT(png_ptr);
74 #ifdef PNG_READ_tEXt_SUPPORTED
75 case PNG_READ_tEXt_MODE:
77 png_push_read_tEXt(png_ptr, info_ptr);
82 #ifdef PNG_READ_zTXt_SUPPORTED
83 case PNG_READ_zTXt_MODE:
85 png_push_read_zTXt(png_ptr, info_ptr);
90 #ifdef PNG_READ_iTXt_SUPPORTED
91 case PNG_READ_iTXt_MODE:
93 png_push_read_iTXt(png_ptr, info_ptr);
100 png_push_crc_finish(png_ptr);
106 png_ptr->buffer_size = 0;
112 /* Read any remaining signature bytes from the stream and compare them with
113 * the correct PNG signature. It is possible that this routine is called
114 * with bytes already read from the signature, either because they have been
115 * checked by the calling application, or because of multiple calls to this
119 png_push_read_sig(png_structp png_ptr, png_infop info_ptr)
121 png_size_t num_checked = png_ptr->sig_bytes,
122 num_to_check = 8 - num_checked;
124 if (png_ptr->buffer_size < num_to_check)
126 num_to_check = png_ptr->buffer_size;
129 png_push_fill_buffer(png_ptr, &(info_ptr->signature[num_checked]),
131 png_ptr->sig_bytes = (png_byte)(png_ptr->sig_bytes + num_to_check);
133 if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
135 if (num_checked < 4 &&
136 png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
137 png_error(png_ptr, "Not a PNG file");
139 png_error(png_ptr, "PNG file corrupted by ASCII conversion");
143 if (png_ptr->sig_bytes >= 8)
145 png_ptr->process_mode = PNG_READ_CHUNK_MODE;
151 png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
157 #ifdef PNG_READ_bKGD_SUPPORTED
160 #ifdef PNG_READ_cHRM_SUPPORTED
163 #ifdef PNG_READ_gAMA_SUPPORTED
166 #ifdef PNG_READ_hIST_SUPPORTED
169 #ifdef PNG_READ_iCCP_SUPPORTED
172 #ifdef PNG_READ_iTXt_SUPPORTED
175 #ifdef PNG_READ_oFFs_SUPPORTED
178 #ifdef PNG_READ_pCAL_SUPPORTED
181 #ifdef PNG_READ_pHYs_SUPPORTED
184 #ifdef PNG_READ_sBIT_SUPPORTED
187 #ifdef PNG_READ_sCAL_SUPPORTED
190 #ifdef PNG_READ_sRGB_SUPPORTED
193 #ifdef PNG_READ_sPLT_SUPPORTED
196 #ifdef PNG_READ_tEXt_SUPPORTED
199 #ifdef PNG_READ_tIME_SUPPORTED
202 #ifdef PNG_READ_tRNS_SUPPORTED
205 #ifdef PNG_READ_zTXt_SUPPORTED
209 /* First we make sure we have enough data for the 4 byte chunk name
210 * and the 4 byte chunk length before proceeding with decoding the
211 * chunk data. To fully decode each of these chunks, we also make
212 * sure we have enough data in the buffer for the 4 byte CRC at the
213 * end of every chunk (except IDAT, which is handled separately).
215 if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
217 png_byte chunk_length[4];
219 if (png_ptr->buffer_size < 8)
221 png_push_save_buffer(png_ptr);
225 png_push_fill_buffer(png_ptr, chunk_length, 4);
226 png_ptr->push_length = png_get_uint_31(png_ptr, chunk_length);
227 png_reset_crc(png_ptr);
228 png_crc_read(png_ptr, png_ptr->chunk_name, 4);
229 png_check_chunk_name(png_ptr, png_ptr->chunk_name);
230 png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
233 if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
234 if (png_ptr->mode & PNG_AFTER_IDAT)
235 png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
237 if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
239 if (png_ptr->push_length != 13)
240 png_error(png_ptr, "Invalid IHDR length");
242 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
244 png_push_save_buffer(png_ptr);
248 png_handle_IHDR(png_ptr, info_ptr, png_ptr->push_length);
251 else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
253 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
255 png_push_save_buffer(png_ptr);
259 png_handle_IEND(png_ptr, info_ptr, png_ptr->push_length);
261 png_ptr->process_mode = PNG_READ_DONE_MODE;
262 png_push_have_end(png_ptr, info_ptr);
265 #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
266 else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
268 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
270 png_push_save_buffer(png_ptr);
274 if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
275 png_ptr->mode |= PNG_HAVE_IDAT;
277 png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length);
279 if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
280 png_ptr->mode |= PNG_HAVE_PLTE;
282 else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
284 if (!(png_ptr->mode & PNG_HAVE_IHDR))
285 png_error(png_ptr, "Missing IHDR before IDAT");
287 else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
288 !(png_ptr->mode & PNG_HAVE_PLTE))
289 png_error(png_ptr, "Missing PLTE before IDAT");
294 else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
296 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
298 png_push_save_buffer(png_ptr);
301 png_handle_PLTE(png_ptr, info_ptr, png_ptr->push_length);
304 else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
306 /* If we reach an IDAT chunk, this means we have read all of the
307 * header chunks, and we can start reading the image (or if this
308 * is called after the image has been read - we have an error).
311 if (!(png_ptr->mode & PNG_HAVE_IHDR))
312 png_error(png_ptr, "Missing IHDR before IDAT");
314 else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
315 !(png_ptr->mode & PNG_HAVE_PLTE))
316 png_error(png_ptr, "Missing PLTE before IDAT");
318 if (png_ptr->mode & PNG_HAVE_IDAT)
320 if (!(png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
321 if (png_ptr->push_length == 0)
324 if (png_ptr->mode & PNG_AFTER_IDAT)
325 png_benign_error(png_ptr, "Too many IDATs found");
328 png_ptr->idat_size = png_ptr->push_length;
329 png_ptr->mode |= PNG_HAVE_IDAT;
330 png_ptr->process_mode = PNG_READ_IDAT_MODE;
331 png_push_have_info(png_ptr, info_ptr);
332 png_ptr->zstream.avail_out =
333 (uInt) PNG_ROWBYTES(png_ptr->pixel_depth,
334 png_ptr->iwidth) + 1;
335 png_ptr->zstream.next_out = png_ptr->row_buf;
339 #ifdef PNG_READ_gAMA_SUPPORTED
340 else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
342 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
344 png_push_save_buffer(png_ptr);
348 png_handle_gAMA(png_ptr, info_ptr, png_ptr->push_length);
352 #ifdef PNG_READ_sBIT_SUPPORTED
353 else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
355 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
357 png_push_save_buffer(png_ptr);
361 png_handle_sBIT(png_ptr, info_ptr, png_ptr->push_length);
365 #ifdef PNG_READ_cHRM_SUPPORTED
366 else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
368 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
370 png_push_save_buffer(png_ptr);
374 png_handle_cHRM(png_ptr, info_ptr, png_ptr->push_length);
378 #ifdef PNG_READ_sRGB_SUPPORTED
379 else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
381 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
383 png_push_save_buffer(png_ptr);
387 png_handle_sRGB(png_ptr, info_ptr, png_ptr->push_length);
391 #ifdef PNG_READ_iCCP_SUPPORTED
392 else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
394 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
396 png_push_save_buffer(png_ptr);
400 png_handle_iCCP(png_ptr, info_ptr, png_ptr->push_length);
404 #ifdef PNG_READ_sPLT_SUPPORTED
405 else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
407 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
409 png_push_save_buffer(png_ptr);
413 png_handle_sPLT(png_ptr, info_ptr, png_ptr->push_length);
417 #ifdef PNG_READ_tRNS_SUPPORTED
418 else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
420 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
422 png_push_save_buffer(png_ptr);
426 png_handle_tRNS(png_ptr, info_ptr, png_ptr->push_length);
430 #ifdef PNG_READ_bKGD_SUPPORTED
431 else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
433 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
435 png_push_save_buffer(png_ptr);
439 png_handle_bKGD(png_ptr, info_ptr, png_ptr->push_length);
443 #ifdef PNG_READ_hIST_SUPPORTED
444 else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
446 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
448 png_push_save_buffer(png_ptr);
452 png_handle_hIST(png_ptr, info_ptr, png_ptr->push_length);
456 #ifdef PNG_READ_pHYs_SUPPORTED
457 else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
459 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
461 png_push_save_buffer(png_ptr);
465 png_handle_pHYs(png_ptr, info_ptr, png_ptr->push_length);
469 #ifdef PNG_READ_oFFs_SUPPORTED
470 else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
472 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
474 png_push_save_buffer(png_ptr);
478 png_handle_oFFs(png_ptr, info_ptr, png_ptr->push_length);
482 #ifdef PNG_READ_pCAL_SUPPORTED
483 else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
485 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
487 png_push_save_buffer(png_ptr);
491 png_handle_pCAL(png_ptr, info_ptr, png_ptr->push_length);
495 #ifdef PNG_READ_sCAL_SUPPORTED
496 else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
498 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
500 png_push_save_buffer(png_ptr);
504 png_handle_sCAL(png_ptr, info_ptr, png_ptr->push_length);
508 #ifdef PNG_READ_tIME_SUPPORTED
509 else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
511 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
513 png_push_save_buffer(png_ptr);
517 png_handle_tIME(png_ptr, info_ptr, png_ptr->push_length);
521 #ifdef PNG_READ_tEXt_SUPPORTED
522 else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
524 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
526 png_push_save_buffer(png_ptr);
530 png_push_handle_tEXt(png_ptr, info_ptr, png_ptr->push_length);
534 #ifdef PNG_READ_zTXt_SUPPORTED
535 else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
537 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
539 png_push_save_buffer(png_ptr);
543 png_push_handle_zTXt(png_ptr, info_ptr, png_ptr->push_length);
547 #ifdef PNG_READ_iTXt_SUPPORTED
548 else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
550 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
552 png_push_save_buffer(png_ptr);
556 png_push_handle_iTXt(png_ptr, info_ptr, png_ptr->push_length);
562 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
564 png_push_save_buffer(png_ptr);
567 png_push_handle_unknown(png_ptr, info_ptr, png_ptr->push_length);
570 png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
574 png_push_crc_skip(png_structp png_ptr, png_uint_32 skip)
576 png_ptr->process_mode = PNG_SKIP_MODE;
577 png_ptr->skip_length = skip;
581 png_push_crc_finish(png_structp png_ptr)
583 if (png_ptr->skip_length && png_ptr->save_buffer_size)
585 png_size_t save_size;
587 if (png_ptr->skip_length < (png_uint_32)png_ptr->save_buffer_size)
588 save_size = (png_size_t)png_ptr->skip_length;
590 save_size = png_ptr->save_buffer_size;
592 png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size);
594 png_ptr->skip_length -= save_size;
595 png_ptr->buffer_size -= save_size;
596 png_ptr->save_buffer_size -= save_size;
597 png_ptr->save_buffer_ptr += save_size;
599 if (png_ptr->skip_length && png_ptr->current_buffer_size)
601 png_size_t save_size;
603 if (png_ptr->skip_length < (png_uint_32)png_ptr->current_buffer_size)
604 save_size = (png_size_t)png_ptr->skip_length;
606 save_size = png_ptr->current_buffer_size;
608 png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size);
610 png_ptr->skip_length -= save_size;
611 png_ptr->buffer_size -= save_size;
612 png_ptr->current_buffer_size -= save_size;
613 png_ptr->current_buffer_ptr += save_size;
615 if (!png_ptr->skip_length)
617 if (png_ptr->buffer_size < 4)
619 png_push_save_buffer(png_ptr);
623 png_crc_finish(png_ptr, 0);
624 png_ptr->process_mode = PNG_READ_CHUNK_MODE;
629 png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length)
637 if (png_ptr->save_buffer_size)
639 png_size_t save_size;
641 if (length < png_ptr->save_buffer_size)
644 save_size = png_ptr->save_buffer_size;
646 png_memcpy(ptr, png_ptr->save_buffer_ptr, save_size);
649 png_ptr->buffer_size -= save_size;
650 png_ptr->save_buffer_size -= save_size;
651 png_ptr->save_buffer_ptr += save_size;
653 if (length && png_ptr->current_buffer_size)
655 png_size_t save_size;
657 if (length < png_ptr->current_buffer_size)
661 save_size = png_ptr->current_buffer_size;
663 png_memcpy(ptr, png_ptr->current_buffer_ptr, save_size);
664 png_ptr->buffer_size -= save_size;
665 png_ptr->current_buffer_size -= save_size;
666 png_ptr->current_buffer_ptr += save_size;
671 png_push_save_buffer(png_structp png_ptr)
673 if (png_ptr->save_buffer_size)
675 if (png_ptr->save_buffer_ptr != png_ptr->save_buffer)
681 istop = png_ptr->save_buffer_size;
682 for (i = 0, sp = png_ptr->save_buffer_ptr, dp = png_ptr->save_buffer;
683 i < istop; i++, sp++, dp++)
689 if (png_ptr->save_buffer_size + png_ptr->current_buffer_size >
690 png_ptr->save_buffer_max)
693 png_bytep old_buffer;
695 if (png_ptr->save_buffer_size > PNG_SIZE_MAX -
696 (png_ptr->current_buffer_size + 256))
698 png_error(png_ptr, "Potential overflow of save_buffer");
701 new_max = png_ptr->save_buffer_size + png_ptr->current_buffer_size + 256;
702 old_buffer = png_ptr->save_buffer;
703 png_ptr->save_buffer = (png_bytep)png_malloc_warn(png_ptr,
704 (png_size_t)new_max);
705 if (png_ptr->save_buffer == NULL)
707 png_free(png_ptr, old_buffer);
708 png_error(png_ptr, "Insufficient memory for save_buffer");
710 png_memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size);
711 png_free(png_ptr, old_buffer);
712 png_ptr->save_buffer_max = new_max;
714 if (png_ptr->current_buffer_size)
716 png_memcpy(png_ptr->save_buffer + png_ptr->save_buffer_size,
717 png_ptr->current_buffer_ptr, png_ptr->current_buffer_size);
718 png_ptr->save_buffer_size += png_ptr->current_buffer_size;
719 png_ptr->current_buffer_size = 0;
721 png_ptr->save_buffer_ptr = png_ptr->save_buffer;
722 png_ptr->buffer_size = 0;
726 png_push_restore_buffer(png_structp png_ptr, png_bytep buffer,
727 png_size_t buffer_length)
729 png_ptr->current_buffer = buffer;
730 png_ptr->current_buffer_size = buffer_length;
731 png_ptr->buffer_size = buffer_length + png_ptr->save_buffer_size;
732 png_ptr->current_buffer_ptr = png_ptr->current_buffer;
736 png_push_read_IDAT(png_structp png_ptr)
739 if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
741 png_byte chunk_length[4];
743 if (png_ptr->buffer_size < 8)
745 png_push_save_buffer(png_ptr);
749 png_push_fill_buffer(png_ptr, chunk_length, 4);
750 png_ptr->push_length = png_get_uint_31(png_ptr, chunk_length);
751 png_reset_crc(png_ptr);
752 png_crc_read(png_ptr, png_ptr->chunk_name, 4);
753 png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
755 if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
757 png_ptr->process_mode = PNG_READ_CHUNK_MODE;
758 if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
759 png_error(png_ptr, "Not enough compressed data");
763 png_ptr->idat_size = png_ptr->push_length;
765 if (png_ptr->idat_size && png_ptr->save_buffer_size)
767 png_size_t save_size;
769 if (png_ptr->idat_size < (png_uint_32)png_ptr->save_buffer_size)
771 save_size = (png_size_t)png_ptr->idat_size;
773 /* Check for overflow */
774 if ((png_uint_32)save_size != png_ptr->idat_size)
775 png_error(png_ptr, "save_size overflowed in pngpread");
778 save_size = png_ptr->save_buffer_size;
780 png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size);
782 if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
783 png_process_IDAT_data(png_ptr, png_ptr->save_buffer_ptr, save_size);
785 png_ptr->idat_size -= save_size;
786 png_ptr->buffer_size -= save_size;
787 png_ptr->save_buffer_size -= save_size;
788 png_ptr->save_buffer_ptr += save_size;
790 if (png_ptr->idat_size && png_ptr->current_buffer_size)
792 png_size_t save_size;
794 if (png_ptr->idat_size < (png_uint_32)png_ptr->current_buffer_size)
796 save_size = (png_size_t)png_ptr->idat_size;
798 /* Check for overflow */
799 if ((png_uint_32)save_size != png_ptr->idat_size)
800 png_error(png_ptr, "save_size overflowed in pngpread");
803 save_size = png_ptr->current_buffer_size;
805 png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size);
806 if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
807 png_process_IDAT_data(png_ptr, png_ptr->current_buffer_ptr, save_size);
809 png_ptr->idat_size -= save_size;
810 png_ptr->buffer_size -= save_size;
811 png_ptr->current_buffer_size -= save_size;
812 png_ptr->current_buffer_ptr += save_size;
814 if (!png_ptr->idat_size)
816 if (png_ptr->buffer_size < 4)
818 png_push_save_buffer(png_ptr);
822 png_crc_finish(png_ptr, 0);
823 png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
824 png_ptr->mode |= PNG_AFTER_IDAT;
829 png_process_IDAT_data(png_structp png_ptr, png_bytep buffer,
830 png_size_t buffer_length)
834 if ((png_ptr->flags & PNG_FLAG_ZLIB_FINISHED) && buffer_length)
835 png_benign_error(png_ptr, "Extra compression data");
837 png_ptr->zstream.next_in = buffer;
838 png_ptr->zstream.avail_in = (uInt)buffer_length;
841 ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
844 if (ret == Z_STREAM_END)
846 if (png_ptr->zstream.avail_in)
847 png_benign_error(png_ptr, "Extra compressed data");
849 if (!(png_ptr->zstream.avail_out))
851 png_push_process_row(png_ptr);
854 png_ptr->mode |= PNG_AFTER_IDAT;
855 png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
858 else if (ret == Z_BUF_ERROR)
862 png_error(png_ptr, "Decompression Error");
864 if (!(png_ptr->zstream.avail_out))
867 #ifdef PNG_READ_INTERLACING_SUPPORTED
868 png_ptr->interlaced && png_ptr->pass > 6) ||
869 (!png_ptr->interlaced &&
871 png_ptr->row_number == png_ptr->num_rows))
873 if (png_ptr->zstream.avail_in)
874 png_warning(png_ptr, "Too much data in IDAT chunks");
875 png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
878 png_push_process_row(png_ptr);
879 png_ptr->zstream.avail_out =
880 (uInt) PNG_ROWBYTES(png_ptr->pixel_depth,
881 png_ptr->iwidth) + 1;
882 png_ptr->zstream.next_out = png_ptr->row_buf;
891 png_push_process_row(png_structp png_ptr)
893 png_ptr->row_info.color_type = png_ptr->color_type;
894 png_ptr->row_info.width = png_ptr->iwidth;
895 png_ptr->row_info.channels = png_ptr->channels;
896 png_ptr->row_info.bit_depth = png_ptr->bit_depth;
897 png_ptr->row_info.pixel_depth = png_ptr->pixel_depth;
899 png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
900 png_ptr->row_info.width);
902 png_read_filter_row(png_ptr, &(png_ptr->row_info),
903 png_ptr->row_buf + 1, png_ptr->prev_row + 1,
904 (int)(png_ptr->row_buf[0]));
906 png_memcpy(png_ptr->prev_row, png_ptr->row_buf, png_ptr->rowbytes + 1);
908 if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
909 png_do_read_transformations(png_ptr);
911 #ifdef PNG_READ_INTERLACING_SUPPORTED
912 /* Blow up interlaced rows to full size */
913 if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
915 if (png_ptr->pass < 6)
916 /* old interface (pre-1.0.9):
917 png_do_read_interlace(&(png_ptr->row_info),
918 png_ptr->row_buf + 1, png_ptr->pass, png_ptr->transformations);
920 png_do_read_interlace(png_ptr);
922 switch (png_ptr->pass)
927 for (i = 0; i < 8 && png_ptr->pass == 0; i++)
929 png_push_have_row(png_ptr, png_ptr->row_buf + 1);
930 png_read_push_finish_row(png_ptr); /* Updates png_ptr->pass */
933 if (png_ptr->pass == 2) /* Pass 1 might be empty */
935 for (i = 0; i < 4 && png_ptr->pass == 2; i++)
937 png_push_have_row(png_ptr, NULL);
938 png_read_push_finish_row(png_ptr);
942 if (png_ptr->pass == 4 && png_ptr->height <= 4)
944 for (i = 0; i < 2 && png_ptr->pass == 4; i++)
946 png_push_have_row(png_ptr, NULL);
947 png_read_push_finish_row(png_ptr);
951 if (png_ptr->pass == 6 && png_ptr->height <= 4)
953 png_push_have_row(png_ptr, NULL);
954 png_read_push_finish_row(png_ptr);
963 for (i = 0; i < 8 && png_ptr->pass == 1; i++)
965 png_push_have_row(png_ptr, png_ptr->row_buf + 1);
966 png_read_push_finish_row(png_ptr);
969 if (png_ptr->pass == 2) /* Skip top 4 generated rows */
971 for (i = 0; i < 4 && png_ptr->pass == 2; i++)
973 png_push_have_row(png_ptr, NULL);
974 png_read_push_finish_row(png_ptr);
985 for (i = 0; i < 4 && png_ptr->pass == 2; i++)
987 png_push_have_row(png_ptr, png_ptr->row_buf + 1);
988 png_read_push_finish_row(png_ptr);
991 for (i = 0; i < 4 && png_ptr->pass == 2; i++)
993 png_push_have_row(png_ptr, NULL);
994 png_read_push_finish_row(png_ptr);
997 if (png_ptr->pass == 4) /* Pass 3 might be empty */
999 for (i = 0; i < 2 && png_ptr->pass == 4; i++)
1001 png_push_have_row(png_ptr, NULL);
1002 png_read_push_finish_row(png_ptr);
1013 for (i = 0; i < 4 && png_ptr->pass == 3; i++)
1015 png_push_have_row(png_ptr, png_ptr->row_buf + 1);
1016 png_read_push_finish_row(png_ptr);
1019 if (png_ptr->pass == 4) /* Skip top two generated rows */
1021 for (i = 0; i < 2 && png_ptr->pass == 4; i++)
1023 png_push_have_row(png_ptr, NULL);
1024 png_read_push_finish_row(png_ptr);
1035 for (i = 0; i < 2 && png_ptr->pass == 4; i++)
1037 png_push_have_row(png_ptr, png_ptr->row_buf + 1);
1038 png_read_push_finish_row(png_ptr);
1041 for (i = 0; i < 2 && png_ptr->pass == 4; i++)
1043 png_push_have_row(png_ptr, NULL);
1044 png_read_push_finish_row(png_ptr);
1047 if (png_ptr->pass == 6) /* Pass 5 might be empty */
1049 png_push_have_row(png_ptr, NULL);
1050 png_read_push_finish_row(png_ptr);
1060 for (i = 0; i < 2 && png_ptr->pass == 5; i++)
1062 png_push_have_row(png_ptr, png_ptr->row_buf + 1);
1063 png_read_push_finish_row(png_ptr);
1066 if (png_ptr->pass == 6) /* Skip top generated row */
1068 png_push_have_row(png_ptr, NULL);
1069 png_read_push_finish_row(png_ptr);
1076 png_push_have_row(png_ptr, png_ptr->row_buf + 1);
1077 png_read_push_finish_row(png_ptr);
1079 if (png_ptr->pass != 6)
1082 png_push_have_row(png_ptr, NULL);
1083 png_read_push_finish_row(png_ptr);
1090 png_push_have_row(png_ptr, png_ptr->row_buf + 1);
1091 png_read_push_finish_row(png_ptr);
1096 png_read_push_finish_row(png_structp png_ptr)
1098 /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
1100 /* Start of interlace block */
1101 PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
1103 /* Offset to next interlace block */
1104 PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
1106 /* Start of interlace block in the y direction */
1107 PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
1109 /* Offset to next interlace block in the y direction */
1110 PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
1112 /* Height of interlace block. This is not currently used - if you need
1113 * it, uncomment it here and in png.h
1114 PNG_CONST int FARDATA png_pass_height[] = {8, 8, 4, 4, 2, 2, 1};
1117 png_ptr->row_number++;
1118 if (png_ptr->row_number < png_ptr->num_rows)
1121 #ifdef PNG_READ_INTERLACING_SUPPORTED
1122 if (png_ptr->interlaced)
1124 png_ptr->row_number = 0;
1125 png_memset(png_ptr->prev_row, 0,
1126 png_ptr->rowbytes + 1);
1130 if ((png_ptr->pass == 1 && png_ptr->width < 5) ||
1131 (png_ptr->pass == 3 && png_ptr->width < 3) ||
1132 (png_ptr->pass == 5 && png_ptr->width < 2))
1135 if (png_ptr->pass > 7)
1138 if (png_ptr->pass >= 7)
1141 png_ptr->iwidth = (png_ptr->width +
1142 png_pass_inc[png_ptr->pass] - 1 -
1143 png_pass_start[png_ptr->pass]) /
1144 png_pass_inc[png_ptr->pass];
1146 if (png_ptr->transformations & PNG_INTERLACE)
1149 png_ptr->num_rows = (png_ptr->height +
1150 png_pass_yinc[png_ptr->pass] - 1 -
1151 png_pass_ystart[png_ptr->pass]) /
1152 png_pass_yinc[png_ptr->pass];
1154 } while (png_ptr->iwidth == 0 || png_ptr->num_rows == 0);
1156 #endif /* PNG_READ_INTERLACING_SUPPORTED */
1159 #ifdef PNG_READ_tEXt_SUPPORTED
1161 png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
1164 if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
1166 png_error(png_ptr, "Out of place tEXt");
1167 info_ptr = info_ptr; /* To quiet some compiler warnings */
1170 #ifdef PNG_MAX_MALLOC_64K
1171 png_ptr->skip_length = 0; /* This may not be necessary */
1173 if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */
1175 png_warning(png_ptr, "tEXt chunk too large to fit in memory");
1176 png_ptr->skip_length = length - (png_uint_32)65535L;
1177 length = (png_uint_32)65535L;
1181 png_ptr->current_text = (png_charp)png_malloc(png_ptr,
1182 (png_size_t)(length + 1));
1183 png_ptr->current_text[length] = '\0';
1184 png_ptr->current_text_ptr = png_ptr->current_text;
1185 png_ptr->current_text_size = (png_size_t)length;
1186 png_ptr->current_text_left = (png_size_t)length;
1187 png_ptr->process_mode = PNG_READ_tEXt_MODE;
1191 png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr)
1193 if (png_ptr->buffer_size && png_ptr->current_text_left)
1195 png_size_t text_size;
1197 if (png_ptr->buffer_size < png_ptr->current_text_left)
1198 text_size = png_ptr->buffer_size;
1201 text_size = png_ptr->current_text_left;
1203 png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
1204 png_ptr->current_text_left -= text_size;
1205 png_ptr->current_text_ptr += text_size;
1207 if (!(png_ptr->current_text_left))
1214 if (png_ptr->buffer_size < 4)
1216 png_push_save_buffer(png_ptr);
1220 png_push_crc_finish(png_ptr);
1222 #ifdef PNG_MAX_MALLOC_64K
1223 if (png_ptr->skip_length)
1227 key = png_ptr->current_text;
1229 for (text = key; *text; text++)
1232 if (text < key + png_ptr->current_text_size)
1235 text_ptr = (png_textp)png_malloc(png_ptr,
1236 png_sizeof(png_text));
1237 text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
1238 text_ptr->key = key;
1239 #ifdef PNG_iTXt_SUPPORTED
1240 text_ptr->lang = NULL;
1241 text_ptr->lang_key = NULL;
1243 text_ptr->text = text;
1245 ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
1247 png_free(png_ptr, key);
1248 png_free(png_ptr, text_ptr);
1249 png_ptr->current_text = NULL;
1252 png_warning(png_ptr, "Insufficient memory to store text chunk");
1257 #ifdef PNG_READ_zTXt_SUPPORTED
1259 png_push_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
1262 if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
1264 png_error(png_ptr, "Out of place zTXt");
1265 info_ptr = info_ptr; /* To quiet some compiler warnings */
1268 #ifdef PNG_MAX_MALLOC_64K
1269 /* We can't handle zTXt chunks > 64K, since we don't have enough space
1270 * to be able to store the uncompressed data. Actually, the threshold
1271 * is probably around 32K, but it isn't as definite as 64K is.
1273 if (length > (png_uint_32)65535L)
1275 png_warning(png_ptr, "zTXt chunk too large to fit in memory");
1276 png_push_crc_skip(png_ptr, length);
1281 png_ptr->current_text = (png_charp)png_malloc(png_ptr,
1282 (png_size_t)(length + 1));
1283 png_ptr->current_text[length] = '\0';
1284 png_ptr->current_text_ptr = png_ptr->current_text;
1285 png_ptr->current_text_size = (png_size_t)length;
1286 png_ptr->current_text_left = (png_size_t)length;
1287 png_ptr->process_mode = PNG_READ_zTXt_MODE;
1291 png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
1293 if (png_ptr->buffer_size && png_ptr->current_text_left)
1295 png_size_t text_size;
1297 if (png_ptr->buffer_size < (png_uint_32)png_ptr->current_text_left)
1298 text_size = png_ptr->buffer_size;
1301 text_size = png_ptr->current_text_left;
1303 png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
1304 png_ptr->current_text_left -= text_size;
1305 png_ptr->current_text_ptr += text_size;
1307 if (!(png_ptr->current_text_left))
1313 png_size_t text_size, key_size;
1315 if (png_ptr->buffer_size < 4)
1317 png_push_save_buffer(png_ptr);
1321 png_push_crc_finish(png_ptr);
1323 key = png_ptr->current_text;
1325 for (text = key; *text; text++)
1328 /* zTXt can't have zero text */
1329 if (text >= key + png_ptr->current_text_size)
1331 png_ptr->current_text = NULL;
1332 png_free(png_ptr, key);
1338 if (*text != PNG_TEXT_COMPRESSION_zTXt) /* Check compression byte */
1340 png_ptr->current_text = NULL;
1341 png_free(png_ptr, key);
1347 png_ptr->zstream.next_in = (png_bytep )text;
1348 png_ptr->zstream.avail_in = (uInt)(png_ptr->current_text_size -
1350 png_ptr->zstream.next_out = png_ptr->zbuf;
1351 png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
1353 key_size = text - key;
1358 while (png_ptr->zstream.avail_in)
1360 ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
1361 if (ret != Z_OK && ret != Z_STREAM_END)
1363 inflateReset(&png_ptr->zstream);
1364 png_ptr->zstream.avail_in = 0;
1365 png_ptr->current_text = NULL;
1366 png_free(png_ptr, key);
1367 png_free(png_ptr, text);
1370 if (!(png_ptr->zstream.avail_out) || ret == Z_STREAM_END)
1374 text = (png_charp)png_malloc(png_ptr,
1376 - png_ptr->zstream.avail_out + key_size + 1));
1378 png_memcpy(text + key_size, png_ptr->zbuf,
1379 png_ptr->zbuf_size - png_ptr->zstream.avail_out);
1381 png_memcpy(text, key, key_size);
1383 text_size = key_size + png_ptr->zbuf_size -
1384 png_ptr->zstream.avail_out;
1386 *(text + text_size) = '\0';
1393 text = (png_charp)png_malloc(png_ptr, text_size +
1395 - png_ptr->zstream.avail_out + 1));
1397 png_memcpy(text, tmp, text_size);
1398 png_free(png_ptr, tmp);
1400 png_memcpy(text + text_size, png_ptr->zbuf,
1401 png_ptr->zbuf_size - png_ptr->zstream.avail_out);
1403 text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out;
1404 *(text + text_size) = '\0';
1406 if (ret != Z_STREAM_END)
1408 png_ptr->zstream.next_out = png_ptr->zbuf;
1409 png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
1417 if (ret == Z_STREAM_END)
1421 inflateReset(&png_ptr->zstream);
1422 png_ptr->zstream.avail_in = 0;
1424 if (ret != Z_STREAM_END)
1426 png_ptr->current_text = NULL;
1427 png_free(png_ptr, key);
1428 png_free(png_ptr, text);
1432 png_ptr->current_text = NULL;
1433 png_free(png_ptr, key);
1437 text_ptr = (png_textp)png_malloc(png_ptr,
1438 png_sizeof(png_text));
1439 text_ptr->compression = PNG_TEXT_COMPRESSION_zTXt;
1440 text_ptr->key = key;
1441 #ifdef PNG_iTXt_SUPPORTED
1442 text_ptr->lang = NULL;
1443 text_ptr->lang_key = NULL;
1445 text_ptr->text = text;
1447 ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
1449 png_free(png_ptr, key);
1450 png_free(png_ptr, text_ptr);
1453 png_warning(png_ptr, "Insufficient memory to store text chunk");
1458 #ifdef PNG_READ_iTXt_SUPPORTED
1460 png_push_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
1463 if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
1465 png_error(png_ptr, "Out of place iTXt");
1466 info_ptr = info_ptr; /* To quiet some compiler warnings */
1469 #ifdef PNG_MAX_MALLOC_64K
1470 png_ptr->skip_length = 0; /* This may not be necessary */
1472 if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */
1474 png_warning(png_ptr, "iTXt chunk too large to fit in memory");
1475 png_ptr->skip_length = length - (png_uint_32)65535L;
1476 length = (png_uint_32)65535L;
1480 png_ptr->current_text = (png_charp)png_malloc(png_ptr,
1481 (png_size_t)(length + 1));
1482 png_ptr->current_text[length] = '\0';
1483 png_ptr->current_text_ptr = png_ptr->current_text;
1484 png_ptr->current_text_size = (png_size_t)length;
1485 png_ptr->current_text_left = (png_size_t)length;
1486 png_ptr->process_mode = PNG_READ_iTXt_MODE;
1490 png_push_read_iTXt(png_structp png_ptr, png_infop info_ptr)
1493 if (png_ptr->buffer_size && png_ptr->current_text_left)
1495 png_size_t text_size;
1497 if (png_ptr->buffer_size < png_ptr->current_text_left)
1498 text_size = png_ptr->buffer_size;
1501 text_size = png_ptr->current_text_left;
1503 png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
1504 png_ptr->current_text_left -= text_size;
1505 png_ptr->current_text_ptr += text_size;
1507 if (!(png_ptr->current_text_left))
1517 if (png_ptr->buffer_size < 4)
1519 png_push_save_buffer(png_ptr);
1523 png_push_crc_finish(png_ptr);
1525 #ifdef PNG_MAX_MALLOC_64K
1526 if (png_ptr->skip_length)
1530 key = png_ptr->current_text;
1532 for (lang = key; *lang; lang++)
1535 if (lang < key + png_ptr->current_text_size - 3)
1538 comp_flag = *lang++;
1539 lang++; /* Skip comp_type, always zero */
1541 for (lang_key = lang; *lang_key; lang_key++)
1544 lang_key++; /* Skip NUL separator */
1548 if (lang_key < key + png_ptr->current_text_size - 1)
1550 for (; *text; text++)
1554 if (text < key + png_ptr->current_text_size)
1557 text_ptr = (png_textp)png_malloc(png_ptr,
1558 png_sizeof(png_text));
1560 text_ptr->compression = comp_flag + 2;
1561 text_ptr->key = key;
1562 text_ptr->lang = lang;
1563 text_ptr->lang_key = lang_key;
1564 text_ptr->text = text;
1565 text_ptr->text_length = 0;
1566 text_ptr->itxt_length = png_strlen(text);
1568 ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
1570 png_ptr->current_text = NULL;
1572 png_free(png_ptr, text_ptr);
1574 png_warning(png_ptr, "Insufficient memory to store iTXt chunk");
1579 /* This function is called when we haven't found a handler for this
1580 * chunk. If there isn't a problem with the chunk itself (ie a bad chunk
1581 * name or a critical chunk), the chunk is (currently) silently ignored.
1584 png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32
1587 png_uint_32 skip = 0;
1589 if (!(png_ptr->chunk_name[0] & 0x20))
1591 #ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
1592 if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
1593 PNG_HANDLE_CHUNK_ALWAYS
1594 #ifdef PNG_READ_USER_CHUNKS_SUPPORTED
1595 && png_ptr->read_user_chunk_fn == NULL
1599 png_chunk_error(png_ptr, "unknown critical chunk");
1601 info_ptr = info_ptr; /* To quiet some compiler warnings */
1604 #ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
1605 if (png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS)
1607 #ifdef PNG_MAX_MALLOC_64K
1608 if (length > (png_uint_32)65535L)
1610 png_warning(png_ptr, "unknown chunk too large to fit in memory");
1611 skip = length - (png_uint_32)65535L;
1612 length = (png_uint_32)65535L;
1615 png_memcpy((png_charp)png_ptr->unknown_chunk.name,
1616 (png_charp)png_ptr->chunk_name,
1617 png_sizeof(png_ptr->unknown_chunk.name));
1618 png_ptr->unknown_chunk.name[png_sizeof(png_ptr->unknown_chunk.name) - 1]
1621 png_ptr->unknown_chunk.size = (png_size_t)length;
1624 png_ptr->unknown_chunk.data = NULL;
1628 png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr,
1629 (png_size_t)length);
1630 png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
1633 #ifdef PNG_READ_USER_CHUNKS_SUPPORTED
1634 if (png_ptr->read_user_chunk_fn != NULL)
1636 /* Callback to user unknown chunk handler */
1638 ret = (*(png_ptr->read_user_chunk_fn))
1639 (png_ptr, &png_ptr->unknown_chunk);
1642 png_chunk_error(png_ptr, "error in user chunk");
1646 if (!(png_ptr->chunk_name[0] & 0x20))
1647 if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
1648 PNG_HANDLE_CHUNK_ALWAYS)
1649 png_chunk_error(png_ptr, "unknown critical chunk");
1650 png_set_unknown_chunks(png_ptr, info_ptr,
1651 &png_ptr->unknown_chunk, 1);
1657 png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
1658 png_free(png_ptr, png_ptr->unknown_chunk.data);
1659 png_ptr->unknown_chunk.data = NULL;
1665 png_push_crc_skip(png_ptr, skip);
1669 png_push_have_info(png_structp png_ptr, png_infop info_ptr)
1671 if (png_ptr->info_fn != NULL)
1672 (*(png_ptr->info_fn))(png_ptr, info_ptr);
1676 png_push_have_end(png_structp png_ptr, png_infop info_ptr)
1678 if (png_ptr->end_fn != NULL)
1679 (*(png_ptr->end_fn))(png_ptr, info_ptr);
1683 png_push_have_row(png_structp png_ptr, png_bytep row)
1685 if (png_ptr->row_fn != NULL)
1686 (*(png_ptr->row_fn))(png_ptr, row, png_ptr->row_number,
1687 (int)png_ptr->pass);
1691 png_progressive_combine_row (png_structp png_ptr,
1692 png_bytep old_row, png_bytep new_row)
1694 PNG_CONST int FARDATA png_pass_dsp_mask[7] =
1695 {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
1697 if (png_ptr == NULL)
1700 if (new_row != NULL) /* new_row must == png_ptr->row_buf here. */
1701 png_combine_row(png_ptr, old_row, png_pass_dsp_mask[png_ptr->pass]);
1705 png_set_progressive_read_fn(png_structp png_ptr, png_voidp progressive_ptr,
1706 png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
1707 png_progressive_end_ptr end_fn)
1709 if (png_ptr == NULL)
1712 png_ptr->info_fn = info_fn;
1713 png_ptr->row_fn = row_fn;
1714 png_ptr->end_fn = end_fn;
1716 png_set_read_fn(png_ptr, progressive_ptr, png_push_fill_buffer);
1720 png_get_progressive_ptr(png_structp png_ptr)
1722 if (png_ptr == NULL)
1725 return png_ptr->io_ptr;
1727 #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */