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 +#if defined(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 ===================================================================
399 #ifdef PNG_READ_SUPPORTED
400 /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
402 ===================================================================
405 @@ -1016,6 +1016,19 @@
406 png_fixed_point int_y_blue;
409 +#if defined(PNG_APNG_SUPPORTED)
410 + png_uint_32 num_frames; /* including default image */
411 + png_uint_32 num_plays;
412 + png_uint_32 next_frame_width;
413 + png_uint_32 next_frame_height;
414 + png_uint_32 next_frame_x_offset;
415 + png_uint_32 next_frame_y_offset;
416 + png_uint_16 next_frame_delay_num;
417 + png_uint_16 next_frame_delay_den;
418 + png_byte next_frame_dispose_op;
419 + png_byte next_frame_blend_op;
424 typedef png_info FAR * png_infop;
425 @@ -1117,6 +1130,8 @@
426 #define PNG_INFO_sPLT 0x2000 /* ESR, 1.0.6 */
427 #define PNG_INFO_sCAL 0x4000 /* ESR, 1.0.6 */
428 #define PNG_INFO_IDAT 0x8000L /* ESR, 1.0.6 */
429 +#define PNG_INFO_acTL 0x10000L
430 +#define PNG_INFO_fcTL 0x20000L
432 /* This is used for the transformation routines, as some of them
433 * change these values for the row. It also should enable using
434 @@ -1157,6 +1172,10 @@
435 typedef void (PNGAPI *png_progressive_end_ptr) PNGARG((png_structp, png_infop));
436 typedef void (PNGAPI *png_progressive_row_ptr) PNGARG((png_structp, png_bytep,
438 +#if defined(PNG_APNG_SUPPORTED)
439 +typedef void (PNGAPI *png_progressive_frame_ptr) PNGARG((png_structp,
444 #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
445 @@ -1491,6 +1510,39 @@
446 png_uint_32 user_height_max;
449 +#if defined(PNG_APNG_SUPPORTED)
450 + png_uint_32 apng_flags;
451 + png_uint_32 next_seq_num; /* next fcTL/fdAT chunk sequence number */
452 + png_uint_32 first_frame_width;
453 + png_uint_32 first_frame_height;
455 +#if defined(PNG_READ_APNG_SUPPORTED)
456 + png_uint_32 num_frames_read; /* incremented after all image data of */
457 + /* a frame is read */
458 +#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
459 + png_progressive_frame_ptr frame_info_fn; /* frame info read callback */
460 + png_progressive_frame_ptr frame_end_fn; /* frame data read callback */
464 +#if defined(PNG_WRITE_APNG_SUPPORTED)
465 + png_uint_32 num_frames_to_write;
466 + png_uint_32 num_frames_written;
470 +/* For png_struct.apng_flags: */
471 +#define PNG_FIRST_FRAME_HIDDEN 0x0001
473 +/* dispose_op flags from inside fcTL */
474 +#define PNG_DISPOSE_OP_NONE 0x00
475 +#define PNG_DISPOSE_OP_BACKGROUND 0x01
476 +#define PNG_DISPOSE_OP_PREVIOUS 0x02
478 +/* blend_op flags from inside fcTL */
479 +#define PNG_BLEND_OP_SOURCE 0x00
480 +#define PNG_BLEND_OP_OVER 0x01
482 /* New member added in libpng-1.0.25 and 1.2.17 */
483 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
484 /* Storage for unknown chunk that the library doesn't recognize. */
485 @@ -1824,6 +1876,18 @@
486 extern PNG_EXPORT(void,png_write_image) PNGARG((png_structp png_ptr,
489 +#if defined(PNG_WRITE_APNG_SUPPORTED)
490 +extern PNG_EXPORT (void,png_write_frame_head) PNGARG((png_structp png_ptr,
491 + png_infop png_info, png_bytepp row_pointers,
492 + png_uint_32 width, png_uint_32 height,
493 + png_uint_32 x_offset, png_uint_32 y_offset,
494 + png_uint_16 delay_num, png_uint_16 delay_den, png_byte dispose_op,
495 + png_byte blend_op));
497 +extern PNG_EXPORT (void,png_write_frame_tail) PNGARG((png_structp png_ptr,
498 + png_infop png_info));
501 /* Writes the end of the PNG file. */
502 extern PNG_EXPORT(void,png_write_end) PNGARG((png_structp png_ptr,
503 png_infop info_ptr));
504 @@ -2077,6 +2141,11 @@
505 png_voidp progressive_ptr,
506 png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
507 png_progressive_end_ptr end_fn));
508 +#if defined(PNG_READ_APNG_SUPPORTED)
509 +extern PNG_EXPORT(void,png_set_progressive_frame_fn) PNGARG((png_structp png_ptr,
510 + png_progressive_frame_ptr frame_info_fn,
511 + png_progressive_frame_ptr frame_end_fn));
514 /* Returns the user pointer associated with the push read functions */
515 extern PNG_EXPORT(png_voidp,png_get_progressive_ptr)
516 @@ -2517,6 +2586,59 @@
518 #endif /* PNG_sCAL_SUPPORTED || PNG_WRITE_sCAL_SUPPORTED */
520 +#if defined(PNG_APNG_SUPPORTED)
521 +extern PNG_EXPORT(png_uint_32,png_get_acTL) PNGARG((png_structp png_ptr,
522 + png_infop info_ptr, png_uint_32 *num_frames, png_uint_32 *num_plays));
523 +extern PNG_EXPORT(png_uint_32,png_set_acTL) PNGARG((png_structp png_ptr,
524 + png_infop info_ptr, png_uint_32 num_frames, png_uint_32 num_plays));
525 +extern PNG_EXPORT(png_uint_32,png_get_num_frames) PNGARG((png_structp png_ptr,
526 + png_infop info_ptr));
527 +extern PNG_EXPORT(png_uint_32,png_get_num_plays)
528 + PNGARG((png_structp png_ptr, png_infop info_ptr));
530 +extern PNG_EXPORT(png_uint_32,png_get_next_frame_fcTL)
531 + PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 *width,
532 + png_uint_32 *height, png_uint_32 *x_offset, png_uint_32 *y_offset,
533 + png_uint_16 *delay_num, png_uint_16 *delay_den, png_byte *dispose_op,
534 + png_byte *blend_op));
535 +extern PNG_EXPORT(png_uint_32,png_set_next_frame_fcTL)
536 + PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 width,
537 + png_uint_32 height, png_uint_32 x_offset, png_uint_32 y_offset,
538 + png_uint_16 delay_num, png_uint_16 delay_den, png_byte dispose_op,
539 + png_byte blend_op));
540 +extern PNG_EXPORT(void,png_ensure_fcTL_is_valid)
541 + PNGARG((png_structp png_ptr,
542 + png_uint_32 width, png_uint_32 height,
543 + png_uint_32 x_offset, png_uint_32 y_offset,
544 + png_uint_16 delay_num, png_uint_16 delay_den,
545 + png_byte dispose_op, png_byte blend_op));
546 +extern PNG_EXPORT(png_uint_32,png_get_next_frame_width)
547 + PNGARG((png_structp png_ptr, png_infop info_ptr));
548 +extern PNG_EXPORT(png_uint_32,png_get_next_frame_height)
549 + PNGARG((png_structp png_ptr, png_infop info_ptr));
550 +extern PNG_EXPORT(png_uint_32,png_get_next_frame_x_offset)
551 + PNGARG((png_structp png_ptr, png_infop info_ptr));
552 +extern PNG_EXPORT(png_uint_32,png_get_next_frame_y_offset)
553 + PNGARG((png_structp png_ptr, png_infop info_ptr));
554 +extern PNG_EXPORT(png_uint_16,png_get_next_frame_delay_num)
555 + PNGARG((png_structp png_ptr, png_infop info_ptr));
556 +extern PNG_EXPORT(png_uint_16,png_get_next_frame_delay_den)
557 + PNGARG((png_structp png_ptr, png_infop info_ptr));
558 +extern PNG_EXPORT(png_byte,png_get_next_frame_dispose_op)
559 + PNGARG((png_structp png_ptr, png_infop info_ptr));
560 +extern PNG_EXPORT(png_byte,png_get_next_frame_blend_op)
561 + PNGARG((png_structp png_ptr, png_infop info_ptr));
562 +extern PNG_EXPORT(png_byte,png_get_first_frame_is_hidden)
563 + PNGARG((png_structp png_ptr, png_infop info_ptr));
564 +extern PNG_EXPORT(png_uint_32,png_set_first_frame_is_hidden)
565 + PNGARG((png_structp png_ptr, png_infop info_ptr, png_byte is_hidden));
566 +#endif /* PNG_APNG_SUPPORTED */
568 +#if defined(PNG_READ_APNG_SUPPORTED)
569 +extern PNG_EXPORT(void,png_read_frame_head) PNGARG((png_structp png_ptr,
570 + png_infop info_ptr));
573 #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
574 /* Provide a list of chunks and how they are to be handled, if the built-in
575 handling or default unknown chunk handling is not desired. Any chunks not
576 @@ -2883,6 +3005,8 @@
577 #define PNG_BACKGROUND_IS_GRAY 0x800
578 #define PNG_HAVE_PNG_SIGNATURE 0x1000
579 #define PNG_HAVE_CHUNK_AFTER_IDAT 0x2000 /* Have another chunk after IDAT */
580 +#define PNG_HAVE_acTL 0x4000
581 +#define PNG_HAVE_fcTL 0x8000L
583 /* Flags for the transformations the PNG library does on the image data */
584 #define PNG_BGR 0x0001
585 @@ -3024,6 +3148,9 @@
586 #define PNG_tIME png_byte png_tIME[5] = {116, 73, 77, 69, '\0'}
587 #define PNG_tRNS png_byte png_tRNS[5] = {116, 82, 78, 83, '\0'}
588 #define PNG_zTXt png_byte png_zTXt[5] = {122, 84, 88, 116, '\0'}
589 +#define PNG_acTL png_byte png_acTL[5] = { 97, 99, 84, 76, '\0'}
590 +#define PNG_fcTL png_byte png_fcTL[5] = {102, 99, 84, 76, '\0'}
591 +#define PNG_fdAT png_byte png_fdAT[5] = {102, 100, 65, 84, '\0'}
593 #ifdef PNG_USE_GLOBAL_ARRAYS
594 PNG_EXPORT_VAR (png_byte FARDATA) png_IHDR[5];
595 @@ -3047,6 +3174,9 @@
596 PNG_EXPORT_VAR (png_byte FARDATA) png_tIME[5];
597 PNG_EXPORT_VAR (png_byte FARDATA) png_tRNS[5];
598 PNG_EXPORT_VAR (png_byte FARDATA) png_zTXt[5];
599 +PNG_EXPORT_VAR (png_byte FARDATA) png_acTL[5];
600 +PNG_EXPORT_VAR (png_byte FARDATA) png_fcTL[5];
601 +PNG_EXPORT_VAR (png_byte FARDATA) png_fdAT[5];
602 #endif /* PNG_USE_GLOBAL_ARRAYS */
604 #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
605 @@ -3322,6 +3452,17 @@
609 +#if defined(PNG_WRITE_APNG_SUPPORTED)
610 +PNG_EXTERN void png_write_acTL PNGARG((png_structp png_ptr,
611 + png_uint_32 num_frames, png_uint_32 num_plays));
613 +PNG_EXTERN void png_write_fcTL PNGARG((png_structp png_ptr,
614 + png_uint_32 width, png_uint_32 height,
615 + png_uint_32 x_offset, png_uint_32 y_offset,
616 + png_uint_16 delay_num, png_uint_16 delay_den,
617 + png_byte dispose_op, png_byte blend_op));
620 /* Called when finished processing a row of data */
621 PNG_EXTERN void png_write_finish_row PNGARG((png_structp png_ptr));
623 @@ -3373,6 +3514,20 @@
624 PNG_EXTERN void png_read_transform_info PNGARG((png_structp png_ptr,
625 png_infop info_ptr));
627 +#if defined(PNG_READ_APNG_SUPPORTED)
628 +/* private, reset some things to become ready for reading next frame */
629 +PNG_EXTERN void png_read_reset PNGARG((png_structp png_ptr));
630 +PNG_EXTERN void png_read_reinit PNGARG((png_structp png_ptr,
631 + png_infop info_ptr));
632 +PNG_EXTERN void png_progressive_read_reset PNGARG((png_structp png_ptr));
634 +#if defined(PNG_WRITE_APNG_SUPPORTED)
635 +/* private, reset some things to become ready for writing next frame */
636 +PNG_EXTERN void png_write_reset PNGARG((png_structp png_ptr));
637 +PNG_EXTERN void png_write_reinit PNGARG((png_structp png_ptr,
638 + png_infop info_ptr, png_uint_32 width, png_uint_32 height));
641 /* These are the functions that do the transformations */
642 #if defined(PNG_READ_FILLER_SUPPORTED)
643 PNG_EXTERN void png_do_read_filler PNGARG((png_row_infop row_info,
644 @@ -3588,6 +3743,18 @@
645 png_uint_32 length));
648 +#if defined(PNG_READ_APNG_SUPPORTED)
649 +PNG_EXTERN void png_handle_acTL PNGARG((png_structp png_ptr, png_infop info_ptr,
650 + png_uint_32 length));
651 +PNG_EXTERN void png_handle_fcTL PNGARG((png_structp png_ptr, png_infop info_ptr,
652 + png_uint_32 length));
653 +PNG_EXTERN void png_have_info PNGARG((png_structp png_ptr, png_infop info_ptr));
654 +PNG_EXTERN void png_handle_fdAT PNGARG((png_structp png_ptr, png_infop info_ptr,
655 + png_uint_32 length));
656 +PNG_EXTERN void png_ensure_sequence_number PNGARG((png_structp png_ptr,
657 + png_uint_32 length));
660 PNG_EXTERN void png_handle_unknown PNGARG((png_structp png_ptr,
661 png_infop info_ptr, png_uint_32 length));
664 ===================================================================
668 /* The rest of these check to see if the valid field has the appropriate
669 * flag set, and if it does, writes the chunk.
671 +#if defined(PNG_WRITE_APNG_SUPPORTED)
672 + if (info_ptr->valid & PNG_INFO_acTL)
673 + png_write_acTL(png_ptr, info_ptr->num_frames, info_ptr->num_plays);
675 #if defined(PNG_WRITE_gAMA_SUPPORTED)
676 if (info_ptr->valid & PNG_INFO_gAMA)
680 if (!(png_ptr->mode & PNG_HAVE_IDAT))
681 png_error(png_ptr, "No IDATs written into file");
682 +#if defined(PNG_WRITE_APNG_SUPPORTED)
683 + if (png_ptr->num_frames_written != png_ptr->num_frames_to_write)
684 + png_error(png_ptr, "Not enough frames written");
687 /* See if user wants us to write information chunks */
688 if (info_ptr != NULL)
689 @@ -1558,4 +1566,39 @@
694 +#if defined(PNG_WRITE_APNG_SUPPORTED)
696 +png_write_frame_head(png_structp png_ptr, png_infop info_ptr,
697 + png_bytepp row_pointers, png_uint_32 width, png_uint_32 height,
698 + png_uint_32 x_offset, png_uint_32 y_offset,
699 + png_uint_16 delay_num, png_uint_16 delay_den, png_byte dispose_op,
702 + png_debug(1, "in png_write_frame_head");
704 + /* there is a chance this has been set after png_write_info was called,
705 + * so it would be set but not written. is there a way to be sure? */
706 + if (!(info_ptr->valid & PNG_INFO_acTL))
707 + png_error(png_ptr, "png_write_frame_head(): acTL not set");
709 + png_write_reset(png_ptr);
711 + png_write_reinit(png_ptr, info_ptr, width, height);
713 + if ( !(png_ptr->num_frames_written == 0 &&
714 + (png_ptr->apng_flags & PNG_FIRST_FRAME_HIDDEN) ) )
715 + png_write_fcTL(png_ptr, width, height, x_offset, y_offset,
716 + delay_num, delay_den, dispose_op, blend_op);
720 +png_write_frame_tail(png_structp png_ptr, png_infop png_info)
722 + png_debug(1, "in png_write_frame_tail");
724 + png_ptr->num_frames_written++;
726 +#endif /* PNG_WRITE_APNG_SUPPORTED */
728 #endif /* PNG_WRITE_SUPPORTED */
730 ===================================================================
734 # define PNG_READ_zTXt_SUPPORTED
735 # define PNG_zTXt_SUPPORTED
737 +#ifndef PNG_NO_READ_APNG
738 +# define PNG_READ_APNG_SUPPORTED
739 +# define PNG_APNG_SUPPORTED
741 #ifndef PNG_NO_READ_OPT_PLTE
742 # define PNG_READ_OPT_PLTE_SUPPORTED /* only affects support of the */
743 #endif /* optional PLTE chunk in RGB and RGBA images */
744 @@ -1091,6 +1095,12 @@
745 # define PNG_zTXt_SUPPORTED
748 +#ifndef PNG_NO_WRITE_APNG
749 +# define PNG_WRITE_APNG_SUPPORTED
750 +# ifndef PNG_APNG_SUPPORTED
751 +# define PNG_APNG_SUPPORTED
754 #if defined(PNG_WRITE_iTXt_SUPPORTED) || defined(PNG_WRITE_tEXt_SUPPORTED) || \
755 defined(PNG_WRITE_zTXt_SUPPORTED)
756 # define PNG_WRITE_TEXT_SUPPORTED
758 ===================================================================
762 #if defined(PNG_READ_zTXt_SUPPORTED)
765 +#if defined(PNG_READ_APNG_SUPPORTED)
766 + PNG_CONST PNG_acTL;
767 + PNG_CONST PNG_fcTL;
768 + PNG_CONST PNG_fdAT;
770 #endif /* PNG_USE_LOCAL_ARRAYS */
771 /* First we make sure we have enough data for the 4 byte chunk name
772 * and the 4 byte chunk length before proceeding with decoding the
773 @@ -230,6 +235,103 @@
774 png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
777 +#if defined(PNG_READ_APNG_SUPPORTED)
778 + if (png_ptr->num_frames_read > 0 &&
779 + png_ptr->num_frames_read < info_ptr->num_frames)
781 + if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
783 + /* discard trailing IDATs for the first frame */
784 + if (png_ptr->mode & PNG_HAVE_fcTL || png_ptr->num_frames_read > 1)
785 + png_error(png_ptr, "out of place IDAT");
787 + if (png_ptr->push_length + 4 > png_ptr->buffer_size)
789 + png_push_save_buffer(png_ptr);
792 + png_push_crc_skip(png_ptr, png_ptr->push_length);
793 + png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
796 + else if (!png_memcmp(png_ptr->chunk_name, png_fdAT, 4))
798 + if (png_ptr->buffer_size < 4)
800 + png_push_save_buffer(png_ptr);
803 + png_ensure_sequence_number(png_ptr, 4);
805 + if (!(png_ptr->mode & PNG_HAVE_fcTL))
807 + /* discard trailing fdATs for frames other than the first */
808 + if (png_ptr->num_frames_read < 2)
809 + png_error(png_ptr, "out of place fdAT");
811 + if (png_ptr->push_length + 4 > png_ptr->buffer_size)
813 + png_push_save_buffer(png_ptr);
816 + png_push_crc_skip(png_ptr, png_ptr->push_length);
817 + png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
822 + /* frame data follows */
823 + png_ptr->idat_size = png_ptr->push_length - 4;
824 + png_ptr->mode |= PNG_HAVE_IDAT;
825 + png_ptr->process_mode = PNG_READ_IDAT_MODE;
830 + else if(!png_memcmp(png_ptr->chunk_name, png_fcTL, 4))
832 + if (png_ptr->push_length + 4 > png_ptr->buffer_size)
834 + png_push_save_buffer(png_ptr);
838 + png_read_reset(png_ptr);
839 + png_ptr->mode &= ~PNG_HAVE_fcTL;
841 + png_handle_fcTL(png_ptr, info_ptr, png_ptr->push_length);
843 + if (!(png_ptr->mode & PNG_HAVE_fcTL))
844 + png_error(png_ptr, "missing required fcTL chunk");
846 + png_read_reinit(png_ptr, info_ptr);
847 + png_progressive_read_reset(png_ptr);
849 + if (png_ptr->frame_info_fn != NULL)
850 + (*(png_ptr->frame_info_fn))(png_ptr, png_ptr->num_frames_read);
852 + png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
858 + if (png_ptr->push_length + 4 > png_ptr->buffer_size)
860 + png_push_save_buffer(png_ptr);
863 + png_warning(png_ptr, "Skipped (ignored) a chunk "
864 + "between APNG chunks");
865 + png_push_crc_skip(png_ptr, png_ptr->push_length);
866 + png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
872 +#endif /* PNG_READ_APNG_SUPPORTED */
874 if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
875 if (png_ptr->mode & PNG_AFTER_IDAT)
876 png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
878 png_error(png_ptr, "Too many IDAT's found");
881 +#if defined(PNG_READ_APNG_SUPPORTED)
882 + png_have_info(png_ptr, info_ptr);
884 png_ptr->idat_size = png_ptr->push_length;
885 png_ptr->mode |= PNG_HAVE_IDAT;
886 png_ptr->process_mode = PNG_READ_IDAT_MODE;
891 +#if defined(PNG_READ_APNG_SUPPORTED)
892 + else if (!png_memcmp(png_ptr->chunk_name, png_acTL, 4))
894 + if (png_ptr->push_length + 4 > png_ptr->buffer_size)
896 + png_push_save_buffer(png_ptr);
900 + png_handle_acTL(png_ptr, info_ptr, png_ptr->push_length);
902 + else if (!png_memcmp(png_ptr->chunk_name, png_fcTL, 4))
904 + if (png_ptr->push_length + 4 > png_ptr->buffer_size)
906 + png_push_save_buffer(png_ptr);
910 + png_handle_fcTL(png_ptr, info_ptr, png_ptr->push_length);
912 + else if (!png_memcmp(png_ptr->chunk_name, png_fdAT, 4))
914 + if (png_ptr->push_length + 4 > png_ptr->buffer_size)
916 + png_push_save_buffer(png_ptr);
920 + png_handle_fdAT(png_ptr, info_ptr, png_ptr->push_length);
922 +#endif /* PNG_READ_APNG_SUPPORTED */
925 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
926 @@ -729,13 +866,17 @@
927 png_push_read_IDAT(png_structp png_ptr)
929 #ifdef PNG_USE_LOCAL_ARRAYS
930 - PNG_CONST PNG_IDAT;
932 +#if defined(PNG_READ_APNG_SUPPORTED)
937 if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
939 png_byte chunk_length[4];
941 - if (png_ptr->buffer_size < 8)
942 + if (png_ptr->buffer_size < 12)
944 png_push_save_buffer(png_ptr);
946 @@ -747,15 +888,62 @@
947 png_crc_read(png_ptr, png_ptr->chunk_name, 4);
948 png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
950 - if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
951 +#if defined(PNG_READ_APNG_SUPPORTED)
952 + if (png_memcmp(png_ptr->chunk_name, (png_bytep)png_fdAT, 4)
953 + && png_ptr->num_frames_read > 0)
955 + if (png_ptr->flags & PNG_FLAG_ZLIB_FINISHED)
957 + png_ptr->process_mode = PNG_READ_CHUNK_MODE;
958 + if (png_ptr->frame_end_fn != NULL)
959 + (*(png_ptr->frame_end_fn))(png_ptr, png_ptr->num_frames_read);
960 + png_ptr->num_frames_read++;
965 + if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
966 + png_error(png_ptr, "Not enough image data");
967 + if (png_ptr->push_length + 4 > png_ptr->buffer_size)
969 + png_push_save_buffer(png_ptr);
972 + png_warning(png_ptr, "Skipping (ignoring) a chunk between "
974 + png_crc_finish(png_ptr, png_ptr->push_length);
975 + png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
981 + if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4)
982 +#if defined(PNG_READ_APNG_SUPPORTED)
983 + && (png_ptr->num_frames_read == 0)
987 png_ptr->process_mode = PNG_READ_CHUNK_MODE;
988 if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
989 png_error(png_ptr, "Not enough compressed data");
990 +#if defined(PNG_READ_APNG_SUPPORTED)
991 + if (png_ptr->frame_end_fn != NULL)
992 + (*(png_ptr->frame_end_fn))(png_ptr, png_ptr->num_frames_read);
993 + png_ptr->num_frames_read++;
998 png_ptr->idat_size = png_ptr->push_length;
1000 +#if defined(PNG_READ_APNG_SUPPORTED)
1001 + if(png_ptr->num_frames_read > 0)
1003 + png_ensure_sequence_number(png_ptr, 4);
1004 + png_ptr->idat_size -= 4;
1008 if (png_ptr->idat_size && png_ptr->save_buffer_size)
1010 @@ -1716,6 +1904,17 @@
1011 png_set_read_fn(png_ptr, progressive_ptr, png_push_fill_buffer);
1014 +#if defined(PNG_READ_APNG_SUPPORTED)
1016 +png_set_progressive_frame_fn(png_structp png_ptr,
1017 + png_progressive_frame_ptr frame_info_fn,
1018 + png_progressive_frame_ptr frame_end_fn)
1020 + png_ptr->frame_info_fn = frame_info_fn;
1021 + png_ptr->frame_end_fn = frame_end_fn;
1026 png_get_progressive_ptr(png_structp png_ptr)
1029 ===================================================================
1032 @@ -320,6 +320,11 @@
1033 info_ptr->rowbytes = (png_size_t)0;
1035 info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, width);
1037 +#if defined(PNG_APNG_SUPPORTED)
1038 + /* for non-animated png. this may be overritten from an acTL chunk later */
1039 + info_ptr->num_frames = 1;
1043 #if defined(PNG_oFFs_SUPPORTED)
1044 @@ -1007,6 +1012,142 @@
1046 #endif /* PNG_sPLT_SUPPORTED */
1048 +#if defined(PNG_APNG_SUPPORTED)
1050 +png_set_acTL(png_structp png_ptr, png_infop info_ptr,
1051 + png_uint_32 num_frames, png_uint_32 num_plays)
1053 + png_debug1(1, "in %s storage function", "acTL");
1055 + if (png_ptr == NULL || info_ptr == NULL)
1057 + png_warning(png_ptr,
1058 + "Call to png_set_acTL() with NULL png_ptr "
1059 + "or info_ptr ignored");
1062 + if (num_frames == 0)
1064 + png_warning(png_ptr,
1065 + "Ignoring attempt to set acTL with num_frames zero");
1068 + if (num_frames > PNG_UINT_31_MAX)
1070 + png_warning(png_ptr,
1071 + "Ignoring attempt to set acTL with num_frames > 2^31-1");
1074 + if (num_plays > PNG_UINT_31_MAX)
1076 + png_warning(png_ptr,
1077 + "Ignoring attempt to set acTL with num_plays "
1082 + info_ptr->num_frames = num_frames;
1083 + info_ptr->num_plays = num_plays;
1085 + info_ptr->valid |= PNG_INFO_acTL;
1090 +/* delay_num and delay_den can hold any 16-bit values including zero */
1092 +png_set_next_frame_fcTL(png_structp png_ptr, png_infop info_ptr,
1093 + png_uint_32 width, png_uint_32 height,
1094 + png_uint_32 x_offset, png_uint_32 y_offset,
1095 + png_uint_16 delay_num, png_uint_16 delay_den,
1096 + png_byte dispose_op, png_byte blend_op)
1098 + png_debug1(1, "in %s storage function", "fcTL");
1100 + if (png_ptr == NULL || info_ptr == NULL)
1102 + png_warning(png_ptr,
1103 + "Call to png_set_fcTL() with NULL png_ptr or info_ptr "
1108 + png_ensure_fcTL_is_valid(png_ptr, width, height, x_offset, y_offset,
1109 + delay_num, delay_den, dispose_op, blend_op);
1111 + if (blend_op == PNG_BLEND_OP_OVER)
1113 + if (!(png_ptr->color_type & PNG_COLOR_MASK_ALPHA) &&
1114 + !(png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)))
1116 + png_warning(png_ptr, "PNG_BLEND_OP_OVER is meaningless "
1117 + "and wasteful for opaque images, ignored");
1118 + blend_op = PNG_BLEND_OP_SOURCE;
1122 + info_ptr->next_frame_width = width;
1123 + info_ptr->next_frame_height = height;
1124 + info_ptr->next_frame_x_offset = x_offset;
1125 + info_ptr->next_frame_y_offset = y_offset;
1126 + info_ptr->next_frame_delay_num = delay_num;
1127 + info_ptr->next_frame_delay_den = delay_den;
1128 + info_ptr->next_frame_dispose_op = dispose_op;
1129 + info_ptr->next_frame_blend_op = blend_op;
1131 + info_ptr->valid |= PNG_INFO_fcTL;
1137 +png_ensure_fcTL_is_valid(png_structp png_ptr,
1138 + png_uint_32 width, png_uint_32 height,
1139 + png_uint_32 x_offset, png_uint_32 y_offset,
1140 + png_uint_16 delay_num, png_uint_16 delay_den,
1141 + png_byte dispose_op, png_byte blend_op)
1143 + if (width + x_offset > png_ptr->first_frame_width ||
1144 + height + y_offset > png_ptr->first_frame_height)
1145 + png_error(png_ptr, "dimensions of a frame are greater than"
1146 + "the ones in IHDR");
1147 + if (width > PNG_UINT_31_MAX)
1148 + png_error(png_ptr, "invalid width in fcTL (> 2^31-1)");
1149 + if (height > PNG_UINT_31_MAX)
1150 + png_error(png_ptr, "invalid height in fcTL (> 2^31-1)");
1151 + if (x_offset > PNG_UINT_31_MAX)
1152 + png_error(png_ptr, "invalid x_offset in fcTL (> 2^31-1)");
1153 + if (y_offset > PNG_UINT_31_MAX)
1154 + png_error(png_ptr, "invalid y_offset in fcTL (> 2^31-1)");
1156 + if (dispose_op != PNG_DISPOSE_OP_NONE &&
1157 + dispose_op != PNG_DISPOSE_OP_BACKGROUND &&
1158 + dispose_op != PNG_DISPOSE_OP_PREVIOUS)
1159 + png_error(png_ptr, "invalid dispose_op in fcTL");
1161 + if (blend_op != PNG_BLEND_OP_SOURCE &&
1162 + blend_op != PNG_BLEND_OP_OVER)
1163 + png_error(png_ptr, "invalid blend_op in fcTL");
1167 +png_set_first_frame_is_hidden(png_structp png_ptr, png_infop info_ptr,
1168 + png_byte is_hidden)
1170 + png_debug(1, "in png_first_frame_is_hidden()");
1172 + if (png_ptr == NULL)
1176 + png_ptr->apng_flags |= PNG_FIRST_FRAME_HIDDEN;
1178 + png_ptr->apng_flags &= ~PNG_FIRST_FRAME_HIDDEN;
1182 +#endif /* PNG_APNG_SUPPORTED */
1184 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
1186 png_set_unknown_chunks(png_structp png_ptr,
1188 ===================================================================
1191 @@ -424,6 +424,11 @@
1192 filter_type = buf[11];
1193 interlace_type = buf[12];
1195 +#if defined(PNG_READ_APNG_SUPPORTED)
1196 + png_ptr->first_frame_width = width;
1197 + png_ptr->first_frame_height = height;
1200 /* Set internal variables */
1201 png_ptr->width = width;
1202 png_ptr->height = height;
1203 @@ -2230,6 +2235,168 @@
1207 +#if defined(PNG_READ_APNG_SUPPORTED)
1209 +png_handle_acTL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
1212 + png_uint_32 num_frames;
1213 + png_uint_32 num_plays;
1214 + png_uint_32 didSet;
1216 + png_debug(1, "in png_handle_acTL");
1218 + if (!(png_ptr->mode & PNG_HAVE_IHDR))
1220 + png_error(png_ptr, "Missing IHDR before acTL");
1222 + else if (png_ptr->mode & PNG_HAVE_IDAT)
1224 + png_warning(png_ptr, "Invalid acTL after IDAT skipped");
1225 + png_crc_finish(png_ptr, length);
1228 + else if (png_ptr->mode & PNG_HAVE_acTL)
1230 + png_warning(png_ptr, "Duplicate acTL skipped");
1231 + png_crc_finish(png_ptr, length);
1234 + else if (length != 8)
1236 + png_warning(png_ptr, "acTL with invalid length skipped");
1237 + png_crc_finish(png_ptr, length);
1241 + png_crc_read(png_ptr, data, 8);
1242 + png_crc_finish(png_ptr, 0);
1244 + num_frames = png_get_uint_31(png_ptr, data);
1245 + num_plays = png_get_uint_31(png_ptr, data + 4);
1247 + /* the set function will do error checking on num_frames */
1248 + didSet = png_set_acTL(png_ptr, info_ptr, num_frames, num_plays);
1250 + png_ptr->mode |= PNG_HAVE_acTL;
1254 +png_handle_fcTL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
1256 + png_byte data[22];
1257 + png_uint_32 width;
1258 + png_uint_32 height;
1259 + png_uint_32 x_offset;
1260 + png_uint_32 y_offset;
1261 + png_uint_16 delay_num;
1262 + png_uint_16 delay_den;
1263 + png_byte dispose_op;
1264 + png_byte blend_op;
1266 + png_debug(1, "in png_handle_fcTL");
1268 + if (!(png_ptr->mode & PNG_HAVE_IHDR))
1270 + png_error(png_ptr, "Missing IHDR before fcTL");
1272 + else if (png_ptr->mode & PNG_HAVE_IDAT)
1274 + /* for any frames other then the first this message may be misleading,
1275 + * but correct. PNG_HAVE_IDAT is unset before the frame head is read
1276 + * i can't think of a better message */
1277 + png_warning(png_ptr, "Invalid fcTL after IDAT skipped");
1278 + png_crc_finish(png_ptr, length);
1281 + else if (png_ptr->mode & PNG_HAVE_fcTL)
1283 + png_warning(png_ptr, "Duplicate fcTL within one frame skipped");
1284 + png_crc_finish(png_ptr, length);
1287 + else if (length != 26)
1289 + png_warning(png_ptr, "fcTL with invalid length skipped");
1290 + png_crc_finish(png_ptr, length);
1294 + png_ensure_sequence_number(png_ptr, length);
1296 + png_crc_read(png_ptr, data, 22);
1297 + png_crc_finish(png_ptr, 0);
1299 + width = png_get_uint_31(png_ptr, data);
1300 + height = png_get_uint_31(png_ptr, data + 4);
1301 + x_offset = png_get_uint_31(png_ptr, data + 8);
1302 + y_offset = png_get_uint_31(png_ptr, data + 12);
1303 + delay_num = png_get_uint_16(data + 16);
1304 + delay_den = png_get_uint_16(data + 18);
1305 + dispose_op = data[20];
1306 + blend_op = data[21];
1308 + if (png_ptr->num_frames_read == 0 && (x_offset != 0 || y_offset != 0))
1309 + png_error(png_ptr, "fcTL for the first frame must have zero offset");
1310 + if (png_ptr->num_frames_read == 0 &&
1311 + (width != info_ptr->width || height != info_ptr->height))
1312 + png_error(png_ptr, "size in first frame's fcTL must match "
1313 + "the size in IHDR");
1315 + /* the set function will do more error checking */
1316 + png_set_next_frame_fcTL(png_ptr, info_ptr, width, height,
1317 + x_offset, y_offset, delay_num, delay_den,
1318 + dispose_op, blend_op);
1320 + png_read_reinit(png_ptr, info_ptr);
1322 + png_ptr->mode |= PNG_HAVE_fcTL;
1326 +png_have_info(png_structp png_ptr, png_infop info_ptr)
1328 + if((info_ptr->valid & PNG_INFO_acTL) && !(info_ptr->valid & PNG_INFO_fcTL))
1330 + png_ptr->apng_flags |= PNG_FIRST_FRAME_HIDDEN;
1331 + info_ptr->num_frames++;
1336 +png_handle_fdAT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
1338 + png_ensure_sequence_number(png_ptr, length);
1340 + /* This function is only called from png_read_end(), png_read_info(),
1341 + * and png_push_read_chunk() which means that:
1342 + * - the user doesn't want to read this frame
1343 + * - or this is an out-of-place fdAT
1344 + * in either case it is safe to ignore the chunk with a warning */
1345 + png_warning(png_ptr, "ignoring fdAT chunk");
1346 + png_crc_finish(png_ptr, length - 4);
1350 +png_ensure_sequence_number(png_structp png_ptr, png_uint_32 length)
1353 + png_uint_32 sequence_number;
1356 + png_error(png_ptr, "invalid fcTL or fdAT chunk found");
1358 + png_crc_read(png_ptr, data, 4);
1359 + sequence_number = png_get_uint_31(png_ptr, data);
1361 + if (sequence_number != png_ptr->next_seq_num)
1362 + png_error(png_ptr, "fcTL or fdAT chunk with out-of-order sequence "
1365 + png_ptr->next_seq_num++;
1367 +#endif /* PNG_READ_APNG_SUPPORTED */
1369 /* This function is called when we haven't found a handler for a
1370 chunk. If there isn't a problem with the chunk itself (ie bad
1371 chunk name, CRC, or a critical chunk), the chunk is silently ignored
1372 @@ -3249,4 +3416,84 @@
1374 png_ptr->flags |= PNG_FLAG_ROW_INIT;
1377 +#if defined(PNG_READ_APNG_SUPPORTED)
1378 +/* This function is to be called after the main IDAT set has been read and
1379 + * before a new IDAT is read. It resets some parts of png_ptr
1380 + * to make them usable by the read functions again */
1382 +png_read_reset(png_structp png_ptr)
1384 + png_ptr->mode &= ~PNG_HAVE_IDAT;
1385 + png_ptr->mode &= ~PNG_AFTER_IDAT;
1386 + png_ptr->row_number = 0;
1387 + png_ptr->pass = 0;
1388 + png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
1392 +png_read_reinit(png_structp png_ptr, png_infop info_ptr)
1394 + png_ptr->width = info_ptr->next_frame_width;
1395 + png_ptr->height = info_ptr->next_frame_height;
1396 + png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->width);
1397 + if (png_ptr->prev_row)
1398 + png_memset_check(png_ptr, png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
1401 +/* same as png_read_reset() but for the progressive reader */
1403 +png_progressive_read_reset(png_structp png_ptr)
1405 +#ifdef PNG_USE_LOCAL_ARRAYS
1406 + /* start of interlace block */
1407 + const int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
1409 + /* offset to next interlace block */
1410 + const int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
1412 + /* start of interlace block in the y direction */
1413 + const int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
1415 + /* offset to next interlace block in the y direction */
1416 + const int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
1418 + png_uint_32 row_bytes;
1420 + if (png_ptr->interlaced)
1422 + if (!(png_ptr->transformations & PNG_INTERLACE))
1423 + png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
1424 + png_pass_ystart[0]) / png_pass_yinc[0];
1426 + png_ptr->num_rows = png_ptr->height;
1428 + png_ptr->iwidth = (png_ptr->width +
1429 + png_pass_inc[png_ptr->pass] - 1 -
1430 + png_pass_start[png_ptr->pass]) /
1431 + png_pass_inc[png_ptr->pass];
1433 + row_bytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->iwidth) + 1;
1435 + png_ptr->irowbytes = (png_size_t)row_bytes;
1436 + if((png_uint_32)png_ptr->irowbytes != row_bytes)
1437 + png_error(png_ptr, "png_progressive_read_reset(): Rowbytes "
1442 + png_ptr->num_rows = png_ptr->height;
1443 + png_ptr->iwidth = png_ptr->width;
1444 + png_ptr->irowbytes = png_ptr->rowbytes + 1;
1447 + png_ptr->flags &= ~PNG_FLAG_ZLIB_FINISHED;
1448 + if (inflateReset(&(png_ptr->zstream)) != Z_OK)
1449 + png_error(png_ptr, "inflateReset failed");
1450 + png_ptr->zstream.avail_in = 0;
1451 + png_ptr->zstream.next_in = 0;
1452 + png_ptr->zstream.next_out = png_ptr->row_buf;
1453 + png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
1455 +#endif /* PNG_READ_APNG_SUPPORTED */
1456 #endif /* PNG_READ_SUPPORTED */
1458 ===================================================================
1461 @@ -511,6 +511,11 @@
1462 /* Write the chunk */
1463 png_write_chunk(png_ptr, (png_bytep)png_IHDR, buf, (png_size_t)13);
1465 +#if defined(PNG_WRITE_APNG_SUPPORTED)
1466 + png_ptr->first_frame_width = width;
1467 + png_ptr->first_frame_height = height;
1470 /* Initialize zlib with PNG info */
1471 png_ptr->zstream.zalloc = png_zalloc;
1472 png_ptr->zstream.zfree = png_zfree;
1475 #ifdef PNG_USE_LOCAL_ARRAYS
1477 +#if defined(PNG_WRITE_APNG_SUPPORTED)
1481 png_debug(1, "in png_write_IDAT");
1483 @@ -677,7 +685,28 @@
1484 "Invalid zlib compression method or flags in IDAT");
1487 +#if defined(PNG_WRITE_APNG_SUPPORTED)
1488 + if(png_ptr->num_frames_written == 0)
1490 png_write_chunk(png_ptr, (png_bytep)png_IDAT, data, length);
1491 +#if defined(PNG_WRITE_APNG_SUPPORTED)
1496 + png_write_chunk_start(png_ptr, (png_bytep)png_fdAT, 4 + length);
1498 + png_save_uint_32(buf, png_ptr->next_seq_num);
1499 + png_write_chunk_data(png_ptr, buf, 4);
1501 + png_write_chunk_data(png_ptr, data, length);
1503 + png_write_chunk_end(png_ptr);
1505 + png_ptr->next_seq_num++;
1509 png_ptr->mode |= PNG_HAVE_IDAT;
1512 @@ -1719,6 +1748,70 @@
1516 +#if defined(PNG_WRITE_APNG_SUPPORTED)
1518 +png_write_acTL(png_structp png_ptr,
1519 + png_uint_32 num_frames, png_uint_32 num_plays)
1521 +#ifdef PNG_USE_LOCAL_ARRAYS
1524 + png_byte data[16];
1526 + png_debug(1, "in png_write_acTL");
1528 + png_ptr->num_frames_to_write = num_frames;
1530 + if (png_ptr->apng_flags & PNG_FIRST_FRAME_HIDDEN)
1533 + png_save_uint_32(data, num_frames);
1534 + png_save_uint_32(data + 4, num_plays);
1536 + png_write_chunk(png_ptr, (png_bytep)png_acTL, data, (png_size_t)8);
1540 +png_write_fcTL(png_structp png_ptr, png_uint_32 width, png_uint_32 height,
1541 + png_uint_32 x_offset, png_uint_32 y_offset,
1542 + png_uint_16 delay_num, png_uint_16 delay_den, png_byte dispose_op,
1543 + png_byte blend_op)
1545 +#ifdef PNG_USE_LOCAL_ARRAYS
1548 + png_byte data[26];
1550 + png_debug(1, "in png_write_fcTL");
1552 + if (png_ptr->num_frames_written == 0 && (x_offset != 0 || y_offset != 0))
1553 + png_error(png_ptr, "x and/or y offset for the first frame aren't 0");
1554 + if (png_ptr->num_frames_written == 0 &&
1555 + (width != png_ptr->first_frame_width ||
1556 + height != png_ptr->first_frame_height))
1557 + png_error(png_ptr, "width and/or height in the first frame's fcTL "
1558 + "don't match the ones in IHDR");
1560 + /* more error checking */
1561 + png_ensure_fcTL_is_valid(png_ptr, width, height, x_offset, y_offset,
1562 + delay_num, delay_den, dispose_op, blend_op);
1564 + png_save_uint_32(data, png_ptr->next_seq_num);
1565 + png_save_uint_32(data + 4, width);
1566 + png_save_uint_32(data + 8, height);
1567 + png_save_uint_32(data + 12, x_offset);
1568 + png_save_uint_32(data + 16, y_offset);
1569 + png_save_uint_16(data + 20, delay_num);
1570 + png_save_uint_16(data + 22, delay_den);
1571 + data[24] = dispose_op;
1572 + data[25] = blend_op;
1574 + png_write_chunk(png_ptr, (png_bytep)png_fcTL, data, (png_size_t)26);
1576 + png_ptr->next_seq_num++;
1578 +#endif /* PNG_WRITE_APNG_SUPPORTED */
1580 /* Initializes the row writing capability of libpng */
1582 png_write_start_row(png_structp png_ptr)
1583 @@ -2122,6 +2215,8 @@
1584 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
1585 int num_p_filters = (int)png_ptr->num_prev_filters;
1587 + if (png_ptr->row_number == 0)
1588 + filter_to_do &= ~(PNG_FILTER_UP | PNG_FILTER_AVG | PNG_FILTER_PAETH); /* they use previous row */
1590 png_debug(1, "in png_write_find_filter");
1591 /* Find out how many bytes offset each pixel is */
1592 @@ -2788,4 +2883,39 @@
1597 +#if defined(PNG_WRITE_APNG_SUPPORTED)
1599 +png_write_reset(png_structp png_ptr)
1601 + png_ptr->row_number = 0;
1602 + png_ptr->pass = 0;
1603 + png_ptr->mode &= ~PNG_HAVE_IDAT;
1607 +png_write_reinit(png_structp png_ptr, png_infop info_ptr,
1608 + png_uint_32 width, png_uint_32 height)
1610 + if (png_ptr->num_frames_written == 0 &&
1611 + (width != png_ptr->first_frame_width ||
1612 + height != png_ptr->first_frame_height))
1613 + png_error(png_ptr, "width and/or height in the first frame's fcTL "
1614 + "don't match the ones in IHDR");
1615 + if (width > png_ptr->first_frame_width ||
1616 + height > png_ptr->first_frame_height)
1617 + png_error(png_ptr, "width and/or height for a frame greater than"
1618 + "the ones in IHDR");
1620 + png_set_IHDR(png_ptr, info_ptr, width, height,
1621 + info_ptr->bit_depth, info_ptr->color_type,
1622 + info_ptr->interlace_type, info_ptr->compression_type,
1623 + info_ptr->filter_type);
1625 + png_ptr->width = width;
1626 + png_ptr->height = height;
1627 + png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, width);
1628 + png_ptr->usr_width = png_ptr->width;
1631 #endif /* PNG_WRITE_SUPPORTED */
1633 ===================================================================
1636 @@ -1321,7 +1321,7 @@
1637 * pixels. This check added to libpng-1.2.19
1639 #if (PNG_WARN_UNINITIALIZED_ROW==1)
1640 - png_error(png_ptr, "Uninitialized row");
1641 + png_warning(png_ptr, "Uninitialized row");
1643 png_warning(png_ptr, "Uninitialized row");