michael@0: Index: pngread.c michael@0: =================================================================== michael@0: --- pngread.c michael@0: +++ pngread.c michael@0: @@ -158,6 +158,9 @@ michael@0: michael@0: else if (chunk_name == png_IDAT) michael@0: { michael@0: +#ifdef PNG_READ_APNG_SUPPORTED michael@0: + png_have_info(png_ptr, info_ptr); michael@0: +#endif michael@0: png_ptr->idat_size = length; michael@0: break; michael@0: } michael@0: @@ -247,6 +250,17 @@ michael@0: png_handle_iTXt(png_ptr, info_ptr, length); michael@0: #endif michael@0: michael@0: +#ifdef PNG_READ_APNG_SUPPORTED michael@0: + else if (chunk_name == png_acTL) michael@0: + png_handle_acTL(png_ptr, info_ptr, length); michael@0: + michael@0: + else if (chunk_name == png_fcTL) michael@0: + png_handle_fcTL(png_ptr, info_ptr, length); michael@0: + michael@0: + else if (chunk_name == png_fdAT) michael@0: + png_handle_fdAT(png_ptr, info_ptr, length); michael@0: +#endif michael@0: + michael@0: else michael@0: png_handle_unknown(png_ptr, info_ptr, length, michael@0: PNG_HANDLE_CHUNK_AS_DEFAULT); michael@0: @@ -254,6 +268,72 @@ michael@0: } michael@0: #endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ michael@0: michael@0: +#ifdef PNG_READ_APNG_SUPPORTED michael@0: +void PNGAPI michael@0: +png_read_frame_head(png_structp png_ptr, png_infop info_ptr) michael@0: +{ michael@0: + png_byte have_chunk_after_DAT; /* after IDAT or after fdAT */ michael@0: + michael@0: + png_debug(0, "Reading frame head"); michael@0: + michael@0: + if (!(png_ptr->mode & PNG_HAVE_acTL)) michael@0: + png_error(png_ptr, "attempt to png_read_frame_head() but " michael@0: + "no acTL present"); michael@0: + michael@0: + /* do nothing for the main IDAT */ michael@0: + if (png_ptr->num_frames_read == 0) michael@0: + return; michael@0: + michael@0: + png_read_reset(png_ptr); michael@0: + png_ptr->flags &= ~PNG_FLAG_ROW_INIT; michael@0: + png_ptr->mode &= ~PNG_HAVE_fcTL; michael@0: + michael@0: + have_chunk_after_DAT = 0; michael@0: + for (;;) michael@0: + { michael@0: + png_uint_32 length = png_read_chunk_header(png_ptr); michael@0: + michael@0: + if (png_ptr->chunk_name == png_IDAT) michael@0: + { michael@0: + /* discard trailing IDATs for the first frame */ michael@0: + if (have_chunk_after_DAT || png_ptr->num_frames_read > 1) michael@0: + png_error(png_ptr, "png_read_frame_head(): out of place IDAT"); michael@0: + png_crc_finish(png_ptr, length); michael@0: + } michael@0: + michael@0: + else if (png_ptr->chunk_name == png_fcTL) michael@0: + { michael@0: + png_handle_fcTL(png_ptr, info_ptr, length); michael@0: + have_chunk_after_DAT = 1; michael@0: + } michael@0: + michael@0: + else if (png_ptr->chunk_name == png_fdAT) michael@0: + { michael@0: + png_ensure_sequence_number(png_ptr, length); michael@0: + michael@0: + /* discard trailing fdATs for frames other than the first */ michael@0: + if (!have_chunk_after_DAT && png_ptr->num_frames_read > 1) michael@0: + png_crc_finish(png_ptr, length - 4); michael@0: + else if(png_ptr->mode & PNG_HAVE_fcTL) michael@0: + { michael@0: + png_ptr->idat_size = length - 4; michael@0: + png_ptr->mode |= PNG_HAVE_IDAT; michael@0: + michael@0: + break; michael@0: + } michael@0: + else michael@0: + png_error(png_ptr, "png_read_frame_head(): out of place fdAT"); michael@0: + } michael@0: + else michael@0: + { michael@0: + png_warning(png_ptr, "Skipped (ignored) a chunk " michael@0: + "between APNG chunks"); michael@0: + png_crc_finish(png_ptr, length); michael@0: + } michael@0: + } michael@0: +} michael@0: +#endif /* PNG_READ_APNG_SUPPORTED */ michael@0: + michael@0: /* Optional call to update the users info_ptr structure */ michael@0: void PNGAPI michael@0: png_read_update_info(png_structrp png_ptr, png_inforp info_ptr) michael@0: Index: pngget.c michael@0: =================================================================== michael@0: --- pngget.c michael@0: +++ pngget.c michael@0: @@ -1174,4 +1174,166 @@ michael@0: # endif michael@0: #endif michael@0: michael@0: +#ifdef PNG_APNG_SUPPORTED michael@0: +png_uint_32 PNGAPI michael@0: +png_get_acTL(png_structp png_ptr, png_infop info_ptr, michael@0: + png_uint_32 *num_frames, png_uint_32 *num_plays) michael@0: +{ michael@0: + png_debug1(1, "in %s retrieval function", "acTL"); michael@0: + michael@0: + if (png_ptr != NULL && info_ptr != NULL && michael@0: + (info_ptr->valid & PNG_INFO_acTL) && michael@0: + num_frames != NULL && num_plays != NULL) michael@0: + { michael@0: + *num_frames = info_ptr->num_frames; michael@0: + *num_plays = info_ptr->num_plays; michael@0: + return (1); michael@0: + } michael@0: + michael@0: + return (0); michael@0: +} michael@0: + michael@0: +png_uint_32 PNGAPI michael@0: +png_get_num_frames(png_structp png_ptr, png_infop info_ptr) michael@0: +{ michael@0: + png_debug(1, "in png_get_num_frames()"); michael@0: + michael@0: + if (png_ptr != NULL && info_ptr != NULL) michael@0: + return (info_ptr->num_frames); michael@0: + return (0); michael@0: +} michael@0: + michael@0: +png_uint_32 PNGAPI michael@0: +png_get_num_plays(png_structp png_ptr, png_infop info_ptr) michael@0: +{ michael@0: + png_debug(1, "in png_get_num_plays()"); michael@0: + michael@0: + if (png_ptr != NULL && info_ptr != NULL) michael@0: + return (info_ptr->num_plays); michael@0: + return (0); michael@0: +} michael@0: + michael@0: +png_uint_32 PNGAPI michael@0: +png_get_next_frame_fcTL(png_structp png_ptr, png_infop info_ptr, michael@0: + png_uint_32 *width, png_uint_32 *height, michael@0: + png_uint_32 *x_offset, png_uint_32 *y_offset, michael@0: + png_uint_16 *delay_num, png_uint_16 *delay_den, michael@0: + png_byte *dispose_op, png_byte *blend_op) michael@0: +{ michael@0: + png_debug1(1, "in %s retrieval function", "fcTL"); michael@0: + michael@0: + if (png_ptr != NULL && info_ptr != NULL && michael@0: + (info_ptr->valid & PNG_INFO_fcTL) && michael@0: + width != NULL && height != NULL && michael@0: + x_offset != NULL && y_offset != NULL && michael@0: + delay_num != NULL && delay_den != NULL && michael@0: + dispose_op != NULL && blend_op != NULL) michael@0: + { michael@0: + *width = info_ptr->next_frame_width; michael@0: + *height = info_ptr->next_frame_height; michael@0: + *x_offset = info_ptr->next_frame_x_offset; michael@0: + *y_offset = info_ptr->next_frame_y_offset; michael@0: + *delay_num = info_ptr->next_frame_delay_num; michael@0: + *delay_den = info_ptr->next_frame_delay_den; michael@0: + *dispose_op = info_ptr->next_frame_dispose_op; michael@0: + *blend_op = info_ptr->next_frame_blend_op; michael@0: + return (1); michael@0: + } michael@0: + michael@0: + return (0); michael@0: +} michael@0: + michael@0: +png_uint_32 PNGAPI michael@0: +png_get_next_frame_width(png_structp png_ptr, png_infop info_ptr) michael@0: +{ michael@0: + png_debug(1, "in png_get_next_frame_width()"); michael@0: + michael@0: + if (png_ptr != NULL && info_ptr != NULL) michael@0: + return (info_ptr->next_frame_width); michael@0: + return (0); michael@0: +} michael@0: + michael@0: +png_uint_32 PNGAPI michael@0: +png_get_next_frame_height(png_structp png_ptr, png_infop info_ptr) michael@0: +{ michael@0: + png_debug(1, "in png_get_next_frame_height()"); michael@0: + michael@0: + if (png_ptr != NULL && info_ptr != NULL) michael@0: + return (info_ptr->next_frame_height); michael@0: + return (0); michael@0: +} michael@0: + michael@0: +png_uint_32 PNGAPI michael@0: +png_get_next_frame_x_offset(png_structp png_ptr, png_infop info_ptr) michael@0: +{ michael@0: + png_debug(1, "in png_get_next_frame_x_offset()"); michael@0: + michael@0: + if (png_ptr != NULL && info_ptr != NULL) michael@0: + return (info_ptr->next_frame_x_offset); michael@0: + return (0); michael@0: +} michael@0: + michael@0: +png_uint_32 PNGAPI michael@0: +png_get_next_frame_y_offset(png_structp png_ptr, png_infop info_ptr) michael@0: +{ michael@0: + png_debug(1, "in png_get_next_frame_y_offset()"); michael@0: + michael@0: + if (png_ptr != NULL && info_ptr != NULL) michael@0: + return (info_ptr->next_frame_y_offset); michael@0: + return (0); michael@0: +} michael@0: + michael@0: +png_uint_16 PNGAPI michael@0: +png_get_next_frame_delay_num(png_structp png_ptr, png_infop info_ptr) michael@0: +{ michael@0: + png_debug(1, "in png_get_next_frame_delay_num()"); michael@0: + michael@0: + if (png_ptr != NULL && info_ptr != NULL) michael@0: + return (info_ptr->next_frame_delay_num); michael@0: + return (0); michael@0: +} michael@0: + michael@0: +png_uint_16 PNGAPI michael@0: +png_get_next_frame_delay_den(png_structp png_ptr, png_infop info_ptr) michael@0: +{ michael@0: + png_debug(1, "in png_get_next_frame_delay_den()"); michael@0: + michael@0: + if (png_ptr != NULL && info_ptr != NULL) michael@0: + return (info_ptr->next_frame_delay_den); michael@0: + return (0); michael@0: +} michael@0: + michael@0: +png_byte PNGAPI michael@0: +png_get_next_frame_dispose_op(png_structp png_ptr, png_infop info_ptr) michael@0: +{ michael@0: + png_debug(1, "in png_get_next_frame_dispose_op()"); michael@0: + michael@0: + if (png_ptr != NULL && info_ptr != NULL) michael@0: + return (info_ptr->next_frame_dispose_op); michael@0: + return (0); michael@0: +} michael@0: + michael@0: +png_byte PNGAPI michael@0: +png_get_next_frame_blend_op(png_structp png_ptr, png_infop info_ptr) michael@0: +{ michael@0: + png_debug(1, "in png_get_next_frame_blend_op()"); michael@0: + michael@0: + if (png_ptr != NULL && info_ptr != NULL) michael@0: + return (info_ptr->next_frame_blend_op); michael@0: + return (0); michael@0: +} michael@0: + michael@0: +png_byte PNGAPI michael@0: +png_get_first_frame_is_hidden(png_structp png_ptr, png_infop info_ptr) michael@0: +{ michael@0: + png_debug(1, "in png_first_frame_is_hidden()"); michael@0: + michael@0: + if (png_ptr != NULL) michael@0: + return (png_byte)(png_ptr->apng_flags & PNG_FIRST_FRAME_HIDDEN); michael@0: + michael@0: + PNG_UNUSED(info_ptr) michael@0: + michael@0: + return 0; michael@0: +} michael@0: +#endif /* PNG_APNG_SUPPORTED */ michael@0: #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */ michael@0: Index: png.h michael@0: =================================================================== michael@0: --- png.h michael@0: +++ png.h michael@0: @@ -457,6 +457,10 @@ michael@0: # include "pnglibconf.h" michael@0: #endif michael@0: michael@0: +#define PNG_APNG_SUPPORTED michael@0: +#define PNG_READ_APNG_SUPPORTED michael@0: +#define PNG_WRITE_APNG_SUPPORTED michael@0: + michael@0: #ifndef PNG_VERSION_INFO_ONLY michael@0: /* Machine specific configuration. */ michael@0: # include "pngconf.h" michael@0: @@ -547,6 +551,17 @@ michael@0: * See pngconf.h for base types that vary by machine/system michael@0: */ michael@0: michael@0: +#ifdef PNG_APNG_SUPPORTED michael@0: +/* dispose_op flags from inside fcTL */ michael@0: +#define PNG_DISPOSE_OP_NONE 0x00 michael@0: +#define PNG_DISPOSE_OP_BACKGROUND 0x01 michael@0: +#define PNG_DISPOSE_OP_PREVIOUS 0x02 michael@0: + michael@0: +/* blend_op flags from inside fcTL */ michael@0: +#define PNG_BLEND_OP_SOURCE 0x00 michael@0: +#define PNG_BLEND_OP_OVER 0x01 michael@0: +#endif /* PNG_APNG_SUPPORTED */ michael@0: + michael@0: /* This triggers a compiler error in png.c, if png.c and png.h michael@0: * do not agree upon the version number. michael@0: */ michael@0: @@ -867,6 +882,10 @@ michael@0: #define PNG_INFO_sPLT 0x2000 /* ESR, 1.0.6 */ michael@0: #define PNG_INFO_sCAL 0x4000 /* ESR, 1.0.6 */ michael@0: #define PNG_INFO_IDAT 0x8000 /* ESR, 1.0.6 */ michael@0: +#ifdef PNG_APNG_SUPPORTED michael@0: +#define PNG_INFO_acTL 0x10000 michael@0: +#define PNG_INFO_fcTL 0x20000 michael@0: +#endif michael@0: michael@0: /* This is used for the transformation routines, as some of them michael@0: * change these values for the row. It also should enable using michael@0: @@ -904,6 +923,10 @@ michael@0: #ifdef PNG_PROGRESSIVE_READ_SUPPORTED michael@0: typedef PNG_CALLBACK(void, *png_progressive_info_ptr, (png_structp, png_infop)); michael@0: typedef PNG_CALLBACK(void, *png_progressive_end_ptr, (png_structp, png_infop)); michael@0: +#ifdef PNG_APNG_SUPPORTED michael@0: +typedef PNG_CALLBACK(void, *png_progressive_frame_ptr, (png_structp, michael@0: + png_uint_32)); michael@0: +#endif michael@0: michael@0: /* The following callback receives png_uint_32 row_number, int pass for the michael@0: * png_bytep data of the row. When transforming an interlaced image the michael@0: @@ -3241,6 +3264,75 @@ michael@0: * END OF HARDWARE OPTIONS michael@0: ******************************************************************************/ michael@0: michael@0: +#ifdef PNG_APNG_SUPPORTED michael@0: +PNG_EXPORT(245, png_uint_32, png_get_acTL, (png_structp png_ptr, michael@0: + png_infop info_ptr, png_uint_32 *num_frames, png_uint_32 *num_plays)); michael@0: + michael@0: +PNG_EXPORT(246, png_uint_32, png_set_acTL, (png_structp png_ptr, michael@0: + png_infop info_ptr, png_uint_32 num_frames, png_uint_32 num_plays)); michael@0: + michael@0: +PNG_EXPORT(247, png_uint_32, png_get_num_frames, (png_structp png_ptr, michael@0: + png_infop info_ptr)); michael@0: + michael@0: +PNG_EXPORT(248, png_uint_32, png_get_num_plays, (png_structp png_ptr, michael@0: + png_infop info_ptr)); michael@0: + michael@0: +PNG_EXPORT(249, png_uint_32, png_get_next_frame_fcTL, michael@0: + (png_structp png_ptr, png_infop info_ptr, png_uint_32 *width, michael@0: + png_uint_32 *height, png_uint_32 *x_offset, png_uint_32 *y_offset, michael@0: + png_uint_16 *delay_num, png_uint_16 *delay_den, png_byte *dispose_op, michael@0: + png_byte *blend_op)); michael@0: + michael@0: +PNG_EXPORT(250, png_uint_32, png_set_next_frame_fcTL, michael@0: + (png_structp png_ptr, png_infop info_ptr, png_uint_32 width, michael@0: + png_uint_32 height, png_uint_32 x_offset, png_uint_32 y_offset, michael@0: + png_uint_16 delay_num, png_uint_16 delay_den, png_byte dispose_op, michael@0: + png_byte blend_op)); michael@0: + michael@0: +PNG_EXPORT(251, png_uint_32, png_get_next_frame_width, michael@0: + (png_structp png_ptr, png_infop info_ptr)); michael@0: +PNG_EXPORT(252, png_uint_32, png_get_next_frame_height, michael@0: + (png_structp png_ptr, png_infop info_ptr)); michael@0: +PNG_EXPORT(253, png_uint_32, png_get_next_frame_x_offset, michael@0: + (png_structp png_ptr, png_infop info_ptr)); michael@0: +PNG_EXPORT(254, png_uint_32, png_get_next_frame_y_offset, michael@0: + (png_structp png_ptr, png_infop info_ptr)); michael@0: +PNG_EXPORT(255, png_uint_16, png_get_next_frame_delay_num, michael@0: + (png_structp png_ptr, png_infop info_ptr)); michael@0: +PNG_EXPORT(256, png_uint_16, png_get_next_frame_delay_den, michael@0: + (png_structp png_ptr, png_infop info_ptr)); michael@0: +PNG_EXPORT(257, png_byte, png_get_next_frame_dispose_op, michael@0: + (png_structp png_ptr, png_infop info_ptr)); michael@0: +PNG_EXPORT(258, png_byte, png_get_next_frame_blend_op, michael@0: + (png_structp png_ptr, png_infop info_ptr)); michael@0: +PNG_EXPORT(259, png_byte, png_get_first_frame_is_hidden, michael@0: + (png_structp png_ptr, png_infop info_ptr)); michael@0: +PNG_EXPORT(260, png_uint_32, png_set_first_frame_is_hidden, michael@0: + (png_structp png_ptr, png_infop info_ptr, png_byte is_hidden)); michael@0: + michael@0: +#ifdef PNG_READ_APNG_SUPPORTED michael@0: +PNG_EXPORT(261, void, png_read_frame_head, (png_structp png_ptr, michael@0: + png_infop info_ptr)); michael@0: +#ifdef PNG_PROGRESSIVE_READ_SUPPORTED michael@0: +PNG_EXPORT(262, void, png_set_progressive_frame_fn, (png_structp png_ptr, michael@0: + png_progressive_frame_ptr frame_info_fn, michael@0: + png_progressive_frame_ptr frame_end_fn)); michael@0: +#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */ michael@0: +#endif /* PNG_READ_APNG_SUPPORTED */ michael@0: + michael@0: +#ifdef PNG_WRITE_APNG_SUPPORTED michael@0: +PNG_EXPORT(263, void, png_write_frame_head, (png_structp png_ptr, michael@0: + png_infop info_ptr, png_bytepp row_pointers, michael@0: + png_uint_32 width, png_uint_32 height, michael@0: + png_uint_32 x_offset, png_uint_32 y_offset, michael@0: + png_uint_16 delay_num, png_uint_16 delay_den, png_byte dispose_op, michael@0: + png_byte blend_op)); michael@0: + michael@0: +PNG_EXPORT(264, void, png_write_frame_tail, (png_structp png_ptr, michael@0: + png_infop info_ptr)); michael@0: +#endif /* PNG_WRITE_APNG_SUPPORTED */ michael@0: +#endif /* PNG_APNG_SUPPORTED */ michael@0: + michael@0: /* Maintainer: Put new public prototypes here ^, in libpng.3, and project michael@0: * defs, scripts/pnglibconf.h, and scripts/pnglibconf.h.prebuilt michael@0: */ michael@0: @@ -3250,7 +3342,11 @@ michael@0: * scripts/symbols.def as well. michael@0: */ michael@0: #ifdef PNG_EXPORT_LAST_ORDINAL michael@0: +#ifdef PNG_APNG_SUPPORTED michael@0: + PNG_EXPORT_LAST_ORDINAL(264); michael@0: +#else michael@0: PNG_EXPORT_LAST_ORDINAL(244); michael@0: +#endif /* PNG_APNG_SUPPORTED */ michael@0: #endif michael@0: michael@0: #ifdef __cplusplus michael@0: Index: pngpriv.h michael@0: =================================================================== michael@0: --- pngpriv.h michael@0: +++ pngpriv.h michael@0: @@ -551,6 +551,10 @@ michael@0: #define PNG_HAVE_CHUNK_AFTER_IDAT 0x2000 /* Have another chunk after IDAT */ michael@0: /* 0x4000 (unused) */ michael@0: #define PNG_IS_READ_STRUCT 0x8000 /* Else is a write struct */ michael@0: +#ifdef PNG_APNG_SUPPORTED michael@0: +#define PNG_HAVE_acTL 0x10000 michael@0: +#define PNG_HAVE_fcTL 0x20000 michael@0: +#endif michael@0: michael@0: /* Flags for the transformations the PNG library does on the image data */ michael@0: #define PNG_BGR 0x0001 michael@0: @@ -772,6 +776,16 @@ michael@0: #define png_tRNS PNG_U32(116, 82, 78, 83) michael@0: #define png_zTXt PNG_U32(122, 84, 88, 116) michael@0: michael@0: +#ifdef PNG_APNG_SUPPORTED michael@0: +#define png_acTL PNG_U32( 97, 99, 84, 76) michael@0: +#define png_fcTL PNG_U32(102, 99, 84, 76) michael@0: +#define png_fdAT PNG_U32(102, 100, 65, 84) michael@0: + michael@0: +/* For png_struct.apng_flags: */ michael@0: +#define PNG_FIRST_FRAME_HIDDEN 0x0001 michael@0: +#define PNG_APNG_APP 0x0002 michael@0: +#endif michael@0: + michael@0: /* The following will work on (signed char*) strings, whereas the get_uint_32 michael@0: * macro will fail on top-bit-set values because of the sign extension. michael@0: */ michael@0: @@ -1452,6 +1466,49 @@ michael@0: michael@0: #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */ michael@0: michael@0: +#ifdef PNG_APNG_SUPPORTED michael@0: +PNG_INTERNAL_FUNCTION(void,png_ensure_fcTL_is_valid,(png_structp png_ptr, michael@0: + png_uint_32 width, png_uint_32 height, michael@0: + png_uint_32 x_offset, png_uint_32 y_offset, michael@0: + png_uint_16 delay_num, png_uint_16 delay_den, michael@0: + png_byte dispose_op, png_byte blend_op),PNG_EMPTY); michael@0: + michael@0: +#ifdef PNG_READ_APNG_SUPPORTED michael@0: +PNG_INTERNAL_FUNCTION(void,png_handle_acTL,(png_structp png_ptr, michael@0: + png_infop info_ptr, png_uint_32 length),PNG_EMPTY); michael@0: +PNG_INTERNAL_FUNCTION(void,png_handle_fcTL,(png_structp png_ptr, michael@0: + png_infop info_ptr, png_uint_32 length),PNG_EMPTY); michael@0: +PNG_INTERNAL_FUNCTION(void,png_handle_fdAT,(png_structp png_ptr, michael@0: + png_infop info_ptr, png_uint_32 length),PNG_EMPTY); michael@0: +PNG_INTERNAL_FUNCTION(void,png_have_info,(png_structp png_ptr, michael@0: + png_infop info_ptr),PNG_EMPTY); michael@0: +PNG_INTERNAL_FUNCTION(void,png_ensure_sequence_number,(png_structp png_ptr, michael@0: + png_uint_32 length),PNG_EMPTY); michael@0: +PNG_INTERNAL_FUNCTION(void,png_read_reset,(png_structp png_ptr),PNG_EMPTY); michael@0: +PNG_INTERNAL_FUNCTION(void,png_read_reinit,(png_structp png_ptr, michael@0: + png_infop info_ptr),PNG_EMPTY); michael@0: +#ifdef PNG_PROGRESSIVE_READ_SUPPORTED michael@0: +PNG_INTERNAL_FUNCTION(void,png_progressive_read_reset,(png_structp png_ptr), michael@0: + PNG_EMPTY); michael@0: +#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */ michael@0: +#endif /* PNG_READ_APNG_SUPPORTED */ michael@0: + michael@0: +#ifdef PNG_WRITE_APNG_SUPPORTED michael@0: +PNG_INTERNAL_FUNCTION(void,png_write_acTL,(png_structp png_ptr, michael@0: + png_uint_32 num_frames, png_uint_32 num_plays),PNG_EMPTY); michael@0: +PNG_INTERNAL_FUNCTION(void,png_write_fcTL,(png_structp png_ptr, michael@0: + png_uint_32 width, png_uint_32 height, michael@0: + png_uint_32 x_offset, png_uint_32 y_offset, michael@0: + png_uint_16 delay_num, png_uint_16 delay_den, michael@0: + png_byte dispose_op, png_byte blend_op),PNG_EMPTY); michael@0: +PNG_INTERNAL_FUNCTION(void,png_write_fdAT,(png_structp png_ptr, michael@0: + png_const_bytep data, png_size_t length),PNG_EMPTY); michael@0: +PNG_INTERNAL_FUNCTION(void,png_write_reset,(png_structp png_ptr),PNG_EMPTY); michael@0: +PNG_INTERNAL_FUNCTION(void,png_write_reinit,(png_structp png_ptr, michael@0: + png_infop info_ptr, png_uint_32 width, png_uint_32 height),PNG_EMPTY); michael@0: +#endif /* PNG_WRITE_APNG_SUPPORTED */ michael@0: +#endif /* PNG_APNG_SUPPORTED */ michael@0: + michael@0: /* Added at libpng version 1.6.0 */ michael@0: #ifdef PNG_GAMMA_SUPPORTED michael@0: PNG_INTERNAL_FUNCTION(void,png_colorspace_set_gamma,(png_const_structrp png_ptr, michael@0: Index: pnginfo.h michael@0: =================================================================== michael@0: --- pnginfo.h michael@0: +++ pnginfo.h michael@0: @@ -256,5 +256,18 @@ michael@0: png_bytepp row_pointers; /* the image bits */ michael@0: #endif michael@0: michael@0: +#ifdef PNG_APNG_SUPPORTED michael@0: + png_uint_32 num_frames; /* including default image */ michael@0: + png_uint_32 num_plays; michael@0: + png_uint_32 next_frame_width; michael@0: + png_uint_32 next_frame_height; michael@0: + png_uint_32 next_frame_x_offset; michael@0: + png_uint_32 next_frame_y_offset; michael@0: + png_uint_16 next_frame_delay_num; michael@0: + png_uint_16 next_frame_delay_den; michael@0: + png_byte next_frame_dispose_op; michael@0: + png_byte next_frame_blend_op; michael@0: +#endif michael@0: + michael@0: }; michael@0: #endif /* PNGINFO_H */ michael@0: Index: pngstruct.h michael@0: =================================================================== michael@0: --- pngstruct.h michael@0: +++ pngstruct.h michael@0: @@ -409,6 +409,27 @@ michael@0: png_byte filter_type; michael@0: #endif michael@0: michael@0: +#ifdef PNG_APNG_SUPPORTED michael@0: + png_uint_32 apng_flags; michael@0: + png_uint_32 next_seq_num; /* next fcTL/fdAT chunk sequence number */ michael@0: + png_uint_32 first_frame_width; michael@0: + png_uint_32 first_frame_height; michael@0: + michael@0: +#ifdef PNG_READ_APNG_SUPPORTED michael@0: + png_uint_32 num_frames_read; /* incremented after all image data of */ michael@0: + /* a frame is read */ michael@0: +#ifdef PNG_PROGRESSIVE_READ_SUPPORTED michael@0: + png_progressive_frame_ptr frame_info_fn; /* frame info read callback */ michael@0: + png_progressive_frame_ptr frame_end_fn; /* frame data read callback */ michael@0: +#endif michael@0: +#endif michael@0: + michael@0: +#ifdef PNG_WRITE_APNG_SUPPORTED michael@0: + png_uint_32 num_frames_to_write; michael@0: + png_uint_32 num_frames_written; michael@0: +#endif michael@0: +#endif /* PNG_APNG_SUPPORTED */ michael@0: + michael@0: /* New members added in libpng-1.2.0 */ michael@0: michael@0: /* New members added in libpng-1.0.2 but first enabled by default in 1.2.0 */ michael@0: Index: pngwrite.c michael@0: =================================================================== michael@0: --- pngwrite.c michael@0: +++ pngwrite.c michael@0: @@ -127,6 +127,10 @@ michael@0: * application continues writing the PNG. So check the 'invalid' flag here michael@0: * too. michael@0: */ michael@0: +#ifdef PNG_WRITE_APNG_SUPPORTED michael@0: + if (info_ptr->valid & PNG_INFO_acTL) michael@0: + png_write_acTL(png_ptr, info_ptr->num_frames, info_ptr->num_plays); michael@0: +#endif michael@0: #ifdef PNG_GAMMA_SUPPORTED michael@0: # ifdef PNG_WRITE_gAMA_SUPPORTED michael@0: if (!(info_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) && michael@0: @@ -352,6 +356,11 @@ michael@0: if (!(png_ptr->mode & PNG_HAVE_IDAT)) michael@0: png_error(png_ptr, "No IDATs written into file"); michael@0: michael@0: +#ifdef PNG_WRITE_APNG_SUPPORTED michael@0: + if (png_ptr->num_frames_written != png_ptr->num_frames_to_write) michael@0: + png_error(png_ptr, "Not enough frames written"); michael@0: +#endif michael@0: + michael@0: #ifdef PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED michael@0: if (png_ptr->num_palette_max > png_ptr->num_palette) michael@0: png_benign_error(png_ptr, "Wrote palette index exceeding num_palette"); michael@0: @@ -2433,4 +2442,42 @@ michael@0: } michael@0: #endif /* PNG_STDIO_SUPPORTED */ michael@0: #endif /* SIMPLIFIED_WRITE */ michael@0: + michael@0: +#ifdef PNG_WRITE_APNG_SUPPORTED michael@0: +void PNGAPI michael@0: +png_write_frame_head(png_structp png_ptr, png_infop info_ptr, michael@0: + png_bytepp row_pointers, png_uint_32 width, png_uint_32 height, michael@0: + png_uint_32 x_offset, png_uint_32 y_offset, michael@0: + png_uint_16 delay_num, png_uint_16 delay_den, png_byte dispose_op, michael@0: + png_byte blend_op) michael@0: +{ michael@0: + png_debug(1, "in png_write_frame_head"); michael@0: + michael@0: + /* there is a chance this has been set after png_write_info was called, michael@0: + * so it would be set but not written. is there a way to be sure? */ michael@0: + if (!(info_ptr->valid & PNG_INFO_acTL)) michael@0: + png_error(png_ptr, "png_write_frame_head(): acTL not set"); michael@0: + michael@0: + png_write_reset(png_ptr); michael@0: + michael@0: + png_write_reinit(png_ptr, info_ptr, width, height); michael@0: + michael@0: + if ( !(png_ptr->num_frames_written == 0 && michael@0: + (png_ptr->apng_flags & PNG_FIRST_FRAME_HIDDEN) ) ) michael@0: + png_write_fcTL(png_ptr, width, height, x_offset, y_offset, michael@0: + delay_num, delay_den, dispose_op, blend_op); michael@0: + michael@0: + PNG_UNUSED(row_pointers) michael@0: +} michael@0: + michael@0: +void PNGAPI michael@0: +png_write_frame_tail(png_structp png_ptr, png_infop info_ptr) michael@0: +{ michael@0: + png_debug(1, "in png_write_frame_tail"); michael@0: + michael@0: + png_ptr->num_frames_written++; michael@0: + michael@0: + PNG_UNUSED(info_ptr) michael@0: +} michael@0: +#endif /* PNG_WRITE_APNG_SUPPORTED */ michael@0: #endif /* PNG_WRITE_SUPPORTED */ michael@0: Index: pngpread.c michael@0: =================================================================== michael@0: --- pngpread.c michael@0: +++ pngpread.c michael@0: @@ -217,6 +217,109 @@ michael@0: michael@0: chunk_name = png_ptr->chunk_name; michael@0: michael@0: +#ifdef PNG_READ_APNG_SUPPORTED michael@0: + if (png_ptr->num_frames_read > 0 && michael@0: + png_ptr->num_frames_read < info_ptr->num_frames) michael@0: + { michael@0: + if (chunk_name == png_IDAT) michael@0: + { michael@0: + /* Discard trailing IDATs for the first frame */ michael@0: + if (png_ptr->mode & PNG_HAVE_fcTL || png_ptr->num_frames_read > 1) michael@0: + png_error(png_ptr, "out of place IDAT"); michael@0: + michael@0: + if (png_ptr->push_length + 4 > png_ptr->buffer_size) michael@0: + { michael@0: + png_push_save_buffer(png_ptr); michael@0: + return; michael@0: + } michael@0: + michael@0: + png_push_crc_skip(png_ptr, png_ptr->push_length); michael@0: + png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER; michael@0: + return; michael@0: + } michael@0: + else if (chunk_name == png_fdAT) michael@0: + { michael@0: + if (png_ptr->buffer_size < 4) michael@0: + { michael@0: + png_push_save_buffer(png_ptr); michael@0: + return; michael@0: + } michael@0: + michael@0: + png_ensure_sequence_number(png_ptr, 4); michael@0: + michael@0: + if (!(png_ptr->mode & PNG_HAVE_fcTL)) michael@0: + { michael@0: + /* Discard trailing fdATs for frames other than the first */ michael@0: + if (png_ptr->num_frames_read < 2) michael@0: + png_error(png_ptr, "out of place fdAT"); michael@0: + michael@0: + if (png_ptr->push_length + 4 > png_ptr->buffer_size) michael@0: + { michael@0: + png_push_save_buffer(png_ptr); michael@0: + return; michael@0: + } michael@0: + michael@0: + png_push_crc_skip(png_ptr, png_ptr->push_length); michael@0: + png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER; michael@0: + return; michael@0: + } michael@0: + michael@0: + else michael@0: + { michael@0: + /* frame data follows */ michael@0: + png_ptr->idat_size = png_ptr->push_length - 4; michael@0: + png_ptr->mode |= PNG_HAVE_IDAT; michael@0: + png_ptr->process_mode = PNG_READ_IDAT_MODE; michael@0: + michael@0: + return; michael@0: + } michael@0: + } michael@0: + michael@0: + else if (chunk_name == png_fcTL) michael@0: + { michael@0: + if (png_ptr->push_length + 4 > png_ptr->buffer_size) michael@0: + { michael@0: + png_push_save_buffer(png_ptr); michael@0: + return; michael@0: + } michael@0: + michael@0: + png_read_reset(png_ptr); michael@0: + png_ptr->mode &= ~PNG_HAVE_fcTL; michael@0: + michael@0: + png_handle_fcTL(png_ptr, info_ptr, png_ptr->push_length); michael@0: + michael@0: + if (!(png_ptr->mode & PNG_HAVE_fcTL)) michael@0: + png_error(png_ptr, "missing required fcTL chunk"); michael@0: + michael@0: + png_read_reinit(png_ptr, info_ptr); michael@0: + png_progressive_read_reset(png_ptr); michael@0: + michael@0: + if (png_ptr->frame_info_fn != NULL) michael@0: + (*(png_ptr->frame_info_fn))(png_ptr, png_ptr->num_frames_read); michael@0: + michael@0: + png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER; michael@0: + michael@0: + return; michael@0: + } michael@0: + michael@0: + else michael@0: + { michael@0: + if (png_ptr->push_length + 4 > png_ptr->buffer_size) michael@0: + { michael@0: + png_push_save_buffer(png_ptr); michael@0: + return; michael@0: + } michael@0: + png_warning(png_ptr, "Skipped (ignored) a chunk " michael@0: + "between APNG chunks"); michael@0: + png_push_crc_skip(png_ptr, png_ptr->push_length); michael@0: + png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER; michael@0: + return; michael@0: + } michael@0: + michael@0: + return; michael@0: + } michael@0: +#endif /* PNG_READ_APNG_SUPPORTED */ michael@0: + michael@0: if (chunk_name == png_IDAT) michael@0: { michael@0: if (png_ptr->mode & PNG_AFTER_IDAT) michael@0: @@ -300,6 +403,9 @@ michael@0: michael@0: else if (chunk_name == png_IDAT) michael@0: { michael@0: +#ifdef PNG_READ_APNG_SUPPORTED michael@0: + png_have_info(png_ptr, info_ptr); michael@0: +#endif michael@0: png_ptr->idat_size = png_ptr->push_length; michael@0: png_ptr->process_mode = PNG_READ_IDAT_MODE; michael@0: png_push_have_info(png_ptr, info_ptr); michael@0: @@ -531,6 +637,30 @@ michael@0: } michael@0: #endif michael@0: michael@0: +#ifdef PNG_READ_APNG_SUPPORTED michael@0: + else if (chunk_name == png_acTL) michael@0: + { michael@0: + if (png_ptr->push_length + 4 > png_ptr->buffer_size) michael@0: + { michael@0: + png_push_save_buffer(png_ptr); michael@0: + return; michael@0: + } michael@0: + michael@0: + png_handle_acTL(png_ptr, info_ptr, png_ptr->push_length); michael@0: + } michael@0: + michael@0: + else if (chunk_name == png_fcTL) michael@0: + { michael@0: + if (png_ptr->push_length + 4 > png_ptr->buffer_size) michael@0: + { michael@0: + png_push_save_buffer(png_ptr); michael@0: + return; michael@0: + } michael@0: + michael@0: + png_handle_fcTL(png_ptr, info_ptr, png_ptr->push_length); michael@0: + } michael@0: + michael@0: +#endif /* PNG_READ_APNG_SUPPORTED */ michael@0: else michael@0: { michael@0: if (png_ptr->push_length + 4 > png_ptr->buffer_size) michael@0: @@ -732,7 +862,11 @@ michael@0: png_byte chunk_tag[4]; michael@0: michael@0: /* TODO: this code can be commoned up with the same code in push_read */ michael@0: +#ifdef PNG_READ_APNG_SUPPORTED michael@0: + if (png_ptr->buffer_size < 12) michael@0: +#else michael@0: if (png_ptr->buffer_size < 8) michael@0: +#endif michael@0: { michael@0: png_push_save_buffer(png_ptr); michael@0: return; michael@0: @@ -745,17 +879,64 @@ michael@0: png_ptr->chunk_name = PNG_CHUNK_FROM_STRING(chunk_tag); michael@0: png_ptr->mode |= PNG_HAVE_CHUNK_HEADER; michael@0: michael@0: +#ifdef PNG_READ_APNG_SUPPORTED michael@0: + if (png_ptr->chunk_name != png_fdAT && png_ptr->num_frames_read > 0) michael@0: + { michael@0: + if (png_ptr->flags & PNG_FLAG_ZSTREAM_ENDED) michael@0: + { michael@0: + png_ptr->process_mode = PNG_READ_CHUNK_MODE; michael@0: + if (png_ptr->frame_end_fn != NULL) michael@0: + (*(png_ptr->frame_end_fn))(png_ptr, png_ptr->num_frames_read); michael@0: + png_ptr->num_frames_read++; michael@0: + return; michael@0: + } michael@0: + else michael@0: + { michael@0: + if (png_ptr->chunk_name == png_IEND) michael@0: + png_error(png_ptr, "Not enough image data"); michael@0: + if (png_ptr->push_length + 4 > png_ptr->buffer_size) michael@0: + { michael@0: + png_push_save_buffer(png_ptr); michael@0: + return; michael@0: + } michael@0: + png_warning(png_ptr, "Skipping (ignoring) a chunk between " michael@0: + "APNG chunks"); michael@0: + png_crc_finish(png_ptr, png_ptr->push_length); michael@0: + png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER; michael@0: + return; michael@0: + } michael@0: + } michael@0: + else michael@0: +#endif michael@0: +#ifdef PNG_READ_APNG_SUPPORTED michael@0: + if (png_ptr->chunk_name != png_IDAT && png_ptr->num_frames_read == 0) michael@0: +#else michael@0: if (png_ptr->chunk_name != png_IDAT) michael@0: +#endif michael@0: { michael@0: png_ptr->process_mode = PNG_READ_CHUNK_MODE; michael@0: michael@0: if (!(png_ptr->flags & PNG_FLAG_ZSTREAM_ENDED)) michael@0: png_error(png_ptr, "Not enough compressed data"); michael@0: michael@0: +#ifdef PNG_READ_APNG_SUPPORTED michael@0: + if (png_ptr->frame_end_fn != NULL) michael@0: + (*(png_ptr->frame_end_fn))(png_ptr, png_ptr->num_frames_read); michael@0: + png_ptr->num_frames_read++; michael@0: +#endif michael@0: + michael@0: return; michael@0: } michael@0: michael@0: png_ptr->idat_size = png_ptr->push_length; michael@0: + michael@0: +#ifdef PNG_READ_APNG_SUPPORTED michael@0: + if (png_ptr->num_frames_read > 0) michael@0: + { michael@0: + png_ensure_sequence_number(png_ptr, 4); michael@0: + png_ptr->idat_size -= 4; michael@0: + } michael@0: +#endif michael@0: } michael@0: michael@0: if (png_ptr->idat_size && png_ptr->save_buffer_size) michael@0: @@ -833,6 +1014,15 @@ michael@0: if (!(buffer_length > 0) || buffer == NULL) michael@0: png_error(png_ptr, "No IDAT data (internal error)"); michael@0: michael@0: +#ifdef PNG_READ_APNG_SUPPORTED michael@0: + /* If the app is not APNG-aware, decode only the first frame */ michael@0: + if (!(png_ptr->apng_flags & PNG_APNG_APP) && png_ptr->num_frames_read > 0) michael@0: + { michael@0: + png_ptr->flags |= PNG_FLAG_ZSTREAM_ENDED; michael@0: + return; michael@0: + } michael@0: +#endif michael@0: + michael@0: /* This routine must process all the data it has been given michael@0: * before returning, calling the row callback as required to michael@0: * handle the uncompressed results. michael@0: @@ -1281,6 +1471,18 @@ michael@0: png_set_read_fn(png_ptr, progressive_ptr, png_push_fill_buffer); michael@0: } michael@0: michael@0: +#ifdef PNG_READ_APNG_SUPPORTED michael@0: +void PNGAPI michael@0: +png_set_progressive_frame_fn(png_structp png_ptr, michael@0: + png_progressive_frame_ptr frame_info_fn, michael@0: + png_progressive_frame_ptr frame_end_fn) michael@0: +{ michael@0: + png_ptr->frame_info_fn = frame_info_fn; michael@0: + png_ptr->frame_end_fn = frame_end_fn; michael@0: + png_ptr->apng_flags |= PNG_APNG_APP; michael@0: +} michael@0: +#endif michael@0: + michael@0: png_voidp PNGAPI michael@0: png_get_progressive_ptr(png_const_structrp png_ptr) michael@0: { michael@0: Index: pngset.c michael@0: =================================================================== michael@0: --- pngset.c michael@0: +++ pngset.c michael@0: @@ -239,6 +239,11 @@ michael@0: info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth); michael@0: michael@0: info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, width); michael@0: + michael@0: +#ifdef PNG_APNG_SUPPORTED michael@0: + /* for non-animated png. this may be overwritten from an acTL chunk later */ michael@0: + info_ptr->num_frames = 1; michael@0: +#endif michael@0: } michael@0: michael@0: #ifdef PNG_oFFs_SUPPORTED michael@0: @@ -1065,6 +1070,147 @@ michael@0: } michael@0: #endif /* PNG_sPLT_SUPPORTED */ michael@0: michael@0: +#ifdef PNG_APNG_SUPPORTED michael@0: +png_uint_32 PNGAPI michael@0: +png_set_acTL(png_structp png_ptr, png_infop info_ptr, michael@0: + png_uint_32 num_frames, png_uint_32 num_plays) michael@0: +{ michael@0: + png_debug1(1, "in %s storage function", "acTL"); michael@0: + michael@0: + if (png_ptr == NULL || info_ptr == NULL) michael@0: + { michael@0: + png_warning(png_ptr, michael@0: + "Call to png_set_acTL() with NULL png_ptr " michael@0: + "or info_ptr ignored"); michael@0: + return (0); michael@0: + } michael@0: + if (num_frames == 0) michael@0: + { michael@0: + png_warning(png_ptr, michael@0: + "Ignoring attempt to set acTL with num_frames zero"); michael@0: + return (0); michael@0: + } michael@0: + if (num_frames > PNG_UINT_31_MAX) michael@0: + { michael@0: + png_warning(png_ptr, michael@0: + "Ignoring attempt to set acTL with num_frames > 2^31-1"); michael@0: + return (0); michael@0: + } michael@0: + if (num_plays > PNG_UINT_31_MAX) michael@0: + { michael@0: + png_warning(png_ptr, michael@0: + "Ignoring attempt to set acTL with num_plays " michael@0: + "> 2^31-1"); michael@0: + return (0); michael@0: + } michael@0: + michael@0: + info_ptr->num_frames = num_frames; michael@0: + info_ptr->num_plays = num_plays; michael@0: + michael@0: + info_ptr->valid |= PNG_INFO_acTL; michael@0: + michael@0: + return (1); michael@0: +} michael@0: + michael@0: +/* delay_num and delay_den can hold any 16-bit values including zero */ michael@0: +png_uint_32 PNGAPI michael@0: +png_set_next_frame_fcTL(png_structp png_ptr, png_infop info_ptr, michael@0: + png_uint_32 width, png_uint_32 height, michael@0: + png_uint_32 x_offset, png_uint_32 y_offset, michael@0: + png_uint_16 delay_num, png_uint_16 delay_den, michael@0: + png_byte dispose_op, png_byte blend_op) michael@0: +{ michael@0: + png_debug1(1, "in %s storage function", "fcTL"); michael@0: + michael@0: + if (png_ptr == NULL || info_ptr == NULL) michael@0: + { michael@0: + png_warning(png_ptr, michael@0: + "Call to png_set_fcTL() with NULL png_ptr or info_ptr " michael@0: + "ignored"); michael@0: + return (0); michael@0: + } michael@0: + michael@0: + png_ensure_fcTL_is_valid(png_ptr, width, height, x_offset, y_offset, michael@0: + delay_num, delay_den, dispose_op, blend_op); michael@0: + michael@0: + if (blend_op == PNG_BLEND_OP_OVER) michael@0: + { michael@0: + if (!(png_ptr->color_type & PNG_COLOR_MASK_ALPHA) && michael@0: + !(png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))) michael@0: + { michael@0: + png_warning(png_ptr, "PNG_BLEND_OP_OVER is meaningless " michael@0: + "and wasteful for opaque images, ignored"); michael@0: + blend_op = PNG_BLEND_OP_SOURCE; michael@0: + } michael@0: + } michael@0: + michael@0: + info_ptr->next_frame_width = width; michael@0: + info_ptr->next_frame_height = height; michael@0: + info_ptr->next_frame_x_offset = x_offset; michael@0: + info_ptr->next_frame_y_offset = y_offset; michael@0: + info_ptr->next_frame_delay_num = delay_num; michael@0: + info_ptr->next_frame_delay_den = delay_den; michael@0: + info_ptr->next_frame_dispose_op = dispose_op; michael@0: + info_ptr->next_frame_blend_op = blend_op; michael@0: + michael@0: + info_ptr->valid |= PNG_INFO_fcTL; michael@0: + michael@0: + return (1); michael@0: +} michael@0: + michael@0: +void /* PRIVATE */ michael@0: +png_ensure_fcTL_is_valid(png_structp png_ptr, michael@0: + png_uint_32 width, png_uint_32 height, michael@0: + png_uint_32 x_offset, png_uint_32 y_offset, michael@0: + png_uint_16 delay_num, png_uint_16 delay_den, michael@0: + png_byte dispose_op, png_byte blend_op) michael@0: +{ michael@0: + if (width > PNG_UINT_31_MAX) michael@0: + png_error(png_ptr, "invalid width in fcTL (> 2^31-1)"); michael@0: + if (height > PNG_UINT_31_MAX) michael@0: + png_error(png_ptr, "invalid height in fcTL (> 2^31-1)"); michael@0: + if (x_offset > PNG_UINT_31_MAX) michael@0: + png_error(png_ptr, "invalid x_offset in fcTL (> 2^31-1)"); michael@0: + if (y_offset > PNG_UINT_31_MAX) michael@0: + png_error(png_ptr, "invalid y_offset in fcTL (> 2^31-1)"); michael@0: + if (width + x_offset > png_ptr->first_frame_width || michael@0: + height + y_offset > png_ptr->first_frame_height) michael@0: + png_error(png_ptr, "dimensions of a frame are greater than" michael@0: + "the ones in IHDR"); michael@0: + michael@0: + if (dispose_op != PNG_DISPOSE_OP_NONE && michael@0: + dispose_op != PNG_DISPOSE_OP_BACKGROUND && michael@0: + dispose_op != PNG_DISPOSE_OP_PREVIOUS) michael@0: + png_error(png_ptr, "invalid dispose_op in fcTL"); michael@0: + michael@0: + if (blend_op != PNG_BLEND_OP_SOURCE && michael@0: + blend_op != PNG_BLEND_OP_OVER) michael@0: + png_error(png_ptr, "invalid blend_op in fcTL"); michael@0: + michael@0: + PNG_UNUSED(delay_num) michael@0: + PNG_UNUSED(delay_den) michael@0: +} michael@0: + michael@0: +png_uint_32 PNGAPI michael@0: +png_set_first_frame_is_hidden(png_structp png_ptr, png_infop info_ptr, michael@0: + png_byte is_hidden) michael@0: +{ michael@0: + png_debug(1, "in png_first_frame_is_hidden()"); michael@0: + michael@0: + if (png_ptr == NULL) michael@0: + return 0; michael@0: + michael@0: + if (is_hidden) michael@0: + png_ptr->apng_flags |= PNG_FIRST_FRAME_HIDDEN; michael@0: + else michael@0: + png_ptr->apng_flags &= ~PNG_FIRST_FRAME_HIDDEN; michael@0: + michael@0: + PNG_UNUSED(info_ptr) michael@0: + michael@0: + return 1; michael@0: +} michael@0: +#endif /* PNG_APNG_SUPPORTED */ michael@0: + michael@0: #ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED michael@0: static png_byte michael@0: check_location(png_const_structrp png_ptr, int location) michael@0: Index: pngrutil.c michael@0: =================================================================== michael@0: --- pngrutil.c michael@0: +++ pngrutil.c michael@0: @@ -818,6 +818,11 @@ michael@0: filter_type = buf[11]; michael@0: interlace_type = buf[12]; michael@0: michael@0: +#ifdef PNG_READ_APNG_SUPPORTED michael@0: + png_ptr->first_frame_width = width; michael@0: + png_ptr->first_frame_height = height; michael@0: +#endif michael@0: + michael@0: /* Set internal variables */ michael@0: png_ptr->width = width; michael@0: png_ptr->height = height; michael@0: @@ -2698,6 +2703,179 @@ michael@0: } michael@0: #endif michael@0: michael@0: +#ifdef PNG_READ_APNG_SUPPORTED michael@0: +void /* PRIVATE */ michael@0: +png_handle_acTL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) michael@0: +{ michael@0: + png_byte data[8]; michael@0: + png_uint_32 num_frames; michael@0: + png_uint_32 num_plays; michael@0: + png_uint_32 didSet; michael@0: + michael@0: + png_debug(1, "in png_handle_acTL"); michael@0: + michael@0: + if (!(png_ptr->mode & PNG_HAVE_IHDR)) michael@0: + { michael@0: + png_error(png_ptr, "Missing IHDR before acTL"); michael@0: + } michael@0: + else if (png_ptr->mode & PNG_HAVE_IDAT) michael@0: + { michael@0: + png_warning(png_ptr, "Invalid acTL after IDAT skipped"); michael@0: + png_crc_finish(png_ptr, length); michael@0: + return; michael@0: + } michael@0: + else if (png_ptr->mode & PNG_HAVE_acTL) michael@0: + { michael@0: + png_warning(png_ptr, "Duplicate acTL skipped"); michael@0: + png_crc_finish(png_ptr, length); michael@0: + return; michael@0: + } michael@0: + else if (length != 8) michael@0: + { michael@0: + png_warning(png_ptr, "acTL with invalid length skipped"); michael@0: + png_crc_finish(png_ptr, length); michael@0: + return; michael@0: + } michael@0: + michael@0: + png_crc_read(png_ptr, data, 8); michael@0: + png_crc_finish(png_ptr, 0); michael@0: + michael@0: + num_frames = png_get_uint_31(png_ptr, data); michael@0: + num_plays = png_get_uint_31(png_ptr, data + 4); michael@0: + michael@0: + /* the set function will do error checking on num_frames */ michael@0: + didSet = png_set_acTL(png_ptr, info_ptr, num_frames, num_plays); michael@0: + if(didSet) michael@0: + png_ptr->mode |= PNG_HAVE_acTL; michael@0: +} michael@0: + michael@0: +void /* PRIVATE */ michael@0: +png_handle_fcTL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) michael@0: +{ michael@0: + png_byte data[22]; michael@0: + png_uint_32 width; michael@0: + png_uint_32 height; michael@0: + png_uint_32 x_offset; michael@0: + png_uint_32 y_offset; michael@0: + png_uint_16 delay_num; michael@0: + png_uint_16 delay_den; michael@0: + png_byte dispose_op; michael@0: + png_byte blend_op; michael@0: + michael@0: + png_debug(1, "in png_handle_fcTL"); michael@0: + michael@0: + png_ensure_sequence_number(png_ptr, length); michael@0: + michael@0: + if (!(png_ptr->mode & PNG_HAVE_IHDR)) michael@0: + { michael@0: + png_error(png_ptr, "Missing IHDR before fcTL"); michael@0: + } michael@0: + else if (png_ptr->mode & PNG_HAVE_IDAT) michael@0: + { michael@0: + /* for any frames other then the first this message may be misleading, michael@0: + * but correct. PNG_HAVE_IDAT is unset before the frame head is read michael@0: + * i can't think of a better message */ michael@0: + png_warning(png_ptr, "Invalid fcTL after IDAT skipped"); michael@0: + png_crc_finish(png_ptr, length-4); michael@0: + return; michael@0: + } michael@0: + else if (png_ptr->mode & PNG_HAVE_fcTL) michael@0: + { michael@0: + png_warning(png_ptr, "Duplicate fcTL within one frame skipped"); michael@0: + png_crc_finish(png_ptr, length-4); michael@0: + return; michael@0: + } michael@0: + else if (length != 26) michael@0: + { michael@0: + png_warning(png_ptr, "fcTL with invalid length skipped"); michael@0: + png_crc_finish(png_ptr, length-4); michael@0: + return; michael@0: + } michael@0: + michael@0: + png_crc_read(png_ptr, data, 22); michael@0: + png_crc_finish(png_ptr, 0); michael@0: + michael@0: + width = png_get_uint_31(png_ptr, data); michael@0: + height = png_get_uint_31(png_ptr, data + 4); michael@0: + x_offset = png_get_uint_31(png_ptr, data + 8); michael@0: + y_offset = png_get_uint_31(png_ptr, data + 12); michael@0: + delay_num = png_get_uint_16(data + 16); michael@0: + delay_den = png_get_uint_16(data + 18); michael@0: + dispose_op = data[20]; michael@0: + blend_op = data[21]; michael@0: + michael@0: + if (png_ptr->num_frames_read == 0 && (x_offset != 0 || y_offset != 0)) michael@0: + { michael@0: + png_warning(png_ptr, "fcTL for the first frame must have zero offset"); michael@0: + return; michael@0: + } michael@0: + michael@0: + if (info_ptr != NULL) michael@0: + { michael@0: + if (png_ptr->num_frames_read == 0 && michael@0: + (width != info_ptr->width || height != info_ptr->height)) michael@0: + { michael@0: + png_warning(png_ptr, "size in first frame's fcTL must match " michael@0: + "the size in IHDR"); michael@0: + return; michael@0: + } michael@0: + michael@0: + /* The set function will do more error checking */ michael@0: + png_set_next_frame_fcTL(png_ptr, info_ptr, width, height, michael@0: + x_offset, y_offset, delay_num, delay_den, michael@0: + dispose_op, blend_op); michael@0: + michael@0: + png_read_reinit(png_ptr, info_ptr); michael@0: + michael@0: + png_ptr->mode |= PNG_HAVE_fcTL; michael@0: + } michael@0: +} michael@0: + michael@0: +void /* PRIVATE */ michael@0: +png_have_info(png_structp png_ptr, png_infop info_ptr) michael@0: +{ michael@0: + if((info_ptr->valid & PNG_INFO_acTL) && !(info_ptr->valid & PNG_INFO_fcTL)) michael@0: + { michael@0: + png_ptr->apng_flags |= PNG_FIRST_FRAME_HIDDEN; michael@0: + info_ptr->num_frames++; michael@0: + } michael@0: +} michael@0: + michael@0: +void /* PRIVATE */ michael@0: +png_handle_fdAT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) michael@0: +{ michael@0: + png_ensure_sequence_number(png_ptr, length); michael@0: + michael@0: + /* This function is only called from png_read_end(), png_read_info(), michael@0: + * and png_push_read_chunk() which means that: michael@0: + * - the user doesn't want to read this frame michael@0: + * - or this is an out-of-place fdAT michael@0: + * in either case it is safe to ignore the chunk with a warning */ michael@0: + png_warning(png_ptr, "ignoring fdAT chunk"); michael@0: + png_crc_finish(png_ptr, length - 4); michael@0: + PNG_UNUSED(info_ptr) michael@0: +} michael@0: + michael@0: +void /* PRIVATE */ michael@0: +png_ensure_sequence_number(png_structp png_ptr, png_uint_32 length) michael@0: +{ michael@0: + png_byte data[4]; michael@0: + png_uint_32 sequence_number; michael@0: + michael@0: + if (length < 4) michael@0: + png_error(png_ptr, "invalid fcTL or fdAT chunk found"); michael@0: + michael@0: + png_crc_read(png_ptr, data, 4); michael@0: + sequence_number = png_get_uint_31(png_ptr, data); michael@0: + michael@0: + if (sequence_number != png_ptr->next_seq_num) michael@0: + png_error(png_ptr, "fcTL or fdAT chunk with out-of-order sequence " michael@0: + "number found"); michael@0: + michael@0: + png_ptr->next_seq_num++; michael@0: +} michael@0: +#endif /* PNG_READ_APNG_SUPPORTED */ michael@0: + michael@0: #ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED michael@0: /* Utility function for png_handle_unknown; set up png_ptr::unknown_chunk */ michael@0: static int michael@0: @@ -3955,6 +4133,38 @@ michael@0: uInt avail_in; michael@0: png_bytep buffer; michael@0: michael@0: +#ifdef PNG_READ_APNG_SUPPORTED michael@0: + png_uint_32 bytes_to_skip = 0; michael@0: + michael@0: + while (png_ptr->idat_size == 0 || bytes_to_skip != 0) michael@0: + { michael@0: + png_crc_finish(png_ptr, bytes_to_skip); michael@0: + bytes_to_skip = 0; michael@0: + michael@0: + png_ptr->idat_size = png_read_chunk_header(png_ptr); michael@0: + if (png_ptr->num_frames_read == 0) michael@0: + { michael@0: + if (png_ptr->chunk_name != png_IDAT) michael@0: + png_error(png_ptr, "Not enough image data"); michael@0: + } michael@0: + else michael@0: + { michael@0: + if (png_ptr->chunk_name == png_IEND) michael@0: + png_error(png_ptr, "Not enough image data"); michael@0: + if (png_ptr->chunk_name != png_fdAT) michael@0: + { michael@0: + png_warning(png_ptr, "Skipped (ignored) a chunk " michael@0: + "between APNG chunks"); michael@0: + bytes_to_skip = png_ptr->idat_size; michael@0: + continue; michael@0: + } michael@0: + michael@0: + png_ensure_sequence_number(png_ptr, png_ptr->idat_size); michael@0: + michael@0: + png_ptr->idat_size -= 4; michael@0: + } michael@0: + } michael@0: +#else michael@0: while (png_ptr->idat_size == 0) michael@0: { michael@0: png_crc_finish(png_ptr, 0); michael@0: @@ -3966,6 +4176,7 @@ michael@0: if (png_ptr->chunk_name != png_IDAT) michael@0: png_error(png_ptr, "Not enough image data"); michael@0: } michael@0: +#endif /* PNG_READ_APNG_SUPPORTED */ michael@0: michael@0: avail_in = png_ptr->IDAT_read_size; michael@0: michael@0: @@ -4029,6 +4240,9 @@ michael@0: michael@0: png_ptr->mode |= PNG_AFTER_IDAT; michael@0: png_ptr->flags |= PNG_FLAG_ZSTREAM_ENDED; michael@0: +#ifdef PNG_READ_APNG_SUPPORTED michael@0: + png_ptr->num_frames_read++; michael@0: +#endif michael@0: michael@0: if (png_ptr->zstream.avail_in > 0 || png_ptr->idat_size > 0) michael@0: png_chunk_benign_error(png_ptr, "Extra compressed data"); michael@0: @@ -4474,4 +4688,80 @@ michael@0: michael@0: png_ptr->flags |= PNG_FLAG_ROW_INIT; michael@0: } michael@0: + michael@0: +#ifdef PNG_READ_APNG_SUPPORTED michael@0: +/* This function is to be called after the main IDAT set has been read and michael@0: + * before a new IDAT is read. It resets some parts of png_ptr michael@0: + * to make them usable by the read functions again */ michael@0: +void /* PRIVATE */ michael@0: +png_read_reset(png_structp png_ptr) michael@0: +{ michael@0: + png_ptr->mode &= ~PNG_HAVE_IDAT; michael@0: + png_ptr->mode &= ~PNG_AFTER_IDAT; michael@0: + png_ptr->row_number = 0; michael@0: + png_ptr->pass = 0; michael@0: +} michael@0: + michael@0: +void /* PRIVATE */ michael@0: +png_read_reinit(png_structp png_ptr, png_infop info_ptr) michael@0: +{ michael@0: + png_ptr->width = info_ptr->next_frame_width; michael@0: + png_ptr->height = info_ptr->next_frame_height; michael@0: + png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->width); michael@0: + png_ptr->info_rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, michael@0: + png_ptr->width); michael@0: + if (png_ptr->prev_row) michael@0: + memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1); michael@0: +} michael@0: + michael@0: +#ifdef PNG_PROGRESSIVE_READ_SUPPORTED michael@0: +/* same as png_read_reset() but for the progressive reader */ michael@0: +void /* PRIVATE */ michael@0: +png_progressive_read_reset(png_structp png_ptr) michael@0: +{ michael@0: +#ifdef PNG_READ_INTERLACING_SUPPORTED michael@0: + /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ michael@0: + michael@0: + /* Start of interlace block */ michael@0: + static PNG_CONST png_byte png_pass_start[] = {0, 4, 0, 2, 0, 1, 0}; michael@0: + michael@0: + /* Offset to next interlace block */ michael@0: + static PNG_CONST png_byte png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1}; michael@0: + michael@0: + /* Start of interlace block in the y direction */ michael@0: + static PNG_CONST png_byte png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1}; michael@0: + michael@0: + /* Offset to next interlace block in the y direction */ michael@0: + static PNG_CONST png_byte png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2}; michael@0: + michael@0: + if (png_ptr->interlaced) michael@0: + { michael@0: + if (!(png_ptr->transformations & PNG_INTERLACE)) michael@0: + png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 - michael@0: + png_pass_ystart[0]) / png_pass_yinc[0]; michael@0: + else michael@0: + png_ptr->num_rows = png_ptr->height; michael@0: + michael@0: + png_ptr->iwidth = (png_ptr->width + michael@0: + png_pass_inc[png_ptr->pass] - 1 - michael@0: + png_pass_start[png_ptr->pass]) / michael@0: + png_pass_inc[png_ptr->pass]; michael@0: + } michael@0: + else michael@0: +#endif /* PNG_READ_INTERLACING_SUPPORTED */ michael@0: + { michael@0: + png_ptr->num_rows = png_ptr->height; michael@0: + png_ptr->iwidth = png_ptr->width; michael@0: + } michael@0: + png_ptr->flags &= ~PNG_FLAG_ZSTREAM_ENDED; michael@0: + if (inflateReset(&(png_ptr->zstream)) != Z_OK) michael@0: + png_error(png_ptr, "inflateReset failed"); michael@0: + png_ptr->zstream.avail_in = 0; michael@0: + png_ptr->zstream.next_in = 0; michael@0: + png_ptr->zstream.next_out = png_ptr->row_buf; michael@0: + png_ptr->zstream.avail_out = (uInt)PNG_ROWBYTES(png_ptr->pixel_depth, michael@0: + png_ptr->iwidth) + 1; michael@0: +} michael@0: +#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */ michael@0: +#endif /* PNG_READ_APNG_SUPPORTED */ michael@0: #endif /* PNG_READ_SUPPORTED */ michael@0: Index: pngwutil.c michael@0: =================================================================== michael@0: --- pngwutil.c michael@0: +++ pngwutil.c michael@0: @@ -898,6 +898,11 @@ michael@0: /* Write the chunk */ michael@0: png_write_complete_chunk(png_ptr, png_IHDR, buf, (png_size_t)13); michael@0: michael@0: +#ifdef PNG_WRITE_APNG_SUPPORTED michael@0: + png_ptr->first_frame_width = width; michael@0: + png_ptr->first_frame_height = height; michael@0: +#endif michael@0: + michael@0: if (!(png_ptr->do_filter)) michael@0: { michael@0: if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE || michael@0: @@ -1076,7 +1081,15 @@ michael@0: optimize_cmf(data, png_image_size(png_ptr)); michael@0: # endif michael@0: michael@0: +# ifdef PNG_WRITE_APNG_SUPPORTED michael@0: + if (png_ptr->num_frames_written == 0) michael@0: +# endif michael@0: png_write_complete_chunk(png_ptr, png_IDAT, data, size); michael@0: +# ifdef PNG_WRITE_APNG_SUPPORTED michael@0: + else michael@0: + png_write_fdAT(png_ptr, data, size); michael@0: +# endif /* PNG_WRITE_APNG_SUPPORTED */ michael@0: + michael@0: png_ptr->mode |= PNG_HAVE_IDAT; michael@0: michael@0: png_ptr->zstream.next_out = data; michael@0: @@ -1122,7 +1135,15 @@ michael@0: optimize_cmf(data, png_image_size(png_ptr)); michael@0: # endif michael@0: michael@0: +# ifdef PNG_WRITE_APNG_SUPPORTED michael@0: + if (png_ptr->num_frames_written == 0) michael@0: +# endif michael@0: png_write_complete_chunk(png_ptr, png_IDAT, data, size); michael@0: +# ifdef PNG_WRITE_APNG_SUPPORTED michael@0: + else michael@0: + png_write_fdAT(png_ptr, data, size); michael@0: +# endif /* PNG_WRITE_APNG_SUPPORTED */ michael@0: + michael@0: png_ptr->zstream.avail_out = 0; michael@0: png_ptr->zstream.next_out = NULL; michael@0: png_ptr->mode |= PNG_HAVE_IDAT | PNG_AFTER_IDAT; michael@0: @@ -1934,6 +1955,82 @@ michael@0: } michael@0: #endif michael@0: michael@0: +#ifdef PNG_WRITE_APNG_SUPPORTED michael@0: +void /* PRIVATE */ michael@0: +png_write_acTL(png_structp png_ptr, michael@0: + png_uint_32 num_frames, png_uint_32 num_plays) michael@0: +{ michael@0: + png_byte buf[8]; michael@0: + michael@0: + png_debug(1, "in png_write_acTL"); michael@0: + michael@0: + png_ptr->num_frames_to_write = num_frames; michael@0: + michael@0: + if (png_ptr->apng_flags & PNG_FIRST_FRAME_HIDDEN) michael@0: + num_frames--; michael@0: + michael@0: + png_save_uint_32(buf, num_frames); michael@0: + png_save_uint_32(buf + 4, num_plays); michael@0: + michael@0: + png_write_complete_chunk(png_ptr, png_acTL, buf, (png_size_t)8); michael@0: +} michael@0: + michael@0: +void /* PRIVATE */ michael@0: +png_write_fcTL(png_structp png_ptr, png_uint_32 width, png_uint_32 height, michael@0: + png_uint_32 x_offset, png_uint_32 y_offset, michael@0: + png_uint_16 delay_num, png_uint_16 delay_den, png_byte dispose_op, michael@0: + png_byte blend_op) michael@0: +{ michael@0: + png_byte buf[26]; michael@0: + michael@0: + png_debug(1, "in png_write_fcTL"); michael@0: + michael@0: + if (png_ptr->num_frames_written == 0 && (x_offset != 0 || y_offset != 0)) michael@0: + png_error(png_ptr, "x and/or y offset for the first frame aren't 0"); michael@0: + if (png_ptr->num_frames_written == 0 && michael@0: + (width != png_ptr->first_frame_width || michael@0: + height != png_ptr->first_frame_height)) michael@0: + png_error(png_ptr, "width and/or height in the first frame's fcTL " michael@0: + "don't match the ones in IHDR"); michael@0: + michael@0: + /* more error checking */ michael@0: + png_ensure_fcTL_is_valid(png_ptr, width, height, x_offset, y_offset, michael@0: + delay_num, delay_den, dispose_op, blend_op); michael@0: + michael@0: + png_save_uint_32(buf, png_ptr->next_seq_num); michael@0: + png_save_uint_32(buf + 4, width); michael@0: + png_save_uint_32(buf + 8, height); michael@0: + png_save_uint_32(buf + 12, x_offset); michael@0: + png_save_uint_32(buf + 16, y_offset); michael@0: + png_save_uint_16(buf + 20, delay_num); michael@0: + png_save_uint_16(buf + 22, delay_den); michael@0: + buf[24] = dispose_op; michael@0: + buf[25] = blend_op; michael@0: + michael@0: + png_write_complete_chunk(png_ptr, png_fcTL, buf, (png_size_t)26); michael@0: + michael@0: + png_ptr->next_seq_num++; michael@0: +} michael@0: + michael@0: +void /* PRIVATE */ michael@0: +png_write_fdAT(png_structp png_ptr, michael@0: + png_const_bytep data, png_size_t length) michael@0: +{ michael@0: + png_byte buf[4]; michael@0: + michael@0: + png_write_chunk_header(png_ptr, png_fdAT, (png_uint_32)(4 + length)); michael@0: + michael@0: + png_save_uint_32(buf, png_ptr->next_seq_num); michael@0: + png_write_chunk_data(png_ptr, buf, 4); michael@0: + michael@0: + png_write_chunk_data(png_ptr, data, length); michael@0: + michael@0: + png_write_chunk_end(png_ptr); michael@0: + michael@0: + png_ptr->next_seq_num++; michael@0: +} michael@0: +#endif /* PNG_WRITE_APNG_SUPPORTED */ michael@0: + michael@0: /* Initializes the row writing capability of libpng */ michael@0: void /* PRIVATE */ michael@0: png_write_start_row(png_structrp png_ptr) michael@0: @@ -3021,4 +3118,39 @@ michael@0: } michael@0: #endif michael@0: } michael@0: + michael@0: +#ifdef PNG_WRITE_APNG_SUPPORTED michael@0: +void /* PRIVATE */ michael@0: +png_write_reset(png_structp png_ptr) michael@0: +{ michael@0: + png_ptr->row_number = 0; michael@0: + png_ptr->pass = 0; michael@0: + png_ptr->mode &= ~PNG_HAVE_IDAT; michael@0: +} michael@0: + michael@0: +void /* PRIVATE */ michael@0: +png_write_reinit(png_structp png_ptr, png_infop info_ptr, michael@0: + png_uint_32 width, png_uint_32 height) michael@0: +{ michael@0: + if (png_ptr->num_frames_written == 0 && michael@0: + (width != png_ptr->first_frame_width || michael@0: + height != png_ptr->first_frame_height)) michael@0: + png_error(png_ptr, "width and/or height in the first frame's fcTL " michael@0: + "don't match the ones in IHDR"); michael@0: + if (width > png_ptr->first_frame_width || michael@0: + height > png_ptr->first_frame_height) michael@0: + png_error(png_ptr, "width and/or height for a frame greater than" michael@0: + "the ones in IHDR"); michael@0: + michael@0: + png_set_IHDR(png_ptr, info_ptr, width, height, michael@0: + info_ptr->bit_depth, info_ptr->color_type, michael@0: + info_ptr->interlace_type, info_ptr->compression_type, michael@0: + info_ptr->filter_type); michael@0: + michael@0: + png_ptr->width = width; michael@0: + png_ptr->height = height; michael@0: + png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, width); michael@0: + png_ptr->usr_width = png_ptr->width; michael@0: +} michael@0: +#endif /* PNG_WRITE_APNG_SUPPORTED */ michael@0: #endif /* PNG_WRITE_SUPPORTED */ michael@0: Index: scripts/symbols.def michael@0: =================================================================== michael@0: --- scripts/symbols.def michael@0: +++ scripts/symbols.def michael@0: @@ -249,3 +249,23 @@ michael@0: png_set_check_for_invalid_index @242 michael@0: png_get_palette_max @243 michael@0: png_set_option @244 michael@0: + png_get_acTL @245 michael@0: + png_set_acTL @246 michael@0: + png_get_num_frames @247 michael@0: + png_get_num_plays @248 michael@0: + png_get_next_frame_fcTL @249 michael@0: + png_set_next_frame_fcTL @250 michael@0: + png_get_next_frame_width @251 michael@0: + png_get_next_frame_height @252 michael@0: + png_get_next_frame_x_offset @253 michael@0: + png_get_next_frame_y_offset @254 michael@0: + png_get_next_frame_delay_num @255 michael@0: + png_get_next_frame_delay_den @256 michael@0: + png_get_next_frame_dispose_op @257 michael@0: + png_get_next_frame_blend_op @258 michael@0: + png_get_first_frame_is_hidden @259 michael@0: + png_set_first_frame_is_hidden @260 michael@0: + png_read_frame_head @261 michael@0: + png_set_progressive_frame_fn @262 michael@0: + png_write_frame_head @263 michael@0: + png_write_frame_tail @264