Compare commits

...

47 Commits

Author SHA1 Message Date
Glenn Randers-Pehrson
f7b1d9a172 [libpng17] Imported from libpng-1.7.0beta82.tar 2016-07-04 14:30:52 -05:00
Glenn Randers-Pehrson
ce67b437ea [libpng17] Fixed two Coverity issues in pngcp.c. 2016-07-04 12:30:10 -05:00
Glenn Randers-Pehrson
86a3c4fb14 [libpng17] Don't call png_icc_set_sRGB() when it's not compiled. 2016-07-03 10:26:38 -05:00
Glenn Randers-Pehrson
4b846be113 [libpng17] Relocated misplaced #endif in png.c sRGB profile checking. 2016-07-02 21:33:25 -05:00
Glenn Randers-Pehrson
b9d7d5525b [libpng17] Added "Common linking failures" section to INSTALL 2016-07-02 12:01:27 -05:00
John Bowler
0ecbe53243 pngimage: correct #define checking
In libpng 1.7 pngimage needs to check PNG_WRITE_PNG_SUPPORTED (new in 1.7), not
PNG_WRITE_SUPPORTED because png_write_png can be disabled without disabling
PNG_WRITE_SUPPORTED.  Copied the approach from 1.6 pngcp.c (so this still works
in 1.6 as well.)
2016-07-02 07:37:37 -07:00
Glenn Randers-Pehrson
53bda5a7af [libpng17] Sync contrib/libtests/pngimage.c with libpng16; update CHANGES and ANNOUNCE 2016-07-02 08:53:21 -05:00
John Bowler
6a574a84bd pngcp minimal configuration changes
Corrections for the pngcp minimal configuration in libpng 1.7 and corrections to
the libpng 1.7 code to fix bugs revealed by the reduced configuration.

Signed-off-by: John Bowler <jbowler@acm.org>
2016-07-01 22:39:13 -07:00
John Bowler
eaf7abfdc3 pngcp: tool to copy PNG files
This adds pngcp to the build together with a pngcp.dfa configuration test; the
test revealed some configuration bugs which are fixed by corrections to the
_SUPPORTED macros.

pngcp builds on all tested configurations and a number of bugs have been fixed
to make this happen relative to the version in libpng 1.7 contrib/examples.
pngcp.dfa will have to be different for 1.7 but pngcp.c should work fine (not
yet tested).  pngcp itself is still missing a usage message; this is a
preliminary version, although since it behaves the same way as 'cp' most unoids
shouldn't have a problem using it correctly.

Signed-off-by: John Bowler <jbowler@acm.org>
2016-07-01 11:44:08 -07:00
John Bowler
0f5992051f Move pngcp to contrib/tools
Signed-off-by: John Bowler <jbowler@acm.org>
2016-07-01 11:38:03 -07:00
Glenn Randers-Pehrson
12c3c2e136 [libpng17] Sync pngvalid.c with libpng16; update CHANGES and ANNOUNCE 2016-06-24 21:36:29 -05:00
Glenn Randers-Pehrson
d6037dcb09 [libpng17] Update CHANGES and ANNOUNCE 2016-06-23 12:14:15 -05:00
John Bowler
9dfdb2270b SKIP definition in pngstest.c misplaced
The SKIP definition needs to come after the png.h include (see all the other .c
files in contrib/libtests) because it depends on PNG_LIBPNG_VER.  This commit
puts it in the correct place.

Signed-off-by: John Bowler <jbowler@acm.org>
2016-06-23 09:13:10 -07:00
Glenn Randers-Pehrson
29be8f11ed [libpng17] Bump version to 1.7.0beta82 2016-06-11 18:47:04 -05:00
Glenn Randers-Pehrson
8592a85535 [libpng17] Imported from libpng-1.7.0beta81.tar 2016-06-11 18:46:56 -05:00
John Bowler
b21a37323f [libpng17] Avoid potential overflow of the PNG_IMAGE_SIZE macro. This macro
is not used within libpng, but is used in some of the examples.
2016-06-11 14:21:08 -05:00
John Bowler
7a0fe97841 Change image size checks
This covers the case where PNG_IMAGE_BUFFER_SIZE can overflow in the application
as a result of the application using an increased 'row_stride'; previously
png_image_finish_read only checked for overflow on the base calculation of
components.  (I.e. it checked for overflow of a png_alloc_size_t number on the
total number of pixel components in the output format, not the possibly padded
row length and not the number of bytes, which for linear formats is twice the
number of components.)
2016-06-11 10:12:59 -07:00
Glenn Randers-Pehrson
9a137f332f [libpng17] Update CHANGES and ANNOUNCE 2016-06-08 13:45:37 -05:00
John Bowler
8c8aea7fd4 png_app_warning fix
The implementations of png_app_error and png_app_warning were swapped.  The
non-release behavior of using PNG_ERROR on both doesn't work in practice because
there are some cases where the warnings are very mild (specifically the one
about writing an iCCP chunk when sRGB could be used.)  png_app_warning now does
PNG_WARN by default in all cases.

Signed-off-by: John Bowler <jbowler@acm.org>
2016-06-08 10:43:25 -07:00
John Bowler
d52c8eba99 Compression changes/fixes
Simplified API: change handling of PNG_IMAGE_FLAG_FAST to use
PNG_COMPRESSION_HIGH_SPEED, and PNG_COMPRESSION_HIGH otherwise.

Compression: add missing break statements that caused some compression settings
to fall through to the 'HIGH' setting.

Internal: remove png_struct::flags, it only stored the 'library mismatch' flag
and that could never be accessed (because immediately after it was set the
png_struct, which was on the stack, was eliminated.)

Signed-off-by: John Bowler <jbowler@acm.org>
2016-06-08 08:37:20 -07:00
Glenn Randers-Pehrson
b70b51ba17 [libpng17] Update CHANGES and ANNOUNCE 2016-06-07 14:46:42 -05:00
John Bowler
2b711a751c LOW_MEMORY and COMPAT bug fixes
The LOW_MEMORY PNG_COMPRESSION option should not be setting HUFFMAN_ONLY or
using a low deflate 'level'; according to the comments in zconf.h only
windowBits and memLevel affect the memory.  pngwutil.c has been changed to use
the same values as HIGH compression.

The COMPAT option turned on the old optimize_cmf code (now in fix_cinfo),
however there was a serious bug in that code; it put the wrong value in z_cmf.
The setting was also not handled correctly in pz_compression_settings.

pngtest now verifies the operation of COMPAT and, as a result, pngtest.png has
been reverted to the libpng 1.6 (etc) version.

IDAT size handling has been improved; if not explicitly set values appropriate
to png_level are now chosen (in addition to the handling for the COMPAT
setting).  HIGH and HIGH_READ_SPEED now create unlimited size IDAT chunks, which
requires buffering the whole of the IDAT data in memory but reflects what other
programs and optimizers do.

Signed-off-by: John Bowler <jbowler@acm.org>
2016-06-07 11:27:23 -07:00
Glenn Randers-Pehrson
2e68f96511 [libpng17] Update link to RFC-2083 in png.5 2016-06-07 11:03:26 -05:00
Glenn Randers-Pehrson
8c7b59f2b9 [libpng17] Update CHANGES and ANNOUNCE, fixed several new typos 2016-06-07 11:02:07 -05:00
John Bowler
01ff090760 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>
2016-06-07 06:48:52 -07:00
Glenn Randers-Pehrson
120f80369b [libpng17] Port contrib/libtests/pngvalid.c from libpng16. 2016-05-31 10:14:08 -05:00
John Bowler
1982dc6c2f Back-port 1.6 pngvalid.c
No changes; files are identical

Signed-off-by: John Bowler <jbowler@acm.org>
2016-05-29 09:28:39 -07:00
Glenn Randers-Pehrson
a1296131fe [libpng17] Refactored duplicate coded in png_set_check_for_invalid_index()
to quiet a Coverity issue and save a few bytes of code.
2016-05-22 14:42:14 -05:00
Glenn Randers-Pehrson
5095b2adfb [libpng17] Update CHANGES and ANNOUNCE 2016-05-21 13:26:51 -05:00
John Bowler
5b19ac3019 Write fine tuning
Fine tuning of options so that the default settings are comparable with 1.6;
test set sizes are about 2% greater than 1.6 because of the use of FAST rather
than ALL filters (this mainly affects RGB images).

Signed-off-by: John Bowler <jbowler@acm.org>
2016-05-21 08:41:44 -07:00
John Bowler
a5b340e20b timepng: fix builds in certain 1.7 configs
Libpng 1.7 supports read without PNG de-interlace, however this means the old
checks on whether contrib/libtests/timepng.c (just checking for sequential read)
are inadequate.  1.7 also provides macros to explicitly turn off png_read_png
and png_read_image, so use these instead.

Signed-off-by: John Bowler <jbowler@acm.org>
2016-05-21 08:40:04 -07:00
John Bowler
21f92eef89 timepng.c: check for clock_gettime
Signed-off-by: John Bowler <jbowler@acm.org>
2016-05-18 08:42:21 -07:00
John Bowler
bf101dcea1 Merge branch 'libpng17' into 20160506-write 2016-05-18 08:41:15 -07:00
John Bowler
764ae3995b Filter tuning, legacy option
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>
2016-05-16 22:59:20 -07:00
Glenn Randers-Pehrson
bd6fb5534f [libpng17] Update Makefile.am, fix typo in timepng.c 2016-05-16 19:39:55 -05:00
Glenn Randers-Pehrson
f05407d292 [libpng17] Check for CLOCK_PROCESS_CPUTIME_ID in /contrib/libtests/timepng.
Otherwise it does not build on platforms that don't supply clock_gettime().
2016-05-16 18:59:47 -05:00
John Bowler
5652acdd48 Filter selection, palette index checks
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>
2016-05-15 16:32:01 -07:00
John Bowler
cf46e3748f Implement base filter selection
Row buffering and a crude code-count algorithm.

Signed-off-by: John Bowler <jbowler@acm.org>
2016-05-14 18:08:25 -07:00
John Bowler
52c9e4fdd6 signed/unsigned warning fix (GCC 4.8.5)
Signed-off-by: John Bowler <jbowler@acm.org>
2016-05-09 16:36:15 -07:00
John Bowler
4905ed4aae Reenable filter selection (dummy)
This implements the code for row-by-row filter selection but does not provide an
actual implementation; the selection function just chooses the lowest set filter
bit.

Signed-off-by: John Bowler <jbowler@acm.org>
2016-05-09 13:08:50 -07:00
Glenn Randers-Pehrson
ba356b4e4d [libpng17] Bump version to 1.7.0beta81 2016-05-07 15:45:03 -05:00
Glenn Randers-Pehrson
d23207b866 [libpng17] Imported from libpng-1.7.0beta80.tar 2016-05-07 15:44:55 -05:00
John Bowler
a70f5053de [libpng17] Update CHANGES and ANNOUNCE about pngcp; sync timepng.c with libpng16 2016-05-06 19:09:58 -05:00
John Bowler
4cc89fb733 Minor write bug-fixes, remove unimplemented code
A debug() assert fired if windowBits was set to 8 for the Huffman only and
no-compression cases.  This commit changes it to do some extra checking.  Remove
unreachable code in pz_default_settings, eliminate a spurious warning in pngcp
for small files.

Signed-off-by: John Bowler <jbowler@acm.org>
2016-05-06 14:35:35 -07:00
Glenn Randers-Pehrson
e966fac5ac [libpng17] Update CHANGES and ANNOUNCE for Write code update (John Bowler) 2016-05-04 22:02:52 -05:00
John Bowler
cde9b583a8 Write code update
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>
2016-05-04 17:02:20 -07:00
Glenn Randers-Pehrson
1fd42d849d [libpng17] Bump version to 1.7.0beta80 2016-03-09 12:05:09 -06:00
50 changed files with 5737 additions and 2858 deletions

142
ANNOUNCE
View File

