API reduction, PNG compression level

PNG compression level setting API: this allows the various compression settings
controlling deflate, fitlering, and so on to be set via a single setting with
six values.  This is currently documented in png.h ("Write compression
settings").

Internally the compression settings have been tuned both for the overall setting
and for any specific settings made by the original APIs.

APIs to control iCCP chunk compression separately have been added.

contrib/examples/pngcp.c has been modified to accomodate the new compression
setting and to include options for separate control of iCCP chunk compression.

The new ABI, png_setting, has been modified to accomodate a wider range of
settings and most of the old compression control ABIs have been replaced by
function-like macros with the same API which call png_setting.  This is an API
check in 1.7.0 for png_setting (alone).  png_setting now handles all of
png_set_option.  This eliminates 19 ABIs at the cost of adding 1 (png_setting).

CRC and benign error checking has been updated internally to use bit-fields and
the CRC calculation skip when the CRC is not used has been improved slightly to
avoid the initialization of the CRC.  A new png_setting based API allows more
detailed control of benign error/warning messages (this may change, the internal
error handling seems too complex.)  The ERROR_NUMBERS support has been removed
with the intent of implementing proper i18n.

The memcpy-size-0 issue in png_push_fill_buffer has been fixed, with an
appropriate debug() assert if a fill for 0 bytes occurs.

Most PNG_FLAG_ values for png_struct::flags have been eliminated (as a result of
the benign error handling changes).  Only one remains.

Signed-off-by: John Bowler <jbowler@acm.org>
This commit is contained in:
John Bowler
2016-06-07 06:48:52 -07:00
parent 120f80369b
commit 01ff090760
18 changed files with 1623 additions and 1086 deletions

View File

@@ -623,22 +623,16 @@
*/
#define PNG_FLAG_LIBRARY_MISMATCH 0x001U
/*#define PNG_FLAG_ZLIB_CUSTOM_STRATEGY 0x002U NO LONGER USED */
#define PNG_FLAG_CRC_ANCILLARY_USE 0x004U
#define PNG_FLAG_CRC_ANCILLARY_NOWARN 0x008U
#define PNG_FLAG_CRC_CRITICAL_USE 0x010U
#define PNG_FLAG_CRC_CRITICAL_IGNORE 0x020U
#define PNG_FLAG_STRIP_ERROR_NUMBERS 0x040U
#define PNG_FLAG_STRIP_ERROR_TEXT 0x080U
#define PNG_FLAG_IDAT_ERRORS_WARN 0x100U
#define PNG_FLAG_BENIGN_ERRORS_WARN 0x200U
#define PNG_FLAG_APP_WARNINGS_WARN 0x400U
#define PNG_FLAG_APP_ERRORS_WARN 0x800U
#define PNG_FLAG_CRC_ANCILLARY_MASK (PNG_FLAG_CRC_ANCILLARY_USE | \
PNG_FLAG_CRC_ANCILLARY_NOWARN)
#define PNG_FLAG_CRC_CRITICAL_MASK (PNG_FLAG_CRC_CRITICAL_USE | \
PNG_FLAG_CRC_CRITICAL_IGNORE)
/*#define PNG_FLAG_CRC_ANCILLARY_USE 0x004U NO LONGER USED */
/*#define PNG_FLAG_CRC_ANCILLARY_NOWARN 0x008U NO LONGER USED */
/*#define PNG_FLAG_CRC_CRITICAL_USE 0x010U NO LONGER USED */
/*#define PNG_FLAG_CRC_CRITICAL_IGNORE 0x020U NO LONGER USED */
/*#define PNG_FLAG_STRIP_ERROR_NUMBERS 0x040U NEVER USED */
/*#define PNG_FLAG_STRIP_ERROR_TEXT 0x080U NEVER USED */
/*#define PNG_FLAG_IDAT_ERRORS_WARN 0x100U NEVER SET */
/*#define PNG_FLAG_BENIGN_ERRORS_WARN 0x200U NO LONGER USED */
/*#define PNG_FLAG_APP_WARNINGS_WARN 0x400U NO LONGER USED */
/*#define PNG_FLAG_APP_ERRORS_WARN 0x800U NO LONGER USED */
#if defined(PNG_SIMPLIFIED_READ_SUPPORTED) ||\
defined(PNG_SIMPLIFIED_WRITE_SUPPORTED)
@@ -1050,8 +1044,12 @@ PNG_INTERNAL_FUNCTION(void PNGCBAPI,png_default_flush,(png_structp png_ptr),
# endif /* WRITE */
#endif /* STDIO */
/* Reset the CRC variable */
PNG_INTERNAL_FUNCTION(void,png_reset_crc,(png_structrp png_ptr),PNG_EMPTY);
/* Reset the CRC variable. The CRC is initialized with the chunk tag (4 bytes).
* NOTE: at present png_struct::chunk_name MUST be set before this as well so
* that png_struct::current_crc is initialized correctly!
*/
PNG_INTERNAL_FUNCTION(void,png_reset_crc,(png_structrp png_ptr,
png_const_bytep chunk_tag), PNG_EMPTY);
/* Write the "data" buffer to whatever output you are using */
PNG_INTERNAL_FUNCTION(void,png_write_data,(png_structrp png_ptr,
@@ -2230,6 +2228,20 @@ PNG_INTERNAL_FUNCTION(void, png_image_free, (png_imagep image), PNG_EMPTY);
#endif /* SIMPLIFIED READ/WRITE */
#ifdef PNG_READ_SUPPORTED
PNG_INTERNAL_FUNCTION(png_int_32, png_read_setting, (png_structrp png_ptr,
png_uint_32 setting, png_uint_32 parameter, png_int_32 value), PNG_EMPTY);
#endif /* READ */
#ifdef PNG_WRITE_SUPPORTED
PNG_INTERNAL_FUNCTION(png_int_32, png_write_setting, (png_structrp png_ptr,
png_uint_32 setting, png_uint_32 parameter, png_int_32 value), PNG_EMPTY);
/* Implementations of read and write settings, in pngrutil.c and pngwutil.c
* respectively.
*/
#endif /* WRITE */
/* Maintainer: Put new private prototypes here ^ */
/* These are initialization functions for hardware specific PNG filter
* optimizations; list these here then select the appropriate one at compile
* time using the macro PNG_FILTER_OPTIMIZATIONS. If the macro is not defined
@@ -2248,8 +2260,6 @@ PNG_INTERNAL_FUNCTION(void, png_init_filter_functions_neon,
(png_structp png_ptr, unsigned int bpp), PNG_EMPTY);
#endif
/* Maintainer: Put new private prototypes here ^ */
#include "pngdebug.h"
/* EXTENSION SPECIFIC FUNCTIONS */