Compare commits

...

239 Commits

Author SHA1 Message Date
Glenn Randers-Pehrson
32cd66d619 [libpng17] Imported from libpng-1.7.0beta27.tar 2014-01-10 08:11:26 -06:00
Glenn Randers-Pehrson
03a53fa429 [libpng17] Removed potentially misleading warning from png_check_IHDR(). 2014-01-10 06:22:41 -06:00
Glenn Randers-Pehrson
441de8f4fd [libpng17] Revised png_check_IHDR() to use PNG_SIZE_MAX instead of
PNG_UINT_32_MAX in the test for potential overflow in PNG_ROWBYTES.
2014-01-09 20:19:36 -06:00
Glenn Randers-Pehrson
4e5c80034e [libpng17] Only issue a warning about image width if an error has not already
been found in IHDR.
2014-01-08 11:44:48 -06:00
Glenn Randers-Pehrson
879d63156a [libpng17] Updated warning in png_check_IHDR() to say "may be too large"
instead of "is too large".
2014-01-07 11:44:41 -06:00
Glenn Randers-Pehrson
eb021245d0 [libpng17] Bump version to 1.7.0beta27 2014-01-01 11:19:28 -06:00
Glenn Randers-Pehrson
6607a3b905 [libpng17] Imported from libpng-1.7.0beta26.tar 2014-01-01 11:19:08 -06:00
Glenn Randers-Pehrson
28711dff2a [libpng17] Updated copyright year in recently-changed files. 2013-12-31 21:15:11 -06:00
John Bowler
4413d5dcd2 [libpng17] 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.
2013-12-29 19:40:13 -06:00
John Bowler
206d1eed42 [libpng17] 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
2013-12-29 15:57:30 -06:00
John Bowler
114fa16ab3 [libpng17] Fixed test programs for interlace options. Made pngvalid.c and
pngtest.c work correctly when READ_INTERLACING and/or WRITE_INTERLACING
are switched off.
2013-12-29 10:33:58 -06:00
Glenn Randers-Pehrson
eb2af04bd3 [libpng16] Merged pngrio.c, pngtrans.c, and pngwio.c with libpng-1.6.9 2013-12-28 13:11:47 -06:00
Glenn Randers-Pehrson
200fc68f52 [libpng17] Removed #error macro from contrib/tools/pngfix.c (Thomas Klausner). 2013-12-27 20:18:50 -06:00
John Bowler
4cfd01a288 [libpng17] Added dSIG to chunk list in png.h 2013-12-27 11:50:52 -06:00
John Bowler
e98229ceb0 [libpng17] Merged with 1.5 and 1.6 changes to create a single pngvalid.c 2013-12-27 08:04:49 -06:00
John Bowler
ad1a4c8cc3 [libpng17] Added libpng 1.5 checks to pngvalid.c 2013-12-27 07:53:50 -06:00
Glenn Randers-Pehrson
8df7c46e5b [libpng17] Removed configure-generated "compile" file. 2013-12-26 14:44:48 -06:00
Glenn Randers-Pehrson
99078ec8bd [libpng17] Bump version to 1.7.0beta26 2013-12-26 11:53:16 -06:00
Glenn Randers-Pehrson
a2c5f56e77 [libpng17] Imported from libpng-1.7.0beta25.tar 2013-12-26 11:53:02 -06:00
Glenn Randers-Pehrson
9e168ea2c9 [libpng17] Merged files with version 1.6.8 that have not changed since then. 2013-12-19 20:33:08 -06:00
Glenn Randers-Pehrson
06be739941 [libpng17] Bump version to 1.7.0beta25 2013-12-15 11:22:59 -06:00
Glenn Randers-Pehrson
448092b8eb [libpng17] Imported from libpng-1.7.0beta24.tar 2013-12-15 11:22:49 -06:00
Glenn Randers-Pehrson
1faa6ff32c [libpng17] 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().
2013-12-15 08:47:52 -06:00
John Bowler
3adf438f39 [libpng17] 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.
2013-12-13 23:55:41 -06:00
John Bowler
d45a632529 [libpng17] Bookkeeping: Moved functions around (no changes). Moved transform
function definitions before the place where they are called so that
they can be masde static. Move the intrapixel functions and the
grayscale palette builder out of the png?tran.c files. The latter
isn't a transform function and is no longer used internally, and the
former MNG specific functions are better placed in pngread/pngwrite.c
2013-12-13 23:50:30 -06:00
John Bowler
5a1b8d106d [libpng17] Tidied up pngfix inits and fixed pngtest no-write builds. 2013-12-01 15:50:03 -06:00
Glenn Randers-Pehrson
05f896004f [libpng17] 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
2013-11-28 16:14:03 -06:00
Glenn Randers-Pehrson
a4f1de9109 [libpng17] Avoid a scan-build warning in pngtest.c 2013-11-25 13:13:32 -06:00
Glenn Randers-Pehrson
7ebb353944 [libpng17] Removed or marked PNG_UNUSED some harmless "dead assignments"
reported by clang scan-build.
2013-11-25 11:08:56 -06:00
Glenn Randers-Pehrson
b1f0c7d0e5 [libpng17] Revised manual about handling of zlib CMF 2013-11-24 13:31:26 -06:00
Glenn Randers-Pehrson
55df049962 [libpng17] Updated CHANGES and ANNOUNCE 2013-11-23 19:26:57 -06:00
Glenn Randers-Pehrson
219ba1370e [libpng17] Bump version to 1.7.0beta24 2013-11-23 19:02:56 -06:00
Glenn Randers-Pehrson
4dc4471bb5 [libpng17] Imported from libpng-1.7.0beta23.tar 2013-11-23 19:01:01 -06:00
Glenn Randers-Pehrson
a199a15b28 [libpng17] Added another "assert()" to pngfix.c 2013-11-23 12:58:32 -06:00
Glenn Randers-Pehrson
e9446f2f95 [libpng17] Added an "assert()" to pngfix.c to quiet a clang scanner warning. 2013-11-23 12:14:02 -06:00
John Bowler
f70f2fcf48 [libpng17] Finished merging with libpng16 (pngrutil.c and pnglibconf.dfa) 2013-11-23 08:20:39 -06:00
John Bowler
158c947ce2 [libpng17] Revert recent change to pngvalid.c. 2013-11-22 18:34:37 -06:00
John Bowler
7e2707e2af [libpng17] Ported recent changes from libpng16 to libpng17
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.
2013-11-22 18:01:30 -06:00
Glenn Randers-Pehrson
81824079b5 [libpng17] Added "-Wall" to CFLAGS in contrib/pngminim/*/makefile 2013-11-18 17:03:24 -06:00
Glenn Randers-Pehrson
e8e1add0a8 [libpng17] Moved prototype for png_handle_unknown() in pngpriv.h outside of
the #ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED/#endif block.
2013-11-18 15:35:55 -06:00
Glenn Randers-Pehrson
a549223f91 [libpng17] Added #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED/#endif in pngpread.c 2013-11-17 11:09:57 -06:00
Glenn Randers-Pehrson
ebe7945b96 [libpng17] Bump version to 1.7.0beta23 2013-11-07 08:33:41 -06:00
Glenn Randers-Pehrson
e3e35aa980 [libpng17] Imported from libpng-1.7.0beta22.tar 2013-11-07 08:33:31 -06:00
John Bowler
9f2fbcf5d8 [libpng17] Fixed #include in filter_neon_intrinsics.c and ctype macros. The
ctype char checking macros take an unsigned char argument, not a signed char.
2013-11-04 13:50:20 -06:00
Glenn Randers-Pehrson
264ba68afe [libpng17] Restored a line to the libpng-1.7.0beta21 entry in ANNOUNCE 2013-11-03 20:56:03 -06:00
Glenn Randers-Pehrson
3ef99c9316 [libpng17] Bump version to 1.7.0beta22 2013-11-02 15:39:27 -05:00
John Bowler
4b29f97f9b [libpng17] Port recent libpng-1.6.7beta03, beta04 changes to 1.7.0beta21
(mainly ARMv8 support)
2013-11-02 15:29:45 -05:00
Glenn Randers-Pehrson
fe6e6cf130 [libpng17] Fixed some typos in autogen.s that don't affect its behavior 2013-10-13 17:12:44 -05:00
Glenn Randers-Pehrson
547df4b9ca [libpng17] Bump version to 1.7.0beta21 2013-10-13 14:10:23 -05:00
Glenn Randers-Pehrson
a0d4a0b971 [libpng17] Imported from libpng-1.7.0beta20.tar 2013-10-13 14:02:50 -05:00
John Bowler
72c2577302 [libpng17] 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.
2013-10-06 09:02:09 -05:00
John Bowler
091fab713c [libpng17] 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).
2013-10-06 08:51:42 -05:00
John Bowler
32aeb2cd4e [libpng17] 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
2013-10-06 08:47:43 -05:00
John Bowler
c1bcdc3a86 [libpng17] 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.
2013-10-06 08:18:31 -05:00
Glenn Randers-Pehrson
553b8f85d3 [libpng17] Bump version to 1.7.0beta20 2013-10-02 13:47:20 -05:00
Glenn Randers-Pehrson
30666a6097 [libpng17] Imported from libpng-1.7.0beta19.tar 2013-09-30 17:17:59 -05:00
John Bowler
0bfa63cd0d [libpng17] Checked in missing update to pnglibconf.dfa 2013-09-30 15:58:53 -05:00
John Bowler
b37a7c6674 [libpng17] Updated pngunknown.c 2013-09-30 13:11:44 -05:00
John Bowler
7657ac14f2 [libpng17] Catch up with recent libpng16 changes; unknown handling and spelling
corrections
2013-09-30 11:18:13 -05:00
John Bowler
d9f60caf72 [libpng17] 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.
2013-09-30 08:07:18 -05:00
Glenn Randers-Pehrson
88c20ada06 [libpng17] Reverted the change to unknown handling #defines; the change
breaks 'NOREAD' builds.
2013-09-20 14:30:16 -05:00
Glenn Randers-Pehrson
f3bfc4a142 [libpng17] Bump version to 1.7.0beta19 2013-09-16 11:47:36 -05:00
Glenn Randers-Pehrson
3fdef04d55 [libpng17] Imported from libpng-1.7.0beta18.tar 2013-09-16 11:47:26 -05:00
Glenn Randers-Pehrson
eae431e514 [libpng17] Bump version to 1.7.0beta18 2013-08-21 19:13:27 -05:00
Glenn Randers-Pehrson
003590c361 [libpng17] Imported from libpng-1.7.0beta17.tar 2013-08-21 19:13:18 -05:00
Glenn Randers-Pehrson
8e23262b2b [libpng17] Update comment in png_init_filter_functions() 2013-08-21 17:53:15 -05:00
Glenn Randers-Pehrson
157e0649e0 [libpng17] Delay calling png_init_filter_functions() until a row with nonzero
filter is found.
2013-08-20 21:28:19 -05:00
Glenn Randers-Pehrson
83f1287c02 [libpng17] Mention png_set_option() in the manual. 2013-08-17 15:56:01 -05:00
Glenn Randers-Pehrson
a1124a574a [libpng17] Use minus signs, not hyphens, in "--i" in libpng.3 2013-08-13 18:59:21 -05:00
Glenn Randers-Pehrson
6f27254a7e [libpng17] Change some hyphens to minus signs and fix other typos in libpng.3 2013-08-06 17:25:37 -05:00
Glenn Randers-Pehrson
79fc8fa0d9 [libpng17] Exit loop over tRNS array once a transparent pixel is found
(performance report by PoChun Chang).
2013-08-04 14:05:39 -05:00
Glenn Randers-Pehrson
394bc6cdee [libpng17] Port recent /*SAFE*/ comments and manual changes from libpng16 2013-07-15 10:28:48 -05:00
Glenn Randers-Pehrson
bb06552075 [libpng17] Bump version to 1.7.0beta17 2013-07-04 22:42:35 -05:00
Glenn Randers-Pehrson
a14071d814 [libpng17] Imported from libpng-1.7.0beta16.tar 2013-07-04 22:31:06 -05:00
John Bowler
23f3e46518 [libpng17] Ported pngfix.c patches from libpng16. 2013-07-03 07:50:24 -05:00
John Bowler
f97b2a6cde [libpng17] Ported ARM no-read patch from libpng16. 2013-07-03 07:46:02 -05:00
John Bowler
23f4320775 [libpng17] Added perfect hash code generation for lists of PNG chunks. This is
a work in progress; checked in for use in pngfix.c
2013-07-03 07:41:04 -05:00
Glenn Randers-Pehrson
fb411867b0 [libpng17] Updated documentation to show default behavior of benign errors
correctly.
2013-07-02 09:54:05 -05:00
Glenn Randers-Pehrson
5aa2ca454d [libpng17] Revised pngfix.c to use PNG_U32() instead of PNG_CHUNK() 2013-07-02 09:52:09 -05:00
Glenn Randers-Pehrson
7905286ffa [libpng17] Renamed contrib/tools/png-fix-too-far-back.c to pngfix.c and revised
it to check all compressed chunks known to libpng.
2013-07-01 15:11:36 -05:00
Glenn Randers-Pehrson
2edcb6ad0f [libpng17] Revised example.c to illustrate use of PNG_DEFAULT_sRGB and
PNG_GAMMA_MAC_18 as parameters for png_set_gamma().
2013-06-25 19:43:16 -05:00
Glenn Randers-Pehrson
0f1599e6e5 [libpng17] Fix spelling of "doclifter" in CHANGES and ANNOUNCE 2013-06-18 15:10:32 -05:00
Glenn Randers-Pehrson
cbf22f30b4 [libpng17] Bump version to 1.7.0beta16 2013-06-18 13:22:10 -05:00
Glenn Randers-Pehrson
9bf3c70730 [libpng17] Imported from libpng-1.7.0beta15.tar 2013-06-18 13:14:34 -05:00
Glenn Randers-Pehrson
1bc5747713 [libpng17] Bump version to 1.7.0beta15 2013-06-08 21:00:45 -05:00
Glenn Randers-Pehrson
4a7796faca [libpng17] Imported from libpng-1.7.0beta14.tar 2013-06-08 21:00:36 -05:00
John Bowler
34081a0e2f [libpng17] Port recent changes to ARM support from libpng-1.6.3beta07. 2013-06-08 14:20:46 -05:00
John Bowler
b88c94208a [libpng17] 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.
2013-06-06 14:57:14 -05:00
Glenn Randers-Pehrson
30662f5e92 [libpng17] Enclose the prototypes for the simplified write API in 2013-06-05 23:25:14 -05:00
Glenn Randers-Pehrson
46ad4c5bd4 [libpng17] Deleted contrib/tools/fixitxt.c, which has been renamed. 2013-06-05 17:03:38 -05:00
Glenn Randers-Pehrson
5c32606ec0 [libpng17] Update README to delete CompuServ and add simplesystems.org 2013-06-05 17:01:14 -05:00
John Bowler
a08ac031fc [libpng17] Fixed ICC compiler warning in tools/png-fix-itxt.c 2013-06-05 16:48:18 -05:00
John Bowler
c233ec8743 [libpng17] Deleted set(CMAKE_BUILD_TYPE) block from CMakeLists.txt 2013-06-05 11:45:55 -05:00
Glenn Randers-Pehrson
d594be641a [libpng17] Added set(CMAKE_CONFIGURATION_TYPES ...) to CMakeLists.txt
(Andrew Hundt)
2013-06-05 11:05:34 -05:00
Glenn Randers-Pehrson
4c9168875b [libpng17] Removed a redundant test in png_set_IHDR(). 2013-06-04 15:09:06 -05:00
Glenn Randers-Pehrson
3c051ee282 [libpng17] Update README with current info about arm, contrib, and projects
directories
2013-06-03 21:02:46 -05:00
Glenn Randers-Pehrson
e1ded944f0 [libpng17] Bump version to 1.7.0beta14 2013-05-12 19:25:30 -05:00
Glenn Randers-Pehrson
c09dddc0cd [libpng17] Imported from libpng-1.7.0beta13.tar 2013-05-12 19:25:16 -05:00
Glenn Randers-Pehrson
bd56d76417 [libpng17] Port recent zlib windowBits handling from libpng-1.6.3beta06 2013-05-10 17:43:59 -05:00
Glenn Randers-Pehrson
0cc23ac171 [libpng17] Updated contrib/pngminus/pnm2png.c (Paul Stewart):
Fixed whitespace handling
Added a call to png_set_packing()
Initialize dimension values so if sscanf fails at least we have known
      invalid values.
