mirror of
https://git.code.sf.net/p/libpng/code.git
synced 2025-07-10 18:04:09 +02:00
Compare commits
332 Commits
21895b05ab
...
v1.7.0beta
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ab71e135e7 | ||
|
|
1b577e9bc6 | ||
|
|
238fdc197d | ||
|
|
8cfee5fa78 | ||
|
|
44a9af81b0 | ||
|
|
755f92fc41 | ||
|
|
d9d1c997d8 | ||
|
|
aeb4a22975 | ||
|
|
9c0b5ab848 | ||
|
|
05dcaffd38 | ||
|
|
cca25b182f | ||
|
|
f87df31c8c | ||
|
|
41547820e8 | ||
|
|
e5d462d829 | ||
|
|
6f46730cb7 | ||
|
|
67b88b8ee0 | ||
|
|
7a4bfbdec1 | ||
|
|
859254054a | ||
|
|
515659d638 | ||
|
|
fd409c8019 | ||
|
|
9ee6678e1f | ||
|
|
9b36280e31 | ||
|
|
eaad9f9177 | ||
|
|
70cd1a10f2 | ||
|
|
7974d60f54 | ||
|
|
c7e743d385 | ||
|
|
b2e89f1af6 | ||
|
|
ad30a1262b | ||
|
|
35f88c1341 | ||
|
|
4f8050416f | ||
|
|
776d1768aa | ||
|
|
d7078c52e2 | ||
|
|
4a67ac3f1e | ||
|
|
2799bf9a4f | ||
|
|
34e49ae1bc | ||
|
|
cea01951da | ||
|
|
1a9c06b11a | ||
|
|
f3b1eb68a6 | ||
|
|
12845bc947 | ||
|
|
3ac960f128 | ||
|
|
eb2b0248e2 | ||
|
|
e529698d38 | ||
|
|
1a9e897289 | ||
|
|
3a81956ffe | ||
|
|
0acf4f9770 | ||
|
|
b407af6503 | ||
|
|
0fb41f05df | ||
|
|
8ebdaa0700 | ||
|
|
4e61b58980 | ||
|
|
88e7d62fbc | ||
|
|
43cd0a0bb5 | ||
|
|
1345c5bff8 | ||
|
|
39c420834f | ||
|
|
f898f69f46 | ||
|
|
352f43cdc6 | ||
|
|
f99393490d | ||
|
|
deb920b4a7 | ||
|
|
148cdac18f | ||
|
|
51ecc14a8a | ||
|
|
713a20c57d | ||
|
|
4526f546ba | ||
|
|
0c5acfa19e | ||
|
|
848eeacb41 | ||
|
|
2ced844b0e | ||
|
|
e2c5ed8d1d | ||
|
|
76004ce6ed | ||
|
|
258b986917 | ||
|
|
50a09830b8 | ||
|
|
9a3f244085 | ||
|
|
fb1305faeb | ||
|
|
3d7f3bbab7 | ||
|
|
2d032e966d | ||
|
|
8dd3784f7c | ||
|
|
98b9371115 | ||
|
|
d29413a2a9 | ||
|
|
dc63b03da1 | ||
|
|
cf354c2c82 | ||
|
|
484dad1a19 | ||
|
|
1695471118 | ||
|
|
ae14dcd404 | ||
|
|
302c58b8cf | ||
|
|
39fee3cee1 | ||
|
|
b7362c6738 | ||
|
|
f2d8561fdc | ||
|
|
1bd81ffa21 | ||
|
|
6d2b1a7dbc | ||
|
|
5daa97c2eb | ||
|
|
9e441e96b9 | ||
|
|
a0d314ce84 | ||
|
|
b871b25997 | ||
|
|
d38ebc9ded | ||
|
|
995402ca6e | ||
|
|
1982968dad | ||
|
|
32cd66d619 | ||
|
|
03a53fa429 | ||
|
|
441de8f4fd | ||
|
|
4e5c80034e | ||
|
|
879d63156a | ||
|
|
eb021245d0 | ||
|
|
6607a3b905 | ||
|
|
28711dff2a | ||
|
|
4413d5dcd2 | ||
|
|
206d1eed42 | ||
|
|
114fa16ab3 | ||
|
|
eb2af04bd3 | ||
|
|
200fc68f52 | ||
|
|
4cfd01a288 | ||
|
|
e98229ceb0 | ||
|
|
ad1a4c8cc3 | ||
|
|
8df7c46e5b | ||
|
|
99078ec8bd | ||
|
|
a2c5f56e77 | ||
|
|
9e168ea2c9 | ||
|
|
06be739941 | ||
|
|
448092b8eb | ||
|
|
1faa6ff32c | ||
|
|
3adf438f39 | ||
|
|
d45a632529 | ||
|
|
5a1b8d106d | ||
|
|
05f896004f | ||
|
|
a4f1de9109 | ||
|
|
7ebb353944 | ||
|
|
b1f0c7d0e5 | ||
|
|
55df049962 | ||
|
|
219ba1370e | ||
|
|
4dc4471bb5 | ||
|
|
a199a15b28 | ||
|
|
e9446f2f95 | ||
|
|
f70f2fcf48 | ||
|
|
158c947ce2 | ||
|
|
7e2707e2af | ||
|
|
81824079b5 | ||
|
|
e8e1add0a8 | ||
|
|
a549223f91 | ||
|
|
ebe7945b96 | ||
|
|
e3e35aa980 | ||
|
|
9f2fbcf5d8 | ||
|
|
264ba68afe | ||
|
|
3ef99c9316 | ||
|
|
4b29f97f9b | ||
|
|
fe6e6cf130 | ||
|
|
547df4b9ca | ||
|
|
a0d4a0b971 | ||
|
|
72c2577302 | ||
|
|
091fab713c | ||
|
|
32aeb2cd4e | ||
|
|
c1bcdc3a86 | ||
|
|
553b8f85d3 | ||
|
|
30666a6097 | ||
|
|
0bfa63cd0d | ||
|
|
b37a7c6674 | ||
|
|
7657ac14f2 | ||
|
|
d9f60caf72 | ||
|
|
88c20ada06 | ||
|
|
f3bfc4a142 | ||
|
|
3fdef04d55 | ||
|
|
eae431e514 | ||
|
|
003590c361 | ||
|
|
8e23262b2b | ||
|
|
157e0649e0 | ||
|
|
83f1287c02 | ||
|
|
a1124a574a | ||
|
|
6f27254a7e | ||
|
|
79fc8fa0d9 | ||
|
|
394bc6cdee | ||
|
|
bb06552075 | ||
|
|
a14071d814 | ||
|
|
23f3e46518 | ||
|
|
f97b2a6cde | ||
|
|
23f4320775 | ||
|
|
fb411867b0 | ||
|
|
5aa2ca454d | ||
|
|
7905286ffa | ||
|
|
2edcb6ad0f | ||
|
|
0f1599e6e5 | ||
|
|
cbf22f30b4 | ||
|
|
9bf3c70730 | ||
|
|
1bc5747713 | ||
|
|
4a7796faca | ||
|
|
34081a0e2f | ||
|
|
b88c94208a | ||
|
|
30662f5e92 | ||
|
|
46ad4c5bd4 | ||
|
|
5c32606ec0 | ||
|
|
a08ac031fc | ||
|
|
c233ec8743 | ||
|
|
d594be641a | ||
|
|
4c9168875b | ||
|
|
3c051ee282 | ||
|
|
e1ded944f0 | ||
|
|
c09dddc0cd | ||
|
|
bd56d76417 | ||
|
|
0cc23ac171 | ||
|
|
cb10e19725 | ||
|
|
9dba7219a0 | ||
|
|
17c6af8c40 | ||
|
|
6a02eb6d2c | ||
|
|
40d41fe6f8 | ||
|
|
7073d26e51 | ||
|
|
cf76fe8654 | ||
|
|
b780b64fbf | ||
|
|
b1876ab6e2 | ||
|
|
28a95d125f | ||
|
|
993f68c006 | ||
|
|
8d23524359 | ||
|
|
e0f4aaa668 | ||
|
|
3de174cd2f | ||
|
|
eaf2f1dcbe | ||
|
|
ea0b4c602e | ||
|
|
371c3d4dfd | ||
|
|
0bcf5fb451 | ||
|
|
57d6907d89 | ||
|
|
6cf97e37af | ||
|
|
8ef61c4693 | ||
|
|
25a116f97d | ||
|
|
d6d41c847a | ||
|
|
9e0297546f | ||
|
|
d529363d13 | ||
|
|
55e93d7090 | ||
|
|
23674b75be | ||
|
|
0ddf350360 | ||
|
|
066f9862f0 | ||
|
|
ae1a5c811c | ||
|
|
5a1ce92c0c | ||
|
|
7a498039c5 | ||
|
|
40a93652aa | ||
|
|
a1362f38de | ||
|
|
30bc0333fe | ||
|
|
55794013d4 | ||
|
|
2e92b4dfa0 | ||
|
|
f46106fa04 | ||
|
|
0dcd32f39c | ||
|
|
808ea281a4 | ||
|
|
ec89aefb44 | ||
|
|
6152dbd424 | ||
|
|
fe18c0d9ea | ||
|
|
1b0358302d | ||
|
|
d20f9d5030 | ||
|
|
fc447311aa | ||
|
|
8e30e43587 | ||
|
|
0403ccf1de | ||
|
|
1a321cc088 | ||
|
|
c9f99f487b | ||
|
|
8360e60abc | ||
|
|
2799f74489 | ||
|
|
7363babe4f | ||
|
|
e3a526f789 | ||
|
|
8f0935b8dc | ||
|
|
ae6503fe0e | ||
|
|
851a6265a8 | ||
|
|
ffa24d4108 | ||
|
|
206f4d2678 | ||
|
|
bb040784c2 | ||
|
|
70e1af50ed | ||
|
|
eb4a645eda | ||
|
|
9f7f03a3c4 | ||
|
|
395ddbd318 | ||
|
|
9f0d36c85f | ||
|
|
e9760e5e95 | ||
|
|
b96b2b7e90 | ||
|
|
9bb705e0a8 | ||
|
|
e860f77393 | ||
|
|
b5a7565908 | ||
|
|
e88e221d91 | ||
|
|
b10867cdc2 | ||
|
|
bf7084b80d | ||
|
|
6afcee826f | ||
|
|
f15a5006c8 | ||
|
|
cdbd5174bd | ||
|
|
7a9b6203ef | ||
|
|
803493e19c | ||
|
|
4245e6b1b2 | ||
|
|
81892f6b90 | ||
|
|
862993827d | ||
|
|
d304125332 | ||
|
|
9124f3e29a | ||
|
|
2969375aa6 | ||
|
|
5e8ba1cbbf | ||
|
|
8aee43d10a | ||
|
|
e355657bbe | ||
|
|
fb6ba9acf4 | ||
|
|
815173a0b5 | ||
|
|
7f489a77bb | ||
|
|
8ec8e8fcd5 | ||
|
|
a4e606dd5f | ||
|
|
646de7962b | ||
|
|
4accd423c2 | ||
|
|
f62caaf4dc | ||
|
|
b789bb84bb | ||
|
|
ce60ad642b | ||
|
|
ab097b1168 | ||
|
|
3a737d86c7 | ||
|
|
a1337e57a8 | ||
|
|
247b3fcf49 | ||
|
|
f01273b25c | ||
|
|
8cb1a2ac6d | ||
|
|
e6e5ac8cb7 | ||
|
|
a4798fb83e | ||
|
|
46369f35c5 | ||
|
|
e699993d70 | ||
|
|
5a0afcfa63 | ||
|
|
3fc9cbf126 | ||
|
|
36b628b19e | ||
|
|
2c31365fd4 | ||
|
|
e1e3c1a2a2 | ||
|
|
b940e5dc5d | ||
|
|
fbbbc620b8 | ||
|
|
9b99600c4d | ||
|
|
3129d7426e | ||
|
|
325ceea971 | ||
|
|
ac39fc3024 | ||
|
|
99343407e6 | ||
|
|
3e23f45ba9 | ||
|
|
72389dec42 | ||
|
|
1f0853f47e | ||
|
|
32a60a4885 | ||
|
|
5e07dc6970 | ||
|
|
4b90a8d416 | ||
|
|
d59c19b64c | ||
|
|
bbabd977d1 | ||
|
|
0cf9c7d63d | ||
|
|
b4e241559e | ||
|
|
1e15aee6be | ||
|
|
d59e60d0fb | ||
|
|
ec1d13a1d4 | ||
|
|
d9002f94cb | ||
|
|
1fa858db48 | ||
|
|
0f2a5bac64 | ||
|
|
eac85878bf | ||
|
|
240ac287eb | ||
|
|
3e42c81193 | ||
|
|
ac3b4d9b69 |
640
CHANGES
640
CHANGES
@@ -3672,7 +3672,8 @@ Version 1.5.6 [November 3, 2011]
|
||||
No changes.
|
||||
|
||||
Version 1.5.7beta01 [November 4, 2011]
|
||||
Added support for ARM processor (Mans Rullgard)
|
||||
Added support for ARM processor, when decoding all PNG up-filtered rows
|
||||
and any other-filtered rows with 3 or 4 bytes per pixel (Mans Rullgard).
|
||||
Fixed bug in pngvalid on early allocation failure; fixed type cast in
|
||||
pngmem.c; pngvalid would attempt to call png_error() if the allocation
|
||||
of a png_struct or png_info failed. This would probably have led to a
|
||||
@@ -4045,7 +4046,9 @@ Version 1.6.0beta17 [March 10, 2012]
|
||||
Deflate/inflate was reworked to move common zlib calls into single
|
||||
functions [rw]util.c. A new shared keyword check routine was also added
|
||||
and the 'zbuf' is no longer allocated on progressive read. It is now
|
||||
possible to call png_inflate() incrementally.
|
||||
possible to call png_inflate() incrementally. A warning is no longer
|
||||
issued if the language tag or translated keyword in the iTXt chunk
|
||||
has zero length.
|
||||
If benign errors are disabled use maximum window on ancilliary inflate.
|
||||
This works round a bug introduced in 1.5.4 where compressed ancillary
|
||||
chunks could end up with a too-small windowBits value in the deflate
|
||||
@@ -4311,6 +4314,639 @@ Version 1.6.0beta33 [December 10, 2012]
|
||||
fall-through condition.
|
||||
Change png_warning() to png_app_warning() in png_write_tRNS().
|
||||
|
||||
Version 1.7.0alpha01 [December 15, 2012]
|
||||
Started 1.7.0 branch from libpng-1.6.0beta33.
|
||||
Made 8-bit compose and rgb_to_grayscale accuracy improvements. These
|
||||
changes cause 16-bit arithmetic to be used for 8-bit data in the gamma
|
||||
corrected compose and grayscale operations. The arithmetic errors have
|
||||
three sources all of which are fixed in this commit:
|
||||
1) 8-bit linear calculations produce massive errors for lower intensity
|
||||
values.
|
||||
2) The old 16-bit "16 to 8" gamma table code erroneously wrote the lowest
|
||||
output value into a table entry which corresponded to multiple output
|
||||
values (so where the value written should have been the closest to the
|
||||
transformed input value.)
|
||||
3) In a number of cases the code to access the 16-bit table did not round;
|
||||
it did a simple shift, which was wrong and made the side effects of (2)
|
||||
even worse.
|
||||
The new gamma code does not have the 16-to-8 problem at the cost of slightly
|
||||
more calculations and the algorithm used to minimize the number of
|
||||
calculations has been extended to all the 16-bit tables; it has advantages
|
||||
for any significant gamma correction.
|
||||
Rearranged png_struct, remove unused members, change png_set_filter handling
|
||||
png_struct members rearranged - partly to reorder to avoid packing, partly
|
||||
to put frequently accessed members at the start and partly to make
|
||||
the grouping more clear. png_set_filter code has been rewritten and the
|
||||
code shared with png_write_start_row moved to a common function. Comments
|
||||
in png.h have been made more clear. Minor fixes to
|
||||
contrib/libtests/timepng.c and some of the png_*_tRNS logic, including
|
||||
more error detection in png_set_tRNS.
|
||||
Cleaned up USER_LIMITS feature, removing members from png_struct when not
|
||||
required.
|
||||
Rearranged ARM-NEON optimizations to isolate the machine specific code to
|
||||
the hardware subdirectory, and add comments to pngrutil.c so that
|
||||
implementors of other optimizations will know what to do.
|
||||
Fixed cases of unquoted DESTDIR in Makefile.am.
|
||||
Rebuilt Makefile.in, configure, etc., with autoconf-2.69 and automake-1.12.5.
|
||||
|
||||
Version 1.7.0alpha02 [December 17, 2012]
|
||||
Removed functions that were deprecated in libpng-1.6.0:
|
||||
png_reset_zstream(), png_info_init_3(), png_data_freer() and its
|
||||
associated flags, png_malloc_default, and png_free_default.
|
||||
Removed some duplicated lines from contrib/tools/scale.c and png.c.
|
||||
Changed some instances of png_warning() to png_app_error().
|
||||
Updated some left over "1.6.0beta32" in code sources.
|
||||
Fixed a "png_structp" prototype (should be png_structrp) in arm_init.c
|
||||
Updated the version-number hack in pngvalid.c
|
||||
|
||||
Version 1.7.0alpha03 [December 19, 2012]
|
||||
Cleaned up and enhanced the configure option; libpng now correctly
|
||||
links and tests against zlib with a prefix; tests have been clarified; and
|
||||
irrelevant or obsolete things (as defined by the autotools man page) have
|
||||
been removed.
|
||||
Documented new PNG_ABORT behavior in the manual and commentary in pngerror.c
|
||||
Cleaned up whitespace in the synopsis portion of the manpage "libpng.3"
|
||||
Fixed previous support for Z_PREFIX in configure builds, corrected sCAL APIs;
|
||||
some of these use floating point arithmetic so they need to be disabled if
|
||||
floating point arithmetic is switched off. This is a quiet API change -
|
||||
previously it appeared that the APIs were supported if fixed point
|
||||
arithmetic was used internally, however they required certain APIs (floor,
|
||||
modf, frexp, atof) that are part of C floating point support. Changed
|
||||
png_fixed and the gamma code specific version of the same to avoid floor(),
|
||||
which may be a library function (not an intrinsic). Removed unused #if 0
|
||||
code.
|
||||
Disassembled the version number in scripts/options.awk (necessary for
|
||||
building on SunOs).
|
||||
|
||||
Version 1.7.0alpha04 [December 23, 2012]
|
||||
Added scripts/makefile.msys contributed by Christopher M. Wheeler
|
||||
Made default Zlib compression settings be configurable. This adds #defines to
|
||||
pnglibconf.h to control the defaults.
|
||||
Fixed Windows build issues, enabled ARM compilation. Various warnings issued
|
||||
by earlier versions of GCC fixed for Cygwin and Min/GW (which both use old
|
||||
GCCs.) ARM support is enabled by default in zlib.props (unsupported by
|
||||
Microsoft) and ARM compilation is made possible by deleting the check for
|
||||
x86. The test programs cannot be run because they are not signed.
|
||||
|
||||
Version 1.7.0alpha05 [December 24, 2012]
|
||||
Discontinued distributing libpng-1.x.x.tar.bz2.
|
||||
Discontinued distributing libpng-1.7.0-1.6.0-diff.txt and similar.
|
||||
|
||||
Version 1.7.0alpha06 [January 1, 2013]
|
||||
Fixed 'make distcheck' on SUN OS - libpng.so was not being removed
|
||||
|
||||
Version 1.7.0alpha07 [January 10, 2013]
|
||||
Fixed conceivable but difficult to repro overflow. Also added two test
|
||||
programs to generate and test a PNG which should have the problem.
|
||||
|
||||
Version 1.7.0alpha08 [January 17, 2013]
|
||||
Corrected previous attempt at overflow detection in png_set_unknown_chunks()
|
||||
(CVE-2013-7353). Added overflow detection in png_set_sPLT() and
|
||||
png_set_text_2() (CVE-2013-7354).
|
||||
|
||||
Version 1.7.0alpha09 [January 21, 2013]
|
||||
Pulled changes to multi-chunk handling from libpng-1.6.0beta40.
|
||||
|
||||
Version 1.7.0alpha10 [February 5, 2013]
|
||||
Make symbol prefixing work with the ARM neon optimizations. Also
|
||||
allow pngpriv.h to be included for preprocessor definitions only, so
|
||||
it can be used in non-C/C++ files.
|
||||
Added png_get_palette_max() function.
|
||||
Changed png_size_t to size_t throughout headers, make sRGB check numbers
|
||||
consistent.
|
||||
Fixed ARM support (Mans Rullgard).
|
||||
Removed stray out-of-order #endif and #ifdef (Mans Rullgard).
|
||||
Ported libpng 1.5 options.awk/dfn file handling to 1.7, fixed one bug.
|
||||
Rebuilt Makefile.in, configure, etc., with autoconf-2.69 and automake-1.13.
|
||||
Minor fixes to assembler changes, verified with a dummy .S file
|
||||
Removed cc -E workround, corrected png_get_palette_max API. Tested on
|
||||
SUN OS cc 5.9, which demonstrates the tokenization problem previously
|
||||
avoided by using /lib/cpp. Since all .dfn output is now protected
|
||||
in double quotes unless it is to be macro substituted the fix should work
|
||||
everywhere.
|
||||
|
||||
Version 1.7.0beta01 [February 15, 2013]
|
||||
Enable parallel tests and rearrange TESTS order to take advantage of
|
||||
the massive speed improvements use a make capable of parallel builds
|
||||
on a multi-CPU machine and pass the right arguments to make (-j10000
|
||||
for GNU make) to get the build to run in parallel.
|
||||
Fixed previous support for Z_PREFIX in configure builds, corrected
|
||||
sCAL APIs; some of these use floating point arithmetic so need to be
|
||||
disabled if floating point arithmetic is switched off. This is a quiet API
|
||||
change - previously it appeared that the APIs were supported if fixed point
|
||||
arithmetic was used internally, however they required certain APIs (floor,
|
||||
modf, frexp, atof) that are part of C floating point support. Changed
|
||||
png_fixed and the gamma code specific version of the same to avoid floor(),
|
||||
which may be a library function (not an intrinsic). Removed unused #if 0
|
||||
code.
|
||||
Fixed make distcheck to skip over the test result files. They were
|
||||
being included because the whole of the 'tests' directory is included,
|
||||
fixed to just include the actual test files and tests/pngstest. Also
|
||||
reverted the previous erroneous change to remove the ${srcdir} from the
|
||||
front of contrib, scripts, projects and added an explanation of what is
|
||||
going on to Makefile.am
|
||||
Fixed missing dependency in --prefix builds. The intermediate
|
||||
internal 'prefix.h' file can only be generated correctly after pnglibconf.h,
|
||||
however the dependency was not in Makefile.am. The symptoms are
|
||||
unpredictable depending on the order make chooses to build pngprefix.h and
|
||||
pnglibconf.h, often the error goes unnoticed because there is a system
|
||||
pnglibconf.h to use instead.
|
||||
Accept "," as a separator in pnglibconf.dfa and allow for
|
||||
continuation lines. This adds to the syntax of "option" and "chunk" lines,
|
||||
allowing the elements to be separated by a "," at the end of an element and
|
||||
interpreting a "," at end of line as a continuation - so the following line
|
||||
is read. The new syntax is optional and solely provided for readability.
|
||||
Enclosed the new png_get_palette_max in #ifdef PNG_GET_PALETTE_MAX_SUPPORTED
|
||||
block, and revised pnglibconf.h and pnglibconf.h.prebuilt accordingly.
|
||||
|
||||
Version 1.7.0beta02 [February 18, 2013]
|
||||
Fixed a race condition in the creation of the build 'scripts' directory
|
||||
while building with a parallel make.
|
||||
Use approved/supported Android method to check for NEON, use Linux/POSIX
|
||||
1003.1 API to check /proc/self/auxv avoiding buffer allocation and other
|
||||
library calls (ported from libpng15).
|
||||
Use parentheses more consistently in "#if defined(MACRO)" tests.
|
||||
Folded long lines.
|
||||
|
||||
Version 1.7.0beta03 [February 22, 2013]
|
||||
Reenabled code to allow zero length PLTE chunks for MNG.
|
||||
Fixed ALIGNED_MEMORY support.
|
||||
Allow run-time ARM NEON checking to be disabled. A new configure option:
|
||||
--enable-arm-neon=always will stop the run-time checks. New checks
|
||||
within arm/arm_init.c will cause the code not to be compiled unless
|
||||
__ARM_NEON__ is set. This should make it fail safe (if someone asks
|
||||
for it on then the build will fail if it can't be done.)
|
||||
Updated the INSTALL document.
|
||||
|
||||
Version 1.7.0beta04 [February 27, 2013]
|
||||
Revised INSTALL to recommend using CPPFLAGS instead of INCLUDES.
|
||||
Revised scripts/makefile.freebsd to respect ZLIBLIB and ZLIBINC.
|
||||
Revised scripts/dfn.awk to work with the buggy MSYS awk that has trouble
|
||||
with CRLF line endings.
|
||||
|
||||
Version 1.7.0beta05 [March 5, 2013]
|
||||
Avoid a possible memory leak in contrib/gregbook/readpng.c
|
||||
Changed user chunk callback API to respect global and per chunk defaults.
|
||||
Previously a return of 0 from a user chunk callback would result in the
|
||||
chunk being saved (if this was safe, even if the chunk was unsafe-to-copy);
|
||||
this change respects the defaults set by the application, so unknown chunks
|
||||
can be discarded by default and known-safe ones preserved.
|
||||
Corrected Android builds and corrected libpng.vers with symbol
|
||||
prefixing. This adds an API to set optimization options externally,
|
||||
providing an alternative and general solution for the non-portable
|
||||
run-time tests used by the ARM Neon code. It also makes those tests
|
||||
compile and link on Android. The order of settings vs options in
|
||||
pnglibconf.h is reversed to allow settings to depend on options and
|
||||
options can now set (or override) the defaults for settings.
|
||||
|
||||
Version 1.7.0beta06 [March 13, 2013]
|
||||
Corrected simplified API default gamma for color-mapped output, added
|
||||
a flag to change default. In 1.6.0 when the simplified API was used
|
||||
to produce color-mapped output from an input image with no gamma
|
||||
information the gamma assumed for the input could be different from
|
||||
that assumed for non-color-mapped output. In particular 16-bit depth
|
||||
input files were assumed to be sRGB encoded, whereas in the 'direct'
|
||||
case they were assumed to have linear data. This was an error. The
|
||||
fix makes the simplified API treat all input files the same way and
|
||||
adds a new flag to the png_image::flags member to allow the
|
||||
application/user to specify that 16-bit files contain sRGB data
|
||||
rather than the default linear.
|
||||
Fixed bugs in the pngpixel and makepng test programs.
|
||||
Fixed CMakelists.txt to allow building a single variant of the library
|
||||
(Claudio Bley):
|
||||
Introduced a PNG_LIB_TARGETS variable that lists all activated library
|
||||
targets. It is an error if this variable ends up empty, ie. you have
|
||||
to build at least one library variant.
|
||||
Made the *_COPY targets only depend on library targets actually being build.
|
||||
Use PNG_LIB_TARGETS to unify a code path.
|
||||
Changed the CREATE_SYMLINK macro to expect the full path to a file as the
|
||||
first argument. When symlinking the filename component of that path is
|
||||
determined and used as the link target.
|
||||
Use copy_if_different in the CREATE_SYMLINK macro.
|
||||
Eliminated two warnings from the Intel C compiler. The warnings are
|
||||
technically valid, although a reasonable treatment of division would
|
||||
show it to be incorrect.
|
||||
|
||||
Version 1.7.0beta07 [April 14, 2013]
|
||||
Updated documentation of 1.5.x to 1.6.x changes in iCCP chunk handling.
|
||||
Fixed incorrect warning of excess deflate data. End condition - the
|
||||
warning would be produced if the end of the deflate stream wasn't read
|
||||
in the last row. The warning is harmless.
|
||||
Corrected the test on user transform changes on read. It was in the
|
||||
png_set of the transform function, but that doesn't matter unless the
|
||||
transform function changes the rowbuf size, and that is only valid if
|
||||
transform_info is called.
|
||||
Corrected a misplaced closing bracket in contrib/libtests/pngvalid.c
|
||||
(Flavio Medeiros).
|
||||
Corrected length written to uncompressed iTXt chunks (Samuli Suominen).
|
||||
|
||||
Version 1.7.0beta08 [April 18, 2013]
|
||||
Added contrib/tools/fixitxt.c, to repair the erroneous iTXt chunk length
|
||||
written by libpng-1.6.0 and 1.6.1.
|
||||
Disallow storing sRGB information when the sRGB is not supported.
|
||||
|
||||
Version 1.7.0beta09 [April 24, 2013]
|
||||
Exposed PNG chunk types in png.h
|
||||
Modified png_uint_32 macros/code to make as few assumptions as possible
|
||||
about the hardware.
|
||||
Revised stack marking in arm/filter_neon.S and configure.ac.
|
||||
Ensure that NEON filter stuff is completely disabled when switched 'off'.
|
||||
Previously the ARM NEON specific files were still built if the option
|
||||
was switched 'off' as opposed to being explicitly disabled.
|
||||
|
||||
Version 1.7.0beta10 [April 24, 2013]
|
||||
Attempt to fix the PNG_ARM_NEON configuration mess.
|
||||
|
||||
Version 1.7.0beta11 [April 26, 2013]
|
||||
Test for 'arm*', not just 'arm' in the host_cpu configure variable.
|
||||
|
||||
Version 1.7.0beta12 [April 30, 2013]
|
||||
Added png_app_warning for out-of-range unknown chunk index in
|
||||
png_set_unknown_chunk_location().
|
||||
Expanded manual paragraph about writing private chunks.
|
||||
Avoid dereferencing NULL pointer possibly returned from
|
||||
png_create_write_struct() (Andrew Church).
|
||||
|
||||
Version 1.7.0beta13 [May 12, 2013]
|
||||
Revised contrib/pngminim/*/makefile to generate pnglibconf.h with the
|
||||
right zlib header files.
|
||||
Separated CPPFLAGS and CFLAGS in contrib/pngminim/*/makefile
|
||||
Updated contrib/pngminus/pnm2png.c (Paul Stewart):
|
||||
Check for EOF
|
||||
Ignore "#" delimited comments in input file to pnm2png.c.
|
||||
Fixed whitespace handling
|
||||
Added a call to png_set_packing()
|
||||
Initialize dimension values so if sscanf fails at least we have known
|
||||
invalid values.
|
||||
Calculate our own zlib windowBits when decoding rather than trusting the
|
||||
CMF bytes in the PNG datastream.
|
||||
Added an option to force maximum window size for inflating, which was
|
||||
the behavior of libpng15 and earlier.
|
||||
Added png-fix-itxt and png-fix-too-far-back to the built programs and
|
||||
removed warnings from the source code and timepng that are revealed as
|
||||
a result.
|
||||
Detect wrong libpng versions linked to png-fix-too-far-back, which currently
|
||||
only works with libpng versions that can be made to reliably fail when
|
||||
the deflate data contains an out-of-window reference. This means only
|
||||
1.6 and later.
|
||||
Attempt to detect configuration issues with png-fix-too-far-back, which
|
||||
requires both the correct libpng and the correct zlib to function
|
||||
correctly.
|
||||
Check ZLIB_VERNUM for mismatches, enclose #error in quotes
|
||||
Added information in the documentation about problems with and fixes for
|
||||
the bad CRC and bad iTXt chunk situations.
|
||||
|
||||
Version 1.7.0beta14 [June 8, 2013]
|
||||
Removed a redundant test in png_set_IHDR().
|
||||
Added set(CMAKE_CONFIGURATION_TYPES ...) to CMakeLists.txt (Andrew Hundt)
|
||||
Deleted set(CMAKE_BUILD_TYPE) block from CMakeLists.txt
|
||||
Enclose the prototypes for the simplified write API in #ifdef STDIO/#endif
|
||||
Make ARM NEON support work at compile time (not just configure time).
|
||||
This moves the test on __ARM_NEON__ into pngconf.h to avoid issues when
|
||||
using a compiler that compiles for multiple architectures at one time.
|
||||
Removed PNG_FILTER_OPTIMIZATIONS and PNG_ARM_NEON_SUPPORTED from
|
||||
pnglibconf.h, allowing more of the decisions to be made internally
|
||||
(pngpriv.h) during the compile. Without this, symbol prefixing is broken
|
||||
under certain circumstances on ARM platforms. Now only the API parts of
|
||||
the optimizations ('check' vs 'api') are exposed in the public header files
|
||||
except that the new setting PNG_ARM_NEON_OPT documents how libpng makes the
|
||||
decision about whether or not to use the optimizations.
|
||||
Protect symbol prefixing against CC/CPPFLAGS/CFLAGS useage.
|
||||
Previous iOS/Xcode fixes for the ARM NEON optimizations moved the test
|
||||
on __ARM_NEON__ from configure time to compile time. This breaks symbol
|
||||
prefixing because the definition of the special png_init_filter_functions
|
||||
call was hidden at configure time if the relevant compiler arguments are
|
||||
passed in CFLAGS as opposed to CC. This change attempts to avoid all
|
||||
the confusion that would result by declaring the init function even when
|
||||
it is not used, so that it will always get prefixed.
|
||||
|
||||
Version 1.7.0beta15 [June 18, 2013]
|
||||
Revised libpng.3 so that "doclifter" can process it.
|
||||
|
||||
Version 1.7.0beta16 [July 5, 2013]
|
||||
Revised example.c to illustrate use of PNG_DEFAULT_sRGB and PNG_GAMMA_MAC_18
|
||||
as parameters for png_set_gamma(). These have been available since
|
||||
libpng-1.5.4.
|
||||
Renamed contrib/tools/png-fix-too-far-back.c to pngfix.c and revised it
|
||||
to check all compressed chunks known to libpng.
|
||||
Updated documentation to show default behavior of benign errors correctly.
|
||||
Added perfect hash code generation for lists of PNG chunks. This is
|
||||
a work in progress; checked in for use in pngfix.c
|
||||
Ported ARM no-read patch from libpng16.
|
||||
Ported pngfix.c patches from libpng16.
|
||||
|
||||
Version 1.7.0beta17 [August 21, 2013]
|
||||
Revised manual about changes in iTXt chunk handling made in libpng-1.6.0.
|
||||
Added "/* SAFE */" comments in pngrutil.c and pngrtran.c where warnings
|
||||
may be erroneously issued by code-checking applications.
|
||||
Added information about png_set_options() to the manual.
|
||||
Delay calling png_init_filter_functions() until a row with nonzero filter
|
||||
is found.
|
||||
|
||||
Version 1.7.0beta18 [September 16, 2013]
|
||||
Fixed inconsistent conditional compilation of png_chunk_unknown_handling()
|
||||
prototype, definition, and usage. Made it depend on
|
||||
PNG_HANDLE_AS_UNKNOWN_SUPPORTED everywhere.
|
||||
|
||||
Version 1.7.0beta19 [September 30, 2013]
|
||||
Reverted the change to unknown handling #defines; the change breaks 'NOREAD'
|
||||
builds.
|
||||
Fixed default behavior of ARM_NEON_API. If the ARM NEON API option is
|
||||
compiled without the CHECK option it defaulted to on, not off.
|
||||
Catch up with recent libpng16 changes; unknown handling and spelling
|
||||
corrections
|
||||
Avoid up-cast warnings in pngvalid.c. On ARM the alignment requirements of
|
||||
png_modifier are greater than that of png_store and as a consequence
|
||||
compilation of pngvalid.c results in a warning about increased alignment
|
||||
requirements because of the bare cast to (png_modifier*). The code is
|
||||
safe, because the pointer is known to point to a stack allocated
|
||||
png_modifier, but this change avoids the warning.
|
||||
Fixed some grammatical changes and updated the png chunks list.
|
||||
|
||||
Version 1.7.0beta20 [October 13, 2013]
|
||||
Made changes for compatibility with automake 1.14:
|
||||
1) Added the 'compile' program to the list of programs that must be cleaned
|
||||
in autogen.sh
|
||||
2) Added 'subdir-objects' which causes .c files in sub-directories to be
|
||||
compiled such that the corresponding .o files are also in the
|
||||
sub-directory. This is because automake 1.14 warns that the
|
||||
current behavior of compiling to the top level directory may be removed
|
||||
in the future.
|
||||
3) Updated dependencies on pnglibconf.h to match the new .o locations and
|
||||
added all the files in contrib/libtests and contrib/tools that depend
|
||||
on pnglibconf.h
|
||||
4) Added 'BUILD_SOURCES = pnglibconf.h'; this is the automake recommended
|
||||
way of handling the dependencies of sources that are machine generated;
|
||||
unfortunately it only works if the user does 'make all' or 'make check',
|
||||
so the dependencies (3) are still required.
|
||||
Cleaned up (char*) casts of zlib messages. The latest version of the Intel C
|
||||
compiler complains about casting a string literal as (char*), so copied the
|
||||
treatment of z_const from the library code into pngfix.c
|
||||
Simplified error message code in pngunknown. The simplification has the
|
||||
useful side effect of avoiding a bogus warning generated by the latest
|
||||
version of the Intel C compiler (it objects to
|
||||
condition ? string-literal : string-literal).
|
||||
Make autogen.sh work with automake 1.13 as well as 1.14. Do this by always
|
||||
removing the 1.14 'compile' script but never checking for it.
|
||||
|
||||
Version 1.7.0beta21 [November 2, 2013]
|
||||
Added ARMv8 support (James Yu <james.yu at linaro.org>). Added file
|
||||
arm/filter_neon_intrinsics.c; enable with -mfpu=neon.
|
||||
Revised pngvalid to generate size images with as many filters as it can
|
||||
manage, limited by the number of rows.
|
||||
Cleaned up ARM NEON compilation handling. The tests are now in pngpriv.h
|
||||
and detect the broken GCC compilers.
|
||||
Allow clang derived from older GCC versions to use ARM intrinsics. This
|
||||
causes all clang builds that use -mfpu=neon to use the intrinsics code,
|
||||
not the assembler code. This has only been tested on iOS 7. It may be
|
||||
necessary to exclude some earlier clang versions but this seems unlikely.
|
||||
Changed NEON implementation selection mechanism. This allows assembler
|
||||
or intrinsics to be turned on at compile time during the build by defining
|
||||
PNG_ARM_NEON_IMPLEMENTATION to the correct value (2 or 1). This macro
|
||||
is undefined by default and the build type is selected in pngpriv.h.
|
||||
|
||||
Version 1.7.0beta22 [November 7, 2013]
|
||||
Fixed #include in filter_neon_intrinsics.c and ctype macros. The ctype char
|
||||
checking macros take an unsigned char argument, not a signed char.
|
||||
|
||||
Version 1.7.0beta23 [November 24, 2013]
|
||||
Changed #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED in pngpread.c to
|
||||
#ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED to be consistent with
|
||||
what is in pngpriv.h.
|
||||
Moved prototype for png_handle_unknown() in pngpriv.h outside of
|
||||
the #ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED/#endif block.
|
||||
Added "-Wall" to CFLAGS in contrib/pngminim/*/makefile
|
||||
Conditionally compile some unused functions reported by -Wall in
|
||||
pngminim.
|
||||
Fixed 'minimal' builds. Various obviously useful minimal configurations
|
||||
don't build because of missing contrib/libtests test programs and
|
||||
overly complex dependencies in scripts/pnglibconf.dfa. This change
|
||||
adds contrib/conftest/*.dfa files that can be used in automatic build
|
||||
scripts to ensure that these configurations continue to build.
|
||||
Enabled WRITE_INVERT and WRITE_PACK in contrib/pngminim/encoder.
|
||||
Fixed pngvalid 'fail' function declaration on the Intel C Compiler.
|
||||
This reverts to the previous 'static' implementation and works round
|
||||
the 'unused static function' warning by using PNG_UNUSED().
|
||||
|
||||
Version 1.7.0beta24 [December 15, 2013]
|
||||
Removed or marked PNG_UNUSED some harmless "dead assignments" reported
|
||||
by clang scan-build.
|
||||
Changed tabs to 3 spaces in png_debug macros and changed '"%s"m'
|
||||
to '"%s" m' to improve portability among compilers.
|
||||
Changed png_free_default() to free() in pngtest.c
|
||||
Tidied up pngfix inits and fixed pngtest no-write builds.
|
||||
Bookkeeping: Moved functions around (no changes). Moved transform
|
||||
function definitions before the place where they are called so that
|
||||
they can be made static. Move the intrapixel functions and the
|
||||
grayscale palette builder out of the png?tran.c files. The latter
|
||||
isn't a transform function and is no longer used internally, and the
|
||||
former MNG specific functions are better placed in pngread/pngwrite.c
|
||||
Made transform implementation functions static. This makes the internal
|
||||
functions called by png_do_{read|write}_transformations static. On an
|
||||
x86-64 DLL build (Gentoo Linux) this reduces the size of the text
|
||||
segment of the DLL by 1208 bytes, about 0.6%. It also simplifies
|
||||
maintenance by removing the declarations from pngpriv.h and allowing
|
||||
easier changes to the internal interfaces.
|
||||
Handle zero-length PLTE chunk or NULL palette with png_error()
|
||||
instead of png_chunk_report(), which by default issues a warning
|
||||
rather than an error, leading to later reading from a NULL pointer
|
||||
(png_ptr->palette) in png_do_expand_palette(). This is CVE-2013-6954
|
||||
and VU#650142. Libpng-1.6.1 through 1.6.7 and libpng-1.7.0beta03
|
||||
through 1.7.0beta23 are vulnerable. Libpng-1.6.0 and earlier do not
|
||||
have the bug.
|
||||
|
||||
Version 1.7.0beta25 [December 26, 2013]
|
||||
Merged files with version 1.6.8 that have not changed since then.
|
||||
Rebuilt configure scripts with automake-1.14.1 and autoconf-2.69
|
||||
|
||||
Version 1.7.0beta26 [January 1, 2014]
|
||||
Added libpng 1.5 checks to pngvalid.c
|
||||
Merged with 1.5 and 1.6 changes to create a single pngvalid.c
|
||||
Added dSIG to chunk list in png.h
|
||||
Removed #error macro from contrib/tools/pngfix.c (Thomas Klausner).
|
||||
Merged pngrio.c, pngtrans.c, and pngwio.c with libpng-1.6.9
|
||||
Fixed test programs for interlace options. Made pngvalid.c and
|
||||
pngtest.c work correctly when READ_INTERLACING and/or WRITE_INTERLACING
|
||||
are switched off.
|
||||
Changed pngvalid.c to support libpng 1.5, which does not support
|
||||
the PNG_MAXIMUM_INFLATE_WINDOW option, so #define it out when
|
||||
appropriate in pngvalid.c
|
||||
Allow unversioned links created on install to be disabled in configure.
|
||||
In configure builds 'make install' changes/adds links like png.h
|
||||
and libpng.a to point to the newly installed, versioned, files (e.g.
|
||||
libpng17/png.h and libpng17.a). Three new configure options and some
|
||||
rearrangement of Makefile.am allow creation of these links to be disabled.
|
||||
|
||||
Version 1.7.0beta27 [January 10, 2014]
|
||||
Removed potentially misleading warning from png_check_IHDR().
|
||||
|
||||
Version 1.7.0beta28 [January 20, 2014]
|
||||
Updated scripts/makefile.* to use CPPFLAGS (Cosmin).
|
||||
Added clang attribute support (Cosmin).
|
||||
|
||||
Version 1.7.0beta29 [January 30, 2014]
|
||||
Quiet an uninitialized memory warning from VS2013 in png_get_png().
|
||||
|
||||
Version 1.7.0beta30 [February 2, 2014]
|
||||
Fixed a large number of instances where PNGCBAPI was omitted from
|
||||
function definitions.
|
||||
Added pngimage test program for png_read_png and png_write_png. This
|
||||
is a work-in-progress; no tests are run automatically at present and
|
||||
the program by virtue of exhaustively testing all the transforms is
|
||||
very slow.
|
||||
|
||||
Version 1.7.0beta31 [February 6, 2014]
|
||||
Make png_read_png() and png_write_png() prototypes in png.h depend
|
||||
upon PNG_READ_SUPPORTED and PNG_WRITE_SUPPORTED.
|
||||
Removed dependence on !PNG_READ_EXPAND_SUPPORTED for calling
|
||||
png_set_packing() in png_read_png().
|
||||
Completed full working pngimage test program and added two test scripts.
|
||||
Fixed combination of ~alpha with shift. On read invert alpha, processing
|
||||
occurred after shift processing, which causes the final values to be
|
||||
outside the range that should be produced by the shift. Reversing the
|
||||
order on read makes the two transforms work together correctly and mirrors
|
||||
the order used on write.
|
||||
Do not read invalid sBIT chunks. Previously libpng only checked sBIT
|
||||
values on write, so a malicious PNG writer could therefore cause
|
||||
the read code to return an invalid sBIT chunk, which might lead to
|
||||
application errors or crashes. Such chunks are now skipped (with
|
||||
chunk_benign_error).
|
||||
Restored a line, "c = b;", that was inadvertently deleted from the
|
||||
PAETH filtering code from libpng-1.7.0beta24/pngrutil.c. Deleted
|
||||
the other instance of "c = b;" which is the one that triggered a
|
||||
scan-build warning.
|
||||
Support builds with unsupported PNG_TRANSFORM_* values. All of the
|
||||
PNG_TRANSFORM_* values are always defined in png.h and, because they
|
||||
are used for both read and write in some cases, it is not reliable
|
||||
to #if out ones that are totally unsupported. This change adds error
|
||||
detection in png_read_image() and png_write_image() to do a
|
||||
png_app_error() if the app requests something that cannot be done
|
||||
and it adds corresponding code to pngimage.c to handle such options
|
||||
by not attempting to test them.
|
||||
|
||||
Version 1.7.0beta32 [February 26, 2014]
|
||||
Moved redefines of png_error(), png_warning(), png_chunk_error(),
|
||||
and png_chunk_warning() from pngpriv.h to png.h to make them visible
|
||||
to libpng-calling applications.
|
||||
Moved OS dependent code from arm/arm_init.c, to allow the included
|
||||
implementation of the ARM NEON discovery function to be set at
|
||||
build-time and provide sample implementations from the current code in the
|
||||
contrib/arm-neon subdirectory. The __linux__ code has also been changed to
|
||||
compile and link on Android by using /proc/cpuinfo, and the old linux code
|
||||
is in contrib/arm-neon/linux-auxv.c. The new code avoids POSIX and Linux
|
||||
dependencies apart from opening /proc/cpuinfo and is C90 compliant.
|
||||
Check for info_ptr == NULL early in png_read_end() so we don't need to
|
||||
run all the png_handle_*() and depend on them to return if info_ptr == NULL.
|
||||
This improves the performance of png_read_end(png_ptr, NULL) and makes
|
||||
it more robust against future programming errors.
|
||||
Check for __has_extension before using it in pngconf.h, to
|
||||
support older Clang versions (Jeremy Sequoia).
|
||||
Use a user warning handler in contrib/gregbook/readpng2.c instead of default,
|
||||
so warnings will be put on stderr even if libpng has CONSOLE_IO disabled.
|
||||
Added png_ptr->process_mode = PNG_READ_IDAT_MODE in png_push_read_chunk
|
||||
after recognizing the IDAT chunk, which avoids an infinite loop while
|
||||
reading a datastream whose first IDAT chunk is of zero-length.
|
||||
This fixes CERT VU#684412 and CVE-2014-0333.
|
||||
Don't recognize known sRGB profiles as sRGB if they have been hacked,
|
||||
but don't reject them and don't issue a copyright violation warning.
|
||||
Minor editing of contrib/arm-neon/README and contrib/examples/*.c
|
||||
Moved some documentation from png.h to libpng.3 and libpng-manual.txt
|
||||
|
||||
Version 1.7.0beta33 [February 27, 2014]
|
||||
Fixed typos in the manual and in scripts/pnglibconf.dfa (CFLAGS -> CPPFLAGS
|
||||
and PNG_USR_CONFIG -> PNG_USER_CONFIG).
|
||||
|
||||
Version 1.7.0beta34 [March 17, 2014]
|
||||
Treat CRC error handling with png_set_crc_action(), instead of with
|
||||
png_set_benign_errors(), which has been the case since libpng-1.6.0beta18.
|
||||
Use "if (value != 0)" instead of "if (value)" consistently.
|
||||
Changed ZlibSrcDir from 1.2.5 to 1.2.8 in projects/vstudio.
|
||||
Moved configuration information from the manual to the INSTALL file.
|
||||
|
||||
Version 1.7.0beta35 [August 6, 2014]
|
||||
Removed #if/#else/#endif from inside two pow() calls in pngvalid.c because
|
||||
they were handled improperly by Portland Group's PGI-14.1 - PGI-14.3
|
||||
when using its "__builtin_pow()" function.
|
||||
Silence 'unused parameter' build warnings (Cosmin).
|
||||
$(CP) is now used alongside $(RM_F). Also, use 'copy' instead
|
||||
of 'cp' where applicable, and applied other minor makefile changes.
|
||||
Don't warn about invalid dimensions exceeding user limits.
|
||||
Allow an easy replacement of the default pre-built configuration
|
||||
header with a custom header, via the make PNGLIBCONF_H_PREBUILT
|
||||
macro.
|
||||
Fixed a typo in pngrutil.c, introduced in libpng-1.5.6, that interferes
|
||||
with "blocky" expansion of sub-8-bit interlaced PNG files (Eric Huss).
|
||||
Removed scripts/makefile.elf. It has not worked since libpng-1.5.0beta14
|
||||
due to elimination of the PNG_FUNCTION_EXPORT and PNG_DATA_EXPORT
|
||||
definitions from pngconf.h.
|
||||
Ensure that CMakeLists.txt makes the target "lib" directory before making
|
||||
symbolic link into it (SourceForge bug report #226 by Rolf Timmermans).
|
||||
Added opinion that the ECCN (Export Control Classification Number) for
|
||||
libpng is EAR99 to the README file.
|
||||
|
||||
Version 1.7.0beta36 [September 27, 2014]
|
||||
Updated scripts/makefiles from libpng-1.6.13beta04.
|
||||
Minor updates to the manual from libpng-1.6.14beta04.
|
||||
Fixed incorrect handling of the iTXt compression flag in pngrutil.c
|
||||
(bug report by Shunsaku Hirata). Bug was introduced in libpng-1.6.0.
|
||||
|
||||
Version 1.7.0beta37 [September 28, 2014]
|
||||
Merged scripts/*, pngvalid.c and pngfix.c with libpng-1.6.14beta04.
|
||||
|
||||
Version 1.7.0beta38 [October 17, 2014]
|
||||
Added "option READ_iCCP enables READ_COMPRESSED_TEXT" to pnglibconf.dfa
|
||||
Removed unused "text_len" parameter from private function png_write_zTXt().
|
||||
Conditionally compile some code in png_deflate_claim(), when
|
||||
PNG_WARNINGS_SUPPORTED and PNG_ERROR_TEXT_SUPPORTED are disabled.
|
||||
Replaced repeated code in pngpread.c with PNG_PUSH_SAVE_BUFFER_IF_FULL.
|
||||
Added "chunk iTXt enables TEXT" and "chunk zTXt enables TEXT"
|
||||
to pnglibconf.dfa.
|
||||
Removed "option READ_COMPRESSED_TEXT enables READ_TEXT" from pnglibconf.dfa,
|
||||
to make it possible to configure a libpng that supports iCCP but not TEXT.
|
||||
Removed "option WRITE_COMPRESSED_TEXT enables WRITE_TEXT" from pnglibconf.dfa
|
||||
Only mark text chunks as written after successfully writing them.
|
||||
|
||||
Version 1.7.0beta39 [November 1, 2014]
|
||||
Ported cosmetic changes from libpng-1.6.15beta02.
|
||||
|
||||
Version 1.7.0beta40 [November 6, 2014]
|
||||
Made a one-line revision to configure.ac to support ARM on aarch64
|
||||
(bug report by Marcin Juszkiewicz, fix by John Bowler).
|
||||
Use png_get_libpng_ver(NULL) instead of PNG_LIBPNG_VER_STRING in
|
||||
example.c, pngtest.c, and applications in the contrib directory.
|
||||
Avoid out-of-bounds memory access in png_user_version_check().
|
||||
Simplified and future-proofed png_user_version_check().
|
||||
Fixed GCC unsigned int->float warnings. Various versions of GCC
|
||||
seem to generate warnings when an unsigned value is implicitly
|
||||
converted to double. This is probably a GCC bug but this change
|
||||
avoids the issue by explicitly converting to (int) where safe.
|
||||
Free all allocated memory in pngimage. The file buffer cache was left
|
||||
allocated at the end of the program, harmless but it causes memory
|
||||
leak reports from clang.
|
||||
Fixed array size calculations to avoid warnings. At various points
|
||||
in the code the number of elements in an array is calculated using
|
||||
sizeof. This generates a compile time constant of type (size_t) which
|
||||
is then typically assigned to an (unsigned int) or (int). Some versions
|
||||
of GCC on 64-bit systems warn about the apparent narrowing, even though
|
||||
the same compiler does apparently generate the correct, in-range,
|
||||
numeric constant. This adds appropriate, safe, casts to make the
|
||||
warnings go away.
|
||||
|
||||
Version 1.7.0beta41 [November 7, 2014]
|
||||
Added #ifdef PNG_16BIT_SUPPORTED/#endif around png_log16bit() and
|
||||
png_do_swap().
|
||||
Changed all "#endif /* PNG_FEATURE_SUPPORTED */" to "#endif /* FEATURE */"
|
||||
|
||||
Version 1.7.0beta42 [November 20, 2014]
|
||||
The macros passed in the command line to Borland make were ignored if
|
||||
similarly-named macros were already defined in makefiles. This behavior
|
||||
is different from POSIX make and other make programs. Surround the
|
||||
macro definitions with ifndef guards (Cosmin).
|
||||
Added "-D_CRT_SECURE_NO_WARNINGS" to CFLAGS in scripts/makefile.vcwin32.
|
||||
Removed the obsolete $ARCH variable from scripts/makefile.darwin.
|
||||
Merged clang no-warning fix from libpng-1.6.13: png_digit was defined
|
||||
but never used in pngerror.c.
|
||||
|
||||
Send comments/corrections/commendations to png-mng-implement at lists.sf.net
|
||||
(subscription required; visit
|
||||
https://lists.sourceforge.net/lists/listinfo/png-mng-implement
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# CMakeLists.txt
|
||||
|
||||
# Copyright (C) 2007-2011 Glenn Randers-Pehrson
|
||||
# Copyright (C) 2007-2014 Glenn Randers-Pehrson
|
||||
|
||||
# This code is released under the libpng license.
|
||||
# For conditions of distribution and use, see the disclaimer
|
||||
@@ -9,32 +9,13 @@
|
||||
cmake_minimum_required(VERSION 2.4.4)
|
||||
set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
|
||||
|
||||
if(UNIX AND NOT DEFINED CMAKE_BUILD_TYPE)
|
||||
if(CMAKE_MAJOR_VERSION EQUAL 2 AND CMAKE_MINOR_VERSION EQUAL 4)
|
||||
# workaround CMake 2.4.x bug
|
||||
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING
|
||||
"Choose the type of build, options are:
|
||||
None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used)
|
||||
Debug
|
||||
Release
|
||||
RelWithDebInfo
|
||||
MinSizeRel.")
|
||||
else()
|
||||
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING
|
||||
"Choose the type of build, options are:
|
||||
None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used)
|
||||
Debug
|
||||
Release
|
||||
RelWithDebInfo
|
||||
MinSizeRel.")
|
||||
endif()
|
||||
endif()
|
||||
set(CMAKE_CONFIGURATION_TYPES "Release;Debug;MinSizeRel;RelWithDebInfo")
|
||||
|
||||
project(libpng C)
|
||||
enable_testing()
|
||||
|
||||
set(PNGLIB_MAJOR 1)
|
||||
set(PNGLIB_MINOR 6)
|
||||
set(PNGLIB_MINOR 7)
|
||||
set(PNGLIB_RELEASE 0)
|
||||
set(PNGLIB_NAME libpng${PNGLIB_MAJOR}${PNGLIB_MINOR})
|
||||
set(PNGLIB_VERSION ${PNGLIB_MAJOR}.${PNGLIB_MINOR}.${PNGLIB_RELEASE})
|
||||
@@ -139,8 +120,11 @@ endif()
|
||||
# NOW BUILD OUR TARGET
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${ZLIB_INCLUDE_DIR})
|
||||
|
||||
unset(PNG_LIB_TARGETS)
|
||||
|
||||
if(PNG_SHARED)
|
||||
add_library(${PNG_LIB_NAME} SHARED ${libpng_sources})
|
||||
set(PNG_LIB_TARGETS ${PNG_LIB_NAME})
|
||||
if(MSVC)
|
||||
# msvc does not append 'lib' - do it here to have consistent name
|
||||
set_target_properties(${PNG_LIB_NAME} PROPERTIES PREFIX "lib")
|
||||
@@ -153,6 +137,7 @@ if(PNG_STATIC)
|
||||
# does not work without changing name
|
||||
set(PNG_LIB_NAME_STATIC ${PNG_LIB_NAME}_static)
|
||||
add_library(${PNG_LIB_NAME_STATIC} STATIC ${libpng_sources})
|
||||
list(APPEND PNG_LIB_TARGETS ${PNG_LIB_NAME_STATIC})
|
||||
if(MSVC)
|
||||
# msvc does not append 'lib' - do it here to have consistent name
|
||||
set_target_properties(${PNG_LIB_NAME_STATIC} PROPERTIES PREFIX "lib")
|
||||
@@ -160,6 +145,12 @@ if(PNG_STATIC)
|
||||
target_link_libraries(${PNG_LIB_NAME_STATIC} ${ZLIB_LIBRARY} ${M_LIBRARY})
|
||||
endif()
|
||||
|
||||
if(NOT PNG_LIB_TARGETS)
|
||||
message(SEND_ERROR
|
||||
"No library variant selected to build. "
|
||||
"Please enable at least one of the following options: PNG_STATIC, PNG_SHARED")
|
||||
endif()
|
||||
|
||||
if(PNG_SHARED AND WIN32)
|
||||
set_target_properties(${PNG_LIB_NAME} PROPERTIES DEFINE_SYMBOL PNG_BUILD_DLL)
|
||||
endif()
|
||||
@@ -222,14 +213,16 @@ macro(CREATE_SYMLINK SRC_FILE DEST_FILE)
|
||||
if(WIN32 AND NOT CYGWIN AND NOT MSYS)
|
||||
ADD_CUSTOM_COMMAND(
|
||||
OUTPUT ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${DEST_FILE} ${CMAKE_CURRENT_BINARY_DIR}/${DEST_FILE}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/${SRC_FILE} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${DEST_FILE}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/${SRC_FILE} ${CMAKE_CURRENT_BINARY_DIR}/${DEST_FILE}
|
||||
DEPENDS ${PNG_LIB_NAME} ${PNG_LIB_NAME_STATIC}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${SRC_FILE}" ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${DEST_FILE}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${SRC_FILE}" ${CMAKE_CURRENT_BINARY_DIR}/${DEST_FILE}
|
||||
DEPENDS ${PNG_LIB_TARGETS}
|
||||
)
|
||||
ADD_CUSTOM_TARGET(${DEST_FILE}_COPY ALL DEPENDS ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${DEST_FILE})
|
||||
else(WIN32 AND NOT CYGWIN AND NOT MSYS)
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${SRC_FILE} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${DEST_FILE} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${SRC_FILE} ${DEST_FILE} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
||||
get_filename_component(LINK_TARGET "${SRC_FILE}" NAME)
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink "${LINK_TARGET}" ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${DEST_FILE} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink "${LINK_TARGET}" ${DEST_FILE} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
||||
endif(WIN32 AND NOT CYGWIN AND NOT MSYS)
|
||||
endmacro()
|
||||
|
||||
@@ -260,9 +253,9 @@ endif(NOT WIN32 OR CYGWIN OR MINGW)
|
||||
# SET UP LINKS
|
||||
if(PNG_SHARED)
|
||||
set_target_properties(${PNG_LIB_NAME} PROPERTIES
|
||||
# VERSION 16.${PNGLIB_RELEASE}.1.6.0beta33
|
||||
VERSION 16.${PNGLIB_RELEASE}.0
|
||||
SOVERSION 16
|
||||
# VERSION 17.${PNGLIB_RELEASE}.1.7.0beta42
|
||||
VERSION 17.${PNGLIB_RELEASE}.0
|
||||
SOVERSION 17
|
||||
CLEAN_DIRECT_OUTPUT 1)
|
||||
endif()
|
||||
if(PNG_STATIC)
|
||||
@@ -287,40 +280,33 @@ endif()
|
||||
|
||||
# INSTALL
|
||||
if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL )
|
||||
if(PNG_SHARED)
|
||||
install(TARGETS ${PNG_LIB_NAME}
|
||||
${PNG_EXPORT_RULE}
|
||||
RUNTIME DESTINATION bin
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
install(TARGETS ${PNG_LIB_TARGETS}
|
||||
${PNG_EXPORT_RULE}
|
||||
RUNTIME DESTINATION bin
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
|
||||
# Create a symlink for libpng.dll.a => libpng16.dll.a on Cygwin
|
||||
if(PNG_SHARED)
|
||||
# Create a symlink for libpng.dll.a => libpng17.dll.a on Cygwin
|
||||
if(CYGWIN OR MINGW)
|
||||
get_target_property(BUILD_TARGET_LOCATION ${PNG_LIB_NAME} LOCATION_${CMAKE_BUILD_TYPE})
|
||||
get_filename_component(BUILD_TARGET_FILE ${BUILD_TARGET_LOCATION} NAME)
|
||||
CREATE_SYMLINK(${BUILD_TARGET_FILE} libpng${CMAKE_IMPORT_LIBRARY_SUFFIX})
|
||||
CREATE_SYMLINK(${BUILD_TARGET_LOCATION} libpng${CMAKE_IMPORT_LIBRARY_SUFFIX})
|
||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng${CMAKE_IMPORT_LIBRARY_SUFFIX}
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
endif(CYGWIN OR MINGW)
|
||||
|
||||
if(NOT WIN32)
|
||||
get_target_property(BUILD_TARGET_LOCATION ${PNG_LIB_NAME} LOCATION_${CMAKE_BUILD_TYPE})
|
||||
get_filename_component(BUILD_TARGET_FILE ${BUILD_TARGET_LOCATION} NAME)
|
||||
CREATE_SYMLINK(${BUILD_TARGET_FILE} libpng${CMAKE_SHARED_LIBRARY_SUFFIX})
|
||||
CREATE_SYMLINK(${BUILD_TARGET_LOCATION} libpng${CMAKE_SHARED_LIBRARY_SUFFIX})
|
||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng${CMAKE_SHARED_LIBRARY_SUFFIX}
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
endif(NOT WIN32)
|
||||
endif(PNG_SHARED)
|
||||
|
||||
if(PNG_STATIC)
|
||||
install(TARGETS ${PNG_LIB_NAME_STATIC}
|
||||
${PNG_EXPORT_RULE}
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
if(NOT WIN32 OR CYGWIN OR MINGW)
|
||||
get_target_property(BUILD_TARGET_LOCATION ${PNG_LIB_NAME_STATIC} LOCATION_${CMAKE_BUILD_TYPE})
|
||||
get_filename_component(BUILD_TARGET_FILE ${BUILD_TARGET_LOCATION} NAME)
|
||||
CREATE_SYMLINK(${BUILD_TARGET_FILE} libpng${CMAKE_STATIC_LIBRARY_SUFFIX})
|
||||
CREATE_SYMLINK(${BUILD_TARGET_LOCATION} libpng${CMAKE_STATIC_LIBRARY_SUFFIX})
|
||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng${CMAKE_STATIC_LIBRARY_SUFFIX}
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
endif(NOT WIN32 OR CYGWIN OR MINGW)
|
||||
@@ -365,7 +351,7 @@ if(PNG_EXPORT_RULE AND NOT SKIP_INSTALL_EXPORT AND NOT SKIP_INSTALL_ALL )
|
||||
install(EXPORT libpng DESTINATION lib/libpng FILE lib${PNG_LIB_NAME}.cmake)
|
||||
endif()
|
||||
|
||||
# what's with libpng-$VER%.txt and all the extra files?
|
||||
# what's with libpng-manual.txt and all the extra files?
|
||||
|
||||
# UNINSTALL
|
||||
# do we need this?
|
||||
|
||||
297
INSTALL
297
INSTALL
@@ -1,13 +1,47 @@
|
||||
|
||||
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. Configuring libpng for multiprocessing
|
||||
XVI. Other sources of information about libpng
|
||||
|
||||
I. Simple installation
|
||||
|
||||
On Unix/Linux and similar systems, you can simply type
|
||||
|
||||
./configure [--prefix=/path]
|
||||
make check
|
||||
make install
|
||||
|
||||
and ignore the rest of this document.
|
||||
and ignore the rest of this document. "/path" is the path to the directory
|
||||
where you want to install the libpng "lib", "include", and "bin"
|
||||
subdirectories.
|
||||
|
||||
If you downloaded a GIT clone, you will need to run ./autogen.sh before
|
||||
running ./configure, to create "configure" and "Makefile.in" which are
|
||||
not included in the GIT repository.
|
||||
|
||||
Note that "configure" is only included in the "*.tar" distributions and not
|
||||
in the "*.zip" or "*.7z" distributions. If you downloaded one of those
|
||||
distributions, see "Building with project files" or "Building with makefiles",
|
||||
below.
|
||||
|
||||
II. Rebuilding the configure scripts
|
||||
|
||||
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
|
||||
@@ -24,9 +58,12 @@ aren't using any of the included pre-built scripts, you can do this:
|
||||
make install
|
||||
make check
|
||||
|
||||
III. Using scripts/makefile*
|
||||
|
||||
Instead, you can use one of the custom-built makefiles in the
|
||||
"scripts" directory
|
||||
|
||||
cp scripts/pnglibconf.h.prebuilt pnglibconf.h
|
||||
cp scripts/makefile.system makefile
|
||||
make test
|
||||
make install
|
||||
@@ -38,8 +75,28 @@ 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. zlib can be placed in another directory,
|
||||
at the same level as libpng.
|
||||
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.
|
||||
|
||||
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
|
||||
correspond to the version of zlib that's installed.
|
||||
|
||||
If you wish to test with a particular zlib that is not first in the
|
||||
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
|
||||
|
||||
If you are using one of the makefile scripts, put ZLIBLIB and ZLIBINC
|
||||
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
|
||||
|
||||
@@ -47,13 +104,15 @@ If you want to use "cmake" (see www.cmake.org), type
|
||||
make
|
||||
make install
|
||||
|
||||
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
|
||||
correspond to the version of zlib that's installed.
|
||||
As when using the simple configure method described above, "/path" points to
|
||||
the installation directory where you want to put the libpng "lib", "include",
|
||||
and "bin" subdirectories.
|
||||
|
||||
V. Directory structure
|
||||
|
||||
You can rename the directories that you downloaded (they
|
||||
might be called "libpng-x.y.z" or "libpngNN" and "zlib-1.2.5"
|
||||
or "zlib125") so that you have directories called "zlib" and "libpng".
|
||||
might be called "libpng-x.y.z" or "libpngNN" and "zlib-1.2.8"
|
||||
or "zlib128") so that you have directories called "zlib" and "libpng".
|
||||
|
||||
Your directory structure should look like this:
|
||||
|
||||
@@ -61,8 +120,7 @@ Your directory structure should look like this:
|
||||
libpng (this directory)
|
||||
INSTALL (this file)
|
||||
README
|
||||
*.h
|
||||
*.c
|
||||
*.h, *.c => libpng source files
|
||||
CMakeLists.txt => "cmake" script
|
||||
configuration files:
|
||||
configure.ac, configure, Makefile.am, Makefile.in,
|
||||
@@ -70,14 +128,10 @@ Your directory structure should look like this:
|
||||
libpng-config.in, aclocal.m4, config.h.in, config.sub,
|
||||
depcomp, install-sh, mkinstalldirs, test-pngtest.sh
|
||||
contrib
|
||||
gregbook
|
||||
pngminim
|
||||
pngminus
|
||||
pngsuite
|
||||
visupng
|
||||
arm-neon, conftest, examples, gregbook, libtests, pngminim,
|
||||
pngminus, pngsuite, tools, visupng
|
||||
projects
|
||||
visualc71
|
||||
vstudio
|
||||
cbuilder5, owatcom, visualc71, vstudio, xcode
|
||||
scripts
|
||||
makefile.*
|
||||
*.def (module definition files)
|
||||
@@ -85,29 +139,31 @@ Your directory structure should look like this:
|
||||
pngtest.png
|
||||
etc.
|
||||
zlib
|
||||
README
|
||||
*.h
|
||||
*.c
|
||||
contrib
|
||||
etc.
|
||||
README, *.h, *.c contrib, etc.
|
||||
|
||||
If the line endings in the files look funny, you may wish to get the other
|
||||
distribution of libpng. It is available in both tar.gz (UNIX style line
|
||||
endings) and zip (DOS style line endings) formats.
|
||||
|
||||
VI. Building with project files
|
||||
|
||||
If you are building libpng with MSVC, you can enter the
|
||||
libpng projects\visualc6 or visualc71 directory and follow the instructions
|
||||
libpng projects\visualc71 or vstudio directory and follow the instructions
|
||||
in README.txt.
|
||||
|
||||
Otherwise enter the zlib directory and follow the instructions in zlib/README,
|
||||
then come back here and run "configure" or choose the appropriate
|
||||
makefile.sys in the scripts directory.
|
||||
|
||||
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
|
||||
UNIX example: cp scripts/makefile.std 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.
|
||||
@@ -130,6 +186,197 @@ do that, run "make install" in the zlib directory first if necessary).
|
||||
Some also allow you to run "make test-installed" after you have
|
||||
run "make install".
|
||||
|
||||
VIII. Configuring libpng for 16-bit platforms
|
||||
|
||||
You will want to look into zconf.h to tell zlib (and thus libpng) that
|
||||
it cannot allocate more then 64K at a time. Even if you can, the memory
|
||||
won't be accessible. So limit zlib and libpng to 64K by defining MAXSEG_64K.
|
||||
|
||||
IX. Configuring for DOS
|
||||
|
||||
For DOS users who only have access to the lower 640K, you will
|
||||
have to limit zlib's memory usage via a png_set_compression_mem_level()
|
||||
call. See zlib.h or zconf.h in the zlib library for more information.
|
||||
|
||||
X. Configuring for Medium Model
|
||||
|
||||
Libpng's support for medium model has been tested on most of the popular
|
||||
compilers. Make sure MAXSEG_64K gets defined, USE_FAR_KEYWORD gets
|
||||
defined, and FAR gets defined to far in pngconf.h, and you should be
|
||||
all set. Everything in the library (except for zlib's structure) is
|
||||
expecting far data. You must use the typedefs with the p or pp on
|
||||
the end for pointers (or at least look at them and be careful). Make
|
||||
note that the rows of data are defined as png_bytepp, which is
|
||||
an "unsigned char far * far *".
|
||||
|
||||
XI. Prepending a prefix to exported symbols
|
||||
|
||||
Starting with libpng-1.6.0, you can configure libpng (when using the
|
||||
"configure" script) to prefix all exported symbols by means of the
|
||||
configuration option "--with-libpng-prefix=FOO_", where FOO_ can be any
|
||||
string beginning with a letter and containing only uppercase
|
||||
and lowercase letters, digits, and the underscore (i.e., a C language
|
||||
identifier). This creates a set of macros in pnglibconf.h, so this is
|
||||
transparent to applications; their function calls get transformed by
|
||||
the macros to use the modified names.
|
||||
|
||||
XII. Configuring for compiler xxx:
|
||||
|
||||
All includes for libpng are in pngconf.h. If you need to add, change
|
||||
or delete an include, this is the place to do it.
|
||||
The includes that are not needed outside libpng are placed in pngpriv.h,
|
||||
which is only used by the routines inside libpng itself.
|
||||
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.
|
||||
|
||||
XIII. Removing unwanted object code
|
||||
|
||||
There are a bunch of #define's in pngconf.h that control what parts of
|
||||
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_.
|
||||
|
||||
In libpng-1.5.0 and later, the #define's are in pnglibconf.h instead.
|
||||
|
||||
You can also turn all of the transforms and ancillary chunk capabilities
|
||||
off en masse with compiler directives that define
|
||||
PNG_NO_READ[or WRITE]_TRANSFORMS, or PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS,
|
||||
or all four, along with directives to turn on any of the capabilities that
|
||||
you do want. The PNG_NO_READ[or WRITE]_TRANSFORMS directives disable the
|
||||
extra transformations but still leave the library fully capable of reading
|
||||
and writing PNG files with all known public chunks. Use of the
|
||||
PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS directive produces a library
|
||||
that is incapable of reading or writing ancillary chunks. If you are
|
||||
not using the progressive reading capability, you can turn that off
|
||||
with PNG_NO_PROGRESSIVE_READ (don't confuse this with the INTERLACING
|
||||
capability, which you'll still have).
|
||||
|
||||
All the reading and writing specific code are in separate files, so the
|
||||
linker should only grab the files it needs. However, if you want to
|
||||
make sure, or if you are building a stand alone library, all the
|
||||
reading files start with "pngr" and all the writing files start with "pngw".
|
||||
The files that don't match either (like png.c, pngtrans.c, etc.)
|
||||
are used for both reading and writing, and always need to be included.
|
||||
The progressive reader is in pngpread.c
|
||||
|
||||
If you are creating or distributing a dynamically linked library (a .so
|
||||
or DLL file), you should not remove or disable any parts of the library,
|
||||
as this will cause applications linked with different versions of the
|
||||
library to fail if they call functions not available in your library.
|
||||
The size of the library itself should not be an issue, because only
|
||||
those sections that are actually used will be loaded into memory.
|
||||
|
||||
XIV. Changes to the build and configuration of libpng in libpng-1.5.x
|
||||
|
||||
Details of internal changes to the library code can be found in the CHANGES
|
||||
file and in the GIT repository logs. These will be of no concern to the vast
|
||||
majority of library users or builders; however, the few who configure libpng
|
||||
to a non-default feature set may need to change how this is done.
|
||||
|
||||
There should be no need for library builders to alter build scripts if
|
||||
these use the distributed build support - configure or the makefiles -
|
||||
however, users of the makefiles may care to update their build scripts
|
||||
to build pnglibconf.h where the corresponding makefile does not do so.
|
||||
|
||||
Building libpng with a non-default configuration has changed completely.
|
||||
The old method using pngusr.h should still work correctly even though the
|
||||
way pngusr.h is used in the build has been changed; however, library
|
||||
builders will probably want to examine the changes to take advantage of
|
||||
new capabilities and to simplify their build system.
|
||||
|
||||
A. Specific changes to library configuration capabilities
|
||||
|
||||
The exact mechanism used to control attributes of API functions has
|
||||
changed. A single set of operating system independent macro definitions
|
||||
is used and operating system specific directives are defined in
|
||||
pnglibconf.h
|
||||
|
||||
As part of this the mechanism used to choose procedure call standards on
|
||||
those systems that allow a choice has been changed. At present this only
|
||||
affects certain Microsoft (DOS, Windows) and IBM (OS/2) operating systems
|
||||
running on Intel processors. As before, PNGAPI is defined where required
|
||||
to control the exported API functions; however, two new macros, PNGCBAPI
|
||||
and PNGCAPI, are used instead for callback functions (PNGCBAPI) and
|
||||
(PNGCAPI) for functions that must match a C library prototype (currently
|
||||
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
|
||||
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
|
||||
(png-mng-implement) of this and library builders who use Openwatcom and
|
||||
therefore set PNG_API_RULE to 2 should also contact the mailing list.
|
||||
|
||||
B. Changes to the configuration mechanism
|
||||
|
||||
Prior to libpng-1.5.0 library builders who needed to configure libpng
|
||||
had either to modify the exported pngconf.h header file to add system
|
||||
specific configuration or had to write feature selection macros into
|
||||
pngusr.h and cause this to be included into pngconf.h by defining
|
||||
PNG_USER_CONFIG. The latter mechanism had the disadvantage that an
|
||||
application built without PNG_USER_CONFIG defined would see the
|
||||
unmodified, default, libpng API and thus would probably fail to link.
|
||||
|
||||
These mechanisms still work in the configure build and in any makefile
|
||||
build that builds pnglibconf.h, although the feature selection macros
|
||||
have changed somewhat as described above. In 1.5.0, however, pngusr.h is
|
||||
processed only once, at the time the exported header file pnglibconf.h is
|
||||
built. pngconf.h no longer includes pngusr.h; therefore, pngusr.h is ignored
|
||||
after the build of pnglibconf.h and it is never included in an application
|
||||
build.
|
||||
|
||||
The formerly used alternative of adding a list of feature macros to the
|
||||
CPPFLAGS setting in the build also still works; however, the macros will be
|
||||
copied to pnglibconf.h and this may produce macro redefinition warnings
|
||||
when the individual C files are compiled.
|
||||
|
||||
All configuration now only works if pnglibconf.h is built from
|
||||
scripts/pnglibconf.dfa. This requires the program awk. Brian Kernighan
|
||||
(the original author of awk) maintains C source code of that awk and this
|
||||
and all known later implementations (often called by subtly different
|
||||
names - nawk and gawk for example) are adequate to build pnglibconf.h.
|
||||
The Sun Microsystems (now Oracle) program 'awk' is an earlier version
|
||||
and does not work; this may also apply to other systems that have a
|
||||
functioning awk called 'nawk'.
|
||||
|
||||
Configuration options are now documented in scripts/pnglibconf.dfa. This
|
||||
file also includes dependency information that ensures a configuration is
|
||||
consistent; that is, if a feature is switched off, dependent features are
|
||||
also switched off. As a recommended alternative to using feature macros in
|
||||
pngusr.h a system builder may also define equivalent options in pngusr.dfa
|
||||
(or, indeed, any file) and add that to the configuration by setting
|
||||
DFA_XTRA to the file name. The makefiles in contrib/pngminim illustrate
|
||||
how to do this, and also illustrate a case where pngusr.h is still required.
|
||||
|
||||
After you have built libpng, the definitions that were recorded in
|
||||
pnglibconf.h are available to your application (pnglibconf.h is included
|
||||
in png.h and gets installed alongside png.h and pngconf.h in your
|
||||
$PREFIX/include directory). Do not edit pnglibconf.h after you have built
|
||||
libpng, because than the settings would not accurately reflect the settings
|
||||
that were used to build libpng.
|
||||
|
||||
XV. Configuring libpng for multiprocessing
|
||||
|
||||
Libpng uses setjmp()/longjmp() for error handling. Unfortunately setjmp()
|
||||
is known to be not thread-safe on some platforms and we don't know of
|
||||
any platform where it is guaranteed to be thread-safe. Therefore, if
|
||||
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
|
||||
|
||||
in your pnglibconf.h or pngusr.h.
|
||||
|
||||
XVI. 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.
|
||||
@@ -147,7 +394,7 @@ CFLAGS="-Wall -O -funroll-loops \
|
||||
--with-pkgconfigdir=/usr/lib/pkgconfig --includedir=/usr/include
|
||||
|
||||
You can alternatively specify --includedir=/usr/include, /usr/local/include,
|
||||
/usr/include/libpng%NN%, or whatever.
|
||||
/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",
|
||||
|
||||
6
LICENSE
6
LICENSE
@@ -10,8 +10,8 @@ this sentence.
|
||||
|
||||
This code is released under the libpng license.
|
||||
|
||||
libpng versions 1.2.6, August 15, 2004, through 1.6.0beta33, December 10, 2012, are
|
||||
Copyright (c) 2004, 2006-2012 Glenn Randers-Pehrson, and are
|
||||
libpng versions 1.2.6, August 15, 2004, through 1.7.0beta42, November 20, 2014, are
|
||||
Copyright (c) 2004, 2006-2014 Glenn Randers-Pehrson, and are
|
||||
distributed according to the same disclaimer and license as libpng-1.2.5
|
||||
with the following individual added to the list of Contributing Authors
|
||||
|
||||
@@ -108,4 +108,4 @@ certification mark of the Open Source Initiative.
|
||||
|
||||
Glenn Randers-Pehrson
|
||||
glennrp at users.sourceforge.net
|
||||
December 10, 2012
|
||||
November 20, 2014
|
||||
|
||||
212
Makefile.am
212
Makefile.am
@@ -7,24 +7,66 @@ PNGLIB_BASENAME= libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@
|
||||
ACLOCAL_AMFLAGS = -I scripts
|
||||
|
||||
# test programs - run on make check, make distcheck
|
||||
TESTS_ENVIRONMENT= srcdir=$(srcdir)
|
||||
check_PROGRAMS= pngtest
|
||||
check_PROGRAMS= pngtest pngunknown pngstest pngvalid pngimage
|
||||
|
||||
# Utilities - installed
|
||||
bin_PROGRAMS= pngfix png-fix-itxt
|
||||
|
||||
# This ensures that pnglibconf.h gets built at the start of 'make all' or
|
||||
# 'make check', but it does not add dependencies to the individual programs,
|
||||
# this is done below.
|
||||
#
|
||||
# IMPORTANT: always add the object modules of new programs to the list below
|
||||
# because otherwise the sequence 'configure; make new-program' will *sometimes*
|
||||
# result in the installed (system) pnglibconf.h being used and the result is
|
||||
# always wrong and always very confusing.
|
||||
BUILT_SOURCES = pnglibconf.h
|
||||
|
||||
pngtest_SOURCES = pngtest.c
|
||||
pngtest_LDADD = libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.la
|
||||
TESTS = test-pngtest.sh
|
||||
|
||||
# Only do the following if the contrib directory is present.
|
||||
check_PROGRAMS+= pngvalid pngstest pngunknown
|
||||
pngvalid_SOURCES = contrib/libtests/pngvalid.c
|
||||
pngstest_SOURCES = contrib/libtests/pngstest.c
|
||||
pngunknown_SOURCES = contrib/libtests/pngunknown.c
|
||||
pngvalid_LDADD = libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.la
|
||||
|
||||
pngstest_SOURCES = contrib/libtests/pngstest.c
|
||||
pngstest_LDADD = libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.la
|
||||
|
||||
pngunknown_SOURCES = contrib/libtests/pngunknown.c
|
||||
pngunknown_LDADD = libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.la
|
||||
TESTS += contrib/libtests/test-pngunknown.sh\
|
||||
contrib/libtests/test-pngvalid-simple.sh\
|
||||
contrib/libtests/test-pngvalid-full.sh\
|
||||
contrib/libtests/test-pngstest.sh
|
||||
|
||||
pngimage_SOURCES = contrib/libtests/pngimage.c
|
||||
pngimage_LDADD = libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.la
|
||||
|
||||
pngfix_SOURCES = contrib/tools/pngfix.c
|
||||
pngfix_LDADD = libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.la
|
||||
|
||||
png_fix_itxt_SOURCES = contrib/tools/png-fix-itxt.c
|
||||
|
||||
# Generally these are single line shell scripts to run a test with a particular
|
||||
# set of parameters:
|
||||
TESTS =\
|
||||
tests/pngtest\
|
||||
tests/pngvalid-gamma-16-to-8 tests/pngvalid-gamma-alpha-mode\
|
||||
tests/pngvalid-gamma-background tests/pngvalid-gamma-expand16-alpha-mode\
|
||||
tests/pngvalid-gamma-expand16-background\
|
||||
tests/pngvalid-gamma-expand16-transform tests/pngvalid-gamma-sbit\
|
||||
tests/pngvalid-gamma-threshold tests/pngvalid-gamma-transform\
|
||||
tests/pngvalid-progressive-interlace-size\
|
||||
tests/pngvalid-progressive-interlace-standard\
|
||||
tests/pngvalid-progressive-interlace-transform\
|
||||
tests/pngvalid-progressive-standard tests/pngvalid-standard\
|
||||
tests/pngstest-0g01 tests/pngstest-0g02 tests/pngstest-0g04\
|
||||
tests/pngstest-0g08 tests/pngstest-0g16 tests/pngstest-2c08\
|
||||
tests/pngstest-2c16 tests/pngstest-3p01 tests/pngstest-3p02\
|
||||
tests/pngstest-3p04 tests/pngstest-3p08 tests/pngstest-4a08\
|
||||
tests/pngstest-4a16 tests/pngstest-6a08 tests/pngstest-6a16\
|
||||
tests/pngstest-error tests/pngunknown-IDAT\
|
||||
tests/pngunknown-discard tests/pngunknown-if-safe tests/pngunknown-sAPI\
|
||||
tests/pngunknown-sTER tests/pngunknown-save tests/pngunknown-vpAg\
|
||||
tests/pngimage-quick tests/pngimage-full
|
||||
|
||||
# These tests are expected, and required, to fail:
|
||||
XFAIL_TESTS = tests/pngstest-error
|
||||
|
||||
# man pages
|
||||
dist_man_MANS= libpng.3 libpngpf.3 png.5
|
||||
@@ -43,7 +85,8 @@ libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_SOURCES = png.c pngerror.c\
|
||||
png.h pngconf.h pngdebug.h pnginfo.h pngpriv.h pngstruct.h pngusr.dfa
|
||||
|
||||
if PNG_ARM_NEON
|
||||
libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_SOURCES += arm/filter_neon.S
|
||||
libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_SOURCES += arm/arm_init.c\
|
||||
arm/filter_neon.S arm/filter_neon_intrinsics.c
|
||||
endif
|
||||
|
||||
nodist_libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_SOURCES = pnglibconf.h
|
||||
@@ -76,12 +119,14 @@ nodist_pkginclude_HEADERS= pnglibconf.h
|
||||
pkgconfigdir = @pkgconfigdir@
|
||||
pkgconfig_DATA = libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.pc
|
||||
|
||||
#extra source distribution files.
|
||||
# Extra source distribution files, '${srcdir}' is used below to stop build files
|
||||
# from those directories being included. This only works if the configure is
|
||||
# not done in the source directory!
|
||||
EXTRA_DIST= \
|
||||
ANNOUNCE CHANGES INSTALL LICENSE README TODO \
|
||||
pngtest.png pngbar.png pngnow.png pngbar.jpg autogen.sh \
|
||||
${srcdir}/contrib ${srcdir}/projects ${srcdir}/scripts \
|
||||
$(TESTS) \
|
||||
$(TESTS) $(XFAIL_TESTS) tests/pngstest \
|
||||
CMakeLists.txt example.c libpng-manual.txt
|
||||
|
||||
SCRIPT_CLEANFILES=scripts/*.out scripts/*.chk scripts/pnglibconf.dfn
|
||||
@@ -100,8 +145,8 @@ config.sub configure depcomp install-sh ltmain.sh missing
|
||||
PNG_COPTS = @PNG_COPTS@
|
||||
AM_CFLAGS = ${PNG_COPTS}
|
||||
|
||||
# DFNCPP is normally just CPP - the C preprocessor - but on Solaris and maybe
|
||||
# other operating systems (NeXT?) the C preprocessor selected by configure
|
||||
# DFNCPP is normally just "CPP -E" - the C preprocessor - but on Solaris and
|
||||
# maybe other operating systems (NeXT?) the C preprocessor selected by configure
|
||||
# checks input tokens for validity - effectively it performs part of the ANSI-C
|
||||
# parsing - and therefore fails with the .df files. configure.ac has special
|
||||
# checks for this and sets DFNCPP appropriately.
|
||||
@@ -118,6 +163,9 @@ $(PNGLIB_BASENAME)-config: libpng-config
|
||||
scripts/sym.out scripts/vers.out: png.h pngconf.h pnglibconf.h
|
||||
scripts/prefix.out: png.h pngconf.h pnglibconf.out
|
||||
scripts/symbols.out: png.h pngconf.h $(srcdir)/scripts/pnglibconf.h.prebuilt
|
||||
scripts/intprefix.out: pnglibconf.h
|
||||
|
||||
pnglibconf.out: config.h
|
||||
|
||||
libpng.sym: scripts/sym.out
|
||||
rm -f $@
|
||||
@@ -130,7 +178,7 @@ if DO_PNG_PREFIX
|
||||
# Rename functions in scripts/prefix.out with a PNG_PREFIX prefix.
|
||||
# Rename macros in scripts/macro.lst from PNG_PREFIXpng_ to PNG_ (the actual
|
||||
# implementation of the macro).
|
||||
pnglibconf.h: pnglibconf.out scripts/prefix.out scripts/macro.lst
|
||||
pnglibconf.h: pnglibconf.out scripts/prefix.out scripts/macro.lst config.h
|
||||
rm -f $@
|
||||
$(AWK) 's==0 && NR>1{print prev}\
|
||||
s==0{prev=$$0}\
|
||||
@@ -156,14 +204,28 @@ endif
|
||||
$(srcdir)/scripts/pnglibconf.h.prebuilt:
|
||||
@echo "Attempting to build $@" >&2
|
||||
@echo "This is a machine generated file, but if you want to make" >&2
|
||||
@echo "a new one simply make 'scripts/pnglibconf.out' and copy that" >&2
|
||||
@echo "a new one simply make 'scripts/pnglibconf.out', copy that" >&2
|
||||
@echo "AND set PNG_ZLIB_VERNUM to 0 (you MUST do this)" >&2
|
||||
@exit 1
|
||||
|
||||
# The following is necessary to ensure that the local pnglibconf.h is used, not
|
||||
# an installed one (this can happen immediately after on a clean system if
|
||||
# 'make test' is the first thing the user does.)
|
||||
contrib/libtests/pngstest.o contrib/libtests/pngvalid.o pngtest.o: pnglibconf.h
|
||||
# 'make test' is the first thing the user does.) Only files which include
|
||||
# one of the png source files (typically png.h or pngpriv.h) need to be listed
|
||||
# here:
|
||||
pngtest.o: pnglibconf.h
|
||||
|
||||
contrib/libtests/makepng.o: pnglibconf.h
|
||||
contrib/libtests/pngstest.o: pnglibconf.h
|
||||
contrib/libtests/pngunknown.o: pnglibconf.h
|
||||
contrib/libtests/pngimage.o: pnglibconf.h
|
||||
contrib/libtests/pngvalid.o: pnglibconf.h
|
||||
contrib/libtests/readpng.o: pnglibconf.h
|
||||
contrib/libtests/tarith.o: pnglibconf.h
|
||||
contrib/libtests/timepng.o: pnglibconf.h
|
||||
|
||||
contrib/tools/makesRGB.o: pnglibconf.h
|
||||
contrib/tools/pngfix.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
|
||||
@@ -178,16 +240,14 @@ SYMBOL_CFLAGS += -DPNG_PREFIX='@PNG_PREFIX@'
|
||||
endif
|
||||
|
||||
.dfn.out:
|
||||
rm -f $@ $*.c $*.tf[123]
|
||||
test -d scripts || mkdir scripts
|
||||
rm -f $@ $*.c $*.tf[12]
|
||||
test -d scripts || mkdir scripts || test -d scripts
|
||||
echo '#include "$<"' >$*.c
|
||||
$(DFNCPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES)\
|
||||
$(CPPFLAGS) $(SYMBOL_CFLAGS) $*.c > $*.tf1
|
||||
$(SED) -n -e 's|^.*PNG_DEFN_MAGIC *-\(.*\)- *PNG_DEFN_END.*$$|\1|p'\
|
||||
$*.tf1 >$*.tf2
|
||||
$(SED) -e 's| *PNG_JOIN *||g' -e 's| *$$||' $*.tf2 >$*.tf3
|
||||
rm -f $*.c $*.tf[12]
|
||||
mv $*.tf3 $@
|
||||
$(AWK) -f "${srcdir}/scripts/dfn.awk" out="$*.tf2" $*.tf1 1>&2
|
||||
rm -f $*.c $*.tf1
|
||||
mv $*.tf2 $@
|
||||
|
||||
# The .dfn file for pnglibconf.h is machine generated
|
||||
pnglibconf.dfn: scripts/pnglibconf.dfa scripts/options.awk pngconf.h pngusr.dfa $(DFA_XTRA)
|
||||
@@ -234,34 +294,76 @@ check: scripts/symbols.chk
|
||||
dist-hook:
|
||||
cd '$(top_distdir)'; rm -f $(SCRIPT_CLEANFILES)
|
||||
|
||||
# install the .../include headers as links to the new ones
|
||||
install-data-hook:
|
||||
cd $(DESTDIR)$(includedir); rm -f png.h pngconf.h pnglibconf.h
|
||||
cd $(DESTDIR)$(includedir); $(LN_S) $(PNGLIB_BASENAME)/png.h png.h
|
||||
cd $(DESTDIR)$(includedir); $(LN_S) $(PNGLIB_BASENAME)/pngconf.h \
|
||||
pngconf.h
|
||||
cd $(DESTDIR)$(includedir); $(LN_S) $(PNGLIB_BASENAME)/pnglibconf.h \
|
||||
pnglibconf.h
|
||||
cd $(DESTDIR)$(pkgconfigdir); rm -f libpng.pc
|
||||
cd $(DESTDIR)$(pkgconfigdir); $(LN_S) $(PNGLIB_BASENAME).pc libpng.pc
|
||||
# Make links between installed files with release-specific names and the generic
|
||||
# file names. If this install rule is run the generic names will be deleted and
|
||||
# recreated - this has obvious issues for systems with multiple installations.
|
||||
|
||||
# do evil things to libpng to cause libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@ to be used
|
||||
install-exec-hook:
|
||||
cd $(DESTDIR)$(bindir); rm -f libpng-config
|
||||
cd $(DESTDIR)$(bindir); $(LN_S) $(PNGLIB_BASENAME)-config libpng-config
|
||||
@set -x;\
|
||||
cd $(DESTDIR)$(libdir);\
|
||||
for ext in a la so so.@PNGLIB_MAJOR@@PNGLIB_MINOR@.@PNGLIB_RELEASE@ sl dylib dll.a; do\
|
||||
rm -f libpng.$$ext;\
|
||||
if test -f $(PNGLIB_BASENAME).$$ext; then\
|
||||
$(LN_S) $(PNGLIB_BASENAME).$$ext libpng.$$ext;\
|
||||
fi;\
|
||||
install-header-links:
|
||||
@set -ex; cd '$(DESTDIR)$(includedir)'; for f in $(HEADERS); do \
|
||||
rm -f "$$f"; $(LN_S) "$(PNGLIB_BASENAME)/$$f" "$$f"; done
|
||||
|
||||
uninstall-header-links:
|
||||
cd '$(DESTDIR)$(includedir)'; rm -f $(HEADERS)
|
||||
|
||||
install-libpng-pc:
|
||||
@set -ex; cd '$(DESTDIR)$(pkgconfigdir)'; rm -f libpng.pc; \
|
||||
$(LN_S) '$(PNGLIB_BASENAME).pc' libpng.pc
|
||||
|
||||
uninstall-libpng-pc:
|
||||
rm -f '$(DESTDIR)$(pkgconfigdir)/libpng.pc'
|
||||
|
||||
# EXT_LIST is a list of the possibly library directory extensions, this exists
|
||||
# because we can't find a good way of discovering the file extensions that are
|
||||
# actually installed on a given system, so instead we check for every extension
|
||||
# we have seen.
|
||||
|
||||
EXT_LIST = a dll.a so so.@PNGLIB_MAJOR@@PNGLIB_MINOR@.@PNGLIB_RELEASE@ la sl dylib
|
||||
|
||||
install-library-links:
|
||||
@set -x; cd '$(DESTDIR)$(libdir)';\
|
||||
for ext in $(EXT_LIST); do\
|
||||
rm -f "libpng.$$ext";\
|
||||
if test -f "$(PNGLIB_BASENAME).$$ext"; then\
|
||||
$(LN_S) "$(PNGLIB_BASENAME).$$ext" "libpng.$$ext" || exit 1;\
|
||||
fi;\
|
||||
done
|
||||
|
||||
uninstall-hook:
|
||||
cd $(DESTDIR)$(includedir); rm -f png.h pngconf.h pnglibconf.h
|
||||
rm -f $(DESTDIR)$(pkgconfigdir)/libpng.pc
|
||||
rm -f $(DESTDIR)$(bindir)/libpng-config
|
||||
rm -f $(DESTDIR)$(libdir)/libpng.a
|
||||
rm -f $(DESTDIR)$(libdir)/libpng.la
|
||||
rm -f $(DESTDIR)$(libdir)/libpng.dll.a
|
||||
uninstall-library-links:
|
||||
@set -x; cd '$(DESTDIR)$(libdir)'; for ext in $(EXT_LIST); do\
|
||||
rm -f "libpng.$$ext"; done
|
||||
|
||||
install-libpng-config:
|
||||
@set -ex; cd '$(DESTDIR)$(bindir)'; rm -f libpng-config; \
|
||||
$(LN_S) '$(PNGLIB_BASENAME)-config' libpng-config
|
||||
|
||||
uninstall-libpng-config:
|
||||
rm -f '$(DESTDIR)$(bindir)/libpng-config'
|
||||
|
||||
if DO_INSTALL_LINKS
|
||||
# If --enable-unversioned-links is specified the header and lib file links
|
||||
# will be automatically made on a 'make install':
|
||||
|
||||
install-data-hook: install-header-links
|
||||
uninstall-hook: uninstall-header-links
|
||||
install-exec-hook: install-library-links
|
||||
uninstall-hook: uninstall-library-links
|
||||
endif
|
||||
|
||||
if DO_INSTALL_LIBPNG_PC
|
||||
# Likewise, --install-pc causes libpng.pc to be constructed:
|
||||
|
||||
install-data-hook: install-libpng-pc
|
||||
uninstall-hook: uninstall-libpng-pc
|
||||
endif
|
||||
|
||||
if DO_INSTALL_LIBPNG_CONFIG
|
||||
# And --install-config:
|
||||
|
||||
install-exec-hook: install-libpng-config
|
||||
uninstall-hook: uninstall-libpng-config
|
||||
endif
|
||||
|
||||
# The following addition ensures that 'make all' always builds the test programs
|
||||
# too. It used to, but some change either in libpng or configure stopped this
|
||||
# working.
|
||||
all-am: $(check_PROGRAMS)
|
||||
|
||||
61
README
61
README
@@ -1,11 +1,11 @@
|
||||
README for libpng version 1.6.0beta33 - December 10, 2012 (shared library 16.0)
|
||||
README for libpng version 1.7.0beta42 - November 20, 2014 (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.
|
||||
|
||||
Libpng comes in several distribution formats. Get libpng-*.tar.gz,
|
||||
libpng-*.tar.xz or libpng-*.tar.bz2 if you want UNIX-style line endings
|
||||
in the text files, or lpng*.zip if you want DOS-style line endings.
|
||||
Libpng comes in several distribution formats. Get libpng-*.tar.gz or
|
||||
libpng-*.tar.xz or if you want UNIX-style line endings in the text files,
|
||||
or lpng*.7z or lpng*.zip if you want DOS-style line endings.
|
||||
|
||||
Version 0.89 was the first official release of libpng. Don't let the
|
||||
fact that it's the first release fool you. The libpng library has been in
|
||||
@@ -23,18 +23,25 @@ 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 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
|
||||
accessing/storing the info_struct data, rather than manipulating it
|
||||
directly, to avoid such problems in the future.
|
||||
|
||||
It is important to note that the APIs do not make current programs
|
||||
It is important to note that the APIs did not make current programs
|
||||
that access the info struct directly incompatible with the new
|
||||
library. However, it is strongly suggested that new programs use
|
||||
the new APIs (as shown in example.c and pngtest.c), and older programs
|
||||
be converted to the new format, to facilitate upgrades in the future.
|
||||
library, through libpng-1.2.x. In libpng-1.4.x, which was meant to
|
||||
be a transitional release, members of the png_struct and the
|
||||
info_struct can still be accessed, but the compiler will issue a
|
||||
warning about deprecated usage. Since libpng-1.5.0, direct access
|
||||
to these structs is not allowed, and the definitions of the structs
|
||||
reside in private pngstruct.h and pnginfo.h header files that are not
|
||||
accessible to applications. It is strongly suggested that new
|
||||
programs use the new APIs (as shown in example.c and pngtest.c), and
|
||||
older programs be converted to the new format, to facilitate upgrades
|
||||
in the future.
|
||||
****
|
||||
|
||||
Additions since 0.90 include the ability to compile libpng as a
|
||||
@@ -77,17 +84,21 @@ compression library that is useful for more things than just PNG files.
|
||||
You can use zlib as a drop-in replacement for fread() and fwrite() if
|
||||
you are so inclined.
|
||||
|
||||
zlib should be available at the same place that libpng is, or at.
|
||||
ftp://ftp.info-zip.org/pub/infozip/zlib
|
||||
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/
|
||||
|
||||
This code is currently being archived at libpng.sf.net in the
|
||||
[DOWNLOAD] area, and on CompuServe, Lib 20 (PNG SUPPORT)
|
||||
at GO GRAPHSUP. If you can't find it in any of those places,
|
||||
e-mail me, and I'll help you find it.
|
||||
[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.
|
||||
|
||||
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
|
||||
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).
|
||||
|
||||
If you have any code changes, requests, problems, etc., please e-mail
|
||||
them to me. Also, I'd appreciate any make files or project files,
|
||||
@@ -123,7 +134,7 @@ and ...". If in doubt, send questions to me. I'll bounce them
|
||||
to others, if necessary.
|
||||
|
||||
Please do not send suggestions on how to change PNG. We have
|
||||
been discussing PNG for sixteen years now, and it is official and
|
||||
been discussing PNG for nineteen years now, and it is official and
|
||||
finished. If you have suggestions for libpng, however, I'll
|
||||
gladly listen. Even if your suggestion is not used immediately,
|
||||
it may be used later.
|
||||
@@ -167,23 +178,25 @@ Files in this distribution:
|
||||
pngwrite.c => High-level write functions
|
||||
pngwtran.c => Write data transformations
|
||||
pngwutil.c => Write utility functions
|
||||
arm => Contains optimized code for the ARM platform
|
||||
contrib => Contributions
|
||||
examples => Example programs
|
||||
gregbook => source code for PNG reading and writing, from
|
||||
Greg Roelofs' "PNG: The Definitive Guide",
|
||||
O'Reilly, 1999
|
||||
msvctest => Builds and runs pngtest using a MSVC workspace
|
||||
pngminus => Simple pnm2png and png2pnm programs
|
||||
pngsuite => Test images
|
||||
visupng => Contains a MSVC workspace for VisualPng
|
||||
libtests => Test programs
|
||||
pngminim => Minimal decoder, encoder, and progressive decoder
|
||||
programs demonstrating use of pngusr.dfa
|
||||
pngminus => Simple pnm2png and png2pnm programs
|
||||
pngsuite => Test images
|
||||
tools => Various tools
|
||||
visupng => Contains a MSVC workspace for VisualPng
|
||||
projects => Contains project files and workspaces for
|
||||
building a DLL
|
||||
cbuilder5 => Contains a Borland workspace for building
|
||||
libpng and zlib
|
||||
visualc6 => Contains a Microsoft Visual C++ (MSVC)
|
||||
workspace for building libpng and zlib
|
||||
owatcom => Contains a WATCOM project for building libpng
|
||||
visualc71 => Contains a Microsoft Visual C++ (MSVC)
|
||||
workspace for building libpng and zlib
|
||||
xcode => Contains an Apple xcode
|
||||
vstudio => Contains a Microsoft Visual C++ (MSVC)
|
||||
workspace for building libpng and zlib
|
||||
scripts => Directory containing scripts for building libpng:
|
||||
(see scripts/README.txt for the list of scripts)
|
||||
|
||||
2
TODO
2
TODO
@@ -6,10 +6,12 @@ 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.
|
||||
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
|
||||
|
||||
133
arm/arm_init.c
Normal file
133
arm/arm_init.c
Normal file
@@ -0,0 +1,133 @@
|
||||
|
||||
/* arm_init.c - NEON optimised filter functions
|
||||
*
|
||||
* Copyright (c) 2014 Glenn Randers-Pehrson
|
||||
* Written by Mans Rullgard, 2011.
|
||||
* Last changed in libpng 1.6.10 [March 6, 2014]
|
||||
*
|
||||
* This code is released under the libpng license.
|
||||
* For conditions of distribution and use, see the disclaimer
|
||||
* and license in png.h
|
||||
*/
|
||||
/* Below, after checking __linux__, various non-C90 POSIX 1003.1 functions are
|
||||
* called.
|
||||
*/
|
||||
#define _POSIX_SOURCE 1
|
||||
|
||||
#include "../pngpriv.h"
|
||||
|
||||
#ifdef PNG_READ_SUPPORTED
|
||||
#if PNG_ARM_NEON_OPT > 0
|
||||
#ifdef PNG_ARM_NEON_CHECK_SUPPORTED /* Do run-time checks */
|
||||
/* WARNING: it is strongly recommended that you do not build libpng with
|
||||
* run-time checks for CPU features if at all possible. In the case of the ARM
|
||||
* NEON instructions there is no processor-specific way of detecting the
|
||||
* presence of the required support, therefore run-time detection is extremely
|
||||
* OS specific.
|
||||
*
|
||||
* You may set the macro PNG_ARM_NEON_FILE to the file name of file containing
|
||||
* a fragment of C source code which defines the png_have_neon function. There
|
||||
* are a number of implementations in contrib/arm-neon, but the only one that
|
||||
* has partial support is contrib/arm-neon/linux.c - a generic Linux
|
||||
* implementation which reads /proc/cpufino.
|
||||
*/
|
||||
#ifndef PNG_ARM_NEON_FILE
|
||||
# ifdef __linux__
|
||||
# define PNG_ARM_NEON_FILE "contrib/arm-neon/linux.c"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef PNG_ARM_NEON_FILE
|
||||
|
||||
#include <signal.h> /* for sig_atomic_t */
|
||||
static int png_have_neon(png_structp png_ptr);
|
||||
#include PNG_ARM_NEON_FILE
|
||||
|
||||
#else /* PNG_ARM_NEON_FILE */
|
||||
# error "PNG_ARM_NEON_FILE undefined: no support for run-time ARM NEON checks"
|
||||
#endif /* PNG_ARM_NEON_FILE */
|
||||
#endif /* PNG_ARM_NEON_CHECK_SUPPORTED */
|
||||
|
||||
#ifndef PNG_ALIGNED_MEMORY_SUPPORTED
|
||||
# error "ALIGNED_MEMORY is required; set: -DPNG_ALIGNED_MEMORY_SUPPORTED"
|
||||
#endif
|
||||
|
||||
void
|
||||
png_init_filter_functions_neon(png_structp pp, unsigned int bpp)
|
||||
{
|
||||
/* The switch statement is compiled in for ARM_NEON_API, the call to
|
||||
* png_have_neon is compiled in for ARM_NEON_CHECK. If both are defined
|
||||
* the check is only performed if the API has not set the NEON option on
|
||||
* or off explicitly. In this case the check controls what happens.
|
||||
*
|
||||
* If the CHECK is not compiled in and the option is UNSET the behavior prior
|
||||
* to 1.6.7 was to use the NEON code - this was a bug caused by having the
|
||||
* wrong order of the 'ON' and 'default' cases. UNSET now defaults to OFF,
|
||||
* as documented in png.h
|
||||
*/
|
||||
#ifdef PNG_ARM_NEON_API_SUPPORTED
|
||||
switch ((pp->options >> PNG_ARM_NEON) & 3)
|
||||
{
|
||||
case PNG_OPTION_UNSET:
|
||||
/* Allow the run-time check to execute if it has been enabled -
|
||||
* thus both API and CHECK can be turned on. If it isn't supported
|
||||
* this case will fall through to the 'default' below, which just
|
||||
* returns.
|
||||
*/
|
||||
#endif /* PNG_ARM_NEON_API_SUPPORTED */
|
||||
#ifdef PNG_ARM_NEON_CHECK_SUPPORTED
|
||||
{
|
||||
static volatile sig_atomic_t no_neon = -1; /* not checked */
|
||||
|
||||
if (no_neon < 0)
|
||||
no_neon = !png_have_neon(pp);
|
||||
|
||||
if (no_neon)
|
||||
return;
|
||||
}
|
||||
#ifdef PNG_ARM_NEON_API_SUPPORTED
|
||||
break;
|
||||
#endif
|
||||
#endif /* PNG_ARM_NEON_CHECK_SUPPORTED */
|
||||
|
||||
#ifdef PNG_ARM_NEON_API_SUPPORTED
|
||||
default: /* OFF or INVALID */
|
||||
return;
|
||||
|
||||
case PNG_OPTION_ON:
|
||||
/* Option turned on */
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* IMPORTANT: any new external functions used here must be declared using
|
||||
* PNG_INTERNAL_FUNCTION in ../pngpriv.h. This is required so that the
|
||||
* 'prefix' option to configure works:
|
||||
*
|
||||
* ./configure --with-libpng-prefix=foobar_
|
||||
*
|
||||
* Verify you have got this right by running the above command, doing a build
|
||||
* and examining pngprefix.h; it must contain a #define for every external
|
||||
* function you add. (Notice that this happens automatically for the
|
||||
* initialization function.)
|
||||
*/
|
||||
pp->read_filter[PNG_FILTER_VALUE_UP-1] = png_read_filter_row_up_neon;
|
||||
|
||||
if (bpp == 3)
|
||||
{
|
||||
pp->read_filter[PNG_FILTER_VALUE_SUB-1] = png_read_filter_row_sub3_neon;
|
||||
pp->read_filter[PNG_FILTER_VALUE_AVG-1] = png_read_filter_row_avg3_neon;
|
||||
pp->read_filter[PNG_FILTER_VALUE_PAETH-1] =
|
||||
png_read_filter_row_paeth3_neon;
|
||||
}
|
||||
|
||||
else if (bpp == 4)
|
||||
{
|
||||
pp->read_filter[PNG_FILTER_VALUE_SUB-1] = png_read_filter_row_sub4_neon;
|
||||
pp->read_filter[PNG_FILTER_VALUE_AVG-1] = png_read_filter_row_avg4_neon;
|
||||
pp->read_filter[PNG_FILTER_VALUE_PAETH-1] =
|
||||
png_read_filter_row_paeth4_neon;
|
||||
}
|
||||
}
|
||||
#endif /* PNG_ARM_NEON_OPT > 0 */
|
||||
#endif /* PNG_READ_SUPPORTED */
|
||||
@@ -1,18 +1,36 @@
|
||||
|
||||
/* filter_neon.S - NEON optimised filter functions
|
||||
*
|
||||
* Copyright (c) 2011 Glenn Randers-Pehrson
|
||||
* Copyright (c) 2013 Glenn Randers-Pehrson
|
||||
* Written by Mans Rullgard, 2011.
|
||||
* Last changed in libpng 1.6.8 [December 19, 2013]
|
||||
*
|
||||
* This code is released under the libpng license.
|
||||
* For conditions of distribution and use, see the disclaimer
|
||||
* and license in png.h
|
||||
*/
|
||||
|
||||
/* This is required to get the symbol renames, which are #defines, and also
|
||||
* includes the definition (or not) of PNG_ARM_NEON_OPT and
|
||||
* PNG_ARM_NEON_IMPLEMENTATION.
|
||||
*/
|
||||
#define PNG_VERSION_INFO_ONLY
|
||||
#include "../pngpriv.h"
|
||||
|
||||
#if defined(__linux__) && defined(__ELF__)
|
||||
.section .note.GNU-stack,"",%progbits /* mark stack as non-executable */
|
||||
#endif
|
||||
|
||||
/* Assembler NEON support - only works for 32-bit ARM (i.e. it does not work for
|
||||
* ARM64). The code in arm/filter_neon_intrinsics.c supports ARM64, however it
|
||||
* only works if -mfpu=neon is specified on the GCC command line. See pngpriv.h
|
||||
* for the logic which sets PNG_USE_ARM_NEON_ASM:
|
||||
*/
|
||||
#if PNG_ARM_NEON_IMPLEMENTATION == 2 /* hand-coded assembler */
|
||||
|
||||
#ifdef PNG_READ_SUPPORTED
|
||||
#if PNG_ARM_NEON_OPT > 0
|
||||
|
||||
#ifdef __ELF__
|
||||
# define ELF
|
||||
#else
|
||||
@@ -223,3 +241,6 @@ func png_read_filter_row_paeth3_neon, export=1
|
||||
|
||||
pop {r4,pc}
|
||||
endfunc
|
||||
#endif /* PNG_ARM_NEON_OPT > 0 */
|
||||
#endif /* PNG_READ_SUPPORTED */
|
||||
#endif /* PNG_ARM_NEON_IMPLEMENTATION == 2 (assembler) */
|
||||
|
||||
372
arm/filter_neon_intrinsics.c
Normal file
372
arm/filter_neon_intrinsics.c
Normal file
@@ -0,0 +1,372 @@
|
||||
|
||||
/* filter_neon_intrinsics.c - NEON optimised filter functions
|
||||
*
|
||||
* Copyright (c) 2013 Glenn Randers-Pehrson
|
||||
* Written by James Yu <james.yu at linaro.org>, October 2013.
|
||||
* Based on filter_neon.S, written by Mans Rullgard, 2011.
|
||||
*
|
||||
* Last changed in libpng 1.6.8 [December 19, 2013]
|
||||
*
|
||||
* This code is released under the libpng license.
|
||||
* For conditions of distribution and use, see the disclaimer
|
||||
* and license in png.h
|
||||
*/
|
||||
|
||||
#include "../pngpriv.h"
|
||||
|
||||
/* This code requires -mfpu=neon on the command line: */
|
||||
#if PNG_ARM_NEON_IMPLEMENTATION == 1 /* intrinsics code from pngpriv.h */
|
||||
|
||||
#include <arm_neon.h>
|
||||
|
||||
/* libpng row pointers are not necessarily aligned to any particular boundary,
|
||||
* however this code will only work with appropriate alignment. arm/arm_init.c
|
||||
* checks for this (and will not compile unless it is done). This code uses
|
||||
* variants of png_aligncast to avoid compiler warnings.
|
||||
*/
|
||||
#define png_ptr(type,pointer) png_aligncast(type *,pointer)
|
||||
#define png_ptrc(type,pointer) png_aligncastconst(const type *,pointer)
|
||||
|
||||
/* The following relies on a variable 'temp_pointer' being declared with type
|
||||
* 'type'. This is written this way just to hide the GCC strict aliasing
|
||||
* warning; note that the code is safe because there never is an alias between
|
||||
* the input and output pointers.
|
||||
*/
|
||||
#define png_ldr(type,pointer)\
|
||||
(temp_pointer = png_ptr(type,pointer), *temp_pointer)
|
||||
|
||||
#ifdef PNG_READ_SUPPORTED
|
||||
#if PNG_ARM_NEON_OPT > 0
|
||||
|
||||
void
|
||||
png_read_filter_row_up_neon(png_row_infop row_info, png_bytep row,
|
||||
png_const_bytep prev_row)
|
||||
{
|
||||
png_bytep rp = row;
|
||||
png_bytep rp_stop = row + row_info->rowbytes;
|
||||
png_const_bytep pp = prev_row;
|
||||
|
||||
for (; rp < rp_stop; rp += 16, pp += 16)
|
||||
{
|
||||
uint8x16_t qrp, qpp;
|
||||
|
||||
qrp = vld1q_u8(rp);
|
||||
qpp = vld1q_u8(pp);
|
||||
qrp = vaddq_u8(qrp, qpp);
|
||||
vst1q_u8(rp, qrp);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
png_read_filter_row_sub3_neon(png_row_infop row_info, png_bytep row,
|
||||
png_const_bytep prev_row)
|
||||
{
|
||||
png_bytep rp = row;
|
||||
png_bytep rp_stop = row + row_info->rowbytes;
|
||||
|
||||
uint8x16_t vtmp = vld1q_u8(rp);
|
||||
uint8x8x2_t *vrpt = png_ptr(uint8x8x2_t, &vtmp);
|
||||
uint8x8x2_t vrp = *vrpt;
|
||||
|
||||
uint8x8x4_t vdest;
|
||||
vdest.val[3] = vdup_n_u8(0);
|
||||
|
||||
for (; rp < rp_stop;)
|
||||
{
|
||||
uint8x8_t vtmp1, vtmp2;
|
||||
uint32x2_t *temp_pointer;
|
||||
|
||||
vtmp1 = vext_u8(vrp.val[0], vrp.val[1], 3);
|
||||
vdest.val[0] = vadd_u8(vdest.val[3], vrp.val[0]);
|
||||
vtmp2 = vext_u8(vrp.val[0], vrp.val[1], 6);
|
||||
vdest.val[1] = vadd_u8(vdest.val[0], vtmp1);
|
||||
|
||||
vtmp1 = vext_u8(vrp.val[1], vrp.val[1], 1);
|
||||
vdest.val[2] = vadd_u8(vdest.val[1], vtmp2);
|
||||
vdest.val[3] = vadd_u8(vdest.val[2], vtmp1);
|
||||
|
||||
vtmp = vld1q_u8(rp + 12);
|
||||
vrpt = png_ptr(uint8x8x2_t, &vtmp);
|
||||
vrp = *vrpt;
|
||||
|
||||
vst1_lane_u32(png_ptr(uint32_t,rp), png_ldr(uint32x2_t,&vdest.val[0]), 0);
|
||||
rp += 3;
|
||||
vst1_lane_u32(png_ptr(uint32_t,rp), png_ldr(uint32x2_t,&vdest.val[1]), 0);
|
||||
rp += 3;
|
||||
vst1_lane_u32(png_ptr(uint32_t,rp), png_ldr(uint32x2_t,&vdest.val[2]), 0);
|
||||
rp += 3;
|
||||
vst1_lane_u32(png_ptr(uint32_t,rp), png_ldr(uint32x2_t,&vdest.val[3]), 0);
|
||||
rp += 3;
|
||||
}
|
||||
|
||||
PNG_UNUSED(prev_row)
|
||||
}
|
||||
|
||||
void
|
||||
png_read_filter_row_sub4_neon(png_row_infop row_info, png_bytep row,
|
||||
png_const_bytep prev_row)
|
||||
{
|
||||
png_bytep rp = row;
|
||||
png_bytep rp_stop = row + row_info->rowbytes;
|
||||
|
||||
uint8x8x4_t vdest;
|
||||
vdest.val[3] = vdup_n_u8(0);
|
||||
|
||||
for (; rp < rp_stop; rp += 16)
|
||||
{
|
||||
uint32x2x4_t vtmp = vld4_u32(png_ptr(uint32_t,rp));
|
||||
uint8x8x4_t *vrpt = png_ptr(uint8x8x4_t,&vtmp);
|
||||
uint8x8x4_t vrp = *vrpt;
|
||||
uint32x2x4_t *temp_pointer;
|
||||
|
||||
vdest.val[0] = vadd_u8(vdest.val[3], vrp.val[0]);
|
||||
vdest.val[1] = vadd_u8(vdest.val[0], vrp.val[1]);
|
||||
vdest.val[2] = vadd_u8(vdest.val[1], vrp.val[2]);
|
||||
vdest.val[3] = vadd_u8(vdest.val[2], vrp.val[3]);
|
||||
vst4_lane_u32(png_ptr(uint32_t,rp), png_ldr(uint32x2x4_t,&vdest), 0);
|
||||
}
|
||||
|
||||
PNG_UNUSED(prev_row)
|
||||
}
|
||||
|
||||
void
|
||||
png_read_filter_row_avg3_neon(png_row_infop row_info, png_bytep row,
|
||||
png_const_bytep prev_row)
|
||||
{
|
||||
png_bytep rp = row;
|
||||
png_const_bytep pp = prev_row;
|
||||
png_bytep rp_stop = row + row_info->rowbytes;
|
||||
|
||||
uint8x16_t vtmp;
|
||||
uint8x8x2_t *vrpt;
|
||||
uint8x8x2_t vrp;
|
||||
uint8x8x4_t vdest;
|
||||
vdest.val[3] = vdup_n_u8(0);
|
||||
|
||||
vtmp = vld1q_u8(rp);
|
||||
vrpt = png_ptr(uint8x8x2_t,&vtmp);
|
||||
vrp = *vrpt;
|
||||
|
||||
for (; rp < rp_stop; pp += 12)
|
||||
{
|
||||
uint8x8_t vtmp1, vtmp2, vtmp3;
|
||||
|
||||
uint8x8x2_t *vppt;
|
||||
uint8x8x2_t vpp;
|
||||
|
||||
uint32x2_t *temp_pointer;
|
||||
|
||||
vtmp = vld1q_u8(pp);
|
||||
vppt = png_ptr(uint8x8x2_t,&vtmp);
|
||||
vpp = *vppt;
|
||||
|
||||
vtmp1 = vext_u8(vrp.val[0], vrp.val[1], 3);
|
||||
vdest.val[0] = vhadd_u8(vdest.val[3], vpp.val[0]);
|
||||
vdest.val[0] = vadd_u8(vdest.val[0], vrp.val[0]);
|
||||
|
||||
vtmp2 = vext_u8(vpp.val[0], vpp.val[1], 3);
|
||||
vtmp3 = vext_u8(vrp.val[0], vrp.val[1], 6);
|
||||
vdest.val[1] = vhadd_u8(vdest.val[0], vtmp2);
|
||||
vdest.val[1] = vadd_u8(vdest.val[1], vtmp1);
|
||||
|
||||
vtmp2 = vext_u8(vpp.val[0], vpp.val[1], 6);
|
||||
vtmp1 = vext_u8(vrp.val[1], vrp.val[1], 1);
|
||||
|
||||
vtmp = vld1q_u8(rp + 12);
|
||||
vrpt = png_ptr(uint8x8x2_t,&vtmp);
|
||||
vrp = *vrpt;
|
||||
|
||||
vdest.val[2] = vhadd_u8(vdest.val[1], vtmp2);
|
||||
vdest.val[2] = vadd_u8(vdest.val[2], vtmp3);
|
||||
|
||||
vtmp2 = vext_u8(vpp.val[1], vpp.val[1], 1);
|
||||
|
||||
vdest.val[3] = vhadd_u8(vdest.val[2], vtmp2);
|
||||
vdest.val[3] = vadd_u8(vdest.val[3], vtmp1);
|
||||
|
||||
vst1_lane_u32(png_ptr(uint32_t,rp), png_ldr(uint32x2_t,&vdest.val[0]), 0);
|
||||
rp += 3;
|
||||
vst1_lane_u32(png_ptr(uint32_t,rp), png_ldr(uint32x2_t,&vdest.val[1]), 0);
|
||||
rp += 3;
|
||||
vst1_lane_u32(png_ptr(uint32_t,rp), png_ldr(uint32x2_t,&vdest.val[2]), 0);
|
||||
rp += 3;
|
||||
vst1_lane_u32(png_ptr(uint32_t,rp), png_ldr(uint32x2_t,&vdest.val[3]), 0);
|
||||
rp += 3;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
png_read_filter_row_avg4_neon(png_row_infop row_info, png_bytep row,
|
||||
png_const_bytep prev_row)
|
||||
{
|
||||
png_bytep rp = row;
|
||||
png_bytep rp_stop = row + row_info->rowbytes;
|
||||
png_const_bytep pp = prev_row;
|
||||
|
||||
uint8x8x4_t vdest;
|
||||
vdest.val[3] = vdup_n_u8(0);
|
||||
|
||||
for (; rp < rp_stop; rp += 16, pp += 16)
|
||||
{
|
||||
uint32x2x4_t vtmp;
|
||||
uint8x8x4_t *vrpt, *vppt;
|
||||
uint8x8x4_t vrp, vpp;
|
||||
uint32x2x4_t *temp_pointer;
|
||||
|
||||
vtmp = vld4_u32(png_ptr(uint32_t,rp));
|
||||
vrpt = png_ptr(uint8x8x4_t,&vtmp);
|
||||
vrp = *vrpt;
|
||||
vtmp = vld4_u32(png_ptrc(uint32_t,pp));
|
||||
vppt = png_ptr(uint8x8x4_t,&vtmp);
|
||||
vpp = *vppt;
|
||||
|
||||
vdest.val[0] = vhadd_u8(vdest.val[3], vpp.val[0]);
|
||||
vdest.val[0] = vadd_u8(vdest.val[0], vrp.val[0]);
|
||||
vdest.val[1] = vhadd_u8(vdest.val[0], vpp.val[1]);
|
||||
vdest.val[1] = vadd_u8(vdest.val[1], vrp.val[1]);
|
||||
vdest.val[2] = vhadd_u8(vdest.val[1], vpp.val[2]);
|
||||
vdest.val[2] = vadd_u8(vdest.val[2], vrp.val[2]);
|
||||
vdest.val[3] = vhadd_u8(vdest.val[2], vpp.val[3]);
|
||||
vdest.val[3] = vadd_u8(vdest.val[3], vrp.val[3]);
|
||||
|
||||
vst4_lane_u32(png_ptr(uint32_t,rp), png_ldr(uint32x2x4_t,&vdest), 0);
|
||||
}
|
||||
}
|
||||
|
||||
static uint8x8_t
|
||||
paeth(uint8x8_t a, uint8x8_t b, uint8x8_t c)
|
||||
{
|
||||
uint8x8_t d, e;
|
||||
uint16x8_t p1, pa, pb, pc;
|
||||
|
||||
p1 = vaddl_u8(a, b); /* a + b */
|
||||
pc = vaddl_u8(c, c); /* c * 2 */
|
||||
pa = vabdl_u8(b, c); /* pa */
|
||||
pb = vabdl_u8(a, c); /* pb */
|
||||
pc = vabdq_u16(p1, pc); /* pc */
|
||||
|
||||
p1 = vcleq_u16(pa, pb); /* pa <= pb */
|
||||
pa = vcleq_u16(pa, pc); /* pa <= pc */
|
||||
pb = vcleq_u16(pb, pc); /* pb <= pc */
|
||||
|
||||
p1 = vandq_u16(p1, pa); /* pa <= pb && pa <= pc */
|
||||
|
||||
d = vmovn_u16(pb);
|
||||
e = vmovn_u16(p1);
|
||||
|
||||
d = vbsl_u8(d, b, c);
|
||||
e = vbsl_u8(e, a, d);
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
void
|
||||
png_read_filter_row_paeth3_neon(png_row_infop row_info, png_bytep row,
|
||||
png_const_bytep prev_row)
|
||||
{
|
||||
png_bytep rp = row;
|
||||
png_const_bytep pp = prev_row;
|
||||
png_bytep rp_stop = row + row_info->rowbytes;
|
||||
|
||||
uint8x16_t vtmp;
|
||||
uint8x8x2_t *vrpt;
|
||||
uint8x8x2_t vrp;
|
||||
uint8x8_t vlast = vdup_n_u8(0);
|
||||
uint8x8x4_t vdest;
|
||||
vdest.val[3] = vdup_n_u8(0);
|
||||
|
||||
vtmp = vld1q_u8(rp);
|
||||
vrpt = png_ptr(uint8x8x2_t,&vtmp);
|
||||
vrp = *vrpt;
|
||||
|
||||
for (; rp < rp_stop; pp += 12)
|
||||
{
|
||||
uint8x8x2_t *vppt;
|
||||
uint8x8x2_t vpp;
|
||||
uint8x8_t vtmp1, vtmp2, vtmp3;
|
||||
uint32x2_t *temp_pointer;
|
||||
|
||||
vtmp = vld1q_u8(pp);
|
||||
vppt = png_ptr(uint8x8x2_t,&vtmp);
|
||||
vpp = *vppt;
|
||||
|
||||
vdest.val[0] = paeth(vdest.val[3], vpp.val[0], vlast);
|
||||
vdest.val[0] = vadd_u8(vdest.val[0], vrp.val[0]);
|
||||
|
||||
vtmp1 = vext_u8(vrp.val[0], vrp.val[1], 3);
|
||||
vtmp2 = vext_u8(vpp.val[0], vpp.val[1], 3);
|
||||
vdest.val[1] = paeth(vdest.val[0], vtmp2, vpp.val[0]);
|
||||
vdest.val[1] = vadd_u8(vdest.val[1], vtmp1);
|
||||
|
||||
vtmp1 = vext_u8(vrp.val[0], vrp.val[1], 6);
|
||||
vtmp3 = vext_u8(vpp.val[0], vpp.val[1], 6);
|
||||
vdest.val[2] = paeth(vdest.val[1], vtmp3, vtmp2);
|
||||
vdest.val[2] = vadd_u8(vdest.val[2], vtmp1);
|
||||
|
||||
vtmp1 = vext_u8(vrp.val[1], vrp.val[1], 1);
|
||||
vtmp2 = vext_u8(vpp.val[1], vpp.val[1], 1);
|
||||
|
||||
vtmp = vld1q_u8(rp + 12);
|
||||
vrpt = png_ptr(uint8x8x2_t,&vtmp);
|
||||
vrp = *vrpt;
|
||||
|
||||
vdest.val[3] = paeth(vdest.val[2], vtmp2, vtmp3);
|
||||
vdest.val[3] = vadd_u8(vdest.val[3], vtmp1);
|
||||
|
||||
vlast = vtmp2;
|
||||
|
||||
vst1_lane_u32(png_ptr(uint32_t,rp), png_ldr(uint32x2_t,&vdest.val[0]), 0);
|
||||
rp += 3;
|
||||
vst1_lane_u32(png_ptr(uint32_t,rp), png_ldr(uint32x2_t,&vdest.val[1]), 0);
|
||||
rp += 3;
|
||||
vst1_lane_u32(png_ptr(uint32_t,rp), png_ldr(uint32x2_t,&vdest.val[2]), 0);
|
||||
rp += 3;
|
||||
vst1_lane_u32(png_ptr(uint32_t,rp), png_ldr(uint32x2_t,&vdest.val[3]), 0);
|
||||
rp += 3;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
png_read_filter_row_paeth4_neon(png_row_infop row_info, png_bytep row,
|
||||
png_const_bytep prev_row)
|
||||
{
|
||||
png_bytep rp = row;
|
||||
png_bytep rp_stop = row + row_info->rowbytes;
|
||||
png_const_bytep pp = prev_row;
|
||||
|
||||
uint8x8_t vlast = vdup_n_u8(0);
|
||||
uint8x8x4_t vdest;
|
||||
vdest.val[3] = vdup_n_u8(0);
|
||||
|
||||
for (; rp < rp_stop; rp += 16, pp += 16)
|
||||
{
|
||||
uint32x2x4_t vtmp;
|
||||
uint8x8x4_t *vrpt, *vppt;
|
||||
uint8x8x4_t vrp, vpp;
|
||||
uint32x2x4_t *temp_pointer;
|
||||
|
||||
vtmp = vld4_u32(png_ptr(uint32_t,rp));
|
||||
vrpt = png_ptr(uint8x8x4_t,&vtmp);
|
||||
vrp = *vrpt;
|
||||
vtmp = vld4_u32(png_ptrc(uint32_t,pp));
|
||||
vppt = png_ptr(uint8x8x4_t,&vtmp);
|
||||
vpp = *vppt;
|
||||
|
||||
vdest.val[0] = paeth(vdest.val[3], vpp.val[0], vlast);
|
||||
vdest.val[0] = vadd_u8(vdest.val[0], vrp.val[0]);
|
||||
vdest.val[1] = paeth(vdest.val[0], vpp.val[1], vpp.val[0]);
|
||||
vdest.val[1] = vadd_u8(vdest.val[1], vrp.val[1]);
|
||||
vdest.val[2] = paeth(vdest.val[1], vpp.val[2], vpp.val[1]);
|
||||
vdest.val[2] = vadd_u8(vdest.val[2], vrp.val[2]);
|
||||
vdest.val[3] = paeth(vdest.val[2], vpp.val[3], vpp.val[2]);
|
||||
vdest.val[3] = vadd_u8(vdest.val[3], vrp.val[3]);
|
||||
|
||||
vlast = vpp.val[3];
|
||||
|
||||
vst4_lane_u32(png_ptr(uint32_t,rp), png_ldr(uint32x2x4_t,&vdest), 0);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* PNG_ARM_NEON_OPT > 0 */
|
||||
#endif /* PNG_READ_SUPPORTED */
|
||||
#endif /* PNG_ARM_NEON_IMPLEMENTATION == 1 (intrinsics) */
|
||||
15
autogen.sh
15
autogen.sh
@@ -9,15 +9,15 @@
|
||||
#
|
||||
# For regular ("tarball") distributions all the files should exist. We do not
|
||||
# want them to be updated *under any circumstances*. It should never be
|
||||
# necessary to rune autogen.sh because ./configure --enable-maintainer-mode says
|
||||
# what to do if Makeile.am or configure.ac are changed.
|
||||
# necessary to run autogen.sh because ./configure --enable-maintainer-mode says
|
||||
# what to do if Makefile.am or configure.ac are changed.
|
||||
#
|
||||
# It is *probably* OK to update the files on a GIT checkout, because they have
|
||||
# come from the local tools, but leave that to the user who is assumed to know
|
||||
# whether it is ok or required.
|
||||
#
|
||||
# This script is intended to work without arguments, there are, however, hidden
|
||||
# arguments for (a) use while testing the script and (b) to fix up systems that
|
||||
# arguments (a) for use while testing the script and (b) to fix up systems that
|
||||
# have been broken. If (b) is required the script prompts for the correct
|
||||
# options. For this reason the options are *NOT* documented in the help; this
|
||||
# is deliberate; UTSL.
|
||||
@@ -74,7 +74,11 @@ done
|
||||
#
|
||||
# The autotools generated files:
|
||||
libpng_autotools_files="Makefile.in aclocal.m4 config.guess config.h.in\
|
||||
config.sub configure depcomp install-sh ltmain.sh missing"
|
||||
config.sub configure depcomp install-sh ltmain.sh missing test-driver"
|
||||
#
|
||||
# Files generated by versions of configue >2.68 or automake >1.13 (i.e. later
|
||||
# versions than those required by configure.ac):
|
||||
libpng_autotools_extra="compile"
|
||||
#
|
||||
# These are separate because 'maintainer-clean' does not remove them.
|
||||
libpng_libtool_files="scripts/libtool.m4 scripts/ltoptions.m4\
|
||||
@@ -94,6 +98,7 @@ libpng_configure_dirs=".deps"
|
||||
# of Makefile. These functions do the two bits of cleaning.
|
||||
clean_autotools(){
|
||||
rm -rf $libpng_autotools_files $libpng_libtool_files $libpng_autotools_dirs
|
||||
rm -rf $libpng_autotools_extra
|
||||
}
|
||||
|
||||
clean_configure(){
|
||||
@@ -198,7 +203,7 @@ case "$mode" in
|
||||
echo " You can run autoreconf yourself if you don't like maintainer"
|
||||
echo " mode and you can also just run autoreconf -f -i to initialize"
|
||||
echo " everything in the first place; this script is only for"
|
||||
echo " compatiblity with prior releases."
|
||||
echo " compatibility with prior releases."
|
||||
exit 1
|
||||
else
|
||||
exec >&2
|
||||
|
||||
303
configure.ac
303
configure.ac
@@ -18,7 +18,7 @@ AC_PREREQ([2.68])
|
||||
|
||||
dnl Version number stuff here:
|
||||
|
||||
AC_INIT([libpng],[1.6.0beta33],[png-mng-implement@lists.sourceforge.net])
|
||||
AC_INIT([libpng],[1.7.0beta42],[png-mng-implement@lists.sourceforge.net])
|
||||
AC_CONFIG_MACRO_DIR([scripts])
|
||||
|
||||
# libpng does not follow GNU file name conventions (hence 'foreign')
|
||||
@@ -26,9 +26,11 @@ AC_CONFIG_MACRO_DIR([scripts])
|
||||
# silent-rules requires automake 1.11 or later
|
||||
# dist-xz requires automake 1.11 or later
|
||||
# 1.12.2 fixes a security issue in 1.11.2 and 1.12.1
|
||||
AM_INIT_AUTOMAKE([1.12.2 foreign dist-xz dist-bzip2 color-tests silent-rules])
|
||||
# was:
|
||||
# AM_INIT_AUTOMAKE
|
||||
# 1.13 is required for parallel tests
|
||||
AM_INIT_AUTOMAKE([1.13 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
|
||||
# time stamps of the autotools generated files being correct
|
||||
AM_MAINTAINER_MODE
|
||||
|
||||
dnl configure.ac and Makefile.am expect automake 1.11.2 or a compatible later
|
||||
@@ -37,9 +39,9 @@ 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.6.0beta33
|
||||
PNGLIB_VERSION=1.7.0beta42
|
||||
PNGLIB_MAJOR=1
|
||||
PNGLIB_MINOR=6
|
||||
PNGLIB_MINOR=7
|
||||
PNGLIB_RELEASE=0
|
||||
|
||||
dnl End of version number stuff
|
||||
@@ -53,8 +55,7 @@ AC_PROG_CC
|
||||
AM_PROG_AS
|
||||
LT_PATH_LD
|
||||
AC_PROG_CPP
|
||||
AC_CHECK_TOOL(SED, sed, :)
|
||||
AC_CHECK_TOOL(AWK, awk, :)
|
||||
AC_PROG_AWK
|
||||
AC_PROG_INSTALL
|
||||
AC_PROG_LN_S
|
||||
AC_PROG_MAKE_SET
|
||||
@@ -64,30 +65,23 @@ dnl compatible later version may be used
|
||||
LT_INIT([win32-dll])
|
||||
LT_PREREQ([2.4.2])
|
||||
|
||||
# On Solaris 10 and 12 CPP gets set to cc -E, however this still
|
||||
# does some input parsing. We need strict ANSI-C style tokenization,
|
||||
# check this:
|
||||
AC_REQUIRE_CPP
|
||||
AC_MSG_CHECKING([for a C preprocessor that does not parse its input])
|
||||
AC_PREPROC_IFELSE([AC_LANG_SOURCE([[1.1.1 16BIT]])],
|
||||
[DFNCPP="$CPP"],
|
||||
[ DFNCPP=""
|
||||
sav_CPP="$CPP"
|
||||
for CPP in "${CC-cc} -E" "${CC-cc} -E -traditional-cpp" "/lib/cpp" "cpp"
|
||||
do
|
||||
AC_PREPROC_IFELSE([AC_LANG_SOURCE([[1.1.1 16BIT]])],
|
||||
[DFNCPP="$CPP"]
|
||||
[break],,)
|
||||
done
|
||||
CPP="$sav_CPP"
|
||||
])
|
||||
if test -n "$DFNCPP"; then
|
||||
AC_MSG_RESULT([$DFNCPP])
|
||||
AC_SUBST(DFNCPP)
|
||||
# Some awks crash when confronted with pnglibconf.dfa, do a test run now
|
||||
# to make sure this doesn't happen
|
||||
AC_MSG_CHECKING([that AWK works])
|
||||
if ${AWK} -f ${srcdir}/scripts/options.awk out="/dev/null" version=search\
|
||||
${srcdir}/pngconf.h ${srcdir}/scripts/pnglibconf.dfa\
|
||||
${srcdir}/pngusr.dfa 1>&2
|
||||
then
|
||||
AC_MSG_RESULT([ok])
|
||||
else
|
||||
AC_MSG_FAILURE([not found], 1)
|
||||
AC_MSG_FAILURE([failed], 1)
|
||||
fi
|
||||
|
||||
# This is a remnant of the old cc -E validation, where it may have been
|
||||
# necessary to use a different preprocessor for .dfn files
|
||||
DFNCPP="$CPP -E"
|
||||
AC_SUBST(DFNCPP)
|
||||
|
||||
# -Werror cannot be passed to GCC in CFLAGS because configure will fail (it
|
||||
# checks the compiler with a program that generates a warning), add the
|
||||
# following option to deal with this
|
||||
@@ -115,31 +109,146 @@ AC_ARG_ENABLE(werror,
|
||||
|
||||
# Checks for header files.
|
||||
AC_HEADER_STDC
|
||||
AC_CHECK_HEADERS([malloc.h stdlib.h string.h strings.h])
|
||||
# Headers used in pngpriv.h:
|
||||
AC_CHECK_HEADERS([assert.h stdlib.h string.h float.h fp.h math.h m68881.h])
|
||||
# Additional headers used in pngconf.h:
|
||||
AC_CHECK_HEADERS([limits.h stddef.h stdio.h setjmp.h time.h])
|
||||
# Used by pngread.c (for the simplified API):
|
||||
AC_CHECK_HEADERS([errno.h])
|
||||
# The following are not required for the standard 'make' build of libpng:
|
||||
# Additional requirements of contrib/libtests/makepng.c:
|
||||
AC_CHECK_HEADERS([ctype.h])
|
||||
# Additional requirements of contrib/libtests/pngvalid.c:
|
||||
AC_CHECK_HEADERS([fenv.h])
|
||||
|
||||
# Checks for typedefs, structures, and compiler characteristics.
|
||||
AC_C_CONST
|
||||
AC_TYPE_SIZE_T
|
||||
AC_STRUCT_TM
|
||||
# Most of these have been removed from 1.7.0 because they checked for non-ANSI-C
|
||||
# behaviors and the result were, anyway, not used by earlier versions of libpng.
|
||||
AC_C_RESTRICT
|
||||
|
||||
# Checks for library functions.
|
||||
AC_FUNC_STRTOD
|
||||
AC_CHECK_FUNCS([memset], , AC_MSG_ERROR(memset not found in libc))
|
||||
AC_CHECK_FUNCS([pow], , AC_CHECK_LIB(m, pow, , AC_MSG_ERROR(cannot find pow)) )
|
||||
AC_ARG_WITH(zlib-prefix,
|
||||
AS_HELP_STRING([[[--with-zlib-prefix]]],
|
||||
[prefix that may have been used in installed zlib]),
|
||||
[ZPREFIX=${withval}],
|
||||
[ZPREFIX='z_'])
|
||||
AC_CHECK_LIB(z, zlibVersion, ,
|
||||
AC_CHECK_LIB(z, ${ZPREFIX}zlibVersion, , AC_MSG_ERROR(zlib not installed)))
|
||||
# Checks for library functions; these need to be in order, least demanding to
|
||||
# most because the -l directives are added to the head of the list at each
|
||||
# check.
|
||||
# ANSI-C functions: all are required but they don't have to be implemented in
|
||||
# libc, it is perfectly ok to configure with an extra, wrapper, library preset
|
||||
# in LIBS. NOTE: this list may not be complete
|
||||
AC_CHECK_FUNCS([memset memcpy strncpy],,
|
||||
AC_MSG_FAILURE([missing ANSI-C functions]))
|
||||
|
||||
# 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],
|
||||
AS_HELP_STRING([[[--enabled-floating-point]]],
|
||||
[Enable floating point APIs (default: yes)]),,
|
||||
[enable_floating_point=yes])
|
||||
|
||||
AC_ARG_ENABLE([fixed-point],
|
||||
AS_HELP_STRING([[[--enable-fixed-point]]],
|
||||
[Enable fixed point APIs (default: yes)]),,
|
||||
[enable_fixed_point=yes])
|
||||
|
||||
AC_ARG_ENABLE([floating-arithmetic],
|
||||
AS_HELP_STRING([[[--enable-floating-arithmetic]]],
|
||||
[Use floating point arithmetic internally (default: yes)]),,
|
||||
[enable_floating_arithmetic=yes])
|
||||
|
||||
# Check for a requirement for math library support
|
||||
if test "$enable_floating_arithmetic" = yes
|
||||
then
|
||||
AC_SEARCH_LIBS([floor],[m],,
|
||||
[AC_MSG_WARN([not found])
|
||||
enable_floating_arithmetic=no])
|
||||
AC_SEARCH_LIBS([frexp],[m],,
|
||||
[AC_MSG_WARN([not found])
|
||||
enable_floating_arithmetic=no])
|
||||
AC_SEARCH_LIBS([modf],[m],,
|
||||
[AC_MSG_WARN([not found])
|
||||
enable_floating_arithmetic=no])
|
||||
AC_SEARCH_LIBS([atof],[m],,
|
||||
[AC_MSG_WARN([not found])
|
||||
enable_floating_arithmetic=no])
|
||||
AC_SEARCH_LIBS([pow],[m],,
|
||||
[AC_MSG_WARN([not found])
|
||||
enable_floating_arithmetic=no])
|
||||
fi
|
||||
|
||||
# Set the relevant defines if required (only if required), this will override
|
||||
# anything on the command line.
|
||||
if test "$enable_floating_point" != yes
|
||||
then
|
||||
AC_MSG_NOTICE([Floating point APIs disabled])
|
||||
AC_DEFINE([PNG_NO_FLOATING_POINT],[1],
|
||||
[No support for floating point APIs])
|
||||
fi
|
||||
if test "$enable_fixed_point" != yes
|
||||
then
|
||||
AC_MSG_NOTICE([Fixed point APIs disabled])
|
||||
AC_DEFINE([PNG_NO_FIXED_POINT],[1],
|
||||
[No support for fixed point APIs])
|
||||
fi
|
||||
if test "$enable_floating_arithmetic" != yes
|
||||
then
|
||||
AC_MSG_NOTICE([Fixed point arithmetic will be used])
|
||||
AC_DEFINE([PNG_NO_FLOATING_ARITHMETIC],[1],
|
||||
[No support for floating point arithmetic])
|
||||
fi
|
||||
|
||||
# The following is for pngvalid, to ensure it catches FP errors even on
|
||||
# platforms that don't enable FP exceptions, the function appears in the math
|
||||
# library (typically), it's not an error if it is not found.
|
||||
AC_CHECK_LIB([m], [feenableexcept])
|
||||
AC_CHECK_FUNCS([feenableexcept])
|
||||
AC_SEARCH_LIBS([feenableexcept],[m],AC_DEFINE([HAVE_FEENABLEEXCEPT],[1],
|
||||
[Define to 1 if the feenableexcept function is available]))
|
||||
# Required by pngvalid:
|
||||
AC_SEARCH_LIBS([ceil],[m])
|
||||
|
||||
# zlib checks and arguments;
|
||||
# package zlib: argument is the name of the library
|
||||
# zlib-header: the name of the header file
|
||||
# zlib-prefix: the prefix for library functions, if any
|
||||
AC_ARG_WITH([zlib],
|
||||
AS_HELP_STRING([[[--with-zlib=<name>]]],
|
||||
[base name of the zlib implementation (e.g. 'z')]),,
|
||||
[with_zlib='z'])
|
||||
|
||||
z_prefix=
|
||||
AC_ARG_WITH([zlib-prefix],
|
||||
AS_HELP_STRING([[[--with-zlib-prefix=<prefix>]]],
|
||||
[prefix for zlib API functions]),
|
||||
[if test "$withval" = "" -o "$withval" = yes; then
|
||||
with_zlib_prefix='z_'
|
||||
AC_DEFINE([PNG_ZLIB_PREFIX],[z_],[Standard zlib prefix])
|
||||
elif test "${withval}" != "no"; then
|
||||
AC_DEFINE_UNQUOTED([PNG_ZLIB_PREFIX],[${withval}],
|
||||
[User defined zlib prefix])
|
||||
else
|
||||
with_zlib_prefix=
|
||||
fi
|
||||
if test "$with_zlib_prefix" != ""; then
|
||||
AC_DEFINE([Z_PREFIX],[1],[Tell zlib.h to prefix function names])
|
||||
z_prefix="#define Z_PREFIX 1"
|
||||
fi])
|
||||
|
||||
AC_ARG_WITH([zlib-header],
|
||||
AS_HELP_STRING([[[--with-zlib-header='<file>' or '"file"']]],
|
||||
[C include argument to locate zlib header file, e.g. <zlib.h>, take
|
||||
care to put single quotes round this on the command line]),
|
||||
[AC_DEFINE_UNQUOTED([PNG_ZLIB_HEADER],[${withval}],[Zlib header file])],
|
||||
with_zlib_header='<zlib.h>')
|
||||
|
||||
# AC_CHECK_LIB isn't quite enough for this because we need the special header
|
||||
# file too.
|
||||
LIBS="-l${with_zlib} $LIBS"
|
||||
AC_MSG_CHECKING(
|
||||
[[Library '${with_zlib}' and #include ${with_zlib_header} for symbol '${with_zlib_prefix}zlibVersion']])
|
||||
AC_LINK_IFELSE(
|
||||
[AC_LANG_PROGRAM(
|
||||
[[
|
||||
${z_prefix}
|
||||
#include ${with_zlib_header}
|
||||
]],
|
||||
[[(void)${with_zlib_prefix}zlibVersion();]])],
|
||||
AC_MSG_RESULT([ok]),
|
||||
AC_MSG_FAILURE([not found]))
|
||||
|
||||
AC_MSG_CHECKING([if using Solaris linker])
|
||||
SLD=`$LD --version 2>&1 | grep Solaris`
|
||||
@@ -185,7 +294,7 @@ AM_CONDITIONAL(HAVE_LD_VERSION_SCRIPT, test "$have_ld_version_script" = "yes")
|
||||
if test "$have_ld_version_script" = "yes"; then
|
||||
AC_MSG_CHECKING([for symbol prefix])
|
||||
SYMBOL_PREFIX=`echo "PREFIX=__USER_LABEL_PREFIX__" \
|
||||
| ${CPP-${CC-gcc} -E} - 2>&1 \
|
||||
| ${DFNCPP-${CC-gcc -E}} - 2>&1 \
|
||||
| ${EGREP-grep} "^PREFIX=" \
|
||||
| ${SED-sed} -e "s:^PREFIX=::" -e "s:__USER_LABEL_PREFIX__::"`
|
||||
AC_SUBST(SYMBOL_PREFIX)
|
||||
@@ -233,24 +342,98 @@ AC_ARG_WITH(libpng-prefix,
|
||||
fi])
|
||||
AM_CONDITIONAL([DO_PNG_PREFIX], [test "${with_libpng_prefix:-no}" != "no"])
|
||||
|
||||
# Because GCC by default assembles code with an executable stack, even though it
|
||||
# compiles C code with a non-executable stack, it is necessary to do a fixup
|
||||
# here (this may by GCC specific)
|
||||
AC_SUBST([AM_CCASFLAGS], [-Wa,--noexecstack])
|
||||
# Control over what links are made for installed files. Versioned files are
|
||||
# always installed, when the following options are turned on corresponding
|
||||
# unversioned links are also created (normally as symbolic links):
|
||||
AC_ARG_ENABLE([unversioned-links],
|
||||
AS_HELP_STRING([[[--enable-unversioned-links]]],
|
||||
[Installed libpng header files are placed in a versioned subdirectory]
|
||||
[and installed libpng library (including DLL) files are versioned.]
|
||||
[If this option is enabled unversioned links will be created pointing to]
|
||||
[the corresponding installed files. If you use libpng.pc or]
|
||||
[libpng-config for all builds you do not need these links, but if you]
|
||||
[compile programs directly they will typically #include <png.h> and]
|
||||
[link with -lpng; in that case you need the links.]
|
||||
[The links can be installed manually using 'make install-header-links']
|
||||
[and 'make install-library-links' and can be removed using the]
|
||||
[corresponding uninstall- targets. If you do enable this option every]
|
||||
[libpng 'make install' will recreate the links to point to the just]
|
||||
[installed version of libpng. The default is to create the links;]
|
||||
[use --disable-unversioned-links to change this]))
|
||||
|
||||
# The AM_CONDITIONAL test is written so that the default is enabled;
|
||||
# --disable-unversioned-links must be given to turn the option off.
|
||||
AM_CONDITIONAL([DO_INSTALL_LINKS],[test "$enable_unversioned_links" != "no"])
|
||||
|
||||
AC_ARG_ENABLE([unversioned-libpng-pc],
|
||||
AS_HELP_STRING([[[--enable-unversioned-libpng-pc]]],
|
||||
[Install the configuration file 'libpng.pc' as a link to the versioned]
|
||||
[version. This is done by default - use --disable-unversioned-libpng-pc]
|
||||
[to change this.]))
|
||||
AM_CONDITIONAL([DO_INSTALL_LIBPNG_PC],
|
||||
[test "$enable_unversioned_libpng_pc" != "no"])
|
||||
|
||||
AC_ARG_ENABLE([unversioned-libpng-config],
|
||||
AS_HELP_STRING([[[--enable-unversioned-libpng-config]]],
|
||||
[Install the configuration file 'libpng-config' as a link to the]
|
||||
[versioned version. This is done by default - use]
|
||||
[--disable-unversioned-libpng-config to change this.]))
|
||||
AM_CONDITIONAL([DO_INSTALL_LIBPNG_CONFIG],
|
||||
[test "$enable_unversioned_libpng_config" != "no"])
|
||||
|
||||
# HOST SPECIFIC OPTIONS
|
||||
# =====================
|
||||
#
|
||||
# ARM
|
||||
# ===
|
||||
#
|
||||
# ARM NEON (SIMD) support.
|
||||
|
||||
AC_ARG_ENABLE([arm-neon],
|
||||
AS_HELP_STRING([[[--enable-arm-neon]]], [Enable ARM NEON optimizations]),
|
||||
[if test "${enableval}" = "yes"; then
|
||||
AC_DEFINE([PNG_ARM_NEON], [1], [Enable ARM NEON optimizations])
|
||||
AC_DEFINE([PNG_ALIGNED_MEMORY_SUPPORTED], [1], [Align row buffers])
|
||||
fi])
|
||||
AM_CONDITIONAL([PNG_ARM_NEON], [test "${enable_arm_neon:-no}" = yes])
|
||||
AS_HELP_STRING([[[--enable-arm-neon]]],
|
||||
[Enable ARM NEON optimizations: =no/off, check, api, yes/on:]
|
||||
[no/off: disable the optimizations; check: use internal checking code]
|
||||
[(deprecated and poorly supported); api: disable by default, enable by]
|
||||
[a call to png_set_option; yes/on: turn on unconditionally.]
|
||||
[If not specified: determined by the compiler.]),
|
||||
[case "$enableval" in
|
||||
no|off)
|
||||
# disable the default enabling on __ARM_NEON__ systems:
|
||||
AC_DEFINE([PNG_ARM_NEON_OPT], [0],
|
||||
[Disable ARM Neon optimizations])
|
||||
# Prevent inclusion of the assembler files below:
|
||||
enable_arm_neon=no;;
|
||||
check)
|
||||
AC_DEFINE([PNG_ARM_NEON_CHECK_SUPPORTED], [],
|
||||
[Check for ARM Neon support at run-time]);;
|
||||
api)
|
||||
AC_DEFINE([PNG_ARM_NEON_API_SUPPORTED], [],
|
||||
[Turn on ARM Neon optimizations at run-time]);;
|
||||
yes|on)
|
||||
AC_DEFINE([PNG_ARM_NEON_OPT], [2],
|
||||
[Enable ARM Neon optimizations])
|
||||
AC_MSG_WARN([--enable-arm-neon: please specify 'check' or 'api', if]
|
||||
[you want the optimizations unconditionally pass -mfpu=neon]
|
||||
[to the compiler.]);;
|
||||
*)
|
||||
AC_MSG_ERROR([--enable-arm-neon=${enable_arm_neon}: invalid value])
|
||||
esac])
|
||||
|
||||
# Add ARM specific files to all builds where the host_cpu is arm ('arm*') or
|
||||
# where ARM optimizations were explicitly requested (this allows a fallback if a
|
||||
# future host CPU does not match 'arm*')
|
||||
|
||||
AM_CONDITIONAL([PNG_ARM_NEON],
|
||||
[test "$enable_arm_neon" != 'no' &&
|
||||
case "$host_cpu" in
|
||||
arm*|aarch64*) :;;
|
||||
*) test "$enable_arm_neon" != '';;
|
||||
esac])
|
||||
|
||||
AC_MSG_NOTICE([[Extra options for compiler: $PNG_COPTS]])
|
||||
|
||||
# Config files, substituting as above
|
||||
AC_CONFIG_FILES([Makefile libpng.pc:libpng.pc.in])
|
||||
AC_CONFIG_FILES([libpng-config:libpng-config.in],
|
||||
[chmod +x libpng-config])
|
||||
AC_CONFIG_FILES([Makefile libpng.pc])
|
||||
AC_CONFIG_FILES([libpng-config], [chmod +x libpng-config])
|
||||
|
||||
AC_OUTPUT
|
||||
|
||||
83
contrib/arm-neon/README
Normal file
83
contrib/arm-neon/README
Normal file
@@ -0,0 +1,83 @@
|
||||
OPERATING SYSTEM SPECIFIC ARM NEON DETECTION
|
||||
--------------------------------------------
|
||||
|
||||
Detection of the ability to exexcute ARM NEON on an ARM processor requires
|
||||
operating system support. (The information is not available in user mode.)
|
||||
|
||||
HOW TO USE THIS
|
||||
---------------
|
||||
|
||||
This directory contains C code fragments that can be included in arm/arm_init.c
|
||||
by setting the macro PNG_ARM_NEON_FILE to the file name in "" or <> at build
|
||||
time. This setting is not recorded in pnglibconf.h and can be changed simply by
|
||||
rebuilding arm/arm_init.o with the required macro definition.
|
||||
|
||||
For any of this code to be used the ARM NEON code must be enabled and run time
|
||||
checks must be supported. I.e.:
|
||||
|
||||
#if PNG_ARM_NEON_OPT > 0
|
||||
#ifdef PNG_ARM_NEON_CHECK_SUPPORTED
|
||||
|
||||
This is done in a 'configure' build by passing configure the argument:
|
||||
|
||||
--enable-arm-neon=check
|
||||
|
||||
Apart from the basic Linux implementation in contrib/arm-neon/linux.c this code
|
||||
is unsupported. That means that it is not even compiled on a regular basis and
|
||||
may be broken in any given minor release.
|
||||
|
||||
FILE FORMAT
|
||||
-----------
|
||||
|
||||
Each file documents its testing status as of the last time it was tested (which
|
||||
may have been a long time ago):
|
||||
|
||||
STATUS: one of:
|
||||
SUPPORTED: This indicates that the file is included in the regularly
|
||||
performed test builds and bugs are fixed when discovered.
|
||||
COMPILED: This indicates that the code did compile at least once. See the
|
||||
more detailed description for the extent to which the result was
|
||||
successful.
|
||||
TESTED: This means the code was fully compiled into the libpng test programs
|
||||
and these were run at least once.
|
||||
|
||||
BUG REPORTS: an email address to which to send reports of problems
|
||||
|
||||
The file is a fragment of C code. It should not define any 'extern' symbols;
|
||||
everything should be static. It must define the function:
|
||||
|
||||
static int png_have_neon(png_structp png_ptr);
|
||||
|
||||
That function must return 1 if ARM NEON instructions are supported, 0 if not.
|
||||
It must not execute png_error unless it detects a bug. A png_error will prevent
|
||||
the reading of the PNG and in the future, writing too.
|
||||
|
||||
BUG REPORTS
|
||||
-----------
|
||||
|
||||
If you mail a bug report for any file that is not SUPPORTED there may only be
|
||||
limited response. Consider fixing it and sending a patch to fix the problem -
|
||||
this is more likely to result in action.
|
||||
|
||||
CONTRIBUTIONS
|
||||
-------------
|
||||
|
||||
You may send contributions of new implementations to
|
||||
png-mng-implement@sourceforge.net. Please write code in strict C90 C where
|
||||
possible. Obviously OS dependencies are to be expected. If you submit code you
|
||||
must have the authors permission and it must have a license that is acceptable
|
||||
to the current maintainer; in particular that license must permit modification
|
||||
and redistribution.
|
||||
|
||||
Please try to make the contribution a single file and give the file a clear and
|
||||
unambiguous name that identifies the target OS. If multiple files really are
|
||||
required put them all in a sub-directory.
|
||||
|
||||
You must also be prepared to handle bug reports from users of the code, either
|
||||
by joining the png-mng-implement mailing list or by providing an email for the
|
||||
"BUG REPORTS" entry or both. Please make sure that the header of the file
|
||||
contains the STATUS and BUG REPORTS fields as above.
|
||||
|
||||
Please list the OS requirements as precisely as possible. Ideally you should
|
||||
also list the environment in which the code has been tested and certainly list
|
||||
any environments where you suspect it might not work.
|
||||
39
contrib/arm-neon/android-ndk.c
Normal file
39
contrib/arm-neon/android-ndk.c
Normal file
@@ -0,0 +1,39 @@
|
||||
/* contrib/arm-neon/android-ndk.c
|
||||
*
|
||||
* Copyright (c) 2014 Glenn Randers-Pehrson
|
||||
* Written by John Bowler, 2014.
|
||||
* Last changed in libpng 1.6.10 [March 6, 2014]
|
||||
*
|
||||
* This code is released under the libpng license.
|
||||
* For conditions of distribution and use, see the disclaimer
|
||||
* and license in png.h
|
||||
*
|
||||
* SEE contrib/arm-neon/README before reporting bugs
|
||||
*
|
||||
* STATUS: COMPILED, UNTESTED
|
||||
* BUG REPORTS: png-mng-implement@sourceforge.net
|
||||
*
|
||||
* png_have_neon implemented for the Android NDK, see:
|
||||
*
|
||||
* Documentation:
|
||||
* http://www.kandroid.org/ndk/docs/CPU-ARM-NEON.html
|
||||
* http://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
|
||||
* has been compiled only, not linked: no version of the library has been found,
|
||||
* only the header files exist in the NDK.
|
||||
*/
|
||||
#include <cpu-features.h>
|
||||
|
||||
static int
|
||||
png_have_neon(png_structp png_ptr)
|
||||
{
|
||||
/* This is a whole lot easier than the linux code, however it is probably
|
||||
* implemented as below, therefore it is better to cache the result (these
|
||||
* function calls may be slow!)
|
||||
*/
|
||||
PNG_UNUSED(png_ptr)
|
||||
return android_getCpuFamily() == ANDROID_CPU_FAMILY_ARM &&
|
||||
(android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON) != 0;
|
||||
}
|
||||
120
contrib/arm-neon/linux-auxv.c
Normal file
120
contrib/arm-neon/linux-auxv.c
Normal file
@@ -0,0 +1,120 @@
|
||||
/* contrib/arm-neon/linux-auxv.c
|
||||
*
|
||||
* Copyright (c) 2014 Glenn Randers-Pehrson
|
||||
* Written by Mans Rullgard, 2011.
|
||||
* Last changed in libpng 1.6.10 [March 6, 2014]
|
||||
*
|
||||
* This code is released under the libpng license.
|
||||
* For conditions of distribution and use, see the disclaimer
|
||||
* and license in png.h
|
||||
*
|
||||
* SEE contrib/arm-neon/README before reporting bugs
|
||||
*
|
||||
* STATUS: COMPILED, TESTED
|
||||
* BUG REPORTS: png-mng-implement@sourceforge.net
|
||||
*
|
||||
* png_have_neon implemented for Linux versions which allow access to
|
||||
* /proc/self/auxv. This is probably faster, cleaner and safer than the code to
|
||||
* read /proc/cpuinfo in contrib/arm-neon/linux, however it is yet another piece
|
||||
* of potentially untested code and has more complex dependencies than the code
|
||||
* to read cpuinfo.
|
||||
*
|
||||
* This generic __linux__ implementation requires reading /proc/self/auxv and
|
||||
* looking at each element for one that records NEON capabilities.
|
||||
*/
|
||||
#include <unistd.h> /* for POSIX 1003.1 */
|
||||
#include <errno.h> /* for EINTR */
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <elf.h>
|
||||
#include <asm/hwcap.h>
|
||||
|
||||
/* A read call may be interrupted, in which case it returns -1 and sets errno to
|
||||
* EINTR if nothing was done, otherwise (if something was done) a partial read
|
||||
* may result.
|
||||
*/
|
||||
static size_t
|
||||
safe_read(png_structp png_ptr, int fd, void *buffer_in, size_t nbytes)
|
||||
{
|
||||
size_t ntotal = 0;
|
||||
char *buffer = png_voidcast(char*, buffer_in);
|
||||
|
||||
while (nbytes > 0)
|
||||
{
|
||||
unsigned int nread;
|
||||
int iread;
|
||||
|
||||
/* Passing nread > INT_MAX to read is implementation defined in POSIX
|
||||
* 1003.1, therefore despite the unsigned argument portable code must
|
||||
* limit the value to INT_MAX!
|
||||
*/
|
||||
if (nbytes > INT_MAX)
|
||||
nread = INT_MAX;
|
||||
|
||||
else
|
||||
nread = (unsigned int)/*SAFE*/nbytes;
|
||||
|
||||
iread = read(fd, buffer, nread);
|
||||
|
||||
if (iread == -1)
|
||||
{
|
||||
/* This is the devil in the details, a read can terminate early with 0
|
||||
* bytes read because of EINTR, yet it still returns -1 otherwise end
|
||||
* of file cannot be distinguished.
|
||||
*/
|
||||
if (errno != EINTR)
|
||||
{
|
||||
png_warning(png_ptr, "/proc read failed");
|
||||
return 0; /* I.e., a permanent failure */
|
||||
}
|
||||
}
|
||||
|
||||
else if (iread < 0)
|
||||
{
|
||||
/* Not a valid 'read' result: */
|
||||
png_warning(png_ptr, "OS /proc read bug");
|
||||
return 0;
|
||||
}
|
||||
|
||||
else if (iread > 0)
|
||||
{
|
||||
/* Continue reading until a permanent failure, or EOF */
|
||||
buffer += iread;
|
||||
nbytes -= (unsigned int)/*SAFE*/iread;
|
||||
ntotal += (unsigned int)/*SAFE*/iread;
|
||||
}
|
||||
|
||||
else
|
||||
return ntotal;
|
||||
}
|
||||
|
||||
return ntotal; /* nbytes == 0 */
|
||||
}
|
||||
|
||||
static int
|
||||
png_have_neon(png_structp png_ptr)
|
||||
{
|
||||
int fd = open("/proc/self/auxv", O_RDONLY);
|
||||
Elf32_auxv_t aux;
|
||||
|
||||
/* Failsafe: failure to open means no NEON */
|
||||
if (fd == -1)
|
||||
{
|
||||
png_warning(png_ptr, "/proc/self/auxv open failed");
|
||||
return 0;
|
||||
}
|
||||
|
||||
while (safe_read(png_ptr, fd, &aux, sizeof aux) == sizeof aux)
|
||||
{
|
||||
if (aux.a_type == AT_HWCAP && (aux.a_un.a_val & HWCAP_NEON) != 0)
|
||||
{
|
||||
close(fd);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
159
contrib/arm-neon/linux.c
Normal file
159
contrib/arm-neon/linux.c
Normal file
@@ -0,0 +1,159 @@
|
||||
/* contrib/arm-neon/linux.c
|
||||
*
|
||||
* Copyright (c) 2014 Glenn Randers-Pehrson
|
||||
* Written by John Bowler, 2014.
|
||||
* Last changed in libpng 1.6.10 [March 6, 2014]
|
||||
*
|
||||
* This code is released under the libpng license.
|
||||
* For conditions of distribution and use, see the disclaimer
|
||||
* and license in png.h
|
||||
*
|
||||
* SEE contrib/arm-neon/README before reporting bugs
|
||||
*
|
||||
* STATUS: SUPPORTED
|
||||
* BUG REPORTS: png-mng-implement@sourceforge.net
|
||||
*
|
||||
* png_have_neon implemented for Linux by reading the widely available
|
||||
* pseudo-file /proc/cpuinfo.
|
||||
*
|
||||
* This code is strict ANSI-C and is probably moderately portable, it does
|
||||
* however use <stdio.h> and assumes that /proc/cpuinfo is never localized.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
|
||||
static int
|
||||
png_have_neon(png_structp png_ptr)
|
||||
{
|
||||
FILE *f = fopen("/proc/cpuinfo", "rb");
|
||||
|
||||
if (f != NULL)
|
||||
{
|
||||
/* This is a simple state machine which reads the input byte-by-byte until
|
||||
* it gets a match on the 'neon' feature or reaches the end of the stream.
|
||||
*/
|
||||
static const char ch_feature[] = { 70, 69, 65, 84, 85, 82, 69, 83 };
|
||||
static const char ch_neon[] = { 78, 69, 79, 78 };
|
||||
|
||||
enum
|
||||
{
|
||||
StartLine, Feature, Colon, StartTag, Neon, HaveNeon, SkipTag, SkipLine
|
||||
} state;
|
||||
int counter;
|
||||
|
||||
for (state=StartLine, counter=0;;)
|
||||
{
|
||||
int ch = fgetc(f);
|
||||
|
||||
if (ch == EOF)
|
||||
{
|
||||
/* EOF means error or end-of-file, return false; neon at EOF is
|
||||
* assumed to be a mistake.
|
||||
*/
|
||||
fclose(f);
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case StartLine:
|
||||
/* Match spaces at the start of line */
|
||||
if (ch <= 32) /* skip control characters and space */
|
||||
break;
|
||||
|
||||
counter=0;
|
||||
state = Feature;
|
||||
/* FALL THROUGH */
|
||||
|
||||
case Feature:
|
||||
/* Match 'FEATURE', ASCII case insensitive. */
|
||||
if ((ch & ~0x20) == ch_feature[counter])
|
||||
{
|
||||
if (++counter == (sizeof ch_feature))
|
||||
state = Colon;
|
||||
break;
|
||||
}
|
||||
|
||||
/* did not match 'feature' */
|
||||
state = SkipLine;
|
||||
/* FALL THROUGH */
|
||||
|
||||
case SkipLine:
|
||||
skipLine:
|
||||
/* Skip everything until we see linefeed or carriage return */
|
||||
if (ch != 10 && ch != 13)
|
||||
break;
|
||||
|
||||
state = StartLine;
|
||||
break;
|
||||
|
||||
case Colon:
|
||||
/* Match any number of space or tab followed by ':' */
|
||||
if (ch == 32 || ch == 9)
|
||||
break;
|
||||
|
||||
if (ch == 58) /* i.e. ':' */
|
||||
{
|
||||
state = StartTag;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Either a bad line format or a 'feature' prefix followed by
|
||||
* other characters.
|
||||
*/
|
||||
state = SkipLine;
|
||||
goto skipLine;
|
||||
|
||||
case StartTag:
|
||||
/* Skip space characters before a tag */
|
||||
if (ch == 32 || ch == 9)
|
||||
break;
|
||||
|
||||
state = Neon;
|
||||
counter = 0;
|
||||
/* FALL THROUGH */
|
||||
|
||||
case Neon:
|
||||
/* Look for 'neon' tag */
|
||||
if ((ch & ~0x20) == ch_neon[counter])
|
||||
{
|
||||
if (++counter == (sizeof ch_neon))
|
||||
state = HaveNeon;
|
||||
break;
|
||||
}
|
||||
|
||||
state = SkipTag;
|
||||
/* FALL THROUGH */
|
||||
|
||||
case SkipTag:
|
||||
/* Skip non-space characters */
|
||||
if (ch == 10 || ch == 13)
|
||||
state = StartLine;
|
||||
|
||||
else if (ch == 32 || ch == 9)
|
||||
state = StartTag;
|
||||
break;
|
||||
|
||||
case HaveNeon:
|
||||
/* Have seen a 'neon' prefix, but there must be a space or new
|
||||
* line character to terminate it.
|
||||
*/
|
||||
if (ch == 10 || ch == 13 || ch == 32 || ch == 9)
|
||||
{
|
||||
fclose(f);
|
||||
return 1;
|
||||
}
|
||||
|
||||
state = SkipTag;
|
||||
break;
|
||||
|
||||
default:
|
||||
png_error(png_ptr, "png_have_neon: internal error (bug)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
png_warning(png_ptr, "/proc/cpuinfo open failed");
|
||||
|
||||
return 0;
|
||||
}
|
||||
49
contrib/conftest/README
Normal file
49
contrib/conftest/README
Normal file
@@ -0,0 +1,49 @@
|
||||
This directory contains test configuration files, currently always '.dfa' files
|
||||
intended to be used in the build by setting the make macro DFA_XTRA to the name
|
||||
of the file.
|
||||
|
||||
These files are used in release validation of the 'configure' builds of libpng
|
||||
by building 'make check', or 'make all-am' for cross-builds, with each .dfa
|
||||
file.
|
||||
|
||||
The files in this directory may change between minor releases, however
|
||||
contributions describing specific builds of libpng are welcomed. There is no
|
||||
guarantee that libpng will continue to build with such configurations; support
|
||||
for given configurations can be, and has been, dropped between successive minor
|
||||
releases. However if a .dfa file describing a configuration is not in this
|
||||
directory it is very unlikely that it will be tested before a minor release!
|
||||
|
||||
You can use these .dfa files as the basis of new configurations. Files in this
|
||||
directory should not have any use restrictions or restrictive licenses.
|
||||
|
||||
This directory is not included in the .zip and .7z distributions, which do
|
||||
not contain 'configure' scripts.
|
||||
|
||||
DOCUMENTATION
|
||||
=============
|
||||
|
||||
Examples:
|
||||
${srcdir}/pngusr.dfa
|
||||
${srcdir}/contrib/pngminim/*/pngusr.dfa
|
||||
|
||||
Documentation of the options:
|
||||
${srcdir}/scripts/pnglibconf.dfa
|
||||
|
||||
Documentation of the file format:
|
||||
${srcdir}/scripts/options.awk
|
||||
|
||||
FILE NAMING
|
||||
===========
|
||||
|
||||
File names in this directory may NOT contain any of the five characters:
|
||||
|
||||
- , + * ?
|
||||
|
||||
Neither may they contain any space character.
|
||||
|
||||
While other characters may be used it is strongly suggested that file names be
|
||||
limited to lower case Latiin alphabetic characters (a-z), digits (0-9) and, if
|
||||
necessary the underscore (_) character. File names should be about 8 characters
|
||||
long (excluding the .dfa extension). Submitted .dfa files should have names
|
||||
between 7 and 16 characters long, shorter names (6 characters or less) are
|
||||
reserved for standard tests.
|
||||
58
contrib/conftest/read.dfa
Normal file
58
contrib/conftest/read.dfa
Normal file
@@ -0,0 +1,58 @@
|
||||
# read.dfa
|
||||
# Build time configuration of libpng
|
||||
#
|
||||
# Author: John Bowler
|
||||
# Copyright: (c) John Bowler, 2013
|
||||
# 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 basic read support. This enables the lowest level libpng
|
||||
# read API - the one where the calling code has to use a loop to read each row.
|
||||
# At present this is the API used by most programs.
|
||||
#
|
||||
# Support is enabled only for those chunks and transformations that are
|
||||
# typically required - others can be added easily.
|
||||
#
|
||||
|
||||
everything = off
|
||||
|
||||
# The sequential read code is enabled here; the progressive code can be used
|
||||
# instead but there is no point enabling both.
|
||||
|
||||
option SEQUENTIAL_READ on
|
||||
|
||||
# Likewise it is pointless enabling both fixed and floating point APIs. Choose
|
||||
# one or the other for both the API and the internal math.
|
||||
|
||||
#Fixed point:
|
||||
#option FIXED_POINT on
|
||||
#option FLOATING_ARITHMETIC off
|
||||
|
||||
#Floating point:
|
||||
option FLOATING_POINT on
|
||||
option FLOATING_ARITHMETIC on
|
||||
|
||||
# Basic error handling, IO and user memory support. The latter allows the
|
||||
# application program to provide its own implementations of 'malloc' and 'free'.
|
||||
option SETJMP on
|
||||
option STDIO on
|
||||
option USER_MEM on
|
||||
|
||||
# To read the full set of PNG images correctly interlace, transparency and
|
||||
# 16-bit support is required. The application can implement interlace itself,
|
||||
# but very few do and it's no longer possible to disable it when READ is
|
||||
# enabled.
|
||||
option READ_tRNS on
|
||||
option READ_16BIT on
|
||||
|
||||
# Everything else is application dependent. This file assumes the app handles
|
||||
# all the native PNG bit layouts, so it doesn't need any of layout change
|
||||
# transforms, but needs libpng to perform gamma correction. It doesn't do any
|
||||
# colorspace stuff and ignores the 'significant bit' information.
|
||||
#
|
||||
# If your app always expands the image to a limited set of bit layouts you
|
||||
# probably want to consider using the simplified API instead of the low level
|
||||
# one - see png.h and s_read.dfa.
|
||||
option READ_GAMMA on
|
||||
35
contrib/conftest/s_read.dfa
Normal file
35
contrib/conftest/s_read.dfa
Normal file
@@ -0,0 +1,35 @@
|
||||
# s_read.dfa
|
||||
# Build time configuration of libpng
|
||||
#
|
||||
# Author: John Bowler
|
||||
# Copyright: (c) John Bowler, 2013
|
||||
# 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 simplified read support (only). This builds a minimal
|
||||
# libpng able to read all PNG formats and convert them into a small number of
|
||||
# well understood memory formats.
|
||||
#
|
||||
|
||||
everything = off
|
||||
|
||||
option SIMPLIFIED_READ on
|
||||
|
||||
# It isn't necessary to chose fixed or floating point for the APIs because the
|
||||
# simplified API doesn't need fixed or floating point numbers. It is necessary
|
||||
# to chose an internal math implementation. The default (because of 'everything
|
||||
# = off') is fixed point - turn the floating point implementation on if you have
|
||||
# hardware floating point or prefer your software floating point implementation.
|
||||
option FLOATING_ARITHMETIC on
|
||||
|
||||
# This is not strictly necessary, but without it the message strings in the API
|
||||
# will not be filled in
|
||||
option ERROR_TEXT on
|
||||
|
||||
# Switching these options on enables the 'AFIRST' and 'BGR' formats - you don't
|
||||
# need this if you don't use them, they just allow the in-memory layout to be
|
||||
# changed to match common hardware formats.
|
||||
option SIMPLIFIED_READ_AFIRST on
|
||||
option SIMPLIFIED_READ_BGR on
|
||||
33
contrib/conftest/s_write.dfa
Normal file
33
contrib/conftest/s_write.dfa
Normal file
@@ -0,0 +1,33 @@
|
||||
# s_write.dfa
|
||||
# Build time configuration of libpng
|
||||
#
|
||||
# Author: John Bowler
|
||||
# Copyright: (c) John Bowler, 2013
|
||||
# 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 (just) simplified write support
|
||||
#
|
||||
|
||||
everything = off
|
||||
|
||||
option SIMPLIFIED_WRITE on
|
||||
|
||||
# It isn't necessary to chose fixed or floating point for the APIs because the
|
||||
# simplified API doesn't need fixed or floating point numbers. It is necessary
|
||||
# to chose an internal math implementation. The default (because of 'everything
|
||||
# = off') is fixed point - turn the floating point implementation on if you have
|
||||
# hardware floating point or prefer your software floating point implementation.
|
||||
option FLOATING_ARITHMETIC on
|
||||
|
||||
# This is not strictly necessary, but without it the message strings in the API
|
||||
# will not be filled in
|
||||
option ERROR_TEXT on
|
||||
|
||||
# Switching these options on enables the 'AFIRST' and 'BGR' formats - you don't
|
||||
# need this if you don't use them, they just allow the in-memory layout to be
|
||||
# changed to match common hardware formats.
|
||||
option SIMPLIFIED_WRITE_AFIRST on
|
||||
option SIMPLIFIED_WRITE_BGR on
|
||||
36
contrib/conftest/simple.dfa
Normal file
36
contrib/conftest/simple.dfa
Normal file
@@ -0,0 +1,36 @@
|
||||
# simple.dfa
|
||||
# Build time configuration of libpng
|
||||
#
|
||||
# Author: John Bowler
|
||||
# Copyright: (c) John Bowler, 2013
|
||||
# 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 just the simplified APIs (read and write).
|
||||
#
|
||||
|
||||
everything = off
|
||||
|
||||
option SIMPLIFIED_WRITE on
|
||||
option SIMPLIFIED_READ on
|
||||
|
||||
# It isn't necessary to chose fixed or floating point for the APIs because the
|
||||
# simplified API doesn't need fixed or floating point numbers. It is necessary
|
||||
# to chose an internal math implementation. The default (because of 'everything
|
||||
# = off') is fixed point - turn the floating point implementation on if you have
|
||||
# hardware floating point or prefer your software floating point implementation.
|
||||
option FLOATING_ARITHMETIC on
|
||||
|
||||
# This is not strictly necessary, but without it the message strings in the API
|
||||
# will not be filled in
|
||||
option ERROR_TEXT on
|
||||
|
||||
# Switching these options on enables the 'AFIRST' and 'BGR' formats - you don't
|
||||
# need this if you don't use them, they just allow the in-memory layout to be
|
||||
# changed to match common hardware formats.
|
||||
option SIMPLIFIED_READ_AFIRST on
|
||||
option SIMPLIFIED_READ_BGR on
|
||||
option SIMPLIFIED_WRITE_AFIRST on
|
||||
option SIMPLIFIED_WRITE_BGR on
|
||||
45
contrib/conftest/write.dfa
Normal file
45
contrib/conftest/write.dfa
Normal file
@@ -0,0 +1,45 @@
|
||||
# write.dfa
|
||||
# Build time configuration of libpng
|
||||
#
|
||||
# Author: John Bowler
|
||||
# Copyright: (c) John Bowler, 2013
|
||||
# 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 no read support and minimal write support.
|
||||
#
|
||||
|
||||
everything = off
|
||||
|
||||
# Switch on the write code - this makes a minimalist encoder
|
||||
|
||||
option WRITE on
|
||||
|
||||
# Choose fixed or floating point APIs and arithmetic. The choices are
|
||||
# independent but normally they will match. It is typically better to use the
|
||||
# floating point if you have floating point hardware. If you don't know, or
|
||||
# (perhaps) to make libpng smaller used fixed point throughout.
|
||||
|
||||
#Fixed point:
|
||||
#option FIXED_POINT on
|
||||
#option FLOATING_ARITHMETIC off
|
||||
|
||||
#Floating point:
|
||||
option FLOATING_POINT on
|
||||
option FLOATING_ARITHMETIC on
|
||||
|
||||
# Basic error handling, IO and user memory support. The latter allows the
|
||||
# application program to provide its own implementations of 'malloc' and 'free'.
|
||||
option SETJMP on
|
||||
option STDIO on
|
||||
option USER_MEM on
|
||||
|
||||
# Everything else is optional. Unlike the read code in libpng the write code
|
||||
# does not need to deal with arbitrary formats, so only add support for things
|
||||
# you really do write! For example you might only write sRGB images, sometimes
|
||||
# with transparency and never write 16 bit images, so:
|
||||
option WRITE_sRGB on
|
||||
option WRITE_tRNS on
|
||||
#option WRITE_16BIT off (this is the default with 'everything = off')
|
||||
@@ -6,9 +6,9 @@
|
||||
* United States.
|
||||
*
|
||||
* Extract any icc profiles found in the given PNG files. This is a simple
|
||||
* example of a program which extracts information from the header of a PNG file
|
||||
* example of a program that extracts information from the header of a PNG file
|
||||
* without processing the image. Notice that some header information may occur
|
||||
* after the image data, textual data and comments are an example; the approach
|
||||
* after the image data. Textual data and comments are an example; the approach
|
||||
* in this file won't work reliably for such data because it only looks for the
|
||||
* information in the section of the file that preceeds the image data.
|
||||
*
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
* Read a single pixel value from a PNG file.
|
||||
*
|
||||
* This code illustrates basic 'by-row' reading of a PNG file using libpng.
|
||||
* Rows are read until a particular pixel is found, the value of this pixel is
|
||||
* Rows are read until a particular pixel is found; the value of this pixel is
|
||||
* then printed on stdout.
|
||||
*
|
||||
* The code illustrates how to do this on interlaced as well as non-interlaced
|
||||
@@ -37,7 +37,7 @@ component(png_const_bytep row, png_uint_32 x, unsigned int c,
|
||||
* bytes wide. Since the row fitted into memory, however, the following must
|
||||
* work:
|
||||
*/
|
||||
png_uint_32 bit_offset_hi = bit_depth * ((x >> 6) * channels + c);
|
||||
png_uint_32 bit_offset_hi = bit_depth * ((x >> 6) * channels);
|
||||
png_uint_32 bit_offset_lo = bit_depth * ((x & 0x3f) * channels + c);
|
||||
|
||||
row = (png_const_bytep)(((PNG_CONST png_byte (*)[8])row) + bit_offset_hi);
|
||||
@@ -56,7 +56,7 @@ component(png_const_bytep row, png_uint_32 x, unsigned int c,
|
||||
case 8: return row[0];
|
||||
case 16: return (row[0] << 8) + row[1];
|
||||
default:
|
||||
/* This should never happen, it indicates a bug in this program or in
|
||||
/* This should never happen; it indicates a bug in this program or in
|
||||
* libpng itself:
|
||||
*/
|
||||
fprintf(stderr, "pngpixel: invalid bit depth %u\n", bit_depth);
|
||||
@@ -132,7 +132,7 @@ print_pixel(png_structp png_ptr, png_infop info_ptr, png_const_bytep row,
|
||||
return;
|
||||
|
||||
default:
|
||||
png_error(png_ptr, "invalid color type");
|
||||
png_error(png_ptr, "pngpixel: invalid color type");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,8 @@ CC = gcc
|
||||
#CC = i386-mingw32msvc-gcc # e.g., Linux -> Win32 cross-compilation
|
||||
LD = $(CC)
|
||||
RM = rm -f
|
||||
CFLAGS = -O -Wall $(INCS) $(MINGW_CCFLAGS)
|
||||
CPPFLAGS = $(INCS)
|
||||
CFLAGS = -O -Wall $(MINGW_CCFLAGS)
|
||||
# [note that -Wall is a gcc-specific compilation flag ("most warnings on")]
|
||||
# [-ansi, -pedantic and -W can also be used]
|
||||
LDFLAGS = $(MINGW_LDFLAGS)
|
||||
@@ -85,10 +86,10 @@ EXES = $(STATIC_EXES) $(DYNAMIC_EXES)
|
||||
# implicit make rules -------------------------------------------------------
|
||||
|
||||
.c$(O):
|
||||
$(CC) -c $(CFLAGS) $<
|
||||
$(CC) -c $(CPPFLAGS) $(CFLAGS) $<
|
||||
|
||||
%.pic$(O): %.c
|
||||
$(CC) -c $(CFLAGS) -DPNG_BUILD_DLL -o $@ $<
|
||||
$(CC) -c $(CPPFLAGS) $(CFLAGS) -DPNG_BUILD_DLL -o $@ $<
|
||||
|
||||
|
||||
# dependencies --------------------------------------------------------------
|
||||
|
||||
@@ -23,9 +23,9 @@
|
||||
|
||||
# macros --------------------------------------------------------------------
|
||||
|
||||
PNGINC = -I/usr/local/include/libpng16
|
||||
PNGLIB = -L/usr/local/lib -lpng16 # dynamically linked against libpng
|
||||
#PNGLIB = /usr/local/lib/libpng16.a # statically linked against libpng
|
||||
PNGINC = -I/usr/local/include/libpng17
|
||||
PNGLIB = -L/usr/local/lib -lpng17 # dynamically linked against libpng
|
||||
#PNGLIB = /usr/local/lib/libpng17.a # statically linked against libpng
|
||||
# or:
|
||||
#PNGINC = -I../..
|
||||
#PNGLIB = -L../.. -lpng
|
||||
@@ -53,7 +53,8 @@ CC = cc
|
||||
LD = cc
|
||||
RM = rm -f
|
||||
# ABI must be the same as that used to build libpng.
|
||||
ABI=
|
||||
ABI =
|
||||
CPPFLAGS =
|
||||
CFLAGS = $(ABI) -O -fullwarn $(INCS)
|
||||
LDFLAGS = $(ABI)
|
||||
O = .o
|
||||
@@ -73,7 +74,7 @@ EXES = $(RPNG)$(E) $(RPNG2)$(E) $(WPNG)$(E)
|
||||
# implicit make rules -------------------------------------------------------
|
||||
|
||||
.c$(O):
|
||||
$(CC) -c $(CFLAGS) $<
|
||||
$(CC) -c $(CPPFLAGS) $(CFLAGS) $<
|
||||
|
||||
|
||||
# dependencies --------------------------------------------------------------
|
||||
|
||||
@@ -26,14 +26,14 @@
|
||||
# macros --------------------------------------------------------------------
|
||||
|
||||
#PNGDIR = /usr/local/lib
|
||||
#PNGINC = -I/usr/local/include/libpng16
|
||||
#PNGLIBd = -L$(PNGDIR) -lpng16 # dynamically linked, installed libpng
|
||||
#PNGLIBs = $(PNGDIR)/libpng16.a # statically linked, installed libpng
|
||||
#PNGINC = -I/usr/local/include/libpng17
|
||||
#PNGLIBd = -L$(PNGDIR) -lpng17 # dynamically linked, installed libpng
|
||||
#PNGLIBs = $(PNGDIR)/libpng17.a # statically linked, installed libpng
|
||||
# or:
|
||||
PNGDIR = ../..# this one is for libpng-x.y.z/contrib/gregbook builds
|
||||
#PNGDIR = ../libpng
|
||||
PNGINC = -I$(PNGDIR)
|
||||
PNGLIBd = -Wl,-rpath,$(PNGDIR) -L$(PNGDIR) -lpng16 # dynamically linked
|
||||
PNGLIBd = -Wl,-rpath,$(PNGDIR) -L$(PNGDIR) -lpng17 # dynamically linked
|
||||
PNGLIBs = $(PNGDIR)/libpng.a # statically linked, local libpng
|
||||
|
||||
ZDIR = /usr/local/lib
|
||||
@@ -64,7 +64,8 @@ WLIBSs = $(PNGLIBs) $(ZLIBs)
|
||||
CC = gcc
|
||||
LD = gcc
|
||||
RM = rm -f
|
||||
CFLAGS = -O -Wall $(INCS) -DFEATURE_LOOP
|
||||
CPPFLAGS = $(INCS) -DFEATURE_LOOP
|
||||
CFLAGS = -O -Wall
|
||||
# [note that -Wall is a gcc-specific compilation flag ("most warnings on")]
|
||||
# [-ansi, -pedantic and -W can also be used]
|
||||
LDFLAGS =
|
||||
@@ -92,7 +93,7 @@ EXES = $(STATIC_EXES) $(DYNAMIC_EXES)
|
||||
# implicit make rules -------------------------------------------------------
|
||||
|
||||
.c$(O):
|
||||
$(CC) -c $(CFLAGS) $<
|
||||
$(CC) -c $(CPPFLAGS) $(CFLAGS) $<
|
||||
|
||||
|
||||
# dependencies --------------------------------------------------------------
|
||||
|
||||
@@ -53,7 +53,8 @@ WLIBS = $(PNGLIB) $(ZLIB)
|
||||
CC = cl
|
||||
LD = link
|
||||
RM = del
|
||||
CFLAGS = -nologo -O -W3 $(INCS) $(cvars)
|
||||
CPPFLAGS = $(INCS)
|
||||
CFLAGS = -nologo -O -W3 $(cvars)
|
||||
# [note that -W3 is an MSVC-specific compilation flag ("all warnings on")]
|
||||
# [see %devstudio%\vc\include\win32.mak for cvars macro definition]
|
||||
O = .obj
|
||||
@@ -76,7 +77,7 @@ EXES = $(RPNG)$(E) $(RPNG2)$(E) $(WPNG)$(E)
|
||||
# implicit make rules -------------------------------------------------------
|
||||
|
||||
.c$(O):
|
||||
$(CC) -c $(CFLAGS) $<
|
||||
$(CC) -c $(CPPFLAGS) $(CFLAGS) $<
|
||||
|
||||
|
||||
# dependencies --------------------------------------------------------------
|
||||
|
||||
@@ -215,6 +215,10 @@ uch *readpng_get_image(double display_exponent, int *pChannels, ulg *pRowbytes)
|
||||
* libpng function */
|
||||
|
||||
if (setjmp(png_jmpbuf(png_ptr))) {
|
||||
free(image_data);
|
||||
image_data = NULL;
|
||||
free(row_pointers);
|
||||
row_pointers = NULL;
|
||||
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -69,6 +69,7 @@ static void readpng2_row_callback(png_structp png_ptr, png_bytep new_row,
|
||||
png_uint_32 row_num, int pass);
|
||||
static void readpng2_end_callback(png_structp png_ptr, png_infop info_ptr);
|
||||
static void readpng2_error_handler(png_structp png_ptr, png_const_charp msg);
|
||||
static void readpng2_warning_handler(png_structp png_ptr, png_const_charp msg);
|
||||
|
||||
|
||||
|
||||
@@ -104,7 +105,7 @@ int readpng2_init(mainprog_info *mainprog_ptr)
|
||||
/* could also replace libpng warning-handler (final NULL), but no need: */
|
||||
|
||||
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, mainprog_ptr,
|
||||
readpng2_error_handler, NULL);
|
||||
readpng2_error_handler, readpng2_warning_handler);
|
||||
if (!png_ptr)
|
||||
return 4; /* out of memory */
|
||||
|
||||
@@ -447,6 +448,8 @@ static void readpng2_end_callback(png_structp png_ptr, png_infop info_ptr)
|
||||
|
||||
/* all done */
|
||||
|
||||
(void)info_ptr; /* Unused */
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -467,7 +470,12 @@ void readpng2_cleanup(mainprog_info *mainprog_ptr)
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void readpng2_warning_handler(png_structp png_ptr, png_const_charp msg)
|
||||
{
|
||||
fprintf(stderr, "readpng2 libpng warning: %s\n", msg);
|
||||
fflush(stderr);
|
||||
(void)png_ptr; /* Unused */
|
||||
}
|
||||
|
||||
|
||||
static void readpng2_error_handler(png_structp png_ptr, png_const_charp msg)
|
||||
|
||||
@@ -163,8 +163,12 @@ uch *readpng_get_image(double display_exponent, int *pChannels, ulg *pRowbytes)
|
||||
|
||||
/* now we can go ahead and just read the whole image */
|
||||
|
||||
fread(image_data, 1L, rowbytes*height, saved_infile);
|
||||
|
||||
if (fread(image_data, 1L, rowbytes*height, saved_infile) <
|
||||
rowbytes*height) {
|
||||
free (image_data);
|
||||
image_data = NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return image_data;
|
||||
}
|
||||
|
||||
57
contrib/libtests/fakepng.c
Normal file
57
contrib/libtests/fakepng.c
Normal file
@@ -0,0 +1,57 @@
|
||||
/* Fake a PNG - just write it out directly. */
|
||||
#include <stdio.h>
|
||||
#include <zlib.h> /* for crc32 */
|
||||
|
||||
void
|
||||
put_uLong(uLong val)
|
||||
{
|
||||
putchar(val >> 24);
|
||||
putchar(val >> 16);
|
||||
putchar(val >> 8);
|
||||
putchar(val >> 0);
|
||||
}
|
||||
|
||||
void
|
||||
put_chunk(const unsigned char *chunk, uInt length)
|
||||
{
|
||||
uLong crc;
|
||||
|
||||
put_uLong(length-4); /* Exclude the tag */
|
||||
|
||||
fwrite(chunk, length, 1, stdout);
|
||||
|
||||
crc = crc32(0, Z_NULL, 0);
|
||||
put_uLong(crc32(crc, chunk, length));
|
||||
}
|
||||
|
||||
const unsigned char signature[] =
|
||||
{
|
||||
137, 80, 78, 71, 13, 10, 26, 10
|
||||
};
|
||||
|
||||
const unsigned char IHDR[] =
|
||||
{
|
||||
73, 72, 68, 82, /* IHDR */
|
||||
0, 0, 0, 1, /* width */
|
||||
0, 0, 0, 1, /* height */
|
||||
1, /* bit depth */
|
||||
0, /* color type: greyscale */
|
||||
0, /* compression method */
|
||||
0, /* filter method */
|
||||
0 /* interlace method: none */
|
||||
};
|
||||
|
||||
const unsigned char unknown[] =
|
||||
{
|
||||
'u', 'n', 'K', 'n' /* "unKn" - private safe to copy */
|
||||
};
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
fwrite(signature, sizeof signature, 1, stdout);
|
||||
put_chunk(IHDR, sizeof IHDR);
|
||||
|
||||
for(;;)
|
||||
put_chunk(unknown, sizeof unknown);
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2012 John Cunningham Bowler
|
||||
# Copyright (c) 2013 John Cunningham Bowler
|
||||
#
|
||||
# Last changed in libpng 1.6.0 [(PENDING RELEASE)]
|
||||
# Last changed in libpng 1.6.0 [February 14, 2013]
|
||||
#
|
||||
# This code is released under the libpng license.
|
||||
# For conditions of distribution and use, see the disclaimer
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/* makepng.c
|
||||
*
|
||||
* Copyright (c) 2012 John Cunningham Bowler
|
||||
* Copyright (c) 2013 John Cunningham Bowler
|
||||
*
|
||||
* Last changed in libpng 1.6.0 [(PENDING RELEASE)]
|
||||
* Last changed in libpng 1.6.1 [March 28, 2013]
|
||||
*
|
||||
* This code is released under the libpng license.
|
||||
* For conditions of distribution and use, see the disclaimer
|
||||
@@ -83,7 +83,7 @@
|
||||
#include <math.h>
|
||||
#include <errno.h>
|
||||
|
||||
#if (defined HAVE_CONFIG_H) && !(defined PNG_NO_CONFIG_H)
|
||||
#if defined(HAVE_CONFIG_H) && !defined(PNG_NO_CONFIG_H)
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
@@ -440,7 +440,7 @@ generate_row(png_bytep row, size_t rowbytes, unsigned int y, int color_type,
|
||||
/* Palette with fixed color: the image rows are all 0 and the image width
|
||||
* is 16.
|
||||
*/
|
||||
memset(row, rowbytes, 0);
|
||||
memset(row, 0, rowbytes);
|
||||
}
|
||||
|
||||
else if (colors[0] == channels_of_type(color_type))
|
||||
@@ -624,8 +624,8 @@ write_png(const char **name, FILE *fp, int color_type, int bit_depth,
|
||||
|
||||
gamma_table[0] = 0;
|
||||
|
||||
for (i=0; i<255; ++i)
|
||||
gamma_table[i] = (png_byte)floor(pow(i/255.,conv) * 255 + 127.5);
|
||||
for (i=1; i<255; ++i)
|
||||
gamma_table[i] = (png_byte)floor(pow(i/255.,conv) * 255 + .5);
|
||||
|
||||
gamma_table[255] = 255;
|
||||
}
|
||||
|
||||
1652
contrib/libtests/pngimage.c
Normal file
1652
contrib/libtests/pngimage.c
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,9 +1,9 @@
|
||||
/*-
|
||||
* pngstest.c
|
||||
*
|
||||
* Copyright (c) 2012 John Cunningham Bowler
|
||||
* Copyright (c) 2013 John Cunningham Bowler
|
||||
*
|
||||
* Last changed in libpng 1.6.0 [(PENDING RELEASE)]
|
||||
* Last changed in libpng 1.6.8 [December 19, 2013]
|
||||
*
|
||||
* This code is released under the libpng license.
|
||||
* For conditions of distribution and use, see the disclaimer
|
||||
@@ -22,7 +22,7 @@
|
||||
#include <ctype.h>
|
||||
#include <math.h>
|
||||
|
||||
#if (defined HAVE_CONFIG_H) && !(defined PNG_NO_CONFIG_H)
|
||||
#if defined(HAVE_CONFIG_H) && !defined(PNG_NO_CONFIG_H)
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
@@ -62,6 +62,12 @@
|
||||
# define aligncastconst(type, value) ((const void*)(value))
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/* During parallel runs of pngstest each temporary file needs a unique name,
|
||||
* this is used to permit uniqueness using a command line argument which can be
|
||||
* up to 22 characters long.
|
||||
*/
|
||||
static char tmpf[23] = "TMP";
|
||||
|
||||
/* Generate random bytes. This uses a boring repeatable algorithm and it
|
||||
* is implemented here so that it gives the same set of numbers on every
|
||||
* architecture. It's a linear congruential generator (Knuth or Sedgewick
|
||||
@@ -309,6 +315,7 @@ compare_16bit(int v1, int v2, int error_limit, int multiple_algorithms)
|
||||
#define KEEP_GOING 32
|
||||
#define ACCUMULATE 64
|
||||
#define FAST_WRITE 128
|
||||
#define sRGB_16BIT 256
|
||||
|
||||
static void
|
||||
print_opts(png_uint_32 opts)
|
||||
@@ -329,6 +336,8 @@ print_opts(png_uint_32 opts)
|
||||
printf(" --accumulate");
|
||||
if (!(opts & FAST_WRITE)) /* --fast is currently the default */
|
||||
printf(" --slow");
|
||||
if (opts & sRGB_16BIT)
|
||||
printf(" --sRGB-16bit");
|
||||
}
|
||||
|
||||
#define FORMAT_NO_CHANGE 0x80000000 /* additional flag */
|
||||
@@ -508,14 +517,23 @@ static void format_default(format_list *pf, int redundant)
|
||||
|
||||
for (f=0; f<FORMAT_COUNT; ++f)
|
||||
{
|
||||
/* Eliminate redundant settings. */
|
||||
/* BGR is meaningless if no color: */
|
||||
if ((f & PNG_FORMAT_FLAG_COLOR) == 0 && (f & PNG_FORMAT_FLAG_BGR) != 0)
|
||||
/* Eliminate redundant and unsupported settings. */
|
||||
# ifdef PNG_FORMAT_BGR_SUPPORTED
|
||||
/* BGR is meaningless if no color: */
|
||||
if ((f & PNG_FORMAT_FLAG_COLOR) == 0 &&
|
||||
(f & PNG_FORMAT_FLAG_BGR) != 0)
|
||||
# else
|
||||
if ((f & 0x10U/*HACK: fixed value*/) != 0)
|
||||
# endif
|
||||
continue;
|
||||
|
||||
/* AFIRST is meaningless if no alpha: */
|
||||
if ((f & PNG_FORMAT_FLAG_ALPHA) == 0 &&
|
||||
(f & PNG_FORMAT_FLAG_AFIRST) != 0)
|
||||
# ifdef PNG_FORMAT_AFIRST_SUPPORTED
|
||||
if ((f & PNG_FORMAT_FLAG_ALPHA) == 0 &&
|
||||
(f & PNG_FORMAT_FLAG_AFIRST) != 0)
|
||||
# else
|
||||
if ((f & 0x20U/*HACK: fixed value*/) != 0)
|
||||
# endif
|
||||
continue;
|
||||
|
||||
format_set(pf, f);
|
||||
@@ -777,6 +795,7 @@ gp_ga8(Pixel *p, png_const_voidp pb)
|
||||
p->a = pp[1];
|
||||
}
|
||||
|
||||
#ifdef PNG_FORMAT_AFIRST_SUPPORTED
|
||||
static void
|
||||
gp_ag8(Pixel *p, png_const_voidp pb)
|
||||
{
|
||||
@@ -785,6 +804,7 @@ gp_ag8(Pixel *p, png_const_voidp pb)
|
||||
p->r = p->g = p->b = pp[1];
|
||||
p->a = pp[0];
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
gp_rgb8(Pixel *p, png_const_voidp pb)
|
||||
@@ -797,6 +817,7 @@ gp_rgb8(Pixel *p, png_const_voidp pb)
|
||||
p->a = 255;
|
||||
}
|
||||
|
||||
#ifdef PNG_FORMAT_BGR_SUPPORTED
|
||||
static void
|
||||
gp_bgr8(Pixel *p, png_const_voidp pb)
|
||||
{
|
||||
@@ -807,6 +828,7 @@ gp_bgr8(Pixel *p, png_const_voidp pb)
|
||||
p->b = pp[0];
|
||||
p->a = 255;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
gp_rgba8(Pixel *p, png_const_voidp pb)
|
||||
@@ -819,6 +841,7 @@ gp_rgba8(Pixel *p, png_const_voidp pb)
|
||||
p->a = pp[3];
|
||||
}
|
||||
|
||||
#ifdef PNG_FORMAT_BGR_SUPPORTED
|
||||
static void
|
||||
gp_bgra8(Pixel *p, png_const_voidp pb)
|
||||
{
|
||||
@@ -829,7 +852,9 @@ gp_bgra8(Pixel *p, png_const_voidp pb)
|
||||
p->b = pp[0];
|
||||
p->a = pp[3];
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PNG_FORMAT_AFIRST_SUPPORTED
|
||||
static void
|
||||
gp_argb8(Pixel *p, png_const_voidp pb)
|
||||
{
|
||||
@@ -840,7 +865,9 @@ gp_argb8(Pixel *p, png_const_voidp pb)
|
||||
p->b = pp[3];
|
||||
p->a = pp[0];
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_FORMAT_AFIRST_SUPPORTED) && defined(PNG_FORMAT_BGR_SUPPORTED)
|
||||
static void
|
||||
gp_abgr8(Pixel *p, png_const_voidp pb)
|
||||
{
|
||||
@@ -851,6 +878,7 @@ gp_abgr8(Pixel *p, png_const_voidp pb)
|
||||
p->b = pp[1];
|
||||
p->a = pp[0];
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
gp_g16(Pixel *p, png_const_voidp pb)
|
||||
@@ -870,6 +898,7 @@ gp_ga16(Pixel *p, png_const_voidp pb)
|
||||
p->a = pp[1];
|
||||
}
|
||||
|
||||
#ifdef PNG_FORMAT_AFIRST_SUPPORTED
|
||||
static void
|
||||
gp_ag16(Pixel *p, png_const_voidp pb)
|
||||
{
|
||||
@@ -878,6 +907,7 @@ gp_ag16(Pixel *p, png_const_voidp pb)
|
||||
p->r = p->g = p->b = pp[1];
|
||||
p->a = pp[0];
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
gp_rgb16(Pixel *p, png_const_voidp pb)
|
||||
@@ -890,6 +920,7 @@ gp_rgb16(Pixel *p, png_const_voidp pb)
|
||||
p->a = 65535;
|
||||
}
|
||||
|
||||
#ifdef PNG_FORMAT_BGR_SUPPORTED
|
||||
static void
|
||||
gp_bgr16(Pixel *p, png_const_voidp pb)
|
||||
{
|
||||
@@ -900,6 +931,7 @@ gp_bgr16(Pixel *p, png_const_voidp pb)
|
||||
p->b = pp[0];
|
||||
p->a = 65535;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
gp_rgba16(Pixel *p, png_const_voidp pb)
|
||||
@@ -912,6 +944,7 @@ gp_rgba16(Pixel *p, png_const_voidp pb)
|
||||
p->a = pp[3];
|
||||
}
|
||||
|
||||
#ifdef PNG_FORMAT_BGR_SUPPORTED
|
||||
static void
|
||||
gp_bgra16(Pixel *p, png_const_voidp pb)
|
||||
{
|
||||
@@ -922,7 +955,9 @@ gp_bgra16(Pixel *p, png_const_voidp pb)
|
||||
p->b = pp[0];
|
||||
p->a = pp[3];
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PNG_FORMAT_AFIRST_SUPPORTED
|
||||
static void
|
||||
gp_argb16(Pixel *p, png_const_voidp pb)
|
||||
{
|
||||
@@ -933,7 +968,9 @@ gp_argb16(Pixel *p, png_const_voidp pb)
|
||||
p->b = pp[3];
|
||||
p->a = pp[0];
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_FORMAT_AFIRST_SUPPORTED) && defined(PNG_FORMAT_BGR_SUPPORTED)
|
||||
static void
|
||||
gp_abgr16(Pixel *p, png_const_voidp pb)
|
||||
{
|
||||
@@ -944,6 +981,7 @@ gp_abgr16(Pixel *p, png_const_voidp pb)
|
||||
p->b = pp[1];
|
||||
p->a = pp[0];
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Given a format, return the correct one of the above functions. */
|
||||
static void (*
|
||||
@@ -957,29 +995,35 @@ get_pixel(png_uint_32 format))(Pixel *p, png_const_voidp pb)
|
||||
{
|
||||
if (format & PNG_FORMAT_FLAG_COLOR)
|
||||
{
|
||||
if (format & PNG_FORMAT_FLAG_BGR)
|
||||
{
|
||||
if (format & PNG_FORMAT_FLAG_ALPHA)
|
||||
# ifdef PNG_FORMAT_BGR_SUPPORTED
|
||||
if (format & PNG_FORMAT_FLAG_BGR)
|
||||
{
|
||||
if (format & PNG_FORMAT_FLAG_AFIRST)
|
||||
return gp_abgr16;
|
||||
if (format & PNG_FORMAT_FLAG_ALPHA)
|
||||
{
|
||||
# ifdef PNG_FORMAT_AFIRST_SUPPORTED
|
||||
if (format & PNG_FORMAT_FLAG_AFIRST)
|
||||
return gp_abgr16;
|
||||
|
||||
else
|
||||
# endif
|
||||
return gp_bgra16;
|
||||
}
|
||||
|
||||
else
|
||||
return gp_bgra16;
|
||||
return gp_bgr16;
|
||||
}
|
||||
|
||||
else
|
||||
return gp_bgr16;
|
||||
}
|
||||
|
||||
else
|
||||
# endif
|
||||
{
|
||||
if (format & PNG_FORMAT_FLAG_ALPHA)
|
||||
{
|
||||
if (format & PNG_FORMAT_FLAG_AFIRST)
|
||||
return gp_argb16;
|
||||
# ifdef PNG_FORMAT_AFIRST_SUPPORTED
|
||||
if (format & PNG_FORMAT_FLAG_AFIRST)
|
||||
return gp_argb16;
|
||||
|
||||
else
|
||||
else
|
||||
# endif
|
||||
return gp_rgba16;
|
||||
}
|
||||
|
||||
@@ -992,10 +1036,12 @@ get_pixel(png_uint_32 format))(Pixel *p, png_const_voidp pb)
|
||||
{
|
||||
if (format & PNG_FORMAT_FLAG_ALPHA)
|
||||
{
|
||||
if (format & PNG_FORMAT_FLAG_AFIRST)
|
||||
return gp_ag16;
|
||||
# ifdef PNG_FORMAT_AFIRST_SUPPORTED
|
||||
if (format & PNG_FORMAT_FLAG_AFIRST)
|
||||
return gp_ag16;
|
||||
|
||||
else
|
||||
else
|
||||
# endif
|
||||
return gp_ga16;
|
||||
}
|
||||
|
||||
@@ -1008,29 +1054,35 @@ get_pixel(png_uint_32 format))(Pixel *p, png_const_voidp pb)
|
||||
{
|
||||
if (format & PNG_FORMAT_FLAG_COLOR)
|
||||
{
|
||||
if (format & PNG_FORMAT_FLAG_BGR)
|
||||
{
|
||||
if (format & PNG_FORMAT_FLAG_ALPHA)
|
||||
# ifdef PNG_FORMAT_BGR_SUPPORTED
|
||||
if (format & PNG_FORMAT_FLAG_BGR)
|
||||
{
|
||||
if (format & PNG_FORMAT_FLAG_AFIRST)
|
||||
return gp_abgr8;
|
||||
if (format & PNG_FORMAT_FLAG_ALPHA)
|
||||
{
|
||||
# ifdef PNG_FORMAT_AFIRST_SUPPORTED
|
||||
if (format & PNG_FORMAT_FLAG_AFIRST)
|
||||
return gp_abgr8;
|
||||
|
||||
else
|
||||
# endif
|
||||
return gp_bgra8;
|
||||
}
|
||||
|
||||
else
|
||||
return gp_bgra8;
|
||||
return gp_bgr8;
|
||||
}
|
||||
|
||||
else
|
||||
return gp_bgr8;
|
||||
}
|
||||
|
||||
else
|
||||
# endif
|
||||
{
|
||||
if (format & PNG_FORMAT_FLAG_ALPHA)
|
||||
{
|
||||
if (format & PNG_FORMAT_FLAG_AFIRST)
|
||||
return gp_argb8;
|
||||
# ifdef PNG_FORMAT_AFIRST_SUPPORTED
|
||||
if (format & PNG_FORMAT_FLAG_AFIRST)
|
||||
return gp_argb8;
|
||||
|
||||
else
|
||||
else
|
||||
# endif
|
||||
return gp_rgba8;
|
||||
}
|
||||
|
||||
@@ -1043,10 +1095,12 @@ get_pixel(png_uint_32 format))(Pixel *p, png_const_voidp pb)
|
||||
{
|
||||
if (format & PNG_FORMAT_FLAG_ALPHA)
|
||||
{
|
||||
if (format & PNG_FORMAT_FLAG_AFIRST)
|
||||
return gp_ag8;
|
||||
# ifdef PNG_FORMAT_AFIRST_SUPPORTED
|
||||
if (format & PNG_FORMAT_FLAG_AFIRST)
|
||||
return gp_ag8;
|
||||
|
||||
else
|
||||
else
|
||||
# endif
|
||||
return gp_ga8;
|
||||
}
|
||||
|
||||
@@ -2609,13 +2663,15 @@ component_loc(png_byte loc[4], png_uint_32 format)
|
||||
|
||||
loc[2] = 1;
|
||||
|
||||
if (format & PNG_FORMAT_FLAG_BGR)
|
||||
{
|
||||
loc[1] = 2;
|
||||
loc[3] = 0;
|
||||
}
|
||||
# ifdef PNG_FORMAT_BGR_SUPPORTED
|
||||
if (format & PNG_FORMAT_FLAG_BGR)
|
||||
{
|
||||
loc[1] = 2;
|
||||
loc[3] = 0;
|
||||
}
|
||||
|
||||
else
|
||||
else
|
||||
# endif
|
||||
{
|
||||
loc[1] = 0;
|
||||
loc[3] = 2;
|
||||
@@ -2630,15 +2686,17 @@ component_loc(png_byte loc[4], png_uint_32 format)
|
||||
|
||||
if (format & PNG_FORMAT_FLAG_ALPHA)
|
||||
{
|
||||
if (format & PNG_FORMAT_FLAG_AFIRST)
|
||||
{
|
||||
loc[0] = 0;
|
||||
++loc[1];
|
||||
++loc[2];
|
||||
++loc[3];
|
||||
}
|
||||
# ifdef PNG_FORMAT_AFIRST_SUPPORTED
|
||||
if (format & PNG_FORMAT_FLAG_AFIRST)
|
||||
{
|
||||
loc[0] = 0;
|
||||
++loc[1];
|
||||
++loc[2];
|
||||
++loc[3];
|
||||
}
|
||||
|
||||
else
|
||||
else
|
||||
# endif
|
||||
loc[0] = channels;
|
||||
|
||||
++channels;
|
||||
@@ -3008,17 +3066,29 @@ read_file(Image *image, png_uint_32 format, png_const_colorp background)
|
||||
return logerror(image, "memory init: ", image->file_name, "");
|
||||
}
|
||||
|
||||
else if (image->input_file != NULL)
|
||||
{
|
||||
if (!png_image_begin_read_from_stdio(&image->image, image->input_file))
|
||||
return logerror(image, "stdio init: ", image->file_name, "");
|
||||
}
|
||||
# ifdef PNG_STDIO_SUPPORTED
|
||||
else if (image->input_file != NULL)
|
||||
{
|
||||
if (!png_image_begin_read_from_stdio(&image->image, image->input_file))
|
||||
return logerror(image, "stdio init: ", image->file_name, "");
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
if (!png_image_begin_read_from_file(&image->image, image->file_name))
|
||||
return logerror(image, "file init: ", image->file_name, "");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!png_image_begin_read_from_file(&image->image, image->file_name))
|
||||
return logerror(image, "file init: ", image->file_name, "");
|
||||
}
|
||||
# else
|
||||
else
|
||||
{
|
||||
return logerror(image, "unsupported file/stdio init: ",
|
||||
image->file_name, "");
|
||||
}
|
||||
# endif
|
||||
|
||||
/* This must be set after the begin_read call: */
|
||||
if (image->opts & sRGB_16BIT)
|
||||
image->image.flags |= PNG_IMAGE_FLAG_16BIT_sRGB;
|
||||
|
||||
/* Have an initialized image with all the data we need plus, maybe, an
|
||||
* allocated file (myfile) or buffer (mybuffer) that need to be freed.
|
||||
@@ -3198,7 +3268,7 @@ write_one_file(Image *output, Image *image, int convert_to_8bit)
|
||||
static int counter = 0;
|
||||
char name[32];
|
||||
|
||||
sprintf(name, "TMP%d.png", ++counter);
|
||||
sprintf(name, "%s%d.png", tmpf, ++counter);
|
||||
|
||||
if (png_image_write_to_file(&image->image, name, convert_to_8bit,
|
||||
image->buffer+16, (png_int_32)image->stride, image->colormap))
|
||||
@@ -3453,11 +3523,19 @@ main(int argc, char **argv)
|
||||
memset(gpc_error_via_linear, 0, sizeof gpc_error_via_linear);
|
||||
}
|
||||
else if (strcmp(arg, "--file") == 0)
|
||||
opts |= READ_FILE;
|
||||
# ifdef PNG_STDIO_SUPPORTED
|
||||
opts |= READ_FILE;
|
||||
# else
|
||||
return 77; /* skipped: no support */
|
||||
# endif
|
||||
else if (strcmp(arg, "--memory") == 0)
|
||||
opts &= ~READ_FILE;
|
||||
else if (strcmp(arg, "--stdio") == 0)
|
||||
opts |= USE_STDIO;
|
||||
# ifdef PNG_STDIO_SUPPORTED
|
||||
opts |= USE_STDIO;
|
||||
# else
|
||||
return 77; /* skipped: no support */
|
||||
# endif
|
||||
else if (strcmp(arg, "--name") == 0)
|
||||
opts &= ~USE_STDIO;
|
||||
else if (strcmp(arg, "--verbose") == 0)
|
||||
@@ -3482,6 +3560,34 @@ main(int argc, char **argv)
|
||||
opts &= ~KEEP_GOING;
|
||||
else if (strcmp(arg, "--strict") == 0)
|
||||
opts |= STRICT;
|
||||
else if (strcmp(arg, "--sRGB-16bit") == 0)
|
||||
opts |= sRGB_16BIT;
|
||||
else if (strcmp(arg, "--linear-16bit") == 0)
|
||||
opts &= ~sRGB_16BIT;
|
||||
else if (strcmp(arg, "--tmpfile") == 0)
|
||||
{
|
||||
if (c+1 < argc)
|
||||
{
|
||||
if (strlen(argv[++c]) >= sizeof tmpf)
|
||||
{
|
||||
fflush(stdout);
|
||||
fprintf(stderr, "%s: %s is too long for a temp file prefix\n",
|
||||
argv[0], argv[c]);
|
||||
exit(99);
|
||||
}
|
||||
|
||||
/* Safe: checked above */
|
||||
strcpy(tmpf, argv[c]);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
fflush(stdout);
|
||||
fprintf(stderr, "%s: %s requires a temporary file prefix\n",
|
||||
argv[0], arg);
|
||||
exit(99);
|
||||
}
|
||||
}
|
||||
else if (strcmp(arg, "--touch") == 0)
|
||||
{
|
||||
if (c+1 < argc)
|
||||
@@ -3492,7 +3598,7 @@ main(int argc, char **argv)
|
||||
fflush(stdout);
|
||||
fprintf(stderr, "%s: %s requires a file name argument\n",
|
||||
argv[0], arg);
|
||||
exit(1);
|
||||
exit(99);
|
||||
}
|
||||
}
|
||||
else if (arg[0] == '+')
|
||||
@@ -3500,7 +3606,7 @@ main(int argc, char **argv)
|
||||
png_uint_32 format = formatof(arg+1);
|
||||
|
||||
if (format > FORMAT_COUNT)
|
||||
exit(1);
|
||||
exit(99);
|
||||
|
||||
format_set(&formats, format);
|
||||
}
|
||||
@@ -3508,7 +3614,7 @@ main(int argc, char **argv)
|
||||
{
|
||||
fflush(stdout);
|
||||
fprintf(stderr, "%s: unknown option: %s\n", argv[0], arg);
|
||||
exit(1);
|
||||
exit(99);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -3557,7 +3663,7 @@ main(int argc, char **argv)
|
||||
buffer[4095] = 0;
|
||||
fprintf(stderr, "%s...%s: file name too long\n", buffer,
|
||||
buffer+(4096-32));
|
||||
exit(1);
|
||||
exit(99);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3676,7 +3782,7 @@ main(int argc, char **argv)
|
||||
{
|
||||
fflush(stdout);
|
||||
fprintf(stderr, "%s: write failed\n", touch);
|
||||
exit(1);
|
||||
exit(99);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3684,7 +3790,7 @@ main(int argc, char **argv)
|
||||
{
|
||||
fflush(stdout);
|
||||
fprintf(stderr, "%s: open failed\n", touch);
|
||||
exit(1);
|
||||
exit(99);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3695,6 +3801,7 @@ main(int argc, char **argv)
|
||||
int main(void)
|
||||
{
|
||||
fprintf(stderr, "pngstest: no read support in libpng, test skipped\n");
|
||||
return 0;
|
||||
/* So the test is skipped: */
|
||||
return 77;
|
||||
}
|
||||
#endif /* PNG_SIMPLIFIED_READ_SUPPORTED */
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
|
||||
/* pngunknown.c - test the read side unknown chunk handling
|
||||
*
|
||||
* Last changed in libpng 1.6.0 [(PENDING RELEASE)]
|
||||
* Copyright (c) 2012 Glenn Randers-Pehrson
|
||||
* Last changed in libpng 1.6.10 [March 6, 2014]
|
||||
* Copyright (c) 2014 Glenn Randers-Pehrson
|
||||
* Written by John Cunningham Bowler
|
||||
*
|
||||
* This code is released under the libpng license.
|
||||
@@ -30,7 +30,19 @@
|
||||
# include "../../png.h"
|
||||
#endif
|
||||
|
||||
#ifdef PNG_READ_SUPPORTED
|
||||
/* Since this program tests the ability to change the unknown chunk handling
|
||||
* these must be defined:
|
||||
*/
|
||||
#if defined(PNG_SET_UNKNOWN_CHUNKS_SUPPORTED) &&\
|
||||
defined(PNG_READ_SUPPORTED)
|
||||
|
||||
/* One of these must be defined to allow us to find out what happened. It is
|
||||
* still useful to set unknown chunk handling without either of these in order
|
||||
* to cause *known* chunks to be discarded. This can be a significant
|
||||
* efficiency gain, but it can't really be tested here.
|
||||
*/
|
||||
#if defined(PNG_READ_USER_CHUNKS_SUPPORTED) ||\
|
||||
defined(PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED)
|
||||
|
||||
#if PNG_LIBPNG_VER < 10500
|
||||
/* This deliberately lacks the PNG_CONST. */
|
||||
@@ -75,43 +87,74 @@ typedef png_byte *png_const_bytep;
|
||||
# define png_const_structp png_structp
|
||||
#endif
|
||||
|
||||
#if PNG_LIBPNG_VER < 10700
|
||||
/* Copied from libpng 1.7.0 png.h */
|
||||
#define PNG_u2(b1, b2) (((unsigned int)(b1) << 8) + (b2))
|
||||
|
||||
/* Copied from pngpriv.h */
|
||||
#define PNG_32b(b,s) ((png_uint_32)(b) << (s))
|
||||
#define PNG_CHUNK(b1,b2,b3,b4) \
|
||||
(PNG_32b(b1,24) | PNG_32b(b2,16) | PNG_32b(b3,8) | PNG_32b(b4,0))
|
||||
#define PNG_U16(b1, b2) ((png_uint_16)PNG_u2(b1, b2))
|
||||
#define PNG_U32(b1, b2, b3, b4)\
|
||||
(((png_uint_32)PNG_u2(b1, b2) << 16) + PNG_u2(b3, b4))
|
||||
|
||||
#define png_IHDR PNG_CHUNK( 73, 72, 68, 82)
|
||||
#define png_IDAT PNG_CHUNK( 73, 68, 65, 84)
|
||||
#define png_IEND PNG_CHUNK( 73, 69, 78, 68)
|
||||
#define png_PLTE PNG_CHUNK( 80, 76, 84, 69)
|
||||
#define png_bKGD PNG_CHUNK( 98, 75, 71, 68)
|
||||
#define png_cHRM PNG_CHUNK( 99, 72, 82, 77)
|
||||
#define png_gAMA PNG_CHUNK(103, 65, 77, 65)
|
||||
#define png_hIST PNG_CHUNK(104, 73, 83, 84)
|
||||
#define png_iCCP PNG_CHUNK(105, 67, 67, 80)
|
||||
#define png_iTXt PNG_CHUNK(105, 84, 88, 116)
|
||||
#define png_oFFs PNG_CHUNK(111, 70, 70, 115)
|
||||
#define png_pCAL PNG_CHUNK(112, 67, 65, 76)
|
||||
#define png_sCAL PNG_CHUNK(115, 67, 65, 76)
|
||||
#define png_pHYs PNG_CHUNK(112, 72, 89, 115)
|
||||
#define png_sBIT PNG_CHUNK(115, 66, 73, 84)
|
||||
#define png_sPLT PNG_CHUNK(115, 80, 76, 84)
|
||||
#define png_sRGB PNG_CHUNK(115, 82, 71, 66)
|
||||
#define png_sTER PNG_CHUNK(115, 84, 69, 82)
|
||||
#define png_tEXt PNG_CHUNK(116, 69, 88, 116)
|
||||
#define png_tIME PNG_CHUNK(116, 73, 77, 69)
|
||||
#define png_tRNS PNG_CHUNK(116, 82, 78, 83)
|
||||
#define png_zTXt PNG_CHUNK(122, 84, 88, 116)
|
||||
#define png_vpAg PNG_CHUNK('v', 'p', 'A', 'g')
|
||||
/* Constants for known chunk types.
|
||||
*/
|
||||
#define png_IDAT PNG_U32( 73, 68, 65, 84)
|
||||
#define png_IEND PNG_U32( 73, 69, 78, 68)
|
||||
#define png_IHDR PNG_U32( 73, 72, 68, 82)
|
||||
#define png_PLTE PNG_U32( 80, 76, 84, 69)
|
||||
#define png_bKGD PNG_U32( 98, 75, 71, 68)
|
||||
#define png_cHRM PNG_U32( 99, 72, 82, 77)
|
||||
#define png_fRAc PNG_U32(102, 82, 65, 99) /* registered, not defined */
|
||||
#define png_gAMA PNG_U32(103, 65, 77, 65)
|
||||
#define png_gIFg PNG_U32(103, 73, 70, 103)
|
||||
#define png_gIFt PNG_U32(103, 73, 70, 116) /* deprecated */
|
||||
#define png_gIFx PNG_U32(103, 73, 70, 120)
|
||||
#define png_hIST PNG_U32(104, 73, 83, 84)
|
||||
#define png_iCCP PNG_U32(105, 67, 67, 80)
|
||||
#define png_iTXt PNG_U32(105, 84, 88, 116)
|
||||
#define png_oFFs PNG_U32(111, 70, 70, 115)
|
||||
#define png_pCAL PNG_U32(112, 67, 65, 76)
|
||||
#define png_pHYs PNG_U32(112, 72, 89, 115)
|
||||
#define png_sBIT PNG_U32(115, 66, 73, 84)
|
||||
#define png_sCAL PNG_U32(115, 67, 65, 76)
|
||||
#define png_sPLT PNG_U32(115, 80, 76, 84)
|
||||
#define png_sRGB PNG_U32(115, 82, 71, 66)
|
||||
#define png_sTER PNG_U32(115, 84, 69, 82)
|
||||
#define png_tEXt PNG_U32(116, 69, 88, 116)
|
||||
#define png_tIME PNG_U32(116, 73, 77, 69)
|
||||
#define png_tRNS PNG_U32(116, 82, 78, 83)
|
||||
#define png_zTXt PNG_U32(122, 84, 88, 116)
|
||||
|
||||
/* Test on flag values as defined in the spec (section 5.4): */
|
||||
#define PNG_CHUNK_ANCILLARY(c ) (1 & ((c) >> 29))
|
||||
#define PNG_CHUNK_ANCILLARY(c) (1 & ((c) >> 29))
|
||||
#define PNG_CHUNK_CRITICAL(c) (!PNG_CHUNK_ANCILLARY(c))
|
||||
#define PNG_CHUNK_PRIVATE(c) (1 & ((c) >> 21))
|
||||
#define PNG_CHUNK_RESERVED(c) (1 & ((c) >> 13))
|
||||
#define PNG_CHUNK_SAFE_TO_COPY(c) (1 & ((c) >> 5))
|
||||
|
||||
#endif /* PNG_LIBPNG_VER < 10700 */
|
||||
|
||||
#ifdef __cplusplus
|
||||
# define this not_the_cpp_this
|
||||
# define new not_the_cpp_new
|
||||
# define voidcast(type, value) static_cast<type>(value)
|
||||
#else
|
||||
# define voidcast(type, value) (value)
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/* Unused formal parameter errors are removed using the following macro which is
|
||||
* expected to have no bad effects on performance.
|
||||
*/
|
||||
#ifndef UNUSED
|
||||
# if defined(__GNUC__) || defined(_MSC_VER)
|
||||
# define UNUSED(param) (void)param;
|
||||
# else
|
||||
# define UNUSED(param)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Types of chunks not known to libpng */
|
||||
#define png_vpAg PNG_U32(118, 112, 65, 103)
|
||||
|
||||
/* Chunk information */
|
||||
#define PNG_INFO_tEXt 0x10000000U
|
||||
#define PNG_INFO_iTXt 0x20000000U
|
||||
@@ -139,23 +182,128 @@ static struct
|
||||
{ "PLTE", PNG_INFO_PLTE, png_PLTE, 0, 0, ABSENT, 0 },
|
||||
|
||||
/* Non-critical chunks that libpng handles */
|
||||
{ "bKGD", PNG_INFO_bKGD, png_bKGD, 0, 1, START, 0 },
|
||||
{ "cHRM", PNG_INFO_cHRM, png_cHRM, 0, 1, START, 0 },
|
||||
{ "gAMA", PNG_INFO_gAMA, png_gAMA, 0, 1, START, 0 },
|
||||
{ "hIST", PNG_INFO_hIST, png_hIST, 0, 1, ABSENT, 0 },
|
||||
{ "iCCP", PNG_INFO_iCCP, png_iCCP, 0, 1, ABSENT, 0 },
|
||||
{ "iTXt", PNG_INFO_iTXt, png_iTXt, 0, 1, ABSENT, 0 },
|
||||
{ "oFFs", PNG_INFO_oFFs, png_oFFs, 0, 1, START, 0 },
|
||||
{ "pCAL", PNG_INFO_pCAL, png_pCAL, 0, 1, START, 0 },
|
||||
{ "pHYs", PNG_INFO_pHYs, png_pHYs, 0, 1, START, 0 },
|
||||
{ "sBIT", PNG_INFO_sBIT, png_sBIT, 0, 1, START, 0 },
|
||||
{ "sCAL", PNG_INFO_sCAL, png_sCAL, 0, 1, START, 0 },
|
||||
{ "sPLT", PNG_INFO_sPLT, png_sPLT, 0, 1, ABSENT, 0 },
|
||||
{ "sRGB", PNG_INFO_sRGB, png_sRGB, 0, 1, START, 0 },
|
||||
{ "tEXt", PNG_INFO_tEXt, png_tEXt, 0, 1, START, 0 },
|
||||
{ "tIME", PNG_INFO_tIME, png_tIME, 0, 1, START, 0 },
|
||||
{ "tRNS", PNG_INFO_tRNS, png_tRNS, 0, 0, ABSENT, 0 },
|
||||
{ "zTXt", PNG_INFO_zTXt, png_zTXt, 0, 1, END, 0 },
|
||||
/* This is a mess but it seems to be the only way to do it - there is no way
|
||||
* to check for a definition outside a #if.
|
||||
*/
|
||||
{ "bKGD", PNG_INFO_bKGD, png_bKGD,
|
||||
# ifdef PNG_READ_bKGD_SUPPORTED
|
||||
0,
|
||||
# else
|
||||
1,
|
||||
# endif
|
||||
1, START, 0 },
|
||||
{ "cHRM", PNG_INFO_cHRM, png_cHRM,
|
||||
# ifdef PNG_READ_cHRM_SUPPORTED
|
||||
0,
|
||||
# else
|
||||
1,
|
||||
# endif
|
||||
1, START, 0 },
|
||||
{ "gAMA", PNG_INFO_gAMA, png_gAMA,
|
||||
# ifdef PNG_READ_gAMA_SUPPORTED
|
||||
0,
|
||||
# else
|
||||
1,
|
||||
# endif
|
||||
1, START, 0 },
|
||||
{ "hIST", PNG_INFO_hIST, png_hIST,
|
||||
# ifdef PNG_READ_hIST_SUPPORTED
|
||||
0,
|
||||
# else
|
||||
1,
|
||||
# endif
|
||||
1, ABSENT, 0 },
|
||||
{ "iCCP", PNG_INFO_iCCP, png_iCCP,
|
||||
# ifdef PNG_READ_iCCP_SUPPORTED
|
||||
0,
|
||||
# else
|
||||
1,
|
||||
# endif
|
||||
1, ABSENT, 0 },
|
||||
{ "iTXt", PNG_INFO_iTXt, png_iTXt,
|
||||
# ifdef PNG_READ_iTXt_SUPPORTED
|
||||
0,
|
||||
# else
|
||||
1,
|
||||
# endif
|
||||
1, ABSENT, 0 },
|
||||
{ "oFFs", PNG_INFO_oFFs, png_oFFs,
|
||||
# ifdef PNG_READ_oFFs_SUPPORTED
|
||||
0,
|
||||
# else
|
||||
1,
|
||||
# endif
|
||||
1, START, 0 },
|
||||
{ "pCAL", PNG_INFO_pCAL, png_pCAL,
|
||||
# ifdef PNG_READ_pCAL_SUPPORTED
|
||||
0,
|
||||
# else
|
||||
1,
|
||||
# endif
|
||||
1, START, 0 },
|
||||
{ "pHYs", PNG_INFO_pHYs, png_pHYs,
|
||||
# ifdef PNG_READ_pHYs_SUPPORTED
|
||||
0,
|
||||
# else
|
||||
1,
|
||||
# endif
|
||||
1, START, 0 },
|
||||
{ "sBIT", PNG_INFO_sBIT, png_sBIT,
|
||||
# ifdef PNG_READ_sBIT_SUPPORTED
|
||||
0,
|
||||
# else
|
||||
1,
|
||||
# endif
|
||||
1, START, 0 },
|
||||
{ "sCAL", PNG_INFO_sCAL, png_sCAL,
|
||||
# ifdef PNG_READ_sCAL_SUPPORTED
|
||||
0,
|
||||
# else
|
||||
1,
|
||||
# endif
|
||||
1, START, 0 },
|
||||
{ "sPLT", PNG_INFO_sPLT, png_sPLT,
|
||||
# ifdef PNG_READ_sPLT_SUPPORTED
|
||||
0,
|
||||
# else
|
||||
1,
|
||||
# endif
|
||||
1, ABSENT, 0 },
|
||||
{ "sRGB", PNG_INFO_sRGB, png_sRGB,
|
||||
# ifdef PNG_READ_sRGB_SUPPORTED
|
||||
0,
|
||||
# else
|
||||
1,
|
||||
# endif
|
||||
1, START, 0 },
|
||||
{ "tEXt", PNG_INFO_tEXt, png_tEXt,
|
||||
# ifdef PNG_READ_tEXt_SUPPORTED
|
||||
0,
|
||||
# else
|
||||
1,
|
||||
# endif
|
||||
1, START, 0 },
|
||||
{ "tIME", PNG_INFO_tIME, png_tIME,
|
||||
# ifdef PNG_READ_tIME_SUPPORTED
|
||||
0,
|
||||
# else
|
||||
1,
|
||||
# endif
|
||||
1, START, 0 },
|
||||
{ "tRNS", PNG_INFO_tRNS, png_tRNS,
|
||||
# ifdef PNG_READ_tRNS_SUPPORTED
|
||||
0,
|
||||
# else
|
||||
1,
|
||||
# endif
|
||||
0, ABSENT, 0 },
|
||||
{ "zTXt", PNG_INFO_zTXt, png_zTXt,
|
||||
# ifdef PNG_READ_zTXt_SUPPORTED
|
||||
0,
|
||||
# else
|
||||
1,
|
||||
# endif
|
||||
1, END, 0 },
|
||||
|
||||
/* No libpng handling */
|
||||
{ "sTER", PNG_INFO_sTER, png_sTER, 1, 1, START, 0 },
|
||||
@@ -212,14 +360,16 @@ find_by_flag(png_uint_32 flag)
|
||||
static int
|
||||
ancillary(const char *name)
|
||||
{
|
||||
return PNG_CHUNK_ANCILLARY(PNG_CHUNK(name[0], name[1], name[2], name[3]));
|
||||
return PNG_CHUNK_ANCILLARY(PNG_U32(name[0], name[1], name[2], name[3]));
|
||||
}
|
||||
|
||||
#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
|
||||
static int
|
||||
ancillaryb(const png_byte *name)
|
||||
{
|
||||
return PNG_CHUNK_ANCILLARY(PNG_CHUNK(name[0], name[1], name[2], name[3]));
|
||||
return PNG_CHUNK_ANCILLARY(PNG_U32(name[0], name[1], name[2], name[3]));
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Type of an error_ptr */
|
||||
typedef struct
|
||||
@@ -227,8 +377,11 @@ typedef struct
|
||||
jmp_buf error_return;
|
||||
png_structp png_ptr;
|
||||
png_infop info_ptr, end_ptr;
|
||||
png_uint_32 before_IDAT;
|
||||
png_uint_32 after_IDAT;
|
||||
int error_count;
|
||||
int warning_count;
|
||||
int keep; /* the default value */
|
||||
const char *program;
|
||||
const char *file;
|
||||
const char *test;
|
||||
@@ -261,9 +414,6 @@ clean_display(display *d)
|
||||
d->test);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Invalidate the test */
|
||||
d->test = init;
|
||||
}
|
||||
|
||||
PNG_FUNCTION(void, display_exit, (display *d), static PNG_NORETURN)
|
||||
@@ -289,7 +439,7 @@ display_rc(const display *d, int strict)
|
||||
}
|
||||
|
||||
/* libpng error and warning callbacks */
|
||||
PNG_FUNCTION(void, error, (png_structp png_ptr, const char *message),
|
||||
PNG_FUNCTION(void, (PNGCBAPI error), (png_structp png_ptr, const char *message),
|
||||
static PNG_NORETURN)
|
||||
{
|
||||
display *d = (display*)png_get_error_ptr(png_ptr);
|
||||
@@ -298,7 +448,7 @@ PNG_FUNCTION(void, error, (png_structp png_ptr, const char *message),
|
||||
display_exit(d);
|
||||
}
|
||||
|
||||
static void
|
||||
static void PNGCBAPI
|
||||
warning(png_structp png_ptr, const char *message)
|
||||
{
|
||||
display *d = (display*)png_get_error_ptr(png_ptr);
|
||||
@@ -308,7 +458,7 @@ warning(png_structp png_ptr, const char *message)
|
||||
}
|
||||
|
||||
static png_uint_32
|
||||
get_valid(display *d, png_const_infop info_ptr)
|
||||
get_valid(display *d, png_infop info_ptr)
|
||||
{
|
||||
png_uint_32 flags = png_get_valid(d->png_ptr, info_ptr, (png_uint_32)~0);
|
||||
|
||||
@@ -339,11 +489,88 @@ get_valid(display *d, png_const_infop info_ptr)
|
||||
return flags;
|
||||
}
|
||||
|
||||
#ifdef PNG_READ_USER_CHUNKS_SUPPORTED
|
||||
static int PNGCBAPI
|
||||
read_callback(png_structp pp, png_unknown_chunkp pc)
|
||||
{
|
||||
/* This function mimics the behavior of png_set_keep_unknown_chunks by
|
||||
* returning '0' to keep the chunk and '1' to discard it.
|
||||
*/
|
||||
display *d = voidcast(display*, png_get_user_chunk_ptr(pp));
|
||||
int chunk = findb(pc->name);
|
||||
int keep, discard;
|
||||
|
||||
if (chunk < 0) /* not one in our list, so not a known chunk */
|
||||
keep = d->keep;
|
||||
|
||||
else
|
||||
{
|
||||
keep = chunk_info[chunk].keep;
|
||||
if (keep == PNG_HANDLE_CHUNK_AS_DEFAULT)
|
||||
{
|
||||
/* See the comments in png.h - use the default for unknown chunks,
|
||||
* do not keep known chunks.
|
||||
*/
|
||||
if (chunk_info[chunk].unknown)
|
||||
keep = d->keep;
|
||||
|
||||
else
|
||||
keep = PNG_HANDLE_CHUNK_NEVER;
|
||||
}
|
||||
}
|
||||
|
||||
switch (keep)
|
||||
{
|
||||
default:
|
||||
fprintf(stderr, "%s(%s): %d: unrecognized chunk option\n", d->file,
|
||||
d->test, chunk_info[chunk].keep);
|
||||
display_exit(d);
|
||||
|
||||
case PNG_HANDLE_CHUNK_AS_DEFAULT:
|
||||
case PNG_HANDLE_CHUNK_NEVER:
|
||||
discard = 1/*handled; discard*/;
|
||||
break;
|
||||
|
||||
case PNG_HANDLE_CHUNK_IF_SAFE:
|
||||
case PNG_HANDLE_CHUNK_ALWAYS:
|
||||
discard = 0/*not handled; keep*/;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Also store information about this chunk in the display, the relevant flag
|
||||
* is set if the chunk is to be kept ('not handled'.)
|
||||
*/
|
||||
if (chunk >= 0) if (!discard) /* stupidity to stop a GCC warning */
|
||||
{
|
||||
png_uint_32 flag = chunk_info[chunk].flag;
|
||||
|
||||
if (pc->location & PNG_AFTER_IDAT)
|
||||
d->after_IDAT |= flag;
|
||||
|
||||
else
|
||||
d->before_IDAT |= flag;
|
||||
}
|
||||
|
||||
/* However if there is no support to store unknown chunks don't ask libpng to
|
||||
* do it; there will be an png_error.
|
||||
*/
|
||||
# ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
|
||||
return discard;
|
||||
# else
|
||||
return 1; /*handled; discard*/
|
||||
# endif
|
||||
}
|
||||
#endif /* READ_USER_CHUNKS_SUPPORTED */
|
||||
|
||||
#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
|
||||
static png_uint_32
|
||||
get_unknown(display *d, int def, png_const_infop info_ptr)
|
||||
get_unknown(display *d, png_infop info_ptr, int after_IDAT)
|
||||
{
|
||||
/* Create corresponding 'unknown' flags */
|
||||
png_uint_32 flags = 0;
|
||||
|
||||
UNUSED(after_IDAT)
|
||||
|
||||
{
|
||||
png_unknown_chunkp unknown;
|
||||
int num_unknown = png_get_unknown_chunks(d->png_ptr, info_ptr, &unknown);
|
||||
@@ -353,16 +580,16 @@ get_unknown(display *d, int def, png_const_infop info_ptr)
|
||||
int chunk = findb(unknown[num_unknown].name);
|
||||
|
||||
/* Chunks not known to pngunknown must be validated here; since they
|
||||
* must also be unknown to libpng the 'def' behavior should have been
|
||||
* used.
|
||||
* must also be unknown to libpng the 'display->keep' behavior should
|
||||
* have been used.
|
||||
*/
|
||||
if (chunk < 0) switch (def)
|
||||
if (chunk < 0) switch (d->keep)
|
||||
{
|
||||
default: /* impossible */
|
||||
case PNG_HANDLE_CHUNK_AS_DEFAULT:
|
||||
case PNG_HANDLE_CHUNK_NEVER:
|
||||
fprintf(stderr, "%s(%s): %s: %s: unknown chunk saved\n",
|
||||
d->file, d->test, def ? "discard" : "default",
|
||||
d->file, d->test, d->keep ? "discard" : "default",
|
||||
unknown[num_unknown].name);
|
||||
++(d->error_count);
|
||||
break;
|
||||
@@ -388,14 +615,39 @@ get_unknown(display *d, int def, png_const_infop info_ptr)
|
||||
|
||||
return flags;
|
||||
}
|
||||
#else
|
||||
static png_uint_32
|
||||
get_unknown(display *d, png_infop info_ptr, int after_IDAT)
|
||||
/* Otherwise this will return the cached values set by any user callback */
|
||||
{
|
||||
UNUSED(info_ptr);
|
||||
|
||||
if (after_IDAT)
|
||||
return d->after_IDAT;
|
||||
|
||||
else
|
||||
return d->before_IDAT;
|
||||
}
|
||||
|
||||
# ifndef PNG_READ_USER_CHUNKS_SUPPORTED
|
||||
/* The #defines above should mean this is never reached, it's just here as
|
||||
* a check to ensure the logic is correct.
|
||||
*/
|
||||
# error No store support and no user chunk support, this will not work
|
||||
# endif
|
||||
#endif
|
||||
|
||||
static int
|
||||
check(FILE *fp, int argc, const char **argv, png_uint_32p flags/*out*/,
|
||||
display *d)
|
||||
display *d, int set_callback)
|
||||
{
|
||||
int i, def = PNG_HANDLE_CHUNK_AS_DEFAULT, npasses, ipass;
|
||||
int i, npasses, ipass;
|
||||
png_uint_32 height;
|
||||
|
||||
d->keep = PNG_HANDLE_CHUNK_AS_DEFAULT;
|
||||
d->before_IDAT = 0;
|
||||
d->after_IDAT = 0;
|
||||
|
||||
/* Some of these errors are permanently fatal and cause an exit here, others
|
||||
* are per-test and cause an error return.
|
||||
*/
|
||||
@@ -421,6 +673,16 @@ check(FILE *fp, int argc, const char **argv, png_uint_32p flags/*out*/,
|
||||
|
||||
png_init_io(d->png_ptr, fp);
|
||||
|
||||
# ifdef PNG_READ_USER_CHUNKS_SUPPORTED
|
||||
/* This is only done if requested by the caller; it interferes with the
|
||||
* standard store/save mechanism.
|
||||
*/
|
||||
if (set_callback)
|
||||
png_set_read_user_chunk_fn(d->png_ptr, d, read_callback);
|
||||
# else
|
||||
UNUSED(set_callback)
|
||||
# endif
|
||||
|
||||
/* Handle each argument in turn; multiple settings are possible for the same
|
||||
* chunk and multiple calls will occur (the last one should override all
|
||||
* preceding ones).
|
||||
@@ -460,13 +722,11 @@ check(FILE *fp, int argc, const char **argv, png_uint_32p flags/*out*/,
|
||||
* in this case, so we just check the arguments! This could
|
||||
* be improved in the future by using the read callback.
|
||||
*/
|
||||
# ifdef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED
|
||||
png_byte name[5];
|
||||
png_byte name[5];
|
||||
|
||||
memcpy(name, chunk_info[chunk].name, 5);
|
||||
png_set_keep_unknown_chunks(d->png_ptr, option, name, 1);
|
||||
chunk_info[chunk].keep = option;
|
||||
# endif
|
||||
memcpy(name, chunk_info[chunk].name, 5);
|
||||
png_set_keep_unknown_chunks(d->png_ptr, option, name, 1);
|
||||
chunk_info[chunk].keep = option;
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -475,10 +735,8 @@ check(FILE *fp, int argc, const char **argv, png_uint_32p flags/*out*/,
|
||||
case 7: /* default */
|
||||
if (memcmp(argv[i], "default", 7) == 0)
|
||||
{
|
||||
# ifdef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED
|
||||
png_set_keep_unknown_chunks(d->png_ptr, option, NULL, 0);
|
||||
# endif
|
||||
def = option;
|
||||
png_set_keep_unknown_chunks(d->png_ptr, option, NULL, 0);
|
||||
d->keep = option;
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -487,14 +745,12 @@ check(FILE *fp, int argc, const char **argv, png_uint_32p flags/*out*/,
|
||||
case 3: /* all */
|
||||
if (memcmp(argv[i], "all", 3) == 0)
|
||||
{
|
||||
# ifdef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED
|
||||
png_set_keep_unknown_chunks(d->png_ptr, option, NULL, -1);
|
||||
def = option;
|
||||
png_set_keep_unknown_chunks(d->png_ptr, option, NULL, -1);
|
||||
d->keep = option;
|
||||
|
||||
for (chunk = 0; chunk < NINFO; ++chunk)
|
||||
if (chunk_info[chunk].all)
|
||||
chunk_info[chunk].keep = option;
|
||||
# endif
|
||||
for (chunk = 0; chunk < NINFO; ++chunk)
|
||||
if (chunk_info[chunk].all)
|
||||
chunk_info[chunk].keep = option;
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -568,18 +824,18 @@ check(FILE *fp, int argc, const char **argv, png_uint_32p flags/*out*/,
|
||||
png_read_end(d->png_ptr, d->end_ptr);
|
||||
|
||||
flags[0] = get_valid(d, d->info_ptr);
|
||||
flags[1] = get_unknown(d, def, d->info_ptr);
|
||||
flags[1] = get_unknown(d, d->info_ptr, 0/*before IDAT*/);
|
||||
|
||||
/* Only png_read_png sets PNG_INFO_IDAT! */
|
||||
flags[chunk_info[0/*IDAT*/].keep != PNG_HANDLE_CHUNK_AS_DEFAULT] |=
|
||||
PNG_INFO_IDAT;
|
||||
|
||||
flags[2] = get_valid(d, d->end_ptr);
|
||||
flags[3] = get_unknown(d, def, d->end_ptr);
|
||||
flags[3] = get_unknown(d, d->end_ptr, 1/*after IDAT*/);
|
||||
|
||||
clean_display(d);
|
||||
|
||||
return def;
|
||||
return d->keep;
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -600,7 +856,7 @@ check_error(display *d, png_uint_32 flags, const char *message)
|
||||
|
||||
static void
|
||||
check_handling(display *d, int def, png_uint_32 chunks, png_uint_32 known,
|
||||
png_uint_32 unknown, const char *position)
|
||||
png_uint_32 unknown, const char *position, int set_callback)
|
||||
{
|
||||
while (chunks)
|
||||
{
|
||||
@@ -707,8 +963,9 @@ check_handling(display *d, int def, png_uint_32 chunks, png_uint_32 known,
|
||||
if (errorx != NULL)
|
||||
{
|
||||
++(d->error_count);
|
||||
fprintf(stderr, "%s(%s): %s %s %s: %s\n",
|
||||
d->file, d->test, type, chunk_info[i].name, position, errorx);
|
||||
fprintf(stderr, "%s(%s%s): %s %s %s: %s\n", d->file, d->test,
|
||||
set_callback ? ",callback" : "",
|
||||
type, chunk_info[i].name, position, errorx);
|
||||
}
|
||||
|
||||
chunks &= ~flag;
|
||||
@@ -717,7 +974,7 @@ check_handling(display *d, int def, png_uint_32 chunks, png_uint_32 known,
|
||||
|
||||
static void
|
||||
perform_one_test(FILE *fp, int argc, const char **argv,
|
||||
png_uint_32 *default_flags, display *d)
|
||||
png_uint_32 *default_flags, display *d, int set_callback)
|
||||
{
|
||||
int def;
|
||||
png_uint_32 flags[2][4];
|
||||
@@ -726,7 +983,7 @@ perform_one_test(FILE *fp, int argc, const char **argv,
|
||||
clear_keep();
|
||||
memcpy(flags[0], default_flags, sizeof flags[0]);
|
||||
|
||||
def = check(fp, argc, argv, flags[1], d);
|
||||
def = check(fp, argc, argv, flags[1], d, set_callback);
|
||||
|
||||
/* Chunks should either be known or unknown, never both and this should apply
|
||||
* whether the chunk is before or after the IDAT (actually, the app can
|
||||
@@ -761,9 +1018,9 @@ perform_one_test(FILE *fp, int argc, const char **argv,
|
||||
* it or not.
|
||||
*/
|
||||
check_handling(d, def, flags[0][0] | flags[0][1], flags[1][0], flags[1][1],
|
||||
"before IDAT");
|
||||
"before IDAT", set_callback);
|
||||
check_handling(d, def, flags[0][2] | flags[0][3], flags[1][2], flags[1][3],
|
||||
"after IDAT");
|
||||
"after IDAT", set_callback);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -773,7 +1030,12 @@ perform_one_test_safe(FILE *fp, int argc, const char **argv,
|
||||
if (setjmp(d->error_return) == 0)
|
||||
{
|
||||
d->test = test; /* allow use of d->error_return */
|
||||
perform_one_test(fp, argc, argv, default_flags, d);
|
||||
# ifdef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED
|
||||
perform_one_test(fp, argc, argv, default_flags, d, 0);
|
||||
# endif
|
||||
# ifdef PNG_READ_USER_CHUNKS_SUPPORTED
|
||||
perform_one_test(fp, argc, argv, default_flags, d, 1);
|
||||
# endif
|
||||
d->test = init; /* prevent use of d->error_return */
|
||||
}
|
||||
}
|
||||
@@ -797,7 +1059,7 @@ usage(const char *program, const char *reason)
|
||||
fprintf(stderr, "pngunknown: %s: usage:\n %s [--strict] "
|
||||
"--default|{(CHNK|default|all)=(default|discard|if-safe|save)} "
|
||||
"testfile.png\n", reason, program);
|
||||
exit(2);
|
||||
exit(99);
|
||||
}
|
||||
|
||||
int
|
||||
@@ -845,11 +1107,6 @@ main(int argc, const char **argv)
|
||||
else if (default_tests) if (argc != 1)
|
||||
usage(d.program, "extra arguments");
|
||||
|
||||
# ifndef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED
|
||||
fprintf(stderr, "%s: warning: no 'save' support so arguments ignored\n",
|
||||
d.program);
|
||||
# endif
|
||||
|
||||
/* The name of the test file is the last argument; remove it. */
|
||||
d.file = argv[--argc];
|
||||
|
||||
@@ -857,24 +1114,40 @@ main(int argc, const char **argv)
|
||||
if (fp == NULL)
|
||||
{
|
||||
perror(d.file);
|
||||
exit(2);
|
||||
exit(99);
|
||||
}
|
||||
|
||||
/* First find all the chunks, known and unknown, in the test file, a failure
|
||||
* here aborts the whole test.
|
||||
*
|
||||
* If 'save' is supported then the normal saving method should happen,
|
||||
* otherwise if 'read' is supported then the read callback will do the
|
||||
* same thing. If both are supported the 'read' callback won't be
|
||||
* instantiated by default. If 'save' is *not* supported then a user
|
||||
* callback is required even though we can call png_get_unknown_chunks.
|
||||
*/
|
||||
if (check(fp, 1, &count_argv, default_flags, &d) !=
|
||||
PNG_HANDLE_CHUNK_ALWAYS)
|
||||
if (check(fp, 1, &count_argv, default_flags, &d,
|
||||
# ifdef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED
|
||||
0
|
||||
# else
|
||||
1
|
||||
# endif
|
||||
) != PNG_HANDLE_CHUNK_ALWAYS)
|
||||
{
|
||||
fprintf(stderr, "%s: %s: internal error\n", d.program, d.file);
|
||||
exit(3);
|
||||
exit(99);
|
||||
}
|
||||
|
||||
/* Now find what the various supplied options cause to change: */
|
||||
if (!default_tests)
|
||||
{
|
||||
d.test = cmd; /* acts as a flag to say exit, do not longjmp */
|
||||
perform_one_test(fp, argc, argv, default_flags, &d);
|
||||
# ifdef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED
|
||||
perform_one_test(fp, argc, argv, default_flags, &d, 0);
|
||||
# endif
|
||||
# ifdef PNG_READ_USER_CHUNKS_SUPPORTED
|
||||
perform_one_test(fp, argc, argv, default_flags, &d, 1);
|
||||
# endif
|
||||
d.test = init;
|
||||
}
|
||||
|
||||
@@ -932,14 +1205,14 @@ main(int argc, const char **argv)
|
||||
if (fclose(fsuccess) || err)
|
||||
{
|
||||
fprintf(stderr, "%s: write failed\n", touch_file);
|
||||
exit(1);
|
||||
exit(99);
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "%s: open failed\n", touch_file);
|
||||
exit(1);
|
||||
exit(99);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -949,12 +1222,24 @@ main(int argc, const char **argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
#else
|
||||
#else /* !(READ_USER_CHUNKS || SAVE_UNKNOWN_CHUNKS) */
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
fprintf(stderr,
|
||||
" test ignored because libpng was not built with unknown chunk support\n");
|
||||
return 0;
|
||||
" test ignored: no support to find out about unknown chunks\n");
|
||||
/* So the test is skipped: */
|
||||
return 77;
|
||||
}
|
||||
#endif
|
||||
#endif /* READ_USER_CHUNKS || SAVE_UNKNOWN_CHUNKS */
|
||||
|
||||
#else /* !(SET_UNKNOWN_CHUNKS && READ) */
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
fprintf(stderr,
|
||||
" test ignored: no support to modify unknown chunk handling\n");
|
||||
/* So the test is skipped: */
|
||||
return 77;
|
||||
}
|
||||
#endif /* SET_UNKNOWN_CHUNKS && READ*/
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
104
contrib/libtests/readpng.c
Normal file
104
contrib/libtests/readpng.c
Normal file
@@ -0,0 +1,104 @@
|
||||
/* readpng.c
|
||||
*
|
||||
* Copyright (c) 2013 John Cunningham Bowler
|
||||
*
|
||||
* Last changed in libpng 1.6.1 [March 28, 2013]
|
||||
*
|
||||
* This code is released under the libpng license.
|
||||
* For conditions of distribution and use, see the disclaimer
|
||||
* and license in png.h
|
||||
*
|
||||
* Load an arbitrary number of PNG files (from the command line, or, if there
|
||||
* are no arguments on the command line, from stdin) then run a time test by
|
||||
* reading each file by row. The test does nothing with the read result and
|
||||
* does no transforms. The only output is a time as a floating point number of
|
||||
* seconds with 9 decimal digits.
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#if defined(HAVE_CONFIG_H) && !defined(PNG_NO_CONFIG_H)
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
/* Define the following to use this test against your installed libpng, rather
|
||||
* than the one being built here:
|
||||
*/
|
||||
#ifdef PNG_FREESTANDING_TESTS
|
||||
# include <png.h>
|
||||
#else
|
||||
# include "../../png.h"
|
||||
#endif
|
||||
|
||||
static int
|
||||
read_png(FILE *fp)
|
||||
{
|
||||
png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,0,0,0);
|
||||
png_infop info_ptr = NULL;
|
||||
png_bytep row = NULL, display = NULL;
|
||||
|
||||
if (png_ptr == NULL)
|
||||
return 0;
|
||||
|
||||
if (setjmp(png_jmpbuf(png_ptr)))
|
||||
{
|
||||
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
||||
if (row != NULL) free(row);
|
||||
if (display != NULL) free(display);
|
||||
return 0;
|
||||
}
|
||||
|
||||
png_init_io(png_ptr, fp);
|
||||
|
||||
info_ptr = png_create_info_struct(png_ptr);
|
||||
if (info_ptr == NULL)
|
||||
png_error(png_ptr, "OOM allocating info structure");
|
||||
|
||||
png_set_keep_unknown_chunks(png_ptr, PNG_HANDLE_CHUNK_ALWAYS, NULL, 0);
|
||||
|
||||
png_read_info(png_ptr, info_ptr);
|
||||
|
||||
{
|
||||
png_size_t rowbytes = png_get_rowbytes(png_ptr, info_ptr);
|
||||
|
||||
row = malloc(rowbytes);
|
||||
display = malloc(rowbytes);
|
||||
|
||||
if (row == NULL || display == NULL)
|
||||
png_error(png_ptr, "OOM allocating row buffers");
|
||||
|
||||
{
|
||||
png_uint_32 height = png_get_image_height(png_ptr, info_ptr);
|
||||
int passes = png_set_interlace_handling(png_ptr);
|
||||
int pass;
|
||||
|
||||
png_start_read_image(png_ptr);
|
||||
|
||||
for (pass = 0; pass < passes; ++pass)
|
||||
{
|
||||
png_uint_32 y = height;
|
||||
|
||||
/* NOTE: this trashes the row each time; interlace handling won't
|
||||
* work, but this avoids memory thrashing for speed testing.
|
||||
*/
|
||||
while (y-- > 0)
|
||||
png_read_row(png_ptr, row, display);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Make sure to read to the end of the file: */
|
||||
png_read_end(png_ptr, info_ptr);
|
||||
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
||||
free(row);
|
||||
free(display);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
/* Exit code 0 on success. */
|
||||
return !read_png(stdin);
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
|
||||
/* tarith.c
|
||||
*
|
||||
* Copyright (c) 2011,2012 John Cunningham Bowler
|
||||
* Copyright (c) 2011-2013 John Cunningham Bowler
|
||||
*
|
||||
* Last changed in libpng 1.6.0 [(PENDING RELEASE)]
|
||||
* Last changed in libpng 1.6.0 [February 14, 2013]
|
||||
*
|
||||
* This code is released under the libpng license.
|
||||
* For conditions of distribution and use, see the disclaimer
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Run the simplified API tests
|
||||
err=0
|
||||
|
||||
echo >> pngtest-log.txt
|
||||
echo "============ pngstest.sh ==============" >> pngtest-log.txt
|
||||
|
||||
echo "Running test-pngstest.sh"
|
||||
for image in ${srcdir}/contrib/pngsuite/*.png
|
||||
do
|
||||
for opts in ""
|
||||
do
|
||||
if ./pngstest --strict --log "$@" $opts $image >>pngtest-log.txt 2>&1
|
||||
then
|
||||
echo " PASS: pngstest $opts $image"
|
||||
else
|
||||
echo " FAIL: pngstest $opts $image"
|
||||
err=1
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
||||
exit $err
|
||||
@@ -1,38 +0,0 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Run the unknown API tests
|
||||
err=0
|
||||
image="${srcdir}/pngtest.png"
|
||||
#
|
||||
# stream 4 is used for the output of the shell, pngtest-log.txt gets all the
|
||||
# normal program output.
|
||||
exec 4>&1 1>>pngtest-log.txt 2>&1
|
||||
|
||||
echo
|
||||
echo "============ test-pngunknown.sh =============="
|
||||
|
||||
echo "Running test-pngunknown.sh" >&4
|
||||
|
||||
for tests in \
|
||||
"discard default=discard"\
|
||||
"save default=save"\
|
||||
"if-safe default=if-safe"\
|
||||
"vpAg vpAg=if-safe"\
|
||||
"sTER sTER=if-safe"\
|
||||
"IDAT default=discard IDAT=save"\
|
||||
"sAPI bKGD=save cHRM=save gAMA=save all=discard iCCP=save sBIT=save sRGB=save"
|
||||
do
|
||||
set $tests
|
||||
test="$1"
|
||||
shift
|
||||
|
||||
if ./pngunknown "$@" "$image" 4>&-
|
||||
then
|
||||
echo " PASS: test-pngunknown $test" >&4
|
||||
else
|
||||
echo " FAIL: test-pngunknown $test" >&4
|
||||
err=1
|
||||
fi
|
||||
done
|
||||
|
||||
exit $err
|
||||
@@ -1,21 +0,0 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Run a sequence of gamma tests quietly
|
||||
err=0
|
||||
|
||||
echo >> pngtest-log.txt
|
||||
echo "============ pngvalid-full.sh ==============" >> pngtest-log.txt
|
||||
|
||||
echo "Running test-pngvalid-full.sh"
|
||||
for gamma in threshold transform sbit 16-to-8 background alpha-mode "transform --expand16" "background --expand16" "alpha-mode --expand16"
|
||||
do
|
||||
if ./pngvalid "$@" --gamma-$gamma >> pngtest-log.txt 2>&1
|
||||
then
|
||||
echo " PASS: pngvalid" "$@" "--gamma-$gamma"
|
||||
else
|
||||
echo " FAIL: pngvalid" "$@" "--gamma-$gamma"
|
||||
err=1
|
||||
fi
|
||||
done
|
||||
|
||||
exit $err
|
||||
@@ -1,30 +0,0 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Run a sequence of tests quietly, without the slow
|
||||
# gamma tests
|
||||
err=0
|
||||
|
||||
echo >> pngtest-log.txt
|
||||
echo "============ pngvalid-simple.sh ==============" >> pngtest-log.txt
|
||||
echo "Running test-pngvalid-simple.sh"
|
||||
# The options to test are:
|
||||
#
|
||||
# standard tests with and without progressive reading and interlace
|
||||
# size images with and without progressive reading
|
||||
# transform tests (standard, non-interlaced only)
|
||||
#
|
||||
for opts in "--standard" "--standard --progressive-read" \
|
||||
"--standard --interlace" "--standard --progressive-read --interlace" \
|
||||
"--size" "--size --progressive-read" \
|
||||
"--transform"
|
||||
do
|
||||
if ./pngvalid "$@" $opts >> pngtest-log.txt 2>&1
|
||||
then
|
||||
echo " PASS: pngvalid" "$@" $opts
|
||||
else
|
||||
echo " FAIL: pngvalid" "$@" $opts
|
||||
err=1
|
||||
fi
|
||||
done
|
||||
|
||||
exit $err
|
||||
@@ -1,8 +1,8 @@
|
||||
/* timepng.c
|
||||
*
|
||||
* Copyright (c) 2012 John Cunningham Bowler
|
||||
* Copyright (c) 2013 John Cunningham Bowler
|
||||
*
|
||||
* Last changed in libpng 1.6.0 [(PENDING RELEASE)]
|
||||
* Last changed in libpng 1.6.1 [March 28, 2013]
|
||||
*
|
||||
* This code is released under the libpng license.
|
||||
* For conditions of distribution and use, see the disclaimer
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#if (defined HAVE_CONFIG_H) && !(defined PNG_NO_CONFIG_H)
|
||||
#if defined(HAVE_CONFIG_H) && !defined(PNG_NO_CONFIG_H)
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
@@ -252,7 +252,7 @@ int main(int argc, char **argv)
|
||||
|
||||
while (fgets(filename, FILENAME_MAX+1, stdin))
|
||||
{
|
||||
int len = strlen(filename);
|
||||
size_t len = strlen(filename);
|
||||
|
||||
if (filename[len-1] == '\n')
|
||||
{
|
||||
|
||||
@@ -14,7 +14,8 @@ LD=$(CC)
|
||||
RM=rm -f
|
||||
COPY=cp
|
||||
|
||||
CFLAGS=-DPNG_USER_CONFIG -DNO_GZCOMPRESS -DZ_SOLO -DNO_GZIP -I. -O1
|
||||
CPPFLAGS=-I. -DPNG_USER_CONFIG -DNO_GZCOMPRESS -DZ_SOLO -DNO_GZIP
|
||||
CFLAGS=-O1 -Wall
|
||||
|
||||
C=.c
|
||||
O=.o
|
||||
@@ -81,7 +82,7 @@ OBJS = $(PROGOBJS) $(PNGOBJS) $(ZOBJS)
|
||||
|
||||
# note: dependencies do not work on implicit rule lines
|
||||
.c$(O):
|
||||
$(CC) -c $(CFLAGS) $<
|
||||
$(CC) $(CPPFLAGS) -c $(CFLAGS) $<
|
||||
|
||||
# dependencies
|
||||
|
||||
@@ -95,16 +96,16 @@ pngm2pnm$(E): $(OBJS)
|
||||
# The CPP_FLAGS setting causes pngusr.h to be included in
|
||||
# both the build of pnglibconf.h and, subsequently, when
|
||||
# building libpng itself.
|
||||
$(PNGCONF): $(PNGSRC)/scripts/pnglibconf.mak\
|
||||
$(PNGCONF): $(PNGSRC)/scripts/pnglibconf.mak $(ZH)\
|
||||
$(PNGSRC)/scripts/pnglibconf.dfa \
|
||||
$(PNGSRC)/scripts/options.awk pngusr.h pngusr.dfa
|
||||
$(RM) pnglibconf.h pnglibconf.dfn
|
||||
$(MAKE) $(MAKEFLAGS) -f $(PNGSRC)/scripts/pnglibconf.mak\
|
||||
srcdir=$(PNGSRC) CPPFLAGS="-DPNG_USER_CONFIG"\
|
||||
$(MAKE) -f $(PNGSRC)/scripts/pnglibconf.mak $(MAKEFLAGS)\
|
||||
srcdir=$(PNGSRC) CPPFLAGS="-DPNG_USER_CONFIG -I."\
|
||||
DFA_XTRA="pngusr.dfa" $@
|
||||
|
||||
clean:
|
||||
$(MAKE) $(MAKEFLAGS) -f $(PNGSRC)/scripts/pnglibconf.mak\
|
||||
$(MAKE) -f $(PNGSRC)/scripts/pnglibconf.mak $(MAKEFLAGS)\
|
||||
srcdir=$(PNGSRC) clean
|
||||
$(RM) pngm2pnm$(O)
|
||||
$(RM) pngm2pnm$(E)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# pngminim/decoder/pngusr.dfa
|
||||
#
|
||||
# Copyright (c) 2010-2011 Glenn Randers-Pehrson
|
||||
# Copyright (c) 2010-2013 Glenn Randers-Pehrson
|
||||
#
|
||||
# This code is released under the libpng license.
|
||||
# For conditions of distribution and use, see the disclaimer
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* minrdpngconf.h: headers to make a minimal png-read-only library
|
||||
*
|
||||
* Copyright (c) 2007, 2010-2011 Glenn Randers-Pehrson
|
||||
* Copyright (c) 2007, 2010-2013 Glenn Randers-Pehrson
|
||||
*
|
||||
* This code is released under the libpng license.
|
||||
* For conditions of distribution and use, see the disclaimer
|
||||
@@ -18,7 +18,6 @@
|
||||
* affect the API (so are not recorded in pnglibconf.h)
|
||||
*/
|
||||
|
||||
#define PNG_NO_WARNINGS
|
||||
#define PNG_ALIGN_TYPE PNG_ALIGN_NONE
|
||||
|
||||
#endif /* MINRDPNGCONF_H */
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
This demonstrates the use of PNG_USER_CONFIG and pngusr.h
|
||||
|
||||
The makefile builds a minimal write-only decoder with embedded libpng
|
||||
The makefile builds a minimal write-only encoder with embedded libpng
|
||||
and zlib.
|
||||
|
||||
Specify the location of the zlib source (1.2.1 or later) as ZLIBSRC
|
||||
|
||||
@@ -14,7 +14,8 @@ LD=$(CC)
|
||||
RM=rm -f
|
||||
COPY=cp
|
||||
|
||||
CFLAGS=-DPNG_USER_CONFIG -DZ_SOLO -DNO_GZIP -I. -O1
|
||||
CPPFLAGS=-I. -DPNG_USER_CONFIG -DNO_GZCOMPRESS -DZ_SOLO -DNO_GZIP
|
||||
CFLAGS=-O1 -Wall
|
||||
|
||||
C=.c
|
||||
O=.o
|
||||
@@ -80,7 +81,7 @@ OBJS = $(PROGOBJS) $(PNGOBJS) $(ZOBJS)
|
||||
# implicit make rules -------------------------------------------------------
|
||||
|
||||
.c$(O):
|
||||
$(CC) -c $(CFLAGS) $<
|
||||
$(CC) $(CPPFLAGS) -c $(CFLAGS) $<
|
||||
|
||||
# dependencies
|
||||
|
||||
@@ -94,16 +95,16 @@ pnm2pngm$(E): $(OBJS)
|
||||
# The CPP_FLAGS setting causes pngusr.h to be included in
|
||||
# both the build of pnglibconf.h and, subsequently, when
|
||||
# building libpng itself.
|
||||
$(PNGCONF): $(PNGSRC)/scripts/pnglibconf.mak\
|
||||
$(PNGCONF): $(PNGSRC)/scripts/pnglibconf.mak $(ZH)\
|
||||
$(PNGSRC)/scripts/pnglibconf.dfa \
|
||||
$(PNGSRC)/scripts/options.awk pngusr.h pngusr.dfa
|
||||
$(RM) pnglibconf.h pnglibconf.dfn
|
||||
$(MAKE) $(MAKEFLAGS) -f $(PNGSRC)/scripts/pnglibconf.mak\
|
||||
srcdir=$(PNGSRC) CPPFLAGS="-DPNG_USER_CONFIG"\
|
||||
$(MAKE) -f $(PNGSRC)/scripts/pnglibconf.mak $(MAKEFLAGS)\
|
||||
srcdir=$(PNGSRC) CPPFLAGS="-DPNG_USER_CONFIG -I."\
|
||||
DFA_XTRA="pngusr.dfa" $@
|
||||
|
||||
clean:
|
||||
$(MAKE) $(MAKEFLAGS) -f $(PNGSRC)/scripts/pnglibconf.mak\
|
||||
$(MAKE) -f $(PNGSRC)/scripts/pnglibconf.mak $(MAKEFLAGS)\
|
||||
srcdir=$(PNGSRC) clean
|
||||
$(RM) pnm2pngm$(O)
|
||||
$(RM) pnm2pngm$(E)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# pngminim/encoder/pngusr.dfa
|
||||
#
|
||||
# Copyright (c) 2010-2011 Glenn Randers-Pehrson
|
||||
# Copyright (c) 2010-2013 Glenn Randers-Pehrson
|
||||
#
|
||||
# This code is released under the libpng license.
|
||||
# For conditions of distribution and use, see the disclaimer
|
||||
@@ -14,6 +14,10 @@ everything = off
|
||||
|
||||
option WRITE on
|
||||
|
||||
# These 2 options are required if you need to read PBM (P1 or P4) files.
|
||||
option WRITE_INVERT on
|
||||
option WRITE_PACK on
|
||||
|
||||
# You must choose fixed or floating point arithmetic:
|
||||
# option FLOATING_POINT on
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* minwrpngconf.h: headers to make a minimal png-write-only library
|
||||
*
|
||||
* Copyright (c) 2007, 2010-2011 Glenn Randers-Pehrson
|
||||
* Copyright (c) 2007, 2010-2013 Glenn Randers-Pehrson
|
||||
*
|
||||
* This code is released under the libpng license.
|
||||
* For conditions of distribution and use, see the disclaimer
|
||||
@@ -18,7 +18,6 @@
|
||||
* affect the API (so are not recorded in pnglibconf.h)
|
||||
*/
|
||||
|
||||
#define PNG_NO_WARNINGS
|
||||
#define PNG_ALIGN_TYPE PNG_ALIGN_NONE
|
||||
|
||||
#endif /* MINWRPNGCONF_H */
|
||||
|
||||
@@ -30,7 +30,8 @@ XLIB = -L/usr/X11R6/lib -lX11
|
||||
#LIBS = $(XLIB)
|
||||
LIBS = $(XLIB) -lm #platforms that need libm
|
||||
|
||||
CFLAGS=-DPNG_USER_CONFIG -DNO_GZCOMPRESS -DZ_SOLO -DNO_GZIP -I. $(XINC) -O1
|
||||
CPPFLAGS=-I. $(XINC) -DPNG_USER_CONFIG -DNO_GZCOMPRESS -DZ_SOLO -DNO_GZIP
|
||||
CFLAGS=-O1 -Wall
|
||||
|
||||
C=.c
|
||||
O=.o
|
||||
@@ -96,7 +97,7 @@ OBJS = $(PROGOBJS) $(PNGOBJS) $(ZOBJS)
|
||||
# implicit make rules -------------------------------------------------------
|
||||
|
||||
.c$(O):
|
||||
$(CC) -c $(CFLAGS) $<
|
||||
$(CC) $(CPPFLAGS) -c $(CFLAGS) $<
|
||||
|
||||
# dependencies
|
||||
|
||||
@@ -110,16 +111,16 @@ rpng2-x$(E): $(OBJS)
|
||||
# The CPP_FLAGS setting causes pngusr.h to be included in
|
||||
# both the build of pnglibconf.h and, subsequently, when
|
||||
# building libpng itself.
|
||||
$(PNGCONF): $(PNGSRC)/scripts/pnglibconf.mak\
|
||||
$(PNGCONF): $(PNGSRC)/scripts/pnglibconf.mak $(ZH)\
|
||||
$(PNGSRC)/scripts/pnglibconf.dfa \
|
||||
$(PNGSRC)/scripts/options.awk pngusr.h pngusr.dfa
|
||||
$(RM) pnglibconf.h pnglibconf.dfn
|
||||
$(MAKE) $(MAKEFLAGS) -f $(PNGSRC)/scripts/pnglibconf.mak\
|
||||
srcdir=$(PNGSRC) CPPFLAGS="-DPNG_USER_CONFIG"\
|
||||
$(MAKE) -f $(PNGSRC)/scripts/pnglibconf.mak $(MAKEFLAGS)\
|
||||
srcdir=$(PNGSRC) CPPFLAGS="-DPNG_USER_CONFIG -I."\
|
||||
DFA_XTRA="pngusr.dfa" $@
|
||||
|
||||
clean:
|
||||
$(MAKE) $(MAKEFLAGS) -f $(PNGSRC)/scripts/pnglibconf.mak\
|
||||
$(MAKE) -f $(PNGSRC)/scripts/pnglibconf.mak $(MAKEFLAGS)\
|
||||
srcdir=$(PNGSRC) clean
|
||||
$(RM) rpng2-x$(O)
|
||||
$(RM) rpng2-x$(E)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# pngminim/preader/pngusr.dfa
|
||||
#
|
||||
# Copyright (c) 2010-2011 Glenn Randers-Pehrson
|
||||
# Copyright (c) 2010-2013 Glenn Randers-Pehrson
|
||||
#
|
||||
# This code is released under the libpng license.
|
||||
# For conditions of distribution and use, see the disclaimer
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* minrdpngconf.h: headers to make a minimal png-read-only library
|
||||
*
|
||||
* Copyright (c) 2009, 2010-2011 Glenn Randers-Pehrson
|
||||
* Copyright (c) 2009, 2010-2013 Glenn Randers-Pehrson
|
||||
*
|
||||
* This code is released under the libpng license.
|
||||
* For conditions of distribution and use, see the disclaimer
|
||||
@@ -18,7 +18,6 @@
|
||||
* affect the API (so are not recorded in pnglibconf.h)
|
||||
*/
|
||||
|
||||
#define PNG_NO_WARNINGS
|
||||
#define PNG_ALIGN_TYPE PNG_ALIGN_NONE
|
||||
|
||||
#endif /* MINPRDPNGCONF_H */
|
||||
|
||||
@@ -8,9 +8,9 @@ LD=$(CC)
|
||||
RM=rm -f
|
||||
|
||||
#PNGPATH = /usr/local
|
||||
#PNGINC = -I$(PNGPATH)/include/libpng16
|
||||
#PNGLIB = -L$(PNGPATH)/lib -lpng16
|
||||
#PNGLIBS = $(PNGPATH)/lib/libpng16.a
|
||||
#PNGINC = -I$(PNGPATH)/include/libpng17
|
||||
#PNGLIB = -L$(PNGPATH)/lib -lpng17
|
||||
#PNGLIBS = $(PNGPATH)/lib/libpng17.a
|
||||
PNGINC = -I../..
|
||||
PNGLIB = -L../.. -lpng
|
||||
PNGLIBS = ../../libpng.a
|
||||
|
||||
0
contrib/pngminus/png2pnm.bat
Normal file → Executable file
0
contrib/pngminus/png2pnm.bat
Normal file → Executable file
0
contrib/pngminus/png2pnm.sh
Normal file → Executable file
0
contrib/pngminus/png2pnm.sh
Normal file → Executable file
0
contrib/pngminus/pngminus.bat
Normal file → Executable file
0
contrib/pngminus/pngminus.bat
Normal file → Executable file
0
contrib/pngminus/pngminus.sh
Normal file → Executable file
0
contrib/pngminus/pngminus.sh
Normal file → Executable file
0
contrib/pngminus/pnm2png.bat
Normal file → Executable file
0
contrib/pngminus/pnm2png.bat
Normal file → Executable file
@@ -198,9 +198,9 @@ BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace,
|
||||
char height_token[16];
|
||||
char maxval_token[16];
|
||||
int color_type;
|
||||
unsigned long ul_width, ul_alpha_width;
|
||||
unsigned long ul_height, ul_alpha_height;
|
||||
unsigned long ul_maxval;
|
||||
unsigned long ul_width=0, ul_alpha_width=0;
|
||||
unsigned long ul_height=0, ul_alpha_height=0;
|
||||
unsigned long ul_maxval=0;
|
||||
png_uint_32 width, alpha_width;
|
||||
png_uint_32 height, alpha_height;
|
||||
png_uint_32 maxval;
|
||||
@@ -210,6 +210,9 @@ BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace,
|
||||
int alpha_present;
|
||||
int row, col;
|
||||
BOOL raw, alpha_raw = FALSE;
|
||||
#if defined(PNG_WRITE_INVERT_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
|
||||
BOOL packed_bitmap = FALSE;
|
||||
#endif
|
||||
png_uint_32 tmp16;
|
||||
int i;
|
||||
|
||||
@@ -222,9 +225,21 @@ BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace,
|
||||
}
|
||||
else if ((type_token[1] == '1') || (type_token[1] == '4'))
|
||||
{
|
||||
#if defined(PNG_WRITE_INVERT_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
|
||||
raw = (type_token[1] == '4');
|
||||
color_type = PNG_COLOR_TYPE_GRAY;
|
||||
get_token(pnm_file, width_token);
|
||||
sscanf (width_token, "%lu", &ul_width);
|
||||
width = (png_uint_32) ul_width;
|
||||
get_token(pnm_file, height_token);
|
||||
sscanf (height_token, "%lu", &ul_height);
|
||||
height = (png_uint_32) ul_height;
|
||||
bit_depth = 1;
|
||||
packed_bitmap = TRUE;
|
||||
#else
|
||||
fprintf (stderr, "PNM2PNG built without PNG_WRITE_INVERT_SUPPORTED and \n");
|
||||
fprintf (stderr, "PNG_WRITE_PACK_SUPPORTED can't read PBM (P1,P4) files\n");
|
||||
#endif
|
||||
}
|
||||
else if ((type_token[1] == '2') || (type_token[1] == '5'))
|
||||
{
|
||||
@@ -343,8 +358,14 @@ BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace,
|
||||
|
||||
alpha_present = (channels - 1) % 2;
|
||||
|
||||
/* row_bytes is the width x number of channels x (bit-depth / 8) */
|
||||
row_bytes = width * channels * ((bit_depth <= 8) ? 1 : 2);
|
||||
#if defined(PNG_WRITE_INVERT_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
|
||||
if (packed_bitmap)
|
||||
/* row data is as many bytes as can fit width x channels x bit_depth */
|
||||
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 = width * channels * ((bit_depth <= 8) ? 1 : 2);
|
||||
|
||||
if ((png_pixels = (png_byte *) malloc (row_bytes * height * sizeof (png_byte))) == NULL)
|
||||
return FALSE;
|
||||
@@ -354,40 +375,48 @@ BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace,
|
||||
|
||||
for (row = 0; row < height; row++)
|
||||
{
|
||||
for (col = 0; col < width; col++)
|
||||
#if defined(PNG_WRITE_INVERT_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
|
||||
if (packed_bitmap) {
|
||||
for (i = 0; i < row_bytes; i++)
|
||||
/* png supports this format natively so no conversion is needed */
|
||||
*pix_ptr++ = get_data (pnm_file, 8);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
for (i = 0; i < (channels - alpha_present); i++)
|
||||
for (col = 0; col < width; col++)
|
||||
{
|
||||
if (raw)
|
||||
*pix_ptr++ = get_data (pnm_file, bit_depth);
|
||||
else
|
||||
if (bit_depth <= 8)
|
||||
*pix_ptr++ = get_value (pnm_file, bit_depth);
|
||||
for (i = 0; i < (channels - alpha_present); i++)
|
||||
{
|
||||
if (raw)
|
||||
*pix_ptr++ = get_data (pnm_file, bit_depth);
|
||||
else
|
||||
{
|
||||
tmp16 = get_value (pnm_file, bit_depth);
|
||||
*pix_ptr = (png_byte) ((tmp16 >> 8) & 0xFF);
|
||||
pix_ptr++;
|
||||
*pix_ptr = (png_byte) (tmp16 & 0xFF);
|
||||
pix_ptr++;
|
||||
}
|
||||
}
|
||||
if (bit_depth <= 8)
|
||||
*pix_ptr++ = get_value (pnm_file, bit_depth);
|
||||
else
|
||||
{
|
||||
tmp16 = get_value (pnm_file, bit_depth);
|
||||
*pix_ptr = (png_byte) ((tmp16 >> 8) & 0xFF);
|
||||
pix_ptr++;
|
||||
*pix_ptr = (png_byte) (tmp16 & 0xFF);
|
||||
pix_ptr++;
|
||||
}
|
||||
}
|
||||
|
||||
if (alpha) /* read alpha-channel from pgm file */
|
||||
{
|
||||
if (alpha_raw)
|
||||
*pix_ptr++ = get_data (alpha_file, alpha_depth);
|
||||
else
|
||||
if (alpha_depth <= 8)
|
||||
*pix_ptr++ = get_value (alpha_file, bit_depth);
|
||||
if (alpha) /* read alpha-channel from pgm file */
|
||||
{
|
||||
if (alpha_raw)
|
||||
*pix_ptr++ = get_data (alpha_file, alpha_depth);
|
||||
else
|
||||
{
|
||||
tmp16 = get_value (alpha_file, bit_depth);
|
||||
*pix_ptr++ = (png_byte) ((tmp16 >> 8) & 0xFF);
|
||||
*pix_ptr++ = (png_byte) (tmp16 & 0xFF);
|
||||
}
|
||||
} /* if alpha */
|
||||
|
||||
if (alpha_depth <= 8)
|
||||
*pix_ptr++ = get_value (alpha_file, bit_depth);
|
||||
else
|
||||
{
|
||||
tmp16 = get_value (alpha_file, bit_depth);
|
||||
*pix_ptr++ = (png_byte) ((tmp16 >> 8) & 0xFF);
|
||||
*pix_ptr++ = (png_byte) (tmp16 & 0xFF);
|
||||
}
|
||||
} /* if alpha */
|
||||
} /* if packed_bitmap */
|
||||
} /* end for col */
|
||||
} /* end for row */
|
||||
|
||||
@@ -404,6 +433,14 @@ BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace,
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#if defined(PNG_WRITE_INVERT_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
|
||||
if (packed_bitmap == TRUE)
|
||||
{
|
||||
png_set_packing (png_ptr);
|
||||
png_set_invert_mono (png_ptr);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* setjmp() must be called in every function that calls a PNG-reading libpng function */
|
||||
if (setjmp (png_jmpbuf(png_ptr)))
|
||||
{
|
||||
@@ -460,19 +497,32 @@ BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace,
|
||||
void get_token(FILE *pnm_file, char *token)
|
||||
{
|
||||
int i = 0;
|
||||
int ret;
|
||||
|
||||
/* remove white-space */
|
||||
/* remove white-space and comment lines */
|
||||
do
|
||||
{
|
||||
token[i] = (unsigned char) fgetc (pnm_file);
|
||||
ret = fgetc(pnm_file);
|
||||
if (ret == '#') {
|
||||
/* the rest of this line is a comment */
|
||||
do
|
||||
{
|
||||
ret = fgetc(pnm_file);
|
||||
}
|
||||
while ((ret != '\n') && (ret != '\r') && (ret != EOF));
|
||||
}
|
||||
if (ret == EOF) break;
|
||||
token[i] = (unsigned char) ret;
|
||||
}
|
||||
while ((token[i] == '\n') || (token[i] == '\r') || (token[i] == ' '));
|
||||
|
||||
/* read string */
|
||||
do
|
||||
{
|
||||
ret = fgetc(pnm_file);
|
||||
if (ret == EOF) break;
|
||||
i++;
|
||||
token[i] = (unsigned char) fgetc (pnm_file);
|
||||
token[i] = (unsigned char) ret;
|
||||
}
|
||||
while ((token[i] != '\n') && (token[i] != '\r') && (token[i] != ' '));
|
||||
|
||||
|
||||
0
contrib/pngminus/pnm2png.sh
Normal file → Executable file
0
contrib/pngminus/pnm2png.sh
Normal file → Executable file
@@ -1,8 +1,8 @@
|
||||
/* checksum-icc.c
|
||||
*
|
||||
* Copyright (c) 2012 John Cunningham Bowler
|
||||
* Copyright (c) 2013 John Cunningham Bowler
|
||||
*
|
||||
* Last changed in libpng 1.6.0 [(PENDING RELEASE)]
|
||||
* Last changed in libpng 1.6.0 [February 14, 2013]
|
||||
*
|
||||
* This code is released under the libpng license.
|
||||
* For conditions of distribution and use, see the disclaimer
|
||||
|
||||
437
contrib/tools/chunkhash.c
Normal file
437
contrib/tools/chunkhash.c
Normal file
@@ -0,0 +1,437 @@
|
||||
/* chunkhash.c -- build a perfect hash code for the chunk names on stdin.
|
||||
*
|
||||
* Last changed in libpng 1.7.0 [(PENDING RELEASE)]
|
||||
*
|
||||
* COPYRIGHT: Written by John Cunningham Bowler, 2014.
|
||||
* 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.
|
||||
*
|
||||
* Feed this program all the known chunks that libpng must recognize. It will
|
||||
* generate an appropriate hash key for the macro in pngpriv.h To generate the
|
||||
* list of chunks currently defined in png.h do this:
|
||||
*
|
||||
* sed -n -e 's/^#define png_\(....\) PNG_U32.*$/\1/p' png.h
|
||||
*
|
||||
* An alternative to using this program is to pipe the output of the above
|
||||
* through gperf, however the code generated by perf is somewhat more verbose
|
||||
* and it doesn't generate as good a result (however it's a heck of a lot faster
|
||||
* than this program!)
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <png.h> /* for the libpng types for this platform */
|
||||
|
||||
/* The machine generated file is checked in, so this works and it obtains the
|
||||
* definition of the PNG_CHUNK_HASH macro. To change this definition only ever
|
||||
* alter the strings below!
|
||||
*/
|
||||
#include "chunkhash.h"
|
||||
|
||||
/* The best_ variables are local variables defined in the functions below. When
|
||||
* used in libpng code, however, they are just constants.
|
||||
*/
|
||||
#define PNG_CHUNK_HASH_MASK best_mask
|
||||
#define PNG_CHUNK_HASH_C0 best_c[0]
|
||||
#define PNG_CHUNK_HASH_C1 best_c[1]
|
||||
#define PNG_CHUNK_HASH_C2 best_c[2]
|
||||
#define PNG_CHUNK_HASH_C3 best_c[3]
|
||||
|
||||
/* These strings contain the C text to copy into the new version of
|
||||
* contrib/tools/chunkhash.c
|
||||
*/
|
||||
static const char *strings[] = {
|
||||
"/* chunkhash.h -- a perfect hash code for the chunk names in png.h",
|
||||
" *",
|
||||
" * Last changed in libpng 1.7.0 [(PENDING RELEASE)]",
|
||||
" *",
|
||||
" * THIS IS A MACHINE GENERATED FILE. See contrib/tools/chunkhash.c for",
|
||||
" * copyright and other information.",
|
||||
" *",
|
||||
" * USAGE: To include the PNG_CHUNK_HASH macro and associated definitions:",
|
||||
" *",
|
||||
" * #define PNG_CHUNKHASH_DEFS",
|
||||
" * #include \"contrib/tools/chunkhash.h\"",
|
||||
" *",
|
||||
" * To define the png_chunk_hash array used by the macro:",
|
||||
" *",
|
||||
" * #define PNG_CHUNKHASH_CODE",
|
||||
" * #include \"contrib/tools/chunkhash.h\"",
|
||||
" *",
|
||||
" * One or both of the defines must be given except when building chunkhash",
|
||||
" * itself.",
|
||||
" */",
|
||||
"#ifdef PNG_CHUNKHASH_DEFS",
|
||||
"#ifndef PNG_CHUNKHASH_H",
|
||||
"#define PNG_CHUNKHASH_H",
|
||||
"/* A perfect hash code - returns a value 0..(PNG_KNOWN_CHUNK_COUNT-1) and is",
|
||||
" * generated by the ridiculously simple program in contrib/tools/chunkhash.c",
|
||||
" *",
|
||||
" * The hash code used here multiplies each byte by a different constant to",
|
||||
" * return a single number:",
|
||||
" *",
|
||||
" * b0 * c[0] + b1 * [c1] + b2 * c[2] + b3 * c[3]",
|
||||
" *",
|
||||
" * The values of the constants are found by search using the a table of",
|
||||
" * primes, including 0, and may be (in fact are at present) 0 for some of the",
|
||||
" * bytes, the compiler is expected to optimize multiply by zero, or one!",
|
||||
" *",
|
||||
" * The lookup table reduces the sparse result of the hash calculation to the",
|
||||
" * correct index values. The chunks are indexed in the string order of the",
|
||||
" * png_uint_32 chunk names.",
|
||||
" */",
|
||||
0, /* HEADER definitions go here */
|
||||
"",
|
||||
"extern const png_byte png_chunk_hash[PNG_CHUNK_HASH_MASK+1];",
|
||||
"#endif /* !PNG_CHUNKHASH_H */",
|
||||
"#endif /* PNG_CHUNKHASH_DEFS */",
|
||||
"",
|
||||
"#ifndef PNG_CHUNK_HASH",
|
||||
"#define PNG_CHUNK_HASH(chunk) (png_chunk_hash[PNG_CHUNK_HASH_MASK & (\\",
|
||||
" ((chunk) >> 24) * PNG_CHUNK_HASH_C0 +\\",
|
||||
" ((chunk) >> 16) * PNG_CHUNK_HASH_C1 +\\",
|
||||
" ((chunk) >> 8) * PNG_CHUNK_HASH_C2 +\\",
|
||||
" ((chunk) ) * PNG_CHUNK_HASH_C3)])",
|
||||
"#endif",
|
||||
"",
|
||||
"#ifdef PNG_CHUNKHASH_CODE",
|
||||
"#ifndef PNG_CHUNKHASH_C",
|
||||
"#define PNG_CHUNKHASH_C",
|
||||
"const png_byte png_chunk_hash[PNG_CHUNK_HASH_MASK+1] = {",
|
||||
0, /* png.c definitions go here */
|
||||
"};",
|
||||
"#endif /* !PNG_CHUNKHASH_C */",
|
||||
"#endif /* PNG_CHUNKHASH_CODE */",
|
||||
0 /* end of file */
|
||||
};
|
||||
|
||||
#define CHUNK_COUNT_MAX 32
|
||||
/* If necessary this is easy to increase; just don't use a png_uint_32
|
||||
* bitmask below, however it doesn't seem likely that the limit will be hit
|
||||
* any time soon.
|
||||
*/
|
||||
|
||||
static const png_byte
|
||||
chunk_hash[256] =
|
||||
{
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
|
||||
22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
|
||||
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
|
||||
60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78,
|
||||
79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97,
|
||||
98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113,
|
||||
114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128,
|
||||
129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
|
||||
144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158,
|
||||
159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173,
|
||||
174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188,
|
||||
189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203,
|
||||
204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218,
|
||||
219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233,
|
||||
234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248,
|
||||
249, 250, 251, 252, 253, 254, 255
|
||||
};
|
||||
|
||||
static void
|
||||
error(const char *string)
|
||||
{
|
||||
fprintf(stderr, "chunkhash: %s\n", string);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Return a hash code for the given chunk; this is the same as the pngpriv.h
|
||||
* macro, but parameterized. The names of the parameters have to be chosen to
|
||||
* match the above #defines.
|
||||
*/
|
||||
static png_uint_32
|
||||
test_hash(png_uint_32 chunk, const unsigned int *best_c, png_uint_32 best_mask)
|
||||
{
|
||||
# define png_chunk_hash chunk_hash /* prevents lookup */
|
||||
return PNG_CHUNK_HASH(chunk);
|
||||
# undef png_chunk_hash
|
||||
}
|
||||
|
||||
static void
|
||||
print_chunks(const png_uint_32 *chunks, unsigned int nchunks, png_uint_32 first,
|
||||
png_uint_32 last, const unsigned int *best_c, png_uint_32 best_mask,
|
||||
const png_byte *lut)
|
||||
{
|
||||
/* 'last' is the last code to print plus 1, this is used to detect duplicates
|
||||
* (which should not happen - if there are any it's an internal error!)
|
||||
*/
|
||||
if (nchunks > 0)
|
||||
{
|
||||
/* Recursive algorithm; find the hash code of the next chunk, then print
|
||||
* all remaining chunks with codes in the range first..code (including
|
||||
* duplicates) and after print all remaining chunks with codes in the
|
||||
* range (code+1)..last
|
||||
*/
|
||||
const png_uint_32 chunk = *chunks++;
|
||||
# define png_chunk_hash lut
|
||||
const png_uint_32 code = PNG_CHUNK_HASH(chunk);
|
||||
# undef png_chunk_hash
|
||||
|
||||
--nchunks;
|
||||
|
||||
/* The code might be out of the print range */
|
||||
if (code >= first && code <= last)
|
||||
{
|
||||
if (code >= first) /* not time yet */
|
||||
print_chunks(chunks, nchunks, first, code, best_c, best_mask, lut);
|
||||
|
||||
printf("#define PNG_CHUNK_%c%c%c%c_TAG %lu%s\n", (char)(chunk>>24),
|
||||
(char)(chunk>>16), (char)(chunk>>8), (char)chunk,
|
||||
(unsigned long)code, code == last ? " /* DUPLICATE */" : "");
|
||||
|
||||
if (code < last) /* still some to go */
|
||||
print_chunks(chunks, nchunks, code+1, last, best_c, best_mask, lut);
|
||||
}
|
||||
|
||||
else
|
||||
print_chunks(chunks, nchunks, first, last, best_c, best_mask, lut);
|
||||
}
|
||||
}
|
||||
|
||||
static unsigned int primes[] =
|
||||
{
|
||||
0, 1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67,
|
||||
71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149,
|
||||
151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229,
|
||||
233, 239, 241, 251
|
||||
};
|
||||
|
||||
#define NPRIMES ((sizeof primes)/(sizeof primes[0]))
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
/* Stdin should just contain chunk names, one per line */
|
||||
png_uint_32 best_mask;
|
||||
unsigned int best_c[4];
|
||||
png_uint_32 chunks[CHUNK_COUNT_MAX];
|
||||
png_byte known_chunk_count;
|
||||
|
||||
/* Not required; stop GCC whining: */
|
||||
memset(best_c, 0xab, sizeof best_c);
|
||||
best_mask = 0x12345678;
|
||||
|
||||
{
|
||||
png_uint_32 this_chunk = 0;
|
||||
png_byte n_chunks = 0;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
int ch = getchar();
|
||||
|
||||
if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
|
||||
{
|
||||
if (this_chunk > 0xffffffU)
|
||||
error("chunk name too long");
|
||||
|
||||
this_chunk = (this_chunk << 8) + (unsigned)ch;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
if (this_chunk > 0)
|
||||
{
|
||||
if (this_chunk <= 0xffffffU)
|
||||
error("chunk name too short");
|
||||
|
||||
if (n_chunks >= CHUNK_COUNT_MAX)
|
||||
error("too many chunks (check CHUNK_COUNT_MAX)");
|
||||
|
||||
chunks[n_chunks++] = this_chunk;
|
||||
this_chunk = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (ch < 0)
|
||||
break;
|
||||
}
|
||||
|
||||
/* 22 is the number of chunks currently defined (excluding fRAc), at any
|
||||
* time it should also be in PNG_KNOWN_CHUNK_COUNT, but this run of
|
||||
* chunkhash may be trying to add a chunk so allow bigger numbers.
|
||||
*/
|
||||
# ifdef PNG_KNOWN_CHUNK_COUNT
|
||||
# define CHUNK_COUNT_MIN PNG_KNOWN_CHUNK_COUNT
|
||||
# else
|
||||
# define CHUNK_COUNT_MIN 26
|
||||
# endif
|
||||
if (n_chunks < CHUNK_COUNT_MIN)
|
||||
error("too few chunks (expecting at least 26)");
|
||||
|
||||
known_chunk_count = n_chunks;
|
||||
}
|
||||
|
||||
/* Exhaustive search of the hash parameters - in fact this isn't very slow at
|
||||
* all.
|
||||
*/
|
||||
{
|
||||
unsigned int i1, c_zero = 0, c_one = 0;
|
||||
|
||||
for (i1=0; i1<NPRIMES; ++i1)
|
||||
{
|
||||
unsigned int i2;
|
||||
unsigned int c[4];
|
||||
|
||||
fprintf(stderr, "TEST: %u\n", primes[i1]);
|
||||
c[0] = primes[i1];
|
||||
|
||||
for (i2=0; i2<NPRIMES; ++i2)
|
||||
{
|
||||
unsigned int i3;
|
||||
|
||||
c[1] = primes[i2];
|
||||
|
||||
for (i3=0; i3<NPRIMES; ++i3)
|
||||
{
|
||||
unsigned int i4;
|
||||
|
||||
c[2] = primes[i3];
|
||||
|
||||
for (i4=0; i4<NPRIMES; ++i4)
|
||||
{
|
||||
unsigned int i;
|
||||
png_uint_32 hash_mask = 0xffU;
|
||||
png_uint_32 hashes[CHUNK_COUNT_MAX];
|
||||
|
||||
c[3] = primes[i4];
|
||||
|
||||
while (hash_mask > 0xfU)
|
||||
{
|
||||
for (i=0; i<known_chunk_count; ++i)
|
||||
{
|
||||
unsigned int j;
|
||||
png_uint_32 hash = test_hash(chunks[i], c, hash_mask);
|
||||
|
||||
for (j=0; j<i; ++j) if (hashes[j] == hash) goto next_i4;
|
||||
|
||||
hashes[i] = hash;
|
||||
}
|
||||
|
||||
hash_mask >>= 1;
|
||||
}
|
||||
|
||||
next_i4:
|
||||
if (hash_mask < 0xffU)
|
||||
{
|
||||
/* This worked */
|
||||
unsigned int best, c0 = 0, c1 = 0;
|
||||
|
||||
hash_mask <<= 1;
|
||||
hash_mask += 1;
|
||||
|
||||
for (i=0; i<4; ++i)
|
||||
{
|
||||
if (c[i] == 0)
|
||||
++c0;
|
||||
|
||||
else if (c[i] == 1)
|
||||
++c1;
|
||||
}
|
||||
|
||||
if (hash_mask == best_mask)
|
||||
best = (c0 > c_zero) || (c0 == c_zero && c1 > c_one);
|
||||
|
||||
else
|
||||
best = (hash_mask < best_mask);
|
||||
|
||||
if (best)
|
||||
{
|
||||
fprintf(stderr, "{%u,%u,%u,%u} & 0x%lx\n",
|
||||
c[0], c[1], c[2], c[3],
|
||||
(unsigned long)hash_mask);
|
||||
|
||||
c_zero = c0;
|
||||
c_one = c1;
|
||||
best_mask = hash_mask;
|
||||
memcpy(best_c, c, sizeof best_c);
|
||||
}
|
||||
}
|
||||
} /* i4 */
|
||||
} /* i3 */
|
||||
} /* i2 */
|
||||
} /* i1 */
|
||||
}
|
||||
|
||||
/* Calculate the LUT (png_chunk_hash) */
|
||||
{
|
||||
png_byte b;
|
||||
png_byte lut[256];
|
||||
|
||||
/* A failure returns PNG_KNOWN_CHUNK_COUNT: */
|
||||
memset(lut, known_chunk_count, sizeof lut);
|
||||
|
||||
for (b=0; b<known_chunk_count; ++b)
|
||||
lut[test_hash(chunks[b], best_c, best_mask)] = b;
|
||||
|
||||
/* Validate the pngpriv.h hash function. */
|
||||
# define png_chunk_hash lut
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for (i=0; i<known_chunk_count; ++i)
|
||||
{
|
||||
png_uint_32 chunk = chunks[i];
|
||||
|
||||
if (PNG_CHUNK_HASH(chunk) != i)
|
||||
error("internal error: hash didn't work!");
|
||||
}
|
||||
}
|
||||
# undef lut
|
||||
|
||||
/* Print all the results, first the stuff for pngpriv.h */
|
||||
{
|
||||
unsigned int i = 0;
|
||||
|
||||
while (strings[i] != 0)
|
||||
puts(strings[i++]);
|
||||
|
||||
printf("#define PNG_CHUNK_HASH_MASK 0x%lxU\n",
|
||||
(unsigned long)best_mask);
|
||||
printf("#define PNG_CHUNK_HASH_C0 %u\n", best_c[0]);
|
||||
printf("#define PNG_CHUNK_HASH_C1 %u\n", best_c[1]);
|
||||
printf("#define PNG_CHUNK_HASH_C2 %u\n", best_c[2]);
|
||||
printf("#define PNG_CHUNK_HASH_C3 %u\n", best_c[3]);
|
||||
|
||||
/* Print the hash codes of all the chunks */
|
||||
putchar('\n');
|
||||
print_chunks(chunks, known_chunk_count, 0, 0xffffffff, best_c,
|
||||
best_mask, lut);
|
||||
putchar('\n');
|
||||
printf("#define PNG_KNOWN_CHUNK_COUNT %u\n", known_chunk_count);
|
||||
|
||||
while (strings[++i] != 0)
|
||||
puts(strings[i]);
|
||||
|
||||
/* Now print the LUT */
|
||||
fputs(" ", stdout);
|
||||
{
|
||||
unsigned int j;
|
||||
|
||||
for (j=0; j<=best_mask; ++j)
|
||||
{
|
||||
printf("%d", lut[j]);
|
||||
|
||||
if ((j % 16) == 15 && j < best_mask)
|
||||
printf(",\n ");
|
||||
|
||||
else if (j < best_mask)
|
||||
printf(", ");
|
||||
|
||||
else
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
/* And the trailing text */
|
||||
while (strings[++i] != 0)
|
||||
puts(strings[i]);
|
||||
}
|
||||
}
|
||||
|
||||
exit(0);
|
||||
}
|
||||
97
contrib/tools/chunkhash.h
Normal file
97
contrib/tools/chunkhash.h
Normal file
@@ -0,0 +1,97 @@
|
||||
/* chunkhash.h -- a perfect hash code for the chunk names in png.h
|
||||
*
|
||||
* Last changed in libpng 1.7.0 [(PENDING RELEASE)]
|
||||
*
|
||||
* THIS IS A MACHINE GENERATED FILE. See contrib/tools/chunkhash.c for
|
||||
* copyright and other information.
|
||||
*
|
||||
* USAGE: To include the PNG_CHUNK_HASH macro and associated definitions:
|
||||
*
|
||||
* #define PNG_CHUNKHASH_DEFS
|
||||
* #include "contrib/tools/chunkhash.h"
|
||||
*
|
||||
* To define the png_chunk_hash array used by the macro:
|
||||
*
|
||||
* #define PNG_CHUNKHASH_CODE
|
||||
* #include "contrib/tools/chunkhash.h"
|
||||
*
|
||||
* One or both of the defines must be given except when building chunkhash
|
||||
* itself.
|
||||
*/
|
||||
#ifdef PNG_CHUNKHASH_DEFS
|
||||
#ifndef PNG_CHUNKHASH_H
|
||||
#define PNG_CHUNKHASH_H
|
||||
/* A perfect hash code - returns a value 0..(PNG_KNOWN_CHUNK_COUNT-1) and is
|
||||
* generated by the ridiculously simple program in contrib/tools/chunkhash.c
|
||||
*
|
||||
* The hash code used here multiplies each byte by a different constant to
|
||||
* return a single number:
|
||||
*
|
||||
* b0 * c[0] + b1 * [c1] + b2 * c[2] + b3 * c[3]
|
||||
*
|
||||
* The values of the constants are found by search using the a table of
|
||||
* primes, including 0, and may be (in fact are at present) 0 for some of the
|
||||
* bytes, the compiler is expected to optimize multiply by zero, or one!
|
||||
*
|
||||
* The lookup table reduces the sparse result of the hash calculation to the
|
||||
* correct index values. The chunks are indexed in the string order of the
|
||||
* png_uint_32 chunk names.
|
||||
*/
|
||||
#define PNG_CHUNK_HASH_MASK 0x3fU
|
||||
#define PNG_CHUNK_HASH_C0 103
|
||||
#define PNG_CHUNK_HASH_C1 1
|
||||
#define PNG_CHUNK_HASH_C2 0
|
||||
#define PNG_CHUNK_HASH_C3 1
|
||||
|
||||
#define PNG_CHUNK_IDAT_TAG 0
|
||||
#define PNG_CHUNK_IEND_TAG 1
|
||||
#define PNG_CHUNK_IHDR_TAG 2
|
||||
#define PNG_CHUNK_PLTE_TAG 3
|
||||
#define PNG_CHUNK_bKGD_TAG 4
|
||||
#define PNG_CHUNK_cHRM_TAG 5
|
||||
#define PNG_CHUNK_fRAc_TAG 6
|
||||
#define PNG_CHUNK_gAMA_TAG 7
|
||||
#define PNG_CHUNK_gIFg_TAG 8
|
||||
#define PNG_CHUNK_gIFt_TAG 9
|
||||
#define PNG_CHUNK_gIFx_TAG 10
|
||||
#define PNG_CHUNK_hIST_TAG 11
|
||||
#define PNG_CHUNK_iCCP_TAG 12
|
||||
#define PNG_CHUNK_iTXt_TAG 13
|
||||
#define PNG_CHUNK_oFFs_TAG 14
|
||||
#define PNG_CHUNK_pCAL_TAG 15
|
||||
#define PNG_CHUNK_pHYs_TAG 16
|
||||
#define PNG_CHUNK_sBIT_TAG 17
|
||||
#define PNG_CHUNK_sCAL_TAG 18
|
||||
#define PNG_CHUNK_sPLT_TAG 19
|
||||
#define PNG_CHUNK_sRGB_TAG 20
|
||||
#define PNG_CHUNK_sTER_TAG 21
|
||||
#define PNG_CHUNK_tEXt_TAG 22
|
||||
#define PNG_CHUNK_tIME_TAG 23
|
||||
#define PNG_CHUNK_tRNS_TAG 24
|
||||
#define PNG_CHUNK_zTXt_TAG 25
|
||||
|
||||
#define PNG_KNOWN_CHUNK_COUNT 26
|
||||
|
||||
extern const png_byte png_chunk_hash[PNG_CHUNK_HASH_MASK+1];
|
||||
#endif /* !PNG_CHUNKHASH_H */
|
||||
#endif /* PNG_CHUNKHASH_DEFS */
|
||||
|
||||
#ifndef PNG_CHUNK_HASH
|
||||
#define PNG_CHUNK_HASH(chunk) (png_chunk_hash[PNG_CHUNK_HASH_MASK & (\
|
||||
((chunk) >> 24) * PNG_CHUNK_HASH_C0 +\
|
||||
((chunk) >> 16) * PNG_CHUNK_HASH_C1 +\
|
||||
((chunk) >> 8) * PNG_CHUNK_HASH_C2 +\
|
||||
((chunk) ) * PNG_CHUNK_HASH_C3)])
|
||||
#endif
|
||||
|
||||
#ifdef PNG_CHUNKHASH_CODE
|
||||
#ifndef PNG_CHUNKHASH_C
|
||||
#define PNG_CHUNKHASH_C
|
||||
const png_byte png_chunk_hash[PNG_CHUNK_HASH_MASK+1] = {
|
||||
26, 3, 26, 26, 26, 26, 26, 13, 26, 26, 26, 16, 26, 26, 26, 26,
|
||||
26, 24, 12, 26, 18, 26, 26, 26, 26, 20, 26, 17, 26, 26, 25, 15,
|
||||
26, 8, 14, 26, 26, 22, 26, 26, 1, 19, 5, 21, 26, 26, 9, 26,
|
||||
26, 26, 10, 7, 26, 11, 26, 0, 26, 2, 23, 26, 26, 4, 26, 6
|
||||
};
|
||||
#endif /* !PNG_CHUNKHASH_C */
|
||||
#endif /* PNG_CHUNKHASH_CODE */
|
||||
@@ -1,9 +1,9 @@
|
||||
/*-
|
||||
* convert.c
|
||||
*
|
||||
* Last changed in libpng 1.6.0 [(PENDING RELEASE)]
|
||||
* Last changed in libpng 1.6.0 [February 14, 2013]
|
||||
*
|
||||
* COPYRIGHT: Written by John Cunningham Bowler, 2012.
|
||||
* COPYRIGHT: Written by John Cunningham Bowler, 2013.
|
||||
* 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.
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
#
|
||||
# intgamma.sh
|
||||
#
|
||||
# Last changed in libpng 1.6.0 [(PENDING RELEASE)]
|
||||
# Last changed in libpng 1.6.0 [February 14, 2013]
|
||||
#
|
||||
# COPYRIGHT: Written by John Cunningham Bowler, 2012.
|
||||
# COPYRIGHT: Written by John Cunningham Bowler, 2013.
|
||||
# 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.
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/* makesRGB.c -- build sRGB-to-linear and linear-to-sRGB conversion tables
|
||||
*
|
||||
* Last changed in libpng 1.6.0 [(PENDING RELEASE)]
|
||||
* Last changed in libpng 1.6.0 [February 14, 2013]
|
||||
*
|
||||
* COPYRIGHT: Written by John Cunningham Bowler, 2012.
|
||||
* COPYRIGHT: Written by John Cunningham Bowler, 2013.
|
||||
* 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.
|
||||
|
||||
153
contrib/tools/png-fix-itxt.c
Normal file
153
contrib/tools/png-fix-itxt.c
Normal file
@@ -0,0 +1,153 @@
|
||||
|
||||
/* png-fix-itxt version 1.0.0
|
||||
*
|
||||
* Copyright 2013 Glenn Randers-Pehrson
|
||||
* Last changed in libpng 1.6.3 [July 18, 2013]
|
||||
*
|
||||
* This code is released under the libpng license.
|
||||
* For conditions of distribution and use, see the disclaimer
|
||||
* and license in png.h
|
||||
*
|
||||
* Usage:
|
||||
*
|
||||
* png-fix-itxt.exe < bad.png > good.png
|
||||
*
|
||||
* Fixes a PNG file written with libpng-1.6.0 or 1.6.1 that has one or more
|
||||
* uncompressed iTXt chunks. Assumes that the actual length is greater
|
||||
* than or equal to the value in the length byte, and that the CRC is
|
||||
* correct for the actual length. This program hunts for the CRC and
|
||||
* adjusts the length byte accordingly. It is not an error to process a
|
||||
* PNG file that has no iTXt chunks or one that has valid iTXt chunks;
|
||||
* such files will simply be copied.
|
||||
*
|
||||
* Requires zlib (for crc32 and Z_NULL); build with
|
||||
*
|
||||
* gcc -O -o png-fix-itxt png-fix-itxt.c -lz
|
||||
*
|
||||
* If you need to handle iTXt chunks larger than 500000 kbytes you must
|
||||
* rebuild png-fix-itxt with a larger values of MAX_LENGTH (or a smaller value
|
||||
* if you know you will never encounter such huge iTXt chunks).
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <zlib.h>
|
||||
|
||||
#define MAX_LENGTH 500000
|
||||
|
||||
#define GETBREAK ((unsigned char)(inchar=getchar())); if (inchar == EOF) break
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
unsigned int i;
|
||||
unsigned char buf[MAX_LENGTH];
|
||||
unsigned long crc;
|
||||
unsigned char c;
|
||||
int inchar;
|
||||
|
||||
/* Skip 8-byte signature */
|
||||
for (i=8; i; i--)
|
||||
{
|
||||
c=GETBREAK;
|
||||
putchar(c);
|
||||
}
|
||||
|
||||
if (inchar != EOF)
|
||||
for (;;)
|
||||
{
|
||||
/* Read the length */
|
||||
unsigned long length; /* must be 32 bits! */
|
||||
c=GETBREAK; buf[0] = c; length = c; length <<= 8;
|
||||
c=GETBREAK; buf[1] = c; length += c; length <<= 8;
|
||||
c=GETBREAK; buf[2] = c; length += c; length <<= 8;
|
||||
c=GETBREAK; buf[3] = c; length += c;
|
||||
|
||||
/* Read the chunkname */
|
||||
c=GETBREAK; buf[4] = c;
|
||||
c=GETBREAK; buf[5] = c;
|
||||
c=GETBREAK; buf[6] = c;
|
||||
c=GETBREAK; buf[7] = c;
|
||||
|
||||
|
||||
/* The iTXt chunk type expressed as integers is (105, 84, 88, 116) */
|
||||
if (buf[4] == 105 && buf[5] == 84 && buf[6] == 88 && buf[7] == 116)
|
||||
{
|
||||
if (length >= MAX_LENGTH-12)
|
||||
break; /* To do: handle this more gracefully */
|
||||
|
||||
/* Initialize the CRC */
|
||||
crc = crc32(0, Z_NULL, 0);
|
||||
|
||||
/* Copy the data bytes */
|
||||
for (i=8; i < length + 12; i++)
|
||||
{
|
||||
c=GETBREAK; buf[i] = c;
|
||||
}
|
||||
|
||||
/* Calculate the CRC */
|
||||
crc = crc32(crc, buf+4, (uInt)length+4);
|
||||
|
||||
for (;;)
|
||||
{
|
||||
/* Check the CRC */
|
||||
if (((crc >> 24) & 0xff) == buf[length+8] &&
|
||||
((crc >> 16) & 0xff) == buf[length+9] &&
|
||||
((crc >> 8) & 0xff) == buf[length+10] &&
|
||||
((crc ) & 0xff) == buf[length+11])
|
||||
break;
|
||||
|
||||
length++;
|
||||
|
||||
if (length >= MAX_LENGTH-12)
|
||||
break;
|
||||
|
||||
c=GETBREAK;
|
||||
buf[length+11]=c;
|
||||
|
||||
/* Update the CRC */
|
||||
crc = crc32(crc, buf+7+length, 1);
|
||||
}
|
||||
|
||||
/* Update length bytes */
|
||||
buf[0] = (unsigned char)((length << 24) & 0xff);
|
||||
buf[1] = (unsigned char)((length << 16) & 0xff);
|
||||
buf[2] = (unsigned char)((length << 8) & 0xff);
|
||||
buf[3] = (unsigned char)((length ) & 0xff);
|
||||
|
||||
/* Write the fixed iTXt chunk (length, name, data, crc) */
|
||||
for (i=0; i<length+12; i++)
|
||||
putchar(buf[i]);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
/* Copy bytes that were already read (length and chunk name) */
|
||||
for (i=0; i<8; i++)
|
||||
putchar(buf[i]);
|
||||
|
||||
/* Copy data bytes and CRC */
|
||||
for (i=8; i< length+12; i++)
|
||||
{
|
||||
c=GETBREAK;
|
||||
putchar(c);
|
||||
}
|
||||
|
||||
if (inchar == EOF)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
/* The IEND chunk type expressed as integers is (73, 69, 78, 68) */
|
||||
if (buf[4] == 73 && buf[5] == 69 && buf[6] == 78 && buf[7] == 68)
|
||||
break;
|
||||
}
|
||||
|
||||
if (inchar == EOF)
|
||||
break;
|
||||
|
||||
if (buf[4] == 73 && buf[5] == 69 && buf[6] == 78 && buf[7] == 68)
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
4048
contrib/tools/pngfix.c
Normal file
4048
contrib/tools/pngfix.c
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,9 +1,9 @@
|
||||
/*-
|
||||
* sRGB.h
|
||||
*
|
||||
* Last changed in libpng 1.6.0 [(PENDING RELEASE)]
|
||||
* Last changed in libpng 1.6.0 [February 14, 2013]
|
||||
*
|
||||
* COPYRIGHT: Written by John Cunningham Bowler, 2012.
|
||||
* COPYRIGHT: Written by John Cunningham Bowler, 2013.
|
||||
* 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.
|
||||
|
||||
238
contrib/tools/scale.c
Normal file
238
contrib/tools/scale.c
Normal file
@@ -0,0 +1,238 @@
|
||||
/* Given a target range and a source range work out an expression to scale from
|
||||
* the source to the target of the form:
|
||||
*
|
||||
* (number * mult + add)>>16
|
||||
*
|
||||
* The command arguments are:
|
||||
*
|
||||
* scale target source
|
||||
*
|
||||
* and the program works out a pair of numbers, mult and add, that evaluate:
|
||||
*
|
||||
* number * target
|
||||
* round( --------------- )
|
||||
* source
|
||||
*
|
||||
* exactly for number in the range 0..source
|
||||
*/
|
||||
#define _ISOC99_SOURCE 1
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
static double minerr;
|
||||
static unsigned long minmult, minadd, minshift;
|
||||
static long mindelta;
|
||||
|
||||
static int
|
||||
test(unsigned long target, unsigned long source, unsigned long mult,
|
||||
long add, unsigned long shift, long delta)
|
||||
{
|
||||
unsigned long i;
|
||||
double maxerr = 0;
|
||||
double rs = (double)target/source;
|
||||
|
||||
for (i=0; i<=source; ++i)
|
||||
{
|
||||
unsigned long t = i*mult+add;
|
||||
double err = fabs((t >> shift) - i*rs);
|
||||
|
||||
if (err > minerr)
|
||||
return 0;
|
||||
|
||||
if (err > maxerr)
|
||||
maxerr = err;
|
||||
}
|
||||
|
||||
if (maxerr < minerr)
|
||||
{
|
||||
minerr = maxerr;
|
||||
minmult = mult;
|
||||
minadd = add;
|
||||
minshift = shift;
|
||||
mindelta = delta;
|
||||
}
|
||||
|
||||
return maxerr < .5;
|
||||
}
|
||||
|
||||
static int
|
||||
dotest(unsigned long target, unsigned long source, unsigned long mult,
|
||||
long add, unsigned long shift, long delta, int print)
|
||||
{
|
||||
if (test(target, source, mult, add, shift, delta))
|
||||
{
|
||||
if (print & 4)
|
||||
printf(" {%11lu,%6ld /* >>%lu */ }, /* %lu/%lu */\n",
|
||||
mult, add, shift, target, source);
|
||||
|
||||
else if (print & 2)
|
||||
printf(" {%11lu,%6ld,%3lu }, /* %lu/%lu */\n",
|
||||
mult, add, shift, target, source);
|
||||
|
||||
else if (print)
|
||||
printf("number * %lu/%lu = (number * %lu + %ld) >> %lu [delta %ld]\n",
|
||||
target, source, mult, add, shift, delta);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
find(unsigned long target, unsigned long source, int print, int fixshift)
|
||||
{
|
||||
unsigned long shift = 0;
|
||||
unsigned long shiftlim = 0;
|
||||
|
||||
/* In the final math the sum is at most (source*mult+add) >> shift, so:
|
||||
*
|
||||
* source*mult+add < 1<<32
|
||||
* mult < (1<<32)/source
|
||||
*
|
||||
* but:
|
||||
*
|
||||
* mult = (target<<shift)/source
|
||||
*
|
||||
* so:
|
||||
*
|
||||
* (target<<shift) < (1<<32)
|
||||
*/
|
||||
if (fixshift < 0)
|
||||
while ((target<<shiftlim) < 0x80000000U) ++shiftlim;
|
||||
|
||||
else
|
||||
shift = shiftlim = (unsigned long)fixshift;
|
||||
|
||||
minerr = 1E8;
|
||||
|
||||
for (; shift<=shiftlim; ++shift)
|
||||
{
|
||||
unsigned long mult = ((target<<shift) + (source>>1)) / source;
|
||||
long delta;
|
||||
long limit = 1; /* seems to be sufficient */
|
||||
long add, start, end;
|
||||
|
||||
end = 1<<shift;
|
||||
start = -end;
|
||||
|
||||
for (add=start; add<=end; ++add)
|
||||
if (dotest(target,source,mult,add,shift,0,print))
|
||||
return 1;
|
||||
|
||||
for (delta=1; delta<=limit; ++delta)
|
||||
{
|
||||
# if 0
|
||||
fprintf(stderr, "%lu/%lu: shift %lu, delta %lu\n", target, source,
|
||||
shift, delta);
|
||||
# endif
|
||||
|
||||
for (add=start; add<=end; ++add)
|
||||
{
|
||||
if (dotest(target, source, mult-delta, add, shift, -delta, print))
|
||||
return 1;
|
||||
|
||||
if (dotest(target, source, mult+delta, add, shift, delta, print))
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (print & 4)
|
||||
printf(" {%11lu,%6ld /* >>%lu */ }, /* %lu/%lu ERROR: .5+%g*/\n",
|
||||
minmult, minadd, minshift, target, source, minerr-.5);
|
||||
|
||||
else if (print & 2)
|
||||
printf(" {%11lu,%6ld,%3lu }, /* %lu/%lu ERROR: .5+%g*/\n",
|
||||
minmult, minadd, minshift, target, source, minerr-.5);
|
||||
|
||||
else if (print)
|
||||
printf(
|
||||
"number * %lu/%lu ~= (number * %lu + %ld) >> %lu +/-.5+%g [delta %ld]\n",
|
||||
target, source, minmult, minadd, minshift, minerr-.5, mindelta);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
usage(const char *prog)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"usage: %s {--denominator|--maxshift|--code} target {source}\n"
|
||||
" For each 'source' prints 'mult' and 'add' such that:\n\n"
|
||||
" (number * mult + add) >> 16 = round(number*target/source)\n\n"
|
||||
" for all integer values of number in the range 0..source.\n\n"
|
||||
" --denominator: swap target and source (specify a single source first\n"
|
||||
" and follow with multiple targets.)\n"
|
||||
" --maxshift: find the lowest shift value that works for all the\n"
|
||||
" repeated 'source' values\n"
|
||||
" --code: output C code for array/structure initialization\n",
|
||||
prog);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, const char **argv)
|
||||
{
|
||||
int i, err = 0, maxshift = 0, firstsrc = 1, code = 0, denominator = 0;
|
||||
unsigned long target, shift = 0;
|
||||
|
||||
while (argc > 1)
|
||||
{
|
||||
if (strcmp(argv[firstsrc], "--maxshift") == 0)
|
||||
{
|
||||
maxshift = 1;
|
||||
++firstsrc;
|
||||
}
|
||||
|
||||
else if (strcmp(argv[firstsrc], "--code") == 0)
|
||||
{
|
||||
code = 1;
|
||||
++firstsrc;
|
||||
}
|
||||
|
||||
else if (strcmp(argv[firstsrc], "--denominator") == 0)
|
||||
{
|
||||
denominator = 1;
|
||||
++firstsrc;
|
||||
}
|
||||
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (argc < 2+firstsrc)
|
||||
usage(argv[0]);
|
||||
|
||||
target = strtoul(argv[firstsrc++], 0, 0);
|
||||
if (target == 0) usage(argv[0]);
|
||||
|
||||
for (i=firstsrc; i<argc; ++i)
|
||||
{
|
||||
unsigned long source = strtoul(argv[i], 0, 0);
|
||||
|
||||
if (source == 0) usage(argv[0]);
|
||||
|
||||
if (!find(denominator ? source : target, denominator ? target : source,
|
||||
maxshift ? 0 : 1+code, -1))
|
||||
err = 1;
|
||||
|
||||
if (minshift > shift) shift = minshift;
|
||||
}
|
||||
|
||||
if (maxshift) for (i=firstsrc; i<argc; ++i)
|
||||
{
|
||||
unsigned long source = strtoul(argv[i], 0, 0);
|
||||
|
||||
if (!find(denominator ? source : target, denominator ? target : source,
|
||||
code ? 4 : 1, shift))
|
||||
err = 1;
|
||||
}
|
||||
|
||||
/* Just an exit code - the printout above lists the problem */
|
||||
return err;
|
||||
}
|
||||
50
example.c
50
example.c
@@ -2,8 +2,8 @@
|
||||
#if 0 /* in case someone actually tries to compile this */
|
||||
|
||||
/* example.c - an example of using libpng
|
||||
* Last changed in libpng 1.6.0 [(PENDING RELEASE)]
|
||||
* Maintained 1998-2012 Glenn Randers-Pehrson
|
||||
* Last changed in libpng 1.7.0 [(PENDING RELEASE)]
|
||||
* Maintained 1998-2014 Glenn Randers-Pehrson
|
||||
* Maintained 1996, 1997 Andreas Dilger)
|
||||
* Written 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
|
||||
* To the extent possible under law, the authors have waived
|
||||
@@ -39,7 +39,7 @@
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <png.h>
|
||||
#include <zlib.h>
|
||||
#include PNG_ZLIB_HEADER /* this is the header libpng was built with */
|
||||
|
||||
int main(int argc, const char **argv)
|
||||
{
|
||||
@@ -52,7 +52,7 @@ int main(int argc, const char **argv)
|
||||
image.version = PNG_IMAGE_VERSION;
|
||||
|
||||
/* The first argument is the file to read: */
|
||||
if (png_image_begin_read_from_file(&image, argv[1]))
|
||||
if (png_image_begin_read_from_file(&image, argv[1]) != 0)
|
||||
{
|
||||
png_bytep buffer;
|
||||
|
||||
@@ -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/*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*/))
|
||||
buffer, 0/*row_stride*/, NULL/*colormap*/) != 0)
|
||||
{
|
||||
/* The image has been written successfully. */
|
||||
exit(0);
|
||||
@@ -188,13 +188,13 @@ int main(int argc, const char **argv)
|
||||
*
|
||||
* Don't repeatedly convert between the 8-bit and 16-bit forms. There is
|
||||
* significant data loss when 16-bit data is converted to the 8-bit encoding and
|
||||
* the current libpng implementation of convertion to 16-bit is also
|
||||
* the current libpng implementation of conversion to 16-bit is also
|
||||
* significantly lossy. The latter will be fixed in the future, but the former
|
||||
* is unavoidable - the 8-bit format just doesn't have enough resolution.
|
||||
*/
|
||||
|
||||
/* If your program needs more information from the PNG data it reads, or if you
|
||||
* need to do more complex transformations, or minimise transformations, on the
|
||||
* need to do more complex transformations, or minimize transformations, on the
|
||||
* data you read, then you must use one of the several lower level libpng
|
||||
* interfaces.
|
||||
*
|
||||
@@ -405,7 +405,7 @@ void read_png(FILE *fp, unsigned int sig_read) /* File is already open */
|
||||
/* Expand paletted or RGB images with transparency to full alpha channels
|
||||
* so the data will be available as RGBA quartets.
|
||||
*/
|
||||
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
|
||||
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS) != 0)
|
||||
png_set_tRNS_to_alpha(png_ptr);
|
||||
|
||||
/* Set the background color to draw transparent and alpha images over.
|
||||
@@ -417,7 +417,7 @@ void read_png(FILE *fp, unsigned int sig_read) /* File is already open */
|
||||
|
||||
png_color_16 my_background, *image_background;
|
||||
|
||||
if (png_get_bKGD(png_ptr, info_ptr, &image_background))
|
||||
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);
|
||||
else
|
||||
@@ -441,9 +441,9 @@ void read_png(FILE *fp, unsigned int sig_read) /* File is already open */
|
||||
/* If we don't have another value */
|
||||
else
|
||||
{
|
||||
screen_gamma = 2.2; /* A good guess for a PC monitor in a dimly
|
||||
lit room */
|
||||
screen_gamma = 1.7 or 1.0; /* A good guess for Mac systems */
|
||||
screen_gamma = PNG_DEFAULT_sRGB; /* A good guess for a PC monitor
|
||||
in a dimly lit room */
|
||||
screen_gamma = PNG_GAMMA_MAC_18 or 1.0; /* Good guesses for Mac systems */
|
||||
}
|
||||
|
||||
/* Tell libpng to handle the gamma conversion for you. The final call
|
||||
@@ -454,12 +454,12 @@ void read_png(FILE *fp, unsigned int sig_read) /* File is already open */
|
||||
|
||||
int intent;
|
||||
|
||||
if (png_get_sRGB(png_ptr, info_ptr, &intent))
|
||||
png_set_gamma(png_ptr, screen_gamma, 0.45455);
|
||||
if (png_get_sRGB(png_ptr, info_ptr, &intent) != 0)
|
||||
png_set_gamma(png_ptr, screen_gamma, PNG_DEFAULT_sRGB);
|
||||
else
|
||||
{
|
||||
double image_gamma;
|
||||
if (png_get_gAMA(png_ptr, info_ptr, &image_gamma))
|
||||
if (png_get_gAMA(png_ptr, info_ptr, &image_gamma) != 0)
|
||||
png_set_gamma(png_ptr, screen_gamma, image_gamma);
|
||||
else
|
||||
png_set_gamma(png_ptr, screen_gamma, 0.45455);
|
||||
@@ -469,7 +469,7 @@ void read_png(FILE *fp, unsigned int sig_read) /* File is already open */
|
||||
/* Quantize RGB files down to 8 bit palette or reduce palettes
|
||||
* to the number of colors available on your screen.
|
||||
*/
|
||||
if (color_type & PNG_COLOR_MASK_COLOR)
|
||||
if ((color_type & PNG_COLOR_MASK_COLOR) != 0)
|
||||
{
|
||||
int num_palette;
|
||||
png_colorp palette;
|
||||
@@ -484,7 +484,7 @@ void read_png(FILE *fp, unsigned int sig_read) /* File is already open */
|
||||
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))
|
||||
else if (png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette) != 0)
|
||||
{
|
||||
png_uint_16p histogram = NULL;
|
||||
|
||||
@@ -494,7 +494,7 @@ void read_png(FILE *fp, unsigned int sig_read) /* File is already open */
|
||||
max_screen_colors, histogram, 0);
|
||||
}
|
||||
}
|
||||
#endif /* PNG_READ_QUANTIZE_SUPPORTED */
|
||||
#endif /* READ_QUANTIZE */
|
||||
|
||||
/* Invert monochrome files to have 0 as white and 1 as black */
|
||||
png_set_invert_mono(png_ptr);
|
||||
@@ -503,7 +503,7 @@ void read_png(FILE *fp, unsigned int sig_read) /* File is already open */
|
||||
* [0,65535] to the original [0,7] or [0,31], or whatever range the
|
||||
* colors were originally in:
|
||||
*/
|
||||
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT))
|
||||
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT) != 0)
|
||||
{
|
||||
png_color_8p sig_bit_p;
|
||||
|
||||
@@ -512,7 +512,7 @@ void read_png(FILE *fp, unsigned int sig_read) /* File is already open */
|
||||
}
|
||||
|
||||
/* Flip the RGB pixels to BGR (or RGBA to BGRA) */
|
||||
if (color_type & PNG_COLOR_MASK_COLOR)
|
||||
if ((color_type & PNG_COLOR_MASK_COLOR) != 0)
|
||||
png_set_bgr(png_ptr);
|
||||
|
||||
/* Swap the RGBA or GA data to ARGB or AG (or BGRA to ABGR) */
|
||||
@@ -532,7 +532,7 @@ void read_png(FILE *fp, unsigned int sig_read) /* File is already open */
|
||||
number_passes = png_set_interlace_handling(png_ptr);
|
||||
#else
|
||||
number_passes = 1;
|
||||
#endif /* PNG_READ_INTERLACING_SUPPORTED */
|
||||
#endif /* READ_INTERLACING */
|
||||
|
||||
|
||||
/* Optional call to gamma correct and add the background to the palette
|
||||
@@ -744,7 +744,7 @@ row_callback(png_structp png_ptr, png_bytep new_row,
|
||||
* to pass the current row as new_row, and the function will combine
|
||||
* the old row and the new row.
|
||||
*/
|
||||
#endif /* PNG_READ_INTERLACING_SUPPORTED */
|
||||
#endif /* READ_INTERLACING */
|
||||
}
|
||||
|
||||
end_callback(png_structp png_ptr, png_infop info)
|
||||
@@ -932,7 +932,7 @@ void write_png(char *file_name /* , ... other image information ... */)
|
||||
*/
|
||||
|
||||
/* Once we write out the header, the compression type on the text
|
||||
* chunks gets changed to PNG_TEXT_COMPRESSION_NONE_WR or
|
||||
* chunk gets changed to PNG_TEXT_COMPRESSION_NONE_WR or
|
||||
* PNG_TEXT_COMPRESSION_zTXt_WR, so it doesn't get written out again
|
||||
* at the end.
|
||||
*/
|
||||
@@ -970,7 +970,7 @@ void write_png(char *file_name /* , ... other image information ... */)
|
||||
png_set_packswap(png_ptr);
|
||||
|
||||
/* Turn on interlace handling if you are not using png_write_image() */
|
||||
if (interlacing)
|
||||
if (interlacing != 0)
|
||||
number_passes = png_set_interlace_handling(png_ptr);
|
||||
|
||||
else
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
16
libpngpf.3
16
libpngpf.3
@@ -1,21 +1,11 @@
|
||||
.TH LIBPNGPF 3 "December 10, 2012"
|
||||
.TH LIBPNGPF 3 "November 20, 2014"
|
||||
.SH NAME
|
||||
libpng \- Portable Network Graphics (PNG) Reference Library 1.6.0beta33
|
||||
libpng \- Portable Network Graphics (PNG) Reference Library 1.7.0beta42
|
||||
(private functions)
|
||||
.SH SYNOPSIS
|
||||
\fB#include \fI"pngpriv.h"
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBAs of libpng version \fP\fI1.5.1\fP\fB, this section is no longer \fP\fImaintained\fP\fB, now \fIthat
|
||||
|
||||
\fBthe private function prototypes are hidden in pngpriv.h and not \fIaccessible
|
||||
|
||||
\fBto applications. Look in pngpriv.h for the prototypes and a short \fIdescription
|
||||
|
||||
\fBof each \fIfunction.
|
||||
|
||||
\fI\fB
|
||||
\fBAs of libpng version \fP\fI1.5.1\fP\fB, this section is no longer \fP\fImaintained\fP\fB, now that the private function prototypes are hidden in pngpriv.h and not accessible to applications. Look in pngpriv.h for the prototypes and a short description of each \fIfunction.
|
||||
|
||||
.SH DESCRIPTION
|
||||
The functions previously listed here are used privately by libpng and are not
|
||||
|
||||
5
png.5
5
png.5
@@ -1,4 +1,4 @@
|
||||
.TH PNG 5 "December 10, 2012"
|
||||
.TH PNG 5 "November 20, 2014"
|
||||
.SH NAME
|
||||
png \- Portable Network Graphics (PNG) format
|
||||
.SH DESCRIPTION
|
||||
@@ -24,6 +24,7 @@ PNG specification (second edition), November 2003:
|
||||
.IP
|
||||
.br
|
||||
<http://www.w3.org/TR/2003/REC-PNG-20031110/
|
||||
.LP
|
||||
PNG 1.2 specification, July 1999:
|
||||
.IP
|
||||
.br
|
||||
@@ -58,7 +59,7 @@ Thomas Boutell and others (png-list).
|
||||
|
||||
.SH COPYRIGHT NOTICE
|
||||
.LP
|
||||
This man page is Copyright (c) 1998-2006 Glenn Randers-Pehrson. See png.h
|
||||
This man page is Copyright (c) 1998-2012 Glenn Randers-Pehrson. See png.h
|
||||
for conditions of use and distribution.
|
||||
.LP
|
||||
The PNG Specification (Second Edition) is
|
||||
|
||||
85
pngconf.h
85
pngconf.h
@@ -1,9 +1,9 @@
|
||||
|
||||
/* pngconf.h - machine configurable file for libpng
|
||||
*
|
||||
* libpng version 1.6.0beta33 - December 10, 2012
|
||||
* libpng version 1.7.0beta42 - November 20, 2014
|
||||
*
|
||||
* Copyright (c) 1998-2012 Glenn Randers-Pehrson
|
||||
* Copyright (c) 1998-2013 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.)
|
||||
*
|
||||
@@ -198,18 +198,16 @@
|
||||
* ==========================
|
||||
* This code is used at build time to find PNG_IMPEXP, the API settings
|
||||
* and PNG_EXPORT_TYPE(), it may also set a macro to indicate the DLL
|
||||
* import processing is possible. On Windows/x86 systems it also sets
|
||||
* import processing is possible. On Windows systems it also sets
|
||||
* compiler-specific macros to the values required to change the calling
|
||||
* conventions of the various functions.
|
||||
*/
|
||||
#if ( defined(_Windows) || defined(_WINDOWS) || defined(WIN32) ||\
|
||||
defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) ) &&\
|
||||
( defined(_X86_) || defined(_X64_) || defined(_M_IX86) ||\
|
||||
defined(_M_X64) || defined(_M_IA64) )
|
||||
/* Windows system (DOS doesn't support DLLs) running on x86/x64. Includes
|
||||
* builds under Cygwin or MinGW. Also includes Watcom builds but these need
|
||||
* special treatment because they are not compatible with GCC or Visual C
|
||||
* because of different calling conventions.
|
||||
#if defined(_Windows) || defined(_WINDOWS) || defined(WIN32) ||\
|
||||
defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
|
||||
/* Windows system (DOS doesn't support DLLs). Includes builds under Cygwin or
|
||||
* MinGW on any architecture currently supported by Windows. Also includes
|
||||
* Watcom builds but these need special treatment because they are not
|
||||
* 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
|
||||
@@ -220,9 +218,12 @@
|
||||
# define PNGCAPI __watcall
|
||||
# endif
|
||||
|
||||
# if defined(__GNUC__) || (defined (_MSC_VER) && (_MSC_VER >= 800))
|
||||
# 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'.
|
||||
*/
|
||||
# define PNGAPI __stdcall
|
||||
# endif
|
||||
# else
|
||||
@@ -260,7 +261,7 @@
|
||||
# endif
|
||||
# endif /* compiler */
|
||||
|
||||
#else /* !Windows/x86 */
|
||||
#else /* !Windows */
|
||||
# if (defined(__IBMC__) || defined(__IBMCPP__)) && defined(__OS2__)
|
||||
# define PNGAPI _System
|
||||
# else /* !Windows/x86 && !OS/2 */
|
||||
@@ -359,7 +360,32 @@
|
||||
* version 1.2.41. Disabling these removes the warnings but may also produce
|
||||
* less efficient code.
|
||||
*/
|
||||
# if defined(__GNUC__)
|
||||
# if defined(__clang__) && defined(__has_attribute)
|
||||
/* 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
|
||||
# if !defined(PNG_NORETURN) && __has_attribute(__noreturn__)
|
||||
# define PNG_NORETURN __attribute__((__noreturn__))
|
||||
# endif
|
||||
# if !defined(PNG_ALLOCATED) && __has_attribute(__malloc__)
|
||||
# define PNG_ALLOCATED __attribute__((__malloc__))
|
||||
# endif
|
||||
# if !defined(PNG_DEPRECATED) && __has_attribute(__deprecated__)
|
||||
# define PNG_DEPRECATED __attribute__((__deprecated__))
|
||||
# endif
|
||||
# if !defined(PNG_PRIVATE)
|
||||
# ifdef __has_extension
|
||||
# if __has_extension(attribute_unavailable_with_message)
|
||||
# define PNG_PRIVATE __attribute__((__unavailable__(\
|
||||
"This function is not exported by libpng.")))
|
||||
# endif
|
||||
# endif
|
||||
# endif
|
||||
# ifndef PNG_RESTRICT
|
||||
# define PNG_RESTRICT __restrict
|
||||
# endif
|
||||
# elif defined(__GNUC__)
|
||||
# ifndef PNG_USE_RESULT
|
||||
# define PNG_USE_RESULT __attribute__((__warn_unused_result__))
|
||||
# endif
|
||||
@@ -382,12 +408,12 @@
|
||||
__attribute__((__deprecated__))
|
||||
# endif
|
||||
# endif
|
||||
# if ((__GNUC__ != 3) || !defined(__GNUC_MINOR__) || (__GNUC_MINOR__ >= 1))
|
||||
# if ((__GNUC__ > 3) || !defined(__GNUC_MINOR__) || (__GNUC_MINOR__ >= 1))
|
||||
# ifndef PNG_RESTRICT
|
||||
# define PNG_RESTRICT __restrict
|
||||
# endif
|
||||
# endif /* __GNUC__ == 3.0 */
|
||||
# endif /* __GNUC__ >= 3 */
|
||||
# endif /* __GNUC__.__GNUC_MINOR__ > 3.0 */
|
||||
# endif /* __GNUC__ >= 3 */
|
||||
|
||||
# elif defined(_MSC_VER) && (_MSC_VER >= 1300)
|
||||
# ifndef PNG_USE_RESULT
|
||||
@@ -417,7 +443,7 @@
|
||||
# ifndef PNG_RESTRICT
|
||||
# define PNG_RESTRICT __restrict
|
||||
# endif
|
||||
# endif /* _MSC_VER */
|
||||
# endif
|
||||
#endif /* PNG_PEDANTIC_WARNINGS */
|
||||
|
||||
#ifndef PNG_DEPRECATED
|
||||
@@ -438,6 +464,15 @@
|
||||
#ifndef PNG_RESTRICT
|
||||
# define PNG_RESTRICT /* The C99 "restrict" feature */
|
||||
#endif
|
||||
|
||||
#ifndef PNG_FP_EXPORT /* A floating point API. */
|
||||
# ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
# define PNG_FP_EXPORT(ordinal, type, name, args)\
|
||||
PNG_EXPORT(ordinal, type, name, args);
|
||||
# else /* No floating point APIs */
|
||||
# define PNG_FP_EXPORT(ordinal, type, name, args)
|
||||
# endif
|
||||
#endif
|
||||
#ifndef PNG_FP_EXPORT /* A floating point API. */
|
||||
# ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
# define PNG_FP_EXPORT(ordinal, type, name, args)\
|
||||
@@ -510,6 +545,8 @@
|
||||
|
||||
/* Prior to 1.6.0 it was possible to disable the use of size_t, 1.6.0, however,
|
||||
* requires an ISOC90 compiler and relies on consistent behavior of sizeof.
|
||||
*
|
||||
* DEPRECATED: don't use these types, instead use size_t and ptrdiff_t.
|
||||
*/
|
||||
typedef size_t png_size_t;
|
||||
typedef ptrdiff_t png_ptrdiff_t;
|
||||
@@ -530,13 +567,13 @@ typedef ptrdiff_t png_ptrdiff_t;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* png_alloc_size_t is guaranteed to be no smaller than png_size_t, and no
|
||||
* smaller than png_uint_32. Casts from png_size_t or png_uint_32 to
|
||||
/* png_alloc_size_t is guaranteed to be no smaller than size_t, and no
|
||||
* smaller than png_uint_32. Casts from size_t or png_uint_32 to
|
||||
* png_alloc_size_t are not necessary; in fact, it is recommended not to use
|
||||
* them at all so that the compiler can complain when something turns out to be
|
||||
* problematic.
|
||||
*
|
||||
* Casts in the other direction (from png_alloc_size_t to png_size_t or
|
||||
* Casts in the other direction (from png_alloc_size_t to size_t or
|
||||
* png_uint_32) should be explicitly applied; however, we do not expect to
|
||||
* encounter practical situations that require such conversions.
|
||||
*
|
||||
@@ -546,7 +583,7 @@ typedef ptrdiff_t png_ptrdiff_t;
|
||||
#ifdef PNG_SMALL_SIZE_T
|
||||
typedef png_uint_32 png_alloc_size_t;
|
||||
#else
|
||||
typedef png_size_t png_alloc_size_t;
|
||||
typedef size_t png_alloc_size_t;
|
||||
#endif
|
||||
|
||||
/* Prior to 1.6.0 libpng offered limited support for Microsoft C compiler
|
||||
@@ -582,8 +619,8 @@ typedef char * png_charp;
|
||||
typedef const char * png_const_charp;
|
||||
typedef png_fixed_point * png_fixed_point_p;
|
||||
typedef const png_fixed_point * png_const_fixed_point_p;
|
||||
typedef png_size_t * png_size_tp;
|
||||
typedef const png_size_t * png_const_size_tp;
|
||||
typedef size_t * png_size_tp;
|
||||
typedef const size_t * png_const_size_tp;
|
||||
|
||||
#ifdef PNG_STDIO_SUPPORTED
|
||||
typedef FILE * png_FILE_p;
|
||||
|
||||
21
pngdebug.h
21
pngdebug.h
@@ -1,11 +1,11 @@
|
||||
|
||||
/* pngdebug.h - Debugging macros for libpng, also used in pngtest.c
|
||||
*
|
||||
* Copyright (c) 1998-2011 Glenn Randers-Pehrson
|
||||
* Copyright (c) 1998-2013 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.)
|
||||
*
|
||||
* Last changed in libpng 1.5.0 [January 6, 2011]
|
||||
* Last changed in libpng 1.6.8 [December 19, 2013]
|
||||
*
|
||||
* This code is released under the libpng license.
|
||||
* For conditions of distribution and use, see the disclaimer
|
||||
@@ -25,7 +25,7 @@
|
||||
* (actually ((void)0)).
|
||||
*
|
||||
* level: level of detail of message, starting at 0. A level 'n'
|
||||
* message is preceded by 'n' tab characters (not implemented
|
||||
* message is preceded by 'n' 3-space indentations (not implemented
|
||||
* on Microsoft compilers unless PNG_DEBUG_FILE is also
|
||||
* defined, to allow debug DLL compilation with no standard IO).
|
||||
* message: a printf(3) style text string. A trailing '\n' is added
|
||||
@@ -77,32 +77,29 @@
|
||||
# endif /* PNG_DEBUG_FILE */
|
||||
|
||||
# if (PNG_DEBUG > 1)
|
||||
/* Note: ["%s"m PNG_STRING_NEWLINE] probably does not work on
|
||||
* non-ISO compilers
|
||||
*/
|
||||
# ifdef __STDC__
|
||||
# ifndef png_debug
|
||||
# define png_debug(l,m) \
|
||||
do { \
|
||||
int num_tabs=l; \
|
||||
fprintf(PNG_DEBUG_FILE,"%s"m PNG_STRING_NEWLINE,(num_tabs==1 ? "\t" : \
|
||||
(num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":"")))); \
|
||||
fprintf(PNG_DEBUG_FILE,"%s" m PNG_STRING_NEWLINE,(num_tabs==1 ? " " : \
|
||||
(num_tabs==2 ? " " : (num_tabs>2 ? " " : "")))); \
|
||||
} while (0)
|
||||
# endif
|
||||
# ifndef png_debug1
|
||||
# define png_debug1(l,m,p1) \
|
||||
do { \
|
||||
int num_tabs=l; \
|
||||
fprintf(PNG_DEBUG_FILE,"%s"m PNG_STRING_NEWLINE,(num_tabs==1 ? "\t" : \
|
||||
(num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1); \
|
||||
fprintf(PNG_DEBUG_FILE,"%s" m PNG_STRING_NEWLINE,(num_tabs==1 ? " " : \
|
||||
(num_tabs==2 ? " " : (num_tabs>2 ? " " : ""))),p1); \
|
||||
} while (0)
|
||||
# endif
|
||||
# ifndef png_debug2
|
||||
# define png_debug2(l,m,p1,p2) \
|
||||
do { \
|
||||
int num_tabs=l; \
|
||||
fprintf(PNG_DEBUG_FILE,"%s"m PNG_STRING_NEWLINE,(num_tabs==1 ? "\t" : \
|
||||
(num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1,p2); \
|
||||
fprintf(PNG_DEBUG_FILE,"%s" m PNG_STRING_NEWLINE,(num_tabs==1 ? " " : \
|
||||
(num_tabs==2 ? " " : (num_tabs>2 ? " " : ""))),p1,p2);\
|
||||
} while (0)
|
||||
# endif
|
||||
# else /* __STDC __ */
|
||||
|
||||
141
pngerror.c
141
pngerror.c
@@ -1,8 +1,8 @@
|
||||
|
||||
/* pngerror.c - stub functions for i/o and memory allocation
|
||||
*
|
||||
* Last changed in libpng 1.6.0 [(PENDING RELEASE)]
|
||||
* Copyright (c) 1998-2012 Glenn Randers-Pehrson
|
||||
* Last changed in libpng 1.7.0 [(PENDING RELEASE)]
|
||||
* Copyright (c) 1998-2014 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.)
|
||||
*
|
||||
@@ -27,7 +27,7 @@ static PNG_FUNCTION(void, png_default_error,PNGARG((png_const_structrp png_ptr,
|
||||
static void /* PRIVATE */
|
||||
png_default_warning PNGARG((png_const_structrp png_ptr,
|
||||
png_const_charp warning_message));
|
||||
#endif /* PNG_WARNINGS_SUPPORTED */
|
||||
#endif /* WARNINGS */
|
||||
|
||||
/* This function is called whenever there is a fatal error. This function
|
||||
* should not be changed. If there is a need to handle errors differently,
|
||||
@@ -43,8 +43,8 @@ png_error,(png_const_structrp png_ptr, png_const_charp error_message),
|
||||
char msg[16];
|
||||
if (png_ptr != NULL)
|
||||
{
|
||||
if (png_ptr->flags&
|
||||
(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
|
||||
if ((png_ptr->flags &
|
||||
(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT)) != 0
|
||||
{
|
||||
if (*error_message == PNG_LITERAL_SHARP)
|
||||
{
|
||||
@@ -54,7 +54,7 @@ png_error,(png_const_structrp png_ptr, png_const_charp error_message),
|
||||
if (error_message[offset] == ' ')
|
||||
break;
|
||||
|
||||
if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
|
||||
if ((png_ptr->flags & PNG_FLAG_STRIP_ERROR_TEXT) != 0)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < offset - 1; i++)
|
||||
@@ -69,7 +69,7 @@ png_error,(png_const_structrp png_ptr, png_const_charp error_message),
|
||||
|
||||
else
|
||||
{
|
||||
if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
|
||||
if ((png_ptr->flags & PNG_FLAG_STRIP_ERROR_TEXT) != 0)
|
||||
{
|
||||
msg[0] = '0';
|
||||
msg[1] = '\0';
|
||||
@@ -103,7 +103,7 @@ png_err,(png_const_structrp png_ptr),PNG_NORETURN)
|
||||
use the default handler, which will not return. */
|
||||
png_default_error(png_ptr, "");
|
||||
}
|
||||
#endif /* PNG_ERROR_TEXT_SUPPORTED */
|
||||
#endif /* ERROR_TEXT */
|
||||
|
||||
/* Utility to safely appends strings to a buffer. This never errors out so
|
||||
* error checking is not required in the caller.
|
||||
@@ -152,7 +152,7 @@ png_format_number(png_const_charp start, png_charp end, int format,
|
||||
case PNG_NUMBER_FORMAT_fixed:
|
||||
/* Needs five digits (the fraction) */
|
||||
mincount = 5;
|
||||
if (output || number % 10 != 0)
|
||||
if (output != 0 || number % 10 != 0)
|
||||
{
|
||||
*--end = digits[number % 10];
|
||||
output = 1;
|
||||
@@ -189,13 +189,13 @@ png_format_number(png_const_charp start, png_charp end, int format,
|
||||
++count;
|
||||
|
||||
/* Float a fixed number here: */
|
||||
if (format == PNG_NUMBER_FORMAT_fixed) if (count == 5) if (end > start)
|
||||
if ((format == PNG_NUMBER_FORMAT_fixed) && (count == 5) && (end > start))
|
||||
{
|
||||
/* End of the fraction, but maybe nothing was output? In that case
|
||||
* drop the decimal point. If the number is a true zero handle that
|
||||
* here.
|
||||
*/
|
||||
if (output)
|
||||
if (output != 0)
|
||||
*--end = '.';
|
||||
else if (number == 0) /* and !output */
|
||||
*--end = '0';
|
||||
@@ -219,8 +219,8 @@ png_warning(png_const_structrp png_ptr, png_const_charp warning_message)
|
||||
if (png_ptr != NULL)
|
||||
{
|
||||
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
|
||||
if (png_ptr->flags&
|
||||
(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
|
||||
if ((png_ptr->flags &
|
||||
(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT)) != 0)
|
||||
#endif
|
||||
{
|
||||
if (*warning_message == PNG_LITERAL_SHARP)
|
||||
@@ -355,13 +355,13 @@ png_formatted_warning(png_const_structrp png_ptr, png_warning_parameters p,
|
||||
*/
|
||||
png_warning(png_ptr, msg);
|
||||
}
|
||||
#endif /* PNG_WARNINGS_SUPPORTED */
|
||||
#endif /* WARNINGS */
|
||||
|
||||
#ifdef PNG_BENIGN_ERRORS_SUPPORTED
|
||||
void PNGAPI
|
||||
png_benign_error(png_const_structrp png_ptr, png_const_charp error_message)
|
||||
{
|
||||
if (png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN)
|
||||
if ((png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN) != 0)
|
||||
{
|
||||
# ifdef PNG_READ_SUPPORTED
|
||||
if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0 &&
|
||||
@@ -382,31 +382,46 @@ png_benign_error(png_const_structrp png_ptr, png_const_charp error_message)
|
||||
# endif
|
||||
png_error(png_ptr, error_message);
|
||||
}
|
||||
|
||||
# ifndef PNG_ERROR_TEXT_SUPPORTED
|
||||
PNG_UNUSED(error_message)
|
||||
# endif
|
||||
}
|
||||
|
||||
void /* PRIVATE */
|
||||
png_app_warning(png_const_structrp png_ptr, png_const_charp error_message)
|
||||
{
|
||||
if (png_ptr->flags & PNG_FLAG_APP_WARNINGS_WARN)
|
||||
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
|
||||
}
|
||||
|
||||
void /* PRIVATE */
|
||||
png_app_error(png_const_structrp png_ptr, png_const_charp error_message)
|
||||
{
|
||||
if (png_ptr->flags & PNG_FLAG_APP_ERRORS_WARN)
|
||||
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
|
||||
}
|
||||
#endif /* BENIGN_ERRORS */
|
||||
|
||||
#define PNG_MAX_ERROR_TEXT 196 /* Currently limited by profile_error in png.c */
|
||||
#if defined(PNG_WARNINGS_SUPPORTED) || \
|
||||
(defined(PNG_READ_SUPPORTED) && defined(PNG_ERROR_TEXT_SUPPORTED))
|
||||
/* These utilities are used internally to build an error message that relates
|
||||
* to the current chunk. The chunk name comes from png_ptr->chunk_name,
|
||||
* this is used to prefix the message. The message is limited in length
|
||||
* to 63 bytes, the name characters are output as hex digits wrapped in []
|
||||
* which is used to prefix the message. The message is limited in length
|
||||
* to 63 bytes. The name characters are output as hex digits wrapped in []
|
||||
* if the character is invalid.
|
||||
*/
|
||||
#define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
|
||||
@@ -415,8 +430,6 @@ static PNG_CONST char png_digit[16] = {
|
||||
'A', 'B', 'C', 'D', 'E', 'F'
|
||||
};
|
||||
|
||||
#define PNG_MAX_ERROR_TEXT 196 /* Currently limited be profile_error in png.c */
|
||||
#if defined(PNG_WARNINGS_SUPPORTED) || defined(PNG_ERROR_TEXT_SUPPORTED)
|
||||
static void /* PRIVATE */
|
||||
png_format_buffer(png_const_structrp png_ptr, png_charp buffer, png_const_charp
|
||||
error_message)
|
||||
@@ -429,7 +442,7 @@ png_format_buffer(png_const_structrp png_ptr, png_charp buffer, png_const_charp
|
||||
int c = (int)(chunk_name >> ishift) & 0xff;
|
||||
|
||||
ishift -= 8;
|
||||
if (isnonalpha(c))
|
||||
if (isnonalpha(c) != 0)
|
||||
{
|
||||
buffer[iout++] = PNG_LITERAL_LEFT_SQUARE_BRACKET;
|
||||
buffer[iout++] = png_digit[(c & 0xf0) >> 4];
|
||||
@@ -460,7 +473,7 @@ png_format_buffer(png_const_structrp png_ptr, png_charp buffer, png_const_charp
|
||||
buffer[iout] = '\0';
|
||||
}
|
||||
}
|
||||
#endif /* PNG_WARNINGS_SUPPORTED || PNG_ERROR_TEXT_SUPPORTED */
|
||||
#endif /* WARNINGS || ERROR_TEXT */
|
||||
|
||||
#if defined(PNG_READ_SUPPORTED) && defined(PNG_ERROR_TEXT_SUPPORTED)
|
||||
PNG_FUNCTION(void,PNGAPI
|
||||
@@ -477,7 +490,7 @@ png_chunk_error,(png_const_structrp png_ptr, png_const_charp error_message),
|
||||
png_error(png_ptr, msg);
|
||||
}
|
||||
}
|
||||
#endif /* PNG_READ_SUPPORTED && PNG_ERROR_TEXT_SUPPORTED */
|
||||
#endif /* READ && ERROR_TEXT */
|
||||
|
||||
#ifdef PNG_WARNINGS_SUPPORTED
|
||||
void PNGAPI
|
||||
@@ -493,7 +506,7 @@ png_chunk_warning(png_const_structrp png_ptr, png_const_charp warning_message)
|
||||
png_warning(png_ptr, msg);
|
||||
}
|
||||
}
|
||||
#endif /* PNG_WARNINGS_SUPPORTED */
|
||||
#endif /* WARNINGS */
|
||||
|
||||
#ifdef PNG_READ_SUPPORTED
|
||||
#ifdef PNG_BENIGN_ERRORS_SUPPORTED
|
||||
@@ -501,23 +514,31 @@ 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)
|
||||
if ((png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN) != 0)
|
||||
png_chunk_warning(png_ptr, error_message);
|
||||
|
||||
else
|
||||
png_chunk_error(png_ptr, error_message);
|
||||
|
||||
# ifndef PNG_ERROR_TEXT_SUPPORTED
|
||||
PNG_UNUSED(error_message)
|
||||
# endif
|
||||
}
|
||||
#endif
|
||||
#endif /* PNG_READ_SUPPORTED */
|
||||
#endif /* READ */
|
||||
|
||||
void /* PRIVATE */
|
||||
png_chunk_report(png_const_structrp png_ptr, png_const_charp message, int error)
|
||||
{
|
||||
# ifndef PNG_WARNINGS_SUPPORTED
|
||||
PNG_UNUSED(message)
|
||||
# endif
|
||||
|
||||
/* This is always supported, but for just read or just write it
|
||||
* unconditionally does the right thing.
|
||||
*/
|
||||
# if (defined PNG_READ_SUPPORTED) && (defined PNG_WRITE_SUPPORTED)
|
||||
if (png_ptr->mode & PNG_IS_READ_STRUCT)
|
||||
# if defined(PNG_READ_SUPPORTED) && defined(PNG_WRITE_SUPPORTED)
|
||||
if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0)
|
||||
# endif
|
||||
|
||||
# ifdef PNG_READ_SUPPORTED
|
||||
@@ -530,8 +551,8 @@ png_chunk_report(png_const_structrp png_ptr, png_const_charp message, int error)
|
||||
}
|
||||
# endif
|
||||
|
||||
# if (defined PNG_READ_SUPPORTED) && (defined PNG_WRITE_SUPPORTED)
|
||||
else if (!(png_ptr->mode & PNG_IS_READ_STRUCT))
|
||||
# if defined(PNG_READ_SUPPORTED) && defined(PNG_WRITE_SUPPORTED)
|
||||
else if ((png_ptr->mode & PNG_IS_READ_STRUCT) == 0)
|
||||
# endif
|
||||
|
||||
# ifdef PNG_WRITE_SUPPORTED
|
||||
@@ -546,7 +567,13 @@ png_chunk_report(png_const_structrp png_ptr, png_const_charp message, int error)
|
||||
}
|
||||
|
||||
#ifdef PNG_ERROR_TEXT_SUPPORTED
|
||||
#ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
|
||||
#if defined(PNG_FLOATING_POINT_SUPPORTED) && \
|
||||
(defined(PNG_gAMA_SUPPORTED) || defined(PNG_cHRM_SUPPORTED) || \
|
||||
defined(PNG_sCAL_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) || \
|
||||
defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)) || \
|
||||
(defined(PNG_FLOATING_ARITHMETIC_SUPPORTED) &&\
|
||||
defined(PNG_sCAL_SUPPORTED))
|
||||
PNG_FUNCTION(void,
|
||||
png_fixed_error,(png_const_structrp png_ptr, png_const_charp name),PNG_NORETURN)
|
||||
{
|
||||
@@ -556,11 +583,12 @@ png_fixed_error,(png_const_structrp png_ptr, png_const_charp name),PNG_NORETURN)
|
||||
char msg[fixed_message_ln+PNG_MAX_ERROR_TEXT];
|
||||
memcpy(msg, fixed_message, fixed_message_ln);
|
||||
iin = 0;
|
||||
if (name != NULL) while (iin < (PNG_MAX_ERROR_TEXT-1) && name[iin] != 0)
|
||||
{
|
||||
msg[fixed_message_ln + iin] = name[iin];
|
||||
++iin;
|
||||
}
|
||||
if (name != NULL)
|
||||
while (iin < (PNG_MAX_ERROR_TEXT-1) && name[iin] != 0)
|
||||
{
|
||||
msg[fixed_message_ln + iin] = name[iin];
|
||||
++iin;
|
||||
}
|
||||
msg[fixed_message_ln + iin] = 0;
|
||||
png_error(png_ptr, msg);
|
||||
}
|
||||
@@ -736,12 +764,25 @@ PNG_FUNCTION(void,PNGAPI
|
||||
png_longjmp,(png_const_structrp png_ptr, int val),PNG_NORETURN)
|
||||
{
|
||||
#ifdef PNG_SETJMP_SUPPORTED
|
||||
if (png_ptr && png_ptr->longjmp_fn && png_ptr->jmp_buf_ptr)
|
||||
if (png_ptr != NULL && png_ptr->longjmp_fn != NULL &&
|
||||
png_ptr->jmp_buf_ptr != NULL)
|
||||
png_ptr->longjmp_fn(*png_ptr->jmp_buf_ptr, val);
|
||||
#else
|
||||
PNG_UNUSED(png_ptr)
|
||||
PNG_UNUSED(val)
|
||||
#endif
|
||||
|
||||
/* Here if not setjmp support or if png_ptr is null. */
|
||||
PNG_ABORT();
|
||||
/* If control reaches this point, png_longjmp() must not return. The only
|
||||
* choice is to terminate the whole process (or maybe the thread); to do
|
||||
* this the ANSI-C abort() function is used unless a different method is
|
||||
* implemented by overriding the default configuration setting for
|
||||
* PNG_ABORT (see scripts/pnglibconf.dfa).
|
||||
*
|
||||
* API change: prior to 1.7.0 PNG_ABORT was invoked as a function type macro
|
||||
* with no arguments 'PNG_ABORT();', in 1.7.0 this is changed to a simple
|
||||
* macro that is defined in the configuration.
|
||||
*/
|
||||
PNG_ABORT
|
||||
}
|
||||
|
||||
#ifdef PNG_WARNINGS_SUPPORTED
|
||||
@@ -793,7 +834,7 @@ png_default_warning(png_const_structrp png_ptr, png_const_charp warning_message)
|
||||
#endif
|
||||
PNG_UNUSED(png_ptr) /* Make compiler happy */
|
||||
}
|
||||
#endif /* PNG_WARNINGS_SUPPORTED */
|
||||
#endif /* WARNINGS */
|
||||
|
||||
/* This function is called when the application wants to use another method
|
||||
* of handling errors and warnings. Note that the error function MUST NOT
|
||||
@@ -844,14 +885,14 @@ png_set_strip_error_numbers(png_structrp png_ptr, png_uint_32 strip_mode)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined PNG_SIMPLIFIED_READ_SUPPORTED ||\
|
||||
defined PNG_SIMPLIFIED_WRITE_SUPPORTED
|
||||
#if defined(PNG_SIMPLIFIED_READ_SUPPORTED) ||\
|
||||
defined(PNG_SIMPLIFIED_WRITE_SUPPORTED)
|
||||
/* Currently the above both depend on SETJMP_SUPPORTED, however it would be
|
||||
* possible to implement without setjmp support just so long as there is some
|
||||
* way to handle the error return here:
|
||||
*/
|
||||
PNG_FUNCTION(void /* PRIVATE */,
|
||||
png_safe_error,(png_structp png_nonconst_ptr, png_const_charp error_message),
|
||||
PNG_FUNCTION(void /* PRIVATE */, (PNGCBAPI
|
||||
png_safe_error),(png_structp png_nonconst_ptr, png_const_charp error_message),
|
||||
PNG_NORETURN)
|
||||
{
|
||||
const png_const_structrp png_ptr = png_nonconst_ptr;
|
||||
@@ -886,7 +927,7 @@ png_safe_error,(png_structp png_nonconst_ptr, png_const_charp error_message),
|
||||
}
|
||||
|
||||
#ifdef PNG_WARNINGS_SUPPORTED
|
||||
void /* PRIVATE */
|
||||
void /* PRIVATE */ PNGCBAPI
|
||||
png_safe_warning(png_structp png_nonconst_ptr, png_const_charp warning_message)
|
||||
{
|
||||
const png_const_structrp png_ptr = png_nonconst_ptr;
|
||||
@@ -913,7 +954,7 @@ png_safe_execute(png_imagep image_in, int (*function)(png_voidp), png_voidp arg)
|
||||
saved_error_buf = image->opaque->error_buf;
|
||||
result = setjmp(safe_jmpbuf) == 0;
|
||||
|
||||
if (result)
|
||||
if (result != 0)
|
||||
{
|
||||
|
||||
image->opaque->error_buf = safe_jmpbuf;
|
||||
@@ -923,10 +964,10 @@ png_safe_execute(png_imagep image_in, int (*function)(png_voidp), png_voidp arg)
|
||||
image->opaque->error_buf = saved_error_buf;
|
||||
|
||||
/* And do the cleanup prior to any failure return. */
|
||||
if (!result)
|
||||
if (result == 0)
|
||||
png_image_free(image);
|
||||
|
||||
return result;
|
||||
}
|
||||
#endif /* SIMPLIFIED READ/WRITE */
|
||||
#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
|
||||
#endif /* SIMPLIFIED READ || SIMPLIFIED_WRITE */
|
||||
#endif /* READ || WRITE */
|
||||
|
||||
206
pngget.c
206
pngget.c
@@ -1,8 +1,8 @@
|
||||
|
||||
/* pngget.c - retrieval of values from info struct
|
||||
*
|
||||
* Last changed in libpng 1.6.0 [(PENDING RELEASE)]
|
||||
* Copyright (c) 1998-2012 Glenn Randers-Pehrson
|
||||
* Last changed in libpng 1.7.0 [(PENDING RELEASE)]
|
||||
* Copyright (c) 1998-2014 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.)
|
||||
*
|
||||
@@ -116,7 +116,8 @@ png_get_x_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp
|
||||
info_ptr)
|
||||
{
|
||||
#ifdef PNG_pHYs_SUPPORTED
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_pHYs) != 0)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function",
|
||||
"png_get_x_pixels_per_meter");
|
||||
@@ -124,6 +125,9 @@ png_get_x_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp
|
||||
if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER)
|
||||
return (info_ptr->x_pixels_per_unit);
|
||||
}
|
||||
#else
|
||||
PNG_UNUSED(png_ptr)
|
||||
PNG_UNUSED(info_ptr)
|
||||
#endif
|
||||
|
||||
return (0);
|
||||
@@ -134,7 +138,8 @@ png_get_y_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp
|
||||
info_ptr)
|
||||
{
|
||||
#ifdef PNG_pHYs_SUPPORTED
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_pHYs) != 0)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function",
|
||||
"png_get_y_pixels_per_meter");
|
||||
@@ -142,6 +147,9 @@ png_get_y_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp
|
||||
if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER)
|
||||
return (info_ptr->y_pixels_per_unit);
|
||||
}
|
||||
#else
|
||||
PNG_UNUSED(png_ptr)
|
||||
PNG_UNUSED(info_ptr)
|
||||
#endif
|
||||
|
||||
return (0);
|
||||
@@ -151,7 +159,8 @@ png_uint_32 PNGAPI
|
||||
png_get_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp info_ptr)
|
||||
{
|
||||
#ifdef PNG_pHYs_SUPPORTED
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_pHYs) != 0)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "png_get_pixels_per_meter");
|
||||
|
||||
@@ -159,6 +168,9 @@ png_get_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp info_ptr)
|
||||
info_ptr->x_pixels_per_unit == info_ptr->y_pixels_per_unit)
|
||||
return (info_ptr->x_pixels_per_unit);
|
||||
}
|
||||
#else
|
||||
PNG_UNUSED(png_ptr)
|
||||
PNG_UNUSED(info_ptr)
|
||||
#endif
|
||||
|
||||
return (0);
|
||||
@@ -170,7 +182,8 @@ png_get_pixel_aspect_ratio(png_const_structrp png_ptr, png_const_inforp
|
||||
info_ptr)
|
||||
{
|
||||
#ifdef PNG_READ_pHYs_SUPPORTED
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_pHYs) != 0)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "png_get_aspect_ratio");
|
||||
|
||||
@@ -193,10 +206,11 @@ png_get_pixel_aspect_ratio_fixed(png_const_structrp png_ptr,
|
||||
png_const_inforp info_ptr)
|
||||
{
|
||||
#ifdef PNG_READ_pHYs_SUPPORTED
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)
|
||||
&& info_ptr->x_pixels_per_unit > 0 && info_ptr->y_pixels_per_unit > 0
|
||||
&& info_ptr->x_pixels_per_unit <= PNG_UINT_31_MAX
|
||||
&& info_ptr->y_pixels_per_unit <= PNG_UINT_31_MAX)
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_pHYs) != 0 &&
|
||||
info_ptr->x_pixels_per_unit > 0 && info_ptr->y_pixels_per_unit > 0 &&
|
||||
info_ptr->x_pixels_per_unit <= PNG_UINT_31_MAX &&
|
||||
info_ptr->y_pixels_per_unit <= PNG_UINT_31_MAX)
|
||||
{
|
||||
png_fixed_point res;
|
||||
|
||||
@@ -206,7 +220,7 @@ png_get_pixel_aspect_ratio_fixed(png_const_structrp png_ptr,
|
||||
* range of 0..2^31-1; otherwise the cast might overflow.
|
||||
*/
|
||||
if (png_muldiv(&res, (png_int_32)info_ptr->y_pixels_per_unit, PNG_FP_1,
|
||||
(png_int_32)info_ptr->x_pixels_per_unit))
|
||||
(png_int_32)info_ptr->x_pixels_per_unit) != 0)
|
||||
return res;
|
||||
}
|
||||
#else
|
||||
@@ -222,13 +236,17 @@ png_int_32 PNGAPI
|
||||
png_get_x_offset_microns(png_const_structrp png_ptr, png_const_inforp info_ptr)
|
||||
{
|
||||
#ifdef PNG_oFFs_SUPPORTED
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_oFFs) != 0)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "png_get_x_offset_microns");
|
||||
|
||||
if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER)
|
||||
return (info_ptr->x_offset);
|
||||
}
|
||||
#else
|
||||
PNG_UNUSED(png_ptr)
|
||||
PNG_UNUSED(info_ptr)
|
||||
#endif
|
||||
|
||||
return (0);
|
||||
@@ -238,13 +256,17 @@ png_int_32 PNGAPI
|
||||
png_get_y_offset_microns(png_const_structrp png_ptr, png_const_inforp info_ptr)
|
||||
{
|
||||
#ifdef PNG_oFFs_SUPPORTED
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_oFFs) != 0)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "png_get_y_offset_microns");
|
||||
|
||||
if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER)
|
||||
return (info_ptr->y_offset);
|
||||
}
|
||||
#else
|
||||
PNG_UNUSED(png_ptr)
|
||||
PNG_UNUSED(info_ptr)
|
||||
#endif
|
||||
|
||||
return (0);
|
||||
@@ -254,13 +276,17 @@ png_int_32 PNGAPI
|
||||
png_get_x_offset_pixels(png_const_structrp png_ptr, png_const_inforp info_ptr)
|
||||
{
|
||||
#ifdef PNG_oFFs_SUPPORTED
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_oFFs) != 0)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "png_get_x_offset_pixels");
|
||||
|
||||
if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL)
|
||||
return (info_ptr->x_offset);
|
||||
}
|
||||
#else
|
||||
PNG_UNUSED(png_ptr)
|
||||
PNG_UNUSED(info_ptr)
|
||||
#endif
|
||||
|
||||
return (0);
|
||||
@@ -270,13 +296,17 @@ png_int_32 PNGAPI
|
||||
png_get_y_offset_pixels(png_const_structrp png_ptr, png_const_inforp info_ptr)
|
||||
{
|
||||
#ifdef PNG_oFFs_SUPPORTED
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_oFFs) != 0)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "png_get_y_offset_pixels");
|
||||
|
||||
if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL)
|
||||
return (info_ptr->y_offset);
|
||||
}
|
||||
#else
|
||||
PNG_UNUSED(png_ptr)
|
||||
PNG_UNUSED(info_ptr)
|
||||
#endif
|
||||
|
||||
return (0);
|
||||
@@ -307,7 +337,7 @@ ppi_from_ppm(png_uint_32 ppm)
|
||||
*/
|
||||
png_fixed_point result;
|
||||
if (ppm <= PNG_UINT_31_MAX && png_muldiv(&result, (png_int_32)ppm, 127,
|
||||
5000))
|
||||
5000) != 0)
|
||||
return result;
|
||||
|
||||
/* Overflow. */
|
||||
@@ -393,7 +423,8 @@ png_get_pHYs_dpi(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
{
|
||||
png_uint_32 retval = 0;
|
||||
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_pHYs) != 0)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "pHYs");
|
||||
|
||||
@@ -424,12 +455,12 @@ png_get_pHYs_dpi(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
|
||||
return (retval);
|
||||
}
|
||||
#endif /* PNG_pHYs_SUPPORTED */
|
||||
#endif /* PNG_INCH_CONVERSIONS_SUPPORTED */
|
||||
#endif /* pHYs */
|
||||
#endif /* INCH_CONVERSIONS */
|
||||
|
||||
/* png_get_channels really belongs in here, too, but it's been around longer */
|
||||
|
||||
#endif /* PNG_EASY_ACCESS_SUPPORTED */
|
||||
#endif /* EASY_ACCESS */
|
||||
|
||||
|
||||
png_byte PNGAPI
|
||||
@@ -457,8 +488,9 @@ png_uint_32 PNGAPI
|
||||
png_get_bKGD(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
png_color_16p *background)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD)
|
||||
&& background != NULL)
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_bKGD) != 0 &&
|
||||
background != NULL)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "bKGD");
|
||||
|
||||
@@ -488,7 +520,7 @@ png_get_cHRM(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
* consistent.
|
||||
*/
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS))
|
||||
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "cHRM");
|
||||
|
||||
@@ -529,7 +561,7 @@ png_get_cHRM_XYZ(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
double *blue_Z)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS))
|
||||
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "cHRM_XYZ(float)");
|
||||
|
||||
@@ -552,14 +584,14 @@ png_get_cHRM_XYZ(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
*green_Z = png_float(png_ptr,
|
||||
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");
|
||||
*blue_X = png_float(png_ptr,
|
||||
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");
|
||||
*blue_Y = png_float(png_ptr,
|
||||
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");
|
||||
*blue_Z = png_float(png_ptr,
|
||||
info_ptr->colorspace.end_points_XYZ.blue_Z, "cHRM blue Z");
|
||||
return (PNG_INFO_cHRM);
|
||||
}
|
||||
|
||||
@@ -577,7 +609,7 @@ png_get_cHRM_XYZ_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
png_fixed_point *int_blue_Z)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS))
|
||||
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "cHRM_XYZ");
|
||||
|
||||
@@ -614,7 +646,7 @@ png_get_cHRM_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
png_debug1(1, "in %s retrieval function", "cHRM");
|
||||
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS))
|
||||
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0)
|
||||
{
|
||||
if (white_x != NULL)
|
||||
*white_x = info_ptr->colorspace.end_points_xy.whitex;
|
||||
@@ -649,7 +681,7 @@ 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) &&
|
||||
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) != 0 &&
|
||||
file_gamma != NULL)
|
||||
{
|
||||
*file_gamma = info_ptr->colorspace.gamma;
|
||||
@@ -668,7 +700,7 @@ png_get_gAMA(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
png_debug1(1, "in %s retrieval function", "gAMA(float)");
|
||||
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) &&
|
||||
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) != 0 &&
|
||||
file_gamma != NULL)
|
||||
{
|
||||
*file_gamma = png_float(png_ptr, info_ptr->colorspace.gamma,
|
||||
@@ -688,8 +720,8 @@ png_get_sRGB(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "sRGB");
|
||||
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)
|
||||
&& file_srgb_intent != NULL)
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_sRGB) != 0 && file_srgb_intent != NULL)
|
||||
{
|
||||
*file_srgb_intent = info_ptr->colorspace.rendering_intent;
|
||||
return (PNG_INFO_sRGB);
|
||||
@@ -701,15 +733,16 @@ png_get_sRGB(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
|
||||
#ifdef PNG_iCCP_SUPPORTED
|
||||
png_uint_32 PNGAPI
|
||||
png_get_iCCP(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
png_get_iCCP(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
png_charpp name, int *compression_type,
|
||||
png_bytepp profile, png_uint_32 *proflen)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "iCCP");
|
||||
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP)
|
||||
&& name != NULL && compression_type != NULL && profile != NULL &&
|
||||
proflen != NULL)
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_iCCP) != 0 &&
|
||||
name != NULL && compression_type != NULL && profile != NULL &&
|
||||
proflen != NULL)
|
||||
{
|
||||
*name = info_ptr->iccp_name;
|
||||
*profile = info_ptr->iccp_profile;
|
||||
@@ -726,14 +759,14 @@ png_get_iCCP(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
#endif
|
||||
|
||||
#ifdef PNG_sPLT_SUPPORTED
|
||||
png_uint_32 PNGAPI
|
||||
png_get_sPLT(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
int PNGAPI
|
||||
png_get_sPLT(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
png_sPLT_tpp spalettes)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
|
||||
{
|
||||
*spalettes = info_ptr->splt_palettes;
|
||||
return ((png_uint_32)info_ptr->splt_palettes_num);
|
||||
return info_ptr->splt_palettes_num;
|
||||
}
|
||||
|
||||
return (0);
|
||||
@@ -742,13 +775,13 @@ png_get_sPLT(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
|
||||
#ifdef PNG_hIST_SUPPORTED
|
||||
png_uint_32 PNGAPI
|
||||
png_get_hIST(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
png_get_hIST(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
png_uint_16p *hist)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "hIST");
|
||||
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)
|
||||
&& hist != NULL)
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_hIST) != 0 && hist != NULL)
|
||||
{
|
||||
*hist = info_ptr->hist;
|
||||
return (PNG_INFO_hIST);
|
||||
@@ -803,8 +836,9 @@ png_get_oFFs(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "oFFs");
|
||||
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)
|
||||
&& offset_x != NULL && offset_y != NULL && unit_type != NULL)
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_oFFs) != 0 &&
|
||||
offset_x != NULL && offset_y != NULL && unit_type != NULL)
|
||||
{
|
||||
*offset_x = info_ptr->x_offset;
|
||||
*offset_y = info_ptr->y_offset;
|
||||
@@ -818,14 +852,15 @@ png_get_oFFs(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
|
||||
#ifdef PNG_pCAL_SUPPORTED
|
||||
png_uint_32 PNGAPI
|
||||
png_get_pCAL(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
png_get_pCAL(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
|
||||
png_charp *units, png_charpp *params)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "pCAL");
|
||||
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)
|
||||
&& purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_pCAL) != 0 &&
|
||||
purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
|
||||
nparams != NULL && units != NULL && params != NULL)
|
||||
{
|
||||
*purpose = info_ptr->pcal_purpose;
|
||||
@@ -843,15 +878,14 @@ png_get_pCAL(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
#endif
|
||||
|
||||
#ifdef PNG_sCAL_SUPPORTED
|
||||
# ifdef PNG_FIXED_POINT_SUPPORTED
|
||||
# if (defined PNG_FLOATING_ARITHMETIC_SUPPORTED) || \
|
||||
(defined PNG_FLOATING_POINT_SUPPORTED)
|
||||
# ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
|
||||
# ifdef PNG_FIXED_POINT_SUPPORTED
|
||||
png_uint_32 PNGAPI
|
||||
png_get_sCAL_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
int *unit, png_fixed_point *width, png_fixed_point *height)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_sCAL))
|
||||
(info_ptr->valid & PNG_INFO_sCAL) != 0)
|
||||
{
|
||||
*unit = info_ptr->scal_unit;
|
||||
/*TODO: make this work without FP support; the API is currently eliminated
|
||||
@@ -866,15 +900,15 @@ png_get_sCAL_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
|
||||
return(0);
|
||||
}
|
||||
# endif /* FLOATING_ARITHMETIC */
|
||||
# endif /* FIXED_POINT */
|
||||
# ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
# endif /* FIXED_POINT */
|
||||
|
||||
# ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
png_uint_32 PNGAPI
|
||||
png_get_sCAL(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
int *unit, double *width, double *height)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_sCAL))
|
||||
(info_ptr->valid & PNG_INFO_sCAL) != 0)
|
||||
{
|
||||
*unit = info_ptr->scal_unit;
|
||||
*width = atof(info_ptr->scal_s_width);
|
||||
@@ -884,13 +918,15 @@ png_get_sCAL(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
|
||||
return(0);
|
||||
}
|
||||
# endif /* FLOATING POINT */
|
||||
# endif /* FLOATING POINT */
|
||||
# endif /* FLOATING_ARITHMETIC */
|
||||
|
||||
png_uint_32 PNGAPI
|
||||
png_get_sCAL_s(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
int *unit, png_charpp width, png_charpp height)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_sCAL))
|
||||
(info_ptr->valid & PNG_INFO_sCAL) != 0)
|
||||
{
|
||||
*unit = info_ptr->scal_unit;
|
||||
*width = info_ptr->scal_s_width;
|
||||
@@ -912,7 +948,7 @@ png_get_pHYs(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
png_debug1(1, "in %s retrieval function", "pHYs");
|
||||
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_pHYs))
|
||||
(info_ptr->valid & PNG_INFO_pHYs) != 0)
|
||||
{
|
||||
if (res_x != NULL)
|
||||
{
|
||||
@@ -938,13 +974,13 @@ png_get_pHYs(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
#endif /* pHYs */
|
||||
|
||||
png_uint_32 PNGAPI
|
||||
png_get_PLTE(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
png_get_PLTE(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
png_colorp *palette, int *num_palette)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "PLTE");
|
||||
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE)
|
||||
&& palette != NULL)
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_PLTE) != 0 && palette != NULL)
|
||||
{
|
||||
*palette = info_ptr->palette;
|
||||
*num_palette = info_ptr->num_palette;
|
||||
@@ -962,8 +998,8 @@ png_get_sBIT(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "sBIT");
|
||||
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)
|
||||
&& sig_bit != NULL)
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_sBIT) != 0 && sig_bit != NULL)
|
||||
{
|
||||
*sig_bit = &(info_ptr->sig_bit);
|
||||
return (PNG_INFO_sBIT);
|
||||
@@ -974,8 +1010,8 @@ png_get_sBIT(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
#endif
|
||||
|
||||
#ifdef PNG_TEXT_SUPPORTED
|
||||
png_uint_32 PNGAPI
|
||||
png_get_text(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
int PNGAPI
|
||||
png_get_text(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
png_textp *text_ptr, int *num_text)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)
|
||||
@@ -989,7 +1025,7 @@ png_get_text(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
if (num_text != NULL)
|
||||
*num_text = info_ptr->num_text;
|
||||
|
||||
return ((png_uint_32)info_ptr->num_text);
|
||||
return info_ptr->num_text;
|
||||
}
|
||||
|
||||
if (num_text != NULL)
|
||||
@@ -1006,8 +1042,8 @@ png_get_tIME(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "tIME");
|
||||
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)
|
||||
&& mod_time != NULL)
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_tIME) != 0 && mod_time != NULL)
|
||||
{
|
||||
*mod_time = &(info_ptr->mod_time);
|
||||
return (PNG_INFO_tIME);
|
||||
@@ -1023,7 +1059,8 @@ png_get_tRNS(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
png_bytep *trans_alpha, int *num_trans, png_color_16p *trans_color)
|
||||
{
|
||||
png_uint_32 retval = 0;
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_tRNS) != 0)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "tRNS");
|
||||
|
||||
@@ -1064,7 +1101,7 @@ png_get_tRNS(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
|
||||
#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
|
||||
int PNGAPI
|
||||
png_get_unknown_chunks(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
png_get_unknown_chunks(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
png_unknown_chunkpp unknowns)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL)
|
||||
@@ -1100,7 +1137,7 @@ png_get_compression_buffer_size(png_const_structrp png_ptr)
|
||||
return 0;
|
||||
|
||||
# ifdef PNG_WRITE_SUPPORTED
|
||||
if (png_ptr->mode & PNG_IS_READ_STRUCT)
|
||||
if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0)
|
||||
# endif
|
||||
{
|
||||
# ifdef PNG_SEQUENTIAL_READ_SUPPORTED
|
||||
@@ -1144,7 +1181,7 @@ png_get_chunk_malloc_max (png_const_structrp png_ptr)
|
||||
{
|
||||
return (png_ptr ? png_ptr->user_chunk_malloc_max : 0);
|
||||
}
|
||||
#endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
|
||||
#endif /* ?SET_USER_LIMITS */
|
||||
|
||||
/* These functions were added to libpng 1.4.0 */
|
||||
#ifdef PNG_IO_STATE_SUPPORTED
|
||||
@@ -1159,6 +1196,19 @@ png_get_io_chunk_type (png_const_structrp png_ptr)
|
||||
{
|
||||
return png_ptr->chunk_name;
|
||||
}
|
||||
#endif /* ?PNG_IO_STATE_SUPPORTED */
|
||||
#endif /* ?IO_STATE */
|
||||
|
||||
#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
|
||||
#ifdef PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED
|
||||
# ifdef PNG_GET_PALETTE_MAX_SUPPORTED
|
||||
int PNGAPI
|
||||
png_get_palette_max(png_const_structrp png_ptr, png_const_inforp info_ptr)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL)
|
||||
return png_ptr->num_palette_max;
|
||||
|
||||
return (-1);
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#endif /* READ || WRITE */
|
||||
|
||||
14
pnginfo.h
14
pnginfo.h
@@ -1,11 +1,11 @@
|
||||
|
||||
/* pnginfo.h - header file for PNG reference library
|
||||
*
|
||||
* Copyright (c) 1998-2011 Glenn Randers-Pehrson
|
||||
* Copyright (c) 1998-2013 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.)
|
||||
*
|
||||
* Last changed in libpng 1.5.0 [January 6, 2011]
|
||||
* Last changed in libpng 1.6.1 [March 28, 2013]
|
||||
*
|
||||
* This code is released under the libpng license.
|
||||
* For conditions of distribution and use, see the disclaimer
|
||||
@@ -88,7 +88,7 @@ struct png_info_def
|
||||
* and initialize the appropriate fields below.
|
||||
*/
|
||||
|
||||
#if defined PNG_COLORSPACE_SUPPORTED || defined PNG_GAMMA_SUPPORTED
|
||||
#if defined(PNG_COLORSPACE_SUPPORTED) || defined(PNG_GAMMA_SUPPORTED)
|
||||
/* png_colorspace only contains 'flags' if neither GAMMA or COLORSPACE are
|
||||
* defined. When COLORSPACE is switched on all the colorspace-defining
|
||||
* chunks should be enabled, when GAMMA is switched on all the gamma-defining
|
||||
@@ -223,13 +223,17 @@ defined(PNG_READ_BACKGROUND_SUPPORTED)
|
||||
#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
|
||||
/* Storage for unknown chunks that the library doesn't recognize. */
|
||||
png_unknown_chunkp unknown_chunks;
|
||||
unsigned int unknown_chunks_num;
|
||||
|
||||
/* The type of this field is limited by the type of
|
||||
* png_struct::user_chunk_cache_max, else overflow can occur.
|
||||
*/
|
||||
int unknown_chunks_num;
|
||||
#endif
|
||||
|
||||
#ifdef PNG_sPLT_SUPPORTED
|
||||
/* Data on sPLT chunks (there may be more than one). */
|
||||
png_sPLT_tp splt_palettes;
|
||||
png_uint_32 splt_palettes_num;
|
||||
int splt_palettes_num; /* Match type returned by png_get API */
|
||||
#endif
|
||||
|
||||
#ifdef PNG_sCAL_SUPPORTED
|
||||
|
||||
122
pngmem.c
122
pngmem.c
@@ -1,8 +1,8 @@
|
||||
|
||||
/* pngmem.c - stub functions for memory allocation
|
||||
*
|
||||
* Last changed in libpng 1.6.0 [(PENDING RELEASE)]
|
||||
* Copyright (c) 1998-2012 Glenn Randers-Pehrson
|
||||
* Last changed in libpng 1.7.0 [(PENDING RELEASE)]
|
||||
* Copyright (c) 1998-2014 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.)
|
||||
*
|
||||
@@ -73,10 +73,11 @@ png_malloc_base,(png_const_structrp png_ptr, png_alloc_size_t size),
|
||||
* to implement a user memory handler. This checks to be sure it isn't
|
||||
* called with big numbers.
|
||||
*/
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
#ifndef PNG_USER_MEM_SUPPORTED
|
||||
PNG_UNUSED(png_ptr)
|
||||
#endif
|
||||
if (size > 0 && size <= ~(size_t)0
|
||||
|
||||
if (size > 0 && size <= PNG_SIZE_MAX
|
||||
# ifdef PNG_MAX_MALLOC_64K
|
||||
&& size <= 65536U
|
||||
# endif
|
||||
@@ -95,6 +96,80 @@ png_malloc_base,(png_const_structrp png_ptr, png_alloc_size_t size),
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#if defined(PNG_TEXT_SUPPORTED) || defined(PNG_sPLT_SUPPORTED) ||\
|
||||
defined(PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED)
|
||||
/* This is really here only to work round a spurious warning in GCC 4.6 and 4.7
|
||||
* that arises because of the checks in png_realloc_array that are repeated in
|
||||
* png_malloc_array.
|
||||
*/
|
||||
static png_voidp
|
||||
png_malloc_array_checked(png_const_structrp png_ptr, int nelements,
|
||||
size_t element_size)
|
||||
{
|
||||
png_alloc_size_t req = nelements; /* known to be > 0 */
|
||||
|
||||
if (req <= PNG_SIZE_MAX/element_size)
|
||||
return png_malloc_base(png_ptr, req * element_size);
|
||||
|
||||
/* The failure case when the request is too large */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PNG_FUNCTION(png_voidp /* PRIVATE */,
|
||||
png_malloc_array,(png_const_structrp png_ptr, int nelements,
|
||||
size_t element_size),PNG_ALLOCATED)
|
||||
{
|
||||
if (nelements <= 0 || element_size == 0)
|
||||
png_error(png_ptr, "internal error: array alloc");
|
||||
|
||||
return png_malloc_array_checked(png_ptr, nelements, element_size);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
/* These are internal errors: */
|
||||
if (add_elements <= 0 || element_size == 0 || old_elements < 0 ||
|
||||
(old_array == NULL && old_elements > 0))
|
||||
png_error(png_ptr, "internal error: array realloc");
|
||||
|
||||
/* Check for overflow on the elements count (so the caller does not have to
|
||||
* check.)
|
||||
*/
|
||||
if (add_elements <= INT_MAX - old_elements)
|
||||
{
|
||||
png_voidp new_array = png_malloc_array_checked(png_ptr,
|
||||
old_elements+add_elements, element_size);
|
||||
|
||||
if (new_array != NULL)
|
||||
{
|
||||
/* Because png_malloc_array worked the size calculations below cannot
|
||||
* overflow.
|
||||
*/
|
||||
if (old_elements > 0)
|
||||
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);
|
||||
|
||||
return new_array;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef PNG_READ_SUPPORTED
|
||||
# ifdef PNG_USER_LIMITS_SUPPORTED
|
||||
/* The potential overflow case. Set the cache counter so libpng will
|
||||
* not make any more attempts
|
||||
*/
|
||||
png_ptr->user_chunk_cache_max = 2;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
return NULL; /* error */
|
||||
}
|
||||
#endif /* TEXT || sPLT || STORE_UNKNOWN_CHUNKS */
|
||||
|
||||
/* Various functions that have different error handling are derived from this.
|
||||
* png_malloc always exists, but if PNG_USER_MEM_SUPPORTED is defined a separate
|
||||
* function png_malloc_default is also provided.
|
||||
@@ -110,31 +185,11 @@ png_malloc,(png_const_structrp png_ptr, png_alloc_size_t size),PNG_ALLOCATED)
|
||||
ret = png_malloc_base(png_ptr, size);
|
||||
|
||||
if (ret == NULL)
|
||||
png_error(png_ptr, "Out of memory"); /* 'm' means png_malloc */
|
||||
png_error(png_ptr, "Out of memory");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
PNG_FUNCTION(png_voidp,PNGAPI
|
||||
png_malloc_default,(png_const_structrp png_ptr, png_alloc_size_t size),
|
||||
PNG_ALLOCATED PNG_DEPRECATED)
|
||||
{
|
||||
png_voidp ret;
|
||||
|
||||
if (png_ptr == NULL)
|
||||
return NULL;
|
||||
|
||||
/* Passing 'NULL' here bypasses the application provided memory handler. */
|
||||
ret = png_malloc_base(NULL/*use malloc*/, size);
|
||||
|
||||
if (ret == NULL)
|
||||
png_error(png_ptr, "Out of Memory"); /* 'M' means png_malloc_default */
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||
|
||||
/* This function was added at libpng version 1.2.3. The png_malloc_warn()
|
||||
* function will issue a png_warning and return NULL instead of issuing a
|
||||
* png_error, if it fails to allocate the requested memory.
|
||||
@@ -170,17 +225,8 @@ png_free(png_const_structrp png_ptr, png_voidp ptr)
|
||||
png_ptr->free_fn(png_constcast(png_structrp,png_ptr), ptr);
|
||||
|
||||
else
|
||||
png_free_default(png_ptr, ptr);
|
||||
}
|
||||
|
||||
PNG_FUNCTION(void,PNGAPI
|
||||
png_free_default,(png_const_structrp png_ptr, png_voidp ptr),PNG_DEPRECATED)
|
||||
{
|
||||
if (png_ptr == NULL || ptr == NULL)
|
||||
return;
|
||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||
|
||||
free(ptr);
|
||||
#endif /* USER_MEM */
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
@@ -211,5 +257,5 @@ png_get_mem_ptr(png_const_structrp png_ptr)
|
||||
|
||||
return png_ptr->mem_ptr;
|
||||
}
|
||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||
#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
|
||||
#endif /* USER_MEM */
|
||||
#endif /* READ || WRITE */
|
||||
|
||||
275
pngpread.c
275
pngpread.c
@@ -1,8 +1,8 @@
|
||||
|
||||
/* pngpread.c - read a png file in push mode
|
||||
*
|
||||
* Last changed in libpng 1.6.0 [(PENDING RELEASE)]
|
||||
* Copyright (c) 1998-2012 Glenn Randers-Pehrson
|
||||
* Last changed in libpng 1.7.0 [(PENDING RELEASE)]
|
||||
* Copyright (c) 1998-2014 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.)
|
||||
*
|
||||
@@ -26,6 +26,13 @@
|
||||
#define PNG_READ_iTXt_MODE 7
|
||||
#define PNG_ERROR_MODE 8
|
||||
|
||||
#define PNG_PUSH_SAVE_BUFFER_IF_FULL \
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size) \
|
||||
{ png_push_save_buffer(png_ptr); return; }
|
||||
#define PNG_PUSH_SAVE_BUFFER_IF_LT(N) \
|
||||
if (png_ptr->buffer_size < N) \
|
||||
{ png_push_save_buffer(png_ptr); return; }
|
||||
|
||||
void PNGAPI
|
||||
png_process_data(png_structrp png_ptr, png_inforp info_ptr,
|
||||
png_bytep buffer, png_size_t buffer_size)
|
||||
@@ -46,10 +53,10 @@ png_process_data_pause(png_structrp png_ptr, int save)
|
||||
{
|
||||
if (png_ptr != NULL)
|
||||
{
|
||||
/* It's easiest for the caller if we do the save, then the caller doesn't
|
||||
/* It's easiest for the caller if we do the save; then the caller doesn't
|
||||
* have to supply the same data again:
|
||||
*/
|
||||
if (save)
|
||||
if (save != 0)
|
||||
png_push_save_buffer(png_ptr);
|
||||
else
|
||||
{
|
||||
@@ -151,7 +158,7 @@ png_process_some_data(png_structrp png_ptr, png_inforp info_ptr)
|
||||
void /* PRIVATE */
|
||||
png_push_read_sig(png_structrp png_ptr, png_inforp info_ptr)
|
||||
{
|
||||
png_size_t num_checked = png_ptr->sig_bytes,
|
||||
png_size_t num_checked = png_ptr->sig_bytes, /* SAFE, does not exceed 8 */
|
||||
num_to_check = 8 - num_checked;
|
||||
|
||||
if (png_ptr->buffer_size < num_to_check)
|
||||
@@ -185,27 +192,22 @@ void /* PRIVATE */
|
||||
png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
|
||||
{
|
||||
png_uint_32 chunk_name;
|
||||
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
|
||||
#ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED
|
||||
int keep; /* unknown handling method */
|
||||
#endif
|
||||
|
||||
/* First we make sure we have enough data for the 4 byte chunk name
|
||||
* and the 4 byte chunk length before proceeding with decoding the
|
||||
/* First we make sure we have enough data for the 4-byte chunk name
|
||||
* and the 4-byte chunk length before proceeding with decoding the
|
||||
* chunk data. To fully decode each of these chunks, we also make
|
||||
* sure we have enough data in the buffer for the 4 byte CRC at the
|
||||
* sure we have enough data in the buffer for the 4-byte CRC at the
|
||||
* end of every chunk (except IDAT, which is handled separately).
|
||||
*/
|
||||
if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
|
||||
if ((png_ptr->mode & PNG_HAVE_CHUNK_HEADER) == 0)
|
||||
{
|
||||
png_byte chunk_length[4];
|
||||
png_byte chunk_tag[4];
|
||||
|
||||
if (png_ptr->buffer_size < 8)
|
||||
{
|
||||
png_push_save_buffer(png_ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
PNG_PUSH_SAVE_BUFFER_IF_LT(8)
|
||||
png_push_fill_buffer(png_ptr, chunk_length, 4);
|
||||
png_ptr->push_length = png_get_uint_31(png_ptr, chunk_length);
|
||||
png_reset_crc(png_ptr);
|
||||
@@ -219,28 +221,29 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
|
||||
|
||||
if (chunk_name == png_IDAT)
|
||||
{
|
||||
if (png_ptr->mode & PNG_AFTER_IDAT)
|
||||
if ((png_ptr->mode & PNG_AFTER_IDAT) != 0)
|
||||
png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
|
||||
|
||||
/* If we reach an IDAT chunk, this means we have read all of the
|
||||
* header chunks, and we can start reading the image (or if this
|
||||
* is called after the image has been read - we have an error).
|
||||
*/
|
||||
if (!(png_ptr->mode & PNG_HAVE_IHDR))
|
||||
if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
|
||||
png_error(png_ptr, "Missing IHDR before IDAT");
|
||||
|
||||
else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
|
||||
!(png_ptr->mode & PNG_HAVE_PLTE))
|
||||
(png_ptr->mode & PNG_HAVE_PLTE) == 0)
|
||||
png_error(png_ptr, "Missing PLTE before IDAT");
|
||||
|
||||
png_ptr->mode |= PNG_HAVE_IDAT;
|
||||
png_ptr->process_mode = PNG_READ_IDAT_MODE;
|
||||
|
||||
if (!(png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
|
||||
if ((png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT) == 0)
|
||||
if (png_ptr->push_length == 0)
|
||||
return;
|
||||
|
||||
if (png_ptr->mode & PNG_AFTER_IDAT)
|
||||
png_benign_error(png_ptr, "Too many IDATs found");
|
||||
if ((png_ptr->mode & PNG_AFTER_IDAT) != 0)
|
||||
png_benign_error(png_ptr, "Too many IDATs found[p]");
|
||||
}
|
||||
|
||||
if (chunk_name == png_IHDR)
|
||||
@@ -248,52 +251,33 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
|
||||
if (png_ptr->push_length != 13)
|
||||
png_error(png_ptr, "Invalid IHDR length");
|
||||
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
{
|
||||
png_push_save_buffer(png_ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
PNG_PUSH_SAVE_BUFFER_IF_FULL
|
||||
png_handle_IHDR(png_ptr, info_ptr, png_ptr->push_length);
|
||||
}
|
||||
|
||||
else if (chunk_name == png_IEND)
|
||||
{
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
{
|
||||
png_push_save_buffer(png_ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
PNG_PUSH_SAVE_BUFFER_IF_FULL
|
||||
png_handle_IEND(png_ptr, info_ptr, png_ptr->push_length);
|
||||
|
||||
png_ptr->process_mode = PNG_READ_DONE_MODE;
|
||||
png_push_have_end(png_ptr, info_ptr);
|
||||
}
|
||||
|
||||
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
|
||||
#ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED
|
||||
else if ((keep = png_chunk_unknown_handling(png_ptr, chunk_name)) != 0)
|
||||
{
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
{
|
||||
png_push_save_buffer(png_ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
PNG_PUSH_SAVE_BUFFER_IF_FULL
|
||||
png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length, keep);
|
||||
|
||||
if (chunk_name == png_PLTE)
|
||||
png_ptr->mode |= PNG_HAVE_PLTE;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
else if (chunk_name == png_PLTE)
|
||||
{
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
{
|
||||
png_push_save_buffer(png_ptr);
|
||||
return;
|
||||
}
|
||||
PNG_PUSH_SAVE_BUFFER_IF_FULL
|
||||
png_handle_PLTE(png_ptr, info_ptr, png_ptr->push_length);
|
||||
}
|
||||
|
||||
@@ -312,12 +296,7 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
|
||||
#ifdef PNG_READ_gAMA_SUPPORTED
|
||||
else if (png_ptr->chunk_name == png_gAMA)
|
||||
{
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
{
|
||||
png_push_save_buffer(png_ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
PNG_PUSH_SAVE_BUFFER_IF_FULL
|
||||
png_handle_gAMA(png_ptr, info_ptr, png_ptr->push_length);
|
||||
}
|
||||
|
||||
@@ -325,12 +304,7 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
|
||||
#ifdef PNG_READ_sBIT_SUPPORTED
|
||||
else if (png_ptr->chunk_name == png_sBIT)
|
||||
{
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
{
|
||||
png_push_save_buffer(png_ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
PNG_PUSH_SAVE_BUFFER_IF_FULL
|
||||
png_handle_sBIT(png_ptr, info_ptr, png_ptr->push_length);
|
||||
}
|
||||
|
||||
@@ -338,12 +312,7 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
|
||||
#ifdef PNG_READ_cHRM_SUPPORTED
|
||||
else if (png_ptr->chunk_name == png_cHRM)
|
||||
{
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
{
|
||||
png_push_save_buffer(png_ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
PNG_PUSH_SAVE_BUFFER_IF_FULL
|
||||
png_handle_cHRM(png_ptr, info_ptr, png_ptr->push_length);
|
||||
}
|
||||
|
||||
@@ -351,12 +320,7 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
|
||||
#ifdef PNG_READ_sRGB_SUPPORTED
|
||||
else if (chunk_name == png_sRGB)
|
||||
{
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
{
|
||||
png_push_save_buffer(png_ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
PNG_PUSH_SAVE_BUFFER_IF_FULL
|
||||
png_handle_sRGB(png_ptr, info_ptr, png_ptr->push_length);
|
||||
}
|
||||
|
||||
@@ -364,12 +328,7 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
|
||||
#ifdef PNG_READ_iCCP_SUPPORTED
|
||||
else if (png_ptr->chunk_name == png_iCCP)
|
||||
{
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
{
|
||||
png_push_save_buffer(png_ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
PNG_PUSH_SAVE_BUFFER_IF_FULL
|
||||
png_handle_iCCP(png_ptr, info_ptr, png_ptr->push_length);
|
||||
}
|
||||
|
||||
@@ -377,12 +336,7 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
|
||||
#ifdef PNG_READ_sPLT_SUPPORTED
|
||||
else if (chunk_name == png_sPLT)
|
||||
{
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
{
|
||||
png_push_save_buffer(png_ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
PNG_PUSH_SAVE_BUFFER_IF_FULL
|
||||
png_handle_sPLT(png_ptr, info_ptr, png_ptr->push_length);
|
||||
}
|
||||
|
||||
@@ -390,12 +344,7 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
|
||||
#ifdef PNG_READ_tRNS_SUPPORTED
|
||||
else if (chunk_name == png_tRNS)
|
||||
{
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
{
|
||||
png_push_save_buffer(png_ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
PNG_PUSH_SAVE_BUFFER_IF_FULL
|
||||
png_handle_tRNS(png_ptr, info_ptr, png_ptr->push_length);
|
||||
}
|
||||
|
||||
@@ -403,12 +352,7 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
|
||||
#ifdef PNG_READ_bKGD_SUPPORTED
|
||||
else if (chunk_name == png_bKGD)
|
||||
{
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
{
|
||||
png_push_save_buffer(png_ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
PNG_PUSH_SAVE_BUFFER_IF_FULL
|
||||
png_handle_bKGD(png_ptr, info_ptr, png_ptr->push_length);
|
||||
}
|
||||
|
||||
@@ -416,12 +360,7 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
|
||||
#ifdef PNG_READ_hIST_SUPPORTED
|
||||
else if (chunk_name == png_hIST)
|
||||
{
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
{
|
||||
png_push_save_buffer(png_ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
PNG_PUSH_SAVE_BUFFER_IF_FULL
|
||||
png_handle_hIST(png_ptr, info_ptr, png_ptr->push_length);
|
||||
}
|
||||
|
||||
@@ -429,12 +368,7 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
|
||||
#ifdef PNG_READ_pHYs_SUPPORTED
|
||||
else if (chunk_name == png_pHYs)
|
||||
{
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
{
|
||||
png_push_save_buffer(png_ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
PNG_PUSH_SAVE_BUFFER_IF_FULL
|
||||
png_handle_pHYs(png_ptr, info_ptr, png_ptr->push_length);
|
||||
}
|
||||
|
||||
@@ -442,12 +376,7 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
|
||||
#ifdef PNG_READ_oFFs_SUPPORTED
|
||||
else if (chunk_name == png_oFFs)
|
||||
{
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
{
|
||||
png_push_save_buffer(png_ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
PNG_PUSH_SAVE_BUFFER_IF_FULL
|
||||
png_handle_oFFs(png_ptr, info_ptr, png_ptr->push_length);
|
||||
}
|
||||
#endif
|
||||
@@ -455,12 +384,7 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
|
||||
#ifdef PNG_READ_pCAL_SUPPORTED
|
||||
else if (chunk_name == png_pCAL)
|
||||
{
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
{
|
||||
png_push_save_buffer(png_ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
PNG_PUSH_SAVE_BUFFER_IF_FULL
|
||||
png_handle_pCAL(png_ptr, info_ptr, png_ptr->push_length);
|
||||
}
|
||||
|
||||
@@ -468,12 +392,7 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
|
||||
#ifdef PNG_READ_sCAL_SUPPORTED
|
||||
else if (chunk_name == png_sCAL)
|
||||
{
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
{
|
||||
png_push_save_buffer(png_ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
PNG_PUSH_SAVE_BUFFER_IF_FULL
|
||||
png_handle_sCAL(png_ptr, info_ptr, png_ptr->push_length);
|
||||
}
|
||||
|
||||
@@ -481,12 +400,7 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
|
||||
#ifdef PNG_READ_tIME_SUPPORTED
|
||||
else if (chunk_name == png_tIME)
|
||||
{
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
{
|
||||
png_push_save_buffer(png_ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
PNG_PUSH_SAVE_BUFFER_IF_FULL
|
||||
png_handle_tIME(png_ptr, info_ptr, png_ptr->push_length);
|
||||
}
|
||||
|
||||
@@ -494,12 +408,7 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
|
||||
#ifdef PNG_READ_tEXt_SUPPORTED
|
||||
else if (chunk_name == png_tEXt)
|
||||
{
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
{
|
||||
png_push_save_buffer(png_ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
PNG_PUSH_SAVE_BUFFER_IF_FULL
|
||||
png_handle_tEXt(png_ptr, info_ptr, png_ptr->push_length);
|
||||
}
|
||||
|
||||
@@ -507,12 +416,7 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
|
||||
#ifdef PNG_READ_zTXt_SUPPORTED
|
||||
else if (chunk_name == png_zTXt)
|
||||
{
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
{
|
||||
png_push_save_buffer(png_ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
PNG_PUSH_SAVE_BUFFER_IF_FULL
|
||||
png_handle_zTXt(png_ptr, info_ptr, png_ptr->push_length);
|
||||
}
|
||||
|
||||
@@ -520,23 +424,14 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
|
||||
#ifdef PNG_READ_iTXt_SUPPORTED
|
||||
else if (chunk_name == png_iTXt)
|
||||
{
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
{
|
||||
png_push_save_buffer(png_ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
PNG_PUSH_SAVE_BUFFER_IF_FULL
|
||||
png_handle_iTXt(png_ptr, info_ptr, png_ptr->push_length);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
else
|
||||
{
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
{
|
||||
png_push_save_buffer(png_ptr);
|
||||
return;
|
||||
}
|
||||
PNG_PUSH_SAVE_BUFFER_IF_FULL
|
||||
png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length,
|
||||
PNG_HANDLE_CHUNK_AS_DEFAULT);
|
||||
}
|
||||
@@ -554,7 +449,7 @@ png_push_crc_skip(png_structrp png_ptr, png_uint_32 skip)
|
||||
void /* PRIVATE */
|
||||
png_push_crc_finish(png_structrp png_ptr)
|
||||
{
|
||||
if (png_ptr->skip_length && png_ptr->save_buffer_size)
|
||||
if (png_ptr->skip_length != 0 && png_ptr->save_buffer_size != 0)
|
||||
{
|
||||
png_size_t save_size = png_ptr->save_buffer_size;
|
||||
png_uint_32 skip_length = png_ptr->skip_length;
|
||||
@@ -578,7 +473,7 @@ png_push_crc_finish(png_structrp png_ptr)
|
||||
png_ptr->save_buffer_size -= save_size;
|
||||
png_ptr->save_buffer_ptr += save_size;
|
||||
}
|
||||
if (png_ptr->skip_length && png_ptr->current_buffer_size)
|
||||
if (png_ptr->skip_length != 0 && png_ptr->current_buffer_size != 0)
|
||||
{
|
||||
png_size_t save_size = png_ptr->current_buffer_size;
|
||||
png_uint_32 skip_length = png_ptr->skip_length;
|
||||
@@ -599,14 +494,9 @@ png_push_crc_finish(png_structrp png_ptr)
|
||||
png_ptr->current_buffer_size -= save_size;
|
||||
png_ptr->current_buffer_ptr += save_size;
|
||||
}
|
||||
if (!png_ptr->skip_length)
|
||||
if (png_ptr->skip_length == 0)
|
||||
{
|
||||
if (png_ptr->buffer_size < 4)
|
||||
{
|
||||
png_push_save_buffer(png_ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
PNG_PUSH_SAVE_BUFFER_IF_LT(4)
|
||||
png_crc_finish(png_ptr, 0);
|
||||
png_ptr->process_mode = PNG_READ_CHUNK_MODE;
|
||||
}
|
||||
@@ -621,7 +511,7 @@ png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length)
|
||||
return;
|
||||
|
||||
ptr = buffer;
|
||||
if (png_ptr->save_buffer_size)
|
||||
if (png_ptr->save_buffer_size != 0)
|
||||
{
|
||||
png_size_t save_size;
|
||||
|
||||
@@ -638,7 +528,7 @@ png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length)
|
||||
png_ptr->save_buffer_size -= save_size;
|
||||
png_ptr->save_buffer_ptr += save_size;
|
||||
}
|
||||
if (length && png_ptr->current_buffer_size)
|
||||
if (length != 0 && png_ptr->current_buffer_size != 0)
|
||||
{
|
||||
png_size_t save_size;
|
||||
|
||||
@@ -658,7 +548,7 @@ png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length)
|
||||
void /* PRIVATE */
|
||||
png_push_save_buffer(png_structrp png_ptr)
|
||||
{
|
||||
if (png_ptr->save_buffer_size)
|
||||
if (png_ptr->save_buffer_size != 0)
|
||||
{
|
||||
if (png_ptr->save_buffer_ptr != png_ptr->save_buffer)
|
||||
{
|
||||
@@ -694,11 +584,13 @@ png_push_save_buffer(png_structrp png_ptr)
|
||||
if (png_ptr->save_buffer == NULL)
|
||||
{
|
||||
png_free(png_ptr, old_buffer);
|
||||
old_buffer = NULL;
|
||||
png_error(png_ptr, "Insufficient memory for save_buffer");
|
||||
}
|
||||
|
||||
memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size);
|
||||
png_free(png_ptr, old_buffer);
|
||||
old_buffer = NULL;
|
||||
png_ptr->save_buffer_max = new_max;
|
||||
}
|
||||
if (png_ptr->current_buffer_size)
|
||||
@@ -725,18 +617,13 @@ png_push_restore_buffer(png_structrp png_ptr, png_bytep buffer,
|
||||
void /* PRIVATE */
|
||||
png_push_read_IDAT(png_structrp png_ptr)
|
||||
{
|
||||
if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
|
||||
if ((png_ptr->mode & PNG_HAVE_CHUNK_HEADER) == 0)
|
||||
{
|
||||
png_byte chunk_length[4];
|
||||
png_byte chunk_tag[4];
|
||||
|
||||
/* TODO: this code can be commoned up with the same code in push_read */
|
||||
if (png_ptr->buffer_size < 8)
|
||||
{
|
||||
png_push_save_buffer(png_ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
PNG_PUSH_SAVE_BUFFER_IF_LT(8)
|
||||
png_push_fill_buffer(png_ptr, chunk_length, 4);
|
||||
png_ptr->push_length = png_get_uint_31(png_ptr, chunk_length);
|
||||
png_reset_crc(png_ptr);
|
||||
@@ -748,7 +635,7 @@ png_push_read_IDAT(png_structrp png_ptr)
|
||||
{
|
||||
png_ptr->process_mode = PNG_READ_CHUNK_MODE;
|
||||
|
||||
if (!(png_ptr->flags & PNG_FLAG_ZSTREAM_ENDED))
|
||||
if ((png_ptr->flags & PNG_FLAG_ZSTREAM_ENDED) == 0)
|
||||
png_error(png_ptr, "Not enough compressed data");
|
||||
|
||||
return;
|
||||
@@ -757,7 +644,7 @@ png_push_read_IDAT(png_structrp png_ptr)
|
||||
png_ptr->idat_size = png_ptr->push_length;
|
||||
}
|
||||
|
||||
if (png_ptr->idat_size && png_ptr->save_buffer_size)
|
||||
if (png_ptr->idat_size != 0 && png_ptr->save_buffer_size != 0)
|
||||
{
|
||||
png_size_t save_size = png_ptr->save_buffer_size;
|
||||
png_uint_32 idat_size = png_ptr->idat_size;
|
||||
@@ -784,7 +671,7 @@ png_push_read_IDAT(png_structrp png_ptr)
|
||||
png_ptr->save_buffer_ptr += save_size;
|
||||
}
|
||||
|
||||
if (png_ptr->idat_size && png_ptr->current_buffer_size)
|
||||
if (png_ptr->idat_size != 0 && png_ptr->current_buffer_size != 0)
|
||||
{
|
||||
png_size_t save_size = png_ptr->current_buffer_size;
|
||||
png_uint_32 idat_size = png_ptr->idat_size;
|
||||
@@ -809,14 +696,9 @@ png_push_read_IDAT(png_structrp png_ptr)
|
||||
png_ptr->current_buffer_size -= save_size;
|
||||
png_ptr->current_buffer_ptr += save_size;
|
||||
}
|
||||
if (!png_ptr->idat_size)
|
||||
if (png_ptr->idat_size == 0)
|
||||
{
|
||||
if (png_ptr->buffer_size < 4)
|
||||
{
|
||||
png_push_save_buffer(png_ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
PNG_PUSH_SAVE_BUFFER_IF_LT(4)
|
||||
png_crc_finish(png_ptr, 0);
|
||||
png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
|
||||
png_ptr->mode |= PNG_AFTER_IDAT;
|
||||
@@ -844,7 +726,7 @@ png_process_IDAT_data(png_structrp png_ptr, png_bytep buffer,
|
||||
* or the stream marked as finished.
|
||||
*/
|
||||
while (png_ptr->zstream.avail_in > 0 &&
|
||||
!(png_ptr->flags & PNG_FLAG_ZSTREAM_ENDED))
|
||||
(png_ptr->flags & PNG_FLAG_ZSTREAM_ENDED) == 0)
|
||||
{
|
||||
int ret;
|
||||
|
||||
@@ -961,7 +843,7 @@ png_push_process_row(png_structrp png_ptr)
|
||||
memcpy(png_ptr->prev_row, png_ptr->row_buf, row_info.rowbytes + 1);
|
||||
|
||||
#ifdef PNG_READ_TRANSFORMS_SUPPORTED
|
||||
if (png_ptr->transformations)
|
||||
if (png_ptr->transformations != 0)
|
||||
png_do_read_transformations(png_ptr, &row_info);
|
||||
#endif
|
||||
|
||||
@@ -978,15 +860,16 @@ png_push_process_row(png_structrp png_ptr)
|
||||
|
||||
|
||||
#ifdef PNG_READ_INTERLACING_SUPPORTED
|
||||
/* Blow up interlaced rows to full size */
|
||||
if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
|
||||
/* Expand interlaced rows to full size */
|
||||
if (png_ptr->interlaced != 0 &&
|
||||
(png_ptr->transformations & PNG_INTERLACE) != 0)
|
||||
{
|
||||
if (png_ptr->pass < 6)
|
||||
png_do_read_interlace(&row_info, png_ptr->row_buf + 1, png_ptr->pass,
|
||||
png_ptr->transformations);
|
||||
|
||||
switch (png_ptr->pass)
|
||||
{
|
||||
switch (png_ptr->pass)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
int i;
|
||||
@@ -1189,7 +1072,7 @@ png_read_push_finish_row(png_structrp png_ptr)
|
||||
return;
|
||||
|
||||
#ifdef PNG_READ_INTERLACING_SUPPORTED
|
||||
if (png_ptr->interlaced)
|
||||
if (png_ptr->interlaced != 0)
|
||||
{
|
||||
png_ptr->row_number = 0;
|
||||
memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
|
||||
@@ -1213,7 +1096,7 @@ png_read_push_finish_row(png_structrp png_ptr)
|
||||
png_pass_start[png_ptr->pass]) /
|
||||
png_pass_inc[png_ptr->pass];
|
||||
|
||||
if (png_ptr->transformations & PNG_INTERLACE)
|
||||
if ((png_ptr->transformations & PNG_INTERLACE) != 0)
|
||||
break;
|
||||
|
||||
png_ptr->num_rows = (png_ptr->height +
|
||||
@@ -1223,7 +1106,7 @@ png_read_push_finish_row(png_structrp png_ptr)
|
||||
|
||||
} while (png_ptr->iwidth == 0 || png_ptr->num_rows == 0);
|
||||
}
|
||||
#endif /* PNG_READ_INTERLACING_SUPPORTED */
|
||||
#endif /* READ_INTERLACING */
|
||||
}
|
||||
|
||||
void /* PRIVATE */
|
||||
@@ -1261,9 +1144,9 @@ png_progressive_combine_row(png_const_structrp png_ptr, png_bytep old_row,
|
||||
* it must be png_ptr->row_buf+1
|
||||
*/
|
||||
if (new_row != NULL)
|
||||
png_combine_row(png_ptr, old_row, 1/*display*/);
|
||||
png_combine_row(png_ptr, old_row, 1/*blocky display*/);
|
||||
}
|
||||
#endif /* PNG_READ_INTERLACING_SUPPORTED */
|
||||
#endif /* READ_INTERLACING */
|
||||
|
||||
void PNGAPI
|
||||
png_set_progressive_read_fn(png_structrp png_ptr, png_voidp progressive_ptr,
|
||||
@@ -1288,4 +1171,4 @@ png_get_progressive_ptr(png_const_structrp png_ptr)
|
||||
|
||||
return png_ptr->io_ptr;
|
||||
}
|
||||
#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
|
||||
#endif /* PROGRESSIVE_READ */
|
||||
|
||||
581
pngpriv.h
581
pngpriv.h
@@ -2,11 +2,11 @@
|
||||
/* pngpriv.h - private declarations for use inside libpng
|
||||
*
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1998-2012 Glenn Randers-Pehrson
|
||||
* Copyright (c) 1998-2014 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.)
|
||||
*
|
||||
* Last changed in libpng 1.6.0 [(PENDING RELEASE)]
|
||||
* 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
|
||||
@@ -39,9 +39,18 @@
|
||||
*/
|
||||
#define _POSIX_SOURCE 1 /* Just the POSIX 1003.1 and C89 APIs */
|
||||
|
||||
#ifndef PNG_VERSION_INFO_ONLY
|
||||
/* Keep standard libraries at the top of this file */
|
||||
|
||||
/* Standard library headers not required by png.h: */
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
# include <stdlib.h>
|
||||
# include <string.h>
|
||||
|
||||
/* For headers only required with some build configurations see the lines after
|
||||
* pnglibconf.h is included!
|
||||
*/
|
||||
|
||||
#endif /* VERSION_INFO_ONLY */
|
||||
|
||||
#define PNGLIB_BUILD /*libpng is being built, not used*/
|
||||
|
||||
@@ -54,7 +63,7 @@
|
||||
* configure generated config.h. Libpng is expected to compile without *any*
|
||||
* special build system support on a reasonably ANSI-C compliant system.
|
||||
*/
|
||||
#if (defined HAVE_CONFIG_H) && !(defined PNG_NO_CONFIG_H)
|
||||
#if defined(HAVE_CONFIG_H) && !defined(PNG_NO_CONFIG_H)
|
||||
# include <config.h>
|
||||
|
||||
/* Pick up the definition of 'restrict' from config.h if it was read: */
|
||||
@@ -71,7 +80,7 @@
|
||||
#endif
|
||||
|
||||
/* Local renames may change non-exported API functions from png.h */
|
||||
#if defined PNG_PREFIX && !defined PNGPREFIX_H
|
||||
#if defined(PNG_PREFIX) && !defined(PNGPREFIX_H)
|
||||
# include "pngprefix.h"
|
||||
#endif
|
||||
|
||||
@@ -86,6 +95,124 @@
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef PNG_VERSION_INFO_ONLY
|
||||
/* Additional standard libaries required in certain cases, put only standard
|
||||
* ANSI-C89 headers here. If not available, or non-functional, the problem
|
||||
* should be fixed by writing a wrapper for the header and the file on your
|
||||
* include path.
|
||||
*/
|
||||
#if defined(PNG_sCAL_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
|
||||
/* png.c requires the following ANSI-C constants if the conversion of
|
||||
* floating point to ASCII is implemented therein:
|
||||
*
|
||||
* DBL_MIN_10_EXP Minimum negative integer such that 10^integer is a
|
||||
* normalized (double) value.
|
||||
* DBL_DIG Maximum number of decimal digits (can be set to any constant)
|
||||
* DBL_MIN Smallest normalized fp number (can be set to an arbitrary value)
|
||||
* DBL_MAX Maximum floating point number (can be set to an arbitrary value)
|
||||
*/
|
||||
# include <float.h>
|
||||
#endif /* sCAL && FLOATING_POINT */
|
||||
|
||||
#if defined(PNG_FLOATING_ARITHMETIC_SUPPORTED) ||\
|
||||
defined(PNG_FLOATING_POINT_SUPPORTED)
|
||||
/* ANSI-C90 math functions are required. Full compliance with the standard
|
||||
* is probably not a requirement, but the functions must exist and be
|
||||
* declared in <math.h>
|
||||
*/
|
||||
# include <math.h>
|
||||
#endif /* FLOATING_ARITHMETIC || FLOATING_POINT */
|
||||
|
||||
#endif /* VERSION_INFO_ONLY */
|
||||
|
||||
/* Compile time options.
|
||||
* =====================
|
||||
* In a multi-arch build the compiler may compile the code several times for the
|
||||
* same object module, producing different binaries for different architectures.
|
||||
* When this happens configure-time setting of the target host options cannot be
|
||||
* done and this interferes with the handling of the ARM NEON optimizations, and
|
||||
* possibly other similar optimizations. Put additional tests here; in general
|
||||
* this is needed when the same option can be changed at both compile time and
|
||||
* run time depending on the target OS (i.e. iOS vs Android.)
|
||||
*
|
||||
* NOTE: symbol prefixing does not pass $(CFLAGS) to the preprocessor, because
|
||||
* this is not possible with certain compilers (Oracle SUN OS CC), as a result
|
||||
* it is necessary to ensure that all extern functions that *might* be used
|
||||
* regardless of $(CFLAGS) get declared in this file. The test on __ARM_NEON__
|
||||
* below is one example of this behavior because it is controlled by the
|
||||
* presence or not of -mfpu=neon on the GCC command line, it is possible to do
|
||||
* this in $(CC), e.g. "CC=gcc -mfpu=neon", but people who build libpng rarely
|
||||
* do this.
|
||||
*/
|
||||
#ifndef PNG_ARM_NEON_OPT
|
||||
/* ARM NEON optimizations are being controlled by the compiler settings,
|
||||
* typically the target FPU. If the FPU has been set to NEON (-mfpu=neon
|
||||
* with GCC) then the compiler will define __ARM_NEON__ and we can rely
|
||||
* unconditionally on NEON instructions not crashing, otherwise we must
|
||||
* disable use of NEON instructions.
|
||||
*
|
||||
* NOTE: at present these optimizations depend on 'ALIGNED_MEMORY', so they
|
||||
* can only be turned on automatically if that is supported too. If
|
||||
* PNG_ARM_NEON_OPT is set in CPPFLAGS (to >0) then arm/arm_init.c will fail
|
||||
* to compile with an appropriate #error if ALIGNED_MEMORY has been turned
|
||||
* off.
|
||||
*/
|
||||
# if defined(__ARM_NEON__) && defined(PNG_ALIGNED_MEMORY_SUPPORTED)
|
||||
# define PNG_ARM_NEON_OPT 2
|
||||
# else
|
||||
# define PNG_ARM_NEON_OPT 0
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if PNG_ARM_NEON_OPT > 0
|
||||
/* NEON optimizations are to be at least considered by libpng, so enable the
|
||||
* callbacks to do this.
|
||||
*/
|
||||
# define PNG_FILTER_OPTIMIZATIONS png_init_filter_functions_neon
|
||||
|
||||
/* By default the 'intrinsics' code in arm/filter_neon_intrinsics.c is used
|
||||
* if possible - if __ARM_NEON__ is set and the compiler version is not known
|
||||
* to be broken. This is controlled by PNG_ARM_NEON_IMPLEMENTATION which can
|
||||
* be:
|
||||
*
|
||||
* 1 The intrinsics code (the default with __ARM_NEON__)
|
||||
* 2 The hand coded assembler (the default without __ARM_NEON__)
|
||||
*
|
||||
* It is possible to set PNG_ARM_NEON_IMPLEMENTATION in CPPFLAGS, however
|
||||
* this is *NOT* supported and may cease to work even after a minor revision
|
||||
* to libpng. It *is* valid to do this for testing purposes, e.g. speed
|
||||
* testing or a new compiler, but the results should be communicated to the
|
||||
* libpng implementation list for incorporation in the next minor release.
|
||||
*/
|
||||
# ifndef PNG_ARM_NEON_IMPLEMENTATION
|
||||
# ifdef __ARM_NEON__
|
||||
# if defined(__clang__)
|
||||
/* At present it is unknown by the libpng developers which versions
|
||||
* of clang support the intrinsics, however some or perhaps all
|
||||
* versions do not work with the assembler so this may be
|
||||
* irrelevant, so just use the default (do nothing here.)
|
||||
*/
|
||||
# elif defined(__GNUC__)
|
||||
/* GCC 4.5.4 NEON support is known to be broken. 4.6.3 is known to
|
||||
* work, so if this *is* GCC, or G++, look for a version >4.5
|
||||
*/
|
||||
# if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 6)
|
||||
# define PNG_ARM_NEON_IMPLEMENTATION 2
|
||||
# endif /* no GNUC support */
|
||||
# endif /* __GNUC__ */
|
||||
# else /* !defined __ARM_NEON__ */
|
||||
/* The 'intrinsics' code simply won't compile without this -mfpu=neon:
|
||||
*/
|
||||
# define PNG_ARM_NEON_IMPLEMENTATION 2
|
||||
# endif /* __ARM_NEON__ */
|
||||
# endif /* !defined PNG_ARM_NEON_IMPLEMENTATION */
|
||||
|
||||
# ifndef PNG_ARM_NEON_IMPLEMENTATION
|
||||
/* Use the intrinsics code by default. */
|
||||
# define PNG_ARM_NEON_IMPLEMENTATION 1
|
||||
# endif
|
||||
#endif /* PNG_ARM_NEON_OPT > 0 */
|
||||
|
||||
/* Is this a build of a DLL where compilation of the object modules requires
|
||||
* different preprocessor settings to those required for a simple library? If
|
||||
* so PNG_BUILD_DLL must be set.
|
||||
@@ -164,6 +291,11 @@
|
||||
extern PNG_FUNCTION(type, name, args, PNG_EMPTY attributes)
|
||||
#endif
|
||||
|
||||
#ifndef PNG_INTERNAL_CALLBACK
|
||||
# define PNG_INTERNAL_CALLBACK(type, name, args, attributes)\
|
||||
extern PNG_FUNCTION(type, (PNGCBAPI name), args, PNG_EMPTY attributes)
|
||||
#endif
|
||||
|
||||
/* If floating or fixed point APIs are disabled they may still be compiled
|
||||
* internally. To handle this make sure they are declared as the appropriate
|
||||
* internal extern function (otherwise the symbol prefixing stuff won't work and
|
||||
@@ -177,10 +309,12 @@
|
||||
# ifndef PNG_FLOATING_POINT_SUPPORTED
|
||||
# define PNG_FP_EXPORT(ordinal, type, name, args)\
|
||||
PNG_INTERNAL_FUNCTION(type, name, args, PNG_EMPTY);
|
||||
typedef struct png_incomplete png_double;
|
||||
typedef png_double* png_doublep;
|
||||
typedef const png_double* png_const_doublep;
|
||||
typedef png_double** png_doublepp;
|
||||
# ifndef PNG_VERSION_INFO_ONLY
|
||||
typedef struct png_incomplete png_double;
|
||||
typedef png_double* png_doublep;
|
||||
typedef const png_double* png_const_doublep;
|
||||
typedef png_double** png_doublepp;
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
#ifndef PNG_FIXED_EXPORT
|
||||
@@ -190,15 +324,27 @@
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Include png.h here to get the version info and other macros, pngstruct.h and
|
||||
* pnginfo.h are included later under the protection of !PNG_VERSION_INFO_ONLY
|
||||
*/
|
||||
#include "png.h"
|
||||
#include "pngstruct.h"
|
||||
#include "pnginfo.h"
|
||||
|
||||
/* pngconf.h does not set PNG_DLL_EXPORT unless it is required, so: */
|
||||
#ifndef PNG_DLL_EXPORT
|
||||
# define PNG_DLL_EXPORT
|
||||
#endif
|
||||
|
||||
/* asserts are turned off in release code, but are in even in release candidates
|
||||
* because often system builders only check future libpng releases when a
|
||||
* release candidate is available.
|
||||
*/
|
||||
#if PNG_LIBPNG_BUILD_BASE_TYPE == PNG_LIBPNG_BUILD_STABLE
|
||||
# define NDEBUG
|
||||
#endif
|
||||
#ifndef PNG_VERSION_INFO_ONLY
|
||||
# include <assert.h>
|
||||
#endif
|
||||
|
||||
/* SECURITY and SAFETY:
|
||||
*
|
||||
* By default libpng is built without any internal limits on image size,
|
||||
@@ -238,11 +384,6 @@
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* This is used for 16 bit gamma tables -- only the top level pointers are
|
||||
* const; this could be changed:
|
||||
*/
|
||||
typedef const png_uint_16p * png_const_uint_16pp;
|
||||
|
||||
/* Moved to pngpriv.h at libpng-1.5.0 */
|
||||
/* NOTE: some of these may have been used in external applications as
|
||||
* these definitions were exposed in pngconf.h prior to 1.5.
|
||||
@@ -288,8 +429,6 @@ typedef const png_uint_16p * png_const_uint_16pp;
|
||||
#ifdef PNG_WARNINGS_SUPPORTED
|
||||
# define PNG_WARNING_PARAMETERS(p) png_warning_parameters p;
|
||||
#else
|
||||
# define png_warning(s1,s2) ((void)(s1))
|
||||
# define png_chunk_warning(s1,s2) ((void)(s1))
|
||||
# define png_warning_parameter(p,number,string) ((void)0)
|
||||
# define png_warning_parameter_unsigned(p,number,format,value) ((void)0)
|
||||
# define png_warning_parameter_signed(p,number,format,value) ((void)0)
|
||||
@@ -297,8 +436,6 @@ typedef const png_uint_16p * png_const_uint_16pp;
|
||||
# define PNG_WARNING_PARAMETERS(p)
|
||||
#endif
|
||||
#ifndef PNG_ERROR_TEXT_SUPPORTED
|
||||
# define png_error(s1,s2) png_err(s1)
|
||||
# define png_chunk_error(s1,s2) png_err(s1)
|
||||
# define png_fixed_error(s1,s2) png_err(s1)
|
||||
#endif
|
||||
|
||||
@@ -331,65 +468,6 @@ typedef const png_uint_16p * png_const_uint_16pp;
|
||||
# define PNGFAPI /* PRIVATE */
|
||||
#endif
|
||||
|
||||
/* Other defines specific to compilers can go here. Try to keep
|
||||
* them inside an appropriate ifdef/endif pair for portability.
|
||||
*/
|
||||
#if defined(PNG_FLOATING_POINT_SUPPORTED) ||\
|
||||
defined(PNG_FLOATING_ARITHMETIC_SUPPORTED)
|
||||
/* png.c requires the following ANSI-C constants if the conversion of
|
||||
* floating point to ASCII is implemented therein:
|
||||
*
|
||||
* DBL_DIG Maximum number of decimal digits (can be set to any constant)
|
||||
* DBL_MIN Smallest normalized fp number (can be set to an arbitrary value)
|
||||
* DBL_MAX Maximum floating point number (can be set to an arbitrary value)
|
||||
*/
|
||||
# include <float.h>
|
||||
|
||||
# if (defined(__MWERKS__) && defined(macintosh)) || defined(applec) || \
|
||||
defined(THINK_C) || defined(__SC__) || defined(TARGET_OS_MAC)
|
||||
/* We need to check that <math.h> hasn't already been included earlier
|
||||
* as it seems it doesn't agree with <fp.h>, yet we should really use
|
||||
* <fp.h> if possible.
|
||||
*/
|
||||
# if !defined(__MATH_H__) && !defined(__MATH_H) && !defined(__cmath__)
|
||||
# include <fp.h>
|
||||
# endif
|
||||
# else
|
||||
# include <math.h>
|
||||
# endif
|
||||
# if defined(_AMIGA) && defined(__SASC) && defined(_M68881)
|
||||
/* Amiga SAS/C: We must include builtin FPU functions when compiling using
|
||||
* MATH=68881
|
||||
*/
|
||||
# include <m68881.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* This provides the non-ANSI (far) memory allocation routines. */
|
||||
#if defined(__TURBOC__) && defined(__MSDOS__)
|
||||
# include <mem.h>
|
||||
# include <alloc.h>
|
||||
#endif
|
||||
|
||||
#if defined(WIN32) || defined(_Windows) || defined(_WINDOWS) || \
|
||||
defined(_WIN32) || defined(__WIN32__)
|
||||
# include <windows.h> /* defines _WINDOWS_ macro */
|
||||
#endif
|
||||
|
||||
/* Moved here around 1.5.0beta36 from pngconf.h */
|
||||
/* Users may want to use these so they are not private. Any library
|
||||
* functions that are passed far data must be model-independent.
|
||||
*/
|
||||
|
||||
/* Memory model/platform independent fns */
|
||||
#ifndef PNG_ABORT
|
||||
# ifdef _WINDOWS_
|
||||
# define PNG_ABORT() ExitProcess(0)
|
||||
# else
|
||||
# define PNG_ABORT() abort()
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* These macros may need to be architecture dependent. */
|
||||
#define PNG_ALIGN_NONE 0 /* do not use data alignment */
|
||||
#define PNG_ALIGN_ALWAYS 1 /* assume unaligned accesses are OK */
|
||||
@@ -411,7 +489,7 @@ typedef const png_uint_16p * png_const_uint_16pp;
|
||||
#if PNG_ALIGN_TYPE == PNG_ALIGN_SIZE
|
||||
/* This is used because in some compiler implementations non-aligned
|
||||
* structure members are supported, so the offsetof approach below fails.
|
||||
* Set PNG_ALIGN_TO_SIZE=0 for compiler combinations where unaligned access
|
||||
* Set PNG_ALIGN_SIZE=0 for compiler combinations where unaligned access
|
||||
* is good for performance. Do not do this unless you have tested the result
|
||||
* and understand it.
|
||||
*/
|
||||
@@ -458,7 +536,7 @@ typedef const png_uint_16p * png_const_uint_16pp;
|
||||
#define PNG_HAVE_CHUNK_HEADER 0x100
|
||||
#define PNG_WROTE_tIME 0x200
|
||||
#define PNG_WROTE_INFO_BEFORE_PLTE 0x400
|
||||
#define PNG_BACKGROUND_IS_GRAY 0x800
|
||||
/* 0x800 (unused) */
|
||||
#define PNG_HAVE_PNG_SIGNATURE 0x1000
|
||||
#define PNG_HAVE_CHUNK_AFTER_IDAT 0x2000 /* Have another chunk after IDAT */
|
||||
/* 0x4000 (unused) */
|
||||
@@ -472,10 +550,10 @@ typedef const png_uint_16p * png_const_uint_16pp;
|
||||
#define PNG_SWAP_BYTES 0x0010
|
||||
#define PNG_INVERT_MONO 0x0020
|
||||
#define PNG_QUANTIZE 0x0040
|
||||
#define PNG_COMPOSE 0x0080 /* Was PNG_BACKGROUND */
|
||||
#define PNG_BACKGROUND_EXPAND 0x0100
|
||||
#define PNG_EXPAND_16 0x0200 /* Added to libpng 1.5.2 */
|
||||
#define PNG_16_TO_8 0x0400 /* Becomes 'chop' in 1.5.4 */
|
||||
#define PNG_COMPOSE 0x0080 /* Was PNG_BACKGROUND */
|
||||
/* 0x0100 unused */
|
||||
#define PNG_EXPAND_16 0x0200 /* Added to libpng 1.5.2 */
|
||||
#define PNG_16_TO_8 0x0400 /* Becomes 'chop' in 1.5.4 */
|
||||
#define PNG_RGBA 0x0800
|
||||
#define PNG_EXPAND 0x1000
|
||||
#define PNG_GAMMA 0x2000
|
||||
@@ -490,13 +568,13 @@ typedef const png_uint_16p * png_const_uint_16pp;
|
||||
#define PNG_RGB_TO_GRAY_WARN 0x400000
|
||||
#define PNG_RGB_TO_GRAY 0x600000 /* two bits, RGB_TO_GRAY_ERR|WARN */
|
||||
#define PNG_ENCODE_ALPHA 0x800000 /* Added to libpng-1.5.4 */
|
||||
#define PNG_ADD_ALPHA 0x1000000 /* Added to libpng-1.2.7 */
|
||||
#define PNG_EXPAND_tRNS 0x2000000 /* Added to libpng-1.2.9 */
|
||||
#define PNG_SCALE_16_TO_8 0x4000000 /* Added to libpng-1.5.4 */
|
||||
/* 0x8000000 unused */
|
||||
/* 0x10000000 unused */
|
||||
/* 0x20000000 unused */
|
||||
/* 0x40000000 unused */
|
||||
#define PNG_ADD_ALPHA 0x1000000 /* Added to libpng-1.2.7 */
|
||||
#define PNG_EXPAND_tRNS 0x2000000 /* Added to libpng-1.2.9 */
|
||||
#define PNG_SCALE_16_TO_8 0x4000000 /* Added to libpng-1.5.4 */
|
||||
/* 0x8000000 unused */
|
||||
/* 0x10000000 unused */
|
||||
/* 0x20000000 unused */
|
||||
/* 0x40000000 unused */
|
||||
/* Flags for png_create_struct */
|
||||
#define PNG_STRUCT_PNG 0x0001
|
||||
#define PNG_STRUCT_INFO 0x0002
|
||||
@@ -529,8 +607,8 @@ typedef const png_uint_16p * png_const_uint_16pp;
|
||||
#define PNG_FLAG_BENIGN_ERRORS_WARN 0x100000 /* Added to libpng-1.4.0 */
|
||||
#define PNG_FLAG_APP_WARNINGS_WARN 0x200000 /* Added to libpng-1.6.0 */
|
||||
#define PNG_FLAG_APP_ERRORS_WARN 0x400000 /* Added to libpng-1.6.0 */
|
||||
/* 0x800000 unused */
|
||||
/* 0x1000000 unused */
|
||||
#define PNG_FLAG_BACKGROUND_IS_GRAY 0x800000
|
||||
#define PNG_FLAG_BACKGROUND_EXPAND 0x1000000
|
||||
/* 0x2000000 unused */
|
||||
/* 0x4000000 unused */
|
||||
/* 0x8000000 unused */
|
||||
@@ -553,19 +631,9 @@ typedef const png_uint_16p * png_const_uint_16pp;
|
||||
abs((int)((c1).green) - (int)((c2).green)) + \
|
||||
abs((int)((c1).blue) - (int)((c2).blue)))
|
||||
|
||||
/* Added to libpng-1.5.7: sRGB conversion tables */
|
||||
#if defined PNG_SIMPLIFIED_READ_SUPPORTED ||\
|
||||
defined PNG_SIMPLIFIED_WRITE_SUPPORTED
|
||||
#ifdef PNG_SIMPLIFIED_READ_SUPPORTED
|
||||
PNG_INTERNAL_DATA(const png_uint_16, png_sRGB_table, [256]);
|
||||
/* Convert from an sRGB encoded value 0..255 to a 16-bit linear value,
|
||||
* 0..65535. This table gives the closest 16-bit answers (no errors).
|
||||
*/
|
||||
#endif
|
||||
|
||||
PNG_INTERNAL_DATA(const png_uint_16, png_sRGB_base, [512]);
|
||||
PNG_INTERNAL_DATA(const png_byte, png_sRGB_delta, [512]);
|
||||
|
||||
#if defined(PNG_SIMPLIFIED_READ_SUPPORTED) ||\
|
||||
defined(PNG_SIMPLIFIED_WRITE_SUPPORTED)
|
||||
/* See below for the definitions of the tables used in these macros */
|
||||
#define PNG_sRGB_FROM_LINEAR(linear) ((png_byte)((png_sRGB_base[(linear)>>15] +\
|
||||
((((linear)&0x7fff)*png_sRGB_delta[(linear)>>15])>>12)) >> 8))
|
||||
/* Given a value 'linear' in the range 0..255*65535 calculate the 8-bit sRGB
|
||||
@@ -637,76 +705,56 @@ PNG_INTERNAL_DATA(const png_byte, png_sRGB_delta, [512]);
|
||||
*/
|
||||
#endif
|
||||
|
||||
/* Constants for known chunk types. If you need to add a chunk, define the name
|
||||
* here. For historical reasons these constants have the form png_<name>; i.e.
|
||||
* the prefix is lower case. Please use decimal values as the parameters to
|
||||
* match the ISO PNG specification and to avoid relying on the C locale
|
||||
* interpretation of character values.
|
||||
*
|
||||
* Prior to 1.5.6 these constants were strings, as of 1.5.6 png_uint_32 values
|
||||
* are computed and a new macro (PNG_STRING_FROM_CHUNK) added to allow a string
|
||||
* to be generated if required.
|
||||
*
|
||||
* PNG_32b correctly produces a value shifted by up to 24 bits, even on
|
||||
* architectures where (int) is only 16 bits.
|
||||
*/
|
||||
#define PNG_32b(b,s) ((png_uint_32)(b) << (s))
|
||||
#define PNG_CHUNK(b1,b2,b3,b4) \
|
||||
(PNG_32b(b1,24) | PNG_32b(b2,16) | PNG_32b(b3,8) | PNG_32b(b4,0))
|
||||
|
||||
#define png_IHDR PNG_CHUNK( 73, 72, 68, 82)
|
||||
#define png_IDAT PNG_CHUNK( 73, 68, 65, 84)
|
||||
#define png_IEND PNG_CHUNK( 73, 69, 78, 68)
|
||||
#define png_PLTE PNG_CHUNK( 80, 76, 84, 69)
|
||||
#define png_bKGD PNG_CHUNK( 98, 75, 71, 68)
|
||||
#define png_cHRM PNG_CHUNK( 99, 72, 82, 77)
|
||||
#define png_gAMA PNG_CHUNK(103, 65, 77, 65)
|
||||
#define png_hIST PNG_CHUNK(104, 73, 83, 84)
|
||||
#define png_iCCP PNG_CHUNK(105, 67, 67, 80)
|
||||
#define png_iTXt PNG_CHUNK(105, 84, 88, 116)
|
||||
#define png_oFFs PNG_CHUNK(111, 70, 70, 115)
|
||||
#define png_pCAL PNG_CHUNK(112, 67, 65, 76)
|
||||
#define png_sCAL PNG_CHUNK(115, 67, 65, 76)
|
||||
#define png_pHYs PNG_CHUNK(112, 72, 89, 115)
|
||||
#define png_sBIT PNG_CHUNK(115, 66, 73, 84)
|
||||
#define png_sPLT PNG_CHUNK(115, 80, 76, 84)
|
||||
#define png_sRGB PNG_CHUNK(115, 82, 71, 66)
|
||||
#define png_sTER PNG_CHUNK(115, 84, 69, 82)
|
||||
#define png_tEXt PNG_CHUNK(116, 69, 88, 116)
|
||||
#define png_tIME PNG_CHUNK(116, 73, 77, 69)
|
||||
#define png_tRNS PNG_CHUNK(116, 82, 78, 83)
|
||||
#define png_zTXt PNG_CHUNK(122, 84, 88, 116)
|
||||
|
||||
/* The following will work on (signed char*) strings, whereas the get_uint_32
|
||||
* macro will fail on top-bit-set values because of the sign extension.
|
||||
*/
|
||||
#define PNG_CHUNK_FROM_STRING(s)\
|
||||
PNG_CHUNK(0xff&(s)[0], 0xff&(s)[1], 0xff&(s)[2], 0xff&(s)[3])
|
||||
|
||||
/* This uses (char), not (png_byte) to avoid warnings on systems where (char) is
|
||||
* signed and the argument is a (char[]) This macro will fail miserably on
|
||||
* systems where (char) is more than 8 bits.
|
||||
*/
|
||||
#define PNG_STRING_FROM_CHUNK(s,c)\
|
||||
(void)(((char*)(s))[0]=(char)((c)>>24), ((char*)(s))[1]=(char)((c)>>16),\
|
||||
((char*)(s))[2]=(char)((c)>>8), ((char*)(s))[3]=(char)((c)))
|
||||
|
||||
/* Do the same but terminate with a null character. */
|
||||
#define PNG_CSTRING_FROM_CHUNK(s,c)\
|
||||
(void)(PNG_STRING_FROM_CHUNK(s,c), ((char*)(s))[4] = 0)
|
||||
|
||||
/* Test on flag values as defined in the spec (section 5.4): */
|
||||
#define PNG_CHUNK_ANCILLIARY(c) (1 & ((c) >> 29))
|
||||
#define PNG_CHUNK_CRITICAL(c) (!PNG_CHUNK_ANCILLIARY(c))
|
||||
#define PNG_CHUNK_PRIVATE(c) (1 & ((c) >> 21))
|
||||
#define PNG_CHUNK_RESERVED(c) (1 & ((c) >> 13))
|
||||
#define PNG_CHUNK_SAFE_TO_COPY(c) (1 & ((c) >> 5))
|
||||
|
||||
/* Gamma values (new at libpng-1.5.4): */
|
||||
#define PNG_GAMMA_MAC_OLD 151724 /* Assume '1.8' is really 2.2/1.45! */
|
||||
#define PNG_GAMMA_MAC_INVERSE 65909
|
||||
#define PNG_GAMMA_sRGB_INVERSE 45455
|
||||
|
||||
/* Almost everything below is C specific; the #defines above can be used in
|
||||
* non-C code (so long as it is C-preprocessed) the rest of this stuff cannot.
|
||||
*/
|
||||
#ifndef PNG_VERSION_INFO_ONLY
|
||||
|
||||
#include "pngstruct.h"
|
||||
#include "pnginfo.h"
|
||||
|
||||
/* Validate the include paths - the include path used to generate pnglibconf.h
|
||||
* must match that used in the build, or we must be using pnglibconf.h.prebuilt:
|
||||
*/
|
||||
#if PNG_ZLIB_VERNUM != 0 && PNG_ZLIB_VERNUM != ZLIB_VERNUM
|
||||
# error ZLIB_VERNUM != PNG_ZLIB_VERNUM \
|
||||
"-I (include path) error: see the notes in pngpriv.h"
|
||||
/* This means that when pnglibconf.h was built the copy of zlib.h that it
|
||||
* used is not the same as the one being used here. Because the build of
|
||||
* libpng makes decisions to use inflateInit2 and inflateReset2 based on the
|
||||
* zlib version number and because this affects handling of certain broken
|
||||
* PNG files the -I directives must match.
|
||||
*
|
||||
* The most likely explanation is that you passed a -I in CFLAGS, this will
|
||||
* not work; all the preprocessor directories and in particular all the -I
|
||||
* directives must be in CPPFLAGS.
|
||||
*/
|
||||
#endif
|
||||
|
||||
/* This is used for 16 bit gamma tables -- only the top level pointers are
|
||||
* const; this could be changed:
|
||||
*/
|
||||
typedef const png_uint_16p * png_const_uint_16pp;
|
||||
|
||||
/* Added to libpng-1.5.7: sRGB conversion tables */
|
||||
#if defined(PNG_SIMPLIFIED_READ_SUPPORTED) ||\
|
||||
defined(PNG_SIMPLIFIED_WRITE_SUPPORTED)
|
||||
#ifdef PNG_SIMPLIFIED_READ_SUPPORTED
|
||||
PNG_INTERNAL_DATA(const png_uint_16, png_sRGB_table, [256]);
|
||||
/* Convert from an sRGB encoded value 0..255 to a 16-bit linear value,
|
||||
* 0..65535. This table gives the closest 16-bit answers (no errors).
|
||||
*/
|
||||
#endif
|
||||
|
||||
PNG_INTERNAL_DATA(const png_uint_16, png_sRGB_base, [512]);
|
||||
PNG_INTERNAL_DATA(const png_byte, png_sRGB_delta, [512]);
|
||||
#endif /* PNG_SIMPLIFIED_READ/WRITE */
|
||||
|
||||
|
||||
/* Inhibit C++ name-mangling for libpng functions but not for system calls. */
|
||||
#ifdef __cplusplus
|
||||
@@ -733,6 +781,16 @@ PNG_INTERNAL_FUNCTION(void,png_free_buffer_list,(png_structrp png_ptr,
|
||||
/* Free the buffer list used by the compressed write code. */
|
||||
#endif
|
||||
|
||||
#ifdef PNG_WRITE_FILTER_SUPPORTED
|
||||
PNG_INTERNAL_FUNCTION(void,png_write_alloc_filter_row_buffers,
|
||||
(png_structrp png_ptr, int filters),PNG_EMPTY);
|
||||
/* Allocate pixel row buffers to cache filtered rows while testing candidate
|
||||
* filters.
|
||||
* TODO: avoid this, only one spare row buffer (at most) is required, this
|
||||
* wastes a lot of memory for large images.
|
||||
*/
|
||||
#endif
|
||||
|
||||
#if defined(PNG_FLOATING_POINT_SUPPORTED) && \
|
||||
!defined(PNG_FIXED_POINT_MACRO_SUPPORTED) && \
|
||||
(defined(PNG_gAMA_SUPPORTED) || defined(PNG_cHRM_SUPPORTED) || \
|
||||
@@ -757,6 +815,23 @@ PNG_INTERNAL_FUNCTION(int,png_user_version_check,(png_structrp png_ptr,
|
||||
PNG_INTERNAL_FUNCTION(png_voidp,png_malloc_base,(png_const_structrp png_ptr,
|
||||
png_alloc_size_t size),PNG_ALLOCATED);
|
||||
|
||||
#if defined(PNG_TEXT_SUPPORTED) || defined(PNG_sPLT_SUPPORTED) ||\
|
||||
defined(PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED)
|
||||
/* Internal array allocator, outputs no error or warning messages on failure,
|
||||
* just returns NULL.
|
||||
*/
|
||||
PNG_INTERNAL_FUNCTION(png_voidp,png_malloc_array,(png_const_structrp png_ptr,
|
||||
int nelements, size_t element_size),PNG_ALLOCATED);
|
||||
|
||||
/* The same but an existing array is extended by add_elements. This function
|
||||
* also memsets the new elements to 0 and copies the old elements. The old
|
||||
* array is not freed or altered.
|
||||
*/
|
||||
PNG_INTERNAL_FUNCTION(png_voidp,png_realloc_array,(png_structrp png_ptr,
|
||||
png_const_voidp array, int old_elements, int add_elements,
|
||||
size_t element_size),PNG_ALLOCATED);
|
||||
#endif /* text, sPLT or unknown chunks */
|
||||
|
||||
/* Magic to create a struct when there is no struct to call the user supplied
|
||||
* memory allocators. Because error handling has not been set up the memory
|
||||
* handlers can't safely call png_error, but this is an obscure and undocumented
|
||||
@@ -923,7 +998,7 @@ PNG_INTERNAL_FUNCTION(void,png_write_tEXt,(png_structrp png_ptr,
|
||||
|
||||
#ifdef PNG_WRITE_zTXt_SUPPORTED
|
||||
PNG_INTERNAL_FUNCTION(void,png_write_zTXt,(png_structrp png_ptr, png_const_charp
|
||||
key, png_const_charp text, png_size_t text_len, int compression),PNG_EMPTY);
|
||||
key, png_const_charp text, int compression),PNG_EMPTY);
|
||||
#endif
|
||||
|
||||
#ifdef PNG_WRITE_iTXt_SUPPORTED
|
||||
@@ -933,7 +1008,7 @@ PNG_INTERNAL_FUNCTION(void,png_write_iTXt,(png_structrp png_ptr,
|
||||
#endif
|
||||
|
||||
#ifdef PNG_TEXT_SUPPORTED /* Added at version 1.0.14 and 1.2.4 */
|
||||
PNG_INTERNAL_FUNCTION(int,png_set_text_2,(png_const_structrp png_ptr,
|
||||
PNG_INTERNAL_FUNCTION(int,png_set_text_2,(png_structrp png_ptr,
|
||||
png_inforp info_ptr, png_const_textp text_ptr, int num_text),PNG_EMPTY);
|
||||
#endif
|
||||
|
||||
@@ -1062,7 +1137,7 @@ PNG_INTERNAL_FUNCTION(void,png_read_finish_IDAT,(png_structrp png_ptr),
|
||||
PNG_INTERNAL_FUNCTION(void,png_read_finish_row,(png_structrp png_ptr),
|
||||
PNG_EMPTY);
|
||||
/* Finish a row while reading, dealing with interlacing passes, etc. */
|
||||
#endif
|
||||
#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
|
||||
|
||||
/* Initialize the row buffers, etc. */
|
||||
PNG_INTERNAL_FUNCTION(void,png_read_start_row,(png_structrp png_ptr),PNG_EMPTY);
|
||||
@@ -1073,32 +1148,7 @@ PNG_INTERNAL_FUNCTION(void,png_read_transform_info,(png_structrp png_ptr,
|
||||
png_inforp info_ptr),PNG_EMPTY);
|
||||
#endif
|
||||
|
||||
/* These are the functions that do the transformations */
|
||||
#ifdef PNG_READ_FILLER_SUPPORTED
|
||||
PNG_INTERNAL_FUNCTION(void,png_do_read_filler,(png_row_infop row_info,
|
||||
png_bytep row, png_uint_32 filler, png_uint_32 flags),PNG_EMPTY);
|
||||
#endif
|
||||
|
||||
#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED
|
||||
PNG_INTERNAL_FUNCTION(void,png_do_read_swap_alpha,(png_row_infop row_info,
|
||||
png_bytep row),PNG_EMPTY);
|
||||
#endif
|
||||
|
||||
#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED
|
||||
PNG_INTERNAL_FUNCTION(void,png_do_write_swap_alpha,(png_row_infop row_info,
|
||||
png_bytep row),PNG_EMPTY);
|
||||
#endif
|
||||
|
||||
#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED
|
||||
PNG_INTERNAL_FUNCTION(void,png_do_read_invert_alpha,(png_row_infop row_info,
|
||||
png_bytep row),PNG_EMPTY);
|
||||
#endif
|
||||
|
||||
#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED
|
||||
PNG_INTERNAL_FUNCTION(void,png_do_write_invert_alpha,(png_row_infop row_info,
|
||||
png_bytep row),PNG_EMPTY);
|
||||
#endif
|
||||
|
||||
/* Shared transform functions, defined in pngtran.c */
|
||||
#if defined(PNG_WRITE_FILLER_SUPPORTED) || \
|
||||
defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
|
||||
PNG_INTERNAL_FUNCTION(void,png_do_strip_channel,(png_row_infop row_info,
|
||||
@@ -1118,96 +1168,16 @@ PNG_INTERNAL_FUNCTION(void,png_do_packswap,(png_row_infop row_info,
|
||||
png_bytep row),PNG_EMPTY);
|
||||
#endif
|
||||
|
||||
#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
|
||||
PNG_INTERNAL_FUNCTION(int,png_do_rgb_to_gray,(png_structrp png_ptr,
|
||||
png_row_infop row_info, png_bytep row),PNG_EMPTY);
|
||||
#endif
|
||||
|
||||
#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
|
||||
PNG_INTERNAL_FUNCTION(void,png_do_gray_to_rgb,(png_row_infop row_info,
|
||||
png_bytep row),PNG_EMPTY);
|
||||
#endif
|
||||
|
||||
#ifdef PNG_READ_PACK_SUPPORTED
|
||||
PNG_INTERNAL_FUNCTION(void,png_do_unpack,(png_row_infop row_info,
|
||||
png_bytep row),PNG_EMPTY);
|
||||
#endif
|
||||
|
||||
#ifdef PNG_READ_SHIFT_SUPPORTED
|
||||
PNG_INTERNAL_FUNCTION(void,png_do_unshift,(png_row_infop row_info,
|
||||
png_bytep row, png_const_color_8p sig_bits),PNG_EMPTY);
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
|
||||
PNG_INTERNAL_FUNCTION(void,png_do_invert,(png_row_infop row_info,
|
||||
png_bytep row),PNG_EMPTY);
|
||||
#endif
|
||||
|
||||
#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
|
||||
PNG_INTERNAL_FUNCTION(void,png_do_scale_16_to_8,(png_row_infop row_info,
|
||||
png_bytep row),PNG_EMPTY);
|
||||
#endif
|
||||
|
||||
#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED
|
||||
PNG_INTERNAL_FUNCTION(void,png_do_chop,(png_row_infop row_info,
|
||||
png_bytep row),PNG_EMPTY);
|
||||
#endif
|
||||
|
||||
#ifdef PNG_READ_QUANTIZE_SUPPORTED
|
||||
PNG_INTERNAL_FUNCTION(void,png_do_quantize,(png_row_infop row_info,
|
||||
png_bytep row, png_const_bytep palette_lookup,
|
||||
png_const_bytep quantize_lookup),PNG_EMPTY);
|
||||
|
||||
# ifdef PNG_CORRECT_PALETTE_SUPPORTED
|
||||
PNG_INTERNAL_FUNCTION(void,png_correct_palette,(png_structrp png_ptr,
|
||||
png_colorp palette, int num_palette),PNG_EMPTY);
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
|
||||
PNG_INTERNAL_FUNCTION(void,png_do_bgr,(png_row_infop row_info,
|
||||
png_bytep row),PNG_EMPTY);
|
||||
#endif
|
||||
|
||||
#ifdef PNG_WRITE_PACK_SUPPORTED
|
||||
PNG_INTERNAL_FUNCTION(void,png_do_pack,(png_row_infop row_info,
|
||||
png_bytep row, png_uint_32 bit_depth),PNG_EMPTY);
|
||||
#endif
|
||||
|
||||
#ifdef PNG_WRITE_SHIFT_SUPPORTED
|
||||
PNG_INTERNAL_FUNCTION(void,png_do_shift,(png_row_infop row_info,
|
||||
png_bytep row, png_const_color_8p bit_depth),PNG_EMPTY);
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_BACKGROUND_SUPPORTED) ||\
|
||||
defined(PNG_READ_ALPHA_MODE_SUPPORTED)
|
||||
PNG_INTERNAL_FUNCTION(void,png_do_compose,(png_row_infop row_info,
|
||||
png_bytep row, png_structrp png_ptr),PNG_EMPTY);
|
||||
#endif
|
||||
|
||||
#ifdef PNG_READ_GAMMA_SUPPORTED
|
||||
PNG_INTERNAL_FUNCTION(void,png_do_gamma,(png_row_infop row_info,
|
||||
png_bytep row, png_structrp png_ptr),PNG_EMPTY);
|
||||
#endif
|
||||
|
||||
#ifdef PNG_READ_ALPHA_MODE_SUPPORTED
|
||||
PNG_INTERNAL_FUNCTION(void,png_do_encode_alpha,(png_row_infop row_info,
|
||||
png_bytep row, png_structrp png_ptr),PNG_EMPTY);
|
||||
#endif
|
||||
|
||||
#ifdef PNG_READ_EXPAND_SUPPORTED
|
||||
PNG_INTERNAL_FUNCTION(void,png_do_expand_palette,(png_row_infop row_info,
|
||||
png_bytep row, png_const_colorp palette, png_const_bytep trans,
|
||||
int num_trans),PNG_EMPTY);
|
||||
PNG_INTERNAL_FUNCTION(void,png_do_expand,(png_row_infop row_info,
|
||||
png_bytep row, png_const_color_16p trans_color),PNG_EMPTY);
|
||||
#endif
|
||||
|
||||
#ifdef PNG_READ_EXPAND_16_SUPPORTED
|
||||
PNG_INTERNAL_FUNCTION(void,png_do_expand_16,(png_row_infop row_info,
|
||||
png_bytep row),PNG_EMPTY);
|
||||
#endif
|
||||
|
||||
/* The following decodes the appropriate chunks, and does error correction,
|
||||
* then calls the appropriate callback for the chunk if it is valid.
|
||||
*/
|
||||
@@ -1308,7 +1278,6 @@ PNG_INTERNAL_FUNCTION(void,png_handle_zTXt,(png_structrp png_ptr,
|
||||
PNG_INTERNAL_FUNCTION(void,png_check_chunk_name,(png_structrp png_ptr,
|
||||
png_uint_32 chunk_name),PNG_EMPTY);
|
||||
|
||||
#ifdef PNG_READ_SUPPORTED
|
||||
PNG_INTERNAL_FUNCTION(void,png_handle_unknown,(png_structrp png_ptr,
|
||||
png_inforp info_ptr, png_uint_32 length, int keep),PNG_EMPTY);
|
||||
/* This is the function that gets called for unknown chunks. The 'keep'
|
||||
@@ -1317,16 +1286,14 @@ PNG_INTERNAL_FUNCTION(void,png_handle_unknown,(png_structrp png_ptr,
|
||||
* just skips the chunk or errors out if it is critical.
|
||||
*/
|
||||
|
||||
#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
|
||||
#ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED
|
||||
#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) ||\
|
||||
defined(PNG_HANDLE_AS_UNKNOWN_SUPPORTED)
|
||||
PNG_INTERNAL_FUNCTION(int,png_chunk_unknown_handling,
|
||||
(png_const_structrp png_ptr, png_uint_32 chunk_name),PNG_EMPTY);
|
||||
/* Exactly as the API png_handle_as_unknown() except that the argument is a
|
||||
* 32-bit chunk name, not a string.
|
||||
*/
|
||||
#endif
|
||||
#endif /* PNG_READ_UNKNOWN_CHUNKS_SUPPORTED */
|
||||
#endif /* PNG_READ_SUPPORTED */
|
||||
#endif /* READ_UNKNOWN_CHUNKS || HANDLE_AS_UNKNOWN */
|
||||
|
||||
/* Handle the transformations for reading and writing */
|
||||
#ifdef PNG_READ_TRANSFORMS_SUPPORTED
|
||||
@@ -1397,13 +1364,6 @@ PNG_INTERNAL_FUNCTION(void,png_push_read_iTXt,(png_structrp png_ptr,
|
||||
|
||||
#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
|
||||
|
||||
#ifdef PNG_MNG_FEATURES_SUPPORTED
|
||||
PNG_INTERNAL_FUNCTION(void,png_do_read_intrapixel,(png_row_infop row_info,
|
||||
png_bytep row),PNG_EMPTY);
|
||||
PNG_INTERNAL_FUNCTION(void,png_do_write_intrapixel,(png_row_infop row_info,
|
||||
png_bytep row),PNG_EMPTY);
|
||||
#endif
|
||||
|
||||
/* Added at libpng version 1.6.0 */
|
||||
#ifdef PNG_GAMMA_SUPPORTED
|
||||
PNG_INTERNAL_FUNCTION(void,png_colorspace_set_gamma,(png_const_structrp png_ptr,
|
||||
@@ -1745,7 +1705,7 @@ PNG_INTERNAL_FUNCTION(int,png_check_fp_string,(png_const_charp string,
|
||||
png_size_t size),PNG_EMPTY);
|
||||
#endif /* pCAL || sCAL */
|
||||
|
||||
#if defined(PNG_READ_GAMMA_SUPPORTED) ||\
|
||||
#if defined(PNG_GAMMA_SUPPORTED) ||\
|
||||
defined(PNG_INCH_CONVERSIONS_SUPPORTED) || defined(PNG_READ_pHYs_SUPPORTED)
|
||||
/* Added at libpng version 1.5.0 */
|
||||
/* This is a utility to provide a*times/div (rounded) and indicate
|
||||
@@ -1802,13 +1762,13 @@ PNG_INTERNAL_FUNCTION(png_byte,png_gamma_8bit_correct,(unsigned int value,
|
||||
png_fixed_point gamma_value),PNG_EMPTY);
|
||||
PNG_INTERNAL_FUNCTION(void,png_destroy_gamma_table,(png_structrp png_ptr),
|
||||
PNG_EMPTY);
|
||||
PNG_INTERNAL_FUNCTION(void,png_build_gamma_table,(png_structrp png_ptr,
|
||||
PNG_INTERNAL_FUNCTION(void,png_build_gamma_tables,(png_structrp png_ptr,
|
||||
int bit_depth),PNG_EMPTY);
|
||||
#endif
|
||||
|
||||
/* SIMPLIFIED READ/WRITE SUPPORT */
|
||||
#if defined PNG_SIMPLIFIED_READ_SUPPORTED ||\
|
||||
defined PNG_SIMPLIFIED_WRITE_SUPPORTED
|
||||
#if defined(PNG_SIMPLIFIED_READ_SUPPORTED) ||\
|
||||
defined(PNG_SIMPLIFIED_WRITE_SUPPORTED)
|
||||
/* The internal structure that png_image::opaque points to. */
|
||||
typedef struct png_control
|
||||
{
|
||||
@@ -1836,11 +1796,11 @@ typedef struct png_control
|
||||
* errors that might occur. Returns true on success, false on failure (either
|
||||
* of the function or as a result of a png_error.)
|
||||
*/
|
||||
PNG_INTERNAL_FUNCTION(void,png_safe_error,(png_structp png_ptr,
|
||||
PNG_INTERNAL_CALLBACK(void,png_safe_error,(png_structp png_ptr,
|
||||
png_const_charp error_message),PNG_NORETURN);
|
||||
|
||||
#ifdef PNG_WARNINGS_SUPPORTED
|
||||
PNG_INTERNAL_FUNCTION(void,png_safe_warning,(png_structp png_ptr,
|
||||
PNG_INTERNAL_CALLBACK(void,png_safe_warning,(png_structp png_ptr,
|
||||
png_const_charp warning_message),PNG_EMPTY);
|
||||
#else
|
||||
# define png_safe_warning 0/*dummy argument*/
|
||||
@@ -1862,6 +1822,24 @@ PNG_INTERNAL_FUNCTION(void, png_image_free, (png_imagep image), PNG_EMPTY);
|
||||
|
||||
#endif /* SIMPLIFIED READ/WRITE */
|
||||
|
||||
/* 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
|
||||
* the generic code is used.
|
||||
*/
|
||||
#ifdef PNG_FILTER_OPTIMIZATIONS
|
||||
PNG_INTERNAL_FUNCTION(void, PNG_FILTER_OPTIMIZATIONS, (png_structrp png_ptr,
|
||||
unsigned int bpp), PNG_EMPTY);
|
||||
/* Just declare the optimization that will be used */
|
||||
#else
|
||||
/* List *all* the possible optimizations here - this branch is required if
|
||||
* the builder of libpng passes the definition of PNG_FILTER_OPTIMIZATIONS in
|
||||
* CFLAGS in place of CPPFLAGS *and* uses symbol prefixing.
|
||||
*/
|
||||
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"
|
||||
@@ -1870,4 +1848,5 @@ PNG_INTERNAL_FUNCTION(void, png_image_free, (png_imagep image), PNG_EMPTY);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* PNG_VERSION_INFO_ONLY */
|
||||
#endif /* PNGPRIV_H */
|
||||
|
||||
8
pngrio.c
8
pngrio.c
@@ -1,8 +1,8 @@
|
||||
|
||||
/* pngrio.c - functions for data input
|
||||
*
|
||||
* Last changed in libpng 1.6.0 [(PENDING RELEASE)]
|
||||
* Copyright (c) 1998-2012 Glenn Randers-Pehrson
|
||||
* Last changed in libpng 1.6.9 [February 6, 2014]
|
||||
* Copyright (c) 1998-2014 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.)
|
||||
*
|
||||
@@ -102,6 +102,7 @@ png_set_read_fn(png_structrp png_ptr, png_voidp io_ptr,
|
||||
png_ptr->read_data_fn = read_data_fn;
|
||||
#endif
|
||||
|
||||
#ifdef PNG_WRITE_SUPPORTED
|
||||
/* It is an error to write to a read device */
|
||||
if (png_ptr->write_data_fn != NULL)
|
||||
{
|
||||
@@ -110,9 +111,10 @@ png_set_read_fn(png_structrp png_ptr, png_voidp io_ptr,
|
||||
"Can't set both read_data_fn and write_data_fn in the"
|
||||
" same structure");
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PNG_WRITE_FLUSH_SUPPORTED
|
||||
png_ptr->output_flush_fn = NULL;
|
||||
#endif
|
||||
}
|
||||
#endif /* PNG_READ_SUPPORTED */
|
||||
#endif /* READ */
|
||||
|
||||
2141
pngrtran.c
2141
pngrtran.c
File diff suppressed because it is too large
Load Diff
392
pngrutil.c
392
pngrutil.c
@@ -1,8 +1,8 @@
|
||||
|
||||
/* pngrutil.c - utilities to read a PNG file
|
||||
*
|
||||
* Last changed in libpng 1.6.0 [(PENDING RELEASE)]
|
||||
* Copyright (c) 1998-2012 Glenn Randers-Pehrson
|
||||
* Last changed in libpng 1.7.0 [(PENDING RELEASE)]
|
||||
* Copyright (c) 1998-2014 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.)
|
||||
*
|
||||
@@ -18,19 +18,6 @@
|
||||
|
||||
#ifdef PNG_READ_SUPPORTED
|
||||
|
||||
#define png_strtod(p,a,b) strtod(a,b)
|
||||
|
||||
png_uint_32 PNGAPI
|
||||
png_get_uint_31(png_const_structrp png_ptr, png_const_bytep buf)
|
||||
{
|
||||
png_uint_32 uval = png_get_uint_32(buf);
|
||||
|
||||
if (uval > PNG_UINT_31_MAX)
|
||||
png_error(png_ptr, "PNG unsigned integer out of range");
|
||||
|
||||
return (uval);
|
||||
}
|
||||
|
||||
#if defined(PNG_READ_gAMA_SUPPORTED) || defined(PNG_READ_cHRM_SUPPORTED)
|
||||
/* The following is a variation on the above for use with the fixed
|
||||
* point values used for gAMA and cHRM. Instead of png_error it
|
||||
@@ -53,7 +40,7 @@ png_get_fixed_point(png_structrp png_ptr, png_const_bytep buf)
|
||||
|
||||
return PNG_FIXED_ERROR;
|
||||
}
|
||||
#endif
|
||||
#endif /* READ_gAMA or READ_cHRM */
|
||||
|
||||
#ifdef PNG_READ_INT_FUNCTIONS_SUPPORTED
|
||||
/* NOTE: the read macros will obscure these definitions, so that if
|
||||
@@ -69,13 +56,7 @@ png_get_fixed_point(png_structrp png_ptr, png_const_bytep buf)
|
||||
png_uint_32 (PNGAPI
|
||||
png_get_uint_32)(png_const_bytep buf)
|
||||
{
|
||||
png_uint_32 uval =
|
||||
((png_uint_32)(*(buf )) << 24) +
|
||||
((png_uint_32)(*(buf + 1)) << 16) +
|
||||
((png_uint_32)(*(buf + 2)) << 8) +
|
||||
((png_uint_32)(*(buf + 3)) ) ;
|
||||
|
||||
return uval;
|
||||
return PNG_U32(buf[0], buf[1], buf[2], buf[3]);
|
||||
}
|
||||
|
||||
/* Grab a signed 32-bit integer from a buffer in big-endian format. The
|
||||
@@ -86,31 +67,31 @@ png_get_uint_32)(png_const_bytep buf)
|
||||
png_int_32 (PNGAPI
|
||||
png_get_int_32)(png_const_bytep buf)
|
||||
{
|
||||
png_uint_32 uval = png_get_uint_32(buf);
|
||||
if ((uval & 0x80000000) == 0) /* non-negative */
|
||||
return uval;
|
||||
|
||||
uval = (uval ^ 0xffffffff) + 1; /* 2's complement: -x = ~x+1 */
|
||||
return -(png_int_32)uval;
|
||||
return PNG_S32(buf[0], buf[1], buf[2], buf[3]);
|
||||
}
|
||||
|
||||
/* Grab an unsigned 16-bit integer from a buffer in big-endian format. */
|
||||
png_uint_16 (PNGAPI
|
||||
png_get_uint_16)(png_const_bytep buf)
|
||||
{
|
||||
/* ANSI-C requires an int value to accomodate at least 16 bits so this
|
||||
* works and allows the compiler not to worry about possible narrowing
|
||||
* on 32 bit systems. (Pre-ANSI systems did not make integers smaller
|
||||
* than 16 bits either.)
|
||||
*/
|
||||
unsigned int val =
|
||||
((unsigned int)(*buf) << 8) +
|
||||
((unsigned int)(*(buf + 1)));
|
||||
|
||||
return (png_uint_16)val;
|
||||
return PNG_U16(buf[0], buf[1]);
|
||||
}
|
||||
#endif /* READ_INT_FUNCTIONS */
|
||||
|
||||
#endif /* PNG_READ_INT_FUNCTIONS_SUPPORTED */
|
||||
/* This is an exported function however its error handling is too harsh for most
|
||||
* internal use. For example if it were used for reading the chunk parameters
|
||||
* it would error out even on ancillary chunks that can be ignored.
|
||||
*/
|
||||
png_uint_32 PNGAPI
|
||||
png_get_uint_31(png_const_structrp png_ptr, png_const_bytep buf)
|
||||
{
|
||||
png_uint_32 uval = png_get_uint_32(buf);
|
||||
|
||||
if (uval > PNG_UINT_31_MAX)
|
||||
png_error(png_ptr, "PNG unsigned integer out of range");
|
||||
|
||||
return uval;
|
||||
}
|
||||
|
||||
/* Read and check the PNG file signature */
|
||||
void /* PRIVATE */
|
||||
@@ -221,18 +202,15 @@ png_crc_finish(png_structrp png_ptr, png_uint_32 skip)
|
||||
|
||||
if (png_crc_error(png_ptr))
|
||||
{
|
||||
if (PNG_CHUNK_ANCILLIARY(png_ptr->chunk_name) ?
|
||||
!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN) :
|
||||
(png_ptr->flags & PNG_FLAG_CRC_CRITICAL_USE))
|
||||
if (PNG_CHUNK_ANCILLARY(png_ptr->chunk_name) ?
|
||||
(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN) == 0:
|
||||
(png_ptr->flags & PNG_FLAG_CRC_CRITICAL_USE) != 0)
|
||||
{
|
||||
png_chunk_warning(png_ptr, "CRC error");
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
png_chunk_benign_error(png_ptr, "CRC error");
|
||||
return (0);
|
||||
}
|
||||
png_chunk_error(png_ptr, "CRC error");
|
||||
|
||||
return (1);
|
||||
}
|
||||
@@ -250,7 +228,7 @@ png_crc_error(png_structrp png_ptr)
|
||||
png_uint_32 crc;
|
||||
int need_crc = 1;
|
||||
|
||||
if (PNG_CHUNK_ANCILLIARY(png_ptr->chunk_name))
|
||||
if (PNG_CHUNK_ANCILLARY(png_ptr->chunk_name))
|
||||
{
|
||||
if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
|
||||
(PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
|
||||
@@ -270,7 +248,7 @@ png_crc_error(png_structrp png_ptr)
|
||||
/* The chunk CRC must be serialized in a single I/O call. */
|
||||
png_read_data(png_ptr, crc_bytes, 4);
|
||||
|
||||
if (need_crc)
|
||||
if (need_crc != 0)
|
||||
{
|
||||
crc = png_get_uint_32(crc_bytes);
|
||||
return ((int)(crc != png_ptr->crc));
|
||||
@@ -280,6 +258,10 @@ png_crc_error(png_structrp png_ptr)
|
||||
return (0);
|
||||
}
|
||||
|
||||
#if defined(PNG_READ_iCCP_SUPPORTED) || defined(PNG_READ_iTXt_SUPPORTED) ||\
|
||||
defined(PNG_READ_pCAL_SUPPORTED) || defined(PNG_READ_sCAL_SUPPORTED) ||\
|
||||
defined(PNG_READ_sPLT_SUPPORTED) || defined(PNG_READ_tEXt_SUPPORTED) ||\
|
||||
defined(PNG_READ_zTXt_SUPPORTED) || defined(PNG_SEQUENTIAL_READ_SUPPORTED)
|
||||
/* Manage the read buffer; this simply reallocates the buffer if it is not small
|
||||
* enough (or if it is not allocated). The routine returns a pointer to the
|
||||
* buffer; if an error occurs and 'warn' is set the routine returns NULL, else
|
||||
@@ -312,21 +294,17 @@ png_read_buffer(png_structrp png_ptr, png_alloc_size_t new_size, int warn)
|
||||
|
||||
else if (warn < 2) /* else silent */
|
||||
{
|
||||
#ifdef PNG_WARNINGS_SUPPORTED
|
||||
if (warn)
|
||||
if (warn != 0)
|
||||
png_chunk_warning(png_ptr, "insufficient memory to read chunk");
|
||||
|
||||
else
|
||||
#endif
|
||||
{
|
||||
#ifdef PNG_ERROR_TEXT_SUPPORTED
|
||||
png_chunk_error(png_ptr, "insufficient memory to read chunk");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
#endif /* READ_iCCP|iTXt|pCAL|sCAL|sPLT|tEXt|zTXt|SEQUENTIAL_READ */
|
||||
|
||||
/* png_inflate_claim: claim the zstream for some nefarious purpose that involves
|
||||
* decompression. Returns Z_OK on success, else a zlib error code. It checks
|
||||
@@ -334,7 +312,7 @@ png_read_buffer(png_structrp png_ptr, png_alloc_size_t new_size, int warn)
|
||||
* chunk apparently owns the stream. Prior to release it does a png_error.
|
||||
*/
|
||||
static int
|
||||
png_inflate_claim(png_structrp png_ptr, png_uint_32 owner, int window_bits)
|
||||
png_inflate_claim(png_structrp png_ptr, png_uint_32 owner)
|
||||
{
|
||||
if (png_ptr->zowner != 0)
|
||||
{
|
||||
@@ -358,8 +336,8 @@ png_inflate_claim(png_structrp png_ptr, png_uint_32 owner, int window_bits)
|
||||
* does not take the size of the data as an argument. Some efficiency could
|
||||
* be gained by using this when it is known *if* the zlib stream itself does
|
||||
* not record the number; however, this is an illusion: the original writer
|
||||
* follow of the PNG may have selected a lower window size, and we really
|
||||
* must do that because, for systems with with limited capabilities, we
|
||||
* of the PNG may have selected a lower window size, and we really must
|
||||
* follow that because, for systems with with limited capabilities, we
|
||||
* would otherwise reject the application's attempts to use a smaller window
|
||||
* size (zlib doesn't have an interface to say "this or lower"!).
|
||||
*
|
||||
@@ -369,6 +347,22 @@ png_inflate_claim(png_structrp png_ptr, png_uint_32 owner, int window_bits)
|
||||
*/
|
||||
{
|
||||
int ret; /* zlib return code */
|
||||
# if PNG_ZLIB_VERNUM >= 0x1240
|
||||
|
||||
# if defined(PNG_SET_OPTION_SUPPORTED) && \
|
||||
defined(PNG_MAXIMUM_INFLATE_WINDOW)
|
||||
int window_bits;
|
||||
|
||||
if (((png_ptr->options >> PNG_MAXIMUM_INFLATE_WINDOW) & 3) ==
|
||||
PNG_OPTION_ON)
|
||||
window_bits = 15;
|
||||
|
||||
else
|
||||
window_bits = 0;
|
||||
# else
|
||||
# define window_bits 0
|
||||
# endif
|
||||
# endif
|
||||
|
||||
/* Set this for safety, just in case the previous owner left pointers to
|
||||
* memory allocations.
|
||||
@@ -380,8 +374,7 @@ png_inflate_claim(png_structrp png_ptr, png_uint_32 owner, int window_bits)
|
||||
|
||||
if (png_ptr->flags & PNG_FLAG_ZSTREAM_INITIALIZED)
|
||||
{
|
||||
# if ZLIB_VERNUM < 0x1240
|
||||
PNG_UNUSED(window_bits)
|
||||
# if PNG_ZLIB_VERNUM < 0x1240
|
||||
ret = inflateReset(&png_ptr->zstream);
|
||||
# else
|
||||
ret = inflateReset2(&png_ptr->zstream, window_bits);
|
||||
@@ -390,7 +383,7 @@ png_inflate_claim(png_structrp png_ptr, png_uint_32 owner, int window_bits)
|
||||
|
||||
else
|
||||
{
|
||||
# if ZLIB_VERNUM < 0x1240
|
||||
# if PNG_ZLIB_VERNUM < 0x1240
|
||||
ret = inflateInit(&png_ptr->zstream);
|
||||
# else
|
||||
ret = inflateInit2(&png_ptr->zstream, window_bits);
|
||||
@@ -408,6 +401,10 @@ png_inflate_claim(png_structrp png_ptr, png_uint_32 owner, int window_bits)
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
# ifdef window_bits
|
||||
# undef window_bits
|
||||
# endif
|
||||
}
|
||||
|
||||
#ifdef PNG_READ_COMPRESSED_TEXT_SUPPORTED
|
||||
@@ -504,7 +501,7 @@ png_inflate(png_structrp png_ptr, png_uint_32 owner, int finish,
|
||||
* end of the output buffer.
|
||||
*/
|
||||
ret = inflate(&png_ptr->zstream, avail_out > 0 ? Z_NO_FLUSH :
|
||||
(finish ? Z_FINISH : Z_SYNC_FLUSH));
|
||||
(finish ? Z_FINISH : Z_SYNC_FLUSH));
|
||||
} while (ret == Z_OK);
|
||||
|
||||
/* For safety kill the local buffer pointer now */
|
||||
@@ -562,7 +559,7 @@ png_decompress_chunk(png_structrp png_ptr,
|
||||
*/
|
||||
png_alloc_size_t limit = PNG_SIZE_MAX;
|
||||
|
||||
# ifdef PNG_SET_CHUNK_MALLOC_LIMIT_SUPPORTED
|
||||
# ifdef PNG_SET_USER_LIMITS_SUPPORTED
|
||||
if (png_ptr->user_chunk_malloc_max > 0 &&
|
||||
png_ptr->user_chunk_malloc_max < limit)
|
||||
limit = png_ptr->user_chunk_malloc_max;
|
||||
@@ -580,14 +577,8 @@ png_decompress_chunk(png_structrp png_ptr,
|
||||
if (limit < *newlength)
|
||||
*newlength = limit;
|
||||
|
||||
/* Now try to claim the stream; the 'warn' setting causes zlib to be told
|
||||
* to use the maximum window size during inflate; this hides errors in the
|
||||
* deflate header window bits value which is used if '0' is passed. In
|
||||
* fact this only has an effect with zlib versions 1.2.4 and later - see
|
||||
* the comments in png_inflate_claim above.
|
||||
*/
|
||||
ret = png_inflate_claim(png_ptr, png_ptr->chunk_name,
|
||||
png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN ? 15 : 0);
|
||||
/* Now try to claim the stream. */
|
||||
ret = png_inflate_claim(png_ptr, png_ptr->chunk_name);
|
||||
|
||||
if (ret == Z_OK)
|
||||
{
|
||||
@@ -629,7 +620,7 @@ png_decompress_chunk(png_structrp png_ptr,
|
||||
{
|
||||
if (new_size == *newlength)
|
||||
{
|
||||
if (terminate)
|
||||
if (terminate != 0)
|
||||
text[prefix_size + *newlength] = 0;
|
||||
|
||||
if (prefix_size > 0)
|
||||
@@ -710,7 +701,7 @@ png_decompress_chunk(png_structrp png_ptr,
|
||||
return Z_MEM_ERROR;
|
||||
}
|
||||
}
|
||||
#endif /* PNG_READ_COMPRESSED_TEXT_SUPPORTED */
|
||||
#endif /* READ_COMPRESSED_TEXT */
|
||||
|
||||
#ifdef PNG_READ_iCCP_SUPPORTED
|
||||
/* Perform a partial read and decompress, producing 'avail_out' bytes and
|
||||
@@ -970,15 +961,10 @@ png_handle_PLTE(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
||||
if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_USE))
|
||||
{
|
||||
if (png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)
|
||||
{
|
||||
png_chunk_benign_error(png_ptr, "CRC error");
|
||||
}
|
||||
return;
|
||||
|
||||
else
|
||||
{
|
||||
png_chunk_warning(png_ptr, "CRC error");
|
||||
return;
|
||||
}
|
||||
png_chunk_error(png_ptr, "CRC error");
|
||||
}
|
||||
|
||||
/* Otherwise, we (optionally) emit a warning and use the chunk. */
|
||||
@@ -1010,7 +996,7 @@ png_handle_PLTE(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
||||
*/
|
||||
#ifdef PNG_READ_tRNS_SUPPORTED
|
||||
if (png_ptr->num_trans > 0 ||
|
||||
(info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS) != 0))
|
||||
(info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS) != 0))
|
||||
{
|
||||
/* Cancel this because otherwise it would be used if the transforms
|
||||
* require it. Don't cancel the 'valid' flag because this would prevent
|
||||
@@ -1096,13 +1082,12 @@ png_handle_gAMA(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
||||
void /* PRIVATE */
|
||||
png_handle_sBIT(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
||||
{
|
||||
unsigned int truelen;
|
||||
unsigned int truelen, i;
|
||||
png_byte sample_depth;
|
||||
png_byte buf[4];
|
||||
|
||||
png_debug(1, "in png_handle_sBIT");
|
||||
|
||||
buf[0] = buf[1] = buf[2] = buf[3] = 0;
|
||||
|
||||
if (!(png_ptr->mode & PNG_HAVE_IHDR))
|
||||
png_chunk_error(png_ptr, "missing IHDR");
|
||||
|
||||
@@ -1121,10 +1106,16 @@ png_handle_sBIT(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
||||
}
|
||||
|
||||
if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
|
||||
{
|
||||
truelen = 3;
|
||||
sample_depth = 8;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
truelen = png_ptr->channels;
|
||||
sample_depth = png_ptr->bit_depth;
|
||||
}
|
||||
|
||||
if (length != truelen || length > 4)
|
||||
{
|
||||
@@ -1133,11 +1124,19 @@ png_handle_sBIT(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
||||
return;
|
||||
}
|
||||
|
||||
buf[0] = buf[1] = buf[2] = buf[3] = sample_depth;
|
||||
png_crc_read(png_ptr, buf, truelen);
|
||||
|
||||
if (png_crc_finish(png_ptr, 0))
|
||||
return;
|
||||
|
||||
for (i=0; i<truelen; ++i)
|
||||
if (buf[i] == 0 || buf[i] > sample_depth)
|
||||
{
|
||||
png_chunk_benign_error(png_ptr, "invalid");
|
||||
return;
|
||||
}
|
||||
|
||||
if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
|
||||
{
|
||||
png_ptr->sig_bit.red = buf[0];
|
||||
@@ -1279,7 +1278,7 @@ png_handle_sRGB(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
||||
(void)png_colorspace_set_sRGB(png_ptr, &png_ptr->colorspace, intent);
|
||||
png_colorspace_sync(png_ptr, info_ptr);
|
||||
}
|
||||
#endif /* PNG_READ_sRGB_SUPPORTED */
|
||||
#endif /* READ_sRGB */
|
||||
|
||||
#ifdef PNG_READ_iCCP_SUPPORTED
|
||||
void /* PRIVATE */
|
||||
@@ -1305,9 +1304,9 @@ png_handle_iCCP(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
||||
* chunk is just ignored, so does not invalidate the color space. An
|
||||
* alternative is to set the 'invalid' flags at the start of this routine
|
||||
* and only clear them in they were not set before and all the tests pass.
|
||||
* The minimum 'deflate' stream is assumed to be just the 2 byte header and 4
|
||||
* byte checksum. The keyword must be one character and there is a
|
||||
* terminator (0) byte and the compression method.
|
||||
* The minimum 'deflate' stream is assumed to be just the 2 byte header and
|
||||
* 4 byte checksum. The keyword must be at least one character and there is
|
||||
* a terminator (0) byte and the compression method.
|
||||
*/
|
||||
if (length < 9)
|
||||
{
|
||||
@@ -1357,8 +1356,7 @@ png_handle_iCCP(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
||||
{
|
||||
read_length -= keyword_length+2;
|
||||
|
||||
if (png_inflate_claim(png_ptr, png_iCCP,
|
||||
png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN ? 15 : 0) == Z_OK)
|
||||
if (png_inflate_claim(png_ptr, png_iCCP) == Z_OK)
|
||||
{
|
||||
Byte profile_header[132];
|
||||
Byte local_buffer[PNG_INFLATE_BUF_SIZE];
|
||||
@@ -1408,7 +1406,7 @@ png_handle_iCCP(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
||||
(sizeof local_buffer), &length,
|
||||
profile + (sizeof profile_header), &size, 0);
|
||||
|
||||
/* Still expect a a buffer error because we expect
|
||||
/* Still expect a buffer error because we expect
|
||||
* there to be some tag data!
|
||||
*/
|
||||
if (size == 0)
|
||||
@@ -1545,7 +1543,7 @@ png_handle_iCCP(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
||||
errmsg = "too many profiles";
|
||||
|
||||
/* Failure: the reason is in 'errmsg' */
|
||||
if (!finished)
|
||||
if (finished == 0)
|
||||
png_crc_finish(png_ptr, length);
|
||||
|
||||
png_ptr->colorspace.flags |= PNG_COLORSPACE_INVALID;
|
||||
@@ -1553,7 +1551,7 @@ png_handle_iCCP(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
||||
if (errmsg != NULL) /* else already output */
|
||||
png_chunk_benign_error(png_ptr, errmsg);
|
||||
}
|
||||
#endif /* PNG_READ_iCCP_SUPPORTED */
|
||||
#endif /* READ_iCCP */
|
||||
|
||||
#ifdef PNG_READ_sPLT_SUPPORTED
|
||||
void /* PRIVATE */
|
||||
@@ -1582,7 +1580,8 @@ png_handle_sPLT(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
||||
|
||||
if (--png_ptr->user_chunk_cache_max == 1)
|
||||
{
|
||||
png_warning(png_ptr, "No space in chunk cache for sPLT");
|
||||
/* Warn the first time */
|
||||
png_chunk_benign_error(png_ptr, "no space in chunk cache");
|
||||
png_crc_finish(png_ptr, length);
|
||||
return;
|
||||
}
|
||||
@@ -1659,8 +1658,8 @@ png_handle_sPLT(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
||||
|
||||
if (dl > max_dl)
|
||||
{
|
||||
png_warning(png_ptr, "sPLT chunk too long");
|
||||
return;
|
||||
png_warning(png_ptr, "sPLT chunk too long");
|
||||
return;
|
||||
}
|
||||
|
||||
new_palette.nentries = (png_int_32)(data_length / entry_size);
|
||||
@@ -1670,8 +1669,8 @@ png_handle_sPLT(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
||||
|
||||
if (new_palette.entries == NULL)
|
||||
{
|
||||
png_warning(png_ptr, "sPLT chunk requires too much memory");
|
||||
return;
|
||||
png_warning(png_ptr, "sPLT chunk requires too much memory");
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef PNG_POINTER_INDEXING_SUPPORTED
|
||||
@@ -1730,7 +1729,7 @@ png_handle_sPLT(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
||||
|
||||
png_free(png_ptr, new_palette.entries);
|
||||
}
|
||||
#endif /* PNG_READ_sPLT_SUPPORTED */
|
||||
#endif /* READ_sPLT */
|
||||
|
||||
#ifdef PNG_READ_tRNS_SUPPORTED
|
||||
void /* PRIVATE */
|
||||
@@ -1832,6 +1831,8 @@ png_handle_tRNS(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
||||
*/
|
||||
png_set_tRNS(png_ptr, info_ptr, readbuf, png_ptr->num_trans,
|
||||
&(png_ptr->trans_color));
|
||||
|
||||
png_ptr->trans_alpha = info_ptr->trans_alpha;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -2627,7 +2628,7 @@ png_handle_iTXt(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
||||
/* prefix_length should now be at the trailing '\0' of the translated
|
||||
* keyword, but it may already be over the end. None of this arithmetic
|
||||
* can overflow because chunks are at most 2^31 bytes long, but on 16-bit
|
||||
* systems the available allocaton may overflow.
|
||||
* systems the available allocation may overflow.
|
||||
*/
|
||||
++prefix_length;
|
||||
|
||||
@@ -2659,7 +2660,7 @@ png_handle_iTXt(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
||||
|
||||
buffer[uncompressed_length+prefix_length] = 0;
|
||||
|
||||
if (compressed)
|
||||
if (compressed == 0)
|
||||
text.compression = PNG_ITXT_COMPRESSION_NONE;
|
||||
|
||||
else
|
||||
@@ -2698,7 +2699,7 @@ png_cache_unknown_chunk(png_structrp png_ptr, png_uint_32 length)
|
||||
png_ptr->unknown_chunk.data = NULL;
|
||||
}
|
||||
|
||||
# ifdef PNG_SET_CHUNK_MALLOC_LIMIT_SUPPORTED
|
||||
# ifdef PNG_SET_USER_LIMITS_SUPPORTED
|
||||
if (png_ptr->user_chunk_malloc_max > 0 &&
|
||||
png_ptr->user_chunk_malloc_max < limit)
|
||||
limit = png_ptr->user_chunk_malloc_max;
|
||||
@@ -2743,7 +2744,7 @@ png_cache_unknown_chunk(png_structrp png_ptr, png_uint_32 length)
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
#endif /* PNG_READ_UNKNOWN_CHUNKS_SUPPORTED */
|
||||
#endif /* READ_UNKNOWN_CHUNKS */
|
||||
|
||||
/* Handle an unknown, or known but disabled, chunk */
|
||||
void /* PRIVATE */
|
||||
@@ -2802,26 +2803,16 @@ png_handle_unknown(png_structrp png_ptr, png_inforp info_ptr,
|
||||
|
||||
else if (ret == 0)
|
||||
{
|
||||
/* If the keep value is 'default' or 'never' override it, but
|
||||
* still error out on critical chunks unless the keep value is
|
||||
* 'always' While this is weird it is the behavior in 1.4.12. A
|
||||
* possible improvement would be to obey the value set for the
|
||||
* chunk, but this would be an API change that would probably
|
||||
* damage some applications.
|
||||
/* Use the default handling, note that if there is per-chunk
|
||||
* handling specified it has already been set into 'keep'.
|
||||
*
|
||||
* The png_app_warning below catches the case that matters, where
|
||||
* the application has neither set specific save for this chunk
|
||||
* or global save.
|
||||
* NOTE: this is an API change in 1.7.0. Prior to 1.7.0 libpng
|
||||
* would force keep to PNG_HANDLE_CHUNK_IF_SAFE at this point,
|
||||
* and 1.6.0 would issue a warning if this caused a default of
|
||||
* discarding the chunk to be changed.
|
||||
*/
|
||||
if (keep < PNG_HANDLE_CHUNK_IF_SAFE)
|
||||
{
|
||||
# ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED
|
||||
if (png_ptr->unknown_default < PNG_HANDLE_CHUNK_IF_SAFE)
|
||||
png_app_warning(png_ptr,
|
||||
"forcing save of an unhandled chunk; please call png_set_keep_unknown_chunks");
|
||||
# endif
|
||||
keep = PNG_HANDLE_CHUNK_IF_SAFE;
|
||||
}
|
||||
if (keep == PNG_HANDLE_CHUNK_AS_DEFAULT)
|
||||
keep = png_ptr->unknown_default;
|
||||
}
|
||||
|
||||
else /* chunk was handled */
|
||||
@@ -2852,7 +2843,7 @@ png_handle_unknown(png_structrp png_ptr, png_inforp info_ptr,
|
||||
|
||||
if (keep == PNG_HANDLE_CHUNK_ALWAYS ||
|
||||
(keep == PNG_HANDLE_CHUNK_IF_SAFE &&
|
||||
PNG_CHUNK_ANCILLIARY(png_ptr->chunk_name)))
|
||||
PNG_CHUNK_ANCILLARY(png_ptr->chunk_name)))
|
||||
{
|
||||
if (!png_cache_unknown_chunk(png_ptr, length))
|
||||
keep = PNG_HANDLE_CHUNK_NEVER;
|
||||
@@ -2886,7 +2877,7 @@ png_handle_unknown(png_structrp png_ptr, png_inforp info_ptr,
|
||||
*/
|
||||
if (keep == PNG_HANDLE_CHUNK_ALWAYS ||
|
||||
(keep == PNG_HANDLE_CHUNK_IF_SAFE &&
|
||||
PNG_CHUNK_ANCILLIARY(png_ptr->chunk_name)))
|
||||
PNG_CHUNK_ANCILLARY(png_ptr->chunk_name)))
|
||||
{
|
||||
# ifdef PNG_USER_LIMITS_SUPPORTED
|
||||
switch (png_ptr->user_chunk_cache_max)
|
||||
@@ -2917,9 +2908,8 @@ png_handle_unknown(png_structrp png_ptr, png_inforp info_ptr,
|
||||
}
|
||||
# endif
|
||||
}
|
||||
# else /* no store support! */
|
||||
# else /* no store support: the chunk must be handled by the user callback */
|
||||
PNG_UNUSED(info_ptr)
|
||||
# error untested code (reading unknown chunks with no store support)
|
||||
# endif
|
||||
|
||||
/* Regardless of the error handling below the cached data (if any) can be
|
||||
@@ -2930,12 +2920,12 @@ png_handle_unknown(png_structrp png_ptr, png_inforp info_ptr,
|
||||
png_free(png_ptr, png_ptr->unknown_chunk.data);
|
||||
png_ptr->unknown_chunk.data = NULL;
|
||||
|
||||
#else /* !PNG_READ_UNKNOWN_CHUNKS_SUPPORTED */
|
||||
#else /* !READ_UNKNOWN_CHUNKS */
|
||||
/* There is no support to read an unknown chunk, so just skip it. */
|
||||
png_crc_finish(png_ptr, length);
|
||||
PNG_UNUSED(info_ptr)
|
||||
PNG_UNUSED(keep)
|
||||
#endif /* !PNG_READ_UNKNOWN_CHUNKS_SUPPORTED */
|
||||
#endif /* !READ_UNKNOWN_CHUNKS */
|
||||
|
||||
/* Check for unhandled critical chunks */
|
||||
if (!handled && PNG_CHUNK_CRITICAL(png_ptr->chunk_name))
|
||||
@@ -3136,7 +3126,7 @@ png_combine_row(png_const_structrp png_ptr, png_bytep dp, int display)
|
||||
# define S_MASKS(d,s) { S_MASK(0,d,s), S_MASK(1,d,s), S_MASK(2,d,s),\
|
||||
S_MASK(3,d,s), S_MASK(4,d,s), S_MASK(5,d,s) }
|
||||
|
||||
# define B_MASKS(d,s) { B_MASK(1,d,s), S_MASK(3,d,s), S_MASK(5,d,s) }
|
||||
# define B_MASKS(d,s) { B_MASK(1,d,s), B_MASK(3,d,s), B_MASK(5,d,s) }
|
||||
|
||||
# define DEPTH_INDEX(d) ((d)==1?0:((d)==2?1:2))
|
||||
|
||||
@@ -3166,16 +3156,16 @@ png_combine_row(png_const_structrp png_ptr, png_bytep dp, int display)
|
||||
((display)?display_mask[png][DEPTH_INDEX(depth)][pass>>1]:\
|
||||
row_mask[png][DEPTH_INDEX(depth)][pass])
|
||||
|
||||
#else /* !PNG_USE_COMPILE_TIME_MASKS */
|
||||
#else /* !USE_COMPILE_TIME_MASKS */
|
||||
/* This is the runtime alternative: it seems unlikely that this will
|
||||
* ever be either smaller or faster than the compile time approach.
|
||||
*/
|
||||
# define MASK(pass,depth,display,png)\
|
||||
((display)?B_MASK(pass,depth,png):S_MASK(pass,depth,png))
|
||||
#endif /* !PNG_USE_COMPILE_TIME_MASKS */
|
||||
#endif /* !USE_COMPILE_TIME_MASKS */
|
||||
|
||||
/* Use the appropriate mask to copy the required bits. In some cases
|
||||
* the byte mask will be 0 or 0xff, optimize these cases. row_width is
|
||||
* the byte mask will be 0 or 0xff; optimize these cases. row_width is
|
||||
* the number of pixels, but the code copies bytes, so it is necessary
|
||||
* to special case the end.
|
||||
*/
|
||||
@@ -3247,7 +3237,7 @@ png_combine_row(png_const_structrp png_ptr, png_bytep dp, int display)
|
||||
}
|
||||
|
||||
/* Work out the bytes to copy. */
|
||||
if (display)
|
||||
if (display != 0)
|
||||
{
|
||||
/* When doing the 'block' algorithm the pixel in the pass gets
|
||||
* replicated to adjacent pixels. This is why the even (0,2,4,6)
|
||||
@@ -3314,7 +3304,7 @@ png_combine_row(png_const_structrp png_ptr, png_bytep dp, int display)
|
||||
/* This can only be the RGB case, so each copy is exactly one
|
||||
* pixel and it is not necessary to check for a partial copy.
|
||||
*/
|
||||
for(;;)
|
||||
for (;;)
|
||||
{
|
||||
dp[0] = sp[0], dp[1] = sp[1], dp[2] = sp[2];
|
||||
|
||||
@@ -3350,7 +3340,7 @@ png_combine_row(png_const_structrp png_ptr, png_bytep dp, int display)
|
||||
png_uint_32p dp32 = png_aligncast(png_uint_32p,dp);
|
||||
png_const_uint_32p sp32 = png_aligncastconst(
|
||||
png_const_uint_32p, sp);
|
||||
unsigned int skip = (bytes_to_jump-bytes_to_copy) /
|
||||
size_t skip = (bytes_to_jump-bytes_to_copy) /
|
||||
(sizeof (png_uint_32));
|
||||
|
||||
do
|
||||
@@ -3392,7 +3382,7 @@ png_combine_row(png_const_structrp png_ptr, png_bytep dp, int display)
|
||||
png_uint_16p dp16 = png_aligncast(png_uint_16p, dp);
|
||||
png_const_uint_16p sp16 = png_aligncastconst(
|
||||
png_const_uint_16p, sp);
|
||||
unsigned int skip = (bytes_to_jump-bytes_to_copy) /
|
||||
size_t skip = (bytes_to_jump-bytes_to_copy) /
|
||||
(sizeof (png_uint_16));
|
||||
|
||||
do
|
||||
@@ -3423,7 +3413,7 @@ png_combine_row(png_const_structrp png_ptr, png_bytep dp, int display)
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endif /* PNG_ALIGN_ code */
|
||||
#endif /* ALIGN_ code */
|
||||
|
||||
/* The true default - use a memcpy: */
|
||||
for (;;)
|
||||
@@ -3679,7 +3669,7 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
|
||||
|
||||
for (i = 0; i < row_info->width; i++)
|
||||
{
|
||||
png_byte v[8];
|
||||
png_byte v[8]; /* SAFE; pixel_depth does not exceed 64 */
|
||||
int j;
|
||||
|
||||
memcpy(v, sp, pixel_bytes);
|
||||
@@ -3703,7 +3693,7 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
|
||||
PNG_UNUSED(transformations) /* Silence compiler warning */
|
||||
#endif
|
||||
}
|
||||
#endif /* PNG_READ_INTERLACING_SUPPORTED */
|
||||
#endif /* READ_INTERLACING */
|
||||
|
||||
static void
|
||||
png_read_filter_row_sub(png_row_infop row_info, png_bytep row,
|
||||
@@ -3857,74 +3847,22 @@ png_read_filter_row_paeth_multibyte_pixel(png_row_infop row_info, png_bytep row,
|
||||
if (pb < pa) pa = pb, a = b;
|
||||
if (pc < pa) a = c;
|
||||
|
||||
c = b;
|
||||
a += *row;
|
||||
*row++ = (png_byte)a;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef PNG_ARM_NEON
|
||||
|
||||
#ifdef __linux__
|
||||
#include <stdio.h>
|
||||
#include <elf.h>
|
||||
#include <asm/hwcap.h>
|
||||
|
||||
static int png_have_hwcap(unsigned cap)
|
||||
{
|
||||
FILE *f = fopen("/proc/self/auxv", "r");
|
||||
Elf32_auxv_t aux;
|
||||
int have_cap = 0;
|
||||
|
||||
if (!f)
|
||||
return 0;
|
||||
|
||||
while (fread(&aux, (sizeof aux), 1, f) > 0)
|
||||
{
|
||||
if (aux.a_type == AT_HWCAP &&
|
||||
aux.a_un.a_val & cap)
|
||||
{
|
||||
have_cap = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
|
||||
return have_cap;
|
||||
}
|
||||
#endif /* __linux__ */
|
||||
|
||||
static void
|
||||
png_init_filter_functions_neon(png_structrp pp, unsigned int bpp)
|
||||
{
|
||||
#ifdef __linux__
|
||||
if (!png_have_hwcap(HWCAP_NEON))
|
||||
return;
|
||||
#endif
|
||||
|
||||
pp->read_filter[PNG_FILTER_VALUE_UP-1] = png_read_filter_row_up_neon;
|
||||
|
||||
if (bpp == 3)
|
||||
{
|
||||
pp->read_filter[PNG_FILTER_VALUE_SUB-1] = png_read_filter_row_sub3_neon;
|
||||
pp->read_filter[PNG_FILTER_VALUE_AVG-1] = png_read_filter_row_avg3_neon;
|
||||
pp->read_filter[PNG_FILTER_VALUE_PAETH-1] =
|
||||
png_read_filter_row_paeth3_neon;
|
||||
}
|
||||
|
||||
else if (bpp == 4)
|
||||
{
|
||||
pp->read_filter[PNG_FILTER_VALUE_SUB-1] = png_read_filter_row_sub4_neon;
|
||||
pp->read_filter[PNG_FILTER_VALUE_AVG-1] = png_read_filter_row_avg4_neon;
|
||||
pp->read_filter[PNG_FILTER_VALUE_PAETH-1] =
|
||||
png_read_filter_row_paeth4_neon;
|
||||
}
|
||||
}
|
||||
#endif /* PNG_ARM_NEON */
|
||||
|
||||
static void
|
||||
png_init_filter_functions(png_structrp pp)
|
||||
/* This function is called once for every PNG image (except for PNG images
|
||||
* that only use PNG_FILTER_VALUE_NONE for all rows) to set the
|
||||
* implementations required to reverse the filtering of PNG rows. Reversing
|
||||
* the filter is the first transformation performed on the row data. It is
|
||||
* performed in place, therefore an implementation can be selected based on
|
||||
* the image pixel format. If the implementation depends on image width then
|
||||
* take care to ensure that it works correctly if the image is interlaced -
|
||||
* interlacing causes the actual row width to vary.
|
||||
*/
|
||||
{
|
||||
unsigned int bpp = (pp->pixel_depth + 7) >> 3;
|
||||
|
||||
@@ -3938,8 +3876,16 @@ png_init_filter_functions(png_structrp pp)
|
||||
pp->read_filter[PNG_FILTER_VALUE_PAETH-1] =
|
||||
png_read_filter_row_paeth_multibyte_pixel;
|
||||
|
||||
#ifdef PNG_ARM_NEON
|
||||
png_init_filter_functions_neon(pp, bpp);
|
||||
#ifdef PNG_FILTER_OPTIMIZATIONS
|
||||
/* To use this define PNG_FILTER_OPTIMIZATIONS as the name of a function to
|
||||
* call to install hardware optimizations for the above functions; simply
|
||||
* replace whatever elements of the pp->read_filter[] array with a hardware
|
||||
* specific (or, for that matter, generic) optimization.
|
||||
*
|
||||
* To see an example of this examine what configure.ac does when
|
||||
* --enable-arm-neon is specified on the command line.
|
||||
*/
|
||||
PNG_FILTER_OPTIMIZATIONS(pp, bpp);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -3947,10 +3893,17 @@ void /* PRIVATE */
|
||||
png_read_filter_row(png_structrp pp, png_row_infop row_info, png_bytep row,
|
||||
png_const_bytep prev_row, int filter)
|
||||
{
|
||||
if (pp->read_filter[0] == NULL)
|
||||
png_init_filter_functions(pp);
|
||||
/* OPTIMIZATION: DO NOT MODIFY THIS FUNCTION, instead #define
|
||||
* PNG_FILTER_OPTIMIZATIONS to a function that overrides the generic
|
||||
* implementations. See png_init_filter_functions above.
|
||||
*/
|
||||
if (filter > PNG_FILTER_VALUE_NONE && filter < PNG_FILTER_VALUE_LAST)
|
||||
{
|
||||
if (pp->read_filter[0] == NULL)
|
||||
png_init_filter_functions(pp);
|
||||
|
||||
pp->read_filter[filter-1](row_info, row, prev_row);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
|
||||
@@ -4018,7 +3971,7 @@ png_read_IDAT_data(png_structrp png_ptr, png_bytep output,
|
||||
png_ptr->zstream.avail_out = out;
|
||||
}
|
||||
|
||||
else /* check for end */
|
||||
else /* after last row, checking for end */
|
||||
{
|
||||
png_ptr->zstream.next_out = tmpbuf;
|
||||
png_ptr->zstream.avail_out = (sizeof tmpbuf);
|
||||
@@ -4033,10 +3986,13 @@ png_read_IDAT_data(png_structrp png_ptr, png_bytep output,
|
||||
*/
|
||||
ret = inflate(&png_ptr->zstream, Z_NO_FLUSH);
|
||||
|
||||
/* Take the unconsumed output back (so, in the 'check' case this just
|
||||
* counts up).
|
||||
*/
|
||||
avail_out += png_ptr->zstream.avail_out;
|
||||
/* Take the unconsumed output back. */
|
||||
if (output != NULL)
|
||||
avail_out += png_ptr->zstream.avail_out;
|
||||
|
||||
else /* avail_out counts the extra bytes */
|
||||
avail_out += (sizeof tmpbuf) - png_ptr->zstream.avail_out;
|
||||
|
||||
png_ptr->zstream.avail_out = 0;
|
||||
|
||||
if (ret == Z_STREAM_END)
|
||||
@@ -4075,7 +4031,7 @@ png_read_IDAT_data(png_structrp png_ptr, png_bytep output,
|
||||
if (output != NULL)
|
||||
png_error(png_ptr, "Not enough image data");
|
||||
|
||||
else /* checking */
|
||||
else /* the deflate stream contained extra data */
|
||||
png_chunk_benign_error(png_ptr, "Too much image data");
|
||||
}
|
||||
}
|
||||
@@ -4145,7 +4101,7 @@ png_read_finish_row(png_structrp png_ptr)
|
||||
|
||||
/* Offset to next interlace block in the y direction */
|
||||
static PNG_CONST png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
|
||||
#endif /* PNG_READ_INTERLACING_SUPPORTED */
|
||||
#endif /* READ_INTERLACING */
|
||||
|
||||
png_debug(1, "in png_read_finish_row");
|
||||
png_ptr->row_number++;
|
||||
@@ -4190,12 +4146,12 @@ png_read_finish_row(png_structrp png_ptr)
|
||||
if (png_ptr->pass < 7)
|
||||
return;
|
||||
}
|
||||
#endif /* PNG_READ_INTERLACING_SUPPORTED */
|
||||
#endif /* READ_INTERLACING */
|
||||
|
||||
/* Here after at the end of the last row of the last pass. */
|
||||
png_read_finish_IDAT(png_ptr);
|
||||
}
|
||||
#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
|
||||
#endif /* SEQUENTIAL_READ */
|
||||
|
||||
void /* PRIVATE */
|
||||
png_read_start_row(png_structrp png_ptr)
|
||||
@@ -4241,7 +4197,7 @@ png_read_start_row(png_structrp png_ptr)
|
||||
}
|
||||
|
||||
else
|
||||
#endif /* PNG_READ_INTERLACING_SUPPORTED */
|
||||
#endif /* READ_INTERLACING */
|
||||
{
|
||||
png_ptr->num_rows = png_ptr->height;
|
||||
png_ptr->iwidth = png_ptr->width;
|
||||
@@ -4410,7 +4366,7 @@ defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
|
||||
png_error(png_ptr, "This image requires a row greater than 64KB");
|
||||
#endif
|
||||
|
||||
if (row_bytes + 48 > png_ptr->old_big_row_buf_size)
|
||||
if (row_bytes + 48 > png_ptr->big_row_buf_size)
|
||||
{
|
||||
png_free(png_ptr, png_ptr->big_row_buf);
|
||||
png_free(png_ptr, png_ptr->big_prev_row);
|
||||
@@ -4447,7 +4403,7 @@ defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
|
||||
png_ptr->row_buf = png_ptr->big_row_buf + 31;
|
||||
png_ptr->prev_row = png_ptr->big_prev_row + 31;
|
||||
#endif
|
||||
png_ptr->old_big_row_buf_size = row_bytes + 48;
|
||||
png_ptr->big_row_buf_size = row_bytes + 48;
|
||||
}
|
||||
|
||||
#ifdef PNG_MAX_MALLOC_64K
|
||||
@@ -4486,9 +4442,9 @@ defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
|
||||
* IDAT stream has a bogus deflate header window_bits value, but this should
|
||||
* not be happening any longer!)
|
||||
*/
|
||||
if (png_inflate_claim(png_ptr, png_IDAT, 0) != Z_OK)
|
||||
if (png_inflate_claim(png_ptr, png_IDAT) != Z_OK)
|
||||
png_error(png_ptr, png_ptr->zstream.msg);
|
||||
|
||||
png_ptr->flags |= PNG_FLAG_ROW_INIT;
|
||||
}
|
||||
#endif /* PNG_READ_SUPPORTED */
|
||||
#endif /* READ */
|
||||
|
||||
530
pngset.c
530
pngset.c
@@ -1,8 +1,8 @@
|
||||
|
||||
/* pngset.c - storage of image information into info struct
|
||||
*
|
||||
* Last changed in libpng 1.6.0 [(PENDING RELEASE)]
|
||||
* Copyright (c) 1998-2012 Glenn Randers-Pehrson
|
||||
* Last changed in libpng 1.7.0 [(PENDING RELEASE)]
|
||||
* Copyright (c) 1998-2014 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.)
|
||||
*
|
||||
@@ -59,7 +59,7 @@ png_set_cHRM_fixed(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
xy.whitey = white_y;
|
||||
|
||||
if (png_colorspace_set_chromaticities(png_ptr, &info_ptr->colorspace, &xy,
|
||||
2/* override with app values*/))
|
||||
2/* override with app values*/) != 0)
|
||||
info_ptr->colorspace.flags |= PNG_COLORSPACE_FROM_cHRM;
|
||||
|
||||
png_colorspace_sync_info(png_ptr, info_ptr);
|
||||
@@ -90,7 +90,8 @@ png_set_cHRM_XYZ_fixed(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
XYZ.blue_Y = int_blue_Y;
|
||||
XYZ.blue_Z = int_blue_Z;
|
||||
|
||||
if (png_colorspace_set_endpoints(png_ptr, &info_ptr->colorspace, &XYZ, 2))
|
||||
if (png_colorspace_set_endpoints(png_ptr, &info_ptr->colorspace,
|
||||
&XYZ, 2) != 0)
|
||||
info_ptr->colorspace.flags |= PNG_COLORSPACE_FROM_cHRM;
|
||||
|
||||
png_colorspace_sync_info(png_ptr, info_ptr);
|
||||
@@ -131,7 +132,7 @@ png_set_cHRM_XYZ(png_const_structrp png_ptr, png_inforp info_ptr, double red_X,
|
||||
}
|
||||
# endif /* PNG_FLOATING_POINT_SUPPORTED */
|
||||
|
||||
#endif /* PNG_cHRM_SUPPORTED */
|
||||
#endif /* cHRM */
|
||||
|
||||
#ifdef PNG_gAMA_SUPPORTED
|
||||
void PNGFAPI
|
||||
@@ -227,27 +228,18 @@ png_set_IHDR(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
|
||||
info_ptr->channels = 1;
|
||||
|
||||
else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
|
||||
else if ((info_ptr->color_type & PNG_COLOR_MASK_COLOR) != 0)
|
||||
info_ptr->channels = 3;
|
||||
|
||||
else
|
||||
info_ptr->channels = 1;
|
||||
|
||||
if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
|
||||
if ((info_ptr->color_type & PNG_COLOR_MASK_ALPHA) != 0)
|
||||
info_ptr->channels++;
|
||||
|
||||
info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth);
|
||||
|
||||
/* Check for potential overflow */
|
||||
if (width >
|
||||
(PNG_UINT_32_MAX >> 3) /* 8-byte RRGGBBAA pixels */
|
||||
- 48 /* bigrowbuf hack */
|
||||
- 1 /* filter byte */
|
||||
- 7*8 /* rounding of width to multiple of 8 pixels */
|
||||
- 8) /* extra max_pixel_depth pad */
|
||||
info_ptr->rowbytes = 0;
|
||||
else
|
||||
info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, width);
|
||||
info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, width);
|
||||
}
|
||||
|
||||
#ifdef PNG_oFFs_SUPPORTED
|
||||
@@ -297,12 +289,14 @@ png_set_pCAL(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
|
||||
/* Validate params[nparams] */
|
||||
for (i=0; i<nparams; ++i)
|
||||
{
|
||||
if (params[i] == NULL ||
|
||||
!png_check_fp_string(params[i], strlen(params[i])))
|
||||
!png_check_fp_string(params[i], strlen(params[i])))
|
||||
png_error(png_ptr, "Invalid format for pCAL parameter");
|
||||
}
|
||||
|
||||
info_ptr->pcal_purpose = png_voidcast(png_charp,
|
||||
png_malloc_warn(png_ptr, length));
|
||||
png_malloc_warn(png_ptr, length));
|
||||
|
||||
if (info_ptr->pcal_purpose == NULL)
|
||||
{
|
||||
@@ -431,7 +425,8 @@ png_set_sCAL_s(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
info_ptr->free_me |= PNG_FREE_SCAL;
|
||||
}
|
||||
|
||||
# ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
# if defined(PNG_FLOATING_POINT_SUPPORTED) &&\
|
||||
defined(PNG_FLOATING_ARITHMETIC_SUPPORTED)
|
||||
void PNGAPI
|
||||
png_set_sCAL(png_const_structrp png_ptr, png_inforp info_ptr, int unit,
|
||||
double width, double height)
|
||||
@@ -514,7 +509,7 @@ png_set_PLTE(png_structrp png_ptr, png_inforp info_ptr,
|
||||
|
||||
png_debug1(1, "in %s storage function", "PLTE");
|
||||
|
||||
if (png_ptr == NULL || info_ptr == NULL || palette == NULL)
|
||||
if (png_ptr == NULL || info_ptr == NULL)
|
||||
return;
|
||||
|
||||
if (num_palette < 0 || num_palette > PNG_MAX_PALETTE_LENGTH)
|
||||
@@ -529,6 +524,17 @@ png_set_PLTE(png_structrp png_ptr, png_inforp info_ptr,
|
||||
}
|
||||
}
|
||||
|
||||
if ((num_palette > 0 && palette == NULL) ||
|
||||
(num_palette == 0
|
||||
# ifdef PNG_MNG_FEATURES_SUPPORTED
|
||||
&& (png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) == 0
|
||||
# endif
|
||||
))
|
||||
{
|
||||
png_error(png_ptr, "Invalid palette");
|
||||
return;
|
||||
}
|
||||
|
||||
/* It may not actually be necessary to set png_ptr->palette here;
|
||||
* we do it for backward compatibility with the way the png_handle_tRNS
|
||||
* function used to do the allocation.
|
||||
@@ -545,7 +551,8 @@ png_set_PLTE(png_structrp png_ptr, png_inforp info_ptr,
|
||||
png_ptr->palette = png_voidcast(png_colorp, png_calloc(png_ptr,
|
||||
PNG_MAX_PALETTE_LENGTH * (sizeof (png_color))));
|
||||
|
||||
memcpy(png_ptr->palette, palette, num_palette * (sizeof (png_color)));
|
||||
if (num_palette > 0)
|
||||
memcpy(png_ptr->palette, palette, num_palette * (sizeof (png_color)));
|
||||
info_ptr->palette = png_ptr->palette;
|
||||
info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;
|
||||
|
||||
@@ -591,7 +598,8 @@ png_set_sRGB_gAMA_and_cHRM(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
if (png_ptr == NULL || info_ptr == NULL)
|
||||
return;
|
||||
|
||||
if (png_colorspace_set_sRGB(png_ptr, &info_ptr->colorspace, srgb_intent))
|
||||
if (png_colorspace_set_sRGB(png_ptr, &info_ptr->colorspace,
|
||||
srgb_intent) != 0)
|
||||
{
|
||||
/* This causes the gAMA and cHRM to be written too */
|
||||
info_ptr->colorspace.flags |=
|
||||
@@ -634,7 +642,7 @@ png_set_iCCP(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
png_colorspace_sync_info(png_ptr, info_ptr);
|
||||
|
||||
/* Don't do any of the copying if the profile was bad, or inconsistent. */
|
||||
if (!result)
|
||||
if (result == 0)
|
||||
return;
|
||||
|
||||
/* But do write the gAMA and cHRM chunks from the profile. */
|
||||
@@ -658,6 +666,7 @@ png_set_iCCP(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
if (new_iccp_profile == NULL)
|
||||
{
|
||||
png_free(png_ptr, new_iccp_name);
|
||||
new_iccp_name = NULL;
|
||||
png_benign_error(png_ptr,
|
||||
"Insufficient memory to process iCCP profile");
|
||||
return;
|
||||
@@ -677,18 +686,18 @@ png_set_iCCP(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
|
||||
#ifdef PNG_TEXT_SUPPORTED
|
||||
void PNGAPI
|
||||
png_set_text(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
png_set_text(png_structrp png_ptr, png_inforp info_ptr,
|
||||
png_const_textp text_ptr, int num_text)
|
||||
{
|
||||
int ret;
|
||||
ret = png_set_text_2(png_ptr, info_ptr, text_ptr, num_text);
|
||||
|
||||
if (ret)
|
||||
if (ret != 0)
|
||||
png_error(png_ptr, "Insufficient memory to store text");
|
||||
}
|
||||
|
||||
int /* PRIVATE */
|
||||
png_set_text_2(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
png_set_text_2(png_structrp png_ptr, png_inforp info_ptr,
|
||||
png_const_textp text_ptr, int num_text)
|
||||
{
|
||||
int i;
|
||||
@@ -696,63 +705,63 @@ png_set_text_2(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
png_debug1(1, "in %lx storage function", png_ptr == NULL ? "unexpected" :
|
||||
(unsigned long)png_ptr->chunk_name);
|
||||
|
||||
if (png_ptr == NULL || info_ptr == NULL || num_text == 0)
|
||||
if (png_ptr == NULL || info_ptr == NULL || num_text <= 0 || text_ptr == NULL)
|
||||
return(0);
|
||||
|
||||
/* Make sure we have enough space in the "text" array in info_struct
|
||||
* to hold all of the incoming text_ptr objects.
|
||||
* to hold all of the incoming text_ptr objects. This compare can't overflow
|
||||
* because max_text >= num_text (anyway, subtract of two positive integers
|
||||
* can't overflow in any case.)
|
||||
*/
|
||||
if (info_ptr->num_text + num_text > info_ptr->max_text)
|
||||
if (num_text > info_ptr->max_text - info_ptr->num_text)
|
||||
{
|
||||
int old_max_text = info_ptr->max_text;
|
||||
int old_num_text = info_ptr->num_text;
|
||||
int max_text;
|
||||
png_textp new_text = NULL;
|
||||
|
||||
if (info_ptr->text != NULL)
|
||||
/* Calculate an appropriate max_text, checking for overflow. */
|
||||
max_text = old_num_text;
|
||||
if (num_text <= INT_MAX - max_text)
|
||||
{
|
||||
png_textp old_text;
|
||||
max_text += num_text;
|
||||
|
||||
info_ptr->max_text = info_ptr->num_text + num_text + 8;
|
||||
old_text = info_ptr->text;
|
||||
/* Round up to a multiple of 8 */
|
||||
if (max_text < INT_MAX-8)
|
||||
max_text = (max_text + 8) & ~0x7;
|
||||
|
||||
info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
|
||||
(png_size_t)(info_ptr->max_text * (sizeof (png_text))));
|
||||
else
|
||||
max_text = INT_MAX;
|
||||
|
||||
if (info_ptr->text == NULL)
|
||||
{
|
||||
/* Restore to previous condition */
|
||||
info_ptr->max_text = old_max_text;
|
||||
info_ptr->text = old_text;
|
||||
return(1);
|
||||
}
|
||||
|
||||
memcpy(info_ptr->text, old_text, (png_size_t)(old_max_text *
|
||||
(sizeof (png_text))));
|
||||
png_free(png_ptr, old_text);
|
||||
/* Now allocate a new array and copy the old members in; this does all
|
||||
* 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));
|
||||
}
|
||||
|
||||
else
|
||||
if (new_text == NULL)
|
||||
{
|
||||
info_ptr->max_text = num_text + 8;
|
||||
info_ptr->num_text = 0;
|
||||
info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
|
||||
(png_size_t)(info_ptr->max_text * (sizeof (png_text))));
|
||||
if (info_ptr->text == NULL)
|
||||
{
|
||||
/* Restore to previous condition */
|
||||
info_ptr->num_text = old_num_text;
|
||||
info_ptr->max_text = old_max_text;
|
||||
return(1);
|
||||
}
|
||||
info_ptr->free_me |= PNG_FREE_TEXT;
|
||||
png_chunk_report(png_ptr, "too many text chunks",
|
||||
PNG_CHUNK_WRITE_ERROR);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
png_debug1(3, "allocated %d entries for info_ptr->text",
|
||||
info_ptr->max_text);
|
||||
png_free(png_ptr, info_ptr->text);
|
||||
|
||||
info_ptr->text = new_text;
|
||||
info_ptr->free_me |= PNG_FREE_TEXT;
|
||||
info_ptr->max_text = max_text;
|
||||
/* num_text is adjusted below as the entries are copied in */
|
||||
|
||||
png_debug1(3, "allocated %d entries for info_ptr->text", max_text);
|
||||
}
|
||||
|
||||
for (i = 0; i < num_text; i++)
|
||||
{
|
||||
png_size_t text_length, key_len;
|
||||
png_size_t lang_len, lang_key_len;
|
||||
size_t text_length, key_len;
|
||||
size_t lang_len, lang_key_len;
|
||||
png_textp textp = &(info_ptr->text[info_ptr->num_text]);
|
||||
|
||||
if (text_ptr[i].key == NULL)
|
||||
@@ -761,7 +770,8 @@ png_set_text_2(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
if (text_ptr[i].compression < PNG_TEXT_COMPRESSION_NONE ||
|
||||
text_ptr[i].compression >= PNG_TEXT_COMPRESSION_LAST)
|
||||
{
|
||||
png_warning(png_ptr, "text compression mode is out of range");
|
||||
png_chunk_report(png_ptr, "text compression mode is out of range",
|
||||
PNG_CHUNK_WRITE_ERROR);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -790,9 +800,10 @@ png_set_text_2(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
else
|
||||
lang_key_len = 0;
|
||||
}
|
||||
# else /* PNG_iTXt_SUPPORTED */
|
||||
# else /* iTXt */
|
||||
{
|
||||
png_warning(png_ptr, "iTXt chunk not supported");
|
||||
png_chunk_report(png_ptr, "iTXt chunk not supported",
|
||||
PNG_CHUNK_WRITE_ERROR);
|
||||
continue;
|
||||
}
|
||||
# endif
|
||||
@@ -815,19 +826,22 @@ png_set_text_2(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
textp->compression = text_ptr[i].compression;
|
||||
}
|
||||
|
||||
textp->key = (png_charp)png_malloc_warn(png_ptr,
|
||||
(png_size_t)
|
||||
(key_len + text_length + lang_len + lang_key_len + 4));
|
||||
textp->key = png_voidcast(png_charp,png_malloc_base(png_ptr,
|
||||
key_len + text_length + lang_len + lang_key_len + 4));
|
||||
|
||||
if (textp->key == NULL)
|
||||
return(1);
|
||||
{
|
||||
png_chunk_report(png_ptr, "text chunk: out of memory",
|
||||
PNG_CHUNK_WRITE_ERROR);
|
||||
return 1;
|
||||
}
|
||||
|
||||
png_debug2(2, "Allocated %lu bytes at %p in png_set_text",
|
||||
(unsigned long)(png_uint_32)
|
||||
(key_len + lang_len + lang_key_len + text_length + 4),
|
||||
textp->key);
|
||||
|
||||
memcpy(textp->key, text_ptr[i].key,(png_size_t)(key_len));
|
||||
memcpy(textp->key, text_ptr[i].key, key_len);
|
||||
*(textp->key + key_len) = '\0';
|
||||
|
||||
if (text_ptr[i].compression > 0)
|
||||
@@ -848,9 +862,8 @@ png_set_text_2(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
textp->text = textp->key + key_len + 1;
|
||||
}
|
||||
|
||||
if (text_length)
|
||||
memcpy(textp->text, text_ptr[i].text,
|
||||
(png_size_t)(text_length));
|
||||
if (text_length != 0)
|
||||
memcpy(textp->text, text_ptr[i].text, text_length);
|
||||
|
||||
*(textp->text + text_length) = '\0';
|
||||
|
||||
@@ -871,6 +884,7 @@ png_set_text_2(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
info_ptr->num_text++;
|
||||
png_debug1(3, "transferred text chunk %d", info_ptr->num_text);
|
||||
}
|
||||
|
||||
return(0);
|
||||
}
|
||||
#endif
|
||||
@@ -883,7 +897,7 @@ png_set_tIME(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
png_debug1(1, "in %s storage function", "tIME");
|
||||
|
||||
if (png_ptr == NULL || info_ptr == NULL || mod_time == NULL ||
|
||||
(png_ptr->mode & PNG_WROTE_tIME))
|
||||
(png_ptr->mode & PNG_WROTE_tIME) != 0)
|
||||
return;
|
||||
|
||||
if (mod_time->month == 0 || mod_time->month > 12 ||
|
||||
@@ -910,59 +924,97 @@ png_set_tRNS(png_structrp png_ptr, png_inforp info_ptr,
|
||||
if (png_ptr == NULL || info_ptr == NULL)
|
||||
return;
|
||||
|
||||
if (trans_alpha != NULL)
|
||||
if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
|
||||
png_chunk_report(png_ptr,
|
||||
"png_set_tRNS: invalid on PNG with alpha channel", PNG_CHUNK_ERROR);
|
||||
|
||||
else if (info_ptr->color_type & PNG_COLOR_MASK_PALETTE)
|
||||
{
|
||||
/* It may not actually be necessary to set png_ptr->trans_alpha here;
|
||||
* we do it for backward compatibility with the way the png_handle_tRNS
|
||||
* function used to do the allocation.
|
||||
*
|
||||
* 1.6.0: The above statement is incorrect; png_handle_tRNS effectively
|
||||
* relies on png_set_tRNS storing the information in png_struct
|
||||
* (otherwise it won't be there for the code in pngrtran.c).
|
||||
*/
|
||||
int max_num;
|
||||
|
||||
png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);
|
||||
/* Free the old data; num_trans 0 can be used to kill the tRNS */
|
||||
png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);
|
||||
|
||||
/* Changed from num_trans to PNG_MAX_PALETTE_LENGTH in version 1.2.1 */
|
||||
png_ptr->trans_alpha = info_ptr->trans_alpha = png_voidcast(png_bytep,
|
||||
png_malloc(png_ptr, PNG_MAX_PALETTE_LENGTH));
|
||||
/* Do this just in case the old data was not owned by libpng: */
|
||||
info_ptr->valid &= ~PNG_INFO_tRNS;
|
||||
info_ptr->trans_alpha = NULL;
|
||||
info_ptr->num_trans = 0;
|
||||
|
||||
if (num_trans > 0 && num_trans <= PNG_MAX_PALETTE_LENGTH)
|
||||
memcpy(info_ptr->trans_alpha, trans_alpha, (png_size_t)num_trans);
|
||||
/* Expect png_set_PLTE to happen before png_set_tRNS, so num_palette will
|
||||
* be set, but this is not a requirement of the API.
|
||||
*/
|
||||
if (png_ptr->num_palette)
|
||||
max_num = png_ptr->num_palette;
|
||||
|
||||
else
|
||||
max_num = 1 << png_ptr->bit_depth;
|
||||
|
||||
if (num_trans > max_num)
|
||||
{
|
||||
png_chunk_report(png_ptr, "png_set_tRNS: num_trans too large",
|
||||
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.
|
||||
*/
|
||||
num_trans = max_num;
|
||||
}
|
||||
|
||||
/* But only attempt a malloc if there is something to do; so the app can
|
||||
* set a tRNS array then later delete it.
|
||||
*/
|
||||
if (num_trans > 0 && trans_alpha != NULL)
|
||||
{
|
||||
/* Changed from num_trans to PNG_MAX_PALETTE_LENGTH in version 1.2.1,
|
||||
* this avoids issues where a palette image contains out of range
|
||||
* indices.
|
||||
*/
|
||||
info_ptr->trans_alpha = png_voidcast(png_bytep, png_malloc(png_ptr,
|
||||
PNG_MAX_PALETTE_LENGTH));
|
||||
info_ptr->free_me |= PNG_FREE_TRNS;
|
||||
|
||||
memcpy(info_ptr->trans_alpha, trans_alpha,
|
||||
(unsigned)/*SAFE*/num_trans);
|
||||
info_ptr->valid |= PNG_INFO_tRNS;
|
||||
info_ptr->num_trans = (png_uint_16)num_trans; /* SAFE */
|
||||
}
|
||||
}
|
||||
|
||||
if (trans_color != NULL)
|
||||
else /* not a PALETTE image */
|
||||
{
|
||||
int sample_max = (1 << info_ptr->bit_depth);
|
||||
/* Invalidate any prior transparent color, set num_trans too, it is not
|
||||
* used internally in this case but png_get_tRNS still returns it.
|
||||
*/
|
||||
info_ptr->valid &= ~PNG_INFO_tRNS;
|
||||
info_ptr->num_trans = 0; /* for png_get_tRNS */
|
||||
|
||||
if ((info_ptr->color_type == PNG_COLOR_TYPE_GRAY &&
|
||||
trans_color->gray > sample_max) ||
|
||||
(info_ptr->color_type == PNG_COLOR_TYPE_RGB &&
|
||||
(trans_color->red > sample_max ||
|
||||
trans_color->green > sample_max ||
|
||||
trans_color->blue > sample_max)))
|
||||
png_warning(png_ptr,
|
||||
"tRNS chunk has out-of-range samples for bit_depth");
|
||||
if (trans_color != NULL)
|
||||
{
|
||||
int sample_max = (1 << info_ptr->bit_depth);
|
||||
|
||||
info_ptr->trans_color = *trans_color;
|
||||
if ((info_ptr->color_type == PNG_COLOR_TYPE_GRAY &&
|
||||
trans_color->gray <= sample_max) ||
|
||||
(info_ptr->color_type == PNG_COLOR_TYPE_RGB &&
|
||||
trans_color->red <= sample_max &&
|
||||
trans_color->green <= sample_max &&
|
||||
trans_color->blue <= sample_max))
|
||||
{
|
||||
info_ptr->trans_color = *trans_color;
|
||||
info_ptr->valid |= PNG_INFO_tRNS;
|
||||
info_ptr->num_trans = 1; /* for png_get_tRNS */
|
||||
}
|
||||
|
||||
if (num_trans == 0)
|
||||
num_trans = 1;
|
||||
}
|
||||
|
||||
info_ptr->num_trans = (png_uint_16)num_trans;
|
||||
|
||||
if (num_trans != 0)
|
||||
{
|
||||
info_ptr->valid |= PNG_INFO_tRNS;
|
||||
info_ptr->free_me |= PNG_FREE_TRNS;
|
||||
else
|
||||
png_chunk_report(png_ptr,
|
||||
"tRNS chunk has out-of-range samples for bit_depth",
|
||||
PNG_CHUNK_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PNG_sPLT_SUPPORTED
|
||||
void PNGAPI
|
||||
png_set_sPLT(png_const_structrp png_ptr,
|
||||
png_set_sPLT(png_structrp png_ptr,
|
||||
png_inforp info_ptr, png_const_sPLT_tp entries, int nentries)
|
||||
/*
|
||||
* entries - array of png_sPLT_t structures
|
||||
@@ -974,80 +1026,91 @@ png_set_sPLT(png_const_structrp png_ptr,
|
||||
*/
|
||||
{
|
||||
png_sPLT_tp np;
|
||||
int i;
|
||||
|
||||
if (png_ptr == NULL || info_ptr == NULL || nentries <= 0 ||
|
||||
entries == NULL)
|
||||
if (png_ptr == NULL || info_ptr == NULL || nentries <= 0 || entries == NULL)
|
||||
return;
|
||||
|
||||
np = png_voidcast(png_sPLT_tp, png_malloc_warn(png_ptr,
|
||||
(info_ptr->splt_palettes_num + nentries) * (sizeof (png_sPLT_t))));
|
||||
/* Use the internal realloc function, which checks for all the possible
|
||||
* 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));
|
||||
|
||||
if (np == NULL)
|
||||
{
|
||||
png_warning(png_ptr, "No memory for sPLT palettes");
|
||||
/* Out of memory or too many chunks */
|
||||
png_chunk_report(png_ptr, "too many sPLT chunks", PNG_CHUNK_WRITE_ERROR);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(np, info_ptr->splt_palettes,
|
||||
info_ptr->splt_palettes_num * (sizeof (png_sPLT_t)));
|
||||
|
||||
png_free(png_ptr, info_ptr->splt_palettes);
|
||||
info_ptr->splt_palettes=NULL;
|
||||
info_ptr->splt_palettes = np;
|
||||
info_ptr->free_me |= PNG_FREE_SPLT;
|
||||
|
||||
/* TODO: fix this, it apparently leaves NULL entries in the event of OOM
|
||||
* below.
|
||||
*/
|
||||
for (i = 0; i < nentries; i++)
|
||||
np += info_ptr->splt_palettes_num;
|
||||
|
||||
do
|
||||
{
|
||||
png_sPLT_tp to = np + info_ptr->splt_palettes_num + i;
|
||||
png_const_sPLT_tp from = entries + i;
|
||||
png_size_t length;
|
||||
|
||||
/* In event of error below the name and entries fields must be set to
|
||||
* NULL, otherwise libpng will crash later on while trying to free the
|
||||
* uninitialized pointers.
|
||||
/* Skip invalid input entries */
|
||||
if (entries->name == NULL || entries->entries == NULL)
|
||||
{
|
||||
/* png_handle_sPLT doesn't do this, so this is an app error */
|
||||
png_app_error(png_ptr, "png_set_sPLT: invalid sPLT");
|
||||
/* Just skip the invalid entry */
|
||||
continue;
|
||||
}
|
||||
|
||||
np->depth = entries->depth;
|
||||
|
||||
/* In the event of out-of-memory just return - there's no point keeping
|
||||
* on trying to add sPLT chunks.
|
||||
*/
|
||||
memset(to, 0, (sizeof *to));
|
||||
length = strlen(entries->name) + 1;
|
||||
np->name = png_voidcast(png_charp, png_malloc_base(png_ptr, length));
|
||||
|
||||
if (from->name == NULL || from->entries == NULL)
|
||||
continue;
|
||||
if (np->name == NULL)
|
||||
break;
|
||||
|
||||
length = strlen(from->name) + 1;
|
||||
to->name = png_voidcast(png_charp, png_malloc_warn(png_ptr, length));
|
||||
memcpy(np->name, entries->name, length);
|
||||
|
||||
if (to->name == NULL)
|
||||
/* IMPORTANT: we have memory now that won't get freed if something else
|
||||
* goes wrong; this code must free it. png_malloc_array produces no
|
||||
* warnings; use a png_chunk_report (below) if there is an error.
|
||||
*/
|
||||
np->entries = png_voidcast(png_sPLT_entryp, png_malloc_array(png_ptr,
|
||||
entries->nentries, sizeof (png_sPLT_entry)));
|
||||
|
||||
if (np->entries == NULL)
|
||||
{
|
||||
png_warning(png_ptr,
|
||||
"Out of memory while processing sPLT chunk");
|
||||
continue;
|
||||
png_free(png_ptr, np->name);
|
||||
np->name = NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
memcpy(to->name, from->name, length);
|
||||
to->entries = png_voidcast(png_sPLT_entryp, png_malloc_warn(png_ptr,
|
||||
from->nentries * (sizeof (png_sPLT_entry))));
|
||||
np->nentries = entries->nentries;
|
||||
/* This multiply can't overflow because png_malloc_array has already
|
||||
* checked it when doing the allocation.
|
||||
*/
|
||||
memcpy(np->entries, entries->entries,
|
||||
entries->nentries * sizeof (png_sPLT_entry));
|
||||
|
||||
if (to->entries == NULL)
|
||||
{
|
||||
png_warning(png_ptr, "Out of memory while processing sPLT chunk");
|
||||
png_free(png_ptr, to->name);
|
||||
to->name = NULL;
|
||||
continue;
|
||||
}
|
||||
|
||||
memcpy(to->entries, from->entries,
|
||||
from->nentries * (sizeof (png_sPLT_entry)));
|
||||
|
||||
to->nentries = from->nentries;
|
||||
to->depth = from->depth;
|
||||
/* Note that 'continue' skips the advance of the out pointer and out
|
||||
* count, so an invalid entry is not added.
|
||||
*/
|
||||
info_ptr->valid |= PNG_INFO_sPLT;
|
||||
++(info_ptr->splt_palettes_num);
|
||||
++np;
|
||||
}
|
||||
while (++entries, --nentries);
|
||||
|
||||
info_ptr->splt_palettes = np;
|
||||
info_ptr->splt_palettes_num += nentries;
|
||||
info_ptr->valid |= PNG_INFO_sPLT;
|
||||
info_ptr->free_me |= PNG_FREE_SPLT;
|
||||
if (nentries > 0)
|
||||
png_chunk_report(png_ptr, "sPLT out of memory", PNG_CHUNK_WRITE_ERROR);
|
||||
}
|
||||
#endif /* PNG_sPLT_SUPPORTED */
|
||||
#endif /* sPLT */
|
||||
|
||||
#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
|
||||
static png_byte
|
||||
@@ -1056,10 +1119,10 @@ check_location(png_const_structrp png_ptr, int location)
|
||||
location &= (PNG_HAVE_IHDR|PNG_HAVE_PLTE|PNG_AFTER_IDAT);
|
||||
|
||||
/* New in 1.6.0; copy the location and check it. This is an API
|
||||
* change, previously the app had to use the
|
||||
* change; previously the app had to use the
|
||||
* png_set_unknown_chunk_location API below for each chunk.
|
||||
*/
|
||||
if (location == 0 && !(png_ptr->mode & PNG_IS_READ_STRUCT))
|
||||
if (location == 0 && (png_ptr->mode & PNG_IS_READ_STRUCT) == 0)
|
||||
{
|
||||
/* Write struct, so unknown chunks come from the app */
|
||||
png_app_warning(png_ptr,
|
||||
@@ -1069,6 +1132,9 @@ check_location(png_const_structrp png_ptr, int location)
|
||||
(PNG_HAVE_IHDR|PNG_HAVE_PLTE|PNG_AFTER_IDAT));
|
||||
}
|
||||
|
||||
/* This need not be an internal error - if the app calls
|
||||
* png_set_unknown_chunks on a read pointer it must get the location right.
|
||||
*/
|
||||
if (location == 0)
|
||||
png_error(png_ptr, "invalid location in png_set_unknown_chunks");
|
||||
|
||||
@@ -1085,12 +1151,13 @@ check_location(png_const_structrp png_ptr, int location)
|
||||
}
|
||||
|
||||
void PNGAPI
|
||||
png_set_unknown_chunks(png_const_structrp png_ptr,
|
||||
png_set_unknown_chunks(png_structrp png_ptr,
|
||||
png_inforp info_ptr, png_const_unknown_chunkp unknowns, int num_unknowns)
|
||||
{
|
||||
png_unknown_chunkp np;
|
||||
|
||||
if (png_ptr == NULL || info_ptr == NULL || num_unknowns <= 0)
|
||||
if (png_ptr == NULL || info_ptr == NULL || num_unknowns <= 0 ||
|
||||
unknowns == NULL)
|
||||
return;
|
||||
|
||||
/* Check for the failure cases where support has been disabled at compile
|
||||
@@ -1099,37 +1166,39 @@ png_set_unknown_chunks(png_const_structrp png_ptr,
|
||||
* code) but may be meaningless if the read or write handling of unknown
|
||||
* chunks is not compiled in.
|
||||
*/
|
||||
# if !(defined PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) && \
|
||||
(defined PNG_READ_SUPPORTED)
|
||||
if (png_ptr->mode & PNG_IS_READ_STRUCT)
|
||||
# if !defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) && \
|
||||
defined(PNG_READ_SUPPORTED)
|
||||
if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0)
|
||||
{
|
||||
png_app_error(png_ptr, "no unknown chunk support on read");
|
||||
return;
|
||||
}
|
||||
# endif
|
||||
# if !(defined PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED) && \
|
||||
(defined PNG_WRITE_SUPPORTED)
|
||||
if (!(png_ptr->mode & PNG_IS_READ_STRUCT))
|
||||
# if !defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED) && \
|
||||
defined(PNG_WRITE_SUPPORTED)
|
||||
if ((png_ptr->mode & PNG_IS_READ_STRUCT) == 0)
|
||||
{
|
||||
png_app_error(png_ptr, "no unknown chunk support on write");
|
||||
return;
|
||||
}
|
||||
# endif
|
||||
|
||||
/* Prior to 1.6.0 this code used png_malloc_warn, however this meant that
|
||||
/* Prior to 1.6.0 this code used png_malloc_warn; however, this meant that
|
||||
* unknown critical chunks could be lost with just a warning resulting in
|
||||
* undefined behavior. Changing to png_malloc fixes this by producing a
|
||||
* png_error. The (png_size_t) cast was also removed as it hides a potential
|
||||
* overflow.
|
||||
*
|
||||
* TODO: fix the potential overflow in the multiply
|
||||
* undefined behavior. Now png_chunk_report is used to provide behavior
|
||||
* appropriate to read or write.
|
||||
*/
|
||||
np = png_voidcast(png_unknown_chunkp, png_malloc(png_ptr,
|
||||
(info_ptr->unknown_chunks_num + (unsigned int)num_unknowns) *
|
||||
(sizeof (png_unknown_chunk))));
|
||||
np = png_voidcast(png_unknown_chunkp, png_realloc_array(png_ptr,
|
||||
info_ptr->unknown_chunks, info_ptr->unknown_chunks_num, num_unknowns,
|
||||
sizeof *np));
|
||||
|
||||
memcpy(np, info_ptr->unknown_chunks,
|
||||
info_ptr->unknown_chunks_num * (sizeof (png_unknown_chunk)));
|
||||
if (np == NULL)
|
||||
{
|
||||
png_chunk_report(png_ptr, "too many unknown chunks",
|
||||
PNG_CHUNK_WRITE_ERROR);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
png_free(png_ptr, info_ptr->unknown_chunks);
|
||||
info_ptr->unknown_chunks = np; /* safe because it is initialized */
|
||||
@@ -1140,24 +1209,41 @@ png_set_unknown_chunks(png_const_structrp png_ptr,
|
||||
/* Increment unknown_chunks_num each time round the loop to protect the
|
||||
* just-allocated chunk data.
|
||||
*/
|
||||
for (; --num_unknowns >= 0;
|
||||
++np, ++unknowns, ++(info_ptr->unknown_chunks_num))
|
||||
for (; num_unknowns > 0; --num_unknowns, ++unknowns)
|
||||
{
|
||||
memcpy(np->name, unknowns->name, (sizeof unknowns->name));
|
||||
memcpy(np->name, unknowns->name, (sizeof np->name));
|
||||
np->name[(sizeof np->name)-1] = '\0';
|
||||
np->size = unknowns->size;
|
||||
np->location = check_location(png_ptr, unknowns->location);
|
||||
|
||||
if (unknowns->size == 0)
|
||||
{
|
||||
np->data = NULL;
|
||||
np->size = 0;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
/* png_error is safe here because the list is stored in png_ptr */
|
||||
np->data = png_voidcast(png_bytep,
|
||||
png_malloc(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_WRITE_ERROR);
|
||||
/* But just skip storing the unknown chunk */
|
||||
continue;
|
||||
}
|
||||
|
||||
memcpy(np->data, unknowns->data, unknowns->size);
|
||||
np->size = unknowns->size;
|
||||
}
|
||||
|
||||
/* These increments are skipped on out-of-memory for the data - the
|
||||
* unknown chunk entry gets overwritten if the png_chunk_report returns.
|
||||
* This is correct in the read case (the chunk is just dropped.)
|
||||
*/
|
||||
++np;
|
||||
++(info_ptr->unknown_chunks_num);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1167,17 +1253,15 @@ png_set_unknown_chunk_location(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
{
|
||||
/* This API is pretty pointless in 1.6.0 because the location can be set
|
||||
* before the call to png_set_unknown_chunks.
|
||||
*
|
||||
* TODO: add a png_app_warning in 1.7
|
||||
*/
|
||||
if (png_ptr != NULL && info_ptr != NULL && chunk >= 0 &&
|
||||
(unsigned int)chunk < info_ptr->unknown_chunks_num)
|
||||
chunk < info_ptr->unknown_chunks_num)
|
||||
{
|
||||
if ((location & (PNG_HAVE_IHDR|PNG_HAVE_PLTE|PNG_AFTER_IDAT)) == 0)
|
||||
{
|
||||
png_app_error(png_ptr, "invalid unknown chunk location");
|
||||
/* Fake out the pre 1.6.0 behavior: */
|
||||
if ((location & PNG_HAVE_IDAT)) /* undocumented! */
|
||||
if ((location & PNG_HAVE_IDAT) != 0) /* undocumented! */
|
||||
location = PNG_AFTER_IDAT;
|
||||
|
||||
else
|
||||
@@ -1187,6 +1271,10 @@ png_set_unknown_chunk_location(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
info_ptr->unknown_chunks[chunk].location =
|
||||
check_location(png_ptr, location);
|
||||
}
|
||||
|
||||
/* TODO: make this an error in 1.8 (or maybe it will become one in 1.7!) */
|
||||
else if (png_ptr != NULL)
|
||||
png_app_warning(png_ptr, "unknown chunk index out of range");
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1215,10 +1303,13 @@ add_one_chunk(png_bytep list, unsigned int count, png_const_bytep add, int keep)
|
||||
/* Utility function: update the 'keep' state of a chunk if it is already in
|
||||
* the list, otherwise add it to the list.
|
||||
*/
|
||||
for (i=0; i<count; ++i, list += 5) if (memcmp(list, add, 4) == 0)
|
||||
for (i=0; i<count; ++i, list += 5)
|
||||
{
|
||||
list[4] = (png_byte)keep;
|
||||
return count;
|
||||
if (memcmp(list, add, 4) == 0)
|
||||
{
|
||||
list[4] = (png_byte)keep;
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
if (keep != PNG_HANDLE_CHUNK_AS_DEFAULT)
|
||||
@@ -1282,7 +1373,7 @@ png_set_keep_unknown_chunks(png_structrp png_ptr, int keep,
|
||||
};
|
||||
|
||||
chunk_list = chunks_to_ignore;
|
||||
num_chunks = (sizeof chunks_to_ignore)/5;
|
||||
num_chunks = (unsigned int)/*SAFE*/(sizeof chunks_to_ignore)/5U;
|
||||
}
|
||||
|
||||
else /* num_chunks_in > 0 */
|
||||
@@ -1315,7 +1406,7 @@ png_set_keep_unknown_chunks(png_structrp png_ptr, int keep,
|
||||
* required because add_one_chunk above doesn't extend the list if the 'keep'
|
||||
* parameter is the default.
|
||||
*/
|
||||
if (keep)
|
||||
if (keep != 0)
|
||||
{
|
||||
new_list = png_voidcast(png_bytep, png_malloc(png_ptr,
|
||||
5 * (num_chunks + old_num_chunks)));
|
||||
@@ -1342,12 +1433,15 @@ png_set_keep_unknown_chunks(png_structrp png_ptr, int keep,
|
||||
unsigned int i;
|
||||
|
||||
for (i=0; i<num_chunks; ++i)
|
||||
{
|
||||
old_num_chunks = add_one_chunk(new_list, old_num_chunks,
|
||||
chunk_list+5*i, keep);
|
||||
}
|
||||
|
||||
/* Now remove any spurious 'default' entries. */
|
||||
num_chunks = 0;
|
||||
for (i=0, inlist=outlist=new_list; i<old_num_chunks; ++i, inlist += 5)
|
||||
{
|
||||
if (inlist[4])
|
||||
{
|
||||
if (outlist != inlist)
|
||||
@@ -1355,6 +1449,7 @@ png_set_keep_unknown_chunks(png_structrp png_ptr, int keep,
|
||||
outlist += 5;
|
||||
++num_chunks;
|
||||
}
|
||||
}
|
||||
|
||||
/* This means the application has removed all the specialized handling. */
|
||||
if (num_chunks == 0)
|
||||
@@ -1406,12 +1501,13 @@ png_set_rows(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
if (png_ptr == NULL || info_ptr == NULL)
|
||||
return;
|
||||
|
||||
if (info_ptr->row_pointers && (info_ptr->row_pointers != row_pointers))
|
||||
if (info_ptr->row_pointers != NULL &&
|
||||
(info_ptr->row_pointers != row_pointers))
|
||||
png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
|
||||
|
||||
info_ptr->row_pointers = row_pointers;
|
||||
|
||||
if (row_pointers)
|
||||
if (row_pointers != NULL)
|
||||
info_ptr->valid |= PNG_INFO_IDAT;
|
||||
}
|
||||
#endif
|
||||
@@ -1426,7 +1522,7 @@ png_set_compression_buffer_size(png_structrp png_ptr, png_size_t size)
|
||||
png_error(png_ptr, "invalid compression buffer size");
|
||||
|
||||
# ifdef PNG_SEQUENTIAL_READ_SUPPORTED
|
||||
if (png_ptr->mode & PNG_IS_READ_STRUCT)
|
||||
if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0)
|
||||
{
|
||||
png_ptr->IDAT_read_size = (png_uint_32)size; /* checked above */
|
||||
return;
|
||||
@@ -1434,7 +1530,7 @@ png_set_compression_buffer_size(png_structrp png_ptr, png_size_t size)
|
||||
# endif
|
||||
|
||||
# ifdef PNG_WRITE_SUPPORTED
|
||||
if (!(png_ptr->mode & PNG_IS_READ_STRUCT))
|
||||
if ((png_ptr->mode & PNG_IS_READ_STRUCT) == 0)
|
||||
{
|
||||
if (png_ptr->zowner != 0)
|
||||
{
|
||||
@@ -1472,7 +1568,7 @@ png_set_compression_buffer_size(png_structrp png_ptr, png_size_t size)
|
||||
void PNGAPI
|
||||
png_set_invalid(png_const_structrp png_ptr, png_inforp info_ptr, int mask)
|
||||
{
|
||||
if (png_ptr && info_ptr)
|
||||
if (png_ptr != NULL && info_ptr != NULL)
|
||||
info_ptr->valid &= ~mask;
|
||||
}
|
||||
|
||||
@@ -1487,19 +1583,19 @@ png_set_user_limits (png_structrp png_ptr, png_uint_32 user_width_max,
|
||||
* rejected by png_set_IHDR(). To accept any PNG datastream
|
||||
* regardless of dimensions, set both limits to 0x7ffffffL.
|
||||
*/
|
||||
if (png_ptr == NULL)
|
||||
return;
|
||||
|
||||
png_ptr->user_width_max = user_width_max;
|
||||
png_ptr->user_height_max = user_height_max;
|
||||
if (png_ptr != NULL)
|
||||
{
|
||||
png_ptr->user_width_max = user_width_max;
|
||||
png_ptr->user_height_max = user_height_max;
|
||||
}
|
||||
}
|
||||
|
||||
/* This function was added to libpng 1.4.0 */
|
||||
void PNGAPI
|
||||
png_set_chunk_cache_max (png_structrp png_ptr, png_uint_32 user_chunk_cache_max)
|
||||
{
|
||||
if (png_ptr)
|
||||
png_ptr->user_chunk_cache_max = user_chunk_cache_max;
|
||||
if (png_ptr != NULL)
|
||||
png_ptr->user_chunk_cache_max = user_chunk_cache_max;
|
||||
}
|
||||
|
||||
/* This function was added to libpng 1.4.1 */
|
||||
@@ -1507,10 +1603,10 @@ void PNGAPI
|
||||
png_set_chunk_malloc_max (png_structrp png_ptr,
|
||||
png_alloc_size_t user_chunk_malloc_max)
|
||||
{
|
||||
if (png_ptr)
|
||||
if (png_ptr != NULL)
|
||||
png_ptr->user_chunk_malloc_max = user_chunk_malloc_max;
|
||||
}
|
||||
#endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
|
||||
#endif /* ?SET_USER_LIMITS */
|
||||
|
||||
|
||||
#ifdef PNG_BENIGN_ERRORS_SUPPORTED
|
||||
@@ -1525,7 +1621,7 @@ png_set_benign_errors(png_structrp png_ptr, int allowed)
|
||||
* is the default behavior if png_set_benign_errors() is not called).
|
||||
*/
|
||||
|
||||
if (allowed)
|
||||
if (allowed != 0)
|
||||
png_ptr->flags |= PNG_FLAG_BENIGN_ERRORS_WARN |
|
||||
PNG_FLAG_APP_WARNINGS_WARN | PNG_FLAG_APP_ERRORS_WARN;
|
||||
|
||||
@@ -1533,14 +1629,14 @@ png_set_benign_errors(png_structrp png_ptr, int allowed)
|
||||
png_ptr->flags &= ~(PNG_FLAG_BENIGN_ERRORS_WARN |
|
||||
PNG_FLAG_APP_WARNINGS_WARN | PNG_FLAG_APP_ERRORS_WARN);
|
||||
}
|
||||
#endif /* PNG_BENIGN_ERRORS_SUPPORTED */
|
||||
#endif /* BENIGN_ERRORS */
|
||||
|
||||
#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 zeroes
|
||||
* 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.
|
||||
*/
|
||||
@@ -1556,4 +1652,4 @@ png_set_check_for_invalid_index(png_structrp png_ptr, int allowed)
|
||||
png_ptr->num_palette_max = -1;
|
||||
}
|
||||
#endif
|
||||
#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
|
||||
#endif /* READ || WRITE */
|
||||
|
||||
657
pngstruct.h
657
pngstruct.h
@@ -1,11 +1,11 @@
|
||||
|
||||
/* pngstruct.h - header file for PNG reference library
|
||||
*
|
||||
* Copyright (c) 1998-2012 Glenn Randers-Pehrson
|
||||
* Copyright (c) 1998-2014 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.)
|
||||
*
|
||||
* Last changed in libpng 1.6.0 [(PENDING RELEASE)]
|
||||
* 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
|
||||
@@ -28,7 +28,9 @@
|
||||
/* We must ensure that zlib uses 'const' in declarations. */
|
||||
# define ZLIB_CONST
|
||||
#endif
|
||||
#include "zlib.h"
|
||||
|
||||
#include PNG_ZLIB_HEADER
|
||||
|
||||
#ifdef const
|
||||
/* zlib.h sometimes #defines const to nothing, undo this. */
|
||||
# undef const
|
||||
@@ -48,10 +50,10 @@
|
||||
/* zlib.h declares a magic type 'uInt' that limits the amount of data that zlib
|
||||
* can handle at once. This type need be no larger than 16 bits (so maximum of
|
||||
* 65535), this define allows us to discover how big it is, but limited by the
|
||||
* maximuum for png_size_t. The value can be overriden in a library build
|
||||
* (pngusr.h, or set it in CPPFLAGS) and it works to set it to a considerably
|
||||
* lower value (e.g. 255 works). A lower value may help memory usage (slightly)
|
||||
* and may even improve performance on some systems (and degrade it on others.)
|
||||
* maximum for size_t. The value can be overridden in a library build (pngusr.h,
|
||||
* or set it in CPPFLAGS) and it works to set it to a considerably lower value
|
||||
* (e.g. 255 works). A lower value may help memory usage (slightly) and may
|
||||
* even improve performance on some systems (and degrade it on others.)
|
||||
*/
|
||||
#ifndef ZLIB_IO_MAX
|
||||
# define ZLIB_IO_MAX ((uInt)-1)
|
||||
@@ -100,7 +102,7 @@ typedef struct png_XYZ
|
||||
} png_XYZ;
|
||||
#endif /* COLORSPACE */
|
||||
|
||||
#if defined PNG_COLORSPACE_SUPPORTED || defined PNG_GAMMA_SUPPORTED
|
||||
#if defined(PNG_COLORSPACE_SUPPORTED) || defined(PNG_GAMMA_SUPPORTED)
|
||||
/* A colorspace is all the above plus, potentially, profile information,
|
||||
* however at present libpng does not use the profile internally so it is only
|
||||
* stored in the png_info struct (if iCCP is supported.) The rendering intent
|
||||
@@ -137,313 +139,239 @@ typedef const png_colorspace * PNG_RESTRICT png_const_colorspacerp;
|
||||
#define PNG_COLORSPACE_FROM_sRGB 0x0020
|
||||
#define PNG_COLORSPACE_ENDPOINTS_MATCH_sRGB 0x0040
|
||||
#define PNG_COLORSPACE_MATCHES_sRGB 0x0080 /* exact match on profile */
|
||||
#define PNG_COLORSPACE_RGB_TO_GRAY_SET 0x0100 /* user specified coeffs */
|
||||
#define PNG_COLORSPACE_INVALID 0x8000
|
||||
#define PNG_COLORSPACE_CANCEL(flags) (0xffff ^ (flags))
|
||||
#endif /* COLORSPACE || GAMMA */
|
||||
|
||||
struct png_struct_def
|
||||
{
|
||||
/* Rearranged in libpng 1.7 to attempt to lessen padding; in general
|
||||
* (char), (short), (int) and pointer types are kept separate, however
|
||||
* associated members under the control of the same #define are still
|
||||
* together.
|
||||
*/
|
||||
#ifdef PNG_SETJMP_SUPPORTED
|
||||
jmp_buf jmp_buf_local; /* New name in 1.6.0 for jmp_buf in png_struct */
|
||||
png_longjmp_ptr longjmp_fn;/* setjmp non-local goto function. */
|
||||
jmp_buf *jmp_buf_ptr; /* passed to longjmp_fn */
|
||||
size_t jmp_buf_size; /* size of the above, if allocated */
|
||||
#endif
|
||||
png_error_ptr error_fn; /* function for printing errors and aborting */
|
||||
#ifdef PNG_WARNINGS_SUPPORTED
|
||||
png_error_ptr warning_fn; /* function for printing warnings */
|
||||
#endif
|
||||
png_voidp error_ptr; /* user supplied struct for error functions */
|
||||
png_rw_ptr write_data_fn; /* function for writing output data */
|
||||
png_rw_ptr read_data_fn; /* function for reading input data */
|
||||
png_voidp io_ptr; /* ptr to application struct for I/O functions */
|
||||
|
||||
#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
|
||||
png_user_transform_ptr read_user_transform_fn; /* user read transform */
|
||||
/* jmp_buf can have very high alignment requirements on some systems, so put
|
||||
* it first (the other setjmp members are later as they are infrequently
|
||||
* accesed.)
|
||||
*/
|
||||
jmp_buf jmp_buf_local;
|
||||
#endif
|
||||
|
||||
#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
|
||||
png_user_transform_ptr write_user_transform_fn; /* user write transform */
|
||||
#endif
|
||||
/* Next the frequently accessed fields. Many processors perform arithmetic
|
||||
* in the address pipeline, but frequently the amount of addition or
|
||||
* subtraction is limited. By putting these fields at the head of png_struct
|
||||
* the hope is that such processors will generate code that is both smaller
|
||||
* and faster.
|
||||
*/
|
||||
png_colorp palette; /* palette from the input file */
|
||||
size_t rowbytes; /* size of row in bytes */
|
||||
size_t info_rowbytes; /* cache of updated row bytes */
|
||||
png_uint_32 width; /* width of image in pixels */
|
||||
png_uint_32 height; /* height of image in pixels */
|
||||
png_uint_32 num_rows; /* number of rows in current pass */
|
||||
png_uint_32 usr_width; /* width of row at start of write */
|
||||
png_uint_32 iwidth; /* width of current interlaced row in pixels */
|
||||
png_uint_32 row_number; /* current row in interlace pass */
|
||||
png_uint_32 chunk_name; /* PNG_CHUNK() id of current chunk */
|
||||
png_uint_32 crc; /* current chunk CRC value */
|
||||
png_uint_32 mode; /* tells us where we are in the PNG file */
|
||||
png_uint_32 flags; /* flags indicating various things to libpng */
|
||||
png_uint_32 transformations;/* which transformations to perform */
|
||||
png_uint_32 zowner; /* ID (chunk type) of zstream owner, 0 if none */
|
||||
png_uint_32 free_me; /* items libpng is responsible for freeing */
|
||||
|
||||
/* These were added in libpng-1.0.2 */
|
||||
#ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED
|
||||
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
|
||||
defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
|
||||
png_voidp user_transform_ptr; /* user supplied struct for user transform */
|
||||
png_byte user_transform_depth; /* bit depth of user transformed pixels */
|
||||
png_byte user_transform_channels; /* channels in user transformed pixels */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
png_uint_32 mode; /* tells us where we are in the PNG file */
|
||||
png_uint_32 flags; /* flags indicating various things to libpng */
|
||||
png_uint_32 transformations; /* which transformations to perform */
|
||||
|
||||
png_uint_32 zowner; /* ID (chunk type) of zstream owner, 0 if none */
|
||||
z_stream zstream; /* decompression structure */
|
||||
|
||||
#ifdef PNG_WRITE_SUPPORTED
|
||||
png_compression_bufferp zbuffer_list; /* Created on demand during write */
|
||||
uInt zbuffer_size; /* size of the actual buffer */
|
||||
|
||||
int zlib_level; /* holds zlib compression level */
|
||||
int zlib_method; /* holds zlib compression method */
|
||||
int zlib_window_bits; /* holds zlib compression window bits */
|
||||
int zlib_mem_level; /* holds zlib compression memory level */
|
||||
int zlib_strategy; /* holds zlib compression strategy */
|
||||
#endif
|
||||
/* Added at libpng 1.5.4 */
|
||||
#ifdef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED
|
||||
int zlib_text_level; /* holds zlib compression level */
|
||||
int zlib_text_method; /* holds zlib compression method */
|
||||
int zlib_text_window_bits; /* holds zlib compression window bits */
|
||||
int zlib_text_mem_level; /* holds zlib compression memory level */
|
||||
int zlib_text_strategy; /* holds zlib compression strategy */
|
||||
#endif
|
||||
/* End of material added at libpng 1.5.4 */
|
||||
/* Added at libpng 1.6.0 */
|
||||
#ifdef PNG_WRITE_SUPPORTED
|
||||
int zlib_set_level; /* Actual values set into the zstream on write */
|
||||
int zlib_set_method;
|
||||
int zlib_set_window_bits;
|
||||
int zlib_set_mem_level;
|
||||
int zlib_set_strategy;
|
||||
#endif
|
||||
|
||||
png_uint_32 width; /* width of image in pixels */
|
||||
png_uint_32 height; /* height of image in pixels */
|
||||
png_uint_32 num_rows; /* number of rows in current pass */
|
||||
png_uint_32 usr_width; /* width of row at start of write */
|
||||
png_size_t rowbytes; /* size of row in bytes */
|
||||
png_uint_32 iwidth; /* width of current interlaced row in pixels */
|
||||
png_uint_32 row_number; /* current row in interlace pass */
|
||||
png_uint_32 chunk_name; /* PNG_CHUNK() id of current chunk */
|
||||
png_bytep prev_row; /* buffer to save previous (unfiltered) row.
|
||||
* This is a pointer into big_prev_row
|
||||
*/
|
||||
png_bytep row_buf; /* buffer to save current (unfiltered) row.
|
||||
* This is a pointer into big_row_buf
|
||||
*/
|
||||
#ifdef PNG_WRITE_SUPPORTED
|
||||
png_bytep sub_row; /* buffer to save "sub" row when filtering */
|
||||
png_bytep up_row; /* buffer to save "up" row when filtering */
|
||||
png_bytep avg_row; /* buffer to save "avg" row when filtering */
|
||||
png_bytep paeth_row; /* buffer to save "Paeth" row when filtering */
|
||||
#endif
|
||||
png_size_t info_rowbytes; /* Added in 1.5.4: cache of updated row bytes */
|
||||
|
||||
png_uint_32 idat_size; /* current IDAT size for read */
|
||||
png_uint_32 crc; /* current chunk CRC value */
|
||||
png_colorp palette; /* palette from the input file */
|
||||
png_uint_16 num_palette; /* number of color entries in palette */
|
||||
|
||||
/* Added at libpng-1.5.10 */
|
||||
int maximum_pixel_depth; /* pixel depth used for the row buffers */
|
||||
#ifdef PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED
|
||||
int num_palette_max; /* maximum palette index found in IDAT */
|
||||
int num_palette_max; /* maximum palette index found in IDAT */
|
||||
#endif
|
||||
|
||||
png_uint_16 num_palette; /* number of color entries in palette */
|
||||
png_uint_16 num_trans; /* number of transparency values */
|
||||
png_byte compression; /* file compression type (always 0) */
|
||||
|
||||
/* 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; /* file filter type (always 0) */
|
||||
png_byte interlaced; /* PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
|
||||
png_byte pass; /* current interlace pass (0 - 6) */
|
||||
png_byte do_filter; /* row filter flags (see PNG_FILTER_ below ) */
|
||||
png_byte color_type; /* color type of file */
|
||||
png_byte bit_depth; /* bit depth of file */
|
||||
png_byte usr_bit_depth; /* bit depth of users row: write only */
|
||||
png_byte pixel_depth; /* number of bits per pixel */
|
||||
png_byte channels; /* number of channels in file */
|
||||
#ifdef PNG_WRITE_SUPPORTED
|
||||
png_byte usr_channels; /* channels at start of write: write only */
|
||||
#endif
|
||||
png_byte sig_bytes; /* magic bytes read/written from start of file */
|
||||
png_byte maximum_pixel_depth;
|
||||
/* pixel depth used for the row buffers */
|
||||
png_byte transformed_pixel_depth;
|
||||
/* pixel depth after read/write transforms */
|
||||
#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
|
||||
png_uint_16 filler; /* filler bytes for pixel expansion */
|
||||
|
||||
/* ERROR HANDLING */
|
||||
#ifdef PNG_SETJMP_SUPPORTED
|
||||
jmp_buf *jmp_buf_ptr; /* passed to longjmp_fn */
|
||||
png_longjmp_ptr longjmp_fn; /* setjmp non-local goto function. */
|
||||
size_t jmp_buf_size; /* size of *jmp_buf_ptr, if allocated */
|
||||
#endif
|
||||
|
||||
#if defined(PNG_bKGD_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) ||\
|
||||
defined(PNG_READ_ALPHA_MODE_SUPPORTED)
|
||||
png_byte background_gamma_type;
|
||||
png_fixed_point background_gamma;
|
||||
png_color_16 background; /* background color in screen gamma space */
|
||||
#ifdef PNG_READ_GAMMA_SUPPORTED
|
||||
png_color_16 background_1; /* background normalized to gamma 1.0 */
|
||||
/* Error/warning callbacks */
|
||||
png_error_ptr error_fn; /* print an error message and abort */
|
||||
#ifdef PNG_WARNINGS_SUPPORTED
|
||||
png_error_ptr warning_fn; /* print a warning and continue */
|
||||
#endif
|
||||
png_voidp error_ptr; /* user supplied data for the above */
|
||||
|
||||
/* MEMORY ALLOCATION */
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
png_malloc_ptr malloc_fn; /* allocate memory */
|
||||
png_free_ptr free_fn; /* free memory */
|
||||
png_voidp mem_ptr; /* user supplied data for the above */
|
||||
#endif
|
||||
|
||||
/* IO and BASIC READ/WRITE SUPPORT */
|
||||
png_voidp io_ptr; /* user supplied data for IO callbacks */
|
||||
|
||||
#ifdef PNG_READ_SUPPORTED
|
||||
png_rw_ptr read_data_fn; /* read some bytes (must succeed) */
|
||||
png_read_status_ptr read_row_fn; /* called after each row is decoded */
|
||||
png_bytep read_buffer; /* buffer for reading chunk data */
|
||||
|
||||
/* During read the following array is set up to point to the appropriate
|
||||
* un-filter function, this allows per-image and per-processor optimization.
|
||||
*/
|
||||
void (*read_filter[PNG_FILTER_VALUE_LAST-1])(png_row_infop row_info,
|
||||
png_bytep row, png_const_bytep prev_row);
|
||||
|
||||
#if defined(PNG_COLORSPACE_SUPPORTED) || defined(PNG_GAMMA_SUPPORTED)
|
||||
/* The png_struct colorspace structure is only required on read - on write it
|
||||
* is in (just) the info_struct.
|
||||
*/
|
||||
png_colorspace colorspace;
|
||||
#endif
|
||||
#endif /* PNG_READ_SUPPORTED */
|
||||
|
||||
#ifdef PNG_SET_USER_LIMITS_SUPPORTED
|
||||
png_uint_32 user_width_max; /* Maximum width on read */
|
||||
png_uint_32 user_height_max; /* Maximum height on read */
|
||||
/* Total memory that a single zTXt, sPLT, iTXt, iCCP, or unknown chunk
|
||||
* can occupy when decompressed. 0 means unlimited. This field is a counter
|
||||
* - it is decremented as memory is allocated.
|
||||
*/
|
||||
png_alloc_size_t user_chunk_malloc_max;
|
||||
#endif
|
||||
#ifdef PNG_USER_LIMITS_SUPPORTED
|
||||
/* limit on total *number* of sPLT, text and unknown chunks that can be
|
||||
* stored. 0 means unlimited. This field is a counter - it is decremented
|
||||
* as chunks are encountered.
|
||||
*/
|
||||
png_uint_32 user_chunk_cache_max;
|
||||
#endif
|
||||
|
||||
/* The progressive reader gets passed data and calls application handling
|
||||
* functions when appropriate.
|
||||
*/
|
||||
#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
|
||||
png_progressive_info_ptr info_fn; /* called after header data fully read */
|
||||
png_progressive_row_ptr row_fn; /* called after a row is decoded */
|
||||
png_progressive_end_ptr end_fn; /* called after image is complete */
|
||||
|
||||
/* Progressive read control data */
|
||||
png_bytep save_buffer_ptr; /* current location in save_buffer */
|
||||
png_bytep save_buffer; /* buffer for previously read data */
|
||||
png_bytep current_buffer_ptr; /* current location in current_buffer */
|
||||
png_bytep current_buffer; /* buffer for recently used data */
|
||||
|
||||
size_t save_buffer_size; /* amount of data now in save_buffer */
|
||||
size_t save_buffer_max; /* total size of save_buffer */
|
||||
size_t buffer_size; /* total amount of available input data */
|
||||
size_t current_buffer_size; /* amount of data now in current_buffer */
|
||||
|
||||
png_uint_32 push_length; /* size of current input chunk */
|
||||
png_uint_32 skip_length; /* bytes to skip in input data */
|
||||
|
||||
int process_mode; /* what push library is currently doing */
|
||||
int cur_palette; /* current push library palette index */
|
||||
#endif
|
||||
|
||||
#ifdef PNG_WRITE_SUPPORTED
|
||||
png_rw_ptr write_data_fn;/* write some bytes (must succeed) */
|
||||
png_write_status_ptr write_row_fn; /* called after each row is encoded */
|
||||
#endif
|
||||
#endif /* PNG_bKGD_SUPPORTED */
|
||||
|
||||
#ifdef PNG_WRITE_FLUSH_SUPPORTED
|
||||
png_flush_ptr output_flush_fn; /* Function for flushing output */
|
||||
png_uint_32 flush_dist; /* how many rows apart to flush, 0 - no flush */
|
||||
png_uint_32 flush_rows; /* number of rows written since last flush */
|
||||
#endif
|
||||
|
||||
#ifdef PNG_READ_GAMMA_SUPPORTED
|
||||
int gamma_shift; /* number of "insignificant" bits in 16-bit gamma */
|
||||
png_fixed_point screen_gamma; /* screen gamma value (display_exponent) */
|
||||
|
||||
png_bytep gamma_table; /* gamma table for 8-bit depth files */
|
||||
png_uint_16pp gamma_16_table; /* gamma table for 16-bit depth files */
|
||||
#if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
|
||||
defined(PNG_READ_ALPHA_MODE_SUPPORTED) || \
|
||||
defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
|
||||
png_bytep gamma_from_1; /* converts from 1.0 to screen */
|
||||
png_bytep gamma_to_1; /* converts from file to 1.0 */
|
||||
png_uint_16pp gamma_16_from_1; /* converts from 1.0 to screen */
|
||||
png_uint_16pp gamma_16_to_1; /* converts from file to 1.0 */
|
||||
#endif /* READ_BACKGROUND || READ_ALPHA_MODE || RGB_TO_GRAY */
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_sBIT_SUPPORTED)
|
||||
png_color_8 sig_bit; /* significant bits in each available channel */
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
|
||||
png_color_8 shift; /* shift for significant bit tranformation */
|
||||
#endif
|
||||
|
||||
#if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) \
|
||||
|| defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
|
||||
png_bytep trans_alpha; /* alpha values for paletted files */
|
||||
png_color_16 trans_color; /* transparent color for non-paletted files */
|
||||
#endif
|
||||
|
||||
png_read_status_ptr read_row_fn; /* called after each row is decoded */
|
||||
png_write_status_ptr write_row_fn; /* called after each row is encoded */
|
||||
#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
|
||||
png_progressive_info_ptr info_fn; /* called after header data fully read */
|
||||
png_progressive_row_ptr row_fn; /* called after a prog. row is decoded */
|
||||
png_progressive_end_ptr end_fn; /* called after image is complete */
|
||||
png_bytep save_buffer_ptr; /* current location in save_buffer */
|
||||
png_bytep save_buffer; /* buffer for previously read data */
|
||||
png_bytep current_buffer_ptr; /* current location in current_buffer */
|
||||
png_bytep current_buffer; /* buffer for recently used data */
|
||||
png_uint_32 push_length; /* size of current input chunk */
|
||||
png_uint_32 skip_length; /* bytes to skip in input data */
|
||||
png_size_t save_buffer_size; /* amount of data now in save_buffer */
|
||||
png_size_t save_buffer_max; /* total size of save_buffer */
|
||||
png_size_t buffer_size; /* total amount of available input data */
|
||||
png_size_t current_buffer_size; /* amount of data now in current_buffer */
|
||||
int process_mode; /* what push library is currently doing */
|
||||
int cur_palette; /* current push library palette index */
|
||||
|
||||
#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
|
||||
|
||||
#if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
|
||||
/* For the Borland special 64K segment handler */
|
||||
png_bytepp offset_table_ptr;
|
||||
png_bytep offset_table;
|
||||
png_uint_16 offset_table_number;
|
||||
png_uint_16 offset_table_count;
|
||||
png_uint_16 offset_table_count_free;
|
||||
#endif
|
||||
|
||||
#ifdef PNG_READ_QUANTIZE_SUPPORTED
|
||||
png_bytep palette_lookup; /* lookup table for quantizing */
|
||||
png_bytep quantize_index; /* index translation for palette files */
|
||||
png_uint_32 flush_dist; /* how many rows apart to flush, 0 - no flush */
|
||||
png_uint_32 flush_rows; /* number of rows written since last flush */
|
||||
#endif
|
||||
|
||||
#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
|
||||
png_byte heuristic_method; /* heuristic for row filter selection */
|
||||
png_byte num_prev_filters; /* number of weights for previous rows */
|
||||
png_bytep prev_filters; /* filter type(s) of previous row(s) */
|
||||
png_bytep prev_filters; /* filter type(s) of previous row(s) */
|
||||
png_uint_16p filter_weights; /* weight(s) for previous line(s) */
|
||||
png_uint_16p inv_filter_weights; /* 1/weight(s) for previous line(s) */
|
||||
png_uint_16p filter_costs; /* relative filter calculation cost */
|
||||
png_uint_16p inv_filter_costs; /* 1/relative filter calculation cost */
|
||||
png_byte heuristic_method; /* heuristic for row filter selection */
|
||||
png_byte num_prev_filters; /* number of weights for previous rows */
|
||||
#endif
|
||||
|
||||
#if PNG_LIBPNG_VER < 10700
|
||||
/* To do: remove this from libpng-1.7 */
|
||||
#ifdef PNG_TIME_RFC1123_SUPPORTED
|
||||
char time_buffer[29]; /* String to hold RFC 1123 time text */
|
||||
#endif
|
||||
#ifdef PNG_WRITE_SUPPORTED
|
||||
png_byte usr_bit_depth; /* bit depth of users row */
|
||||
png_byte usr_channels; /* channels at start of write */
|
||||
#endif
|
||||
|
||||
/* New members added in libpng-1.0.6 */
|
||||
#ifdef PNG_IO_STATE_SUPPORTED
|
||||
png_uint_32 io_state; /* tells the app read/write progress */
|
||||
#endif
|
||||
|
||||
png_uint_32 free_me; /* flags items libpng is responsible for freeing */
|
||||
/* ROW BUFFERS
|
||||
*
|
||||
* Members that hold pointers to the decompressed image rows.
|
||||
*/
|
||||
png_bytep row_buf; /* buffer for the current (unfiltered) row */
|
||||
#if defined(PNG_WRITE_FILTER_SUPPORTED) || defined(PNG_READ_SUPPORTED)
|
||||
png_bytep prev_row; /* buffer to save the previous (unfiltered) row */
|
||||
#endif
|
||||
|
||||
#ifdef PNG_READ_SUPPORTED
|
||||
/* The row_buf and prev_row pointers are misaligned so that the start of the
|
||||
* row - after the filter byte - is aligned, the 'big_' pointers record the
|
||||
* original allocated pointer.
|
||||
*/
|
||||
png_bytep big_row_buf;
|
||||
png_bytep big_prev_row;
|
||||
size_t big_row_buf_size; /* Actual size of both */
|
||||
#endif
|
||||
|
||||
#ifdef PNG_WRITE_SUPPORTED
|
||||
/* This is somewhat excessive, there is no obvious reason on write to
|
||||
* allocate a buffer for each possible filtered row, only for the one being
|
||||
* tested and the current best.
|
||||
*
|
||||
* TODO: fix this
|
||||
*/
|
||||
png_bytep sub_row; /* buffer to save "sub" row when filtering */
|
||||
png_bytep up_row; /* buffer to save "up" row when filtering */
|
||||
png_bytep avg_row; /* buffer to save "avg" row when filtering */
|
||||
png_bytep paeth_row; /* buffer to save "Paeth" row when filtering */
|
||||
#endif
|
||||
|
||||
/* UNKNOWN CHUNK HANDLING */
|
||||
/* TODO: this is excessively complicated, there are multiple ways of doing
|
||||
* the same thing. It should be cleaned up, possibly by finding out which
|
||||
* APIs applications really use.
|
||||
*/
|
||||
#ifdef PNG_USER_CHUNKS_SUPPORTED
|
||||
/* General purpose pointer for all user/unknown chunk handling; points to
|
||||
* application supplied data for use in the read_user_chunk_fn callback
|
||||
* (currently there is no write side support - the write side must use the
|
||||
* set_unknown_chunks interface.)
|
||||
*/
|
||||
png_voidp user_chunk_ptr;
|
||||
#endif
|
||||
|
||||
#ifdef PNG_READ_USER_CHUNKS_SUPPORTED
|
||||
png_user_chunk_ptr read_user_chunk_fn; /* user read chunk handler */
|
||||
/* This is called back from the unknown chunk handling */
|
||||
png_user_chunk_ptr read_user_chunk_fn; /* user read chunk handler */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED
|
||||
int unknown_default; /* As PNG_HANDLE_* */
|
||||
unsigned int num_chunk_list; /* Number of entries in the list */
|
||||
png_bytep chunk_list; /* List of png_byte[5]; the textual chunk name
|
||||
* followed by a PNG_HANDLE_* byte */
|
||||
#endif
|
||||
|
||||
/* New members added in libpng-1.0.3 */
|
||||
#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
|
||||
png_byte rgb_to_gray_status;
|
||||
/* Added in libpng 1.5.5 to record setting of coefficients: */
|
||||
png_byte rgb_to_gray_coefficients_set;
|
||||
/* These were changed from png_byte in libpng-1.0.6 */
|
||||
png_uint_16 rgb_to_gray_red_coeff;
|
||||
png_uint_16 rgb_to_gray_green_coeff;
|
||||
/* deleted in 1.5.5: rgb_to_gray_blue_coeff; */
|
||||
#endif
|
||||
|
||||
/* New member added in libpng-1.0.4 (renamed in 1.0.9) */
|
||||
#if defined(PNG_MNG_FEATURES_SUPPORTED)
|
||||
/* Changed from png_byte to png_uint_32 at version 1.2.0 */
|
||||
png_uint_32 mng_features_permitted;
|
||||
#endif
|
||||
|
||||
/* New member added in libpng-1.0.9, ifdef'ed out in 1.0.12, enabled in 1.2.0 */
|
||||
#ifdef PNG_MNG_FEATURES_SUPPORTED
|
||||
png_byte filter_type;
|
||||
#endif
|
||||
|
||||
/* New members added in libpng-1.2.0 */
|
||||
|
||||
/* New members added in libpng-1.0.2 but first enabled by default in 1.2.0 */
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
png_voidp mem_ptr; /* user supplied struct for mem functions */
|
||||
png_malloc_ptr malloc_fn; /* function for allocating memory */
|
||||
png_free_ptr free_fn; /* function for freeing memory */
|
||||
#endif
|
||||
|
||||
/* New member added in libpng-1.0.13 and 1.2.0 */
|
||||
png_bytep big_row_buf; /* buffer to save current (unfiltered) row */
|
||||
|
||||
#ifdef PNG_READ_QUANTIZE_SUPPORTED
|
||||
/* The following three members were added at version 1.0.14 and 1.2.4 */
|
||||
png_bytep quantize_sort; /* working sort array */
|
||||
png_bytep index_to_palette; /* where the original index currently is
|
||||
in the palette */
|
||||
png_bytep palette_to_index; /* which original index points to this
|
||||
palette color */
|
||||
#endif
|
||||
|
||||
/* New members added in libpng-1.0.16 and 1.2.6 */
|
||||
png_byte compression_type;
|
||||
|
||||
#ifdef PNG_USER_LIMITS_SUPPORTED
|
||||
png_uint_32 user_width_max;
|
||||
png_uint_32 user_height_max;
|
||||
|
||||
/* Added in libpng-1.4.0: Total number of sPLT, text, and unknown
|
||||
* chunks that can be stored (0 means unlimited).
|
||||
*/
|
||||
png_uint_32 user_chunk_cache_max;
|
||||
|
||||
/* Total memory that a zTXt, sPLT, iTXt, iCCP, or unknown chunk
|
||||
* can occupy when decompressed. 0 means unlimited.
|
||||
*/
|
||||
png_alloc_size_t user_chunk_malloc_max;
|
||||
#endif
|
||||
|
||||
/* New member added in libpng-1.0.25 and 1.2.17 */
|
||||
#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
|
||||
/* Temporary storage for unknown chunk that the library doesn't recognize,
|
||||
* used while reading the chunk.
|
||||
@@ -451,33 +379,182 @@ struct png_struct_def
|
||||
png_unknown_chunk unknown_chunk;
|
||||
#endif
|
||||
|
||||
/* New member added in libpng-1.2.26 */
|
||||
png_size_t old_big_row_buf_size;
|
||||
#ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED
|
||||
png_bytep chunk_list; /* List of png_byte[5]; the textual chunk name
|
||||
* followed by a PNG_HANDLE_* byte */
|
||||
int unknown_default; /* As PNG_HANDLE_* */
|
||||
unsigned int num_chunk_list; /* Number of entries in the list */
|
||||
#endif
|
||||
|
||||
/* USER TRANSFORM SUPPORT */
|
||||
#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
|
||||
png_user_transform_ptr read_user_transform_fn; /* user read transform */
|
||||
#endif
|
||||
#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
|
||||
png_user_transform_ptr write_user_transform_fn; /* user write transform */
|
||||
#endif
|
||||
#ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED
|
||||
png_voidp user_transform_ptr; /* user supplied data for the above */
|
||||
png_byte user_transform_depth; /* bit depth of user transformed pixels */
|
||||
png_byte user_transform_channels; /* channels in user transformed pixels */
|
||||
#endif
|
||||
|
||||
/* READ TRANSFORM SUPPORT
|
||||
*
|
||||
* Quite a lot of things can be done to the original image data on read, and
|
||||
* most of these are configurable. The data required by the configurable
|
||||
* read transforms should be stored here. The png_color_16 and png_color_8
|
||||
* structures have low alignment requirements and odd sizes, so may cause
|
||||
* misalignment when present. Member alignment is as follows:
|
||||
*
|
||||
* png_color_16 png_uint_16
|
||||
* png_color_8 png_byte
|
||||
*/
|
||||
/* GAMMA/BACKGROUND/ALPHA-MODE/RGB-TO-GRAY/tRNS/sBIT
|
||||
*
|
||||
* These things are all interrelated because they need some or all of the
|
||||
* gamma tables. Some attempt has been made below to order these members by
|
||||
* size, so that as little padding as possible is required.
|
||||
*/
|
||||
#ifdef PNG_READ_GAMMA_SUPPORTED
|
||||
png_bytep gamma_table; /* gamma table for 8-bit depth files */
|
||||
png_uint_16p gamma_16_table; /* gamma table for 16-bit depth files */
|
||||
|
||||
#if defined(PNG_READ_BACKGROUND_SUPPORTED) ||\
|
||||
defined(PNG_READ_ALPHA_MODE_SUPPORTED) ||\
|
||||
defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
|
||||
png_bytep gamma_from_1; /* converts from 1.0 to screen */
|
||||
png_uint_16p gamma_to_1; /* converts from file to 1.0 */
|
||||
png_uint_16p gamma_16_from_1; /* converts from 1.0 to screen */
|
||||
png_uint_16p gamma_16_to_1; /* converts from file to 1.0 */
|
||||
#endif /* READ_BACKGROUND || READ_ALPHA_MODE || RGB_TO_GRAY */
|
||||
#endif /* PNG_READ_GAMMA_SUPPORTED */
|
||||
|
||||
#if defined(PNG_READ_tRNS_SUPPORTED) || \
|
||||
defined(PNG_READ_BACKGROUND_SUPPORTED) || \
|
||||
defined(PNG_READ_EXPAND_SUPPORTED)
|
||||
png_bytep trans_alpha; /* alpha values for paletted files */
|
||||
#endif
|
||||
|
||||
/* Integer values */
|
||||
#if defined(PNG_READ_BACKGROUND_SUPPORTED) ||\
|
||||
defined(PNG_READ_ALPHA_MODE_SUPPORTED)
|
||||
png_fixed_point background_gamma;
|
||||
#endif
|
||||
#ifdef PNG_READ_GAMMA_SUPPORTED
|
||||
png_fixed_point screen_gamma; /* screen gamma value (display_exponent) */
|
||||
int gamma_shift; /* number of "insignificant" bits in 16-bit gamma */
|
||||
#endif
|
||||
|
||||
/* png_color_16 */
|
||||
#if defined(PNG_READ_BACKGROUND_SUPPORTED) ||\
|
||||
defined(PNG_READ_ALPHA_MODE_SUPPORTED)
|
||||
png_color_16 background; /* background color in screen gamma space */
|
||||
png_color_16 background_1; /* background normalized to gamma 1.0 */
|
||||
#endif
|
||||
#if defined(PNG_READ_tRNS_SUPPORTED) || \
|
||||
defined(PNG_READ_BACKGROUND_SUPPORTED) || \
|
||||
defined(PNG_READ_EXPAND_SUPPORTED)
|
||||
png_color_16 trans_color; /* transparent color for non-paletted files */
|
||||
#endif
|
||||
|
||||
/* png_uint_16 */
|
||||
#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
|
||||
png_uint_16 rgb_to_gray_red_coeff;
|
||||
png_uint_16 rgb_to_gray_green_coeff;
|
||||
/* The blue coefficient is calculated from the above */
|
||||
#endif
|
||||
|
||||
/* png_color_8 */
|
||||
#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_sBIT_SUPPORTED)
|
||||
png_color_8 sig_bit; /* significant bits in each available channel */
|
||||
#endif
|
||||
|
||||
/* png_byte */
|
||||
#if defined(PNG_READ_BACKGROUND_SUPPORTED) ||\
|
||||
defined(PNG_READ_ALPHA_MODE_SUPPORTED)
|
||||
png_byte background_gamma_type;
|
||||
#endif
|
||||
#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
|
||||
png_byte rgb_to_gray_status;
|
||||
#endif
|
||||
|
||||
/* SHIFT - both READ_SHIFT and WRITE_SHIFT */
|
||||
#if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
|
||||
png_color_8 shift; /* shift for significant bit tranformation */
|
||||
#endif
|
||||
|
||||
/* FILLER SUPPORT (pixel expansion or read, contraction on write) */
|
||||
#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
|
||||
png_uint_16 filler; /* filler bytes for pixel expansion */
|
||||
#endif
|
||||
|
||||
/* QUANTIZE (convert to color-mapped) */
|
||||
#ifdef PNG_READ_QUANTIZE_SUPPORTED
|
||||
png_bytep palette_lookup; /* lookup table for quantizing */
|
||||
png_bytep quantize_index; /* index translation for palette files */
|
||||
png_bytep quantize_sort; /* working sort array */
|
||||
png_bytep index_to_palette; /* where the original index currently is in the
|
||||
* palette
|
||||
*/
|
||||
png_bytep palette_to_index; /* which original index points to this palette
|
||||
* color
|
||||
*/
|
||||
#endif
|
||||
|
||||
/* MNG SUPPORT */
|
||||
#ifdef PNG_MNG_FEATURES_SUPPORTED
|
||||
png_uint_32 mng_features_permitted;
|
||||
png_byte filter_type;
|
||||
#endif
|
||||
|
||||
/* Options */
|
||||
#ifdef PNG_SET_OPTION_SUPPORTED
|
||||
png_byte options; /* On/off state (up to 4 options) */
|
||||
#endif
|
||||
|
||||
/* COMPRESSION AND DECOMPRESSION SUPPORT.
|
||||
*
|
||||
* zlib expects a 'zstream' as the fundamental control structure, it allows
|
||||
* all the parameters to be passed as one pointer.
|
||||
*/
|
||||
z_stream zstream; /* decompression structure */
|
||||
|
||||
#ifdef PNG_READ_SUPPORTED
|
||||
/* New member added in libpng-1.2.30 */
|
||||
png_bytep read_buffer; /* buffer for reading chunk data */
|
||||
png_alloc_size_t read_buffer_size; /* current size of the buffer */
|
||||
/* These, and IDAT_read_size below, control how much input and output (at
|
||||
* most) is available to zlib.
|
||||
*/
|
||||
png_uint_32 idat_size; /* current IDAT size for read */
|
||||
png_alloc_size_t read_buffer_size; /* current size of the buffer */
|
||||
#endif
|
||||
|
||||
#ifdef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED
|
||||
int zlib_text_level; /* holds zlib compression level */
|
||||
int zlib_text_method; /* holds zlib compression method */
|
||||
int zlib_text_window_bits; /* holds zlib compression window bits */
|
||||
int zlib_text_mem_level; /* holds zlib compression memory level */
|
||||
int zlib_text_strategy; /* holds zlib compression strategy */
|
||||
#endif
|
||||
|
||||
#ifdef PNG_WRITE_SUPPORTED
|
||||
int zlib_level; /* holds zlib compression level */
|
||||
int zlib_method; /* holds zlib compression method */
|
||||
int zlib_window_bits; /* holds zlib compression window bits */
|
||||
int zlib_mem_level; /* holds zlib compression memory level */
|
||||
int zlib_strategy; /* holds zlib compression strategy */
|
||||
|
||||
int zlib_set_level; /* Actual values set into the zstream on write */
|
||||
int zlib_set_method;
|
||||
int zlib_set_window_bits;
|
||||
int zlib_set_mem_level;
|
||||
int zlib_set_strategy;
|
||||
|
||||
png_compression_bufferp zbuffer_list; /* Created on demand during write */
|
||||
uInt zbuffer_size; /* size of the actual zlib buffer */
|
||||
#endif
|
||||
|
||||
#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
|
||||
uInt IDAT_read_size; /* limit on read buffer size for IDAT */
|
||||
#endif
|
||||
|
||||
#ifdef PNG_IO_STATE_SUPPORTED
|
||||
/* New member added in libpng-1.4.0 */
|
||||
png_uint_32 io_state;
|
||||
#endif
|
||||
|
||||
/* New member added in libpng-1.5.6 */
|
||||
png_bytep big_prev_row;
|
||||
|
||||
void (*read_filter[PNG_FILTER_VALUE_LAST-1])(png_row_infop row_info,
|
||||
png_bytep row, png_const_bytep prev_row);
|
||||
|
||||
#ifdef PNG_READ_SUPPORTED
|
||||
#if defined PNG_COLORSPACE_SUPPORTED || defined PNG_GAMMA_SUPPORTED
|
||||
png_colorspace colorspace;
|
||||
#endif
|
||||
uInt IDAT_read_size; /* limit on read buffer size for IDAT */
|
||||
#endif
|
||||
};
|
||||
#endif /* PNGSTRUCT_H */
|
||||
|
||||
263
pngtest.c
263
pngtest.c
@@ -1,8 +1,8 @@
|
||||
|
||||
/* pngtest.c - a simple test program to test libpng
|
||||
*
|
||||
* Last changed in libpng 1.6.0 [(PENDING RELEASE)]
|
||||
* Copyright (c) 1998-2012 Glenn Randers-Pehrson
|
||||
* Last changed in libpng 1.6.15 [(PENDING RELEASE)]
|
||||
* Copyright (c) 1998-2014 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.)
|
||||
*
|
||||
@@ -43,8 +43,35 @@
|
||||
|
||||
#include "png.h"
|
||||
|
||||
#ifdef PNG_READ_SUPPORTED /* else nothing can be done */
|
||||
#include "zlib.h"
|
||||
/* Known chunks that exist in pngtest.png must be supported or pngtest will fail
|
||||
* simply as a result of re-ordering them. This may be fixed in 1.7
|
||||
*
|
||||
* pngtest allocates a single row buffer for each row and overwrites it,
|
||||
* therefore if the write side doesn't support the writing of interlaced images
|
||||
* nothing can be done for an interlaced image (and the code below will fail
|
||||
* horribly trying to write extra data after writing garbage).
|
||||
*/
|
||||
#if defined PNG_READ_SUPPORTED && /* else nothing can be done */\
|
||||
defined PNG_READ_bKGD_SUPPORTED &&\
|
||||
defined PNG_READ_cHRM_SUPPORTED &&\
|
||||
defined PNG_READ_gAMA_SUPPORTED &&\
|
||||
defined PNG_READ_oFFs_SUPPORTED &&\
|
||||
defined PNG_READ_pCAL_SUPPORTED &&\
|
||||
defined PNG_READ_pHYs_SUPPORTED &&\
|
||||
defined PNG_READ_sBIT_SUPPORTED &&\
|
||||
defined PNG_READ_sCAL_SUPPORTED &&\
|
||||
defined PNG_READ_sRGB_SUPPORTED &&\
|
||||
defined PNG_READ_tEXt_SUPPORTED &&\
|
||||
defined PNG_READ_tIME_SUPPORTED &&\
|
||||
defined PNG_READ_zTXt_SUPPORTED &&\
|
||||
defined PNG_WRITE_INTERLACING_SUPPORTED
|
||||
|
||||
#ifdef PNG_ZLIB_HEADER
|
||||
# include PNG_ZLIB_HEADER /* defined by pnglibconf.h from 1.7 */
|
||||
#else
|
||||
# include "zlib.h"
|
||||
#endif
|
||||
|
||||
/* Copied from pngpriv.h but only used in error messages below. */
|
||||
#ifndef PNG_ZBUF_SIZE
|
||||
# define PNG_ZBUF_SIZE 8192
|
||||
@@ -100,10 +127,6 @@ static int unsupported_chunks = 0; /* chunk unsupported by libpng in input */
|
||||
static int error_count = 0; /* count calls to png_error */
|
||||
static int warning_count = 0; /* count calls to png_warning */
|
||||
|
||||
#ifdef __TURBOC__
|
||||
#include <mem.h>
|
||||
#endif
|
||||
|
||||
/* Define png_jmpbuf() in case we are using a pre-1.0.6 version of libpng */
|
||||
#ifndef png_jmpbuf
|
||||
# define png_jmpbuf(png_ptr) png_ptr->jmpbuf
|
||||
@@ -260,7 +283,8 @@ count_zero_samples(png_structp png_ptr, png_row_infop row_info, png_bytep data)
|
||||
png_uint_32 n, nstop;
|
||||
int channel;
|
||||
int color_channels = row_info->channels;
|
||||
if (row_info->color_type > 3)color_channels--;
|
||||
if (row_info->color_type > 3)
|
||||
color_channels--;
|
||||
|
||||
for (n = 0, nstop=row_info->width; n<nstop; n++)
|
||||
{
|
||||
@@ -287,7 +311,7 @@ count_zero_samples(png_structp png_ptr, png_row_infop row_info, png_bytep data)
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* PNG_WRITE_USER_TRANSFORM_SUPPORTED */
|
||||
#endif /* WRITE_USER_TRANSFORM */
|
||||
|
||||
#ifndef PNG_STDIO_SUPPORTED
|
||||
/* START of code to validate stdio-free compilation */
|
||||
@@ -336,7 +360,7 @@ pngtest_check_io_state(png_structp png_ptr, png_size_t data_length,
|
||||
default:
|
||||
err = 1; /* uninitialized */
|
||||
}
|
||||
if (err)
|
||||
if (err != 0)
|
||||
png_error(png_ptr, "Bad I/O state or buffer size");
|
||||
}
|
||||
#endif
|
||||
@@ -396,7 +420,7 @@ pngtest_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
pngtest_check_io_state(png_ptr, length, PNG_IO_WRITING);
|
||||
#endif
|
||||
}
|
||||
#endif /* !PNG_STDIO_SUPPORTED */
|
||||
#endif /* !STDIO */
|
||||
|
||||
/* This function is called when there is a warning, but the library thinks
|
||||
* it can continue anyway. Replacement functions don't have to do anything
|
||||
@@ -517,7 +541,7 @@ PNGCBAPI png_debug_malloc(png_structp png_ptr, png_alloc_size_t size)
|
||||
/* Make sure the caller isn't assuming zeroed memory. */
|
||||
memset(pinfo->pointer, 0xdd, pinfo->size);
|
||||
|
||||
if (verbose)
|
||||
if (verbose != 0)
|
||||
printf("png_malloc %lu bytes at %p\n", (unsigned long)size,
|
||||
pinfo->pointer);
|
||||
|
||||
@@ -557,14 +581,15 @@ png_debug_free(png_structp png_ptr, png_voidp ptr)
|
||||
/* We must free the list element too, but first kill
|
||||
the memory that is to be freed. */
|
||||
memset(ptr, 0x55, pinfo->size);
|
||||
png_free_default(png_ptr, pinfo);
|
||||
if (pinfo != NULL)
|
||||
free(pinfo);
|
||||
pinfo = NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
if (pinfo->next == NULL)
|
||||
{
|
||||
fprintf(STDERR, "Pointer %x not found\n", (unsigned int)ptr);
|
||||
fprintf(STDERR, "Pointer %p not found\n", ptr);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -573,13 +598,14 @@ png_debug_free(png_structp png_ptr, png_voidp ptr)
|
||||
}
|
||||
|
||||
/* Finally free the data. */
|
||||
if (verbose)
|
||||
if (verbose != 0)
|
||||
printf("Freeing %p\n", ptr);
|
||||
|
||||
png_free_default(png_ptr, ptr);
|
||||
if (ptr != NULL)
|
||||
free(ptr);
|
||||
ptr = NULL;
|
||||
}
|
||||
#endif /* PNG_USER_MEM_SUPPORTED && PNG_DEBUG */
|
||||
#endif /* USER_MEM && DEBUG */
|
||||
/* END of code to test memory allocation/deallocation */
|
||||
|
||||
|
||||
@@ -618,16 +644,16 @@ set_location(png_structp png_ptr, struct user_chunk_data *data, int what)
|
||||
{
|
||||
int location;
|
||||
|
||||
if ((data->location[0] & what) || (data->location[1] & what))
|
||||
if ((data->location[0] & what) != 0 || (data->location[1] & what) != 0)
|
||||
return 0; /* already have one of these */
|
||||
|
||||
/* Find where we are (the code below zeros info_ptr to indicate that the
|
||||
/* Find where we are (the code below zeroes info_ptr to indicate that the
|
||||
* chunks before the first IDAT have been read.)
|
||||
*/
|
||||
if (data->info_ptr == NULL) /* after IDAT */
|
||||
location = what | after_IDAT;
|
||||
|
||||
else if (png_get_valid(png_ptr, data->info_ptr, PNG_INFO_PLTE))
|
||||
else if (png_get_valid(png_ptr, data->info_ptr, PNG_INFO_PLTE) != 0)
|
||||
location = what | before_IDAT;
|
||||
|
||||
else
|
||||
@@ -642,8 +668,8 @@ set_location(png_structp png_ptr, struct user_chunk_data *data, int what)
|
||||
return 1; /* handled */
|
||||
}
|
||||
|
||||
static int PNGCBAPI read_user_chunk_callback(png_struct *png_ptr,
|
||||
png_unknown_chunkp chunk)
|
||||
static int PNGCBAPI
|
||||
read_user_chunk_callback(png_struct *png_ptr, png_unknown_chunkp chunk)
|
||||
{
|
||||
struct user_chunk_data *my_user_chunk_data =
|
||||
(struct user_chunk_data*)png_get_user_chunk_ptr(png_ptr);
|
||||
@@ -674,7 +700,7 @@ static int PNGCBAPI read_user_chunk_callback(png_struct *png_ptr,
|
||||
if (chunk->data[0] != 0 && chunk->data[0] != 1)
|
||||
return (-1); /* Invalid mode */
|
||||
|
||||
if (set_location(png_ptr, my_user_chunk_data, have_sTER))
|
||||
if (set_location(png_ptr, my_user_chunk_data, have_sTER) != 0)
|
||||
{
|
||||
my_user_chunk_data->sTER_mode=chunk->data[0];
|
||||
return (1);
|
||||
@@ -693,7 +719,7 @@ static int PNGCBAPI read_user_chunk_callback(png_struct *png_ptr,
|
||||
if (chunk->size != 9)
|
||||
return (-1); /* Error return */
|
||||
|
||||
if (!set_location(png_ptr, my_user_chunk_data, have_vpAg))
|
||||
if (set_location(png_ptr, my_user_chunk_data, have_vpAg) == 0)
|
||||
return (0); /* duplicate vpAg */
|
||||
|
||||
my_user_chunk_data->vpAg_width = png_get_uint_31(png_ptr, chunk->data);
|
||||
@@ -707,22 +733,22 @@ static int PNGCBAPI read_user_chunk_callback(png_struct *png_ptr,
|
||||
static void
|
||||
write_sTER_chunk(png_structp write_ptr)
|
||||
{
|
||||
png_byte png_sTER[5] = {115, 84, 69, 82, '\0'};
|
||||
png_byte sTER[5] = {115, 84, 69, 82, '\0'};
|
||||
|
||||
if (verbose)
|
||||
if (verbose != 0)
|
||||
fprintf(STDERR, "\n stereo mode = %d\n", user_chunk_data.sTER_mode);
|
||||
|
||||
png_write_chunk(write_ptr, png_sTER, &user_chunk_data.sTER_mode, 1);
|
||||
png_write_chunk(write_ptr, sTER, &user_chunk_data.sTER_mode, 1);
|
||||
}
|
||||
|
||||
static void
|
||||
write_vpAg_chunk(png_structp write_ptr)
|
||||
{
|
||||
png_byte png_vpAg[5] = {118, 112, 65, 103, '\0'};
|
||||
png_byte vpAg[5] = {118, 112, 65, 103, '\0'};
|
||||
|
||||
png_byte vpag_chunk_data[9];
|
||||
|
||||
if (verbose)
|
||||
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,
|
||||
@@ -731,7 +757,7 @@ write_vpAg_chunk(png_structp write_ptr)
|
||||
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);
|
||||
vpag_chunk_data[8] = user_chunk_data.vpAg_units;
|
||||
png_write_chunk(write_ptr, png_vpAg, vpag_chunk_data, 9);
|
||||
png_write_chunk(write_ptr, vpAg, vpag_chunk_data, 9);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -754,8 +780,8 @@ write_chunks(png_structp write_ptr, int location)
|
||||
write_vpAg_chunk(write_ptr);
|
||||
}
|
||||
}
|
||||
#endif /* PNG_WRITE_SUPPORTED */
|
||||
#else /* !PNG_READ_USER_CHUNKS_SUPPORTED */
|
||||
#endif /* WRITE */
|
||||
#else /* !READ_USER_CHUNKS */
|
||||
# define write_chunks(pp,loc) ((void)0)
|
||||
#endif
|
||||
/* END of code to demonstrate user chunk support */
|
||||
@@ -812,6 +838,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
png_structp write_ptr;
|
||||
png_infop write_info_ptr;
|
||||
png_infop write_end_info_ptr;
|
||||
int interlace_preserved = 1;
|
||||
#else
|
||||
png_structp write_ptr = NULL;
|
||||
png_infop write_info_ptr = NULL;
|
||||
@@ -820,7 +847,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
png_bytep row_buf;
|
||||
png_uint_32 y;
|
||||
png_uint_32 width, height;
|
||||
int num_pass, pass;
|
||||
int num_pass = 1, pass;
|
||||
int bit_depth, color_type;
|
||||
|
||||
row_buf = NULL;
|
||||
@@ -912,7 +939,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (strict)
|
||||
if (strict != 0)
|
||||
{
|
||||
/* Treat png_benign_error() as errors on read */
|
||||
png_set_benign_errors(read_ptr, 0);
|
||||
@@ -928,7 +955,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
*/
|
||||
}
|
||||
|
||||
else if (relaxed)
|
||||
else if (relaxed != 0)
|
||||
{
|
||||
/* Allow application (pngtest) errors and warnings to pass */
|
||||
png_set_benign_errors(read_ptr, 1);
|
||||
@@ -1023,13 +1050,29 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
int interlace_type, compression_type, filter_type;
|
||||
|
||||
if (png_get_IHDR(read_ptr, read_info_ptr, &width, &height, &bit_depth,
|
||||
&color_type, &interlace_type, &compression_type, &filter_type))
|
||||
&color_type, &interlace_type, &compression_type, &filter_type) != 0)
|
||||
{
|
||||
png_set_IHDR(write_ptr, write_info_ptr, width, height, bit_depth,
|
||||
#ifdef PNG_WRITE_INTERLACING_SUPPORTED
|
||||
color_type, interlace_type, compression_type, filter_type);
|
||||
#else
|
||||
color_type, PNG_INTERLACE_NONE, compression_type, filter_type);
|
||||
#ifndef PNG_READ_INTERLACING_SUPPORTED
|
||||
/* num_pass will not be set below, set it here if the image is
|
||||
* interlaced: what happens is that write interlacing is *not* turned
|
||||
* on an the partial interlaced rows are written directly.
|
||||
*/
|
||||
switch (interlace_type)
|
||||
{
|
||||
case PNG_INTERLACE_NONE:
|
||||
num_pass = 1;
|
||||
break;
|
||||
|
||||
case PNG_INTERLACE_ADAM7:
|
||||
num_pass = 7;
|
||||
break;
|
||||
|
||||
default:
|
||||
png_error(read_ptr, "invalid interlace type");
|
||||
/*NOT REACHED*/
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -1040,7 +1083,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
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))
|
||||
&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);
|
||||
@@ -1051,7 +1094,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
{
|
||||
png_fixed_point gamma;
|
||||
|
||||
if (png_get_gAMA_fixed(read_ptr, read_info_ptr, &gamma))
|
||||
if (png_get_gAMA_fixed(read_ptr, read_info_ptr, &gamma) != 0)
|
||||
png_set_gAMA_fixed(write_ptr, write_info_ptr, gamma);
|
||||
}
|
||||
#endif
|
||||
@@ -1063,7 +1106,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
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))
|
||||
&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);
|
||||
@@ -1074,7 +1117,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
{
|
||||
double gamma;
|
||||
|
||||
if (png_get_gAMA(read_ptr, read_info_ptr, &gamma))
|
||||
if (png_get_gAMA(read_ptr, read_info_ptr, &gamma) != 0)
|
||||
png_set_gAMA(write_ptr, write_info_ptr, gamma);
|
||||
}
|
||||
#endif
|
||||
@@ -1088,7 +1131,7 @@ 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))
|
||||
&profile, &proflen) != 0)
|
||||
{
|
||||
png_set_iCCP(write_ptr, write_info_ptr, name, compression_type,
|
||||
profile, proflen);
|
||||
@@ -1099,7 +1142,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
{
|
||||
int intent;
|
||||
|
||||
if (png_get_sRGB(read_ptr, read_info_ptr, &intent))
|
||||
if (png_get_sRGB(read_ptr, read_info_ptr, &intent) != 0)
|
||||
png_set_sRGB(write_ptr, write_info_ptr, intent);
|
||||
}
|
||||
#endif
|
||||
@@ -1107,14 +1150,14 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
png_colorp palette;
|
||||
int num_palette;
|
||||
|
||||
if (png_get_PLTE(read_ptr, read_info_ptr, &palette, &num_palette))
|
||||
if (png_get_PLTE(read_ptr, read_info_ptr, &palette, &num_palette) != 0)
|
||||
png_set_PLTE(write_ptr, write_info_ptr, palette, num_palette);
|
||||
}
|
||||
#ifdef PNG_bKGD_SUPPORTED
|
||||
{
|
||||
png_color_16p background;
|
||||
|
||||
if (png_get_bKGD(read_ptr, read_info_ptr, &background))
|
||||
if (png_get_bKGD(read_ptr, read_info_ptr, &background) != 0)
|
||||
{
|
||||
png_set_bKGD(write_ptr, write_info_ptr, background);
|
||||
}
|
||||
@@ -1124,7 +1167,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
{
|
||||
png_uint_16p hist;
|
||||
|
||||
if (png_get_hIST(read_ptr, read_info_ptr, &hist))
|
||||
if (png_get_hIST(read_ptr, read_info_ptr, &hist) != 0)
|
||||
png_set_hIST(write_ptr, write_info_ptr, hist);
|
||||
}
|
||||
#endif
|
||||
@@ -1134,7 +1177,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
int unit_type;
|
||||
|
||||
if (png_get_oFFs(read_ptr, read_info_ptr, &offset_x, &offset_y,
|
||||
&unit_type))
|
||||
&unit_type) != 0)
|
||||
{
|
||||
png_set_oFFs(write_ptr, write_info_ptr, offset_x, offset_y, unit_type);
|
||||
}
|
||||
@@ -1148,7 +1191,7 @@ 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))
|
||||
&nparams, &units, ¶ms) != 0)
|
||||
{
|
||||
png_set_pCAL(write_ptr, write_info_ptr, purpose, X0, X1, type,
|
||||
nparams, units, params);
|
||||
@@ -1160,7 +1203,8 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
png_uint_32 res_x, res_y;
|
||||
int unit_type;
|
||||
|
||||
if (png_get_pHYs(read_ptr, read_info_ptr, &res_x, &res_y, &unit_type))
|
||||
if (png_get_pHYs(read_ptr, read_info_ptr, &res_x, &res_y,
|
||||
&unit_type) != 0)
|
||||
png_set_pHYs(write_ptr, write_info_ptr, res_x, res_y, unit_type);
|
||||
}
|
||||
#endif
|
||||
@@ -1168,18 +1212,19 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
{
|
||||
png_color_8p sig_bit;
|
||||
|
||||
if (png_get_sBIT(read_ptr, read_info_ptr, &sig_bit))
|
||||
if (png_get_sBIT(read_ptr, read_info_ptr, &sig_bit) != 0)
|
||||
png_set_sBIT(write_ptr, write_info_ptr, sig_bit);
|
||||
}
|
||||
#endif
|
||||
#ifdef PNG_sCAL_SUPPORTED
|
||||
#ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
#if defined(PNG_FLOATING_POINT_SUPPORTED) && \
|
||||
defined(PNG_FLOATING_ARITHMETIC_SUPPORTED)
|
||||
{
|
||||
int unit;
|
||||
double scal_width, scal_height;
|
||||
|
||||
if (png_get_sCAL(read_ptr, read_info_ptr, &unit, &scal_width,
|
||||
&scal_height))
|
||||
&scal_height) != 0)
|
||||
{
|
||||
png_set_sCAL(write_ptr, write_info_ptr, unit, scal_width, scal_height);
|
||||
}
|
||||
@@ -1191,7 +1236,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))
|
||||
&scal_height) != 0)
|
||||
{
|
||||
png_set_sCAL_s(write_ptr, write_info_ptr, unit, scal_width,
|
||||
scal_height);
|
||||
@@ -1211,7 +1256,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
|
||||
pngtest_check_text_support(read_ptr, text_ptr, num_text);
|
||||
|
||||
if (verbose)
|
||||
if (verbose != 0)
|
||||
{
|
||||
int i;
|
||||
|
||||
@@ -1231,11 +1276,11 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
{
|
||||
png_timep mod_time;
|
||||
|
||||
if (png_get_tIME(read_ptr, read_info_ptr, &mod_time))
|
||||
if (png_get_tIME(read_ptr, read_info_ptr, &mod_time) != 0)
|
||||
{
|
||||
png_set_tIME(write_ptr, write_info_ptr, mod_time);
|
||||
#ifdef PNG_TIME_RFC1123_SUPPORTED
|
||||
if (png_convert_to_rfc1123_buffer(tIME_string, mod_time))
|
||||
if (png_convert_to_rfc1123_buffer(tIME_string, mod_time) != 0)
|
||||
tIME_string[(sizeof tIME_string) - 1] = '\0';
|
||||
|
||||
else
|
||||
@@ -1245,7 +1290,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
}
|
||||
|
||||
tIME_chunk_present++;
|
||||
#endif /* PNG_TIME_RFC1123_SUPPORTED */
|
||||
#endif /* TIME_RFC1123 */
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1256,7 +1301,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))
|
||||
&trans_color) != 0)
|
||||
{
|
||||
int sample_max = (1 << bit_depth);
|
||||
/* libpng doesn't reject a tRNS chunk with out-of-range samples */
|
||||
@@ -1277,7 +1322,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
int num_unknowns = png_get_unknown_chunks(read_ptr, read_info_ptr,
|
||||
&unknowns);
|
||||
|
||||
if (num_unknowns)
|
||||
if (num_unknowns != 0)
|
||||
{
|
||||
png_set_unknown_chunks(write_ptr, write_info_ptr, unknowns,
|
||||
num_unknowns);
|
||||
@@ -1321,14 +1366,10 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
#endif /* SINGLE_ROWBUF_ALLOC */
|
||||
pngtest_debug("Writing row data");
|
||||
|
||||
#if defined(PNG_READ_INTERLACING_SUPPORTED) || \
|
||||
defined(PNG_WRITE_INTERLACING_SUPPORTED)
|
||||
#ifdef PNG_READ_INTERLACING_SUPPORTED
|
||||
num_pass = png_set_interlace_handling(read_ptr);
|
||||
# ifdef PNG_WRITE_SUPPORTED
|
||||
png_set_interlace_handling(write_ptr);
|
||||
# endif
|
||||
#else
|
||||
num_pass = 1;
|
||||
if (png_set_interlace_handling(write_ptr) != num_pass)
|
||||
png_error(write_ptr, "png_set_interlace_handling: inconsistent num_pass");
|
||||
#endif
|
||||
|
||||
#ifdef PNGTEST_TIMING
|
||||
@@ -1343,11 +1384,12 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
{
|
||||
#ifndef SINGLE_ROWBUF_ALLOC
|
||||
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));
|
||||
|
||||
pngtest_debug2("\t0x%08lx (%u bytes)", (unsigned long)row_buf,
|
||||
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));
|
||||
|
||||
#endif /* !SINGLE_ROWBUF_ALLOC */
|
||||
png_read_rows(read_ptr, (png_bytepp)&row_buf, NULL, 1);
|
||||
@@ -1364,7 +1406,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
t_encode += (t_stop - t_start);
|
||||
t_start = t_stop;
|
||||
#endif
|
||||
#endif /* PNG_WRITE_SUPPORTED */
|
||||
#endif /* WRITE */
|
||||
|
||||
#ifndef SINGLE_ROWBUF_ALLOC
|
||||
pngtest_debug2("Freeing row buffer (pass %d, y = %u)", pass, y);
|
||||
@@ -1374,11 +1416,13 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
|
||||
png_free_data(read_ptr, read_info_ptr, PNG_FREE_UNKN, -1);
|
||||
#endif
|
||||
#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
|
||||
png_free_data(write_ptr, write_info_ptr, PNG_FREE_UNKN, -1);
|
||||
#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
|
||||
# ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
|
||||
png_free_data(read_ptr, read_info_ptr, PNG_FREE_UNKN, -1);
|
||||
# endif
|
||||
# ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
|
||||
png_free_data(write_ptr, write_info_ptr, PNG_FREE_UNKN, -1);
|
||||
# endif
|
||||
#endif
|
||||
|
||||
pngtest_debug("Reading and writing end_info data");
|
||||
@@ -1395,7 +1439,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
|
||||
pngtest_check_text_support(read_ptr, text_ptr, num_text);
|
||||
|
||||
if (verbose)
|
||||
if (verbose != 0)
|
||||
{
|
||||
int i;
|
||||
|
||||
@@ -1415,11 +1459,11 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
{
|
||||
png_timep mod_time;
|
||||
|
||||
if (png_get_tIME(read_ptr, end_info_ptr, &mod_time))
|
||||
if (png_get_tIME(read_ptr, end_info_ptr, &mod_time) != 0)
|
||||
{
|
||||
png_set_tIME(write_ptr, write_end_info_ptr, mod_time);
|
||||
#ifdef PNG_TIME_RFC1123_SUPPORTED
|
||||
if (png_convert_to_rfc1123_buffer(tIME_string, mod_time))
|
||||
if (png_convert_to_rfc1123_buffer(tIME_string, mod_time) != 0)
|
||||
tIME_string[(sizeof tIME_string) - 1] = '\0';
|
||||
|
||||
else
|
||||
@@ -1429,7 +1473,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
}
|
||||
|
||||
tIME_chunk_present++;
|
||||
#endif /* PNG_TIME_RFC1123_SUPPORTED */
|
||||
#endif /* TIME_RFC1123 */
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1439,7 +1483,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
int num_unknowns = png_get_unknown_chunks(read_ptr, end_info_ptr,
|
||||
&unknowns);
|
||||
|
||||
if (num_unknowns)
|
||||
if (num_unknowns != 0)
|
||||
{
|
||||
png_set_unknown_chunks(write_ptr, write_end_info_ptr, unknowns,
|
||||
num_unknowns);
|
||||
@@ -1470,7 +1514,8 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
|
||||
/* When the unknown vpAg/sTER chunks are written by pngtest the only way to
|
||||
* do it is to write them *before* calling png_write_end. When unknown
|
||||
* chunks are written by libpng, however, they are written just before IEND. * There seems to be no way round this, however vpAg/sTER are not expected
|
||||
* chunks are written by libpng, however, they are written just before IEND.
|
||||
* There seems to be no way round this, however vpAg/sTER are not expected
|
||||
* after IDAT.
|
||||
*/
|
||||
write_chunks(write_ptr, after_IDAT);
|
||||
@@ -1479,7 +1524,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
#endif
|
||||
|
||||
#ifdef PNG_EASY_ACCESS_SUPPORTED
|
||||
if (verbose)
|
||||
if (verbose != 0)
|
||||
{
|
||||
png_uint_32 iwidth, iheight;
|
||||
iwidth = png_get_image_width(write_ptr, write_info_ptr);
|
||||
@@ -1557,15 +1602,14 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
}
|
||||
|
||||
#ifdef PNG_WRITE_SUPPORTED /* else nothing was written */
|
||||
if (interlace_preserved != 0) /* else the files will be changed */
|
||||
{
|
||||
int wrote_question = 0;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
static int wrote_question = 0;
|
||||
png_size_t num_in, num_out;
|
||||
char inbuf[256], outbuf[256];
|
||||
|
||||
|
||||
num_in = fread(inbuf, 1, sizeof inbuf, fpin);
|
||||
num_out = fread(outbuf, 1, sizeof outbuf, fpout);
|
||||
|
||||
@@ -1597,7 +1641,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
return (0);
|
||||
}
|
||||
|
||||
if (!num_in)
|
||||
if (num_in == 0)
|
||||
break;
|
||||
|
||||
if (memcmp(inbuf, outbuf, num_in))
|
||||
@@ -1634,7 +1678,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* PNG_WRITE_SUPPORTED */
|
||||
#endif /* WRITE */
|
||||
|
||||
FCLOSE(fpin);
|
||||
FCLOSE(fpout);
|
||||
@@ -1739,10 +1783,11 @@ main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
if (!multiple && argc == 3 + verbose)
|
||||
if (multiple == 0 && argc == 3 + verbose)
|
||||
outname = argv[2 + verbose];
|
||||
|
||||
if ((!multiple && argc > 3 + verbose) || (multiple && argc < 2))
|
||||
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",
|
||||
@@ -1754,7 +1799,7 @@ main(int argc, char *argv[])
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (multiple)
|
||||
if (multiple != 0)
|
||||
{
|
||||
int i;
|
||||
#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
|
||||
@@ -1764,6 +1809,9 @@ main(int argc, char *argv[])
|
||||
{
|
||||
int kerror;
|
||||
fprintf(STDERR, "\n Testing %s:", argv[i]);
|
||||
#if PNG_DEBUG > 0
|
||||
fprintf(STDERR, "\n");
|
||||
#endif
|
||||
kerror = test_one_file(argv[i], outname);
|
||||
if (kerror == 0)
|
||||
{
|
||||
@@ -1778,7 +1826,7 @@ main(int argc, char *argv[])
|
||||
#endif
|
||||
#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
|
||||
for (k = 0; k<256; k++)
|
||||
if (filters_used[k])
|
||||
if (filters_used[k] != 0)
|
||||
fprintf(STDERR, " Filter %d was used %lu times\n",
|
||||
k, (unsigned long)filters_used[k]);
|
||||
#endif
|
||||
@@ -1787,7 +1835,7 @@ main(int argc, char *argv[])
|
||||
fprintf(STDERR, " tIME = %s\n", tIME_string);
|
||||
|
||||
tIME_chunk_present = 0;
|
||||
#endif /* PNG_TIME_RFC1123_SUPPORTED */
|
||||
#endif /* TIME_RFC1123 */
|
||||
}
|
||||
|
||||
else
|
||||
@@ -1809,9 +1857,9 @@ main(int argc, char *argv[])
|
||||
|
||||
while (pinfo != NULL)
|
||||
{
|
||||
fprintf(STDERR, " %lu bytes at %x\n",
|
||||
fprintf(STDERR, " %lu bytes at %p\n",
|
||||
(unsigned long)pinfo->size,
|
||||
(unsigned int)pinfo->pointer);
|
||||
pinfo->pointer);
|
||||
pinfo = pinfo->next;
|
||||
}
|
||||
}
|
||||
@@ -1845,7 +1893,12 @@ main(int argc, char *argv[])
|
||||
status_dots_requested = 0;
|
||||
|
||||
if (i == 0 || verbose == 1 || ierror != 0)
|
||||
{
|
||||
fprintf(STDERR, "\n Testing %s:", inname);
|
||||
#if PNG_DEBUG > 0
|
||||
fprintf(STDERR, "\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
kerror = test_one_file(inname, outname);
|
||||
|
||||
@@ -1864,21 +1917,26 @@ main(int argc, char *argv[])
|
||||
#endif
|
||||
#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
|
||||
for (k = 0; k<256; k++)
|
||||
if (filters_used[k])
|
||||
if (filters_used[k] != 0)
|
||||
fprintf(STDERR, " Filter %d was used %lu times\n",
|
||||
k, (unsigned long)filters_used[k]);
|
||||
#endif
|
||||
#ifdef PNG_TIME_RFC1123_SUPPORTED
|
||||
if (tIME_chunk_present != 0)
|
||||
fprintf(STDERR, " tIME = %s\n", tIME_string);
|
||||
#endif /* PNG_TIME_RFC1123_SUPPORTED */
|
||||
#endif /* TIME_RFC1123 */
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
if (verbose == 0 && i != 2)
|
||||
{
|
||||
fprintf(STDERR, "\n Testing %s:", inname);
|
||||
#if PNG_DEBUG > 0
|
||||
fprintf(STDERR, "\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
fprintf(STDERR, " FAIL\n");
|
||||
ierror += kerror;
|
||||
@@ -1897,8 +1955,8 @@ main(int argc, char *argv[])
|
||||
|
||||
while (pinfo != NULL)
|
||||
{
|
||||
fprintf(STDERR, " %lu bytes at %x\n",
|
||||
(unsigned long)pinfo->size, (unsigned int)pinfo->pointer);
|
||||
fprintf(STDERR, " %lu bytes at %p\n",
|
||||
(unsigned long)pinfo->size, pinfo->pointer);
|
||||
pinfo = pinfo->next;
|
||||
}
|
||||
}
|
||||
@@ -1944,9 +2002,10 @@ main(void)
|
||||
{
|
||||
fprintf(STDERR,
|
||||
" test ignored because libpng was not built with read support\n");
|
||||
return 0;
|
||||
/* 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_6_0beta33 Your_png_h_is_not_version_1_6_0beta33;
|
||||
typedef png_libpng_version_1_7_0beta42 Your_png_h_is_not_version_1_7_0beta42;
|
||||
|
||||
56
pngtrans.c
56
pngtrans.c
@@ -1,8 +1,8 @@
|
||||
|
||||
/* pngtrans.c - transforms the data in a row (used by both readers and writers)
|
||||
*
|
||||
* Last changed in libpng 1.6.0 [(PENDING RELEASE)]
|
||||
* Copyright (c) 1998-2012 Glenn Randers-Pehrson
|
||||
* Last changed in libpng 1.6.15 [(PENDING RELEASE)]
|
||||
* Copyright (c) 1998-2014 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.)
|
||||
*
|
||||
@@ -57,7 +57,9 @@ png_set_packing(png_structrp png_ptr)
|
||||
if (png_ptr->bit_depth < 8)
|
||||
{
|
||||
png_ptr->transformations |= PNG_PACK;
|
||||
png_ptr->usr_bit_depth = 8;
|
||||
# ifdef PNG_WRITE_SUPPORTED
|
||||
png_ptr->usr_bit_depth = 8;
|
||||
# endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -98,7 +100,7 @@ png_set_interlace_handling(png_structrp png_ptr)
|
||||
{
|
||||
png_debug(1, "in png_set_interlace handling");
|
||||
|
||||
if (png_ptr && png_ptr->interlaced)
|
||||
if (png_ptr != 0 && png_ptr->interlaced != 0)
|
||||
{
|
||||
png_ptr->transformations |= PNG_INTERLACE;
|
||||
return (7);
|
||||
@@ -125,7 +127,7 @@ png_set_filler(png_structrp png_ptr, png_uint_32 filler, int filler_loc)
|
||||
/* In libpng 1.6 it is possible to determine whether this is a read or write
|
||||
* operation and therefore to do more checking here for a valid call.
|
||||
*/
|
||||
if (png_ptr->mode & PNG_IS_READ_STRUCT)
|
||||
if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0)
|
||||
{
|
||||
# ifdef PNG_READ_FILLER_SUPPORTED
|
||||
/* On read png_set_filler is always valid, regardless of the base PNG
|
||||
@@ -208,7 +210,7 @@ png_set_add_alpha(png_structrp png_ptr, png_uint_32 filler, int filler_loc)
|
||||
|
||||
png_set_filler(png_ptr, filler, filler_loc);
|
||||
/* The above may fail to do anything. */
|
||||
if (png_ptr->transformations & PNG_FILLER)
|
||||
if ((png_ptr->transformations & PNG_FILLER) != 0)
|
||||
png_ptr->transformations |= PNG_ADD_ALPHA;
|
||||
}
|
||||
|
||||
@@ -325,9 +327,16 @@ png_do_swap(png_row_infop row_info, png_bytep row)
|
||||
|
||||
for (i = 0; i < istop; i++, rp += 2)
|
||||
{
|
||||
#ifdef PNG_BUILTIN_BSWAP16_SUPPORTED
|
||||
/* Feature added to libpng-1.6.11 for testing purposes, not
|
||||
* enabled by default.
|
||||
*/
|
||||
*(png_uint_16*)rp = __builtin_bswap16(*(png_uint_16*)rp);
|
||||
#else
|
||||
png_byte t = *rp;
|
||||
*rp = *(rp + 1);
|
||||
*(rp + 1) = t;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -469,7 +478,7 @@ png_do_packswap(png_row_infop row_info, png_bytep row)
|
||||
*rp = table[*rp];
|
||||
}
|
||||
}
|
||||
#endif /* PNG_READ_PACKSWAP_SUPPORTED or PNG_WRITE_PACKSWAP_SUPPORTED */
|
||||
#endif /* READ_PACKSWAP or WRITE_PACKSWAP */
|
||||
|
||||
#if defined(PNG_WRITE_FILLER_SUPPORTED) || \
|
||||
defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
|
||||
@@ -501,7 +510,7 @@ png_do_strip_channel(png_row_infop row_info, png_bytep row, int at_start)
|
||||
{
|
||||
if (row_info->bit_depth == 8)
|
||||
{
|
||||
if (at_start) /* Skip initial filler */
|
||||
if (at_start != 0) /* Skip initial filler */
|
||||
++sp;
|
||||
else /* Skip initial channel and, for sp, the filler */
|
||||
sp += 2, ++dp;
|
||||
@@ -515,7 +524,7 @@ png_do_strip_channel(png_row_infop row_info, png_bytep row, int at_start)
|
||||
|
||||
else if (row_info->bit_depth == 16)
|
||||
{
|
||||
if (at_start) /* Skip initial filler */
|
||||
if (at_start != 0) /* Skip initial filler */
|
||||
sp += 2;
|
||||
else /* Skip initial channel and, for sp, the filler */
|
||||
sp += 4, dp += 2;
|
||||
@@ -541,7 +550,7 @@ png_do_strip_channel(png_row_infop row_info, png_bytep row, int at_start)
|
||||
{
|
||||
if (row_info->bit_depth == 8)
|
||||
{
|
||||
if (at_start) /* Skip initial filler */
|
||||
if (at_start != 0) /* Skip initial filler */
|
||||
++sp;
|
||||
else /* Skip initial channels and, for sp, the filler */
|
||||
sp += 4, dp += 3;
|
||||
@@ -555,7 +564,7 @@ png_do_strip_channel(png_row_infop row_info, png_bytep row, int at_start)
|
||||
|
||||
else if (row_info->bit_depth == 16)
|
||||
{
|
||||
if (at_start) /* Skip initial filler */
|
||||
if (at_start != 0) /* Skip initial filler */
|
||||
sp += 2;
|
||||
else /* Skip initial channels and, for sp, the filler */
|
||||
sp += 8, dp += 6;
|
||||
@@ -596,7 +605,7 @@ png_do_bgr(png_row_infop row_info, png_bytep row)
|
||||
{
|
||||
png_debug(1, "in png_do_bgr");
|
||||
|
||||
if ((row_info->color_type & PNG_COLOR_MASK_COLOR))
|
||||
if ((row_info->color_type & PNG_COLOR_MASK_COLOR) != 0)
|
||||
{
|
||||
png_uint_32 row_width = row_info->width;
|
||||
if (row_info->bit_depth == 8)
|
||||
@@ -666,7 +675,7 @@ png_do_bgr(png_row_infop row_info, png_bytep row)
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif /* PNG_READ_BGR_SUPPORTED or PNG_WRITE_BGR_SUPPORTED */
|
||||
#endif /* READ_BGR or WRITE_BGR */
|
||||
|
||||
#if defined(PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED) || \
|
||||
defined(PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED)
|
||||
@@ -769,7 +778,7 @@ png_do_check_palette_indexes(png_structrp png_ptr, png_row_infop row_info)
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED */
|
||||
#endif /* CHECK_FOR_INVALID_INDEX */
|
||||
|
||||
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
|
||||
defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
|
||||
@@ -782,6 +791,17 @@ png_set_user_transform_info(png_structrp png_ptr, png_voidp
|
||||
|
||||
if (png_ptr == NULL)
|
||||
return;
|
||||
|
||||
#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
|
||||
if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0 &&
|
||||
(png_ptr->flags & PNG_FLAG_ROW_INIT) != 0)
|
||||
{
|
||||
png_app_error(png_ptr,
|
||||
"info change after png_start_read_image or png_read_update_info");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
png_ptr->user_transform_ptr = user_transform_ptr;
|
||||
png_ptr->user_transform_depth = (png_byte)user_transform_depth;
|
||||
png_ptr->user_transform_channels = (png_byte)user_transform_channels;
|
||||
@@ -808,7 +828,7 @@ png_get_user_transform_ptr(png_const_structrp png_ptr)
|
||||
png_uint_32 PNGAPI
|
||||
png_get_current_row_number(png_const_structrp png_ptr)
|
||||
{
|
||||
/* See the comments in png.h - this is the sub-image row when reading and
|
||||
/* See the comments in png.h - this is the sub-image row when reading an
|
||||
* interlaced image.
|
||||
*/
|
||||
if (png_ptr != NULL)
|
||||
@@ -824,7 +844,7 @@ png_get_current_pass_number(png_const_structrp png_ptr)
|
||||
return png_ptr->pass;
|
||||
return 8; /* invalid */
|
||||
}
|
||||
#endif /* PNG_USER_TRANSFORM_INFO_SUPPORTED */
|
||||
#endif /* PNG_READ_USER_TRANSFORM_SUPPORTED ||
|
||||
#endif /* USER_TRANSFORM_INFO */
|
||||
#endif /* READ_USER_TRANSFORM ||
|
||||
PNG_WRITE_USER_TRANSFORM_SUPPORTED */
|
||||
#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
|
||||
#endif /* READ || WRITE */
|
||||
|
||||
12
pngwio.c
12
pngwio.c
@@ -1,8 +1,8 @@
|
||||
|
||||
/* pngwio.c - functions for data output
|
||||
*
|
||||
* Last changed in libpng 1.6.0 [(PENDING RELEASE)]
|
||||
* Copyright (c) 1998-2012 Glenn Randers-Pehrson
|
||||
* Last changed in libpng 1.6.9 [February 6, 2014]
|
||||
* Copyright (c) 1998-2014 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.)
|
||||
*
|
||||
@@ -149,8 +149,11 @@ png_set_write_fn(png_structrp png_ptr, png_voidp io_ptr,
|
||||
# else
|
||||
png_ptr->output_flush_fn = output_flush_fn;
|
||||
# endif
|
||||
#endif /* PNG_WRITE_FLUSH_SUPPORTED */
|
||||
#else
|
||||
PNG_UNUSED(output_flush_fn)
|
||||
#endif /* WRITE_FLUSH */
|
||||
|
||||
#ifdef PNG_READ_SUPPORTED
|
||||
/* It is an error to read while writing a png file */
|
||||
if (png_ptr->read_data_fn != NULL)
|
||||
{
|
||||
@@ -160,5 +163,6 @@ png_set_write_fn(png_structrp png_ptr, png_voidp io_ptr,
|
||||
"Can't set both read_data_fn and write_data_fn in the"
|
||||
" same structure");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif /* PNG_WRITE_SUPPORTED */
|
||||
#endif /* WRITE */
|
||||
|
||||
637
pngwrite.c
637
pngwrite.c
File diff suppressed because it is too large
Load Diff
219
pngwtran.c
219
pngwtran.c
@@ -1,8 +1,8 @@
|
||||
|
||||
/* pngwtran.c - transforms the data in a row for PNG writers
|
||||
*
|
||||
* Last changed in libpng 1.6.0 [(PENDING RELEASE)]
|
||||
* Copyright (c) 1998-2012 Glenn Randers-Pehrson
|
||||
* Last changed in libpng 1.6.9 [February 6, 2014]
|
||||
* Copyright (c) 1998-2014 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.)
|
||||
*
|
||||
@@ -14,90 +14,14 @@
|
||||
#include "pngpriv.h"
|
||||
|
||||
#ifdef PNG_WRITE_SUPPORTED
|
||||
|
||||
#ifdef PNG_WRITE_TRANSFORMS_SUPPORTED
|
||||
/* Transform the data according to the user's wishes. The order of
|
||||
* transformations is significant.
|
||||
*/
|
||||
void /* PRIVATE */
|
||||
png_do_write_transformations(png_structrp png_ptr, png_row_infop row_info)
|
||||
{
|
||||
png_debug(1, "in png_do_write_transformations");
|
||||
|
||||
if (png_ptr == NULL)
|
||||
return;
|
||||
|
||||
#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
|
||||
if (png_ptr->transformations & PNG_USER_TRANSFORM)
|
||||
if (png_ptr->write_user_transform_fn != NULL)
|
||||
(*(png_ptr->write_user_transform_fn)) /* User write transform
|
||||
function */
|
||||
(png_ptr, /* png_ptr */
|
||||
row_info, /* row_info: */
|
||||
/* png_uint_32 width; width of row */
|
||||
/* png_size_t rowbytes; number of bytes in row */
|
||||
/* png_byte color_type; color type of pixels */
|
||||
/* png_byte bit_depth; bit depth of samples */
|
||||
/* png_byte channels; number of channels (1-4) */
|
||||
/* png_byte pixel_depth; bits per pixel (depth*channels) */
|
||||
png_ptr->row_buf + 1); /* start of pixel data for row */
|
||||
#endif
|
||||
|
||||
#ifdef PNG_WRITE_FILLER_SUPPORTED
|
||||
if (png_ptr->transformations & PNG_FILLER)
|
||||
png_do_strip_channel(row_info, png_ptr->row_buf + 1,
|
||||
!(png_ptr->flags & PNG_FLAG_FILLER_AFTER));
|
||||
#endif
|
||||
|
||||
#ifdef PNG_WRITE_PACKSWAP_SUPPORTED
|
||||
if (png_ptr->transformations & PNG_PACKSWAP)
|
||||
png_do_packswap(row_info, png_ptr->row_buf + 1);
|
||||
#endif
|
||||
|
||||
#ifdef PNG_WRITE_PACK_SUPPORTED
|
||||
if (png_ptr->transformations & PNG_PACK)
|
||||
png_do_pack(row_info, png_ptr->row_buf + 1,
|
||||
(png_uint_32)png_ptr->bit_depth);
|
||||
#endif
|
||||
|
||||
#ifdef PNG_WRITE_SWAP_SUPPORTED
|
||||
if (png_ptr->transformations & PNG_SWAP_BYTES)
|
||||
png_do_swap(row_info, png_ptr->row_buf + 1);
|
||||
#endif
|
||||
|
||||
#ifdef PNG_WRITE_SHIFT_SUPPORTED
|
||||
if (png_ptr->transformations & PNG_SHIFT)
|
||||
png_do_shift(row_info, png_ptr->row_buf + 1,
|
||||
&(png_ptr->shift));
|
||||
#endif
|
||||
|
||||
#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED
|
||||
if (png_ptr->transformations & PNG_SWAP_ALPHA)
|
||||
png_do_write_swap_alpha(row_info, png_ptr->row_buf + 1);
|
||||
#endif
|
||||
|
||||
#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED
|
||||
if (png_ptr->transformations & PNG_INVERT_ALPHA)
|
||||
png_do_write_invert_alpha(row_info, png_ptr->row_buf + 1);
|
||||
#endif
|
||||
|
||||
#ifdef PNG_WRITE_BGR_SUPPORTED
|
||||
if (png_ptr->transformations & PNG_BGR)
|
||||
png_do_bgr(row_info, png_ptr->row_buf + 1);
|
||||
#endif
|
||||
|
||||
#ifdef PNG_WRITE_INVERT_SUPPORTED
|
||||
if (png_ptr->transformations & PNG_INVERT_MONO)
|
||||
png_do_invert(row_info, png_ptr->row_buf + 1);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef PNG_WRITE_PACK_SUPPORTED
|
||||
/* Pack pixels into bytes. Pass the true bit depth in bit_depth. The
|
||||
* row_info bit depth should be 8 (one pixel per byte). The channels
|
||||
* should be 1 (this only happens on grayscale and paletted images).
|
||||
*/
|
||||
void /* PRIVATE */
|
||||
static void
|
||||
png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth)
|
||||
{
|
||||
png_debug(1, "in png_do_pack");
|
||||
@@ -242,7 +166,7 @@ png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth)
|
||||
* would pass 3 as bit_depth, and this routine would translate the
|
||||
* data to 0 to 15.
|
||||
*/
|
||||
void /* PRIVATE */
|
||||
static void
|
||||
png_do_shift(png_row_infop row_info, png_bytep row,
|
||||
png_const_color_8p bit_depth)
|
||||
{
|
||||
@@ -253,7 +177,7 @@ png_do_shift(png_row_infop row_info, png_bytep row,
|
||||
int shift_start[4], shift_dec[4];
|
||||
int channels = 0;
|
||||
|
||||
if (row_info->color_type & PNG_COLOR_MASK_COLOR)
|
||||
if ((row_info->color_type & PNG_COLOR_MASK_COLOR) != 0)
|
||||
{
|
||||
shift_start[channels] = row_info->bit_depth - bit_depth->red;
|
||||
shift_dec[channels] = bit_depth->red;
|
||||
@@ -275,7 +199,7 @@ png_do_shift(png_row_infop row_info, png_bytep row,
|
||||
channels++;
|
||||
}
|
||||
|
||||
if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
|
||||
if ((row_info->color_type & PNG_COLOR_MASK_ALPHA) != 0)
|
||||
{
|
||||
shift_start[channels] = row_info->bit_depth - bit_depth->alpha;
|
||||
shift_dec[channels] = bit_depth->alpha;
|
||||
@@ -381,7 +305,7 @@ png_do_shift(png_row_infop row_info, png_bytep row,
|
||||
#endif
|
||||
|
||||
#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED
|
||||
void /* PRIVATE */
|
||||
static void
|
||||
png_do_write_swap_alpha(png_row_infop row_info, png_bytep row)
|
||||
{
|
||||
png_debug(1, "in png_do_write_swap_alpha");
|
||||
@@ -429,7 +353,7 @@ png_do_write_swap_alpha(png_row_infop row_info, png_bytep row)
|
||||
*(dp++) = save[1];
|
||||
}
|
||||
}
|
||||
#endif /* PNG_WRITE_16BIT_SUPPORTED */
|
||||
#endif /* WRITE_16BIT */
|
||||
}
|
||||
|
||||
else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
|
||||
@@ -468,14 +392,14 @@ png_do_write_swap_alpha(png_row_infop row_info, png_bytep row)
|
||||
*(dp++) = save[1];
|
||||
}
|
||||
}
|
||||
#endif /* PNG_WRITE_16BIT_SUPPORTED */
|
||||
#endif /* WRITE_16BIT */
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED
|
||||
void /* PRIVATE */
|
||||
static void
|
||||
png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
|
||||
{
|
||||
png_debug(1, "in png_do_write_invert_alpha");
|
||||
@@ -525,7 +449,7 @@ png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
|
||||
*(dp++) = (png_byte)(255 - *(sp++));
|
||||
}
|
||||
}
|
||||
#endif /* PNG_WRITE_16BIT_SUPPORTED */
|
||||
#endif /* WRITE_16BIT */
|
||||
}
|
||||
|
||||
else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
|
||||
@@ -563,75 +487,88 @@ png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
|
||||
*(dp++) = (png_byte)(255 - *(sp++));
|
||||
}
|
||||
}
|
||||
#endif /* PNG_WRITE_16BIT_SUPPORTED */
|
||||
#endif /* WRITE_16BIT */
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif /* PNG_WRITE_TRANSFORMS_SUPPORTED */
|
||||
|
||||
#ifdef PNG_MNG_FEATURES_SUPPORTED
|
||||
/* Undoes intrapixel differencing */
|
||||
/* Transform the data according to the user's wishes. The order of
|
||||
* transformations is significant.
|
||||
*/
|
||||
void /* PRIVATE */
|
||||
png_do_write_intrapixel(png_row_infop row_info, png_bytep row)
|
||||
png_do_write_transformations(png_structrp png_ptr, png_row_infop row_info)
|
||||
{
|
||||
png_debug(1, "in png_do_write_intrapixel");
|
||||
png_debug(1, "in png_do_write_transformations");
|
||||
|
||||
if ((row_info->color_type & PNG_COLOR_MASK_COLOR))
|
||||
{
|
||||
int bytes_per_pixel;
|
||||
png_uint_32 row_width = row_info->width;
|
||||
if (row_info->bit_depth == 8)
|
||||
{
|
||||
png_bytep rp;
|
||||
png_uint_32 i;
|
||||
if (png_ptr == NULL)
|
||||
return;
|
||||
|
||||
if (row_info->color_type == PNG_COLOR_TYPE_RGB)
|
||||
bytes_per_pixel = 3;
|
||||
#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
|
||||
if ((png_ptr->transformations & PNG_USER_TRANSFORM) != 0)
|
||||
if (png_ptr->write_user_transform_fn != NULL)
|
||||
(*(png_ptr->write_user_transform_fn)) /* User write transform
|
||||
function */
|
||||
(png_ptr, /* png_ptr */
|
||||
row_info, /* row_info: */
|
||||
/* png_uint_32 width; width of row */
|
||||
/* png_size_t rowbytes; number of bytes in row */
|
||||
/* png_byte color_type; color type of pixels */
|
||||
/* png_byte bit_depth; bit depth of samples */
|
||||
/* png_byte channels; number of channels (1-4) */
|
||||
/* png_byte pixel_depth; bits per pixel (depth*channels) */
|
||||
png_ptr->row_buf + 1); /* start of pixel data for row */
|
||||
#endif
|
||||
|
||||
else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
|
||||
bytes_per_pixel = 4;
|
||||
#ifdef PNG_WRITE_FILLER_SUPPORTED
|
||||
if ((png_ptr->transformations & PNG_FILLER) != 0)
|
||||
png_do_strip_channel(row_info, png_ptr->row_buf + 1,
|
||||
!(png_ptr->flags & PNG_FLAG_FILLER_AFTER));
|
||||
#endif
|
||||
|
||||
else
|
||||
return;
|
||||
#ifdef PNG_WRITE_PACKSWAP_SUPPORTED
|
||||
if ((png_ptr->transformations & PNG_PACKSWAP) != 0)
|
||||
png_do_packswap(row_info, png_ptr->row_buf + 1);
|
||||
#endif
|
||||
|
||||
for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
|
||||
{
|
||||
*(rp) = (png_byte)((*rp - *(rp + 1)) & 0xff);
|
||||
*(rp + 2) = (png_byte)((*(rp + 2) - *(rp + 1)) & 0xff);
|
||||
}
|
||||
}
|
||||
#ifdef PNG_WRITE_PACK_SUPPORTED
|
||||
if ((png_ptr->transformations & PNG_PACK) != 0)
|
||||
png_do_pack(row_info, png_ptr->row_buf + 1,
|
||||
(png_uint_32)png_ptr->bit_depth);
|
||||
#endif
|
||||
|
||||
#ifdef PNG_WRITE_16BIT_SUPPORTED
|
||||
else if (row_info->bit_depth == 16)
|
||||
{
|
||||
png_bytep rp;
|
||||
png_uint_32 i;
|
||||
#ifdef PNG_WRITE_SWAP_SUPPORTED
|
||||
# ifdef PNG_16BIT_SUPPORTED
|
||||
if ((png_ptr->transformations & PNG_SWAP_BYTES) != 0)
|
||||
png_do_swap(row_info, png_ptr->row_buf + 1);
|
||||
# endif
|
||||
#endif
|
||||
|
||||
if (row_info->color_type == PNG_COLOR_TYPE_RGB)
|
||||
bytes_per_pixel = 6;
|
||||
#ifdef PNG_WRITE_SHIFT_SUPPORTED
|
||||
if ((png_ptr->transformations & PNG_SHIFT) != 0)
|
||||
png_do_shift(row_info, png_ptr->row_buf + 1,
|
||||
&(png_ptr->shift));
|
||||
#endif
|
||||
|
||||
else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
|
||||
bytes_per_pixel = 8;
|
||||
#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED
|
||||
if ((png_ptr->transformations & PNG_SWAP_ALPHA) != 0)
|
||||
png_do_write_swap_alpha(row_info, png_ptr->row_buf + 1);
|
||||
#endif
|
||||
|
||||
else
|
||||
return;
|
||||
#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED
|
||||
if ((png_ptr->transformations & PNG_INVERT_ALPHA) != 0)
|
||||
png_do_write_invert_alpha(row_info, png_ptr->row_buf + 1);
|
||||
#endif
|
||||
|
||||
for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
|
||||
{
|
||||
png_uint_32 s0 = (*(rp ) << 8) | *(rp + 1);
|
||||
png_uint_32 s1 = (*(rp + 2) << 8) | *(rp + 3);
|
||||
png_uint_32 s2 = (*(rp + 4) << 8) | *(rp + 5);
|
||||
png_uint_32 red = (png_uint_32)((s0 - s1) & 0xffffL);
|
||||
png_uint_32 blue = (png_uint_32)((s2 - s1) & 0xffffL);
|
||||
*(rp ) = (png_byte)((red >> 8) & 0xff);
|
||||
*(rp + 1) = (png_byte)(red & 0xff);
|
||||
*(rp + 4) = (png_byte)((blue >> 8) & 0xff);
|
||||
*(rp + 5) = (png_byte)(blue & 0xff);
|
||||
}
|
||||
}
|
||||
#endif /* PNG_WRITE_16BIT_SUPPORTED */
|
||||
}
|
||||
#ifdef PNG_WRITE_BGR_SUPPORTED
|
||||
if ((png_ptr->transformations & PNG_BGR) != 0)
|
||||
png_do_bgr(row_info, png_ptr->row_buf + 1);
|
||||
#endif
|
||||
|
||||
#ifdef PNG_WRITE_INVERT_SUPPORTED
|
||||
if ((png_ptr->transformations & PNG_INVERT_MONO) != 0)
|
||||
png_do_invert(row_info, png_ptr->row_buf + 1);
|
||||
#endif
|
||||
}
|
||||
#endif /* PNG_MNG_FEATURES_SUPPORTED */
|
||||
#endif /* PNG_WRITE_SUPPORTED */
|
||||
#endif /* WRITE_TRANSFORMS */
|
||||
#endif /* WRITE */
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user