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

@@ -285,33 +285,16 @@ setting ZLIB_HEADER default <zlib.h>
# must be made by the user)
option SET_OPTION disabled
# Run-time setting of parameters, enabled as required below
option SETTING disabled
# To support hardware specific optimizations libpng can include a hardware
# specific header at build time, this setting records the included header:
setting EXTENSION_HEADER
# These settings configure the default compression level (0-9) and 'strategy';
# strategy is as defined by the implementors of zlib. It describes the input
# data and modifies the zlib parameters in an attempt to optimize the balance
# between search and huffman encoding in the zlib algorithms. The defaults are
# the zlib.h defaults - the apparently recursive definition does not arise
# because the name of the setting is prefixed by PNG_
#
# The TEXT values are the defaults when writing compressed text (all forms)
# This setting controls the default zlib compression settings. See the
# description of the values in png.h
setting DEFAULT_COMPRESSION_LEVEL default PNG_COMPRESSION_MEDIUM
# The '@' here means to substitute the value when pnglibconf.h is built
setting ZLIB_VERNUM default @ZLIB_VERNUM
setting Z_DEFAULT_COMPRESSION default @Z_DEFAULT_COMPRESSION
# By experiment even if other strategies are favored over the zlib default it
# still comes out best for 47% of files tested; more than filtered, the next
# best, for 38.8% of files tested.
setting Z_DEFAULT_STRATEGY default @Z_DEFAULT_STRATEGY
setting Z_DEFAULT_NOFILTER_STRATEGY default @Z_DEFAULT_STRATEGY
setting TEXT_Z_DEFAULT_COMPRESSION default @Z_DEFAULT_COMPRESSION
setting TEXT_Z_DEFAULT_STRATEGY default @Z_DEFAULT_STRATEGY
# Define this to something that will stop, at least, the current thread; control
# cannot proceed beyond the PNG_ABORT operation and compilation of pngerror.c is
@@ -343,7 +326,6 @@ option WRITE_INT_FUNCTIONS disabled
#
# WARNINGS: normally on, if off no warnings are generated
# ERROR_TEXT: normally on, if off errors happen but there is no message
# ERROR_NUMBERS: unimplemented feature, therefore disabled
# BENIGN_ERRORS: support for just issuing warnings for recoverable errors
#
# BENIGN_READ_ERRORS:
@@ -360,7 +342,6 @@ option WRITE_INT_FUNCTIONS disabled
option WARNINGS
option ERROR_TEXT
option ERROR_NUMBERS disabled
option BENIGN_ERRORS
option BENIGN_WRITE_ERRORS requires BENIGN_ERRORS disabled
@@ -515,7 +496,7 @@ option READ_QUANTIZE requires READ_TRANSFORMS enables TRANSFORM_MECH
# gamma processing; and it is an enormous waste of space. You just need to
# remove the use of libpng APIs that depend on it.
option READ_GAMMA requires READ_TRANSFORMS, READ_gAMA, READ_sRGB,
enables TRANSFORM_MECH, READ_SCALE_16_TO_8, READ_EXPAND, SETTING
enables TRANSFORM_MECH, READ_SCALE_16_TO_8, READ_EXPAND
option READ_ALPHA_MODE requires READ_TRANSFORMS, READ_GAMMA, READ_BACKGROUND
option READ_BACKGROUND requires READ_TRANSFORMS, READ_STRIP_ALPHA, READ_GAMMA,
@@ -852,10 +833,8 @@ option WRITE_tEXt enables WRITE_TEXT
option WRITE_zTXt enables WRITE_TEXT
option WRITE_iTXt enables WRITE_TEXT
# This only affects support of the optional PLTE chunk in RGB and RGBA
# images. Notice that READ_ANCILLARY_CHUNKS therefore disables part
# of the regular chunk reading too.
# WARNING: unless this option is set PLTE chunks in non-palette images are
# simply discarded (with checking of the CRC, but nothing else.)
option READ_OPT_PLTE requires READ_ANCILLARY_CHUNKS
# Unknown chunk handling

View File

@@ -27,7 +27,6 @@
#define PNG_CONSOLE_IO_SUPPORTED
#define PNG_CONVERT_tIME_SUPPORTED
#define PNG_EASY_ACCESS_SUPPORTED
/*#undef PNG_ERROR_NUMBERS_SUPPORTED*/
#define PNG_ERROR_TEXT_SUPPORTED
#define PNG_FIXED_POINT_SUPPORTED
#define PNG_FLOATING_ARITHMETIC_SUPPORTED
@@ -103,7 +102,6 @@
#define PNG_SELECT_FILTER_SUPPORTED
#define PNG_SEQUENTIAL_READ_SUPPORTED
#define PNG_SETJMP_SUPPORTED
#define PNG_SETTING_SUPPORTED
#define PNG_SET_OPTION_SUPPORTED
#define PNG_SET_UNKNOWN_CHUNKS_SUPPORTED
#define PNG_SET_USER_LIMITS_SUPPORTED
@@ -192,6 +190,7 @@
/* settings */
#define PNG_ABORT { (abort()); }
#define PNG_API_RULE 0
#define PNG_DEFAULT_COMPRESSION_LEVEL PNG_COMPRESSION_MEDIUM
#define PNG_DEFAULT_GAMMA_ACCURACY 665
#define PNG_DEFAULT_READ_MACROS 1
#define PNG_GAMMA_THRESHOLD_FIXED 153
@@ -201,8 +200,6 @@
#define PNG_QUANTIZE_BLUE_BITS 5
#define PNG_QUANTIZE_GREEN_BITS 5
#define PNG_QUANTIZE_RED_BITS 5
#define PNG_TEXT_Z_DEFAULT_COMPRESSION (-1)
#define PNG_TEXT_Z_DEFAULT_STRATEGY 0
#define PNG_USER_CHUNK_CACHE_MAX 1000
#define PNG_USER_CHUNK_MALLOC_MAX 8000000
#define PNG_USER_HEIGHT_MAX 1000000
@@ -210,9 +207,6 @@
#define PNG_ZBUF_SIZE 4096
#define PNG_ZLIB_HEADER <zlib.h>
#define PNG_ZLIB_VERNUM 0
#define PNG_Z_DEFAULT_COMPRESSION (-1)
#define PNG_Z_DEFAULT_NOFILTER_STRATEGY 0
#define PNG_Z_DEFAULT_STRATEGY 0
#define PNG_sCAL_PRECISION 5
#define PNG_sRGB_PROFILE_CHECKS 2
/* end of settings */

View File

@@ -53,7 +53,6 @@ EXPORTS
png_set_strip_16 @48
png_set_quantize @49
png_set_gamma @50
png_set_flush @51
png_write_flush @52
png_start_read_image @53
png_read_update_info @54
@@ -68,14 +67,6 @@ EXPORTS
png_destroy_info_struct @63
png_destroy_read_struct @64
png_destroy_write_struct @65
png_set_crc_action @66
png_set_filter @67
png_set_filter_heuristics @68
png_set_compression_level @69
png_set_compression_mem_level @70
png_set_compression_strategy @71
png_set_compression_window_bits @72
png_set_compression_method @73
png_init_io @74
png_set_error_fn @75
png_get_error_ptr @76
@@ -108,7 +99,6 @@ EXPORTS
png_chunk_warning @106
png_benign_error @107
png_chunk_benign_error @108
png_set_benign_errors @109
png_get_valid @110
png_get_rowbytes @111
png_get_rows @112
@@ -184,7 +174,6 @@ EXPORTS
png_get_header_version @182
png_get_libpng_ver @183
png_permit_mng_features @184
png_set_strip_error_numbers @185
png_set_user_limits @186
png_get_user_width_max @187
png_get_user_height_max @188
@@ -206,7 +195,6 @@ EXPORTS
png_save_uint_32 @205
png_save_uint_16 @207
png_set_gamma_fixed @208
png_set_filter_heuristics_fixed @209
png_get_pixel_aspect_ratio_fixed @210
png_get_x_offset_inches_fixed @211
png_get_y_offset_inches_fixed @212
@@ -219,11 +207,6 @@ EXPORTS
png_process_data_pause @219
png_process_data_skip @220
png_set_expand_16 @221
png_set_text_compression_level @222
png_set_text_compression_mem_level @223
png_set_text_compression_strategy @224
png_set_text_compression_window_bits @225
png_set_text_compression_method @226
png_set_alpha_mode @227
png_set_alpha_mode_fixed @228
png_set_scale_16 @229
@@ -239,9 +222,7 @@ EXPORTS
png_image_write_to_file @239
png_image_write_to_stdio @240
png_convert_to_rfc1123_buffer @241
png_set_check_for_invalid_index @242
png_get_palette_max @243
png_set_option @244
png_image_write_to_memory @245
png_memory_format @246
png_memory_channel_depth @247