2013-05-09 23:30:46 -05:00
Glenn Randers-Pehrson
cb10e19725 [libpng17] Added a needed #ifdef/#endif pair. 2013-05-09 23:18:10 -05:00
Glenn Randers-Pehrson
9dba7219a0 [libpng17] Revised contrib/pngminim/*/makefile to generate pnglibconf.h with the
right zlib header files.
2013-05-09 22:59:08 -05:00
Glenn Randers-Pehrson
17c6af8c40 [libpng17] Check for EOF in contrib/pngminus/pnm2png.c (Paul Stewart).
Ignore "#" delimited comments in input file to pnm2png.c.
2013-05-07 14:38:19 -05:00
Glenn Randers-Pehrson
6a02eb6d2c [libpng17] Bump version to 1.7.0beta13 2013-04-29 21:32:33 -05:00
Glenn Randers-Pehrson
40d41fe6f8 [libpng17] Imported from libpng-1.7.0beta12.tar 2013-04-29 21:32:12 -05:00
Glenn Randers-Pehrson
7073d26e51 [libpng17] Avoid dereferencing NULL pointer possibly returned from
png_create_write_struct() (Andrew Church).
2013-04-29 08:58:15 -05:00
Glenn Randers-Pehrson
cf76fe8654 [libpng17] Expanded manual paragraph about writing private chunks. 2013-04-28 21:04:12 -05:00
Glenn Randers-Pehrson
b780b64fbf [libpng17] Bump version to 1.7.0beta12 2013-04-26 08:46:11 -05:00
Glenn Randers-Pehrson
b1876ab6e2 [libpng17] Imported from libpng-1.7.0beta11.tar 2013-04-26 08:46:00 -05:00
John Bowler
28a95d125f [libpng17] Test for 'arm*' not just 'arm' in the host_cpu configure variable. 2013-04-25 22:51:21 -05:00
Glenn Randers-Pehrson
993f68c006 [libpng17] Bump version to 1.7.0beta11 2013-04-24 08:34:00 -05:00
Glenn Randers-Pehrson
8d23524359 [libpng17] Imported from libpng-1.7.0beta10.tar 2013-04-24 08:33:48 -05:00
John Bowler
e0f4aaa668 [libpng17] Attempt to fix the arm-neon configuration mess. 2013-04-24 00:07:59 -05:00
Glenn Randers-Pehrson
3de174cd2f [libpng17] Imported from libpng-1.7.0beta10.tar 2013-04-23 23:52:30 -05:00
Glenn Randers-Pehrson
eaf2f1dcbe [libpng17] Imported from libpng-1.7.0beta09.tar 2013-04-23 20:43:09 -05:00
John Bowler
ea0b4c602e [libpng17] Port recent changes from libpng-1.6.2. 2013-04-23 20:40:42 -05:00
John Bowler
371c3d4dfd [libpng17] Install missing patch to contrib/libtests/pngunknown.c 2013-04-19 21:56:00 -05:00
John Bowler
0bcf5fb451 [libpng17] Exposed PNG chunk types in png.h, modified png_uint_32 macros/code
to make as few assumptions as possible
2013-04-19 07:06:02 -05:00
Glenn Randers-Pehrson
57d6907d89 [libpng17] Bump version to 1.7.0beta09 2013-04-18 07:40:10 -05:00
Glenn Randers-Pehrson
6cf97e37af [libpng17] Bump version to 1.7.0beta08 2013-04-18 07:39:57 -05:00
Glenn Randers-Pehrson
8ef61c4693 [libpng17] Added contrib/tools/fixitxt.c, to repair the erroneous iTXt
chunk length written by libpng-1.6.0 and 1.6.1.
2013-04-16 23:09:35 -05:00
Glenn Randers-Pehrson
25a116f97d [libpng17] Imported from libpng-1.7.0beta08.tar 2013-04-13 21:27:16 -05:00
Glenn Randers-Pehrson
d6d41c847a [libpng17] Imported from libpng-1.7.0beta07.tar 2013-04-13 20:54:54 -05:00
Glenn Randers-Pehrson
9e0297546f [libpng17] Removed extra line left over from recent patch to pngwutil.c 2013-04-13 20:07:29 -05:00
John Bowler
d529363d13 [libpng17] Revised last patch to work on 64-bit platforms. 2013-04-13 16:42:37 -05:00
Glenn Randers-Pehrson
55e93d7090 [libpng17] Fixed length written to uncompressed iTXt chunks (Samuli Suominen). 2013-04-13 16:23:48 -05:00
John Bowler
23674b75be [libpng17] Added "{ }" that were omitted from previous patch to pngtrans.c 2013-04-13 12:28:30 -05:00
Glenn Randers-Pehrson
0ddf350360 [libpng17] Corrected a misplaced closing bracket in contrib/libtests/pngvalid.c
(Flavio Medeiros).
2013-04-13 11:42:52 -05:00
John Bowler
066f9862f0 [libpng17] 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.
2013-04-12 22:10:38 -05:00
Glenn Randers-Pehrson
ae1a5c811c [libpng17] Updated the URL of the GIT repository in the manual. 2013-04-11 19:00:10 -05:00
John Bowler
5a1ce92c0c [libpng16] 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.
2013-04-07 21:37:52 -05:00
Glenn Randers-Pehrson
7a498039c5 [libpng17]Updated documentation of 1.5.x to 1.6.x changes in iCCP chunk
handling.
2013-03-31 23:03:32 -05:00
Glenn Randers-Pehrson
40a93652aa [libpng17] Bump version to 1.7.0beta07 2013-03-13 09:52:06 -05:00
Glenn Randers-Pehrson
a1362f38de [libpng17] Imported from libpng-1.7.0beta06.tar 2013-03-13 09:51:58 -05:00
John Bowler
30bc0333fe [libpng17] Eliminated two warnings from the Intel C compiler. 2013-03-13 09:50:48 -05:00
Claudio Bley
55794013d4 [libpng16] 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.
2013-03-07 11:23:12 -06:00
John Bowler
2e92b4dfa0 [libpng16] 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.
2013-03-06 22:23:40 -06:00
Glenn Randers-Pehrson
f46106fa04 [libpng17] Bump version to 1.7.0beta06 2013-03-04 18:23:04 -06:00
Glenn Randers-Pehrson
0dcd32f39c [libpng17] Imported from libpng-1.7.0beta05.tar 2013-03-04 18:22:54 -06:00
John Bowler
808ea281a4 [libpng17] 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.
2013-03-03 21:29:36 -06:00
John Bowler
ec89aefb44 [libpng17] 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.
2013-03-02 21:39:44 -06:00
Glenn Randers-Pehrson
6152dbd424 [libpng17] Fixed bug introduced in libpng-1.6.0beta28 that causes libpng to
handle chunks even when they have been tagged PNG_HANDLE_CHUNK_NEVER.
Also fixed two typos (SUPPOPRTED should be SUPPORTED) in pngrutil.c
2013-03-01 20:08:33 -06:00
Glenn Randers-Pehrson
fe18c0d9ea [libpng17] Avoid a possible memory leak in contrib/gregbook/readpng.c 2013-03-01 13:28:20 -06:00
Glenn Randers-Pehrson
1b0358302d [libpng17] Bump version to 1.7.0beta05 2013-02-27 14:53:47 -06:00
Glenn Randers-Pehrson
d20f9d5030 [libpng17] Imported from libpng-1.7.0beta04.tar 2013-02-27 14:40:40 -06:00
John Bowler
fc447311aa [libpng17] Revised scripts/dfn.awk to work with the buggy MSYS awk that
has trouble with CRLF line endings.
2013-02-27 13:30:52 -06:00
Glenn Randers-Pehrson
8e30e43587 [libpng17] Add info about order of png_set_* calls to the manual. 2013-02-26 08:34:45 -06:00
Glenn Randers-Pehrson
0403ccf1de [libpng16] Revised INSTALL to recommend using CPPFLAGS instead of INCLUDES.
Revised scripts/makefile.freebsd to respect ZLIBDIR and ZLIBINC.
2013-02-22 20:32:03 -06:00
Glenn Randers-Pehrson
1a321cc088 [libpng17] Bump version to 1.7.0beta04 2013-02-22 17:29:54 -06:00
Glenn Randers-Pehrson
c9f99f487b [libpng17] Imported from libpng-1.7.0beta03.tar 2013-02-22 17:29:03 -06:00
Glenn Randers-Pehrson
8360e60abc [libpng17] Update scripts/pnglibconf.h.prebuilt 2013-02-19 10:07:56 -06:00
John Bowler
2799f74489 [libpng17] Fixed ALIGNED_MEMORY support and
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.)
2013-02-19 09:52:30 -06:00
John Bowler
7363babe4f [libpng17] Reenabled code to allow zero length PLTE chunks for MNG. 2013-02-18 21:36:25 -06:00
Glenn Randers-Pehrson
e3a526f789 [libpng17] Eliminated references to "png_sizeof()" in the documentation. 2013-02-18 15:25:08 -06:00
Glenn Randers-Pehrson
8f0935b8dc [libpng17] Bump version to 1.7.0beta03 2013-02-18 13:02:33 -06:00
Glenn Randers-Pehrson
ae6503fe0e [libpng17] Imported from libpng-1.7.0beta02.tar 2013-02-18 13:02:25 -06:00
Glenn Randers-Pehrson
851a6265a8 [libpng17] Use parentheses consistently with #if defined()
and wrapped some long lines.
2013-02-17 15:25:29 -06:00
Glenn Randers-Pehrson
ffa24d4108 [libpng17] Fixed double-underscore typo in an #ifdef in png.c 2013-02-16 16:38:24 -06:00
John Bowler
206f4d2678 [libpng17] 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).
2013-02-16 07:53:19 -06:00
John Bowler
bb040784c2 [libpng17] Fixed a race condition in the creation of the build 'scripts'
directory while building with a parallel make.
2013-02-16 07:52:15 -06:00
Glenn Randers-Pehrson
70e1af50ed [libpng17] Bump version to 1.7.0beta02 2013-02-15 11:00:16 -06:00
Glenn Randers-Pehrson
eb4a645eda [libpng17] Imported from libpng-1.7.0beta01.tar 2013-02-15 11:00:07 -06:00
John Bowler
9f7f03a3c4 [libpng17] Accept "," as separator in options.awk 2013-02-10 18:04:16 -06:00
John Bowler
395ddbd318 [libpng17] Fix typos of PNG_GET_PALLETE_MAX_SUPPORTED
in png.h and pnglibconf.dfa
2013-02-10 17:24:46 -06:00
Glenn Randers-Pehrson
9f0d36c85f [libpng17] Fix typo, indentation of #ifdef PNG_GET_PALETTE_MAX_SUPPORTED
in png.h and pnglibconf.dfa
2013-02-10 16:57:38 -06:00
Glenn Randers-Pehrson
e9760e5e95 [libpng17] Enclosed the new png_get_palette_max API
in #ifdef PNG_GET_PALETTE_MAX_SUPPORTED
block, and revised pnglibconf.h and pnglibconf.h.prebuilt accordingly.
2013-02-10 15:59:15 -06:00
John Bowler
b96b2b7e90 [libpng17] 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.
2013-02-09 07:53:57 -06:00
John Bowler
9bb705e0a8 [libpng17] 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
2013-02-08 11:16:06 -06:00
Glenn Randers-Pehrson
e860f77393 [libpng17] Updated manual page about png_get_palette_max() API. 2013-02-08 09:24:35 -06:00
Glenn Randers-Pehrson
b5a7565908 [libpng17] Removed some obsolete test scripts. 2013-02-08 08:00:11 -06:00
John Bowler
e88e221d91 [libpng17] Make tests/pngstest* work with the original Bourne shell 2013-02-07 21:59:36 -06:00
Glenn Randers-Pehrson
b10867cdc2 [libpng17] 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.
2013-02-07 08:26:34 -06:00
Glenn Randers-Pehrson
bf7084b80d [libpng17] Bump version to 1.7.0alpha11 2013-02-06 22:23:37 -06:00
Glenn Randers-Pehrson
6afcee826f [libpng17] Imported from libpng-1.7.0alpha10.tar 2013-02-06 19:51:21 -06:00
John Bowler
f15a5006c8 [libpng17] 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.
2013-02-06 17:52:30 -06:00
John Bowler
cdbd5174bd [libpng17] Minor fixes to assembler changes, verified with a dummy .S file 2013-02-06 17:40:52 -06:00
John Bowler
7a9b6203ef [libpng16] Removed new test-driver from autogen.sh 2013-02-06 17:16:49 -06:00
John Bowler
803493e19c [libpng17] Ported libpng 1.5 options.awk/dfn file handling to 1.7, fixed one
bug.
2013-02-05 10:16:42 -06:00
Mans Rullgard
4245e6b1b2 [libpng17] Fixed ARM support (Mans Rullgard).
Also removed stray out-of-order #endif and #ifdef
2013-02-05 09:55:36 -06:00
John Bowler
81892f6b90 [libpng17] Fix typos in png_get_palette_max name and prototype 2013-02-05 08:10:01 -06:00
John Bowler
862993827d [libpng17] Changed png_size_t to size_t throughout headers, make sRGB check
numbers consistent.
2013-02-04 20:04:10 -06:00
Glenn Randers-Pehrson
d304125332 [libpng17] Added png_get_palette_max() function. 2013-02-04 19:55:53 -06:00
John Bowler
9124f3e29a [libpng17] 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.
2013-02-04 18:00:34 -06:00
Glenn Randers-Pehrson
2969375aa6 [libpng17] Restored a "return" statement accidentally deleted from pngset.c 2013-01-22 07:03:51 -06:00
Glenn Randers-Pehrson
5e8ba1cbbf [libpng17] Set counter to prevent additional attempts to cache a chunk
after running out of memory or reaching a potential overflow condition.
2013-01-21 16:37:54 -06:00
Glenn Randers-Pehrson
8aee43d10a [libpng17] Bump version to 1.7.0alpha10 2013-01-21 09:21:36 -06:00
Glenn Randers-Pehrson
e355657bbe [libpng17] Imported from libpng-1.7.0alpha09.tar 2013-01-21 09:21:21 -06:00
John Bowler
fb6ba9acf4 [libpng17] Pulled changes to multi-chunk handling from libpng-1.6.0beta40. 2013-01-21 09:11:17 -06:00
Glenn Randers-Pehrson
815173a0b5 [libpng17] Bump version to 1.7.0alpha09 2013-01-17 13:50:32 -06:00
Glenn Randers-Pehrson
7f489a77bb [libpng17] Imported from libpng-1.7.0alpha08.tar 2013-01-17 13:50:23 -06:00
John Bowler
8ec8e8fcd5 [libpng17] Corrected previous attempt at overflow detection in
png_set_unknown_chunks().
2013-01-17 13:42:42 -06:00
Glenn Randers-Pehrson
a4e606dd5f [libpng17] Bump version to 1.7.0alpha08 2013-01-10 12:05:08 -06:00
Glenn Randers-Pehrson
646de7962b [libpng17] Imported from libpng-1.7.0alpha07.tar 2013-01-10 12:04:54 -06:00
John Bowler
4accd423c2 [libpng17]Fixed conceivable but difficult to repro overflow. Also added
two test programs to generate and test a PNG which should have the problem.
2013-01-10 11:01:00 -06:00
Glenn Randers-Pehrson
f62caaf4dc [libpng17] Fixed typo in copyright year and version in pngmem.c 2013-01-01 10:55:18 -06:00
Glenn Randers-Pehrson
b789bb84bb [libpng17] Bump version to 1.7.0alpha07 2013-01-01 09:02:35 -06:00
Glenn Randers-Pehrson
ce60ad642b [libpng17] Imported from libpng-1.7.0alpha06.tar 2013-01-01 09:02:25 -06:00
Glenn Randers-Pehrson
ab097b1168 [libpng17] Updated copyright year to 2013 in changed files. 2013-01-01 08:54:06 -06:00
John Bowler
3a737d86c7 [libpng17] Fixed 'make distcheck' on SUN OS - libpng.so was not being removed 2012-12-27 09:46:33 -06:00
Glenn Randers-Pehrson
a1337e57a8 [libpng17] Bump version to 1.7.0alpha06 2012-12-23 21:00:36 -06:00
Glenn Randers-Pehrson
247b3fcf49 [libpng17] Imported from libpng-1.7.0alpha05.tar 2012-12-23 21:00:22 -06:00
Glenn Randers-Pehrson
f01273b25c [libpng17] Bump version to 1.7.0alpha05 2012-12-22 18:23:22 -06:00
Glenn Randers-Pehrson
8cb1a2ac6d [libpng17] Imported from libpng-1.7.0alpha04.tar 2012-12-22 18:13:34 -06:00
Glenn Randers-Pehrson
e6e5ac8cb7 [libpng17] Added missing dependency on pnglibconf.h in scripts/makefile.linux 2012-12-22 17:53:18 -06:00
Glenn Randers-Pehrson
a4798fb83e [libpng17] Reformatted latest CHANGES/ANNOUNCE entry to 80 character lines. 2012-12-22 17:13:02 -06:00
John Bowler
46369f35c5 [libpng17] 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.
2012-12-20 22:58:13 -06:00
John Bowler
e699993d70 [libpng17] Made default Zlib compression settings be configurable. This adds #defines to
pnglibconf.h to control the defaults.
2012-12-20 22:21:02 -06:00
Glenn Randers-Pehrson
5a0afcfa63 [libpng17] Added scripts/makefile.msys contributed by Christipher M. Wheeler 2012-12-19 23:06:12 -06:00
Glenn Randers-Pehrson
3fc9cbf126 [libpng17] Bump version to 1.7.0alpha04 2012-12-19 16:06:17 -06:00
Glenn Randers-Pehrson
36b628b19e [libpng17] Imported from libpng-1.7.0alpha03.tar 2012-12-19 15:53:18 -06:00
Glenn Randers-Pehrson
2c31365fd4 [libpng16] Announce that git repository location at SourceForge has changed. 2012-12-18 21:45:58 -06:00
Glenn Randers-Pehrson
e1e3c1a2a2 [libpng17] Fixed typo in contrib/pngminim/encoder/README 2012-12-18 14:58:44 -06:00
John Bowler
b940e5dc5d [libpng17] Disassembled the version number in scripts/options.awk (necessary
for building on SunOs)
2012-12-17 23:36:08 -06:00
John Bowler
fbbbc620b8 [libpng16] 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.
2012-12-17 21:07:30 -06:00
Glenn Randers-Pehrson
9b99600c4d [libpng17] Fixed several more whitespace errors in libpng.3 2012-12-17 20:00:44 -06:00
Glenn Randers-Pehrson
3129d7426e [libpng16] Cleaned up whitespace in the synopsis portion of the manpage. 2012-12-17 19:21:14 -06:00
Glenn Randers-Pehrson
325ceea971 [libpng17] Bump version to 1.7.0alpha03 2012-12-17 12:25:13 -06:00
Glenn Randers-Pehrson
ac39fc3024 [libpng17] Bump version to 1.7.0alpha03 2012-12-17 12:16:32 -06:00
Glenn Randers-Pehrson
99343407e6 [libpng17] Add #ifdef PNG_WRITE_FILTERED_ROW around a use of prev_row. 2012-12-17 12:12:49 -06:00
Glenn Randers-Pehrson
3e23f45ba9 [libpng17] Document new PNG_ABORT behavior in libpng-1.7.x 2012-12-17 11:53:34 -06:00
John Bowler
72389dec42 [libpng17] 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.
2012-12-17 09:20:02 -06:00
Glenn Randers-Pehrson
1f0853f47e [libpng17] Bump version to 1.7.0alpha03 2012-12-16 19:43:18 -06:00
Glenn Randers-Pehrson
32a60a4885 [libpng17] Imported from libpng-1.7.0alpha02.tar 2012-12-16 19:43:10 -06:00
Glenn Randers-Pehrson
5e07dc6970 [libpng17] Updated documentation about functions deprecated in 1.6.0 2012-12-16 16:47:07 -06:00
John Bowler
4b90a8d416 [libpng17] Build fixes (trailing ;, missing/misplaced PNG_REMOVED) in png.h 2012-12-16 15:56:18 -06:00
John Bowler
d59c19b64c [libpng17] Removed more functions that were deprecated in libpng-1.6.0:
png_malloc_default png_free_default.
  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
2012-12-15 21:41:31 -06:00
Glenn Randers-Pehrson
bbabd977d1 [libpng17] Fixed some typos in comments; updated manual. 2012-12-15 17:12:48 -06:00
John Bowler
0cf9c7d63d [libpng17] Removed some duplicated code from png.c and contrib/tools/scale.c
and changed some png_warning() calls to png_app_error() calls in pngwutil.c
2012-12-15 16:04:28 -06:00
Glenn Randers-Pehrson
b4e241559e [libpng17] Removed no-longer-exported functions from scripts/symbols.def 2012-12-15 16:02:24 -06:00
Glenn Randers-Pehrson
1e15aee6be [libpng17] Removed functions that were deprecated in libpng-1.6.0:
png_reset_zstream(), png_info_init_3(), and png_data_freer() and its
associated flags.
2012-12-15 15:40:56 -06:00
Glenn Randers-Pehrson
d59e60d0fb [libpng17] Bump version to 1.7.0alpha02 2012-12-15 12:33:51 -06:00
Glenn Randers-Pehrson
ec1d13a1d4 [libpng17] Imported from libpng-1.7.0alpha01.tar 2012-12-15 12:33:44 -06:00
Glenn Randers-Pehrson
d9002f94cb [libpng17] Rebuilt Makefile.in, configure, etc., with autoconf-2.69
and automake-1.12.5 in the tar distributions.
2012-12-15 10:12:36 -06:00
John Bowler
1fa858db48 [libpng17] Fixed cases of unquoted DESTDIR in Makefile.am. 2012-12-15 09:48:10 -06:00
John Bowler
0f2a5bac64 [libpng17] 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.
2012-12-14 23:12:16 -06:00
John Bowler
eac85878bf [libpng17] Clean up USER_LIMITS feature, removing members from png_struct
when not required.
2012-12-14 22:56:00 -06:00
John Bowler
240ac287eb [libpng17]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.
2012-12-14 22:31:50 -06:00
John Bowler
3e42c81193 [libpng17] 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 slighly
    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.
2012-12-14 22:17:54 -06:00
Glenn Randers-Pehrson
ac3b4d9b69 [libpng17] Bump version to 1.7.0alpha01 2012-12-10 16:21:25 -06:00
175 changed files with 14042 additions and 5596 deletions

948
ANNOUNCE
View File

@@ -1,5 +1,5 @@
Libpng 1.6.0beta33 - December 10, 2012
Libpng 1.7.0beta27 - January 10, 2014
This is not intended to be a public release. It will be replaced
within a few weeks by a public version or by another test version.
@@ -9,555 +9,485 @@ Files available for download:
Source files with LF line endings (for Unix/Linux) and with a
"configure" script
1.6.0beta33.tar.xz (LZMA-compressed, recommended)
1.6.0beta33.tar.gz
1.6.0beta33.tar.bz2
1.7.0beta27.tar.xz (LZMA-compressed, recommended)
1.7.0beta27.tar.gz
Source files with CRLF line endings (for Windows), without the
"configure" script
lp160b33.7z (LZMA-compressed, recommended)
lp160b33.zip
lp170b27.7z (LZMA-compressed, recommended)
lp170b27.zip
Other information:
1.6.0beta33-README.txt
1.6.0beta33-LICENSE.txt
1.7.0beta27-README.txt
1.7.0beta27-LICENSE.txt
Gnupg/*.asc (PGP armored detached signatures)
Changes since the last public release (1.5.7):
Changes since the last public release (1.6.0):
Version 1.6.0beta01 [December 15, 2011]
Removed machine-generated configure files from the GIT repository (they will
continue to appear in the tarball distributions).
Restored the new 'simplified' API, which was started in libpng-1.5.7beta02
but later deleted from libpng-1.5.7beta05.
Added example programs for the new 'simplified' API.
Added ANSI-C (C90) headers and require them, and take advantage of the
change. Also fixed some of the projects/* and contrib/* files that needed
updates for libpng16 and the move of pngvalid.c.
With this change the required ANSI-C header files are assumed to exist: the
implementation must provide float.h, limits.h, stdarg.h and stddef.h and
libpng relies on limits.h and stddef.h existing and behaving as defined
(the other two required headers aren't used). Non-ANSI systems that don't
have stddef.h or limits.h will have to provide an appropriate fake
containing the relevant types and #defines.
The use of FAR/far has been eliminated and the definition of png_alloc_size_t
is now controlled by a flag so that 'small size_t' systems can select it
if necessary. Libpng 1.6 may not currently work on such systems -- it
seems likely that it will ask 'malloc' for more than 65535 bytes with any
image that has a sufficiently large row size (rather than simply failing
to read such images).
New tools directory containing tools used to generate libpng code.
Fixed race conditions in parallel make builds. With higher degrees of
parallelism during 'make' the use of the same temporary file names such
as 'dfn*' can result in a race where a temporary file from one arm of the
build is deleted or overwritten in another arm. This changes the
temporary files for suffix rules to always use $* and ensures that the
non-suffix rules use unique file names.
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.6.0beta02 [December 21, 2011]
Correct configure builds where build and source directories are separate.
The include path of 'config.h' was erroneously made relative in pngvalid.c
in libpng 1.5.7.
Version 1.7.0alpha02 [December 17, 2012]
Removed functions that were deprecated in libpng-1.6.0:
png_reset_zstream(), png_info_init_3(), and png_data_freer() and its
associated flags.
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.6.0beta03 [December 22, 2011]
Start-up code size improvements, error handler flexibility. These changes
alter how the tricky allocation of the initial png_struct and png_info
structures are handled. png_info is now handled in pretty much the same
way as everything else, except that the allocations handle NULL return
silently. png_struct is changed in a similar way on allocation and on
deallocation a 'safety' error handler is put in place (which should never
be required). The error handler itself is changed to permit mismatches
in the application and libpng error buffer size; however, this means a
silent change to the API to return the jmp_buf if the size doesn't match
the size from the libpng compilation; libpng now allocates the memory and
this may fail. Overall these changes result in slight code size
reductions; however, this is a reduction in code that is always executed
so is particularly valuable. Overall on a 64-bit system the libpng DLL
decreases in code size by 1733 bytes. pngerror.o increases in size by
about 465 bytes because of the new functionality.
Added png_convert_to_rfc1123_buffer() and deprecated png_convert_to_rfc1123()
to avoid including a spurious buffer in the png_struct.
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.6.0beta04 [December 30, 2011]
Regenerated configure scripts with automake-1.11.2
Eliminated png_info_destroy(). It is now used only in png.c and only calls
one other internal function and memset().
Enabled png_get_sCAL_fixed() if floating point APIs are enabled. Previously
it was disabled whenever internal fixed point arithmetic was selected,
which meant it didn't exist even on systems where FP was available but not
preferred.
Added pngvalid.c compile time checks for const APIs.
Implemented 'restrict' for png_info and png_struct. Because of the way
libpng works both png_info and png_struct are always accessed via a
single pointer. This means adding C99 'restrict' to the pointer gives
the compiler some opportunity to optimize the code. This change allows
that.
Moved AC_MSG_CHECKING([if libraries can be versioned]) later to the proper
location in configure.ac (Gilles Espinasse).
Changed png_memcpy to C assignment where appropriate. Changed all those
uses of png_memcpy that were doing a simple assignment to assignments
(all those cases where the thing being copied is a non-array C L-value).
Added some error checking to png_set_*() routines.
Removed the reference to the non-exported function png_memcpy() from
example.c.
Fixed the Visual C 64-bit build - it requires jmp_buf to be aligned, but
it had become misaligned.
Revised contrib/pngminus/pnm2png.c to avoid warnings when png_uint_32
and unsigned long are of different sizes.
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.6.0beta05 [January 15, 2012]
Updated manual with description of the simplified API (copied from png.h)
Fix bug in pngerror.c: some long warnings were being improperly truncated
(CVE-2011-3464, bug introduced in libpng-1.5.3beta05).
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.6.0beta06 [January 24, 2012]
Added palette support to the simplified APIs. This commit
changes some of the macro definitions in png.h, app code
may need corresponding changes.
Increased the formatted warning buffer to 192 bytes.
Added color-map support to simplified API. This is an initial version for
review; the documentation has not yet been updated.
Fixed Min/GW uninstall to remove libpng.dll.a
Version 1.7.0alpha06 [January 1, 2013]
Fixed 'make distcheck' on SUN OS - libpng.so was not being removed
Version 1.6.0beta07 [January 28, 2012]
Eliminated Intel icc/icl compiler warnings. The Intel (GCC derived)
compiler issues slightly different warnings from those issued by the
current vesions of GCC. This eliminates those warnings by
adding/removing casts and small code rewrites.
Updated configure.ac from autoupdate: added --enable-werror option.
Also some layout regularization and removal of introduced tab characters
(replaced with 3-character indentation). Obsolete macros identified by
autoupdate have been removed; the replacements are all in 2.59 so
the pre-req hasn't been changed. --enable-werror checks for support
for -Werror (or the given argument) in the compiler. This mimics the
gcc configure option by allowing -Werror to be turned on safely; without
the option the tests written in configure itself fail compilation because
they cause compiler warnings.
Rewrote autogen.sh to run autoreconf instead of running tools one-by-one.
Conditionalize the install rules for MINGW and CYGWIN in CMakeLists.txt and
set CMAKE_LIBRARY_OUTPUT_DIRECTORY to "lib" on all platforms (C. Yapp).
Freeze libtool files in the 'scripts' directory. This version of autogen.sh
attempts to dissuade people from running it when it is not, or should not,
be necessary. In fact, autogen.sh does not work when run in a libpng
directory extracted from atar distribution anymore. You must run it in
a GIT clone instead.
Added two images to contrib/pngsuite (1-bit and 2-bit transparent grayscale),
and renamed three whose names were inconsistent with those in
pngsuite/README.txt.
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.6.0beta08 [February 1, 2012]
Fixed Image::colormap misalignment in pngstest.c
Check libtool/libtoolize version number (2.4.2) in configure.ac
Divide test-pngstest.sh into separate pngstest runs for basic and
transparent images.
Moved automake options to AM_INIT_AUTOMAKE in configure.ac
Added color-tests, silent-rules (Not yet implemented in Makefile.am) and
version checking to configure.ac
Improved pngstest speed by not doing redundant tests and add const to
the background parameter of png_image_finish_read. The --background
option is now done automagically only when required, so that commandline
option no longer exists.
Cleaned up pngpriv.h to consistently declare all functions and data.
Also eliminated PNG_CONST_DATA, which is apparently not needed but we
can't be sure until it is gone.
Added symbol prefixing that allows all the libpng external symbols
to be prefixed (suggested by Reuben Hawkins).
Updated "ftbb*.png" list in the owatcom and vstudio projects.
Fixed 'prefix' builds on clean systems. The generation of pngprefix.h
should not require itself.
Updated INSTALL to explain that autogen.sh must be run in a GIT clone,
not in a libpng directory extracted from a tar distribution.
Version 1.7.0alpha08 [January 17, 2013]
Corrected previous attempt at overflow detection in png_set_unknown_chunks().
Version 1.6.0beta09 [February 1, 2012]
Reverted the prebuilt configure files to libpng-1.6.0beta05 condition.
Version 1.7.0alpha09 [January 21, 2013]
Pulled changes to multi-chunk handling from libpng-1.6.0beta40.
Version 1.6.0beta10 [February 3, 2012]
Added Z_SOLO for zlib-1.2.6+ and correct pngstest tests
Updated list of test images in CMakeLists.txt
Updated the prebuilt configure files to current condition.
Revised INSTALL information about autogen.sh; it works in tar distributions.
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.6.0beta11 [February 16, 2012]
Fix character count in pngstest command in projects/owatcom/pngstest.tgt
Revised test-pngstest.sh to report PASS/FAIL for each image.
Updated documentation about the simplified API.
Corrected estimate of error in libpng png_set_rgb_to_gray API. The API is
extremely inaccurate for sRGB conversions because it uses an 8-bit
intermediate linear value and it does not use the sRGB transform, so it
suffers from the known instability in gamma transforms for values close
to 0 (see Poynton). The net result is that the calculation has a maximum
error of 14.99/255; 0.5/255^(1/2.2). pngstest now uses 15 for the
permitted 8-bit error. This may still not be enough because of arithmetic
error.
Removed some unused arrays (with #ifdef) from png_read_push_finish_row().
Fixed a memory overwrite bug in simplified read of RGB PNG with
non-linear gamma Also bugs in the error checking in pngread.c and changed
quite a lot of the checks in pngstest.c to be correct; either correctly
written or not over-optimistic. The pngstest changes are insufficient to
allow all possible RGB transforms to be passed; pngstest cmppixel needs
to be rewritten to make it clearer which errors it allows and then changed
to permit known inaccuracies.
Removed tests for no-longer-used *_EMPTY_PLTE_SUPPORTED from pngstruct.h
Fixed fixed/float API export conditionals. 1) If FIXED_POINT or
FLOATING_POINT options were switched off, png.h ended up with lone ';'
characters. This is not valid ANSI-C outside a function. The ';'
characters have been moved inside the definition of PNG_FP_EXPORT and
PNG_FIXED_EXPORT. 2) If either option was switched off, the declaration
of the corresponding functions were completely omitted, even though some
of them are still used internally. The result is still valid, but
produces warnings from gcc with some warning options (including -Wall). The
fix is to cause png.h to declare the functions with PNG_INTERNAL_FUNCTION
when png.h is included from pngpriv.h.
Check for invalid palette index while reading paletted PNG. When one is
found, issue a warning and increase png_ptr->num_palette accordingly.
Apps are responsible for checking to see if that happened.
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.6.0beta12 [February 18, 2012]
Do not increase num_palette on invalid_index.
Relocated check for invalid palette index to pngrtran.c, after unpacking
the sub-8-bit pixels.
Fixed CVE-2011-3026 buffer overrun bug. Deal more correctly with the test
on iCCP chunk length. Also removed spurious casts that may hide problems
on 16-bit systems.
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.6.0beta13 [February 24, 2012]
Eliminated redundant png_push_read_tEXt|zTXt|iTXt|unknown code from
pngpread.c and use the sequential png_handle_tEXt, etc., in pngrutil.c;
now that png_ptr->buffer is inaccessible to applications, the special
handling is no longer useful.
Added PNG_SAFE_LIMITS feature to pnglibconf.dfa, pngpriv.h, and new
pngusr.dfa to reset the user limits to safe ones if PNG_SAFE_LIMITS is
defined. To enable, use "CPPFLAGS=-DPNG_SAFE_LIMITS_SUPPORTED=1" on the
configure command or put #define PNG_SAFE_LIMITS_SUPPORTED in
pnglibconf.h.prebuilt and pnglibconf.h.
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.6.0beta14 [February 27, 2012]
Added information about the new limits in the manual.
Updated Makefile.in
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.6.0beta15 [March 2, 2012]
Removed unused "current_text" members of png_struct and the png_free()
of png_ptr->current_text from pngread.c
Rewrote pngstest.c for substantial speed improvement.
Fixed transparent pixel and 16-bit rgb tests in pngstest and removed a
spurious check in pngwrite.c
Added PNG_IMAGE_FLAG_FAST for the benefit of applications that store
intermediate files, or intermediate in-memory data, while processing
image data with the simplified API. The option makes the files larger
but faster to write and read. pngstest now uses this by default; this
can be disabled with the --slow option.
Improved pngstest fine tuning of error numbers, new test file generator.
The generator generates images that test the full range of sample values,
allow the error numbers in pngstest to be tuned and checked. makepng
also allows generation of images with extra chunks, although this is
still work-in-progress.
Added tests for invalid palette index while reading and writing (work in
progress, the latter isn't finished).
Fixed some bugs in ICC profile writing. The code should now accept
all potentially valid ICC profiles and reject obviously invalid ones.
It now uses png_error() to do so rather than casually writing a PNG
without the necessary color data.
Removed whitespace from the end of lines in all source files and scripts.
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.6.0beta16 [March 6, 2012]
Relocated palette-index checking function from pngrutil.c to pngtrans.c
Added palette-index checking while writing.
Changed png_inflate() and calling routines to avoid overflow problems.
This is an intermediate check-in that solves the immediate problems and
introduces one performance improvement (avoiding a copy via png_ptr->zbuf.)
Further changes will be made to make ICC profile handling more secure.
Fixed build warnings (MSVC, GCC, GCC v3). Cygwin GCC with default options
declares 'index' as a global, causing a warning if it is used as a local
variable. GCC 64-bit warns about assigning a (size_t) (unsigned 64-bit)
to an (int) (signed 32-bit). MSVC, however, warns about using the
unary '-' operator on an unsigned value (even though it is well defined
by ANSI-C to be ~x+1). The padding calculation was changed to use a
different method. Removed the tests on png_ptr->pass.
Added contrib/libtests/tarith.c to test internal arithmetic functions from
png.c. This is a libpng maintainer program used to validate changes to the
internal arithmetic functions.
Made read 'inflate' handling like write 'deflate' handling. The read
code now claims and releases png_ptr->zstream, like the write code.
The bug whereby the progressive reader failed to release the zstream
is now fixed, all initialization is delayed, and the code checks for
changed parameters on deflate rather than always calling
deflatedEnd/deflateInit.
Validate the zTXt strings in pngvalid.
Added code to validate the windowBits value passed to deflateInit2().
If the call to deflateInit2() is wrong a png_warning will be issued
(in fact this is harmless, but the PNG data produced may be sub-optimal).
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.6.0beta17 [March 10, 2012]
Fixed PNG_LIBPNG_BUILD_BASE_TYPE definition.
Reject all iCCP chunks after the first, even if the first one is invalid.
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.
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
header.
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.6.0beta18 [March 16, 2012]
Issue a png_benign_error() instead of png_warning() about bad palette index.
In pngtest, treat benign errors as errors if "-strict" is present.
Fixed an off-by-one error in the palette index checking function.
Fixed a compiler warning under Cygwin (Windows-7, 32-bit system)
Revised example.c to put text strings in a temporary character array
instead of directly assigning string constants to png_textp members.
This avoids compiler warnings when -Wwrite-strings is enabled.
Added output flushing to aid debugging under Visual Studio. Unfortunately
this is necessary because the VS2010 output window otherwise simply loses
the error messages on error (they weren't flushed to the window before
the process exited, apparently!)
Added configuration support for benign errors and changed the read
default. Also changed some warnings in the iCCP and sRGB handling
from to benign errors. Configuration now makes read benign
errors warnings and write benign errors to errors by default (thus
changing the behavior on read). The simplified API always forces
read benign errors to warnings (regardless of the system default, unless
this is disabled in which case the simplified API can't be built.)
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.6.0beta19 [March 18,2012]
Work around for duplicate row start calls; added warning messages.
This turns on PNG_FLAG_DETECT_UNINITIALIZED to detect app code that
fails to call one of the 'start' routines (not enabled in libpng-1.5
because it is technically an API change, since it did normally work
before.) It also makes duplicate calls to png_read_start_row (an
internal function called at the start of the image read) benign, as
they were before changes to use png_inflate_claim. Somehow webkit is
causing this to happen; this is probably a mis-feature in the zlib
changes so this commit is only a work-round.
Removed erroneous setting of DETECT_UNINITIALIZED and added more
checks. The code now does a png_error if an attempt is made to do the
row initialization twice; this is an application error and it has
serious consequences because the transform data in png_struct is
changed by each call.
Added application error reporting and added chunk names to read
benign errors; also added --strict to pngstest - not enabled
yet because a warning is produced.
Avoid the double gamma correction warning in the simplified API.
This allows the --strict option to pass in the pngstest checks
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
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.6.0beta20 [March 29, 2012]
Changed chunk handler warnings into benign errors, incrementally load iCCP
Added checksum-icc.c to contrib/tools
Prevent PNG_EXPAND+PNG_SHIFT doing the shift twice.
Recognize known sRGB ICC profiles while reading; prefer writing the
iCCP profile over writing the sRGB chunk, controlled by the
PNG_sRGB_PROFILE_CHECKS option.
Revised png_set_text_2() to avoid potential memory corruption (fixes
CVE-2011-3048, also known as CVE-2012-3425).
Version 1.7.0beta10 [April 24, 2013]
Attempt to fix the PNG_ARM_NEON configuration mess.
Version 1.6.0beta21 [April 27, 2012]
Revised scripts/makefile.darwin: use system zlib; remove quotes around
architecture list; add missing ppc architecture; add architecture options
to shared library link; don't try to create a shared lib based on missing
RELEASE variable.
Enable png_set_check_for_invalid_index() for both read and write.
Removed #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED in pngpriv.h around
declaration of png_handle_unknown().
Added -lssp_nonshared in a comment in scripts/makefile.freebsd
and changed deprecated NOOBJ and NOPROFILE to NO_OBJ and NO_PROFILE.
Version 1.7.0beta11 [April 26, 2013]
Test for 'arm*', not just 'arm' in the host_cpu configure variable.
Version 1.6.0beta22 [May 23, 2012]
Removed need for -Wno-cast-align with clang. clang correctly warns on
alignment increasing pointer casts when -Wcast-align is passed. This
fixes the cases that clang warns about either by eliminating the
casts from png_bytep to png_uint_16p (pngread.c), or, for pngrutil.c
where the cast is previously verified or pngstest.c where it is OK, by
introducing new png_aligncast macros to do the cast in a way that clang
accepts.
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.6.0beta23 [June 6, 2012]
Revised CMakeLists.txt to not attempt to make a symlink under mingw.
Made fixes for new optimization warnings from gcc 4.7.0. The compiler
performs an optimization which is safe; however it then warns about it.
Changing the type of 'palette_number' in pngvalid.c removes the warning.
Do not depend upon a GCC feature macro being available for use in generating
the linker mapfile symbol prefix.
Improved performance of new do_check_palette_indexes() function (only
update the value when it actually increases, move test for whether
the check is wanted out of the function.
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.6.0beta24 [June 7, 2012]
Don't check palette indexes if num_palette is 0 (as it can be in MNG files).
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.6.0beta25 [June 16, 2012]
Revised png_set_keep_unknown_chunks() so num_chunks < 0 means ignore all
unknown chunks and all known chunks except for IHDR, PLTE, tRNS, IDAT,
and IEND. Previously it only meant ignore all unknown chunks, the
same as num_chunks == 0. Revised png_image_skip_unused_chunks() to
provide a list of chunks to be processed instead of a list of chunks to
ignore. Revised contrib/gregbook/readpng2.c accordingly.
Version 1.7.0beta15 [June 18, 2013]
Revised libpng.3 so that "doclifter" can process it.
Version 1.6.0beta26 [July 10, 2012]
Removed scripts/makefile.cegcc from the *.zip and *.7z distributions; it
depends on configure, which is not included in those archives.
Moved scripts/chkfmt to contrib/tools.
Changed "a+w" to "u+w" in Makefile.in to fix CVE-2012-3386.
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.6.0beta27 [August 11, 2012]
Do not compile PNG_DEPRECATED, PNG_ALLOC and PNG_PRIVATE when __GNUC__ < 3.
Do not use __restrict when GNUC is <= 3.1
Removed references to png_zalloc() and png_zfree() from the manual.
Fixed configurations where floating point is completely disabled. Because
of the changes to support symbol prefixing PNG_INTERNAL_FUNCTION declares
floating point APIs during libpng builds even if they are completely
disabled. This requires the png floating point types (png_double*) to be
declared even though the functions are never actually defined. This
change provides a dummy definition so that the declarations work, yet any
implementation will fail to compile because of an incomplete type.
Re-eliminated the use of strcpy() in pngtest.c. An unncessary use of
strcpy() was accidentally re-introduced in libpng16; this change replaces
it with strncpy().
Eliminated use of png_sizeof(); use sizeof() instead.
Use a consistent style for (sizeof type) and (sizeof (array))
Cleanup of png_set_filler(). This function does very different things on
read and write. In libpng 1.6 the two cases can be distinguished and
considerable code cleanup, and extra error checking, is possible. This
makes calls on the write side that have no effect be ignored with a
png_app_error(), which can be disabled in the app using
png_set_benign_errors(), and removes the spurious use of usr_channels
on the read side.
Insist on autotools 1.12.1 for git builds because there are security issues
with 1.12 and insisting on anything less would allow 1.12 to be used.
Removed info_ptr->signature[8] from WRITE-only builds.
Add some conditions for compiling png_fixed(). This is a small function
but it requires "-lm" on some platforms.
Cause pngtest --strict to fail on any warning from libpng (not just errors)
and cause it not to fail at the comparison step if libpng lacks support
for writing chunks that it reads from the input (currently only implemented
for compressed text chunks).
Make all three "make check" test programs work without READ or WRITE support.
Now "make check" will succeed even if libpng is compiled with -DPNG_NO_READ
or -DPNG_NO_WRITE. The tests performed are reduced, but the basic reading
and writing of a PNG file is always tested by one or more of the tests.
Consistently use strlen(), memset(), memcpy(), and memcmp() instead of the
png_strlen(), png_memset(), png_memcpy(), and png_memcmp() macros.
Removed the png_sizeof(), png_strlen(), png_memset(), png_memcpy(), and
png_memcmp() macros.
Work around gcc 3.x and Microsoft Visual Studio 2010 complaints. Both object
to the split initialization of num_chunks.
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.6.0beta28 [August 29, 2012]
Unknown handling fixes and clean up. This adds more correct option
control of the unknown handling, corrects the pre-existing bug where
the per-chunk 'keep' setting is ignored and makes it possible to skip
IDAT chunks in the sequential reader (broken in earlier 1.6 versions).
There is a new test program, test-unknown.c, which is a work in progress
(not currently part of the test suite). Comments in the header files now
explain how the unknown handling works.
Allow fine grain control of unknown chunk APIs. This change allows
png_set_keep_unknown_chunks() to be turned off if not required and causes
both read and write to behave appropriately (on read this is only possible
if the user callback is used to handle unknown chunks). The change
also removes the support for storing unknown chunks in the info_struct
if the only unknown handling enabled is via the callback, allowing libpng
to be configured with callback reading and none of the unnecessary code.
Corrected fix for unknown handling in pngtest. This reinstates the
libpng handling of unknown chunks other than vpAg and sTER (including
unsafe-to-copy chunks which were dropped before) and eliminates the
repositioning of vpAg and sTER in pngtest.png by changing pngtest.png
(so the chunks are where libpng would put them).
Added "tunknown" test and corrected a logic error in png_handle_unknown()
when SAVE support is absent. Moved the shell test scripts for
contrib/libtests from the libpng top directory to contrib/libtests.
png_handle_unknown() must always read or skip the chunk, if
SAVE_UNKNOWN_CHUNKS is turned off *and* the application does not set
a user callback an unknown chunk will not be read, leading to a read
error, which was revealed by the "tunknown" test.
Cleaned up and corrected ICC profile handling.
contrib/libtests/makepng: corrected 'rgb' and 'gray' cases. profile_error
messages could be truncated; made a correct buffer size calculation and
adjusted pngerror.c appropriately. png_icc_check_* checking improved;
changed the functions to receive the correct color type of the PNG on read
or write and check that it matches the color space of the profile (despite
what the comments said before, there is danger in assuming the app will
cope correctly with an RGB profile on a grayscale image and, since it
violates the PNG spec, allowing it is certain to produce inconsistent
app behavior and might even cause app crashes.) Check that profiles
contain the tags needed to process the PNG (tags all required by the ICC
spec). Removed unused PNG_STATIC from pngpriv.h.
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.6.0beta29 [September 4, 2012]
Fixed the simplified API example programs and improved the error message
if the version field is not set.
Added contrib/examples/* to the *.zip and *.7z distributions.
Updated simplified API synopses and description of the png_image structure
in the manual.
Made makepng and pngtest produce identical PNGs, add "--relaxed" option
to pngtest. The "--relaxed" option turns off the benign errors that are
enabled by default in pre-RC builds. makepng can now write ICC profiles
where the length has not been extended to a multiple of 4, and pngtest
now intercepts all libpng errors, allowing the previously-introduced
"--strict test" on no warnings to actually work.
Improved ICC profile handling including cHRM chunk generation and fixed
Cygwin+MSVC build errors. The ICC profile handling now includes more
checking. Several errors that caused rejection of the profile are now
handled with a warning in such a way that the invalid profiles will be
read by default in release (but not pre-RC) builds but will not be
written by default. The easy part of handling the cHRM chunk is written,
where the ICC profile contains the required data. The more difficult
part plus guessing a gAMA value requires code to pass selected RGB values
through the profile.
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.6.0beta30 [October 24, 2012]
Changed ICC profile matrix/vector types to not depend on array type rules.
By the ANSI-C standard the new types should be identical to the previous
versions, and all known versions of gcc tested with the previous versions
except for GCC-4.2.1 work with this version. The change makes the ANSI-C
rule that const applied to an array of elements applies instead to the
elements in the array moot by explicitly applying const to the base
elements of the png_icc_matrix and png_icc_vector types. The accidental
(harmless) 'const' previously applied to the parameters of two of the
functions have also been removed.
Added a work around for GCC 4.2 optimization bug.
Marked the broken (bad white point) original HP sRGB profiles correctly and
correct comments.
Added -DZ_SOLO to contrib/pngminim/*/makefile to work with zlib-1.2.7
Use /MDd for vstudio debug builds. Also added pngunkown to the vstudio
builds, fixed build errors and corrected a minor exit code error in
pngvalid if the 'touch' file name is invalid.
Add updated WARNING file to projects/vstudio from libpng 1.5/vstudio
Fixed build when using #define PNG_NO_READ_GAMMA in png_do_compose() in
pngrtran.c (Domani Hannes).
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.6.0beta31 [November 1, 2012]
Undid the erroneous change to vstudio/pngvalid build in libpng-1.6.0beta30.
Made pngvalid so that it will build outside the libpng source tree.
Made builds -DPNG_NO_READ_GAMMA compile (the unit tests still fail).
Made PNG_NO_READ_GAMMA switch off interfaces that depend on READ_GAMMA.
Prior to 1.6.0 switching off READ_GAMMA did unpredictable things to the
interfaces that use it (specifically, png_do_background in 1.4 would
simply display composite for grayscale images but do composition
with the incorrect arithmetic for color ones). In 1.6 the semantic
of -DPNG_NO_READ_GAMMA is changed to simply disable any interface that
depends on it; this obliges people who set it to consider whether they
really want it off if they happen to use any of the interfaces in
question (typically most users who disable it won't).
Fixed GUIDs in projects/vstudio. Some were duplicated or missing,
resulting in VS2010 having to update the files.
Removed non-working ICC profile support code that was mostly added to
libpng-1.6.0beta29 and beta30. There was too much code for too little
gain; implementing full ICC color correction may be desireable but is left
up to applications.
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.6.0beta32 [November 25, 2012]
Fixed an intermittent SEGV in pngstest due to an uninitialized array element.
Added the ability for contrib/libtests/makepng.c to make a PNG with just one
color. This is useful for debugging pngstest color inaccuracy reports.
Fixed error checking in the simplified write API (Olaf van der Spek)
Made png_user_version_check() ok to use with libpng version 1.10.x and later.
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.6.0beta33 [December 10, 2012]
Fixed typo in png.c (PNG_SET_CHUNK_MALLOC_MAX should be PNG_CHUNK_MALLOC_MAX)
that causes the MALLOC_MAX limit not to work (John Bowler)
Change png_warning() to png_app_error() in pngwrite.c and comment the
fall-through condition.
Change png_warning() to png_app_warning() in png_write_tRNS().
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 masde static. Move the intrapixel functions and the
grayscale palette builder out of the png?tran.c files. The latter
isn't a transform function and is no longer used internally, and the
former MNG specific functions are better placed in pngread/pngwrite.c
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().
Send comments/corrections/commendations to png-mng-implement at lists.sf.net
(subscription required; visit

471
CHANGES
View File

@@ -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,470 @@ 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().
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 masde static. Move the intrapixel functions and the
grayscale palette builder out of the png?tran.c files. The latter
isn't a transform function and is no longer used internally, and the
former MNG specific functions are better placed in pngread/pngwrite.c
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().
Send comments/corrections/commendations to png-mng-implement at lists.sf.net
(subscription required; visit
https://lists.sourceforge.net/lists/listinfo/png-mng-implement

View File

@@ -1,6 +1,6 @@
# CMakeLists.txt
# Copyright (C) 2007-2011 Glenn Randers-Pehrson
# Copyright (C) 2007-2013 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,15 @@ 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 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 +252,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.0beta27
VERSION 17.${PNGLIB_RELEASE}.0
SOVERSION 17
CLEAN_DIRECT_OUTPUT 1)
endif()
if(PNG_STATIC)
@@ -287,40 +279,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)

27
INSTALL
View File

@@ -41,19 +41,33 @@ 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.
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".
If you want to use "cmake" (see www.cmake.org), type
cmake . -DCMAKE_INSTALL_PREFIX=/path
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.
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.7"
or "zlib127") so that you have directories called "zlib" and "libpng".
Your directory structure should look like this:
@@ -71,6 +85,7 @@ Your directory structure should look like this:
depcomp, install-sh, mkinstalldirs, test-pngtest.sh
contrib
gregbook
libtests
pngminim
pngminus
pngsuite

