2 ===================================================================
6 #if defined(PNG_READ_zTXt_SUPPORTED)
9 +#if defined(PNG_READ_APNG_SUPPORTED)
14 #endif /* PNG_USE_LOCAL_ARRAYS */
15 png_uint_32 length = png_read_chunk_header(png_ptr);
16 PNG_CONST png_bytep chunk_name = png_ptr->chunk_name;
18 !(png_ptr->mode & PNG_HAVE_PLTE))
19 png_error(png_ptr, "Missing PLTE before IDAT");
21 +#if defined(PNG_READ_APNG_SUPPORTED)
22 + png_have_info(png_ptr, info_ptr);
24 png_ptr->idat_size = length;
25 png_ptr->mode |= PNG_HAVE_IDAT;
28 else if (!png_memcmp(chunk_name, png_iTXt, 4))
29 png_handle_iTXt(png_ptr, info_ptr, length);
31 +#if defined(PNG_READ_APNG_SUPPORTED)
32 + else if (!png_memcmp(chunk_name, png_acTL, 4))
33 + png_handle_acTL(png_ptr, info_ptr, length);
34 + else if (!png_memcmp(chunk_name, png_fcTL, 4))
35 + png_handle_fcTL(png_ptr, info_ptr, length);
36 + else if (!png_memcmp(chunk_name, png_fdAT, 4))
37 + png_handle_fdAT(png_ptr, info_ptr, length);
40 png_handle_unknown(png_ptr, info_ptr, length);
43 #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
45 +#if defined(PNG_READ_APNG_SUPPORTED)
47 +png_read_frame_head(png_structp png_ptr, png_infop info_ptr)
49 + png_byte have_chunk_after_DAT; /* after IDAT or after fdAT */
51 + png_debug(0, "Reading frame head");
53 + if (!(png_ptr->mode & PNG_HAVE_acTL))
54 + png_error(png_ptr, "attempt to png_read_frame_head() but "
57 + /* do nothing for the main IDAT */
58 + if (png_ptr->num_frames_read == 0)
61 + png_crc_finish(png_ptr, 0); /* CRC from last IDAT or fdAT chunk */
63 + png_read_reset(png_ptr);
64 + png_ptr->mode &= ~PNG_HAVE_fcTL;
66 + have_chunk_after_DAT = 0;
69 +#ifdef PNG_USE_LOCAL_ARRAYS
74 + png_byte chunk_length[4];
77 + png_read_data(png_ptr, chunk_length, 4);
78 + length = png_get_uint_31(png_ptr, chunk_length);
80 + png_reset_crc(png_ptr);
81 + png_crc_read(png_ptr, png_ptr->chunk_name, 4);
83 + if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
85 + /* discard trailing IDATs for the first frame */
86 + if (have_chunk_after_DAT || png_ptr->num_frames_read > 1)
87 + png_error(png_ptr, "png_read_frame_head(): out of place IDAT");
88 + png_crc_finish(png_ptr, length);
90 + else if (!png_memcmp(png_ptr->chunk_name, png_fcTL, 4))
92 + png_handle_fcTL(png_ptr, info_ptr, length);
93 + have_chunk_after_DAT = 1;
95 + else if (!png_memcmp(png_ptr->chunk_name, png_fdAT, 4))
97 + png_ensure_sequence_number(png_ptr, length);
99 + /* discard trailing fdATs for frames other than the first */
100 + if (!have_chunk_after_DAT && png_ptr->num_frames_read > 1)
101 + png_crc_finish(png_ptr, length - 4);
102 + else if(png_ptr->mode & PNG_HAVE_fcTL)
104 + png_ptr->idat_size = length - 4;
105 + png_ptr->mode |= PNG_HAVE_IDAT;
110 + png_error(png_ptr, "png_read_frame_head(): out of place fdAT");
114 + png_warning(png_ptr, "Skipped (ignored) a chunk "
115 + "between APNG chunks");
116 + png_crc_finish(png_ptr, length);
120 +#endif /* PNG_READ_APNG_SUPPORTED */
122 /* Optional call to update the users info_ptr structure */
124 png_read_update_info(png_structp png_ptr, png_infop info_ptr)
127 #ifdef PNG_USE_LOCAL_ARRAYS
129 +#if defined(PNG_READ_APNG_SUPPORTED)
130 + PNG_CONST PNG_fdAT;
131 + PNG_CONST PNG_IEND;
133 PNG_CONST int png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55,
135 PNG_CONST int png_pass_mask[7] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
136 @@ -703,13 +800,39 @@
138 if (!(png_ptr->zstream.avail_in))
140 - while (!png_ptr->idat_size)
141 + png_uint_32 bytes_to_skip = 0;
143 + while (!png_ptr->idat_size || bytes_to_skip != 0)
145 - png_crc_finish(png_ptr, 0);
146 + png_crc_finish(png_ptr, bytes_to_skip);
149 png_ptr->idat_size = png_read_chunk_header(png_ptr);
150 +#if defined(PNG_READ_APNG_SUPPORTED)
151 + if (png_ptr->num_frames_read == 0)
154 if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
155 png_error(png_ptr, "Not enough image data");
156 +#if defined(PNG_READ_APNG_SUPPORTED)
160 + if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
161 + png_error(png_ptr, "Not enough image data");
162 + if (png_memcmp(png_ptr->chunk_name, png_fdAT, 4))
164 + png_warning(png_ptr, "Skipped (ignored) a chunk "
165 + "between APNG chunks");
166 + bytes_to_skip = png_ptr->idat_size;
170 + png_ensure_sequence_number(png_ptr, png_ptr->idat_size);
172 + png_ptr->idat_size -= 4;
176 png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size;
177 png_ptr->zstream.next_in = png_ptr->zbuf;
179 png_error(png_ptr, "Extra compressed data");
180 png_ptr->mode |= PNG_AFTER_IDAT;
181 png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
182 +#if defined(PNG_READ_APNG_SUPPORTED)
183 + png_ptr->num_frames_read++;
188 @@ -981,6 +1107,11 @@
189 #if defined(PNG_READ_zTXt_SUPPORTED)
192 +#if defined(PNG_READ_APNG_SUPPORTED)
193 + PNG_CONST PNG_acTL;
194 + PNG_CONST PNG_fcTL;
195 + PNG_CONST PNG_fdAT;
197 #endif /* PNG_USE_LOCAL_ARRAYS */
198 png_uint_32 length = png_read_chunk_header(png_ptr);
199 PNG_CONST png_bytep chunk_name = png_ptr->chunk_name;
200 @@ -1081,6 +1212,14 @@
201 else if (!png_memcmp(chunk_name, png_iTXt, 4))
202 png_handle_iTXt(png_ptr, info_ptr, length);
204 +#if defined(PNG_READ_APNG_SUPPORTED)
205 + else if (!png_memcmp(chunk_name, png_acTL, 4))
206 + png_handle_acTL(png_ptr, info_ptr, length);
207 + else if (!png_memcmp(chunk_name, png_fcTL, 4))
208 + png_handle_fcTL(png_ptr, info_ptr, length);
209 + else if (!png_memcmp(chunk_name, png_fdAT, 4))
210 + png_handle_fdAT(png_ptr, info_ptr, length);
213 png_handle_unknown(png_ptr, info_ptr, length);
214 } while (!(png_ptr->mode & PNG_HAVE_IEND));
216 ===================================================================
219 @@ -839,6 +839,167 @@
223 +#ifdef PNG_APNG_SUPPORTED
225 +png_get_acTL(png_structp png_ptr, png_infop info_ptr,
226 + png_uint_32 *num_frames, png_uint_32 *num_plays)
228 + png_debug1(1, "in %s retrieval function", "acTL");
230 + if (png_ptr != NULL && info_ptr != NULL &&
231 + (info_ptr->valid & PNG_INFO_acTL) &&
232 + num_frames != NULL && num_plays != NULL)
234 + *num_frames = info_ptr->num_frames;
235 + *num_plays = info_ptr->num_plays;
243 +png_get_num_frames(png_structp png_ptr, png_infop info_ptr)
245 + png_debug(1, "in png_get_num_frames()");
247 + if (png_ptr != NULL && info_ptr != NULL)
248 + return (info_ptr->num_frames);
253 +png_get_num_plays(png_structp png_ptr, png_infop info_ptr)
255 + png_debug(1, "in png_get_num_plays()");
257 + if (png_ptr != NULL && info_ptr != NULL)
258 + return (info_ptr->num_plays);
263 +png_get_next_frame_fcTL(png_structp png_ptr, png_infop info_ptr,
264 + png_uint_32 *width, png_uint_32 *height,
265 + png_uint_32 *x_offset, png_uint_32 *y_offset,
266 + png_uint_16 *delay_num, png_uint_16 *delay_den,
267 + png_byte *dispose_op, png_byte *blend_op)
269 + png_debug1(1, "in %s retrieval function", "fcTL");
271 + if (png_ptr != NULL && info_ptr != NULL &&
272 + (info_ptr->valid & PNG_INFO_fcTL) &&
273 + width != NULL && height != NULL &&
274 + x_offset != NULL && x_offset != NULL &&
275 + delay_num != NULL && delay_den != NULL &&
276 + dispose_op != NULL && blend_op != NULL)
278 + *width = info_ptr->next_frame_width;
279 + *height = info_ptr->next_frame_height;
280 + *x_offset = info_ptr->next_frame_x_offset;
281 + *y_offset = info_ptr->next_frame_y_offset;
282 + *delay_num = info_ptr->next_frame_delay_num;
283 + *delay_den = info_ptr->next_frame_delay_den;
284 + *dispose_op = info_ptr->next_frame_dispose_op;
285 + *blend_op = info_ptr->next_frame_blend_op;
293 +png_get_next_frame_width(png_structp png_ptr, png_infop info_ptr)
295 + png_debug(1, "in png_get_next_frame_width()");
297 + if (png_ptr != NULL && info_ptr != NULL)
298 + return (info_ptr->next_frame_width);
303 +png_get_next_frame_height(png_structp png_ptr, png_infop info_ptr)
305 + png_debug(1, "in png_get_next_frame_height()");
307 + if (png_ptr != NULL && info_ptr != NULL)
308 + return (info_ptr->next_frame_height);
313 +png_get_next_frame_x_offset(png_structp png_ptr, png_infop info_ptr)
315 + png_debug(1, "in png_get_next_frame_x_offset()");
317 + if (png_ptr != NULL && info_ptr != NULL)
318 + return (info_ptr->next_frame_x_offset);
323 +png_get_next_frame_y_offset(png_structp png_ptr, png_infop info_ptr)
325 + png_debug(1, "in png_get_next_frame_y_offset()");
327 + if (png_ptr != NULL && info_ptr != NULL)
328 + return (info_ptr->next_frame_y_offset);
333 +png_get_next_frame_delay_num(png_structp png_ptr, png_infop info_ptr)
335 + png_debug(1, "in png_get_next_frame_delay_num()");
337 + if (png_ptr != NULL && info_ptr != NULL)
338 + return (info_ptr->next_frame_delay_num);
343 +png_get_next_frame_delay_den(png_structp png_ptr, png_infop info_ptr)
345 + png_debug(1, "in png_get_next_frame_delay_den()");
347 + if (png_ptr != NULL && info_ptr != NULL)
348 + return (info_ptr->next_frame_delay_den);
353 +png_get_next_frame_dispose_op(png_structp png_ptr, png_infop info_ptr)
355 + png_debug(1, "in png_get_next_frame_dispose_op()");
357 + if (png_ptr != NULL && info_ptr != NULL)
358 + return (info_ptr->next_frame_dispose_op);
363 +png_get_next_frame_blend_op(png_structp png_ptr, png_infop info_ptr)
365 + png_debug(1, "in png_get_next_frame_blend_op()");
367 + if (png_ptr != NULL && info_ptr != NULL)
368 + return (info_ptr->next_frame_blend_op);
373 +png_get_first_frame_is_hidden(png_structp png_ptr, png_infop info_ptr)
375 + png_debug(1, "in png_first_frame_is_hidden()");
377 + if (png_ptr != NULL)
378 + return (png_byte)(png_ptr->apng_flags & PNG_FIRST_FRAME_HIDDEN);
382 +#endif /* PNG_APNG_SUPPORTED */
384 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
386 png_get_unknown_chunks(png_structp png_ptr, png_infop info_ptr,
388 ===================================================================
395 +#ifdef PNG_APNG_SUPPORTED
401 #ifdef PNG_READ_SUPPORTED
402 /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
404 ===================================================================
407 @@ -1024,6 +1024,19 @@
408 png_fixed_point int_y_blue;
411 +#ifdef PNG_APNG_SUPPORTED
412 + png_uint_32 num_frames; /* including default image */
413 + png_uint_32 num_plays;
414 + png_uint_32 next_frame_width;
415 + png_uint_32 next_frame_height;
416 + png_uint_32 next_frame_x_offset;
417 + png_uint_32 next_frame_y_offset;
418 + png_uint_16 next_frame_delay_num;
419 + png_uint_16 next_frame_delay_den;
420 + png_byte next_frame_dispose_op;
421 + png_byte next_frame_blend_op;
426 typedef png_info FAR * png_infop;
427 @@ -1125,6 +1138,10 @@
428 #define PNG_INFO_sPLT 0x2000 /* ESR, 1.0.6 */
429 #define PNG_INFO_sCAL 0x4000 /* ESR, 1.0.6 */
430 #define PNG_INFO_IDAT 0x8000L /* ESR, 1.0.6 */
431 +#ifdef PNG_APNG_SUPPORTED
432 +#define PNG_INFO_acTL 0x10000L
433 +#define PNG_INFO_fcTL 0x20000L
436 /* This is used for the transformation routines, as some of them
437 * change these values for the row. It also should enable using
438 @@ -1165,6 +1182,10 @@
439 typedef void (PNGAPI *png_progressive_end_ptr) PNGARG((png_structp, png_infop));
440 typedef void (PNGAPI *png_progressive_row_ptr) PNGARG((png_structp, png_bytep,
442 +#ifdef PNG_APNG_SUPPORTED
443 +typedef void (PNGAPI *png_progressive_frame_ptr) PNGARG((png_structp,
448 #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
449 @@ -1499,6 +1520,39 @@
450 png_uint_32 user_height_max;
453 +#ifdef PNG_APNG_SUPPORTED
454 + png_uint_32 apng_flags;
455 + png_uint_32 next_seq_num; /* next fcTL/fdAT chunk sequence number */
456 + png_uint_32 first_frame_width;
457 + png_uint_32 first_frame_height;
459 +#ifdef PNG_READ_APNG_SUPPORTED
460 + png_uint_32 num_frames_read; /* incremented after all image data of */
461 + /* a frame is read */
462 +#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
463 + png_progressive_frame_ptr frame_info_fn; /* frame info read callback */
464 + png_progressive_frame_ptr frame_end_fn; /* frame data read callback */
468 +#ifdef PNG_WRITE_APNG_SUPPORTED
469 + png_uint_32 num_frames_to_write;
470 + png_uint_32 num_frames_written;
473 +/* For png_struct.apng_flags: */
474 +#define PNG_FIRST_FRAME_HIDDEN 0x0001
476 +/* dispose_op flags from inside fcTL */
477 +#define PNG_DISPOSE_OP_NONE 0x00
478 +#define PNG_DISPOSE_OP_BACKGROUND 0x01
479 +#define PNG_DISPOSE_OP_PREVIOUS 0x02
481 +/* blend_op flags from inside fcTL */
482 +#define PNG_BLEND_OP_SOURCE 0x00
483 +#define PNG_BLEND_OP_OVER 0x01
484 +#endif /* PNG_APNG_SUPPORTED */
486 /* New member added in libpng-1.0.25 and 1.2.17 */
487 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
488 /* Storage for unknown chunk that the library doesn't recognize. */
489 @@ -1832,6 +1886,18 @@
490 extern PNG_EXPORT(void,png_write_image) PNGARG((png_structp png_ptr,
493 +#ifdef PNG_WRITE_APNG_SUPPORTED
494 +extern PNG_EXPORT (void,png_write_frame_head) PNGARG((png_structp png_ptr,
495 + png_infop png_info, png_bytepp row_pointers,
496 + png_uint_32 width, png_uint_32 height,
497 + png_uint_32 x_offset, png_uint_32 y_offset,
498 + png_uint_16 delay_num, png_uint_16 delay_den, png_byte dispose_op,
499 + png_byte blend_op));
501 +extern PNG_EXPORT (void,png_write_frame_tail) PNGARG((png_structp png_ptr,
502 + png_infop png_info));
505 /* Writes the end of the PNG file. */
506 extern PNG_EXPORT(void,png_write_end) PNGARG((png_structp png_ptr,
507 png_infop info_ptr));
508 @@ -2085,6 +2151,11 @@
509 png_voidp progressive_ptr,
510 png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
511 png_progressive_end_ptr end_fn));
512 +#ifdef PNG_READ_APNG_SUPPORTED
513 +extern PNG_EXPORT(void,png_set_progressive_frame_fn) PNGARG((png_structp png_ptr,
514 + png_progressive_frame_ptr frame_info_fn,
515 + png_progressive_frame_ptr frame_end_fn));
518 /* Returns the user pointer associated with the push read functions */
519 extern PNG_EXPORT(png_voidp,png_get_progressive_ptr)
520 @@ -2525,6 +2596,59 @@
522 #endif /* PNG_sCAL_SUPPORTED || PNG_WRITE_sCAL_SUPPORTED */
524 +#ifdef PNG_APNG_SUPPORTED
525 +extern PNG_EXPORT(png_uint_32,png_get_acTL) PNGARG((png_structp png_ptr,
526 + png_infop info_ptr, png_uint_32 *num_frames, png_uint_32 *num_plays));
527 +extern PNG_EXPORT(png_uint_32,png_set_acTL) PNGARG((png_structp png_ptr,
528 + png_infop info_ptr, png_uint_32 num_frames, png_uint_32 num_plays));
529 +extern PNG_EXPORT(png_uint_32,png_get_num_frames) PNGARG((png_structp png_ptr,
530 + png_infop info_ptr));
531 +extern PNG_EXPORT(png_uint_32,png_get_num_plays)
532 + PNGARG((png_structp png_ptr, png_infop info_ptr));
534 +extern PNG_EXPORT(png_uint_32,png_get_next_frame_fcTL)
535 + PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 *width,
536 + png_uint_32 *height, png_uint_32 *x_offset, png_uint_32 *y_offset,
537 + png_uint_16 *delay_num, png_uint_16 *delay_den, png_byte *dispose_op,
538 + png_byte *blend_op));
539 +extern PNG_EXPORT(png_uint_32,png_set_next_frame_fcTL)
540 + PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 width,
541 + png_uint_32 height, png_uint_32 x_offset, png_uint_32 y_offset,
542 + png_uint_16 delay_num, png_uint_16 delay_den, png_byte dispose_op,
543 + png_byte blend_op));
544 +extern PNG_EXPORT(void,png_ensure_fcTL_is_valid)
545 + PNGARG((png_structp png_ptr,
546 + png_uint_32 width, png_uint_32 height,
547 + png_uint_32 x_offset, png_uint_32 y_offset,
548 + png_uint_16 delay_num, png_uint_16 delay_den,
549 + png_byte dispose_op, png_byte blend_op));
550 +extern PNG_EXPORT(png_uint_32,png_get_next_frame_width)
551 + PNGARG((png_structp png_ptr, png_infop info_ptr));
552 +extern PNG_EXPORT(png_uint_32,png_get_next_frame_height)
553 + PNGARG((png_structp png_ptr, png_infop info_ptr));
554 +extern PNG_EXPORT(png_uint_32,png_get_next_frame_x_offset)
555 + PNGARG((png_structp png_ptr, png_infop info_ptr));
556 +extern PNG_EXPORT(png_uint_32,png_get_next_frame_y_offset)
557 + PNGARG((png_structp png_ptr, png_infop info_ptr));
558 +extern PNG_EXPORT(png_uint_16,png_get_next_frame_delay_num)
559 + PNGARG((png_structp png_ptr, png_infop info_ptr));
560 +extern PNG_EXPORT(png_uint_16,png_get_next_frame_delay_den)
561 + PNGARG((png_structp png_ptr, png_infop info_ptr));
562 +extern PNG_EXPORT(png_byte,png_get_next_frame_dispose_op)
563 + PNGARG((png_structp png_ptr, png_infop info_ptr));
564 +extern PNG_EXPORT(png_byte,png_get_next_frame_blend_op)
565 + PNGARG((png_structp png_ptr, png_infop info_ptr));
566 +extern PNG_EXPORT(png_byte,png_get_first_frame_is_hidden)
567 + PNGARG((png_structp png_ptr, png_infop info_ptr));
568 +extern PNG_EXPORT(png_uint_32,png_set_first_frame_is_hidden)
569 + PNGARG((png_structp png_ptr, png_infop info_ptr, png_byte is_hidden));
570 +#endif /* PNG_APNG_SUPPORTED */
572 +#ifdef PNG_READ_APNG_SUPPORTED
573 +extern PNG_EXPORT(void,png_read_frame_head) PNGARG((png_structp png_ptr,
574 + png_infop info_ptr));
577 #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
578 /* Provide a list of chunks and how they are to be handled, if the built-in
579 handling or default unknown chunk handling is not desired. Any chunks not
580 @@ -2891,6 +3015,10 @@
581 #define PNG_BACKGROUND_IS_GRAY 0x800
582 #define PNG_HAVE_PNG_SIGNATURE 0x1000
583 #define PNG_HAVE_CHUNK_AFTER_IDAT 0x2000 /* Have another chunk after IDAT */
584 +#ifdef PNG_APNG_SUPPORTED
585 +#define PNG_HAVE_acTL 0x4000
586 +#define PNG_HAVE_fcTL 0x8000L
589 /* Flags for the transformations the PNG library does on the image data */
590 #define PNG_BGR 0x0001
591 @@ -3032,6 +3160,11 @@
592 #define PNG_tIME png_byte png_tIME[5] = {116, 73, 77, 69, '\0'}
593 #define PNG_tRNS png_byte png_tRNS[5] = {116, 82, 78, 83, '\0'}
594 #define PNG_zTXt png_byte png_zTXt[5] = {122, 84, 88, 116, '\0'}
595 +#ifdef PNG_APNG_SUPPORTED
596 +#define PNG_acTL png_byte png_acTL[5] = { 97, 99, 84, 76, '\0'}
597 +#define PNG_fcTL png_byte png_fcTL[5] = {102, 99, 84, 76, '\0'}
598 +#define PNG_fdAT png_byte png_fdAT[5] = {102, 100, 65, 84, '\0'}
601 #ifdef PNG_USE_GLOBAL_ARRAYS
602 PNG_EXPORT_VAR (png_byte FARDATA) png_IHDR[5];
603 @@ -3055,6 +3188,11 @@
604 PNG_EXPORT_VAR (png_byte FARDATA) png_tIME[5];
605 PNG_EXPORT_VAR (png_byte FARDATA) png_tRNS[5];
606 PNG_EXPORT_VAR (png_byte FARDATA) png_zTXt[5];
607 +#ifdef PNG_APNG_SUPPORTED
608 +PNG_EXPORT_VAR (png_byte FARDATA) png_acTL[5];
609 +PNG_EXPORT_VAR (png_byte FARDATA) png_fcTL[5];
610 +PNG_EXPORT_VAR (png_byte FARDATA) png_fdAT[5];
612 #endif /* PNG_USE_GLOBAL_ARRAYS */
614 #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
615 @@ -3330,6 +3468,17 @@
619 +#ifdef PNG_WRITE_APNG_SUPPORTED
620 +PNG_EXTERN void png_write_acTL PNGARG((png_structp png_ptr,
621 + png_uint_32 num_frames, png_uint_32 num_plays));
623 +PNG_EXTERN void png_write_fcTL PNGARG((png_structp png_ptr,
624 + png_uint_32 width, png_uint_32 height,
625 + png_uint_32 x_offset, png_uint_32 y_offset,
626 + png_uint_16 delay_num, png_uint_16 delay_den,
627 + png_byte dispose_op, png_byte blend_op));
630 /* Called when finished processing a row of data */
631 PNG_EXTERN void png_write_finish_row PNGARG((png_structp png_ptr));
633 @@ -3381,6 +3530,20 @@
634 PNG_EXTERN void png_read_transform_info PNGARG((png_structp png_ptr,
635 png_infop info_ptr));
637 +#ifdef PNG_READ_APNG_SUPPORTED
638 +/* Private, reset some things to become ready for reading next frame */
639 +PNG_EXTERN void png_read_reset PNGARG((png_structp png_ptr));
640 +PNG_EXTERN void png_read_reinit PNGARG((png_structp png_ptr,
641 + png_infop info_ptr));
642 +PNG_EXTERN void png_progressive_read_reset PNGARG((png_structp png_ptr));
644 +#ifdef PNG_WRITE_APNG_SUPPORTED
645 +/* Private, reset some things to become ready for writing next frame */
646 +PNG_EXTERN void png_write_reset PNGARG((png_structp png_ptr));
647 +PNG_EXTERN void png_write_reinit PNGARG((png_structp png_ptr,
648 + png_infop info_ptr, png_uint_32 width, png_uint_32 height));
651 /* These are the functions that do the transformations */
652 #if defined(PNG_READ_FILLER_SUPPORTED)
653 PNG_EXTERN void png_do_read_filler PNGARG((png_row_infop row_info,
654 @@ -3596,6 +3759,18 @@
655 png_uint_32 length));
658 +#ifdef PNG_READ_APNG_SUPPORTED
659 +PNG_EXTERN void png_handle_acTL PNGARG((png_structp png_ptr, png_infop info_ptr,
660 + png_uint_32 length));
661 +PNG_EXTERN void png_handle_fcTL PNGARG((png_structp png_ptr, png_infop info_ptr,
662 + png_uint_32 length));
663 +PNG_EXTERN void png_have_info PNGARG((png_structp png_ptr, png_infop info_ptr));
664 +PNG_EXTERN void png_handle_fdAT PNGARG((png_structp png_ptr, png_infop info_ptr,
665 + png_uint_32 length));
666 +PNG_EXTERN void png_ensure_sequence_number PNGARG((png_structp png_ptr,
667 + png_uint_32 length));
670 PNG_EXTERN void png_handle_unknown PNGARG((png_structp png_ptr,
671 png_infop info_ptr, png_uint_32 length));
674 ===================================================================
678 /* The rest of these check to see if the valid field has the appropriate
679 * flag set, and if it does, writes the chunk.
681 +#if defined(PNG_WRITE_APNG_SUPPORTED)
682 + if (info_ptr->valid & PNG_INFO_acTL)
683 + png_write_acTL(png_ptr, info_ptr->num_frames, info_ptr->num_plays);
685 #if defined(PNG_WRITE_gAMA_SUPPORTED)
686 if (info_ptr->valid & PNG_INFO_gAMA)
690 if (!(png_ptr->mode & PNG_HAVE_IDAT))
691 png_error(png_ptr, "No IDATs written into file");
692 +#if defined(PNG_WRITE_APNG_SUPPORTED)
693 + if (png_ptr->num_frames_written != png_ptr->num_frames_to_write)
694 + png_error(png_ptr, "Not enough frames written");
697 /* See if user wants us to write information chunks */
698 if (info_ptr != NULL)
699 @@ -1558,4 +1566,39 @@
704 +#if defined(PNG_WRITE_APNG_SUPPORTED)
706 +png_write_frame_head(png_structp png_ptr, png_infop info_ptr,
707 + png_bytepp row_pointers, png_uint_32 width, png_uint_32 height,
708 + png_uint_32 x_offset, png_uint_32 y_offset,
709 + png_uint_16 delay_num, png_uint_16 delay_den, png_byte dispose_op,
712 + png_debug(1, "in png_write_frame_head");
714 + /* there is a chance this has been set after png_write_info was called,
715 + * so it would be set but not written. is there a way to be sure? */
716 + if (!(info_ptr->valid & PNG_INFO_acTL))
717 + png_error(png_ptr, "png_write_frame_head(): acTL not set");
719 + png_write_reset(png_ptr);
721 + png_write_reinit(png_ptr, info_ptr, width, height);
723 + if ( !(png_ptr->num_frames_written == 0 &&
724 + (png_ptr->apng_flags & PNG_FIRST_FRAME_HIDDEN) ) )
725 + png_write_fcTL(png_ptr, width, height, x_offset, y_offset,
726 + delay_num, delay_den, dispose_op, blend_op);
730 +png_write_frame_tail(png_structp png_ptr, png_infop png_info)
732 + png_debug(1, "in png_write_frame_tail");
734 + png_ptr->num_frames_written++;
736 +#endif /* PNG_WRITE_APNG_SUPPORTED */
738 #endif /* PNG_WRITE_SUPPORTED */
740 ===================================================================
744 # define PNG_NO_READ_tEXt
745 # define PNG_NO_READ_zTXt
747 +#ifndef PNG_NO_READ_APNG
748 +# define PNG_READ_APNG_SUPPORTED
749 +# define PNG_APNG_SUPPORTED
751 #ifndef PNG_NO_READ_bKGD
752 # define PNG_READ_bKGD_SUPPORTED
753 # define PNG_bKGD_SUPPORTED
754 @@ -1098,6 +1102,14 @@
755 # define PNG_TEXT_SUPPORTED
758 +#ifndef PNG_NO_WRITE_APNG
759 +# ifndef PNG_WRITE_APNG_SUPPORTED
760 +# define PNG_WRITE_APNG_SUPPORTED
762 +# ifndef PNG_APNG_SUPPORTED
763 +# define PNG_APNG_SUPPORTED
767 #endif /* PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED */
770 ===================================================================
774 #if defined(PNG_READ_zTXt_SUPPORTED)
777 +#if defined(PNG_READ_APNG_SUPPORTED)
778 + PNG_CONST PNG_acTL;
779 + PNG_CONST PNG_fcTL;
780 + PNG_CONST PNG_fdAT;
782 #endif /* PNG_USE_LOCAL_ARRAYS */
783 /* First we make sure we have enough data for the 4 byte chunk name
784 * and the 4 byte chunk length before proceeding with decoding the
785 @@ -230,6 +235,103 @@
786 png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
789 +#if defined(PNG_READ_APNG_SUPPORTED)
790 + if (png_ptr->num_frames_read > 0 &&
791 + png_ptr->num_frames_read < info_ptr->num_frames)
793 + if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
795 + /* Discard trailing IDATs for the first frame */
796 + if (png_ptr->mode & PNG_HAVE_fcTL || png_ptr->num_frames_read > 1)
797 + png_error(png_ptr, "out of place IDAT");
799 + if (png_ptr->push_length + 4 > png_ptr->buffer_size)
801 + png_push_save_buffer(png_ptr);
804 + png_push_crc_skip(png_ptr, png_ptr->push_length);
805 + png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
808 + else if (!png_memcmp(png_ptr->chunk_name, png_fdAT, 4))
810 + if (png_ptr->buffer_size < 4)
812 + png_push_save_buffer(png_ptr);
815 + png_ensure_sequence_number(png_ptr, 4);
817 + if (!(png_ptr->mode & PNG_HAVE_fcTL))
819 + /* Discard trailing fdATs for frames other than the first */
820 + if (png_ptr->num_frames_read < 2)
821 + png_error(png_ptr, "out of place fdAT");
823 + if (png_ptr->push_length + 4 > png_ptr->buffer_size)
825 + png_push_save_buffer(png_ptr);
828 + png_push_crc_skip(png_ptr, png_ptr->push_length);
829 + png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
834 + /* frame data follows */
835 + png_ptr->idat_size = png_ptr->push_length - 4;
836 + png_ptr->mode |= PNG_HAVE_IDAT;
837 + png_ptr->process_mode = PNG_READ_IDAT_MODE;
842 + else if(!png_memcmp(png_ptr->chunk_name, png_fcTL, 4))
844 + if (png_ptr->push_length + 4 > png_ptr->buffer_size)
846 + png_push_save_buffer(png_ptr);
850 + png_read_reset(png_ptr);
851 + png_ptr->mode &= ~PNG_HAVE_fcTL;
853 + png_handle_fcTL(png_ptr, info_ptr, png_ptr->push_length);
855 + if (!(png_ptr->mode & PNG_HAVE_fcTL))
856 + png_error(png_ptr, "missing required fcTL chunk");
858 + png_read_reinit(png_ptr, info_ptr);
859 + png_progressive_read_reset(png_ptr);
861 + if (png_ptr->frame_info_fn != NULL)
862 + (*(png_ptr->frame_info_fn))(png_ptr, png_ptr->num_frames_read);
864 + png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
870 + if (png_ptr->push_length + 4 > png_ptr->buffer_size)
872 + png_push_save_buffer(png_ptr);
875 + png_warning(png_ptr, "Skipped (ignored) a chunk "
876 + "between APNG chunks");
877 + png_push_crc_skip(png_ptr, png_ptr->push_length);
878 + png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
884 +#endif /* PNG_READ_APNG_SUPPORTED */
886 if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
887 if (png_ptr->mode & PNG_AFTER_IDAT)
888 png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
890 png_error(png_ptr, "Too many IDAT's found");
893 +#if defined(PNG_READ_APNG_SUPPORTED)
894 + png_have_info(png_ptr, info_ptr);
896 png_ptr->idat_size = png_ptr->push_length;
897 png_ptr->mode |= PNG_HAVE_IDAT;
898 png_ptr->process_mode = PNG_READ_IDAT_MODE;
903 +#if defined(PNG_READ_APNG_SUPPORTED)
904 + else if (!png_memcmp(png_ptr->chunk_name, png_acTL, 4))
906 + if (png_ptr->push_length + 4 > png_ptr->buffer_size)
908 + png_push_save_buffer(png_ptr);
912 + png_handle_acTL(png_ptr, info_ptr, png_ptr->push_length);
914 + else if (!png_memcmp(png_ptr->chunk_name, png_fcTL, 4))
916 + if (png_ptr->push_length + 4 > png_ptr->buffer_size)
918 + png_push_save_buffer(png_ptr);
922 + png_handle_fcTL(png_ptr, info_ptr, png_ptr->push_length);
924 + else if (!png_memcmp(png_ptr->chunk_name, png_fdAT, 4))
926 + if (png_ptr->push_length + 4 > png_ptr->buffer_size)
928 + png_push_save_buffer(png_ptr);
932 + png_handle_fdAT(png_ptr, info_ptr, png_ptr->push_length);
934 +#endif /* PNG_READ_APNG_SUPPORTED */
937 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
938 @@ -729,13 +866,17 @@
939 png_push_read_IDAT(png_structp png_ptr)
941 #ifdef PNG_USE_LOCAL_ARRAYS
942 - PNG_CONST PNG_IDAT;
944 +#if defined(PNG_READ_APNG_SUPPORTED)
949 if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
951 png_byte chunk_length[4];
953 - if (png_ptr->buffer_size < 8)
954 + if (png_ptr->buffer_size < 12)
956 png_push_save_buffer(png_ptr);
958 @@ -747,15 +888,62 @@
959 png_crc_read(png_ptr, png_ptr->chunk_name, 4);
960 png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
962 - if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
963 +#if defined(PNG_READ_APNG_SUPPORTED)
964 + if (png_memcmp(png_ptr->chunk_name, (png_bytep)png_fdAT, 4)
965 + && png_ptr->num_frames_read > 0)
967 + if (png_ptr->flags & PNG_FLAG_ZLIB_FINISHED)
969 + png_ptr->process_mode = PNG_READ_CHUNK_MODE;
970 + if (png_ptr->frame_end_fn != NULL)
971 + (*(png_ptr->frame_end_fn))(png_ptr, png_ptr->num_frames_read);
972 + png_ptr->num_frames_read++;
977 + if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
978 + png_error(png_ptr, "Not enough image data");
979 + if (png_ptr->push_length + 4 > png_ptr->buffer_size)
981 + png_push_save_buffer(png_ptr);
984 + png_warning(png_ptr, "Skipping (ignoring) a chunk between "
986 + png_crc_finish(png_ptr, png_ptr->push_length);
987 + png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
993 + if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4)
994 +#if defined(PNG_READ_APNG_SUPPORTED)
995 + && (png_ptr->num_frames_read == 0)
999 png_ptr->process_mode = PNG_READ_CHUNK_MODE;
1000 if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
1001 png_error(png_ptr, "Not enough compressed data");
1002 +#if defined(PNG_READ_APNG_SUPPORTED)
1003 + if (png_ptr->frame_end_fn != NULL)
1004 + (*(png_ptr->frame_end_fn))(png_ptr, png_ptr->num_frames_read);
1005 + png_ptr->num_frames_read++;
1010 png_ptr->idat_size = png_ptr->push_length;
1012 +#if defined(PNG_READ_APNG_SUPPORTED)
1013 + if (png_ptr->num_frames_read > 0)
1015 + png_ensure_sequence_number(png_ptr, 4);
1016 + png_ptr->idat_size -= 4;
1020 if (png_ptr->idat_size && png_ptr->save_buffer_size)
1022 @@ -1716,6 +1904,17 @@
1023 png_set_read_fn(png_ptr, progressive_ptr, png_push_fill_buffer);
1026 +#if defined(PNG_READ_APNG_SUPPORTED)
1028 +png_set_progressive_frame_fn(png_structp png_ptr,
1029 + png_progressive_frame_ptr frame_info_fn,
1030 + png_progressive_frame_ptr frame_end_fn)
1032 + png_ptr->frame_info_fn = frame_info_fn;
1033 + png_ptr->frame_end_fn = frame_end_fn;
1038 png_get_progressive_ptr(png_structp png_ptr)
1041 ===================================================================
1044 @@ -329,6 +329,11 @@
1045 info_ptr->rowbytes = (png_size_t)0;
1047 info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, width);
1049 +#ifdef PNG_APNG_SUPPORTED
1050 + /* for non-animated png. this may be overritten from an acTL chunk later */
1051 + info_ptr->num_frames = 1;
1055 #if defined(PNG_oFFs_SUPPORTED)
1056 @@ -1029,6 +1034,142 @@
1058 #endif /* PNG_sPLT_SUPPORTED */
1060 +#ifdef PNG_APNG_SUPPORTED
1062 +png_set_acTL(png_structp png_ptr, png_infop info_ptr,
1063 + png_uint_32 num_frames, png_uint_32 num_plays)
1065 + png_debug1(1, "in %s storage function", "acTL");
1067 + if (png_ptr == NULL || info_ptr == NULL)
1069 + png_warning(png_ptr,
1070 + "Call to png_set_acTL() with NULL png_ptr "
1071 + "or info_ptr ignored");
1074 + if (num_frames == 0)
1076 + png_warning(png_ptr,
1077 + "Ignoring attempt to set acTL with num_frames zero");
1080 + if (num_frames > PNG_UINT_31_MAX)
1082 + png_warning(png_ptr,
1083 + "Ignoring attempt to set acTL with num_frames > 2^31-1");
1086 + if (num_plays > PNG_UINT_31_MAX)
1088 + png_warning(png_ptr,
1089 + "Ignoring attempt to set acTL with num_plays "
1094 + info_ptr->num_frames = num_frames;
1095 + info_ptr->num_plays = num_plays;
1097 + info_ptr->valid |= PNG_INFO_acTL;
1102 +/* delay_num and delay_den can hold any 16-bit values including zero */
1104 +png_set_next_frame_fcTL(png_structp png_ptr, png_infop info_ptr,
1105 + png_uint_32 width, png_uint_32 height,
1106 + png_uint_32 x_offset, png_uint_32 y_offset,
1107 + png_uint_16 delay_num, png_uint_16 delay_den,
1108 + png_byte dispose_op, png_byte blend_op)
1110 + png_debug1(1, "in %s storage function", "fcTL");
1112 + if (png_ptr == NULL || info_ptr == NULL)
1114 + png_warning(png_ptr,
1115 + "Call to png_set_fcTL() with NULL png_ptr or info_ptr "
1120 + png_ensure_fcTL_is_valid(png_ptr, width, height, x_offset, y_offset,
1121 + delay_num, delay_den, dispose_op, blend_op);
1123 + if (blend_op == PNG_BLEND_OP_OVER)
1125 + if (!(png_ptr->color_type & PNG_COLOR_MASK_ALPHA) &&
1126 + !(png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)))
1128 + png_warning(png_ptr, "PNG_BLEND_OP_OVER is meaningless "
1129 + "and wasteful for opaque images, ignored");
1130 + blend_op = PNG_BLEND_OP_SOURCE;
1134 + info_ptr->next_frame_width = width;
1135 + info_ptr->next_frame_height = height;
1136 + info_ptr->next_frame_x_offset = x_offset;
1137 + info_ptr->next_frame_y_offset = y_offset;
1138 + info_ptr->next_frame_delay_num = delay_num;
1139 + info_ptr->next_frame_delay_den = delay_den;
1140 + info_ptr->next_frame_dispose_op = dispose_op;
1141 + info_ptr->next_frame_blend_op = blend_op;
1143 + info_ptr->valid |= PNG_INFO_fcTL;
1149 +png_ensure_fcTL_is_valid(png_structp png_ptr,
1150 + png_uint_32 width, png_uint_32 height,
1151 + png_uint_32 x_offset, png_uint_32 y_offset,
1152 + png_uint_16 delay_num, png_uint_16 delay_den,
1153 + png_byte dispose_op, png_byte blend_op)
1155 + if (width + x_offset > png_ptr->first_frame_width ||
1156 + height + y_offset > png_ptr->first_frame_height)
1157 + png_error(png_ptr, "dimensions of a frame are greater than"
1158 + "the ones in IHDR");
1159 + if (width > PNG_UINT_31_MAX)
1160 + png_error(png_ptr, "invalid width in fcTL (> 2^31-1)");
1161 + if (height > PNG_UINT_31_MAX)
1162 + png_error(png_ptr, "invalid height in fcTL (> 2^31-1)");
1163 + if (x_offset > PNG_UINT_31_MAX)
1164 + png_error(png_ptr, "invalid x_offset in fcTL (> 2^31-1)");
1165 + if (y_offset > PNG_UINT_31_MAX)
1166 + png_error(png_ptr, "invalid y_offset in fcTL (> 2^31-1)");
1168 + if (dispose_op != PNG_DISPOSE_OP_NONE &&
1169 + dispose_op != PNG_DISPOSE_OP_BACKGROUND &&
1170 + dispose_op != PNG_DISPOSE_OP_PREVIOUS)
1171 + png_error(png_ptr, "invalid dispose_op in fcTL");
1173 + if (blend_op != PNG_BLEND_OP_SOURCE &&
1174 + blend_op != PNG_BLEND_OP_OVER)
1175 + png_error(png_ptr, "invalid blend_op in fcTL");
1179 +png_set_first_frame_is_hidden(png_structp png_ptr, png_infop info_ptr,
1180 + png_byte is_hidden)
1182 + png_debug(1, "in png_first_frame_is_hidden()");
1184 + if (png_ptr == NULL)
1188 + png_ptr->apng_flags |= PNG_FIRST_FRAME_HIDDEN;
1190 + png_ptr->apng_flags &= ~PNG_FIRST_FRAME_HIDDEN;
1194 +#endif /* PNG_APNG_SUPPORTED */
1196 #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
1198 png_set_unknown_chunks(png_structp png_ptr,
1200 ===================================================================
1203 @@ -424,6 +424,11 @@
1204 filter_type = buf[11];
1205 interlace_type = buf[12];
1207 +#if defined(PNG_READ_APNG_SUPPORTED)
1208 + png_ptr->first_frame_width = width;
1209 + png_ptr->first_frame_height = height;
1212 /* Set internal variables */
1213 png_ptr->width = width;
1214 png_ptr->height = height;
1215 @@ -2230,6 +2235,168 @@
1219 +#if defined(PNG_READ_APNG_SUPPORTED)
1221 +png_handle_acTL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
1224 + png_uint_32 num_frames;
1225 + png_uint_32 num_plays;
1226 + png_uint_32 didSet;
1228 + png_debug(1, "in png_handle_acTL");
1230 + if (!(png_ptr->mode & PNG_HAVE_IHDR))
1232 + png_error(png_ptr, "Missing IHDR before acTL");
1234 + else if (png_ptr->mode & PNG_HAVE_IDAT)
1236 + png_warning(png_ptr, "Invalid acTL after IDAT skipped");
1237 + png_crc_finish(png_ptr, length);
1240 + else if (png_ptr->mode & PNG_HAVE_acTL)
1242 + png_warning(png_ptr, "Duplicate acTL skipped");
1243 + png_crc_finish(png_ptr, length);
1246 + else if (length != 8)
1248 + png_warning(png_ptr, "acTL with invalid length skipped");
1249 + png_crc_finish(png_ptr, length);
1253 + png_crc_read(png_ptr, data, 8);
1254 + png_crc_finish(png_ptr, 0);
1256 + num_frames = png_get_uint_31(png_ptr, data);
1257 + num_plays = png_get_uint_31(png_ptr, data + 4);
1259 + /* the set function will do error checking on num_frames */
1260 + didSet = png_set_acTL(png_ptr, info_ptr, num_frames, num_plays);
1262 + png_ptr->mode |= PNG_HAVE_acTL;
1266 +png_handle_fcTL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
1268 + png_byte data[22];
1269 + png_uint_32 width;
1270 + png_uint_32 height;
1271 + png_uint_32 x_offset;
1272 + png_uint_32 y_offset;
1273 + png_uint_16 delay_num;
1274 + png_uint_16 delay_den;
1275 + png_byte dispose_op;
1276 + png_byte blend_op;
1278 + png_debug(1, "in png_handle_fcTL");
1280 + if (!(png_ptr->mode & PNG_HAVE_IHDR))
1282 + png_error(png_ptr, "Missing IHDR before fcTL");
1284 + else if (png_ptr->mode & PNG_HAVE_IDAT)
1286 + /* for any frames other then the first this message may be misleading,
1287 + * but correct. PNG_HAVE_IDAT is unset before the frame head is read
1288 + * i can't think of a better message */
1289 + png_warning(png_ptr, "Invalid fcTL after IDAT skipped");
1290 + png_crc_finish(png_ptr, length);
1293 + else if (png_ptr->mode & PNG_HAVE_fcTL)
1295 + png_warning(png_ptr, "Duplicate fcTL within one frame skipped");
1296 + png_crc_finish(png_ptr, length);
1299 + else if (length != 26)
1301 + png_warning(png_ptr, "fcTL with invalid length skipped");
1302 + png_crc_finish(png_ptr, length);
1306 + png_ensure_sequence_number(png_ptr, length);
1308 + png_crc_read(png_ptr, data, 22);
1309 + png_crc_finish(png_ptr, 0);
1311 + width = png_get_uint_31(png_ptr, data);
1312 + height = png_get_uint_31(png_ptr, data + 4);
1313 + x_offset = png_get_uint_31(png_ptr, data + 8);
1314 + y_offset = png_get_uint_31(png_ptr, data + 12);
1315 + delay_num = png_get_uint_16(data + 16);
1316 + delay_den = png_get_uint_16(data + 18);
1317 + dispose_op = data[20];
1318 + blend_op = data[21];
1320 + if (png_ptr->num_frames_read == 0 && (x_offset != 0 || y_offset != 0))
1321 + png_error(png_ptr, "fcTL for the first frame must have zero offset");
1322 + if (png_ptr->num_frames_read == 0 &&
1323 + (width != info_ptr->width || height != info_ptr->height))
1324 + png_error(png_ptr, "size in first frame's fcTL must match "
1325 + "the size in IHDR");
1327 + /* the set function will do more error checking */
1328 + png_set_next_frame_fcTL(png_ptr, info_ptr, width, height,
1329 + x_offset, y_offset, delay_num, delay_den,
1330 + dispose_op, blend_op);
1332 + png_read_reinit(png_ptr, info_ptr);
1334 + png_ptr->mode |= PNG_HAVE_fcTL;
1338 +png_have_info(png_structp png_ptr, png_infop info_ptr)
1340 + if((info_ptr->valid & PNG_INFO_acTL) && !(info_ptr->valid & PNG_INFO_fcTL))
1342 + png_ptr->apng_flags |= PNG_FIRST_FRAME_HIDDEN;
1343 + info_ptr->num_frames++;
1348 +png_handle_fdAT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
1350 + png_ensure_sequence_number(png_ptr, length);
1352 + /* This function is only called from png_read_end(), png_read_info(),
1353 + * and png_push_read_chunk() which means that:
1354 + * - the user doesn't want to read this frame
1355 + * - or this is an out-of-place fdAT
1356 + * in either case it is safe to ignore the chunk with a warning */
1357 + png_warning(png_ptr, "ignoring fdAT chunk");
1358 + png_crc_finish(png_ptr, length - 4);
1362 +png_ensure_sequence_number(png_structp png_ptr, png_uint_32 length)
1365 + png_uint_32 sequence_number;
1368 + png_error(png_ptr, "invalid fcTL or fdAT chunk found");
1370 + png_crc_read(png_ptr, data, 4);
1371 + sequence_number = png_get_uint_31(png_ptr, data);
1373 + if (sequence_number != png_ptr->next_seq_num)
1374 + png_error(png_ptr, "fcTL or fdAT chunk with out-of-order sequence "
1377 + png_ptr->next_seq_num++;
1379 +#endif /* PNG_READ_APNG_SUPPORTED */
1381 /* This function is called when we haven't found a handler for a
1382 chunk. If there isn't a problem with the chunk itself (ie bad
1383 chunk name, CRC, or a critical chunk), the chunk is silently ignored
1384 @@ -3249,4 +3416,84 @@
1386 png_ptr->flags |= PNG_FLAG_ROW_INIT;
1389 +#if defined(PNG_READ_APNG_SUPPORTED)
1390 +/* This function is to be called after the main IDAT set has been read and
1391 + * before a new IDAT is read. It resets some parts of png_ptr
1392 + * to make them usable by the read functions again */
1394 +png_read_reset(png_structp png_ptr)
1396 + png_ptr->mode &= ~PNG_HAVE_IDAT;
1397 + png_ptr->mode &= ~PNG_AFTER_IDAT;
1398 + png_ptr->row_number = 0;
1399 + png_ptr->pass = 0;
1400 + png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
1404 +png_read_reinit(png_structp png_ptr, png_infop info_ptr)
1406 + png_ptr->width = info_ptr->next_frame_width;
1407 + png_ptr->height = info_ptr->next_frame_height;
1408 + png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->width);
1409 + if (png_ptr->prev_row)
1410 + png_memset_check(png_ptr, png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
1413 +/* same as png_read_reset() but for the progressive reader */
1415 +png_progressive_read_reset(png_structp png_ptr)
1417 +#ifdef PNG_USE_LOCAL_ARRAYS
1418 + /* start of interlace block */
1419 + const int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
1421 + /* offset to next interlace block */
1422 + const int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
1424 + /* start of interlace block in the y direction */
1425 + const int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
1427 + /* offset to next interlace block in the y direction */
1428 + const int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
1430 + png_uint_32 row_bytes;
1432 + if (png_ptr->interlaced)
1434 + if (!(png_ptr->transformations & PNG_INTERLACE))
1435 + png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
1436 + png_pass_ystart[0]) / png_pass_yinc[0];
1438 + png_ptr->num_rows = png_ptr->height;
1440 + png_ptr->iwidth = (png_ptr->width +
1441 + png_pass_inc[png_ptr->pass] - 1 -
1442 + png_pass_start[png_ptr->pass]) /
1443 + png_pass_inc[png_ptr->pass];
1445 + row_bytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->iwidth) + 1;
1447 + png_ptr->irowbytes = (png_size_t)row_bytes;
1448 + if((png_uint_32)png_ptr->irowbytes != row_bytes)
1449 + png_error(png_ptr, "png_progressive_read_reset(): Rowbytes "
1454 + png_ptr->num_rows = png_ptr->height;
1455 + png_ptr->iwidth = png_ptr->width;
1456 + png_ptr->irowbytes = png_ptr->rowbytes + 1;
1459 + png_ptr->flags &= ~PNG_FLAG_ZLIB_FINISHED;
1460 + if (inflateReset(&(png_ptr->zstream)) != Z_OK)
1461 + png_error(png_ptr, "inflateReset failed");
1462 + png_ptr->zstream.avail_in = 0;
1463 + png_ptr->zstream.next_in = 0;
1464 + png_ptr->zstream.next_out = png_ptr->row_buf;
1465 + png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
1467 +#endif /* PNG_READ_APNG_SUPPORTED */
1468 #endif /* PNG_READ_SUPPORTED */
1470 ===================================================================
1473 @@ -513,6 +513,11 @@
1474 /* Write the chunk */
1475 png_write_chunk(png_ptr, (png_bytep)png_IHDR, buf, (png_size_t)13);
1477 +#if defined(PNG_WRITE_APNG_SUPPORTED)
1478 + png_ptr->first_frame_width = width;
1479 + png_ptr->first_frame_height = height;
1482 /* Initialize zlib with PNG info */
1483 png_ptr->zstream.zalloc = png_zalloc;
1484 png_ptr->zstream.zfree = png_zfree;
1487 #ifdef PNG_USE_LOCAL_ARRAYS
1489 +#if defined(PNG_WRITE_APNG_SUPPORTED)
1494 png_debug(1, "in png_write_IDAT");
1495 @@ -681,7 +689,28 @@
1496 "Invalid zlib compression method or flags in IDAT");
1499 +#if defined(PNG_WRITE_APNG_SUPPORTED)
1500 + if(png_ptr->num_frames_written == 0)
1502 png_write_chunk(png_ptr, (png_bytep)png_IDAT, data, length);
1503 +#if defined(PNG_WRITE_APNG_SUPPORTED)
1508 + png_write_chunk_start(png_ptr, (png_bytep)png_fdAT, 4 + length);
1510 + png_save_uint_32(buf, png_ptr->next_seq_num);
1511 + png_write_chunk_data(png_ptr, buf, 4);
1513 + png_write_chunk_data(png_ptr, data, length);
1515 + png_write_chunk_end(png_ptr);
1517 + png_ptr->next_seq_num++;
1521 png_ptr->mode |= PNG_HAVE_IDAT;
1524 @@ -1748,6 +1777,70 @@
1528 +#if defined(PNG_WRITE_APNG_SUPPORTED)
1530 +png_write_acTL(png_structp png_ptr,
1531 + png_uint_32 num_frames, png_uint_32 num_plays)
1533 +#ifdef PNG_USE_LOCAL_ARRAYS
1536 + png_byte data[16];
1538 + png_debug(1, "in png_write_acTL");
1540 + png_ptr->num_frames_to_write = num_frames;
1542 + if (png_ptr->apng_flags & PNG_FIRST_FRAME_HIDDEN)
1545 + png_save_uint_32(data, num_frames);
1546 + png_save_uint_32(data + 4, num_plays);
1548 + png_write_chunk(png_ptr, (png_bytep)png_acTL, data, (png_size_t)8);
1552 +png_write_fcTL(png_structp png_ptr, png_uint_32 width, png_uint_32 height,
1553 + png_uint_32 x_offset, png_uint_32 y_offset,
1554 + png_uint_16 delay_num, png_uint_16 delay_den, png_byte dispose_op,
1555 + png_byte blend_op)
1557 +#ifdef PNG_USE_LOCAL_ARRAYS
1560 + png_byte data[26];
1562 + png_debug(1, "in png_write_fcTL");
1564 + if (png_ptr->num_frames_written == 0 && (x_offset != 0 || y_offset != 0))
1565 + png_error(png_ptr, "x and/or y offset for the first frame aren't 0");
1566 + if (png_ptr->num_frames_written == 0 &&
1567 + (width != png_ptr->first_frame_width ||
1568 + height != png_ptr->first_frame_height))
1569 + png_error(png_ptr, "width and/or height in the first frame's fcTL "
1570 + "don't match the ones in IHDR");
1572 + /* more error checking */
1573 + png_ensure_fcTL_is_valid(png_ptr, width, height, x_offset, y_offset,
1574 + delay_num, delay_den, dispose_op, blend_op);
1576 + png_save_uint_32(data, png_ptr->next_seq_num);
1577 + png_save_uint_32(data + 4, width);
1578 + png_save_uint_32(data + 8, height);
1579 + png_save_uint_32(data + 12, x_offset);
1580 + png_save_uint_32(data + 16, y_offset);
1581 + png_save_uint_16(data + 20, delay_num);
1582 + png_save_uint_16(data + 22, delay_den);
1583 + data[24] = dispose_op;
1584 + data[25] = blend_op;
1586 + png_write_chunk(png_ptr, (png_bytep)png_fcTL, data, (png_size_t)26);
1588 + png_ptr->next_seq_num++;
1590 +#endif /* PNG_WRITE_APNG_SUPPORTED */
1592 /* Initializes the row writing capability of libpng */
1594 png_write_start_row(png_structp png_ptr)
1595 @@ -2157,6 +2250,14 @@
1597 png_debug(1, "in png_write_find_filter");
1599 +#ifndef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
1600 + if (png_ptr->row_number == 0 && filter_to_do == PNG_ALL_FILTERS)
1602 + /* These use previous row */
1603 + filter_to_do &= ~(PNG_FILTER_UP | PNG_FILTER_AVG | PNG_FILTER_PAETH);
1607 /* Find out how many bytes offset each pixel is */
1608 bpp = (row_info->pixel_depth + 7) >> 3;
1610 @@ -2822,4 +2923,39 @@
1615 +#if defined(PNG_WRITE_APNG_SUPPORTED)
1617 +png_write_reset(png_structp png_ptr)
1619 + png_ptr->row_number = 0;
1620 + png_ptr->pass = 0;
1621 + png_ptr->mode &= ~PNG_HAVE_IDAT;
1625 +png_write_reinit(png_structp png_ptr, png_infop info_ptr,
1626 + png_uint_32 width, png_uint_32 height)
1628 + if (png_ptr->num_frames_written == 0 &&
1629 + (width != png_ptr->first_frame_width ||
1630 + height != png_ptr->first_frame_height))
1631 + png_error(png_ptr, "width and/or height in the first frame's fcTL "
1632 + "don't match the ones in IHDR");
1633 + if (width > png_ptr->first_frame_width ||
1634 + height > png_ptr->first_frame_height)
1635 + png_error(png_ptr, "width and/or height for a frame greater than"
1636 + "the ones in IHDR");
1638 + png_set_IHDR(png_ptr, info_ptr, width, height,
1639 + info_ptr->bit_depth, info_ptr->color_type,
1640 + info_ptr->interlace_type, info_ptr->compression_type,
1641 + info_ptr->filter_type);
1643 + png_ptr->width = width;
1644 + png_ptr->height = height;
1645 + png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, width);
1646 + png_ptr->usr_width = png_ptr->width;
1649 #endif /* PNG_WRITE_SUPPORTED */
1651 ===================================================================
1654 @@ -1321,7 +1321,7 @@
1655 * pixels. This check added to libpng-1.2.19
1657 #if (PNG_WARN_UNINITIALIZED_ROW==1)
1658 - png_error(png_ptr, "Uninitialized row");
1659 + png_warning(png_ptr, "Uninitialized row");
1661 png_warning(png_ptr, "Uninitialized row");