diff -ru4NwbB libpng-1.5.2/Makefile.am libpng-1.5.3beta01/Makefile.am --- libpng-1.5.2/Makefile.am 2011-03-31 11:23:47.610923954 -0500 +++ libpng-1.5.3beta01/Makefile.am 2011-03-31 23:44:37.385951290 -0500 @@ -161,9 +161,9 @@ rm -f $@ dfn?.out test -z "$(CPPFLAGS)" echo "com @PNGLIB_VERSION@ STANDARD API DEFINITION" |\ $(AWK) -f ${srcdir}/scripts/options.awk out=dfn1.out\ - logunsupported=2 - ${srcdir}/scripts/pnglibconf.dfa 1>&2 + logunsupported=3 - ${srcdir}/scripts/pnglibconf.dfa 1>&2 $(AWK) -f ${srcdir}/scripts/options.awk out=dfn2.out dfn1.out 1>&2 rm dfn1.out mv dfn2.out $@ diff -ru4NwbB libpng-1.5.2/png.h libpng-1.5.3beta01/png.h --- libpng-1.5.2/png.h 2011-03-31 11:23:40.652780723 -0500 +++ libpng-1.5.3beta01/png.h 2011-03-31 23:44:30.537595171 -0500 @@ -149,8 +149,9 @@ * 1.5.1 15 10501 15.so.15.1[.0] * 1.5.2beta01-03 15 10502 15.so.15.2[.0] * 1.5.2rc01-03 15 10502 15.so.15.2[.0] * 1.5.2 15 10502 15.so.15.2[.0] + * 1.5.3beta01 15 10503 15.so.15.3[.0] * * Henceforth the source version will match the shared-library major * and minor numbers; the shared-library major version number will be * used for changes in backward compatibility, as it is intended. The @@ -1412,8 +1413,26 @@ PNG_EXPORT(73, void, png_set_compression_method, (png_structp png_ptr, int method)); +#ifdef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION +/* Also set zlib parameters for compressing non-IDAT chunks */ +PNG_EXPORT(222, void, png_set_text_compression_level, + (png_structp png_ptr, int level)); + +PNG_EXPORT(223, void, png_set_text_compression_mem_level, (png_structp png_ptr, + int mem_level)); + +PNG_EXPORT(224, void, png_set_text_compression_strategy, (png_structp png_ptr, + int strategy)); + +PNG_EXPORT(225, void, png_set_text_compression_window_bits, (png_structp + png_ptr, int window_bits)); + +PNG_EXPORT(226, void, png_set_text_compression_method, (png_structp png_ptr, + int method)); +#endif /* PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION */ + /* These next functions are called for input/output, memory, and error * handling. They are in the file pngrio.c, pngwio.c, and pngerror.c, * and call standard C I/O routines such as fread(), fwrite(), and * fprintf(). These functions can be made to use other I/O routines @@ -2296,9 +2315,9 @@ * one to use is one more than this.) Maintainer, remember to add an entry to * scripts/symbols.def as well. */ #ifdef PNG_EXPORT_LAST_ORDINAL - PNG_EXPORT_LAST_ORDINAL(221); + PNG_EXPORT_LAST_ORDINAL(226); #endif #ifdef __cplusplus } diff -ru4NwbB libpng-1.5.2/pngmem.c libpng-1.5.3beta01/pngmem.c --- libpng-1.5.2/pngmem.c 2011-03-31 11:23:40.721711366 -0500 +++ libpng-1.5.3beta01/pngmem.c 2011-03-31 23:44:30.605039805 -0500 @@ -1,8 +1,8 @@ /* pngmem.c - stub functions for memory allocation * - * Last changed in libpng 1.5.1 [February 3, 2011] + * Last changed in libpng 1.5.3 [(PENDING RELEASE)] * Copyright (c) 1998-2011 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * @@ -186,25 +186,34 @@ { int num_blocks; png_uint_32 total_size; png_bytep table; - int i; + int i, mem_level, window_bits; png_byte huge * hptr; + int window_bits if (ret != NULL) { farfree(ret); ret = NULL; } - if (png_ptr->zlib_window_bits > 14) - num_blocks = (int)(1 << (png_ptr->zlib_window_bits - 14)); + window_bits = + png_ptr->zlib_window_bits >= png_ptr->zlib_text_window_bits ? + png_ptr->zlib_window_bits : png_ptr->zlib_text_window_bits; + + if (window_bits > 14) + num_blocks = (int)(1 << (window_bits - 14)); else num_blocks = 1; - if (png_ptr->zlib_mem_level >= 7) - num_blocks += (int)(1 << (png_ptr->zlib_mem_level - 7)); + mem_level = + png_ptr->zlib_mem_level >= png_ptr->zlib_text_mem_level ? + png_ptr->zlib_mem_level : png_ptr->zlib_text_mem_level; + + if (mem_level >= 7) + num_blocks += (int)(1 << (mem_level - 7)); else num_blocks++; @@ -276,9 +285,9 @@ if (png_ptr->offset_table_count >= png_ptr->offset_table_number) { # ifndef PNG_USER_MEM_SUPPORTED if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0) - png_error(png_ptr, "Out of Memory"); /* Note "o" and "M" */ + png_error(png_ptr, "Out of Memory"); /* Note "O" and "M" */ else png_warning(png_ptr, "Out of Memory"); # endif diff -ru4NwbB libpng-1.5.2/pngpriv.h libpng-1.5.3beta01/pngpriv.h --- libpng-1.5.2/pngpriv.h 2011-03-31 11:23:40.667851883 -0500 +++ libpng-1.5.3beta01/pngpriv.h 2011-03-31 23:44:30.552446059 -0500 @@ -5,9 +5,9 @@ * Copyright (c) 1998-2011 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * - * Last changed in libpng 1.5.2 [March 31, 2011] + * Last changed in libpng 1.5.3 [(PENDING RELEASE)] * * This code is released under the libpng license. * For conditions of distribution and use, see the disclaimer * and license in png.h @@ -276,8 +276,9 @@ #define PNG_WROTE_INFO_BEFORE_PLTE 0x400 #define PNG_BACKGROUND_IS_GRAY 0x800 #define PNG_HAVE_PNG_SIGNATURE 0x1000 #define PNG_HAVE_CHUNK_AFTER_IDAT 0x2000 /* Have another chunk after IDAT */ +#define PNG_ZLIB_READY_FOR_ZTXT 0x4000 /* 1: ready for ZTXT; 0: for IDAT */ /* Flags for the transformations the PNG library does on the image data */ #define PNG_BGR 0x0001 #define PNG_INTERLACE 0x0002 @@ -344,13 +345,13 @@ #define PNG_FLAG_MALLOC_NULL_MEM_OK 0x100000L /* 0x200000L unused */ /* 0x400000L unused */ #define PNG_FLAG_BENIGN_ERRORS_WARN 0x800000L /* Added to libpng-1.4.0 */ - /* 0x1000000L unused */ - /* 0x2000000L unused */ - /* 0x4000000L unused */ - /* 0x8000000L unused */ - /* 0x10000000L unused */ +#define PNG_FLAG_ZTXT_CUSTOM_STRATEGY 0x1000000L /* 5 lines added */ +#define PNG_FLAG_ZTXT_CUSTOM_LEVEL 0x2000000L /* to libpng-1.5.3 */ +#define PNG_FLAG_ZTXT_CUSTOM_MEM_LEVEL 0x4000000L +#define PNG_FLAG_ZTXT_CUSTOM_WINDOW_BITS 0x8000000L +#define PNG_FLAG_ZTXT_CUSTOM_METHOD 0x10000000L /* 0x20000000L unused */ /* 0x40000000L unused */ #define PNG_FLAG_CRC_ANCILLARY_MASK (PNG_FLAG_CRC_ANCILLARY_USE | \ diff -ru4NwbB libpng-1.5.2/pngstruct.h libpng-1.5.3beta01/pngstruct.h --- libpng-1.5.2/pngstruct.h 2011-03-31 11:23:40.673577111 -0500 +++ libpng-1.5.3beta01/pngstruct.h 2011-03-31 23:44:30.558109932 -0500 @@ -68,8 +68,15 @@ int zlib_method; /* holds zlib compression method */ int zlib_window_bits; /* holds zlib compression window bits */ int zlib_mem_level; /* holds zlib compression memory level */ int zlib_strategy; /* holds zlib compression strategy */ +/* Added at libpng 1.5.3 */ + int zlib_text_level; /* holds zlib compression level */ + int zlib_text_method; /* holds zlib compression method */ + int zlib_text_window_bits; /* holds zlib compression window bits */ + int zlib_text_mem_level; /* holds zlib compression memory level */ + int zlib_text_strategy; /* holds zlib compression strategy */ +/* End of material added at libpng 1.5.3 */ png_uint_32 width; /* width of image in pixels */ png_uint_32 height; /* height of image in pixels */ png_uint_32 num_rows; /* number of rows in current pass */ diff -ru4NwbB libpng-1.5.2/pngtest.c libpng-1.5.3beta01/pngtest.c --- libpng-1.5.2/pngtest.c 2011-03-31 11:23:40.790873438 -0500 +++ libpng-1.5.3beta01/pngtest.c 2011-03-31 23:44:30.673452148 -0500 @@ -912,8 +912,12 @@ # endif # endif #endif +#ifdef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION + png_set_text_compression_strategy(write_ptr, Z_FILTERED); +#endif + if (status_dots_requested == 1) { #ifdef PNG_WRITE_SUPPORTED png_set_write_status_fn(write_ptr, write_row_callback); diff -ru4NwbB libpng-1.5.2/pngwrite.c libpng-1.5.3beta01/pngwrite.c --- libpng-1.5.2/pngwrite.c 2011-03-31 11:23:40.832722141 -0500 +++ libpng-1.5.3beta01/pngwrite.c 2011-03-31 23:44:30.714848416 -0500 @@ -1,8 +1,8 @@ /* pngwrite.c - general routines to write a PNG file * - * Last changed in libpng 1.5.1 [February 3, 2011] + * Last changed in libpng 1.5.3 [(PENDING RELEASE)] * Copyright (c) 1998-2011 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * @@ -1490,8 +1490,88 @@ png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_METHOD; png_ptr->zlib_method = method; } +/* The following were added to libpng-1.5.3 */ +#ifdef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION +void PNGAPI +png_set_text_compression_level(png_structp png_ptr, int level) +{ + png_debug(1, "in png_set_text_compression_level"); + + if (png_ptr == NULL) + return; + + png_ptr->flags |= PNG_FLAG_ZTXT_CUSTOM_LEVEL; + png_ptr->zlib_text_level = level; +} + +void PNGAPI +png_set_text_compression_mem_level(png_structp png_ptr, int mem_level) +{ + png_debug(1, "in png_set_text_compression_mem_level"); + + if (png_ptr == NULL) + return; + + png_ptr->flags |= PNG_FLAG_ZTXT_CUSTOM_MEM_LEVEL; + png_ptr->zlib_text_mem_level = mem_level; +} + +void PNGAPI +png_set_text_compression_strategy(png_structp png_ptr, int strategy) +{ + png_debug(1, "in png_set_text_compression_strategy"); + + if (png_ptr == NULL) + return; + + png_ptr->flags |= PNG_FLAG_ZTXT_CUSTOM_STRATEGY; + png_ptr->zlib_text_strategy = strategy; +} + +void PNGAPI +png_set_text_compression_window_bits(png_structp png_ptr, int window_bits) +{ + if (png_ptr == NULL) + return; + + if (window_bits > 15) + png_warning(png_ptr, "Only compression windows <= 32k supported by PNG"); + + else if (window_bits < 8) + png_warning(png_ptr, "Only compression windows >= 256 supported by PNG"); + +#ifndef WBITS_8_OK + /* Avoid libpng bug with 256-byte windows */ + if (window_bits == 8) + { + png_warning(png_ptr, "Text compression window is being reset to 512"); + window_bits = 9; + } + +#endif + png_ptr->flags |= PNG_FLAG_ZTXT_CUSTOM_WINDOW_BITS; + png_ptr->zlib_text_window_bits = window_bits; +} + +void PNGAPI +png_set_text_compression_method(png_structp png_ptr, int method) +{ + png_debug(1, "in png_set_text_compression_method"); + + if (png_ptr == NULL) + return; + + if (method != 8) + png_warning(png_ptr, "Only compression method 8 is supported by PNG"); + + png_ptr->flags |= PNG_FLAG_ZTXT_CUSTOM_METHOD; + png_ptr->zlib_text_method = method; +} +#endif /* PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION */ +/* end of API added to libpng-1.5.3 */ + void PNGAPI png_set_write_status_fn(png_structp png_ptr, png_write_status_ptr write_row_fn) { if (png_ptr == NULL) diff -ru4NwbB libpng-1.5.2/pngwutil.c libpng-1.5.3beta01/pngwutil.c --- libpng-1.5.2/pngwutil.c 2011-03-31 11:23:40.850911793 -0500 +++ libpng-1.5.3beta01/pngwutil.c 2011-03-31 23:44:30.732880487 -0500 @@ -1,8 +1,8 @@ /* pngwutil.c - utilities to write a PNG file * - * Last changed in libpng 1.5.0 [January 6, 2011] + * Last changed in libpng 1.5.3 [(PENDING RELEASE)] * Copyright (c) 1998-2011 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * @@ -255,11 +255,44 @@ * data, or if the input string is incredibly large (although this * wouldn't cause a failure, just a slowdown due to swapping). */ + if (!(png_ptr->mode & PNG_ZLIB_READY_FOR_ZTXT)) + { + + /* png_warning(png_ptr, "Initialize compressor for ztxt"); */ + /* Free memory from previously opened zstream */ + deflateEnd(&png_ptr->zstream); + + /* Initialize the compressor for zTXt compression. */ + ret = deflateInit2(&png_ptr->zstream, png_ptr->zlib_text_level, + png_ptr->zlib_text_method, png_ptr->zlib_text_window_bits, + png_ptr->zlib_text_mem_level, png_ptr->zlib_text_strategy); + + if (ret != Z_OK) + { + if (ret == Z_VERSION_ERROR) + png_error(png_ptr, + "zlib failed to initialize compressor for text-- version error"); + + if (ret == Z_STREAM_ERROR) + png_error(png_ptr, + "zlib failed to initialize compressor for text-- stream error"); + + if (ret == Z_MEM_ERROR) + png_error(png_ptr, + "zlib failed to initialize compressor for text-- mem error"); + + png_error(png_ptr, "zlib failed to initialize compressor for text"); + } + png_ptr->mode |= PNG_ZLIB_READY_FOR_ZTXT; + } + /* Set up the compression buffers */ + /* TODO: the following cast hides a potential overflow problem. */ png_ptr->zstream.avail_in = (uInt)text_len; + /* NOTE: assume zlib doesn't overwrite the input */ png_ptr->zstream.next_in = (Bytef *)text; png_ptr->zstream.avail_out = png_ptr->zbuf_size; png_ptr->zstream.next_out = png_ptr->zbuf; @@ -436,9 +469,8 @@ (png_size_t)(png_ptr->zbuf_size - png_ptr->zstream.avail_out)); /* Reset zlib for another zTXt/iTXt or image data */ deflateReset(&png_ptr->zstream); - png_ptr->zstream.data_type = Z_BINARY; } #endif /* Write the IHDR chunk, and update the png_struct with the necessary @@ -631,37 +663,40 @@ if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_METHOD)) png_ptr->zlib_method = 8; - ret = deflateInit2(&png_ptr->zstream, png_ptr->zlib_level, - png_ptr->zlib_method, png_ptr->zlib_window_bits, - png_ptr->zlib_mem_level, png_ptr->zlib_strategy); +#ifdef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION + if (!(png_ptr->flags & PNG_FLAG_ZTXT_CUSTOM_STRATEGY)) + png_ptr->zlib_text_strategy = Z_DEFAULT_STRATEGY; - if (ret != Z_OK) - { - if (ret == Z_VERSION_ERROR) - png_error(png_ptr, - "zlib failed to initialize compressor -- version error"); + if (!(png_ptr->flags & PNG_FLAG_ZTXT_CUSTOM_LEVEL)) + png_ptr->zlib_text_level = Z_DEFAULT_COMPRESSION; - if (ret == Z_STREAM_ERROR) - png_error(png_ptr, - "zlib failed to initialize compressor -- stream error"); + if (!(png_ptr->flags & PNG_FLAG_ZTXT_CUSTOM_MEM_LEVEL)) + png_ptr->zlib_text_mem_level = 8; - if (ret == Z_MEM_ERROR) - png_error(png_ptr, - "zlib failed to initialize compressor -- mem error"); - - png_error(png_ptr, "zlib failed to initialize compressor"); - } + if (!(png_ptr->flags & PNG_FLAG_ZTXT_CUSTOM_WINDOW_BITS)) + png_ptr->zlib_text_window_bits = 15; - png_ptr->zstream.next_out = png_ptr->zbuf; - png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; - /* libpng is not interested in zstream.data_type, so set it - * to a predefined value, to avoid its evaluation inside zlib - */ - png_ptr->zstream.data_type = Z_BINARY; + if (!(png_ptr->flags & PNG_FLAG_ZTXT_CUSTOM_METHOD)) + png_ptr->zlib_text_method = 8; +#else + png_ptr->zlib_text_strategy = Z_DEFAULT_STRATEGY; + png_ptr->zlib_text_level = Z_DEFAULT_COMPRESSION; + png_ptr->zlib_text_mem_level = 8; + png_ptr->zlib_text_window_bits = 15; + png_ptr->zlib_text_method = 8; +#endif /* PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION */ + + /* png_warning(png_ptr, "Initialize compressor for IDAT"); */ + /* Free memory from previously opened zstream */ + deflateEnd(&png_ptr->zstream); + /* Initialize the zlib compressor */ + ret = deflateInit2(&png_ptr->zstream, png_ptr->zlib_level, + png_ptr->zlib_method, png_ptr->zlib_window_bits, + png_ptr->zlib_mem_level, png_ptr->zlib_strategy); - png_ptr->mode = PNG_HAVE_IHDR; + png_ptr->mode = PNG_HAVE_IHDR; /* not READY_FOR_ZTXT */ } /* Write the palette. We are careful not to trust png_color to be in the * correct order for PNG, so people can redefine it to any convenient @@ -749,9 +784,50 @@ /* This hack of the zlib stream is compliant to the stream specification. */ if (!(png_ptr->mode & PNG_HAVE_IDAT) && png_ptr->compression_type == PNG_COMPRESSION_TYPE_BASE) { - unsigned int z_cmf = data[0]; /* zlib compression method and flags */ + int ret; + unsigned int z_cmf; /* zlib compression method and flags */ + + if (png_ptr->mode & PNG_ZLIB_READY_FOR_ZTXT) + { + /* png_warning(png_ptr, "Initialize compressor for IDAT"); */ + + /* Free memory from previously opened zstream */ + deflateEnd(&png_ptr->zstream); + + ret = deflateInit2(&png_ptr->zstream, png_ptr->zlib_level, + png_ptr->zlib_method, png_ptr->zlib_window_bits, + png_ptr->zlib_mem_level, png_ptr->zlib_strategy); + + if (ret != Z_OK) + { + if (ret == Z_VERSION_ERROR) + png_error(png_ptr, + "zlib failed to initialize compressor -- version error"); + + if (ret == Z_STREAM_ERROR) + png_error(png_ptr, + "zlib failed to initialize compressor -- stream error"); + + if (ret == Z_MEM_ERROR) + png_error(png_ptr, + "zlib failed to initialize compressor -- mem error"); + + png_error(png_ptr, "zlib failed to initialize compressor"); + } + png_ptr->mode &= ~PNG_ZLIB_READY_FOR_ZTXT; /* Ready for IDAT */ + } + + png_ptr->zstream.next_out = png_ptr->zbuf; + png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; + /* libpng is not interested in zstream.data_type, so set it + * to a predefined value, to avoid its evaluation inside zlib + */ + png_ptr->zstream.data_type = Z_BINARY; + + z_cmf = data[0]; + if ((z_cmf & 0x0f) == 8 && (z_cmf & 0xf0) <= 0x70) { /* Avoid memory underflows and multiplication overflows. * diff -ru4NwbB libpng-1.5.2/scripts/pnglibconf.dfa libpng-1.5.3beta01/scripts/pnglibconf.dfa --- libpng-1.5.2/scripts/pnglibconf.dfa 2011-02-12 09:16:01.541296000 -0600 +++ libpng-1.5.3beta01/scripts/pnglibconf.dfa 2011-03-31 20:49:07.825550000 -0500 @@ -385,8 +385,13 @@ # apps implementing the user transforms option USER_TRANSFORM_PTR if READ_USER_TRANSFORM WRITE_USER_TRANSFORM option USER_TRANSFORM_INFO if READ_USER_TRANSFORM WRITE_USER_TRANSFORM +# This enables API to set compression parameters for compressing +# non-IDAT chunks (zTXt, iTXt, iCCP, and unknown chunks). This feature +# was added at libpng-1.5.3. +option WRITE_CUSTOMIZE_ZTXT_COMPRESSION requires WRITE + # Any chunks you are not interested in, you can undef here. The # ones that allocate memory may be expecially important (hIST, # tEXt, zTXt, tRNS, pCAL). Others will just save time and make png_info # a bit smaller. diff -ru4NwbB libpng-1.5.2/scripts/pnglibconf.h.prebuilt libpng-1.5.3beta01/scripts/pnglibconf.h.prebuilt --- libpng-1.5.2/scripts/pnglibconf.h.prebuilt 2011-02-12 09:20:50.414618000 -0600 +++ libpng-1.5.3beta01/scripts/pnglibconf.h.prebuilt 2011-03-31 20:48:37.383494000 -0500 @@ -150,8 +150,9 @@ #define PNG_WRITE_INTERLACING_SUPPORTED #define PNG_WRITE_INT_FUNCTIONS_SUPPORTED #define PNG_WRITE_INVERT_ALPHA_SUPPORTED #define PNG_WRITE_INVERT_SUPPORTED +#define PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION #define PNG_WRITE_iTXt_SUPPORTED #define PNG_WRITE_oFFs_SUPPORTED #define PNG_WRITE_PACK_SUPPORTED #define PNG_WRITE_PACKSWAP_SUPPORTED