View File

@@ -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.0beta27, January 10, 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
January 10, 2014

View File

@@ -7,24 +7,62 @@ 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
# 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
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
# 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 +81,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 +115,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
@@ -118,6 +159,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 +174,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 +200,27 @@ 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/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 +235,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 +289,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)

36
README
View File

@@ -1,11 +1,11 @@
README for libpng version 1.6.0beta33 - December 10, 2012 (shared library 16.0)
README for libpng version 1.7.0beta27 - January 10, 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
@@ -77,17 +77,15 @@ 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.
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 +121,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 +165,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
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)

232
arm/arm_init.c Normal file
View File

@@ -0,0 +1,232 @@
/* arm_init.c - NEON optimised filter functions
*
* Copyright (c) 2013 Glenn Randers-Pehrson
* Written by Mans Rullgard, 2011.
* Last changed in libpng 1.6.6 [September 16, 2013]
*
* 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 */
#include <signal.h> /* for sig_atomic_t */
#ifdef __ANDROID__
/* Linux provides access to information about CPU capabilites via
* /proc/self/auxv, however Android blocks this while still claiming to be
* Linux. The Andoid NDK, however, provides appropriate support.
*
* Documentation: http://www.kandroid.org/ndk/docs/CPU-ARM-NEON.html
*/
#include <cpu-features.h>
static int
png_have_neon(png_structp png_ptr)
{
/* This is a whole lot easier than the mess below, 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;
}
#elif defined(__linux__)
/* The 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;
}
#else
/* We don't know how to do a run-time check on this system */
# error "no support for run-time ARM NEON checks"
#endif /* OS checks */
#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 */

View File

@@ -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) */

View 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) */

View File

@@ -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

View File

