define __KERNEL_STRICT_NAMES to avoid inclusion of kernel types on systems that carry...
[cake.git] / compiler / libpng / pngpread.c
blob719d43897732bc8aeedafbedf03844d196329563
2 /* pngpread.c - read a png file in push mode
4 * libpng 1.0.10 - March 30, 2001
5 * For conditions of distribution and use, see copyright notice in png.h
6 * Copyright (c) 1998-2001 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.)
9 */
11 #define PNG_INTERNAL
12 #include "png.h"
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
27 void PNGAPI
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...
42 void /* PRIVATE */
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);
50 break;
52 case PNG_READ_CHUNK_MODE:
54 png_push_read_chunk(png_ptr, info_ptr);
55 break;
57 case PNG_READ_IDAT_MODE:
59 png_push_read_IDAT(png_ptr);
60 break;
62 #if defined(PNG_READ_tEXt_SUPPORTED)
63 case PNG_READ_tEXt_MODE:
65 png_push_read_tEXt(png_ptr, info_ptr);
66 break;
68 #endif
69 #if defined(PNG_READ_zTXt_SUPPORTED)
70 case PNG_READ_zTXt_MODE:
72 png_push_read_zTXt(png_ptr, info_ptr);
73 break;
75 #endif
76 #if defined(PNG_READ_iTXt_SUPPORTED)
77 case PNG_READ_iTXt_MODE:
79 png_push_read_iTXt(png_ptr, info_ptr);
80 break;
82 #endif
83 case PNG_SKIP_MODE:
85 png_push_crc_finish(png_ptr);
86 break;
88 default:
90 png_ptr->buffer_size = 0;
91 break;
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
100 * routine.
102 void /* PRIVATE */
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]),
114 num_to_check);
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");
122 else
123 png_error(png_ptr, "PNG file corrupted by ASCII conversion");
125 else
127 if (png_ptr->sig_bytes >= 8)
129 png_ptr->process_mode = PNG_READ_CHUNK_MODE;
134 void /* PRIVATE */
135 png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
137 #ifdef PNG_USE_LOCAL_ARRAYS
138 PNG_IHDR;
139 PNG_IDAT;
140 PNG_IEND;
141 PNG_PLTE;
142 #if defined(PNG_READ_bKGD_SUPPORTED)
143 PNG_bKGD;
144 #endif
145 #if defined(PNG_READ_cHRM_SUPPORTED)
146 PNG_cHRM;
147 #endif
148 #if defined(PNG_READ_gAMA_SUPPORTED)
149 PNG_gAMA;
150 #endif
151 #if defined(PNG_READ_hIST_SUPPORTED)
152 PNG_hIST;
153 #endif
154 #if defined(PNG_READ_iCCP_SUPPORTED)
155 PNG_iCCP;
156 #endif
157 #if defined(PNG_READ_iTXt_SUPPORTED)
158 PNG_iTXt;
159 #endif
160 #if defined(PNG_READ_oFFs_SUPPORTED)
161 PNG_oFFs;
162 #endif
163 #if defined(PNG_READ_pCAL_SUPPORTED)
164 PNG_pCAL;
165 #endif
166 #if defined(PNG_READ_pHYs_SUPPORTED)
167 PNG_pHYs;
168 #endif
169 #if defined(PNG_READ_sBIT_SUPPORTED)
170 PNG_sBIT;
171 #endif
172 #if defined(PNG_READ_sCAL_SUPPORTED)
173 PNG_sCAL;
174 #endif
175 #if defined(PNG_READ_sRGB_SUPPORTED)
176 PNG_sRGB;
177 #endif
178 #if defined(PNG_READ_sPLT_SUPPORTED)
179 PNG_sPLT;
180 #endif
181 #if defined(PNG_READ_tEXt_SUPPORTED)
182 PNG_tEXt;
183 #endif
184 #if defined(PNG_READ_tIME_SUPPORTED)
185 PNG_tIME;
186 #endif
187 #if defined(PNG_READ_tRNS_SUPPORTED)
188 PNG_tRNS;
189 #endif
190 #if defined(PNG_READ_zTXt_SUPPORTED)
191 PNG_zTXt;
192 #endif
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);
207 return;
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);
222 return;
225 png_handle_IHDR(png_ptr, info_ptr, png_ptr->push_length);
227 else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
229 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
231 png_push_save_buffer(png_ptr);
232 return;
235 png_handle_PLTE(png_ptr, info_ptr, png_ptr->push_length);
237 else if (!png_memcmp(png_ptr->chunk_name, (png_bytep)png_IDAT, 4))
239 /* If we reach an IDAT chunk, this means we have read all of the
240 * header chunks, and we can start reading the image (or if this
241 * is called after the image has been read - we have an error).
243 if (png_ptr->mode & PNG_HAVE_IDAT)
245 if (png_ptr->push_length == 0)
246 return;
248 if (png_ptr->mode & PNG_AFTER_IDAT)
249 png_error(png_ptr, "Too many IDAT's found");
252 png_ptr->idat_size = png_ptr->push_length;
253 png_ptr->mode |= PNG_HAVE_IDAT;
254 png_ptr->process_mode = PNG_READ_IDAT_MODE;
255 png_push_have_info(png_ptr, info_ptr);
256 png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
257 png_ptr->zstream.next_out = png_ptr->row_buf;
258 return;
260 else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
262 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
264 png_push_save_buffer(png_ptr);
265 return;
268 png_handle_IEND(png_ptr, info_ptr, png_ptr->push_length);
269 png_ptr->process_mode = PNG_READ_DONE_MODE;
270 png_push_have_end(png_ptr, info_ptr);
272 #if defined(PNG_READ_gAMA_SUPPORTED)
273 else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
275 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
277 png_push_save_buffer(png_ptr);
278 return;
281 png_handle_gAMA(png_ptr, info_ptr, png_ptr->push_length);
283 #endif
284 #if defined(PNG_READ_sBIT_SUPPORTED)
285 else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
287 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
289 png_push_save_buffer(png_ptr);
290 return;
293 png_handle_sBIT(png_ptr, info_ptr, png_ptr->push_length);
295 #endif
296 #if defined(PNG_READ_cHRM_SUPPORTED)
297 else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
299 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
301 png_push_save_buffer(png_ptr);
302 return;
305 png_handle_cHRM(png_ptr, info_ptr, png_ptr->push_length);
307 #endif
308 #if defined(PNG_READ_sRGB_SUPPORTED)
309 else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
311 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
313 png_push_save_buffer(png_ptr);
314 return;
317 png_handle_sRGB(png_ptr, info_ptr, png_ptr->push_length);
319 #endif
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);
326 return;
329 png_handle_iCCP(png_ptr, info_ptr, png_ptr->push_length);
331 #endif
332 #if defined(PNG_READ_sPLT_SUPPORTED)
333 else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
335 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
337 png_push_save_buffer(png_ptr);
338 return;
341 png_handle_sPLT(png_ptr, info_ptr, png_ptr->push_length);
343 #endif
344 #if defined(PNG_READ_tRNS_SUPPORTED)
345 else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
347 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
349 png_push_save_buffer(png_ptr);
350 return;
353 png_handle_tRNS(png_ptr, info_ptr, png_ptr->push_length);
355 #endif
356 #if defined(PNG_READ_bKGD_SUPPORTED)
357 else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
359 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
361 png_push_save_buffer(png_ptr);
362 return;
365 png_handle_bKGD(png_ptr, info_ptr, png_ptr->push_length);
367 #endif
368 #if defined(PNG_READ_hIST_SUPPORTED)
369 else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
371 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
373 png_push_save_buffer(png_ptr);
374 return;
377 png_handle_hIST(png_ptr, info_ptr, png_ptr->push_length);
379 #endif
380 #if defined(PNG_READ_pHYs_SUPPORTED)
381 else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
383 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
385 png_push_save_buffer(png_ptr);
386 return;
389 png_handle_pHYs(png_ptr, info_ptr, png_ptr->push_length);
391 #endif
392 #if defined(PNG_READ_oFFs_SUPPORTED)
393 else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
395 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
397 png_push_save_buffer(png_ptr);
398 return;
401 png_handle_oFFs(png_ptr, info_ptr, png_ptr->push_length);
403 #endif
404 #if defined(PNG_READ_pCAL_SUPPORTED)
405 else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
407 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
409 png_push_save_buffer(png_ptr);
410 return;
413 png_handle_pCAL(png_ptr, info_ptr, png_ptr->push_length);
415 #endif
416 #if defined(PNG_READ_sCAL_SUPPORTED)
417 else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
419 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
421 png_push_save_buffer(png_ptr);
422 return;
425 png_handle_sCAL(png_ptr, info_ptr, png_ptr->push_length);
427 #endif
428 #if defined(PNG_READ_tIME_SUPPORTED)
429 else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
431 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
433 png_push_save_buffer(png_ptr);
434 return;
437 png_handle_tIME(png_ptr, info_ptr, png_ptr->push_length);
439 #endif
440 #if defined(PNG_READ_tEXt_SUPPORTED)
441 else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
443 png_push_handle_tEXt(png_ptr, info_ptr, png_ptr->push_length);
445 #endif
446 #if defined(PNG_READ_zTXt_SUPPORTED)
447 else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
449 png_push_handle_zTXt(png_ptr, info_ptr, png_ptr->push_length);
451 #endif
452 #if defined(PNG_READ_iTXt_SUPPORTED)
453 else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
455 png_push_handle_iTXt(png_ptr, info_ptr, png_ptr->push_length);
457 #endif
458 else
460 png_push_handle_unknown(png_ptr, info_ptr, png_ptr->push_length);
463 png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
466 void /* PRIVATE */
467 png_push_crc_skip(png_structp png_ptr, png_uint_32 skip)
469 png_ptr->process_mode = PNG_SKIP_MODE;
470 png_ptr->skip_length = skip;
473 void /* PRIVATE */
474 png_push_crc_finish(png_structp png_ptr)
476 if (png_ptr->skip_length && png_ptr->save_buffer_size)
478 png_size_t save_size;
480 if (png_ptr->skip_length < (png_uint_32)png_ptr->save_buffer_size)
481 save_size = (png_size_t)png_ptr->skip_length;
482 else
483 save_size = png_ptr->save_buffer_size;
485 png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size);
487 png_ptr->skip_length -= save_size;
488 png_ptr->buffer_size -= save_size;
489 png_ptr->save_buffer_size -= save_size;
490 png_ptr->save_buffer_ptr += save_size;
492 if (png_ptr->skip_length && png_ptr->current_buffer_size)
494 png_size_t save_size;
496 if (png_ptr->skip_length < (png_uint_32)png_ptr->current_buffer_size)
497 save_size = (png_size_t)png_ptr->skip_length;
498 else
499 save_size = png_ptr->current_buffer_size;
501 png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size);
503 png_ptr->skip_length -= save_size;
504 png_ptr->buffer_size -= save_size;
505 png_ptr->current_buffer_size -= save_size;
506 png_ptr->current_buffer_ptr += save_size;
508 if (!png_ptr->skip_length)
510 if (png_ptr->buffer_size < 4)
512 png_push_save_buffer(png_ptr);
513 return;
516 png_crc_finish(png_ptr, 0);
517 png_ptr->process_mode = PNG_READ_CHUNK_MODE;
521 void /* PRIVATE */
522 png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length)
524 png_bytep ptr;
526 ptr = buffer;
527 if (png_ptr->save_buffer_size)
529 png_size_t save_size;
531 if (length < png_ptr->save_buffer_size)
532 save_size = length;
533 else
534 save_size = png_ptr->save_buffer_size;
536 png_memcpy(ptr, png_ptr->save_buffer_ptr, save_size);
537 length -= save_size;
538 ptr += save_size;
539 png_ptr->buffer_size -= save_size;
540 png_ptr->save_buffer_size -= save_size;
541 png_ptr->save_buffer_ptr += save_size;
543 if (length && png_ptr->current_buffer_size)
545 png_size_t save_size;
547 if (length < png_ptr->current_buffer_size)
548 save_size = length;
549 else
550 save_size = png_ptr->current_buffer_size;
552 png_memcpy(ptr, png_ptr->current_buffer_ptr, save_size);
553 png_ptr->buffer_size -= save_size;
554 png_ptr->current_buffer_size -= save_size;
555 png_ptr->current_buffer_ptr += save_size;
559 void /* PRIVATE */
560 png_push_save_buffer(png_structp png_ptr)
562 if (png_ptr->save_buffer_size)
564 if (png_ptr->save_buffer_ptr != png_ptr->save_buffer)
566 png_size_t i,istop;
567 png_bytep sp;
568 png_bytep dp;
570 istop = png_ptr->save_buffer_size;
571 for (i = 0, sp = png_ptr->save_buffer_ptr, dp = png_ptr->save_buffer;
572 i < istop; i++, sp++, dp++)
574 *dp = *sp;
578 if (png_ptr->save_buffer_size + png_ptr->current_buffer_size >
579 png_ptr->save_buffer_max)
581 png_size_t new_max;
582 png_bytep old_buffer;
584 new_max = png_ptr->save_buffer_size + png_ptr->current_buffer_size + 256;
585 old_buffer = png_ptr->save_buffer;
586 png_ptr->save_buffer = (png_bytep)png_malloc(png_ptr,
587 (png_uint_32)new_max);
588 png_memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size);
589 png_free(png_ptr, old_buffer);
590 png_ptr->save_buffer_max = new_max;
592 if (png_ptr->current_buffer_size)
594 png_memcpy(png_ptr->save_buffer + png_ptr->save_buffer_size,
595 png_ptr->current_buffer_ptr, png_ptr->current_buffer_size);
596 png_ptr->save_buffer_size += png_ptr->current_buffer_size;
597 png_ptr->current_buffer_size = 0;
599 png_ptr->save_buffer_ptr = png_ptr->save_buffer;
600 png_ptr->buffer_size = 0;
603 void /* PRIVATE */
604 png_push_restore_buffer(png_structp png_ptr, png_bytep buffer,
605 png_size_t buffer_length)
607 png_ptr->current_buffer = buffer;
608 png_ptr->current_buffer_size = buffer_length;
609 png_ptr->buffer_size = buffer_length + png_ptr->save_buffer_size;
610 png_ptr->current_buffer_ptr = png_ptr->current_buffer;
613 void /* PRIVATE */
614 png_push_read_IDAT(png_structp png_ptr)
616 #ifdef PNG_USE_LOCAL_ARRAYS
617 PNG_IDAT;
618 #endif
619 if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
621 png_byte chunk_length[4];
623 if (png_ptr->buffer_size < 8)
625 png_push_save_buffer(png_ptr);
626 return;
629 png_push_fill_buffer(png_ptr, chunk_length, 4);
630 png_ptr->push_length = png_get_uint_32(chunk_length);
632 png_reset_crc(png_ptr);
633 png_crc_read(png_ptr, png_ptr->chunk_name, 4);
634 png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
636 if (png_memcmp(png_ptr->chunk_name, (png_bytep)png_IDAT, 4))
638 png_ptr->process_mode = PNG_READ_CHUNK_MODE;
639 if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
640 png_error(png_ptr, "Not enough compressed data");
641 return;
644 png_ptr->idat_size = png_ptr->push_length;
646 if (png_ptr->idat_size && png_ptr->save_buffer_size)
648 png_size_t save_size;
650 if (png_ptr->idat_size < (png_uint_32)png_ptr->save_buffer_size)
652 save_size = (png_size_t)png_ptr->idat_size;
653 /* check for overflow */
654 if((png_uint_32)save_size != png_ptr->idat_size)
655 png_error(png_ptr, "save_size overflowed in pngpread");
657 else
658 save_size = png_ptr->save_buffer_size;
660 png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size);
661 png_process_IDAT_data(png_ptr, png_ptr->save_buffer_ptr, save_size);
663 png_ptr->idat_size -= save_size;
664 png_ptr->buffer_size -= save_size;
665 png_ptr->save_buffer_size -= save_size;
666 png_ptr->save_buffer_ptr += save_size;
668 if (png_ptr->idat_size && png_ptr->current_buffer_size)
670 png_size_t save_size;
672 if (png_ptr->idat_size < (png_uint_32)png_ptr->current_buffer_size)
674 save_size = (png_size_t)png_ptr->idat_size;
675 /* check for overflow */
676 if((png_uint_32)save_size != png_ptr->idat_size)
677 png_error(png_ptr, "save_size overflowed in pngpread");
679 else
680 save_size = png_ptr->current_buffer_size;
682 png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size);
683 png_process_IDAT_data(png_ptr, png_ptr->current_buffer_ptr, save_size);
685 png_ptr->idat_size -= save_size;
686 png_ptr->buffer_size -= save_size;
687 png_ptr->current_buffer_size -= save_size;
688 png_ptr->current_buffer_ptr += save_size;
690 if (!png_ptr->idat_size)
692 if (png_ptr->buffer_size < 4)
694 png_push_save_buffer(png_ptr);
695 return;
698 png_crc_finish(png_ptr, 0);
699 png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
703 void /* PRIVATE */
704 png_process_IDAT_data(png_structp png_ptr, png_bytep buffer,
705 png_size_t buffer_length)
707 int ret;
709 if ((png_ptr->flags & PNG_FLAG_ZLIB_FINISHED) && buffer_length)
710 png_error(png_ptr, "Extra compression data");
712 png_ptr->zstream.next_in = buffer;
713 png_ptr->zstream.avail_in = (uInt)buffer_length;
714 for(;;)
716 ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
717 if (ret != Z_OK)
719 if (ret == Z_STREAM_END)
721 if (png_ptr->zstream.avail_in)
722 png_error(png_ptr, "Extra compressed data");
723 if (!(png_ptr->zstream.avail_out))
725 png_push_process_row(png_ptr);
728 png_ptr->mode |= PNG_AFTER_IDAT;
729 png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
730 break;
732 else if (ret == Z_BUF_ERROR)
733 break;
734 else
735 png_error(png_ptr, "Decompression Error");
737 if (!(png_ptr->zstream.avail_out))
739 png_push_process_row(png_ptr);
740 png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
741 png_ptr->zstream.next_out = png_ptr->row_buf;
743 else
744 break;
748 void /* PRIVATE */
749 png_push_process_row(png_structp png_ptr)
751 png_ptr->row_info.color_type = png_ptr->color_type;
752 png_ptr->row_info.width = png_ptr->iwidth;
753 png_ptr->row_info.channels = png_ptr->channels;
754 png_ptr->row_info.bit_depth = png_ptr->bit_depth;
755 png_ptr->row_info.pixel_depth = png_ptr->pixel_depth;
757 png_ptr->row_info.rowbytes = ((png_ptr->row_info.width *
758 (png_uint_32)png_ptr->row_info.pixel_depth + 7) >> 3);
760 png_read_filter_row(png_ptr, &(png_ptr->row_info),
761 png_ptr->row_buf + 1, png_ptr->prev_row + 1,
762 (int)(png_ptr->row_buf[0]));
764 png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf,
765 png_ptr->rowbytes + 1);
767 if (png_ptr->transformations)
768 png_do_read_transformations(png_ptr);
770 #if defined(PNG_READ_INTERLACING_SUPPORTED)
771 /* blow up interlaced rows to full size */
772 if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
774 if (png_ptr->pass < 6)
775 /* old interface (pre-1.0.9):
776 png_do_read_interlace(&(png_ptr->row_info),
777 png_ptr->row_buf + 1, png_ptr->pass, png_ptr->transformations);
779 png_do_read_interlace(png_ptr);
781 switch (png_ptr->pass)
783 case 0:
785 int i;
786 for (i = 0; i < 8 && png_ptr->pass == 0; i++)
788 png_push_have_row(png_ptr, png_ptr->row_buf + 1);
789 png_read_push_finish_row(png_ptr); /* updates png_ptr->pass */
791 if (png_ptr->pass == 2) /* pass 1 might be empty */
793 for (i = 0; i < 4 && png_ptr->pass == 2; i++)
795 png_push_have_row(png_ptr, NULL);
796 png_read_push_finish_row(png_ptr);
799 if (png_ptr->pass == 4 && png_ptr->height <= 4)
801 for (i = 0; i < 2 && png_ptr->pass == 4; i++)
803 png_push_have_row(png_ptr, NULL);
804 png_read_push_finish_row(png_ptr);
807 if (png_ptr->pass == 6 && png_ptr->height <= 4)
809 png_push_have_row(png_ptr, NULL);
810 png_read_push_finish_row(png_ptr);
812 break;
814 case 1:
816 int i;
817 for (i = 0; i < 8 && png_ptr->pass == 1; i++)
819 png_push_have_row(png_ptr, png_ptr->row_buf + 1);
820 png_read_push_finish_row(png_ptr);
822 if (png_ptr->pass == 2) /* skip top 4 generated rows */
824 for (i = 0; i < 4 && png_ptr->pass == 2; i++)
826 png_push_have_row(png_ptr, NULL);
827 png_read_push_finish_row(png_ptr);
830 break;
832 case 2:
834 int i;
835 for (i = 0; i < 4 && png_ptr->pass == 2; i++)
837 png_push_have_row(png_ptr, png_ptr->row_buf + 1);
838 png_read_push_finish_row(png_ptr);
840 for (i = 0; i < 4 && png_ptr->pass == 2; i++)
842 png_push_have_row(png_ptr, NULL);
843 png_read_push_finish_row(png_ptr);
845 if (png_ptr->pass == 4) /* pass 3 might be empty */
847 for (i = 0; i < 2 && png_ptr->pass == 4; i++)
849 png_push_have_row(png_ptr, NULL);
850 png_read_push_finish_row(png_ptr);
853 break;
855 case 3:
857 int i;
858 for (i = 0; i < 4 && png_ptr->pass == 3; i++)
860 png_push_have_row(png_ptr, png_ptr->row_buf + 1);
861 png_read_push_finish_row(png_ptr);
863 if (png_ptr->pass == 4) /* skip top two generated rows */
865 for (i = 0; i < 2 && png_ptr->pass == 4; i++)
867 png_push_have_row(png_ptr, NULL);
868 png_read_push_finish_row(png_ptr);
871 break;
873 case 4:
875 int i;
876 for (i = 0; i < 2 && png_ptr->pass == 4; i++)
878 png_push_have_row(png_ptr, png_ptr->row_buf + 1);
879 png_read_push_finish_row(png_ptr);
881 for (i = 0; i < 2 && png_ptr->pass == 4; i++)
883 png_push_have_row(png_ptr, NULL);
884 png_read_push_finish_row(png_ptr);
886 if (png_ptr->pass == 6) /* pass 5 might be empty */
888 png_push_have_row(png_ptr, NULL);
889 png_read_push_finish_row(png_ptr);
891 break;
893 case 5:
895 int i;
896 for (i = 0; i < 2 && png_ptr->pass == 5; i++)
898 png_push_have_row(png_ptr, png_ptr->row_buf + 1);
899 png_read_push_finish_row(png_ptr);
901 if (png_ptr->pass == 6) /* skip top generated row */
903 png_push_have_row(png_ptr, NULL);
904 png_read_push_finish_row(png_ptr);
906 break;
908 case 6:
910 png_push_have_row(png_ptr, png_ptr->row_buf + 1);
911 png_read_push_finish_row(png_ptr);
912 if (png_ptr->pass != 6)
913 break;
914 png_push_have_row(png_ptr, NULL);
915 png_read_push_finish_row(png_ptr);
919 else
920 #endif
922 png_push_have_row(png_ptr, png_ptr->row_buf + 1);
923 png_read_push_finish_row(png_ptr);
927 void /* PRIVATE */
928 png_read_push_finish_row(png_structp png_ptr)
930 #ifdef PNG_USE_LOCAL_ARRAYS
931 /* arrays to facilitate easy interlacing - use pass (0 - 6) as index */
933 /* start of interlace block */
934 const int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
936 /* offset to next interlace block */
937 const int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
939 /* start of interlace block in the y direction */
940 const int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
942 /* offset to next interlace block in the y direction */
943 const int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
945 /* Width of interlace block. This is not currently used - if you need
946 * it, uncomment it here and in png.h
947 const int FARDATA png_pass_width[] = {8, 4, 4, 2, 2, 1, 1};
950 /* Height of interlace block. This is not currently used - if you need
951 * it, uncomment it here and in png.h
952 const int FARDATA png_pass_height[] = {8, 8, 4, 4, 2, 2, 1};
954 #endif
956 png_ptr->row_number++;
957 if (png_ptr->row_number < png_ptr->num_rows)
958 return;
960 if (png_ptr->interlaced)
962 png_ptr->row_number = 0;
963 png_memset_check(png_ptr, png_ptr->prev_row, 0,
964 png_ptr->rowbytes + 1);
967 png_ptr->pass++;
968 if ((png_ptr->pass == 1 && png_ptr->width < 5) ||
969 (png_ptr->pass == 3 && png_ptr->width < 3) ||
970 (png_ptr->pass == 5 && png_ptr->width < 2))
971 png_ptr->pass++;
973 if (png_ptr->pass >= 7)
974 break;
976 png_ptr->iwidth = (png_ptr->width +
977 png_pass_inc[png_ptr->pass] - 1 -
978 png_pass_start[png_ptr->pass]) /
979 png_pass_inc[png_ptr->pass];
981 png_ptr->irowbytes = ((png_ptr->iwidth *
982 png_ptr->pixel_depth + 7) >> 3) + 1;
984 if (png_ptr->transformations & PNG_INTERLACE)
985 break;
987 png_ptr->num_rows = (png_ptr->height +
988 png_pass_yinc[png_ptr->pass] - 1 -
989 png_pass_ystart[png_ptr->pass]) /
990 png_pass_yinc[png_ptr->pass];
992 } while (png_ptr->iwidth == 0 || png_ptr->num_rows == 0);
996 #if defined(PNG_READ_tEXt_SUPPORTED)
997 void /* PRIVATE */
998 png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
1000 if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
1002 png_error(png_ptr, "Out of place tEXt");
1003 /* to quiet some compiler warnings */
1004 if(info_ptr == NULL) return;
1007 #ifdef PNG_MAX_MALLOC_64K
1008 png_ptr->skip_length = 0; /* This may not be necessary */
1010 if (length > (png_uint_32)65535L) /* Can't hold the entire string in memory */
1012 png_warning(png_ptr, "tEXt chunk too large to fit in memory");
1013 png_ptr->skip_length = length - (png_uint_32)65535L;
1014 length = (png_uint_32)65535L;
1016 #endif
1018 png_ptr->current_text = (png_charp)png_malloc(png_ptr,
1019 (png_uint_32)(length+1));
1020 png_ptr->current_text[length] = '\0';
1021 png_ptr->current_text_ptr = png_ptr->current_text;
1022 png_ptr->current_text_size = (png_size_t)length;
1023 png_ptr->current_text_left = (png_size_t)length;
1024 png_ptr->process_mode = PNG_READ_tEXt_MODE;
1027 void /* PRIVATE */
1028 png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr)
1030 if (png_ptr->buffer_size && png_ptr->current_text_left)
1032 png_size_t text_size;
1034 if (png_ptr->buffer_size < png_ptr->current_text_left)
1035 text_size = png_ptr->buffer_size;
1036 else
1037 text_size = png_ptr->current_text_left;
1038 png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
1039 png_ptr->current_text_left -= text_size;
1040 png_ptr->current_text_ptr += text_size;
1042 if (!(png_ptr->current_text_left))
1044 png_textp text_ptr;
1045 png_charp text;
1046 png_charp key;
1048 if (png_ptr->buffer_size < 4)
1050 png_push_save_buffer(png_ptr);
1051 return;
1054 png_push_crc_finish(png_ptr);
1056 #if defined(PNG_MAX_MALLOC_64K)
1057 if (png_ptr->skip_length)
1058 return;
1059 #endif
1061 key = png_ptr->current_text;
1062 png_ptr->current_text = 0;
1064 for (text = key; *text; text++)
1065 /* empty loop */ ;
1067 if (text != key + png_ptr->current_text_size)
1068 text++;
1070 text_ptr = (png_textp)png_malloc(png_ptr, (png_uint_32)sizeof(png_text));
1071 text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
1072 text_ptr->key = key;
1073 #ifdef PNG_iTXt_SUPPORTED
1074 text_ptr->lang = (char *)NULL;
1075 text_ptr->lang_key = (char *)NULL;
1076 #endif
1077 text_ptr->text = text;
1079 png_set_text(png_ptr, info_ptr, text_ptr, 1);
1081 png_free(png_ptr, key);
1082 png_free(png_ptr, text_ptr);
1085 #endif
1087 #if defined(PNG_READ_zTXt_SUPPORTED)
1088 void /* PRIVATE */
1089 png_push_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
1091 if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
1093 png_error(png_ptr, "Out of place zTXt");
1094 /* to quiet some compiler warnings */
1095 if(info_ptr == NULL) return;
1098 #ifdef PNG_MAX_MALLOC_64K
1099 /* We can't handle zTXt chunks > 64K, since we don't have enough space
1100 * to be able to store the uncompressed data. Actually, the threshold
1101 * is probably around 32K, but it isn't as definite as 64K is.
1103 if (length > (png_uint_32)65535L)
1105 png_warning(png_ptr, "zTXt chunk too large to fit in memory");
1106 png_push_crc_skip(png_ptr, length);
1107 return;
1109 #endif
1111 png_ptr->current_text = (png_charp)png_malloc(png_ptr,
1112 (png_uint_32)(length+1));
1113 png_ptr->current_text[length] = '\0';
1114 png_ptr->current_text_ptr = png_ptr->current_text;
1115 png_ptr->current_text_size = (png_size_t)length;
1116 png_ptr->current_text_left = (png_size_t)length;
1117 png_ptr->process_mode = PNG_READ_zTXt_MODE;
1120 void /* PRIVATE */
1121 png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
1123 if (png_ptr->buffer_size && png_ptr->current_text_left)
1125 png_size_t text_size;
1127 if (png_ptr->buffer_size < (png_uint_32)png_ptr->current_text_left)
1128 text_size = png_ptr->buffer_size;
1129 else
1130 text_size = png_ptr->current_text_left;
1131 png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
1132 png_ptr->current_text_left -= text_size;
1133 png_ptr->current_text_ptr += text_size;
1135 if (!(png_ptr->current_text_left))
1137 png_textp text_ptr;
1138 png_charp text;
1139 png_charp key;
1140 int ret;
1141 png_size_t text_size, key_size;
1143 if (png_ptr->buffer_size < 4)
1145 png_push_save_buffer(png_ptr);
1146 return;
1149 png_push_crc_finish(png_ptr);
1151 key = png_ptr->current_text;
1152 png_ptr->current_text = 0;
1154 for (text = key; *text; text++)
1155 /* empty loop */ ;
1157 /* zTXt can't have zero text */
1158 if (text == key + png_ptr->current_text_size)
1160 png_free(png_ptr, key);
1161 return;
1164 text++;
1166 if (*text != PNG_TEXT_COMPRESSION_zTXt) /* check compression byte */
1168 png_free(png_ptr, key);
1169 return;
1172 text++;
1174 png_ptr->zstream.next_in = (png_bytep )text;
1175 png_ptr->zstream.avail_in = (uInt)(png_ptr->current_text_size -
1176 (text - key));
1177 png_ptr->zstream.next_out = png_ptr->zbuf;
1178 png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
1180 key_size = text - key;
1181 text_size = 0;
1182 text = NULL;
1183 ret = Z_STREAM_END;
1185 while (png_ptr->zstream.avail_in)
1187 ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
1188 if (ret != Z_OK && ret != Z_STREAM_END)
1190 inflateReset(&png_ptr->zstream);
1191 png_ptr->zstream.avail_in = 0;
1192 png_free(png_ptr, key);
1193 png_free(png_ptr, text);
1194 return;
1196 if (!(png_ptr->zstream.avail_out) || ret == Z_STREAM_END)
1198 if (text == NULL)
1200 text = (png_charp)png_malloc(png_ptr,
1201 (png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out +
1202 key_size + 1));
1203 png_memcpy(text + key_size, png_ptr->zbuf,
1204 png_ptr->zbuf_size - png_ptr->zstream.avail_out);
1205 png_memcpy(text, key, key_size);
1206 text_size = key_size + png_ptr->zbuf_size -
1207 png_ptr->zstream.avail_out;
1208 *(text + text_size) = '\0';
1210 else
1212 png_charp tmp;
1214 tmp = text;
1215 text = (png_charp)png_malloc(png_ptr, text_size +
1216 (png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out
1217 + 1));
1218 png_memcpy(text, tmp, text_size);
1219 png_free(png_ptr, tmp);
1220 png_memcpy(text + text_size, png_ptr->zbuf,
1221 png_ptr->zbuf_size - png_ptr->zstream.avail_out);
1222 text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out;
1223 *(text + text_size) = '\0';
1225 if (ret != Z_STREAM_END)
1227 png_ptr->zstream.next_out = png_ptr->zbuf;
1228 png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
1231 else
1233 break;
1236 if (ret == Z_STREAM_END)
1237 break;
1240 inflateReset(&png_ptr->zstream);
1241 png_ptr->zstream.avail_in = 0;
1243 if (ret != Z_STREAM_END)
1245 png_free(png_ptr, key);
1246 png_free(png_ptr, text);
1247 return;
1250 png_free(png_ptr, key);
1251 key = text;
1252 text += key_size;
1254 text_ptr = (png_textp)png_malloc(png_ptr, (png_uint_32)sizeof(png_text));
1255 text_ptr->compression = PNG_TEXT_COMPRESSION_zTXt;
1256 text_ptr->key = key;
1257 #ifdef PNG_iTXt_SUPPORTED
1258 text_ptr->lang = (char *)NULL;
1259 text_ptr->lang_key = (char *)NULL;
1260 #endif
1261 text_ptr->text = text;
1263 png_set_text(png_ptr, info_ptr, text_ptr, 1);
1265 png_free(png_ptr, key);
1266 png_free(png_ptr, text_ptr);
1269 #endif
1271 #if defined(PNG_READ_iTXt_SUPPORTED)
1272 void /* PRIVATE */
1273 png_push_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
1275 if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
1277 png_error(png_ptr, "Out of place iTXt");
1278 /* to quiet some compiler warnings */
1279 if(info_ptr == NULL) return;
1282 #ifdef PNG_MAX_MALLOC_64K
1283 png_ptr->skip_length = 0; /* This may not be necessary */
1285 if (length > (png_uint_32)65535L) /* Can't hold the entire string in memory */
1287 png_warning(png_ptr, "iTXt chunk too large to fit in memory");
1288 png_ptr->skip_length = length - (png_uint_32)65535L;
1289 length = (png_uint_32)65535L;
1291 #endif
1293 png_ptr->current_text = (png_charp)png_malloc(png_ptr,
1294 (png_uint_32)(length+1));
1295 png_ptr->current_text[length] = '\0';
1296 png_ptr->current_text_ptr = png_ptr->current_text;
1297 png_ptr->current_text_size = (png_size_t)length;
1298 png_ptr->current_text_left = (png_size_t)length;
1299 png_ptr->process_mode = PNG_READ_iTXt_MODE;
1302 void /* PRIVATE */
1303 png_push_read_iTXt(png_structp png_ptr, png_infop info_ptr)
1306 if (png_ptr->buffer_size && png_ptr->current_text_left)
1308 png_size_t text_size;
1310 if (png_ptr->buffer_size < png_ptr->current_text_left)
1311 text_size = png_ptr->buffer_size;
1312 else
1313 text_size = png_ptr->current_text_left;
1314 png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
1315 png_ptr->current_text_left -= text_size;
1316 png_ptr->current_text_ptr += text_size;
1318 if (!(png_ptr->current_text_left))
1320 png_textp text_ptr;
1321 png_charp key;
1322 int comp_flag;
1323 png_charp lang;
1324 png_charp lang_key;
1325 png_charp text;
1327 if (png_ptr->buffer_size < 4)
1329 png_push_save_buffer(png_ptr);
1330 return;
1333 png_push_crc_finish(png_ptr);
1335 #if defined(PNG_MAX_MALLOC_64K)
1336 if (png_ptr->skip_length)
1337 return;
1338 #endif
1340 key = png_ptr->current_text;
1341 png_ptr->current_text = 0;
1343 for (lang = key; *lang; lang++)
1344 /* empty loop */ ;
1346 if (lang != key + png_ptr->current_text_size)
1347 lang++;
1349 comp_flag = *lang++;
1350 lang++; /* skip comp_type, always zero */
1352 for (lang_key = lang; *lang_key; lang_key++)
1353 /* empty loop */ ;
1354 lang_key++; /* skip NUL separator */
1356 for (text = lang_key; *text; text++)
1357 /* empty loop */ ;
1359 if (text != key + png_ptr->current_text_size)
1360 text++;
1362 text_ptr = (png_textp)png_malloc(png_ptr, (png_uint_32)sizeof(png_text));
1363 text_ptr->compression = comp_flag + 2;
1364 text_ptr->key = key;
1365 text_ptr->lang = lang;
1366 text_ptr->lang_key = lang_key;
1367 text_ptr->text = text;
1368 text_ptr->text_length = 0;
1369 text_ptr->itxt_length = png_strlen(text);
1371 png_set_text(png_ptr, info_ptr, text_ptr, 1);
1373 png_free(png_ptr, text_ptr);
1376 #endif
1378 /* This function is called when we haven't found a handler for this
1379 * chunk. If there isn't a problem with the chunk itself (ie a bad chunk
1380 * name or a critical chunk), the chunk is (currently) silently ignored.
1382 void /* PRIVATE */
1383 png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
1385 png_uint_32 skip=0;
1386 png_check_chunk_name(png_ptr, png_ptr->chunk_name);
1388 if (!(png_ptr->chunk_name[0] & 0x20))
1390 #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
1391 if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
1392 HANDLE_CHUNK_ALWAYS
1393 #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
1394 && png_ptr->read_user_chunk_fn == (png_user_chunk_ptr)NULL
1395 #endif
1397 #endif
1398 png_chunk_error(png_ptr, "unknown critical chunk");
1400 /* to quiet compiler warnings about unused info_ptr */
1401 if (info_ptr == NULL)
1402 return;
1405 #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
1406 if (png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS)
1408 png_unknown_chunk chunk;
1410 #ifdef PNG_MAX_MALLOC_64K
1411 if (length > (png_uint_32)65535L)
1413 png_warning(png_ptr, "unknown chunk too large to fit in memory");
1414 skip = length - (png_uint_32)65535L;
1415 length = (png_uint_32)65535L;
1417 #endif
1419 png_strcpy((png_charp)chunk.name, (png_charp)png_ptr->chunk_name);
1420 chunk.data = (png_bytep)png_malloc(png_ptr, length);
1421 png_crc_read(png_ptr, chunk.data, length);
1422 chunk.size = length;
1423 #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
1424 if(png_ptr->read_user_chunk_fn != (png_user_chunk_ptr)NULL)
1426 /* callback to user unknown chunk handler */
1427 if ((*(png_ptr->read_user_chunk_fn)) (png_ptr, &chunk) <= 0)
1429 if (!(png_ptr->chunk_name[0] & 0x20))
1430 if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
1431 HANDLE_CHUNK_ALWAYS)
1432 png_chunk_error(png_ptr, "unknown critical chunk");
1434 png_set_unknown_chunks(png_ptr, info_ptr, &chunk, 1);
1436 else
1437 #endif
1438 png_set_unknown_chunks(png_ptr, info_ptr, &chunk, 1);
1439 png_free(png_ptr, chunk.data);
1441 else
1442 #endif
1443 skip=length;
1444 png_push_crc_skip(png_ptr, skip);
1447 void /* PRIVATE */
1448 png_push_have_info(png_structp png_ptr, png_infop info_ptr)
1450 if (png_ptr->info_fn != NULL)
1451 (*(png_ptr->info_fn))(png_ptr, info_ptr);
1454 void /* PRIVATE */
1455 png_push_have_end(png_structp png_ptr, png_infop info_ptr)
1457 if (png_ptr->end_fn != NULL)
1458 (*(png_ptr->end_fn))(png_ptr, info_ptr);
1461 void /* PRIVATE */
1462 png_push_have_row(png_structp png_ptr, png_bytep row)
1464 if (png_ptr->row_fn != NULL)
1465 (*(png_ptr->row_fn))(png_ptr, row, png_ptr->row_number,
1466 (int)png_ptr->pass);
1469 void PNGAPI
1470 png_progressive_combine_row (png_structp png_ptr,
1471 png_bytep old_row, png_bytep new_row)
1473 #ifdef PNG_USE_LOCAL_ARRAYS
1474 const int FARDATA png_pass_dsp_mask[7] =
1475 {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
1476 #endif
1477 if (new_row != NULL) /* new_row must == png_ptr->row_buf here. */
1478 png_combine_row(png_ptr, old_row, png_pass_dsp_mask[png_ptr->pass]);
1481 void PNGAPI
1482 png_set_progressive_read_fn(png_structp png_ptr, png_voidp progressive_ptr,
1483 png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
1484 png_progressive_end_ptr end_fn)
1486 png_ptr->info_fn = info_fn;
1487 png_ptr->row_fn = row_fn;
1488 png_ptr->end_fn = end_fn;
1490 png_set_read_fn(png_ptr, progressive_ptr, png_push_fill_buffer);
1493 png_voidp PNGAPI
1494 png_get_progressive_ptr(png_structp png_ptr)
1496 return png_ptr->io_ptr;
1499 #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */