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>
png_level -1 sets the defaults for write compression/filters/IDAT size to those
used in pre-1.7 versions of libpng, producing results that with a few exceptions
are identical to earlier versions. This commit also includes an important bug
fix for the previous commit which was erroneously using the greatest sum not the
least sum of absolute values when performing filter selection.
Signed-off-by: John Bowler <jbowler@acm.org>
Palette index checking: checking on read was erroneously skipped. pngcp can now
turn off the palette index checking or fix the errors (mainly to allow
comparison with libpng 1.6, which defaulted to ignoring it). The API now
documents how the 'enabled' parameter works. On read the check is on by default
(it was apparently off in libpng 1.6) however now if explicitly turned on the
warning message is stopped, this provides better interaction with
get_palette_max at the cost of a small API change (may need to be reviewed.)
Palette size errors: invalid entries in the palette are now set to #beaded to
make the errors more obvious and allow easy detection in memory.
Read transform pipeline caching: changes to fix the palette index check (which
are erroneously cached), the pipeline can now contain multiple caches. E.g.
caching of packing of palette indices can be combined with caching of palette
RGB transforms.
Read code now checks for callbacks to read 0 data (and faults them). Fixed the
reading of PNGs with multiple 0 length IDATs that failed as a result plus the
handling of zero length unknown. (Which occurs, validly; the spurious warning
has been removed).
filter selection: the 1.6 and earlier sum of absolute differences algorithm has
been reintroduced with an option to disfavor some filters over others where the
sums are close (not yet exposed). The selection code also logs the last known
occurence of each possible byte code across multiple lines. This allows
detection of PNG images with lower bit depth than the format implies and,
therefore, allows the filtering to be turned off in those cases as well.
The default write zlib settings are still lower than libpng16. The selection
algorithm is being refined (the overall results are worse than not doing any
filtering).
Signed-off-by: John Bowler <jbowler@acm.org>
Implemented better defaulting of zlib settings based on image properties.
Implemented pass-through of png_write_rows when the rows can be used directly (a
common case) optimizing the handling of previous-row buffering.
Removed the METHODICAL filter selection method and disabled the HEURISTIC one;
the first was ridiculously slow (though useful for experiments) the second
doesn't work. Filter selection is temporarily disabled (it defaults to the
lowest numbered filter in the list; typically 'none').
New handling of compression settings (incomplete), new PNG compression level
(not yet visible in an API).
Back ported 'PNG_FAST_FILTERS' from 1.6 (in png.h).
There are minimal API changes beyond removal of the selection options. Work is
still to be done to investigate a filter selection mechanism that is at least as
good as the previous one.
Signed-off-by: John Bowler <jbowler@acm.org>
More sophisticated defaulting which helps significantly for some files along
with code to make it easier to control the compression defaults and to make the
settings honor the API calls the application makes (previously low windowBits
settings would get reset to higher values.)
Signed-off-by: John Bowler <jbowler@acm.org>
This is an API change for 1.7, albeit a quiet one; it may produce compiler
warnings but should not result in errors, unless warnings are treated as errors.
On 64-bit systems it widens the results of the various PNG_IMAGE_ macros that
return size values (component counts, byte sizes) to 64 bits. It also changes
the row_stride parameter, which is the pointer difference between adjacent rows
of the image buffer, to ptrdiff_t which is the ANSI-C90 defined type of the
difference of two pointers. The existing (1.6.22) checks for overflow are
preserved but now accomdate images that require more than 32 bits of address
space when size_t/ptrdiff_t are 64 bit types.
Signed-off-by: John Bowler <jbowler@acm.org>
This implements an API and provides a number of assist macros to allow an
application which uses the simplified API write to bypass stdio and write
directly to memory.
It also includes some warnings (png.h) and some check code to detect *possible*
overflow in the ROW_STRIDE and simplified image SIZE macros. This disallows
image width/height/format that *might* overflow. A quiet API change that limits
in-memory image size (uncompressed) to less that 4GByte and image row size
(stride) to less than 2GByte.
Signed-off-by: John Bowler <jbowler@acm.org>
The handling of tIME and text chunks on read now records the location of the
chunks relative to PLTE and IDAT. Behavior on write is unchanged except that if
the position was recorded on read it will be re-used.
This involves an ABI change to the png_text_struct; a one byte location field is
added (with the same meaning as the one used to record unknown chunk location.)
Because this field is only used on read there is no API change unless a png_info
from a libpng read is passed to a subsequent libpng write (this did not work
very well before 1.7; the tIME chunk could get duplicated.)
png_set_text ignores the new field, resetting it to the current position in the
read or write stream. On write the position is set to the next location to be
written unless the write has not started (the position is before the signature)
in which case the location is set to PNG_HAVE_PLTE|PNG_AFTER_IDAT. When the
chunk is written the position is set to the actual write location (effectively
the position is frozen.)
Signed-off-by: John Bowler <jbowler@acm.org>
This rewrites the code used previously in the heuristics to make it easier to
debug and introduces the 'methodical' method, which is intended to be an
expensive but reliable way of reducing image size.
The code in this commit does not work; the 'methodical' test for success does
not take account of data buffered inside zlib and, anyway, it changes the
results of pngtest so that the test fails. This commit is just a checkpoint of
the current state; another commit will temporarily disable the 'methodical'
code.
Signed-off-by: John Bowler <jbowler@acm.org>
Unify the compression code so that inflate calls are localized to a common
routine. Ground work for filter selection support. Minor API changes to use
void* not byte* for data parameters. Unification of some of the compression
code with the decompression code; IDAT_size replaces IDAT_read_size and
zbuffer_size, IDAT reading and writing is no longer controlled by the size of
the compression buffer.
Signed-off-by: John Bowler <jbowler@acm.org>
This commit moves code round and changes the filter write interfaces that took
png_uint_32 buffer pixel counts to unsigned int. Also moves compression code
and definitions into pngwutil.c so that the compression code is isolated from
other definitions.
Signed-off-by: John Bowler <jbowler@acm.org>
The removal of png_struct::row_buffer and png_struct::row_format from write
builds configured without filter or transform support (respectively) wasn't
complete; some of the png.c and pngwrite.c cleanup code needed to handle the
potentially removed members.
Signed-off-by: John Bowler <jbowler@acm.org>
Now that the code works consistently so that these just switch off the support
for having libpng do the interlace/deinterlace the old names make more sense,
restoring them avoids cruft in the configuration file and avoids an unnecessary
version specific change.
Signed-off-by: John Bowler <jbowler@acm.org>
commit fc4b42b1d56f95efeb1b9fe42dc35b7d98d246bb
Merge: 74516c7 9eb1413
Author: John Bowler <jbowler@acm.org>
Date: Sun Nov 22 19:37:54 2015 -0800
Merge branch 'libpng17' into libpng17-filter-enhancements
commit 74516c7257f1a28a69985684c5673caa390c700a
Author: John Bowler <jbowler@acm.org>
Date: Sun Nov 22 19:32:43 2015 -0800
Make check full pass on gcc/g++ x86_64
Signed-off-by: John Bowler <jbowler@acm.org>
commit e891e34737fc0bc9ee873a5d56b83c1e777b990c
Author: John Bowler <jbowler@acm.org>
Date: Sun Nov 22 12:01:37 2015 -0800
Checkpoint: write buffering changes
This version fails in pngvalid --size because of an error handling very narrow
images, otherwise a standard build passes make check.
Signed-off-by: John Bowler <jbowler@acm.org>
commit 457a046ebdab737eefb477126cf855e49df6de50
Author: John Bowler <jbowler@acm.org>
Date: Sun Nov 22 06:39:36 2015 -0800
Fix previous bad merge
commit b4f426c97267317637d43f41fe0b05d1659bc63d
Merge: 07b9b90 a3458a6
Author: John Bowler <jbowler@acm.org>
Date: Sun Nov 22 06:32:34 2015 -0800
Merge branch 'libpng17' into libpng17-filter-enhancements
commit 07b9b90dfd653b744dbc3710b096facf6b4605f6
Merge: ed43306 5592e0b
Author: John Bowler <jbowler@acm.org>
Date: Sat Nov 21 17:07:23 2015 -0800
Merge branch 'libpng17' into libpng17-filter-enhancements
commit ed43306599f7039a90187862db82273fca3a4c3d
Merge: 772aed7 d3c0359
Author: John Bowler <jbowler@acm.org>
Date: Tue Nov 17 17:47:26 2015 -0800
Merge branch 'libpng17' into libpng17-filter-enhancements
commit 772aed72378df9c8fccc5a4594b095d02d410a9c
Merge: 73ae431 801608f
Author: John Bowler <jbowler@acm.org>
Date: Mon Nov 16 14:26:38 2015 -0800
Merge branch 'libpng17' into libpng17-filter-enhancements
commit 73ae4316cb6db7d7f6756583a1c213c35ca4e3f4
Merge: 687e6e3 c09b3ab
Author: John Bowler <jbowler@acm.org>
Date: Sun Nov 15 09:31:30 2015 -0800
Merge branch 'libpng17' into libpng17-filter-enhancements
commit 687e6e393e9d0220c2a12ec474aa01b83c5e9f25
Merge: fedd6da e916d9b
Author: John Bowler <jbowler@acm.org>
Date: Thu Nov 5 08:45:14 2015 -0800
Merge branch 'libpng17' into libpng17-filter-enhancements
commit fedd6da8798a14b2e002b0bc1379f5a09a03598a
Merge: 2e2fc5f ea41fd2
Author: John Bowler <jbowler@acm.org>
Date: Tue Nov 3 21:05:01 2015 -0800
Merge branch 'libpng17' into libpng17-filter-enhancements
commit 2e2fc5f6d7678b710c52b7ea081ac4add677d8d5
Merge: 990d5f8 5b05197
Author: John Bowler <jbowler@acm.org>
Date: Mon Oct 12 08:28:30 2015 -0700
Merge branch 'libpng17' into libpng17-filter-enhancements
commit 990d5f88688635dc0888657b689e30ffe7e7a7b3
Author: John Bowler <jbowler@acm.org>
Date: Sun Oct 4 17:04:53 2015 -0700
Read row buffer changes
The read code now allocates one row buffer of the size of the input PNG row and,
only if required, one buffer of the size of the output.
The output buffer is required for the progressive reader (always) and for the
sequential reader if libpng is de-interlacing an image (because the output row
is used multiple times if png_read_row is called with a display row parameter.)
This should reduce memory utilization by libpng significantly, but it has no
detectable effect on overall performance figures of the test programs, these are
probably dominated by memory allocations for the whole image within the test
programs.
Signed-off-by: John Bowler <jbowler@acm.org>
commit 527bf989bf0e30440f9e07a5544a6ebb1d6fd039
Merge: 50ebbc2 9099254
Author: John Bowler <jbowler@acm.org>
Date: Sat Oct 3 13:39:17 2015 -0700
Merge branch 'libpng17' into libpng17-filter-enhancements
commit 50ebbc2c9a24cf1a6b428db53d55fbd5af4d6be6
Merge: 21a7f40 2cd6d56
Author: John Bowler <jbowler@acm.org>
Date: Sat Oct 3 11:16:32 2015 -0700
Merge branch 'libpng17' into libpng17-filter-enhancements
commit 21a7f401ab40c79ead9e35882a8066e2cf1d6902
Merge: b512e1c 15a143e
Author: John Bowler <jbowler@acm.org>
Date: Wed Sep 30 19:01:23 2015 -0700
Merge branch 'libpng17' into libpng17-filter-enhancements
commit b512e1c2c5bfe6df8b6dca32f862d325ec22115e
Author: John Bowler <jbowler@acm.org>
Date: Wed Sep 30 17:33:34 2015 -0700
Transform rewrite: perform transforms in small chunks
The intent of this change is to reduce the memory footprint during transform
sequences by performing transforms in fixed (small) sized blocks of pixels.
The change is incomplete; the filter code still works row-by-row, so the whole
tranform also works row-by-row, the intent is to fix this so that everything
works in small(ish) chunks.
At present the change has no discernable effect on pngvalid --speed or pngstest
with (e.g.) rgb-8-1.8.png; user time and (minor) page faults are the same in old
and new versions. The same applies to real-world 15MP PNG images; even on these
the presence of the filter code causes a cyclical progress through memory which
will interfere with any caching otherwise possible (useful word, 'otherwise'.)
Signed-off-by: John Bowler <jbowler@acm.org>
commit 781cb3699b92beb0e6bc5e03cef8fba820267082
Author: John Bowler <jbowler@acm.org>
Date: Wed Sep 30 17:12:53 2015 -0700
Fix NO_WRITE_INTERLACE in pngvalid.c
The support for writing interlaced images directly from libpng 1.7 was
unintentionally disabled (INTERLACE_LAST was defined incorrectly, excluding the
interlaced images). This obscured the fact that the transform and error test
case generators lacked the support for writing interlaced images from libpng.
Signed-off-by: John Bowler <jbowler@acm.org>
commit 406ee2fd7946a384f1d7713712dc646080c5c52c
Author: John Bowler <jbowler@acm.org>
Date: Wed Sep 30 17:11:40 2015 -0700
Add pngvalid --transform --interlace test
This increases code coverage by generating test cases with smaller length rows
as a result of the interlacing. Without this packswap handling was incompletely
tested.
Signed-off-by: John Bowler <jbowler@acm.org>
Signed-off-by: John Bowler <jbowler@acm.org>
This implements a new chunk parse implementation that can be shared, it
is currently shared by the progressive reader and the sequential one
(not, yet, the writer).
The patch also implements shared transform handling that is used
throughout.
Signed-off-by: John Bowler <jbowler@acm.org>
compiled library size. It never worked properly and as far as we can
tell, no one uses it. The png_set_filter_heuristics() and
png_set_filter_heuristics_fixed() APIs are retained but deprecated.
internal struct (png_transform_control) to replace row_info and uses
that to implement affirms correctly. The change also adds checks on
the rowbytes calculation and additional checks on most transform
implementations.
Added png_uint_16 range checking, pngvalid tRNS, fixed png_uint_16:
review of previous checks, removal of some where SAFE. pngvalid: add
testing of tRNS for better code coverage pngvalid: correct rgb-to-gray
error calculations. Code coverage is still incomplete: see /*UNTESTED*/
in pngrtran.c
added RELEASE/!RELEASE convenience macros. png_muldiv_warn was used in
only one place, and the overflow condition is a genuine warning not
an internal error. Four macros allow code or function parameters to be
condition on RELEASE (or not) builds and tidy up the #ifdef handling of
functions.
where the code depended on the build base type and can be defined on
the command line, allowing testing in beta builds. Overflows previously
handled by png_warning in png.c have been changed to use new
macros/affirm functions so that beta builds will abort on overflow and
release builds will quietly ignore it. This avoids release builds
producing warnings that are of no use to end users.
Added 'assert' based overflow checking for debug builds for char
and short assignments. Simply ignore the error in release builds
(a truncated value will be used without warning). Controlled by
PNG_RANGE_CHECK_SUPPORTED.
single try_row buffer and in cases where two or more of those are
being tested, a second tst_row buffer. This improves CPU speed
over that achieved by libpng-1.7.0beta49.
Removed "option READ_COMPRESSED_TEXT enables READ_TEXT" from pnglibconf.dfa,
to make it possible to configure a libpng that supports iCCP but not TEXT.
Removed "option WRITE_COMPRESSED_TEXT enables WRITE_TEXT" from pnglibconf.dfa
Only mark text chunks as written after successfully writing them.
Added "option READ_iCCP enables READ_COMPRESSED_TEXT" to pnglibconf.dfa
Removed unused "text_len" parameter from private function png_write_zTXt().
Conditionally compile some code in png_deflate_claim(), when
PNG_WARNINGS_SUPPORTED and PNG_ERROR_TEXT_SUPPORTED are disabled.
Replaced repeated code in pngpread.c with PNG_PUSH_SAVE_BUFFER_IF_FULL.
Added "chunk iTXt enables TEXT" and "chunk zTXt enables TEXT"
to pnglibconf.dfa.
Edit and fix typos in comments.
PNG_TRANSFORM_* values are always defined in png.h and, because they
are used for both read and write in some cases, it is not reliable
to #if out ones that are totally unsupported. This change adds error
detection in png_read_image() and png_write_image() to do a
png_app_error() if the app requests something that cannot be done
and it adds corresponding code to pngimage.c to handle such options
by not attempting to test them.
function definitions before the place where they are called so that
they can be masde static. Move the intrapixel functions and the
grayscale palette builder out of the png?tran.c files. The latter
isn't a transform function and is no longer used internally, and the
former MNG specific functions are better placed in pngread/pngwrite.c
Fixed 'minimal' builds. Various obviously useful minimal configurations
don't build because of missing contrib/libtests test programs and overly
complex dependencies in scripts/pnglibconf.dfa. This change adds
contrib/conftest/*.dfa files that can be used in automatic build
scripts to ensure that these configurations continue to build.
Enabled WRITE_INVERT and WRITE_PACK in contrib/pngminim/encoder.
by earlier versions of GCC fixed for Cygwin and Min/GW (which both use old GCCs.)
ARM support is enabled by default in zlib.props (unsupported by Microsoft) and
ARM compilation is made possible by deleting the check for x86. The test programs
cannot be run because they are not signed.