Compare commits
95 Commits
v1.7.0beta
...
libpng17
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
69ddffdf2c | ||
|
|
3e2769b9d7 | ||
|
|
780d38b87d | ||
|
|
031a3815ae | ||
|
|
ef5a5760d4 | ||
|
|
0b2b7d8ab5 | ||
|
|
1c2e35ab73 | ||
|
|
58cd558a43 | ||
|
|
bdca749e35 | ||
|
|
19855cd8b1 | ||
|
|
9bda575f69 | ||
|
|
66def3fb3c | ||
|
|
8f4d83a881 | ||
|
|
a9b02399ac | ||
|
|
ba42eccb05 | ||
|
|
7345c50aaa | ||
|
|
20be5b5411 | ||
|
|
750a023377 | ||
|
|
e00c39596a | ||
|
|
448fad2d02 | ||
|
|
76a1f4bb3f | ||
|
|
243d4e5f3f | ||
|
|
48f8ca26e4 | ||
|
|
6c9ecd348d | ||
|
|
e6470a8876 | ||
|
|
b14987b483 | ||
|
|
7ed5c08fad | ||
|
|
5a1f75289e | ||
|
|
4caddaafbb | ||
|
|
512336676e | ||
|
|
0ea7a09ced | ||
|
|
0b02a667cf | ||
|
|
e1c7c0402c | ||
|
|
2127ecd0fa | ||
|
|
1757736115 | ||
|
|
6f9a39848e | ||
|
|
517fe770e2 | ||
|
|
f911c1146a | ||
|
|
28de8bf6cd | ||
|
|
6f39846891 | ||
|
|
07e2cf117f | ||
|
|
f0ada4edee | ||
|
|
3220f9c5a5 | ||
|
|
5096cac90c | ||
|
|
2a2373c1ec | ||
|
|
4283e2bf66 | ||
|
|
8ffea2e56b | ||
|
|
99eb6b5d5d | ||
|
|
096dbf8335 | ||
|
|
9743d58bc0 | ||
|
|
bdb730a593 | ||
|
|
f1fb09c406 | ||
|
|
83ca33b017 | ||
|
|
aa78bc36d9 | ||
|
|
f7b1d9a172 | ||
|
|
ce67b437ea | ||
|
|
86a3c4fb14 | ||
|
|
4b846be113 | ||
|
|
b9d7d5525b | ||
|
|
0ecbe53243 | ||
|
|
53bda5a7af | ||
|
|
6a574a84bd | ||
|
|
eaf7abfdc3 | ||
|
|
0f5992051f | ||
|
|
12c3c2e136 | ||
|
|
d6037dcb09 | ||
|
|
9dfdb2270b | ||
|
|
29be8f11ed | ||
|
|
8592a85535 | ||
|
|
b21a37323f | ||
|
|
7a0fe97841 | ||
|
|
9a137f332f | ||
|
|
8c8aea7fd4 | ||
|
|
d52c8eba99 | ||
|
|
b70b51ba17 | ||
|
|
2b711a751c | ||
|
|
2e68f96511 | ||
|
|
8c7b59f2b9 | ||
|
|
01ff090760 | ||
|
|
120f80369b | ||
|
|
1982dc6c2f | ||
|
|
a1296131fe | ||
|
|
5095b2adfb | ||
|
|
5b19ac3019 | ||
|
|
a5b340e20b | ||
|
|
21f92eef89 | ||
|
|
bf101dcea1 | ||
|
|
764ae3995b | ||
|
|
bd6fb5534f | ||
|
|
f05407d292 | ||
|
|
5652acdd48 | ||
|
|
cf46e3748f | ||
|
|
52c9e4fdd6 | ||
|
|
4905ed4aae | ||
|
|
ba356b4e4d |
171
ANNOUNCE
@@ -1,5 +1,5 @@
|
||||
|
||||
Libpng 1.7.0beta80 - May 6, 2016
|
||||
Libpng 1.7.0beta90 - September 3, 2017
|
||||
|
||||
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.0beta80.tar.xz (LZMA-compressed, recommended)
|
||||
1.7.0beta80.tar.gz
|
||||
1.7.0beta90.tar.xz (LZMA-compressed, recommended)
|
||||
1.7.0beta90.tar.gz
|
||||
|
||||
Source files with CRLF line endings (for Windows), without the
|
||||
"configure" script
|
||||
|
||||
/scratch/glennrp/Libpng17/lp170b80.7z (LZMA-compressed, recommended)
|
||||
/scratch/glennrp/Libpng17/lp170b80.zip
|
||||
/scratch/glennrp/Libpng17/lp170b90.7z (LZMA-compressed, recommended)
|
||||
/scratch/glennrp/Libpng17/lp170b90.zip
|
||||
|
||||
Other information:
|
||||
|
||||
1.7.0beta80-README.txt
|
||||
1.7.0beta80-LICENSE.txt
|
||||
libpng-1.7.0beta80-*.asc (armored detached GPG signatures)
|
||||
1.7.0beta90-README.txt
|
||||
1.7.0beta90-LICENSE.txt
|
||||
libpng-1.7.0beta90-*.asc (armored detached GPG signatures)
|
||||
|
||||
Changes since the last public release (1.6.0):
|
||||
|
||||
@@ -1290,6 +1290,161 @@ Version 1.7.0beta80 [May 6, 2016]
|
||||
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.
|
||||
|
||||
Version 1.7.0beta83 [July 23, 2016]
|
||||
Fixed some indentation to comply with our coding style.
|
||||
Removed/rearranged certain png_struct fields that are only used
|
||||
in reading.
|
||||
Fixed debug test of output gamma.
|
||||
|
||||
Version 1.7.0beta84 [September 26, 2016]
|
||||
Minor editing of INSTALL, (whitespace, added copyright line)
|
||||
Don't install pngcp; it conflicts with pngcp in the pngtools package.
|
||||
Fixed handling zero length IDAT in pngfix (bug report by Agostino Sarubbo,
|
||||
bugfix by John Bowler).
|
||||
Conditionally compile png_set_benign_errors() in pngread.c and pngtest.c
|
||||
Changed PNG_ZLIB_VERNUM to ZLIB_VERNUM in pngrutil.c.
|
||||
If CRC handling of critical chunks has been set to PNG_CRC_QUIET_USE,
|
||||
ignore the ADLER32 checksum in the IDAT chunk as well as the chunk CRCs.
|
||||
Issue png_benign_error() on ADLER32 checksum mismatch instead of png_error().
|
||||
Add tests/badcrc.png and tests/badadler.png to tests/pngtest.
|
||||
|
||||
Version 1.7.0beta85 [December 27, 2016]
|
||||
Updated the documentation about CRC and ADLER32 handling.
|
||||
Quieted warnings from clang-3.8 in pngunknown.c and pngvalid.c.
|
||||
Removed the use of a macro containing the pre-processor 'defined'
|
||||
operator. It is unclear whether this is valid; a macro that
|
||||
"generates" 'defined' is not permitted, but the use of the word
|
||||
"generates" within the C90 standard seems to imply more than simple
|
||||
substitution of an expression itself containing a well-formed defined
|
||||
operation.
|
||||
|
||||
Version 1.7.0beta86 [December 29, 2016]
|
||||
Ported CMakeLists.txt from libpng-1.6.27rc01.
|
||||
Fixed a potential null pointer dereference in png_set_text_2() (bug report
|
||||
and patch by Patrick Keshishian, CVE-2016-10087).
|
||||
|
||||
Version 1.7.0beta87 [April 1, 2017]
|
||||
Fixed arm/aarch64 detection in CMakeLists.txt (Gianfranco Costamagna).
|
||||
The contrib/examples/pngtopng.c recovery code was in the wrong "if"
|
||||
branches; the comments were correct.
|
||||
Added missing "$(CPPFLAGS)" to the compile line for c.pic.o in
|
||||
makefile.linux and makefile.solaris-x86 (Cosmin).
|
||||
Merged some recent changes from libpng-1.6.30beta01.
|
||||
|
||||
Version 1.7.0beta88 [August 7. 2017]
|
||||
Added private png_check_chunk_name() and png_check_chunk_length()
|
||||
functions (Fixes CVE-2017-12652).
|
||||
|
||||
Version 1.7.0beta89 [August 19, 2017]
|
||||
Check for 0 return from png_get_rowbytes() in contrib/pngminus/*.c to stop
|
||||
some Coverity issues (162705, 162706, and 162707).
|
||||
|
||||
Version 1.7.0beta90 [September 3, 2017]
|
||||
Added PNGMINUS_UNUSED macro to contrib/pngminus/p*.c and added missing
|
||||
parenthesis in contrib/pngminus/pnm2png.c (bug report by Christian Hesse).
|
||||
Compute a larger limit on IDAT because some applications write a deflate
|
||||
buffer for each row (Bug report by Andrew Church).
|
||||
|
||||
Send comments/corrections/commendations to png-mng-implement at lists.sf.net
|
||||
(subscription required; visit
|
||||
https://lists.sourceforge.net/lists/listinfo/png-mng-implement
|
||||
|
||||
156
CHANGES
@@ -5590,6 +5590,162 @@ Version 1.7.0beta80 [May 6, 2016]
|
||||
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.
|
||||
|
||||
Version 1.7.0beta83 [July 23, 2016]
|
||||
Fixed some indentation to comply with our coding style.
|
||||
Removed/rearranged certain png_struct fields that are only used
|
||||
in reading.
|
||||
Fixed debug test of output gamma.
|
||||
|
||||
Version 1.7.0beta84 [September 26, 2016]
|
||||
Minor editing of INSTALL, (whitespace, added copyright line)
|
||||
Don't install pngcp; it conflicts with pngcp in the pngtools package.
|
||||
Fixed handling zero length IDAT in pngfix (bug report by Agostino Sarubbo,
|
||||
bugfix by John Bowler).
|
||||
Conditionally compile png_set_benign_errors() in pngread.c and pngtest.c
|
||||
Changed PNG_ZLIB_VERNUM to ZLIB_VERNUM in pngrutil.c.
|
||||
If CRC handling of critical chunks has been set to PNG_CRC_QUIET_USE,
|
||||
ignore the ADLER32 checksum in the IDAT chunk as well as the chunk CRCs.
|
||||
Issue png_benign_error() on ADLER32 checksum mismatch instead of png_error().
|
||||
Add tests/badcrc.png and tests/badadler.png to tests/pngtest.
|
||||
|
||||
Version 1.7.0beta85 [December 27, 2016]
|
||||
Updated the documentation about CRC and ADLER32 handling.
|
||||
Quieted warnings from clang-3.8 in pngunknown.c and pngvalid.c.
|
||||
Removed the use of a macro containing the pre-processor 'defined'
|
||||
operator. It is unclear whether this is valid; a macro that
|
||||
"generates" 'defined' is not permitted, but the use of the word
|
||||
"generates" within the C90 standard seems to imply more than simple
|
||||
substitution of an expression itself containing a well-formed defined
|
||||
operation.
|
||||
|
||||
Version 1.7.0beta86 [December 29, 2016]
|
||||
Ported CMakeLists.txt from libpng-1.6.27rc01.
|
||||
Fixed a potential null pointer dereference in png_set_text_2() (bug report
|
||||
and patch by Patrick Keshishian, CVE-2016-10087).
|
||||
|
||||
Version 1.7.0beta87 [April 1, 2017]
|
||||
Fixed arm/aarch64 detection in CMakeLists.txt (Gianfranco Costamagna).
|
||||
The contrib/examples/pngtopng.c recovery code was in the wrong "if"
|
||||
branches; the comments were correct.
|
||||
Added missing "$(CPPFLAGS)" to the compile line for c.pic.o in
|
||||
makefile.linux and makefile.solaris-x86 (Cosmin).
|
||||
Merged some recent changes from libpng-1.6.30beta01.
|
||||
|
||||
Version 1.7.0beta88 [August 7, 2017]
|
||||
Initialized btoa[] in pngstest.c
|
||||
Added private png_check_chunk_name() and png_check_chunk_length()
|
||||
functions (Fixes CVE-2017-12652).
|
||||
|
||||
Version 1.7.0beta89 [August 19, 2017]
|
||||
Check for 0 return from png_get_rowbytes() in contrib/pngminus/*.c to stop
|
||||
some Coverity issues (162705, 162706, and 162707).
|
||||
|
||||
Version 1.7.0beta90 [September 3, 2017]
|
||||
Added PNGMINUS_UNUSED macro to contrib/pngminus/p*.c and added missing
|
||||
parenthesis in contrib/pngminus/pnm2png.c (bug report by Christian Hesse).
|
||||
Compute a larger limit on IDAT because some applications write a deflate
|
||||
buffer for each row (Bug report by Andrew Church).
|
||||
|
||||
Send comments/corrections/commendations to png-mng-implement at lists.sf.net
|
||||
(subscription required; visit
|
||||
https://lists.sourceforge.net/lists/listinfo/png-mng-implement
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
# Revised by Roger Lowman, 2009-2010
|
||||
# Revised by Clifford Yapp, 2011-2012
|
||||
# Revised by Roger Leigh, 2016
|
||||
# Revised by Andreas Franek, 2016
|
||||
|
||||
# This code is released under the libpng license.
|
||||
# For conditions of distribution and use, see the disclaimer
|
||||
@@ -69,6 +70,36 @@ option(PNGARG "Disable ANSI-C prototypes" OFF)
|
||||
set(PNG_PREFIX "" CACHE STRING "Prefix to add to the API function names")
|
||||
set(DFA_XTRA "" CACHE FILEPATH "File containing extra configuration settings")
|
||||
|
||||
# set definitions and sources for arm
|
||||
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "^arm" OR
|
||||
${CMAKE_SYSTEM_PROCESSOR} MATCHES "^aarch64")
|
||||
set(PNG_ARM_NEON_POSSIBLE_VALUES check on off)
|
||||
set(PNG_ARM_NEON "check" CACHE STRING "Enable ARM NEON optimizations:
|
||||
check: (default) use internal checking code;
|
||||
off: disable the optimizations;
|
||||
on: turn on unconditionally.")
|
||||
set_property(CACHE PNG_ARM_NEON PROPERTY STRINGS
|
||||
${PNG_ARM_NEON_POSSIBLE_VALUES})
|
||||
list(FIND PNG_ARM_NEON_POSSIBLE_VALUES ${PNG_ARM_NEON} index)
|
||||
if(index EQUAL -1)
|
||||
message(FATAL_ERROR
|
||||
" PNG_ARM_NEON must be one of [${PNG_ARM_NEON_POSSIBLE_VALUES}]")
|
||||
elseif(NOT ${PNG_ARM_NEON} STREQUAL "no")
|
||||
set(libpng_arm_sources
|
||||
arm/arm_init.c
|
||||
arm/filter_neon.S
|
||||
arm/filter_neon_intrinsics.c)
|
||||
|
||||
if(${PNG_ARM_NEON} STREQUAL "on")
|
||||
add_definitions(-DPNG_ARM_NEON_OPT=2)
|
||||
elseif(${PNG_ARM_NEON} STREQUAL "check")
|
||||
add_definitions(-DPNG_ARM_NEON_CHECK_SUPPORTED)
|
||||
endif()
|
||||
else()
|
||||
add_definitions(-DPNG_ARM_NEON_OPT=0)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# SET LIBNAME
|
||||
set(PNG_LIB_NAME png${PNGLIB_MAJOR}${PNGLIB_MINOR})
|
||||
|
||||
@@ -360,6 +391,7 @@ set(libpng_sources
|
||||
pngwrite.c
|
||||
pngwtran.c
|
||||
pngwutil.c
|
||||
${libpng_arm_sources}
|
||||
)
|
||||
set(pngtest_sources
|
||||
pngtest.c
|
||||
@@ -697,7 +729,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.0beta80
|
||||
# VERSION 17.${PNGLIB_RELEASE}.1.7.0beta90
|
||||
VERSION 17.${PNGLIB_RELEASE}.0
|
||||
SOVERSION 17
|
||||
CLEAN_DIRECT_OUTPUT 1)
|
||||
|
||||
124
INSTALL
@@ -1,24 +1,25 @@
|
||||
|
||||
Installing libpng
|
||||
Installing libpng
|
||||
|
||||
Contents
|
||||
|
||||
I. Simple installation
|
||||
II. Rebuilding the configure scripts
|
||||
III. Using scripts/makefile*
|
||||
IV. Using cmake
|
||||
V. Directory structure
|
||||
VI. Building with project files
|
||||
VII. Building with makefiles
|
||||
VIII. Configuring libpng for 16-bit platforms
|
||||
IX. Configuring for DOS
|
||||
X. Configuring for Medium Model
|
||||
XI. Prepending a prefix to exported symbols
|
||||
XII. Configuring for compiler xxx:
|
||||
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
|
||||
I. Simple installation
|
||||
II. Rebuilding the configure scripts
|
||||
III. Using scripts/makefile*
|
||||
IV. Using cmake
|
||||
V. Directory structure
|
||||
VI. Building with project files
|
||||
VII. Building with makefiles
|
||||
VIII. Configuring libpng for 16-bit platforms
|
||||
IX. Configuring for DOS
|
||||
X. Configuring for Medium Model
|
||||
XI. Prepending a prefix to exported symbols
|
||||
XII. Configuring for compiler xxx:
|
||||
XIII. Removing unwanted object code
|
||||
XIV. Changes to the build and configuration of libpng in libpng-1.5.x
|
||||
XV. Setjmp/longjmp issues
|
||||
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
|
||||
@@ -76,7 +79,7 @@ Or you can use one of the "projects" in the "projects" directory.
|
||||
Before installing libpng, you must first install zlib, if it
|
||||
is not already on your system. zlib can usually be found
|
||||
wherever you got libpng; otherwise go to http://zlib.net. You can place
|
||||
zlib in in the same directory as libpng or in another directory.
|
||||
zlib in the same directory as libpng or in another directory.
|
||||
|
||||
If your system already has a preinstalled zlib you will still need
|
||||
to have access to the zlib.h and zconf.h include files that
|
||||
@@ -87,22 +90,24 @@ standard library search path, put ZLIBLIB, ZLIBINC, CPPFLAGS, LDFLAGS,
|
||||
and LD_LIBRARY_PATH in your environment before running "make test"
|
||||
or "make distcheck":
|
||||
|
||||
ZLIBLIB=/path/to/lib export ZLIBLIB
|
||||
ZLIBINC=/path/to/include export ZLIBINC
|
||||
CPPFLAGS="-I$ZLIBINC" export CPPFLAGS
|
||||
LDFLAGS="-L$ZLIBLIB" export LDFLAGS
|
||||
LD_LIBRARY_PATH="$ZLIBLIB:$LD_LIBRARY_PATH" export LD_LIBRARY_PATH
|
||||
ZLIBLIB=/path/to/lib export ZLIBLIB
|
||||
ZLIBINC=/path/to/include export ZLIBINC
|
||||
CPPFLAGS="-I$ZLIBINC" export CPPFLAGS
|
||||
LDFLAGS="-L$ZLIBLIB" export LDFLAGS
|
||||
LD_LIBRARY_PATH="$ZLIBLIB:$LD_LIBRARY_PATH" export LD_LIBRARY_PATH
|
||||
|
||||
If you are using one of the makefile scripts, put ZLIBLIB and ZLIBINC
|
||||
in your environment and type "make ZLIBLIB=$ZLIBLIB ZLIBINC=$ZLIBINC test".
|
||||
in your environment and type
|
||||
|
||||
make ZLIBLIB=$ZLIBLIB ZLIBINC=$ZLIBINC test
|
||||
|
||||
IV. Using cmake
|
||||
|
||||
If you want to use "cmake" (see www.cmake.org), type
|
||||
|
||||
cmake . -DCMAKE_INSTALL_PREFIX=/path
|
||||
make
|
||||
make install
|
||||
cmake . -DCMAKE_INSTALL_PREFIX=/path
|
||||
make
|
||||
make install
|
||||
|
||||
As when using the simple configure method described above, "/path" points to
|
||||
the installation directory where you want to put the libpng "lib", "include",
|
||||
@@ -116,8 +121,8 @@ or "zlib128") so that you have directories called "zlib" and "libpng".
|
||||
|
||||
Your directory structure should look like this:
|
||||
|
||||
.. (the parent directory)
|
||||
libpng (this directory)
|
||||
.. (the parent directory)
|
||||
libpng (this directory)
|
||||
INSTALL (this file)
|
||||
README
|
||||
*.h, *.c => libpng source files
|
||||
@@ -160,10 +165,15 @@ VII. Building with makefiles
|
||||
Copy the file (or files) that you need from the
|
||||
scripts directory into this directory, for example
|
||||
|
||||
MSDOS example: copy scripts\makefile.msc makefile
|
||||
copy scripts\pnglibconf.h.prebuilt pnglibconf.h
|
||||
UNIX example: cp scripts/makefile.std makefile
|
||||
cp scripts/pnglibconf.h.prebuilt pnglibconf.h
|
||||
MSDOS example:
|
||||
|
||||
copy scripts\makefile.msc makefile
|
||||
copy scripts\pnglibconf.h.prebuilt pnglibconf.h
|
||||
|
||||
UNIX example:
|
||||
|
||||
cp scripts/makefile.std makefile
|
||||
cp scripts/pnglibconf.h.prebuilt pnglibconf.h
|
||||
|
||||
Read the makefile to see if you need to change any source or
|
||||
target directories to match your preferences.
|
||||
@@ -230,7 +240,8 @@ The files in libpng proper only include pngpriv.h and png.h, which
|
||||
in turn includes pngconf.h and, as of libpng-1.5.0, pnglibconf.h.
|
||||
As of libpng-1.5.0, pngpriv.h also includes three other private header
|
||||
files, pngstruct.h, pnginfo.h, and pngdebug.h, which contain material
|
||||
that previously appeared in the public headers.
|
||||
that previously appeared in the public headers. As of libpng-1.7.0,
|
||||
pngchunk.h is also included, and is used privately by pngrutil.c.
|
||||
|
||||
XIII. Removing unwanted object code
|
||||
|
||||
@@ -239,7 +250,7 @@ libpng are compiled. All the defines end in _SUPPORTED. If you are
|
||||
never going to use a capability, you can change the #define to #undef
|
||||
before recompiling libpng and save yourself code and data space, or
|
||||
you can turn off individual capabilities with defines that begin with
|
||||
PNG_NO_.
|
||||
"PNG_NO_".
|
||||
|
||||
In libpng-1.5.0 and later, the #define's are in pnglibconf.h instead.
|
||||
|
||||
@@ -307,7 +318,7 @@ only png_longjmp_ptr, which must match the C longjmp function.) The new
|
||||
approach is documented in pngconf.h
|
||||
|
||||
Despite these changes, libpng 1.5.0 only supports the native C function
|
||||
calling standard on those platforms tested so far (__cdecl on Microsoft
|
||||
calling standard on those platforms tested so far ("__cdecl" on Microsoft
|
||||
Windows). This is because the support requirements for alternative
|
||||
calling conventions seem to no longer exist. Developers who find it
|
||||
necessary to set PNG_API_RULE to 1 should advise the mailing list
|
||||
@@ -371,7 +382,7 @@ your application is going to be using multiple threads, you should
|
||||
configure libpng with PNG_NO_SETJMP in your pngusr.dfa file, with
|
||||
-DPNG_NO_SETJMP on your compile line, or with
|
||||
|
||||
#undef PNG_SETJMP_SUPPORTED
|
||||
#undef PNG_SETJMP_SUPPORTED
|
||||
|
||||
in your pnglibconf.h or pngusr.h.
|
||||
|
||||
@@ -380,28 +391,25 @@ 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.
|
||||
|
||||
Copyright (c) 1998-2002,2006-2016 Glenn Randers-Pehrson
|
||||
This document is released under the libpng license.
|
||||
For conditions of distribution and use, see the disclaimer
|
||||
and license in png.h.
|
||||
|
||||
34
LICENSE
@@ -10,8 +10,8 @@ this sentence.
|
||||
|
||||
This code is released under the libpng license.
|
||||
|
||||
libpng versions 1.0.7, July 1, 2000, through 1.7.0beta80, May 6, 2016, are
|
||||
Copyright (c) 2000-2002, 2004, 2006-2016 Glenn Randers-Pehrson, are
|
||||
libpng versions 1.0.7, July 1, 2000 through 1.7.0beta90, August 28, 2017 are
|
||||
Copyright (c) 2000-2002, 2004, 2006-2017 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
|
||||
added to the list of Contributing Authors:
|
||||
@@ -32,6 +32,10 @@ and with the following additions to the disclaimer:
|
||||
risk of satisfactory quality, performance, accuracy, and effort is with
|
||||
the user.
|
||||
|
||||
Some files in the "contrib" directory and some configure-generated
|
||||
files that are distributed with libpng have other copyright owners and
|
||||
are released under other open source licenses.
|
||||
|
||||
libpng versions 0.97, January 1998, through 1.0.6, March 20, 2000, are
|
||||
Copyright (c) 1998-2000 Glenn Randers-Pehrson, are derived from
|
||||
libpng-0.96, and are distributed according to the same disclaimer and
|
||||
@@ -55,6 +59,9 @@ Contributing Authors:
|
||||
Greg Roelofs
|
||||
Tom Tanner
|
||||
|
||||
Some files in the "scripts" directory have other copyright owners
|
||||
but are released under this license.
|
||||
|
||||
libpng versions 0.5, May 1995, through 0.88, January 1996, are
|
||||
Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
|
||||
@@ -95,18 +102,29 @@ appreciated.
|
||||
|
||||
END OF COPYRIGHT NOTICE, DISCLAIMER, and LICENSE.
|
||||
|
||||
A "png_get_copyright" function is available, for convenient use in "about"
|
||||
boxes and the like:
|
||||
TRADEMARK:
|
||||
|
||||
printf("%s", png_get_copyright(NULL));
|
||||
The name "libpng" has not been registered by the Copyright owner
|
||||
as a trademark in any jurisdiction. However, because libpng has
|
||||
been distributed and maintained world-wide, continually since 1995,
|
||||
the Copyright owner claims "common-law trademark protection" in any
|
||||
jurisdiction where common-law trademark is recognized.
|
||||
|
||||
Also, the PNG logo (in PNG format, of course) is supplied in the
|
||||
files "pngbar.png" and "pngbar.jpg (88x31) and "pngnow.png" (98x31).
|
||||
OSI CERTIFICATION:
|
||||
|
||||
Libpng is OSI Certified Open Source Software. OSI Certified Open Source is
|
||||
a certification mark of the Open Source Initiative. OSI has not addressed
|
||||
the additional disclaimers inserted at version 1.0.7.
|
||||
|
||||
EXPORT CONTROL:
|
||||
|
||||
The Copyright owner believes that the Export Control Classification
|
||||
Number (ECCN) for libpng is EAR99, which means not subject to export
|
||||
controls or International Traffic in Arms Regulations (ITAR) because
|
||||
it is open source, publicly available software, that does not contain
|
||||
any encryption software. See the EAR, paragraphs 734.3(b)(3) and
|
||||
734.7(b).
|
||||
|
||||
Glenn Randers-Pehrson
|
||||
glennrp at users.sourceforge.net
|
||||
May 6, 2016
|
||||
August 28, 2017
|
||||
|
||||
24
Makefile.am
@@ -1,13 +1,21 @@
|
||||
# Makefile.am:
|
||||
# Source file for Makefile.in (and hence Makefile)
|
||||
# Makefile.am, the source file for Makefile.in (and hence Makefile), is
|
||||
#
|
||||
# Copyright (c) 2004-2016 Glenn Randers-Pehrson
|
||||
# Last changed in libpng 1.7.0 [(PENDING RELEASE)]
|
||||
#
|
||||
# This code is released under the libpng license.
|
||||
# For conditions of distribution and use, see the disclaimer
|
||||
# and license in png.h
|
||||
|
||||
PNGLIB_BASENAME= libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@
|
||||
|
||||
ACLOCAL_AMFLAGS = -I scripts
|
||||
|
||||
# test programs - run on make check, make distcheck
|
||||
check_PROGRAMS= pngtest pngunknown pngstest pngvalid pngimage
|
||||
check_PROGRAMS= pngtest pngunknown pngstest pngvalid pngimage pngcp
|
||||
if HAVE_CLOCK_GETTIME
|
||||
check_PROGRAMS += timepng
|
||||
endif
|
||||
|
||||
# Utilities - installed
|
||||
bin_PROGRAMS= pngfix png-fix-itxt
|
||||
@@ -42,6 +50,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 +239,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 +286,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
|
||||
|
||||
12
README
@@ -1,4 +1,4 @@
|
||||
README for libpng version 1.7.0beta80 - May 6, 2016 (shared library 17.0)
|
||||
README for libpng version 1.7.0beta90 - August 28, 2017 (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.
|
||||
@@ -23,7 +23,7 @@ earlier versions if you are using a shared library. The type of the
|
||||
png_uint_32, which will affect shared-library applications that use
|
||||
this function.
|
||||
|
||||
To avoid problems with changes to the internals of png info_struct,
|
||||
To avoid problems with changes to the internals of the png info_struct,
|
||||
new APIs have been made available in 0.95 to avoid direct application
|
||||
access to info_ptr. These functions are the png_set_<chunk> and
|
||||
png_get_<chunk> functions. These functions should be used when
|
||||
@@ -88,11 +88,11 @@ zlib should be available at the same place that libpng is, or at zlib.net.
|
||||
|
||||
You may also want a copy of the PNG specification. It is available
|
||||
as an RFC, a W3C Recommendation, and an ISO/IEC Standard. You can find
|
||||
these at http://www.libpng.org/pub/png/documents/
|
||||
these at http://www.libpng.org/pub/png/pngdocs.html .
|
||||
|
||||
This code is currently being archived at libpng.sf.net in the
|
||||
[DOWNLOAD] area, and at ftp://ftp.simplesystems.org. If you can't find it
|
||||
in any of those places, e-mail me, and I'll help you find it.
|
||||
This code is currently being archived at libpng.sourceforge.io in the
|
||||
[DOWNLOAD] area, and at ftp://ftp-osl.osuosl.org/pub/libpng/src . If you
|
||||
can't find it in any of those places, e-mail me, and I'll help you find it.
|
||||
|
||||
I am not a lawyer, but I believe that the Export Control Classification
|
||||
Number (ECCN) for libpng is EAR99, which means not subject to export
|
||||
|
||||
7
TODO
@@ -5,13 +5,14 @@ Final bug fixes.
|
||||
Better C++ wrapper/full C++ implementation?
|
||||
Fix problem with C++ and EXTERN "C".
|
||||
cHRM transformation.
|
||||
Remove setjmp/longjmp usage in favor of returning error codes.
|
||||
Remove setjmp/longjmp usage in favor of returning error codes. As a start on
|
||||
this, minimize the use of png_error(), replacing them with
|
||||
png_warning(); return(0); or similar.
|
||||
Palette creation.
|
||||
Add "grayscale->palette" transformation and "palette->grayscale" detection.
|
||||
Improved dithering.
|
||||
Multi-lingual error and warning message support.
|
||||
Complete sRGB transformation (presently it simply uses gamma=0.45455).
|
||||
Make profile checking optional via a png_set_something() call.
|
||||
Man pages for function calls.
|
||||
Better documentation.
|
||||
Better filter selection
|
||||
@@ -23,8 +24,8 @@ Use greater precision when changing to linear gamma for compositing against
|
||||
background and doing rgb-to-gray transformation.
|
||||
Investigate pre-incremented loop counters and other loop constructions.
|
||||
Add interpolated method of handling interlacing.
|
||||
Switch to the simpler zlib (zlib/libpng) license if legally possible.
|
||||
Extend pngvalid.c to validate more of the libpng transformations.
|
||||
Refactor preprocessor conditionals to compile entire statements
|
||||
Quiet compiler warnings (mostly -Wconversion warnings).
|
||||
|
||||
*/
|
||||
|
||||
21
configure.ac
@@ -1,5 +1,13 @@
|
||||
# configure.ac
|
||||
|
||||
# Copyright (c) 2004-2016 Glenn Randers-Pehrson
|
||||
# Last changed in libpng 1.7.0 [(PENDING RELEASE)]
|
||||
|
||||
# This code is released under the libpng license.
|
||||
# For conditions of distribution and use, see the disclaimer
|
||||
# and license in png.h
|
||||
|
||||
|
||||
dnl Process this file with autoconf to produce a configure script.
|
||||
dnl
|
||||
dnl Minor upgrades (compatible ABI): increment the package version
|
||||
@@ -18,7 +26,7 @@ AC_PREREQ([2.68])
|
||||
|
||||
dnl Version number stuff here:
|
||||
|
||||
AC_INIT([libpng],[1.7.0beta80],[png-mng-implement@lists.sourceforge.net])
|
||||
AC_INIT([libpng],[1.7.0beta90],[png-mng-implement@lists.sourceforge.net])
|
||||
AC_CONFIG_MACRO_DIR([scripts])
|
||||
|
||||
# libpng does not follow GNU file name conventions (hence 'foreign')
|
||||
@@ -30,7 +38,7 @@ AC_CONFIG_MACRO_DIR([scripts])
|
||||
# 1.14.1 is required for %reldir% support
|
||||
AM_INIT_AUTOMAKE([1.15 foreign dist-xz color-tests silent-rules subdir-objects])
|
||||
# The following line causes --disable-maintainer-mode to be the default to
|
||||
# configure, this is necessary because libpng distributions cannot rely on the
|
||||
# configure. This is necessary because libpng distributions cannot rely on the
|
||||
# time stamps of the autotools generated files being correct
|
||||
AM_MAINTAINER_MODE
|
||||
|
||||
@@ -40,7 +48,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.0beta80
|
||||
PNGLIB_VERSION=1.7.0beta90
|
||||
PNGLIB_MAJOR=1
|
||||
PNGLIB_MINOR=7
|
||||
PNGLIB_RELEASE=0
|
||||
@@ -136,6 +144,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],
|
||||
@@ -173,7 +186,7 @@ then
|
||||
enable_floating_arithmetic=no])
|
||||
fi
|
||||
|
||||
# Set the relevant defines if required (only if required), this will override
|
||||
# Set the relevant defines if required (only if required). This will override
|
||||
# anything on the command line.
|
||||
if test "$enable_floating_point" != yes
|
||||
then
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
*
|
||||
* Documentation:
|
||||
* http://www.kandroid.org/ndk/docs/CPU-ARM-NEON.html
|
||||
* http://code.google.com/p/android/issues/detail?id=49065
|
||||
* https://code.google.com/p/android/issues/detail?id=49065
|
||||
*
|
||||
* NOTE: this requires that libpng is built against the Android NDK and linked
|
||||
* with an implementation of the Android ARM 'cpu-features' library. The code
|
||||
|
||||
38
contrib/conftest/pngcp.dfa
Normal 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
|
||||
@@ -1,10 +1,12 @@
|
||||
/*- pngtopng
|
||||
*
|
||||
* COPYRIGHT: Written by John Cunningham Bowler, 2011.
|
||||
* COPYRIGHT: Written by John Cunningham Bowler, 2011, 2017.
|
||||
* 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.
|
||||
*
|
||||
* Last changed in libpng 1.6.29 [%RDATE%]
|
||||
*
|
||||
* Read a PNG and write it out in a fixed format, using the 'simplified API'
|
||||
* that was introduced in libpng-1.6.0.
|
||||
*
|
||||
@@ -59,26 +61,27 @@ int main(int argc, const char **argv)
|
||||
else
|
||||
fprintf(stderr, "pngtopng: write %s: %s\n", argv[2],
|
||||
image.message);
|
||||
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "pngtopng: read %s: %s\n", argv[1],
|
||||
image.message);
|
||||
|
||||
/* This is the only place where a 'free' is required; libpng does
|
||||
* the cleanup on error and success, but in this case we couldn't
|
||||
* complete the read because of running out of memory.
|
||||
*/
|
||||
png_image_free(&image);
|
||||
}
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "pngtopng: out of memory: %lu bytes\n",
|
||||
(unsigned long)PNG_IMAGE_SIZE(image));
|
||||
|
||||
/* This is the only place where a 'free' is required; libpng does
|
||||
* the cleanup on error and success, but in this case we couldn't
|
||||
* complete the read because of running out of memory and so libpng
|
||||
* has not got to the point where it can do cleanup.
|
||||
*/
|
||||
png_image_free(&image);
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
|
||||
@@ -55,7 +55,7 @@ mation and links to the latest version of the source code, and Chapters
|
||||
13-15 of the book for detailed discussion of the three programs.
|
||||
|
||||
Greg Roelofs
|
||||
http://pobox.com/~newt/greg_contact.html
|
||||
https://pobox.com/~newt/greg_contact.html
|
||||
16 March 2008
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ BUILD INSTRUCTIONS
|
||||
|
||||
- Prerequisites (in order of compilation):
|
||||
|
||||
- zlib http://zlib.net/
|
||||
- zlib https://zlib.net/
|
||||
- libpng http://www.libpng.org/pub/png/libpng.html
|
||||
- pngbook http://www.libpng.org/pub/png/book/sources.html
|
||||
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
/*-
|
||||
* pngstest.c
|
||||
*
|
||||
* Copyright (c) 2013-2016 John Cunningham Bowler
|
||||
*
|
||||
* Last changed in libpng 1.6.22 [(PENDING RELEASE)]
|
||||
* Last changed in libpng 1.6.31 [July 27, 2017]
|
||||
* Copyright (c) 2013-2017 John Cunningham Bowler
|
||||
*
|
||||
* This code is released under the libpng license.
|
||||
* For conditions of distribution and use, see the disclaimer
|
||||
@@ -26,15 +25,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 +34,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"
|
||||
|
||||
@@ -2611,9 +2610,9 @@ compare_two_images(Image *a, Image *b, int via_linear,
|
||||
const unsigned int b_sample = PNG_IMAGE_SAMPLE_SIZE(formatb);
|
||||
int alpha_added, alpha_removed;
|
||||
int bchannels;
|
||||
int btoa[4];
|
||||
png_uint_32 y;
|
||||
Transform tr;
|
||||
int btoa[4]={0,0,0,0};
|
||||
|
||||
/* This should never happen: */
|
||||
if (width != b->image.width || height != b->image.height)
|
||||
@@ -2746,22 +2745,27 @@ compare_two_images(Image *a, Image *b, int via_linear,
|
||||
*/
|
||||
else if ((a->opts & ACCUMULATE) == 0)
|
||||
{
|
||||
# ifdef __GNUC__
|
||||
# define BYTE_CHARS 20 /* 2^32: GCC sprintf warning */
|
||||
# else
|
||||
# define BYTE_CHARS 3 /* 2^8: real maximum value */
|
||||
# endif
|
||||
/* Check the original image first,
|
||||
* TODO: deal with input images with bad pixel values?
|
||||
*/
|
||||
if (amax >= a->image.colormap_entries)
|
||||
{
|
||||
char pindex[9];
|
||||
sprintf(pindex, "%d[%lu]", amax,
|
||||
(unsigned long)a->image.colormap_entries);
|
||||
char pindex[3+2*BYTE_CHARS];
|
||||
sprintf(pindex, "%d[%u]", amax,
|
||||
(png_byte)/*SAFE*/a->image.colormap_entries);
|
||||
return logerror(a, a->file_name, ": bad pixel index: ", pindex);
|
||||
}
|
||||
|
||||
else if (bmax >= b->image.colormap_entries)
|
||||
{
|
||||
char pindex[9];
|
||||
sprintf(pindex, "%d[%lu]", bmax,
|
||||
(unsigned long)b->image.colormap_entries);
|
||||
char pindex[3+2*BYTE_CHARS];
|
||||
sprintf(pindex, "%d[%u]", bmax,
|
||||
(png_byte)/*SAFE*/b->image.colormap_entries);
|
||||
return logerror(b, b->file_name, ": bad pixel index: ", pindex);
|
||||
}
|
||||
}
|
||||
@@ -2881,10 +2885,13 @@ compare_two_images(Image *a, Image *b, int via_linear,
|
||||
{
|
||||
case 4:
|
||||
if (pua[btoa[3]] != pub[3]) break;
|
||||
/* FALLTHROUGH */
|
||||
case 3:
|
||||
if (pua[btoa[2]] != pub[2]) break;
|
||||
/* FALLTHROUGH */
|
||||
case 2:
|
||||
if (pua[btoa[1]] != pub[1]) break;
|
||||
/* FALLTHROUGH */
|
||||
case 1:
|
||||
if (pua[btoa[0]] != pub[0]) break;
|
||||
if (alpha_added != 4 && pub[alpha_added] != 65535) break;
|
||||
@@ -2900,10 +2907,13 @@ compare_two_images(Image *a, Image *b, int via_linear,
|
||||
{
|
||||
case 4:
|
||||
if (psa[btoa[3]] != psb[3]) break;
|
||||
/* FALLTHROUGH */
|
||||
case 3:
|
||||
if (psa[btoa[2]] != psb[2]) break;
|
||||
/* FALLTHROUGH */
|
||||
case 2:
|
||||
if (psa[btoa[1]] != psb[1]) break;
|
||||
/* FALLTHROUGH */
|
||||
case 1:
|
||||
if (psa[btoa[0]] != psb[0]) break;
|
||||
if (alpha_added != 4 && psb[alpha_added] != 255) break;
|
||||
|
||||
@@ -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.26 [October 20, 2016]
|
||||
* Copyright (c) 2015,2016 Glenn Randers-Pehrson
|
||||
* Written by John Cunningham Bowler
|
||||
*
|
||||
@@ -478,7 +478,7 @@ get_valid(display *d, png_infop info_ptr)
|
||||
png_textp text;
|
||||
png_uint_32 ntext = png_get_text(d->png_ptr, info_ptr, &text, NULL);
|
||||
|
||||
while (ntext-- > 0) switch (text[ntext].compression)
|
||||
while (ntext > 0) switch (text[--ntext].compression)
|
||||
{
|
||||
case -1:
|
||||
flags |= PNG_INFO_tEXt;
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
|
||||
/* pngvalid.c - validate libpng by constructing then reading png files.
|
||||
*
|
||||
* Last changed in libpng 1.6.22 [(PENDING RELEASE)]
|
||||
* Copyright (c) 2014-2016 Glenn Randers-Pehrson
|
||||
* Written by John Cunningham Bowler
|
||||
* Last changed in libpng 1.6.27 [December 29, 2016]
|
||||
* Copyright (c) 2014-2016 John Cunningham Bowler
|
||||
*
|
||||
* This code is released under the libpng license.
|
||||
* For conditions of distribution and use, see the disclaimer
|
||||
@@ -131,6 +130,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 +307,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 +343,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 +352,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 +708,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 +765,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 +781,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 +870,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 +897,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 +915,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 +945,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;
|
||||
@@ -1194,7 +1241,7 @@ store_image_check(const png_store* ps, png_const_structp pp, int iImage)
|
||||
|
||||
image += 2; /* skip image first row markers */
|
||||
|
||||
while (rows-- > 0)
|
||||
for (; rows > 0; --rows)
|
||||
{
|
||||
if (image[-2] != 190 || image[-1] != 239)
|
||||
png_error(pp, "row start overwritten");
|
||||
@@ -1209,32 +1256,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 +1388,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 +1412,6 @@ store_read_buffer_avail(png_store *ps)
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int
|
||||
store_read_buffer_next(png_store *ps)
|
||||
@@ -1331,6 +1463,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 +1706,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 +2103,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 +2122,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 +2964,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 +3003,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 +3013,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 +3054,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 +3071,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 +3137,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 +3705,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 +3715,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 +3723,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;
|
||||
}
|
||||
|
||||
@@ -3638,8 +4010,11 @@ check_interlace_type(int const interlace_type)
|
||||
# define do_own_interlace 1
|
||||
#endif /* WRITE_INTERLACING tests */
|
||||
|
||||
#define CAN_WRITE_INTERLACE\
|
||||
PNG_LIBPNG_VER >= 10700 || defined PNG_WRITE_INTERLACING_SUPPORTED
|
||||
#if PNG_LIBPNG_VER >= 10700 || defined PNG_WRITE_INTERLACING_SUPPORTED
|
||||
# define CAN_WRITE_INTERLACE 1
|
||||
#else
|
||||
# define CAN_WRITE_INTERLACE 0
|
||||
#endif
|
||||
|
||||
/* Do the same thing for read interlacing; this controls whether read tests do
|
||||
* their own de-interlace or use libpng.
|
||||
@@ -7303,7 +7678,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 +8606,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 +8679,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);
|
||||
@@ -11054,23 +11429,36 @@ perform_interlace_macro_validation(void)
|
||||
*/
|
||||
for (v=0;;)
|
||||
{
|
||||
/* The first two tests overflow if the pass row or column is outside
|
||||
* the possible range for a 32-bit result. In fact the values should
|
||||
* never be outside the range for a 31-bit result, but checking for 32
|
||||
* bits here ensures that if an app uses a bogus pass row or column
|
||||
* (just so long as it fits in a 32 bit integer) it won't get a
|
||||
* possibly dangerous overflow.
|
||||
*/
|
||||
/* First the base 0 stuff: */
|
||||
m = PNG_ROW_FROM_PASS_ROW(v, pass);
|
||||
f = png_row_from_pass_row(v, pass);
|
||||
if (m != f)
|
||||
if (v < png_pass_rows(0xFFFFFFFFU, pass))
|
||||
{
|
||||
fprintf(stderr, "PNG_ROW_FROM_PASS_ROW(%u, %d) = %u != %x\n",
|
||||
v, pass, m, f);
|
||||
exit(99);
|
||||
m = PNG_ROW_FROM_PASS_ROW(v, pass);
|
||||
f = png_row_from_pass_row(v, pass);
|
||||
if (m != f)
|
||||
{
|
||||
fprintf(stderr, "PNG_ROW_FROM_PASS_ROW(%u, %d) = %u != %x\n",
|
||||
v, pass, m, f);
|
||||
exit(99);
|
||||
}
|
||||
}
|
||||
|
||||
m = PNG_COL_FROM_PASS_COL(v, pass);
|
||||
f = png_col_from_pass_col(v, pass);
|
||||
if (m != f)
|
||||
if (v < png_pass_cols(0xFFFFFFFFU, pass))
|
||||
{
|
||||
fprintf(stderr, "PNG_COL_FROM_PASS_COL(%u, %d) = %u != %x\n",
|
||||
v, pass, m, f);
|
||||
exit(99);
|
||||
m = PNG_COL_FROM_PASS_COL(v, pass);
|
||||
f = png_col_from_pass_col(v, pass);
|
||||
if (m != f)
|
||||
{
|
||||
fprintf(stderr, "PNG_COL_FROM_PASS_COL(%u, %d) = %u != %x\n",
|
||||
v, pass, m, f);
|
||||
exit(99);
|
||||
}
|
||||
}
|
||||
|
||||
m = PNG_ROW_IN_INTERLACE_PASS(v, pass);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
*
|
||||
* Copyright (c) 2013,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
|
||||
@@ -44,8 +44,20 @@
|
||||
# define voidcast(type, value) (value)
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#if ((defined(PNG_SEQUENTIAL_READ_SUPPORTED)) && defined(PNG_STDIO_SUPPORTED)\
|
||||
&& defined(PNG_EASY_ACCESS_SUPPORTED) && defined(PNG_INFO_IMAGE_SUPPORTED))
|
||||
/* '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
|
||||
{
|
||||
FILE *input;
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
/*
|
||||
* png2pnm.c --- conversion from PNG-file to PGM/PPM-file
|
||||
* copyright (C) 1999 by Willem van Schaik <willem@schaik.com>
|
||||
* copyright (C) 1999,2017 by Willem van Schaik <willem at schaik.com>
|
||||
*
|
||||
* version 1.0 - 1999.10.15 - First version.
|
||||
* 1.1 - 2017.04.22 - Add buffer-size check (Glenn Randers-Pehrson)
|
||||
* 1.2 - 2017.08.24 - Fix potential overflow in buffer-size check
|
||||
* (Glenn Randers-Pehrson)
|
||||
* 1.3 - 2017.08.28 - Add PNGMINUS_UNUSED (Christian Hesse)
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software and
|
||||
* its documentation for any purpose and without fee is hereby granted,
|
||||
@@ -41,6 +45,7 @@
|
||||
#define PNG_DEBUG 0
|
||||
#endif
|
||||
|
||||
|
||||
#include "png.h"
|
||||
|
||||
/* Define png_jmpbuf() in case we are using a pre-1.0.6 version of libpng */
|
||||
@@ -48,11 +53,20 @@
|
||||
# define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf)
|
||||
#endif
|
||||
|
||||
#ifndef PNGMINUS_UNUSED
|
||||
/* Unused formal parameter warnings are silenced using the following macro
|
||||
* which is expected to have no bad effects on performance (optimizing
|
||||
* compilers will probably remove it entirely).
|
||||
*/
|
||||
# define PNGMINUS_UNUSED(param) (void)param
|
||||
#endif
|
||||
|
||||
/* function prototypes */
|
||||
|
||||
int main (int argc, char *argv[]);
|
||||
void usage ();
|
||||
BOOL png2pnm (FILE *png_file, FILE *pnm_file, FILE *alpha_file, BOOL raw, BOOL alpha);
|
||||
BOOL png2pnm (FILE *png_file, FILE *pnm_file, FILE *alpha_file, BOOL raw,
|
||||
BOOL alpha);
|
||||
|
||||
/*
|
||||
* main
|
||||
@@ -85,7 +99,8 @@ int main(int argc, char *argv[])
|
||||
if ((fp_al = fopen (argv[argi], "wb")) == NULL)
|
||||
{
|
||||
fprintf (stderr, "PNM2PNG\n");
|
||||
fprintf (stderr, "Error: can not create alpha-channel file %s\n", argv[argi]);
|
||||
fprintf (stderr, "Error: can not create alpha-channel file %s\n",
|
||||
argv[argi]);
|
||||
exit (1);
|
||||
}
|
||||
break;
|
||||
@@ -176,9 +191,11 @@ void usage()
|
||||
fprintf (stderr, "Usage: png2pnm [options] <file>.png [<file>.pnm]\n");
|
||||
fprintf (stderr, " or: ... | png2pnm [options]\n");
|
||||
fprintf (stderr, "Options:\n");
|
||||
fprintf (stderr, " -r[aw] write pnm-file in binary format (P4/P5/P6) (default)\n");
|
||||
fprintf (stderr,
|
||||
" -r[aw] write pnm-file in binary format (P4/P5/P6) (default)\n");
|
||||
fprintf (stderr, " -n[oraw] write pnm-file in ascii format (P1/P2/P3)\n");
|
||||
fprintf (stderr, " -a[lpha] <file>.pgm write PNG alpha channel as pgm-file\n");
|
||||
fprintf (stderr,
|
||||
" -a[lpha] <file>.pgm write PNG alpha channel as pgm-file\n");
|
||||
fprintf (stderr, " -h | -? print this help-information\n");
|
||||
}
|
||||
|
||||
@@ -186,7 +203,8 @@ void usage()
|
||||
* png2pnm
|
||||
*/
|
||||
|
||||
BOOL png2pnm (FILE *png_file, FILE *pnm_file, FILE *alpha_file, BOOL raw, BOOL alpha)
|
||||
BOOL png2pnm (FILE *png_file, FILE *pnm_file, FILE *alpha_file,
|
||||
volatile BOOL raw, BOOL alpha)
|
||||
{
|
||||
png_struct *png_ptr = NULL;
|
||||
png_info *info_ptr = NULL;
|
||||
@@ -218,7 +236,7 @@ BOOL png2pnm (FILE *png_file, FILE *pnm_file, FILE *alpha_file, BOOL raw, BOOL a
|
||||
|
||||
/* create png and info structures */
|
||||
|
||||
png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING,
|
||||
png_ptr = png_create_read_struct (png_get_libpng_ver(NULL),
|
||||
NULL, NULL, NULL);
|
||||
if (!png_ptr)
|
||||
return FALSE; /* out of memory */
|
||||
@@ -261,7 +279,7 @@ BOOL png2pnm (FILE *png_file, FILE *pnm_file, FILE *alpha_file, BOOL raw, BOOL a
|
||||
png_set_expand (png_ptr);
|
||||
|
||||
#ifdef NJET
|
||||
/* downgrade 16-bit images to 8 bit */
|
||||
/* downgrade 16-bit images to 8-bit */
|
||||
if (bit_depth == 16)
|
||||
png_set_strip_16 (png_ptr);
|
||||
/* transform grayscale images into full-color */
|
||||
@@ -315,12 +333,21 @@ BOOL png2pnm (FILE *png_file, FILE *pnm_file, FILE *alpha_file, BOOL raw, BOOL a
|
||||
/* row_bytes is the width x number of channels x (bit-depth / 8) */
|
||||
row_bytes = png_get_rowbytes (png_ptr, info_ptr);
|
||||
|
||||
if ((png_pixels = (png_byte *) malloc (row_bytes * height * sizeof (png_byte))) == NULL) {
|
||||
if ((row_bytes == 0 || (size_t)height > ((size_t)(-1))/(size_t)row_bytes))
|
||||
{
|
||||
/* too big */
|
||||
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
|
||||
return FALSE;
|
||||
}
|
||||
if ((png_pixels = (png_byte *)
|
||||
malloc ((size_t)row_bytes * (size_t)height * sizeof (png_byte))) == NULL)
|
||||
{
|
||||
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ((row_pointers = (png_byte **) malloc (height * sizeof (png_bytep))) == NULL)
|
||||
if ((row_pointers = (png_byte **)
|
||||
malloc ((size_t)height * sizeof (png_bytep))) == NULL)
|
||||
{
|
||||
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
|
||||
free (png_pixels);
|
||||
@@ -329,7 +356,7 @@ BOOL png2pnm (FILE *png_file, FILE *pnm_file, FILE *alpha_file, BOOL raw, BOOL a
|
||||
}
|
||||
|
||||
/* set the individual row_pointers to point at the correct offsets */
|
||||
for (i = 0; i < (height); i++)
|
||||
for (i = 0; i < ((int) height); i++)
|
||||
row_pointers[i] = png_pixels + i * row_bytes;
|
||||
|
||||
/* now we can go ahead and just read the whole image */
|
||||
@@ -372,9 +399,9 @@ BOOL png2pnm (FILE *png_file, FILE *pnm_file, FILE *alpha_file, BOOL raw, BOOL a
|
||||
/* write data to PNM file */
|
||||
pix_ptr = png_pixels;
|
||||
|
||||
for (row = 0; row < height; row++)
|
||||
for (row = 0; row < (int) height; row++)
|
||||
{
|
||||
for (col = 0; col < width; col++)
|
||||
for (col = 0; col < (int) width; col++)
|
||||
{
|
||||
for (i = 0; i < (channels - alpha_present); i++)
|
||||
{
|
||||
@@ -401,7 +428,8 @@ BOOL png2pnm (FILE *png_file, FILE *pnm_file, FILE *alpha_file, BOOL raw, BOOL a
|
||||
if (raw)
|
||||
fputc ((int) *pix_ptr++ , alpha_file);
|
||||
else
|
||||
if (bit_depth == 16){
|
||||
if (bit_depth == 16)
|
||||
{
|
||||
dep_16 = (long) *pix_ptr++;
|
||||
fprintf (alpha_file, "%ld ", (dep_16 << 8) + (long) *pix_ptr++);
|
||||
}
|
||||
@@ -425,6 +453,7 @@ BOOL png2pnm (FILE *png_file, FILE *pnm_file, FILE *alpha_file, BOOL raw, BOOL a
|
||||
if (png_pixels != (unsigned char*) NULL)
|
||||
free (png_pixels);
|
||||
|
||||
PNGMINUS_UNUSED(raw); /* to quiet a Coverity defect */
|
||||
return TRUE;
|
||||
|
||||
} /* end of source */
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
/*
|
||||
* pnm2png.c --- conversion from PBM/PGM/PPM-file to PNG-file
|
||||
* copyright (C) 1999,2015 by Willem van Schaik <willem@schaik.com>
|
||||
* copyright (C) 1999,2015,2017 by Willem van Schaik <willem at schaik.com>
|
||||
*
|
||||
* version 1.0 - 1999.10.15 - First version.
|
||||
* version 1.1 - 2015.07.29 - Fixed leaks (Glenn Randers-Pehrson)
|
||||
* version 1.2 - 2017.04.22 - Add buffer-size check
|
||||
* 1.3 - 2017.08.24 - Fix potential overflow in buffer-size check
|
||||
* (Glenn Randers-Pehrson)
|
||||
* 1.4 - 2017.08.28 - Add PNGMINUS_UNUSED (Christian Hesse)
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software and
|
||||
* its documentation for any purpose and without fee is hereby granted,
|
||||
@@ -47,6 +51,15 @@
|
||||
# define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf)
|
||||
#endif
|
||||
|
||||
#ifndef PNGMINUS_UNUSED
|
||||
/* Unused formal parameter warnings are silenced using the following macro
|
||||
* which is expected to have no bad effects on performance (optimizing
|
||||
* compilers will probably remove it entirely).
|
||||
*/
|
||||
# define PNGMINUS_UNUSED(param) (void)param
|
||||
#endif
|
||||
|
||||
|
||||
/* function prototypes */
|
||||
|
||||
int main (int argc, char *argv[]);
|
||||
@@ -370,11 +383,16 @@ BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace,
|
||||
row_bytes = (width * channels * bit_depth + 7) / 8;
|
||||
else
|
||||
#endif
|
||||
/* row_bytes is the width x number of channels x (bit-depth / 8) */
|
||||
/* row_bytes is the width x number of channels x (bit-depth / 8) */
|
||||
row_bytes = width * channels * ((bit_depth <= 8) ? 1 : 2);
|
||||
|
||||
if ((row_bytes == 0 || (size_t)height > ((size_t)(-1))/(size_t)row_bytes))
|
||||
{
|
||||
/* too big */
|
||||
return FALSE;
|
||||
}
|
||||
if ((png_pixels = (png_byte *)
|
||||
malloc (row_bytes * height * sizeof (png_byte))) == NULL)
|
||||
malloc ((size_t)row_bytes * (size_t)height * sizeof (png_byte))) == NULL)
|
||||
return FALSE;
|
||||
|
||||
/* read data from PNM file */
|
||||
@@ -383,7 +401,8 @@ BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace,
|
||||
for (row = 0; row < (int) height; row++)
|
||||
{
|
||||
#if defined(PNG_WRITE_INVERT_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
|
||||
if (packed_bitmap) {
|
||||
if (packed_bitmap)
|
||||
{
|
||||
for (i = 0; i < (int) row_bytes; i++)
|
||||
/* png supports this format natively so no conversion is needed */
|
||||
*pix_ptr++ = get_data (pnm_file, 8);
|
||||
@@ -504,6 +523,8 @@ BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace,
|
||||
if (png_pixels != (unsigned char*) NULL)
|
||||
free (png_pixels);
|
||||
|
||||
PNGMINUS_UNUSED(raw); /* Quiet a Coverity defect */
|
||||
|
||||
return TRUE;
|
||||
} /* end of pnm2png */
|
||||
|
||||
@@ -520,7 +541,8 @@ void get_token(FILE *pnm_file, char *token)
|
||||
do
|
||||
{
|
||||
ret = fgetc(pnm_file);
|
||||
if (ret == '#') {
|
||||
if (ret == '#')
|
||||
{
|
||||
/* the rest of this line is a comment */
|
||||
do
|
||||
{
|
||||
|
||||
@@ -23,4 +23,5 @@ ORIGINAL AUTHORS
|
||||
of the people below claim any rights with regard to the contents of this
|
||||
directory.
|
||||
|
||||
John Bowler <jbowler@acm.org>
|
||||
John Bowler <jbowler at acm.org>
|
||||
Glenn Randers-Pehrson <glennrp at users.sourceforge.net>
|
||||
|
||||
@@ -1,4 +1,11 @@
|
||||
#!/bin/sh
|
||||
|
||||
# chkfmt
|
||||
#
|
||||
# COPYRIGHT: Written by John Cunningham Bowler, 2010.
|
||||
# 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.
|
||||
#
|
||||
# Check the format of the source files in the current directory - checks for a
|
||||
# line length of 80 characters max and no tab characters.
|
||||
|
||||
@@ -1,34 +1,46 @@
|
||||
/* pngcp.c
|
||||
*
|
||||
* COPYRIGHT: Written by John Cunningham Bowler, 2016.
|
||||
* 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.
|
||||
* Copyright (c) 2016 John Cunningham Bowler
|
||||
*
|
||||
* Last changed in libpng 1.7.0 [(PENDING RELEASE)]
|
||||
* Last changed in libpng 1.6.24 [August 4, 2016]
|
||||
*
|
||||
* This is a minimal example of copying a PNG without changes using the
|
||||
* png_read_png and png_write_png interfaces.
|
||||
* This code is released under the libpng license.
|
||||
* For conditions of distribution and use, see the disclaimer
|
||||
* and license in png.h
|
||||
*
|
||||
* This is an example of copying a PNG without changes using the png_read_png
|
||||
* and png_write_png interfaces. A considerable number of options are provided
|
||||
* to manipulate the compression of the PNG data and other compressed chunks.
|
||||
*
|
||||
* For a more extensive example that uses the transforms see
|
||||
* contrib/libtests/pngimage.c in the libpng distribution.
|
||||
*/
|
||||
#define _POSIX_SOURCE 1
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <limits.h>
|
||||
#include <assert.h>
|
||||
#include "pnglibconf.h" /* To find how libpng was configured. */
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#ifdef PNG_PNGCP_TIMING_SUPPORTED
|
||||
/* WARNING:
|
||||
*
|
||||
* This test is here to allow POSIX.1b extensions to be used if enabled in
|
||||
* the compile; specifically the code requires_POSIX_C_SOURCE support of
|
||||
* 199309L or later to enable clock_gettime use.
|
||||
*
|
||||
* IF this causes problems THEN compile with a strict ANSI C compiler and let
|
||||
* this code turn on the POSIX features that it minimally requires.
|
||||
*
|
||||
* IF this does not work there is probably a bug in your ANSI C compiler or
|
||||
* your POSIX implementation.
|
||||
*/
|
||||
# define _POSIX_C_SOURCE 199309L
|
||||
#else /* No timing support required */
|
||||
# define _POSIX_SOURCE 1
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_CONFIG_H) && !defined(PNG_NO_CONFIG_H)
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/* Define the following to use this test against your installed libpng, rather
|
||||
* than the one being built here:
|
||||
*/
|
||||
@@ -38,22 +50,6 @@
|
||||
# include "../../png.h"
|
||||
#endif
|
||||
|
||||
#include <zlib.h>
|
||||
|
||||
#ifndef PNG_SETJMP_SUPPORTED
|
||||
# include <setjmp.h> /* because png.h did *not* include this */
|
||||
#endif
|
||||
|
||||
#ifdef __GNUC__
|
||||
/* Many versions of GCC erroneously report that local variables unmodified
|
||||
* within the scope of a setjmp may be clobbered. This hacks round the
|
||||
* problem (sometimes) without harming other compilers.
|
||||
*/
|
||||
# define gv volatile
|
||||
#else
|
||||
# define gv
|
||||
#endif
|
||||
|
||||
#if PNG_LIBPNG_VER < 10700
|
||||
/* READ_PNG and WRITE_PNG were not defined, so: */
|
||||
# ifdef PNG_INFO_IMAGE_SUPPORTED
|
||||
@@ -67,6 +63,56 @@
|
||||
#endif /* pre 1.7.0 */
|
||||
|
||||
#if (defined(PNG_READ_PNG_SUPPORTED)) && (defined(PNG_WRITE_PNG_SUPPORTED))
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <zlib.h>
|
||||
|
||||
#ifndef PNG_SETJMP_SUPPORTED
|
||||
# include <setjmp.h> /* because png.h did *not* include this */
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
# define voidcast(type, value) static_cast<type>(value)
|
||||
#else
|
||||
# define voidcast(type, value) (value)
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#ifdef __GNUC__
|
||||
/* Many versions of GCC erroneously report that local variables unmodified
|
||||
* within the scope of a setjmp may be clobbered. This hacks round the
|
||||
* problem (sometimes) without harming other compilers.
|
||||
*/
|
||||
# define gv volatile
|
||||
#else
|
||||
# define gv
|
||||
#endif
|
||||
|
||||
/* '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.
|
||||
*/
|
||||
#ifdef PNG_PNGCP_TIMING_SUPPORTED
|
||||
# include <time.h> /* clock_gettime and associated definitions */
|
||||
# ifndef CLOCK_PROCESS_CPUTIME_ID
|
||||
/* Prevent inclusion of the spurious code: */
|
||||
# undef PNG_PNGCP_TIMING_SUPPORTED
|
||||
# endif
|
||||
#endif /* PNGCP_TIMING */
|
||||
|
||||
/* So if the timing feature has been activated: */
|
||||
|
||||
/* This structure is used to control the test of a single file. */
|
||||
typedef enum
|
||||
{
|
||||
@@ -92,6 +138,12 @@ typedef enum
|
||||
#define SIZES 0x080 /* Report input and output sizes */
|
||||
#define SEARCH 0x100 /* Search IDAT compression options */
|
||||
#define NOWRITE 0x200 /* Do not write an output file */
|
||||
#ifdef PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED
|
||||
# define IGNORE_INDEX 0x400 /* Ignore out of range palette indices (BAD!) */
|
||||
# ifdef PNG_GET_PALETTE_MAX_SUPPORTED
|
||||
# define FIX_INDEX 0x800 /* 'Fix' out of range palette indices (OK) */
|
||||
# endif /* GET_PALETTE_MAX */
|
||||
#endif /* CHECK_FOR_INVALID_INDEX */
|
||||
#define OPTION 0x80000000 /* Used for handling options */
|
||||
#define LIST 0x80000001 /* Used for handling options */
|
||||
|
||||
@@ -107,18 +159,36 @@ static const char range_lo[] = "low";
|
||||
static const char range_hi[] = "high";
|
||||
static const char all[] = "all";
|
||||
#define RANGE(lo,hi) { range_lo, lo }, { range_hi, hi }
|
||||
static const struct value_list
|
||||
typedef struct value_list
|
||||
{
|
||||
const char *name; /* the command line name of the value */
|
||||
int value; /* the actual value to use */
|
||||
}
|
||||
} value_list;
|
||||
|
||||
static const value_list
|
||||
#ifdef PNG_SW_COMPRESS_png_level
|
||||
vl_compression[] =
|
||||
{
|
||||
/* Overall compression control. The order controls the search order for
|
||||
* 'all'. Since the search is for the smallest the order used is low memory
|
||||
* then high speed.
|
||||
*/
|
||||
{ "low-memory", PNG_COMPRESSION_LOW_MEMORY },
|
||||
{ "high-speed", PNG_COMPRESSION_HIGH_SPEED },
|
||||
{ "high-read-speed", PNG_COMPRESSION_HIGH_READ_SPEED },
|
||||
{ "low", PNG_COMPRESSION_LOW },
|
||||
{ "medium", PNG_COMPRESSION_MEDIUM },
|
||||
{ "old", PNG_COMPRESSION_COMPAT },
|
||||
{ "high", PNG_COMPRESSION_HIGH },
|
||||
{ all, 0 }
|
||||
},
|
||||
#endif /* SW_COMPRESS_png_level */
|
||||
|
||||
#if defined(PNG_WRITE_CUSTOMIZE_COMPRESSION_SUPPORTED) ||\
|
||||
defined(PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED)
|
||||
vl_strategy[] =
|
||||
{
|
||||
/* This controls the order of search and also the default (which is RLE
|
||||
* compression):
|
||||
*/
|
||||
/* This controls the order of search. */
|
||||
{ "huffman", Z_HUFFMAN_ONLY },
|
||||
{ "RLE", Z_RLE },
|
||||
{ "fixed", Z_FIXED }, /* the remainder do window searchs */
|
||||
@@ -170,35 +240,33 @@ vl_filter[] =
|
||||
{ "paeth", PNG_FILTER_PAETH }
|
||||
},
|
||||
#endif /* WRITE_FILTER */
|
||||
#define SELECT_HEURISTICALLY 1
|
||||
#define SELECT_METHODICALLY 2
|
||||
#if defined(PNG_SELECT_FILTER_HEURISTICALLY_SUPPORTED) ||\
|
||||
defined(PNG_SELECT_FILTER_METHODICALLY_SUPPORTED)
|
||||
vl_select[] =
|
||||
#ifdef PNG_PNGCP_TIMING_SUPPORTED
|
||||
# define PNGCP_TIME_READ 1
|
||||
# define PNGCP_TIME_WRITE 2
|
||||
vl_time[] =
|
||||
{
|
||||
{ all, SELECT_HEURISTICALLY|SELECT_METHODICALLY },
|
||||
{ "off", 0 },
|
||||
#ifdef PNG_SELECT_FILTER_HEURISTICALLY_SUPPORTED
|
||||
{ "heuristically", SELECT_HEURISTICALLY },
|
||||
#endif /* SELECT_FILTER_HEURISTICALLY */
|
||||
#ifdef PNG_SELECT_FILTER_METHODICALLY_SUPPORTED
|
||||
{ "methodically", SELECT_METHODICALLY },
|
||||
#endif /* SELECT_FILTER_METHODICALLY */
|
||||
{ "both", SELECT_HEURISTICALLY|SELECT_METHODICALLY }
|
||||
{ "both", PNGCP_TIME_READ+PNGCP_TIME_WRITE },
|
||||
{ "off", 0 },
|
||||
{ "read", PNGCP_TIME_READ },
|
||||
{ "write", PNGCP_TIME_WRITE }
|
||||
},
|
||||
#endif /* SELECT_FILTER_HEURISTICALLY || SELECT_FILTER_METHODICALLY */
|
||||
vl_IDAT_size[] = /* for png_set_compression_buffer_size */
|
||||
#endif /* PNGCP_TIMING */
|
||||
vl_IDAT_size[] = /* for png_set_IDAT_size */
|
||||
{
|
||||
{ "default", 0x7FFFFFFF },
|
||||
{ "minimal", 1 },
|
||||
RANGE(1, 0x7FFFFFFF)
|
||||
},
|
||||
#ifndef PNG_SW_IDAT_size
|
||||
/* Pre 1.7 API: */
|
||||
# define png_set_IDAT_size(p,v) png_set_compression_buffer_size(p, v)
|
||||
#endif /* !SW_IDAT_size */
|
||||
#define SL 8 /* stack limit in display, below */
|
||||
vl_log_depth[] = { { "on", 1 }, { "off", 0 }, RANGE(0, SL) },
|
||||
vl_on_off[] = { { "on", 1 }, { "off", 2 } };
|
||||
vl_on_off[] = { { "on", 1 }, { "off", 0 } };
|
||||
|
||||
#ifdef PNG_WRITE_CUSTOMIZE_COMPRESSION_SUPPORTED
|
||||
static struct value_list
|
||||
static value_list
|
||||
vl_windowBits_IDAT[] =
|
||||
{
|
||||
{ "default", MAX_WBITS },
|
||||
@@ -208,14 +276,16 @@ vl_windowBits_IDAT[] =
|
||||
};
|
||||
#endif /* IDAT compression */
|
||||
|
||||
static const struct option
|
||||
typedef struct option
|
||||
{
|
||||
const char *name; /* name of the option */
|
||||
png_uint_32 opt; /* an option, or OPTION or LIST */
|
||||
png_byte search; /* Search on --search */
|
||||
png_byte value_count; /* length of the list of values: */
|
||||
const struct value_list *values; /* values for OPTION or LIST */
|
||||
} options[] =
|
||||
const char *name; /* name of the option */
|
||||
png_uint_32 opt; /* an option, or OPTION or LIST */
|
||||
png_byte search; /* Search on --search */
|
||||
png_byte value_count; /* length of the list of values: */
|
||||
const value_list *values; /* values for OPTION or LIST */
|
||||
} option;
|
||||
|
||||
static const option options[] =
|
||||
{
|
||||
/* struct display options, these are set when the command line is read */
|
||||
# define S(n,v) { #n, v, 0, 2, vl_on_off },
|
||||
@@ -229,19 +299,32 @@ static const struct option
|
||||
S(sizes, SIZES)
|
||||
S(search, SEARCH)
|
||||
S(nowrite, NOWRITE)
|
||||
# ifdef IGNORE_INDEX
|
||||
S(ignore-palette-index, IGNORE_INDEX)
|
||||
# endif /* IGNORE_INDEX */
|
||||
# ifdef FIX_INDEX
|
||||
S(fix-palette-index, FIX_INDEX)
|
||||
# endif /* FIX_INDEX */
|
||||
# undef S
|
||||
|
||||
/* OPTION settings, these and LIST settings are read on demand */
|
||||
# define VLNAME(name) vl_ ## name
|
||||
# define VLSIZE(name) ((sizeof VLNAME(name))/(sizeof VLNAME(name)[0]))
|
||||
# define VLSIZE(name) voidcast(png_byte,\
|
||||
(sizeof VLNAME(name))/(sizeof VLNAME(name)[0]))
|
||||
# define VL(oname, name, type, search)\
|
||||
{ oname, type, search, VLSIZE(name), VLNAME(name) },
|
||||
# define VLO(oname, name, search) VL(oname, name, OPTION, search)
|
||||
|
||||
# ifdef PNG_WRITE_CUSTOMIZE_COMPRESSION_SUPPORTED
|
||||
# define VLCIDAT(name) VLO(#name, name, 1/*search*/)
|
||||
# ifdef PNG_SW_COMPRESS_level
|
||||
# define VLCiCCP(name) VLO("ICC-profile-" #name, name, 0/*search*/)
|
||||
# else
|
||||
# define VLCiCCP(name)
|
||||
# endif
|
||||
# else
|
||||
# define VLCIDAT(name)
|
||||
# define VLCiCCP(name)
|
||||
# endif /* WRITE_CUSTOMIZE_COMPRESSION */
|
||||
|
||||
# ifdef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED
|
||||
@@ -250,10 +333,21 @@ static const struct option
|
||||
# define VLCzTXt(name)
|
||||
# endif /* WRITE_CUSTOMIZE_ZTXT_COMPRESSION */
|
||||
|
||||
# define VLC(name) VLCIDAT(name) VLCzTXt(name)
|
||||
# define VLC(name) VLCIDAT(name) VLCiCCP(name) VLCzTXt(name)
|
||||
|
||||
# ifdef PNG_SW_COMPRESS_png_level
|
||||
/* The libpng compression level isn't searched beause it justs sets the
|
||||
* other things that are searched!
|
||||
*/
|
||||
VLO("compression", compression, 0)
|
||||
VLO("text-compression", compression, 0)
|
||||
VLO("ICC-profile-compression", compression, 0)
|
||||
# endif /* SW_COMPRESS_png_level */
|
||||
VLC(strategy)
|
||||
VLO("windowBits", windowBits_IDAT, 1)
|
||||
# ifdef PNG_SW_COMPRESS_windowBits
|
||||
VLO("ICC-profile-windowBits", windowBits_text/*sic*/, 0)
|
||||
# endif
|
||||
VLO("text-windowBits", windowBits_text, 0)
|
||||
VLC(level)
|
||||
VLC(memLevel)
|
||||
@@ -264,18 +358,21 @@ static const struct option
|
||||
|
||||
/* LIST settings */
|
||||
# define VLL(name, search) VL(#name, name, LIST, search)
|
||||
#if defined(PNG_SELECT_FILTER_HEURISTICALLY_SUPPORTED) ||\
|
||||
defined(PNG_SELECT_FILTER_METHODICALLY_SUPPORTED)
|
||||
VLL(select, 1)
|
||||
#endif /* SELECT_FILTER_HEURISTICALLY || SELECT_FILTER_METHODICALLY */
|
||||
#ifdef PNG_WRITE_FILTER_SUPPORTED
|
||||
VLL(filter, 0)
|
||||
#endif /* WRITE_FILTER */
|
||||
#ifdef PNG_PNGCP_TIMING_SUPPORTED
|
||||
VLL(time, 0)
|
||||
#endif /* PNGCP_TIMING */
|
||||
# undef VLL
|
||||
# undef VL
|
||||
};
|
||||
|
||||
#define opt_count ((sizeof options)/(sizeof options[0]))
|
||||
#ifdef __cplusplus
|
||||
static const size_t option_count((sizeof options)/(sizeof options[0]));
|
||||
#else /* !__cplusplus */
|
||||
# define option_count ((sizeof options)/(sizeof options[0]))
|
||||
#endif /* !__cplusplus */
|
||||
|
||||
static const char *
|
||||
cts(int ct)
|
||||
@@ -309,12 +406,19 @@ struct display
|
||||
png_alloc_size_t read_size;
|
||||
png_structp read_pp;
|
||||
png_infop ip;
|
||||
# if PNG_LIBPNG_VER < 10700
|
||||
# if PNG_LIBPNG_VER < 10700 && defined PNG_TEXT_SUPPORTED
|
||||
png_textp text_ptr; /* stash of text chunks */
|
||||
int num_text;
|
||||
int text_stashed;
|
||||
# endif /* pre 1.7 */
|
||||
|
||||
# ifdef PNG_PNGCP_TIMING_SUPPORTED
|
||||
struct timespec read_time;
|
||||
struct timespec read_time_total;
|
||||
struct timespec write_time;
|
||||
struct timespec write_time_total;
|
||||
# endif /* PNGCP_TIMING */
|
||||
|
||||
/* Used to write a new image (the original info_ptr is used) */
|
||||
# define MAX_SIZE ((png_alloc_size_t)(-1))
|
||||
png_alloc_size_t write_size;
|
||||
@@ -331,12 +435,12 @@ struct display
|
||||
int min_windowBits; /* The windowBits range is 8..8 */
|
||||
|
||||
/* Options handling */
|
||||
png_uint_32 results; /* A mask of errors seen */
|
||||
png_uint_32 options; /* See display_log below */
|
||||
png_byte entry[opt_count]; /* The selected entry+1 of an option that
|
||||
* appears on the command line, or 0 if
|
||||
* it was not given. */
|
||||
int value[opt_count]; /* Corresponding value */
|
||||
png_uint_32 results; /* A mask of errors seen */
|
||||
png_uint_32 options; /* See display_log below */
|
||||
png_byte entry[option_count]; /* The selected entry+1 of an option
|
||||
* that appears on the command line, or
|
||||
* 0 if it was not given. */
|
||||
int value[option_count]; /* Corresponding value */
|
||||
|
||||
/* Compression exhaustive testing */
|
||||
/* Temporary variables used only while testing a single collection of
|
||||
@@ -371,7 +475,7 @@ struct display
|
||||
char curr[32*SL]; /* current options being tested */
|
||||
char best[32*SL]; /* best options */
|
||||
|
||||
char namebuf[FILENAME_MAX+1]; /* output file name */
|
||||
char namebuf[FILENAME_MAX]; /* output file name */
|
||||
};
|
||||
|
||||
static void
|
||||
@@ -391,7 +495,7 @@ display_init(struct display *dp)
|
||||
dp->ip = NULL;
|
||||
dp->write_pp = NULL;
|
||||
dp->min_windowBits = -1; /* this is an OPTIND, so -1 won't match anything */
|
||||
# if PNG_LIBPNG_VER < 10700
|
||||
# if PNG_LIBPNG_VER < 10700 && defined PNG_TEXT_SUPPORTED
|
||||
dp->text_ptr = NULL;
|
||||
dp->num_text = 0;
|
||||
dp->text_stashed = 0;
|
||||
@@ -433,7 +537,7 @@ display_clean(struct display *dp)
|
||||
display_clean_write(dp);
|
||||
dp->output_file = NULL;
|
||||
|
||||
# if PNG_LIBPNG_VER < 10700
|
||||
# if PNG_LIBPNG_VER < 10700 && defined PNG_TEXT_SUPPORTED
|
||||
/* This is actually created and used by the write code, but only
|
||||
* once; it has to be retained for subsequent writes of the same file.
|
||||
*/
|
||||
@@ -534,7 +638,7 @@ display_log(struct display *dp, error_level level, const char *fmt, ...)
|
||||
}
|
||||
}
|
||||
|
||||
#if PNG_LIBPNG_VER < 10700
|
||||
#if PNG_LIBPNG_VER < 10700 && defined PNG_TEXT_SUPPORTED
|
||||
static void
|
||||
text_stash(struct display *dp)
|
||||
{
|
||||
@@ -562,7 +666,7 @@ text_stash(struct display *dp)
|
||||
|
||||
if (dp->num_text > 0)
|
||||
{
|
||||
dp->text_ptr = malloc(dp->num_text * sizeof *chunks);
|
||||
dp->text_ptr = voidcast(png_textp, malloc(dp->num_text * sizeof *chunks));
|
||||
|
||||
if (dp->text_ptr == NULL)
|
||||
display_log(dp, APP_ERROR, "text chunks: stash malloc failed");
|
||||
@@ -605,7 +709,7 @@ text_restore(struct display *dp)
|
||||
* Set an option to a bitmask constructed from the values (List)
|
||||
*/
|
||||
static png_byte
|
||||
optind(struct display *dp, const char *opt, size_t len)
|
||||
option_index(struct display *dp, const char *opt, size_t len)
|
||||
/* Return the index (in options[]) of the given option, outputs an error if
|
||||
* it does not exist. Takes the name of the option and a length (number of
|
||||
* characters in the name).
|
||||
@@ -613,7 +717,7 @@ optind(struct display *dp, const char *opt, size_t len)
|
||||
{
|
||||
png_byte j;
|
||||
|
||||
for (j=0; j<opt_count; ++j)
|
||||
for (j=0; j<option_count; ++j)
|
||||
if (strncmp(options[j].name, opt, len) == 0 && options[j].name[len] == 0)
|
||||
return j;
|
||||
|
||||
@@ -626,12 +730,12 @@ optind(struct display *dp, const char *opt, size_t len)
|
||||
}
|
||||
|
||||
/* This works for an option name (no quotes): */
|
||||
#define OPTIND(dp, name) optind(dp, #name, (sizeof #name)-1)
|
||||
#define OPTIND(dp, name) option_index(dp, #name, (sizeof #name)-1)
|
||||
|
||||
static int
|
||||
getopt(struct display *dp, const char *opt, int *value)
|
||||
get_option(struct display *dp, const char *opt, int *value)
|
||||
{
|
||||
const png_byte i = optind(dp, opt, strlen(opt));
|
||||
const png_byte i = option_index(dp, opt, strlen(opt));
|
||||
|
||||
if (dp->entry[i]) /* option was set on command line */
|
||||
{
|
||||
@@ -1147,7 +1251,7 @@ getallopts_(struct display *dp, const png_byte opt, int *value, int record)
|
||||
static int
|
||||
getallopts(struct display *dp, const char *opt_str, int *value)
|
||||
{
|
||||
return getallopts_(dp, optind(dp, opt_str, strlen(opt_str)), value, 0);
|
||||
return getallopts_(dp, option_index(dp, opt_str, strlen(opt_str)), value, 0);
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -1155,7 +1259,7 @@ getsearchopts(struct display *dp, const char *opt_str, int *value)
|
||||
/* As above except that if the option was not set try a search */
|
||||
{
|
||||
png_byte istrat;
|
||||
const png_byte opt = optind(dp, opt_str, strlen(opt_str));
|
||||
const png_byte opt = option_index(dp, opt_str, strlen(opt_str));
|
||||
int record = options[opt].search;
|
||||
const char *entry_name;
|
||||
|
||||
@@ -1172,17 +1276,6 @@ getsearchopts(struct display *dp, const char *opt_str, int *value)
|
||||
istrat = OPTIND(dp, strategy);
|
||||
entry_name = range_lo; /* record the value, not the name */
|
||||
|
||||
#if defined(PNG_SELECT_FILTER_HEURISTICALLY_SUPPORTED) ||\
|
||||
defined(PNG_SELECT_FILTER_METHODICALLY_SUPPORTED)
|
||||
if (opt == OPTIND(dp, select))
|
||||
{
|
||||
dp->value[opt] = SELECT_METHODICALLY; /* should probably be all */
|
||||
entry_name = "methodically"; /* for the moment */
|
||||
}
|
||||
|
||||
else
|
||||
#endif /* SELECT_FILTER_HEURISTICALLY || SELECT_FILTER_METHODICALLY */
|
||||
|
||||
if (opt == istrat) /* search all strategies */
|
||||
(void)advance_opt(dp, opt, 0/*iterate*/), record=0;
|
||||
|
||||
@@ -1223,7 +1316,7 @@ getsearchopts(struct display *dp, const char *opt_str, int *value)
|
||||
}
|
||||
|
||||
else /* something else */
|
||||
assert(!"reached");
|
||||
assert(0=="reached");
|
||||
|
||||
if (record)
|
||||
record_opt(dp, opt, entry_name);
|
||||
@@ -1235,8 +1328,9 @@ getsearchopts(struct display *dp, const char *opt_str, int *value)
|
||||
|
||||
static int
|
||||
find_val(struct display *dp, png_byte opt, const char *str, size_t len)
|
||||
/* Like optind but sets (index+i) of the entry in options[opt] that matches
|
||||
* str[0..len-1] into dp->entry[opt] as well as returning the actual value.
|
||||
/* Like option_index but sets (index+i) of the entry in options[opt] that
|
||||
* matches str[0..len-1] into dp->entry[opt] as well as returning the actual
|
||||
* value.
|
||||
*/
|
||||
{
|
||||
int rlo = INT_MAX, rhi = INT_MIN;
|
||||
@@ -1297,7 +1391,7 @@ opt_check(struct display *dp, const char *arg)
|
||||
/* So arg[0..i-1] is the argument name, this does not return if this isn't
|
||||
* a valid option name.
|
||||
*/
|
||||
j = optind(dp, arg, i);
|
||||
j = option_index(dp, arg, i);
|
||||
|
||||
/* It matcheth an option; check the remainder. */
|
||||
if (arg[i] == 0) /* no specified value, use the default */
|
||||
@@ -1401,6 +1495,83 @@ opt_check(struct display *dp, const char *arg)
|
||||
return 0; /* not an option */
|
||||
}
|
||||
|
||||
#ifdef PNG_PNGCP_TIMING_SUPPORTED
|
||||
static void
|
||||
set_timer(struct display *dp, struct timespec *timer)
|
||||
{
|
||||
/* Do the timing using clock_gettime and the per-process timer. */
|
||||
if (clock_gettime(CLOCK_PROCESS_CPUTIME_ID, timer))
|
||||
{
|
||||
display_log(dp, APP_ERROR,
|
||||
"CLOCK_PROCESS_CPUTIME_ID: %s: timing disabled\n", strerror(errno));
|
||||
dp->value[OPTIND(dp,time)] = 0; /* i.e. off */
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
start_timer(struct display *dp, int what)
|
||||
{
|
||||
if ((dp->value[OPTIND(dp,time)] & what) != 0)
|
||||
set_timer(dp, what == PNGCP_TIME_READ ? &dp->read_time : &dp->write_time);
|
||||
}
|
||||
|
||||
static void
|
||||
end_timer(struct display *dp, int what)
|
||||
{
|
||||
if ((dp->value[OPTIND(dp,time)] & what) != 0)
|
||||
{
|
||||
struct timespec t, tmp;
|
||||
|
||||
set_timer(dp, &t);
|
||||
|
||||
if (what == PNGCP_TIME_READ)
|
||||
tmp = dp->read_time;
|
||||
|
||||
else
|
||||
tmp = dp->write_time;
|
||||
|
||||
t.tv_sec -= tmp.tv_sec;
|
||||
t.tv_nsec -= tmp.tv_nsec;
|
||||
|
||||
if (t.tv_nsec < 0)
|
||||
{
|
||||
--(t.tv_sec);
|
||||
t.tv_nsec += 1000000000L;
|
||||
}
|
||||
|
||||
if (what == PNGCP_TIME_READ)
|
||||
dp->read_time = t, tmp = dp->read_time_total;
|
||||
|
||||
else
|
||||
dp->write_time = t, tmp = dp->write_time_total;
|
||||
|
||||
tmp.tv_sec += t.tv_sec;
|
||||
tmp.tv_nsec += t.tv_nsec;
|
||||
|
||||
if (tmp.tv_nsec >= 1000000000L)
|
||||
{
|
||||
++(tmp.tv_sec);
|
||||
tmp.tv_nsec -= 1000000000L;
|
||||
}
|
||||
|
||||
if (what == PNGCP_TIME_READ)
|
||||
dp->read_time_total = tmp;
|
||||
|
||||
else
|
||||
dp->write_time_total = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
print_time(const char *what, struct timespec t)
|
||||
{
|
||||
printf("%s %.2lu.%.9ld", what, (unsigned long)t.tv_sec, t.tv_nsec);
|
||||
}
|
||||
#else /* !PNGCP_TIMING */
|
||||
#define start_timer(dp, what) ((void)0)
|
||||
#define end_timer(dp, what) ((void)0)
|
||||
#endif /* !PNGCP_TIMING */
|
||||
|
||||
/* The following is used in main to verify that the final argument is a
|
||||
* directory:
|
||||
*/
|
||||
@@ -1468,7 +1639,7 @@ makename(struct display *dp, const char *dir, const char *infile)
|
||||
{
|
||||
size_t dsize = strlen(dir);
|
||||
|
||||
if (dsize < FILENAME_MAX+2)
|
||||
if (dsize <= (sizeof dp->namebuf)-2) /* Allow for name + '/' + '\0' */
|
||||
{
|
||||
size_t isize = strlen(infile);
|
||||
size_t istart = isize-1;
|
||||
@@ -1488,7 +1659,7 @@ makename(struct display *dp, const char *dir, const char *infile)
|
||||
isize -= istart;
|
||||
infile += istart;
|
||||
|
||||
if (dsize+isize <= FILENAME_MAX)
|
||||
if (dsize+isize < (sizeof dp->namebuf)) /* dsize + infile + '\0' */
|
||||
{
|
||||
memcpy(dp->namebuf+dsize, infile, isize+1);
|
||||
|
||||
@@ -1499,7 +1670,7 @@ makename(struct display *dp, const char *dir, const char *infile)
|
||||
|
||||
else
|
||||
{
|
||||
dp->namebuf[dsize] = 0;
|
||||
dp->namebuf[dsize] = 0; /* allowed for: -2 at start */
|
||||
display_log(dp, USER_ERROR, "%s%s: output file name too long",
|
||||
dp->namebuf, infile);
|
||||
}
|
||||
@@ -1558,7 +1729,7 @@ read_function(png_structp pp, png_bytep data, png_size_t size)
|
||||
{
|
||||
struct display *dp = get_dp(pp);
|
||||
|
||||
if (fread(data, size, 1U, dp->fp) == 1U)
|
||||
if (size == 0U || fread(data, size, 1U, dp->fp) == 1U)
|
||||
dp->read_size += size;
|
||||
|
||||
else
|
||||
@@ -1582,7 +1753,21 @@ read_png(struct display *dp, const char *filename)
|
||||
if (dp->read_pp == NULL)
|
||||
display_log(dp, LIBPNG_ERROR, "failed to create read struct");
|
||||
|
||||
png_set_benign_errors(dp->read_pp, 1/*allowed*/);
|
||||
# ifdef PNG_BENIGN_ERRORS_SUPPORTED
|
||||
png_set_benign_errors(dp->read_pp, 1/*allowed*/);
|
||||
# endif /* BENIGN_ERRORS */
|
||||
|
||||
# ifdef FIX_INDEX
|
||||
if ((dp->options & FIX_INDEX) != 0)
|
||||
png_set_check_for_invalid_index(dp->read_pp, 1/*on, no warning*/);
|
||||
# ifdef IGNORE_INDEX
|
||||
else
|
||||
# endif /* IGNORE_INDEX */
|
||||
# endif /* FIX_INDEX */
|
||||
# ifdef IGNORE_INDEX
|
||||
if ((dp->options & IGNORE_INDEX) != 0) /* DANGEROUS */
|
||||
png_set_check_for_invalid_index(dp->read_pp, -1/*off completely*/);
|
||||
# endif /* IGNORE_INDEX */
|
||||
|
||||
/* The png_read_png API requires us to make the info struct, but it does the
|
||||
* call to png_read_info.
|
||||
@@ -1594,10 +1779,10 @@ read_png(struct display *dp, const char *filename)
|
||||
/* Set the IO handling */
|
||||
png_set_read_fn(dp->read_pp, dp, read_function);
|
||||
|
||||
# ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED
|
||||
# ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
|
||||
png_set_keep_unknown_chunks(dp->read_pp, PNG_HANDLE_CHUNK_ALWAYS, NULL,
|
||||
0);
|
||||
# endif /* SET_UNKNOWN_CHUNKS */
|
||||
# endif /* HANDLE_AS_UNKNOWN */
|
||||
|
||||
# ifdef PNG_SET_USER_LIMITS_SUPPORTED
|
||||
/* Remove the user limits, if any */
|
||||
@@ -1605,15 +1790,24 @@ read_png(struct display *dp, const char *filename)
|
||||
# endif /* SET_USER_LIMITS */
|
||||
|
||||
/* Now read the PNG. */
|
||||
start_timer(dp, PNGCP_TIME_READ);
|
||||
png_read_png(dp->read_pp, dp->ip, 0U/*transforms*/, NULL/*params*/);
|
||||
end_timer(dp, PNGCP_TIME_READ);
|
||||
dp->w = png_get_image_width(dp->read_pp, dp->ip);
|
||||
dp->h = png_get_image_height(dp->read_pp, dp->ip);
|
||||
dp->ct = png_get_color_type(dp->read_pp, dp->ip);
|
||||
dp->bpp = png_get_bit_depth(dp->read_pp, dp->ip) *
|
||||
png_get_channels(dp->read_pp, dp->ip);
|
||||
{
|
||||
/* png_get_rowbytes should never return 0 because the value is set by the
|
||||
* first call to png_set_IHDR, which should have happened by now, but just
|
||||
* in case:
|
||||
*/
|
||||
png_alloc_size_t rb = png_get_rowbytes(dp->read_pp, dp->ip);
|
||||
|
||||
if (rb == 0)
|
||||
png_error(dp->read_pp, "invalid row byte count from libpng");
|
||||
|
||||
/* The size calc can overflow. */
|
||||
if ((MAX_SIZE-dp->h)/rb < dp->h)
|
||||
png_error(dp->read_pp, "image too large");
|
||||
@@ -1621,6 +1815,39 @@ read_png(struct display *dp, const char *filename)
|
||||
dp->size = rb * dp->h + dp->h/*filter byte*/;
|
||||
}
|
||||
|
||||
#ifdef FIX_INDEX
|
||||
if (dp->ct == PNG_COLOR_TYPE_PALETTE && (dp->options & FIX_INDEX) != 0)
|
||||
{
|
||||
int max = png_get_palette_max(dp->read_pp, dp->ip);
|
||||
png_colorp palette = NULL;
|
||||
int num = -1;
|
||||
|
||||
if (png_get_PLTE(dp->read_pp, dp->ip, &palette, &num) != PNG_INFO_PLTE
|
||||
|| max < 0 || num <= 0 || palette == NULL)
|
||||
display_log(dp, LIBPNG_ERROR, "invalid png_get_PLTE result");
|
||||
|
||||
if (max >= num)
|
||||
{
|
||||
/* 'Fix' the palette. */
|
||||
int i;
|
||||
png_color newpal[256];
|
||||
|
||||
for (i=0; i<num; ++i)
|
||||
newpal[i] = palette[i];
|
||||
|
||||
/* Fill in any remainder with a warning color: */
|
||||
for (; i<=max; ++i)
|
||||
{
|
||||
newpal[i].red = 0xbe;
|
||||
newpal[i].green = 0xad;
|
||||
newpal[i].blue = 0xed;
|
||||
}
|
||||
|
||||
png_set_PLTE(dp->read_pp, dp->ip, newpal, i);
|
||||
}
|
||||
}
|
||||
#endif /* FIX_INDEX */
|
||||
|
||||
display_clean_read(dp);
|
||||
dp->operation = "none";
|
||||
}
|
||||
@@ -1709,9 +1936,25 @@ set_compression(struct display *dp)
|
||||
SET_COMPRESSION
|
||||
# undef SET
|
||||
}
|
||||
|
||||
#ifdef PNG_SW_COMPRESS_level /* 1.7.0+ */
|
||||
static void
|
||||
set_ICC_profile_compression(struct display *dp)
|
||||
{
|
||||
int val;
|
||||
|
||||
# define SET(name, func) if (getallopts(dp, "ICC-profile-" #name, &val))\
|
||||
png_set_ICC_profile_compression_ ## func(dp->write_pp, val);
|
||||
SET_COMPRESSION
|
||||
# undef SET
|
||||
}
|
||||
#else
|
||||
# define set_ICC_profile_compression(dp) ((void)0)
|
||||
#endif
|
||||
#else
|
||||
# define search_compression(dp) ((void)0)
|
||||
# define set_compression(dp) ((void)0)
|
||||
# define set_ICC_profile_compression(dp) ((void)0)
|
||||
#endif /* WRITE_CUSTOMIZE_COMPRESSION */
|
||||
|
||||
#ifdef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED
|
||||
@@ -1741,19 +1984,27 @@ write_png(struct display *dp, const char *destname)
|
||||
if (dp->write_pp == NULL)
|
||||
display_log(dp, LIBPNG_ERROR, "failed to create write png_struct");
|
||||
|
||||
png_set_benign_errors(dp->write_pp, 1/*allowed*/);
|
||||
# ifdef PNG_BENIGN_ERRORS_SUPPORTED
|
||||
png_set_benign_errors(dp->write_pp, 1/*allowed*/);
|
||||
# endif /* BENIGN_ERRORS */
|
||||
|
||||
png_set_write_fn(dp->write_pp, dp, write_function, NULL/*flush*/);
|
||||
|
||||
#ifdef IGNORE_INDEX
|
||||
if ((dp->options & IGNORE_INDEX) != 0) /* DANGEROUS */
|
||||
png_set_check_for_invalid_index(dp->write_pp, -1/*off completely*/);
|
||||
#endif /* IGNORE_INDEX */
|
||||
|
||||
/* Restore the text chunks when using libpng 1.6 or less; this is a macro
|
||||
* which expands to nothing in 1.7+ In earlier versions it tests
|
||||
* dp->text_stashed, which is only set (below) *after* the first write.
|
||||
*/
|
||||
text_restore(dp);
|
||||
|
||||
# ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED
|
||||
# ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
|
||||
png_set_keep_unknown_chunks(dp->write_pp, PNG_HANDLE_CHUNK_ALWAYS, NULL,
|
||||
0);
|
||||
# endif /* SET_UNKNOWN_CHUNKS */
|
||||
# endif /* HANDLE_AS_UNKNOWN */
|
||||
|
||||
# ifdef PNG_SET_USER_LIMITS_SUPPORTED
|
||||
/* Remove the user limits, if any */
|
||||
@@ -1764,53 +2015,53 @@ write_png(struct display *dp, const char *destname)
|
||||
/* compression outputs, IDAT and zTXt/iTXt: */
|
||||
dp->tsp = dp->nsp;
|
||||
dp->nsp = dp->csp = 0;
|
||||
# ifdef PNG_SW_COMPRESS_png_level
|
||||
{
|
||||
int val;
|
||||
|
||||
/* This sets everything, but then the following options just override
|
||||
* the specific settings for ICC profiles and text.
|
||||
*/
|
||||
if (getallopts(dp, "compression", &val))
|
||||
png_set_compression(dp->write_pp, val);
|
||||
|
||||
if (getallopts(dp, "ICC-profile-compression", &val))
|
||||
png_set_ICC_profile_compression(dp->write_pp, val);
|
||||
|
||||
if (getallopts(dp, "text-compression", &val))
|
||||
png_set_text_compression(dp->write_pp, val);
|
||||
}
|
||||
# endif /* png_level support */
|
||||
if (dp->options & SEARCH)
|
||||
search_compression(dp);
|
||||
else
|
||||
set_compression(dp);
|
||||
set_ICC_profile_compression(dp);
|
||||
set_text_compression(dp);
|
||||
|
||||
{
|
||||
int val;
|
||||
|
||||
/* The permitted range is 1..0x7FFFFFFF, so the cast is safe */
|
||||
if (getopt(dp, "IDAT-size", &val))
|
||||
png_set_compression_buffer_size(dp->write_pp,
|
||||
(png_alloc_size_t)/*SAFE*/val);
|
||||
if (get_option(dp, "IDAT-size", &val))
|
||||
png_set_IDAT_size(dp->write_pp, val);
|
||||
}
|
||||
|
||||
/* filter handling */
|
||||
#if defined(PNG_SELECT_FILTER_HEURISTICALLY_SUPPORTED) ||\
|
||||
defined(PNG_SELECT_FILTER_METHODICALLY_SUPPORTED)
|
||||
{
|
||||
int val;
|
||||
|
||||
if (getopt(dp, "select", &val))
|
||||
{
|
||||
# ifdef PNG_SELECT_FILTER_HEURISTICALLY_SUPPORTED
|
||||
png_set_option(dp->write_pp, PNG_SELECT_FILTER_HEURISTICALLY,
|
||||
(val & SELECT_HEURISTICALLY) != 0);
|
||||
# endif /* SELECT_FILTER_HEURISTICALLY */
|
||||
# ifdef PNG_SELECT_FILTER_METHODICALLY_SUPPORTED
|
||||
png_set_option(dp->write_pp, PNG_SELECT_FILTER_METHODICALLY,
|
||||
(val & SELECT_METHODICALLY) != 0);
|
||||
# endif /* SELECT_FILTER_METHODICALLY */
|
||||
}
|
||||
}
|
||||
#endif /* SELECT_FILTER_HEURISTICALLY || SELECT_FILTER_METHODICALLY */
|
||||
|
||||
# ifdef PNG_WRITE_FILTER_SUPPORTED
|
||||
{
|
||||
int val;
|
||||
|
||||
if (getopt(dp, "filter", &val))
|
||||
if (get_option(dp, "filter", &val))
|
||||
png_set_filter(dp->write_pp, PNG_FILTER_TYPE_BASE, val);
|
||||
}
|
||||
# endif /* WRITE_FILTER */
|
||||
|
||||
/* This just uses the 'read' info_struct directly, it contains the image. */
|
||||
dp->write_size = 0U;
|
||||
start_timer(dp, PNGCP_TIME_WRITE);
|
||||
png_write_png(dp->write_pp, dp->ip, 0U/*transforms*/, NULL/*params*/);
|
||||
end_timer(dp, PNGCP_TIME_WRITE);
|
||||
|
||||
/* Make sure the file was written ok: */
|
||||
if (dp->fp != NULL)
|
||||
@@ -1938,7 +2189,7 @@ cp_one_file(struct display *dp, const char *filename, const char *destname)
|
||||
{
|
||||
int val;
|
||||
|
||||
if (getopt(dp, "log-depth", &val) && val >= 0)
|
||||
if (get_option(dp, "log-depth", &val) && val >= 0)
|
||||
log_depth = (unsigned int)/*SAFE*/val;
|
||||
|
||||
else
|
||||
@@ -1968,7 +2219,6 @@ cp_one_file(struct display *dp, const char *filename, const char *destname)
|
||||
/* Initialize the 'best' fields: */
|
||||
strcpy(dp->best, dp->curr);
|
||||
dp->best_size = dp->write_size;
|
||||
log_search(dp, log_depth);
|
||||
|
||||
if (dp->nsp > 0) /* interating over lists */
|
||||
{
|
||||
@@ -1976,6 +2226,7 @@ cp_one_file(struct display *dp, const char *filename, const char *destname)
|
||||
assert(dp->curr[0] == ' ' && dp->tsp > 0);
|
||||
|
||||
/* Cancel warnings on subsequent writes */
|
||||
log_search(dp, log_depth);
|
||||
dp->no_warnings = 1;
|
||||
|
||||
/* Make a temporary name for the subsequent tests: */
|
||||
@@ -2069,7 +2320,7 @@ main(const int argc, const char * const * const argv)
|
||||
/* Do a quick check on the directory target case; when there are more than
|
||||
* two arguments the last one must be a directory.
|
||||
*/
|
||||
if (option_end+2 < argc && !checkdir(argv[argc-1]))
|
||||
if (!(d.options & NOWRITE) && option_end+2 < argc && !checkdir(argv[argc-1]))
|
||||
{
|
||||
fprintf(stderr,
|
||||
"pngcp: %s: directory required with more than two arguments\n",
|
||||
@@ -2093,7 +2344,7 @@ main(const int argc, const char * const * const argv)
|
||||
if (i < argc)
|
||||
{
|
||||
infile = argv[i++];
|
||||
if (i < argc)
|
||||
if (!(d.options & NOWRITE) && i < argc)
|
||||
outfile = argv[argc-1];
|
||||
}
|
||||
|
||||
@@ -2146,6 +2397,15 @@ main(const int argc, const char * const * const argv)
|
||||
if (infile != NULL)
|
||||
printf(" %s", infile);
|
||||
|
||||
# ifdef PNG_PNGCP_TIMING_SUPPORTED
|
||||
/* When logging output the files for each file, if enabled. */
|
||||
if ((d.value[OPTIND(&d,time)] & PNGCP_TIME_READ) != 0)
|
||||
print_time(" read", d.read_time);
|
||||
|
||||
if ((d.value[OPTIND(&d,time)] & PNGCP_TIME_WRITE) != 0)
|
||||
print_time(" write", d.write_time);
|
||||
# endif /* PNGCP_TIMING */
|
||||
|
||||
printf("\n");
|
||||
fflush(stdout);
|
||||
}
|
||||
@@ -2153,8 +2413,8 @@ main(const int argc, const char * const * const argv)
|
||||
|
||||
display_clean(&d);
|
||||
}
|
||||
while (i+1 < argc);
|
||||
/* I.e. for all cases after the first time through the loop require
|
||||
while (i+!(d.options & NOWRITE) < argc);
|
||||
/* I.e. for write cases after the first time through the loop require
|
||||
* there to be at least two arguments left and for the last one to be a
|
||||
* directory (this was checked above).
|
||||
*/
|
||||
@@ -2162,6 +2422,24 @@ main(const int argc, const char * const * const argv)
|
||||
/* Release allocated memory */
|
||||
display_destroy(&d);
|
||||
|
||||
# ifdef PNG_PNGCP_TIMING_SUPPORTED
|
||||
{
|
||||
int output = 0;
|
||||
|
||||
if ((d.value[OPTIND(&d,time)] & PNGCP_TIME_READ) != 0)
|
||||
print_time("read", d.read_time_total), output = 1;
|
||||
|
||||
if ((d.value[OPTIND(&d,time)] & PNGCP_TIME_WRITE) != 0)
|
||||
{
|
||||
if (output) putchar(' ');
|
||||
print_time("write", d.write_time_total);
|
||||
output = 1;
|
||||
}
|
||||
|
||||
if (output) putchar('\n');
|
||||
}
|
||||
# endif /* PNGCP_TIMING */
|
||||
|
||||
return errors != 0;
|
||||
}
|
||||
}
|
||||
@@ -2172,4 +2450,4 @@ main(void)
|
||||
fprintf(stderr, "pngcp: no support for png_read/write_image\n");
|
||||
return 77;
|
||||
}
|
||||
#endif
|
||||
#endif /* !READ_PNG || !WRITE_PNG */
|
||||
@@ -2,7 +2,7 @@
|
||||
*
|
||||
* Copyright (c) 2014-2016 John Cunningham Bowler
|
||||
*
|
||||
* Last changed in libpng 1.6.21 [January 15, 2016]
|
||||
* Last changed in libpng 1.6.26 [October 20, 2016]
|
||||
*
|
||||
* This code is released under the libpng license.
|
||||
* For conditions of distribution and use, see the disclaimer
|
||||
@@ -1824,7 +1824,7 @@ IDAT_init(struct IDAT * const idat, struct file * const file)
|
||||
}
|
||||
|
||||
static png_uint_32
|
||||
rechunk_length(struct IDAT *idat)
|
||||
rechunk_length(struct IDAT *idat, int start)
|
||||
/* Return the length for the next IDAT chunk, taking into account
|
||||
* rechunking.
|
||||
*/
|
||||
@@ -1836,7 +1836,7 @@ rechunk_length(struct IDAT *idat)
|
||||
const struct IDAT_list *cur;
|
||||
unsigned int count;
|
||||
|
||||
if (idat->idat_index == 0) /* at the new chunk (first time) */
|
||||
if (start)
|
||||
return idat->idat_length; /* use the cache */
|
||||
|
||||
/* Otherwise rechunk_length is called at the end of a chunk for the length
|
||||
@@ -1995,7 +1995,7 @@ process_IDAT(struct file *file)
|
||||
idat->idat_index = 0; /* Index into chunk data */
|
||||
|
||||
/* Update the chunk length to the correct value for the IDAT chunk: */
|
||||
file->chunk->chunk_length = rechunk_length(idat);
|
||||
file->chunk->chunk_length = rechunk_length(idat, 1/*start*/);
|
||||
|
||||
/* Change the state to writing IDAT chunks */
|
||||
file->state = STATE_IDAT;
|
||||
@@ -3473,7 +3473,8 @@ read_callback(png_structp png_ptr, png_bytep buffer, size_t count)
|
||||
/* Write another IDAT chunk. Call rechunk_length to
|
||||
* calculate the length required.
|
||||
*/
|
||||
length = chunk->chunk_length = rechunk_length(file->idat);
|
||||
length = chunk->chunk_length =
|
||||
rechunk_length(file->idat, 0/*end*/);
|
||||
assert(type == png_IDAT);
|
||||
file->write_count = 0; /* for the new chunk */
|
||||
--(file->write_count); /* fake out the increment below */
|
||||
|
||||
25
contrib/tools/reindent
Normal file
@@ -0,0 +1,25 @@
|
||||
#!/bin/sh
|
||||
|
||||
# reindent a libpng C source
|
||||
|
||||
# COPYRIGHT: Written by Glenn Randers-Pehrson, 2016.
|
||||
# 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.
|
||||
|
||||
# Usage:
|
||||
# reindent inputtabsize outputtabsize inputcontinuestring outputcontinuestring
|
||||
#
|
||||
# Assumes that continued lines begin with indentation plus one space, and
|
||||
# that continued comments begin with indentation plus " *".
|
||||
#
|
||||
# eg, to change libpng coding style from 3-space indentation with 4-space
|
||||
# continuations to 4-space indentation with 2-space continuations:
|
||||
#
|
||||
# reindent 3 4 "\t " " " < example.c > example.c_4_2
|
||||
# and to restore the file back to libpng coding style
|
||||
# reindent 4 3 " " " " < example.c_4_2 > example.c_3_4
|
||||
|
||||
unexpand --first-only --t $1 | \
|
||||
sed -e "/^ *$3[^\*]/{s/$3/$4/}" | \
|
||||
expand -t $2
|
||||
@@ -14,7 +14,7 @@
|
||||
* All routines take and return a floating point value in the range
|
||||
* 0 to 1.0, doing a calculation according to the sRGB specification
|
||||
* (in fact the source of the numbers is the wikipedia article at
|
||||
* http://en.wikipedia.org/wiki/SRGB).
|
||||
* https://en.wikipedia.org/wiki/SRGB).
|
||||
*/
|
||||
static double
|
||||
sRGB_from_linear(double l)
|
||||
|
||||
44
example.c
@@ -97,7 +97,7 @@ int main(int argc, const char **argv)
|
||||
*/
|
||||
if (buffer != NULL &&
|
||||
png_image_finish_read(&image, NULL/*background*/, buffer,
|
||||
0/*row_stride*/, NULL/*colormap*/) != 0)
|
||||
0/*row_stride*/, NULL/*colormap*/) != 0)
|
||||
{
|
||||
/* Now write the image out to the second argument. In the write
|
||||
* call 'convert_to_8bit' allows 16-bit data to be squashed down to
|
||||
@@ -105,7 +105,7 @@ int main(int argc, const char **argv)
|
||||
* to the 8-bit format.
|
||||
*/
|
||||
if (png_image_write_to_file(&image, argv[2], 0/*convert_to_8bit*/,
|
||||
buffer, 0/*row_stride*/, NULL/*colormap*/) != 0)
|
||||
buffer, 0/*row_stride*/, NULL/*colormap*/) != 0)
|
||||
{
|
||||
/* The image has been written successfully. */
|
||||
exit(0);
|
||||
@@ -295,7 +295,7 @@ void read_png(FILE *fp, int sig_read) /* File is already open */
|
||||
* was compiled with a compatible version of the library. REQUIRED
|
||||
*/
|
||||
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,
|
||||
png_voidp user_error_ptr, user_error_fn, user_warning_fn);
|
||||
png_voidp user_error_ptr, user_error_fn, user_warning_fn);
|
||||
|
||||
if (png_ptr == NULL)
|
||||
{
|
||||
@@ -375,7 +375,7 @@ void read_png(FILE *fp, int sig_read) /* File is already open */
|
||||
* low byte.
|
||||
*/
|
||||
#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
|
||||
png_set_scale_16(png_ptr);
|
||||
png_set_scale_16(png_ptr);
|
||||
#else
|
||||
png_set_strip_16(png_ptr);
|
||||
#endif
|
||||
@@ -419,10 +419,10 @@ void read_png(FILE *fp, int sig_read) /* File is already open */
|
||||
|
||||
if (png_get_bKGD(png_ptr, info_ptr, &image_background) != 0)
|
||||
png_set_background(png_ptr, image_background,
|
||||
PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);
|
||||
PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);
|
||||
else
|
||||
png_set_background(png_ptr, &my_background,
|
||||
PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0);
|
||||
PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0);
|
||||
|
||||
/* Some suggestions as to how to get a screen gamma value
|
||||
*
|
||||
@@ -481,7 +481,7 @@ void read_png(FILE *fp, int sig_read) /* File is already open */
|
||||
png_color std_color_cube[MAX_SCREEN_COLORS];
|
||||
|
||||
png_set_quantize(png_ptr, std_color_cube, MAX_SCREEN_COLORS,
|
||||
MAX_SCREEN_COLORS, NULL, 0);
|
||||
MAX_SCREEN_COLORS, NULL, 0);
|
||||
}
|
||||
/* This reduces the image to the palette supplied in the file */
|
||||
else if (png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette) != 0)
|
||||
@@ -491,7 +491,7 @@ void read_png(FILE *fp, int sig_read) /* File is already open */
|
||||
png_get_hIST(png_ptr, info_ptr, &histogram);
|
||||
|
||||
png_set_quantize(png_ptr, palette, num_palette,
|
||||
max_screen_colors, histogram, 0);
|
||||
max_screen_colors, histogram, 0);
|
||||
}
|
||||
}
|
||||
#endif /* READ_QUANTIZE */
|
||||
@@ -522,7 +522,7 @@ void read_png(FILE *fp, int sig_read) /* File is already open */
|
||||
png_set_swap(png_ptr);
|
||||
|
||||
/* Add filler (or alpha) byte (before/after each RGB triplet) */
|
||||
png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER);
|
||||
png_set_filler(png_ptr, 0xffff, PNG_FILLER_AFTER);
|
||||
|
||||
#ifdef PNG_READ_INTERLACING_SUPPORTED
|
||||
/* Turn on interlace handling. REQUIRED if you are not using
|
||||
@@ -532,7 +532,7 @@ void read_png(FILE *fp, int sig_read) /* File is already open */
|
||||
number_passes = png_set_interlace_handling(png_ptr);
|
||||
#else /* !READ_INTERLACING */
|
||||
number_passes = 1;
|
||||
#endif /* !READ_INTERLACING */
|
||||
#endif /* READ_INTERLACING */
|
||||
|
||||
|
||||
/* Optional call to gamma correct and add the background to the palette
|
||||
@@ -552,7 +552,7 @@ void read_png(FILE *fp, int sig_read) /* File is already open */
|
||||
|
||||
for (row = 0; row < height; row++)
|
||||
row_pointers[row] = png_malloc(png_ptr, png_get_rowbytes(png_ptr,
|
||||
info_ptr));
|
||||
info_ptr));
|
||||
|
||||
/* Now it's time to read the image. One of these methods is REQUIRED */
|
||||
#ifdef entire /* Read the entire image in one go */
|
||||
@@ -574,10 +574,10 @@ void read_png(FILE *fp, int sig_read) /* File is already open */
|
||||
{
|
||||
#ifdef sparkle /* Read the image using the "sparkle" effect. */
|
||||
png_read_rows(png_ptr, &row_pointers[y], NULL,
|
||||
number_of_rows);
|
||||
number_of_rows);
|
||||
#else no_sparkle /* Read the image using the "rectangle" effect */
|
||||
png_read_rows(png_ptr, NULL, &row_pointers[y],
|
||||
number_of_rows);
|
||||
number_of_rows);
|
||||
#endif no_sparkle /* Use only one of these two methods */
|
||||
}
|
||||
|
||||
@@ -614,7 +614,7 @@ initialize_png_reader(png_structp *png_ptr, png_infop *info_ptr)
|
||||
* linked libraries.
|
||||
*/
|
||||
*png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,
|
||||
png_voidp user_error_ptr, user_error_fn, user_warning_fn);
|
||||
png_voidp user_error_ptr, user_error_fn, user_warning_fn);
|
||||
|
||||
if (*png_ptr == NULL)
|
||||
{
|
||||
@@ -649,14 +649,14 @@ initialize_png_reader(png_structp *png_ptr, png_infop *info_ptr)
|
||||
* the function png_get_progressive_ptr(png_ptr).
|
||||
*/
|
||||
png_set_progressive_read_fn(*png_ptr, (void *)stream_data,
|
||||
info_callback, row_callback, end_callback);
|
||||
info_callback, row_callback, end_callback);
|
||||
|
||||
return (OK);
|
||||
}
|
||||
|
||||
int
|
||||
process_data(png_structp *png_ptr, png_infop *info_ptr,
|
||||
png_bytep buffer, png_uint_32 length)
|
||||
png_bytep buffer, png_uint_32 length)
|
||||
{
|
||||
if (setjmp(png_jmpbuf((*png_ptr))))
|
||||
{
|
||||
@@ -691,7 +691,7 @@ info_callback(png_structp png_ptr, png_infop info)
|
||||
}
|
||||
|
||||
row_callback(png_structp png_ptr, png_bytep new_row,
|
||||
png_uint_32 row_num, int pass)
|
||||
png_uint_32 row_num, int pass)
|
||||
{
|
||||
/*
|
||||
* This function is called for every row in the image. If the
|
||||
@@ -780,7 +780,7 @@ void write_png(char *file_name /* , ... other image information ... */)
|
||||
* in case we are using dynamically linked libraries. REQUIRED.
|
||||
*/
|
||||
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,
|
||||
png_voidp user_error_ptr, user_error_fn, user_warning_fn);
|
||||
png_voidp user_error_ptr, user_error_fn, user_warning_fn);
|
||||
|
||||
if (png_ptr == NULL)
|
||||
{
|
||||
@@ -819,7 +819,7 @@ void write_png(char *file_name /* , ... other image information ... */)
|
||||
* png_init_io() here you would call
|
||||
*/
|
||||
png_set_write_fn(png_ptr, (void *)user_io_ptr, user_write_fn,
|
||||
user_IO_flush_function);
|
||||
user_IO_flush_function);
|
||||
/* where user_io_ptr is a structure you want available to the callbacks */
|
||||
#endif no_streams /* Only use one initialization method */
|
||||
|
||||
@@ -842,7 +842,7 @@ void write_png(char *file_name /* , ... other image information ... */)
|
||||
* currently be PNG_COMPRESSION_TYPE_BASE and PNG_FILTER_TYPE_BASE. REQUIRED
|
||||
*/
|
||||
png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth, PNG_COLOR_TYPE_???,
|
||||
PNG_INTERLACE_????, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
|
||||
PNG_INTERLACE_????, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
|
||||
|
||||
/* Set the palette if there is one. REQUIRED for indexed-color images */
|
||||
palette = (png_colorp)png_malloc(png_ptr, PNG_MAX_PALETTE_LENGTH
|
||||
@@ -988,11 +988,11 @@ void write_png(char *file_name /* , ... other image information ... */)
|
||||
png_bytep row_pointers[height];
|
||||
|
||||
if (height > PNG_UINT_32_MAX/(sizeof (png_bytep)))
|
||||
png_error (png_ptr, "Image is too tall to process in memory");
|
||||
png_error (png_ptr, "Image is too tall to process in memory");
|
||||
|
||||
/* Set up pointers into your "image" byte array */
|
||||
for (k = 0; k < height; k++)
|
||||
row_pointers[k] = image + k*width*bytes_per_pixel;
|
||||
row_pointers[k] = image + k*width*bytes_per_pixel;
|
||||
|
||||
/* One of the following output methods is REQUIRED */
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
libpng-manual.txt - A description on how to use and modify libpng
|
||||
|
||||
libpng version 1.7.0beta80 - May 6, 2016
|
||||
libpng version 1.7.0beta90 - August 28, 2017
|
||||
Updated and distributed by Glenn Randers-Pehrson
|
||||
<glennrp at users.sourceforge.net>
|
||||
Copyright (c) 1998-2015 Glenn Randers-Pehrson
|
||||
Copyright (c) 1998-2017 Glenn Randers-Pehrson
|
||||
|
||||
This document is released under the libpng license.
|
||||
For conditions of distribution and use, see the disclaimer
|
||||
@@ -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.0beta80 - May 6, 2016
|
||||
libpng versions 0.97, January 1998, through 1.7.0beta90 - August 28, 2017
|
||||
Updated and distributed by Glenn Randers-Pehrson
|
||||
Copyright (c) 1998-2015 Glenn Randers-Pehrson
|
||||
|
||||
@@ -67,17 +67,17 @@ file format in application programs.
|
||||
|
||||
The PNG specification (second edition), November 2003, is available as
|
||||
a W3C Recommendation and as an ISO Standard (ISO/IEC 15948:2004 (E)) at
|
||||
<http://www.w3.org/TR/2003/REC-PNG-20031110/
|
||||
<https://www.w3.org/TR/2003/REC-PNG-20031110/
|
||||
The W3C and ISO documents have identical technical content.
|
||||
|
||||
The PNG-1.2 specification is available at
|
||||
<http://png-mng.sourceforge.net/pub/png/spec/1.2/>.
|
||||
<https://png-mng.sourceforge.io/pub/png/spec/1.2/>.
|
||||
It is technically equivalent
|
||||
to the PNG specification (second edition) but has some additional material.
|
||||
|
||||
The PNG-1.0 specification is available as RFC 2083
|
||||
<http://png-mng.sourceforge.net/pub/png/spec/1.0/> and as a
|
||||
W3C Recommendation <http://www.w3.org/TR/REC-png-961001>.
|
||||
The PNG-1.0 specification is available as RFC 2083
|
||||
<https://png-mng.sourceforge.io/pub/png/spec/1.0/> and as a
|
||||
W3C Recommendation <https://www.w3.org/TR/REC-png-961001>.
|
||||
|
||||
Some additional chunks are described in the special-purpose public chunks
|
||||
documents at <http://www.libpng.org/pub/png/spec/register/>
|
||||
@@ -102,7 +102,7 @@ majority of the needs of its users.
|
||||
|
||||
Libpng uses zlib for its compression and decompression of PNG files.
|
||||
Further information about zlib, and the latest version of zlib, can
|
||||
be found at the zlib home page, <http://zlib.net/>.
|
||||
be found at the zlib home page, <https://zlib.net/>.
|
||||
The zlib compression utility is a general purpose utility that is
|
||||
useful for more than PNG files, and can be used without libpng.
|
||||
See the documentation delivered with zlib for more details.
|
||||
@@ -471,8 +471,9 @@ the default, use
|
||||
|
||||
The values for png_set_crc_action() say how libpng is to handle CRC errors in
|
||||
ancillary and critical chunks, and whether to use the data contained
|
||||
therein. Note that it is impossible to "discard" data in a critical
|
||||
chunk.
|
||||
therein. Starting with libpng-1.6.26, this also governs how an ADLER32 error
|
||||
is handled while reading the IDAT chunk. Note that it is impossible to
|
||||
"discard" data in a critical chunk.
|
||||
|
||||
Choices for (int) crit_action are
|
||||
PNG_CRC_DEFAULT 0 error/quit
|
||||
@@ -489,6 +490,9 @@ Choices for (int) ancil_action are
|
||||
PNG_CRC_QUIET_USE 4 quiet/use data
|
||||
PNG_CRC_NO_CHANGE 5 use the current value
|
||||
|
||||
When the setting for crit_action is PNG_CRC_QUIET_USE, the CRC and ADLER32
|
||||
checksums are not only ignored, but they are not evaluated.
|
||||
|
||||
Setting up callback code
|
||||
|
||||
You can set up a callback function to handle any unknown chunks in the
|
||||
@@ -563,7 +567,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.
|
||||
|
||||
@@ -3833,7 +3837,7 @@ The #defines to be used in png_image::format. Each #define identifies a
|
||||
particular layout of channel data and, if present, alpha values. There are
|
||||
separate defines for each of the two channel encodings.
|
||||
|
||||
A format is built up using single bit flag values. Not all combinations are
|
||||
A format is built up using one-bit flag values. Not all combinations are
|
||||
valid: use the bit flag values below for testing a format returned by the
|
||||
read APIs, but set formats from the derived values.
|
||||
|
||||
@@ -4046,7 +4050,7 @@ READ APIs
|
||||
|
||||
When the simplified API needs to convert between sRGB and linear colorspaces,
|
||||
the actual sRGB transfer curve defined in the sRGB specification (see the
|
||||
article at http://en.wikipedia.org/wiki/SRGB) is used, not the gamma=1/2.2
|
||||
article at https://en.wikipedia.org/wiki/SRGB) is used, not the gamma=1/2.2
|
||||
approximation used elsewhere in libpng.
|
||||
|
||||
WRITE APIS
|
||||
@@ -4223,7 +4227,7 @@ However, there are some uncertainties about the status of local variables
|
||||
after a longjmp, so the user may want to be careful about doing anything
|
||||
after setjmp returns non-zero besides returning itself. Consult your
|
||||
compiler documentation for more details. For an alternative approach, you
|
||||
may wish to use the "cexcept" facility (see http://cexcept.sourceforge.net),
|
||||
may wish to use the "cexcept" facility (see https://cexcept.sourceforge.io/),
|
||||
which is illustrated in pngvalid.c and in contrib/visupng.
|
||||
|
||||
Beginning in libpng-1.4.0, the png_set_benign_errors() API became available.
|
||||
@@ -4443,7 +4447,7 @@ in a MNG datastream. As a minimum, it must have the MNG 8-byte signature
|
||||
and the MHDR and MEND chunks. Libpng does not provide support for these
|
||||
or any other MNG chunks; your application must provide its own support for
|
||||
them. You may wish to consider using libmng (available at
|
||||
http://www.libmng.com) instead.
|
||||
https://www.libmng.com/) instead.
|
||||
|
||||
VIII. Changes to Libpng from version 0.88
|
||||
|
||||
@@ -5185,27 +5189,33 @@ control. The git repository was built from old libpng-x.y.z.tar.gz files
|
||||
going back to version 0.70. You can access the git repository (read only)
|
||||
at
|
||||
|
||||
git://git.code.sf.net/p/libpng/code
|
||||
https://github.com/glennrp/libpng or
|
||||
https://git.code.sf.net/p/libpng/code.git
|
||||
|
||||
or you can browse it with a web browser by selecting the "code" button at
|
||||
or you can browse it with a web browser at
|
||||
|
||||
https://sourceforge.net/projects/libpng
|
||||
https://github.com/glennrp/libpng or
|
||||
https://sourceforge.net/p/libpng/code/ci/libpng16/tree/
|
||||
|
||||
Patches can be sent to glennrp at users.sourceforge.net or to
|
||||
png-mng-implement at lists.sourceforge.net or you can upload them to
|
||||
the libpng bug tracker at
|
||||
|
||||
http://libpng.sourceforge.net
|
||||
https://libpng.sourceforge.io/
|
||||
|
||||
or as a "pull request" to
|
||||
|
||||
https://github.com/glennrp/libpng/pulls
|
||||
|
||||
We also accept patches built from the tar or zip distributions, and
|
||||
simple verbal discriptions of bug fixes, reported either to the
|
||||
SourceForge bug tracker, to the png-mng-implement at lists.sf.net
|
||||
mailing list, or directly to glennrp.
|
||||
mailing list, as github issues, or directly to glennrp.
|
||||
|
||||
XVI. Coding style
|
||||
|
||||
Our coding style is similar to the "Allman" style
|
||||
(See http://en.wikipedia.org/wiki/Indent_style#Allman_style), with curly
|
||||
(See https://en.wikipedia.org/wiki/Indent_style#Allman_style), with curly
|
||||
braces on separate lines:
|
||||
|
||||
if (condition)
|
||||
@@ -5247,6 +5257,19 @@ the statement that follows the comment:
|
||||
*/
|
||||
statement;
|
||||
|
||||
%17+%Linus Torvalds recomends putting the leading "/*" in multiple-line
|
||||
%17+%comments on a separate line:
|
||||
%17+%
|
||||
%17+% /*
|
||||
%17+% * This is a multiple-line
|
||||
%17+% * comment.
|
||||
%17+% */
|
||||
%17+% statement;
|
||||
%17+%
|
||||
%17+%See
|
||||
%17+%https://developers.slashdot.org/story/16/07/12/2036201
|
||||
%17+%/linus-torvalds-in-sweary-rant-about-punctuation-in-kernel-comments
|
||||
%17+%
|
||||
Very short comments can be placed after the end of the statement
|
||||
to which they pertain:
|
||||
|
||||
@@ -5306,7 +5329,7 @@ Prior to libpng-1.6.0 we used a "png_sizeof()" macro, formatted as
|
||||
though it were a function.
|
||||
|
||||
Control keywords if, for, while, and switch are always followed by a space
|
||||
to distinguish them from function calls, which have no trailing space.
|
||||
to distinguish them from function calls, which have no trailing space.
|
||||
|
||||
We put a space after each comma and after each semicolon
|
||||
in "for" statements, and we put spaces before and after each
|
||||
@@ -5328,8 +5351,9 @@ with an even number of lower-case hex digits (e.g., 0x00, 0xff, 0x0100).
|
||||
We prefer to use underscores in variable names rather than camelCase, except
|
||||
for a few type names that we inherit from zlib.h.
|
||||
|
||||
We prefer "if (something != 0)" and "if (something == 0)"
|
||||
over "if (something)" and if "(!something)", respectively.
|
||||
We prefer "if (something != 0)" and "if (something == 0)" over
|
||||
"if (something)" and if "(!something)", respectively, and for pointers
|
||||
we prefer "if (some_pointer != NULL)" or "if (some_pointer == NULL)".
|
||||
|
||||
We do not use the TAB character for indentation in the C sources.
|
||||
|
||||
@@ -5343,7 +5367,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.0beta80 are Y2K compliant. It is my belief that earlier
|
||||
upward through 1.7.0beta90 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
|
||||
|
||||
140
libpng.3
@@ -1,6 +1,6 @@
|
||||
.TH LIBPNG 3 "May 6, 2016"
|
||||
.TH LIBPNG 3 "August 28, 2017"
|
||||
.SH NAME
|
||||
libpng \- Portable Network Graphics (PNG) Reference Library 1.7.0beta80
|
||||
libpng \- Portable Network Graphics (PNG) Reference Library 1.7.0beta90
|
||||
.SH SYNOPSIS
|
||||
\fB
|
||||
#include <png.h>\fP
|
||||
@@ -500,10 +500,10 @@ 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.0beta80 - May 6, 2016
|
||||
libpng version 1.7.0beta90 - August 28, 2017
|
||||
Updated and distributed by Glenn Randers-Pehrson
|
||||
<glennrp at users.sourceforge.net>
|
||||
Copyright (c) 1998-2015 Glenn Randers-Pehrson
|
||||
Copyright (c) 1998-2017 Glenn Randers-Pehrson
|
||||
|
||||
This document is released under the libpng license.
|
||||
For conditions of distribution and use, see the disclaimer
|
||||
@@ -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.0beta80 - May 6, 2016
|
||||
libpng versions 0.97, January 1998, through 1.7.0beta90 - August 28, 2017
|
||||
Updated and distributed by Glenn Randers-Pehrson
|
||||
Copyright (c) 1998-2015 Glenn Randers-Pehrson
|
||||
|
||||
@@ -567,17 +567,17 @@ file format in application programs.
|
||||
|
||||
The PNG specification (second edition), November 2003, is available as
|
||||
a W3C Recommendation and as an ISO Standard (ISO/IEC 15948:2004 (E)) at
|
||||
<http://www.w3.org/TR/2003/REC-PNG-20031110/
|
||||
<https://www.w3.org/TR/2003/REC-PNG-20031110/
|
||||
The W3C and ISO documents have identical technical content.
|
||||
|
||||
The PNG-1.2 specification is available at
|
||||
<http://png-mng.sourceforge.net/pub/png/spec/1.2/>.
|
||||
<https://png-mng.sourceforge.io/pub/png/spec/1.2/>.
|
||||
It is technically equivalent
|
||||
to the PNG specification (second edition) but has some additional material.
|
||||
|
||||
The PNG-1.0 specification is available as RFC 2083
|
||||
<http://png-mng.sourceforge.net/pub/png/spec/1.0/> and as a
|
||||
W3C Recommendation <http://www.w3.org/TR/REC-png-961001>.
|
||||
The PNG-1.0 specification is available as RFC 2083
|
||||
<https://png-mng.sourceforge.io/pub/png/spec/1.0/> and as a
|
||||
W3C Recommendation <https://www.w3.org/TR/REC-png-961001>.
|
||||
|
||||
Some additional chunks are described in the special-purpose public chunks
|
||||
documents at <http://www.libpng.org/pub/png/spec/register/>
|
||||
@@ -602,7 +602,7 @@ majority of the needs of its users.
|
||||
|
||||
Libpng uses zlib for its compression and decompression of PNG files.
|
||||
Further information about zlib, and the latest version of zlib, can
|
||||
be found at the zlib home page, <http://zlib.net/>.
|
||||
be found at the zlib home page, <https://zlib.net/>.
|
||||
The zlib compression utility is a general purpose utility that is
|
||||
useful for more than PNG files, and can be used without libpng.
|
||||
See the documentation delivered with zlib for more details.
|
||||
@@ -971,8 +971,9 @@ the default, use
|
||||
|
||||
The values for png_set_crc_action() say how libpng is to handle CRC errors in
|
||||
ancillary and critical chunks, and whether to use the data contained
|
||||
therein. Note that it is impossible to "discard" data in a critical
|
||||
chunk.
|
||||
therein. Starting with libpng-1.6.26, this also governs how an ADLER32 error
|
||||
is handled while reading the IDAT chunk. Note that it is impossible to
|
||||
"discard" data in a critical chunk.
|
||||
|
||||
Choices for (int) crit_action are
|
||||
PNG_CRC_DEFAULT 0 error/quit
|
||||
@@ -989,6 +990,9 @@ Choices for (int) ancil_action are
|
||||
PNG_CRC_QUIET_USE 4 quiet/use data
|
||||
PNG_CRC_NO_CHANGE 5 use the current value
|
||||
|
||||
When the setting for crit_action is PNG_CRC_QUIET_USE, the CRC and ADLER32
|
||||
checksums are not only ignored, but they are not evaluated.
|
||||
|
||||
.SS Setting up callback code
|
||||
|
||||
You can set up a callback function to handle any unknown chunks in the
|
||||
@@ -1063,7 +1067,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.
|
||||
|
||||
@@ -4333,7 +4337,7 @@ The #defines to be used in png_image::format. Each #define identifies a
|
||||
particular layout of channel data and, if present, alpha values. There are
|
||||
separate defines for each of the two channel encodings.
|
||||
|
||||
A format is built up using single bit flag values. Not all combinations are
|
||||
A format is built up using one-bit flag values. Not all combinations are
|
||||
valid: use the bit flag values below for testing a format returned by the
|
||||
read APIs, but set formats from the derived values.
|
||||
|
||||
@@ -4546,7 +4550,7 @@ READ APIs
|
||||
|
||||
When the simplified API needs to convert between sRGB and linear colorspaces,
|
||||
the actual sRGB transfer curve defined in the sRGB specification (see the
|
||||
article at http://en.wikipedia.org/wiki/SRGB) is used, not the gamma=1/2.2
|
||||
article at https://en.wikipedia.org/wiki/SRGB) is used, not the gamma=1/2.2
|
||||
approximation used elsewhere in libpng.
|
||||
|
||||
WRITE APIS
|
||||
@@ -4723,7 +4727,7 @@ However, there are some uncertainties about the status of local variables
|
||||
after a longjmp, so the user may want to be careful about doing anything
|
||||
after setjmp returns non-zero besides returning itself. Consult your
|
||||
compiler documentation for more details. For an alternative approach, you
|
||||
may wish to use the "cexcept" facility (see http://cexcept.sourceforge.net),
|
||||
may wish to use the "cexcept" facility (see https://cexcept.sourceforge.io/),
|
||||
which is illustrated in pngvalid.c and in contrib/visupng.
|
||||
|
||||
Beginning in libpng-1.4.0, the png_set_benign_errors() API became available.
|
||||
@@ -4943,7 +4947,7 @@ in a MNG datastream. As a minimum, it must have the MNG 8-byte signature
|
||||
and the MHDR and MEND chunks. Libpng does not provide support for these
|
||||
or any other MNG chunks; your application must provide its own support for
|
||||
them. You may wish to consider using libmng (available at
|
||||
http://www.libmng.com) instead.
|
||||
https://www.libmng.com/) instead.
|
||||
|
||||
.SH VIII. Changes to Libpng from version 0.88
|
||||
|
||||
@@ -5685,27 +5689,33 @@ control. The git repository was built from old libpng-x.y.z.tar.gz files
|
||||
going back to version 0.70. You can access the git repository (read only)
|
||||
at
|
||||
|
||||
git://git.code.sf.net/p/libpng/code
|
||||
https://github.com/glennrp/libpng or
|
||||
https://git.code.sf.net/p/libpng/code.git
|
||||
|
||||
or you can browse it with a web browser by selecting the "code" button at
|
||||
or you can browse it with a web browser at
|
||||
|
||||
https://sourceforge.net/projects/libpng
|
||||
https://github.com/glennrp/libpng or
|
||||
https://sourceforge.net/p/libpng/code/ci/libpng16/tree/
|
||||
|
||||
Patches can be sent to glennrp at users.sourceforge.net or to
|
||||
png-mng-implement at lists.sourceforge.net or you can upload them to
|
||||
the libpng bug tracker at
|
||||
|
||||
http://libpng.sourceforge.net
|
||||
https://libpng.sourceforge.io/
|
||||
|
||||
or as a "pull request" to
|
||||
|
||||
https://github.com/glennrp/libpng/pulls
|
||||
|
||||
We also accept patches built from the tar or zip distributions, and
|
||||
simple verbal discriptions of bug fixes, reported either to the
|
||||
SourceForge bug tracker, to the png-mng-implement at lists.sf.net
|
||||
mailing list, or directly to glennrp.
|
||||
mailing list, as github issues, or directly to glennrp.
|
||||
|
||||
.SH XVI. Coding style
|
||||
|
||||
Our coding style is similar to the "Allman" style
|
||||
(See http://en.wikipedia.org/wiki/Indent_style#Allman_style), with curly
|
||||
(See https://en.wikipedia.org/wiki/Indent_style#Allman_style), with curly
|
||||
braces on separate lines:
|
||||
|
||||
if (condition)
|
||||
@@ -5747,6 +5757,19 @@ the statement that follows the comment:
|
||||
*/
|
||||
statement;
|
||||
|
||||
%17+%Linus Torvalds recomends putting the leading "/*" in multiple-line
|
||||
%17+%comments on a separate line:
|
||||
%17+%
|
||||
%17+% /*
|
||||
%17+% * This is a multiple-line
|
||||
%17+% * comment.
|
||||
%17+% */
|
||||
%17+% statement;
|
||||
%17+%
|
||||
%17+%See
|
||||
%17+%https://developers.slashdot.org/story/16/07/12/2036201
|
||||
%17+%/linus-torvalds-in-sweary-rant-about-punctuation-in-kernel-comments
|
||||
%17+%
|
||||
Very short comments can be placed after the end of the statement
|
||||
to which they pertain:
|
||||
|
||||
@@ -5806,7 +5829,7 @@ Prior to libpng-1.6.0 we used a "png_sizeof()" macro, formatted as
|
||||
though it were a function.
|
||||
|
||||
Control keywords if, for, while, and switch are always followed by a space
|
||||
to distinguish them from function calls, which have no trailing space.
|
||||
to distinguish them from function calls, which have no trailing space.
|
||||
|
||||
We put a space after each comma and after each semicolon
|
||||
in "for" statements, and we put spaces before and after each
|
||||
@@ -5828,8 +5851,9 @@ with an even number of lower-case hex digits (e.g., 0x00, 0xff, 0x0100).
|
||||
We prefer to use underscores in variable names rather than camelCase, except
|
||||
for a few type names that we inherit from zlib.h.
|
||||
|
||||
We prefer "if (something != 0)" and "if (something == 0)"
|
||||
over "if (something)" and if "(!something)", respectively.
|
||||
We prefer "if (something != 0)" and "if (something == 0)" over
|
||||
"if (something)" and if "(!something)", respectively, and for pointers
|
||||
we prefer "if (some_pointer != NULL)" or "if (some_pointer == NULL)".
|
||||
|
||||
We do not use the TAB character for indentation in the C sources.
|
||||
|
||||
@@ -5843,7 +5867,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.0beta80 are Y2K compliant. It is my belief that earlier
|
||||
upward through 1.7.0beta90 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 +5964,13 @@ 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.57 13 10257 12.so.0.56[.0]
|
||||
...
|
||||
1.5.23 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.5.28 15 10528 15.so.15.28[.0]
|
||||
...
|
||||
1.6.28 16 10628 16.so.16.28[.0]
|
||||
1.7.0alpha01-10 17 10700 17.so.17.0[.0]
|
||||
1.7.0beta01-80 17 10700 17.so.17.0[.0]
|
||||
1.7.0beta01-86 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
|
||||
@@ -5965,7 +5987,7 @@ release number plus "betaNN" or "rcNN".
|
||||
.LP
|
||||
.IR libpng :
|
||||
.IP
|
||||
http://libpng.sourceforge.net (follow the [DOWNLOAD] link)
|
||||
https://libpng.sourceforge.io/ (follow the [DOWNLOAD] link)
|
||||
http://www.libpng.org/pub/png
|
||||
|
||||
.LP
|
||||
@@ -5975,7 +5997,7 @@ http://www.libpng.org/pub/png
|
||||
.I libpng
|
||||
or at
|
||||
.br
|
||||
ftp://ftp.info-zip.org/pub/infozip/zlib
|
||||
https://zlib.net/
|
||||
|
||||
.LP
|
||||
.IR PNG specification: RFC 2083
|
||||
@@ -5984,11 +6006,11 @@ ftp://ftp.info-zip.org/pub/infozip/zlib
|
||||
.I libpng
|
||||
or at
|
||||
.br
|
||||
ftp://ftp.rfc-editor.org:/in-notes/rfc2083.txt
|
||||
https://www.ietf.org/rfc/rfc2083.txt
|
||||
.br
|
||||
or (as a W3C Recommendation) at
|
||||
.br
|
||||
http://www.w3.org/TR/REC-png.html
|
||||
https://www.w3.org/TR/REC-png.html
|
||||
|
||||
.LP
|
||||
In the case of any inconsistency between the PNG specification
|
||||
@@ -6004,7 +6026,7 @@ possible without all of you.
|
||||
|
||||
Thanks to Frank J. T. Wojcik for helping with the documentation.
|
||||
|
||||
Libpng version 1.7.0beta80 - May 6, 2016:
|
||||
Libpng version 1.7.0beta90 - August 28, 2017:
|
||||
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,8 +6051,8 @@ this sentence.
|
||||
|
||||
This code is released under the libpng license.
|
||||
|
||||
libpng versions 1.0.7, July 1, 2000, through 1.7.0beta80, May 6, 2016, are
|
||||
Copyright (c) 2000-2002, 2004, 2006-2016 Glenn Randers-Pehrson, are
|
||||
libpng versions 1.0.7, July 1, 2000 through 1.7.0beta90, August 28, 2017 are
|
||||
Copyright (c) 2000-2002, 2004, 2006-2017 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
|
||||
added to the list of Contributing Authors:
|
||||
@@ -6051,6 +6073,10 @@ and with the following additions to the disclaimer:
|
||||
risk of satisfactory quality, performance, accuracy, and effort is with
|
||||
the user.
|
||||
|
||||
Some files in the "contrib" directory and some configure-generated
|
||||
files that are distributed with libpng have other copyright owners and
|
||||
are released under other open source licenses.
|
||||
|
||||
libpng versions 0.97, January 1998, through 1.0.6, March 20, 2000, are
|
||||
Copyright (c) 1998-2000 Glenn Randers-Pehrson, are derived from
|
||||
libpng-0.96, and are distributed according to the same disclaimer and
|
||||
@@ -6074,6 +6100,9 @@ Contributing Authors:
|
||||
Greg Roelofs
|
||||
Tom Tanner
|
||||
|
||||
Some files in the "scripts" directory have other copyright owners
|
||||
but are released under this license.
|
||||
|
||||
libpng versions 0.5, May 1995, through 0.88, January 1996, are
|
||||
Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
|
||||
@@ -6114,6 +6143,29 @@ appreciated.
|
||||
|
||||
END OF COPYRIGHT NOTICE, DISCLAIMER, and LICENSE.
|
||||
|
||||
TRADEMARK:
|
||||
|
||||
The name "libpng" has not been registered by the Copyright owner
|
||||
as a trademark in any jurisdiction. However, because libpng has
|
||||
been distributed and maintained world-wide, continually since 1995,
|
||||
the Copyright owner claims "common-law trademark protection" in any
|
||||
jurisdiction where common-law trademark is recognized.
|
||||
|
||||
OSI CERTIFICATION:
|
||||
|
||||
Libpng is OSI Certified Open Source Software. OSI Certified Open Source is
|
||||
a certification mark of the Open Source Initiative. OSI has not addressed
|
||||
the additional disclaimers inserted at version 1.0.7.
|
||||
|
||||
EXPORT CONTROL:
|
||||
|
||||
The Copyright owner believes that the Export Control Classification
|
||||
Number (ECCN) for libpng is EAR99, which means not subject to export
|
||||
controls or International Traffic in Arms Regulations (ITAR) because
|
||||
it is open source, publicly available software, that does not contain
|
||||
any encryption software. See the EAR, paragraphs 734.3(b)(3) and
|
||||
734.7(b).
|
||||
|
||||
A "png_get_copyright" function is available, for convenient use in "about"
|
||||
boxes and the like:
|
||||
|
||||
@@ -6122,13 +6174,9 @@ boxes and the like:
|
||||
Also, the PNG logo (in PNG format, of course) is supplied in the
|
||||
files "pngbar.png" and "pngbar.jpg (88x31) and "pngnow.png" (98x31).
|
||||
|
||||
Libpng is OSI Certified Open Source Software. OSI Certified Open Source is
|
||||
a certification mark of the Open Source Initiative. OSI has not addressed
|
||||
the additional disclaimers inserted at version 1.0.7.
|
||||
|
||||
Glenn Randers-Pehrson
|
||||
glennrp at users.sourceforge.net
|
||||
May 6, 2016
|
||||
August 28, 2017
|
||||
|
||||
.\" end of man page
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
.TH LIBPNGPF 3 "May 6, 2016"
|
||||
.TH LIBPNGPF 3 "August 28, 2017"
|
||||
.SH NAME
|
||||
libpng \- Portable Network Graphics (PNG) Reference Library 1.7.0beta80
|
||||
libpng \- Portable Network Graphics (PNG) Reference Library 1.7.0beta90
|
||||
(private functions)
|
||||
.SH SYNOPSIS
|
||||
\fB#include \fI"pngpriv.h"
|
||||
|
||||
10
png.5
@@ -1,4 +1,4 @@
|
||||
.TH PNG 5 "May 6, 2016"
|
||||
.TH PNG 5 "August 28, 2017"
|
||||
.SH NAME
|
||||
png \- Portable Network Graphics (PNG) format
|
||||
.SH DESCRIPTION
|
||||
@@ -23,12 +23,12 @@ platforms.
|
||||
PNG specification (second edition), November 2003:
|
||||
.IP
|
||||
.br
|
||||
<http://www.w3.org/TR/2003/REC-PNG-20031110/
|
||||
<https://www.w3.org/TR/2003/REC-PNG-20031110/
|
||||
.LP
|
||||
PNG 1.2 specification, July 1999:
|
||||
.IP
|
||||
.br
|
||||
http://png-mng.sourceforge.net/pub/png/spec/1.2/
|
||||
https://png-mng.sourceforge.io/pub/png/spec/1.2/
|
||||
.LP
|
||||
PNG 1.0 specification, October 1996:
|
||||
.IP
|
||||
@@ -36,11 +36,11 @@ PNG 1.0 specification, October 1996:
|
||||
RFC 2083
|
||||
.IP
|
||||
.br
|
||||
ftp://ds.internic.net/rfc/rfc2083.txt
|
||||
https://www.ietf.org/rfc/rfc2083.txt
|
||||
.br
|
||||
or (as a W3C Recommendation) at
|
||||
.br
|
||||
http://www.w3.org/TR/REC-png-961001
|
||||
https://www.w3.org/TR/REC-png-961001
|
||||
.SH AUTHORS
|
||||
This man page: Glenn Randers-Pehrson
|
||||
.LP
|
||||
|
||||
464
png.c
@@ -2,7 +2,7 @@
|
||||
/* png.c - location for general purpose libpng functions
|
||||
*
|
||||
* Last changed in libpng 1.7.0 [(PENDING RELEASE)]
|
||||
* Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson
|
||||
* Copyright (c) 1998-2002,2004,2006-2017 Glenn Randers-Pehrson
|
||||
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
|
||||
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
|
||||
*
|
||||
@@ -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_0beta80 Your_png_h_is_not_version_1_7_0beta80;
|
||||
typedef png_libpng_version_1_7_0beta90 Your_png_h_is_not_version_1_7_0beta90;
|
||||
|
||||
/* 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
|
||||
@@ -81,7 +81,7 @@ png_zalloc,(voidpf png_ptr, uInt items, uInt size),PNG_ALLOCATED)
|
||||
if (items >= (~(png_alloc_size_t)0)/size)
|
||||
{
|
||||
png_warning(png_voidcast(png_structrp, png_ptr),
|
||||
"Potential overflow in png_zalloc()");
|
||||
"Potential overflow in png_zalloc()");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -311,7 +310,7 @@ png_create_png_struct,(png_const_charp user_png_ver, png_voidp error_ptr,
|
||||
if (png_user_version_check(&create_struct, user_png_ver) != 0)
|
||||
{
|
||||
png_structrp png_ptr = png_voidcast(png_structrp,
|
||||
png_malloc_warn(&create_struct, (sizeof *png_ptr)));
|
||||
png_malloc_warn(&create_struct, (sizeof *png_ptr)));
|
||||
|
||||
if (png_ptr != NULL)
|
||||
{
|
||||
@@ -353,7 +352,7 @@ png_create_info_struct,(png_const_structrp png_ptr),PNG_ALLOCATED)
|
||||
* has always been done in 'example.c'.
|
||||
*/
|
||||
info_ptr = png_voidcast(png_inforp, png_malloc_base(png_ptr,
|
||||
(sizeof *info_ptr)));
|
||||
(sizeof *info_ptr)));
|
||||
|
||||
if (info_ptr != NULL)
|
||||
memset(info_ptr, 0, (sizeof *info_ptr));
|
||||
@@ -400,7 +399,7 @@ png_destroy_info_struct(png_const_structrp png_ptr, png_infopp info_ptr_ptr)
|
||||
|
||||
void PNGAPI
|
||||
png_free_data(png_const_structrp png_ptr, png_inforp info_ptr, png_uint_32 mask,
|
||||
int num)
|
||||
int num)
|
||||
{
|
||||
png_debug(1, "in png_free_data");
|
||||
|
||||
@@ -428,6 +427,7 @@ png_free_data(png_const_structrp png_ptr, png_inforp info_ptr, png_uint_32 mask,
|
||||
png_free(png_ptr, info_ptr->text);
|
||||
info_ptr->text = NULL;
|
||||
info_ptr->num_text = 0;
|
||||
info_ptr->max_text = 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -705,15 +705,15 @@ png_get_copyright(png_const_structrp png_ptr)
|
||||
#else
|
||||
# ifdef __STDC__
|
||||
return PNG_STRING_NEWLINE \
|
||||
"libpng version 1.7.0beta80 - May 6, 2016" PNG_STRING_NEWLINE \
|
||||
"Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson" \
|
||||
"libpng version 1.7.0beta90 - August 28, 2017" PNG_STRING_NEWLINE \
|
||||
"Copyright (c) 1998-2002,2004,2006-2017 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.0beta80 - May 6, 2016\
|
||||
Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson\
|
||||
return "libpng version 1.7.0beta90 - August 28, 2017\
|
||||
Copyright (c) 1998-2002,2004,2006-2017 Glenn Randers-Pehrson\
|
||||
Copyright (c) 1996-1997 Andreas Dilger\
|
||||
Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.";
|
||||
# endif
|
||||
@@ -934,7 +934,7 @@ png_zstream_error(z_stream *zstream, int ret)
|
||||
#ifdef PNG_GAMMA_SUPPORTED /* always set if COLORSPACE */
|
||||
static int
|
||||
png_colorspace_check_gamma(png_const_structrp png_ptr,
|
||||
png_colorspacerp colorspace, png_fixed_point gAMA, int from)
|
||||
png_colorspacerp colorspace, png_fixed_point gAMA, int from)
|
||||
/* This is called to check a new gamma value against an existing one. The
|
||||
* routine returns false if the new gamma value should not be written.
|
||||
*
|
||||
@@ -954,7 +954,7 @@ png_colorspace_check_gamma(png_const_structrp png_ptr,
|
||||
png_fixed_point gtest;
|
||||
|
||||
if ((colorspace->flags & PNG_COLORSPACE_HAVE_GAMMA) != 0 &&
|
||||
(png_muldiv(>est, colorspace->gamma, PNG_FP_1, gAMA) == 0 ||
|
||||
(png_muldiv(>est, colorspace->gamma, PNG_FP_1, gAMA) == 0 ||
|
||||
gtest < PNG_FP_1 - 1000 || gtest > PNG_FP_1 + 1000))
|
||||
{
|
||||
/* Either this is an sRGB image, in which case the calculated gamma
|
||||
@@ -966,7 +966,7 @@ png_colorspace_check_gamma(png_const_structrp png_ptr,
|
||||
if ((colorspace->flags & PNG_COLORSPACE_FROM_sRGB) != 0 || from == 2)
|
||||
{
|
||||
png_chunk_report(png_ptr, "gamma value does not match sRGB",
|
||||
PNG_CHUNK_ERROR);
|
||||
PNG_CHUNK_ERROR);
|
||||
/* Do not overwrite an sRGB value */
|
||||
return from == 2;
|
||||
}
|
||||
@@ -974,7 +974,7 @@ png_colorspace_check_gamma(png_const_structrp png_ptr,
|
||||
else /* sRGB tag not involved */
|
||||
{
|
||||
png_chunk_report(png_ptr, "gamma value does not match libpng estimate",
|
||||
PNG_CHUNK_WARNING);
|
||||
PNG_CHUNK_WARNING);
|
||||
return from == 1;
|
||||
}
|
||||
}
|
||||
@@ -984,7 +984,7 @@ png_colorspace_check_gamma(png_const_structrp png_ptr,
|
||||
|
||||
void /* PRIVATE */
|
||||
png_colorspace_set_gamma(png_const_structrp png_ptr,
|
||||
png_colorspacerp colorspace, png_fixed_point gAMA)
|
||||
png_colorspacerp colorspace, png_fixed_point gAMA)
|
||||
{
|
||||
/* Changed in libpng-1.5.4 to limit the values to ensure overflow can't
|
||||
* occur. Since the fixed point representation is asymmetrical it is
|
||||
@@ -997,8 +997,13 @@ png_colorspace_set_gamma(png_const_structrp png_ptr,
|
||||
* In 1.6.0 this test replaces the ones in pngrutil.c, in the gAMA chunk
|
||||
* handling code, which only required the value to be >0.
|
||||
*/
|
||||
# define ERRMSG (defined PNG_TRANSFORM_MECH_SUPPORTED) &&\
|
||||
(defined PNG_ERROR_TEXT_SUPPORTED)
|
||||
# if (defined PNG_TRANSFORM_MECH_SUPPORTED) &&\
|
||||
(defined PNG_ERROR_TEXT_SUPPORTED)
|
||||
# define ERRMSG 1
|
||||
# else
|
||||
# define ERRMSG 0
|
||||
# endif
|
||||
|
||||
# if ERRMSG
|
||||
png_const_charp errmsg;
|
||||
# endif
|
||||
@@ -1574,8 +1579,8 @@ static const png_xy sRGB_xy = /* From ITU-R BT.709-3 */
|
||||
|
||||
static int
|
||||
png_colorspace_set_xy_and_XYZ(png_const_structrp png_ptr,
|
||||
png_colorspacerp colorspace, const png_xy *xy, const png_XYZ *XYZ,
|
||||
int preferred)
|
||||
png_colorspacerp colorspace, const png_xy *xy, const png_XYZ *XYZ,
|
||||
int preferred)
|
||||
{
|
||||
if ((colorspace->flags & PNG_COLORSPACE_INVALID) != 0)
|
||||
return 0;
|
||||
@@ -1622,7 +1627,7 @@ png_colorspace_set_xy_and_XYZ(png_const_structrp png_ptr,
|
||||
|
||||
int /* PRIVATE */
|
||||
png_colorspace_set_chromaticities(png_const_structrp png_ptr,
|
||||
png_colorspacerp colorspace, const png_xy *xy, int preferred)
|
||||
png_colorspacerp colorspace, const png_xy *xy, int preferred)
|
||||
{
|
||||
/* We must check the end points to ensure they are reasonable - in the past
|
||||
* color management systems have crashed as a result of getting bogus
|
||||
@@ -1636,7 +1641,7 @@ png_colorspace_set_chromaticities(png_const_structrp png_ptr,
|
||||
{
|
||||
case 0: /* success */
|
||||
return png_colorspace_set_xy_and_XYZ(png_ptr, colorspace, xy, &XYZ,
|
||||
preferred);
|
||||
preferred);
|
||||
|
||||
case 1:
|
||||
/* We can't invert the chromaticities so we can't produce value XYZ
|
||||
@@ -1660,7 +1665,7 @@ png_colorspace_set_chromaticities(png_const_structrp png_ptr,
|
||||
|
||||
int /* PRIVATE */
|
||||
png_colorspace_set_endpoints(png_const_structrp png_ptr,
|
||||
png_colorspacerp colorspace, const png_XYZ *XYZ_in, int preferred)
|
||||
png_colorspacerp colorspace, const png_XYZ *XYZ_in, int preferred)
|
||||
{
|
||||
png_XYZ XYZ = *XYZ_in;
|
||||
png_xy xy;
|
||||
@@ -1669,7 +1674,7 @@ png_colorspace_set_endpoints(png_const_structrp png_ptr,
|
||||
{
|
||||
case 0:
|
||||
return png_colorspace_set_xy_and_XYZ(png_ptr, colorspace, &xy, &XYZ,
|
||||
preferred);
|
||||
preferred);
|
||||
|
||||
case 1:
|
||||
/* End points are invalid. */
|
||||
@@ -1727,7 +1732,7 @@ is_ICC_signature(png_alloc_size_t it)
|
||||
|
||||
static int
|
||||
png_icc_profile_error(png_const_structrp png_ptr, png_colorspacerp colorspace,
|
||||
png_const_charp name, png_alloc_size_t value, png_const_charp reason)
|
||||
png_const_charp name, png_alloc_size_t value, png_const_charp reason)
|
||||
{
|
||||
size_t pos;
|
||||
char message[196]; /* see below for calculation */
|
||||
@@ -1752,8 +1757,8 @@ png_icc_profile_error(png_const_structrp png_ptr, png_colorspacerp colorspace,
|
||||
char number[PNG_NUMBER_BUFFER_SIZE]; /* +24 = 114*/
|
||||
|
||||
pos = png_safecat(message, (sizeof message), pos,
|
||||
png_format_number(number, number+(sizeof number),
|
||||
PNG_NUMBER_FORMAT_x, value));
|
||||
png_format_number(number, number+(sizeof number),
|
||||
PNG_NUMBER_FORMAT_x, value));
|
||||
pos = png_safecat(message, (sizeof message), pos, "h: "); /*+2 = 116*/
|
||||
}
|
||||
# endif
|
||||
@@ -1767,7 +1772,7 @@ png_icc_profile_error(png_const_structrp png_ptr, png_colorspacerp colorspace,
|
||||
* application errors the PNG won't be written.)
|
||||
*/
|
||||
png_chunk_report(png_ptr, message,
|
||||
(colorspace != NULL) ? PNG_CHUNK_ERROR : PNG_CHUNK_WRITE_ERROR);
|
||||
(colorspace != NULL) ? PNG_CHUNK_ERROR : PNG_CHUNK_WRITE_ERROR);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1776,7 +1781,7 @@ png_icc_profile_error(png_const_structrp png_ptr, png_colorspacerp colorspace,
|
||||
#ifdef PNG_sRGB_SUPPORTED
|
||||
int /* PRIVATE */
|
||||
png_colorspace_set_sRGB(png_const_structrp png_ptr, png_colorspacerp colorspace,
|
||||
int intent)
|
||||
int intent)
|
||||
{
|
||||
/* sRGB sets known gamma, end points and (from the chunk) intent. */
|
||||
/* IMPORTANT: these are not necessarily the values found in an ICC profile
|
||||
@@ -1813,10 +1818,10 @@ png_colorspace_set_sRGB(png_const_structrp png_ptr, png_colorspacerp colorspace,
|
||||
*/
|
||||
if (intent < 0 || intent >= PNG_sRGB_INTENT_LAST)
|
||||
return png_icc_profile_error(png_ptr, colorspace, "sRGB",
|
||||
(unsigned)intent, "invalid sRGB rendering intent");
|
||||
(unsigned)intent, "invalid sRGB rendering intent");
|
||||
|
||||
if ((colorspace->flags & PNG_COLORSPACE_HAVE_INTENT) != 0 &&
|
||||
colorspace->rendering_intent != intent)
|
||||
colorspace->rendering_intent != intent)
|
||||
return png_icc_profile_error(png_ptr, colorspace, "sRGB",
|
||||
(unsigned)intent, "inconsistent rendering intents");
|
||||
|
||||
@@ -1830,8 +1835,8 @@ png_colorspace_set_sRGB(png_const_structrp png_ptr, png_colorspacerp colorspace,
|
||||
* warn but overwrite the value with the correct one.
|
||||
*/
|
||||
if ((colorspace->flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0 &&
|
||||
!png_colorspace_endpoints_match(&sRGB_xy, &colorspace->end_points_xy,
|
||||
100))
|
||||
!png_colorspace_endpoints_match(&sRGB_xy, &colorspace->end_points_xy,
|
||||
100))
|
||||
png_chunk_report(png_ptr, "cHRM chunk does not match sRGB",
|
||||
PNG_CHUNK_ERROR);
|
||||
|
||||
@@ -1839,7 +1844,7 @@ png_colorspace_set_sRGB(png_const_structrp png_ptr, png_colorspacerp colorspace,
|
||||
* returns true when the 'from' argument corresponds to sRGB (2).
|
||||
*/
|
||||
(void)png_colorspace_check_gamma(png_ptr, colorspace, PNG_GAMMA_sRGB_INVERSE,
|
||||
2/*from sRGB*/);
|
||||
2/*from sRGB*/);
|
||||
|
||||
/* intent: bugs in GCC force 'int' to be used as the parameter type. */
|
||||
colorspace->rendering_intent = png_check_u16(png_ptr, intent);
|
||||
@@ -1874,23 +1879,23 @@ static const png_byte D50_nCIEXYZ[12] =
|
||||
|
||||
int /* PRIVATE */
|
||||
png_icc_check_length(png_const_structrp png_ptr, png_colorspacerp colorspace,
|
||||
png_const_charp name, png_uint_32 profile_length)
|
||||
png_const_charp name, png_uint_32 profile_length)
|
||||
{
|
||||
if (profile_length < 132)
|
||||
return png_icc_profile_error(png_ptr, colorspace, name, profile_length,
|
||||
"too short");
|
||||
"too short");
|
||||
|
||||
if (profile_length & 3)
|
||||
return png_icc_profile_error(png_ptr, colorspace, name, profile_length,
|
||||
"invalid length");
|
||||
"invalid length");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int /* PRIVATE */
|
||||
png_icc_check_header(png_const_structrp png_ptr, png_colorspacerp colorspace,
|
||||
png_const_charp name, png_uint_32 profile_length,
|
||||
png_const_bytep profile/* first 132 bytes only */, int is_color)
|
||||
png_const_charp name, png_uint_32 profile_length,
|
||||
png_const_bytep profile/* first 132 bytes only */, int is_color)
|
||||
{
|
||||
png_uint_32 temp;
|
||||
|
||||
@@ -1902,13 +1907,13 @@ png_icc_check_header(png_const_structrp png_ptr, png_colorspacerp colorspace,
|
||||
temp = png_get_uint_32(profile);
|
||||
if (temp != profile_length)
|
||||
return png_icc_profile_error(png_ptr, colorspace, name, temp,
|
||||
"length does not match profile");
|
||||
"length does not match profile");
|
||||
|
||||
temp = png_get_uint_32(profile+128); /* tag count: 12 bytes/tag */
|
||||
if (temp > 357913930 || /* (2^32-4-132)/12: maximum possible tag count */
|
||||
profile_length < 132+12*temp) /* truncated tag table */
|
||||
return png_icc_profile_error(png_ptr, colorspace, name, temp,
|
||||
"tag count too large");
|
||||
"tag count too large");
|
||||
|
||||
/* The 'intent' must be valid or we can't store it, ICC limits the intent to
|
||||
* 16 bits.
|
||||
@@ -1916,14 +1921,14 @@ png_icc_check_header(png_const_structrp png_ptr, png_colorspacerp colorspace,
|
||||
temp = png_get_uint_32(profile+64);
|
||||
if (temp >= 0xffff) /* The ICC limit */
|
||||
return png_icc_profile_error(png_ptr, colorspace, name, temp,
|
||||
"invalid rendering intent");
|
||||
"invalid rendering intent");
|
||||
|
||||
/* This is just a warning because the profile may be valid in future
|
||||
* versions.
|
||||
*/
|
||||
if (temp >= PNG_sRGB_INTENT_LAST)
|
||||
(void)png_icc_profile_error(png_ptr, NULL, name, temp,
|
||||
"intent outside defined range");
|
||||
"intent outside defined range");
|
||||
|
||||
/* At this point the tag table can't be checked because it hasn't necessarily
|
||||
* been loaded; however, various header fields can be checked. These checks
|
||||
@@ -1940,7 +1945,7 @@ png_icc_check_header(png_const_structrp png_ptr, png_colorspacerp colorspace,
|
||||
temp = png_get_uint_32(profile+36); /* signature 'ascp' */
|
||||
if (temp != 0x61637370)
|
||||
return png_icc_profile_error(png_ptr, colorspace, name, temp,
|
||||
"invalid signature");
|
||||
"invalid signature");
|
||||
|
||||
/* Currently the PCS illuminant/adopted white point (the computational
|
||||
* white point) are required to be D50,
|
||||
@@ -1951,7 +1956,7 @@ png_icc_check_header(png_const_structrp png_ptr, png_colorspacerp colorspace,
|
||||
*/
|
||||
if (memcmp(profile+68, D50_nCIEXYZ, 12) != 0)
|
||||
(void)png_icc_profile_error(png_ptr, NULL, name, 0/*no tag value*/,
|
||||
"PCS illuminant is not D50");
|
||||
"PCS illuminant is not D50");
|
||||
|
||||
/* The PNG spec requires this:
|
||||
* "If the iCCP chunk is present, the image samples conform to the colour
|
||||
@@ -1979,18 +1984,18 @@ png_icc_check_header(png_const_structrp png_ptr, png_colorspacerp colorspace,
|
||||
case 0x52474220: /* 'RGB ' */
|
||||
if (!is_color)
|
||||
return png_icc_profile_error(png_ptr, colorspace, name, temp,
|
||||
"RGB color space not permitted on grayscale PNG");
|
||||
"RGB color space not permitted on grayscale PNG");
|
||||
break;
|
||||
|
||||
case 0x47524159: /* 'GRAY' */
|
||||
if (is_color)
|
||||
return png_icc_profile_error(png_ptr, colorspace, name, temp,
|
||||
"Gray color space not permitted on RGB PNG");
|
||||
"Gray color space not permitted on RGB PNG");
|
||||
break;
|
||||
|
||||
default:
|
||||
return png_icc_profile_error(png_ptr, colorspace, name, temp,
|
||||
"invalid ICC profile color space");
|
||||
"invalid ICC profile color space");
|
||||
}
|
||||
|
||||
/* It is up to the application to check that the profile class matches the
|
||||
@@ -2015,7 +2020,7 @@ png_icc_check_header(png_const_structrp png_ptr, png_colorspacerp colorspace,
|
||||
case 0x61627374: /* 'abst' */
|
||||
/* May not be embedded in an image */
|
||||
return png_icc_profile_error(png_ptr, colorspace, name, temp,
|
||||
"invalid embedded Abstract ICC profile");
|
||||
"invalid embedded Abstract ICC profile");
|
||||
|
||||
case 0x6C696E6B: /* 'link' */
|
||||
/* DeviceLink profiles cannot be interpreted in a non-device specific
|
||||
@@ -2025,7 +2030,7 @@ png_icc_check_header(png_const_structrp png_ptr, png_colorspacerp colorspace,
|
||||
* PNG.
|
||||
*/
|
||||
return png_icc_profile_error(png_ptr, colorspace, name, temp,
|
||||
"unexpected DeviceLink ICC profile class");
|
||||
"unexpected DeviceLink ICC profile class");
|
||||
|
||||
case 0x6E6D636C: /* 'nmcl' */
|
||||
/* A NamedColor profile is also device specific, however it doesn't
|
||||
@@ -2033,7 +2038,7 @@ png_icc_check_header(png_const_structrp png_ptr, png_colorspacerp colorspace,
|
||||
* certainly it will fail the tests below.
|
||||
*/
|
||||
(void)png_icc_profile_error(png_ptr, NULL, name, temp,
|
||||
"unexpected NamedColor ICC profile class");
|
||||
"unexpected NamedColor ICC profile class");
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -2043,7 +2048,7 @@ png_icc_check_header(png_const_structrp png_ptr, png_colorspacerp colorspace,
|
||||
* understood profiles.
|
||||
*/
|
||||
(void)png_icc_profile_error(png_ptr, NULL, name, temp,
|
||||
"unrecognized ICC profile class");
|
||||
"unrecognized ICC profile class");
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -2059,7 +2064,7 @@ png_icc_check_header(png_const_structrp png_ptr, png_colorspacerp colorspace,
|
||||
|
||||
default:
|
||||
return png_icc_profile_error(png_ptr, colorspace, name, temp,
|
||||
"unexpected ICC PCS encoding");
|
||||
"unexpected ICC PCS encoding");
|
||||
}
|
||||
|
||||
return 1;
|
||||
@@ -2067,8 +2072,8 @@ png_icc_check_header(png_const_structrp png_ptr, png_colorspacerp colorspace,
|
||||
|
||||
int /* PRIVATE */
|
||||
png_icc_check_tag_table(png_const_structrp png_ptr, png_colorspacerp colorspace,
|
||||
png_const_charp name, png_uint_32 profile_length,
|
||||
png_const_bytep profile /* header plus whole tag table */)
|
||||
png_const_charp name, png_uint_32 profile_length,
|
||||
png_const_bytep profile /* header plus whole tag table */)
|
||||
{
|
||||
png_uint_32 tag_count = png_get_uint_32(profile+128);
|
||||
png_uint_32 itag;
|
||||
@@ -2096,7 +2101,7 @@ png_icc_check_tag_table(png_const_structrp png_ptr, png_colorspacerp colorspace,
|
||||
* alignment.
|
||||
*/
|
||||
(void)png_icc_profile_error(png_ptr, NULL, name, tag_id,
|
||||
"ICC profile tag start not a multiple of 4");
|
||||
"ICC profile tag start not a multiple of 4");
|
||||
}
|
||||
|
||||
/* This is a hard error; potentially it can cause read outside the
|
||||
@@ -2104,7 +2109,7 @@ png_icc_check_tag_table(png_const_structrp png_ptr, png_colorspacerp colorspace,
|
||||
*/
|
||||
if (tag_start > profile_length || tag_length > profile_length - tag_start)
|
||||
return png_icc_profile_error(png_ptr, colorspace, name, tag_id,
|
||||
"ICC profile tag outside profile");
|
||||
"ICC profile tag outside profile");
|
||||
}
|
||||
|
||||
return 1; /* success, maybe with warnings */
|
||||
@@ -2132,22 +2137,22 @@ static const struct
|
||||
*/
|
||||
/* adler32, crc32, MD5[4], intent, date, length, file-name */
|
||||
PNG_ICC_CHECKSUM(0x0a3fd9f6, 0x3b8772b9,
|
||||
PNG_MD5(0x29f83dde, 0xaff255ae, 0x7842fae4, 0xca83390d), 0, 0,
|
||||
"2009/03/27 21:36:31", 3048, "sRGB_IEC61966-2-1_black_scaled.icc")
|
||||
PNG_MD5(0x29f83dde, 0xaff255ae, 0x7842fae4, 0xca83390d), 0, 0,
|
||||
"2009/03/27 21:36:31", 3048, "sRGB_IEC61966-2-1_black_scaled.icc")
|
||||
|
||||
/* ICC sRGB v2 perceptual no black-compensation: */
|
||||
PNG_ICC_CHECKSUM(0x4909e5e1, 0x427ebb21,
|
||||
PNG_MD5(0xc95bd637, 0xe95d8a3b, 0x0df38f99, 0xc1320389), 1, 0,
|
||||
"2009/03/27 21:37:45", 3052, "sRGB_IEC61966-2-1_no_black_scaling.icc")
|
||||
PNG_MD5(0xc95bd637, 0xe95d8a3b, 0x0df38f99, 0xc1320389), 1, 0,
|
||||
"2009/03/27 21:37:45", 3052, "sRGB_IEC61966-2-1_no_black_scaling.icc")
|
||||
|
||||
PNG_ICC_CHECKSUM(0xfd2144a1, 0x306fd8ae,
|
||||
PNG_MD5(0xfc663378, 0x37e2886b, 0xfd72e983, 0x8228f1b8), 0, 0,
|
||||
"2009/08/10 17:28:01", 60988, "sRGB_v4_ICC_preference_displayclass.icc")
|
||||
PNG_MD5(0xfc663378, 0x37e2886b, 0xfd72e983, 0x8228f1b8), 0, 0,
|
||||
"2009/08/10 17:28:01", 60988, "sRGB_v4_ICC_preference_displayclass.icc")
|
||||
|
||||
/* ICC sRGB v4 perceptual */
|
||||
PNG_ICC_CHECKSUM(0x209c35d2, 0xbbef7812,
|
||||
PNG_MD5(0x34562abf, 0x994ccd06, 0x6d2c5721, 0xd0d68c5d), 0, 0,
|
||||
"2007/07/25 00:05:37", 60960, "sRGB_v4_ICC_preference.icc")
|
||||
PNG_MD5(0x34562abf, 0x994ccd06, 0x6d2c5721, 0xd0d68c5d), 0, 0,
|
||||
"2007/07/25 00:05:37", 60960, "sRGB_v4_ICC_preference.icc")
|
||||
|
||||
/* The following profiles have no known MD5 checksum. If there is a match
|
||||
* on the (empty) MD5 the other fields are used to attempt a match and
|
||||
@@ -2155,8 +2160,8 @@ static const struct
|
||||
* which suggests that they were also made by Hewlett Packard.
|
||||
*/
|
||||
PNG_ICC_CHECKSUM(0xa054d762, 0x5d5129ce,
|
||||
PNG_MD5(0x00000000, 0x00000000, 0x00000000, 0x00000000), 1, 0,
|
||||
"2004/07/21 18:57:42", 3024, "sRGB_IEC61966-2-1_noBPC.icc")
|
||||
PNG_MD5(0x00000000, 0x00000000, 0x00000000, 0x00000000), 1, 0,
|
||||
"2004/07/21 18:57:42", 3024, "sRGB_IEC61966-2-1_noBPC.icc")
|
||||
|
||||
/* This is a 'mntr' (display) profile with a mediaWhitePointTag that does not
|
||||
* match the D50 PCS illuminant in the header (it is in fact the D65 values,
|
||||
@@ -2166,17 +2171,17 @@ static const struct
|
||||
* chromaticAdaptationTag.
|
||||
*/
|
||||
PNG_ICC_CHECKSUM(0xf784f3fb, 0x182ea552,
|
||||
PNG_MD5(0x00000000, 0x00000000, 0x00000000, 0x00000000), 0, 1/*broken*/,
|
||||
"1998/02/09 06:49:00", 3144, "HP-Microsoft sRGB v2 perceptual")
|
||||
PNG_MD5(0x00000000, 0x00000000, 0x00000000, 0x00000000), 0, 1/*broken*/,
|
||||
"1998/02/09 06:49:00", 3144, "HP-Microsoft sRGB v2 perceptual")
|
||||
|
||||
PNG_ICC_CHECKSUM(0x0398f3fc, 0xf29e526d,
|
||||
PNG_MD5(0x00000000, 0x00000000, 0x00000000, 0x00000000), 1, 1/*broken*/,
|
||||
"1998/02/09 06:49:00", 3144, "HP-Microsoft sRGB v2 media-relative")
|
||||
PNG_MD5(0x00000000, 0x00000000, 0x00000000, 0x00000000), 1, 1/*broken*/,
|
||||
"1998/02/09 06:49:00", 3144, "HP-Microsoft sRGB v2 media-relative")
|
||||
};
|
||||
|
||||
static int
|
||||
png_compare_ICC_profile_with_sRGB(png_const_structrp png_ptr,
|
||||
png_const_bytep profile, uLong adler)
|
||||
png_const_bytep profile, uLong adler)
|
||||
{
|
||||
/* The quick check is to verify just the MD5 signature and trust the
|
||||
* rest of the data. Because the profile has already been verified for
|
||||
@@ -2192,13 +2197,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] &&
|
||||
@@ -2259,7 +2263,7 @@ png_compare_ICC_profile_with_sRGB(png_const_structrp png_ptr,
|
||||
* which is made irrelevant by this error.
|
||||
*/
|
||||
png_chunk_report(png_ptr, "known incorrect sRGB profile",
|
||||
PNG_CHUNK_ERROR);
|
||||
PNG_CHUNK_ERROR);
|
||||
}
|
||||
|
||||
/* Warn that this being done; this isn't even an error since
|
||||
@@ -2269,8 +2273,8 @@ png_compare_ICC_profile_with_sRGB(png_const_structrp png_ptr,
|
||||
else if (png_sRGB_checks[i].have_md5 == 0)
|
||||
{
|
||||
png_chunk_report(png_ptr,
|
||||
"out-of-date sRGB profile with no signature",
|
||||
PNG_CHUNK_WARNING);
|
||||
"out-of-date sRGB profile with no signature",
|
||||
PNG_CHUNK_WARNING);
|
||||
}
|
||||
|
||||
return 1+png_sRGB_checks[i].is_broken;
|
||||
@@ -2293,38 +2297,36 @@ 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,
|
||||
png_colorspacerp colorspace, png_const_bytep profile, uLong adler)
|
||||
png_colorspacerp colorspace, png_const_bytep profile, uLong adler)
|
||||
{
|
||||
/* 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 */
|
||||
png_colorspace_set_ICC(png_const_structrp png_ptr, png_colorspacerp colorspace,
|
||||
png_const_charp name, png_uint_32 profile_length, png_const_bytep profile,
|
||||
int is_color)
|
||||
png_const_charp name, png_uint_32 profile_length, png_const_bytep profile,
|
||||
int is_color)
|
||||
{
|
||||
if ((colorspace->flags & PNG_COLORSPACE_INVALID) != 0)
|
||||
return 0;
|
||||
|
||||
if (png_icc_check_length(png_ptr, colorspace, name, profile_length) != 0 &&
|
||||
png_icc_check_header(png_ptr, colorspace, name, profile_length, profile,
|
||||
is_color) != 0 &&
|
||||
is_color) != 0 &&
|
||||
png_icc_check_tag_table(png_ptr, colorspace, name, profile_length,
|
||||
profile) != 0)
|
||||
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
|
||||
@@ -2475,9 +2477,9 @@ png_copy_row(png_const_structrp png_ptr, png_bytep dp, png_const_bytep sp,
|
||||
|
||||
void /* PRIVATE */
|
||||
png_check_IHDR(png_const_structrp png_ptr,
|
||||
png_uint_32 width, png_uint_32 height, int bit_depth,
|
||||
int color_type, int interlace_type, int compression_type,
|
||||
int filter_type)
|
||||
png_uint_32 width, png_uint_32 height, int bit_depth,
|
||||
int color_type, int interlace_type, int compression_type,
|
||||
int filter_type)
|
||||
{
|
||||
int error = 0;
|
||||
|
||||
@@ -2633,7 +2635,7 @@ png_check_IHDR(png_const_structrp png_ptr,
|
||||
|
||||
int /* PRIVATE */
|
||||
png_check_fp_number(png_const_charp string, png_size_t size, int *statep,
|
||||
png_size_tp whereami)
|
||||
png_size_tp whereami)
|
||||
{
|
||||
int state = *statep;
|
||||
png_size_t i = *whereami;
|
||||
@@ -2789,7 +2791,7 @@ png_pow10(int power)
|
||||
if (power < 0)
|
||||
{
|
||||
if (power < DBL_MIN_10_EXP) return 0;
|
||||
recip = 1, power = -power;
|
||||
recip = 1; power = -power;
|
||||
}
|
||||
|
||||
if (power > 0)
|
||||
@@ -2867,7 +2869,9 @@ png_ascii_from_fp(png_const_structrp png_ptr, png_charp ascii, png_size_t size,
|
||||
double test = png_pow10(exp_b10+1);
|
||||
|
||||
if (test <= DBL_MAX)
|
||||
++exp_b10, base = test;
|
||||
{
|
||||
++exp_b10; base = test;
|
||||
}
|
||||
|
||||
else
|
||||
break;
|
||||
@@ -2881,7 +2885,10 @@ png_ascii_from_fp(png_const_structrp png_ptr, png_charp ascii, png_size_t size,
|
||||
* test on DBL_MAX above.
|
||||
*/
|
||||
fp /= base;
|
||||
while (fp >= 1) fp /= 10, ++exp_b10;
|
||||
while (fp >= 1)
|
||||
{
|
||||
fp /= 10; ++exp_b10;
|
||||
}
|
||||
|
||||
/* Because of the code above fp may, at this point, be
|
||||
* less than .1, this is ok because the code below can
|
||||
@@ -2932,7 +2939,7 @@ png_ascii_from_fp(png_const_structrp png_ptr, png_charp ascii, png_size_t size,
|
||||
/* Rounding up to 10, handle that here. */
|
||||
if (czero > 0)
|
||||
{
|
||||
--czero, d = 1;
|
||||
--czero; d = 1;
|
||||
if (cdigits == 0) --clead;
|
||||
}
|
||||
else
|
||||
@@ -2946,7 +2953,7 @@ png_ascii_from_fp(png_const_structrp png_ptr, png_charp ascii, png_size_t size,
|
||||
|
||||
else if (ch == 46)
|
||||
{
|
||||
ch = *--ascii, ++size;
|
||||
ch = *--ascii; ++size;
|
||||
/* Advance exp_b10 to '1', so that the
|
||||
* decimal point happens after the
|
||||
* previous digit.
|
||||
@@ -2973,7 +2980,9 @@ png_ascii_from_fp(png_const_structrp png_ptr, png_charp ascii, png_size_t size,
|
||||
int ch = *--ascii;
|
||||
|
||||
if (ch == 46)
|
||||
++size, exp_b10 = 1;
|
||||
{
|
||||
++size; exp_b10 = 1;
|
||||
}
|
||||
|
||||
/* Else lost a leading zero, so 'exp_b10' is
|
||||
* still ok at (-1)
|
||||
@@ -3064,7 +3073,7 @@ png_ascii_from_fp(png_const_structrp png_ptr, png_charp ascii, png_size_t size,
|
||||
*/
|
||||
size -= cdigits;
|
||||
|
||||
*ascii++ = 69, --size; /* 'E': PLUS 1 TOTAL 2+precision */
|
||||
*ascii++ = 69; --size; /* 'E': PLUS 1 TOTAL 2+precision */
|
||||
|
||||
/* The following use of an unsigned temporary avoids ambiguities in
|
||||
* the signed arithmetic on exp_b10 and permits GCC at least to do
|
||||
@@ -3180,7 +3189,10 @@ png_ascii_from_fixed(png_const_structrp png_ptr, png_charp ascii,
|
||||
* then ndigits digits to first:
|
||||
*/
|
||||
i = 5;
|
||||
while (ndigits < i) *ascii++ = 48, --i;
|
||||
while (ndigits < i)
|
||||
{
|
||||
*ascii++ = 48; --i;
|
||||
}
|
||||
while (ndigits >= first) *ascii++ = digits[--ndigits];
|
||||
/* Don't output the trailing zeros! */
|
||||
}
|
||||
@@ -3355,74 +3367,136 @@ 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) ||\
|
||||
defined(PNG_SIMPLIFIED_WRITE_SUPPORTED)
|
||||
/* sRGB conversion tables; these are machine generated with the code in
|
||||
* contrib/tools/makesRGB.c. The actual sRGB transfer curve defined in the
|
||||
* specification (see the article at http://en.wikipedia.org/wiki/SRGB)
|
||||
* specification (see the article at https://en.wikipedia.org/wiki/SRGB)
|
||||
* is used, not the gamma=1/2.2 approximation use elsewhere in libpng.
|
||||
* The sRGB to linear table is exact (to the nearest 16-bit linear fraction).
|
||||
* The inverse (linear to sRGB) table has accuracies as follows:
|
||||
|
||||
44
pngconf.h
@@ -1,7 +1,7 @@
|
||||
|
||||
/* pngconf.h - machine configurable file for libpng
|
||||
*
|
||||
* libpng version 1.7.0beta80, May 6, 2016
|
||||
* libpng version 1.7.0beta90, August 28, 2017
|
||||
*
|
||||
* Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson
|
||||
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
|
||||
@@ -188,27 +188,27 @@
|
||||
* compatible with GCC or Visual C because of different calling conventions.
|
||||
*/
|
||||
# if PNG_API_RULE == 2
|
||||
/* If this line results in an error, either because __watcall is not
|
||||
* understood or because of a redefine just below you cannot use *this*
|
||||
* build of the library with the compiler you are using. *This* build was
|
||||
* build using Watcom and applications must also be built using Watcom!
|
||||
*/
|
||||
/* If this line results in an error, either because __watcall is not
|
||||
* understood or because of a redefine just below you cannot use *this*
|
||||
* build of the library with the compiler you are using. *This* build was
|
||||
* build using Watcom and applications must also be built using Watcom!
|
||||
*/
|
||||
# define PNGCAPI __watcall
|
||||
# endif
|
||||
|
||||
# if defined(__GNUC__) || (defined(_MSC_VER) && (_MSC_VER >= 800))
|
||||
# define PNGCAPI __cdecl
|
||||
# if PNG_API_RULE == 1
|
||||
/* If this line results in an error __stdcall is not understood and
|
||||
* PNG_API_RULE should not have been set to '1'.
|
||||
*/
|
||||
/* If this line results in an error __stdcall is not understood and
|
||||
* PNG_API_RULE should not have been set to '1'.
|
||||
*/
|
||||
# define PNGAPI __stdcall
|
||||
# endif
|
||||
# else
|
||||
/* An older compiler, or one not detected (erroneously) above,
|
||||
* if necessary override on the command line to get the correct
|
||||
* variants for the compiler.
|
||||
*/
|
||||
/* An older compiler, or one not detected (erroneously) above,
|
||||
* if necessary override on the command line to get the correct
|
||||
* variants for the compiler.
|
||||
*/
|
||||
# ifndef PNGCAPI
|
||||
# define PNGCAPI _cdecl
|
||||
# endif
|
||||
@@ -225,10 +225,10 @@
|
||||
|
||||
# if (defined(_MSC_VER) && _MSC_VER < 800) ||\
|
||||
(defined(__BORLANDC__) && __BORLANDC__ < 0x500)
|
||||
/* older Borland and MSC
|
||||
* compilers used '__export' and required this to be after
|
||||
* the type.
|
||||
*/
|
||||
/* older Borland and MSC
|
||||
* compilers used '__export' and required this to be after
|
||||
* the type.
|
||||
*/
|
||||
# ifndef PNG_EXPORT_TYPE
|
||||
# define PNG_EXPORT_TYPE(type) type PNG_IMPEXP
|
||||
# endif
|
||||
@@ -244,9 +244,9 @@
|
||||
# if (defined(__IBMC__) || defined(__IBMCPP__)) && defined(__OS2__)
|
||||
# define PNGAPI _System
|
||||
# else /* !Windows/x86 && !OS/2 */
|
||||
/* Use the defaults, or define PNG*API on the command line (but
|
||||
* this will have to be done for every compile!)
|
||||
*/
|
||||
/* Use the defaults, or define PNG*API on the command line (but
|
||||
* this will have to be done for every compile!)
|
||||
*/
|
||||
# endif /* other system, !OS/2 */
|
||||
#endif /* !Windows/x86 */
|
||||
|
||||
@@ -267,7 +267,7 @@
|
||||
*/
|
||||
#ifndef PNG_IMPEXP
|
||||
# if defined(PNG_USE_DLL) && defined(PNG_DLL_IMPORT)
|
||||
/* This forces use of a DLL, disallowing static linking */
|
||||
/* This forces use of a DLL, disallowing static linking */
|
||||
# define PNG_IMPEXP PNG_DLL_IMPORT
|
||||
# endif
|
||||
|
||||
@@ -340,7 +340,7 @@
|
||||
* less efficient code.
|
||||
*/
|
||||
# if defined(__clang__) && defined(__has_attribute)
|
||||
/* Clang defines both __clang__ and __GNUC__. Check __clang__ first. */
|
||||
/* Clang defines both __clang__ and __GNUC__. Check __clang__ first. */
|
||||
# if !defined(PNG_USE_RESULT) && __has_attribute(__warn_unused_result__)
|
||||
# define PNG_USE_RESULT __attribute__((__warn_unused_result__))
|
||||
# endif
|
||||
|
||||
@@ -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
|
||||
|
||||
242
pngerror.c
@@ -27,7 +27,7 @@ static PNG_FUNCTION(void, png_default_error,PNGARG((png_const_structrp png_ptr,
|
||||
#ifdef PNG_WARNINGS_SUPPORTED
|
||||
static void /* PRIVATE */
|
||||
png_default_warning PNGARG((png_const_structrp png_ptr,
|
||||
png_const_charp warning_message));
|
||||
png_const_charp warning_message));
|
||||
#endif /* WARNINGS */
|
||||
|
||||
/* This function is called whenever there is a fatal error. This function
|
||||
@@ -38,48 +38,8 @@ png_default_warning PNGARG((png_const_structrp png_ptr,
|
||||
#ifdef PNG_ERROR_TEXT_SUPPORTED
|
||||
PNG_FUNCTION(void,PNGAPI
|
||||
png_error,(png_const_structrp png_ptr, png_const_charp error_message),
|
||||
PNG_NORETURN)
|
||||
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);
|
||||
@@ -111,7 +71,7 @@ png_err,(png_const_structrp png_ptr),PNG_NORETURN)
|
||||
*/
|
||||
size_t
|
||||
png_safecat(png_charp buffer, size_t bufsize, size_t pos,
|
||||
png_const_charp string)
|
||||
png_const_charp string)
|
||||
{
|
||||
if (buffer != NULL && pos < bufsize)
|
||||
{
|
||||
@@ -133,7 +93,7 @@ png_safecat(png_charp buffer, size_t bufsize, size_t pos,
|
||||
#define PNG_HAVE_FORMAT_NUMBER /* for the code below */
|
||||
png_charp
|
||||
png_format_number(png_const_charp start, png_charp end, int format,
|
||||
png_alloc_size_t number)
|
||||
png_alloc_size_t number)
|
||||
{
|
||||
int count = 0; /* number of digits output */
|
||||
int mincount = 1; /* minimum number required */
|
||||
@@ -218,24 +178,9 @@ 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);
|
||||
warning_message + offset);
|
||||
else
|
||||
png_default_warning(png_ptr, warning_message + offset);
|
||||
}
|
||||
@@ -247,7 +192,7 @@ png_warning(png_const_structrp png_ptr, png_const_charp warning_message)
|
||||
*/
|
||||
void
|
||||
png_warning_parameter(png_warning_parameters p, int number,
|
||||
png_const_charp string)
|
||||
png_const_charp string)
|
||||
{
|
||||
if (number > 0 && number <= PNG_WARNING_PARAMETER_COUNT)
|
||||
(void)png_safecat(p[number-1], (sizeof p[number-1]), 0, string);
|
||||
@@ -255,7 +200,7 @@ png_warning_parameter(png_warning_parameters p, int number,
|
||||
|
||||
void
|
||||
png_warning_parameter_unsigned(png_warning_parameters p, int number, int format,
|
||||
png_alloc_size_t value)
|
||||
png_alloc_size_t value)
|
||||
{
|
||||
char buffer[PNG_NUMBER_BUFFER_SIZE];
|
||||
png_warning_parameter(p, number, PNG_FORMAT_NUMBER(buffer, format, value));
|
||||
@@ -263,7 +208,7 @@ png_warning_parameter_unsigned(png_warning_parameters p, int number, int format,
|
||||
|
||||
void
|
||||
png_warning_parameter_signed(png_warning_parameters p, int number, int format,
|
||||
png_int_32 value)
|
||||
png_int_32 value)
|
||||
{
|
||||
png_alloc_size_t u;
|
||||
png_charp str;
|
||||
@@ -284,7 +229,7 @@ png_warning_parameter_signed(png_warning_parameters p, int number, int format,
|
||||
|
||||
void
|
||||
png_formatted_warning(png_const_structrp png_ptr, png_warning_parameters p,
|
||||
png_const_charp message)
|
||||
png_const_charp message)
|
||||
{
|
||||
/* The internal buffer is just 192 bytes - enough for all our messages,
|
||||
* overflow doesn't happen because this code checks! If someone figures
|
||||
@@ -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 */
|
||||
|
||||
@@ -485,10 +433,10 @@ png_format_buffer(png_const_structrp png_ptr, png_charp buffer, png_const_charp
|
||||
#if defined(PNG_READ_SUPPORTED) && defined(PNG_ERROR_TEXT_SUPPORTED)
|
||||
PNG_FUNCTION(void,PNGAPI
|
||||
png_chunk_error,(png_const_structrp png_ptr, png_const_charp error_message),
|
||||
PNG_NORETURN)
|
||||
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 */
|
||||
@@ -640,7 +596,7 @@ png_set_longjmp_fn(png_structrp png_ptr, png_longjmp_ptr longjmp_fn,
|
||||
else
|
||||
{
|
||||
png_ptr->jmp_buf_ptr = png_voidcast(jmp_buf *,
|
||||
png_malloc_warn(png_ptr, jmp_buf_size));
|
||||
png_malloc_warn(png_ptr, jmp_buf_size));
|
||||
|
||||
if (png_ptr->jmp_buf_ptr == NULL)
|
||||
return NULL; /* new NULL return on OOM */
|
||||
@@ -729,40 +685,9 @@ png_free_jmpbuf(png_structrp png_ptr)
|
||||
*/
|
||||
static PNG_FUNCTION(void /* PRIVATE */,
|
||||
png_default_error,(png_const_structrp png_ptr, png_const_charp error_message),
|
||||
PNG_NORETURN)
|
||||
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
|
||||
@@ -907,7 +789,7 @@ png_set_strip_error_numbers(png_structrp png_ptr, png_uint_32 strip_mode)
|
||||
*/
|
||||
PNG_FUNCTION(void /* PRIVATE */, (PNGCBAPI
|
||||
png_safe_error),(png_structp png_nonconst_ptr, png_const_charp error_message),
|
||||
PNG_NORETURN)
|
||||
PNG_NORETURN)
|
||||
{
|
||||
const png_const_structrp png_ptr = png_nonconst_ptr;
|
||||
png_imagep image = png_voidcast(png_imagep, png_ptr->error_ptr);
|
||||
@@ -930,7 +812,7 @@ png_safe_error),(png_structp png_nonconst_ptr, png_const_charp error_message),
|
||||
/* Missing longjmp buffer, the following is to help debugging: */
|
||||
{
|
||||
size_t pos = png_safecat(image->message, (sizeof image->message), 0,
|
||||
"bad longjmp: ");
|
||||
"bad longjmp: ");
|
||||
png_safecat(image->message, (sizeof image->message), pos,
|
||||
error_message);
|
||||
}
|
||||
|
||||
52
pngget.c
@@ -499,7 +499,7 @@ png_get_signature(png_const_structrp png_ptr, png_const_inforp info_ptr)
|
||||
#ifdef PNG_bKGD_SUPPORTED
|
||||
png_uint_32 PNGAPI
|
||||
png_get_bKGD(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
png_color_16p *background)
|
||||
png_color_16p *background)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_bKGD) != 0 &&
|
||||
@@ -539,28 +539,28 @@ png_get_cHRM(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
|
||||
if (white_x != NULL)
|
||||
*white_x = png_float(png_ptr,
|
||||
info_ptr->colorspace.end_points_xy.whitex, "cHRM white X");
|
||||
info_ptr->colorspace.end_points_xy.whitex, "cHRM white X");
|
||||
if (white_y != NULL)
|
||||
*white_y = png_float(png_ptr,
|
||||
info_ptr->colorspace.end_points_xy.whitey, "cHRM white Y");
|
||||
info_ptr->colorspace.end_points_xy.whitey, "cHRM white Y");
|
||||
if (red_x != NULL)
|
||||
*red_x = png_float(png_ptr, info_ptr->colorspace.end_points_xy.redx,
|
||||
"cHRM red X");
|
||||
"cHRM red X");
|
||||
if (red_y != NULL)
|
||||
*red_y = png_float(png_ptr, info_ptr->colorspace.end_points_xy.redy,
|
||||
"cHRM red Y");
|
||||
"cHRM red Y");
|
||||
if (green_x != NULL)
|
||||
*green_x = png_float(png_ptr,
|
||||
info_ptr->colorspace.end_points_xy.greenx, "cHRM green X");
|
||||
info_ptr->colorspace.end_points_xy.greenx, "cHRM green X");
|
||||
if (green_y != NULL)
|
||||
*green_y = png_float(png_ptr,
|
||||
info_ptr->colorspace.end_points_xy.greeny, "cHRM green Y");
|
||||
info_ptr->colorspace.end_points_xy.greeny, "cHRM green Y");
|
||||
if (blue_x != NULL)
|
||||
*blue_x = png_float(png_ptr, info_ptr->colorspace.end_points_xy.bluex,
|
||||
"cHRM blue X");
|
||||
"cHRM blue X");
|
||||
if (blue_y != NULL)
|
||||
*blue_y = png_float(png_ptr, info_ptr->colorspace.end_points_xy.bluey,
|
||||
"cHRM blue Y");
|
||||
"cHRM blue Y");
|
||||
return (PNG_INFO_cHRM);
|
||||
}
|
||||
|
||||
@@ -569,42 +569,42 @@ png_get_cHRM(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
|
||||
png_uint_32 PNGAPI
|
||||
png_get_cHRM_XYZ(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
double *red_X, double *red_Y, double *red_Z, double *green_X,
|
||||
double *green_Y, double *green_Z, double *blue_X, double *blue_Y,
|
||||
double *blue_Z)
|
||||
double *red_X, double *red_Y, double *red_Z, double *green_X,
|
||||
double *green_Y, double *green_Z, double *blue_X, double *blue_Y,
|
||||
double *blue_Z)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0)
|
||||
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "cHRM_XYZ(float)");
|
||||
|
||||
if (red_X != NULL)
|
||||
*red_X = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_X,
|
||||
"cHRM red X");
|
||||
"cHRM red X");
|
||||
if (red_Y != NULL)
|
||||
*red_Y = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_Y,
|
||||
"cHRM red Y");
|
||||
"cHRM red Y");
|
||||
if (red_Z != NULL)
|
||||
*red_Z = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_Z,
|
||||
"cHRM red Z");
|
||||
"cHRM red Z");
|
||||
if (green_X != NULL)
|
||||
*green_X = png_float(png_ptr,
|
||||
info_ptr->colorspace.end_points_XYZ.green_X, "cHRM green X");
|
||||
info_ptr->colorspace.end_points_XYZ.green_X, "cHRM green X");
|
||||
if (green_Y != NULL)
|
||||
*green_Y = png_float(png_ptr,
|
||||
info_ptr->colorspace.end_points_XYZ.green_Y, "cHRM green Y");
|
||||
info_ptr->colorspace.end_points_XYZ.green_Y, "cHRM green Y");
|
||||
if (green_Z != NULL)
|
||||
*green_Z = png_float(png_ptr,
|
||||
info_ptr->colorspace.end_points_XYZ.green_Z, "cHRM green Z");
|
||||
info_ptr->colorspace.end_points_XYZ.green_Z, "cHRM green Z");
|
||||
if (blue_X != NULL)
|
||||
*blue_X = png_float(png_ptr,
|
||||
info_ptr->colorspace.end_points_XYZ.blue_X, "cHRM blue X");
|
||||
info_ptr->colorspace.end_points_XYZ.blue_X, "cHRM blue X");
|
||||
if (blue_Y != NULL)
|
||||
*blue_Y = png_float(png_ptr,
|
||||
info_ptr->colorspace.end_points_XYZ.blue_Y, "cHRM blue Y");
|
||||
info_ptr->colorspace.end_points_XYZ.blue_Y, "cHRM blue Y");
|
||||
if (blue_Z != NULL)
|
||||
*blue_Z = png_float(png_ptr,
|
||||
info_ptr->colorspace.end_points_XYZ.blue_Z, "cHRM blue Z");
|
||||
info_ptr->colorspace.end_points_XYZ.blue_Z, "cHRM blue Z");
|
||||
return (PNG_INFO_cHRM);
|
||||
}
|
||||
|
||||
@@ -694,8 +694,8 @@ png_get_gAMA_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
png_debug1(1, "in %s retrieval function", "gAMA");
|
||||
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) != 0 &&
|
||||
file_gamma != NULL)
|
||||
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) != 0 &&
|
||||
file_gamma != NULL)
|
||||
{
|
||||
*file_gamma = info_ptr->colorspace.gamma;
|
||||
return (PNG_INFO_gAMA);
|
||||
@@ -717,7 +717,7 @@ png_get_gAMA(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
file_gamma != NULL)
|
||||
{
|
||||
*file_gamma = png_float(png_ptr, info_ptr->colorspace.gamma,
|
||||
"png_get_gAMA");
|
||||
"png_get_gAMA");
|
||||
return (PNG_INFO_gAMA);
|
||||
}
|
||||
|
||||
@@ -904,7 +904,7 @@ png_get_sCAL_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
*/
|
||||
*width = png_fixed(png_ptr, atof(info_ptr->scal_s_width), "sCAL width");
|
||||
*height = png_fixed(png_ptr, atof(info_ptr->scal_s_height),
|
||||
"sCAL height");
|
||||
"sCAL height");
|
||||
return (PNG_INFO_sCAL);
|
||||
}
|
||||
|
||||
|
||||
14
pngmem.c
@@ -67,7 +67,7 @@ png_calloc,(png_const_structrp png_ptr, png_alloc_size_t size),PNG_ALLOCATED)
|
||||
*/
|
||||
PNG_FUNCTION(png_voidp /* PRIVATE */,
|
||||
png_malloc_base,(png_const_structrp png_ptr, png_alloc_size_t size),
|
||||
PNG_ALLOCATED)
|
||||
PNG_ALLOCATED)
|
||||
{
|
||||
/* Moved to png_malloc_base from png_malloc_default in 1.6.0; the DOS
|
||||
* allocators have also been removed in 1.6.0, so any 16-bit system now has
|
||||
@@ -112,7 +112,7 @@ png_malloc_base,(png_const_structrp png_ptr, png_alloc_size_t size),
|
||||
*/
|
||||
static png_voidp
|
||||
png_malloc_array_checked(png_const_structrp png_ptr, int nelements,
|
||||
size_t element_size)
|
||||
size_t element_size)
|
||||
{
|
||||
png_alloc_size_t req = nelements; /* known to be > 0 */
|
||||
|
||||
@@ -125,7 +125,7 @@ png_malloc_array_checked(png_const_structrp png_ptr, int nelements,
|
||||
|
||||
PNG_FUNCTION(png_voidp /* PRIVATE */,
|
||||
png_malloc_array,(png_const_structrp png_ptr, int nelements,
|
||||
size_t element_size),PNG_ALLOCATED)
|
||||
size_t element_size),PNG_ALLOCATED)
|
||||
{
|
||||
affirm(nelements > 0 && element_size > 0);
|
||||
return png_malloc_array_checked(png_ptr, nelements, element_size);
|
||||
@@ -133,7 +133,7 @@ png_malloc_array,(png_const_structrp png_ptr, int nelements,
|
||||
|
||||
PNG_FUNCTION(png_voidp /* PRIVATE */,
|
||||
png_realloc_array,(png_structrp png_ptr, png_const_voidp old_array,
|
||||
int old_elements, int add_elements, size_t element_size),PNG_ALLOCATED)
|
||||
int old_elements, int add_elements, size_t element_size),PNG_ALLOCATED)
|
||||
{
|
||||
/* These are internal errors: */
|
||||
affirm(add_elements > 0 && element_size > 0 && old_elements >= 0 &&
|
||||
@@ -145,7 +145,7 @@ png_realloc_array,(png_structrp png_ptr, png_const_voidp old_array,
|
||||
if (add_elements <= INT_MAX - old_elements)
|
||||
{
|
||||
png_voidp new_array = png_malloc_array_checked(png_ptr,
|
||||
old_elements+add_elements, element_size);
|
||||
old_elements+add_elements, element_size);
|
||||
|
||||
if (new_array != NULL)
|
||||
{
|
||||
@@ -156,7 +156,7 @@ png_realloc_array,(png_structrp png_ptr, png_const_voidp old_array,
|
||||
memcpy(new_array, old_array, element_size*(unsigned)old_elements);
|
||||
|
||||
memset((char*)new_array + element_size*(unsigned)old_elements, 0,
|
||||
element_size*(unsigned)add_elements);
|
||||
element_size*(unsigned)add_elements);
|
||||
|
||||
return new_array;
|
||||
}
|
||||
@@ -201,7 +201,7 @@ png_malloc,(png_const_structrp png_ptr, png_alloc_size_t size),PNG_ALLOCATED)
|
||||
*/
|
||||
PNG_FUNCTION(png_voidp,PNGAPI
|
||||
png_malloc_warn,(png_const_structrp png_ptr, png_alloc_size_t size),
|
||||
PNG_ALLOCATED)
|
||||
PNG_ALLOCATED)
|
||||
{
|
||||
if (png_ptr != NULL)
|
||||
{
|
||||
|
||||
22
pngpread.c
@@ -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;
|
||||
|
||||
@@ -193,7 +195,7 @@ png_process_data_skip(png_structrp png_ptr)
|
||||
|
||||
static void
|
||||
png_push_restore_buffer(png_structrp png_ptr, png_bytep buffer,
|
||||
png_size_t buffer_length)
|
||||
png_size_t buffer_length)
|
||||
{
|
||||
png_ptr->current_buffer_size = buffer_length;
|
||||
png_ptr->buffer_size = buffer_length + png_ptr->save_buffer_size;
|
||||
@@ -734,15 +736,15 @@ 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);
|
||||
png_check_chunk_name(png_ptr, png_ptr->chunk_name);
|
||||
png_check_chunk_length(png_ptr, png_ptr->chunk_length);
|
||||
mode = png_ptr->mode;
|
||||
png_ptr->process_mode = png_check_bits(png_ptr,
|
||||
png_read_chunk+png_find_chunk_op(png_ptr), 4);
|
||||
|
||||
97
pngpriv.h
@@ -319,9 +319,13 @@
|
||||
* is just the affirm code; there's no reason to allow configuration of this
|
||||
* option.
|
||||
*/
|
||||
#define PNG_AFFIRM_TEXT (PNG_RELEASE_BUILD ?\
|
||||
(defined PNG_ERROR_TEXT_SUPPORTED) :\
|
||||
(defined PNG_WARNINGS_SUPPORTED) || (defined PNG_CONSOLE_IO_SUPPORTED))
|
||||
#if PNG_RELEASE_BUILD ?\
|
||||
(defined PNG_ERROR_TEXT_SUPPORTED) :\
|
||||
(defined PNG_WARNINGS_SUPPORTED) || (defined PNG_CONSOLE_IO_SUPPORTED)
|
||||
# define PNG_AFFIRM_TEXT 1
|
||||
#else
|
||||
# define PNG_AFFIRM_TEXT 0
|
||||
#endif /* PNG_AFFIRM_TEXT definition */
|
||||
|
||||
#define PNG_SRC_LINE (PNG_SRC_FILE + __LINE__)
|
||||
|
||||
@@ -390,7 +394,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 +622,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 +956,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 +1026,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,
|
||||
@@ -1107,7 +1087,7 @@ PNG_INTERNAL_FUNCTION(void,png_write_sBIT,(png_structrp png_ptr,
|
||||
#ifdef PNG_WRITE_cHRM_SUPPORTED
|
||||
PNG_INTERNAL_FUNCTION(void,png_write_cHRM_fixed,(png_structrp png_ptr,
|
||||
const png_xy *xy), PNG_EMPTY);
|
||||
/* The xy value must have been previously validated */
|
||||
/* The xy value must have been previously validated */
|
||||
#endif
|
||||
|
||||
#ifdef PNG_WRITE_sRGB_SUPPORTED
|
||||
@@ -1378,7 +1358,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.
|
||||
@@ -1726,7 +1711,6 @@ PNG_INTERNAL_FUNCTION(int,png_read_finish_IDAT,(png_structrp png_ptr),
|
||||
* is more IDAT data available the caller should output an
|
||||
* appropriate (too much IDAT) error message.
|
||||
*/
|
||||
#endif /* READ */
|
||||
|
||||
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
|
||||
PNG_INTERNAL_FUNCTION(void,png_cache_known_unknown,(png_structrp png_ptr,
|
||||
@@ -1753,6 +1737,12 @@ PNG_INTERNAL_FUNCTION(png_chunk_op,png_find_chunk_op,(png_structrp png_ptr),
|
||||
* read state.
|
||||
*/
|
||||
|
||||
PNG_INTERNAL_FUNCTION(void,png_check_chunk_name,(png_const_structrp png_ptr,
|
||||
const png_uint_32 chunk_name),PNG_EMPTY);
|
||||
|
||||
PNG_INTERNAL_FUNCTION(void,png_check_chunk_length,(png_const_structrp png_ptr,
|
||||
const png_uint_32 chunk_length),PNG_EMPTY);
|
||||
|
||||
#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
|
||||
PNG_INTERNAL_FUNCTION(void,png_handle_unknown,(png_structrp png_ptr,
|
||||
png_inforp info_ptr, png_bytep chunk_data),PNG_EMPTY);
|
||||
@@ -1771,6 +1761,7 @@ PNG_INTERNAL_FUNCTION(void,png_handle_chunk,(png_structrp png_ptr,
|
||||
* has returned png_chunk_process_all and all the data is available for
|
||||
* png_handle_chunk (via the libpng read callback.)
|
||||
*/
|
||||
#endif /* READ */
|
||||
|
||||
PNG_INTERNAL_FUNCTION(void,png_init_row_info,(png_structrp png_ptr),PNG_EMPTY);
|
||||
/* Set the png_struct::row_ members from the PNG file information, running
|
||||
@@ -1788,13 +1779,13 @@ PNG_INTERNAL_FUNCTION(void,png_colorspace_set_gamma,(png_const_structrp png_ptr,
|
||||
|
||||
PNG_INTERNAL_FUNCTION(void,png_colorspace_sync_info,(png_const_structrp png_ptr,
|
||||
png_inforp info_ptr), PNG_EMPTY);
|
||||
/* Synchronize the info 'valid' flags with the colorspace */
|
||||
/* Synchronize the info 'valid' flags with the colorspace */
|
||||
|
||||
PNG_INTERNAL_FUNCTION(void,png_colorspace_sync,(png_const_structrp png_ptr,
|
||||
png_inforp info_ptr), PNG_EMPTY);
|
||||
/* Copy the png_struct colorspace to the info_struct and call the above to
|
||||
* synchronize the flags. Checks for NULL info_ptr and does nothing.
|
||||
*/
|
||||
/* Copy the png_struct colorspace to the info_struct and call the above to
|
||||
* synchronize the flags. Checks for NULL info_ptr and does nothing.
|
||||
*/
|
||||
#endif
|
||||
|
||||
/* Added at libpng version 1.4.0 */
|
||||
@@ -2136,6 +2127,14 @@ PNG_INTERNAL_FUNCTION(unsigned int,png_gamma_nxmbit_correct,
|
||||
/* In this case the value must have 'n' bits and the output will have 'm'
|
||||
* bits.
|
||||
*/
|
||||
|
||||
#if !PNG_RELEASE_BUILD
|
||||
PNG_INTERNAL_FUNCTION(int,png_gamma_check,(png_const_structrp png_ptr,
|
||||
png_const_transform_controlp tc),PNG_EMPTY);
|
||||
/* Debugging only routine to repeat the test used above to determine if the
|
||||
* gamma was insignificant.
|
||||
*/
|
||||
#endif /* !RELEASE_BUILD */
|
||||
#endif /* READ_GAMMA */
|
||||
|
||||
#ifdef PNG_SIMPLIFIED_READ_SUPPORTED
|
||||
@@ -2225,6 +2224,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
|
||||
@@ -2243,8 +2256,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 */
|
||||
|
||||
315
pngread.c
@@ -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,
|
||||
@@ -97,10 +28,10 @@ png_create_read_struct,(png_const_charp user_png_ver, png_voidp error_ptr,
|
||||
{
|
||||
#ifndef PNG_USER_MEM_SUPPORTED
|
||||
png_structp png_ptr = png_create_png_struct(user_png_ver, error_ptr,
|
||||
error_fn, warn_fn, NULL, NULL, NULL);
|
||||
error_fn, warn_fn, NULL, NULL, NULL);
|
||||
#else
|
||||
return png_create_read_struct_2(user_png_ver, error_ptr, error_fn,
|
||||
warn_fn, NULL, NULL, NULL);
|
||||
warn_fn, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
/* Alternate create PNG structure for reading, and allocate any memory
|
||||
@@ -112,36 +43,48 @@ png_create_read_struct_2,(png_const_charp user_png_ver, png_voidp error_ptr,
|
||||
png_malloc_ptr malloc_fn, png_free_ptr free_fn),PNG_ALLOCATED)
|
||||
{
|
||||
png_structp png_ptr = png_create_png_struct(user_png_ver, error_ptr,
|
||||
error_fn, warn_fn, mem_ptr, malloc_fn, free_fn);
|
||||
error_fn, warn_fn, mem_ptr, malloc_fn, free_fn);
|
||||
#endif /* USER_MEM */
|
||||
|
||||
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);
|
||||
}
|
||||
@@ -301,7 +245,7 @@ png_start_read_image(png_structrp png_ptr)
|
||||
*/
|
||||
else
|
||||
png_app_error(png_ptr,
|
||||
"png_start_read_image/png_read_update_info: duplicate call");
|
||||
"png_start_read_image/png_read_update_info: duplicate call");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -834,7 +779,7 @@ png_gt(size_t a, size_t b)
|
||||
|
||||
void PNGAPI
|
||||
png_read_png(png_structrp png_ptr, png_inforp info_ptr, int transforms,
|
||||
voidp params)
|
||||
voidp params)
|
||||
{
|
||||
if (png_ptr == NULL || info_ptr == NULL)
|
||||
return;
|
||||
@@ -1110,7 +1055,7 @@ png_image_read_init(png_imagep image)
|
||||
if (info_ptr != NULL)
|
||||
{
|
||||
png_controlp control = png_voidcast(png_controlp,
|
||||
png_malloc_warn(png_ptr, (sizeof *control)));
|
||||
png_malloc_warn(png_ptr, (sizeof *control)));
|
||||
|
||||
if (control != NULL)
|
||||
{
|
||||
@@ -1186,7 +1131,9 @@ png_image_read_header(png_voidp argument)
|
||||
png_structrp png_ptr = image->opaque->png_ptr;
|
||||
png_inforp info_ptr = image->opaque->info_ptr;
|
||||
|
||||
#ifdef PNG_BENIGN_ERRORS_SUPPORTED
|
||||
png_set_benign_errors(png_ptr, 1/*warn*/);
|
||||
#endif
|
||||
png_read_info(png_ptr, info_ptr);
|
||||
|
||||
/* Do this the fast way; just read directly out of png_struct. */
|
||||
@@ -1297,12 +1244,12 @@ png_image_begin_read_from_stdio(png_imagep image, FILE* file)
|
||||
|
||||
else
|
||||
return png_image_error(image,
|
||||
"png_image_begin_read_from_stdio: invalid argument");
|
||||
"png_image_begin_read_from_stdio: invalid argument");
|
||||
}
|
||||
|
||||
else if (image != NULL)
|
||||
return png_image_error(image,
|
||||
"png_image_begin_read_from_stdio: incorrect PNG_IMAGE_VERSION");
|
||||
"png_image_begin_read_from_stdio: incorrect PNG_IMAGE_VERSION");
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1335,12 +1282,12 @@ png_image_begin_read_from_file(png_imagep image, const char *file_name)
|
||||
|
||||
else
|
||||
return png_image_error(image,
|
||||
"png_image_begin_read_from_file: invalid argument");
|
||||
"png_image_begin_read_from_file: invalid argument");
|
||||
}
|
||||
|
||||
else if (image != NULL)
|
||||
return png_image_error(image,
|
||||
"png_image_begin_read_from_file: incorrect PNG_IMAGE_VERSION");
|
||||
"png_image_begin_read_from_file: incorrect PNG_IMAGE_VERSION");
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1389,7 +1336,7 @@ image_init_memory_io(png_voidp param)
|
||||
|
||||
int PNGAPI
|
||||
png_image_begin_read_from_memory(png_imagep image, png_const_voidp memory,
|
||||
png_size_t size)
|
||||
png_size_t size)
|
||||
{
|
||||
if (image != NULL && image->version == PNG_IMAGE_VERSION)
|
||||
{
|
||||
@@ -1411,12 +1358,12 @@ png_image_begin_read_from_memory(png_imagep image, png_const_voidp memory,
|
||||
|
||||
else
|
||||
return png_image_error(image,
|
||||
"png_image_begin_read_from_memory: invalid argument");
|
||||
"png_image_begin_read_from_memory: invalid argument");
|
||||
}
|
||||
|
||||
else if (image != NULL)
|
||||
return png_image_error(image,
|
||||
"png_image_begin_read_from_memory: incorrect PNG_IMAGE_VERSION");
|
||||
"png_image_begin_read_from_memory: incorrect PNG_IMAGE_VERSION");
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1462,12 +1409,12 @@ png_image_skip_unused_chunks(png_structrp png_ptr)
|
||||
* IHDR, PLTE, tRNS, IDAT, and IEND chunks.
|
||||
*/
|
||||
png_set_keep_unknown_chunks(png_ptr, PNG_HANDLE_CHUNK_NEVER,
|
||||
NULL, -1);
|
||||
NULL, -1);
|
||||
|
||||
/* But do not ignore image data handling chunks */
|
||||
png_set_keep_unknown_chunks(png_ptr, PNG_HANDLE_CHUNK_AS_DEFAULT,
|
||||
chunks_to_process, (int)/*SAFE*/(sizeof chunks_to_process)/5);
|
||||
}
|
||||
chunks_to_process, (int)/*SAFE*/(sizeof chunks_to_process)/5);
|
||||
}
|
||||
}
|
||||
|
||||
# define PNG_SKIP_CHUNKS(p) png_image_skip_unused_chunks(p)
|
||||
@@ -1669,7 +1616,7 @@ decode_gamma(png_image_read_control *display, png_uint_32 value,
|
||||
|
||||
default:
|
||||
png_impossiblepp(display->image->opaque->png_ptr,
|
||||
"unexpected encoding");
|
||||
"unexpected encoding");
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1678,9 +1625,9 @@ decode_gamma(png_image_read_control *display, png_uint_32 value,
|
||||
|
||||
static png_uint_32
|
||||
png_colormap_compose(png_image_read_control *display,
|
||||
png_uint_32 foreground, unsigned int foreground_significant_bits,
|
||||
int foreground_encoding, png_uint_32 alpha,
|
||||
png_uint_32 background, int encoding)
|
||||
png_uint_32 foreground, unsigned int foreground_significant_bits,
|
||||
int foreground_encoding, png_uint_32 alpha,
|
||||
png_uint_32 background, int encoding)
|
||||
{
|
||||
/* The file value is composed on the background, the background has the given
|
||||
* encoding and so does the result, the file is encoded with P_FILE and the
|
||||
@@ -1717,21 +1664,21 @@ png_colormap_compose(png_image_read_control *display,
|
||||
*/
|
||||
static void
|
||||
png_create_colormap_entry(png_image_read_control *display,
|
||||
png_uint_32 ip, png_uint_32 red, png_uint_32 green, png_uint_32 blue,
|
||||
png_uint_32 alpha, int encoding)
|
||||
png_uint_32 ip, png_uint_32 red, png_uint_32 green, png_uint_32 blue,
|
||||
png_uint_32 alpha, int encoding)
|
||||
{
|
||||
png_imagep image = display->image;
|
||||
# define png_ptr image->opaque->png_ptr /* for error messages */
|
||||
const int output_encoding = (image->format & PNG_FORMAT_FLAG_LINEAR) != 0 ?
|
||||
P_LINEAR : P_sRGB;
|
||||
const int convert_to_Y = (image->format & PNG_FORMAT_FLAG_COLOR) == 0 &&
|
||||
(red != green || green != blue);
|
||||
(red != green || green != blue);
|
||||
int use_sBIT = encoding == P_FILE;
|
||||
|
||||
affirm(ip <= 255);
|
||||
implies(encoding != P_LINEAR, red <= 255U && green <= 255U && blue <= 255U
|
||||
&& display->sBIT[0] <= 8U && display->sBIT[1] <= 8U
|
||||
&& display->sBIT[2] <= 8U && display->sBIT[3] <= 8U);
|
||||
&& display->sBIT[0] <= 8U && display->sBIT[1] <= 8U
|
||||
&& display->sBIT[2] <= 8U && display->sBIT[3] <= 8U);
|
||||
|
||||
/* This is a hack for the grayscale colormap below. */
|
||||
if (encoding == P_FILE8)
|
||||
@@ -1756,11 +1703,11 @@ png_create_colormap_entry(png_image_read_control *display,
|
||||
if (convert_to_Y != 0 || output_encoding == P_LINEAR)
|
||||
{
|
||||
red = convert_to_linear(display, red,
|
||||
use_sBIT ? display->sBIT[0] : 8U);
|
||||
use_sBIT ? display->sBIT[0] : 8U);
|
||||
green = convert_to_linear(display, green,
|
||||
use_sBIT ? display->sBIT[1] : 8U);
|
||||
use_sBIT ? display->sBIT[1] : 8U);
|
||||
blue = convert_to_linear(display, blue,
|
||||
use_sBIT ? display->sBIT[2] : 8U);
|
||||
use_sBIT ? display->sBIT[2] : 8U);
|
||||
alpha *= 257U;
|
||||
if (use_sBIT)
|
||||
alpha = update_for_sBIT(alpha, display->sBIT[3], 16U);
|
||||
@@ -1772,11 +1719,11 @@ png_create_colormap_entry(png_image_read_control *display,
|
||||
else
|
||||
{
|
||||
red = convert_to_sRGB(display, red,
|
||||
use_sBIT ? display->sBIT[0] : 8U);
|
||||
use_sBIT ? display->sBIT[0] : 8U);
|
||||
green = convert_to_sRGB(display, green,
|
||||
use_sBIT ? display->sBIT[1] : 8U);
|
||||
use_sBIT ? display->sBIT[1] : 8U);
|
||||
blue = convert_to_sRGB(display, blue,
|
||||
use_sBIT ? display->sBIT[2] : 8U);
|
||||
use_sBIT ? display->sBIT[2] : 8U);
|
||||
if (use_sBIT)
|
||||
alpha = update_for_sBIT(alpha, display->sBIT[3], 8U);
|
||||
encoding = P_sRGB;
|
||||
@@ -1885,7 +1832,7 @@ png_create_colormap_entry(png_image_read_control *display,
|
||||
{
|
||||
# ifdef PNG_FORMAT_AFIRST_SUPPORTED
|
||||
const int afirst = (image->format & PNG_FORMAT_FLAG_AFIRST) != 0 &&
|
||||
(image->format & PNG_FORMAT_FLAG_ALPHA) != 0;
|
||||
(image->format & PNG_FORMAT_FLAG_ALPHA) != 0;
|
||||
# else
|
||||
# define afirst 0
|
||||
# endif
|
||||
@@ -2062,7 +2009,7 @@ make_ga_colormap(png_image_read_control *display)
|
||||
|
||||
for (g=0; g<6; ++g)
|
||||
png_create_colormap_entry(display, i++, g*51, g*51, g*51, a*51,
|
||||
P_sRGB);
|
||||
P_sRGB);
|
||||
}
|
||||
|
||||
return i;
|
||||
@@ -2086,7 +2033,7 @@ make_rgb_colormap(png_image_read_control *display)
|
||||
|
||||
for (b=0; b<6; ++b)
|
||||
png_create_colormap_entry(display, i++, r*51, g*51, b*51, 255,
|
||||
P_sRGB);
|
||||
P_sRGB);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2139,7 +2086,7 @@ png_image_read_colormap(png_voidp argument)
|
||||
|
||||
else if (display->background == NULL /* no way to remove it */)
|
||||
png_error(png_ptr,
|
||||
"a background color must be supplied to remove alpha/transparency");
|
||||
"background color must be supplied to remove alpha/transparency");
|
||||
|
||||
/* Get a copy of the background color (this avoids repeating the checks
|
||||
* below.) The encoding is 8-bit sRGB or 16-bit linear, depending on the
|
||||
@@ -2239,7 +2186,7 @@ png_image_read_colormap(png_voidp argument)
|
||||
*/
|
||||
if (i != trans)
|
||||
png_create_colormap_entry(display, i, val, val, val, 255,
|
||||
P_FILE/*8-bit with file gamma*/);
|
||||
P_FILE/*8-bit with file gamma*/);
|
||||
|
||||
/* Else this entry is transparent. The colors don't matter if
|
||||
* there is an alpha channel (back_alpha == 0), but it does no
|
||||
@@ -2254,10 +2201,10 @@ png_image_read_colormap(png_voidp argument)
|
||||
#ifdef __COVERITY__
|
||||
/* Coverity says back_r|g|b might be 16-bit values */
|
||||
png_affirmpp(png_ptr, back_r < 256 && back_g < 256 &&
|
||||
back_b < 256);
|
||||
back_b < 256);
|
||||
#endif
|
||||
png_create_colormap_entry(display, i, back_r, back_g, back_b,
|
||||
back_alpha, output_encoding);
|
||||
back_alpha, output_encoding);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2323,7 +2270,7 @@ png_image_read_colormap(png_voidp argument)
|
||||
* matches.
|
||||
*/
|
||||
png_create_colormap_entry(display, gray, back_g, back_g,
|
||||
back_g, 65535, P_LINEAR);
|
||||
back_g, 65535, P_LINEAR);
|
||||
}
|
||||
|
||||
/* The background passed to libpng, however, must be the
|
||||
@@ -2331,15 +2278,15 @@ png_image_read_colormap(png_voidp argument)
|
||||
*/
|
||||
c.index = 0; /*unused*/
|
||||
c.gray = c.red = c.green = c.blue =
|
||||
png_check_u16(png_ptr, gray);
|
||||
png_check_u16(png_ptr, gray);
|
||||
|
||||
/* NOTE: does this work without expanding tRNS to alpha?
|
||||
* It should be the color->gray case below apparently
|
||||
* doesn't.
|
||||
*/
|
||||
png_set_background_fixed(png_ptr, &c,
|
||||
PNG_BACKGROUND_GAMMA_SCREEN, 0/*need_expand*/,
|
||||
0/*gamma: not used*/);
|
||||
PNG_BACKGROUND_GAMMA_SCREEN, 0/*need_expand*/,
|
||||
0/*gamma: not used*/);
|
||||
|
||||
output_processing = PNG_CMAP_NONE;
|
||||
break;
|
||||
@@ -2371,7 +2318,7 @@ png_image_read_colormap(png_voidp argument)
|
||||
back_b < 256);
|
||||
#endif
|
||||
png_create_colormap_entry(display, 254, back_r, back_g, back_b,
|
||||
back_alpha, output_encoding);
|
||||
back_alpha, output_encoding);
|
||||
}
|
||||
|
||||
else
|
||||
@@ -2439,7 +2386,7 @@ png_image_read_colormap(png_voidp argument)
|
||||
|
||||
/* And make sure the corresponding palette entry matches. */
|
||||
png_create_colormap_entry(display, gray, back_g, back_g,
|
||||
back_g, 65535, P_LINEAR);
|
||||
back_g, 65535, P_LINEAR);
|
||||
}
|
||||
|
||||
/* The background passed to libpng, however, must be the sRGB
|
||||
@@ -2449,8 +2396,8 @@ png_image_read_colormap(png_voidp argument)
|
||||
c.gray = c.red = c.green = c.blue = png_check_u16(png_ptr, gray);
|
||||
|
||||
png_set_background_fixed(png_ptr, &c,
|
||||
PNG_BACKGROUND_GAMMA_SCREEN, 0/*need_expand*/,
|
||||
0/*gamma: not used*/);
|
||||
PNG_BACKGROUND_GAMMA_SCREEN, 0/*need_expand*/,
|
||||
0/*gamma: not used*/);
|
||||
|
||||
output_processing = PNG_CMAP_NONE;
|
||||
}
|
||||
@@ -2470,7 +2417,7 @@ png_image_read_colormap(png_voidp argument)
|
||||
{
|
||||
png_uint_32 gray = (i * 256 + 115) / 231;
|
||||
png_create_colormap_entry(display, i++, gray, gray, gray,
|
||||
255, P_sRGB);
|
||||
255, P_sRGB);
|
||||
}
|
||||
|
||||
/* NOTE: this preserves the full precision of the application
|
||||
@@ -2548,7 +2495,7 @@ png_image_read_colormap(png_voidp argument)
|
||||
* png_set_tRNS_to_alpha before png_set_background_fixed.
|
||||
*/
|
||||
png_set_rgb_to_gray_fixed(png_ptr, PNG_ERROR_ACTION_NONE, -1,
|
||||
-1);
|
||||
-1);
|
||||
data_encoding = P_sRGB;
|
||||
|
||||
/* The output will now be one or two 8-bit gray or gray+alpha
|
||||
@@ -2656,8 +2603,8 @@ png_image_read_colormap(png_voidp argument)
|
||||
*/
|
||||
expand_tRNS = 1;
|
||||
png_set_background_fixed(png_ptr, &c,
|
||||
PNG_BACKGROUND_GAMMA_SCREEN, 0/*need_expand*/,
|
||||
0/*gamma: not used*/);
|
||||
PNG_BACKGROUND_GAMMA_SCREEN, 0/*need_expand*/,
|
||||
0/*gamma: not used*/);
|
||||
}
|
||||
|
||||
output_processing = PNG_CMAP_NONE;
|
||||
@@ -2691,7 +2638,7 @@ png_image_read_colormap(png_voidp argument)
|
||||
|
||||
/* Add a transparent entry. */
|
||||
png_create_colormap_entry(display, cmap_entries, 255, 255,
|
||||
255, 0, P_sRGB);
|
||||
255, 0, P_sRGB);
|
||||
|
||||
/* This is stored as the background index for the processing
|
||||
* algorithm.
|
||||
@@ -2712,7 +2659,7 @@ png_image_read_colormap(png_voidp argument)
|
||||
*/
|
||||
for (b=0; b<256; b = (b << 1) | 0x7f)
|
||||
png_create_colormap_entry(display, cmap_entries++,
|
||||
r, g, b, 128, P_sRGB);
|
||||
r, g, b, 128, P_sRGB);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2739,7 +2686,7 @@ png_image_read_colormap(png_voidp argument)
|
||||
cmap_entries = make_rgb_colormap(display);
|
||||
|
||||
png_create_colormap_entry(display, cmap_entries, back_r,
|
||||
back_g, back_b, 0/*unused*/, output_encoding);
|
||||
back_g, back_b, 0/*unused*/, output_encoding);
|
||||
|
||||
if (output_encoding == P_LINEAR)
|
||||
{
|
||||
@@ -2761,9 +2708,9 @@ png_image_read_colormap(png_voidp argument)
|
||||
* index.
|
||||
*/
|
||||
if (memcmp((png_const_bytep)display->colormap +
|
||||
sample_size * cmap_entries,
|
||||
(png_const_bytep)display->colormap +
|
||||
sample_size * PNG_RGB_INDEX(r,g,b),
|
||||
sample_size * cmap_entries,
|
||||
(png_const_bytep)display->colormap +
|
||||
sample_size * PNG_RGB_INDEX(r,g,b),
|
||||
sample_size) != 0)
|
||||
{
|
||||
/* The background color must be added. */
|
||||
@@ -2805,8 +2752,8 @@ png_image_read_colormap(png_voidp argument)
|
||||
c.blue = png_check_u16(png_ptr, back_b);
|
||||
|
||||
png_set_background_fixed(png_ptr, &c,
|
||||
PNG_BACKGROUND_GAMMA_SCREEN, 0/*need_expand*/,
|
||||
0/*gamma: not used*/);
|
||||
PNG_BACKGROUND_GAMMA_SCREEN, 0/*need_expand*/,
|
||||
0/*gamma: not used*/);
|
||||
|
||||
output_processing = PNG_CMAP_RGB;
|
||||
}
|
||||
@@ -2858,7 +2805,7 @@ png_image_read_colormap(png_voidp argument)
|
||||
{
|
||||
if (trans[i] == 0)
|
||||
png_create_colormap_entry(display, i, back_r, back_g,
|
||||
back_b, 0, output_encoding);
|
||||
back_b, 0, output_encoding);
|
||||
|
||||
else
|
||||
{
|
||||
@@ -2983,7 +2930,7 @@ static int
|
||||
png_image_read_and_map(png_voidp argument)
|
||||
{
|
||||
png_image_read_control *display = png_voidcast(png_image_read_control*,
|
||||
argument);
|
||||
argument);
|
||||
png_imagep image = display->image;
|
||||
png_structrp png_ptr = image->opaque->png_ptr;
|
||||
int passes;
|
||||
@@ -3120,7 +3067,7 @@ png_image_read_and_map(png_voidp argument)
|
||||
|
||||
if (alpha >= 196)
|
||||
*outrow = PNG_RGB_INDEX(inrow[0], inrow[1],
|
||||
inrow[2]);
|
||||
inrow[2]);
|
||||
|
||||
else if (alpha < 64)
|
||||
*outrow = PNG_CMAP_RGB_ALPHA_BACKGROUND;
|
||||
@@ -3172,7 +3119,7 @@ static int
|
||||
png_image_read_colormapped(png_voidp argument)
|
||||
{
|
||||
png_image_read_control *display = png_voidcast(png_image_read_control*,
|
||||
argument);
|
||||
argument);
|
||||
png_imagep image = display->image;
|
||||
png_controlp control = image->opaque;
|
||||
png_structrp png_ptr = control->png_ptr;
|
||||
@@ -3310,7 +3257,7 @@ static int
|
||||
png_image_read_composite(png_voidp argument)
|
||||
{
|
||||
png_image_read_control *display = png_voidcast(png_image_read_control*,
|
||||
argument);
|
||||
argument);
|
||||
png_imagep image = display->image;
|
||||
png_structrp png_ptr = image->opaque->png_ptr;
|
||||
int passes;
|
||||
@@ -3438,7 +3385,7 @@ static int
|
||||
png_image_read_background(png_voidp argument)
|
||||
{
|
||||
png_image_read_control *display = png_voidcast(png_image_read_control*,
|
||||
argument);
|
||||
argument);
|
||||
png_imagep image = display->image;
|
||||
png_structrp png_ptr = image->opaque->png_ptr;
|
||||
png_inforp info_ptr = image->opaque->info_ptr;
|
||||
@@ -3497,8 +3444,7 @@ png_image_read_background(png_voidp argument)
|
||||
|
||||
for (pass = 0; pass < passes; ++pass)
|
||||
{
|
||||
png_bytep row = png_voidcast(png_bytep,
|
||||
display->first_row);
|
||||
png_bytep row = png_voidcast(png_bytep, display->first_row);
|
||||
unsigned int startx, stepx, stepy;
|
||||
png_uint_32 y;
|
||||
|
||||
@@ -3526,7 +3472,7 @@ png_image_read_background(png_voidp argument)
|
||||
for (; y<height; y += stepy)
|
||||
{
|
||||
png_bytep inrow = png_voidcast(png_bytep,
|
||||
display->local_row);
|
||||
display->local_row);
|
||||
png_bytep outrow = first_row + y * step_row;
|
||||
png_const_bytep end_row = outrow + width;
|
||||
|
||||
@@ -3572,7 +3518,7 @@ png_image_read_background(png_voidp argument)
|
||||
for (; y<height; y += stepy)
|
||||
{
|
||||
png_bytep inrow = png_voidcast(png_bytep,
|
||||
display->local_row);
|
||||
display->local_row);
|
||||
png_bytep outrow = first_row + y * step_row;
|
||||
png_const_bytep end_row = outrow + width;
|
||||
|
||||
@@ -3620,7 +3566,7 @@ png_image_read_background(png_voidp argument)
|
||||
*/
|
||||
{
|
||||
png_uint_16p first_row = png_voidcast(png_uint_16p,
|
||||
display->first_row);
|
||||
display->first_row);
|
||||
/* The division by two is safe because the caller passed in a
|
||||
* stride which was multiplied by 2 (below) to get row_bytes.
|
||||
*/
|
||||
@@ -3670,7 +3616,7 @@ png_image_read_background(png_voidp argument)
|
||||
|
||||
/* Read the row, which is packed: */
|
||||
png_read_row(png_ptr, png_voidcast(png_bytep,
|
||||
display->local_row), NULL);
|
||||
display->local_row), NULL);
|
||||
inrow = png_voidcast(png_const_uint_16p, display->local_row);
|
||||
|
||||
/* Now do the pre-multiplication on each pixel in this row.
|
||||
@@ -3715,7 +3661,7 @@ static int
|
||||
png_image_read_direct(png_voidp argument)
|
||||
{
|
||||
png_image_read_control *display = png_voidcast(png_image_read_control*,
|
||||
argument);
|
||||
argument);
|
||||
png_imagep image = display->image;
|
||||
png_structrp png_ptr = image->opaque->png_ptr;
|
||||
png_inforp info_ptr = image->opaque->info_ptr;
|
||||
@@ -3766,7 +3712,7 @@ png_image_read_direct(png_voidp argument)
|
||||
do_local_background = 1/*maybe*/;
|
||||
|
||||
png_set_rgb_to_gray_fixed(png_ptr, PNG_ERROR_ACTION_NONE,
|
||||
PNG_RGB_TO_GRAY_DEFAULT, PNG_RGB_TO_GRAY_DEFAULT);
|
||||
PNG_RGB_TO_GRAY_DEFAULT, PNG_RGB_TO_GRAY_DEFAULT);
|
||||
}
|
||||
|
||||
change &= PNG_BIC_MASK(PNG_FORMAT_FLAG_COLOR);
|
||||
@@ -3885,8 +3831,8 @@ png_image_read_direct(png_voidp argument)
|
||||
* pixels.
|
||||
*/
|
||||
png_set_background_fixed(png_ptr, &c,
|
||||
PNG_BACKGROUND_GAMMA_SCREEN, 0/*need_expand*/,
|
||||
0/*gamma: not used*/);
|
||||
PNG_BACKGROUND_GAMMA_SCREEN, 0/*need_expand*/,
|
||||
0/*gamma: not used*/);
|
||||
}
|
||||
|
||||
else /* compose on row: implemented below. */
|
||||
@@ -4128,7 +4074,7 @@ png_image_read_direct(png_voidp argument)
|
||||
|
||||
int PNGAPI
|
||||
png_image_finish_read(png_imagep image, png_const_colorp background,
|
||||
void *buffer, ptrdiff_t row_stride, void *colormap)
|
||||
void *buffer, ptrdiff_t row_stride, void *colormap)
|
||||
{
|
||||
if (image != NULL && image->version == PNG_IMAGE_VERSION)
|
||||
{
|
||||
@@ -4159,11 +4105,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))
|
||||
@@ -4183,15 +4139,16 @@ png_image_finish_read(png_imagep image, png_const_colorp background,
|
||||
* all the setup has already been done.
|
||||
*/
|
||||
if ((image->format & PNG_FORMAT_FLAG_COLORMAP) != 0)
|
||||
result = png_safe_execute(image,
|
||||
png_image_read_colormap, &display) &&
|
||||
png_safe_execute(image,
|
||||
png_image_read_colormapped, &display);
|
||||
result =
|
||||
png_safe_execute(image,
|
||||
png_image_read_colormap, &display) &&
|
||||
png_safe_execute(image,
|
||||
png_image_read_colormapped, &display);
|
||||
|
||||
else
|
||||
result =
|
||||
png_safe_execute(image,
|
||||
png_image_read_direct, &display);
|
||||
png_image_read_direct, &display);
|
||||
|
||||
png_image_free(image);
|
||||
return result;
|
||||
@@ -4199,27 +4156,27 @@ png_image_finish_read(png_imagep image, png_const_colorp background,
|
||||
|
||||
else
|
||||
return png_image_error(image,
|
||||
"png_image_finish_read[color-map]: no color-map");
|
||||
"png_image_finish_read[color-map]: no color-map");
|
||||
}
|
||||
|
||||
else
|
||||
return png_image_error(image,
|
||||
"png_image_finish_read: image too large");
|
||||
"png_image_finish_read: image too large");
|
||||
}
|
||||
|
||||
else
|
||||
return png_image_error(image,
|
||||
"png_image_finish_read: invalid argument");
|
||||
"png_image_finish_read: invalid argument");
|
||||
}
|
||||
|
||||
else
|
||||
return png_image_error(image,
|
||||
"png_image_finish_read: row_stride too large");
|
||||
"png_image_finish_read: row_stride too large");
|
||||
}
|
||||
|
||||
else if (image != NULL)
|
||||
return png_image_error(image,
|
||||
"png_image_finish_read: damaged PNG_IMAGE_VERSION");
|
||||
"png_image_finish_read: damaged PNG_IMAGE_VERSION");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
9
pngrio.c
@@ -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);
|
||||
|
||||
@@ -86,7 +91,7 @@ png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
*/
|
||||
void PNGAPI
|
||||
png_set_read_fn(png_structrp png_ptr, png_voidp io_ptr,
|
||||
png_rw_ptr read_data_fn)
|
||||
png_rw_ptr read_data_fn)
|
||||
{
|
||||
if (png_ptr == NULL)
|
||||
return;
|
||||
|
||||
89
pngrtran.c
@@ -3434,9 +3434,29 @@ png_init_gamma(png_transformp *transform, png_transform_controlp tc)
|
||||
}
|
||||
}
|
||||
|
||||
#if !PNG_RELEASE_BUILD
|
||||
int /* PRIVATE(debug only) */
|
||||
png_gamma_check(png_const_structrp png_ptr, png_const_transform_controlp tc)
|
||||
/* Debugging only routine to repeat the test used above to determine if the
|
||||
* gamma was insignificant.
|
||||
*
|
||||
* NOTE: JB20160723: This may still be incorrect in a complicated transform
|
||||
* pipeline because it uses 'tc_sBIT' for the end of the pipeline whereas the
|
||||
* init above happens earlier. I don't think this matters because the test
|
||||
* is only invoked if the gamma transform is eliminated or if there is a bug
|
||||
* and in the former case the sBIT values should remain unchanged.
|
||||
*/
|
||||
{
|
||||
png_fixed_point dummy;
|
||||
|
||||
return png_gamma_equal(png_ptr, png_ptr->row_gamma, tc->gamma, &dummy,
|
||||
tc_sBIT(tc));
|
||||
}
|
||||
#endif /* !RELEASE_BUILD */
|
||||
|
||||
static png_fixed_point
|
||||
translate_gamma_flags(png_const_structrp png_ptr, png_fixed_point gamma,
|
||||
int is_screen)
|
||||
int is_screen)
|
||||
/* If 'is_screen' is set this returns the inverse of the supplied value; i.e.
|
||||
* this routine always returns an encoding value.
|
||||
*/
|
||||
@@ -3511,7 +3531,7 @@ add_gamma_transform(png_structrp png_ptr, unsigned int order,
|
||||
|
||||
void PNGFAPI
|
||||
png_set_gamma_fixed(png_structrp png_ptr, png_fixed_point scrn_gamma,
|
||||
png_fixed_point file_gamma)
|
||||
png_fixed_point file_gamma)
|
||||
{
|
||||
png_debug(1, "in png_set_gamma_fixed");
|
||||
|
||||
@@ -3566,7 +3586,7 @@ void PNGAPI
|
||||
png_set_gamma(png_structrp png_ptr, double scrn_gamma, double file_gamma)
|
||||
{
|
||||
png_set_gamma_fixed(png_ptr, convert_gamma_value(png_ptr, scrn_gamma),
|
||||
convert_gamma_value(png_ptr, file_gamma));
|
||||
convert_gamma_value(png_ptr, file_gamma));
|
||||
}
|
||||
#endif /* FLOATING_POINT */
|
||||
#endif /* READ_GAMMA */
|
||||
@@ -4044,7 +4064,7 @@ png_set_rgb_to_gray_fixed(png_structrp png_ptr, int error_action,
|
||||
|
||||
void PNGAPI
|
||||
png_set_rgb_to_gray(png_structrp png_ptr, int error_action, double red,
|
||||
double green)
|
||||
double green)
|
||||
{
|
||||
png_set_rgb_to_gray_fixed(png_ptr, error_action,
|
||||
png_fixed(png_ptr, red, "rgb to gray red coefficient"),
|
||||
@@ -5490,7 +5510,7 @@ png_set_background(png_structrp png_ptr,
|
||||
#ifdef PNG_READ_ALPHA_MODE_SUPPORTED
|
||||
void PNGFAPI
|
||||
png_set_alpha_mode_fixed(png_structrp png_ptr, int mode,
|
||||
png_fixed_point output_gamma)
|
||||
png_fixed_point output_gamma)
|
||||
{
|
||||
if (png_ptr != NULL)
|
||||
{
|
||||
@@ -5603,7 +5623,7 @@ void PNGAPI
|
||||
png_set_alpha_mode(png_structrp png_ptr, int mode, double output_gamma)
|
||||
{
|
||||
png_set_alpha_mode_fixed(png_ptr, mode, convert_gamma_value(png_ptr,
|
||||
output_gamma));
|
||||
output_gamma));
|
||||
}
|
||||
#endif /* FLOATING_POINT */
|
||||
#endif /* READ_ALPHA_MODE */
|
||||
@@ -5885,26 +5905,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 +5937,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 +6044,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 +6053,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 +6320,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 +6613,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 +6632,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 +6642,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 +6669,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 +6705,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: */
|
||||
|
||||
648
pngrutil.c
142
pngset.c
@@ -105,14 +105,14 @@ png_set_cHRM(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
double green_x, double green_y, double blue_x, double blue_y)
|
||||
{
|
||||
png_set_cHRM_fixed(png_ptr, info_ptr,
|
||||
png_fixed(png_ptr, white_x, "cHRM White X"),
|
||||
png_fixed(png_ptr, white_y, "cHRM White Y"),
|
||||
png_fixed(png_ptr, red_x, "cHRM Red X"),
|
||||
png_fixed(png_ptr, red_y, "cHRM Red Y"),
|
||||
png_fixed(png_ptr, green_x, "cHRM Green X"),
|
||||
png_fixed(png_ptr, green_y, "cHRM Green Y"),
|
||||
png_fixed(png_ptr, blue_x, "cHRM Blue X"),
|
||||
png_fixed(png_ptr, blue_y, "cHRM Blue Y"));
|
||||
png_fixed(png_ptr, white_x, "cHRM White X"),
|
||||
png_fixed(png_ptr, white_y, "cHRM White Y"),
|
||||
png_fixed(png_ptr, red_x, "cHRM Red X"),
|
||||
png_fixed(png_ptr, red_y, "cHRM Red Y"),
|
||||
png_fixed(png_ptr, green_x, "cHRM Green X"),
|
||||
png_fixed(png_ptr, green_y, "cHRM Green Y"),
|
||||
png_fixed(png_ptr, blue_x, "cHRM Blue X"),
|
||||
png_fixed(png_ptr, blue_y, "cHRM Blue Y"));
|
||||
}
|
||||
|
||||
void PNGAPI
|
||||
@@ -121,15 +121,15 @@ png_set_cHRM_XYZ(png_const_structrp png_ptr, png_inforp info_ptr, double red_X,
|
||||
double blue_X, double blue_Y, double blue_Z)
|
||||
{
|
||||
png_set_cHRM_XYZ_fixed(png_ptr, info_ptr,
|
||||
png_fixed(png_ptr, red_X, "cHRM Red X"),
|
||||
png_fixed(png_ptr, red_Y, "cHRM Red Y"),
|
||||
png_fixed(png_ptr, red_Z, "cHRM Red Z"),
|
||||
png_fixed(png_ptr, green_X, "cHRM Green X"),
|
||||
png_fixed(png_ptr, green_Y, "cHRM Green Y"),
|
||||
png_fixed(png_ptr, green_Z, "cHRM Green Z"),
|
||||
png_fixed(png_ptr, blue_X, "cHRM Blue X"),
|
||||
png_fixed(png_ptr, blue_Y, "cHRM Blue Y"),
|
||||
png_fixed(png_ptr, blue_Z, "cHRM Blue Z"));
|
||||
png_fixed(png_ptr, red_X, "cHRM Red X"),
|
||||
png_fixed(png_ptr, red_Y, "cHRM Red Y"),
|
||||
png_fixed(png_ptr, red_Z, "cHRM Red Z"),
|
||||
png_fixed(png_ptr, green_X, "cHRM Green X"),
|
||||
png_fixed(png_ptr, green_Y, "cHRM Green Y"),
|
||||
png_fixed(png_ptr, green_Z, "cHRM Green Z"),
|
||||
png_fixed(png_ptr, blue_X, "cHRM Blue X"),
|
||||
png_fixed(png_ptr, blue_Y, "cHRM Blue Y"),
|
||||
png_fixed(png_ptr, blue_Z, "cHRM Blue Z"));
|
||||
}
|
||||
# endif /* FLOATING_POINT */
|
||||
|
||||
@@ -304,10 +304,10 @@ png_set_pCAL(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
|
||||
length = strlen(units) + 1;
|
||||
png_debug1(3, "allocating units for info (%lu bytes)",
|
||||
(unsigned long)length);
|
||||
(unsigned long)length);
|
||||
|
||||
info_ptr->pcal_units = png_voidcast(png_charp,
|
||||
png_malloc_warn(png_ptr, length));
|
||||
png_malloc_warn(png_ptr, length));
|
||||
|
||||
if (info_ptr->pcal_units == NULL)
|
||||
{
|
||||
@@ -386,7 +386,7 @@ png_set_sCAL_s(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
png_debug1(3, "allocating unit for info (%u bytes)", (unsigned int)lengthw);
|
||||
|
||||
info_ptr->scal_s_width = png_voidcast(png_charp,
|
||||
png_malloc_warn(png_ptr, lengthw));
|
||||
png_malloc_warn(png_ptr, lengthw));
|
||||
|
||||
if (info_ptr->scal_s_width == NULL)
|
||||
{
|
||||
@@ -402,7 +402,7 @@ png_set_sCAL_s(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
png_debug1(3, "allocating unit for info (%u bytes)", (unsigned int)lengthh);
|
||||
|
||||
info_ptr->scal_s_height = png_voidcast(png_charp,
|
||||
png_malloc_warn(png_ptr, lengthh));
|
||||
png_malloc_warn(png_ptr, lengthh));
|
||||
|
||||
if (info_ptr->scal_s_height == NULL)
|
||||
{
|
||||
@@ -442,9 +442,9 @@ png_set_sCAL(png_const_structrp png_ptr, png_inforp info_ptr, int unit,
|
||||
char sheight[PNG_sCAL_MAX_DIGITS+1];
|
||||
|
||||
png_ascii_from_fp(png_ptr, swidth, (sizeof swidth), width,
|
||||
PNG_sCAL_PRECISION);
|
||||
PNG_sCAL_PRECISION);
|
||||
png_ascii_from_fp(png_ptr, sheight, (sizeof sheight), height,
|
||||
PNG_sCAL_PRECISION);
|
||||
PNG_sCAL_PRECISION);
|
||||
|
||||
png_set_sCAL_s(png_ptr, info_ptr, unit, swidth, sheight);
|
||||
}
|
||||
@@ -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;
|
||||
@@ -626,7 +644,7 @@ png_set_iCCP(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
*/
|
||||
{
|
||||
int result = png_colorspace_set_ICC(png_ptr, &info_ptr->colorspace, name,
|
||||
proflen, profile, (info_ptr->format & PNG_FORMAT_FLAG_COLOR) != 0);
|
||||
proflen, profile, (info_ptr->format & PNG_FORMAT_FLAG_COLOR) != 0);
|
||||
|
||||
png_colorspace_sync_info(png_ptr, info_ptr);
|
||||
|
||||
@@ -636,7 +654,7 @@ png_set_iCCP(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
|
||||
/* But do write the gAMA and cHRM chunks from the profile. */
|
||||
info_ptr->colorspace.flags |=
|
||||
PNG_COLORSPACE_FROM_gAMA|PNG_COLORSPACE_FROM_cHRM;
|
||||
PNG_COLORSPACE_FROM_gAMA|PNG_COLORSPACE_FROM_cHRM;
|
||||
}
|
||||
|
||||
length = strlen(name)+1;
|
||||
@@ -651,7 +669,7 @@ png_set_iCCP(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
|
||||
memcpy(new_iccp_name, name, length);
|
||||
new_iccp_profile = png_voidcast(png_bytep,
|
||||
png_malloc_warn(png_ptr, proflen));
|
||||
png_malloc_warn(png_ptr, proflen));
|
||||
|
||||
if (new_iccp_profile == NULL)
|
||||
{
|
||||
@@ -801,14 +819,14 @@ png_set_text_2(png_structrp png_ptr, png_inforp info_ptr,
|
||||
* the overflow checks.
|
||||
*/
|
||||
new_text = png_voidcast(png_textp,png_realloc_array(png_ptr,
|
||||
info_ptr->text, old_num_text, max_text-old_num_text,
|
||||
sizeof *new_text));
|
||||
info_ptr->text, old_num_text, max_text-old_num_text,
|
||||
sizeof *new_text));
|
||||
}
|
||||
|
||||
if (new_text == NULL)
|
||||
{
|
||||
png_chunk_report(png_ptr, "too many text chunks",
|
||||
PNG_CHUNK_WRITE_ERROR);
|
||||
PNG_CHUNK_WRITE_ERROR);
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -836,7 +854,7 @@ png_set_text_2(png_structrp png_ptr, png_inforp info_ptr,
|
||||
text_ptr[i].compression >= PNG_TEXT_COMPRESSION_LAST)
|
||||
{
|
||||
png_chunk_report(png_ptr, "text compression mode is out of range",
|
||||
PNG_CHUNK_WRITE_ERROR);
|
||||
PNG_CHUNK_WRITE_ERROR);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -868,7 +886,7 @@ png_set_text_2(png_structrp png_ptr, png_inforp info_ptr,
|
||||
# else /* iTXt */
|
||||
{
|
||||
png_chunk_report(png_ptr, "iTXt chunk not supported",
|
||||
PNG_CHUNK_WRITE_ERROR);
|
||||
PNG_CHUNK_WRITE_ERROR);
|
||||
continue;
|
||||
}
|
||||
# endif
|
||||
@@ -903,7 +921,7 @@ png_set_text_2(png_structrp png_ptr, png_inforp info_ptr,
|
||||
if (textp->key == NULL)
|
||||
{
|
||||
png_chunk_report(png_ptr, "text chunk: out of memory",
|
||||
PNG_CHUNK_WRITE_ERROR);
|
||||
PNG_CHUNK_WRITE_ERROR);
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -1013,7 +1031,7 @@ png_set_tRNS(png_structrp png_ptr, png_inforp info_ptr,
|
||||
|
||||
if ((info_ptr->format & PNG_FORMAT_FLAG_ALPHA) != 0)
|
||||
png_chunk_report(png_ptr,
|
||||
"png_set_tRNS: invalid on PNG with alpha channel", PNG_CHUNK_ERROR);
|
||||
"png_set_tRNS: invalid on PNG with alpha channel", PNG_CHUNK_ERROR);
|
||||
|
||||
else if ((info_ptr->format & PNG_FORMAT_FLAG_COLORMAP) != 0)
|
||||
{
|
||||
@@ -1039,7 +1057,7 @@ png_set_tRNS(png_structrp png_ptr, png_inforp info_ptr,
|
||||
if (num_trans > max_num)
|
||||
{
|
||||
png_chunk_report(png_ptr, "png_set_tRNS: num_trans too large",
|
||||
PNG_CHUNK_ERROR);
|
||||
PNG_CHUNK_ERROR);
|
||||
/* If control returns simply limit it; the behavior prior to 1.7 was to
|
||||
* issue a warning and skip the palette in png_write_tRNS.
|
||||
*/
|
||||
@@ -1056,11 +1074,11 @@ png_set_tRNS(png_structrp png_ptr, png_inforp info_ptr,
|
||||
* indices.
|
||||
*/
|
||||
info_ptr->trans_alpha = png_voidcast(png_bytep, png_malloc(png_ptr,
|
||||
PNG_MAX_PALETTE_LENGTH));
|
||||
PNG_MAX_PALETTE_LENGTH));
|
||||
info_ptr->free_me |= PNG_FREE_TRNS;
|
||||
|
||||
memcpy(info_ptr->trans_alpha, trans_alpha,
|
||||
(unsigned)/*SAFE*/num_trans);
|
||||
(unsigned)/*SAFE*/num_trans);
|
||||
info_ptr->valid |= PNG_INFO_tRNS;
|
||||
info_ptr->num_trans = png_check_bits(png_ptr, num_trans, 9);
|
||||
}
|
||||
@@ -1091,8 +1109,8 @@ png_set_tRNS(png_structrp png_ptr, png_inforp info_ptr,
|
||||
|
||||
else
|
||||
png_chunk_report(png_ptr,
|
||||
"tRNS chunk has out-of-range samples for bit_depth",
|
||||
PNG_CHUNK_ERROR);
|
||||
"tRNS chunk has out-of-range samples for bit_depth",
|
||||
PNG_CHUNK_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1120,8 +1138,8 @@ png_set_sPLT(png_structrp png_ptr,
|
||||
* overflows. Notice that the parameters are (int) and (size_t)
|
||||
*/
|
||||
np = png_voidcast(png_sPLT_tp,png_realloc_array(png_ptr,
|
||||
info_ptr->splt_palettes, info_ptr->splt_palettes_num, nentries,
|
||||
sizeof *np));
|
||||
info_ptr->splt_palettes, info_ptr->splt_palettes_num, nentries,
|
||||
sizeof *np));
|
||||
|
||||
if (np == NULL)
|
||||
{
|
||||
@@ -1182,7 +1200,7 @@ png_set_sPLT(png_structrp png_ptr,
|
||||
* checked it when doing the allocation.
|
||||
*/
|
||||
memcpy(np->entries, entries->entries,
|
||||
entries->nentries * sizeof (png_sPLT_entry));
|
||||
entries->nentries * sizeof (png_sPLT_entry));
|
||||
|
||||
/* Note that 'continue' skips the advance of the out pointer and out
|
||||
* count, so an invalid entry is not added.
|
||||
@@ -1190,8 +1208,9 @@ png_set_sPLT(png_structrp png_ptr,
|
||||
info_ptr->valid |= PNG_INFO_sPLT;
|
||||
++(info_ptr->splt_palettes_num);
|
||||
++np;
|
||||
++entries;
|
||||
}
|
||||
while (++entries, --nentries);
|
||||
while (--nentries);
|
||||
|
||||
if (nentries > 0)
|
||||
png_chunk_report(png_ptr, "sPLT out of memory", PNG_CHUNK_WRITE_ERROR);
|
||||
@@ -1212,10 +1231,10 @@ check_location(png_const_structrp png_ptr, int location)
|
||||
{
|
||||
/* Write struct, so unknown chunks come from the app */
|
||||
png_app_warning(png_ptr,
|
||||
"png_set_unknown_chunks now expects a valid location");
|
||||
"png_set_unknown_chunks now expects a valid location");
|
||||
/* Use the old behavior */
|
||||
location = png_check_byte(png_ptr, png_ptr->mode &
|
||||
(PNG_HAVE_IHDR|PNG_HAVE_PLTE|PNG_AFTER_IDAT));
|
||||
(PNG_HAVE_IHDR|PNG_HAVE_PLTE|PNG_AFTER_IDAT));
|
||||
}
|
||||
|
||||
/* This need not be an internal error - if the app calls
|
||||
@@ -1238,7 +1257,7 @@ check_location(png_const_structrp png_ptr, int location)
|
||||
|
||||
void PNGAPI
|
||||
png_set_unknown_chunks(png_structrp png_ptr,
|
||||
png_inforp info_ptr, png_const_unknown_chunkp unknowns, int num_unknowns)
|
||||
png_inforp info_ptr, png_const_unknown_chunkp unknowns, int num_unknowns)
|
||||
{
|
||||
png_unknown_chunkp np;
|
||||
|
||||
@@ -1308,12 +1327,12 @@ png_set_unknown_chunks(png_structrp png_ptr,
|
||||
else
|
||||
{
|
||||
np->data = png_voidcast(png_bytep,
|
||||
png_malloc_base(png_ptr, unknowns->size));
|
||||
png_malloc_base(png_ptr, unknowns->size));
|
||||
|
||||
if (np->data == NULL)
|
||||
{
|
||||
png_chunk_report(png_ptr, "unknown chunk: out of memory",
|
||||
PNG_CHUNK_ERROR);
|
||||
PNG_CHUNK_ERROR);
|
||||
/* But just skip storing the unknown chunk */
|
||||
continue;
|
||||
}
|
||||
@@ -1518,7 +1537,7 @@ png_set_keep_unknown_chunks(png_structrp png_ptr, int keep,
|
||||
for (i=0; i<num_chunks; ++i)
|
||||
{
|
||||
old_num_chunks = add_one_chunk(png_ptr, new_list, old_num_chunks,
|
||||
chunk_list+5*i, keep);
|
||||
chunk_list+5*i, keep);
|
||||
}
|
||||
|
||||
/* Now remove any spurious 'default' entries. */
|
||||
@@ -1606,7 +1625,7 @@ png_set_compression_buffer_size(png_structrp png_ptr, png_alloc_size_t size)
|
||||
png_error(png_ptr, "invalid compression buffer size");
|
||||
|
||||
# if (defined PNG_SEQUENTIAL_READ_SUPPORTED) || defined PNG_WRITE_SUPPORTED
|
||||
png_ptr->IDAT_size = (png_uint_32)/*SAFE*/size;
|
||||
png_ptr->IDAT_size = (png_uint_32)/*SAFE*/size;
|
||||
# endif /* SEQUENTIAL_READ || WRITE */
|
||||
}
|
||||
|
||||
@@ -1652,27 +1671,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 */
|
||||
|
||||
78
pngstruct.h
@@ -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
|
||||
@@ -382,10 +391,11 @@ struct png_struct_def
|
||||
png_uint_32 width; /* width of image in pixels */
|
||||
png_uint_32 height; /* height of image in pixels */
|
||||
png_uint_32 chunk_name; /* PNG_CHUNK() id of current chunk */
|
||||
#ifdef PNG_READ_SUPPORTED
|
||||
png_uint_32 chunk_length; /* Length (possibly remaining) in said chunk. */
|
||||
#endif /* READ */
|
||||
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 +403,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 */
|
||||
@@ -410,18 +422,12 @@ struct png_struct_def
|
||||
/* Single byte values, typically used either to save space or to hold 1-byte
|
||||
* values from the PNG chunk specifications.
|
||||
*/
|
||||
png_byte compression_type; /* file compression type (always 0) */
|
||||
png_byte filter_method; /* file filter type (only non-0 with MNG) */
|
||||
png_byte interlaced; /* PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
|
||||
png_byte color_type; /* color type of file */
|
||||
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 /* SET_OPTIONS */
|
||||
|
||||
#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
|
||||
@@ -444,7 +450,6 @@ struct png_struct_def
|
||||
*/
|
||||
#ifdef PNG_READ_SUPPORTED
|
||||
png_bytep row_buffer; /* primary row buffer */
|
||||
#endif /* READ */
|
||||
#if (defined(PNG_PROGRESSIVE_READ_SUPPORTED) ||\
|
||||
defined(PNG_READ_INTERLACING_SUPPORTED)) &&\
|
||||
defined(PNG_TRANSFORM_MECH_SUPPORTED)
|
||||
@@ -453,11 +458,11 @@ struct png_struct_def
|
||||
*/
|
||||
#endif /* (PROGRESSIVE_READ || READ_INTERLACING) && TRANSFORM_MECH */
|
||||
|
||||
#ifdef PNG_READ_SUPPORTED
|
||||
png_alloc_size_t row_bytes_read; /* Total read in row */
|
||||
#endif /* READ */
|
||||
|
||||
png_uint_32 row_number; /* current row in pass */
|
||||
#ifdef PNG_READ_SUPPORTED
|
||||
#ifdef PNG_READ_GAMMA_SUPPORTED
|
||||
png_fixed_point row_gamma; /* Gamma of final output */
|
||||
#if 0 /* NYI */
|
||||
@@ -482,23 +487,22 @@ 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 /* SEQUENTIAL_READ */
|
||||
#if defined (PNG_READ_INTERLACING_SUPPORTED) ||\
|
||||
defined (PNG_WRITE_INTERLACING_SUPPORTED)
|
||||
unsigned int do_interlace :1; /* libpng handles the interlace */
|
||||
# endif /* R/W INTERLACING */
|
||||
unsigned int pass :3; /* current (interlace) pass (0 - 6) */
|
||||
|
||||
/* The next two fields are just used by the IDAT process functions to store
|
||||
/* The next field is just used by the read IDAT process functions to store
|
||||
* the state of IDAT processing; they should not be altered or used by other
|
||||
* functions.
|
||||
*/
|
||||
unsigned int row_state :2; /* state of row parsing (internal) */
|
||||
#endif /* READ */
|
||||
|
||||
#if defined (PNG_READ_INTERLACING_SUPPORTED) ||\
|
||||
defined (PNG_WRITE_INTERLACING_SUPPORTED)
|
||||
unsigned int do_interlace :1; /* libpng handles the interlace */
|
||||
# endif /* R/W INTERLACING */
|
||||
|
||||
unsigned int pass :3; /* current (interlace) pass (0 - 6) */
|
||||
|
||||
/* The following fields are set by png_row_init to the pixel depths of the
|
||||
* pixels at various states. If transforms are not supported they will
|
||||
@@ -735,6 +739,28 @@ 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
|
||||
|
||||
391
pngtest.c
@@ -1,7 +1,7 @@
|
||||
|
||||
/* pngtest.c - a simple test program to test libpng
|
||||
*
|
||||
* Last changed in libpng 1.5.25 [(PENDING RELEASE)]
|
||||
* Last changed in libpng 1.6.26 [(PENDING RELEASE)]
|
||||
* Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson
|
||||
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
|
||||
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
|
||||
@@ -130,13 +130,13 @@ static char tIME_string[PNG_tIME_STRING_LENGTH] = "tIME chunk is not present";
|
||||
static int
|
||||
tIME_to_str(png_structp png_ptr, png_charp ts, png_const_timep t)
|
||||
{
|
||||
png_const_charp str = png_convert_to_rfc1123(png_ptr, t);
|
||||
png_const_charp str = png_convert_to_rfc1123(png_ptr, t);
|
||||
|
||||
if (str == NULL)
|
||||
return 0;
|
||||
if (str == NULL)
|
||||
return 0;
|
||||
|
||||
strcpy(ts, str);
|
||||
return 1;
|
||||
strcpy(ts, str);
|
||||
return 1;
|
||||
}
|
||||
#endif /* older libpng */
|
||||
#endif
|
||||
@@ -240,95 +240,95 @@ count_zero_samples(png_structp png_ptr, png_row_infop row_info, png_bytep data)
|
||||
* png_byte pixel_depth bits per pixel (depth*channels)
|
||||
*/
|
||||
|
||||
/* Counts the number of zero samples (or zero pixels if color_type is 3 */
|
||||
/* Counts the number of zero samples (or zero pixels if color_type is 3 */
|
||||
|
||||
if (row_info->color_type == 0 || row_info->color_type == 3)
|
||||
{
|
||||
int pos = 0;
|
||||
png_uint_32 n, nstop;
|
||||
if (row_info->color_type == 0 || row_info->color_type == 3)
|
||||
{
|
||||
int pos = 0;
|
||||
png_uint_32 n, nstop;
|
||||
|
||||
for (n = 0, nstop=row_info->width; n<nstop; n++)
|
||||
{
|
||||
if (row_info->bit_depth == 1)
|
||||
{
|
||||
if (((*dp << pos++ ) & 0x80) == 0)
|
||||
zero_samples++;
|
||||
for (n = 0, nstop=row_info->width; n<nstop; n++)
|
||||
{
|
||||
if (row_info->bit_depth == 1)
|
||||
{
|
||||
if (((*dp << pos++ ) & 0x80) == 0)
|
||||
zero_samples++;
|
||||
|
||||
if (pos == 8)
|
||||
{
|
||||
pos = 0;
|
||||
dp++;
|
||||
}
|
||||
}
|
||||
if (pos == 8)
|
||||
{
|
||||
pos = 0;
|
||||
dp++;
|
||||
}
|
||||
}
|
||||
|
||||
if (row_info->bit_depth == 2)
|
||||
{
|
||||
if (((*dp << (pos+=2)) & 0xc0) == 0)
|
||||
zero_samples++;
|
||||
if (row_info->bit_depth == 2)
|
||||
{
|
||||
if (((*dp << (pos+=2)) & 0xc0) == 0)
|
||||
zero_samples++;
|
||||
|
||||
if (pos == 8)
|
||||
{
|
||||
pos = 0;
|
||||
dp++;
|
||||
}
|
||||
}
|
||||
if (pos == 8)
|
||||
{
|
||||
pos = 0;
|
||||
dp++;
|
||||
}
|
||||
}
|
||||
|
||||
if (row_info->bit_depth == 4)
|
||||
{
|
||||
if (((*dp << (pos+=4)) & 0xf0) == 0)
|
||||
zero_samples++;
|
||||
if (row_info->bit_depth == 4)
|
||||
{
|
||||
if (((*dp << (pos+=4)) & 0xf0) == 0)
|
||||
zero_samples++;
|
||||
|
||||
if (pos == 8)
|
||||
{
|
||||
pos = 0;
|
||||
dp++;
|
||||
}
|
||||
}
|
||||
if (pos == 8)
|
||||
{
|
||||
pos = 0;
|
||||
dp++;
|
||||
}
|
||||
}
|
||||
|
||||
if (row_info->bit_depth == 8)
|
||||
if (*dp++ == 0)
|
||||
zero_samples++;
|
||||
if (row_info->bit_depth == 8)
|
||||
if (*dp++ == 0)
|
||||
zero_samples++;
|
||||
|
||||
if (row_info->bit_depth == 16)
|
||||
{
|
||||
if ((*dp | *(dp+1)) == 0)
|
||||
zero_samples++;
|
||||
dp+=2;
|
||||
}
|
||||
}
|
||||
}
|
||||
else /* Other color types */
|
||||
{
|
||||
png_uint_32 n, nstop;
|
||||
int channel;
|
||||
int color_channels = row_info->channels;
|
||||
if (row_info->color_type > 3)
|
||||
color_channels--;
|
||||
if (row_info->bit_depth == 16)
|
||||
{
|
||||
if ((*dp | *(dp+1)) == 0)
|
||||
zero_samples++;
|
||||
dp+=2;
|
||||
}
|
||||
}
|
||||
}
|
||||
else /* Other color types */
|
||||
{
|
||||
png_uint_32 n, nstop;
|
||||
int channel;
|
||||
int color_channels = row_info->channels;
|
||||
if (row_info->color_type > 3)
|
||||
color_channels--;
|
||||
|
||||
for (n = 0, nstop=row_info->width; n<nstop; n++)
|
||||
{
|
||||
for (channel = 0; channel < color_channels; channel++)
|
||||
{
|
||||
if (row_info->bit_depth == 8)
|
||||
if (*dp++ == 0)
|
||||
zero_samples++;
|
||||
for (n = 0, nstop=row_info->width; n<nstop; n++)
|
||||
{
|
||||
for (channel = 0; channel < color_channels; channel++)
|
||||
{
|
||||
if (row_info->bit_depth == 8)
|
||||
if (*dp++ == 0)
|
||||
zero_samples++;
|
||||
|
||||
if (row_info->bit_depth == 16)
|
||||
{
|
||||
if ((*dp | *(dp+1)) == 0)
|
||||
zero_samples++;
|
||||
if (row_info->bit_depth == 16)
|
||||
{
|
||||
if ((*dp | *(dp+1)) == 0)
|
||||
zero_samples++;
|
||||
|
||||
dp+=2;
|
||||
}
|
||||
}
|
||||
if (row_info->color_type > 3)
|
||||
{
|
||||
dp++;
|
||||
if (row_info->bit_depth == 16)
|
||||
dp++;
|
||||
}
|
||||
}
|
||||
}
|
||||
dp+=2;
|
||||
}
|
||||
}
|
||||
if (row_info->color_type > 3)
|
||||
{
|
||||
dp++;
|
||||
if (row_info->bit_depth == 16)
|
||||
dp++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* WRITE_USER_TRANSFORM */
|
||||
|
||||
@@ -345,10 +345,10 @@ count_zero_samples(png_structp png_ptr, png_row_infop row_info, png_bytep data)
|
||||
#ifdef PNG_IO_STATE_SUPPORTED
|
||||
void
|
||||
pngtest_check_io_state(png_structp png_ptr, png_size_t data_length,
|
||||
png_uint_32 io_op);
|
||||
png_uint_32 io_op);
|
||||
void
|
||||
pngtest_check_io_state(png_structp png_ptr, png_size_t data_length,
|
||||
png_uint_32 io_op)
|
||||
png_uint_32 io_op)
|
||||
{
|
||||
png_uint_32 io_state = png_get_io_state(png_ptr);
|
||||
int err = 0;
|
||||
@@ -532,7 +532,7 @@ PNGCBAPI png_debug_malloc(png_structp png_ptr, png_alloc_size_t size)
|
||||
memory_infop pinfo;
|
||||
png_set_mem_fn(png_ptr, NULL, NULL, NULL);
|
||||
pinfo = (memory_infop)png_malloc(png_ptr,
|
||||
(sizeof *pinfo));
|
||||
(sizeof *pinfo));
|
||||
pinfo->size = size;
|
||||
current_allocation += size;
|
||||
total_allocation += size;
|
||||
@@ -562,7 +562,7 @@ PNGCBAPI png_debug_malloc(png_structp png_ptr, png_alloc_size_t size)
|
||||
|
||||
if (verbose != 0)
|
||||
printf("png_malloc %lu bytes at %p\n", (unsigned long)size,
|
||||
pinfo->pointer);
|
||||
pinfo->pointer);
|
||||
|
||||
return (png_voidp)(pinfo->pointer);
|
||||
}
|
||||
@@ -769,9 +769,9 @@ write_vpAg_chunk(png_structp write_ptr)
|
||||
|
||||
if (verbose != 0)
|
||||
fprintf(STDERR, " vpAg = %lu x %lu, units = %d\n",
|
||||
(unsigned long)user_chunk_data.vpAg_width,
|
||||
(unsigned long)user_chunk_data.vpAg_height,
|
||||
user_chunk_data.vpAg_units);
|
||||
(unsigned long)user_chunk_data.vpAg_width,
|
||||
(unsigned long)user_chunk_data.vpAg_height,
|
||||
user_chunk_data.vpAg_units);
|
||||
|
||||
png_save_uint_32(vpag_chunk_data, user_chunk_data.vpAg_width);
|
||||
png_save_uint_32(vpag_chunk_data + 4, user_chunk_data.vpAg_height);
|
||||
@@ -812,7 +812,7 @@ write_chunks(png_structp write_ptr, int location)
|
||||
#ifdef PNG_TEXT_SUPPORTED
|
||||
static void
|
||||
pngtest_check_text_support(png_structp png_ptr, png_textp text_ptr,
|
||||
int num_text)
|
||||
int num_text)
|
||||
{
|
||||
while (num_text > 0)
|
||||
{
|
||||
@@ -894,26 +894,26 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
pngtest_debug("Allocating read and write structures");
|
||||
#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
|
||||
read_ptr =
|
||||
png_create_read_struct_2(PNG_LIBPNG_VER_STRING, NULL,
|
||||
NULL, NULL, NULL, png_debug_malloc, png_debug_free);
|
||||
png_create_read_struct_2(PNG_LIBPNG_VER_STRING, NULL,
|
||||
NULL, NULL, NULL, png_debug_malloc, png_debug_free);
|
||||
#else
|
||||
read_ptr =
|
||||
png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||
png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||
#endif
|
||||
png_set_error_fn(read_ptr, &error_parameters, pngtest_error,
|
||||
pngtest_warning);
|
||||
pngtest_warning);
|
||||
|
||||
#ifdef PNG_WRITE_SUPPORTED
|
||||
#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
|
||||
write_ptr =
|
||||
png_create_write_struct_2(PNG_LIBPNG_VER_STRING, NULL,
|
||||
NULL, NULL, NULL, png_debug_malloc, png_debug_free);
|
||||
png_create_write_struct_2(PNG_LIBPNG_VER_STRING, NULL,
|
||||
NULL, NULL, NULL, png_debug_malloc, png_debug_free);
|
||||
#else
|
||||
write_ptr =
|
||||
png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||
png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||
#endif
|
||||
png_set_error_fn(write_ptr, &error_parameters, pngtest_error,
|
||||
pngtest_warning);
|
||||
pngtest_warning);
|
||||
#endif
|
||||
pngtest_debug("Allocating read_info, write_info and end_info structures");
|
||||
read_info_ptr = png_create_info_struct(read_ptr);
|
||||
@@ -926,7 +926,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
#ifdef PNG_READ_USER_CHUNKS_SUPPORTED
|
||||
init_callback_info(read_info_ptr);
|
||||
png_set_read_user_chunk_fn(read_ptr, &user_chunk_data,
|
||||
read_user_chunk_callback);
|
||||
read_user_chunk_callback);
|
||||
#endif
|
||||
|
||||
#ifdef PNG_SETJMP_SUPPORTED
|
||||
@@ -964,15 +964,16 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef PNG_BENIGN_ERRORS_SUPPORTED
|
||||
if (strict != 0)
|
||||
{
|
||||
/* Treat png_benign_error() as errors on read */
|
||||
png_set_benign_errors(read_ptr, 0);
|
||||
|
||||
#ifdef PNG_WRITE_SUPPORTED
|
||||
# ifdef PNG_WRITE_SUPPORTED
|
||||
/* Treat them as errors on write */
|
||||
png_set_benign_errors(write_ptr, 0);
|
||||
#endif
|
||||
# endif
|
||||
|
||||
/* if strict is not set, then app warnings and errors are treated as
|
||||
* warnings in release builds, but not in unstable builds; this can be
|
||||
@@ -985,10 +986,15 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
/* Allow application (pngtest) errors and warnings to pass */
|
||||
png_set_benign_errors(read_ptr, 1);
|
||||
|
||||
#ifdef PNG_WRITE_SUPPORTED
|
||||
/* Turn off CRC and ADLER32 checking while reading */
|
||||
png_set_crc_action(read_ptr, PNG_CRC_QUIET_USE, PNG_CRC_QUIET_USE);
|
||||
|
||||
# ifdef PNG_WRITE_SUPPORTED
|
||||
png_set_benign_errors(write_ptr, 1);
|
||||
#endif
|
||||
# endif
|
||||
|
||||
}
|
||||
#endif /* BENIGN_ERRORS */
|
||||
|
||||
pngtest_debug("Initializing input and output streams");
|
||||
#ifdef PNG_STDIO_SUPPORTED
|
||||
@@ -1001,9 +1007,9 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
# ifdef PNG_WRITE_SUPPORTED
|
||||
png_set_write_fn(write_ptr, (png_voidp)fpout, pngtest_write_data,
|
||||
# ifdef PNG_WRITE_FLUSH_SUPPORTED
|
||||
pngtest_flush);
|
||||
pngtest_flush);
|
||||
# else
|
||||
NULL);
|
||||
NULL);
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
@@ -1043,11 +1049,11 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
*/
|
||||
#ifdef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED
|
||||
png_set_keep_unknown_chunks(read_ptr, PNG_HANDLE_CHUNK_ALWAYS,
|
||||
NULL, 0);
|
||||
NULL, 0);
|
||||
#endif
|
||||
#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
|
||||
png_set_keep_unknown_chunks(write_ptr, PNG_HANDLE_CHUNK_ALWAYS,
|
||||
NULL, 0);
|
||||
NULL, 0);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -1071,7 +1077,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
&color_type, &interlace_type, &compression_type, &filter_type) != 0)
|
||||
{
|
||||
png_set_IHDR(write_ptr, write_info_ptr, width, height, bit_depth,
|
||||
color_type, interlace_type, compression_type, filter_type);
|
||||
color_type, interlace_type, compression_type, filter_type);
|
||||
/* num_passes may not be available below if interlace support is not
|
||||
* provided by libpng for both read and write.
|
||||
*/
|
||||
@@ -1098,13 +1104,13 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
#ifdef PNG_cHRM_SUPPORTED
|
||||
{
|
||||
png_fixed_point white_x, white_y, red_x, red_y, green_x, green_y, blue_x,
|
||||
blue_y;
|
||||
blue_y;
|
||||
|
||||
if (png_get_cHRM_fixed(read_ptr, read_info_ptr, &white_x, &white_y,
|
||||
&red_x, &red_y, &green_x, &green_y, &blue_x, &blue_y) != 0)
|
||||
&red_x, &red_y, &green_x, &green_y, &blue_x, &blue_y) != 0)
|
||||
{
|
||||
png_set_cHRM_fixed(write_ptr, write_info_ptr, white_x, white_y, red_x,
|
||||
red_y, green_x, green_y, blue_x, blue_y);
|
||||
red_y, green_x, green_y, blue_x, blue_y);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1121,13 +1127,13 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
#ifdef PNG_cHRM_SUPPORTED
|
||||
{
|
||||
double white_x, white_y, red_x, red_y, green_x, green_y, blue_x,
|
||||
blue_y;
|
||||
blue_y;
|
||||
|
||||
if (png_get_cHRM(read_ptr, read_info_ptr, &white_x, &white_y, &red_x,
|
||||
&red_y, &green_x, &green_y, &blue_x, &blue_y) != 0)
|
||||
&red_y, &green_x, &green_y, &blue_x, &blue_y) != 0)
|
||||
{
|
||||
png_set_cHRM(write_ptr, write_info_ptr, white_x, white_y, red_x,
|
||||
red_y, green_x, green_y, blue_x, blue_y);
|
||||
red_y, green_x, green_y, blue_x, blue_y);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1149,10 +1155,10 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
int compression_type;
|
||||
|
||||
if (png_get_iCCP(read_ptr, read_info_ptr, &name, &compression_type,
|
||||
&profile, &proflen) != 0)
|
||||
&profile, &proflen) != 0)
|
||||
{
|
||||
png_set_iCCP(write_ptr, write_info_ptr, name, compression_type,
|
||||
profile, proflen);
|
||||
profile, proflen);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1209,10 +1215,10 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
int type, nparams;
|
||||
|
||||
if (png_get_pCAL(read_ptr, read_info_ptr, &purpose, &X0, &X1, &type,
|
||||
&nparams, &units, ¶ms) != 0)
|
||||
&nparams, &units, ¶ms) != 0)
|
||||
{
|
||||
png_set_pCAL(write_ptr, write_info_ptr, purpose, X0, X1, type,
|
||||
nparams, units, params);
|
||||
nparams, units, params);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1242,7 +1248,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
double scal_width, scal_height;
|
||||
|
||||
if (png_get_sCAL(read_ptr, read_info_ptr, &unit, &scal_width,
|
||||
&scal_height) != 0)
|
||||
&scal_height) != 0)
|
||||
{
|
||||
png_set_sCAL(write_ptr, write_info_ptr, unit, scal_width, scal_height);
|
||||
}
|
||||
@@ -1254,7 +1260,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
png_charp scal_width, scal_height;
|
||||
|
||||
if (png_get_sCAL_s(read_ptr, read_info_ptr, &unit, &scal_width,
|
||||
&scal_height) != 0)
|
||||
&scal_height) != 0)
|
||||
{
|
||||
png_set_sCAL_s(write_ptr, write_info_ptr, unit, scal_width,
|
||||
scal_height);
|
||||
@@ -1295,7 +1301,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
for (i=0; i<num_text; i++)
|
||||
{
|
||||
printf(" Text compression[%d]=%d\n",
|
||||
i, text_ptr[i].compression);
|
||||
i, text_ptr[i].compression);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1332,7 +1338,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
png_color_16p trans_color;
|
||||
|
||||
if (png_get_tRNS(read_ptr, read_info_ptr, &trans_alpha, &num_trans,
|
||||
&trans_color) != 0)
|
||||
&trans_color) != 0)
|
||||
{
|
||||
int sample_max = (1 << bit_depth);
|
||||
/* libpng doesn't reject a tRNS chunk with out-of-range samples */
|
||||
@@ -1351,12 +1357,12 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
{
|
||||
png_unknown_chunkp unknowns;
|
||||
int num_unknowns = png_get_unknown_chunks(read_ptr, read_info_ptr,
|
||||
&unknowns);
|
||||
&unknowns);
|
||||
|
||||
if (num_unknowns != 0)
|
||||
{
|
||||
png_set_unknown_chunks(write_ptr, write_info_ptr, unknowns,
|
||||
num_unknowns);
|
||||
num_unknowns);
|
||||
#if PNG_LIBPNG_VER < 10600
|
||||
/* Copy the locations from the read_info_ptr. The automatically
|
||||
* generated locations in write_end_info_ptr are wrong prior to 1.6.0
|
||||
@@ -1366,7 +1372,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
int i;
|
||||
for (i = 0; i < num_unknowns; i++)
|
||||
png_set_unknown_chunk_location(write_ptr, write_info_ptr, i,
|
||||
unknowns[i].location);
|
||||
unknowns[i].location);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -1386,12 +1392,17 @@ 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
|
||||
pngtest_debug("Allocating row buffer...");
|
||||
row_buf = (png_bytep)png_malloc(read_ptr,
|
||||
png_get_rowbytes(read_ptr, read_info_ptr));
|
||||
png_get_rowbytes(read_ptr, read_info_ptr));
|
||||
|
||||
pngtest_debug1("\t0x%08lx", (unsigned long)row_buf);
|
||||
#endif /* SINGLE_ROWBUF_ALLOC */
|
||||
@@ -1405,10 +1416,10 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
*/
|
||||
if (png_set_interlace_handling(read_ptr) != num_passes)
|
||||
png_error(write_ptr,
|
||||
"png_set_interlace_handling(read): wrong pass count ");
|
||||
"png_set_interlace_handling(read): wrong pass count ");
|
||||
if (png_set_interlace_handling(write_ptr) != num_passes)
|
||||
png_error(write_ptr,
|
||||
"png_set_interlace_handling(write): wrong pass count ");
|
||||
"png_set_interlace_handling(write): wrong pass count ");
|
||||
#else /* png_set_interlace_handling not called on either read or write */
|
||||
# define calc_pass_height
|
||||
#endif /* not using libpng interlace handling */
|
||||
@@ -1445,10 +1456,10 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
pngtest_debug2("Allocating row buffer (pass %d, y = %u)...", pass, y);
|
||||
|
||||
row_buf = (png_bytep)png_malloc(read_ptr,
|
||||
png_get_rowbytes(read_ptr, read_info_ptr));
|
||||
png_get_rowbytes(read_ptr, read_info_ptr));
|
||||
|
||||
pngtest_debug2("\t0x%08lx (%lu bytes)", (unsigned long)row_buf,
|
||||
(unsigned long)png_get_rowbytes(read_ptr, read_info_ptr));
|
||||
(unsigned long)png_get_rowbytes(read_ptr, read_info_ptr));
|
||||
|
||||
#endif /* !SINGLE_ROWBUF_ALLOC */
|
||||
png_read_rows(read_ptr, (png_bytepp)&row_buf, NULL, 1);
|
||||
@@ -1506,7 +1517,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
for (i=0; i<num_text; i++)
|
||||
{
|
||||
printf(" Text compression[%d]=%d\n",
|
||||
i, text_ptr[i].compression);
|
||||
i, text_ptr[i].compression);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1540,12 +1551,12 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
{
|
||||
png_unknown_chunkp unknowns;
|
||||
int num_unknowns = png_get_unknown_chunks(read_ptr, end_info_ptr,
|
||||
&unknowns);
|
||||
&unknowns);
|
||||
|
||||
if (num_unknowns != 0)
|
||||
{
|
||||
png_set_unknown_chunks(write_ptr, write_end_info_ptr, unknowns,
|
||||
num_unknowns);
|
||||
num_unknowns);
|
||||
#if PNG_LIBPNG_VER < 10600
|
||||
/* Copy the locations from the read_info_ptr. The automatically
|
||||
* generated locations in write_end_info_ptr are wrong prior to 1.6.0
|
||||
@@ -1555,7 +1566,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
int i;
|
||||
for (i = 0; i < num_unknowns; i++)
|
||||
png_set_unknown_chunk_location(write_ptr, write_end_info_ptr, i,
|
||||
unknowns[i].location);
|
||||
unknowns[i].location);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -1589,7 +1600,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
iwidth = png_get_image_width(write_ptr, write_info_ptr);
|
||||
iheight = png_get_image_height(write_ptr, write_info_ptr);
|
||||
fprintf(STDERR, "\n Image width = %lu, height = %lu\n",
|
||||
(unsigned long)iwidth, (unsigned long)iheight);
|
||||
(unsigned long)iwidth, (unsigned long)iheight);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1622,7 +1633,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
* above, but this is safe.
|
||||
*/
|
||||
fprintf(STDERR, "\n %s: %d libpng errors found (%d warnings)",
|
||||
inname, error_count, warning_count);
|
||||
inname, error_count, warning_count);
|
||||
|
||||
if (strict != 0)
|
||||
return (1);
|
||||
@@ -1633,14 +1644,14 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
else if (unsupported_chunks > 0)
|
||||
{
|
||||
fprintf(STDERR, "\n %s: unsupported chunks (%d)%s",
|
||||
inname, unsupported_chunks, strict ? ": IGNORED --strict!" : "");
|
||||
inname, unsupported_chunks, strict ? ": IGNORED --strict!" : "");
|
||||
}
|
||||
# endif
|
||||
|
||||
else if (warning_count > 0)
|
||||
{
|
||||
fprintf(STDERR, "\n %s: %d libpng warnings found",
|
||||
inname, warning_count);
|
||||
inname, warning_count);
|
||||
|
||||
if (strict != 0)
|
||||
return (1);
|
||||
@@ -1676,18 +1687,19 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
if (num_in != num_out)
|
||||
{
|
||||
fprintf(STDERR, "\nFiles %s and %s are of a different size\n",
|
||||
inname, outname);
|
||||
inname, outname);
|
||||
|
||||
if (wrote_question == 0 && unsupported_chunks == 0)
|
||||
{
|
||||
fprintf(STDERR,
|
||||
" Was %s written with the same maximum IDAT chunk size (%d bytes),",
|
||||
inname, PNG_ZBUF_SIZE);
|
||||
" Was %s written with the same maximum IDAT"
|
||||
" chunk size (%d bytes),",
|
||||
inname, PNG_ZBUF_SIZE);
|
||||
fprintf(STDERR,
|
||||
"\n filtering heuristic (libpng default), compression");
|
||||
"\n filtering heuristic (libpng default), compression");
|
||||
fprintf(STDERR,
|
||||
" level (zlib default),\n and zlib version (%s)?\n\n",
|
||||
ZLIB_VERSION);
|
||||
" level (zlib default),\n and zlib version (%s)?\n\n",
|
||||
ZLIB_VERSION);
|
||||
wrote_question = 1;
|
||||
}
|
||||
|
||||
@@ -1707,17 +1719,18 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
if (memcmp(inbuf, outbuf, num_in))
|
||||
{
|
||||
fprintf(STDERR, "\nFiles %s and %s are different\n", inname,
|
||||
outname);
|
||||
outname);
|
||||
|
||||
if (wrote_question == 0 && unsupported_chunks == 0)
|
||||
{
|
||||
fprintf(STDERR,
|
||||
" Was %s written with the same maximum IDAT chunk size (%d bytes),",
|
||||
" Was %s written with the same maximum"
|
||||
" IDAT chunk size (%d bytes),",
|
||||
inname, PNG_ZBUF_SIZE);
|
||||
fprintf(STDERR,
|
||||
"\n filtering heuristic (libpng default), compression");
|
||||
"\n filtering heuristic (libpng default), compression");
|
||||
fprintf(STDERR,
|
||||
" level (zlib default),\n and zlib version (%s)?\n\n",
|
||||
" level (zlib default),\n and zlib version (%s)?\n\n",
|
||||
ZLIB_VERSION);
|
||||
wrote_question = 1;
|
||||
}
|
||||
@@ -1768,12 +1781,12 @@ main(int argc, char *argv[])
|
||||
fprintf(STDERR, "%s", png_get_copyright(NULL));
|
||||
/* Show the version of libpng used in building the library */
|
||||
fprintf(STDERR, " library (%lu):%s",
|
||||
(unsigned long)png_access_version_number(),
|
||||
png_get_header_version(NULL));
|
||||
(unsigned long)png_access_version_number(),
|
||||
png_get_header_version(NULL));
|
||||
|
||||
/* Show the version of libpng used in building the application */
|
||||
fprintf(STDERR, " pngtest (%lu):%s", (unsigned long)PNG_LIBPNG_VER,
|
||||
PNG_HEADER_VERSION_STRING);
|
||||
PNG_HEADER_VERSION_STRING);
|
||||
|
||||
/* Do some consistency checking on the memory allocation settings, I'm
|
||||
* not sure this matters, but it is nice to know, the first of these
|
||||
@@ -1791,7 +1804,7 @@ main(int argc, char *argv[])
|
||||
if (strcmp(png_libpng_ver, PNG_LIBPNG_VER_STRING))
|
||||
{
|
||||
fprintf(STDERR,
|
||||
"Warning: versions are different between png.h and png.c\n");
|
||||
"Warning: versions are different between png.h and png.c\n");
|
||||
fprintf(STDERR, " png.h version: %s\n", PNG_LIBPNG_VER_STRING);
|
||||
fprintf(STDERR, " png.c version: %s\n\n", png_libpng_ver);
|
||||
++ierror;
|
||||
@@ -1846,19 +1859,19 @@ main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
if (multiple == 0 && argc == 3 + verbose)
|
||||
outname = argv[2 + verbose];
|
||||
outname = argv[2 + verbose];
|
||||
|
||||
if ((multiple == 0 && argc > 3 + verbose) ||
|
||||
(multiple != 0 && argc < 2))
|
||||
{
|
||||
fprintf(STDERR,
|
||||
"usage: %s [infile.png] [outfile.png]\n\t%s -m {infile.png}\n",
|
||||
argv[0], argv[0]);
|
||||
fprintf(STDERR,
|
||||
" reads/writes one PNG file (without -m) or multiple files (-m)\n");
|
||||
fprintf(STDERR,
|
||||
" with -m %s is used as a temporary file\n", outname);
|
||||
exit(1);
|
||||
fprintf(STDERR,
|
||||
"usage: %s [infile.png] [outfile.png]\n\t%s -m {infile.png}\n",
|
||||
argv[0], argv[0]);
|
||||
fprintf(STDERR,
|
||||
" reads/writes one PNG file (without -m) or multiple files (-m)\n");
|
||||
fprintf(STDERR,
|
||||
" with -m %s is used as a temporary file\n", outname);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (multiple != 0)
|
||||
@@ -1879,7 +1892,7 @@ main(int argc, char *argv[])
|
||||
{
|
||||
#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
|
||||
fprintf(STDERR, "\n PASS (%lu zero samples)\n",
|
||||
(unsigned long)zero_samples);
|
||||
(unsigned long)zero_samples);
|
||||
#else
|
||||
fprintf(STDERR, " PASS\n");
|
||||
#endif
|
||||
@@ -1899,20 +1912,20 @@ main(int argc, char *argv[])
|
||||
#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
|
||||
if (allocation_now != current_allocation)
|
||||
fprintf(STDERR, "MEMORY ERROR: %d bytes lost\n",
|
||||
current_allocation - allocation_now);
|
||||
current_allocation - allocation_now);
|
||||
|
||||
if (current_allocation != 0)
|
||||
{
|
||||
memory_infop pinfo = pinformation;
|
||||
|
||||
fprintf(STDERR, "MEMORY ERROR: %d bytes still allocated\n",
|
||||
current_allocation);
|
||||
current_allocation);
|
||||
|
||||
while (pinfo != NULL)
|
||||
{
|
||||
fprintf(STDERR, " %lu bytes at %p\n",
|
||||
(unsigned long)pinfo->size,
|
||||
pinfo->pointer);
|
||||
(unsigned long)pinfo->size,
|
||||
pinfo->pointer);
|
||||
pinfo = pinfo->next;
|
||||
}
|
||||
}
|
||||
@@ -1920,13 +1933,13 @@ main(int argc, char *argv[])
|
||||
}
|
||||
#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
|
||||
fprintf(STDERR, " Current memory allocation: %10d bytes\n",
|
||||
current_allocation);
|
||||
current_allocation);
|
||||
fprintf(STDERR, " Maximum memory allocation: %10d bytes\n",
|
||||
maximum_allocation);
|
||||
maximum_allocation);
|
||||
fprintf(STDERR, " Total memory allocation: %10d bytes\n",
|
||||
total_allocation);
|
||||
total_allocation);
|
||||
fprintf(STDERR, " Number of allocations: %10d\n",
|
||||
num_allocations);
|
||||
num_allocations);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1961,7 +1974,7 @@ main(int argc, char *argv[])
|
||||
{
|
||||
#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
|
||||
fprintf(STDERR, "\n PASS (%lu zero samples)\n",
|
||||
(unsigned long)zero_samples);
|
||||
(unsigned long)zero_samples);
|
||||
#else
|
||||
fprintf(STDERR, " PASS\n");
|
||||
#endif
|
||||
@@ -1988,19 +2001,19 @@ main(int argc, char *argv[])
|
||||
#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
|
||||
if (allocation_now != current_allocation)
|
||||
fprintf(STDERR, "MEMORY ERROR: %d bytes lost\n",
|
||||
current_allocation - allocation_now);
|
||||
current_allocation - allocation_now);
|
||||
|
||||
if (current_allocation != 0)
|
||||
{
|
||||
memory_infop pinfo = pinformation;
|
||||
|
||||
fprintf(STDERR, "MEMORY ERROR: %d bytes still allocated\n",
|
||||
current_allocation);
|
||||
current_allocation);
|
||||
|
||||
while (pinfo != NULL)
|
||||
{
|
||||
fprintf(STDERR, " %lu bytes at %p\n",
|
||||
(unsigned long)pinfo->size, pinfo->pointer);
|
||||
(unsigned long)pinfo->size, pinfo->pointer);
|
||||
pinfo = pinfo->next;
|
||||
}
|
||||
}
|
||||
@@ -2008,13 +2021,13 @@ main(int argc, char *argv[])
|
||||
}
|
||||
#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
|
||||
fprintf(STDERR, " Current memory allocation: %10d bytes\n",
|
||||
current_allocation);
|
||||
current_allocation);
|
||||
fprintf(STDERR, " Maximum memory allocation: %10d bytes\n",
|
||||
maximum_allocation);
|
||||
maximum_allocation);
|
||||
fprintf(STDERR, " Total memory allocation: %10d bytes\n",
|
||||
total_allocation);
|
||||
total_allocation);
|
||||
fprintf(STDERR, " Number of allocations: %10d\n",
|
||||
num_allocations);
|
||||
num_allocations);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -2023,13 +2036,13 @@ main(int argc, char *argv[])
|
||||
t_misc += (t_stop - t_start);
|
||||
t_start = t_stop;
|
||||
fprintf(STDERR, " CPU time used = %.3f seconds",
|
||||
(t_misc+t_decode+t_encode)/(float)CLOCKS_PER_SEC);
|
||||
(t_misc+t_decode+t_encode)/(float)CLOCKS_PER_SEC);
|
||||
fprintf(STDERR, " (decoding %.3f,\n",
|
||||
t_decode/(float)CLOCKS_PER_SEC);
|
||||
t_decode/(float)CLOCKS_PER_SEC);
|
||||
fprintf(STDERR, " encoding %.3f ,",
|
||||
t_encode/(float)CLOCKS_PER_SEC);
|
||||
t_encode/(float)CLOCKS_PER_SEC);
|
||||
fprintf(STDERR, " other %.3f seconds)\n\n",
|
||||
t_misc/(float)CLOCKS_PER_SEC);
|
||||
t_misc/(float)CLOCKS_PER_SEC);
|
||||
#endif
|
||||
|
||||
if (ierror == 0)
|
||||
@@ -2041,19 +2054,19 @@ main(int argc, char *argv[])
|
||||
dummy_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||
fprintf(STDERR, " Default limits:\n");
|
||||
fprintf(STDERR, " width_max = %lu\n",
|
||||
(unsigned long) png_get_user_width_max(dummy_ptr));
|
||||
(unsigned long) png_get_user_width_max(dummy_ptr));
|
||||
fprintf(STDERR, " height_max = %lu\n",
|
||||
(unsigned long) png_get_user_height_max(dummy_ptr));
|
||||
(unsigned long) png_get_user_height_max(dummy_ptr));
|
||||
if (png_get_chunk_cache_max(dummy_ptr) == 0)
|
||||
fprintf(STDERR, " cache_max = unlimited\n");
|
||||
else
|
||||
fprintf(STDERR, " cache_max = %lu\n",
|
||||
(unsigned long) png_get_chunk_cache_max(dummy_ptr));
|
||||
(unsigned long) png_get_chunk_cache_max(dummy_ptr));
|
||||
if (png_get_chunk_malloc_max(dummy_ptr) == 0)
|
||||
fprintf(STDERR, " malloc_max = unlimited\n");
|
||||
else
|
||||
fprintf(STDERR, " malloc_max = %lu\n",
|
||||
(unsigned long) png_get_chunk_malloc_max(dummy_ptr));
|
||||
(unsigned long) png_get_chunk_malloc_max(dummy_ptr));
|
||||
png_destroy_read_struct(&dummy_ptr, NULL, NULL);
|
||||
|
||||
return (int)(ierror != 0);
|
||||
@@ -2063,11 +2076,11 @@ int
|
||||
main(void)
|
||||
{
|
||||
fprintf(STDERR,
|
||||
" test ignored because libpng was not built with read support\n");
|
||||
" test ignored because libpng was not built with read support\n");
|
||||
/* And skip this test */
|
||||
return PNG_LIBPNG_VER < 10600 ? 0 : 77;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Generate a compiler error if there is an old png.h in the search path. */
|
||||
typedef png_libpng_version_1_7_0beta80 Your_png_h_is_not_version_1_7_0beta80;
|
||||
typedef png_libpng_version_1_7_0beta90 Your_png_h_is_not_version_1_7_0beta90;
|
||||
|
||||
BIN
pngtest.png
|
Before Width: | Height: | Size: 5.6 KiB After Width: | Height: | Size: 8.5 KiB |
145
pngtrans.c
@@ -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 */
|
||||
@@ -2706,7 +2697,7 @@ png_do_invert_all(png_transformp *transform, png_transform_controlp tc)
|
||||
while (png_upcast(void*,dp) < dp_end)
|
||||
*dp++ = ~*sp++;
|
||||
|
||||
PNG_UNUSED(transform);
|
||||
PNG_UNUSED(transform)
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -2757,7 +2748,7 @@ png_do_invert_channel(png_transformp *transform, png_transform_controlp tc)
|
||||
}
|
||||
}
|
||||
|
||||
PNG_UNUSED(transform);
|
||||
PNG_UNUSED(transform)
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -3588,7 +3579,7 @@ png_set_user_transform_info(png_structrp png_ptr, png_voidp ptr, int depth,
|
||||
}
|
||||
else
|
||||
png_app_error(png_ptr,
|
||||
"cannot change user info after image start");
|
||||
"cannot change user info after image start");
|
||||
}
|
||||
# else /* !READ_USER_TRANSFORM */
|
||||
PNG_UNUSED(depth)
|
||||
|
||||
9
pngwio.c
@@ -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
|
||||
@@ -40,7 +45,7 @@ png_write_data(png_structrp png_ptr, png_const_voidp data, png_size_t length)
|
||||
*/
|
||||
if (png_ptr->rw_data_fn != NULL )
|
||||
png_ptr->rw_data_fn(png_ptr,
|
||||
png_constcast(png_bytep,png_voidcast(png_const_bytep,data)), length);
|
||||
png_constcast(png_bytep,png_voidcast(png_const_bytep,data)), length);
|
||||
|
||||
else
|
||||
png_app_error(png_ptr, "No write function");
|
||||
@@ -125,7 +130,7 @@ png_set_write_fn(png_structrp png_ptr, png_voidp io_ptr,
|
||||
if (write_data_fn == NULL)
|
||||
{
|
||||
png_app_error(png_ptr,
|
||||
"API change: png_set_write_fn requires a function");
|
||||
"API change: png_set_write_fn requires a function");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
236
pngwrite.c
@@ -24,7 +24,7 @@
|
||||
/* Write out all the unknown chunks for the current given location */
|
||||
static void
|
||||
write_unknown_chunks(png_structrp png_ptr, png_const_inforp info_ptr,
|
||||
unsigned int where)
|
||||
unsigned int where)
|
||||
{
|
||||
if (info_ptr->unknown_chunks_num != 0)
|
||||
{
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -175,7 +169,7 @@ png_write_info_before_PLTE(png_structrp png_ptr, png_const_inforp info_ptr)
|
||||
png_ptr->mng_features_permitted != 0)
|
||||
{
|
||||
png_app_error(png_ptr,
|
||||
"MNG features are not allowed in a PNG datastream");
|
||||
"MNG features are not allowed in a PNG datastream");
|
||||
/* Recovery: disable MNG features: */
|
||||
png_ptr->mng_features_permitted = 0;
|
||||
}
|
||||
@@ -183,8 +177,8 @@ png_write_info_before_PLTE(png_structrp png_ptr, png_const_inforp info_ptr)
|
||||
|
||||
/* Write IHDR information. */
|
||||
png_write_IHDR(png_ptr, info_ptr->width, info_ptr->height,
|
||||
info_ptr->bit_depth, color_type, info_ptr->compression_type,
|
||||
info_ptr->filter_type, info_ptr->interlace_type);
|
||||
info_ptr->bit_depth, color_type, info_ptr->compression_type,
|
||||
info_ptr->filter_type, info_ptr->interlace_type);
|
||||
|
||||
# ifdef PNG_WRITE_TRANSFORMS_SUPPORTED
|
||||
/* This are used for checking later on: */
|
||||
@@ -241,11 +235,11 @@ png_write_info_before_PLTE(png_structrp png_ptr, png_const_inforp info_ptr)
|
||||
*/
|
||||
if ((info_ptr->valid & PNG_INFO_sRGB) != 0)
|
||||
png_app_warning(png_ptr,
|
||||
"profile matches sRGB but writing iCCP instead");
|
||||
"profile matches sRGB but writing iCCP instead");
|
||||
# endif /* WRITE_sRGB */
|
||||
|
||||
png_write_iCCP(png_ptr, info_ptr->iccp_name,
|
||||
info_ptr->iccp_profile);
|
||||
info_ptr->iccp_profile);
|
||||
}
|
||||
# ifdef PNG_WRITE_sRGB_SUPPORTED
|
||||
else /* iCCP not written */
|
||||
@@ -286,7 +280,7 @@ png_write_info_before_PLTE(png_structrp png_ptr, png_const_inforp info_ptr)
|
||||
|
||||
else /* 1.7.0: flag multiple calls; previously ignored */
|
||||
png_app_error(png_ptr,
|
||||
"png_write_info_before_PLTE called more than once");
|
||||
"png_write_info_before_PLTE called more than once");
|
||||
}
|
||||
|
||||
void PNGAPI
|
||||
@@ -328,15 +322,15 @@ png_write_info(png_structrp png_ptr, png_const_inforp info_ptr)
|
||||
if ((info_ptr->valid & PNG_INFO_tRNS) !=0)
|
||||
{
|
||||
png_write_tRNS(png_ptr, info_ptr->trans_alpha,
|
||||
&(info_ptr->trans_color), info_ptr->num_trans,
|
||||
PNG_COLOR_TYPE_FROM_FORMAT(info_ptr->format));
|
||||
&(info_ptr->trans_color), info_ptr->num_trans,
|
||||
PNG_COLOR_TYPE_FROM_FORMAT(info_ptr->format));
|
||||
}
|
||||
# endif /* WRITE_tRNS */
|
||||
|
||||
# ifdef PNG_WRITE_bKGD_SUPPORTED
|
||||
if ((info_ptr->valid & PNG_INFO_bKGD) != 0)
|
||||
png_write_bKGD(png_ptr, &(info_ptr->background),
|
||||
PNG_COLOR_TYPE_FROM_FORMAT(info_ptr->format));
|
||||
PNG_COLOR_TYPE_FROM_FORMAT(info_ptr->format));
|
||||
# endif /* WRITE_bKGD */
|
||||
|
||||
# ifdef PNG_WRITE_hIST_SUPPORTED
|
||||
@@ -360,7 +354,7 @@ png_write_info(png_structrp png_ptr, png_const_inforp info_ptr)
|
||||
# ifdef PNG_WRITE_sCAL_SUPPORTED
|
||||
if ((info_ptr->valid & PNG_INFO_sCAL) != 0)
|
||||
png_write_sCAL_s(png_ptr, info_ptr->scal_unit, info_ptr->scal_s_width,
|
||||
info_ptr->scal_s_height);
|
||||
info_ptr->scal_s_height);
|
||||
# endif /* WRITE_sCAL */
|
||||
|
||||
# ifdef PNG_WRITE_pHYs_SUPPORTED
|
||||
@@ -544,27 +538,28 @@ 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;
|
||||
@@ -575,10 +570,10 @@ png_create_write_struct_2,(png_const_charp user_png_ver, png_voidp error_ptr,
|
||||
defined(PNG_WRITE_TRANSFORMS_SUPPORTED)
|
||||
static void
|
||||
write_row_buffered(png_structrp png_ptr,
|
||||
png_const_bytep row, unsigned int row_info_flags,
|
||||
void (*copy_fn)(png_const_structrp png_ptr, png_bytep row_buffer,
|
||||
png_const_bytep row, png_uint_32 x, unsigned int count, unsigned int p),
|
||||
unsigned int copy_parameter)
|
||||
png_const_bytep row, unsigned int row_info_flags,
|
||||
void (*copy_fn)(png_const_structrp png_ptr, png_bytep row_buffer,
|
||||
png_const_bytep row, png_uint_32 x, unsigned int count, unsigned int p),
|
||||
unsigned int copy_parameter)
|
||||
{
|
||||
unsigned int max_pixels = png_max_pixel_block(png_ptr);
|
||||
const unsigned int pass = png_ptr->pass;
|
||||
@@ -619,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);
|
||||
@@ -653,7 +648,7 @@ write_row_buffered(png_structrp png_ptr,
|
||||
* maxpixels says if this is the final block in the row.
|
||||
*/
|
||||
png_write_png_data(png_ptr, prev_pixels, pixel_buffer.buffer, x,
|
||||
max_pixels, row_info_flags);
|
||||
max_pixels, row_info_flags);
|
||||
}
|
||||
}
|
||||
#endif /* WRITE { INTERLACING || TRANSFORMS } */
|
||||
@@ -661,19 +656,19 @@ write_row_buffered(png_structrp png_ptr,
|
||||
#ifdef PNG_WRITE_TRANSFORMS_SUPPORTED
|
||||
static void
|
||||
copy_row(png_const_structrp png_ptr, png_bytep row_buffer,
|
||||
png_const_bytep row, png_uint_32 x, unsigned int count,
|
||||
unsigned int pixel_depth)
|
||||
png_const_bytep row, png_uint_32 x, unsigned int count,
|
||||
unsigned int pixel_depth)
|
||||
{
|
||||
/* Copy row[x..x+count] pixels to row_buffer. */
|
||||
png_copy_row(png_ptr, row_buffer, row, x, count, pixel_depth, 1/*clear*/,
|
||||
0/* x_in_dest; row[x]->row_buffer */);
|
||||
0/* x_in_dest; row[x]->row_buffer */);
|
||||
}
|
||||
#endif /* WRITE_TRANSFORMS */
|
||||
|
||||
#ifdef PNG_WRITE_INTERLACING_SUPPORTED
|
||||
static void
|
||||
interlace_row_lbd(png_const_structrp png_ptr, png_bytep dp, png_const_bytep sp,
|
||||
png_uint_32 x, unsigned int count, const unsigned int B)
|
||||
png_uint_32 x, unsigned int count, const unsigned int B)
|
||||
{
|
||||
/* Pick out the correct pixels for the interlace pass. The basic idea here
|
||||
* is to go through the row with a source pointer and a destination pointer
|
||||
@@ -750,7 +745,7 @@ interlace_row_lbd(png_const_structrp png_ptr, png_bytep dp, png_const_bytep sp,
|
||||
|
||||
static void
|
||||
interlace_row_byte(png_const_structrp png_ptr, png_bytep dp, png_const_bytep sp,
|
||||
png_uint_32 x, unsigned int count, unsigned int cbytes)
|
||||
png_uint_32 x, unsigned int count, unsigned int cbytes)
|
||||
{
|
||||
const unsigned int pass = png_ptr->pass;
|
||||
const unsigned int inc = PNG_PASS_COL_OFFSET(pass);
|
||||
@@ -769,12 +764,12 @@ interlace_row_byte(png_const_structrp png_ptr, png_bytep dp, png_const_bytep sp,
|
||||
#ifdef PNG_WRITE_TRANSFORMS_SUPPORTED
|
||||
static void
|
||||
write_row_core(png_structrp png_ptr, png_const_bytep row,
|
||||
unsigned int row_info_flags)
|
||||
unsigned int row_info_flags)
|
||||
{
|
||||
# ifdef PNG_WRITE_TRANSFORMS_SUPPORTED
|
||||
if (png_ptr->transform_list != NULL)
|
||||
write_row_buffered(png_ptr, row, row_info_flags,
|
||||
copy_row, png_ptr->row_input_pixel_depth);
|
||||
copy_row, png_ptr->row_input_pixel_depth);
|
||||
|
||||
else
|
||||
# endif /* WRITE_TRANSFORMS */
|
||||
@@ -864,12 +859,12 @@ interlace_row(png_structrp png_ptr, png_const_bytep row)
|
||||
/*FALL THROUGH*/
|
||||
case 1U: /* B will be 0 */
|
||||
write_row_buffered(png_ptr, row, row_info_flags,
|
||||
interlace_row_lbd, B);
|
||||
interlace_row_lbd, B);
|
||||
break;
|
||||
|
||||
default: /* Parameter is the pixel size in bytes */
|
||||
write_row_buffered(png_ptr, row, row_info_flags,
|
||||
interlace_row_byte, input_depth >> 3);
|
||||
interlace_row_byte, input_depth >> 3);
|
||||
break;
|
||||
}
|
||||
} /* pass < 6 */
|
||||
@@ -900,7 +895,7 @@ interlace_row(png_structrp png_ptr, png_const_bytep row)
|
||||
*/
|
||||
static void
|
||||
png_write_rows_internal(png_structrp png_ptr, png_const_bytep *rows,
|
||||
png_uint_32 num_rows)
|
||||
png_uint_32 num_rows)
|
||||
{
|
||||
if (png_ptr != NULL && num_rows > 0U && rows != NULL)
|
||||
{
|
||||
@@ -1016,9 +1011,9 @@ png_write_rows_internal(png_structrp png_ptr, png_const_bytep *rows,
|
||||
|
||||
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->pass) &&
|
||||
png_ptr->row_number <
|
||||
PNG_PASS_ROWS(png_ptr->height, png_ptr->pass));
|
||||
}
|
||||
} /* png_ptr, rows, num_rows all valid */
|
||||
|
||||
@@ -1047,7 +1042,7 @@ png_write_rows(png_structrp png_ptr, png_bytepp rows, png_uint_32 num_rows)
|
||||
|
||||
if (png_ptr != NULL)
|
||||
png_write_rows_internal(png_ptr, png_constcast(png_const_bytep*,rows),
|
||||
num_rows);
|
||||
num_rows);
|
||||
}
|
||||
|
||||
/* Write the image. You only need to call this function once, even
|
||||
@@ -1207,7 +1202,7 @@ png_write_png(png_structrp png_ptr, png_inforp info_ptr,
|
||||
{
|
||||
if ((transforms & PNG_TRANSFORM_STRIP_FILLER_BEFORE) != 0)
|
||||
png_app_error(png_ptr,
|
||||
"PNG_TRANSFORM_STRIP_FILLER: BEFORE+AFTER not supported");
|
||||
"PNG_TRANSFORM_STRIP_FILLER: BEFORE+AFTER not supported");
|
||||
|
||||
/* Continue if ignored - this is the pre-1.6.10 behavior */
|
||||
png_set_filler(png_ptr, 0, PNG_FILLER_AFTER);
|
||||
@@ -1271,7 +1266,7 @@ static int
|
||||
png_image_write_init(png_imagep image)
|
||||
{
|
||||
png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, image,
|
||||
png_safe_error, png_safe_warning);
|
||||
png_safe_error, png_safe_warning);
|
||||
|
||||
if (png_ptr != NULL)
|
||||
{
|
||||
@@ -1280,7 +1275,7 @@ png_image_write_init(png_imagep image)
|
||||
if (info_ptr != NULL)
|
||||
{
|
||||
png_controlp control = png_voidcast(png_controlp,
|
||||
png_malloc_warn(png_ptr, (sizeof *control)));
|
||||
png_malloc_warn(png_ptr, (sizeof *control)));
|
||||
|
||||
if (control != NULL)
|
||||
{
|
||||
@@ -1331,12 +1326,12 @@ static int
|
||||
png_write_image_16bit(png_voidp argument)
|
||||
{
|
||||
png_image_write_control *display = png_voidcast(png_image_write_control*,
|
||||
argument);
|
||||
argument);
|
||||
png_imagep image = display->image;
|
||||
png_structrp png_ptr = image->opaque->png_ptr;
|
||||
|
||||
png_const_uint_16p input_row = png_voidcast(png_const_uint_16p,
|
||||
display->first_row);
|
||||
display->first_row);
|
||||
png_uint_16p output_row = png_voidcast(png_uint_16p, display->local_row);
|
||||
png_uint_16p row_end;
|
||||
const int channels = (image->format & PNG_FORMAT_FLAG_COLOR) != 0 ? 3 : 1;
|
||||
@@ -1441,7 +1436,7 @@ png_write_image_16bit(png_voidp argument)
|
||||
|
||||
static png_byte
|
||||
png_unpremultiply(png_const_structrp png_ptr, png_uint_32 component,
|
||||
png_uint_32 alpha, png_uint_32 reciprocal/*from the above macro*/)
|
||||
png_uint_32 alpha, png_uint_32 reciprocal/*from the above macro*/)
|
||||
{
|
||||
/* The following gives 1.0 for an alpha of 0, which is fine, otherwise if 0/0
|
||||
* is represented as some other value there is more likely to be a
|
||||
@@ -1490,12 +1485,12 @@ static int
|
||||
png_write_image_8bit(png_voidp argument)
|
||||
{
|
||||
png_image_write_control *display = png_voidcast(png_image_write_control*,
|
||||
argument);
|
||||
argument);
|
||||
png_imagep image = display->image;
|
||||
png_structrp png_ptr = image->opaque->png_ptr;
|
||||
|
||||
png_const_uint_16p input_row = png_voidcast(png_const_uint_16p,
|
||||
display->first_row);
|
||||
display->first_row);
|
||||
png_bytep output_row = png_voidcast(png_bytep, display->local_row);
|
||||
png_uint_32 y = image->height;
|
||||
const int channels = (image->format & PNG_FORMAT_FLAG_COLOR) != 0 ? 3 : 1;
|
||||
@@ -1541,7 +1536,7 @@ png_write_image_8bit(png_voidp argument)
|
||||
c = channels;
|
||||
do /* always at least one channel */
|
||||
*out_ptr++ = png_unpremultiply(png_ptr, *in_ptr++, alpha,
|
||||
reciprocal);
|
||||
reciprocal);
|
||||
while (--c > 0);
|
||||
|
||||
/* Skip to next component (skip the intervening alpha channel) */
|
||||
@@ -1550,7 +1545,7 @@ png_write_image_8bit(png_voidp argument)
|
||||
} /* while out_ptr < row_end */
|
||||
|
||||
png_write_row(png_ptr, png_voidcast(png_const_bytep,
|
||||
display->local_row));
|
||||
display->local_row));
|
||||
input_row += display->row_bytes/(sizeof (png_uint_16));
|
||||
} /* while y */
|
||||
}
|
||||
@@ -1642,7 +1637,7 @@ png_image_set_PLTE(png_image_write_control *display)
|
||||
else /* Gray */
|
||||
palette[i].blue = palette[i].red = palette[i].green =
|
||||
PNG_sRGB_FROM_LINEAR(display->image->opaque->png_ptr,
|
||||
255 * *entry);
|
||||
255 * *entry);
|
||||
}
|
||||
|
||||
else /* alpha */
|
||||
@@ -1666,20 +1661,20 @@ png_image_set_PLTE(png_image_write_control *display)
|
||||
if (channels >= 3) /* RGB */
|
||||
{
|
||||
palette[i].blue = png_unpremultiply(
|
||||
display->image->opaque->png_ptr, entry[afirst + (2 ^ bgr)],
|
||||
alpha, reciprocal);
|
||||
display->image->opaque->png_ptr, entry[afirst + (2 ^ bgr)],
|
||||
alpha, reciprocal);
|
||||
palette[i].green = png_unpremultiply(
|
||||
display->image->opaque->png_ptr, entry[afirst + 1], alpha,
|
||||
reciprocal);
|
||||
display->image->opaque->png_ptr, entry[afirst + 1], alpha,
|
||||
reciprocal);
|
||||
palette[i].red = png_unpremultiply(
|
||||
display->image->opaque->png_ptr, entry[afirst + bgr], alpha,
|
||||
reciprocal);
|
||||
display->image->opaque->png_ptr, entry[afirst + bgr], alpha,
|
||||
reciprocal);
|
||||
}
|
||||
|
||||
else /* gray */
|
||||
palette[i].blue = palette[i].red = palette[i].green =
|
||||
png_unpremultiply(display->image->opaque->png_ptr,
|
||||
entry[afirst], alpha, reciprocal);
|
||||
png_unpremultiply(display->image->opaque->png_ptr,
|
||||
entry[afirst], alpha, reciprocal);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1726,11 +1721,11 @@ png_image_set_PLTE(png_image_write_control *display)
|
||||
# endif
|
||||
|
||||
png_set_PLTE(image->opaque->png_ptr, image->opaque->info_ptr, palette,
|
||||
entries);
|
||||
entries);
|
||||
|
||||
if (num_trans > 0)
|
||||
png_set_tRNS(image->opaque->png_ptr, image->opaque->info_ptr, tRNS,
|
||||
num_trans, NULL);
|
||||
num_trans, NULL);
|
||||
|
||||
image->colormap_entries = entries;
|
||||
}
|
||||
@@ -1739,7 +1734,7 @@ static int
|
||||
png_image_write_main(png_voidp argument)
|
||||
{
|
||||
png_image_write_control *display = png_voidcast(png_image_write_control*,
|
||||
argument);
|
||||
argument);
|
||||
png_imagep image = display->image;
|
||||
png_structrp png_ptr = image->opaque->png_ptr;
|
||||
png_inforp info_ptr = image->opaque->info_ptr;
|
||||
@@ -1807,24 +1802,24 @@ png_image_write_main(png_voidp argument)
|
||||
png_uint_32 entries = image->colormap_entries;
|
||||
|
||||
png_set_IHDR(png_ptr, info_ptr, image->width, image->height,
|
||||
entries > 16 ? 8 : (entries > 4 ? 4 : (entries > 2 ? 2 : 1)),
|
||||
PNG_COLOR_TYPE_PALETTE, PNG_INTERLACE_NONE,
|
||||
PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
|
||||
entries > 16 ? 8 : (entries > 4 ? 4 : (entries > 2 ? 2 : 1)),
|
||||
PNG_COLOR_TYPE_PALETTE, PNG_INTERLACE_NONE,
|
||||
PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
|
||||
|
||||
png_image_set_PLTE(display);
|
||||
}
|
||||
|
||||
else
|
||||
png_error(image->opaque->png_ptr,
|
||||
"no color-map for color-mapped image");
|
||||
"no color-map for color-mapped image");
|
||||
}
|
||||
|
||||
else
|
||||
png_set_IHDR(png_ptr, info_ptr, image->width, image->height,
|
||||
write_16bit ? 16 : 8,
|
||||
((format & PNG_FORMAT_FLAG_COLOR) ? PNG_COLOR_MASK_COLOR : 0) +
|
||||
((format & PNG_FORMAT_FLAG_ALPHA) ? PNG_COLOR_MASK_ALPHA : 0),
|
||||
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
|
||||
write_16bit ? 16 : 8,
|
||||
((format & PNG_FORMAT_FLAG_COLOR) ? PNG_COLOR_MASK_COLOR : 0) +
|
||||
((format & PNG_FORMAT_FLAG_ALPHA) ? PNG_COLOR_MASK_ALPHA : 0),
|
||||
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
|
||||
|
||||
/* Counter-intuitively the data transformations must be called *after*
|
||||
* png_write_info, not before as in the read code, but the 'set' functions
|
||||
@@ -1839,11 +1834,11 @@ png_image_write_main(png_voidp argument)
|
||||
|
||||
if ((image->flags & PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB) == 0)
|
||||
png_set_cHRM_fixed(png_ptr, info_ptr,
|
||||
/* color x y */
|
||||
/* white */ 31270, 32900,
|
||||
/* red */ 64000, 33000,
|
||||
/* green */ 30000, 60000,
|
||||
/* blue */ 15000, 6000
|
||||
/* color x y */
|
||||
/* white */ 31270, 32900,
|
||||
/* red */ 64000, 33000,
|
||||
/* green */ 30000, 60000,
|
||||
/* blue */ 15000, 6000
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1915,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
|
||||
@@ -1939,7 +1925,7 @@ png_image_write_main(png_voidp argument)
|
||||
(colormap == 0 && display->convert_to_8bit != 0))
|
||||
{
|
||||
png_bytep row = png_voidcast(png_bytep, png_malloc(png_ptr,
|
||||
png_get_rowbytes(png_ptr, info_ptr)));
|
||||
png_get_rowbytes(png_ptr, info_ptr)));
|
||||
int result;
|
||||
|
||||
display->local_row = row;
|
||||
@@ -1979,10 +1965,10 @@ png_image_write_main(png_voidp argument)
|
||||
|
||||
static void (PNGCBAPI
|
||||
image_memory_write)(png_structp png_ptr, png_bytep/*const*/ data,
|
||||
png_size_t size)
|
||||
png_size_t size)
|
||||
{
|
||||
png_image_write_control *display = png_voidcast(png_image_write_control*,
|
||||
png_ptr->io_ptr/*backdoor: png_get_io_ptr(png_ptr)*/);
|
||||
png_ptr->io_ptr/*backdoor: png_get_io_ptr(png_ptr)*/);
|
||||
const png_alloc_size_t ob = display->output_bytes;
|
||||
|
||||
/* Check for overflow; this should never happen: */
|
||||
@@ -2013,22 +1999,22 @@ static int
|
||||
png_image_write_memory(png_voidp argument)
|
||||
{
|
||||
png_image_write_control *display = png_voidcast(png_image_write_control*,
|
||||
argument);
|
||||
argument);
|
||||
|
||||
/* The rest of the memory-specific init and write_main in an error protected
|
||||
* environment. This case needs to use callbacks for the write operations
|
||||
* since libpng has no built in support for writing to memory.
|
||||
*/
|
||||
png_set_write_fn(display->image->opaque->png_ptr, display/*io_ptr*/,
|
||||
image_memory_write, image_memory_flush);
|
||||
image_memory_write, image_memory_flush);
|
||||
|
||||
return png_image_write_main(display);
|
||||
}
|
||||
|
||||
int PNGAPI
|
||||
png_image_write_to_memory(png_imagep image, void *memory,
|
||||
png_alloc_size_t * PNG_RESTRICT memory_bytes, int convert_to_8bit,
|
||||
const void *buffer, ptrdiff_t row_stride, const void *colormap)
|
||||
png_alloc_size_t * PNG_RESTRICT memory_bytes, int convert_to_8bit,
|
||||
const void *buffer, ptrdiff_t row_stride, const void *colormap)
|
||||
{
|
||||
/* Write the image to the given buffer, or count the bytes if it is NULL */
|
||||
if (image != NULL && image->version == PNG_IMAGE_VERSION)
|
||||
@@ -2080,12 +2066,12 @@ png_image_write_to_memory(png_imagep image, void *memory,
|
||||
|
||||
else
|
||||
return png_image_error(image,
|
||||
"png_image_write_to_memory: invalid argument");
|
||||
"png_image_write_to_memory: invalid argument");
|
||||
}
|
||||
|
||||
else if (image != NULL)
|
||||
return png_image_error(image,
|
||||
"png_image_write_to_memory: incorrect PNG_IMAGE_VERSION");
|
||||
"png_image_write_to_memory: incorrect PNG_IMAGE_VERSION");
|
||||
|
||||
else
|
||||
return 0;
|
||||
@@ -2094,7 +2080,7 @@ png_image_write_to_memory(png_imagep image, void *memory,
|
||||
#ifdef PNG_SIMPLIFIED_WRITE_STDIO_SUPPORTED
|
||||
int PNGAPI
|
||||
png_image_write_to_stdio(png_imagep image, FILE *file, int convert_to_8bit,
|
||||
const void *buffer, ptrdiff_t row_stride, const void *colormap)
|
||||
const void *buffer, ptrdiff_t row_stride, const void *colormap)
|
||||
{
|
||||
/* Write the image to the given (FILE*). */
|
||||
if (image != NULL && image->version == PNG_IMAGE_VERSION)
|
||||
@@ -2125,12 +2111,12 @@ png_image_write_to_stdio(png_imagep image, FILE *file, int convert_to_8bit,
|
||||
|
||||
else
|
||||
return png_image_error(image,
|
||||
"png_image_write_to_stdio: invalid argument");
|
||||
"png_image_write_to_stdio: invalid argument");
|
||||
}
|
||||
|
||||
else if (image != NULL)
|
||||
return png_image_error(image,
|
||||
"png_image_write_to_stdio: incorrect PNG_IMAGE_VERSION");
|
||||
"png_image_write_to_stdio: incorrect PNG_IMAGE_VERSION");
|
||||
|
||||
else
|
||||
return 0;
|
||||
@@ -2138,8 +2124,8 @@ png_image_write_to_stdio(png_imagep image, FILE *file, int convert_to_8bit,
|
||||
|
||||
int PNGAPI
|
||||
png_image_write_to_file(png_imagep image, const char *file_name,
|
||||
int convert_to_8bit, const void *buffer, ptrdiff_t row_stride,
|
||||
const void *colormap)
|
||||
int convert_to_8bit, const void *buffer, ptrdiff_t row_stride,
|
||||
const void *colormap)
|
||||
{
|
||||
/* Write the image to the named file. */
|
||||
if (image != NULL && image->version == PNG_IMAGE_VERSION)
|
||||
@@ -2151,7 +2137,7 @@ png_image_write_to_file(png_imagep image, const char *file_name,
|
||||
if (fp != NULL)
|
||||
{
|
||||
if (png_image_write_to_stdio(image, fp, convert_to_8bit, buffer,
|
||||
row_stride, colormap) != 0)
|
||||
row_stride, colormap) != 0)
|
||||
{
|
||||
int error; /* from fflush/fclose */
|
||||
|
||||
@@ -2192,12 +2178,12 @@ png_image_write_to_file(png_imagep image, const char *file_name,
|
||||
|
||||
else
|
||||
return png_image_error(image,
|
||||
"png_image_write_to_file: invalid argument");
|
||||
"png_image_write_to_file: invalid argument");
|
||||
}
|
||||
|
||||
else if (image != NULL)
|
||||
return png_image_error(image,
|
||||
"png_image_write_to_file: incorrect PNG_IMAGE_VERSION");
|
||||
"png_image_write_to_file: incorrect PNG_IMAGE_VERSION");
|
||||
|
||||
else
|
||||
return 0;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
/* pngwtran.c - transforms the data in a row for PNG writers
|
||||
*
|
||||
* Last changed in libpng 1.6.17 [(PENDING RELEASE)]
|
||||
* Last changed in libpng 1.7.0 [(PENDING RELEASE)]
|
||||
* Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson
|
||||
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
|
||||
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
|
||||
|
||||
2665
pngwutil.c
@@ -126,7 +126,7 @@ $# to work, download Brian Kernighan's awk (Brian Kernighan is the author of
|
||||
$# awk.) You can find source code and a built executable (called awk95.exe)
|
||||
$# here:
|
||||
$#
|
||||
$# http://www.cs.princeton.edu/~bwk/btl.mirror/
|
||||
$# https://www.cs.princeton.edu/~bwk/btl.mirror/
|
||||
$#
|
||||
$# The executable works just fine.
|
||||
$#
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
VisualStudio instructions
|
||||
|
||||
libpng version 1.7.0beta80 - May 6, 2016
|
||||
libpng version 1.7.0beta90 - August 28, 2017
|
||||
|
||||
Copyright (c) 2010,2013,2015 Glenn Randers-Pehrson
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<!--
|
||||
* zlib.props - location of zlib source
|
||||
*
|
||||
* libpng version 1.7.0beta80 - May 6, 2016
|
||||
* libpng version 1.7.0beta90 - August 28, 2017
|
||||
*
|
||||
* Copyright (c) 2011,2013,2014 Glenn Randers-Pehrson
|
||||
*
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
|
||||
Makefiles for libpng version 1.7.0beta80 - May 6, 2016
|
||||
Makefiles for libpng version 1.7.0beta90 - August 28, 2017
|
||||
|
||||
pnglibconf.h.prebuilt => Stores configuration settings
|
||||
makefile.linux => Linux/ELF makefile
|
||||
(gcc, creates libpng17.so.17.1.7.0beta80)
|
||||
(gcc, creates libpng17.so.17.1.7.0beta90)
|
||||
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.0beta80)
|
||||
creates libpng17.so.17.1.7.0beta90)
|
||||
makefile.sgi => Silicon Graphics IRIX makefile (cc, creates static lib)
|
||||
makefile.solaris => Solaris 2.X makefile (gcc,
|
||||
creates libpng17.so.17.1.7.0beta80)
|
||||
creates libpng17.so.17.1.7.0beta90)
|
||||
makefile.so9 => Solaris 9 makefile (gcc,
|
||||
creates libpng17.so.17.1.7.0beta80)
|
||||
creates libpng17.so.17.1.7.0beta90)
|
||||
makefile.std => Generic UNIX makefile (cc, creates static libpng.a)
|
||||
makefile.sunos => Sun makefile
|
||||
makefile.32sunu => Sun Ultra 32-bit makefile
|
||||
|
||||
@@ -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.0beta80"
|
||||
PNG_DFN ";Version 1.7.0beta90"
|
||||
|
||||
#define PNG_EXPORTA(ordinal, type, name, args, attributes)\
|
||||
PNG_DFN "@" SYMBOL_PREFIX "@@" name "@"
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
# Modeled after libxml-config.
|
||||
|
||||
version=1.7.0beta80
|
||||
version=1.7.0beta90
|
||||
prefix=""
|
||||
libdir=""
|
||||
libs=""
|
||||
|
||||
@@ -5,6 +5,6 @@ includedir=@includedir@/libpng17
|
||||
|
||||
Name: libpng
|
||||
Description: Loads and saves PNG files
|
||||
Version: 1.7.0beta80
|
||||
Version: 1.7.0beta90
|
||||
Libs: -L${libdir} -lpng17
|
||||
Cflags: -I${includedir}
|
||||
|
||||
@@ -92,7 +92,7 @@ OBJSDLL = $(OBJS:.o=.pic.o)
|
||||
$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<
|
||||
|
||||
.c.pic.o:
|
||||
$(CC) -c $(CFLAGS) -fPIC -o $@ $*.c
|
||||
$(CC) -c $(CPPFLAGS) $(CFLAGS) -fPIC -o $@ $*.c
|
||||
|
||||
all: libpng.a $(LIBSO) pngtest pngtest-static libpng.pc libpng-config
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ INCSDIR=${LOCALBASE}/include/libpng17
|
||||
|
||||
LIB= png17
|
||||
SHLIB_MAJOR= 0
|
||||
SHLIB_MINOR= 1.7.0beta80
|
||||
SHLIB_MINOR= 1.7.0beta90
|
||||
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
|
||||
|
||||
@@ -17,7 +17,7 @@ INCSDIR=${LOCALBASE}/include
|
||||
|
||||
LIB= png
|
||||
SHLIB_MAJOR= 17
|
||||
SHLIB_MINOR= 1.7.0beta80
|
||||
SHLIB_MINOR= 1.7.0beta90
|
||||
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
|
||||
|
||||
@@ -11,7 +11,7 @@ LIBDIR= ${PREFIX}/lib
|
||||
MANDIR= ${PREFIX}/man/cat
|
||||
|
||||
SHLIB_MAJOR= 17
|
||||
SHLIB_MINOR= 1.7.0beta80
|
||||
SHLIB_MINOR= 1.7.0beta90
|
||||
|
||||
LIB= png
|
||||
SRCS= png.c pngerror.c pngget.c pngmem.c pngpread.c \
|
||||
|
||||
@@ -83,7 +83,7 @@ OBJSDLL = $(OBJS:.o=.pic.o)
|
||||
$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<
|
||||
|
||||
.c.pic.o:
|
||||
$(CC) -c $(CFLAGS) -fPIC -o $@ $*.c
|
||||
$(CC) -c $(CPPFLAGS) $(CFLAGS) -fPIC -o $@ $*.c
|
||||
|
||||
all: libpng.a $(LIBSO) pngtest libpng.pc libpng-config
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -935,31 +918,8 @@ option CONVERT_tIME requires WRITE_ANCILLARY_CHUNKS
|
||||
# the 'first' (lowest numbered) filter will be selected an this typically
|
||||
# works out as PNG_FILTER_VALUE_NONE.
|
||||
#
|
||||
# COMPRESSION_BUFFER_MAX
|
||||
# WARNING: take care if you set this. This is the maximum amount of input
|
||||
# data that the implementation of deflate can consume before it outputs a
|
||||
# Huffman table for that data. I.e. before it commits to an encoding of the
|
||||
# data it has read. This is used solely to implement a limit on the amount
|
||||
# of image data buffering that occurs inside libpng before filter selection
|
||||
# is done. Normally the limit is never reached because of the next setting,
|
||||
# but this is a compile time limit and it is intended to prevent a potential
|
||||
# DNS service as a result of an application setting the libpng equivalent of
|
||||
# volume level 11 (read the wikipedia article on "Up to eleven").
|
||||
#
|
||||
# NOTE: the image of a black cat in a coal mine obviously requires this
|
||||
# limit, but some more valid images can get very close; well over 8MByte.
|
||||
#
|
||||
# COMPRESSION_BUFFER_LIMIT
|
||||
# This is the (overrideable) default for the amount of memory libpng will
|
||||
# buffer before selecting a filter for a row. It is limited itself to
|
||||
# COMPRESSION_BUFFER_MAX as values above that level make no change (see the
|
||||
# previous paragraph.)
|
||||
#
|
||||
# See png.h for more description of these options.
|
||||
option WRITE_FILTER requires WRITE
|
||||
option SELECT_FILTER requires WRITE_FILTER disabled
|
||||
setting COMPRESSION_BUFFER_MAX default 8453377
|
||||
setting COMPRESSION_BUFFER_LIMIT default 8453377
|
||||
option SELECT_FILTER requires WRITE_FILTER
|
||||
|
||||
# added at libpng-1.5.4
|
||||
|
||||
@@ -979,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.
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/* libpng 1.7.0beta80 STANDARD API DEFINITION */
|
||||
/* libpng 1.7.0beta90 STANDARD API DEFINITION */
|
||||
|
||||
/* pnglibconf.h - library build configuration */
|
||||
|
||||
/* libpng version 1.7.0beta80, May 6, 2016 */
|
||||
/* libpng version 1.7.0beta90, August 28, 2017 */
|
||||
|
||||
/* 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,10 +99,9 @@
|
||||
#define PNG_READ_tRNS_SUPPORTED
|
||||
#define PNG_READ_zTXt_SUPPORTED
|
||||
#define PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED
|
||||
/*#undef PNG_SELECT_FILTER_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
|
||||
@@ -192,8 +190,7 @@
|
||||
/* settings */
|
||||
#define PNG_ABORT { (abort()); }
|
||||
#define PNG_API_RULE 0
|
||||
#define PNG_COMPRESSION_BUFFER_LIMIT 8453377
|
||||
#define PNG_COMPRESSION_BUFFER_MAX 8453377
|
||||
#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
|
||||
@@ -203,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
|
||||
@@ -212,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 */
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
;Version 1.7.0beta80
|
||||
;Version 1.7.0beta90
|
||||
;--------------------------------------------------------------
|
||||
; 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
|
||||
|
||||
BIN
tests/bad_iccp.png
Normal file
|
After Width: | Height: | Size: 321 B |
BIN
tests/badadler.png
Normal file
|
After Width: | Height: | Size: 67 B |
BIN
tests/badcrc.png
Normal file
|
After Width: | Height: | Size: 67 B |
BIN
tests/empty_ancillary_chunks.png
Normal file
|
After Width: | Height: | Size: 730 B |
BIN
tests/huge_idat.png
Normal file
|
After Width: | Height: | Size: 79 B |
@@ -1,2 +1,7 @@
|
||||
#!/bin/sh
|
||||
./pngtest --relaxed ${srcdir}/tests/badcrc.png
|
||||
./pngtest --relaxed ${srcdir}/tests/badadler.png
|
||||
./pngtest --relaxed ${srcdir}/tests/bad_iccp.png
|
||||
./pngtest --relaxed ${srcdir}/tests/huge_idat.png
|
||||
./pngtest --relaxed ${srcdir}/tests/empty_ancillary_chunks.png
|
||||
exec ./pngtest --strict ${srcdir}/pngtest.png
|
||||
|
||||