From c559bb58ed25ae0d6b732283afeaabb36e4b430f Mon Sep 17 00:00:00 2001 From: Glenn Randers-Pehrson Date: Thu, 5 May 2011 16:55:20 -0500 Subject: [PATCH] [devel] Added PNG_WRITE_OPTIMIZE_CMF_SUPPORTED macro to make zlib "CMF" optimization configureable. --- ANNOUNCE | 2 ++ CHANGES | 2 ++ pngwutil.c | 10 ++++++++-- scripts/pnglibconf.dfa | 6 +++++- scripts/pnglibconf.h.prebuilt | 1 + 5 files changed, 18 insertions(+), 3 deletions(-) diff --git a/ANNOUNCE b/ANNOUNCE index 642f04f0c..814d1787a 100644 --- a/ANNOUNCE +++ b/ANNOUNCE @@ -87,6 +87,8 @@ Version 1.5.3beta05 [May 5, 2011] requiring the host OS to implement snprintf. As a side effect the dependency of the tIME-supporting RFC1132 code on stdio is removed and PNG_NO_WARNINGS does actually work now. + Added PNG_WRITE_OPTIMIZE_CMF_SUPPORTED macro to make the zlib "CMF" byte + optimization configureable. Send comments/corrections/commendations to png-mng-implement at lists.sf.net: (subscription required; visit diff --git a/CHANGES b/CHANGES index 700dd3027..1aaa5b1fa 100644 --- a/CHANGES +++ b/CHANGES @@ -3346,6 +3346,8 @@ Version 1.5.3beta05 [May 5, 2011] requiring the host OS to implement snprintf. As a side effect the dependency of the tIME-supporting RFC1132 code on stdio is removed and PNG_NO_WARNINGS does actually work now. + Added PNG_WRITE_OPTIMIZE_CMF_SUPPORTED macro to make the zlib "CMF" byte + optimization configureable. Send comments/corrections/commendations to png-mng-implement at lists.sf.net (subscription required; visit diff --git a/pngwutil.c b/pngwutil.c index fb0fb1d0f..637f8b367 100644 --- a/pngwutil.c +++ b/pngwutil.c @@ -447,6 +447,7 @@ png_write_compressed_data_out(png_structp png_ptr, compression_state *comp) return; } +#ifdef PNG_WRITE_OPTIMIZE_CMF_SUPPORTED if (comp->input_len >= 2 && comp->input_len < 16384) { unsigned int z_cmf; /* zlib compression method and flags */ @@ -464,12 +465,12 @@ png_write_compressed_data_out(png_structp png_ptr, compression_state *comp) { unsigned int z_cinfo; unsigned int half_z_window_size; - png_size_t uncompressed_idat_size = comp->input_len; + png_size_t uncompressed_text_size = comp->input_len; z_cinfo = z_cmf >> 4; half_z_window_size = 1 << (z_cinfo + 7); - while (uncompressed_idat_size <= half_z_window_size && + while (uncompressed_text_size <= half_z_window_size && half_z_window_size >= 256) { z_cinfo--; @@ -506,6 +507,7 @@ png_write_compressed_data_out(png_structp png_ptr, compression_state *comp) png_error(png_ptr, "Invalid zlib compression method or flags in non-IDAT chunk"); } +#endif /* PNG_WRITE_OPTIMIZE_CMF_SUPPORTED */ /* Write saved output buffers, if any */ for (i = 0; i < comp->num_output_ptr; i++) @@ -838,7 +840,9 @@ png_write_IDAT(png_structp png_ptr, png_bytep data, png_size_t length) if (!(png_ptr->mode & PNG_HAVE_IDAT) && png_ptr->compression_type == PNG_COMPRESSION_TYPE_BASE) { +#ifdef PNG_WRITE_OPTIMIZE_CMF_SUPPORTED unsigned int z_cmf; /* zlib compression method and flags */ +#endif /* PNG_WRITE_OPTIMIZE_CMF_SUPPORTED */ #ifdef PNG_WRITE_COMPRESSED_TEXT_SUPPORTED int ret; @@ -880,6 +884,7 @@ png_write_IDAT(png_structp png_ptr, png_bytep data, png_size_t length) */ png_ptr->zstream.data_type = Z_BINARY; +#ifdef PNG_WRITE_OPTIMIZE_CMF_SUPPORTED /* Optimize the CMF field in the zlib stream. This hack of the zlib * stream is compliant to the stream specification. */ @@ -941,6 +946,7 @@ png_write_IDAT(png_structp png_ptr, png_bytep data, png_size_t length) else png_error(png_ptr, "Invalid zlib compression method or flags in IDAT"); +#endif /* PNG_WRITE_OPTIMIZE_CMF_SUPPORTED */ } png_write_chunk(png_ptr, png_IDAT, data, length); diff --git a/scripts/pnglibconf.dfa b/scripts/pnglibconf.dfa index 120291200..2366f8bb1 100644 --- a/scripts/pnglibconf.dfa +++ b/scripts/pnglibconf.dfa @@ -6,7 +6,7 @@ # com pnglibconf.h - library build configuration com -com libpng version 1.5.0 - January 6, 2011 +com libpng version 1.5.3 - (PENDING RELEASE) com com Copyright (c) 1998-2011 Glenn Randers-Pehrson com @@ -550,6 +550,9 @@ option SAVE_INT_32 requires WRITE # png_save_int_32 is required by the ancillary chunks oFFs and pCAL +# added at libpng-1.5.3 +option WRITE_OPTIMIZE_CMF requires WRITE + option READ_iCCP enables READ_COMPRESSED_TEXT option READ_iTXt enables READ_COMPRESSED_TEXT option READ_zTXt enables READ_COMPRESSED_TEXT @@ -563,6 +566,7 @@ option WRITE_iTXt enables WRITE_COMPRESSED_TEXT option WRITE_zTXt enables WRITE_COMPRESSED_TEXT option WRITE_COMPRESSED_TEXT enables WRITE_TEXT + # Turn this off to disable png_read_png() and png_write_png() and # leave the row_pointers member out of the info structure. diff --git a/scripts/pnglibconf.h.prebuilt b/scripts/pnglibconf.h.prebuilt index b240c34a8..6acb9950c 100644 --- a/scripts/pnglibconf.h.prebuilt +++ b/scripts/pnglibconf.h.prebuilt @@ -156,6 +156,7 @@ #define PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION #define PNG_WRITE_iTXt_SUPPORTED #define PNG_WRITE_oFFs_SUPPORTED +#define PNG_WRITE_OPTIMIZE_CMF_SUPPORTED #define PNG_WRITE_PACK_SUPPORTED #define PNG_WRITE_PACKSWAP_SUPPORTED #define PNG_WRITE_pCAL_SUPPORTED