@@ -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.0beta27],[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.0beta27
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"
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`
@@ -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*) :;;
*) 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

46
contrib/conftest/README Normal file
View File

@@ -0,0 +1,46 @@
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.
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
View 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

View 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

View 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

View 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

View 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')

View File

@@ -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);

View File

@@ -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

View File

@@ -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

View File

@@ -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;
}

View 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);
}

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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 */

View File

@@ -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.0 [February 14, 2013]
* Copyright (c) 2013 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)
@@ -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
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
View 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);
}

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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')
{

View File

@@ -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)

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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)

View File

@@ -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

View File

@@ -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

View File

@@ -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)

View File

@@ -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

View File

@@ -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

View File

@@ -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

View 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] != ' '));

View 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
View 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
View 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 */

View File

@@ -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.

View File

@@ -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.

View File

@@ -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.

View 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;
}

4036
contrib/tools/pngfix.c Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -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
View 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;
}

View File

@@ -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)
{
@@ -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
@@ -455,7 +455,7 @@ 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);
png_set_gamma(png_ptr, screen_gamma, PNG_DEFAULT_sRGB);
else
{
double image_gamma;

View File

@@ -1,9 +1,9 @@
libpng-manual.txt - A description on how to use and modify libpng
libpng version 1.6.0beta33 - December 10, 2012
libpng version 1.7.0beta27 - January 10, 2014
Updated and distributed by Glenn Randers-Pehrson
<glennrp at users.sourceforge.net>
Copyright (c) 1998-2011 Glenn Randers-Pehrson
Copyright (c) 1998-2013 Glenn Randers-Pehrson
This document is released under the libpng license.
For conditions of distribution and use, see the disclaimer
@@ -11,9 +11,9 @@ libpng-manual.txt - A description on how to use and modify libpng
Based on:
libpng versions 0.97, January 1998, through 1.6.0beta33 - December 10, 2012
libpng versions 0.97, January 1998, through 1.7.0beta27 - January 10, 2014
Updated and distributed by Glenn Randers-Pehrson
Copyright (c) 1998-2011 Glenn Randers-Pehrson
Copyright (c) 1998-2013 Glenn Randers-Pehrson
libpng 1.0 beta 6 version 0.96 May 28, 1997
Updated and distributed by Andreas Dilger
@@ -42,17 +42,16 @@ libpng-manual.txt - A description on how to use and modify libpng
X. Changes to Libpng from version 1.0.x/1.2.x to 1.4.x
XI. Changes to Libpng from version 1.4.x to 1.5.x
XII. Changes to Libpng from version 1.5.x to 1.6.x
XIII. Detecting libpng
XIV. Source code repository
XV. Coding style
XVI. Y2K Compliance in libpng
XIII. Changes to Libpng from version 1.6.x to 1.7.x
XIV. Detecting libpng
XV. Source code repository
XVI. Coding style
XVII. Y2K Compliance in libpng
I. Introduction
This file describes how to use and modify the PNG reference library
(known as libpng) for your own use. There are five sections to this
file: introduction, structures, reading, writing, and modification and
configuration notes for various special platforms. In addition to this
(known as libpng) for your own use. In addition to this
file, example.c is a good starting point for using the library, as
it is heavily commented and should include everything most people
will need. We assume that libpng is already installed; see the
@@ -431,7 +430,7 @@ If you would rather avoid the complexity of setjmp/longjmp issues,
you can compile libpng with PNG_NO_SETJMP, in which case
errors will result in a call to PNG_ABORT() which defaults to abort().
You can #define PNG_ABORT() to a function that does something
You can #define PNG_ABORT to a function or other C code that does something
more useful than abort(), as long as your function does not
return.
@@ -526,10 +525,15 @@ you can retrieve with
png_get_user_chunk_ptr(png_ptr);
If you call the png_set_read_user_chunk_fn() function, then all unknown
chunks will be saved when read, in case your callback function will need
one or more of them. This behavior can be changed with the
png_set_keep_unknown_chunks() function, described below.
If you call the png_set_read_user_chunk_fn() function, then all unknown chunks
will be passed to your callback when read. You can cause known chunks to be
passed in as well by using png_set_keep_unknown_chunks (see below) - this will
prevent the normal libpng handling of those known chunks.
If your callback returns 0 the default unknown handling will be used (see
below). This is new behavior in libpng 1.7, prior to 1.7 it was not possible to
discard a chunk; PNG_HANDLE_CHUNK_IF_SAFE was forced. Libpng 1.6.0 issues a
warning when this was done.
At this point, you can set up a callback function that will be
called after each row has been read, which you can use to control
@@ -636,7 +640,7 @@ callback function:
/* also ignore unused known chunks: */
png_set_keep_unknown_chunks(read_ptr, 1, unused_chunks,
(int)sizeof(unused_chunks)/5);
(int)(sizeof unused_chunks)/5);
#endif
User limits
@@ -675,9 +679,6 @@ where 0x7fffffffL means unlimited. You can retrieve this limit with
chunk_cache_max = png_get_chunk_cache_max(png_ptr);
This limit also applies to the number of buffers that can be allocated
by png_decompress_chunk() while decompressing iTXt, zTXt, and iCCP chunks.
You can also set a limit on the amount of memory that a compressed chunk
other than IDAT can occupy, with
@@ -738,7 +739,7 @@ situations:
encoding.
You would use the linear (unencoded) value if you need to process the pixel
values further because this avoids the need to decode and reencode each
values further because this avoids the need to decode and re-encode each
component value whenever arithmetic is performed. A lot of graphics software
uses linear values for this reason, often with higher precision component values
to preserve overall accuracy.
@@ -991,7 +992,7 @@ where row_pointers is an array of pointers to the pixel data for each row:
If you know your image size and pixel size ahead of time, you can allocate
row_pointers prior to calling png_read_png() with
if (height > PNG_UINT_32_MAX/png_sizeof(png_byte))
if (height > PNG_UINT_32_MAX/(sizeof (png_byte))
png_error (png_ptr,
"Image is too tall to process in memory");
@@ -1000,7 +1001,7 @@ row_pointers prior to calling png_read_png() with
"Image is too wide to process in memory");
row_pointers = png_malloc(png_ptr,
height*png_sizeof(png_bytep));
height*(sizeof (png_bytep)));
for (int i=0; i<height, i++)
row_pointers[i]=NULL; /* security precaution */
@@ -2287,7 +2288,7 @@ For a more compact example of reading a PNG image, see the file example.c.
Reading PNG files progressively
The progressive reader is slightly different then the non-progressive
The progressive reader is slightly different from the non-progressive
reader. Instead of calling png_read_info(), png_read_rows(), and
png_read_end(), you make one call to png_process_data(), which calls
callbacks when it has the info, a row, or the end of the image. You
@@ -2561,9 +2562,9 @@ section below for more information on the libpng error handling.
If you would rather avoid the complexity of setjmp/longjmp issues,
you can compile libpng with PNG_NO_SETJMP, in which case
errors will result in a call to PNG_ABORT() which defaults to abort().
errors will result in a call to PNG_ABORT which defaults to abort().
You can #define PNG_ABORT() to a function that does something
You can #define PNG_ABORT to a function or other C code that does something
more useful than abort(), as long as your function does not
return.
@@ -3083,19 +3084,53 @@ tEXt chunk use RFC 1123 format dates (e.g. "22 May 1997 18:07:10 GMT"),
although this isn't a requirement. Unlike the tIME chunk, the
"Creation Time" tEXt chunk is not expected to be automatically changed
by the software. To facilitate the use of RFC 1123 dates, a function
png_convert_to_rfc1123_buffer(buffer, png_timep) is provided to convert
from PNG time to an RFC 1123 format string. The caller must provide
png_convert_to_rfc1123_buffer(png_ptr, buffer, png_timep) is provided to
convert from PNG time to an RFC 1123 format string. The caller must provide
a writeable buffer of at least 29 bytes.
Writing unknown chunks
You can use the png_set_unknown_chunks function to queue up chunks
for writing. You give it a chunk name, raw data, and a size; that's
all there is to it. The chunks will be written by the next following
png_write_info_before_PLTE, png_write_info, or png_write_end function.
Any chunks previously read into the info structure's unknown-chunk
list will also be written out in a sequence that satisfies the PNG
specification's ordering rules.
You can use the png_set_unknown_chunks function to queue up private chunks
for writing. You give it a chunk name, location, raw data, and a size. You
also must use png_set_keep_unknown_chunks() to ensure that libpng will
handle them. That's all there is to it. The chunks will be written by the
next following png_write_info_before_PLTE, png_write_info, or png_write_end
function, depending upon the specified location. Any chunks previously
read into the info structure's unknown-chunk list will also be written out
in a sequence that satisfies the PNG specification's ordering rules.
Here is an example of writing two private chunks, prVt and miNE:
#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
/* Set unknown chunk data */
png_unknown_chunk unk_chunk[2];
strcpy((char *) unk_chunk[0].name, "prVt";
unk_chunk[0].data = (unsigned char *) "PRIVATE DATA";
unk_chunk[0].size = strlen(unk_chunk[0].data)+1;
unk_chunk[0].location = PNG_HAVE_IHDR;
strcpy((char *) unk_chunk[1].name, "miNE";
unk_chunk[1].data = (unsigned char *) "MY CHUNK DATA";
unk_chunk[1].size = strlen(unk_chunk[0].data)+1;
unk_chunk[1].location = PNG_AFTER_IDAT;
png_set_unknown_chunks(write_ptr, write_info_ptr,
unk_chunk, 2);
/* Needed because miNE is not safe-to-copy */
png_set_keep_unknown_chunks(png, PNG_HANDLE_CHUNK_ALWAYS,
(png_bytep) "miNE", 1);
# if PNG_LIBPNG_VER < 10600
/* Deal with unknown chunk location bug in 1.5.x and earlier */
png_set_unknown_chunk_location(png, info, 0, PNG_HAVE_IHDR);
png_set_unknown_chunk_location(png, info, 1, PNG_AFTER_IDAT);
# endif
# if PNG_LIBPNG_VER < 10500
/* PNG_AFTER_IDAT writes two copies of the chunk prior to libpng-1.5.0,
* one before IDAT and another after IDAT, so don't use it; only use
* PNG_HAVE_IHDR location. This call resets the location previously
* set by assignment and png_set_unknown_chunk_location() for chunk 1.
*/
png_set_unknown_chunk_location(png, info, 1, PNG_HAVE_IHDR);
# endif
#endif
The high-level write interface
@@ -3499,7 +3534,7 @@ The simplified API, which became available in libpng-1.6.0, hides the details
of both libpng and the PNG file format itself.
It allows PNG files to be read into a very limited number of
in-memory bitmap formats or to be written from the same formats. If these
formats do not accomodate your needs then you can, and should, use the more
formats do not accommodate your needs then you can, and should, use the more
sophisticated APIs above - these support a wide variety of in-memory formats
and a wide variety of sophisticated transformations to those formats as well
as a wide variety of APIs to manipulate ancilliary information.
@@ -3942,7 +3977,7 @@ Error handling in libpng is done through png_error() and png_warning().
Errors handled through png_error() are fatal, meaning that png_error()
should never return to its caller. Currently, this is handled via
setjmp() and longjmp() (unless you have compiled libpng with
PNG_NO_SETJMP, in which case it is handled via PNG_ABORT()),
PNG_NO_SETJMP, in which case it is handled via PNG_ABORT),
but you could change this to do things like exit() if you should wish,
as long as your function does not return.
@@ -3984,6 +4019,18 @@ compiler documentation for more details. For an alternative approach, you
may wish to use the "cexcept" facility (see http://cexcept.sourceforge.net),
which is illustrated in pngvalid.c and in contrib/visupng.
Beginning in libpng-1.4.0, the png_set_benign_errors() API became available.
You can use this to handle certain errors (normally handled as errors)
as warnings.
png_set_benign_errors (png_ptr, int allowed);
allowed: 0: treat png_benign_error() as an error.
1: treat png_benign_error() as a warning.
As of libpng-1.6.0, the default condition is to treat benign errors as
warnings while reading and as errors while writing.
Custom chunks
If you need to read or write custom chunks, you may need to get deeper
@@ -4254,7 +4301,7 @@ the message, "message" is the formatted string to be printed,
and p1 and p2 are parameters that are to be embedded in the string
according to printf-style formatting directives. For example,
png_debug1(2, "foo=%d\n", foo);
png_debug1(2, "foo=%d", foo);
is expanded to
@@ -4561,7 +4608,7 @@ it has not been well tested and doesn't actually "dither".
The code was not
removed, however, and could be enabled by building libpng with
PNG_READ_DITHER_SUPPORTED defined. In libpng-1.4.2, this support
was reenabled, but the function was renamed png_set_quantize() to
was re-enabled, but the function was renamed png_set_quantize() to
reflect more accurately what it actually does. At the same time,
the PNG_DITHER_[RED,GREEN_BLUE]_BITS macros were also renamed to
PNG_QUANTIZE_[RED,GREEN,BLUE]_BITS, and PNG_READ_DITHER_SUPPORTED
@@ -4573,12 +4620,13 @@ XI. Changes to Libpng from version 1.4.x to 1.5.x
From libpng-1.4.0 until 1.4.4, the png_get_uint_16 macro (but not the
function) incorrectly returned a value of type png_uint_32.
The incorrect macro was removed from libpng-1.4.5.
Checking for invalid palette index on read or write was added at libpng
1.5.10. When an invalid index is found, libpng issues a benign error.
This is enabled by default because this condition is an error according
to the PNG specification, Clause 11.3.2, but the error can be ignored in
each png_ptr with
Checking for invalid palette index on write was added at libpng
1.5.10. If a pixel contains an invalid (out-of-range) index libpng issues
a benign error. This is enabled by default because this condition is an
error according to the PNG specification, Clause 11.3.2, but the error can
be ignored in each png_ptr with
png_set_check_for_invalid_index(png_ptr, allowed);
@@ -4593,6 +4641,18 @@ If the error is ignored, or if png_benign_error() treats it as a warning,
any invalid pixels are decoded as opaque black by the decoder and written
as-is by the encoder.
Retrieving the maximum palette index found was added at libpng-1.5.15.
This statement must appear after png_read_png() or png_read_image() while
reading, and after png_write_png() or png_write_image() while writing.
int max_palette = png_get_palette_max(png_ptr, info_ptr);
This will return the maximum palette index found in the image, or "-1" if
the palette was not checked, or "0" if no palette was found. Note that this
does not account for any palette index used by ancillary chunks such as the
bKGD chunk; you must check those separately to determine the maximum
palette index actually used.
A. Changes that affect users of libpng
There are no substantial API changes between the non-deprecated parts of
@@ -4685,15 +4745,10 @@ reset by pngusr.h or by explicit settings on the compiler command line.
These settings may produce compiler warnings or errors in 1.5.0 because
of macro redefinition.
From libpng-1.4.0 until 1.4.4, the png_get_uint_16 macro (but not the
function) incorrectly returned a value of type png_uint_32. libpng 1.5.0
is consistent with the implementation in 1.4.5 and 1.2.x (where the macro
did not exist.)
Applications can now choose whether to use these macros or to call the
corresponding function by defining PNG_USE_READ_MACROS or
PNG_NO_USE_READ_MACROS before including png.h. Notice that this is
only supported from 1.5.0 -defining PNG_NO_USE_READ_MACROS prior to 1.5.0
only supported from 1.5.0; defining PNG_NO_USE_READ_MACROS prior to 1.5.0
will lead to a link failure.
Prior to libpng-1.5.4, the zlib compressor used the same set of parameters
@@ -4707,7 +4762,10 @@ option was off by default, and slightly inaccurate scaling occurred.
This option can no longer be turned off, and the choice of accurate
or inaccurate 16-to-8 scaling is by using the new png_set_scale_16_to_8()
API for accurate scaling or the old png_set_strip_16_to_8() API for simple
chopping.
chopping. In libpng-1.5.4, the PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED
macro became PNG_READ_SCALE_16_TO_8_SUPPORTED, and the PNG_READ_16_TO_8
macro became PNG_READ_STRIP_16_TO_8_SUPPORTED, to enable the two
png_set_*_16_to_8() functions separately.
Prior to libpng-1.5.4, the png_set_user_limits() function could only be
used to reduce the width and height limits from the value of
@@ -4729,6 +4787,9 @@ limits are now
png_user_chunk_cache_max 0 (unlimited) 128
png_user_chunk_malloc_max 0 (unlimited) 8,000,000
The png_set_option() function (and the "options" member of the png struct) was
added to libpng-1.5.15.
B. Changes to the build and configuration of libpng
Details of internal changes to the library code can be found in the CHANGES
@@ -4922,18 +4983,20 @@ symbols, using the PNG_PREFIX macro.
We no longer include string.h in png.h. The include statement has been moved
to pngpriv.h, where it is not accessible by applications. Applications that
need access to information in string.h must add an '#include "string.h"'
need access to information in string.h must add an '#include <string.h>'
directive. It does not matter whether this is placed prior to or after
the '"#include png.h"' directive.
the '#include "png.h"' directive.
The following API are now DEPRECATED:
png_info_init_3()
png_convert_to_rfc1123() which has been replaced
with png_convert_to_rfc1123_buffer()
png_data_freer()
png_malloc_default()
png_free_default()
png_reset_zstream()
The following has been removed:
The following have been removed:
png_get_io_chunk_name(), which has been replaced
with png_get_io_chunk_type(). The new
function returns a 32-bit integer instead of
@@ -4950,8 +5013,25 @@ where "rp" indicates a "restricted pointer".
Error detection in some chunks has improved; in particular the iCCP chunk
reader now does pretty complete validation of the basic format. Some bad
profiles that were previously accepted are now rejected, in particular the
very old broken Microsoft/HP sRGB profile.
profiles that were previously accepted are now accepted with a warning or
rejected, depending upon the png_set_benign_errors() setting, in particular the
very old broken Microsoft/HP 3144-byte sRGB profile. The PNG spec requirement
that only grayscale profiles may appear in images with color type 0 or 4 and
that even if the image only contains gray pixels, only RGB profiles may appear
in images with color type 2, 3, or 6, is now enforced. The sRGB chunk
is allowed to appear in images with any color type.
Prior to libpng-1.6.0 a warning would be issued if the iTXt chunk contained
an empty language field or an empty translated keyword. Both of these
are allowed by the PNG specification, so these warnings are no longer issued.
The library now issues an error if the application attempts to set a
transform after it calls png_read_update_info() or if it attempts to call
both png_read_update_info() and png_start_read_image() or to call either
of them more than once.
The default condition for benign_errors is now to treat benign errors as
warnings while reading and as errors while writing.
The library now issues a warning if both background processing and RGB to
gray are used when gamma correction happens. As with previous versions of
@@ -4965,7 +5045,64 @@ This adds more correct option control of the unknown handling, corrects
a pre-existing bug where the per-chunk 'keep' setting is ignored, and makes
it possible to skip IDAT chunks in the sequential reader.
XIII. Detecting libpng
The machine-generated configure files are no longer included in branches
libpng16 and later of the GIT repository. They continue to be included
in the tarball releases, however.
Libpng-1.6.0 through 1.6.2 used the CMF bytes at the beginning of the IDAT
stream to set the size of the sliding window for reading instead of using the
default 32-kbyte sliding window size. It was discovered that there are
hundreds of PNG files in the wild that have incorrect CMF bytes that caused
libpng to issue a "too far back" error and reject the file. Libpng-1.6.3 and
later calculate their own safe CMF from the image dimensions, provide a way
to revert to the libpng-1.5.x behavior (ignoring the CMF bytes and using a
32-kbyte sliding window), by using
png_set_option(png_ptr, PNG_MAXIMUM_INFLATE_WINDOW,
PNG_OPTION_ON);
and provide a tool (contrib/tools/pngfix) for optimizing the CMF bytes
correctly.
Libpng-1.6.0 and libpng-1.6.1 wrote uncompressed iTXt chunks with the wrong
length, which resulted in PNG files that cannot be read beyond the bad iTXt
chunk. This error was fixed in libpng-1.6.3, and a tool (called
contrib/tools/png-fix-itxt) has been added to the libpng distribution.
XIII. Changes to Libpng from version 1.6.x to 1.7.x
Some functions that were deprecated in libpng-1.6.0 were removed:
png_reset_zstream(),
png_info_init_3(),
png_data_freer() and its associated flags,
png_malloc_default(),
and png_free_default().
The PNG_ABORT() macro was changed to PNG_ABORT, and the default is now
"abort()" for all platforms (previously it was "ExitProcess(0)" on
Windows platforms). Starting with libpng-1.7.0 you have to define
PNG_ABORT instead of PNG_ABORT(), and you must include a terminating
semicolon in your definition, e.g.,
#if PNGCRUSH_LIBPNG_VER >= 10700
# ifdef _WINDOWS_
# define PNG_ABORT ExitProcess(0);
# else
# define PNG_ABORT abort();
# endif
#else
# ifdef _WINDOWS_
# define PNG_ABORT() ExitProcess(0)
# else
# define PNG_ABORT() abort()
# endif
#endif
The 8-bit compose and rgb_to_grayscale operations were made more accurate.
While these did not introduce API incompatibility, there may be differences
in unit test results.
XIV. Detecting libpng
The png_get_io_ptr() function has been present since libpng-0.88, has never
changed, and is unaffected by conditional compilation macros. It is the
@@ -4981,11 +5118,11 @@ control. The git repository was built from old libpng-x.y.z.tar.gz files
going back to version 0.70. You can access the git repository (read only)
at
git://libpng.git.sourceforge.net/gitroot/libpng
git://git.code.sf.net/p/libpng/code
or you can browse it via "gitweb" at
or you can browse it with a web browser by selecting the "code" button at
http://libpng.git.sourceforge.net/git/gitweb.cgi?p=libpng
https://sourceforge.net/projects/libpng
Patches can be sent to glennrp at users.sourceforge.net or to
png-mng-implement at lists.sourceforge.net or you can upload them to
@@ -4998,7 +5135,7 @@ simple verbal discriptions of bug fixes, reported either to the
SourceForge bug tracker, to the png-mng-implement at lists.sf.net
mailing list, or directly to glennrp.
XV. Coding style
XVI. Coding style
Our coding style is similar to the "Allman" style, with curly
braces on separate lines:
@@ -5110,7 +5247,8 @@ left parenthesis that follows it:
y[i] = a(x) + (int)b;
We prefer #ifdef and #ifndef to #if defined() and #if !defined()
when there is only one macro being tested.
when there is only one macro being tested. We always use parentheses
with "defined".
We prefer to express integers that are used as bit masks in hex format,
with an even number of lower-case hex digits (e.g., 0x00, 0xff, 0x0100).
@@ -5124,15 +5262,15 @@ Lines do not exceed 80 characters.
Other rules can be inferred by inspecting the libpng source.
XVI. Y2K Compliance in libpng
XVII. Y2K Compliance in libpng
December 10, 2012
January 10, 2014
Since the PNG Development group is an ad-hoc body, we can't make
an official declaration.
This is your unofficial assurance that libpng from version 0.71 and
upward through 1.6.0beta33 are Y2K compliant. It is my belief that earlier
upward through 1.7.0beta27 are Y2K compliant. It is my belief that earlier
versions were also Y2K compliant.
Libpng only has two year fields. One is a 2-byte unsigned integer

827
libpng.3

File diff suppressed because it is too large Load Diff

View File

@@ -1,21 +1,11 @@
.TH LIBPNGPF 3 "December 10, 2012"
.TH LIBPNGPF 3 "January 10, 2014"
.SH NAME
libpng \- Portable Network Graphics (PNG) Reference Library 1.6.0beta33
libpng \- Portable Network Graphics (PNG) Reference Library 1.7.0beta27
(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
View File

@@ -1,4 +1,4 @@
.TH PNG 5 "December 10, 2012"
.TH PNG 5 "January 10, 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

844
png.c

File diff suppressed because it is too large Load Diff

468
png.h
View File

@@ -1,8 +1,8 @@
/* png.h - header file for PNG reference library
*
* libpng version 1.6.0beta33 - December 10, 2012
* Copyright (c) 1998-2012 Glenn Randers-Pehrson
* libpng version 1.7.0beta27 - January 10, 2014
* 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.)
*
@@ -11,7 +11,7 @@
* Authors and maintainers:
* libpng versions 0.71, May 1995, through 0.88, January 1996: Guy Schalnat
* libpng versions 0.89c, June 1996, through 0.96, May 1997: Andreas Dilger
* libpng versions 0.97, January 1998, through 1.6.0beta33 - December 10, 2012: Glenn
* libpng versions 0.97, January 1998, through 1.7.0beta27 - January 10, 2014: Glenn
* See also "Contributing Authors", below.
*
* Note about libpng version numbers:
@@ -166,7 +166,9 @@
* 1.5.7beta01-05 15 10507 15.so.15.7[.0]
* 1.5.7rc01-03 15 10507 15.so.15.7[.0]
* 1.5.7 15 10507 15.so.15.7[.0]
* 1.6.0beta01-32 16 10600 16.so.16.0[.0]
* 1.6.0beta01-37 16 10600 16.so.16.0[.0]
* 1.7.0alpha01-10 17 10700 17.so.17.0[.0]
* 1.7.0beta01-27 17 10700 17.so.17.0[.0]
*
* Henceforth the source version will match the shared-library major
* and minor numbers; the shared-library major version number will be
@@ -198,8 +200,8 @@
*
* 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.0beta27, January 10, 2014, are
* Copyright (c) 2004, 2006-2013 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:
*
@@ -310,13 +312,13 @@
* Y2K compliance in libpng:
* =========================
*
* December 10, 2012
* January 10, 2014
*
* Since the PNG Development group is an ad-hoc body, we can't make
* an official declaration.
*
* This is your unofficial assurance that libpng from version 0.71 and
* upward through 1.6.0beta33 are Y2K compliant. It is my belief that
* upward through 1.7.0beta27 are Y2K compliant. It is my belief that
* earlier versions were also Y2K compliant.
*
* Libpng only has two year fields. One is a 2-byte unsigned integer
@@ -376,23 +378,23 @@
*/
/* Version information for png.h - this should match the version in png.c */
#define PNG_LIBPNG_VER_STRING "1.6.0beta33"
#define PNG_LIBPNG_VER_STRING "1.7.0beta27"
#define PNG_HEADER_VERSION_STRING \
" libpng version 1.6.0beta33 - December 10, 2012\n"
" libpng version 1.7.0beta27 - January 10, 2014\n"
#define PNG_LIBPNG_VER_SONUM 16
#define PNG_LIBPNG_VER_DLLNUM 16
#define PNG_LIBPNG_VER_SONUM 17
#define PNG_LIBPNG_VER_DLLNUM 17
/* These should match the first 3 components of PNG_LIBPNG_VER_STRING: */
#define PNG_LIBPNG_VER_MAJOR 1
#define PNG_LIBPNG_VER_MINOR 6
#define PNG_LIBPNG_VER_MINOR 7
#define PNG_LIBPNG_VER_RELEASE 0
/* This should match the numeric part of the final component of
* PNG_LIBPNG_VER_STRING, omitting any leading zero:
*/
#define PNG_LIBPNG_VER_BUILD 33
#define PNG_LIBPNG_VER_BUILD 27
/* Release Status */
#define PNG_LIBPNG_BUILD_ALPHA 1
@@ -417,7 +419,7 @@
* version 1.0.0 was mis-numbered 100 instead of 10000). From
* version 1.0.1 it's xxyyzz, where x=major, y=minor, z=release
*/
#define PNG_LIBPNG_VER 10600 /* 1.6.0 */
#define PNG_LIBPNG_VER 10700 /* 1.7.0 */
/* Library configuration: these options cannot be changed after
* the library has been built.
@@ -462,11 +464,6 @@
#ifndef PNG_VERSION_INFO_ONLY
/* Inhibit C++ name-mangling for libpng functions but not for system calls. */
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* Version information for C files, stored in png.c. This had better match
* the version above.
*/
@@ -474,17 +471,138 @@ extern "C" {
/* This file is arranged in several sections:
*
* 1. Any configuration options that can be specified by for the application
* 1. ISO-PNG constants and definitions; values defined by PNG and not specific
* to the libpng API.
* 2. Any configuration options that can be specified by for the application
* code when it is built. (Build time configuration is in pnglibconf.h)
* 2. Type definitions (base types are defined in pngconf.h), structure
* 3. Type definitions (base types are defined in pngconf.h), structure
* definitions.
* 3. Exported library functions.
* 4. Simplified API.
* 4. Exported library functions.
* 5. Simplified API.
*
* The library source code has additional files (principally pngpriv.h) that
* allow configuration of the library.
*/
/* Section 1: run time configuration
/* Section 1: ISO PNG constants and macros. */
/* ISO-PNG defines byte encodings for 16 and 32-bit unsigned values and 32-bit
* signed values. The macros PNG_U16, PNG_U32 and PNG_S32 return values of type
* (png_uint_16), (png_uint_32) and (png_int_32) which are target machine
* specific representations of these values, using the types defined in
* pngconf.h. The macros take two or four byte values in the order in which
* they would occur in a PNG stream.
*
* These macros must return compile time constants if passed constant values -
* machine specific implementations are not permitted. These macros are used by
* default in the API functions/macros png_get_uint_16, png_get_uint_32,
* png_get_uint_31 and png_get_int_32 declared below: these functions or macros
* are the correct places for machine specific implementations (such as hardware
* specific instructions.)
*
* The macros defined here are generic and intended to give maximum flexibility
* in implementation to the compiler; only PNG_S32 contains a sequence point,
* there are no side effects and the expressions used permit the maximum
* parallelization (relevant because the four bytes may be loaded in parallel.)
*/
#define PNG_u2(b1, b2) (((unsigned int)(b1) << 8) + (b2))
#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))
/* ISO-PNG states that signed 32-bit values are stored in two's complement
* format. There is no guarantee that (png_int_32) is exactly 32 bits, so the
* following macro tests for a negative number and generates the machine format
* directly by portable arithmetic operations. The cost is that the argument
* 'b1' is evaluated twice.
*/
#define PNG_S32(b1, b2, b3, b4) ((b1) & 0x80\
? -(png_int_32)((PNG_U32(b1, b2, b3, b4) ^ 0xffffffff) + 1)\
: (png_int_32)PNG_U32(b1, b2, b3, b4))
/* Constants for known chunk types.
*
* MAINTAINERS: 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. Please keep the list sorted.
*
* Notice that PNG_U32 is used to define a 32-bit value for the 4 byte chunk
* type. In fact the specification does not express chunk types this way,
* however using a 32-bit value means that the chunk type can be read from the
* stream using exactly the same code as used for a 32-bit unsigned value and
* can be examined far more efficiently (using one arithmetic compare).
*
* Prior to 1.5.6 the chunk type constants were expressed as C strings. The
* libpng API still uses strings for 'unknown' chunks and a macro,
* PNG_STRING_FROM_CHUNK, allows a string to be generated if required. Notice
* that for portable code numeric values must still be used; the string "IHDR"
* is not portable and neither is PNG_U32('I', 'H', 'D', 'R').
*
* In 1.7.0 the definitions were made public in png.h to avoid having to
* duplicate the same definitions in application code.
*
* SOURCE: http://www.libpng.org/pub/png/spec/register/
* "Register of PNG Public Chunks and Keywords, version 1.4.6"
* "Extensions to the PNG Specification, version 1.4.0"
*/
#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_dSIG PNG_U32(100, 83, 73, 71) /* separate spec */
#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)
/* The following will work on (signed char*) strings, whereas the PNG_U32 macro
* used directory would fail on top-bit-set values because of the sign
* extension.
*/
#define PNG_CHUNK_FROM_STRING(s)\
PNG_U32(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_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))
/* Section 2: run time configuration
* See pnglibconf.h for build time configuration
*
* Run time configuration allows the application to choose between
@@ -514,7 +632,12 @@ extern "C" {
* Otherwise the calls are mapped to png_error.
*/
/* Section 2: type definitions, including structures and compile time
/* Inhibit C++ name-mangling for libpng functions but not for system calls. */
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* Section 3: type definitions, including structures and compile time
* constants.
* See pngconf.h for base types that vary by machine/system
*/
@@ -522,7 +645,7 @@ extern "C" {
/* This triggers a compiler error in png.c, if png.c and png.h
* do not agree upon the version number.
*/
typedef char* png_libpng_version_1_6_0beta33;
typedef char* png_libpng_version_1_7_0beta27;
/* Basic control structions. Read libpng-manual.txt or libpng.3 for more info.
*
@@ -663,8 +786,8 @@ typedef struct png_text_struct
png_charp key; /* keyword, 1-79 character description of "text" */
png_charp text; /* comment, may be an empty string (ie "")
or a NULL pointer */
png_size_t text_length; /* length of the text string */
png_size_t itxt_length; /* length of the itxt string */
size_t text_length; /* length of the text string */
size_t itxt_length; /* length of the itxt string */
png_charp lang; /* language code, 0-79 characters
or a NULL pointer */
png_charp lang_key; /* keyword translated UTF-8 string, 0 or more
@@ -704,7 +827,8 @@ typedef png_time * png_timep;
typedef const png_time * png_const_timep;
typedef png_time * * png_timepp;
#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
#if defined(PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED) ||\
defined(PNG_USER_CHUNKS_SUPPORTED)
/* png_unknown_chunk is a structure to hold queued chunks for which there is
* no specific support. The idea is that we can use this to queue
* up private chunks for output even though the library doesn't actually
@@ -716,7 +840,7 @@ typedef struct png_unknown_chunk_t
{
png_byte name[5]; /* Textual chunk name with '\0' terminator */
png_byte *data; /* Data, should not be modified on read! */
png_size_t size;
size_t size;
/* On write 'location' must be set using the flag values listed below.
* Notice that on read it is set by libpng however the values stored have
@@ -741,7 +865,7 @@ typedef png_unknown_chunk * * png_unknown_chunkpp;
/* Maximum positive integer used in PNG is (2^31)-1 */
#define PNG_UINT_31_MAX ((png_uint_32)0x7fffffffL)
#define PNG_UINT_32_MAX ((png_uint_32)(-1))
#define PNG_SIZE_MAX ((png_size_t)(-1))
#define PNG_SIZE_MAX ((size_t)(-1))
/* These are constants for fixed point values encoded in the
* PNG specification manner (x100000)
@@ -846,7 +970,7 @@ typedef png_unknown_chunk * * png_unknown_chunkpp;
typedef struct png_row_info_struct
{
png_uint_32 width; /* width of row */
png_size_t rowbytes; /* number of bytes in row */
size_t rowbytes; /* number of bytes in row */
png_byte color_type; /* color type of row */
png_byte bit_depth; /* bit depth of row */
png_byte channels; /* number of channels (1, 2, 3, or 4) */
@@ -865,7 +989,7 @@ typedef png_row_info * * png_row_infopp;
* expected to return the read data in the buffer.
*/
typedef PNG_CALLBACK(void, *png_error_ptr, (png_structp, png_const_charp));
typedef PNG_CALLBACK(void, *png_rw_ptr, (png_structp, png_bytep, png_size_t));
typedef PNG_CALLBACK(void, *png_rw_ptr, (png_structp, png_bytep, size_t));
typedef PNG_CALLBACK(void, *png_flush_ptr, (png_structp));
typedef PNG_CALLBACK(void, *png_read_status_ptr, (png_structp, png_uint_32,
int));
@@ -958,7 +1082,7 @@ typedef PNG_CALLBACK(png_voidp, *png_malloc_ptr, (png_structp,
png_alloc_size_t));
typedef PNG_CALLBACK(void, *png_free_ptr, (png_structp, png_voidp));
/* Section 3: exported functions
/* Section 4: exported functions
* Here are the function definitions most commonly used. This is not
* the place to find out how to use libpng. See libpng-manual.txt for the
* full explanation, see example.c for the summary. This just provides
@@ -1000,8 +1124,8 @@ PNG_EXPORT(2, void, png_set_sig_bytes, (png_structrp png_ptr, int num_bytes));
* signature, and non-zero otherwise. Having num_to_check == 0 or
* start > 7 will always fail (ie return non-zero).
*/
PNG_EXPORT(3, int, png_sig_cmp, (png_const_bytep sig, png_size_t start,
png_size_t num_to_check));
PNG_EXPORT(3, int, png_sig_cmp, (png_const_bytep sig, size_t start,
size_t num_to_check));
/* Simple signature checking function. This is the same as calling
* png_check_sig(sig, n) := !png_sig_cmp(sig, 0, n).
@@ -1020,11 +1144,11 @@ PNG_EXPORTA(5, png_structp, png_create_write_struct,
png_error_ptr warn_fn),
PNG_ALLOCATED);
PNG_EXPORT(6, png_size_t, png_get_compression_buffer_size,
PNG_EXPORT(6, size_t, png_get_compression_buffer_size,
(png_const_structrp png_ptr));
PNG_EXPORT(7, void, png_set_compression_buffer_size, (png_structrp png_ptr,
png_size_t size));
size_t size));
/* Moved from pngconf.h in 1.4.0 and modified to ensure setjmp/longjmp
* match up.
@@ -1054,8 +1178,8 @@ PNG_EXPORTA(9, void, png_longjmp, (png_const_structrp png_ptr, int val),
PNG_NORETURN);
#ifdef PNG_READ_SUPPORTED
/* Reset the compression stream */
PNG_EXPORTA(10, int, png_reset_zstream, (png_structrp png_ptr), PNG_DEPRECATED);
/* Reset the compression stream -- Removed from libpng-1.7.0 */
PNG_REMOVED(10, int, png_reset_zstream, (png_structrp png_ptr), PNG_DEPRECATED)
#endif
/* New functions added in libpng-1.0.2 (not enabled by default until 1.2.0) */
@@ -1077,7 +1201,7 @@ PNG_EXPORT(13, void, png_write_sig, (png_structrp png_ptr));
/* Write a PNG chunk - size, type, (optional) data, CRC. */
PNG_EXPORT(14, void, png_write_chunk, (png_structrp png_ptr, png_const_bytep
chunk_name, png_const_bytep data, png_size_t length));
chunk_name, png_const_bytep data, size_t length));
/* Write the start of a PNG chunk - length and chunk name. */
PNG_EXPORT(15, void, png_write_chunk_start, (png_structrp png_ptr,
@@ -1085,7 +1209,7 @@ PNG_EXPORT(15, void, png_write_chunk_start, (png_structrp png_ptr,
/* Write the data of a PNG chunk started with png_write_chunk_start(). */
PNG_EXPORT(16, void, png_write_chunk_data, (png_structrp png_ptr,
png_const_bytep data, png_size_t length));
png_const_bytep data, size_t length));
/* Finish a chunk started with png_write_chunk_start() (includes CRC). */
PNG_EXPORT(17, void, png_write_chunk_end, (png_structrp png_ptr));
@@ -1094,12 +1218,9 @@ PNG_EXPORT(17, void, png_write_chunk_end, (png_structrp png_ptr));
PNG_EXPORTA(18, png_infop, png_create_info_struct, (png_const_structrp png_ptr),
PNG_ALLOCATED);
/* DEPRECATED: this function allowed init structures to be created using the
* default allocation method (typically malloc). Use is deprecated in 1.6.0 and
* the API will be removed in the future.
*/
PNG_EXPORTA(19, void, png_info_init_3, (png_infopp info_ptr,
png_size_t png_info_struct_size), PNG_DEPRECATED);
/* Removed from libpng-1.7.0 */
PNG_REMOVED(19, void, png_info_init_3, (png_infopp info_ptr,
size_t png_info_struct_size), PNG_DEPRECATED)
/* Writes all the PNG information before the image. */
PNG_EXPORT(20, void, png_write_info_before_PLTE,
@@ -1116,13 +1237,10 @@ PNG_EXPORT(22, void, png_read_info,
#ifdef PNG_TIME_RFC1123_SUPPORTED
/* Convert to a US string format: there is no localization support in this
* routine. The original implementation used a 29 character buffer in
* png_struct, this will be removed in future versions.
* png_struct, this has been removed (in libpng 1.7.0).
*/
#if PNG_LIBPNG_VER < 10700
/* To do: remove this from libpng17 (and from libpng17/png.c and pngstruct.h) */
PNG_EXPORTA(23, png_const_charp, png_convert_to_rfc1123, (png_structrp png_ptr,
png_const_timep ptime),PNG_DEPRECATED);
#endif
PNG_REMOVED(23, png_const_charp, png_convert_to_rfc1123, (png_structrp png_ptr,
png_const_timep ptime),PNG_DEPRECATED)
PNG_EXPORT(241, int, png_convert_to_rfc1123_buffer, (char out[29],
png_const_timep ptime));
#endif
@@ -1619,22 +1737,8 @@ PNG_EXPORT(66, void, png_set_crc_action, (png_structrp png_ptr, int crit_action,
PNG_EXPORT(67, void, png_set_filter, (png_structrp png_ptr, int method,
int filters));
/* Flags for png_set_filter() to say which filters to use. The flags
* are chosen so that they don't conflict with real filter types
* below, in case they are supplied instead of the #defined constants.
* These values should NOT be changed.
*/
#define PNG_NO_FILTERS 0x00
#define PNG_FILTER_NONE 0x08
#define PNG_FILTER_SUB 0x10
#define PNG_FILTER_UP 0x20
#define PNG_FILTER_AVG 0x40
#define PNG_FILTER_PAETH 0x80
#define PNG_ALL_FILTERS (PNG_FILTER_NONE | PNG_FILTER_SUB | PNG_FILTER_UP | \
PNG_FILTER_AVG | PNG_FILTER_PAETH)
/* Filter values (not flags) - used in pngwrite.c, pngwutil.c for now.
* These defines should NOT be changed.
* These defines match the values in the PNG specification.
*/
#define PNG_FILTER_VALUE_NONE 0
#define PNG_FILTER_VALUE_SUB 1
@@ -1643,6 +1747,26 @@ PNG_EXPORT(67, void, png_set_filter, (png_structrp png_ptr, int method,
#define PNG_FILTER_VALUE_PAETH 4
#define PNG_FILTER_VALUE_LAST 5
/* The above values are valid arguments to png_set_filter() if only a single
* filter is to be used. If multiple filters are to be allowed (the default is
* to allow any of them) then a combination of the following masks must be used
* and the low three bits of the argument to png_set_filter must be 0.
*
* The resultant argument fits in a single byte.
*/
#define PNG_FILTER_NONE (0x08 << PNG_FILTER_VALUE_NONE)
#define PNG_FILTER_SUB (0x08 << PNG_FILTER_VALUE_SUB)
#define PNG_FILTER_UP (0x08 << PNG_FILTER_VALUE_UP)
#define PNG_FILTER_AVG (0x08 << PNG_FILTER_VALUE_AVG)
#define PNG_FILTER_PAETH (0x08 << PNG_FILTER_VALUE_PAETH)
/* Then two convenience values. PNG_NO_FILTERS is the same as
* PNG_FILTER_VALUE_NONE, but this is harmless because they mean the same thing.
*/
#define PNG_NO_FILTERS 0x00
#define PNG_ALL_FILTERS (PNG_FILTER_NONE | PNG_FILTER_SUB | PNG_FILTER_UP | \
PNG_FILTER_AVG | PNG_FILTER_PAETH)
#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED /* EXPERIMENTAL */
/* The "heuristic_method" is given by one of the PNG_FILTER_HEURISTIC_
* defines, either the default (minimum-sum-of-absolute-differences), or
@@ -1835,7 +1959,7 @@ PNG_EXPORT(218, png_byte, png_get_current_pass_number, (png_const_structrp));
#endif
#ifdef PNG_READ_USER_CHUNKS_SUPPORTED
/* This callback is called only for *unknown* chunks, if
/* This callback is called only for *unknown* chunks. If
* PNG_HANDLE_AS_UNKNOWN_SUPPORTED is set then it is possible to set known
* chunks to be treated as unknown, however in this case the callback must do
* any processing required by the chunk (e.g. by calling the appropriate
@@ -1847,11 +1971,13 @@ PNG_EXPORT(218, png_byte, png_get_current_pass_number, (png_const_structrp));
* The integer return from the callback function is interpreted thus:
*
* negative: An error occured, png_chunk_error will be called.
* zero: The chunk was not handled, the chunk will be discarded unless
* png_set_keep_unknown_chunks has been used to set a 'keep' behavior
* for this particular chunk, in which case that will be used. A
* critical chunk will cause an error at this point unless it is to be
* saved.
* zero: The chunk was not handled, the default unknown handling is used
* (even if this was a chunk that would otherwise be known.)
* NOTE: prior to libpng 1.7 handling values of
* PNG_HANDLE_CHUNK_AS_DEFAULT and PNG_HANDLE_CHUNK_NEVER were
* converted to PNG_HANDLE_CHUNK_IF_SAFE (libpng 1.6.0 warns if this
* happens) so it was not possible to discard unknown chunk data if a
* user callback was installed.
* positive: The chunk was handled, libpng will ignore/discard it.
*/
PNG_EXPORT(88, void, png_set_read_user_chunk_fn, (png_structrp png_ptr,
@@ -1876,7 +2002,7 @@ PNG_EXPORT(91, png_voidp, png_get_progressive_ptr,
/* Function to be called when data becomes available */
PNG_EXPORT(92, void, png_process_data, (png_structrp png_ptr,
png_inforp info_ptr, png_bytep buffer, png_size_t buffer_size));
png_inforp info_ptr, png_bytep buffer, size_t buffer_size));
/* A function which may be called *only* within png_process_data to stop the
* processing of any more data. The function returns the number of bytes
@@ -1885,7 +2011,7 @@ PNG_EXPORT(92, void, png_process_data, (png_structrp png_ptr,
* 'save' is set to true the routine will first save all the pending data and
* will always return 0.
*/
PNG_EXPORT(219, png_size_t, png_process_data_pause, (png_structrp, int save));
PNG_EXPORT(219, size_t, png_process_data_pause, (png_structrp, int save));
/* A function which may be called *only* outside (after) a call to
* png_process_data. It returns the number of bytes of data to skip in the
@@ -1928,16 +2054,13 @@ PNG_EXPORT(98, void, png_free_data, (png_const_structrp png_ptr,
* in, it does not change the state for other png_info structures.
*
* It is unlikely that this function works correctly as of 1.6.0 and using it
* may result either in memory leaks or double free of allocated data.
* may result either in memory leaks or double free of allocated data. It was
* removed in libpng 1.7.0.
*/
PNG_EXPORTA(99, void, png_data_freer, (png_const_structrp png_ptr,
png_inforp info_ptr, int freer, png_uint_32 mask), PNG_DEPRECATED);
PNG_REMOVED(99, void, png_data_freer, (png_const_structrp png_ptr,
png_inforp info_ptr, int freer, png_uint_32 mask), PNG_DEPRECATED)
/* Assignments for png_data_freer */
#define PNG_DESTROY_WILL_FREE_DATA 1
#define PNG_SET_WILL_FREE_DATA 1
#define PNG_USER_WILL_FREE_DATA 2
/* Flags for png_ptr->free_me and info_ptr->free_me */
/* Flags for png_free_data */
#define PNG_FREE_HIST 0x0008
#define PNG_FREE_ICCP 0x0010
#define PNG_FREE_SPLT 0x0020
@@ -1955,10 +2078,14 @@ PNG_EXPORTA(99, void, png_data_freer, (png_const_structrp png_ptr,
#define PNG_FREE_MUL 0x4220 /* PNG_FREE_SPLT|PNG_FREE_TEXT|PNG_FREE_UNKN */
#ifdef PNG_USER_MEM_SUPPORTED
PNG_EXPORTA(100, png_voidp, png_malloc_default, (png_const_structrp png_ptr,
png_alloc_size_t size), PNG_ALLOCATED PNG_DEPRECATED);
PNG_EXPORTA(101, void, png_free_default, (png_const_structrp png_ptr,
png_voidp ptr), PNG_DEPRECATED);
/* These were deprecated in libpng 1.6.0 and have been removed from libpng
* 1.7.0; the functionality should be accessed by calling malloc or free
* directly or, if png_error handling is required, calling png_malloc.
*/
PNG_REMOVED(100, png_voidp, png_malloc_default, (png_const_structrp png_ptr,
png_alloc_size_t size), PNG_ALLOCATED PNG_DEPRECATED)
PNG_REMOVED(101, void, png_free_default, (png_const_structrp png_ptr,
png_voidp ptr), PNG_DEPRECATED)
#endif
#ifdef PNG_ERROR_TEXT_SUPPORTED
@@ -2026,7 +2153,7 @@ PNG_EXPORT(110, png_uint_32, png_get_valid, (png_const_structrp png_ptr,
png_const_inforp info_ptr, png_uint_32 flag));
/* Returns number of bytes needed to hold a transformed row. */
PNG_EXPORT(111, png_size_t, png_get_rowbytes, (png_const_structrp png_ptr,
PNG_EXPORT(111, size_t, png_get_rowbytes, (png_const_structrp png_ptr,
png_const_inforp info_ptr));
#ifdef PNG_INFO_IMAGE_SUPPORTED
@@ -2182,7 +2309,7 @@ PNG_FIXED_EXPORT(140, void, png_set_gAMA_fixed, (png_const_structrp png_ptr,
#ifdef PNG_hIST_SUPPORTED
PNG_EXPORT(141, png_uint_32, png_get_hIST, (png_const_structrp png_ptr,
png_const_inforp info_ptr, png_uint_16p *hist));
png_inforp info_ptr, png_uint_16p *hist));
#endif
#ifdef PNG_hIST_SUPPORTED
@@ -2214,7 +2341,7 @@ PNG_EXPORT(146, void, png_set_oFFs, (png_const_structrp png_ptr,
#ifdef PNG_pCAL_SUPPORTED
PNG_EXPORT(147, png_uint_32, png_get_pCAL, (png_const_structrp png_ptr,
png_const_inforp info_ptr, png_charp *purpose, png_int_32 *X0,
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));
#endif
@@ -2237,7 +2364,7 @@ PNG_EXPORT(150, void, png_set_pHYs, (png_const_structrp png_ptr,
#endif
PNG_EXPORT(151, png_uint_32, png_get_PLTE, (png_const_structrp png_ptr,
png_const_inforp info_ptr, png_colorp *palette, int *num_palette));
png_inforp info_ptr, png_colorp *palette, int *num_palette));
PNG_EXPORT(152, void, png_set_PLTE, (png_structrp png_ptr,
png_inforp info_ptr, png_const_colorp palette, int num_palette));
@@ -2266,7 +2393,7 @@ PNG_EXPORT(157, void, png_set_sRGB_gAMA_and_cHRM, (png_const_structrp png_ptr,
#ifdef PNG_iCCP_SUPPORTED
PNG_EXPORT(158, png_uint_32, png_get_iCCP, (png_const_structrp png_ptr,
png_const_inforp info_ptr, png_charpp name, int *compression_type,
png_inforp info_ptr, png_charpp name, int *compression_type,
png_bytepp profile, png_uint_32 *proflen));
#endif
@@ -2277,19 +2404,19 @@ PNG_EXPORT(159, void, png_set_iCCP, (png_const_structrp png_ptr,
#endif
#ifdef PNG_sPLT_SUPPORTED
PNG_EXPORT(160, png_uint_32, png_get_sPLT, (png_const_structrp png_ptr,
png_const_inforp info_ptr, png_sPLT_tpp entries));
PNG_EXPORT(160, int, png_get_sPLT, (png_const_structrp png_ptr,
png_inforp info_ptr, png_sPLT_tpp entries));
#endif
#ifdef PNG_sPLT_SUPPORTED
PNG_EXPORT(161, void, png_set_sPLT, (png_const_structrp png_ptr,
PNG_EXPORT(161, void, png_set_sPLT, (png_structrp png_ptr,
png_inforp info_ptr, png_const_sPLT_tp entries, int nentries));
#endif
#ifdef PNG_TEXT_SUPPORTED
/* png_get_text also returns the number of text chunks in *num_text */
PNG_EXPORT(162, png_uint_32, png_get_text, (png_const_structrp png_ptr,
png_const_inforp info_ptr, png_textp *text_ptr, int *num_text));
PNG_EXPORT(162, int, png_get_text, (png_const_structrp png_ptr,
png_inforp info_ptr, png_textp *text_ptr, int *num_text));
#endif
/* Note while png_set_text() will accept a structure whose text,
@@ -2300,7 +2427,7 @@ PNG_EXPORT(162, png_uint_32, png_get_text, (png_const_structrp png_ptr,
*/
#ifdef PNG_TEXT_SUPPORTED
PNG_EXPORT(163, void, png_set_text, (png_const_structrp png_ptr,
PNG_EXPORT(163, void, png_set_text, (png_structrp png_ptr,
png_inforp info_ptr, png_const_textp text_ptr, int num_text));
#endif
@@ -2327,15 +2454,14 @@ PNG_EXPORT(167, void, png_set_tRNS, (png_structrp png_ptr,
#endif
#ifdef PNG_sCAL_SUPPORTED
PNG_FP_EXPORT(168, png_uint_32, png_get_sCAL, (png_const_structrp png_ptr,
png_const_inforp info_ptr, int *unit, double *width, double *height))
#if (defined PNG_FLOATING_ARITHMETIC_SUPPORTED) || \
(defined PNG_FLOATING_POINT_SUPPORTED)
/* NOTE: this API is currently implemented using floating point arithmetic,
* consequently it can only be used on systems with floating point support.
#ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
/* NOTE: these API are currently implemented using floating point arithmetic,
* consequently they can only be used on systems with floating point support.
* In any case the range of values supported by png_fixed_point is small and it
* is highly recommended that png_get_sCAL_s be used instead.
*/
PNG_FP_EXPORT(168, png_uint_32, png_get_sCAL, (png_const_structrp png_ptr,
png_const_inforp info_ptr, int *unit, double *width, double *height))
PNG_FIXED_EXPORT(214, png_uint_32, png_get_sCAL_fixed,
(png_const_structrp png_ptr, png_const_inforp info_ptr, int *unit,
png_fixed_point *width, png_fixed_point *height))
@@ -2344,8 +2470,13 @@ PNG_EXPORT(169, png_uint_32, png_get_sCAL_s,
(png_const_structrp png_ptr, png_const_inforp info_ptr, int *unit,
png_charpp swidth, png_charpp sheight));
#ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
/* This also requires internal floating point arithmetic support - i.e. it
* requires a full math library, not just floating point handling.
*/
PNG_FP_EXPORT(170, void, png_set_sCAL, (png_const_structrp png_ptr,
png_inforp info_ptr, int unit, double width, double height))
#endif
PNG_FIXED_EXPORT(213, void, png_set_sCAL_fixed, (png_const_structrp png_ptr,
png_inforp info_ptr, int unit, png_fixed_point width,
png_fixed_point height))
@@ -2361,16 +2492,21 @@ PNG_EXPORT(171, void, png_set_sCAL_s, (png_const_structrp png_ptr,
* NOTE: prior to 1.6.0 the handling specified for particular chunks on read was
* ignored and the default was used, the per-chunk setting only had an effect on
* write. If you wish to have chunk-specific handling on read in code that must
* work on earlier versions you must use a user chunk callback to specify the
* work on earlier versions you must use a user chunk callback to implement the
* desired handling (keep or discard.)
*
* NOTE: prior to 1.7.0 when a user callback returned '0', indicating that the
* chunk had not been handled, libpng would preserve it regardless of the
* default or per-chunk settings. For compatibility with earlier versions
* simply return '1' (handled) from the callback to discard the chunk.
*
* The 'keep' parameter is a PNG_HANDLE_CHUNK_ value as listed below. The
* parameter is interpreted as follows:
*
* READ:
* PNG_HANDLE_CHUNK_AS_DEFAULT:
* Known chunks: do normal libpng processing, do not keep the chunk (but
* set the comments below about PNG_HANDLE_AS_UNKNOWN_SUPPORTED)
* see the comments below about PNG_HANDLE_AS_UNKNOWN_SUPPORTED)
* Unknown chunks: for a specific chunk use the global default, when used
* as the default discard the chunk data.
* PNG_HANDLE_CHUNK_NEVER:
@@ -2456,7 +2592,7 @@ PNG_EXPORT(173, int, png_handle_as_unknown, (png_const_structrp png_ptr,
#endif
#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
PNG_EXPORT(174, void, png_set_unknown_chunks, (png_const_structrp png_ptr,
PNG_EXPORT(174, void, png_set_unknown_chunks, (png_structrp png_ptr,
png_inforp info_ptr, png_const_unknown_chunkp unknowns,
int num_unknowns));
/* NOTE: prior to 1.6.0 this routine set the 'location' field of the added
@@ -2472,7 +2608,7 @@ PNG_EXPORT(175, void, png_set_unknown_chunk_location,
(png_const_structrp png_ptr, png_inforp info_ptr, int chunk, int location));
PNG_EXPORT(176, int, png_get_unknown_chunks, (png_const_structrp png_ptr,
png_const_inforp info_ptr, png_unknown_chunkpp entries));
png_inforp info_ptr, png_unknown_chunkpp entries));
#endif
/* Png_free_data() will turn off the "valid" flag for anything it frees.
@@ -2726,27 +2862,18 @@ PNG_EXPORT(207, void, png_save_uint_16, (png_bytep buf, unsigned int i));
#ifdef PNG_USE_READ_MACROS
/* Inline macros to do direct reads of bytes from the input buffer.
* The png_get_int_32() routine assumes we are using two's complement
* format for negative values, which is almost certainly true.
*/
# define PNG_B(ptr, offset) (((png_const_bytep)(ptr))[offset])
# define PNG_get_uint_32(buf) \
(((png_uint_32)(*(buf)) << 24) + \
((png_uint_32)(*((buf) + 1)) << 16) + \
((png_uint_32)(*((buf) + 2)) << 8) + \
((png_uint_32)(*((buf) + 3))))
PNG_U32(PNG_B(buf,0), PNG_B(buf,1), PNG_B(buf,2), PNG_B(buf,3))
/* From libpng-1.4.0 until 1.4.4, the png_get_uint_16 macro (but not the
* function) incorrectly returned a value of type png_uint_32.
*/
# define PNG_get_uint_16(buf) \
((png_uint_16) \
(((unsigned int)(*(buf)) << 8) + \
((unsigned int)(*((buf) + 1)))))
# define PNG_get_uint_16(buf) PNG_U16(PNG_B(buf,0), PNG_B(buf,1))
# define PNG_get_int_32(buf) \
((png_int_32)((*(buf) & 0x80) \
? -((png_int_32)((png_get_uint_32(buf) ^ 0xffffffffL) + 1)) \
: (png_int_32)png_get_uint_32(buf)))
PNG_S32(PNG_B(buf,0), PNG_B(buf,1), PNG_B(buf,2), PNG_B(buf,3))
/* If PNG_PREFIX is defined the same thing as below happens in pnglibconf.h,
* but defining a macro name prefixed with PNG_PREFIX.
@@ -2765,8 +2892,63 @@ PNG_EXPORT(207, void, png_save_uint_16, (png_bytep buf, unsigned int i));
# endif
#endif
#ifdef PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED
PNG_EXPORT(242, void, png_set_check_for_invalid_index,
(png_structrp png_ptr, int allowed));
# ifdef PNG_GET_PALETTE_MAX_SUPPORTED
PNG_EXPORT(243, int, png_get_palette_max, (png_const_structrp png_ptr,
png_const_inforp info_ptr));
# endif
#endif /* CHECK_FOR_INVALID_INDEX */
/*******************************************************************************
* SIMPLIFIED API
* IMPLEMENTATION OPTIONS
*******************************************************************************
*
* Support for arbitrary implementation-specific optimizations. The API allows
* particular options to be turned on or off. 'Option' is the number of the
* option and 'onoff' is 0 (off) or non-0 (on). The value returned is given
* by the PNG_OPTION_ defines below.
*
* HARDWARE: normally hardware capabilites, such as the Intel SSE instructions,
* are detected at run time, however sometimes it may be impossible
* to do this in user mode, in which case it is necessary to discover
* the capabilities in an OS specific way. Such capabilities are
* listed here when libpng has support for them and must be turned
* ON by the application if present.
*
* SOFTWARE: sometimes software optimizations actually result in performance
* decrease on some architectures or systems, or with some sets of
* PNG images. 'Software' options allow such optimizations to be
* selected at run time.
*/
#ifdef PNG_SET_OPTION_SUPPORTED
#ifdef PNG_ARM_NEON_API_SUPPORTED
# define PNG_ARM_NEON 0 /* HARDWARE: ARM Neon SIMD instructions supported */
#endif
#define PNG_MAXIMUM_INFLATE_WINDOW 2 /* SOFTWARE: force maximum window */
#define PNG_OPTION_NEXT 4 /* Next option - numbers must be even */
/* Return values: NOTE: there are four values and 'off' is *not* zero */
#define PNG_OPTION_UNSET 0 /* Unset - defaults to off */
#define PNG_OPTION_INVALID 1 /* Option number out of range */
#define PNG_OPTION_OFF 2
#define PNG_OPTION_ON 3
PNG_EXPORT(244, int, png_set_option, (png_structrp png_ptr, int option,
int onoff));
#endif
/*******************************************************************************
* END OF HARDWARE OPTIONS
******************************************************************************/
/* Maintainer: Put new public prototypes here ^, in libpng.3, and project
* defs
*/
/*******************************************************************************
* Section 5: SIMPLIFIED API
*******************************************************************************
*
* Please read the documentation in libpng-manual.txt (TODO: write said
@@ -3086,6 +3268,24 @@ typedef struct
* slight speed gain.
*/
#define PNG_IMAGE_FLAG_16BIT_sRGB 0x04
/* On read if the image is a 16-bit per component image and there is no gAMA
* or sRGB chunk assume that the components are sRGB encoded. Notice that
* images output by the simplified API always have gamma information; setting
* this flag only affects the interpretation of 16-bit images from an
* external source. It is recommended that the application expose this flag
* to the user; the user can normally easily recognize the difference between
* linear and sRGB encoding. This flag has no effect on write - the data
* passed to the write APIs must have the correct encoding (as defined
* above.)
*
* If the flag is not set (the default) input 16-bit per component data is
* assumed to be linear.
*
* NOTE: the flag can only be set after the png_image_begin_read_ call,
* because that call initializes the 'flags' field.
*/
#ifdef PNG_SIMPLIFIED_READ_SUPPORTED
/* READ APIs
* ---------
@@ -3106,7 +3306,7 @@ PNG_EXPORT(235, int, png_image_begin_read_from_stdio, (png_imagep image,
#endif /* PNG_STDIO_SUPPORTED */
PNG_EXPORT(236, int, png_image_begin_read_from_memory, (png_imagep image,
png_const_voidp memory, png_size_t size));
png_const_voidp memory, size_t size));
/* The PNG header is read from the given memory buffer. */
PNG_EXPORT(237, int, png_image_finish_read, (png_imagep image,
@@ -3136,7 +3336,7 @@ PNG_EXPORT(237, int, png_image_finish_read, (png_imagep image,
* PNG_FORMAT_FLAG_LINEAR *not* set.
*
* For linear output removing the alpha channel is always done by compositing
* on black and background is ignored.:
* on black and background is ignored.
*
* colormap must be supplied when PNG_FORMAT_FLAG_COLORMAP is set. It must
* be at least the size (in bytes) returned by PNG_IMAGE_COLORMAP_SIZE.
@@ -3151,6 +3351,7 @@ PNG_EXPORT(238, void, png_image_free, (png_imagep image));
#endif /* PNG_SIMPLIFIED_READ_SUPPORTED */
#ifdef PNG_SIMPLIFIED_WRITE_SUPPORTED
#ifdef PNG_STDIO_SUPPORTED
/* WRITE APIS
* ----------
* For write you must initialize a png_image structure to describe the image to
@@ -3193,27 +3394,18 @@ PNG_EXPORT(240, int, png_image_write_to_stdio, (png_imagep image, FILE *file,
*
* Note that the write API does not support interlacing or sub-8-bit pixels.
*/
#endif /* PNG_STDIO_SUPPORTED */
#endif /* PNG_SIMPLIFIED_WRITE_SUPPORTED */
/*******************************************************************************
* END OF SIMPLIFIED API
******************************************************************************/
#if defined(PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED) || \
defined(PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED)
PNG_EXPORT(242, void, png_set_check_for_invalid_index,
(png_structrp png_ptr, int allowed));
#endif
/* Maintainer: Put new public prototypes here ^, in libpng.3, and project
* defs
*/
/* The last ordinal number (this is the *last* one already used; the next
* one to use is one more than this.) Maintainer, remember to add an entry to
* scripts/symbols.def as well.
*/
#ifdef PNG_EXPORT_LAST_ORDINAL
PNG_EXPORT_LAST_ORDINAL(242);
PNG_EXPORT_LAST_ORDINAL(244);
#endif
#ifdef __cplusplus

View File

@@ -1,9 +1,9 @@
/* pngconf.h - machine configurable file for libpng
*
* libpng version 1.6.0beta33 - December 10, 2012
* libpng version 1.7.0beta27 - January 10, 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 */
@@ -510,6 +511,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 +533,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 +549,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 +585,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;

View File

@@ -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 __ */

View File

@@ -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.)
*
@@ -382,6 +382,10 @@ 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 */
@@ -391,6 +395,10 @@ png_app_warning(png_const_structrp png_ptr, png_const_charp error_message)
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 */
@@ -400,6 +408,10 @@ png_app_error(png_const_structrp png_ptr, png_const_charp error_message)
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 */
@@ -416,7 +428,8 @@ static PNG_CONST char png_digit[16] = {
};
#define PNG_MAX_ERROR_TEXT 196 /* Currently limited be profile_error in png.c */
#if defined(PNG_WARNINGS_SUPPORTED) || defined(PNG_ERROR_TEXT_SUPPORTED)
#if defined(PNG_WARNINGS_SUPPORTED) || \
(defined(PNG_READ_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)
@@ -506,6 +519,10 @@ png_chunk_benign_error(png_const_structrp png_ptr, png_const_charp
else
png_chunk_error(png_ptr, error_message);
# ifndef PNG_ERROR_TEXT_SUPPORTED
PNG_UNUSED(error_message)
# endif
}
#endif
#endif /* PNG_READ_SUPPORTED */
@@ -513,10 +530,14 @@ png_chunk_benign_error(png_const_structrp png_ptr, png_const_charp
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 defined(PNG_READ_SUPPORTED) && defined(PNG_WRITE_SUPPORTED)
if (png_ptr->mode & PNG_IS_READ_STRUCT)
# endif
@@ -530,7 +551,7 @@ png_chunk_report(png_const_structrp png_ptr, png_const_charp message, int error)
}
# endif
# if (defined PNG_READ_SUPPORTED) && (defined PNG_WRITE_SUPPORTED)
# if defined(PNG_READ_SUPPORTED) && defined(PNG_WRITE_SUPPORTED)
else if (!(png_ptr->mode & PNG_IS_READ_STRUCT))
# endif
@@ -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)
{
@@ -740,8 +767,17 @@ png_longjmp,(png_const_structrp png_ptr, int val),PNG_NORETURN)
png_ptr->longjmp_fn(*png_ptr->jmp_buf_ptr, 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
@@ -844,8 +880,8 @@ 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:

View File

@@ -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.6.1 [March 28, 2013]
* 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.)
*
@@ -552,14 +552,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);
}
@@ -701,7 +701,7 @@ 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)
{
@@ -726,14 +726,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,7 +742,7 @@ 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");
@@ -818,7 +818,7 @@ 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)
{
@@ -843,9 +843,8 @@ 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)
@@ -866,9 +865,9 @@ 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)
@@ -884,7 +883,9 @@ 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)
@@ -938,7 +939,7 @@ 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");
@@ -974,8 +975,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 +990,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)
@@ -1064,7 +1065,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)
@@ -1161,4 +1162,17 @@ png_get_io_chunk_type (png_const_structrp png_ptr)
}
#endif /* ?PNG_IO_STATE_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 /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */

View File

@@ -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

116
pngmem.c
View File

@@ -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);
free(ptr);
}
#ifdef PNG_USER_MEM_SUPPORTED

View File

@@ -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.)
*
@@ -151,7 +151,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,7 +185,7 @@ 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
@@ -240,7 +240,7 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
return;
if (png_ptr->mode & PNG_AFTER_IDAT)
png_benign_error(png_ptr, "Too many IDATs found");
png_benign_error(png_ptr, "Too many IDATs found[p]");
}
if (chunk_name == png_IHDR)
@@ -271,7 +271,7 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
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)
@@ -285,8 +285,8 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
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)
@@ -528,8 +528,8 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
png_handle_iTXt(png_ptr, info_ptr, png_ptr->push_length);
}
#endif
else
{
if (png_ptr->push_length + 4 > png_ptr->buffer_size)

566
pngpriv.h
View File

@@ -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.
@@ -177,10 +304,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 +319,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 +379,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.
@@ -331,65 +467,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 +488,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 +535,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 +549,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 +567,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 +606,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 +630,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 +704,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 +780,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 +814,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
@@ -933,7 +1007,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 +1136,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 +1147,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 +1167,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 +1277,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 +1285,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 +1363,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 +1704,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 +1761,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
{
@@ -1862,6 +1821,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 +1847,5 @@ PNG_INTERNAL_FUNCTION(void, png_image_free, (png_imagep image), PNG_EMPTY);
}
#endif
#endif /* PNG_VERSION_INFO_ONLY */
#endif /* PNGPRIV_H */

314
pngread.c
View File

@@ -1,8 +1,8 @@
/* pngread.c - 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.)
*
@@ -15,7 +15,7 @@
*/
#include "pngpriv.h"
#if defined PNG_SIMPLIFIED_READ_SUPPORTED && defined PNG_STDIO_SUPPORTED
#if defined(PNG_SIMPLIFIED_READ_SUPPORTED) && defined(PNG_STDIO_SUPPORTED)
# include <errno.h>
#endif
@@ -121,7 +121,7 @@ png_read_info(png_structrp png_ptr, png_inforp info_ptr)
png_chunk_error(png_ptr, "Missing PLTE before IDAT");
else if (png_ptr->mode & PNG_AFTER_IDAT)
png_chunk_benign_error(png_ptr, "Too many IDATs found");
png_chunk_benign_error(png_ptr, "Too many IDATs found[s]");
png_ptr->mode |= PNG_HAVE_IDAT;
}
@@ -305,6 +305,72 @@ png_start_read_image(png_structrp png_ptr)
#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
#ifdef PNG_MNG_FEATURES_SUPPORTED
/* Undoes intrapixel differencing,
* NOTE: this is apparently only supported in the 'sequential' reader.
*/
static void
png_do_read_intrapixel(png_row_infop row_info, png_bytep row)
{
png_debug(1, "in png_do_read_intrapixel");
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 (row_info->color_type == PNG_COLOR_TYPE_RGB)
bytes_per_pixel = 3;
else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
bytes_per_pixel = 4;
else
return;
for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
{
*(rp) = (png_byte)((256 + *rp + *(rp + 1)) & 0xff);
*(rp+2) = (png_byte)((256 + *(rp + 2) + *(rp + 1)) & 0xff);
}
}
else if (row_info->bit_depth == 16)
{
png_bytep rp;
png_uint_32 i;
if (row_info->color_type == PNG_COLOR_TYPE_RGB)
bytes_per_pixel = 6;
else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
bytes_per_pixel = 8;
else
return;
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 = (s0 + s1 + 65536) & 0xffff;
png_uint_32 blue = (s2 + s1 + 65536) & 0xffff;
*(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_MNG_FEATURES_SUPPORTED */
void PNGAPI
png_read_row(png_structrp png_ptr, png_bytep row, png_bytep dsp_row)
{
@@ -489,7 +555,6 @@ png_read_row(png_structrp png_ptr, png_bytep row, png_bytep dsp_row)
}
#endif
#ifdef PNG_READ_TRANSFORMS_SUPPORTED
if (png_ptr->transformations)
png_do_read_transformations(png_ptr, &row_info);
@@ -728,7 +793,7 @@ png_read_end(png_structrp png_ptr, png_inforp info_ptr)
if (chunk_name == png_IDAT)
{
if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
png_benign_error(png_ptr, "Too many IDATs found");
png_benign_error(png_ptr, "Too many IDATs found(a1)");
}
png_handle_unknown(png_ptr, info_ptr, length, keep);
if (chunk_name == png_PLTE)
@@ -742,7 +807,7 @@ png_read_end(png_structrp png_ptr, png_inforp info_ptr)
* read, but not after other chunks have been read.
*/
if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
png_benign_error(png_ptr, "Too many IDATs found");
png_benign_error(png_ptr, "Too many IDATs found(a2)");
png_crc_finish(png_ptr, length);
}
@@ -877,8 +942,8 @@ png_read_destroy(png_structrp png_ptr)
png_free(png_ptr, png_ptr->save_buffer);
#endif
#if (defined PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED) &&\
(defined PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
#if defined(PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED) && \
defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
png_free(png_ptr, png_ptr->unknown_chunk.data);
#endif
@@ -1125,12 +1190,11 @@ png_read_png(png_structrp png_ptr, png_inforp info_ptr,
/* Arguments to png_image_finish_read: */
/* Encoding of PNG data (used by the color-map code) */
/* TODO: change these, dang, ANSI-C reserves the 'E' namespace. */
# define E_NOTSET 0 /* File encoding not yet known */
# define E_sRGB 1 /* 8-bit encoded to sRGB gamma */
# define E_LINEAR 2 /* 16-bit linear: not encoded, NOT pre-multiplied! */
# define E_FILE 3 /* 8-bit encoded to file gamma, not sRGB or linear */
# define E_LINEAR8 4 /* 8-bit linear: only from a file value */
# define P_NOTSET 0 /* File encoding not yet known */
# define P_sRGB 1 /* 8-bit encoded to sRGB gamma */
# define P_LINEAR 2 /* 16-bit linear: not encoded, NOT pre-multiplied! */
# define P_FILE 3 /* 8-bit encoded to file gamma, not sRGB or linear */
# define P_LINEAR8 4 /* 8-bit linear: only from a file value */
/* Color-map processing: after libpng has run on the PNG image further
* processing may be needed to conver the data to color-map indicies.
@@ -1161,7 +1225,7 @@ typedef struct
png_voidp first_row;
ptrdiff_t row_bytes; /* step between rows */
int file_encoding; /* E_ values above */
png_fixed_point gamma_to_linear; /* For E_FILE, reciprocal of gamma */
png_fixed_point gamma_to_linear; /* For P_FILE, reciprocal of gamma */
int colormap_processing; /* PNG_CMAP_ values above */
} png_image_read_control;
@@ -1293,7 +1357,7 @@ png_image_read_header(png_voidp argument)
#ifdef PNG_COLORSPACE_SUPPORTED
/* Does the colorspace match sRGB? If there is no color endpoint
* (colorant) information assume yes, otherwise require the
* 'ENDPOINTS_MATCHE_sRGB' colorspace flag to have been set. If the
* 'ENDPOINTS_MATCHP_sRGB' colorspace flag to have been set. If the
* colorspace has been determined to be invalid ignore it.
*/
if ((format & PNG_FORMAT_FLAG_COLOR) != 0 && ((png_ptr->colorspace.flags
@@ -1482,17 +1546,24 @@ png_image_skip_unused_chunks(png_structrp png_ptr)
*
* Or image data handling:
*
* tRNS, bKGD, gAMA, cHRM, sRGB, iCCP and sBIT.
* tRNS, bKGD, gAMA, cHRM, sRGB, [iCCP] and sBIT.
*
* This provides a small performance improvement and eliminates any
* potential vulnerability to security problems in the unused chunks.
*
* At present the iCCP chunk data isn't used, so iCCP chunk can be ignored
* too. This allows the simplified API to be compiled without iCCP support,
* however if the support is there the chunk is still checked to detect
* errors (which are unfortunately quite common.)
*/
{
static PNG_CONST png_byte chunks_to_process[] = {
98, 75, 71, 68, '\0', /* bKGD */
99, 72, 82, 77, '\0', /* cHRM */
103, 65, 77, 65, '\0', /* gAMA */
# ifdef PNG_READ_iCCP_SUPPORTED
105, 67, 67, 80, '\0', /* iCCP */
# endif
115, 66, 73, 84, '\0', /* sBIT */
115, 82, 71, 66, '\0', /* sRGB */
};
@@ -1529,25 +1600,25 @@ set_file_encoding(png_image_read_control *display)
{
if (png_gamma_not_sRGB(g))
{
display->file_encoding = E_FILE;
display->file_encoding = P_FILE;
display->gamma_to_linear = png_reciprocal(g);
}
else
display->file_encoding = E_sRGB;
display->file_encoding = P_sRGB;
}
else
display->file_encoding = E_LINEAR8;
display->file_encoding = P_LINEAR8;
}
static unsigned int
decode_gamma(png_image_read_control *display, png_uint_32 value, int encoding)
{
if (encoding == E_FILE) /* double check */
if (encoding == P_FILE) /* double check */
encoding = display->file_encoding;
if (encoding == E_NOTSET) /* must be the file encoding */
if (encoding == P_NOTSET) /* must be the file encoding */
{
set_file_encoding(display);
encoding = display->file_encoding;
@@ -1555,18 +1626,18 @@ decode_gamma(png_image_read_control *display, png_uint_32 value, int encoding)
switch (encoding)
{
case E_FILE:
case P_FILE:
value = png_gamma_16bit_correct(value*257, display->gamma_to_linear);
break;
case E_sRGB:
case P_sRGB:
value = png_sRGB_table[value];
break;
case E_LINEAR:
case P_LINEAR:
break;
case E_LINEAR8:
case P_LINEAR8:
value *= 257;
break;
@@ -1585,9 +1656,9 @@ png_colormap_compose(png_image_read_control *display,
png_uint_32 background, int encoding)
{
/* The file value is composed on the background, the background has the given
* encoding and so does the result, the file is encoded with E_FILE and the
* encoding and so does the result, the file is encoded with P_FILE and the
* file and alpha are 8-bit values. The (output) encoding will always be
* E_LINEAR or E_sRGB.
* P_LINEAR or P_sRGB.
*/
png_uint_32 f = decode_gamma(display, foreground, foreground_encoding);
png_uint_32 b = decode_gamma(display, background, encoding);
@@ -1597,7 +1668,7 @@ png_colormap_compose(png_image_read_control *display,
*/
f = f * alpha + b * (255-alpha);
if (encoding == E_LINEAR)
if (encoding == P_LINEAR)
{
/* Scale to 65535; divide by 255, approximately (in fact this is extremely
* accurate, it divides by 255.00000005937181414556, with no overflow.)
@@ -1607,13 +1678,13 @@ png_colormap_compose(png_image_read_control *display,
f = (f+32768) >> 16;
}
else /* E_sRGB */
else /* P_sRGB */
f = PNG_sRGB_FROM_LINEAR(f);
return f;
}
/* NOTE: E_LINEAR values to this routine must be 16-bit, but E_FILE values must
/* NOTE: P_LINEAR values to this routine must be 16-bit, but P_FILE values must
* be 8-bit.
*/
static void
@@ -1623,7 +1694,7 @@ png_create_colormap_entry(png_image_read_control *display,
{
png_imagep image = display->image;
const int output_encoding = (image->format & PNG_FORMAT_FLAG_LINEAR) ?
E_LINEAR : E_sRGB;
P_LINEAR : P_sRGB;
const int convert_to_Y = (image->format & PNG_FORMAT_FLAG_COLOR) == 0 &&
(red != green || green != blue);
@@ -1633,18 +1704,18 @@ png_create_colormap_entry(png_image_read_control *display,
/* Update the cache with whether the file gamma is significantly different
* from sRGB.
*/
if (encoding == E_FILE)
if (encoding == P_FILE)
{
if (display->file_encoding == E_NOTSET)
if (display->file_encoding == P_NOTSET)
set_file_encoding(display);
/* Note that the cached value may be E_FILE too, but if it is then the
/* Note that the cached value may be P_FILE too, but if it is then the
* gamma_to_linear member has been set.
*/
encoding = display->file_encoding;
}
if (encoding == E_FILE)
if (encoding == P_FILE)
{
png_fixed_point g = display->gamma_to_linear;
@@ -1652,10 +1723,10 @@ png_create_colormap_entry(png_image_read_control *display,
green = png_gamma_16bit_correct(green*257, g);
blue = png_gamma_16bit_correct(blue*257, g);
if (convert_to_Y || output_encoding == E_LINEAR)
if (convert_to_Y || output_encoding == P_LINEAR)
{
alpha *= 257;
encoding = E_LINEAR;
encoding = P_LINEAR;
}
else
@@ -1663,11 +1734,11 @@ png_create_colormap_entry(png_image_read_control *display,
red = PNG_sRGB_FROM_LINEAR(red * 255);
green = PNG_sRGB_FROM_LINEAR(green * 255);
blue = PNG_sRGB_FROM_LINEAR(blue * 255);
encoding = E_sRGB;
encoding = P_sRGB;
}
}
else if (encoding == E_LINEAR8)
else if (encoding == P_LINEAR8)
{
/* This encoding occurs quite frequently in test cases because PngSuite
* includes a gAMA 1.0 chunk with most images.
@@ -1676,10 +1747,10 @@ png_create_colormap_entry(png_image_read_control *display,
green *= 257;
blue *= 257;
alpha *= 257;
encoding = E_LINEAR;
encoding = P_LINEAR;
}
else if (encoding == E_sRGB && (convert_to_Y || output_encoding == E_LINEAR))
else if (encoding == P_sRGB && (convert_to_Y || output_encoding == P_LINEAR))
{
/* The values are 8-bit sRGB values, but must be converted to 16-bit
* linear.
@@ -1688,11 +1759,11 @@ png_create_colormap_entry(png_image_read_control *display,
green = png_sRGB_table[green];
blue = png_sRGB_table[blue];
alpha *= 257;
encoding = E_LINEAR;
encoding = P_LINEAR;
}
/* This is set if the color isn't gray but the output is. */
if (encoding == E_LINEAR)
if (encoding == P_LINEAR)
{
if (convert_to_Y)
{
@@ -1700,7 +1771,7 @@ png_create_colormap_entry(png_image_read_control *display,
png_uint_32 y = (png_uint_32)6968 * red + (png_uint_32)23434 * green +
(png_uint_32)2366 * blue;
if (output_encoding == E_LINEAR)
if (output_encoding == P_LINEAR)
y = (y + 16384) >> 15;
else
@@ -1709,19 +1780,19 @@ png_create_colormap_entry(png_image_read_control *display,
y = (y + 128) >> 8;
y *= 255;
y = PNG_sRGB_FROM_LINEAR((y + 64) >> 7);
encoding = E_sRGB;
encoding = P_sRGB;
}
blue = red = green = y;
}
else if (output_encoding == E_sRGB)
else if (output_encoding == P_sRGB)
{
red = PNG_sRGB_FROM_LINEAR(red * 255);
green = PNG_sRGB_FROM_LINEAR(green * 255);
blue = PNG_sRGB_FROM_LINEAR(blue * 255);
alpha = PNG_DIV257(alpha);
encoding = E_sRGB;
encoding = P_sRGB;
}
}
@@ -1730,7 +1801,7 @@ png_create_colormap_entry(png_image_read_control *display,
/* Store the value. */
{
# ifdef PNG_FORMAT_BGR_SUPPORTED
# ifdef PNG_FORMAT_AFIRST_SUPPORTED
const int afirst = (image->format & PNG_FORMAT_FLAG_AFIRST) != 0 &&
(image->format & PNG_FORMAT_FLAG_ALPHA) != 0;
# else
@@ -1742,7 +1813,7 @@ png_create_colormap_entry(png_image_read_control *display,
# define bgr 0
# endif
if (output_encoding == E_LINEAR)
if (output_encoding == P_LINEAR)
{
png_uint_16p entry = png_voidcast(png_uint_16p, display->colormap);
@@ -1797,7 +1868,7 @@ png_create_colormap_entry(png_image_read_control *display,
}
}
else /* output encoding is E_sRGB */
else /* output encoding is P_sRGB */
{
png_bytep entry = png_voidcast(png_bytep, display->colormap);
@@ -1839,7 +1910,7 @@ make_gray_file_colormap(png_image_read_control *display)
unsigned int i;
for (i=0; i<256; ++i)
png_create_colormap_entry(display, i, i, i, i, 255, E_FILE);
png_create_colormap_entry(display, i, i, i, i, 255, P_FILE);
return i;
}
@@ -1850,7 +1921,7 @@ make_gray_colormap(png_image_read_control *display)
unsigned int i;
for (i=0; i<256; ++i)
png_create_colormap_entry(display, i, i, i, i, 255, E_sRGB);
png_create_colormap_entry(display, i, i, i, i, 255, P_sRGB);
return i;
}
@@ -1889,13 +1960,13 @@ make_ga_colormap(png_image_read_control *display)
while (i < 231)
{
unsigned int gray = (i * 256 + 115) / 231;
png_create_colormap_entry(display, i++, gray, gray, gray, 255, E_sRGB);
png_create_colormap_entry(display, i++, gray, gray, gray, 255, P_sRGB);
}
/* 255 is used here for the component values for consistency with the code
* that undoes premultiplication in pngwrite.c.
*/
png_create_colormap_entry(display, i++, 255, 255, 255, 0, E_sRGB);
png_create_colormap_entry(display, i++, 255, 255, 255, 0, P_sRGB);
for (a=1; a<5; ++a)
{
@@ -1903,7 +1974,7 @@ make_ga_colormap(png_image_read_control *display)
for (g=0; g<6; ++g)
png_create_colormap_entry(display, i++, g*51, g*51, g*51, a*51,
E_sRGB);
P_sRGB);
}
return i;
@@ -1927,7 +1998,7 @@ make_rgb_colormap(png_image_read_control *display)
for (b=0; b<6; ++b)
png_create_colormap_entry(display, i++, r*51, g*51, b*51, 255,
E_sRGB);
P_sRGB);
}
}
@@ -1950,11 +2021,11 @@ png_image_read_colormap(png_voidp argument)
const png_structrp png_ptr = image->opaque->png_ptr;
const png_uint_32 output_format = image->format;
const int output_encoding = (output_format & PNG_FORMAT_FLAG_LINEAR) ?
E_LINEAR : E_sRGB;
P_LINEAR : P_sRGB;
unsigned int cmap_entries;
unsigned int output_processing; /* Output processing option */
unsigned int data_encoding = E_NOTSET; /* Encoding libpng must produce */
unsigned int data_encoding = P_NOTSET; /* Encoding libpng must produce */
/* Background information; the background color and the index of this color
* in the color-map if it exists (else 256).
@@ -1974,7 +2045,7 @@ png_image_read_colormap(png_voidp argument)
png_ptr->num_trans > 0) /* alpha in input */ &&
((output_format & PNG_FORMAT_FLAG_ALPHA) == 0) /* no alpha in output */)
{
if (output_encoding == E_LINEAR) /* compose on black */
if (output_encoding == P_LINEAR) /* compose on black */
back_b = back_g = back_r = 0;
else if (display->background == NULL /* no way to remove it */)
@@ -1998,12 +2069,34 @@ png_image_read_colormap(png_voidp argument)
}
}
else if (output_encoding == E_LINEAR)
else if (output_encoding == P_LINEAR)
back_b = back_r = back_g = 65535;
else
back_b = back_r = back_g = 255;
/* Default the input file gamma if required - this is necessary because
* libpng assumes that if no gamma information is present the data is in the
* output format, but the simplified API deduces the gamma from the input
* format.
*/
if ((png_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) == 0)
{
/* Do this directly, not using the png_colorspace functions, to ensure
* that it happens even if the colorspace is invalid (though probably if
* it is the setting will be ignored) Note that the same thing can be
* achieved at the application interface with png_set_gAMA.
*/
if (png_ptr->bit_depth == 16 &&
(image->flags & PNG_IMAGE_FLAG_16BIT_sRGB) == 0)
png_ptr->colorspace.gamma = PNG_GAMMA_LINEAR;
else
png_ptr->colorspace.gamma = PNG_GAMMA_sRGB_INVERSE;
png_ptr->colorspace.flags |= PNG_COLORSPACE_HAVE_GAMMA;
}
/* Decide what to do based on the PNG color type of the input data. The
* utility function png_create_colormap_entry deals with most aspects of the
* output transformations; this code works out how to produce bytes of
@@ -2034,7 +2127,7 @@ png_image_read_colormap(png_voidp argument)
trans = png_ptr->trans_color.gray;
if ((output_format & PNG_FORMAT_FLAG_ALPHA) == 0)
back_alpha = output_encoding == E_LINEAR ? 65535 : 255;
back_alpha = output_encoding == P_LINEAR ? 65535 : 255;
}
/* png_create_colormap_entry just takes an RGBA and writes the
@@ -2052,7 +2145,7 @@ png_image_read_colormap(png_voidp argument)
*/
if (i != trans)
png_create_colormap_entry(display, i, val, val, val, 255,
E_FILE/*8-bit with file gamma*/);
P_FILE/*8-bit with file gamma*/);
/* Else this entry is transparent. The colors don't matter if
* there is an alpha channel (back_alpha == 0), but it does no
@@ -2068,7 +2161,7 @@ png_image_read_colormap(png_voidp argument)
}
/* We need libpng to preserve the original encoding. */
data_encoding = E_FILE;
data_encoding = P_FILE;
/* The rows from libpng, while technically gray values, are now also
* color-map indicies; however, they may need to be expanded to 1
@@ -2097,7 +2190,7 @@ png_image_read_colormap(png_voidp argument)
* ensuring that the corresponding gray level matches the background
* color exactly.
*/
data_encoding = E_sRGB;
data_encoding = P_sRGB;
if (PNG_GRAY_COLORMAP_ENTRIES > image->colormap_entries)
png_error(png_ptr, "gray[16] color-map: too few entries");
@@ -2121,7 +2214,7 @@ png_image_read_colormap(png_voidp argument)
png_color_16 c;
png_uint_32 gray = back_g;
if (output_encoding == E_LINEAR)
if (output_encoding == P_LINEAR)
{
gray = PNG_sRGB_FROM_LINEAR(gray * 255);
@@ -2129,7 +2222,7 @@ png_image_read_colormap(png_voidp argument)
* matches.
*/
png_create_colormap_entry(display, gray, back_g, back_g,
back_g, 65535, E_LINEAR);
back_g, 65535, P_LINEAR);
}
/* The background passed to libpng, however, must be the
@@ -2150,7 +2243,7 @@ png_image_read_colormap(png_voidp argument)
break;
}
back_alpha = output_encoding == E_LINEAR ? 65535 : 255;
back_alpha = output_encoding == P_LINEAR ? 65535 : 255;
}
/* output_processing means that the libpng-processed row will be
@@ -2187,7 +2280,7 @@ png_image_read_colormap(png_voidp argument)
* worry about tRNS matching - tRNS is ignored if there is an alpha
* channel.
*/
data_encoding = E_sRGB;
data_encoding = P_sRGB;
if (output_format & PNG_FORMAT_FLAG_ALPHA)
{
@@ -2230,13 +2323,13 @@ png_image_read_colormap(png_voidp argument)
cmap_entries = make_gray_colormap(display);
if (output_encoding == E_LINEAR)
if (output_encoding == P_LINEAR)
{
gray = PNG_sRGB_FROM_LINEAR(gray * 255);
/* And make sure the corresponding palette entry matches. */
png_create_colormap_entry(display, gray, back_g, back_g,
back_g, 65535, E_LINEAR);
back_g, 65535, P_LINEAR);
}
/* The background passed to libpng, however, must be the sRGB
@@ -2267,7 +2360,7 @@ png_image_read_colormap(png_voidp argument)
{
png_uint_32 gray = (i * 256 + 115) / 231;
png_create_colormap_entry(display, i++, gray, gray, gray,
255, E_sRGB);
255, P_sRGB);
}
/* NOTE: this preserves the full precision of the application
@@ -2275,7 +2368,7 @@ png_image_read_colormap(png_voidp argument)
*/
background_index = i;
png_create_colormap_entry(display, i++, back_r, back_g, back_b,
output_encoding == E_LINEAR ? 65535U : 255U, output_encoding);
output_encoding == P_LINEAR ? 65535U : 255U, output_encoding);
/* For non-opaque input composite on the sRGB background - this
* requires inverting the encoding for each component. The input
@@ -2285,7 +2378,7 @@ png_image_read_colormap(png_voidp argument)
* represents. Consequently 'G' is always sRGB encoded, while
* 'A' is linear. We need the linear background colors.
*/
if (output_encoding == E_sRGB) /* else already linear */
if (output_encoding == P_sRGB) /* else already linear */
{
/* This may produce a value not exactly matching the
* background, but that's ok because these numbers are only
@@ -2315,7 +2408,7 @@ png_image_read_colormap(png_voidp argument)
png_create_colormap_entry(display, i++,
PNG_sRGB_FROM_LINEAR(gray + back_rx),
PNG_sRGB_FROM_LINEAR(gray + back_gx),
PNG_sRGB_FROM_LINEAR(gray + back_bx), 255, E_sRGB);
PNG_sRGB_FROM_LINEAR(gray + back_bx), 255, P_sRGB);
}
}
@@ -2342,7 +2435,7 @@ png_image_read_colormap(png_voidp argument)
*/
png_set_rgb_to_gray_fixed(png_ptr, PNG_ERROR_ACTION_NONE, -1,
-1);
data_encoding = E_sRGB;
data_encoding = P_sRGB;
/* The output will now be one or two 8-bit gray or gray+alpha
* channels. The more complex case arises when the input has alpha.
@@ -2387,7 +2480,7 @@ png_image_read_colormap(png_voidp argument)
png_gamma_not_sRGB(png_ptr->colorspace.gamma))
{
cmap_entries = make_gray_file_colormap(display);
data_encoding = E_FILE;
data_encoding = P_FILE;
}
else
@@ -2406,18 +2499,18 @@ png_image_read_colormap(png_voidp argument)
* it. Achieve this simply by ensuring that the entry
* selected for the background really is the background color.
*/
if (data_encoding == E_FILE) /* from the fixup above */
if (data_encoding == P_FILE) /* from the fixup above */
{
/* The app supplied a gray which is in output_encoding, we
* need to convert it to a value of the input (E_FILE)
* need to convert it to a value of the input (P_FILE)
* encoding then set this palette entry to the required
* output encoding.
*/
if (output_encoding == E_sRGB)
gray = png_sRGB_table[gray]; /* now E_LINEAR */
if (output_encoding == P_sRGB)
gray = png_sRGB_table[gray]; /* now P_LINEAR */
gray = PNG_DIV257(png_gamma_16bit_correct(gray,
png_ptr->colorspace.gamma)); /* now E_FILE */
png_ptr->colorspace.gamma)); /* now P_FILE */
/* And make sure the corresponding palette entry contains
* exactly the required sRGB value.
@@ -2426,14 +2519,14 @@ png_image_read_colormap(png_voidp argument)
back_g, 0/*unused*/, output_encoding);
}
else if (output_encoding == E_LINEAR)
else if (output_encoding == P_LINEAR)
{
gray = PNG_sRGB_FROM_LINEAR(gray * 255);
/* And make sure the corresponding palette entry matches.
*/
png_create_colormap_entry(display, gray, back_g, back_g,
back_g, 0/*unused*/, E_LINEAR);
back_g, 0/*unused*/, P_LINEAR);
}
/* The background passed to libpng, however, must be the
@@ -2463,7 +2556,7 @@ png_image_read_colormap(png_voidp argument)
* to do it once and using PNG_DIV51 on the 6x6x6 reduced RGB cube.
* Consequently we always want libpng to produce sRGB data.
*/
data_encoding = E_sRGB;
data_encoding = P_sRGB;
/* Is there any transparency or alpha? */
if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA ||
@@ -2483,7 +2576,7 @@ png_image_read_colormap(png_voidp argument)
/* Add a transparent entry. */
png_create_colormap_entry(display, cmap_entries, 255, 255,
255, 0, E_sRGB);
255, 0, P_sRGB);
/* This is stored as the background index for the processing
* algorithm.
@@ -2504,7 +2597,7 @@ png_image_read_colormap(png_voidp argument)
*/
for (b=0; b<256; b = (b << 1) | 0x7f)
png_create_colormap_entry(display, cmap_entries++,
r, g, b, 128, E_sRGB);
r, g, b, 128, P_sRGB);
}
}
@@ -2533,7 +2626,7 @@ png_image_read_colormap(png_voidp argument)
png_create_colormap_entry(display, cmap_entries, back_r,
back_g, back_b, 0/*unused*/, output_encoding);
if (output_encoding == E_LINEAR)
if (output_encoding == P_LINEAR)
{
r = PNG_sRGB_FROM_LINEAR(back_r * 255);
g = PNG_sRGB_FROM_LINEAR(back_g * 255);
@@ -2573,11 +2666,11 @@ png_image_read_colormap(png_voidp argument)
*/
for (b=0; b<256; b = (b << 1) | 0x7f)
png_create_colormap_entry(display, cmap_entries++,
png_colormap_compose(display, r, E_sRGB, 128,
png_colormap_compose(display, r, P_sRGB, 128,
back_r, output_encoding),
png_colormap_compose(display, g, E_sRGB, 128,
png_colormap_compose(display, g, P_sRGB, 128,
back_g, output_encoding),
png_colormap_compose(display, b, E_sRGB, 128,
png_colormap_compose(display, b, P_sRGB, 128,
back_b, output_encoding),
0/*unused*/, output_encoding);
}
@@ -2636,7 +2729,7 @@ png_image_read_colormap(png_voidp argument)
num_trans = 0;
output_processing = PNG_CMAP_NONE;
data_encoding = E_FILE; /* Don't change from color-map indicies */
data_encoding = P_FILE; /* Don't change from color-map indicies */
cmap_entries = png_ptr->num_palette;
if (cmap_entries > 256)
cmap_entries = 256;
@@ -2658,13 +2751,13 @@ png_image_read_colormap(png_voidp argument)
* on the sRGB color in 'back'.
*/
png_create_colormap_entry(display, i,
png_colormap_compose(display, colormap[i].red, E_FILE,
png_colormap_compose(display, colormap[i].red, P_FILE,
trans[i], back_r, output_encoding),
png_colormap_compose(display, colormap[i].green, E_FILE,
png_colormap_compose(display, colormap[i].green, P_FILE,
trans[i], back_g, output_encoding),
png_colormap_compose(display, colormap[i].blue, E_FILE,
png_colormap_compose(display, colormap[i].blue, P_FILE,
trans[i], back_b, output_encoding),
output_encoding == E_LINEAR ? trans[i] * 257U :
output_encoding == P_LINEAR ? trans[i] * 257U :
trans[i],
output_encoding);
}
@@ -2673,7 +2766,7 @@ png_image_read_colormap(png_voidp argument)
else
png_create_colormap_entry(display, i, colormap[i].red,
colormap[i].green, colormap[i].blue,
i < num_trans ? trans[i] : 255U, E_FILE/*8-bit*/);
i < num_trans ? trans[i] : 255U, P_FILE/*8-bit*/);
}
/* The PNG data may have indicies packed in fewer than 8 bits, it
@@ -2701,12 +2794,12 @@ png_image_read_colormap(png_voidp argument)
png_error(png_ptr, "bad data option (internal error)");
break;
case E_sRGB:
case P_sRGB:
/* Change to 8-bit sRGB */
png_set_alpha_mode_fixed(png_ptr, PNG_ALPHA_PNG, PNG_GAMMA_sRGB);
/* FALL THROUGH */
case E_FILE:
case P_FILE:
if (png_ptr->bit_depth > 8)
png_set_scale_16(png_ptr);
break;
@@ -2783,7 +2876,6 @@ png_image_read_and_map(png_voidp argument)
break;
default:
passes = 0;
png_error(png_ptr, "unknown interlace type");
}
@@ -3102,7 +3194,6 @@ png_image_read_composite(png_voidp argument)
break;
default:
passes = 0;
png_error(png_ptr, "unknown interlace type");
}
@@ -3251,11 +3342,15 @@ png_image_read_background(png_voidp argument)
break;
default:
passes = 0;
png_error(png_ptr, "unknown interlace type");
}
switch (png_get_bit_depth(png_ptr, info_ptr))
/* Use direct access to info_ptr here because otherwise the simplified API
* would require PNG_EASY_ACCESS_SUPPORTED (just for this.) Note this is
* checking the value after libpng expansions, not the original value in the
* PNG.
*/
switch (info_ptr->bit_depth)
{
default:
png_error(png_ptr, "unexpected bit depth");
@@ -3263,7 +3358,7 @@ png_image_read_background(png_voidp argument)
case 8:
/* 8-bit sRGB gray values with an alpha channel; the alpha channel is
* to be removed by composing on a backgroundi: either the row if
* to be removed by composing on a background: either the row if
* display->background is NULL or display->background->green if not.
* Unlike the code above ALPHA_OPTIMIZED has *not* been done.
*/
@@ -3403,8 +3498,10 @@ png_image_read_background(png_voidp argument)
unsigned int outchannels = 1+preserve_alpha;
int swap_alpha = 0;
if (preserve_alpha && (image->format & PNG_FORMAT_FLAG_AFIRST))
swap_alpha = 1;
# ifdef PNG_SIMPLIFIED_READ_AFIRST_SUPPORTED
if (preserve_alpha && (image->format & PNG_FORMAT_FLAG_AFIRST))
swap_alpha = 1;
# endif
for (pass = 0; pass < passes; ++pass)
{
@@ -3547,7 +3644,8 @@ png_image_read_direct(png_voidp argument)
{
png_fixed_point input_gamma_default;
if (base_format & PNG_FORMAT_FLAG_LINEAR)
if ((base_format & PNG_FORMAT_FLAG_LINEAR) &&
(image->flags & PNG_IMAGE_FLAG_16BIT_sRGB) == 0)
input_gamma_default = PNG_GAMMA_LINEAR;
else
input_gamma_default = PNG_DEFAULT_sRGB;

View File

@@ -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 [(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.)
*
@@ -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,6 +111,7 @@ 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;

1907
pngrtran.c

File diff suppressed because it is too large Load Diff

View File

@@ -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,49 +56,39 @@ 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
* data is stored in the PNG file in two's complement format and there
* is no guarantee that a 'png_int_32' is exactly 32 bits, therefore
* the following code does a two's complement to native conversion.
*/
/* Grab a signed 32-bit integer from a buffer in big-endian format. */
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 /* 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 */
png_read_sig(png_structrp png_ptr, png_inforp info_ptr)
@@ -221,7 +198,7 @@ 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) ?
if (PNG_CHUNK_ANCILLARY(png_ptr->chunk_name) ?
!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN) :
(png_ptr->flags & PNG_FLAG_CRC_CRITICAL_USE))
{
@@ -250,7 +227,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))
@@ -280,6 +257,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
@@ -327,6 +308,7 @@ png_read_buffer(png_structrp png_ptr, png_alloc_size_t new_size, int warn)
return buffer;
}
#endif /* PNG_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 +316,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 +340,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 +351,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 +378,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 +387,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 +405,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
@@ -562,7 +563,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 +581,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)
{
@@ -1357,8 +1352,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];
@@ -1582,7 +1576,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, "chunk cache full");
png_crc_finish(png_ptr, length);
return;
}
@@ -1659,8 +1654,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 +1665,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
@@ -1832,6 +1827,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
@@ -2370,7 +2367,7 @@ png_handle_tEXt(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
if (--png_ptr->user_chunk_cache_max == 1)
{
png_crc_finish(png_ptr, length);
png_chunk_benign_error(png_ptr, "no space in chunk cache");
png_chunk_benign_error(png_ptr, "chunk cache full");
return;
}
}
@@ -2449,7 +2446,7 @@ png_handle_zTXt(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
if (--png_ptr->user_chunk_cache_max == 1)
{
png_crc_finish(png_ptr, length);
png_chunk_benign_error(png_ptr, "no space in chunk cache");
png_chunk_benign_error(png_ptr, "chunk cache full");
return;
}
}
@@ -2558,7 +2555,7 @@ png_handle_iTXt(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
if (--png_ptr->user_chunk_cache_max == 1)
{
png_crc_finish(png_ptr, length);
png_chunk_benign_error(png_ptr, "no space in chunk cache");
png_chunk_benign_error(png_ptr, "chunk cache full");
return;
}
}
@@ -2698,7 +2695,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;
@@ -2802,26 +2799,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 +2839,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,14 +2873,14 @@ 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)
{
case 2:
png_ptr->user_chunk_cache_max = 1;
png_chunk_benign_error(png_ptr, "no space in chunk cache");
png_chunk_benign_error(png_ptr, "chunk cache full");
/* FALL THROUGH */
case 1:
/* NOTE: prior to 1.6.0 this case resulted in an unknown critical
@@ -2917,9 +2904,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
@@ -3350,7 +3336,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 +3378,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
@@ -3679,7 +3665,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);
@@ -3808,7 +3794,6 @@ png_read_filter_row_paeth_1byte_pixel(png_row_infop row_info, png_bytep row,
/* Calculate the current pixel in a, and move the previous row pixel to c
* for the next time round the loop
*/
c = b;
a += *row;
*row++ = (png_byte)a;
}
@@ -3863,68 +3848,17 @@ png_read_filter_row_paeth_multibyte_pixel(png_row_infop row_info, png_bytep row,
}
}
#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 +3872,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 +3889,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 +3967,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 +3982,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 +4027,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");
}
}
@@ -4410,7 +4362,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 +4399,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,7 +4438,7 @@ 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;

448
pngset.c
View File

@@ -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.)
*
@@ -238,16 +238,7 @@ png_set_IHDR(png_const_structrp png_ptr, png_inforp info_ptr,
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
@@ -431,7 +422,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 +506,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 +521,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 +548,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;
@@ -677,7 +681,7 @@ 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;
@@ -688,7 +692,7 @@ png_set_text(png_const_structrp png_ptr, png_inforp info_ptr,
}
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 +700,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 +765,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;
}
@@ -792,7 +797,8 @@ png_set_text_2(png_const_structrp png_ptr, png_inforp info_ptr,
}
# else /* PNG_iTXt_SUPPORTED */
{
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 +821,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)
@@ -849,8 +858,7 @@ png_set_text_2(png_const_structrp png_ptr, png_inforp info_ptr,
}
if (text_length)
memcpy(textp->text, text_ptr[i].text,
(png_size_t)(text_length));
memcpy(textp->text, text_ptr[i].text, text_length);
*(textp->text + text_length) = '\0';
@@ -871,6 +879,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
@@ -910,59 +919,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,78 +1021,88 @@ 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 even 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);
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 */
@@ -1069,6 +1126,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 +1145,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,16 +1160,16 @@ 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 !defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) && \
defined(PNG_READ_SUPPORTED)
if (png_ptr->mode & PNG_IS_READ_STRUCT)
{
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 !defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED) && \
defined(PNG_WRITE_SUPPORTED)
if (!(png_ptr->mode & PNG_IS_READ_STRUCT))
{
png_app_error(png_ptr, "no unknown chunk support on write");
@@ -1116,20 +1177,22 @@ png_set_unknown_chunks(png_const_structrp png_ptr,
}
# 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 +1203,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,11 +1247,9 @@ 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)
{
@@ -1187,6 +1265,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
@@ -1487,19 +1569,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,7 +1589,7 @@ 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 */

View File

@@ -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 */

116
pngtest.c
View File

@@ -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.9 [(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
@@ -557,7 +580,8 @@ 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)
free(pinfo);
pinfo = NULL;
break;
}
@@ -576,7 +600,8 @@ png_debug_free(png_structp png_ptr, png_voidp ptr)
if (verbose)
printf("Freeing %p\n", ptr);
png_free_default(png_ptr, ptr);
if (ptr)
free(ptr);
ptr = NULL;
}
#endif /* PNG_USER_MEM_SUPPORTED && PNG_DEBUG */
@@ -707,18 +732,18 @@ 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)
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];
@@ -731,7 +756,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
@@ -812,6 +837,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 +846,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;
@@ -1026,10 +1052,26 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
&color_type, &interlace_type, &compression_type, &filter_type))
{
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
}
}
@@ -1173,7 +1215,8 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
}
#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;
@@ -1321,14 +1364,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
@@ -1374,11 +1413,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");
@@ -1470,7 +1511,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);
@@ -1557,15 +1599,14 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
}
#ifdef PNG_WRITE_SUPPORTED /* else nothing was written */
if (interlace_preserved) /* 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);
@@ -1944,9 +1985,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_0beta27 Your_png_h_is_not_version_1_7_0beta27;

View File

@@ -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.9 [(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
@@ -782,6 +784,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;

View File

@@ -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 [(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.)
*
@@ -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
#else
PNG_UNUSED(output_flush_fn)
#endif /* PNG_WRITE_FLUSH_SUPPORTED */
#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 */

View File

@@ -1,8 +1,8 @@
/* pngwrite.c - general routines to write 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.)
*
@@ -12,7 +12,7 @@
*/
#include "pngpriv.h"
#if defined PNG_SIMPLIFIED_WRITE_SUPPORTED && defined PNG_STDIO_SUPPORTED
#if defined(PNG_SIMPLIFIED_WRITE_SUPPORTED) && defined(PNG_STDIO_SUPPORTED)
# include <errno.h>
#endif
@@ -216,8 +216,13 @@ png_write_info(png_structrp png_ptr, png_const_inforp info_ptr)
if ((png_ptr->transformations & PNG_INVERT_ALPHA) &&
info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
{
int j;
for (j = 0; j<(int)info_ptr->num_trans; j++)
int j, jend;
jend = info_ptr->num_trans;
if (jend > PNG_MAX_PALETTE_LENGTH)
jend = PNG_MAX_PALETTE_LENGTH;
for (j = 0; j<jend; ++j)
info_ptr->trans_alpha[j] =
(png_byte)(255 - info_ptr->trans_alpha[j]);
}
@@ -447,7 +452,6 @@ png_write_end(png_structrp png_ptr, png_inforp info_ptr)
}
#ifdef PNG_CONVERT_tIME_SUPPORTED
/* "tm" structure is not supported on WindowsCE */
void PNGAPI
png_convert_from_struct_tm(png_timep ptime, PNG_CONST struct tm * ttime)
{
@@ -496,46 +500,50 @@ png_create_write_struct_2,(png_const_charp user_png_ver, png_voidp error_ptr,
error_fn, warn_fn, mem_ptr, malloc_fn, free_fn);
#endif /* PNG_USER_MEM_SUPPORTED */
/* Set the zlib control values to defaults; they can be overridden by the
* application after the struct has been created.
*/
png_ptr->zbuffer_size = PNG_ZBUF_SIZE;
if (png_ptr != NULL)
{
/* Set the zlib control values to defaults; they can be overridden by the
* application after the struct has been created.
*/
png_ptr->zbuffer_size = PNG_ZBUF_SIZE;
png_ptr->zlib_strategy = Z_FILTERED; /* may be overridden if no filters */
png_ptr->zlib_level = Z_DEFAULT_COMPRESSION;
png_ptr->zlib_mem_level = 8;
png_ptr->zlib_window_bits = 15;
png_ptr->zlib_method = 8;
/* The 'zlib_strategy' setting is irrelevant because png_default_claim in
* pngwutil.c defaults it according to whether or not filters will be
* used, and ignores this setting.
*/
png_ptr->zlib_strategy = PNG_Z_DEFAULT_STRATEGY;
png_ptr->zlib_level = PNG_Z_DEFAULT_COMPRESSION;
png_ptr->zlib_mem_level = 8;
png_ptr->zlib_window_bits = 15;
png_ptr->zlib_method = 8;
#ifdef PNG_WRITE_COMPRESSED_TEXT_SUPPORTED
png_ptr->zlib_text_strategy = Z_DEFAULT_STRATEGY;
png_ptr->zlib_text_level = Z_DEFAULT_COMPRESSION;
png_ptr->zlib_text_mem_level = 8;
png_ptr->zlib_text_window_bits = 15;
png_ptr->zlib_text_method = 8;
png_ptr->zlib_text_strategy = PNG_TEXT_Z_DEFAULT_STRATEGY;
png_ptr->zlib_text_level = PNG_TEXT_Z_DEFAULT_COMPRESSION;
png_ptr->zlib_text_mem_level = 8;
png_ptr->zlib_text_window_bits = 15;
png_ptr->zlib_text_method = 8;
#endif /* PNG_WRITE_COMPRESSED_TEXT_SUPPORTED */
/* This is a highly dubious configuration option; by default it is off, but
* it may be appropriate for private builds that are testing extensions not
* conformant to the current specification, or of applications that must not
* fail to write at all costs!
*/
# ifdef PNG_BENIGN_WRITE_ERRORS_SUPPORTED
/* This is a highly dubious configuration option; by default it is off,
* but it may be appropriate for private builds that are testing
* extensions not conformant to the current specification, or of
* applications that must not fail to write at all costs!
*/
#ifdef PNG_BENIGN_WRITE_ERRORS_SUPPORTED
png_ptr->flags |= PNG_FLAG_BENIGN_ERRORS_WARN;
/* In stable builds only warn if an application error can be completely
* handled.
*/
# endif
#endif
/* App warnings are warnings in release (or release candidate) builds but
* are errors during development.
*/
# if PNG_LIBPNG_BUILD_BASE_TYPE >= PNG_LIBPNG_BUILD_RC
png_ptr->flags |= PNG_FLAG_APP_WARNINGS_WARN;
# endif
/* App warnings are warnings in release (or release candidate) builds but
* are errors during development.
*/
#if PNG_LIBPNG_BUILD_BASE_TYPE >= PNG_LIBPNG_BUILD_RC
png_ptr->flags |= PNG_FLAG_APP_WARNINGS_WARN;
#endif
if (png_ptr != NULL)
{
/* TODO: delay this, it can be done in png_init_io() (if the app doesn't
* do it itself) avoiding setting the default function if it is not
* required.
@@ -605,6 +613,71 @@ png_write_image(png_structrp png_ptr, png_bytepp image)
}
}
#ifdef PNG_MNG_FEATURES_SUPPORTED
/* Performs intrapixel differencing */
static void
png_do_write_intrapixel(png_row_infop row_info, png_bytep row)
{
png_debug(1, "in png_do_write_intrapixel");
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 (row_info->color_type == PNG_COLOR_TYPE_RGB)
bytes_per_pixel = 3;
else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
bytes_per_pixel = 4;
else
return;
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_16BIT_SUPPORTED
else if (row_info->bit_depth == 16)
{
png_bytep rp;
png_uint_32 i;
if (row_info->color_type == PNG_COLOR_TYPE_RGB)
bytes_per_pixel = 6;
else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
bytes_per_pixel = 8;
else
return;
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 */
}
}
#endif /* PNG_MNG_FEATURES_SUPPORTED */
/* Called by user to write a row of image data */
void PNGAPI
png_write_row(png_structrp png_ptr, png_const_bytep row)
@@ -927,42 +1000,52 @@ png_set_filter(png_structrp png_ptr, int method, int filters)
if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
(method == PNG_INTRAPIXEL_DIFFERENCING))
method = PNG_FILTER_TYPE_BASE;
#endif
if (method == PNG_FILTER_TYPE_BASE)
{
switch (filters & (PNG_ALL_FILTERS | 0x07))
/* The only supported method, except for the check above, is
* PNG_FILTER_TYPE_BASE. The code below does not use 'method' other than
* for the check, so just keep going if png_app_error returns.
*/
if (method != PNG_FILTER_TYPE_BASE)
png_app_error(png_ptr, "Unknown custom filter method");
/* If filter writing is not supported the 'filters' value must be zero,
* otherwise the value must be a single, valid, filter value or a set of the
* mask values. The defines in png.h are such that the filter masks used in
* this API and internally are 1<<(3+value), value is in the range 0..4, so
* this fits in a byte.
*/
# ifdef PNG_WRITE_FILTER_SUPPORTED
/* Notice that PNG_NO_FILTERS is 0 and passes this test; this is OK
* because filters then gets set to PNG_FILTER_NONE, as is required.
*/
if (filters < PNG_FILTER_VALUE_LAST)
filters = 0x08 << filters;
else if ((filters & ~PNG_ALL_FILTERS) != 0)
{
#ifdef PNG_WRITE_FILTER_SUPPORTED
case 5:
case 6:
case 7: png_app_error(png_ptr, "Unknown row filter for method 0");
/* FALL THROUGH */
#endif /* PNG_WRITE_FILTER_SUPPORTED */
case PNG_FILTER_VALUE_NONE:
png_ptr->do_filter = PNG_FILTER_NONE; break;
png_app_error(png_ptr, "png_set_filter: invalid filters mask/value");
#ifdef PNG_WRITE_FILTER_SUPPORTED
case PNG_FILTER_VALUE_SUB:
png_ptr->do_filter = PNG_FILTER_SUB; break;
/* For compatibility with the previous behavior assume a mask value was
* passed and ignore the non-mask bits.
*/
filters &= PNG_ALL_FILTERS;
case PNG_FILTER_VALUE_UP:
png_ptr->do_filter = PNG_FILTER_UP; break;
case PNG_FILTER_VALUE_AVG:
png_ptr->do_filter = PNG_FILTER_AVG; break;
case PNG_FILTER_VALUE_PAETH:
png_ptr->do_filter = PNG_FILTER_PAETH; break;
default:
png_ptr->do_filter = (png_byte)filters; break;
#else
default:
png_app_error(png_ptr, "Unknown row filter for method 0");
#endif /* PNG_WRITE_FILTER_SUPPORTED */
/* For a possibly foolish consistency (it shouldn't matter) set
* PNG_FILTER_NONE rather than 0.
*/
if (filters == 0)
filters = PNG_FILTER_NONE;
}
# else
/* PNG_FILTER_VALUE_NONE and PNG_NO_FILTERS are both 0. */
if (filters != 0 && filters != PNG_FILTER_NONE)
png_app_error(png_ptr, "png_set_filter: no filters supported");
filters = PNG_FILTER_NONE;
# endif
# ifdef PNG_WRITE_FILTER_SUPPORTED
/* If we have allocated the row_buf, this means we have already started
* with the image and we should have allocated all of the filter buffers
* that have been selected. If prev_row isn't already allocated, then
@@ -971,75 +1054,45 @@ png_set_filter(png_structrp png_ptr, int method, int filters)
* wants to start and stop using particular filters during compression,
* it should start out with all of the filters, and then add and
* remove them after the start of compression.
*
* NOTE: this is a nasty constraint on the code, because it means that the
* prev_row buffer must be maintained even if there are currently no
* 'prev_row' requiring filters active.
*/
if (png_ptr->row_buf != NULL)
{
#ifdef PNG_WRITE_FILTER_SUPPORTED
if ((png_ptr->do_filter & PNG_FILTER_SUB) && png_ptr->sub_row == NULL)
/* Repeat the checks in png_write_start_row; 1 pixel high or wide
* images cannot benefit from certain filters. If this isn't done here
* the check below will fire on 1 pixel high images.
*/
if (png_ptr->height == 1)
filters &= ~(PNG_FILTER_UP|PNG_FILTER_AVG|PNG_FILTER_PAETH);
if (png_ptr->width == 1)
filters &= ~(PNG_FILTER_SUB|PNG_FILTER_AVG|PNG_FILTER_PAETH);
if ((filters & (PNG_FILTER_UP|PNG_FILTER_AVG|PNG_FILTER_PAETH)) != 0
&& png_ptr->prev_row == NULL)
{
png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
(png_ptr->rowbytes + 1));
png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
/* This is the error case, however it is benign - the previous row
* is not available so the filter can't be used. Just warn here.
*/
png_app_warning(png_ptr,
"png_set_filter: UP/AVG/PAETH cannot be added after start");
filters &= ~(PNG_FILTER_UP|PNG_FILTER_AVG|PNG_FILTER_PAETH);
}
if ((png_ptr->do_filter & PNG_FILTER_UP) && png_ptr->up_row == NULL)
{
if (png_ptr->prev_row == NULL)
{
png_warning(png_ptr, "Can't add Up filter after starting");
png_ptr->do_filter = (png_byte)(png_ptr->do_filter &
~PNG_FILTER_UP);
}
else
{
png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
(png_ptr->rowbytes + 1));
png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
}
}
if ((png_ptr->do_filter & PNG_FILTER_AVG) && png_ptr->avg_row == NULL)
{
if (png_ptr->prev_row == NULL)
{
png_warning(png_ptr, "Can't add Average filter after starting");
png_ptr->do_filter = (png_byte)(png_ptr->do_filter &
~PNG_FILTER_AVG);
}
else
{
png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
(png_ptr->rowbytes + 1));
png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
}
}
if ((png_ptr->do_filter & PNG_FILTER_PAETH) &&
png_ptr->paeth_row == NULL)
{
if (png_ptr->prev_row == NULL)
{
png_warning(png_ptr, "Can't add Paeth filter after starting");
png_ptr->do_filter &= (png_byte)(~PNG_FILTER_PAETH);
}
else
{
png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
(png_ptr->rowbytes + 1));
png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
}
}
if (png_ptr->do_filter == PNG_NO_FILTERS)
#endif /* PNG_WRITE_FILTER_SUPPORTED */
png_ptr->do_filter = PNG_FILTER_NONE;
/* Allocate any required buffers that have not already been allocated.
*/
png_write_alloc_filter_row_buffers(png_ptr, filters);
}
}
else
png_error(png_ptr, "Unknown custom filter method");
# endif /* PNG_WRITE_FILTER_SUPPORTED */
/* Finally store the value.
* TODO: this field could probably be removed if neither READ nor
* WRITE_FILTER are supported.
*/
png_ptr->do_filter = (png_byte)filters; /* SAFE: checked above */
}
/* This allows us to influence the way in which libpng chooses the "best"
@@ -1636,14 +1689,16 @@ png_write_image_16bit(png_voidp argument)
if (image->format & PNG_FORMAT_FLAG_ALPHA)
{
if (image->format & PNG_FORMAT_FLAG_AFIRST)
{
aindex = -1;
++input_row; /* To point to the first component */
++output_row;
}
# ifdef PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED
if (image->format & PNG_FORMAT_FLAG_AFIRST)
{
aindex = -1;
++input_row; /* To point to the first component */
++output_row;
}
else
else
# endif
aindex = channels;
}
@@ -1792,14 +1847,16 @@ png_write_image_8bit(png_voidp argument)
png_bytep row_end;
int aindex;
if (image->format & PNG_FORMAT_FLAG_AFIRST)
{
aindex = -1;
++input_row; /* To point to the first component */
++output_row;
}
# ifdef PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED
if (image->format & PNG_FORMAT_FLAG_AFIRST)
{
aindex = -1;
++input_row; /* To point to the first component */
++output_row;
}
else
else
# endif
aindex = channels;
/* Use row_end in place of a loop counter: */
@@ -1879,7 +1936,8 @@ png_image_set_PLTE(png_image_write_control *display)
const png_uint_32 format = image->format;
const int channels = PNG_IMAGE_SAMPLE_CHANNELS(format);
# ifdef PNG_FORMAT_BGR_SUPPORTED
# if defined(PNG_FORMAT_BGR_SUPPORTED) &&\
defined(PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED)
const int afirst = (format & PNG_FORMAT_FLAG_AFIRST) != 0 &&
(format & PNG_FORMAT_FLAG_ALPHA) != 0;
# else

View File

@@ -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 [(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.)
*
@@ -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)
{
@@ -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");
@@ -475,7 +399,7 @@ png_do_write_swap_alpha(png_row_infop row_info, png_bytep row)
#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");
@@ -568,70 +492,81 @@ png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
}
}
#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)
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)
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)
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)
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
if (png_ptr->transformations & PNG_SWAP_BYTES)
png_do_swap(row_info, png_ptr->row_buf + 1);
#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)
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)
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)
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)
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
}
#endif /* PNG_MNG_FEATURES_SUPPORTED */
#endif /* PNG_WRITE_TRANSFORMS_SUPPORTED */
#endif /* PNG_WRITE_SUPPORTED */

View File

@@ -1,8 +1,8 @@
/* pngwutil.c - utilities to write 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.)
*
@@ -338,10 +338,10 @@ png_deflate_claim(png_structrp png_ptr, png_uint_32 owner,
strategy = png_ptr->zlib_strategy;
else if (png_ptr->do_filter != PNG_FILTER_NONE)
strategy = Z_FILTERED;
strategy = PNG_Z_DEFAULT_STRATEGY;
else
strategy = Z_DEFAULT_STRATEGY;
strategy = PNG_Z_DEFAULT_NOFILTER_STRATEGY;
}
else
@@ -1425,10 +1425,11 @@ png_write_tRNS(png_structrp png_ptr, png_const_bytep trans_alpha,
if (color_type == PNG_COLOR_TYPE_PALETTE)
{
if (num_trans <= 0 || num_trans > (int)png_ptr->num_palette)
if (num_trans <= 0 || num_trans > png_ptr->num_palette)
{
png_app_warning(png_ptr,
"Invalid number of transparent colors specified");
/* This is an error which can only be reliably detected late. */
png_app_error(png_ptr,
"Invalid number of transparent colors specified");
return;
}
@@ -1442,7 +1443,8 @@ png_write_tRNS(png_structrp png_ptr, png_const_bytep trans_alpha,
/* One 16 bit value */
if (tran->gray >= (1 << png_ptr->bit_depth))
{
png_app_warning(png_ptr,
/* This can no longer happen because it is checked in png_set_tRNS */
png_app_error(png_ptr,
"Ignoring attempt to write tRNS chunk out-of-range for bit_depth");
return;
@@ -1464,7 +1466,8 @@ png_write_tRNS(png_structrp png_ptr, png_const_bytep trans_alpha,
if (buf[0] | buf[2] | buf[4])
#endif
{
png_app_warning(png_ptr,
/* Also checked in png_set_tRNS */
png_app_error(png_ptr,
"Ignoring attempt to write 16-bit tRNS chunk when bit_depth is 8");
return;
}
@@ -1474,7 +1477,8 @@ png_write_tRNS(png_structrp png_ptr, png_const_bytep trans_alpha,
else
{
png_app_warning(png_ptr, "Can't write tRNS with an alpha channel");
/* Checked in png_set_tRNS */
png_app_error(png_ptr, "Can't write tRNS with an alpha channel");
}
}
#endif
@@ -1744,6 +1748,9 @@ png_write_iTXt(png_structrp png_ptr, int compression, png_const_charp key,
{
if (comp.input_len > PNG_UINT_31_MAX-prefix_len)
png_error(png_ptr, "iTXt: uncompressed text too long");
/* So the string will fit in a chunk: */
comp.output_len = (png_uint_32)/*SAFE*/comp.input_len;
}
png_write_chunk_header(png_ptr, png_iTXt, comp.output_len + prefix_len);
@@ -1758,7 +1765,7 @@ png_write_iTXt(png_structrp png_ptr, int compression, png_const_charp key,
png_write_compressed_data_out(png_ptr, &comp);
else
png_write_chunk_data(png_ptr, (png_const_bytep)text, comp.input_len);
png_write_chunk_data(png_ptr, (png_const_bytep)text, comp.output_len);
png_write_chunk_end(png_ptr);
}
@@ -1931,6 +1938,47 @@ png_write_tIME(png_structrp png_ptr, png_const_timep mod_time)
}
#endif
#ifdef PNG_WRITE_FILTER_SUPPORTED
void /* PRIVATE */
png_write_alloc_filter_row_buffers(png_structrp png_ptr, int filters)
/* Allocate row buffers for any filters that need them, this is also called
* from png_set_filter if the filters are changed during write to ensure that
* the required buffers exist. png_set_filter ensures that up/avg/paeth are
* only set if png_ptr->prev_row is allocated.
*/
{
/* The buffer size is determined just by the output row size, not any
* processing requirements.
*/
png_alloc_size_t buf_size = png_ptr->rowbytes + 1;
if ((filters & PNG_FILTER_SUB) != 0 && png_ptr->sub_row == NULL)
{
png_ptr->sub_row = png_voidcast(png_bytep, png_malloc(png_ptr, buf_size));
png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
}
if ((filters & PNG_FILTER_UP) != 0 && png_ptr->up_row == NULL)
{
png_ptr->up_row = png_voidcast(png_bytep, png_malloc(png_ptr, buf_size));
png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
}
if ((filters & PNG_FILTER_AVG) != 0 && png_ptr->avg_row == NULL)
{
png_ptr->avg_row = png_voidcast(png_bytep, png_malloc(png_ptr, buf_size));
png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
}
if ((filters & PNG_FILTER_PAETH) != 0 && png_ptr->paeth_row == NULL)
{
png_ptr->paeth_row = png_voidcast(png_bytep, png_malloc(png_ptr,
buf_size));
png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
}
}
#endif /* PNG_WRITE_FILTER_SUPPORTED */
/* Initializes the row writing capability of libpng */
void /* PRIVATE */
png_write_start_row(png_structrp png_ptr)
@@ -1951,11 +1999,18 @@ png_write_start_row(png_structrp png_ptr)
static PNG_CONST png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
#endif
#ifdef PNG_WRITE_FILTER_SUPPORTED
int filters;
#endif
png_alloc_size_t buf_size;
int usr_pixel_depth;
png_debug(1, "in png_write_start_row");
if (png_ptr == NULL)
return;
usr_pixel_depth = png_ptr->usr_channels * png_ptr->usr_bit_depth;
buf_size = PNG_ROWBYTES(usr_pixel_depth, png_ptr->width) + 1;
@@ -1964,49 +2019,34 @@ png_write_start_row(png_structrp png_ptr)
png_ptr->maximum_pixel_depth = (png_byte)usr_pixel_depth;
/* Set up row buffer */
png_ptr->row_buf = (png_bytep)png_malloc(png_ptr, buf_size);
png_ptr->row_buf = png_voidcast(png_bytep, png_malloc(png_ptr, buf_size));
png_ptr->row_buf[0] = PNG_FILTER_VALUE_NONE;
#ifdef PNG_WRITE_FILTER_SUPPORTED
/* Set up filtering buffer, if using this filter */
if (png_ptr->do_filter & PNG_FILTER_SUB)
{
png_ptr->sub_row = (png_bytep)png_malloc(png_ptr, png_ptr->rowbytes + 1);
filters = png_ptr->do_filter;
png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
}
if (png_ptr->height == 1)
filters &= ~(PNG_FILTER_UP|PNG_FILTER_AVG|PNG_FILTER_PAETH);
/* We only need to keep the previous row if we are using one of these. */
if (png_ptr->do_filter & (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH))
{
/* Set up previous row buffer */
png_ptr->prev_row = (png_bytep)png_calloc(png_ptr, buf_size);
if (png_ptr->width == 1)
filters &= ~(PNG_FILTER_SUB|PNG_FILTER_AVG|PNG_FILTER_PAETH);
if (png_ptr->do_filter & PNG_FILTER_UP)
{
png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
png_ptr->rowbytes + 1);
if (filters == 0)
filters = PNG_FILTER_NONE;
png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
}
/* We only need to keep the previous row if we are using one of the following
* filters.
*/
if (filters & (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH))
png_ptr->prev_row = png_voidcast(png_bytep, png_calloc(png_ptr,
buf_size));
if (png_ptr->do_filter & PNG_FILTER_AVG)
{
png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
png_ptr->rowbytes + 1);
png_write_alloc_filter_row_buffers(png_ptr, filters);
png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
}
if (png_ptr->do_filter & PNG_FILTER_PAETH)
{
png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
png_ptr->rowbytes + 1);
png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
}
}
png_ptr->do_filter = (png_byte)filters; /* in case it was changed above */
#else
png_ptr->do_filter = PNG_FILTER_NONE;
#endif /* PNG_WRITE_FILTER_SUPPORTED */
#ifdef PNG_WRITE_INTERLACING_SUPPORTED
@@ -2994,6 +3034,7 @@ png_write_filtered_row(png_structrp png_ptr, png_bytep filtered_row,
png_compress_IDAT(png_ptr, filtered_row, full_row_length, Z_NO_FLUSH);
#ifdef PNG_WRITE_FILTER_SUPPORTED
/* Swap the current and previous rows */
if (png_ptr->prev_row != NULL)
{
@@ -3003,6 +3044,7 @@ png_write_filtered_row(png_structrp png_ptr, png_bytep filtered_row,
png_ptr->prev_row = png_ptr->row_buf;
png_ptr->row_buf = tptr;
}
#endif /* PNG_WRITE_FILTER_SUPPORTED */
/* Finish row - updates counters and flushes zlib if last row */
png_write_finish_row(png_ptr);

View File

@@ -30,7 +30,7 @@
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
OutputFile="$(OutDir)/libpng16.dll"
OutputFile="$(OutDir)/libpng17.dll"
LinkIncremental="1"/>
<Tool
Name="VCMIDLTool"/>
@@ -78,7 +78,7 @@
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
OutputFile="$(OutDir)/libpng16d.dll"
OutputFile="$(OutDir)/libpng17d.dll"
GenerateDebugInformation="TRUE"/>
<Tool
Name="VCMIDLTool"/>
@@ -126,7 +126,7 @@
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
OutputFile="$(OutDir)/libpng16vb.dll"
OutputFile="$(OutDir)/libpng17vb.dll"
LinkIncremental="1"/>
<Tool
Name="VCMIDLTool"/>

View File

@@ -130,7 +130,7 @@ $(TargetPath) ..\..\pngtest.png $(IntDir)\pngout.png"
Name="VCLinkerTool"
OutputFile="$(OutDir)/pngtest.exe"
LinkIncremental="1"
IgnoreDefaultLibraryNames="$(IntDir)\libpng16b.lib"
IgnoreDefaultLibraryNames="$(IntDir)\libpng17b.lib"
SubSystem="1"
TargetMachine="1"/>
<Tool

View File

@@ -23,8 +23,8 @@
<Keyword>Win32Proj</Keyword>
<RootNamespace>libpng</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<Import Project="$(SolutionDir)\zlib.props" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
@@ -63,23 +63,23 @@
<LinkIncremental>false</LinkIncremental>
<CustomBuildBeforeTargets>
</CustomBuildBeforeTargets>
<TargetName>$(ProjectName)16</TargetName>
<TargetName>$(ProjectName)17</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug Library|Win32'">
<LinkIncremental>false</LinkIncremental>
<CustomBuildBeforeTargets />
<TargetName>$(ProjectName)16</TargetName>
<TargetName>$(ProjectName)17</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<CustomBuildBeforeTargets>
</CustomBuildBeforeTargets>
<TargetName>$(ProjectName)16</TargetName>
<TargetName>$(ProjectName)17</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release Library|Win32'">
<LinkIncremental>false</LinkIncremental>
<CustomBuildBeforeTargets />
<TargetName>$(ProjectName)16</TargetName>
<TargetName>$(ProjectName)17</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
@@ -107,7 +107,7 @@
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>zlib.lib</AdditionalDependencies>
<Version>16</Version>
<Version>17</Version>
<AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
@@ -164,7 +164,7 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>zlib.lib</AdditionalDependencies>
<Version>16</Version>
<Version>17</Version>
<AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>

View File

@@ -17,6 +17,7 @@
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(SolutionDir)\zlib.props" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>

View File

@@ -23,8 +23,8 @@
<Keyword>Win32Proj</Keyword>
<RootNamespace>pngstest</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<Import Project="$(SolutionDir)\zlib.props" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
@@ -96,7 +96,7 @@
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>libpng16.lib;zlib.lib</AdditionalDependencies>
<AdditionalDependencies>libpng17.lib</AdditionalDependencies>
<AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>
</Link>
<CustomBuildStep>
@@ -129,7 +129,7 @@
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>libpng16.lib;zlib.lib</AdditionalDependencies>
<AdditionalDependencies>libpng17.lib;zlib.lib</AdditionalDependencies>
<AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>
</Link>
<CustomBuildStep>
@@ -163,7 +163,7 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>libpng16.lib;zlib.lib</AdditionalDependencies>
<AdditionalDependencies>libpng17.lib</AdditionalDependencies>
<AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
</Link>
@@ -199,7 +199,7 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>libpng16.lib;zlib.lib</AdditionalDependencies>
<AdditionalDependencies>libpng17.lib;zlib.lib</AdditionalDependencies>
<AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
</Link>

View File

@@ -23,8 +23,8 @@
<Keyword>Win32Proj</Keyword>
<RootNamespace>pngtest</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<Import Project="$(SolutionDir)\zlib.props" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
@@ -96,7 +96,7 @@
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>libpng16.lib</AdditionalDependencies>
<AdditionalDependencies>libpng17.lib</AdditionalDependencies>
<AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>
</Link>
<CustomBuildStep>
@@ -129,7 +129,7 @@
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>libpng16.lib;zlib.lib</AdditionalDependencies>
<AdditionalDependencies>libpng17.lib;zlib.lib</AdditionalDependencies>
<AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>
</Link>
<CustomBuildStep>
@@ -164,7 +164,7 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
<AdditionalDependencies>libpng16.lib</AdditionalDependencies>
<AdditionalDependencies>libpng17.lib</AdditionalDependencies>
<AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>
</Link>
<CustomBuildStep>
@@ -199,7 +199,7 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>libpng16.lib;zlib.lib</AdditionalDependencies>
<AdditionalDependencies>libpng17.lib;zlib.lib</AdditionalDependencies>
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
<AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>
</Link>

View File

@@ -23,8 +23,8 @@
<Keyword>Win32Proj</Keyword>
<RootNamespace>pngunknown</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<Import Project="$(SolutionDir)\zlib.props" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
@@ -96,7 +96,7 @@
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>libpng16.lib;zlib.lib</AdditionalDependencies>
<AdditionalDependencies>libpng17.lib</AdditionalDependencies>
<AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>
</Link>
<CustomBuildStep>
@@ -129,7 +129,7 @@
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>libpng16.lib;zlib.lib</AdditionalDependencies>
<AdditionalDependencies>libpng17.lib;zlib.lib</AdditionalDependencies>
<AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>
</Link>
<CustomBuildStep>
@@ -163,7 +163,7 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>libpng16.lib;zlib.lib</AdditionalDependencies>
<AdditionalDependencies>libpng17.lib</AdditionalDependencies>
<AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
</Link>
@@ -199,7 +199,7 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>libpng16.lib;zlib.lib</AdditionalDependencies>
<AdditionalDependencies>libpng17.lib;zlib.lib</AdditionalDependencies>
<AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
</Link>

View File

@@ -23,8 +23,8 @@
<Keyword>Win32Proj</Keyword>
<RootNamespace>pngvalid</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<Import Project="$(SolutionDir)\zlib.props" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
@@ -96,7 +96,7 @@
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>libpng16.lib;zlib.lib</AdditionalDependencies>
<AdditionalDependencies>libpng17.lib;zlib.lib</AdditionalDependencies>
<AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>
</Link>
<CustomBuildStep>
@@ -129,7 +129,7 @@
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>libpng16.lib;zlib.lib</AdditionalDependencies>
<AdditionalDependencies>libpng17.lib;zlib.lib</AdditionalDependencies>
<AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>
</Link>
<CustomBuildStep>
@@ -163,7 +163,7 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>libpng16.lib;zlib.lib</AdditionalDependencies>
<AdditionalDependencies>libpng17.lib;zlib.lib</AdditionalDependencies>
<AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
</Link>
@@ -199,7 +199,7 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>libpng16.lib;zlib.lib</AdditionalDependencies>
<AdditionalDependencies>libpng17.lib;zlib.lib</AdditionalDependencies>
<AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
</Link>

View File

@@ -1,7 +1,7 @@
VisualStudio instructions
libpng version 1.6.0beta33 - December 10, 2012
libpng version 1.7.0beta27 - January 10, 2014
Copyright (c) 1998-2010 Glenn Randers-Pehrson
@@ -40,7 +40,7 @@ problems.
If you don't use the Visual Studio defaults your application must still be built
with the default runtime option (/MD). If, for some reason, it is not then your
application will crash inside libpng16.dll as soon as libpng tries to read
application will crash inside libpng17.dll as soon as libpng tries to read
from a file handle you pass in.
If you do not want to use the DLL, for example for a very small application,

View File

@@ -2,7 +2,7 @@
<!--
* zlib.props - location of zlib source
*
* libpng version 1.6.0beta33 - December 10, 2012
* libpng version 1.7.0beta27 - January 10, 2014
*
* Copyright (c) 1998-2011 Glenn Randers-Pehrson
*
@@ -33,5 +33,13 @@
below:
-->
<ZLibSrcDir>..\..\..\..\zlib-1.2.5</ZLibSrcDir>
<!-- The following line allows compilation for an ARM target with Visual
Studio 2012. Notice that this is not supported by the Visual Studio
2012 IDE and that the programs that result cannot be run unless they
signed by Microsoft. This is therefore untested; only Microsoft can
test it:
-->
<WindowsSDKDesktopARMSupport>true</WindowsSDKDesktopARMSupport>
</PropertyGroup>
</Project>

View File

@@ -36,8 +36,8 @@
<Keyword>Win32Proj</Keyword>
<RootNamespace>zlib</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<Import Project="$(SolutionDir)\zlib.props" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug Library|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
</PropertyGroup>

View File

@@ -1,9 +1,9 @@
Makefiles for libpng version 1.6.0beta33 - December 10, 2012
Makefiles for libpng version 1.7.0beta27 - January 10, 2014
pnglibconf.h.prebuilt => Stores configuration settings
makefile.linux => Linux/ELF makefile
(gcc, creates libpng16.so.16.1.6.0beta33)
(gcc, creates libpng17.so.17.1.7.0beta27)
makefile.gcc => Generic makefile (gcc, creates static libpng.a)
makefile.knr => Archaic UNIX Makefile that converts files with
ansi2knr (Requires ansi2knr.c from
@@ -20,7 +20,7 @@ pnglibconf.h.prebuilt => Stores configuration settings
makefile.dec => DEC Alpha UNIX makefile
makefile.dj2 => DJGPP 2 makefile
makefile.elf => Linux/ELF makefile symbol versioning,
(gcc, creates libpng16.so.16.1.6.0beta33)
(gcc, creates libpng17.so.17.1.7.0beta27)
makefile.freebsd => FreeBSD makefile
makefile.gcc => Generic gcc makefile
makefile.hpgcc => HPUX makefile using gcc
@@ -35,12 +35,12 @@ pnglibconf.h.prebuilt => Stores configuration settings
makefile.os2 => OS/2 Makefile (gcc and emx, requires libpng.def)
makefile.sco => For SCO OSr5 ELF and Unixware 7 with Native cc
makefile.sggcc => Silicon Graphics (gcc,
creates libpng16.so.16.1.6.0beta33)
creates libpng17.so.17.1.7.0beta27)
makefile.sgi => Silicon Graphics IRIX makefile (cc, creates static lib)
makefile.solaris => Solaris 2.X makefile (gcc,
creates libpng16.so.16.1.6.0beta33)
creates libpng17.so.17.1.7.0beta27)
makefile.so9 => Solaris 9 makefile (gcc,
creates libpng16.so.16.1.6.0beta33)
creates libpng17.so.17.1.7.0beta27)
makefile.std => Generic UNIX makefile (cc, creates static libpng.a)
makefile.sunos => Sun makefile
makefile.32sunu => Sun Ultra 32-bit makefile

View File

@@ -113,6 +113,16 @@ END{
err = 1
}
unexported=0
# Add a standard header to symbols.new:
print ";Version INSERT-VERSION-HERE" >of
print ";--------------------------------------------------------------" >of
print "; LIBPNG symbol list as a Win32 DEF file" >of
print "; Contains all the symbols that can be exported from libpng" >of
print ";--------------------------------------------------------------" >of
print "LIBRARY" >of
print "" >of
print "EXPORTS" >of
for (o=1; o<=lasto; ++o) {
if (symbol[o] == "" && removed[o] == "") {
if (unexported == 0) unexported = o

View File

@@ -8,31 +8,22 @@
* and license in png.h
*/
/* These macros exist to make the header and trailer shorter below: */
#define S PNG_DEFN_MAGIC
#define E PNG_DEFN_END
/* Write the export file header: */
S-;---------------------------------------------------------------E
S-; LIBPNG module definition file for OS/2-E
S-;---------------------------------------------------------------E
S--E
S-; If you give the library an explicit name one or other files-E
S-; may need modifying to support the new name on one or more-E
S-; systems.-E
S-LIBRARY-E
S-OS2 DESCRIPTION "PNG image compression library"-E
S-OS2 CODE PRELOAD MOVEABLE DISCARDABLE-E
S--E
S-EXPORTS-E
S-;Version 1.5.0beta58-E
PNG_DFN ";--------------------------------------------------------------"
PNG_DFN "; LIBPNG module definition file for OS/2"
PNG_DFN ";--------------------------------------------------------------"
PNG_DFN ""
PNG_DFN "; If you give the library an explicit name one or other files"
PNG_DFN "; may need modifying to support the new name on one or more"
PNG_DFN "; systems."
PNG_DFN "LIBRARY"
PNG_DFN "OS2 DESCRIPTION "PNG image compression library""
PNG_DFN "OS2 CODE PRELOAD MOVEABLE DISCARDABLE"
PNG_DFN ""
PNG_DFN "EXPORTS"
PNG_DFN ";Version 1.7.0beta27"
/* NOTE: PNG_JOIN is interpreted by the calling script as a signal to
* join the two things on either side, so we can do symbol
* substitution within the name, regular C ## joins the pp-tokens,
* not their final values.
*/
#define PNG_EXPORTA(ordinal, type, name, args, attributes)\
PNG_DEFN_MAGIC- SYMBOL_PREFIX PNG_JOIN name-PNG_DEFN_END
PNG_DFN "@" SYMBOL_PREFIX "@@" name "@"
#include "../png.h"

203
scripts/dfn.awk Normal file
View File

@@ -0,0 +1,203 @@
#!/bin/awk -f
# scripts/dfn.awk - process a .dfn file
#
# last changed in libpng version 1.5.14 - February 4, 2013
#
# Copyright (c) 2013-2013 Glenn Randers-Pehrson
#
# This code is released under the libpng license.
# For conditions of distribution and use, see the disclaimer
# and license in png.h
# The output of this script is written to the file given by
# the variable 'out', which should be set on the command line.
# Error messages are printed to stdout and if any are printed
# the script will exit with error code 1.
BEGIN{
out="/dev/null" # as a flag
out_count=0 # count of output lines
err=0 # set if an error occured
sort=0 # sort the output
array[""]=""
}
# The output file must be specified before any input:
NR==1 && out == "/dev/null" {
print "out=output.file must be given on the command line"
# but continue without setting the error code, this allows the
# script to be checked easily
}
# Output can be sorted; two lines are recognized
$1 == "PNG_DFN_START_SORT"{
sort=0+$2
next
}
$1 ~ /^PNG_DFN_END_SORT/{
# Do a very simple, slow, sort; notice that blank lines won't be
# output by this
for (entry in array) {
while (array[entry] != "") {
key = entry
value = array[key]
array[key] = ""
for (alt in array) {
if (array[alt] != "" && alt < key) {
array[key] = value
value = array[alt]
key = alt
array[alt] = ""
}
}
print value >out
}
}
sort=0
next
}
/^[^"]*PNG_DFN *".*"[^"]*$/{
# A definition line, apparently correctly formated, extract the
# definition then replace any doubled "" that remain with a single
# double quote. Notice that the original doubled double quotes
# may have been split by tokenization
#
# Sometimes GCC splits the PNG_DFN lines, we know this has happened
# if the quotes aren't closed and must read another line. In this
# case it is essential to reject lines that start '#' because those
# are introduced #line directives.
orig=$0
line=$0
lineno=FNR
if (lineno == "") lineno=NR
if (sub(/^[^"]*PNG_DFN *"/,"",line) != 1) {
print "line", lineno ": processing failed:"
print orig
err=1
next
} else {
++out_count
}
# Now examine quotes within the value:
#
# @" - delete this and any following spaces
# "@ - delete this and any preceding spaces
# @' - replace this by a double quote
#
# This allows macro substitution by the C compiler thus:
#
# #define first_name John
# #define last_name Smith
#
# PNG_DFN"#define name @'@" first_name "@ @" last_name "@@'"
#
# Might get C preprocessed to:
#
# PNG_DFN "#define foo @'@" John "@ @" Smith "@@'"
#
# Which this script reduces to:
#
# #define name "John Smith"
#
while (1) {
# While there is an @" remove it and the next "@
if (line ~ /@"/) {
if (line ~ /@".*"@/) {
# Do this special case first to avoid swallowing extra spaces
# before or after the @ stuff:
if (!sub(/@" *"@/, "", line)) {
# Ok, do it in pieces - there has to be a non-space between the
# two. NOTE: really weird things happen if a leading @" is
# lost - the code will error out below (I believe).
if (!sub(/@" */, "", line) || !sub(/ *"@/, "", line)) {
print "line", lineno, ": internal error:", orig
exit 1
}
}
}
# There is no matching "@. Assume a split line
else while (1) {
if (getline nextline) {
# If the line starts with '#' it is a preprocesor line directive
# from cc -E, skip it:
if (nextline !~ /^#/) {
line = line " " nextline
break
}
} else {
# This is end-of-input - probably a missig "@ on the first line:
print "line", lineno ": unbalanced @\" ... \"@ pair"
err=1
next
}
}
# Keep going until all the @" have gone
continue
}
# Attempt to remove a trailing " (not preceded by '@') - if this can
# be done stop now, if not assume a split line again
if (sub(/"[^"]*$/, "", line))
break
# Read another line
while (1) {
if (getline nextline) {
if (nextline !~ /^#/) {
line = line " " nextline
# Go back to stripping @" "@ pairs
break
}
} else {
print "line", lineno ": unterminated PNG_DFN string"
err=1
next
}
}
}
# Put any needed double quotes in (at the end, because these would otherwise
# interfere with the processing above.)
gsub(/@'/,"\"", line)
# Remove any trailing spaces (not really required, but for
# editorial consistency
sub(/ *$/, "", line)
# Remove trailing CR
sub(/
$/, "", line)
if (sort) {
if (split(line, parts) < sort) {
print "line", lineno ": missing sort field:", line
err=1
} else
array[parts[sort]] = line
}
else
print line >out
next
}
/PNG_DFN/{
print "line", NR, "incorrectly formated PNG_DFN line:"
print $0
err = 1
}
END{
if (out_count > 0 || err > 0)
exit err
print "no definition lines found"
exit 1

View File

@@ -10,10 +10,10 @@
*/
#define PNG_INTERNAL_DATA(type, name, array)\
PNG_DEFN_MAGIC-name-PNG_DEFN_END
PNG_DFN "@" name "@"
#define PNG_INTERNAL_FUNCTION(type, name, args, attributes)\
PNG_DEFN_MAGIC-name-PNG_DEFN_END
PNG_DFN "@" name "@"
#define PNGPREFIX_H /* self generation */
#include "../pngpriv.h"

Some files were not shown because too many files have changed in this diff Show More