@@ -1,5 +1,5 @@
Libpng 1.7.0beta79 - March 9, 2016
Libpng 1.7.0beta82 - July 4, 2016
This is not intended to be a public release. It will be replaced
within a few weeks by a public version or by another test version.
@@ -9,20 +9,20 @@ Files available for download:
Source files with LF line endings (for Unix/Linux) and with a
"configure" script
1.7.0beta79.tar.xz (LZMA-compressed, recommended)
1.7.0beta79.tar.gz
1.7.0beta82.tar.xz (LZMA-compressed, recommended)
1.7.0beta82.tar.gz
Source files with CRLF line endings (for Windows), without the
"configure" script
/scratch/glennrp/Libpng17/lp170b79.7z (LZMA-compressed, recommended)
/scratch/glennrp/Libpng17/lp170b79.zip
/scratch/glennrp/Libpng17/lp170b82.7z (LZMA-compressed, recommended)
/scratch/glennrp/Libpng17/lp170b82.zip
Other information:
1.7.0beta79-README.txt
1.7.0beta79-LICENSE.txt
libpng-1.7.0beta79-*.asc (armored detached GPG signatures)
1.7.0beta82-README.txt
1.7.0beta82-LICENSE.txt
libpng-1.7.0beta82-*.asc (armored detached GPG signatures)
Changes since the last public release (1.6.0):
@@ -1264,6 +1264,132 @@ Version 1.7.0beta79 [March 9, 2016]
(Robert C. Seacord). Various other flags in png.h made unsigned as well.
Fixed some misleading indentation (Krishnaraj Bhat).
Version 1.7.0beta80 [May 6, 2016]
Fixed typo (missing underscore) in #define PNG_READ_16_TO_8_SUPPORTED
Bug report by (Y.Ohashik).
Quieted two Coverity issues in contrib/libtests/timepng.c.
Write code update (John Bowler):
Implemented better defaulting of zlib settings based on image properties.
Replaced pngtest.png with one compressed with the new zlib settings.
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),
and the second didn'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.
Minor write bug-fixes, remove unimplemented code. A debug() assert
fired if windowBits was set to 8 for the Huffman only and no-compression
cases. This commit changes it to do some extra checking. Removed
unreachable code in pz_default_settings and eliminated a spurious
warning in pngcp for small files.
Version 1.7.0beta81 [June 11, 2016]
Check for CLOCK_PROCESS_CPUTIME_ID when building /contrib/libtests/timepng.
Otherwise it does not build on platforms that don't supply clock_gettime().
Add check for clock_gettime() in Makefile.am and configure.ac
Reenabled filter selection (dummy). This implements the code for
row-by-row filter selection but does not provide an actual implementation;
the selection function just chooses the lowest set filter bit.
Fixed a signed/unsigned warning (GCC 4.8.5) in pngwutil.c
Implemented base filter selection with row buffering and a crude code-count
algorithm.
Added filter selection, palette index checks. 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).
Port contrib/libtests/pngvalid.c from libpng16.
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 "png_setting" ABI 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.
The LOW_MEMORY PNG_COMPRESSION option should not be setting HUFFMAN_ONLY or
using a low deflate 'level'; according to the comments in zconf.h only
windowBits and memLevel affect the memory. pngwutil.c has been changed
to use the same values as HIGH compression.
The COMPAT option turned on the old optimize_cmf code (now in fix_cinfo),
however there was a serious bug in that code; it put the wrong value in
z_cmf. The setting was also not handled correctly in
pz_compression_settings.
pngtest now verifies the operation of COMPAT and, as a result, pngtest.png
has been reverted to the libpng 1.6 (etc) version.
IDAT size handling has been improved; if not explicitly set values
appropriate to png_level are now chosen (in addition to the handling for
the COMPAT setting). HIGH and HIGH_READ_SPEED now create unlimited
(up to the PNG chunk-size limit of 2^31-1 bytes) size IDAT chunks,
which requires buffering the whole of the IDAT data in memory but
reflects what other programs and optimizers do.
Changed handling of PNG_IMAGE_FLAG_FAST in the simplified API to use
PNG_COMPRESSION_HIGH_SPEED, and PNG_COMPRESSION_HIGH otherwise.
Removed png_struct::flags which is no longer used.
Fixed implementations of png_app_error() and png_app_warning() which
previously were swapped.
Avoid potential overflow of the PNG_IMAGE_SIZE macro. This macro
is not used within libpng, but is used in some of the examples.
Version 1.7.0beta82 [July 4, 2016]
Put the SKIP definition in the correct place. It needs to come after the
png.h include (see all the other .c files in contrib/libtests) because it
depends on PNG_LIBPNG_VER.
Moved pngcp to contrib/tools and added pngcp to the build together
with a pngcp.dfa configuration test (John Bowler)
Added a "Common linking failures" section to the INSTALL document.
Relocated misplaced #endif in png.c sRGB profile checking.
Fixed two Coverity issues in pngcp.c.
Send comments/corrections/commendations to png-mng-implement at lists.sf.net
(subscription required; visit
https://lists.sourceforge.net/lists/listinfo/png-mng-implement

126
CHANGES
View File

@@ -5564,6 +5564,132 @@ Version 1.7.0beta79 [March 9, 2016]
(Robert C. Seacord). Various other flags in png.h made unsigned as well.
Fixed some misleading indentation (Krishnaraj Bhat).
Version 1.7.0beta80 [May 6, 2016]
Fixed typo (missing underscore) in #define PNG_READ_16_TO_8_SUPPORTED
Bug report by (Y.Ohashik).
Quieted two Coverity issues in contrib/libtests/timepng.c.
Write code update (John Bowler):
Implemented better defaulting of zlib settings based on image properties.
Replaced pngtest.png with one compressed with the new zlib settings.
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),
and the second didn'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.
Minor write bug-fixes, remove unimplemented code. A debug() assert
fired if windowBits was set to 8 for the Huffman only and no-compression
cases. This commit changes it to do some extra checking. Removed
unreachable code in pz_default_settings and eliminated a spurious
warning in pngcp for small files.
Version 1.7.0beta81 [June 11, 2016]
Check for CLOCK_PROCESS_CPUTIME_ID when building /contrib/libtests/timepng.
Otherwise it does not build on platforms that don't supply clock_gettime().
Add check for clock_gettime() in Makefile.am and configure.ac
Reenabled filter selection (dummy). This implements the code for
row-by-row filter selection but does not provide an actual implementation;
the selection function just chooses the lowest set filter bit.
Fixed a signed/unsigned warning (GCC 4.8.5) in pngwutil.c
Implemented base filter selection with row buffering and a crude code-count
algorithm.
Added filter selection, palette index checks. 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).
Port contrib/libtests/pngvalid.c from libpng16.
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 "png_setting" ABI 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.
The LOW_MEMORY PNG_COMPRESSION option should not be setting HUFFMAN_ONLY or
using a low deflate 'level'; according to the comments in zconf.h only
windowBits and memLevel affect the memory. pngwutil.c has been changed
to use the same values as HIGH compression.
The COMPAT option turned on the old optimize_cmf code (now in fix_cinfo),
however there was a serious bug in that code; it put the wrong value in
z_cmf. The setting was also not handled correctly in
pz_compression_settings.
pngtest now verifies the operation of COMPAT and, as a result, pngtest.png
has been reverted to the libpng 1.6 (etc) version.
IDAT size handling has been improved; if not explicitly set values
appropriate to png_level are now chosen (in addition to the handling for
the COMPAT setting). HIGH and HIGH_READ_SPEED now create unlimited
(up to the PNG chunk-size limit of 2^31-1 bytes) size IDAT chunks,
which requires buffering the whole of the IDAT data in memory but
reflects what other programs and optimizers do.
Changed handling of PNG_IMAGE_FLAG_FAST in the simplified API to use
PNG_COMPRESSION_HIGH_SPEED, and PNG_COMPRESSION_HIGH otherwise.
Removed png_struct::flags which is no longer used.
Fixed implementations of png_app_error() and png_app_warning() which
previously were swapped.
Avoid potential overflow of the PNG_IMAGE_SIZE macro. This macro
is not used within libpng, but is used in some of the examples.
Version 1.7.0beta82 [July 4, 2016]
Put the SKIP definition in the correct place. It needs to come after the
png.h include (see all the other .c files in contrib/libtests) because it
depends on PNG_LIBPNG_VER.
Moved pngcp to contrib/tools and added pngcp to the build together
with a pngcp.dfa configuration test (John Bowler)
Added a "Common linking failures" section to the INSTALL document.
Relocated misplaced #endif in png.c sRGB profile checking.
Fixed two Coverity issues in pngcp.c.
Send comments/corrections/commendations to png-mng-implement at lists.sf.net
(subscription required; visit
https://lists.sourceforge.net/lists/listinfo/png-mng-implement

View File

@@ -697,7 +697,7 @@ endif(NOT WIN32 OR CYGWIN OR MINGW)
# SET UP LINKS
if(PNG_SHARED)
set_target_properties(png PROPERTIES
# VERSION 17.${PNGLIB_RELEASE}.1.7.0beta79
# VERSION 17.${PNGLIB_RELEASE}.1.7.0beta82
VERSION 17.${PNGLIB_RELEASE}.0
SOVERSION 17
CLEAN_DIRECT_OUTPUT 1)

41
INSTALL
View File

@@ -18,7 +18,8 @@ VIII. Configuring libpng for 16-bit platforms
XIII. Removing unwanted object code
XIV. Changes to the build and configuration of libpng in libpng-1.5.x
XV. Setjmp/longjmp issues
XVI. Other sources of information about libpng
XVI. Common linking failures
XVII. Other sources of information about libpng
I. Simple installation
@@ -47,7 +48,9 @@ If configure does not work on your system, or if you have a need to
change configure.ac or Makefile.am, and you have a reasonably
up-to-date set of tools, running ./autogen.sh in a git clone before
running ./configure may fix the problem. To be really sure that you
aren't using any of the included pre-built scripts, you can do this:
aren't using any of the included pre-built scripts, especially if you
are building from a tar distribution instead of a git distribution,
do this:
./configure --enable-maintainer-mode
make maintainer-clean
@@ -380,28 +383,20 @@ This requires setjmp/longjmp, so you must either build the library
with PNG_SETJMP_SUPPORTED defined, or with PNG_SIMPLIFIED_READ_SUPPORTED
and PNG_SIMPLIFIED_WRITE_SUPPORTED undefined.
XVI. Other sources of information about libpng:
XVI. Common linking failures
If your application fails to find libpng or zlib entries while linking:
Be sure "-lz" appears after "-lpng" on your linking command.
Be sure you have built libpng, zlib, and your application for the
same platform (e.g., 32-bit or 64-bit).
If you are using the vstudio project, observe the WARNING in
project/vstudio/README.txt.
XVII. Other sources of information about libpng:
Further information can be found in the README and libpng-manual.txt
files, in the individual makefiles, in png.h, and the manual pages
libpng.3 and png.5.
Using the ./configure script -- 16 December 2002.
=================================================
The ./configure script should work compatibly with what scripts/makefile.*
did, however there are some options you might need to add to configure
explicitly, which previously was done semi-automatically (if you didn't edit
scripts/makefile.* yourself, that is)
CFLAGS="-Wall -O -funroll-loops \
-malign-loops=2 -malign-functions=2" ./configure --prefix=/usr/include \
--with-pkgconfigdir=/usr/lib/pkgconfig --includedir=/usr/include
You can alternatively specify --includedir=/usr/include, /usr/local/include,
/usr/include/libpng17, or whatever.
If you find that the configure script is out-of-date or is not supporting
your platform properly, try running autogen.sh to regenerate "configure",
"Makefile.in", and the other configuration files. Then try configure again.

View File

@@ -10,7 +10,7 @@ this sentence.
This code is released under the libpng license.
libpng versions 1.0.7, July 1, 2000, through 1.7.0beta79, March 9, 2016, are
libpng versions 1.0.7, July 1, 2000, through 1.7.0beta82, July 4, 2016, are
Copyright (c) 2000-2002, 2004, 2006-2016 Glenn Randers-Pehrson, are
derived from libpng-1.0.6, and are distributed according to the same
disclaimer and license as libpng-1.0.6 with the following individuals
@@ -109,4 +109,4 @@ the additional disclaimers inserted at version 1.0.7.
Glenn Randers-Pehrson
glennrp at users.sourceforge.net
March 9, 2016
July 4, 2016

View File

@@ -8,9 +8,12 @@ ACLOCAL_AMFLAGS = -I scripts
# test programs - run on make check, make distcheck
check_PROGRAMS= pngtest pngunknown pngstest pngvalid pngimage
if HAVE_CLOCK_GETTIME
check_PROGRAMS += timepng
endif
# Utilities - installed
bin_PROGRAMS= pngfix png-fix-itxt
bin_PROGRAMS= pngcp pngfix png-fix-itxt
# This ensures that pnglibconf.h gets built at the start of 'make all' or
# 'make check', but it does not add dependencies to the individual programs,
@@ -42,6 +45,12 @@ pngfix_LDADD = libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.la
png_fix_itxt_SOURCES = contrib/tools/png-fix-itxt.c
timepng_SOURCES = contrib/libtests/timepng.c
timepng_LDADD = libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.la
pngcp_SOURCES = contrib/tools/pngcp.c
pngcp_LDADD = libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.la
# Generally these are single line shell scripts to run a test with a particular
# set of parameters:
TESTS =\
@@ -225,6 +234,7 @@ contrib/libtests/timepng.o: pnglibconf.h
contrib/tools/makesRGB.o: pnglibconf.h
contrib/tools/pngfix.o: pnglibconf.h
contrib/tools/pngcp.o: pnglibconf.h
# We must use -DPNG_NO_USE_READ_MACROS here even when the library may actually
# be built with PNG_USE_READ_MACROS; this prevents the read macros from
@@ -271,7 +281,8 @@ scripts/symbols.chk: scripts/checksym.awk scripts/symbols.def scripts/symbols.ou
scripts/pnglibconf.c: scripts/pnglibconf.dfa scripts/options.awk pngconf.h
rm -f $@ pnglibconf.tf[67]
test -z "$(CPPFLAGS)" -a -z "$(AM_CPPFLAGS)"
echo "com libpng @PNGLIB_VERSION@ STANDARD API DEFINITION" |\
(echo "com libpng @PNGLIB_VERSION@ STANDARD API DEFINITION";\
echo "com") |\
$(AWK) -f ${srcdir}/scripts/options.awk out=pnglibconf.tf6\
logunsupported=1 version=search ${srcdir}/pngconf.h -\
${srcdir}/scripts/pnglibconf.dfa 1>&2

2
README
View File

@@ -1,4 +1,4 @@
README for libpng version 1.7.0beta79 - March 9, 2016 (shared library 17.0)
README for libpng version 1.7.0beta82 - July 4, 2016 (shared library 17.0)
See the note about version numbers near the top of png.h
See INSTALL for instructions on how to install libpng.

View File

@@ -18,7 +18,7 @@ AC_PREREQ([2.68])
dnl Version number stuff here:
AC_INIT([libpng],[1.7.0beta79],[png-mng-implement@lists.sourceforge.net])
AC_INIT([libpng],[1.7.0beta82],[png-mng-implement@lists.sourceforge.net])
AC_CONFIG_MACRO_DIR([scripts])
# libpng does not follow GNU file name conventions (hence 'foreign')
@@ -40,7 +40,7 @@ dnl automake, so the following is not necessary (and is not defined anyway):
dnl AM_PREREQ([1.11.2])
dnl stop configure from automagically running automake
PNGLIB_VERSION=1.7.0beta79
PNGLIB_VERSION=1.7.0beta82
PNGLIB_MAJOR=1
PNGLIB_MINOR=7
PNGLIB_RELEASE=0
@@ -136,6 +136,11 @@ AC_C_RESTRICT
AC_CHECK_FUNCS([memset memcpy strncpy],,
AC_MSG_FAILURE([missing ANSI-C functions]))
# Some later POSIX 1003.1 functions are required for test programs, failure here
# is soft (the corresponding test program is not built).
AC_CHECK_FUNC([clock_gettime],,[AC_MSG_WARN([not building timepng])])
AM_CONDITIONAL([HAVE_CLOCK_GETTIME], [test "$ac_cv_func_clock_gettime" = "yes"])
# floor and ceil are required for FLOATING_POINT, but they can be turned off on
# the configure command line (and they are independent.) Default is to 'on'
AC_ARG_ENABLE([floating-point],

View File

@@ -0,0 +1,38 @@
# pngcp.dfa
# Build time configuration of libpng
#
# Author: John Bowler
# Copyright: (c) John Bowler, 2016
# Usage rights:
# To the extent possible under law, the author has waived all copyright and
# related or neighboring rights to this work. This work is published from:
# United States.
#
# Build libpng with support for pngcp. This means just png_read_png,
# png_write_png and small number of configuration settings.
#
everything = off
# Options to turn on png_read_png and png_write_png:
option WRITE_PNG on
option READ_PNG on
option EASY_ACCESS on
option WRITE_16BIT on
option SELECT_FILTER on
# pngcp needs this to preserve unknown chunks, switching all these on means that
# pngcp can work without explicit known chunk reading suppport
option SAVE_UNKNOWN_CHUNKS on
option WRITE_UNKNOWN_CHUNKS on
# pngcp needs this to handle palette files with invalid indices:
option CHECK_FOR_INVALID_INDEX on
option GET_PALETTE_MAX on
# this is used to turn off limits:
option USER_LIMITS on
option SET_USER_LIMITS on
# these are are just required for specific customizations
option WRITE_CUSTOMIZE_ZTXT_COMPRESSION on
option WRITE_CUSTOMIZE_COMPRESSION on

View File

@@ -2,7 +2,7 @@
*
* Copyright (c) 2015,2016 John Cunningham Bowler
*
* Last changed in libpng 1.6.22 [(PENDING RELEASE)]
* Last changed in libpng 1.6.22 [May 26, 2016]
*
* This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer
@@ -45,8 +45,19 @@
# define SKIP 0
#endif
#if defined(PNG_INFO_IMAGE_SUPPORTED) && defined(PNG_SEQUENTIAL_READ_SUPPORTED)\
&& (defined(PNG_READ_PNG_SUPPORTED) || PNG_LIBPNG_VER < 10700)
#if PNG_LIBPNG_VER < 10700
/* READ_PNG and WRITE_PNG were not defined, so: */
# ifdef PNG_INFO_IMAGE_SUPPORTED
# ifdef PNG_SEQUENTIAL_READ_SUPPORTED
# define PNG_READ_PNG_SUPPORTED
# endif /* SEQUENTIAL_READ */
# ifdef PNG_WRITE_SUPPORTED
# define PNG_WRITE_PNG_SUPPORTED
# endif /* WRITE */
# endif /* INFO_IMAGE */
#endif /* pre 1.7.0 */
#ifdef PNG_READ_PNG_SUPPORTED
/* If a transform is valid on both read and write this implies that if the
* transform is applied to read it must also be applied on write to produce
* meaningful data. This is because these transforms when performed on read
@@ -395,7 +406,7 @@ buffer_destroy(struct buffer *buffer)
buffer_destroy_list(list);
}
#ifdef PNG_WRITE_SUPPORTED
#ifdef PNG_WRITE_PNG_SUPPORTED
static void
buffer_start_write(struct buffer *buffer)
{
@@ -565,7 +576,7 @@ struct display
png_structp read_pp;
png_infop read_ip;
# ifdef PNG_WRITE_SUPPORTED
# ifdef PNG_WRITE_PNG_SUPPORTED
/* Used to write a new image (the original info_ptr is used) */
png_structp write_pp;
struct buffer written_file; /* where the file gets written */
@@ -592,7 +603,7 @@ display_init(struct display *dp)
dp->read_ip = NULL;
buffer_init(&dp->original_file);
# ifdef PNG_WRITE_SUPPORTED
# ifdef PNG_WRITE_PNG_SUPPORTED
dp->write_pp = NULL;
buffer_init(&dp->written_file);
# endif
@@ -605,7 +616,7 @@ display_clean_read(struct display *dp)
png_destroy_read_struct(&dp->read_pp, &dp->read_ip, NULL);
}
#ifdef PNG_WRITE_SUPPORTED
#ifdef PNG_WRITE_PNG_SUPPORTED
static void
display_clean_write(struct display *dp)
{
@@ -617,7 +628,7 @@ display_clean_write(struct display *dp)
static void
display_clean(struct display *dp)
{
# ifdef PNG_WRITE_SUPPORTED
# ifdef PNG_WRITE_PNG_SUPPORTED
display_clean_write(dp);
# endif
display_clean_read(dp);
@@ -635,7 +646,7 @@ static void
display_destroy(struct display *dp)
{
/* Release any memory held in the display. */
# ifdef PNG_WRITE_SUPPORTED
# ifdef PNG_WRITE_PNG_SUPPORTED
buffer_destroy(&dp->written_file);
# endif
@@ -1082,6 +1093,7 @@ compare_read(struct display *dp, int applied_transforms)
}
else
# ifdef PNG_sBIT_SUPPORTED
{
unsigned long y;
int bpp; /* bits-per-pixel then bytes-per-pixel */
@@ -1243,12 +1255,16 @@ compare_read(struct display *dp, int applied_transforms)
}
} /* for y */
}
# else /* !sBIT */
display_log(dp, INTERNAL_ERROR,
"active shift transform but no sBIT support");
# endif /* !sBIT */
}
return 1; /* compare succeeded */
}
#ifdef PNG_WRITE_SUPPORTED
#ifdef PNG_WRITE_PNG_SUPPORTED
static void
buffer_write(struct display *dp, struct buffer *buffer, png_bytep data,
png_size_t size)
@@ -1347,7 +1363,7 @@ write_png(struct display *dp, png_infop ip, int transforms)
*/
display_clean_write(dp);
}
#endif /* WRITE_SUPPORTED */
#endif /* WRITE_PNG */
static int
skip_transform(struct display *dp, int tr)
@@ -1409,7 +1425,7 @@ test_one_file(struct display *dp, const char *filename)
return; /* no point testing more */
}
#ifdef PNG_WRITE_SUPPORTED
#ifdef PNG_WRITE_PNG_SUPPORTED
/* Second test: write the original PNG data out to a new file (to test the
* write side) then read the result back in and make sure that it hasn't
* changed.
@@ -1450,7 +1466,7 @@ test_one_file(struct display *dp, const char *filename)
* out and read it back in again (without the reversible transforms)
* we should get back to the place where we started.
*/
#ifdef PNG_WRITE_SUPPORTED
#ifdef PNG_WRITE_PNG_SUPPORTED
if ((current & write_transforms) == current)
{
/* All transforms reversible: write the PNG with the transformations
@@ -1686,7 +1702,7 @@ main(const int argc, const char * const * const argv)
return errors != 0;
}
}
#else /* !INFO_IMAGE || !SEQUENTIAL_READ || !READ_PNG*/
#else /* !READ_PNG */
int
main(void)
{

View File

@@ -3,7 +3,7 @@
*
* Copyright (c) 2013-2016 John Cunningham Bowler
*
* Last changed in libpng 1.6.22 [(PENDING RELEASE)]
* Last changed in libpng 1.6.24 [(PENDING RELEASE)]
*
* This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer
@@ -26,15 +26,6 @@
# include <config.h>
#endif
/* 1.6.1 added support for the configure test harness, which uses 77 to indicate
* a skipped test, in earlier versions we need to succeed on a skipped test, so:
*/
#if PNG_LIBPNG_VER >= 10601 && defined(HAVE_CONFIG_H)
# define SKIP 77
#else
# define SKIP 0
#endif
/* Define the following to use this test against your installed libpng, rather
* than the one being built here:
*/
@@ -44,6 +35,15 @@
# include "../../png.h"
#endif
/* 1.6.1 added support for the configure test harness, which uses 77 to indicate
* a skipped test, in earlier versions we need to succeed on a skipped test, so:
*/
#if PNG_LIBPNG_VER >= 10601 && defined(HAVE_CONFIG_H)
# define SKIP 77
#else
# define SKIP 0
#endif
#ifdef PNG_SIMPLIFIED_READ_SUPPORTED /* Else nothing can be done */
#include "../tools/sRGB.h"

View File

@@ -1,7 +1,7 @@
/* pngunknown.c - test the read side unknown chunk handling
*
* Last changed in libpng 1.6.22 [(PENDING RELEASE)]
* Last changed in libpng 1.6.22 [May 26, 2016]
* Copyright (c) 2015,2016 Glenn Randers-Pehrson
* Written by John Cunningham Bowler
*

View File

@@ -1,7 +1,7 @@
/* pngvalid.c - validate libpng by constructing then reading png files.
*
* Last changed in libpng 1.6.22 [(PENDING RELEASE)]
* Last changed in libpng 1.6.24 [(PENDING RELEASE)]
* Copyright (c) 2014-2016 Glenn Randers-Pehrson
* Written by John Cunningham Bowler
*
@@ -131,6 +131,17 @@ typedef png_byte *png_const_bytep;
#include <string.h> /* For memcpy, memset */
#include <math.h> /* For floor */
/* Convenience macros. */
#define CHUNK(a,b,c,d) (((a)<<24)+((b)<<16)+((c)<<8)+(d))
#define CHUNK_IHDR CHUNK(73,72,68,82)
#define CHUNK_PLTE CHUNK(80,76,84,69)
#define CHUNK_IDAT CHUNK(73,68,65,84)
#define CHUNK_IEND CHUNK(73,69,78,68)
#define CHUNK_cHRM CHUNK(99,72,82,77)
#define CHUNK_gAMA CHUNK(103,65,77,65)
#define CHUNK_sBIT CHUNK(115,66,73,84)
#define CHUNK_sRGB CHUNK(115,82,71,66)
/* Unused formal parameter errors are removed using the following macro which is
* expected to have no bad effects on performance.
*/
@@ -297,38 +308,33 @@ randomize(void *pv, size_t size)
#define R8(this) randomize(&(this), sizeof (this))
static void r16(png_uint_16p p16, size_t count)
#ifdef PNG_READ_SUPPORTED
static png_byte
random_byte(void)
{
size_t i;
for (i=0; i<count; ++i)
{
unsigned char b2[2];
randomize(b2, sizeof b2);
*p16++ = png_get_uint_16(b2);
}
unsigned char b1[1];
randomize(b1, sizeof b1);
return b1[0];
}
#endif /* READ */
#define R16(this) r16(&(this), (sizeof (this))/(sizeof (png_uint_16)))
#define R16_1(this) r16(&(this), (size_t) 1U)
static png_uint_16
random_u16(void)
{
unsigned char b2[2];
randomize(b2, sizeof b2);
return png_get_uint_16(b2);
}
#if defined PNG_READ_RGB_TO_GRAY_SUPPORTED ||\
defined PNG_READ_FILLER_SUPPORTED
static void r32(png_uint_32p p32, size_t count)
static png_uint_32
random_u32(void)
{
size_t i;
for (i=0; i<count; ++i)
{
unsigned char b4[4];
randomize(b4, sizeof b4);
*p32++ = png_get_uint_32(b4);
}
unsigned char b4[4];
randomize(b4, sizeof b4);
return png_get_uint_32(b4);
}
#define R32(this) r32(&(this), (sizeof (this))/(sizeof (png_uint_32)))
#define R32_1(this) r32(&(this), (size_t) 1U)
#endif /* READ_FILLER || READ_RGB_TO_GRAY */
#endif /* READ || WRITE_tRNS || WRITE_FILTER */
@@ -338,11 +344,7 @@ static void r32(png_uint_32p p32, size_t count)
static unsigned int
random_mod(unsigned int max)
{
png_uint_16 x;
R16_1(x);
return x % max; /* 0 .. max-1 */
return random_u16() % max; /* 0 .. max-1 */
}
#endif /* READ_TRANSFORMS || WRITE_FILTER */
@@ -351,11 +353,7 @@ random_mod(unsigned int max)
static int
random_choice(void)
{
unsigned char x;
R8(x);
return x & 1;
return random_byte() & 1;
}
#endif /* READ_RGB_TO_GRAY || READ_FILLER */
@@ -711,6 +709,8 @@ typedef struct png_store_file
{
struct png_store_file* next; /* as many as you like... */
char name[FILE_NAME_SIZE];
unsigned int IDAT_bits; /* Number of bits in IDAT size */
png_uint_32 IDAT_size; /* Total size of IDAT data */
png_uint_32 id; /* must be correct (see FILEID) */
png_size_t datacount; /* In this (the last) buffer */
png_store_buffer data; /* Last buffer in file */
@@ -766,6 +766,13 @@ typedef struct png_store
char test[128]; /* Name of test */
char error[256];
/* Share fields */
png_uint_32 chunklen; /* Length of chunk+overhead (chunkpos >= 8) */
png_uint_32 chunktype;/* Type of chunk (valid if chunkpos >= 4) */
png_uint_32 chunkpos; /* Position in chunk */
png_uint_32 IDAT_size;/* Accumulated IDAT size in .new */
unsigned int IDAT_bits;/* Cache of the file store value */
/* Read fields */
png_structp pread; /* Used to read a saved file */
png_infop piread;
@@ -775,6 +782,9 @@ typedef struct png_store
png_byte* image; /* Buffer for reading interlaced images */
png_size_t cb_image; /* Size of this buffer */
png_size_t cb_row; /* Row size of the image(s) */
uLong IDAT_crc;
png_uint_32 IDAT_len; /* Used when re-chunking IDAT chunks */
png_uint_32 IDAT_pos; /* Used when re-chunking IDAT chunks */
png_uint_32 image_h; /* Number of rows in a single image */
store_pool read_memory_pool;
@@ -861,6 +871,11 @@ store_init(png_store* ps)
ps->pwrite = NULL;
ps->piwrite = NULL;
ps->writepos = 0;
ps->chunkpos = 8;
ps->chunktype = 0;
ps->chunklen = 16;
ps->IDAT_size = 0;
ps->IDAT_bits = 0;
ps->new.prev = NULL;
ps->palette = NULL;
ps->npalette = 0;
@@ -883,6 +898,11 @@ store_freenew(png_store *ps)
{
store_freebuffer(&ps->new);
ps->writepos = 0;
ps->chunkpos = 8;
ps->chunktype = 0;
ps->chunklen = 16;
ps->IDAT_size = 0;
ps->IDAT_bits = 0;
if (ps->palette != NULL)
{
free(ps->palette);
@@ -896,9 +916,6 @@ store_storenew(png_store *ps)
{
png_store_buffer *pb;
if (ps->writepos != STORE_BUFFER_SIZE)
png_error(ps->pwrite, "invalid store call");
pb = voidcast(png_store_buffer*, malloc(sizeof *pb));
if (pb == NULL)
@@ -929,21 +946,52 @@ store_freefile(png_store_file **ppf)
}
}
static unsigned int
bits_of(png_uint_32 num)
{
/* Return the number of bits in 'num' */
unsigned int b = 0;
if (num & 0xffff0000U) b += 16U, num >>= 16;
if (num & 0xff00U) b += 8U, num >>= 8;
if (num & 0xf0U) b += 4U, num >>= 4;
if (num & 0xcU) b += 2U, num >>= 2;
if (num & 0x2U) ++b, num >>= 1;
if (num) ++b;
return b; /* 0..32 */
}
/* Main interface to file storeage, after writing a new PNG file (see the API
* below) call store_storefile to store the result with the given name and id.
*/
static void
store_storefile(png_store *ps, png_uint_32 id)
{
png_store_file *pf = voidcast(png_store_file*, malloc(sizeof *pf));
png_store_file *pf;
if (ps->chunkpos != 0U || ps->chunktype != 0U || ps->chunklen != 0U ||
ps->IDAT_size == 0)
png_error(ps->pwrite, "storefile: incomplete write");
pf = voidcast(png_store_file*, malloc(sizeof *pf));
if (pf == NULL)
png_error(ps->pwrite, "storefile: OOM");
safecat(pf->name, sizeof pf->name, 0, ps->wname);
pf->id = id;
pf->data = ps->new;
pf->datacount = ps->writepos;
pf->IDAT_size = ps->IDAT_size;
pf->IDAT_bits = bits_of(ps->IDAT_size);
/* Because the IDAT always has zlib header stuff this must be true: */
if (pf->IDAT_bits == 0U)
png_error(ps->pwrite, "storefile: 0 sized IDAT");
ps->new.prev = NULL;
ps->writepos = 0;
ps->chunkpos = 8;
ps->chunktype = 0;
ps->chunklen = 16;
ps->IDAT_size = 0;
pf->palette = ps->palette;
pf->npalette = ps->npalette;
ps->palette = 0;
@@ -1067,7 +1115,7 @@ store_warning(png_structp ppIn, png_const_charp message)
if (!ps->expect_warning)
store_log(ps, pp, message, 0 /* warning */);
else
ps->saw_warning = 1;
ps->saw_warning = 1;
}
/* These somewhat odd functions are used when reading an image to ensure that
@@ -1209,32 +1257,119 @@ store_image_check(const png_store* ps, png_const_structp pp, int iImage)
}
#endif /* PNG_READ_SUPPORTED */
static int
valid_chunktype(png_uint_32 chunktype)
{
/* Each byte in the chunk type must be in one of the ranges 65..90, 97..122
* (both inclusive), so:
*/
unsigned int i;
for (i=0; i<4; ++i)
{
unsigned int c = chunktype & 0xffU;
if (!((c >= 65U && c <= 90U) || (c >= 97U && c <= 122U)))
return 0;
chunktype >>= 8;
}
return 1; /* It's valid */
}
static void PNGCBAPI
store_write(png_structp ppIn, png_bytep pb, png_size_t st)
{
png_const_structp pp = ppIn;
png_store *ps = voidcast(png_store*, png_get_io_ptr(pp));
size_t writepos = ps->writepos;
png_uint_32 chunkpos = ps->chunkpos;
png_uint_32 chunktype = ps->chunktype;
png_uint_32 chunklen = ps->chunklen;
if (ps->pwrite != pp)
png_error(pp, "store state damaged");
/* Technically this is legal, but in practice libpng never writes more than
* the maximum chunk size at once so if it happens something weird has
* changed inside libpng (probably).
*/
if (st > 0x7fffffffU)
png_error(pp, "unexpected write size");
/* Now process the bytes to be written. Do this in units of the space in the
* output (write) buffer or, at the start 4 bytes for the chunk type and
* length limited in any case by the amount of data.
*/
while (st > 0)
{
size_t cb;
if (writepos >= STORE_BUFFER_SIZE)
store_storenew(ps), writepos = 0;
if (ps->writepos >= STORE_BUFFER_SIZE)
store_storenew(ps);
if (chunkpos < 4)
{
png_byte b = *pb++;
--st;
chunklen = (chunklen << 8) + b;
ps->new.buffer[writepos++] = b;
++chunkpos;
}
cb = st;
else if (chunkpos < 8)
{
png_byte b = *pb++;
--st;
chunktype = (chunktype << 8) + b;
ps->new.buffer[writepos++] = b;
if (cb > STORE_BUFFER_SIZE - ps->writepos)
cb = STORE_BUFFER_SIZE - ps->writepos;
if (++chunkpos == 8)
{
chunklen &= 0xffffffffU;
if (chunklen > 0x7fffffffU)
png_error(pp, "chunk length too great");
memcpy(ps->new.buffer + ps->writepos, pb, cb);
pb += cb;
st -= cb;
ps->writepos += cb;
}
chunktype &= 0xffffffffU;
if (chunktype == CHUNK_IDAT)
{
if (chunklen > ~ps->IDAT_size)
png_error(pp, "pngvalid internal image too large");
ps->IDAT_size += chunklen;
}
else if (!valid_chunktype(chunktype))
png_error(pp, "invalid chunk type");
chunklen += 12; /* for header and CRC */
}
}
else /* chunkpos >= 8 */
{
png_size_t cb = st;
if (cb > STORE_BUFFER_SIZE - writepos)
cb = STORE_BUFFER_SIZE - writepos;
if (cb > chunklen - chunkpos/* bytes left in chunk*/)
cb = (png_size_t)/*SAFE*/(chunklen - chunkpos);
memcpy(ps->new.buffer + writepos, pb, cb);
chunkpos += (png_uint_32)/*SAFE*/cb;
pb += cb;
writepos += cb;
st -= cb;
if (chunkpos >= chunklen) /* must be equal */
chunkpos = chunktype = chunklen = 0;
}
} /* while (st > 0) */
ps->writepos = writepos;
ps->chunkpos = chunkpos;
ps->chunktype = chunktype;
ps->chunklen = chunklen;
}
static void PNGCBAPI
@@ -1254,7 +1389,6 @@ store_read_buffer_size(png_store *ps)
return ps->current->datacount;
}
#ifdef PNG_READ_TRANSFORMS_SUPPORTED
/* Return total bytes available for read. */
static size_t
store_read_buffer_avail(png_store *ps)
@@ -1279,7 +1413,6 @@ store_read_buffer_avail(png_store *ps)
return 0;
}
#endif
static int
store_read_buffer_next(png_store *ps)
@@ -1331,6 +1464,240 @@ store_read_imp(png_store *ps, png_bytep pb, png_size_t st)
}
}
static png_size_t
store_read_chunk(png_store *ps, png_bytep pb, const png_size_t max,
const png_size_t min)
{
png_uint_32 chunklen = ps->chunklen;
png_uint_32 chunktype = ps->chunktype;
png_uint_32 chunkpos = ps->chunkpos;
png_size_t st = max;
if (st > 0) do
{
if (chunkpos >= chunklen) /* end of last chunk */
{
png_byte buffer[8];
/* Read the header of the next chunk: */
store_read_imp(ps, buffer, 8U);
chunklen = png_get_uint_32(buffer) + 12U;
chunktype = png_get_uint_32(buffer+4U);
chunkpos = 0U; /* Position read so far */
}
if (chunktype == CHUNK_IDAT)
{
png_uint_32 IDAT_pos = ps->IDAT_pos;
png_uint_32 IDAT_len = ps->IDAT_len;
png_uint_32 IDAT_size = ps->IDAT_size;
/* The IDAT headers are constructed here; skip the input header. */
if (chunkpos < 8U)
chunkpos = 8U;
if (IDAT_pos == IDAT_len)
{
png_byte random = random_byte();
/* Make a new IDAT chunk, if IDAT_len is 0 this is the first IDAT,
* if IDAT_size is 0 this is the end. At present this is set up
* using a random number so that there is a 25% chance before
* the start of the first IDAT chunk being 0 length.
*/
if (IDAT_len == 0U) /* First IDAT */
{
switch (random & 3U)
{
case 0U: IDAT_len = 12U; break; /* 0 bytes */
case 1U: IDAT_len = 13U; break; /* 1 byte */
default: IDAT_len = random_u32();
IDAT_len %= IDAT_size;
IDAT_len += 13U; /* 1..IDAT_size bytes */
break;
}
}
else if (IDAT_size == 0U) /* all IDAT data read */
{
/* The last (IDAT) chunk should be positioned at the CRC now: */
if (chunkpos != chunklen-4U)
png_error(ps->pread, "internal: IDAT size mismatch");
/* The only option here is to add a zero length IDAT, this
* happens 25% of the time. Because of the check above
* chunklen-4U-chunkpos must be zero, we just need to skip the
* CRC now.
*/
if ((random & 3U) == 0U)
IDAT_len = 12U; /* Output another 0 length IDAT */
else
{
/* End of IDATs, skip the CRC to make the code above load the
* next chunk header next time round.
*/
png_byte buffer[4];
store_read_imp(ps, buffer, 4U);
chunkpos += 4U;
ps->IDAT_pos = IDAT_pos;
ps->IDAT_len = IDAT_len;
ps->IDAT_size = 0U;
continue; /* Read the next chunk */
}
}
else
{
/* Middle of IDATs, use 'random' to determine the number of bits
* to use in the IDAT length.
*/
IDAT_len = random_u32();
IDAT_len &= (1U << (1U + random % ps->IDAT_bits)) - 1U;
if (IDAT_len > IDAT_size)
IDAT_len = IDAT_size;
IDAT_len += 12U; /* zero bytes may occur */
}
IDAT_pos = 0U;
ps->IDAT_crc = 0x35af061e; /* Ie: crc32(0UL, "IDAT", 4) */
} /* IDAT_pos == IDAT_len */
if (IDAT_pos < 8U) /* Return the header */ do
{
png_uint_32 b;
unsigned int shift;
if (IDAT_pos < 4U)
b = IDAT_len - 12U;
else
b = CHUNK_IDAT;
shift = 3U & IDAT_pos;
++IDAT_pos;
if (shift < 3U)
b >>= 8U*(3U-shift);
*pb++ = 0xffU & b;
}
while (--st > 0 && IDAT_pos < 8);
else if (IDAT_pos < IDAT_len - 4U) /* I.e not the CRC */
{
if (chunkpos < chunklen-4U)
{
uInt avail = (uInt)-1;
if (avail > (IDAT_len-4U) - IDAT_pos)
avail = (uInt)/*SAFE*/((IDAT_len-4U) - IDAT_pos);
if (avail > st)
avail = (uInt)/*SAFE*/st;
if (avail > (chunklen-4U) - chunkpos)
avail = (uInt)/*SAFE*/((chunklen-4U) - chunkpos);
store_read_imp(ps, pb, avail);
ps->IDAT_crc = crc32(ps->IDAT_crc, pb, avail);
pb += (png_size_t)/*SAFE*/avail;
st -= (png_size_t)/*SAFE*/avail;
chunkpos += (png_uint_32)/*SAFE*/avail;
IDAT_size -= (png_uint_32)/*SAFE*/avail;
IDAT_pos += (png_uint_32)/*SAFE*/avail;
}
else /* skip the input CRC */
{
png_byte buffer[4];
store_read_imp(ps, buffer, 4U);
chunkpos += 4U;
}
}
else /* IDAT crc */ do
{
uLong b = ps->IDAT_crc;
unsigned int shift = (IDAT_len - IDAT_pos); /* 4..1 */
++IDAT_pos;
if (shift > 1U)
b >>= 8U*(shift-1U);
*pb++ = 0xffU & b;
}
while (--st > 0 && IDAT_pos < IDAT_len);
ps->IDAT_pos = IDAT_pos;
ps->IDAT_len = IDAT_len;
ps->IDAT_size = IDAT_size;
}
else /* !IDAT */
{
/* If there is still some pending IDAT data after the IDAT chunks have
* been processed there is a problem:
*/
if (ps->IDAT_len > 0 && ps->IDAT_size > 0)
png_error(ps->pread, "internal: missing IDAT data");
if (chunktype == CHUNK_IEND && ps->IDAT_len == 0U)
png_error(ps->pread, "internal: missing IDAT");
if (chunkpos < 8U) /* Return the header */ do
{
png_uint_32 b;
unsigned int shift;
if (chunkpos < 4U)
b = chunklen - 12U;
else
b = chunktype;
shift = 3U & chunkpos;
++chunkpos;
if (shift < 3U)
b >>= 8U*(3U-shift);
*pb++ = 0xffU & b;
}
while (--st > 0 && chunkpos < 8);
else /* Return chunk bytes, including the CRC */
{
png_size_t avail = st;
if (avail > chunklen - chunkpos)
avail = (png_size_t)/*SAFE*/(chunklen - chunkpos);
store_read_imp(ps, pb, avail);
pb += avail;
st -= avail;
chunkpos += (png_uint_32)/*SAFE*/avail;
/* Check for end of chunk and end-of-file; don't try to read a new
* chunk header at this point unless instructed to do so by 'min'.
*/
if (chunkpos >= chunklen && max-st >= min &&
store_read_buffer_avail(ps) == 0)
break;
}
} /* !IDAT */
}
while (st > 0);
ps->chunklen = chunklen;
ps->chunktype = chunktype;
ps->chunkpos = chunkpos;
return st; /* space left */
}
static void PNGCBAPI
store_read(png_structp ppIn, png_bytep pb, png_size_t st)
{
@@ -1340,26 +1707,33 @@ store_read(png_structp ppIn, png_bytep pb, png_size_t st)
if (ps == NULL || ps->pread != pp)
png_error(pp, "bad store read call");
store_read_imp(ps, pb, st);
store_read_chunk(ps, pb, st, st);
}
static void
store_progressive_read(png_store *ps, png_structp pp, png_infop pi)
{
/* Notice that a call to store_read will cause this function to fail because
* readpos will be set.
*/
if (ps->pread != pp || ps->current == NULL || ps->next == NULL)
png_error(pp, "store state damaged (progressive)");
do
/* This is another Horowitz and Hill random noise generator. In this case
* the aim is to stress the progressive reader with truly horrible variable
* buffer sizes in the range 1..500, so a sequence of 9 bit random numbers
* is generated. We could probably just count from 1 to 32767 and get as
* good a result.
*/
while (store_read_buffer_avail(ps) > 0)
{
if (ps->readpos != 0)
png_error(pp, "store_read called during progressive read");
static png_uint_32 noise = 2;
png_size_t cb;
png_byte buffer[512];
png_process_data(pp, pi, ps->next->buffer, store_read_buffer_size(ps));
/* Generate 15 more bits of stuff: */
noise = (noise << 9) | ((noise ^ (noise >> (9-5))) & 0x1ff);
cb = noise & 0x1ff;
cb -= store_read_chunk(ps, buffer, cb, 1);
png_process_data(pp, pi, buffer, cb);
}
while (store_read_buffer_next(ps));
}
#endif /* PNG_READ_SUPPORTED */
@@ -1730,6 +2104,11 @@ store_read_reset(png_store *ps)
ps->next = NULL;
ps->readpos = 0;
ps->validated = 0;
ps->chunkpos = 8;
ps->chunktype = 0;
ps->chunklen = 16;
ps->IDAT_size = 0;
}
#ifdef PNG_READ_SUPPORTED
@@ -1744,6 +2123,11 @@ store_read_set(png_store *ps, png_uint_32 id)
{
ps->current = pf;
ps->next = NULL;
ps->IDAT_size = pf->IDAT_size;
ps->IDAT_bits = pf->IDAT_bits; /* just a cache */
ps->IDAT_len = 0;
ps->IDAT_pos = 0;
ps->IDAT_crc = 0UL;
store_read_buffer_next(ps);
return;
}
@@ -2581,17 +2965,6 @@ modifier_color_encoding_is_set(const png_modifier *pm)
return pm->current_gamma != 0;
}
/* Convenience macros. */
#define CHUNK(a,b,c,d) (((a)<<24)+((b)<<16)+((c)<<8)+(d))
#define CHUNK_IHDR CHUNK(73,72,68,82)
#define CHUNK_PLTE CHUNK(80,76,84,69)
#define CHUNK_IDAT CHUNK(73,68,65,84)
#define CHUNK_IEND CHUNK(73,69,78,68)
#define CHUNK_cHRM CHUNK(99,72,82,77)
#define CHUNK_gAMA CHUNK(103,65,77,65)
#define CHUNK_sBIT CHUNK(115,66,73,84)
#define CHUNK_sRGB CHUNK(115,82,71,66)
/* The guts of modification are performed during a read. */
static void
modifier_crc(png_bytep buffer)
@@ -2631,7 +3004,7 @@ modifier_read_imp(png_modifier *pm, png_bytep pb, png_size_t st)
{
static png_byte sign[8] = { 137, 80, 78, 71, 13, 10, 26, 10 };
case modifier_start:
store_read_imp(&pm->this, pm->buffer, 8); /* size of signature. */
store_read_chunk(&pm->this, pm->buffer, 8, 8); /* signature. */
pm->buffer_count = 8;
pm->buffer_position = 0;
@@ -2641,7 +3014,7 @@ modifier_read_imp(png_modifier *pm, png_bytep pb, png_size_t st)
break;
case modifier_signature:
store_read_imp(&pm->this, pm->buffer, 13+12); /* size of IHDR */
store_read_chunk(&pm->this, pm->buffer, 13+12, 13+12); /* IHDR */
pm->buffer_count = 13+12;
pm->buffer_position = 0;
@@ -2682,7 +3055,7 @@ modifier_read_imp(png_modifier *pm, png_bytep pb, png_size_t st)
{
if (cb > st) cb = st;
pm->flush -= cb;
store_read_imp(&pm->this, pb, cb);
store_read_chunk(&pm->this, pb, cb, cb);
pb += cb;
st -= cb;
if (st == 0) return;
@@ -2699,7 +3072,7 @@ modifier_read_imp(png_modifier *pm, png_bytep pb, png_size_t st)
pm->pending_chunk = 0;
}
else
store_read_imp(&pm->this, pm->buffer, 8);
store_read_chunk(&pm->this, pm->buffer, 8, 8);
pm->buffer_count = 8;
pm->buffer_position = 0;
@@ -2765,8 +3138,8 @@ modifier_read_imp(png_modifier *pm, png_bytep pb, png_size_t st)
*/
if (len+12 <= sizeof pm->buffer)
{
store_read_imp(&pm->this, pm->buffer+pm->buffer_count,
len+12-pm->buffer_count);
png_size_t s = len+12-pm->buffer_count;
store_read_chunk(&pm->this, pm->buffer+pm->buffer_count, s, s);
pm->buffer_count = len+12;
/* Check for a modification, else leave it be. */
@@ -3333,8 +3706,8 @@ set_random_tRNS(png_structp pp, png_infop pi, const png_byte colour_type,
{
if (bit_depth == 8)
{
R16(tRNS.red);
R16(tRNS.green);
tRNS.red = random_u16();
tRNS.green = random_u16();
tRNS.blue = tRNS.red ^ tRNS.green;
tRNS.red &= mask;
tRNS.green &= mask;
@@ -3343,7 +3716,7 @@ set_random_tRNS(png_structp pp, png_infop pi, const png_byte colour_type,
else /* bit_depth == 16 */
{
R16(tRNS.red);
tRNS.red = random_u16();
tRNS.green = (png_uint_16)(tRNS.red * 257);
tRNS.blue = (png_uint_16)(tRNS.green * 17);
}
@@ -3351,7 +3724,7 @@ set_random_tRNS(png_structp pp, png_infop pi, const png_byte colour_type,
else
{
R16(tRNS.gray);
tRNS.gray = random_u16();
tRNS.gray &= mask;
}
@@ -7303,7 +7676,7 @@ image_transform_png_set_rgb_to_gray_ini(const image_transform *this,
png_uint_32 ru;
double total;
R32_1(ru);
ru = random_u32();
data.green_coefficient = total = (ru & 0xffff) / 65535.;
ru >>= 16;
data.red_coefficient = (1 - total) * (ru & 0xffff) / 65535.;
@@ -8231,7 +8604,7 @@ image_transform_png_set_filler_set(const image_transform *this,
* filler. The 'filler' value has all 32 bits set, but only bit_depth
* will be used. At this point we don't know bit_depth.
*/
R32(data.filler);
data.filler = random_u32();
data.flags = random_choice();
png_set_filler(pp, data.filler, data.flags);
@@ -8304,7 +8677,7 @@ image_transform_png_set_add_alpha_set(const image_transform *this,
* filler. The 'filler' value has all 32 bits set, but only bit_depth
* will be used. At this point we don't know bit_depth.
*/
R32(data.filler);
data.filler = random_u32();
data.flags = random_choice();
png_set_add_alpha(pp, data.filler, data.flags);

View File

@@ -1,8 +1,8 @@
/* timepng.c
*
* Copyright (c) 2013 John Cunningham Bowler
* Copyright (c) 2013,2016 John Cunningham Bowler
*
* Last changed in libpng 1.6.1 [March 28, 2013]
* Last changed in libpng 1.6.22 [May 26, 2016]
*
* This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer
@@ -10,15 +10,17 @@
*
* Load an arbitrary number of PNG files (from the command line, or, if there
* are no arguments on the command line, from stdin) then run a time test by
* reading each file by row. The test does nothing with the read result and
* does no transforms. The only output is a time as a floating point number of
* seconds with 9 decimal digits.
* reading each file by row or by image (possibly with transforms in the latter
* case). The only output is a time as a floating point number of seconds with
* 9 decimal digits.
*/
#define _POSIX_C_SOURCE 199309L /* for clock_gettime */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <limits.h>
#include <time.h>
@@ -35,36 +37,73 @@
# include "../../png.h"
#endif
static int read_png(FILE *fp)
/* The following is to support direct compilation of this file as C++ */
#ifdef __cplusplus
# define voidcast(type, value) static_cast<type>(value)
#else
# define voidcast(type, value) (value)
#endif /* __cplusplus */
/* 'CLOCK_PROCESS_CPUTIME_ID' is one of the clock timers for clock_gettime. It
* need not be supported even when clock_gettime is available. It returns the
* 'CPU' time the process has consumed. 'CPU' time is assumed to include time
* when the CPU is actually blocked by a pending cache fill but not time
* waiting for page faults. The attempt is to get a measure of the actual time
* the implementation takes to read a PNG ignoring the potentially very large IO
* overhead.
*/
#if defined (CLOCK_PROCESS_CPUTIME_ID) && defined(PNG_STDIO_SUPPORTED) &&\
defined(PNG_EASY_ACCESS_SUPPORTED) &&\
(PNG_LIBPNG_VER >= 10700 ? defined(PNG_READ_PNG_SUPPORTED) :\
defined (PNG_SEQUENTIAL_READ_SUPPORTED) &&\
defined(PNG_INFO_IMAGE_SUPPORTED))
typedef struct
{
png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,0,0,0);
png_infop info_ptr = NULL;
png_bytep row = NULL, display = NULL;
FILE *input;
FILE *output;
} io_data;
if (png_ptr == NULL)
return 0;
static PNG_CALLBACK(void, read_and_copy,
(png_structp png_ptr, png_bytep buffer, png_size_t cb))
{
io_data *io = (io_data*)png_get_io_ptr(png_ptr);
if (setjmp(png_jmpbuf(png_ptr)))
if (fread(buffer, cb, 1, io->input) != 1)
png_error(png_ptr, strerror(errno));
if (fwrite(buffer, cb, 1, io->output) != 1)
{
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
if (row != NULL) free(row);
if (display != NULL) free(display);
return 0;
perror("temporary file");
fprintf(stderr, "temporary file PNG write failed\n");
exit(1);
}
}
png_init_io(png_ptr, fp);
static void read_by_row(png_structp png_ptr, png_infop info_ptr,
FILE *write_ptr, FILE *read_ptr)
{
/* These don't get freed on error, this is fine; the program immediately
* exits.
*/
png_bytep row = NULL, display = NULL;
io_data io_copy;
info_ptr = png_create_info_struct(png_ptr);
if (info_ptr == NULL)
png_error(png_ptr, "OOM allocating info structure");
if (write_ptr != NULL)
{
/* Set up for a copy to the temporary file: */
io_copy.input = read_ptr;
io_copy.output = write_ptr;
png_set_read_fn(png_ptr, &io_copy, read_and_copy);
}
png_read_info(png_ptr, info_ptr);
{
png_size_t rowbytes = png_get_rowbytes(png_ptr, info_ptr);
row = malloc(rowbytes);
display = malloc(rowbytes);
row = voidcast(png_bytep,malloc(rowbytes));
display = voidcast(png_bytep,malloc(rowbytes));
if (row == NULL || display == NULL)
png_error(png_ptr, "OOM allocating row buffers");
@@ -81,7 +120,8 @@ static int read_png(FILE *fp)
png_uint_32 y = height;
/* NOTE: this trashes the row each time; interlace handling won't
* work, but this avoids memory thrashing for speed testing.
* work, but this avoids memory thrashing for speed testing and is
* somewhat representative of an application that works row-by-row.
*/
while (y-- > 0)
png_read_row(png_ptr, row, display);
@@ -91,9 +131,51 @@ static int read_png(FILE *fp)
/* Make sure to read to the end of the file: */
png_read_end(png_ptr, info_ptr);
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
/* Free this up: */
free(row);
free(display);
}
static PNG_CALLBACK(void, no_warnings, (png_structp png_ptr,
png_const_charp warning))
{
(void)png_ptr;
(void)warning;
}
static int read_png(FILE *fp, png_int_32 transforms, FILE *write_file)
{
png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,0,0,
no_warnings);
png_infop info_ptr = NULL;
if (png_ptr == NULL)
return 0;
if (setjmp(png_jmpbuf(png_ptr)))
{
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
return 0;
}
# ifdef PNG_BENIGN_ERRORS_SUPPORTED
png_set_benign_errors(png_ptr, 1/*allowed*/);
# endif
png_init_io(png_ptr, fp);
info_ptr = png_create_info_struct(png_ptr);
if (info_ptr == NULL)
png_error(png_ptr, "OOM allocating info structure");
if (transforms < 0)
read_by_row(png_ptr, info_ptr, write_file, fp);
else
png_read_png(png_ptr, info_ptr, transforms, NULL/*params*/);
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
return 1;
}
@@ -108,7 +190,7 @@ static int mytime(struct timespec *t)
return 0;
}
static int perform_one_test(FILE *fp, int nfiles)
static int perform_one_test(FILE *fp, int nfiles, png_int_32 transforms)
{
int i;
struct timespec before, after;
@@ -120,7 +202,7 @@ static int perform_one_test(FILE *fp, int nfiles)
{
for (i=0; i<nfiles; ++i)
{
if (read_png(fp))
if (read_png(fp, transforms, NULL/*write*/))
{
if (ferror(fp))
{
@@ -184,120 +266,343 @@ static int add_one_file(FILE *fp, char *name)
if (ip != NULL)
{
int ch;
for (;;)
/* Read the file using libpng; this detects errors and also deals with
* files which contain data beyond the end of the file.
*/
int ok = 0;
fpos_t pos;
if (fgetpos(fp, &pos))
{
ch = getc(ip);
if (ch == EOF) break;
putc(ch, fp);
/* Fatal error reading the start: */
perror("temporary file");
fprintf(stderr, "temporary file fgetpos error\n");
exit(1);
}
if (ferror(ip))
if (read_png(ip, -1/*by row*/, fp/*output*/))
{
perror(name);
fprintf(stderr, "%s: read error\n", name);
return 0;
if (ferror(ip))
{
perror(name);
fprintf(stderr, "%s: read error\n", name);
}
else
ok = 1; /* read ok */
}
else
fprintf(stderr, "%s: file not added\n", name);
(void)fclose(ip);
/* An error in the output is fatal; exit immediately: */
if (ferror(fp))
{
perror("temporary file");
fprintf(stderr, "temporary file write error\n");
return 0;
exit(1);
}
if (ok)
return 1;
/* Did not read the file successfully, simply rewind the temporary
* file. This must happen after the ferror check above to avoid clearing
* the error.
*/
if (fsetpos(fp, &pos))
{
perror("temporary file");
fprintf(stderr, "temporary file fsetpos error\n");
exit(1);
}
}
else
{
/* file open error: */
perror(name);
fprintf(stderr, "%s: open failed\n", name);
return 0;
}
return 1;
return 0; /* file not added */
}
static void
usage(FILE *fp)
{
if (fp != NULL) fclose(fp);
fprintf(stderr,
"Usage:\n"
" timepng --assemble <assembly> {files}\n"
" Read the files into <assembly>, output the count. Options are ignored.\n"
" timepng --dissemble <assembly> <count> [options]\n"
" Time <count> files from <assembly>, additional files may not be given.\n"
" Otherwise:\n"
" Read the files into a temporary file and time the decode\n"
"Transforms:\n"
" --by-image: read by image with png_read_png\n"
" --<transform>: implies by-image, use PNG_TRANSFORM_<transform>\n"
" Otherwise: read by row using png_read_row (to a single row buffer)\n"
/* ISO C90 string length max 509 */);fprintf(stderr,
"{files}:\n"
" PNG files to copy into the assembly and time. Invalid files are skipped\n"
" with appropriate error messages. If no files are given the list of files\n"
" is read from stdin with each file name terminated by a newline\n"
"Output:\n"
" For --assemble the output is the name of the assembly file followed by the\n"
" count of the files it contains; the arguments for --dissemble. Otherwise\n"
" the output is the total decode time in seconds.\n");
exit(99);
}
int main(int argc, char **argv)
{
int ok = 0;
FILE *fp = tmpfile();
int err = 0;
int nfiles = 0;
int transforms = -1; /* by row */
const char *assembly = NULL;
FILE *fp;
if (fp != NULL)
if (argc > 2 && strcmp(argv[1], "--assemble") == 0)
{
int err = 0;
int nfiles = 0;
if (argc > 1)
/* Just build the test file, argv[2] is the file name. */
assembly = argv[2];
fp = fopen(assembly, "wb");
if (fp == NULL)
{
int i;
perror(assembly);
fprintf(stderr, "timepng --assemble %s: could not open for write\n",
assembly);
usage(NULL);
}
for (i=1; i<argc; ++i)
argv += 2;
argc -= 2;
}
else if (argc > 3 && strcmp(argv[1], "--dissemble") == 0)
{
fp = fopen(argv[2], "rb");
if (fp == NULL)
{
perror(argv[2]);
fprintf(stderr, "timepng --dissemble %s: could not open for read\n",
argv[2]);
usage(NULL);
}
nfiles = atoi(argv[3]);
if (nfiles <= 0)
{
fprintf(stderr,
"timepng --dissemble <file> <count>: %s is not a count\n",
argv[3]);
exit(99);
}
#ifdef __COVERITY__
else
{
nfiles &= PNG_UINT_31_MAX;
}
#endif
argv += 3;
argc -= 3;
}
else /* Else use a temporary file */
{
#ifndef __COVERITY__
fp = tmpfile();
#else
/* Experimental. Coverity says tmpfile() is insecure because it
* generates predictable names.
*
* It is possible to satisfy Coverity by using mkstemp(); however,
* any platform supporting mkstemp() undoubtedly has a secure tmpfile()
* implementation as well, and doesn't need the fix. Note that
* the fix won't work on platforms that don't support mkstemp().
*
* https://www.securecoding.cert.org/confluence/display/c/
* FIO21-C.+Do+not+create+temporary+files+in+shared+directories
* says that most historic implementations of tmpfile() provide
* only a limited number of possible temporary file names
* (usually 26) before file names are recycled. That article also
* provides a secure solution that unfortunately depends upon mkstemp().
*/
char tmpfile[] = "timepng-XXXXXX";
int filedes;
umask(0177);
filedes = mkstemp(tmpfile);
if (filedes < 0)
fp = NULL;
else
{
fp = fdopen(filedes,"w+");
/* Hide the filename immediately and ensure that the file does
* not exist after the program ends
*/
(void) unlink(tmpfile);
}
#endif
if (fp == NULL)
{
perror("tmpfile");
fprintf(stderr, "timepng: could not open the temporary file\n");
exit(1); /* not a user error */
}
}
/* Handle the transforms: */
while (argc > 1 && argv[1][0] == '-' && argv[1][1] == '-')
{
const char *opt = *++argv + 2;
--argc;
/* Transforms turn on the by-image processing and maybe set some
* transforms:
*/
if (transforms == -1)
transforms = PNG_TRANSFORM_IDENTITY;
if (strcmp(opt, "by-image") == 0)
{
/* handled above */
}
# define OPT(name) else if (strcmp(opt, #name) == 0)\
transforms |= PNG_TRANSFORM_ ## name
OPT(STRIP_16);
OPT(STRIP_ALPHA);
OPT(PACKING);
OPT(PACKSWAP);
OPT(EXPAND);
OPT(INVERT_MONO);
OPT(SHIFT);
OPT(BGR);
OPT(SWAP_ALPHA);
OPT(SWAP_ENDIAN);
OPT(INVERT_ALPHA);
OPT(STRIP_FILLER);
OPT(STRIP_FILLER_BEFORE);
OPT(STRIP_FILLER_AFTER);
OPT(GRAY_TO_RGB);
OPT(EXPAND_16);
OPT(SCALE_16);
else
{
fprintf(stderr, "timepng %s: unrecognized transform\n", opt);
usage(fp);
}
}
/* Handle the files: */
if (argc > 1 && nfiles > 0)
usage(fp); /* Additional files not valid with --dissemble */
else if (argc > 1)
{
int i;
for (i=1; i<argc; ++i)
{
if (nfiles == INT_MAX)
{
if (add_one_file(fp, argv[i]))
fprintf(stderr, "%s: skipped, too many files\n", argv[i]);
break;
}
else if (add_one_file(fp, argv[i]))
++nfiles;
}
}
else if (nfiles == 0) /* Read from stdin withoout --dissemble */
{
char filename[FILENAME_MAX+1];
while (fgets(filename, FILENAME_MAX+1, stdin))
{
size_t len = strlen(filename);
if (filename[len-1] == '\n')
{
filename[len-1] = 0;
if (nfiles == INT_MAX)
{
fprintf(stderr, "%s: skipped, too many files\n", filename);
break;
}
else if (add_one_file(fp, filename))
++nfiles;
}
else
{
fprintf(stderr, "timepng: file name too long: ...%s\n",
filename+len-32);
err = 1;
break;
}
}
if (ferror(stdin))
{
fprintf(stderr, "timepng: stdin: read error\n");
err = 1;
}
}
/* Perform the test, or produce the --assemble output: */
if (!err)
{
if (nfiles > 0)
{
if (assembly != NULL)
{
if (fflush(fp) && !ferror(fp) && fclose(fp))
{
perror(assembly);
fprintf(stderr, "%s: close failed\n", assembly);
}
else
{
err = 1;
break;
printf("%s %d\n", assembly, nfiles);
fflush(stdout);
ok = !ferror(stdout);
}
}
else
{
ok = perform_one_test(fp, nfiles, transforms);
(void)fclose(fp);
}
}
else
{
char filename[FILENAME_MAX+1];
while (fgets(filename, FILENAME_MAX+1, stdin))
{
size_t len = strlen(filename);
if (filename[len-1] == '\n')
{
filename[len-1] = 0;
if (add_one_file(fp, filename))
++nfiles;
else
{
err = 1;
break;
}
}
else
{
fprintf(stderr, "timepng: truncated file name ...%s\n",
filename+len-32);
err = 1;
break;
}
}
if (ferror(stdin))
{
fprintf(stderr, "timepng: stdin: read error\n");
err = 1;
}
}
if (!err)
{
if (nfiles > 0)
ok = perform_one_test(fp, nfiles);
else
fprintf(stderr, "usage: timepng {files} or ls files | timepng\n");
}
(void)fclose(fp);
usage(fp);
}
else
fprintf(stderr, "timepng: could not open temporary file\n");
(void)fclose(fp);
/* Exit code 0 on success. */
return ok == 0;
}
#else /* !sufficient support */
int main(void) { return 77; }
#endif /* !sufficient support */

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
libpng-manual.txt - A description on how to use and modify libpng
libpng version 1.7.0beta79 - March 9, 2016
libpng version 1.7.0beta82 - July 4, 2016
Updated and distributed by Glenn Randers-Pehrson
<glennrp at users.sourceforge.net>
Copyright (c) 1998-2015 Glenn Randers-Pehrson
@@ -11,7 +11,7 @@ libpng-manual.txt - A description on how to use and modify libpng
Based on:
libpng versions 0.97, January 1998, through 1.7.0beta79 - March 9, 2016
libpng versions 0.97, January 1998, through 1.7.0beta82 - July 4, 2016
Updated and distributed by Glenn Randers-Pehrson
Copyright (c) 1998-2015 Glenn Randers-Pehrson
@@ -563,7 +563,7 @@ non-interlaced case the row that was just handled is simply one less than the
passed in row number, and pass will always be 0. For the interlaced case the
same applies unless the row value is 0, in which case the row just handled was
the last one from one of the preceding passes. Because interlacing may skip a
pass you cannot be sure that the preceding pass is just 'pass-1', if you really
pass you cannot be sure that the preceding pass is just 'pass-1'; if you really
need to know what the last pass is record (row,pass) from the callback and use
the last recorded value each time.
@@ -5343,7 +5343,7 @@ Since the PNG Development group is an ad-hoc body, we can't make
an official declaration.
This is your unofficial assurance that libpng from version 0.71 and
upward through 1.7.0beta79 are Y2K compliant. It is my belief that earlier
upward through 1.7.0beta82 are Y2K compliant. It is my belief that earlier
versions were also Y2K compliant.
Libpng only has two year fields. One is a 2-byte unsigned integer

View File

@@ -1,6 +1,6 @@
.TH LIBPNG 3 "March 9, 2016"
.TH LIBPNG 3 "July 4, 2016"
.SH NAME
libpng \- Portable Network Graphics (PNG) Reference Library 1.7.0beta79
libpng \- Portable Network Graphics (PNG) Reference Library 1.7.0beta82
.SH SYNOPSIS
\fB
#include <png.h>\fP
@@ -500,7 +500,7 @@ Following is a copy of the libpng-manual.txt file that accompanies libpng.
.SH LIBPNG.TXT
libpng-manual.txt - A description on how to use and modify libpng
libpng version 1.7.0beta79 - March 9, 2016
libpng version 1.7.0beta82 - July 4, 2016
Updated and distributed by Glenn Randers-Pehrson
<glennrp at users.sourceforge.net>
Copyright (c) 1998-2015 Glenn Randers-Pehrson
@@ -511,7 +511,7 @@ libpng-manual.txt - A description on how to use and modify libpng
Based on:
libpng versions 0.97, January 1998, through 1.7.0beta79 - March 9, 2016
libpng versions 0.97, January 1998, through 1.7.0beta82 - July 4, 2016
Updated and distributed by Glenn Randers-Pehrson
Copyright (c) 1998-2015 Glenn Randers-Pehrson
@@ -1063,7 +1063,7 @@ non-interlaced case the row that was just handled is simply one less than the
passed in row number, and pass will always be 0. For the interlaced case the
same applies unless the row value is 0, in which case the row just handled was
the last one from one of the preceding passes. Because interlacing may skip a
pass you cannot be sure that the preceding pass is just 'pass\-1', if you really
pass you cannot be sure that the preceding pass is just 'pass\-1'; if you really
need to know what the last pass is record (row,pass) from the callback and use
the last recorded value each time.
@@ -5843,7 +5843,7 @@ Since the PNG Development group is an ad-hoc body, we can't make
an official declaration.
This is your unofficial assurance that libpng from version 0.71 and
upward through 1.7.0beta79 are Y2K compliant. It is my belief that earlier
upward through 1.7.0beta82 are Y2K compliant. It is my belief that earlier
versions were also Y2K compliant.
Libpng only has two year fields. One is a 2-byte unsigned integer
@@ -5940,15 +5940,14 @@ the first widely used release:
...
1.0.19 10 10019 10.so.0.19[.0]
...
1.2.53 13 10253 12.so.0.53[.0]
1.2.56 13 10253 12.so.0.53[.0]
...
1.5.23 15 10523 15.so.15.23[.0]
1.5.27 15 10523 15.so.15.23[.0]
...
1.6.19beta01-04 16 10619 16.so.16.19[.0]
1.6.19rc01-03 16 10619 16.so.16.19[.0]
1.6.22 16 10622 16.so.16.22[.0]
...
1.7.0alpha01-10 17 10700 17.so.17.0[.0]
1.7.0beta01-79 17 10700 17.so.17.0[.0]
1.7.0beta01-82 17 10700 17.so.17.0[.0]
Henceforth the source version will match the shared-library minor
and patch numbers; the shared-library major version number will be
@@ -6004,7 +6003,7 @@ possible without all of you.
Thanks to Frank J. T. Wojcik for helping with the documentation.
Libpng version 1.7.0beta79 - March 9, 2016:
Libpng version 1.7.0beta82 - July 4, 2016:
Initially created in 1995 by Guy Eric Schalnat, then of Group 42, Inc.
Currently maintained by Glenn Randers-Pehrson (glennrp at users.sourceforge.net).
@@ -6029,7 +6028,7 @@ this sentence.
This code is released under the libpng license.
libpng versions 1.0.7, July 1, 2000, through 1.7.0beta79, March 9, 2016, are
libpng versions 1.0.7, July 1, 2000, through 1.7.0beta82, July 4, 2016, are
Copyright (c) 2000-2002, 2004, 2006-2016 Glenn Randers-Pehrson, are
derived from libpng-1.0.6, and are distributed according to the same
disclaimer and license as libpng-1.0.6 with the following individuals
@@ -6128,7 +6127,7 @@ the additional disclaimers inserted at version 1.0.7.
Glenn Randers-Pehrson
glennrp at users.sourceforge.net
March 9, 2016
July 4, 2016
.\" end of man page

View File

@@ -1,6 +1,6 @@
.TH LIBPNGPF 3 "March 9, 2016"
.TH LIBPNGPF 3 "July 4, 2016"
.SH NAME
libpng \- Portable Network Graphics (PNG) Reference Library 1.7.0beta79
libpng \- Portable Network Graphics (PNG) Reference Library 1.7.0beta82
(private functions)
.SH SYNOPSIS
\fB#include \fI"pngpriv.h"

4
png.5
View File

@@ -1,4 +1,4 @@
.TH PNG 5 "March 9, 2016"
.TH PNG 5 "July 4, 2016"
.SH NAME
png \- Portable Network Graphics (PNG) format
.SH DESCRIPTION
@@ -36,7 +36,7 @@ PNG 1.0 specification, October 1996:
RFC 2083
.IP
.br
ftp://ds.internic.net/rfc/rfc2083.txt
http://www.ietf.org/rfc/rfc2083.txt
.br
or (as a W3C Recommendation) at
.br

270
png.c
View File

@@ -15,7 +15,7 @@
#define PNG_SRC_FILE PNG_SRC_FILE_png
/* Generate a compiler error if there is an old png.h in the search path. */
typedef png_libpng_version_1_7_0beta79 Your_png_h_is_not_version_1_7_0beta79;
typedef png_libpng_version_1_7_0beta82 Your_png_h_is_not_version_1_7_0beta82;
/* Tells libpng that we have already handled the first "num_bytes" bytes
* of the PNG file signature. If the PNG data is embedded into another
@@ -100,10 +100,26 @@ png_zfree(voidpf png_ptr, voidpf ptr)
* in case CRC is > 32 bits to leave the top bits 0.
*/
void /* PRIVATE */
png_reset_crc(png_structrp png_ptr)
png_reset_crc(png_structrp png_ptr, png_const_bytep chunk_tag)
{
/* The cast is safe because the crc is a 32 bit value. */
png_ptr->crc = (png_uint_32)crc32(0, Z_NULL, 0);
# ifdef PNG_READ_SUPPORTED
if (png_ptr->read_struct)
{
/* Set png_struct::current_crc appropriately. */
if (PNG_CHUNK_ANCILLARY(png_ptr->chunk_name))
png_ptr->current_crc = png_ptr->ancillary_crc;
else /* critical */
png_ptr->current_crc = png_ptr->critical_crc;
}
else
png_ptr->current_crc = crc_error_quit; /* for write */
/* Now do not calculate the CRC if it isn't required: */
if (png_ptr->current_crc != crc_quiet_use)
# endif /* READ */
png_ptr->crc = 0xFFFFFFFFU & crc32(0, chunk_tag, 4);
}
/* Calculate the CRC over a section of data. We can only pass as
@@ -114,27 +130,15 @@ png_reset_crc(png_structrp png_ptr)
void /* PRIVATE */
png_calculate_crc(png_structrp png_ptr, png_const_voidp ptr, png_size_t length)
{
int need_crc = 1;
if (PNG_CHUNK_ANCILLARY(png_ptr->chunk_name) != 0)
{
if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
(PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
need_crc = 0;
}
else /* critical */
{
if ((png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE) != 0)
need_crc = 0;
}
/* 'uLong' is defined in zlib.h as unsigned long; this means that on some
* systems it is a 64 bit value. crc32, however, returns 32 bits so the
* following cast is safe. 'uInt' may be no more than 16 bits, so it is
* necessary to perform a loop here.
*/
if (need_crc != 0 && length > 0)
# ifdef PNG_READ_SUPPORTED
if (png_ptr->current_crc != crc_quiet_use)
# endif /* READ */
if (length > 0)
{
uLong crc = png_ptr->crc; /* Should never issue a warning */
const Bytef* rptr = png_voidcast(const Bytef*,ptr);
@@ -171,58 +175,53 @@ png_calculate_crc(png_structrp png_ptr, png_const_voidp ptr, png_size_t length)
/* Check a user supplied version number, called from both read and write
* functions that create a png_struct.
*/
int
static int
png_user_version_check(png_structrp png_ptr, png_const_charp user_png_ver)
{
/* Libpng versions 1.0.0 and later are binary compatible if the version
* string matches through the second '.'; we must recompile any
* applications that use any older library version.
*/
/* Libpng versions 1.0.0 and later are binary compatible if the version
* string matches through the second '.'; we must recompile any applications
* that use any older library version.
*/
if (user_png_ver != NULL)
{
int library_match = 1;
int i = -1;
int found_dots = 0;
unsigned int found_dots = 0;
do
{
i++;
if (user_png_ver[i] != PNG_LIBPNG_VER_STRING[i])
png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
library_match = 0;
if (user_png_ver[i] == '.')
found_dots++;
} while (found_dots < 2 && user_png_ver[i] != 0 &&
} while (library_match && found_dots < 2 && user_png_ver[i] != 0 &&
PNG_LIBPNG_VER_STRING[i] != 0);
if (library_match)
return 1; /* Library matches ok */
}
else
png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
if ((png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH) != 0)
{
/* Failure: mismatched library major version number */
#ifdef PNG_WARNINGS_SUPPORTED
{
size_t pos = 0;
char m[128];
pos = png_safecat(m, (sizeof m), pos,
"Application built with libpng-");
/* This is ok if user_png_ver is NULL, it appends nothing: */
pos = png_safecat(m, (sizeof m), pos, user_png_ver);
pos = png_safecat(m, (sizeof m), pos, " but running with ");
pos = png_safecat(m, (sizeof m), pos, PNG_LIBPNG_VER_STRING);
PNG_UNUSED(pos)
png_warning(png_ptr, m);
#endif
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
png_ptr->flags = 0;
#endif
return 0;
png_app_warning(png_ptr, m);
}
#endif
/* Success return. */
return 1;
return 0; /* Failure */
PNG_UNUSED(png_ptr) /* if no warning */
}
/* Generic function to create a png_struct for either read or write - this
@@ -705,14 +704,14 @@ png_get_copyright(png_const_structrp png_ptr)
#else
# ifdef __STDC__
return PNG_STRING_NEWLINE \
"libpng version 1.7.0beta79 - March 9, 2016" PNG_STRING_NEWLINE \
"libpng version 1.7.0beta82 - July 4, 2016" PNG_STRING_NEWLINE \
"Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson" \
PNG_STRING_NEWLINE \
"Copyright (c) 1996-1997 Andreas Dilger" PNG_STRING_NEWLINE \
"Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc." \
PNG_STRING_NEWLINE;
# else
return "libpng version 1.7.0beta79 - March 9, 2016\
return "libpng version 1.7.0beta82 - July 4, 2016\
Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson\
Copyright (c) 1996-1997 Andreas Dilger\
Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.";
@@ -2192,13 +2191,12 @@ png_compare_ICC_profile_with_sRGB(png_const_structrp png_ptr,
#endif
unsigned int i;
#ifdef PNG_SET_OPTION_SUPPORTED
/* First see if PNG_SKIP_sRGB_CHECK_PROFILE has been set to "on" */
if (((png_ptr->options >> PNG_SKIP_sRGB_CHECK_PROFILE) & 3) ==
PNG_OPTION_ON)
return 0;
#endif
# ifdef PNG_SET_OPTION_SUPPORTED
# ifdef PNG_SKIP_sRGB_CHECK_PROFILE
/* First see if PNG_SKIP_sRGB_CHECK_PROFILE has been set to "on" */
if (!png_ptr->skip_sRGB_profile_check)
# endif /* SKIP_sRGB_CHECK_PROFILE */
# endif /* SET_OPTION */
for (i=0; i < (sizeof png_sRGB_checks) / (sizeof png_sRGB_checks[0]); ++i)
{
if (png_get_uint_32(profile+84) == png_sRGB_checks[i].md5[0] &&
@@ -2293,7 +2291,6 @@ png_compare_ICC_profile_with_sRGB(png_const_structrp png_ptr,
return 0; /* no match */
}
#endif /* PNG_sRGB_PROFILE_CHECKS >= 0 */
void /* PRIVATE */
png_icc_set_sRGB(png_const_structrp png_ptr,
@@ -2302,12 +2299,11 @@ png_icc_set_sRGB(png_const_structrp png_ptr,
/* Is this profile one of the known ICC sRGB profiles? If it is, just set
* the sRGB information.
*/
#if PNG_sRGB_PROFILE_CHECKS >= 0
if (png_compare_ICC_profile_with_sRGB(png_ptr, profile, adler) != 0)
#endif
(void)png_colorspace_set_sRGB(png_ptr, colorspace,
(int)/*already checked*/png_get_uint_32(profile+64));
}
#endif /* PNG_sRGB_PROFILE_CHECKS >= 0 */
#endif /* sRGB */
int /* PRIVATE */
@@ -2324,7 +2320,7 @@ png_colorspace_set_ICC(png_const_structrp png_ptr, png_colorspacerp colorspace,
png_icc_check_tag_table(png_ptr, colorspace, name, profile_length,
profile) != 0)
{
# ifdef PNG_sRGB_SUPPORTED
# if defined(PNG_sRGB_SUPPORTED) && PNG_sRGB_PROFILE_CHECKS >= 0
/* If no sRGB support, don't try storing sRGB information */
png_icc_set_sRGB(png_ptr, colorspace, profile, 0);
# endif
@@ -3355,67 +3351,129 @@ png_muldiv(png_fixed_point_p res, png_fixed_point a, png_int_32 times,
}
#endif /* GAMMA || INCH_CONVERSIONS */
/* HARDWARE OPTION SUPPORT */
#ifdef PNG_SET_OPTION_SUPPORTED
int PNGAPI
png_set_option(png_structrp png_ptr, int option, int onoff)
{
if (png_ptr != NULL && option >= 0 && option < PNG_OPTION_NEXT &&
(option & 1) == 0)
{
unsigned int mask = 3U << option;
unsigned int setting = (2U + (onoff != 0)) << option;
unsigned int current = png_ptr->options;
png_ptr->options = (current & ~mask) | setting;
return (current & mask) >> option;
}
return PNG_OPTION_INVALID;
}
#endif /* SET_OPTION */
/* SOFTWARE SETTING SUPPORT */
#ifdef PNG_SETTING_SUPPORTED
png_int_32 PNGAPI
png_setting(png_structrp png_ptr, int setting, png_int_32 value)
png_setting(png_structrp png_ptr, png_uint_32 setting, png_uint_32 parameter,
png_int_32 value)
{
switch (setting)
png_int_32 result;
if (png_ptr != NULL)
{
# ifdef PNG_READ_GAMMA_SUPPORTED
case PNG_GAMMA_MINIMUM:
if (value < 0 || value > 0xFFFF)
value = PNG_GAMMA_THRESHOLD_FIXED;
int handle_error = (setting & PNG_SF_ERROR) != 0U;
setting &= ~PNG_SF_ERROR; /* because it is handled below. */
switch (setting & (PNG_SF_READ|PNG_SF_WRITE))
{
# ifdef PNG_READ_SUPPORTED
case PNG_SF_READ:
if (png_ptr->read_struct)
result = png_read_setting(png_ptr, setting, parameter, value);
else
result = PNG_EINVAL; /* read setting on write struct */
break;
# endif /* READ */
# ifdef PNG_WRITE_SUPPORTED
case PNG_SF_WRITE:
if (!png_ptr->read_struct)
result = png_write_setting(png_ptr, setting, parameter,
value);
else
result = PNG_EINVAL; /* write setting on read struct */
break;
# endif /* WRITE */
default:
/* Handle everything else here. This includes the error of not
* having either read or write set; that error will cause a
* PNG_ENOSYS return code.
*/
switch (setting)
{
png_int_32 old = png_ptr->gamma_threshold;
png_ptr->gamma_threshold = PNG_UINT_16(value);
return old;
# ifdef PNG_SET_OPTION_SUPPORTED
case PNG_SRW_OPTION:
if (parameter >= PNG_OPTION_NEXT)
return PNG_OPTION_INVALID;
if (parameter == PNG_SKIP_sRGB_CHECK_PROFILE)
{
if (png_ptr->skip_sRGB_profile_check)
{
if (!value)
png_ptr->skip_sRGB_profile_check = 0U;
result = PNG_OPTION_ON;
}
else
{
if (value)
png_ptr->skip_sRGB_profile_check = 1U;
result = PNG_OPTION_OFF;
}
break;
}
# ifdef PNG_READ_SUPPORTED
if (png_ptr->read_struct)
{
result = png_read_setting(png_ptr, setting,
parameter, value);
break;
}
# endif /* READ */
/* No write options at present */
result = PNG_OPTION_UNSET; /* i.e. ignore it */
break;
# endif /* SET_OPTION */
default:
/* Any other option; handle in the appropriate setting: */
# ifdef PNG_READ_SUPPORTED
if (png_ptr->read_struct)
{
result = png_read_setting(png_ptr, setting,
parameter, value);
break;
}
# endif /* READ */
# ifdef PNG_WRITE_SUPPORTED
if (!png_ptr->read_struct)
{
result = png_write_setting(png_ptr, setting,
parameter, value);
break;
}
# endif /* WRITE */
NOT_REACHED;
result= PNG_ENOSYS;
break;
}
break;
} /* switch */
#if 0 /*NYI*/
case PNG_GAMMA_ACCURACY:
if (value < 0 || value > 1600)
value = PNG_DEFAULT_GAMMA_ACCURACY;
{
png_int_32 old = png_ptr->gamma_accuracy;
png_ptr->gamma_accuracy = value;
return old;
}
break;
#endif /*NYI*/
# endif /* READ_GAMMA */
default:
break;
/* Handle error returns here.
* TODO: this is crude, should use a formatted warning style message and
* output result/setting/parameter/value.
*/
if (handle_error && PNG_FAILED(result))
png_error(png_ptr, "png_setting");
}
PNG_UNUSED(png_ptr)
else /* png_ptr is NULL */
result = PNG_EINVAL;
return result;
PNG_UNUSED(parameter)
PNG_UNUSED(value)
return PNG_UNSUPPORTED_SETTING;
}
#endif /* SETTING */
/* sRGB support */
#if defined(PNG_SIMPLIFIED_READ_SUPPORTED) ||\

869
png.h

File diff suppressed because it is too large Load Diff

View File

@@ -1,7 +1,7 @@
/* pngconf.h - machine configurable file for libpng
*
* libpng version 1.7.0beta79, March 9, 2016
* libpng version 1.7.0beta82, July 4, 2016
*
* Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)

View File

@@ -35,9 +35,6 @@
#define PNGDEBUG_H
/* These settings control the formatting of messages in png.c and pngerror.c */
/* Moved to pngdebug.h at 1.5.0 */
# ifndef PNG_LITERAL_SHARP
# define PNG_LITERAL_SHARP 0x23U
# endif
# ifndef PNG_LITERAL_LEFT_SQUARE_BRACKET
# define PNG_LITERAL_LEFT_SQUARE_BRACKET 0x5bU
# endif

View File

@@ -40,46 +40,6 @@ PNG_FUNCTION(void,PNGAPI
png_error,(png_const_structrp png_ptr, png_const_charp error_message),
PNG_NORETURN)
{
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
char msg[16];
if (png_ptr != NULL)
{
if ((png_ptr->flags &
(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT)) != 0)
{
if (*error_message == PNG_LITERAL_SHARP)
{
/* Strip "#nnnn " from beginning of error message. */
int offset;
for (offset = 1; offset<15; offset++)
if (error_message[offset] == ' ')
break;
if ((png_ptr->flags & PNG_FLAG_STRIP_ERROR_TEXT) != 0)
{
int i;
for (i = 0; i < offset - 1; i++)
msg[i] = error_message[i + 1];
msg[i - 1] = '\0';
error_message = msg;
}
else
error_message += offset;
}
else
{
if ((png_ptr->flags & PNG_FLAG_STRIP_ERROR_TEXT) != 0)
{
msg[0] = '0';
msg[1] = '\0';
error_message = msg;
}
}
}
}
#endif
if (png_ptr != NULL && png_ptr->error_fn != NULL)
(*(png_ptr->error_fn))(png_constcast(png_structrp,png_ptr),
error_message);
@@ -218,21 +178,6 @@ void PNGAPI
png_warning(png_const_structrp png_ptr, png_const_charp warning_message)
{
int offset = 0;
if (png_ptr != NULL)
{
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
if ((png_ptr->flags &
(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT)) != 0)
#endif
{
if (*warning_message == PNG_LITERAL_SHARP)
{
for (offset = 1; offset < 15; offset++)
if (warning_message[offset] == ' ')
break;
}
}
}
if (png_ptr != NULL && png_ptr->warning_fn != NULL)
(*(png_ptr->warning_fn))(png_constcast(png_structrp,png_ptr),
warning_message + offset);
@@ -363,24 +308,41 @@ png_formatted_warning(png_const_structrp png_ptr, png_warning_parameters p,
void PNGAPI
png_benign_error(png_const_structrp png_ptr, png_const_charp error_message)
{
if ((png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN) != 0)
switch (png_ptr->benign_error_action)
{
# ifdef PNG_READ_SUPPORTED
if (png_ptr->read_struct && png_ptr->chunk_name != 0)
png_chunk_warning(png_ptr, error_message);
else
# endif
png_warning(png_ptr, error_message);
case PNG_ERROR:
png_chunk_error(png_ptr, error_message);
break;
case PNG_WARN:
png_chunk_warning(png_ptr, error_message);
break;
default: /* PNG_IGNORE */
break;
}
else
# ifndef PNG_ERROR_TEXT_SUPPORTED
PNG_UNUSED(error_message)
# endif
}
static void
app_error(png_const_structrp png_ptr, png_const_charp error_message,
unsigned int error_action)
{
switch (error_action)
{
# ifdef PNG_READ_SUPPORTED
if (png_ptr->read_struct && png_ptr->chunk_name != 0)
png_chunk_error(png_ptr, error_message);
else
# endif
png_error(png_ptr, error_message);
case PNG_ERROR:
png_error(png_ptr, error_message);
break;
case PNG_WARN:
png_warning(png_ptr, error_message);
break;
default: /* PNG_IGNORE */
break;
}
# ifndef PNG_ERROR_TEXT_SUPPORTED
@@ -391,27 +353,13 @@ png_benign_error(png_const_structrp png_ptr, png_const_charp error_message)
void /* PRIVATE */
png_app_warning(png_const_structrp png_ptr, png_const_charp error_message)
{
if ((png_ptr->flags & PNG_FLAG_APP_WARNINGS_WARN) != 0)
png_warning(png_ptr, error_message);
else
png_error(png_ptr, error_message);
# ifndef PNG_ERROR_TEXT_SUPPORTED
PNG_UNUSED(error_message)
# endif
app_error(png_ptr, error_message, png_ptr->app_warning_action);
}
void /* PRIVATE */
png_app_error(png_const_structrp png_ptr, png_const_charp error_message)
{
if ((png_ptr->flags & PNG_FLAG_APP_ERRORS_WARN) != 0)
png_warning(png_ptr, error_message);
else
png_error(png_ptr, error_message);
# ifndef PNG_ERROR_TEXT_SUPPORTED
PNG_UNUSED(error_message)
# endif
app_error(png_ptr, error_message, png_ptr->app_error_action);
}
#endif /* BENIGN_ERRORS */
@@ -488,7 +436,7 @@ png_chunk_error,(png_const_structrp png_ptr, png_const_charp error_message),
PNG_NORETURN)
{
char msg[18+PNG_MAX_ERROR_TEXT];
if (png_ptr == NULL)
if (png_ptr == NULL || png_ptr->chunk_name == 0U)
png_error(png_ptr, error_message);
else
@@ -504,7 +452,7 @@ void PNGAPI
png_chunk_warning(png_const_structrp png_ptr, png_const_charp warning_message)
{
char msg[18+PNG_MAX_ERROR_TEXT];
if (png_ptr == NULL)
if (png_ptr == NULL || png_ptr->chunk_name == 0U)
png_warning(png_ptr, warning_message);
else
@@ -521,17 +469,25 @@ void PNGAPI
png_chunk_benign_error(png_const_structrp png_ptr, png_const_charp
error_message)
{
if ((png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN) != 0)
png_chunk_warning(png_ptr, error_message);
switch (png_ptr->benign_error_action)
{
case PNG_ERROR:
png_chunk_error(png_ptr, error_message);
break;
else
png_chunk_error(png_ptr, error_message);
case PNG_WARN:
png_chunk_warning(png_ptr, error_message);
break;
default: /* PNG_IGNORE */
break;
}
# ifndef PNG_ERROR_TEXT_SUPPORTED
PNG_UNUSED(error_message)
# endif
}
#endif
#endif /* BENIGN_ERRORS */
#endif /* READ */
void /* PRIVATE */
@@ -732,37 +688,6 @@ png_default_error,(png_const_structrp png_ptr, png_const_charp error_message),
PNG_NORETURN)
{
#ifdef PNG_CONSOLE_IO_SUPPORTED
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
/* Check on NULL only added in 1.5.4 */
if (error_message != NULL && *error_message == PNG_LITERAL_SHARP)
{
/* Strip "#nnnn " from beginning of error message. */
int offset;
char error_number[16];
for (offset = 0; offset<15; offset++)
{
error_number[offset] = error_message[offset + 1];
if (error_message[offset] == ' ')
break;
}
if ((offset > 1) && (offset < 15))
{
error_number[offset - 1] = '\0';
fprintf(stderr, "libpng error no. %s: %s",
error_number, error_message + offset + 1);
fprintf(stderr, PNG_STRING_NEWLINE);
}
else
{
fprintf(stderr, "libpng error: %s, offset=%d",
error_message, offset);
fprintf(stderr, PNG_STRING_NEWLINE);
}
}
else
#endif
{
fprintf(stderr, "libpng error: %s", error_message ? error_message :
"undefined");
@@ -809,36 +734,6 @@ static void /* PRIVATE */
png_default_warning(png_const_structrp png_ptr, png_const_charp warning_message)
{
#ifdef PNG_CONSOLE_IO_SUPPORTED
# ifdef PNG_ERROR_NUMBERS_SUPPORTED
if (*warning_message == PNG_LITERAL_SHARP)
{
int offset;
char warning_number[16];
for (offset = 0; offset < 15; offset++)
{
warning_number[offset] = warning_message[offset + 1];
if (warning_message[offset] == ' ')
break;
}
if ((offset > 1) && (offset < 15))
{
warning_number[offset + 1] = '\0';
fprintf(stderr, "libpng warning no. %s: %s",
warning_number, warning_message + offset);
fprintf(stderr, PNG_STRING_NEWLINE);
}
else
{
fprintf(stderr, "libpng warning: %s",
warning_message);
fprintf(stderr, PNG_STRING_NEWLINE);
}
}
else
# endif
{
fprintf(stderr, "libpng warning: %s", warning_message);
fprintf(stderr, PNG_STRING_NEWLINE);
@@ -886,19 +781,6 @@ png_get_error_ptr(png_const_structrp png_ptr)
}
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
void PNGAPI
png_set_strip_error_numbers(png_structrp png_ptr, png_uint_32 strip_mode)
{
if (png_ptr != NULL)
{
png_ptr->flags &=
((PNG_BIC_MASK(PNG_FLAG_STRIP_ERROR_NUMBERS |
PNG_FLAG_STRIP_ERROR_TEXT))&strip_mode);
}
}
#endif
#if defined(PNG_SIMPLIFIED_READ_SUPPORTED) ||\
defined(PNG_SIMPLIFIED_WRITE_SUPPORTED)
/* Currently the above both depend on SETJMP_SUPPORTED, however it would be

View File

@@ -26,7 +26,9 @@ png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length)
return;
ptr = buffer;
if (png_ptr->save_buffer_size != 0)
debug(length > 0);
if (length > 0 && png_ptr->save_buffer_size > 0)
{
png_size_t save_size;
@@ -44,7 +46,7 @@ png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length)
png_ptr->save_buffer_ptr += save_size;
}
if (length != 0 && png_ptr->current_buffer_size != 0)
if (length > 0 && png_ptr->current_buffer_size > 0)
{
png_size_t save_size;
@@ -734,15 +736,13 @@ png_push_read_chunk_header(png_structrp png_ptr, png_infop info_ptr)
* of the data.
*/
unsigned int mode; /* mode prior to the header */
png_byte chunk_length[4];
png_byte chunk_tag[4];
png_byte chunk_header[8];
PNG_PUSH_SAVE_BUFFER_IF_LT(8)
png_push_fill_buffer(png_ptr, chunk_length, 4);
png_ptr->chunk_length = png_get_uint_31(png_ptr, chunk_length);
png_reset_crc(png_ptr);
png_crc_read(png_ptr, chunk_tag, 4);
png_ptr->chunk_name = PNG_CHUNK_FROM_STRING(chunk_tag);
png_push_fill_buffer(png_ptr, chunk_header, 8);
png_ptr->chunk_length = png_get_uint_31(png_ptr, chunk_header);
png_ptr->chunk_name = PNG_CHUNK_FROM_STRING(chunk_header+4);
png_reset_crc(png_ptr, chunk_header+4);
mode = png_ptr->mode;
png_ptr->process_mode = png_check_bits(png_ptr,
png_read_chunk+png_find_chunk_op(png_ptr), 4);

View File

@@ -390,7 +390,7 @@
#define PNG_SRC_FILE_pngwtran (PNG_SRC_FILE_pngwrite +4096)
#define PNG_SRC_FILE_pngwutil (PNG_SRC_FILE_pngwtran +1024)
#define PNG_SRC_FILE_arm_arm_init (PNG_SRC_FILE_pngwutil +4096)
#define PNG_SRC_FILE_arm_arm_init (PNG_SRC_FILE_pngwutil +8192)
#define PNG_SRC_FILE_arm_filter_neon_intrinsics\
(PNG_SRC_FILE_arm_arm_init +1024)
@@ -618,28 +618,6 @@
#define PNG_HAVE_IEND 0x10U
#define PNG_HAVE_PNG_SIGNATURE 0x20U
/* Flags for the png_ptr->flags.
* TODO: change to bit fields.
*/
#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)
#if defined(PNG_SIMPLIFIED_READ_SUPPORTED) ||\
defined(PNG_SIMPLIFIED_WRITE_SUPPORTED)
/* See below for the definitions of the tables used in these macros */
@@ -974,12 +952,6 @@ PNG_INTERNAL_FUNCTION(png_fixed_point,png_fixed,(png_const_structrp png_ptr,
double fp, png_const_charp text),PNG_EMPTY);
#endif
/* Check the user version string for compatibility, returns false if the version
* numbers aren't compatible.
*/
PNG_INTERNAL_FUNCTION(int,png_user_version_check,(png_structrp png_ptr,
png_const_charp user_png_ver),PNG_EMPTY);
/* Internal base allocator - no messages, NULL on failure to allocate. This
* does, however, call the application provided allocator and that could call
* png_error (although that would be a bug in the application implementation.)
@@ -1050,8 +1022,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,
@@ -1080,10 +1056,6 @@ PNG_INTERNAL_FUNCTION(int,png_crc_finish,(png_structrp png_ptr,
PNG_INTERNAL_FUNCTION(void,png_calculate_crc,(png_structrp png_ptr,
png_const_voidp ptr, png_size_t length),PNG_EMPTY);
#ifdef PNG_WRITE_FLUSH_SUPPORTED
PNG_INTERNAL_FUNCTION(void,png_flush,(png_structrp png_ptr),PNG_EMPTY);
#endif
/* Write various chunks */
/* Write the IHDR chunk, and update the png_struct with the necessary
@@ -1199,9 +1171,9 @@ PNG_INTERNAL_FUNCTION(void,png_write_sCAL_s,(png_structrp png_ptr,
#endif
#ifdef PNG_WRITE_SUPPORTED
/* Initialize the row compression mechanism. */
PNG_INTERNAL_FUNCTION(void, png_write_start_IDAT, (png_structp png_ptr),
PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_write_start_IDAT,(png_structrp png_ptr),
PNG_EMPTY);
/* Do any required initialization before IDAT or row processing starts. */
/* Choose the best filter to use and filter the row data then write it out. If
* WRITE_FILTERING is not supported this just writes the data out with a zero
@@ -1215,10 +1187,11 @@ PNG_INTERNAL_FUNCTION(void, png_write_start_IDAT, (png_structp png_ptr),
*/
enum
{
png_row_end =0x1U, /* This is the last block in the row */
png_pass_first_row =0x2U, /* This is the first row in a pass */
png_pass_last_row =0x4U, /* This is the last row in a pass */
png_pass_last =0x8U /* This is the last pass in the image */
png_pass_last =0x1U, /* This is the last pass in the image */
png_pass_last_row =0x2U, /* This is the last row in a pass */
png_pass_first_row =0x4U, /* This is the first row in a pass */
png_row_end =0x8U, /* This is the last block in the row */
png_no_row_info =0x0U /* Placeholder */
/* A useful macro; return true if this is the last block of the last row in
* the image.
@@ -1226,11 +1199,21 @@ enum
# define PNG_IDAT_END(f) (((f) & ~png_pass_first_row) == \
(png_row_end+png_pass_last_row+png_pass_last))
};
PNG_INTERNAL_FUNCTION(void, png_write_filter_row, (png_structrp png_ptr,
PNG_INTERNAL_FUNCTION(void,png_write_png_data,(png_structrp png_ptr,
png_bytep prev_pixels, png_const_bytep unfiltered_row, png_uint_32 x,
unsigned int width/*pixels*/, unsigned int row_info_flags),
PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_write_png_rows,(png_structrp png_ptr,
png_const_bytep *rows, png_uint_32 num_rows), PNG_EMPTY);
/* As above but rows[num_rows] of correctly (PNG) formated but unfiltered
* data are passed in. For an interlaced image the rows will be interlaced
* rows and therefore may be narrower than the image width.
*
* This function advances png_structp::pass and png_structp::row_number as
* required.
*/
/* Release memory used by the deflate mechanism */
PNG_INTERNAL_FUNCTION(void, png_deflate_destroy, (png_structp png_ptr),
PNG_EMPTY);
@@ -1371,7 +1354,12 @@ PNG_INTERNAL_FUNCTION(png_transformp,png_add_transform,(png_structrp png_ptr,
*
* PNG_RWTR_CHECK_PALETTE PI W11: happens in pngwrite.c last
*/
# define PNG_TR_INIT_ALPHA (PNG_TR_START + 0x0300U)
# define PNG_TR_START_CACHE (PNG_TR_START + 0x0300U)
/* Not used on a transform; this is just a marker for the point at which
* palette or low-bit-depth caching can start on read. (The previous
* operations cannot be cached).
*/
# define PNG_TR_INIT_ALPHA (PNG_TR_START + 0x0400U)
/* This just handles alpha/tRNS initialization issues to resolve the
* inter-dependencies with tRNS expansion and background composition; it
* doesn't do anything itself, just sets flags and pushes transforms.
@@ -2218,6 +2206,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
@@ -2236,8 +2238,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 */

143
pngread.c
View File

@@ -21,75 +21,6 @@
#define PNG_SRC_FILE PNG_SRC_FILE_pngread
#ifdef PNG_READ_SUPPORTED
/* Set the action on getting a CRC error for an ancillary or critical chunk. */
void PNGAPI
png_set_crc_action(png_structrp png_ptr, int crit_action, int ancil_action)
{
png_debug(1, "in png_set_crc_action");
if (png_ptr == NULL)
return;
/* Tell libpng how we react to CRC errors in critical chunks */
switch (crit_action)
{
case PNG_CRC_NO_CHANGE: /* Leave setting as is */
break;
case PNG_CRC_WARN_USE: /* Warn/use data */
png_ptr->flags &= PNG_BIC_MASK(PNG_FLAG_CRC_CRITICAL_MASK);
png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE;
break;
case PNG_CRC_QUIET_USE: /* Quiet/use data */
png_ptr->flags &= PNG_BIC_MASK(PNG_FLAG_CRC_CRITICAL_MASK);
png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE |
PNG_FLAG_CRC_CRITICAL_IGNORE;
break;
case PNG_CRC_WARN_DISCARD: /* Not a valid action for critical data */
png_warning(png_ptr,
"Can't discard critical data on CRC error");
case PNG_CRC_ERROR_QUIT: /* Error/quit */
case PNG_CRC_DEFAULT:
default:
png_ptr->flags &= PNG_BIC_MASK(PNG_FLAG_CRC_CRITICAL_MASK);
break;
}
/* Tell libpng how we react to CRC errors in ancillary chunks */
switch (ancil_action)
{
case PNG_CRC_NO_CHANGE: /* Leave setting as is */
break;
case PNG_CRC_WARN_USE: /* Warn/use data */
png_ptr->flags &= PNG_BIC_MASK(PNG_FLAG_CRC_ANCILLARY_MASK);
png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE;
break;
case PNG_CRC_QUIET_USE: /* Quiet/use data */
png_ptr->flags &= PNG_BIC_MASK(PNG_FLAG_CRC_ANCILLARY_MASK);
png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE |
PNG_FLAG_CRC_ANCILLARY_NOWARN;
break;
case PNG_CRC_ERROR_QUIT: /* Error/quit */
png_ptr->flags &= PNG_BIC_MASK(PNG_FLAG_CRC_ANCILLARY_MASK);
png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_NOWARN;
break;
case PNG_CRC_WARN_DISCARD: /* Warn/discard data */
case PNG_CRC_DEFAULT:
default:
png_ptr->flags &= PNG_BIC_MASK(PNG_FLAG_CRC_ANCILLARY_MASK);
break;
}
}
/* Create a PNG structure for reading, and allocate any memory needed. */
PNG_FUNCTION(png_structp,PNGAPI
png_create_read_struct,(png_const_charp user_png_ver, png_voidp error_ptr,
@@ -118,30 +49,42 @@ png_create_read_struct_2,(png_const_charp user_png_ver, png_voidp error_ptr,
if (png_ptr != NULL)
{
png_ptr->read_struct = 1;
png_ptr->critical_crc = crc_error_quit;
png_ptr->ancillary_crc = crc_warn_discard;
# ifdef PNG_BENIGN_ERRORS_SUPPORTED
# if !PNG_RELEASE_BUILD
/* Always quit on error prior to release */
png_ptr->benign_error_action = PNG_ERROR;
png_ptr->app_warning_action = PNG_WARN;
png_ptr->app_error_action = PNG_ERROR;
# else /* RELEASE_BUILD */
/* Allow benign errors on read, subject to app control. */
png_ptr->benign_error_action = PNG_WARN;
# ifdef PNG_BENIGN_READ_ERRORS_SUPPORTED
png_ptr->app_error_action = PNG_WARN;
png_ptr->app_warning_action = PNG_WARN;
# else /* !BENIGN_READ_ERRORS */
/* libpng build without benign error support; the application
* author has to be assumed to be correct, so:
*/
png_ptr->app_warning_action = PNG_WARN;
png_ptr->app_error_action = PNG_ERROR;
# endif /* !BENIGN_READ_ERRORS */
# endif /* RELEASE_BUILD */
/* This is always png_error unless explicitly changed: */
png_ptr->IDAT_error_action = PNG_ERROR;
# endif /* BENIGN_ERRORS */
/* Added in libpng-1.6.0; this can be used to detect a read structure if
* required (it will be zero in a write structure.)
*/
# ifdef PNG_SEQUENTIAL_READ_SUPPORTED
png_ptr->IDAT_size = PNG_IDAT_READ_SIZE;
# endif /* SEQUENTIAL_READ */
# ifdef PNG_BENIGN_READ_ERRORS_SUPPORTED
png_ptr->flags |= PNG_FLAG_BENIGN_ERRORS_WARN;
png_ptr->flags |= PNG_FLAG_APP_WARNINGS_WARN;
/* In stable builds only warn if an application error can be completely
* handled.
*/
# if PNG_RELEASE_BUILD
png_ptr->flags |= PNG_FLAG_APP_ERRORS_WARN;
# endif
# endif /* BENIGN_READ_ERRORS */
# ifdef PNG_READ_GAMMA_SUPPORTED
/* Default gamma correction values: */
# if 0 /*NYI*/
png_ptr->gamma_accuracy = PNG_DEFAULT_GAMMA_ACCURACY;
png_ptr->gamma_accuracy = PNG_DEFAULT_GAMMA_ACCURACY;
# endif /*NYI*/
png_ptr->gamma_threshold = PNG_GAMMA_THRESHOLD_FIXED;
# endif /* READ_GAMMA */
@@ -178,8 +121,7 @@ png_read_chunk_header(png_structrp png_ptr)
(unsigned long)png_ptr->chunk_length);
/* Reset the crc and run it over the chunk name. */
png_reset_crc(png_ptr);
png_calculate_crc(png_ptr, buf + 4, 4);
png_reset_crc(png_ptr, buf + 4);
#ifdef PNG_IO_STATE_SUPPORTED
png_ptr->io_state = PNG_IO_READING | PNG_IO_CHUNK_DATA;
@@ -196,7 +138,9 @@ png_read_sequential_unknown(png_structrp png_ptr, png_inforp info_ptr)
if (buffer != NULL)
{
png_crc_read(png_ptr, buffer, png_ptr->chunk_length);
if (png_ptr->chunk_length > 0U)
png_crc_read(png_ptr, buffer, png_ptr->chunk_length);
png_crc_finish(png_ptr, 0);
png_handle_unknown(png_ptr, info_ptr, buffer);
}
@@ -323,7 +267,7 @@ png_read_IDAT(png_structrp png_ptr)
{
png_uint_32 l = png_ptr->chunk_length;
if (l == 0) /* end of this IDAT */
while (l == 0) /* end of this IDAT */
{
png_crc_finish(png_ptr, 0);
png_read_chunk_header(png_ptr);
@@ -331,7 +275,7 @@ png_read_IDAT(png_structrp png_ptr)
if (png_ptr->chunk_name != png_IDAT) /* end of all IDAT */
{
png_ptr->mode |= PNG_AFTER_IDAT;
break;
goto done;
}
l = png_ptr->chunk_length;
@@ -346,6 +290,7 @@ png_read_IDAT(png_structrp png_ptr)
IDAT_size += (uInt)/*SAFE*/l;
png_ptr->chunk_length -= l;
}
done:
/* IDAT_size may be zero if the compressed image stream is truncated;
* this is likely given a broken PNG.
@@ -4159,11 +4104,21 @@ png_image_finish_read(png_imagep image, png_const_colorp background,
if (image->opaque != NULL && buffer != NULL && check >= png_row_stride)
{
/* Now check for overflow of the image buffer calculation; check for
* (size_t) overflow here. This detects issues with the
* PNG_IMAGE_BUFFER_SIZE macro.
/* Now check for overflow of the image buffer calculation; this
* limits the whole image size to PNG_SIZE_MAX bytes.
*
* The PNG_IMAGE_BUFFER_SIZE macro is:
*
* (PNG_IMAGE_PIXEL_COMPONENT_SIZE(fmt)*height*(row_stride))
*
* We have no way of guaranteeing that the application used the
* correct type for 'row_stride' if it used the macro, so this is
* technically not completely safe, but this is the case throughout
* libpng; the app is responsible for making sure the calcualtion of
* buffer sizes does not overflow.
*/
if (image->height <= PNG_SIZE_MAX/png_row_stride)
if (image->height <= PNG_SIZE_MAX /
PNG_IMAGE_PIXEL_COMPONENT_SIZE(image->format) / check)
{
if ((image->format & PNG_FORMAT_FLAG_COLORMAP) == 0 ||
(image->colormap_entries > 0 && colormap != NULL))

View File

@@ -19,7 +19,7 @@
*/
#include "pngpriv.h"
#define PNG_SRC_FILE PNG_SRC_FILE_rio
#define PNG_SRC_FILE PNG_SRC_FILE_pngrio
#ifdef PNG_READ_SUPPORTED
@@ -34,6 +34,11 @@ png_read_data(png_structrp png_ptr, png_voidp data, png_size_t length)
{
png_debug1(4, "reading %d bytes", (int)length);
/* This was guaranteed by prior versions of libpng, so app callbacks may
* assume it even though it isn't documented to be the case.
*/
debug(length > 0U);
if (png_ptr->rw_data_fn != NULL)
png_ptr->rw_data_fn(png_ptr, png_voidcast(png_bytep,data), length);

View File

@@ -5885,26 +5885,31 @@ typedef struct
} png_cache_params, *png_cache_paramsp;
static void
init_caching(png_structp png_ptr, png_cache_paramsp cp)
/* Given an already initialized cp->tend turn on caching if appropriate. */
init_caching(png_structp png_ptr, png_transform_controlp tend)
/* Given an already initialized tend turn on caching if appropriate. */
{
/* Handle the colormap case, where a cache is always required: */
if (cp->tend.format & PNG_FORMAT_FLAG_COLORMAP)
if (tend->format & PNG_FORMAT_FLAG_COLORMAP)
{
/* This turns starts the palette caching with the next transform: */
cp->tend.palette = cp->tend.caching = 1U;
cp->tend.transparent_alpha = png_ptr->transparent_palette;
cp->tend.format = PNG_FORMAT_FLAG_COLOR;
tend->palette = tend->caching = 1U;
# ifdef PNG_READ_tRNS_SUPPORTED
if (png_ptr->num_trans > 0 && !(cp->tend.invalid_info & PNG_INFO_tRNS))
tend->transparent_alpha = png_ptr->transparent_palette;
# else /* !READ_tRNS */
tend->transparent_alpha = 0;
PNG_UNUSED(png_ptr)
# endif /* !READ_tRNS */
tend->format = PNG_FORMAT_FLAG_COLOR;
# ifdef PNG_READ_tRNS_SUPPORTED
if (png_ptr->num_trans > 0 && !(tend->invalid_info & PNG_INFO_tRNS))
{
cp->tend.format |= PNG_FORMAT_FLAG_ALPHA;
tend->format |= PNG_FORMAT_FLAG_ALPHA;
}
# endif /* READ_tRNS */
cp->tend.bit_depth = 8U;
tend->bit_depth = 8U;
}
else if (PNG_TC_PIXEL_DEPTH(cp->tend) <= 8)
else if (PNG_TC_PIXEL_DEPTH(*tend) <= 8)
{
/* Cacheable pixel transforms; the pixel is less than 8 bits in size so
* the cache makes sense.
@@ -5912,7 +5917,7 @@ init_caching(png_structp png_ptr, png_cache_paramsp cp)
* TODO: check the cost estimate and the image size to avoid expensive
* caches of very small images.
*/
cp->tend.caching = 1U;
tend->caching = 1U;
}
/* TODO: handle handle 8-bit GA/RGB/RGBA */
@@ -6019,7 +6024,6 @@ update_palette(png_structp png_ptr, png_cache_paramsp cp,
* list, so:
*/
affirm((cp->tstart.format & PNG_FORMAT_FLAG_COLORMAP) != 0); /* required */
debug(cp->start == &png_ptr->transform_list); /* should be harmless */
/* Run the whole of the given list on the palette data. PNG_TC_INIT_FINAL
* has already been run; this is a full run (with init == 0).
@@ -6029,7 +6033,7 @@ update_palette(png_structp png_ptr, png_cache_paramsp cp,
only_deb(png_transform_control orig = cp->tend;)
cp->tend = cp->tstart;
init_caching(png_ptr, cp);
init_caching(png_ptr, &cp->tend);
/* And set up tend to actually work out the palette: */
cp->tend.init = 0U;
cp->tend.width = setup_palette_cache(png_ptr, cache.b8);
@@ -6296,7 +6300,7 @@ make_cache(png_structp png_ptr, png_cache_paramsp cp, unsigned int max_depth)
*/
save_cp_channel_data(&save, &cp->tend);
cp->tend = cp->tstart;
init_caching(png_ptr, cp);
init_caching(png_ptr, &cp->tend);
/* And set tend to work out the result of transforming each possible pixel
* value:
*/
@@ -6589,7 +6593,7 @@ png_read_init_transform_mech(png_structp png_ptr, png_transform_controlp tc)
*/
{
png_transformp *list = &png_ptr->transform_list;
unsigned int max_depth;
unsigned int max_depth, cache_start_depth;
png_cache_params cp;
/* PNG color-mapped data must be handled here so that the palette is updated
@@ -6608,8 +6612,7 @@ png_read_init_transform_mech(png_structp png_ptr, png_transform_controlp tc)
# endif /* READ_tRNS */
cp.end = cp.start = list;
cp.tend = cp.tstart = *tc;
init_caching(png_ptr, &cp);
max_depth = PNG_TC_PIXEL_DEPTH(cp.tend);
max_depth = cache_start_depth = PNG_TC_PIXEL_DEPTH(cp.tend);
while (*cp.end != NULL)
{
@@ -6619,6 +6622,22 @@ png_read_init_transform_mech(png_structp png_ptr, png_transform_controlp tc)
if (tr->order >= PNG_TR_USER)
break;
/* If caching is not on and this transform is after PNG_TR_START_CACHE
* try to turn it on.
*/
if (tr->order > PNG_TR_START_CACHE && !cp.tend.caching)
{
cp.start = cp.end;
cp.tstart = cp.tend;
init_caching(png_ptr, &cp.tend);
if (cp.tend.caching)
{
cache_start_depth = max_depth;
max_depth = PNG_TC_PIXEL_DEPTH(cp.tend);
}
}
/* If the 'palette' flag is set and the next transform has order
* PNG_TR_ENCODING or later cache the results so far and continue with the
* original palette data (cp.tstart).
@@ -6630,6 +6649,8 @@ png_read_init_transform_mech(png_structp png_ptr, png_transform_controlp tc)
/* The cache handling function must maintain cp.end; */
affirm(tr == *cp.end);
max_depth = PNG_TC_PIXEL_DEPTH(cp.tend);
if (max_depth < cache_start_depth)
max_depth = cache_start_depth;
}
/* Now run the transform list entry: */
@@ -6664,6 +6685,8 @@ png_read_init_transform_mech(png_structp png_ptr, png_transform_controlp tc)
handle_cache(png_ptr, &cp, max_depth);
affirm(tr == *cp.end);
max_depth = PNG_TC_PIXEL_DEPTH(cp.tend);
if (max_depth < cache_start_depth)
max_depth = cache_start_depth;
}
/* At the end run the init on the user transform: */

View File

@@ -138,50 +138,10 @@ png_crc_read(png_structrp png_ptr, png_voidp buf, png_uint_32 length)
png_calculate_crc(png_ptr, buf, length);
}
/* Compare the CRC stored in the PNG file with that calculated by libpng from
* the data it has read thus far.
*/
static int
png_crc_error(png_structrp png_ptr)
{
png_byte crc_bytes[4];
png_uint_32 crc;
int need_crc = 1;
if (PNG_CHUNK_ANCILLARY(png_ptr->chunk_name))
{
if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
(PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
need_crc = 0;
}
else /* critical */
{
if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
need_crc = 0;
}
#ifdef PNG_IO_STATE_SUPPORTED
png_ptr->io_state = PNG_IO_READING | PNG_IO_CHUNK_CRC;
#endif
/* The chunk CRC must be serialized in a single I/O call. */
png_read_data(png_ptr, crc_bytes, 4);
if (need_crc != 0)
{
crc = png_get_uint_32(crc_bytes);
return ((int)(crc != png_ptr->crc));
}
else
return (0);
}
/* Optionally skip data and then check the CRC. Depending on whether we
* are reading an ancillary or critical chunk, and how the program has set
* things up, we may calculate the CRC on the data and print a message.
* Returns '1' if there was a CRC error, '0' otherwise.
/* Optionally skip data and then check the CRC. Depending on whether we are
* reading an ancillary or critical chunk, and how the program has set things
* up, we may calculate the CRC on the data and print a message. Returns true
* if the chunk should be discarded, otherwise false.
*/
int /* PRIVATE */
png_crc_finish(png_structrp png_ptr, png_uint_32 skip)
@@ -202,22 +162,37 @@ png_crc_finish(png_structrp png_ptr, png_uint_32 skip)
png_crc_read(png_ptr, tmpbuf, len);
}
if (png_crc_error(png_ptr))
/* Compare the CRC stored in the PNG file with that calculated by libpng from
* the data it has read thus far. Do any required error handling. The
* second parameter is to allow a critical chunk (specifically PLTE) to be
* treated as ancillary.
*/
{
if (PNG_CHUNK_ANCILLARY(png_ptr->chunk_name) ?
(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN) == 0:
(png_ptr->flags & PNG_FLAG_CRC_CRITICAL_USE) != 0)
png_byte crc_bytes[4];
# ifdef PNG_IO_STATE_SUPPORTED
png_ptr->io_state = PNG_IO_READING | PNG_IO_CHUNK_CRC;
# endif
png_read_data(png_ptr, crc_bytes, 4);
if (png_ptr->current_crc != crc_quiet_use &&
png_get_uint_32(crc_bytes) != png_ptr->crc)
{
png_chunk_warning(png_ptr, "CRC error");
if (png_ptr->current_crc == crc_error_quit)
png_chunk_error(png_ptr, "CRC");
else
png_chunk_warning(png_ptr, "CRC");
/* The only way to discard a chunk at present is to issue a warning.
* TODO: quiet_discard.
*/
return png_ptr->current_crc == crc_warn_discard;
}
else
png_chunk_error(png_ptr, "CRC error");
return (1);
}
return (0);
return 0;
}
#if defined(PNG_READ_iCCP_SUPPORTED) || defined(PNG_READ_iTXt_SUPPORTED) ||\
@@ -314,8 +289,7 @@ png_inflate_claim(png_structrp png_ptr, png_uint_32 owner)
defined(PNG_MAXIMUM_INFLATE_WINDOW)
int window_bits;
if (((png_ptr->options >> PNG_MAXIMUM_INFLATE_WINDOW) & 3) ==
PNG_OPTION_ON)
if (png_ptr->maximum_inflate_window)
window_bits = 15;
else
@@ -803,11 +777,18 @@ png_handle_error(png_structrp png_ptr
png_chunk_benign_error(png_ptr, error);
}
#if defined (PNG_READ_gAMA_SUPPORTED) || defined (PNG_READ_sBIT_SUPPORTED) ||\
defined (PNG_READ_cHRM_SUPPORTED) || defined (PNG_READ_sRGB_SUPPORTED) ||\
defined (PNG_READ_iCCP_SUPPORTED) || defined (PNG_READ_tRNS_SUPPORTED) ||\
defined (PNG_READ_bKGD_SUPPORTED) || defined (PNG_READ_hIST_SUPPORTED) ||\
defined (PNG_READ_pHYs_SUPPORTED) || defined (PNG_READ_oFFs_SUPPORTED) ||\
defined (PNG_READ_sCAL_SUPPORTED) || defined (PNG_READ_tIME_SUPPORTED)
static void
png_handle_bad_length(png_structrp png_ptr)
{
png_handle_error(png_ptr, "invalid length");
}
#endif /* chunks that can generate length errors */
/* Read and check the IDHR chunk */
static void
@@ -870,6 +851,7 @@ png_handle_PLTE(png_structrp png_ptr, png_inforp info_ptr)
#ifndef PNG_READ_OPT_PLTE_SUPPORTED
if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
{
/* Skip the whole chunk: */
png_handle_skip(png_ptr);
return;
}
@@ -910,53 +892,18 @@ png_handle_PLTE(png_structrp png_ptr, png_inforp info_ptr)
palette[i].blue = buf[2];
}
/* If we actually need the PLTE chunk (ie for a paletted image), we do
* whatever the normal CRC configuration tells us. However, if we
* have an RGB image, the PLTE can be considered ancillary, so
* we will act as though it is.
*/
#ifndef PNG_READ_OPT_PLTE_SUPPORTED
if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
#endif
png_crc_finish(png_ptr, length - num * 3U);
#ifndef PNG_READ_OPT_PLTE_SUPPORTED
else if (png_crc_error(png_ptr)) /* Only if we have a CRC error */
{
/* If we don't want to use the data from an ancillary chunk,
* we have two options: an error abort, or a warning and we
* ignore the data in this chunk (which should be OK, since
* it's considered ancillary for a RGB or RGBA image).
*
* IMPLEMENTATION NOTE: this is only here because png_crc_finish uses the
* chunk type to determine whether to check the ancillary or the critical
* flags.
*/
if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_USE))
{
if (png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)
return;
else
png_chunk_error(png_ptr, "CRC error");
}
/* Otherwise, we (optionally) emit a warning and use the chunk. */
else if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN))
{
png_chunk_warning(png_ptr, "CRC error");
}
}
#endif /* READ_OPT_PLTE */
png_crc_finish(png_ptr, length - num * 3U);
png_set_PLTE(png_ptr, info_ptr, palette, num);
/* Ok, make our own copy since the set succeeded: */
debug(png_ptr->palette == NULL); /* should only get set once */
png_ptr->palette = png_voidcast(png_colorp, png_malloc(png_ptr,
sizeof (png_color[PNG_MAX_PALETTE_LENGTH])));
memset(png_ptr->palette, 0xFFU, sizeof (png_color[PNG_MAX_PALETTE_LENGTH]));
memcpy(png_ptr->palette, info_ptr->palette, 3*num);
/* This works because we know png_set_PLTE also expands the palette to the
* full size:
*/
memcpy(png_ptr->palette, info_ptr->palette,
sizeof (png_color[PNG_MAX_PALETTE_LENGTH]));
png_ptr->num_palette = info_ptr->num_palette;
/* The three chunks, bKGD, hIST and tRNS *must* appear after PLTE and before
@@ -1348,8 +1295,12 @@ png_handle_iCCP(png_structrp png_ptr, png_inforp info_ptr)
profile + (sizeof profile_header) +
12 * tag_count, &size, 1/*finish*/);
if (length > 0 && !(png_ptr->flags &
PNG_FLAG_BENIGN_ERRORS_WARN))
if (length > 0
# ifdef PNG_BENIGN_READ_ERRORS_SUPPORTED
&& png_ptr->benign_error_action ==
PNG_ERROR
# endif /* BENIGN_READ_ERRORS */
)
errmsg = "extra compressed data";
/* But otherwise allow extra data: */
@@ -1367,12 +1318,12 @@ png_handle_iCCP(png_structrp png_ptr, png_inforp info_ptr)
png_crc_finish(png_ptr, length);
finished = 1;
# ifdef PNG_sRGB_SUPPORTED
# if defined(PNG_sRGB_SUPPORTED) && PNG_sRGB_PROFILE_CHECKS >= 0
/* Check for a match against sRGB */
png_icc_set_sRGB(png_ptr,
&png_ptr->colorspace, profile,
png_ptr->zstream.adler);
# endif
# endif
/* Steal the profile for info_ptr. */
if (info_ptr != NULL)
@@ -3815,17 +3766,28 @@ png_inflate_IDAT(png_structrp png_ptr, int finish,
/* This is the error return case; there was missing data, or an error.
* Either continue with a warning (once; hence the zstream_error flag)
* or png_error. The 'warn' setting has to be turned on and benign errors
* have to be turned off (made warnings.) The logic of this is that this
* is a pretty serious error; PNG is about images and we don't know that the
* image is correct.
* or png_error.
*/
if (!png_ptr->zstream_error) /* first time */
{
if ((png_ptr->flags & PNG_FLAG_IDAT_ERRORS_WARN) != 0)
png_chunk_benign_error(png_ptr, png_ptr->zstream.msg);
else
# ifdef PNG_BENIGN_READ_ERRORS_SUPPORTED
switch (png_ptr->IDAT_error_action)
{
case PNG_ERROR:
png_chunk_error(png_ptr, png_ptr->zstream.msg);
break;
case PNG_WARN:
png_chunk_warning(png_ptr, png_ptr->zstream.msg);
break;
default: /* ignore */
/* Keep going */
break;
}
# else
png_chunk_error(png_ptr, png_ptr->zstream.msg);
# endif /* !BENIGN_ERRORS */
/* And prevent the report about too many IDATs on streams with internal
* LZ errors:
@@ -4330,11 +4292,10 @@ png_read_process_IDAT(png_structrp png_ptr, png_bytep transformed_row,
/* Run the list. It is ok if it doesn't end up doing
* anything; this can happen with a lazy init.
*
* TODO: I don't think lazy inits happen any more, hence
* the 'debug' below.
* NOTE: if the only thingin the list is a palette check
* function it can remove itself at this point.
*/
max_depth = png_run_transform_list_forwards(png_ptr, &tc);
debug(png_ptr->transform_list != NULL);
/* This is too late, a stack overwrite has already
* happened, but it may still prevent exploits:
@@ -4585,4 +4546,177 @@ png_read_update_info(png_structrp png_ptr, png_inforp info_ptr)
}
}
png_int_32 /* PRIVATE */
png_read_setting(png_structrp png_ptr, png_uint_32 setting,
png_uint_32 parameter, png_int_32 value)
{
/* Caller checks the arguments for basic validity */
int only_get = (setting & PNG_SF_GET) != 0U;
if (only_get) /* spurious: in case it isn't used */
setting &= ~PNG_SF_GET;
switch (setting)
{
# ifdef PNG_SEQUENTIAL_READ_SUPPORTED
case PNG_SR_COMPRESS_buffer_size:
if (parameter > 0 && parameter <= ZLIB_IO_MAX)
{
png_ptr->IDAT_size = parameter;
return 0; /* Cannot return a 32-bit value */
}
else
return PNG_EINVAL;
# endif /* SEQUENTIAL_READ */
# ifdef PNG_READ_GAMMA_SUPPORTED
case PNG_SR_GAMMA_threshold:
if (parameter <= 0xFFFF)
{
if (!only_get)
png_ptr->gamma_threshold = PNG_UINT_16(parameter);
return (png_int_32)/*SAFE*/parameter;
}
return PNG_EDOM;
#if 0 /*NYI*/
case PNG_SR_GAMMA_accuracy:
if (parameter <= 1600)
{
if (!only_get)
png_ptr->gamma_accuracy = parameter;
return (png_int_32)/*SAFE*/parameter;
}
return PNG_EDOM;
#endif /*NYI*/
# endif /* READ_GAMMA */
case PNG_SR_CRC_ACTION:
/* Tell libpng how we react to CRC errors in critical chunks */
switch (parameter)
{
case PNG_CRC_NO_CHANGE: /* Leave setting as is */
break;
case PNG_CRC_WARN_USE: /* Warn/use data */
png_ptr->critical_crc = crc_warn_use;
break;
case PNG_CRC_QUIET_USE: /* Quiet/use data */
png_ptr->critical_crc = crc_quiet_use;
break;
default:
case PNG_CRC_WARN_DISCARD: /* Not valid for critical data */
return PNG_EINVAL;
case PNG_CRC_ERROR_QUIT: /* Error/quit */
case PNG_CRC_DEFAULT:
png_ptr->critical_crc = crc_error_quit;
break;
}
/* Tell libpng how we react to CRC errors in ancillary chunks */
switch (value)
{
case PNG_CRC_NO_CHANGE: /* Leave setting as is */
break;
case PNG_CRC_WARN_USE: /* Warn/use data */
png_ptr->ancillary_crc = crc_warn_use;
break;
case PNG_CRC_QUIET_USE: /* Quiet/use data */
png_ptr->ancillary_crc = crc_quiet_use;
break;
case PNG_CRC_ERROR_QUIT: /* Error/quit */
png_ptr->ancillary_crc = crc_error_quit;
break;
case PNG_CRC_WARN_DISCARD: /* Warn/discard data */
case PNG_CRC_DEFAULT:
png_ptr->ancillary_crc = crc_warn_discard;
break;
default:
return PNG_EINVAL;
}
return 0; /* success */
# ifdef PNG_SET_OPTION_SUPPORTED
case PNG_SRW_OPTION:
switch (parameter)
{
case PNG_MAXIMUM_INFLATE_WINDOW:
if (png_ptr->maximum_inflate_window)
{
if (!value && !only_get)
png_ptr->maximum_inflate_window = 0U;
return PNG_OPTION_ON;
}
else
{
if (value && !only_get)
png_ptr->maximum_inflate_window = 1U;
return PNG_OPTION_OFF;
}
default:
return PNG_OPTION_UNSET;
}
# endif /* SET_OPTION */
# ifdef PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED
case PNG_SRW_CHECK_FOR_INVALID_INDEX:
/* The 'enabled' value is a FORTRAN style three-state: */
if (value > 0)
png_ptr->palette_index_check = PNG_PALETTE_CHECK_ON;
else if (value < 0)
png_ptr->palette_index_check = PNG_PALETTE_CHECK_OFF;
else
png_ptr->palette_index_check = PNG_PALETTE_CHECK_DEFAULT;
return 0;
# endif /* READ_CHECK_FOR_INVALID_INDEX */
# ifdef PNG_BENIGN_READ_ERRORS_SUPPORTED
case PNG_SRW_ERROR_HANDLING:
/* The parameter is a bit mask of what to set, the value is what to
* set it to.
*/
if (value >= PNG_IGNORE && value <= PNG_ERROR &&
parameter <= PNG_ALL_ERRORS)
{
if ((parameter & PNG_BENIGN_ERRORS) != 0U)
png_ptr->benign_error_action = value & 0x3U;
if ((parameter & PNG_APP_WARNINGS) != 0U)
png_ptr->app_warning_action = value & 0x3U;
if ((parameter & PNG_APP_ERRORS) != 0U)
png_ptr->app_error_action = value & 0x3U;
if ((parameter & PNG_IDAT_ERRORS) != 0U)
png_ptr->IDAT_error_action = value & 0x3U;
return 0;
}
return PNG_EINVAL;
# endif /* BENIGN_READ_ERRORS */
default:
return PNG_ENOSYS; /* not supported (whatever it is) */
}
}
#endif /* READ */

View File

@@ -539,12 +539,30 @@ png_set_PLTE(png_structrp png_ptr, png_inforp info_ptr,
* of num_palette entries, in case of an invalid PNG file or incorrect
* call to png_set_PLTE() with too-large sample values.
*/
info_ptr->palette = png_voidcast(png_colorp, png_calloc(png_ptr,
info_ptr->palette = png_voidcast(png_colorp, png_malloc(png_ptr,
PNG_MAX_PALETTE_LENGTH * (sizeof (png_color))));
if (num_palette > 0)
memcpy(info_ptr->palette, palette, num_palette * (sizeof (png_color)));
/* Set the remainder of the palette entries to something recognizable; the
* code used to leave them set to 0, which made seeing palette index errors
* difficult.
*/
if (num_palette < PNG_MAX_PALETTE_LENGTH)
{
int i;
png_color c;
memset(&c, 0x42, sizeof c); /* fill in any padding */
c.red = 0xbe;
c.green = 0xad;
c.blue = 0xed; /* Visible in memory as 'beaded' */
for (i=num_palette; i<PNG_MAX_PALETTE_LENGTH; ++i)
info_ptr->palette[i] = c;
}
info_ptr->num_palette = png_check_bits(png_ptr, num_palette, 9);
info_ptr->free_me |= PNG_FREE_PLTE;
info_ptr->valid |= PNG_INFO_PLTE;
@@ -1652,27 +1670,4 @@ png_set_chunk_malloc_max (png_structrp png_ptr,
png_ptr->user_chunk_malloc_max = user_chunk_malloc_max;
}
#endif /* ?SET_USER_LIMITS */
#ifdef PNG_BENIGN_ERRORS_SUPPORTED
void PNGAPI
png_set_benign_errors(png_structrp png_ptr, int allowed)
{
png_debug(1, "in png_set_benign_errors");
/* If allowed is 1, png_benign_error() is treated as a warning.
*
* If allowed is 0, png_benign_error() is treated as an error (which
* is the default behavior if png_set_benign_errors() is not called).
*/
if (allowed != 0)
png_ptr->flags |= PNG_FLAG_BENIGN_ERRORS_WARN |
PNG_FLAG_APP_WARNINGS_WARN | PNG_FLAG_APP_ERRORS_WARN;
else
png_ptr->flags &= PNG_BIC_MASK(PNG_FLAG_BENIGN_ERRORS_WARN |
PNG_FLAG_APP_WARNINGS_WARN | PNG_FLAG_APP_ERRORS_WARN);
}
#endif /* BENIGN_ERRORS */
#endif /* READ || WRITE */

View File

@@ -26,14 +26,14 @@
#ifndef ZLIB_CONST
/* We must ensure that zlib uses 'const' in declarations. */
# define ZLIB_CONST
#endif
#endif /* !ZLIB_CONST */
#include PNG_ZLIB_HEADER
#ifdef const
/* zlib.h sometimes #defines const to nothing, undo this. */
# undef const
#endif
#endif /* const */
/* zlib.h has mediocre z_const use before 1.2.6, this stuff is for compatibility
* with older builds.
@@ -41,10 +41,10 @@
#if ZLIB_VERNUM < 0x1260
# define PNGZ_MSG_CAST(s) png_constcast(char*,s)
# define PNGZ_INPUT_CAST(b) png_constcast(png_bytep,b)
#else
#else /* ZLIB_VERNUM >= 0x1260 */
# define PNGZ_MSG_CAST(s) (s)
# define PNGZ_INPUT_CAST(b) (b)
#endif
#endif /* ZLIB_VERNUM >= 0x1260 */
/* zlib.h declares a magic type 'uInt' that limits the amount of data that zlib
* can handle at once. This type need be no larger than 16 bits (so maximum of
@@ -57,17 +57,17 @@
#ifndef ZLIB_IO_MAX
# ifdef __COVERITY__
# define ZLIB_IO_MAX ((uInt)255U) /* else COVERITY whines */
# else
# else /* !COVERITY */
# define ZLIB_IO_MAX ((uInt)-1)
# endif /* COVERITY */
#endif
# endif /* !COVERITY */
#endif /* !ZLIB_IO_MAX */
#ifdef PNG_WRITE_SUPPORTED
/* The write compression control (allocated on demand).
* TODO: use this for the read state too.
*/
typedef struct png_zlib_state *png_zlib_statep;
#endif
#endif /* WRITE */
/* Colorspace support; structures used in png_struct, png_info and in internal
* functions to hold and communicate information about the color space.
@@ -114,13 +114,13 @@ typedef struct png_colorspace
{
#ifdef PNG_GAMMA_SUPPORTED
png_fixed_point gamma; /* File gamma */
#endif
#endif /* GAMMA */
#ifdef PNG_COLORSPACE_SUPPORTED
png_xy end_points_xy; /* End points as chromaticities */
png_XYZ end_points_XYZ; /* End points as CIE XYZ colorant values */
png_uint_16 rendering_intent; /* Rendering intent of a profile */
#endif
#endif /* COLORSPACE */
/* Flags are always defined to simplify the code. */
png_uint_16 flags; /* As defined below */
@@ -182,7 +182,7 @@ typedef struct
* during PNG_TC_INIT_FINAL. The field is only used on read; write
* transforms do not modify the gamma of the data.
*/
# endif
# endif /* READ_GAMMA */
unsigned int format; /* As pngstruct::row_format below */
unsigned int range; /* Count of range transforms */
# define PNG_TC_CHANNELS(tc) PNG_FORMAT_CHANNELS((tc).format)
@@ -351,6 +351,15 @@ typedef struct png_transform /* Linked list of transform functions */
} png_transform;
#endif /* TRANSFORM_MECH */
/* Action to take on CRC errors (four values) */
typedef enum
{
crc_error_quit = PNG_CRC_ERROR_QUIT-1,
crc_warn_discard = PNG_CRC_WARN_DISCARD-1,
crc_warn_use = PNG_CRC_WARN_USE-1,
crc_quiet_use = PNG_CRC_QUIET_USE-1
} png_crc_action;
struct png_struct_def
{
/* Rearranged in libpng 1.7 to attempt to lessen padding; in general
@@ -364,7 +373,7 @@ struct png_struct_def
* accessed.)
*/
jmp_buf jmp_buf_local;
#endif
#endif /* SETJMP */
/* Next the frequently accessed fields. Many processors perform arithmetic
* in the address pipeline, but frequently the amount of addition or
@@ -385,7 +394,6 @@ struct png_struct_def
png_uint_32 chunk_length; /* Length (possibly remaining) in said chunk. */
png_uint_32 crc; /* current chunk CRC value */
unsigned int flags; /* flags (should be bit fields) */
unsigned int mode :6; /* where we are in the PNG file */
unsigned int read_struct :1; /* this is a read (not write) struct */
unsigned int num_palette :9; /* number of color entries in palette */
@@ -393,13 +401,15 @@ struct png_struct_def
unsigned int num_trans :9; /* number of transparency values */
unsigned int transparent_palette :1; /* if they are all 0 or 255 */
#endif /* READ_tRNS */
#ifdef PNG_GET_PALETTE_MAX_SUPPORTED
unsigned int palette_index_max :9; /* maximum palette index found in IDAT */
#endif /* GET_PALETTE_MAX */
#ifdef PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED
unsigned int palette_index_check_disabled :1; /* defaults to 0, 'enabled' */
unsigned int palette_index_check_issued :1; /* error message output */
#endif /* CHECK_FOR_INVALID_INDEX */
#ifdef PNG_PALETTE_MAX_SUPPORTED
unsigned int palette_index_max :8; /* maximum palette index in IDAT */
unsigned int palette_index_check :2; /* one of the following: */
# define PNG_PALETTE_CHECK_DEFAULT 0U
# define PNG_PALETTE_CHECK_OFF 1U
# define PNG_PALETTE_CHECK_ON 2U
unsigned int palette_index_have_max :1; /* max is being set */
unsigned int palette_index_check_issued :1; /* error message output */
#endif /* PALETTE_MAX */
#ifdef PNG_READ_tRNS_SUPPORTED
png_color_16 trans_color; /* transparent color for non-paletted files */
#endif /* READ_tRNS */
@@ -417,24 +427,19 @@ struct png_struct_def
png_byte bit_depth; /* bit depth of file */
png_byte sig_bytes; /* magic bytes read/written at start of file */
/* Options */
#ifdef PNG_SET_OPTION_SUPPORTED
png_uint_32 options; /* On/off state (up to 16 options) */
#endif
#ifdef PNG_READ_SUPPORTED
#if defined(PNG_COLORSPACE_SUPPORTED) || defined(PNG_GAMMA_SUPPORTED)
/* The png_struct colorspace structure is only required on read - on write it
* is in (just) the info_struct.
*/
png_colorspace colorspace;
#endif
#endif /* COLORSPACE || GAMMA */
#endif /* READ */
/* Transform handling */
#ifdef PNG_TRANSFORM_MECH_SUPPORTED
png_transformp transform_list; /* List of transformation to perform. */
#endif
#endif /* TRANSFORM_MECH */
/* ROW BUFFERS and CONTROL
*
@@ -442,9 +447,9 @@ struct png_struct_def
* filter byte (which is in next_filter.) All fields are only used during
* IDAT processing and start of 0.
*/
#if defined(PNG_WRITE_FILTER_SUPPORTED) || defined(PNG_READ_SUPPORTED)
#ifdef PNG_READ_SUPPORTED
png_bytep row_buffer; /* primary row buffer */
#endif /* WRITE_FILTER || READ */
#endif /* READ */
#if (defined(PNG_PROGRESSIVE_READ_SUPPORTED) ||\
defined(PNG_READ_INTERLACING_SUPPORTED)) &&\
defined(PNG_TRANSFORM_MECH_SUPPORTED)
@@ -482,10 +487,12 @@ struct png_struct_def
unsigned int invalid_info; /* PNG_INFO_* for invalidated chunks */
unsigned int palette_updated:1; /* png_struct::palette changed */
#endif /* READ_TRANSFORMS */
#ifdef PNG_WRITE_SUPPORTED
unsigned int write_rows :1; /* libpng has complete rows to write */
#endif /* WRITE */
#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
unsigned int read_started :1; /* at least one call to png_read_row */
#endif
#endif /* SEQUENTIAL_READ */
#if defined (PNG_READ_INTERLACING_SUPPORTED) ||\
defined (PNG_WRITE_INTERLACING_SUPPORTED)
unsigned int do_interlace :1; /* libpng handles the interlace */
@@ -574,7 +581,7 @@ struct png_struct_def
* available to zlib during read decompression.
*/
png_alloc_size_t read_buffer_size; /* current size of the buffer */
#endif
#endif /* READ */
#if defined(PNG_SEQUENTIAL_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
png_uint_32 IDAT_size; /* limit on IDAT read and write IDAT size */
@@ -585,13 +592,13 @@ struct png_struct_def
jmp_buf *jmp_buf_ptr; /* passed to longjmp_fn */
png_longjmp_ptr longjmp_fn; /* setjmp non-local goto function. */
size_t jmp_buf_size; /* size of *jmp_buf_ptr, if allocated */
#endif
#endif /* SETJMP */
/* Error/warning callbacks */
png_error_ptr error_fn; /* print an error message and abort */
#ifdef PNG_WARNINGS_SUPPORTED
png_error_ptr warning_fn; /* print a warning and continue */
#endif
#endif /* WARNINGS */
png_voidp error_ptr; /* user supplied data for the above */
/* MEMORY ALLOCATION */
@@ -599,7 +606,7 @@ struct png_struct_def
png_malloc_ptr malloc_fn; /* allocate memory */
png_free_ptr free_fn; /* free memory */
png_voidp mem_ptr; /* user supplied data for the above */
#endif
#endif /* USER_MEM */
/* IO and BASIC READ/WRITE SUPPORT */
png_voidp io_ptr; /* user supplied data for IO callbacks */
@@ -622,8 +629,7 @@ struct png_struct_def
#ifdef PNG_WRITE_FLUSH_SUPPORTED
png_flush_ptr output_flush_fn; /* Function for flushing output */
#endif
#endif /* WRITE_FLUSH */
#endif /* WRITE */
#ifdef PNG_SET_USER_LIMITS_SUPPORTED
@@ -634,14 +640,14 @@ struct png_struct_def
* - it is decremented as memory is allocated.
*/
png_alloc_size_t user_chunk_malloc_max;
#endif
#endif /* SET_USER_LIMITS */
#ifdef PNG_USER_LIMITS_SUPPORTED
/* limit on total *number* of sPLT, text and unknown chunks that can be
* stored. 0 means unlimited. This field is a counter - it is decremented
* as chunks are encountered.
*/
png_uint_32 user_chunk_cache_max;
#endif
#endif /* USER_LIMITS */
/* The progressive reader gets passed data and calls application handling
* functions when appropriate.
@@ -672,7 +678,7 @@ struct png_struct_def
#ifdef PNG_IO_STATE_SUPPORTED
png_uint_32 io_state; /* tells the app read/write progress */
#endif
#endif /* IO_STATE */
/* UNKNOWN CHUNK HANDLING */
/* TODO: this is excessively complicated, there are multiple ways of doing
@@ -686,12 +692,12 @@ struct png_struct_def
* set_unknown_chunks interface.)
*/
png_voidp user_chunk_ptr;
#endif
#endif /* USER_CHUNKS */
#ifdef PNG_READ_USER_CHUNKS_SUPPORTED
/* This is called back from the unknown chunk handling */
png_user_chunk_ptr read_user_chunk_fn; /* user read chunk handler */
#endif
#endif /* READ_USER_CHUNKS */
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
png_uint_32 known_unknown; /* Bit mask of known chunks to be treated as
@@ -703,7 +709,7 @@ struct png_struct_def
* 'known & ~save'.
*/
# define png_IDATs_skipped(pp) (((pp)->known_unknown & ~(pp)->save_unknown)&1U)
#else
#else /* !SAVE_UNKNOWN_CHUNKS */
# define png_IDATs_skipped(pp) ((pp)->known_unknown & 1U)
#endif /* !SAVE_UNKNOWN_CHUNKS */
#endif /* HANDLE_AS_UNKNOWN */
@@ -713,7 +719,7 @@ struct png_struct_def
* followed by a PNG_HANDLE_* byte */
unsigned int unknown_default :2; /* As PNG_HANDLE_* */
unsigned int num_chunk_list; /* Number of entries in the list */
#endif
#endif /* SET_UNKNOWN_CHUNKS */
/* COMPRESSION AND DECOMPRESSION SUPPORT.
*
@@ -734,11 +740,33 @@ struct png_struct_def
* received; set by the zstream using code for
* its own purposes. [progressive read] */
# endif /* PROGRESSIVE_READ */
# ifdef PNG_BENIGN_ERRORS_SUPPORTED
unsigned int benign_error_action :2;
unsigned int app_warning_action :2;
unsigned int app_error_action :2;
# ifdef PNG_READ_SUPPORTED
unsigned int IDAT_error_action :2;
# endif /* READ */
# endif /* BENIGN_ERRORS */
# ifdef PNG_READ_SUPPORTED
/* CRC checking actions, one for critical chunks, one for ancillary
* chunks.
*/
unsigned int critical_crc :2;
unsigned int ancillary_crc :2;
unsigned int current_crc :2; /* Cache of one or other of the above */
# endif
# ifdef PNG_SET_OPTION_SUPPORTED
# ifdef PNG_READ_SUPPORTED
unsigned int maximum_inflate_window :1U;
# endif /* READ */
unsigned int skip_sRGB_profile_check :1U;
# endif /* SET_OPTION */
/* MNG SUPPORT */
#ifdef PNG_MNG_FEATURES_SUPPORTED
unsigned int mng_features_permitted :3;
#endif
#endif /* MNG_FEATURES */
/* SCRATCH buffers, used when control returns to the application or a read
* loop.

View File

@@ -1386,6 +1386,11 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
png_write_info(write_ptr, write_info_ptr);
write_chunks(write_ptr, before_IDAT); /* after PLTE */
#ifdef PNG_COMPRESSION_COMPAT
/* Test the 'compatibility' setting here, if it is available. */
png_set_compression(write_ptr, PNG_COMPRESSION_COMPAT);
#endif
#endif
#ifdef SINGLE_ROWBUF_ALLOC
@@ -2070,4 +2075,4 @@ main(void)
#endif
/* Generate a compiler error if there is an old png.h in the search path. */
typedef png_libpng_version_1_7_0beta79 Your_png_h_is_not_version_1_7_0beta79;
typedef png_libpng_version_1_7_0beta82 Your_png_h_is_not_version_1_7_0beta82;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.6 KiB

After

Width:  |  Height:  |  Size: 8.5 KiB

View File

@@ -586,23 +586,39 @@ set_palette_max(png_structrp png_ptr, png_transformp tr, unsigned int max,
{
/* One of these must be true: */
# ifdef PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED
if (max >= tr->args && !png_ptr->palette_index_check_issued)
if (max >= (tr->args & 0x1FFU) && !png_ptr->palette_index_check_issued)
{
# ifdef PNG_READ_SUPPORTED
/* In 1.7 only issue the error/warning by default; the 'check' API is
* used to enable/disable the check. Assume that if the app enabled it
* then the app will be checking the result with get_palette_max in
* read. In write an error results unless the check is disabled.
*/
if (png_ptr->palette_index_check == PNG_PALETTE_CHECK_DEFAULT
# ifdef PNG_WRITE_SUPPORTED
(png_ptr->read_struct ? png_chunk_benign_error : png_error)
# else /* !WRITE */
png_chunk_benign_error
# endif /* !WRITE */
# else /* !READ */
png_error
# endif /* !READ */
(png_ptr, "palette index too large");
|| (!png_ptr->read_struct &&
png_ptr->palette_index_check != PNG_PALETTE_CHECK_OFF)
# endif /* WRITE */
)
{
# ifdef PNG_READ_SUPPORTED
# ifdef PNG_WRITE_SUPPORTED
if (png_ptr->read_struct)
# endif /* WRITE */
png_chunk_benign_error(png_ptr, "palette index too large");
# ifdef PNG_WRITE_SUPPORTED
else
# endif
# endif /* READ */
# ifdef PNG_WRITE_SUPPORTED
png_error(png_ptr, "palette index too large");
# endif /* WRITE */
}
png_ptr->palette_index_check_issued = 1;
}
# endif
# endif /* CHECK_FOR_INVALID_INDEX */
# ifdef PNG_GET_PALETTE_MAX_SUPPORTED
png_ptr->palette_index_max = png_check_bits(png_ptr, max, 9);
png_ptr->palette_index_max = png_check_byte(png_ptr, max);
# endif
if (max == format_max)
@@ -642,7 +658,8 @@ palette_max_2bpp(png_transformp *tr, png_transform_controlp tc)
{
png_const_bytep sp = png_voidcast(png_const_bytep, tc->sp);
png_uint_32 width = tc->width;
unsigned int max = (*tr)->args; /* saved maximum */
const png_uint_32 args = (*tr)->args;
unsigned int max = args >> 24; /* saved maximum */
while (width > 0)
{
@@ -699,7 +716,7 @@ palette_max_2bpp(png_transformp *tr, png_transform_controlp tc)
}
/* End of input, check the next line. */
(*tr)->args = max;
(*tr)->args = (max << 24) + (args & 0xFFFFFFU);
}
static void
@@ -707,7 +724,8 @@ palette_max_4bpp(png_transformp *tr, png_transform_controlp tc)
{
png_const_bytep sp = png_voidcast(png_const_bytep, tc->sp);
png_uint_32 width = tc->width;
unsigned int max = (*tr)->args; /* saved maximum */
const png_uint_32 args = (*tr)->args;
unsigned int max = args >> 24; /* saved maximum */
while (width > 0)
{
@@ -725,12 +743,12 @@ palette_max_4bpp(png_transformp *tr, png_transform_controlp tc)
max = (input >> 4) & 0xFU;
}
if (max > (*tr)->args)
if (max > (args >> 24))
{
if (set_palette_max(tc->png_ptr, *tr, max, 15U))
return;
(*tr)->args = max;
(*tr)->args = (max << 24) + (args & 0xFFFFFFU);
}
}
@@ -739,7 +757,8 @@ palette_max_8bpp(png_transformp *tr, png_transform_controlp tc)
{
png_const_bytep sp = png_voidcast(png_const_bytep, tc->sp);
png_uint_32 width = tc->width;
unsigned int max = (*tr)->args; /* saved maximum */
const png_uint_32 args = (*tr)->args;
unsigned int max = args >> 24; /* saved maximum */
while (width > 0)
{
@@ -751,12 +770,12 @@ palette_max_8bpp(png_transformp *tr, png_transform_controlp tc)
--width;
}
if (max > (*tr)->args)
if (max > (args >> 24))
{
if (set_palette_max(tc->png_ptr, *tr, max, 255U))
return;
(*tr)->args = max;
(*tr)->args = (max << 24) + (args & 0xFFFFFFU);
}
}
@@ -764,26 +783,27 @@ static void
palette_max_init(png_transformp *tr, png_transform_controlp tc)
{
# define png_ptr (tc->png_ptr)
if ((tc->format & PNG_FORMAT_FLAG_COLORMAP) != 0)
affirm((tc->format & PNG_FORMAT_FLAG_COLORMAP) != 0);
debug(tc->init);
if (tc->init == PNG_TC_INIT_FINAL)
{
if (tc->init == PNG_TC_INIT_FINAL)
/* Record the palette depth to check here along with the running total
* in the top 8 bits (initially 0, which is always valid).
*/
(*tr)->args = png_ptr->num_palette;
switch (tc->bit_depth)
{
/* Record the palette depth to check here: */
(*tr)->args = png_ptr->num_palette;
switch (tc->bit_depth)
{
case 1: (*tr)->fn = palette_max_1bpp; break;
case 2: (*tr)->fn = palette_max_2bpp; break;
case 4: (*tr)->fn = palette_max_4bpp; break;
case 8: (*tr)->fn = palette_max_8bpp; break;
default:impossible("palette bit depth");
}
case 1: (*tr)->fn = palette_max_1bpp; break;
case 2: (*tr)->fn = palette_max_2bpp; break;
case 4: (*tr)->fn = palette_max_4bpp; break;
case 8: (*tr)->fn = palette_max_8bpp; break;
default:impossible("palette bit depth");
}
}
else
(*tr)->fn = NULL; /* not applicable */
png_ptr->palette_index_have_max = 1U;
}
# undef png_ptr
}
#endif /* PALETTE_MAX */
@@ -792,11 +812,7 @@ palette_max_init(png_transformp *tr, png_transform_controlp tc)
int PNGAPI
png_get_palette_max(png_const_structrp png_ptr, png_const_inforp info_ptr)
{
if (png_ptr != NULL
# ifdef PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED
&& !png_ptr->palette_index_check_disabled
# endif
)
if (png_ptr != NULL && png_ptr->palette_index_have_max)
return png_ptr->palette_index_max;
/* This indicates to the caller that the information is not available: */
@@ -805,37 +821,6 @@ png_get_palette_max(png_const_structrp png_ptr, png_const_inforp info_ptr)
}
#endif /* GET_PALETTE_MAX */
#ifdef PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED
/* Whether to report invalid palette index; added at libng-1.5.10.
* It is possible for an indexed (color-type==3) PNG file to contain
* pixels with invalid (out-of-range) indexes if the PLTE chunk has
* fewer entries than the image's bit-depth would allow. We recover
* from this gracefully by filling any incomplete palette with zeros
* (opaque black). By default, when this occurs libpng will issue
* a benign error. This API can be used to override that behavior.
*/
void PNGAPI
png_set_check_for_invalid_index(png_structrp png_ptr, int enabled)
{
/* This defaults to 0, therefore *on*: */
if (png_ptr != NULL)
{
if (png_ptr->read_struct)
# ifdef PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED
png_ptr->palette_index_check_disabled = enabled <= 0;
# else /* !READ_CHECK_FOR_INVALID_INDEX */
png_app_error(png_ptr, "no read palette check support");
# endif /* !READ_CHECK_FOR_INVALID_INDEX */
else /* write struct */
# ifdef PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED
png_ptr->palette_index_check_disabled = enabled <= 0;
# else /* !WRITE_CHECK_FOR_INVALID_INDEX */
png_app_error(png_ptr, "no write palette check support");
# endif /* !WRITE_CHECK_FOR_INVALID_INDEX */
}
}
#endif /* CHECK_FOR_INVALID_INDEX */
void /* PRIVATE */
png_init_row_info(png_structrp png_ptr)
{
@@ -856,8 +841,11 @@ png_init_row_info(png_structrp png_ptr)
defined (PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED)
(png_ptr->read_struct
# ifdef PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED
&& !png_ptr->palette_index_check_disabled)
&& (png_ptr->palette_index_check == PNG_PALETTE_CHECK_ON ||
(png_ptr->palette_index_check == PNG_PALETTE_CHECK_DEFAULT
&& png_ptr->num_palette < (1U << png_ptr->bit_depth)))
# endif /* READ_CHECK_FOR_INVALID_INDEX */
)
# else /* no READ support */
0
# endif /* READ checks */
@@ -866,8 +854,11 @@ png_init_row_info(png_structrp png_ptr)
defined (PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED)
(!png_ptr->read_struct
# ifdef PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED
&& !png_ptr->palette_index_check_disabled)
&& (png_ptr->palette_index_check == PNG_PALETTE_CHECK_ON ||
(png_ptr->palette_index_check == PNG_PALETTE_CHECK_DEFAULT
&& png_ptr->num_palette < (1U << png_ptr->bit_depth)))
# endif /* WRITE_CHECK_FOR_INVALID_INDEX */
)
# else /* no WRITE support */
0
# endif /* WRITE checks */

View File

@@ -33,6 +33,11 @@
void /* PRIVATE */
png_write_data(png_structrp png_ptr, png_const_voidp data, png_size_t length)
{
/* This was guaranteed by prior versions of libpng, so app callbacks may
* assume it even though it isn't documented to be the case.
*/
debug(length > 0U);
/* NOTE: write_data_fn must not change the buffer!
* This cast is required because of the API; changing the type of the
* callback would require every app to change the callback and that change
@@ -67,18 +72,7 @@ png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
}
#endif
/* This function is called to output any data pending writing (normally
* to disk). After png_flush is called, there should be no data pending
* writing in any buffers.
*/
#ifdef PNG_WRITE_FLUSH_SUPPORTED
void /* PRIVATE */
png_flush(png_structrp png_ptr)
{
if (png_ptr->output_flush_fn != NULL)
png_ptr->output_flush_fn(png_ptr);
}
# ifdef PNG_STDIO_SUPPORTED
void PNGCBAPI
png_default_flush(png_structp png_ptr)

View File

@@ -61,13 +61,7 @@ write_unknown_chunks(png_structrp png_ptr, png_const_inforp info_ptr,
(keep == PNG_HANDLE_CHUNK_AS_DEFAULT &&
png_ptr->unknown_default == PNG_HANDLE_CHUNK_ALWAYS)))
#endif
{
/* TODO: review, what is wrong with a zero length unknown chunk? */
if (up->size == 0)
png_warning(png_ptr, "Writing zero-length unknown chunk");
png_write_chunk(png_ptr, up->name, up->data, up->size);
}
}
}
}
@@ -487,7 +481,8 @@ png_write_end(png_structrp png_ptr, png_inforp info_ptr)
*/
# ifdef PNG_WRITE_FLUSH_SUPPORTED
# ifdef PNG_WRITE_FLUSH_AFTER_IEND_SUPPORTED
png_flush(png_ptr);
if (png_ptr->output_flush_fn != NULL)
png_ptr->output_flush_fn(png_ptr);
# endif
# endif
}
@@ -543,92 +538,34 @@ png_create_write_struct_2,(png_const_charp user_png_ver, png_voidp error_ptr,
if (png_ptr != NULL)
{
/* Set the IDAT size to the default, the app can change it later. */
png_ptr->IDAT_size = PNG_ZBUF_SIZE;
/* This is a highly dubious configuration option; by default it is off,
* but it may be appropriate for private builds that are testing
* extensions not conformant to the current specification, or of
* applications that must not fail to write at all costs!
*/
#ifdef PNG_BENIGN_WRITE_ERRORS_SUPPORTED
/* In stable builds only warn if an application error can be completely
* handled.
*/
png_ptr->flags |= PNG_FLAG_BENIGN_ERRORS_WARN;
#endif
/* App warnings are warnings in release (or release candidate) builds but
* are errors during development.
*/
#if PNG_RELEASE_BUILD
png_ptr->flags |= PNG_FLAG_APP_WARNINGS_WARN;
#endif
# ifdef PNG_BENIGN_ERRORS_SUPPORTED
# if !PNG_RELEASE_BUILD
/* Always quit on error prior to release */
png_ptr->benign_error_action = PNG_ERROR;
png_ptr->app_warning_action = PNG_WARN;
png_ptr->app_error_action = PNG_ERROR;
# else /* RELEASE_BUILD */
/* Allow benign errors on write, subject to app control. */
# ifdef PNG_BENIGN_WRITE_ERRORS_SUPPORTED
png_ptr->benign_error_action = PNG_WARN;
png_ptr->app_error_action = PNG_WARN;
png_ptr->app_warning_action = PNG_WARN;
# else /* !BENIGN_WRITE_ERRORS */
/* libpng build without benign error support; the application
* author has to be assumed to be correct, so:
*/
png_ptr->benign_error_action = PNG_ERROR;
png_ptr->app_warning_action = PNG_WARN;
png_ptr->app_error_action = PNG_ERROR;
# endif /* !BENIGN_WRITE_ERRORS */
# endif /* RELEASE_BUILD */
# endif /* BENIGN_ERRORS */
}
return png_ptr;
}
/* Write a few rows of image data. If the image is interlaced,
* either you will have to write the 7 sub images, or, if you
* have called png_set_interlace_handling(), you will have to
* "write" the image seven times.
*/
void PNGAPI
png_write_rows(png_structrp png_ptr, png_bytepp row,
png_uint_32 num_rows)
{
png_debug(1, "in png_write_rows");
if (png_ptr == NULL || row == NULL)
return;
/* Loop through the rows */
while (num_rows-- > 0)
png_write_row(png_ptr, *row++);
}
/* Write the image. You only need to call this function once, even
* if you are writing an interlaced image.
*/
void PNGAPI
png_write_image(png_structrp png_ptr, png_bytepp image)
{
int num_pass; /* pass variables */
if (png_ptr == NULL || image == NULL)
return;
png_debug(1, "in png_write_image");
#ifdef PNG_WRITE_INTERLACING_SUPPORTED
/* Initialize interlace handling. If image is not interlaced,
* this will set pass to 1
*/
num_pass = png_set_interlace_handling(png_ptr);
#else
num_pass = 1;
if (png_ptr->interlaced)
{
png_app_error(png_ptr, "no interlace support");
return;
}
#endif
/* Loop through passes */
while (num_pass-- > 0)
{
png_bytepp rp = image; /* points to current row */
png_uint_32 num_rows = png_ptr->height;
/* Loop through image */
while (num_rows-- > 0)
png_write_row(png_ptr, *rp++);
}
}
#if defined(PNG_WRITE_INTERLACING_SUPPORTED) ||\
defined(PNG_WRITE_TRANSFORMS_SUPPORTED)
static void
@@ -677,7 +614,7 @@ write_row_buffered(png_structrp png_ptr,
{
png_transform_control tc;
/* The initial values are the memory format, this was worked out in
/* The initial values are the memory format; this was worked out in
* png_init_row_info below.
*/
memset(&tc, 0, sizeof tc);
@@ -707,10 +644,10 @@ write_row_buffered(png_structrp png_ptr,
}
# endif /* WRITE_TRANSFORMS */
/* Call png_write_filter_row to write this block of data, the test on
/* Call png_write_png_data to write this block of data, the test on
* maxpixels says if this is the final block in the row.
*/
png_write_filter_row(png_ptr, prev_pixels, pixel_buffer.buffer, x,
png_write_png_data(png_ptr, prev_pixels, pixel_buffer.buffer, x,
max_pixels, row_info_flags);
}
}
@@ -824,47 +761,7 @@ interlace_row_byte(png_const_structrp png_ptr, png_bytep dp, png_const_bytep sp,
}
#endif /* WRITE_INTERLACING */
static void
write_row_unbuffered(png_structrp png_ptr, png_const_bytep row,
unsigned int row_info_flags)
{
/* Split the row into blocks of the appropriate size: */
const unsigned int input_depth = png_ptr->row_input_pixel_depth;
unsigned int max_pixels = png_max_pixel_block(png_ptr);
png_uint_32 max_bytes = max_pixels;
const unsigned int pass = png_ptr->pass;
const png_uint_32 width = png_ptr->interlaced == PNG_INTERLACE_NONE ?
png_ptr->width : PNG_PASS_COLS(png_ptr->width, pass);
png_uint_32 x;
png_byte prev_pixels[4*2*2]; /* 2 pixels up to 4 2-byte channels each */
/* max_pixels is at most 16 bits, input_depth is at most 64, so the product
* always fits in 32 bits:
*/
max_bytes *= input_depth; /* bits */
debug(input_depth <= 64 && (max_bytes & 7U) == 0U);
max_bytes >>= 3;
memset(prev_pixels, 0U, sizeof prev_pixels);
for (x = 0U; x < width; x += max_pixels, row += max_bytes)
{
if (max_pixels > width - x)
{
max_bytes = width - x;
max_pixels = (unsigned int)/*SAFE*/max_bytes;
max_bytes = (max_bytes * input_depth + 7U) >> 3;
}
debug((row_info_flags & png_row_end) == 0U); /* must be set here at end */
if (x + max_pixels >= width)
row_info_flags |= png_row_end;
png_write_filter_row(png_ptr, prev_pixels, row, x, max_pixels,
row_info_flags);
}
}
#ifdef PNG_WRITE_TRANSFORMS_SUPPORTED
static void
write_row_core(png_structrp png_ptr, png_const_bytep row,
unsigned int row_info_flags)
@@ -880,7 +777,8 @@ write_row_core(png_structrp png_ptr, png_const_bytep row,
/* If control reaches this point the intermediate buffer is not required and
* the input data can be used unmodified.
*/
write_row_unbuffered(png_ptr, row, row_info_flags);
png_write_png_rows(png_ptr, &row, 1U);
PNG_UNUSED(row_info_flags)
}
/* Write a single non-interlaced row. */
@@ -888,75 +786,53 @@ static void
write_row_non_interlaced(png_structrp png_ptr, png_const_bytep row)
{
const png_uint_32 row_number = png_ptr->row_number+1U;
const int last_pass_row = row_number == png_ptr->height;
/* There is only one pass, so this is the last pass: */
write_row_core(png_ptr, row,
(row_number == 1U ? png_pass_first_row : 0) |
(last_pass_row ? png_pass_last_row : 0) |
png_pass_last);
const unsigned int row_info_flags =
(row_number == 1U ? png_pass_first_row : 0) |
(row_number >= png_ptr->height ? png_pass_last_row : 0) |
png_pass_last;
if (!last_pass_row)
png_ptr->row_number = row_number;
debug(png_ptr->interlaced == PNG_INTERLACE_NONE);
else
{
png_ptr->row_number = 0U;
png_ptr->pass = 7U;
}
write_row_core(png_ptr, row, row_info_flags);
}
/* Write a single interlaced row. */
static void
write_row_interlaced(png_structrp png_ptr, png_const_bytep row)
{
/* row_number is the row in the pass. The app must only call png_write_row
* the correct number of times. 'pass' is set to 7U after the end.
*/
const png_uint_32 row_number = png_ptr->row_number+1U;
unsigned int pass = png_ptr->pass;
const int last_pass_row = row_number == PNG_PASS_ROWS(png_ptr->height, pass);
const png_uint_32 height = png_ptr->height;
const unsigned int pass = png_ptr->pass;
const unsigned int row_info_flags =
(row_number == 1U ? png_pass_first_row : 0) |
(row_number == PNG_PASS_ROWS(height, pass) ? png_pass_last_row : 0) |
(pass == PNG_LAST_PASS(png_ptr->width, height) ? png_pass_last : 0);
write_row_core(png_ptr, row,
(row_number == 1U ? png_pass_first_row : 0) |
(last_pass_row ? png_pass_last_row : 0) |
(pass == PNG_LAST_PASS(png_ptr->width, png_ptr->height) ?
png_pass_last : 0));
# ifdef PNG_WRITE_INTERLACING_SUPPORTED
/* Check that libpng is not doing the interlace: */
debug(png_ptr->interlaced != PNG_INTERLACE_NONE &&
!png_ptr->do_interlace);
# endif /* WRITE_INTERLACING */
if (!last_pass_row)
png_ptr->row_number = row_number;
else
{
png_ptr->row_number = 0U;
do
++pass;
while (pass < 7U &&
!PNG_PASS_IN_IMAGE(png_ptr->width, png_ptr->height, pass));
png_ptr->pass = 0x7U & pass;
}
write_row_core(png_ptr, row, row_info_flags);
}
#endif /* WRITE_TRANSFORMS */
#ifdef PNG_WRITE_INTERLACING_SUPPORTED
/* Interlace a row then write it out. */
static int
static void
interlace_row(png_structrp png_ptr, png_const_bytep row)
{
/* row_number is in the image, it may not be in the pass and, likewise, the
* pass may not exist.
*/
/* The row may not exist in the image (for this pass). */
const png_uint_32 row_number = png_ptr->row_number; /* in image */
const unsigned int pass = png_ptr->pass;
const int write_row = png_ptr->width > PNG_PASS_START_COL(pass) &&
PNG_ROW_IN_INTERLACE_PASS(row_number, pass);
if (write_row)
if (png_ptr->width > PNG_PASS_START_COL(pass) &&
PNG_ROW_IN_INTERLACE_PASS(row_number, pass))
{
const unsigned int row_info_flags =
(row_number == PNG_PASS_START_ROW(pass) ?
png_pass_first_row : 0) |
(row_number == PNG_PASS_START_ROW(pass) ? png_pass_first_row : 0) |
(PNG_LAST_PASS_ROW(row_number, pass, png_ptr->height) ?
png_pass_last_row : 0) |
(pass == PNG_LAST_PASS(png_ptr->width, png_ptr->height) ?
@@ -991,79 +867,214 @@ interlace_row(png_structrp png_ptr, png_const_bytep row)
interlace_row_byte, input_depth >> 3);
break;
}
}
} /* pass < 6 */
else /* pass 6; no interlacing required */
else /* pass 6: no interlacing required */
write_row_core(png_ptr, row, row_info_flags);
}
if (row_number+1U < png_ptr->height)
png_ptr->row_number = row_number+1U;
else
{
png_ptr->row_number = 0U;
png_ptr->pass = 0x7U & (pass+1U);
}
/* This code must advance row_number/pass itself; the row has been
* skipped.
*/
if (row_number+1U < png_ptr->height)
png_ptr->row_number = row_number+1U;
return write_row;
else
{
png_ptr->row_number = 0U;
png_ptr->pass = 0x7U & (pass+1U);
}
}
}
#endif /* WRITE_INTERLACING */
/* Called by user to write a row of image data */
void PNGAPI
png_write_row(png_structrp png_ptr, png_const_bytep row)
/* Bottleneck API to actually write a number of rows, only exists because the
* rows parameter to png_write_rows is wrong.
*/
static void
png_write_rows_internal(png_structrp png_ptr, png_const_bytep *rows,
png_uint_32 num_rows)
{
if (png_ptr != NULL)
if (png_ptr != NULL && num_rows > 0U && rows != NULL)
{
const unsigned int pass = png_ptr->pass;
const png_uint_32 row_number = png_ptr->row_number;
/* Unlike the read code initialization happens automatically: */
if (row_number == 0 && pass == 0)
png_write_start_IDAT(png_ptr); /* doesn't change row/pass/width */
if (png_ptr->row_number == 0U && png_ptr->pass == 0U)
{
png_init_row_info(png_ptr);
else if (pass == 7U) /* too many calls; write already ended */
# ifdef PNG_WRITE_TRANSFORMS_SUPPORTED
/* If the app takes a png_info from a read operation and if the app has
* performed transforms on the data the png_info can contain IHDR
* information that cannot be represented in PNG. The code that writes
* the IHDR takes the color type from the png_info::format. The app
* adds transforms, before or after writing the IHDR, then the IHDR
* color_type stored in png_struct::color_type is used in
* png_init_row_info above to work out the actual row format.
*
* Prior to 1.7.0 this was not verified (there was no easy way to do
* so). Now we can check it here, however this is an:
*
* API CHANGE: in 1.7.0 an error may be flagged against bogus
* info_struct formats even though the app had removed them itself.
* It's just a warning at present.
*
* The test is that either the row_format produced by the write
* transforms exactly matches that in the original info_struct::format
* or that the info_struct::format was a simple mapping of the
* color_type that ended up in the IHDR:
*/
if (png_ptr->row_format != png_ptr->info_format &&
PNG_FORMAT_FROM_COLOR_TYPE(png_ptr->color_type) !=
png_ptr->info_format)
png_app_warning(png_ptr, "info_struct format does not match IHDR");
# endif /* WRITE_TRANSFORMS */
/* Perform initialization required before IDATs are written. */
png_write_start_IDAT(png_ptr);
}
else if (png_ptr->pass >= 7U) /* too many calls; write already ended */
{
debug(png_ptr->row_number == 0U);
png_app_error(png_ptr, "Too many calls to png_write_row");
return;
}
/* Make sure there is a row to write: */
if (row == NULL)
{
png_app_error(png_ptr, "NULL row pointer to png_write_row");
return;
}
if (png_ptr->interlaced == PNG_INTERLACE_NONE)
write_row_non_interlaced(png_ptr, row);
/* The remainder of these tests detect internal errors in libpng */
else if (png_ptr->interlaced == PNG_INTERLACE_NONE)
affirm(png_ptr->row_number < png_ptr->height && png_ptr->pass == 0U);
# ifdef PNG_WRITE_INTERLACING_SUPPORTED
/* Optional: libpng does the interlacing, app passes every row of the
* image the required number of times.
*/
else if (png_ptr->do_interlace != 0U)
{
if (!interlace_row(png_ptr, row))
return; /* row skipped; skip the write callback */
}
# endif
else if (png_ptr->do_interlace)
affirm(png_ptr->row_number < png_ptr->height);
# endif /* WRITE_INTERLACING */
else /* app does the interlacing */
write_row_interlaced(png_ptr, row);
else /* app does interlace */
affirm(
PNG_PASS_IN_IMAGE(png_ptr->width, png_ptr->height, png_ptr->pass) &&
png_ptr->row_number < PNG_PASS_ROWS(png_ptr->height, png_ptr->pass)
);
/* API CHANGE: 1.7.0: this is now called after png_struct::row_number and
* png_struct::pass have been updated and, at the end of the image, after
* the deflate stream has been closed. The order of the call with respect
* to the flush operation has also changed. The callback can't discover
* any of this unless it relies on the write callbacks to find the row
* data, and that was never predictable.
/* First handle rows that require buffering because of the need to
* interlace them or the need to perform write transforms.
*/
if (png_ptr->write_row_fn != NULL)
(*(png_ptr->write_row_fn))(png_ptr, row_number, pass);
} /* png_ptr != NULL */
# ifdef PNG_WRITE_INTERLACING_SUPPORTED
/* libpng is doing the interlacing, but this only makes a difference to
* the first six passes (numbered, in libpng, 0..5); the seventh pass
* (numbered 6 by libpng) consists of complete image rows.
*/
if (png_ptr->do_interlace) while (num_rows > 0U && png_ptr->pass < 6)
interlace_row(png_ptr, *rows++), --num_rows;
# endif /* WRITE_INTERLACING */
# ifdef PNG_WRITE_TRANSFORMS_SUPPORTED
/* Transforms required however the row interlacing has already been
* handled and we have a complete (PNG) row.
*/
if (png_ptr->transform_list != NULL)
{
if (png_ptr->interlaced == PNG_INTERLACE_NONE)
while (num_rows > 0U)
write_row_non_interlaced(png_ptr, *rows++), --num_rows;
# ifdef PNG_WRITE_INTERLACING_SUPPORTED
else if (png_ptr->do_interlace)
while (num_rows > 0U)
interlace_row(png_ptr, *rows++), --num_rows;
# endif /* WRITE_INTERLACING */
else /* app does the interlacing */
while (num_rows > 0U)
write_row_interlaced(png_ptr, *rows++), --num_rows;
}
# endif /* WRITE_TRANSFORMS */
/* Finally handle any remaining rows that require no (libpng) interlace
* and no transforms.
*/
if (num_rows > 0U)
png_write_png_rows(png_ptr, rows, num_rows);
/* Repeat the checks above, but allow for end-of-image. */
if (png_ptr->pass < 7U)
{
if (png_ptr->interlaced == PNG_INTERLACE_NONE)
affirm(png_ptr->row_number < png_ptr->height &&
png_ptr->pass == 0U);
# ifdef PNG_WRITE_INTERLACING_SUPPORTED
else if (png_ptr->do_interlace)
affirm(png_ptr->row_number < png_ptr->height);
# endif /* WRITE_INTERLACING */
else /* app does interlace */
affirm(PNG_PASS_IN_IMAGE(png_ptr->width, png_ptr->height,
png_ptr->pass) &&
png_ptr->row_number <
PNG_PASS_ROWS(png_ptr->height, png_ptr->pass));
}
} /* png_ptr, rows, num_rows all valid */
else if (png_ptr != NULL)
png_app_warning(png_ptr, "Missing rows to row write API");
}
/* ROW WRITE APIs */
/* Called by user to write a single row of image data */
void PNGAPI
png_write_row(png_structrp png_ptr, png_const_bytep row)
{
png_debug(1, "in png_write_row");
png_write_rows_internal(png_ptr, &row, 1U);
}
/* Write a few rows of image data. If the image is interlaced,
* either you will have to write the 7 sub images, or, if you
* have called png_set_interlace_handling(), you will have to
* "write" the image seven times.
*/
void PNGAPI
png_write_rows(png_structrp png_ptr, png_bytepp rows, png_uint_32 num_rows)
{
png_debug(1, "in png_write_rows");
if (png_ptr != NULL)
png_write_rows_internal(png_ptr, png_constcast(png_const_bytep*,rows),
num_rows);
}
/* Write the image. You only need to call this function once, even
* if you are writing an interlaced image.
*/
void PNGAPI
png_write_image(png_structrp png_ptr, png_bytepp image)
{
png_debug(1, "in png_write_image");
if (png_ptr != NULL)
{
int num_pass = 1;
/* The image is always an non-interlaced image. To write it as interlaced
* interlace handling must be present:
*/
if (png_ptr->interlaced)
{
# ifdef PNG_WRITE_INTERLACING_SUPPORTED
num_pass = png_set_interlace_handling(png_ptr);
# else /* !WRITE_INTERLACING */
/* There is no recovery because the IHDR has already been written.
*/
png_error(png_ptr, "No interlace support");
# endif /* !WRITE_INTERLACING */
}
/* And write the whole thing, 7 times if interlacing it: */
for (; num_pass > 0; --num_pass)
png_write_rows(png_ptr, image, png_ptr->height);
}
}
/* Free any memory used in png_ptr struct without freeing the struct itself. */
@@ -1074,10 +1085,6 @@ png_write_destroy(png_structrp png_ptr)
png_deflate_destroy(png_ptr);
#ifdef PNG_WRITE_FILTER_SUPPORTED
png_free(png_ptr, png_ptr->row_buffer);
png_ptr->row_buffer = NULL;
#endif /* WRITE_FILTER */
#ifdef PNG_TRANSFORM_MECH_SUPPORTED
png_transform_free(png_ptr, &png_ptr->transform_list);
#endif
@@ -1903,21 +1910,12 @@ png_image_write_main(png_voidp argument)
display->row_bytes = row_bytes;
}
/* Apply 'fast' options if the flag is set. */
if ((image->flags & PNG_IMAGE_FLAG_FAST) != 0)
{
# ifdef PNG_WRITE_FILTER_SUPPORTED
png_set_filter(png_ptr, PNG_FILTER_TYPE_BASE, PNG_NO_FILTERS);
# endif /* WRITE_FILTER */
/* NOTE: determined by experiment using pngstest, this reflects some
* balance between the time to write the image once and the time to read
* it about 50 times. The speed-up in pngstest was about 10-20% of the
* total (user) time on a heavily loaded system.
*/
# ifdef PNG_WRITE_CUSTOMIZE_COMPRESSION_SUPPORTED
png_set_compression_level(png_ptr, 3);
# endif /* WRITE_CUSTOMIZE_COMPRESSION */
}
/* Select the right compression mode based on the presence or absence of the
* 'fast' flag. This will use whatever options are available in the libpng
* build. It is always supported.
*/
png_set_compression(png_ptr, (image->flags & PNG_IMAGE_FLAG_FAST) != 0 ?
PNG_COMPRESSION_HIGH_SPEED : PNG_COMPRESSION_HIGH);
/* Check for the cases that currently require a pre-transform on the row
* before it is written. This only applies when the input is 16-bit and

3495
pngwutil.c

File diff suppressed because it is too large Load Diff

View File

@@ -1,7 +1,7 @@
VisualStudio instructions
libpng version 1.7.0beta79 - March 9, 2016
libpng version 1.7.0beta82 - July 4, 2016
Copyright (c) 2010,2013,2015 Glenn Randers-Pehrson

View File

@@ -2,7 +2,7 @@
<!--
* zlib.props - location of zlib source
*
* libpng version 1.7.0beta79 - March 9, 2016
* libpng version 1.7.0beta82 - July 4, 2016
*
* Copyright (c) 2011,2013,2014 Glenn Randers-Pehrson
*

View File

@@ -1,9 +1,9 @@
Makefiles for libpng version 1.7.0beta79 - March 9, 2016
Makefiles for libpng version 1.7.0beta82 - July 4, 2016
pnglibconf.h.prebuilt => Stores configuration settings
makefile.linux => Linux/ELF makefile
(gcc, creates libpng17.so.17.1.7.0beta79)
(gcc, creates libpng17.so.17.1.7.0beta82)
makefile.gcc => Generic makefile (gcc, creates static libpng.a)
makefile.knr => Archaic UNIX Makefile that converts files with
ansi2knr (Requires ansi2knr.c from
@@ -33,12 +33,12 @@ pnglibconf.h.prebuilt => Stores configuration settings
makefile.os2 => OS/2 Makefile (gcc and emx, requires libpng.def)
makefile.sco => For SCO OSr5 ELF and Unixware 7 with Native cc
makefile.sggcc => Silicon Graphics (gcc,
creates libpng17.so.17.1.7.0beta79)
creates libpng17.so.17.1.7.0beta82)
makefile.sgi => Silicon Graphics IRIX makefile (cc, creates static lib)
makefile.solaris => Solaris 2.X makefile (gcc,
creates libpng17.so.17.1.7.0beta79)
creates libpng17.so.17.1.7.0beta82)
makefile.so9 => Solaris 9 makefile (gcc,
creates libpng17.so.17.1.7.0beta79)
creates libpng17.so.17.1.7.0beta82)
makefile.std => Generic UNIX makefile (cc, creates static libpng.a)
makefile.sunos => Sun makefile
makefile.32sunu => Sun Ultra 32-bit makefile

View File

@@ -21,7 +21,7 @@ PNG_DFN "OS2 DESCRIPTION "PNG image compression library""
PNG_DFN "OS2 CODE PRELOAD MOVEABLE DISCARDABLE"
PNG_DFN ""
PNG_DFN "EXPORTS"
PNG_DFN ";Version 1.7.0beta79"
PNG_DFN ";Version 1.7.0beta82"
#define PNG_EXPORTA(ordinal, type, name, args, attributes)\
PNG_DFN "@" SYMBOL_PREFIX "@@" name "@"

View File

@@ -11,7 +11,7 @@
# Modeled after libxml-config.
version=1.7.0beta79
version=1.7.0beta82
prefix=""
libdir=""
libs=""

View File

@@ -5,6 +5,6 @@ includedir=@includedir@/libpng17
Name: libpng
Description: Loads and saves PNG files
Version: 1.7.0beta79
Version: 1.7.0beta82
Libs: -L${libdir} -lpng17
Cflags: -I${includedir}

View File

@@ -17,7 +17,7 @@ INCSDIR=${LOCALBASE}/include/libpng17
LIB= png17
SHLIB_MAJOR= 0
SHLIB_MINOR= 1.7.0beta79
SHLIB_MINOR= 1.7.0beta82
SRCS= png.c pngset.c pngget.c pngrutil.c pngtrans.c pngwutil.c \
pngread.c pngrio.c pngwio.c pngwrite.c pngrtran.c \
pngwtran.c pngmem.c pngerror.c pngpread.c

View File

@@ -17,7 +17,7 @@ INCSDIR=${LOCALBASE}/include
LIB= png
SHLIB_MAJOR= 17
SHLIB_MINOR= 1.7.0beta79
SHLIB_MINOR= 1.7.0beta82
SRCS= png.c pngset.c pngget.c pngrutil.c pngtrans.c pngwutil.c \
pngread.c pngrio.c pngwio.c pngwrite.c pngrtran.c \
pngwtran.c pngmem.c pngerror.c pngpread.c

View File

@@ -11,7 +11,7 @@ LIBDIR= ${PREFIX}/lib
MANDIR= ${PREFIX}/man/cat
SHLIB_MAJOR= 17
SHLIB_MINOR= 1.7.0beta79
SHLIB_MINOR= 1.7.0beta82
LIB= png
SRCS= png.c pngerror.c pngget.c pngmem.c pngpread.c \

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,
@@ -798,8 +779,12 @@ setting sCAL_PRECISION default 5
# written IDAT chunks. It can be any (zlib) uInt value, however this amount of
# data has to be buffered on write so it is recommended that a smaller size be
# used unless saving the 12-byte chunk overhead is necessary.
#
# If not set libpng uses the DEFAULT_COMPRESSION_LEVEL setting to determine
# something appropriate. The value below is only used for 'MEDIUM' compression
# (which is the default: see below.)
setting ZBUF_SIZE default 4096
setting ZBUF_SIZE default 8192
# This is the size of the decompression buffer used when counting or checking
# the decompressed size of an LZ stream from a compressed ancilliary chunk; the
@@ -852,10 +837,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
@@ -930,20 +913,13 @@ option CONVERT_tIME requires WRITE_ANCILLARY_CHUNKS
# png_set_filter interface allowing the application to select the filter
# used for each row.
#
# SELECT_FILTER_HEURISTICALLY
# Enables code to cause libpng to choose a filter from a set passed to
# png_set_filter. Without this code libpng just chooses the first filter in
# the list if multiple are given.
# SELECT_FILTER
# Enables code to select between multiple filters on write. Without this
# the 'first' (lowest numbered) filter will be selected an this typically
# works out as PNG_FILTER_VALUE_NONE.
#
# SELECT_FILTER_METHODICALLY
# Enables code to try all the filters in the list passed to png_set_filter
# and choose the one which results in the least number of compressed bytes
# added by the current row.
#
# See png.h for more description of these options.
option WRITE_FILTER requires WRITE
option SELECT_FILTER_HEURISTICALLY requires WRITE_FILTER enables SET_OPTION
option SELECT_FILTER_METHODICALLY requires WRITE_FILTER enables SET_OPTION
option SELECT_FILTER requires WRITE_FILTER
# added at libpng-1.5.4
@@ -963,8 +939,10 @@ option WRITE_zTXt enables WRITE_COMPRESSED_TEXT
# leave the row_pointers member out of the info structure.
option INFO_IMAGE disabled
option READ_PNG requires READ_IMAGE READ_TRANSFORMS enables INFO_IMAGE
option WRITE_PNG requires WRITE WRITE_TRANSFORMS enables INFO_IMAGE
option READ_PNG requires READ_IMAGE READ_TRANSFORMS READ_INTERLACING,
enables INFO_IMAGE
option WRITE_PNG requires WRITE WRITE_TRANSFORMS WRITE_INTERLACING,
enables INFO_IMAGE
# There are four options here, two each for read and write. By default they are
# all switched on.

View File

@@ -1,8 +1,8 @@
/* libpng 1.7.0beta79 STANDARD API DEFINITION */
/* libpng 1.7.0beta82 STANDARD API DEFINITION */
/* pnglibconf.h - library build configuration */
/* Libpng version 1.7.0beta79, March 9, 2016 */
/* libpng version 1.7.0beta82, July 4, 2016 */
/* Copyright (c) 1998-2016 Glenn Randers-Pehrson */
@@ -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
@@ -100,11 +99,9 @@
#define PNG_READ_tRNS_SUPPORTED
#define PNG_READ_zTXt_SUPPORTED
#define PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED
#define PNG_SELECT_FILTER_HEURISTICALLY_SUPPORTED
#define PNG_SELECT_FILTER_METHODICALLY_SUPPORTED
#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
@@ -193,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
@@ -202,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
@@ -211,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

@@ -1,4 +1,4 @@
;Version 1.7.0beta79
;Version 1.7.0beta82
;--------------------------------------------------------------
; LIBPNG symbol list as a Win32 DEF file
; Contains all the symbols that can be exported from libpng
@@ -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