-+PNG_EXPORT(252, png_uint_32, png_get_next_frame_width,
-+ (png_structp png_ptr, png_infop info_ptr));
-+PNG_EXPORT(253, png_uint_32, png_get_next_frame_height,
-+ (png_structp png_ptr, png_infop info_ptr));
-+PNG_EXPORT(254, png_uint_32, png_get_next_frame_x_offset,
-+ (png_structp png_ptr, png_infop info_ptr));
-+PNG_EXPORT(255, png_uint_32, png_get_next_frame_y_offset,
-+ (png_structp png_ptr, png_infop info_ptr));
-+PNG_EXPORT(256, png_uint_16, png_get_next_frame_delay_num,
-+ (png_structp png_ptr, png_infop info_ptr));
-+PNG_EXPORT(257, png_uint_16, png_get_next_frame_delay_den,
-+ (png_structp png_ptr, png_infop info_ptr));
-+PNG_EXPORT(258, png_byte, png_get_next_frame_dispose_op,
-+ (png_structp png_ptr, png_infop info_ptr));
-+PNG_EXPORT(259, png_byte, png_get_next_frame_blend_op,
-+ (png_structp png_ptr, png_infop info_ptr));
-+PNG_EXPORT(260, png_byte, png_get_first_frame_is_hidden,
-+ (png_structp png_ptr, png_infop info_ptr));
-+PNG_EXPORT(261, png_uint_32, png_set_first_frame_is_hidden,
-+ (png_structp png_ptr, png_infop info_ptr, png_byte is_hidden));
-+
-+#ifdef PNG_READ_APNG_SUPPORTED
-+PNG_EXPORT(262, void, png_read_frame_head, (png_structp png_ptr,
-+ png_infop info_ptr));
-+#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
-+PNG_EXPORT(263, void, png_set_progressive_frame_fn, (png_structp png_ptr,
-+ png_progressive_frame_ptr frame_info_fn,
-+ png_progressive_frame_ptr frame_end_fn));
-+#endif /* PROGRESSIVE_READ */
-+#endif /* READ_APNG */
-+
-+#ifdef PNG_WRITE_APNG_SUPPORTED
-+PNG_EXPORT(264, void, png_write_frame_head, (png_structp png_ptr,
-+ png_infop info_ptr, png_bytepp row_pointers,
-+ png_uint_32 width, png_uint_32 height,
-+ png_uint_32 x_offset, png_uint_32 y_offset,
-+ png_uint_16 delay_num, png_uint_16 delay_den, png_byte dispose_op,
-+ png_byte blend_op));
-+
-+PNG_EXPORT(265, void, png_write_frame_tail, (png_structp png_ptr,
-+ png_infop info_ptr));
-+#endif /* WRITE_APNG */
-+#endif /* APNG */
-+
- /* Maintainer: Put new public prototypes here ^, in libpng.3, in project
- * defs, and in scripts/symbols.def.
- */
-@@ -3253,7 +3352,11 @@
- * one to use is one more than this.)
- */
- #ifdef PNG_EXPORT_LAST_ORDINAL
-+#ifdef PNG_APNG_SUPPORTED
-+ PNG_EXPORT_LAST_ORDINAL(265);
-+#else
- PNG_EXPORT_LAST_ORDINAL(245);
-+#endif /* APNG */
- #endif
-
- #ifdef __cplusplus
-Index: pngpriv.h
-===================================================================
---- pngpriv.h
-+++ pngpriv.h
-@@ -625,6 +625,10 @@
- #define PNG_HAVE_CHUNK_AFTER_IDAT 0x2000U /* Have another chunk after IDAT */
- /* 0x4000U (unused) */
- #define PNG_IS_READ_STRUCT 0x8000U /* Else is a write struct */
-+#ifdef PNG_APNG_SUPPORTED
-+#define PNG_HAVE_acTL 0x10000U
-+#define PNG_HAVE_fcTL 0x20000U
-+#endif
-
- /* Flags for the transformations the PNG library does on the image data */
- #define PNG_BGR 0x0001U
-@@ -860,6 +864,16 @@
- #define png_tRNS PNG_U32(116, 82, 78, 83)
- #define png_zTXt PNG_U32(122, 84, 88, 116)
-
-+#ifdef PNG_APNG_SUPPORTED
-+#define png_acTL PNG_U32( 97, 99, 84, 76)
-+#define png_fcTL PNG_U32(102, 99, 84, 76)
-+#define png_fdAT PNG_U32(102, 100, 65, 84)
-+
-+/* For png_struct.apng_flags: */
-+#define PNG_FIRST_FRAME_HIDDEN 0x0001U
-+#define PNG_APNG_APP 0x0002U
-+#endif
-+
- /* The following will work on (signed char*) strings, whereas the get_uint_32
- * macro will fail on top-bit-set values because of the sign extension.
- */
-@@ -1598,6 +1612,49 @@
-
- #endif /* PROGRESSIVE_READ */
-
-+#ifdef PNG_APNG_SUPPORTED
-+PNG_INTERNAL_FUNCTION(void,png_ensure_fcTL_is_valid,(png_structp png_ptr,
-+ png_uint_32 width, png_uint_32 height,
-+ png_uint_32 x_offset, png_uint_32 y_offset,
-+ png_uint_16 delay_num, png_uint_16 delay_den,
-+ png_byte dispose_op, png_byte blend_op),PNG_EMPTY);
-+
-+#ifdef PNG_READ_APNG_SUPPORTED
-+PNG_INTERNAL_FUNCTION(void,png_handle_acTL,(png_structp png_ptr,
-+ png_infop info_ptr, png_uint_32 length),PNG_EMPTY);
-+PNG_INTERNAL_FUNCTION(void,png_handle_fcTL,(png_structp png_ptr,
-+ png_infop info_ptr, png_uint_32 length),PNG_EMPTY);
-+PNG_INTERNAL_FUNCTION(void,png_handle_fdAT,(png_structp png_ptr,
-+ png_infop info_ptr, png_uint_32 length),PNG_EMPTY);
-+PNG_INTERNAL_FUNCTION(void,png_have_info,(png_structp png_ptr,
-+ png_infop info_ptr),PNG_EMPTY);
-+PNG_INTERNAL_FUNCTION(void,png_ensure_sequence_number,(png_structp png_ptr,
-+ png_uint_32 length),PNG_EMPTY);
-+PNG_INTERNAL_FUNCTION(void,png_read_reset,(png_structp png_ptr),PNG_EMPTY);
-+PNG_INTERNAL_FUNCTION(void,png_read_reinit,(png_structp png_ptr,
-+ png_infop info_ptr),PNG_EMPTY);
-+#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
-+PNG_INTERNAL_FUNCTION(void,png_progressive_read_reset,(png_structp png_ptr),
-+ PNG_EMPTY);
-+#endif /* PROGRESSIVE_READ */
-+#endif /* READ_APNG */
-+
-+#ifdef PNG_WRITE_APNG_SUPPORTED
-+PNG_INTERNAL_FUNCTION(void,png_write_acTL,(png_structp png_ptr,
-+ png_uint_32 num_frames, png_uint_32 num_plays),PNG_EMPTY);
-+PNG_INTERNAL_FUNCTION(void,png_write_fcTL,(png_structp png_ptr,
-+ png_uint_32 width, png_uint_32 height,
-+ png_uint_32 x_offset, png_uint_32 y_offset,
-+ png_uint_16 delay_num, png_uint_16 delay_den,
-+ png_byte dispose_op, png_byte blend_op),PNG_EMPTY);
-+PNG_INTERNAL_FUNCTION(void,png_write_fdAT,(png_structp png_ptr,
-+ png_const_bytep data, png_size_t length),PNG_EMPTY);
-+PNG_INTERNAL_FUNCTION(void,png_write_reset,(png_structp png_ptr),PNG_EMPTY);
-+PNG_INTERNAL_FUNCTION(void,png_write_reinit,(png_structp png_ptr,
-+ png_infop info_ptr, png_uint_32 width, png_uint_32 height),PNG_EMPTY);
-+#endif /* WRITE_APNG */
-+#endif /* APNG */
-+
- /* Added at libpng version 1.6.0 */
- #ifdef PNG_GAMMA_SUPPORTED
- PNG_INTERNAL_FUNCTION(void,png_colorspace_set_gamma,(png_const_structrp png_ptr,
-Index: pnginfo.h
-===================================================================
---- pnginfo.h
-+++ pnginfo.h
-@@ -255,5 +255,18 @@
- png_bytepp row_pointers; /* the image bits */
- #endif
-
-+#ifdef PNG_APNG_SUPPORTED
-+ png_uint_32 num_frames; /* including default image */
-+ png_uint_32 num_plays;
-+ png_uint_32 next_frame_width;
-+ png_uint_32 next_frame_height;
-+ png_uint_32 next_frame_x_offset;
-+ png_uint_32 next_frame_y_offset;
-+ png_uint_16 next_frame_delay_num;
-+ png_uint_16 next_frame_delay_den;
-+ png_byte next_frame_dispose_op;
-+ png_byte next_frame_blend_op;
-+#endif
-+
- };
- #endif /* PNGINFO_H */
-Index: pngstruct.h
-===================================================================
---- pngstruct.h
-+++ pngstruct.h
-@@ -403,6 +403,27 @@
- png_byte filter_type;
- #endif
-
-+#ifdef PNG_APNG_SUPPORTED
-+ png_uint_32 apng_flags;
-+ png_uint_32 next_seq_num; /* next fcTL/fdAT chunk sequence number */
-+ png_uint_32 first_frame_width;
-+ png_uint_32 first_frame_height;
-+
-+#ifdef PNG_READ_APNG_SUPPORTED
-+ png_uint_32 num_frames_read; /* incremented after all image data of */
-+ /* a frame is read */
-+#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
-+ png_progressive_frame_ptr frame_info_fn; /* frame info read callback */
-+ png_progressive_frame_ptr frame_end_fn; /* frame data read callback */
-+#endif
-+#endif
-+
-+#ifdef PNG_WRITE_APNG_SUPPORTED
-+ png_uint_32 num_frames_to_write;
-+ png_uint_32 num_frames_written;
-+#endif
-+#endif /* APNG */
-+
- /* New members added in libpng-1.2.0 */
-
- /* New members added in libpng-1.0.2 but first enabled by default in 1.2.0 */
-Index: pngwrite.c
-===================================================================
---- pngwrite.c
-+++ pngwrite.c
-@@ -128,6 +128,10 @@
- * the application continues writing the PNG. So check the 'invalid'
- * flag here too.
- */
-+#ifdef PNG_WRITE_APNG_SUPPORTED
-+ if ((info_ptr->valid & PNG_INFO_acTL) != 0)
-+ png_write_acTL(png_ptr, info_ptr->num_frames, info_ptr->num_plays);
-+#endif
- #ifdef PNG_GAMMA_SUPPORTED
- # ifdef PNG_WRITE_gAMA_SUPPORTED
- if ((info_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) == 0 &&
-@@ -360,6 +364,11 @@
- if ((png_ptr->mode & PNG_HAVE_IDAT) == 0)
- png_error(png_ptr, "No IDATs written into file");
-
-+#ifdef PNG_WRITE_APNG_SUPPORTED
-+ if (png_ptr->num_frames_written != png_ptr->num_frames_to_write)
-+ png_error(png_ptr, "Not enough frames written");
-+#endif
-+
- #ifdef PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED
- if (png_ptr->num_palette_max > png_ptr->num_palette)
- png_benign_error(png_ptr, "Wrote palette index exceeding num_palette");
-@@ -2382,4 +2391,42 @@
- }
- #endif /* SIMPLIFIED_WRITE_STDIO */
- #endif /* SIMPLIFIED_WRITE */
-+
-+#ifdef PNG_WRITE_APNG_SUPPORTED
-+void PNGAPI
-+png_write_frame_head(png_structp png_ptr, png_infop info_ptr,
-+ png_bytepp row_pointers, png_uint_32 width, png_uint_32 height,
-+ png_uint_32 x_offset, png_uint_32 y_offset,
-+ png_uint_16 delay_num, png_uint_16 delay_den, png_byte dispose_op,
-+ png_byte blend_op)
-+{
-+ png_debug(1, "in png_write_frame_head");
-+
-+ /* there is a chance this has been set after png_write_info was called,
-+ * so it would be set but not written. is there a way to be sure? */
-+ if ((info_ptr->valid & PNG_INFO_acTL) == 0)
-+ png_error(png_ptr, "png_write_frame_head(): acTL not set");
-+
-+ png_write_reset(png_ptr);
-+
-+ png_write_reinit(png_ptr, info_ptr, width, height);
-+
-+ if ((png_ptr->apng_flags & PNG_FIRST_FRAME_HIDDEN) == 0 ||
-+ png_ptr->num_frames_written != 0)
-+ png_write_fcTL(png_ptr, width, height, x_offset, y_offset,
-+ delay_num, delay_den, dispose_op, blend_op);
-+
-+ PNG_UNUSED(row_pointers)
-+}
-+
-+void PNGAPI
-+png_write_frame_tail(png_structp png_ptr, png_infop info_ptr)
-+{
-+ png_debug(1, "in png_write_frame_tail");
-+
-+ png_ptr->num_frames_written++;
-+
-+ PNG_UNUSED(info_ptr)
-+}
-+#endif /* WRITE_APNG */
- #endif /* WRITE */
-Index: pngpread.c
-===================================================================
---- pngpread.c
-+++ pngpread.c
-@@ -194,6 +194,89 @@
-
- chunk_name = png_ptr->chunk_name;
-
-+#ifdef PNG_READ_APNG_SUPPORTED
-+ if (png_ptr->num_frames_read > 0 &&
-+ png_ptr->num_frames_read < info_ptr->num_frames)
-+ {
-+ if (chunk_name == png_IDAT)
-+ {
-+ /* Discard trailing IDATs for the first frame */
-+ if ((png_ptr->mode & PNG_HAVE_fcTL) != 0 ||
-+ png_ptr->num_frames_read > 1)
-+ png_error(png_ptr, "out of place IDAT");
-+
-+ PNG_PUSH_SAVE_BUFFER_IF_FULL
-+ png_crc_finish(png_ptr, png_ptr->push_length);
-+ png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
-+ }
-+
-+ else if (chunk_name == png_fdAT)
-+ {
-+ PNG_PUSH_SAVE_BUFFER_IF_LT(4)
-+ png_ensure_sequence_number(png_ptr, 4);
-+
-+ if ((png_ptr->mode & PNG_HAVE_fcTL) == 0)
-+ {
-+ /* Discard trailing fdATs for frames other than the first */
-+ if (png_ptr->num_frames_read < 2)
-+ png_error(png_ptr, "out of place fdAT");
-+
-+ PNG_PUSH_SAVE_BUFFER_IF_FULL
-+ png_crc_finish(png_ptr, png_ptr->push_length);