Compare commits

..

1 Commits

Author SHA1 Message Date
Glenn Randers-Pehrson
a9b99fc64d [libpng16] Imported from libpng-1.6.0beta20.tar 2012-03-29 06:37:06 -05:00
71 changed files with 1664 additions and 5984 deletions

194
ANNOUNCE
View File

@@ -1,5 +1,5 @@
Libpng 1.6.0beta30 - October 24, 2012
Libpng 1.6.0beta20 - March 29, 2012
This is not intended to be a public release. It will be replaced
within a few weeks by a public version or by another test version.
@@ -9,20 +9,20 @@ Files available for download:
Source files with LF line endings (for Unix/Linux) and with a
"configure" script
1.6.0beta30.tar.xz (LZMA-compressed, recommended)
1.6.0beta30.tar.gz
1.6.0beta30.tar.bz2
1.6.0beta20.tar.xz (LZMA-compressed, recommended)
1.6.0beta20.tar.gz
1.6.0beta20.tar.bz2
Source files with CRLF line endings (for Windows), without the
"configure" script
lp160b30.7z (LZMA-compressed, recommended)
lp160b30.zip
lp160b20.7z (LZMA-compressed, recommended)
lp160b20.zip
Other information:
1.6.0beta30-README.txt
1.6.0beta30-LICENSE.txt
1.6.0beta20-README.txt
1.6.0beta20-LICENSE.txt
Changes since the last public release (1.5.7):
@@ -76,8 +76,6 @@ Version 1.6.0beta03 [December 22, 2011]
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.6.0beta04 [December 30, 2011]
Regenerated configure scripts with automake-1.11.2
@@ -349,181 +347,7 @@ Version 1.6.0beta20 [March 29, 2012]
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.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.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.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.6.0beta24 [June 7, 2012]
Don't check palette indexes if num_palette is 0 (as it can be in MNG files).
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.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.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.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.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.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).
CVE-2011-3048).
Send comments/corrections/commendations to png-mng-implement at lists.sf.net
(subscription required; visit

179
CHANGES
View File

@@ -3827,8 +3827,6 @@ Version 1.6.0beta03 [December 22, 2011]
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.6.0beta04 [December 30, 2011]
Regenerated configure scripts with automake-1.11.2
@@ -4100,182 +4098,7 @@ Version 1.6.0beta20 [March 29, 2012]
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.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.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.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.6.0beta24 [June 7, 2012]
Don't check palette indexes if num_palette is 0 (as it can be in MNG files).
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.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.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.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.6.0beta29 [September 4, 2012]
Fixed the simplified API example programs to add the *colormap parameter
to several of he API 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.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).
CVE-2011-3048).
Send comments/corrections/commendations to png-mng-implement at lists.sf.net
(subscription required; visit

View File

@@ -219,7 +219,7 @@ ENDIF(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
# copies if different.
macro(CREATE_SYMLINK SRC_FILE DEST_FILE)
FILE(REMOVE ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${DEST_FILE})
if(WIN32 AND NOT CYGWIN AND NOT MSYS)
if(WIN32 AND NOT CYGWIN AND NOT MINGW)
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}
@@ -227,10 +227,10 @@ macro(CREATE_SYMLINK SRC_FILE DEST_FILE)
DEPENDS ${PNG_LIB_NAME} ${PNG_LIB_NAME_STATIC}
)
ADD_CUSTOM_TARGET(${DEST_FILE}_COPY ALL DEPENDS ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${DEST_FILE})
else(WIN32 AND NOT CYGWIN AND NOT MSYS)
else(WIN32 AND NOT CYGWIN AND NOT MINGW)
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})
endif(WIN32 AND NOT CYGWIN AND NOT MSYS)
endif(WIN32 AND NOT CYGWIN AND NOT MINGW)
endmacro()
# libpng is a library so default to 'lib'
@@ -260,7 +260,7 @@ 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.0beta30
# VERSION 16.${PNGLIB_RELEASE}.1.6.0beta20
VERSION 16.${PNGLIB_RELEASE}.0
SOVERSION 16
CLEAN_DIRECT_OUTPUT 1)

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.0beta30, October 24, 2012, are
Copyright (c) 2004, 2006-2012 Glenn Randers-Pehrson, and are
libpng versions 1.2.6, August 15, 2004, through 1.6.0beta20, March 29, 2012, are
Copyright (c) 2004, 2006-2011 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
October 24, 2012
March 29, 2012

View File

@@ -14,17 +14,12 @@ 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
check_PROGRAMS+= pngvalid pngstest
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_LDADD = libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.la
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
TESTS += test-pngvalid-simple.sh test-pngvalid-full.sh test-pngstest.sh
# man pages
dist_man_MANS= libpng.3 libpngpf.3 png.5
@@ -163,7 +158,6 @@ $(srcdir)/scripts/pnglibconf.h.prebuilt:
# 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
contrib/libtests/pngunknown.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

2
README
View File

@@ -1,4 +1,4 @@
README for libpng version 1.6.0beta30 - October 24, 2012 (shared library 16.0)
README for libpng version 1.6.0beta20 - March 29, 2012 (shared library 16.0)
See the note about version numbers near the top of png.h
See INSTALL for instructions on how to install libpng.

View File

@@ -213,7 +213,7 @@ case "$mode" in
exec >&2
echo "Your system has a partial set of autotools generated files."
echo "autogen.sh is unable to proceed. The full set of files is"
echo "contained in the libpng 'tar' distribution archive and you do"
echo "not need to run autogen.sh if you use it."
echo "contained in the distribution archive and you do not need to run"
echo "autogen.sh if you use it."
exit 1;;
esac

37
check_icc.c Normal file
View File

@@ -0,0 +1,37 @@
{
int
icheck;
/* 0: not a known sRGB profile
* 1: HP-Microsoft sRGB v2
* 2: ICC sRGB v4 perceptual
* 3: ICC sRGB v2 perceptual no black-compensation
*/
png_uint_32
check_crc[4] = {0, 0xf29e526dUL, 0xbbef7812UL, 0x427ebb21UL},
check_len[4] = {0, 3144, 60960, 3052};
png_uint_32
length,
profile_crc;
unsigned char
*data;
length=(png_uint_32) ...;
for (icheck=3; icheck > 0; icheck--)
{
if (length == check_len[icheck])
{
data=...(profile);
profile_crc=crc32(0,data,length);
if (profile_crc == check_crc[icheck])
{
/* set sRGB.... */
break;
}
}
}
}

View File

@@ -18,15 +18,15 @@ AC_PREREQ([2.68])
dnl Version number stuff here:
AC_INIT([libpng],[1.6.0beta30],[png-mng-implement@lists.sourceforge.net])
AC_INIT([libpng],[1.6.0beta20],[png-mng-implement@lists.sourceforge.net])
AC_CONFIG_MACRO_DIR([scripts])
# libpng does not follow GNU file name conventions (hence 'foreign')
# color-tests requires automake 1.11 or later
# 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])
# 1.11.1 fixes a security issue in 1.11
AM_INIT_AUTOMAKE([1.11.1 foreign dist-xz dist-bzip2 color-tests silent-rules])
# was:
# AM_INIT_AUTOMAKE
AM_MAINTAINER_MODE
@@ -37,7 +37,7 @@ dnl automake, so the following is not necessary (and is not defined anyway):
dnl AM_PREREQ([1.11.2])
dnl stop configure from automagically running automake
PNGLIB_VERSION=1.6.0beta30
PNGLIB_VERSION=1.6.0beta20
PNGLIB_MAJOR=1
PNGLIB_MINOR=6
PNGLIB_RELEASE=0
@@ -185,9 +185,9 @@ AM_CONDITIONAL(HAVE_LD_VERSION_SCRIPT, test "$have_ld_version_script" = "yes")
if test "$have_ld_version_script" = "yes"; then
AC_MSG_CHECKING([for symbol prefix])
SYMBOL_PREFIX=`echo "PREFIX=__USER_LABEL_PREFIX__" \
| ${CPP-${CC-gcc} -E} - 2>&1 \
| ${EGREP-grep} "^PREFIX=" \
| ${SED-sed} -e "s:^PREFIX=::" -e "s:__USER_LABEL_PREFIX__::"`
| ${CPP-${CC-gcc} -E} - 2>&1 \
| ${EGREP-grep} "^PREFIX=" \
| ${SED-sed} "s:^PREFIX=::"`
AC_SUBST(SYMBOL_PREFIX)
AC_MSG_RESULT($SYMBOL_PREFIX)
fi

View File

@@ -273,7 +273,7 @@ int main(int argc, const char **argv)
ystep = xstep = 1;
}
/* To find the pixel, loop over 'py' for each pass
/* To find the pixel loop over 'py' for each pass
* reading a row and then checking to see if it
* contains the pixel.
*/
@@ -283,13 +283,12 @@ int main(int argc, const char **argv)
/* png_read_row takes two pointers. When libpng
* handles the interlace the first is filled in
* pixel-by-pixel, and the second receives the same
* pixel-by-pixel, the second receives the same
* pixels but they are replicated across the
* unwritten pixels so far for each pass. When we
* do the interlace, however, they just contain
* the pixels from the interlace pass - giving
* both is wasteful and pointless, so we pass a
* NULL pointer.
* both is wasteful and pointless.
*/
png_read_row(png_ptr, row_tmp, NULL);
@@ -327,7 +326,7 @@ int main(int argc, const char **argv)
else
{
/* Else libpng has raised an error. An error message has
* already been output, so it is only necessary to clean up
* already been output, it is only necessary to clean up
* locally allocated data:
*/
if (row != NULL)

View File

@@ -29,17 +29,13 @@ int main(int argc, const char **argv)
{
png_image image;
/* Only the image structure version number needs to be set. */
memset(&image, 0, sizeof image);
image.version = PNG_IMAGE_VERSION;
if (png_image_begin_read_from_file(&image, argv[1]))
{
png_bytep buffer;
/* Change this to try different formats! If you set a colormap format
* then you must also supply a colormap below.
*/
/* Change this to try different formats! */
image.format = PNG_FORMAT_RGBA;
buffer = malloc(PNG_IMAGE_SIZE(image));
@@ -47,11 +43,10 @@ int main(int argc, const char **argv)
if (buffer != NULL)
{
if (png_image_finish_read(&image, NULL/*background*/, buffer,
0/*row_stride*/, NULL/*colormap for PNG_FORMAT_FLAG_COLORMAP */))
0/*row_stride*/))
{
if (png_image_write_to_file(&image, argv[2],
0/*convert_to_8bit*/, buffer, 0/*row_stride*/,
NULL/*colormap*/))
0/*convert_to_8bit*/, buffer, 0/*row_stride*/))
result = 0;
else

View File

@@ -136,23 +136,29 @@ int readpng2_init(mainprog_info *mainprog_ptr)
* used, i.e., all chunks recognized by libpng except for IHDR, PLTE, IDAT,
* IEND, tRNS, bKGD, gAMA, and sRGB (small performance improvement) */
{
/* These byte strings were copied from png.h. If a future version
* of readpng2.c recognizes more chunks, add them to this list.
*/
static PNG_CONST png_byte chunks_to_process[] = {
98, 75, 71, 68, '\0', /* bKGD */
103, 65, 77, 65, '\0', /* gAMA */
115, 82, 71, 66, '\0', /* sRGB */
};
/* These byte strings were copied from png.h. If a future libpng
* version recognizes more chunks, add them to this list. If a
* future version of readpng2.c recognizes more chunks, delete them
* from this list. */
static /* const */ png_byte chunks_to_ignore[] = {
99, 72, 82, 77, '\0', /* cHRM */
104, 73, 83, 84, '\0', /* hIST */
105, 67, 67, 80, '\0', /* iCCP */
105, 84, 88, 116, '\0', /* iTXt */
111, 70, 70, 115, '\0', /* oFFs */
112, 67, 65, 76, '\0', /* pCAL */
112, 72, 89, 115, '\0', /* pHYs */
115, 66, 73, 84, '\0', /* sBIT */
115, 67, 65, 76, '\0', /* sCAL */
115, 80, 76, 84, '\0', /* sPLT */
115, 84, 69, 82, '\0', /* sTER */
116, 69, 88, 116, '\0', /* tEXt */
116, 73, 77, 69, '\0', /* tIME */
122, 84, 88, 116, '\0' /* zTXt */
};
/* Ignore all chunks except for IHDR, PLTE, tRNS, IDAT, and IEND */
png_set_keep_unknown_chunks(png_ptr, -1 /* PNG_HANDLE_CHUNK_NEVER */,
NULL, -1);
/* But do not ignore chunks in the "chunks_to_process" list */
png_set_keep_unknown_chunks(png_ptr,
0 /* PNG_HANDLE_CHUNK_AS_DEFAULT */, chunks_to_process,
sizeof(chunks_to_process)/5);
png_set_keep_unknown_chunks(png_ptr, 1 /* PNG_HANDLE_CHUNK_NEVER */,
chunks_to_ignore, sizeof(chunks_to_ignore)/5);
}
#endif /* PNG_HANDLE_AS_UNKNOWN_SUPPORTED */

0
contrib/libtests/gentests.sh Executable file → Normal file
View File

View File

@@ -72,7 +72,6 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <errno.h>
@@ -392,36 +391,11 @@ generate_row(png_bytep row, size_t rowbytes, unsigned int y, int color_type,
}
}
static void PNGCBAPI
makepng_warning(png_structp png_ptr, png_const_charp message)
{
const char **ep = png_get_error_ptr(png_ptr);
const char *name;
if (ep != NULL && *ep != NULL)
name = *ep;
else
name = "makepng";
fprintf(stderr, "%s: warning: %s\n", name, message);
}
static void PNGCBAPI
makepng_error(png_structp png_ptr, png_const_charp message)
{
makepng_warning(png_ptr, message);
png_longjmp(png_ptr, 1);
}
static int /* 0 on success, else an error code */
write_png(const char **name, FILE *fp, int color_type, int bit_depth,
volatile png_fixed_point gamma, chunk_insert * volatile insert,
unsigned int filters)
write_png(FILE *fp, int color_type, int bit_depth,
volatile png_fixed_point gamma, chunk_insert * volatile insert)
{
png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,
name, makepng_error, makepng_warning);
png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,0,0,0);
volatile png_infop info_ptr = NULL;
volatile png_bytep row = NULL;
@@ -542,7 +516,7 @@ write_png(const char **name, FILE *fp, int color_type, int bit_depth,
png_write_info(png_ptr, info_ptr);
/* Restrict the filters */
png_set_filter(png_ptr, PNG_FILTER_TYPE_BASE, filters);
png_set_filter(png_ptr, PNG_FILTER_TYPE_BASE, PNG_NO_FILTERS);
{
int passes = png_set_interlace_handling(png_ptr);
@@ -629,10 +603,7 @@ load_file(png_const_charp name, png_bytepp result)
if (total > 0)
{
/* Round up to a multiple of 4 here to allow an iCCP profile
* to be padded to a 4x boundary.
*/
png_bytep data = malloc((total+3)&~3);
png_bytep data = malloc(total);
if (data != NULL)
{
@@ -757,13 +728,12 @@ insert_iCCP(png_structp png_ptr, png_infop info_ptr, int nparams,
case '<':
{
png_size_t filelen = load_file(params[1]+1, &profile);
if (filelen > 0xfffffffc) /* Maximum profile length */
if (filelen > 0xffffffff) /* Maximum profile length */
{
fprintf(stderr, "%s: file too long (%lu) for an ICC profile\n",
params[1]+1, (unsigned long)filelen);
exit(1);
}
proflen = (png_uint_32)filelen;
}
break;
@@ -800,14 +770,9 @@ insert_iCCP(png_structp png_ptr, png_infop info_ptr, int nparams,
if (proflen & 3)
{
fprintf(stderr,
"makepng: --insert iCCP %s: profile length made a multiple of 4\n",
"--insert iCCP %s: profile length must be a multiple of 4\n",
params[1]);
/* load_file allocates extra space for this padding, the ICC spec requires
* padding with zero bytes.
*/
while (proflen & 3)
profile[proflen++] = 0;
result = 0; /* Cannot fix this! */
}
if (profile != NULL && proflen > 3)
@@ -1101,7 +1066,6 @@ main(int argc, char **argv)
const char *file_name = NULL;
int color_type = 8; /* invalid */
int bit_depth = 32; /* invalid */
unsigned int filters = PNG_ALL_FILTERS;
png_fixed_point gamma = 0; /* not set */
chunk_insert *head_insert = NULL;
chunk_insert **insert_ptr = &head_insert;
@@ -1128,12 +1092,6 @@ main(int argc, char **argv)
continue;
}
if (strcmp(arg, "--nofilters") == 0)
{
filters = PNG_FILTER_NONE;
continue;
}
if (argc >= 3 && strcmp(arg, "--insert") == 0)
{
png_const_charp what = *++argv;
@@ -1167,7 +1125,7 @@ main(int argc, char **argv)
if (strncmp(arg, "gray", 4) == 0)
{
if (arg[4] == 0)
if (arg[5] == 0)
{
color_type = PNG_COLOR_TYPE_GRAY;
continue;
@@ -1184,7 +1142,7 @@ main(int argc, char **argv)
if (strncmp(arg, "rgb", 3) == 0)
{
if (arg[3] == 0)
if (arg[4] == 0)
{
color_type = PNG_COLOR_TYPE_RGB;
continue;
@@ -1199,7 +1157,7 @@ main(int argc, char **argv)
}
}
if (color_type == 8 && isdigit(arg[0]))
if (color_type == 8)
{
color_type = atoi(arg);
if (color_type < 0 || color_type > 6 || color_type == 1 ||
@@ -1212,7 +1170,7 @@ main(int argc, char **argv)
continue;
}
if (bit_depth == 32 && isdigit(arg[0]))
if (bit_depth == 32)
{
bit_depth = atoi(arg);
if (bit_depth <= 0 || bit_depth > 16 ||
@@ -1250,30 +1208,8 @@ main(int argc, char **argv)
exit(1);
}
/* Restrict the filters for more speed to those we know are used for the
* generated images.
*/
if (filters == PNG_ALL_FILTERS)
{
if ((color_type & PNG_COLOR_MASK_PALETTE) != 0 || bit_depth < 8)
filters = PNG_FILTER_NONE;
else if (color_type & PNG_COLOR_MASK_COLOR) /* rgb */
{
if (bit_depth == 8)
filters &= ~(PNG_FILTER_NONE | PNG_FILTER_AVG);
else
filters = PNG_FILTER_SUB | PNG_FILTER_PAETH;
}
else /* gray 8 or 16-bit */
filters &= ~PNG_FILTER_NONE;
}
{
int ret = write_png(&file_name, fp, color_type, bit_depth, gamma,
head_insert, filters);
int ret = write_png(fp, color_type, bit_depth, gamma, head_insert);
if (ret != 0 && file_name != NULL)
remove(file_name);

View File

@@ -35,12 +35,11 @@
# include "../../png.h"
#endif
#ifdef PNG_SIMPLIFIED_READ_SUPPORTED /* Else nothing can be done */
#include "../tools/sRGB.h"
/* KNOWN ISSUES
*
* These defines switch on alternate algorithms for format conversions to match
* These defines switch on alternate algorithms for format convertions to match
* the current libpng implementation; they are set to allow pngstest to pass
* even though libpng is producing answers that are not as correct as they
* should be.
@@ -55,11 +54,8 @@
/* The following is to support direct compilation of this file as C++ */
#ifdef __cplusplus
# define voidcast(type, value) static_cast<type>(value)
# define aligncastconst(type, value) \
static_cast<type>(static_cast<const void*>(value))
#else
# define voidcast(type, value) (value)
# define aligncastconst(type, value) ((const void*)(value))
#endif /* __cplusplus */
/* Generate random bytes. This uses a boring repeatable algorithm and it
@@ -125,7 +121,7 @@ u16d(double d)
}
/* sRGB support: use exact calculations rounded to the nearest int, see the
* fesetround() call in main(). sRGB_to_d optimizes the 8 to 16-bit conversion.
* fesetround() call in main(). sRGB_to_d optimizes the 8 to 16-bit convertion.
*/
static double sRGB_to_d[256];
static double g22_to_d[256];
@@ -236,7 +232,7 @@ power_law_error16(int value)
if (value > 0 && value < 65535)
{
/* Round trip the value through an 8-bit representation but using
* non-matching to/from conversions.
* non-matching to/from convertions.
*/
double vd = value / 65535.;
double e = fabs(
@@ -1067,7 +1063,7 @@ get_pixel(png_uint_32 format))(Pixel *p, png_const_voidp pb)
* 3) Convert between 8-bit and 16-bit components. (Both directtions are
* relevant.)
*
* This gives the following base format conversion matrix:
* This gives the following base format convertion matrix:
*
* OUT: ----- 8-bit ----- ----- 16-bit -----
* IN G GA RGB RGBA G GA RGB RGBA
@@ -1161,7 +1157,7 @@ gpc_nop6(Pixel *out, const Pixel *in, const Background *back)
}
#endif
/* 8-bit to 8-bit conversions */
/* 8-bit to 8-bit convertions */
/* bckg: composite on gray background */
static void
gpc_bckg(Pixel *out, const Pixel *in, const Background *back)
@@ -1256,7 +1252,7 @@ gpc_g8b(Pixel *out, const Pixel *in, const Background *back)
out->a = 255;
}
/* 8-bit to 16-bit conversions */
/* 8-bit to 16-bit convertions */
/* lin: make sRGB components linear, alpha := 65535 */
static void
gpc_lin(Pixel *out, const Pixel *in, const Background *back)
@@ -1413,7 +1409,7 @@ gpc_gprq(Pixel *out, const Pixel *in, const Background *back)
out->a = 65535;
}
/* 8-bit to 16-bit conversions for gAMA 45455 encoded values */
/* 8-bit to 16-bit convertions for gAMA 45455 encoded values */
/* Lin: make gAMA 45455 components linear, alpha := 65535 */
static void
gpc_Lin(Pixel *out, const Pixel *in, const Background *back)
@@ -1584,7 +1580,7 @@ gpc_Gprq(Pixel *out, const Pixel *in, const Background *back)
}
#endif
/* 16-bit to 8-bit conversions */
/* 16-bit to 8-bit convertions */
/* sRGB: convert linear components to sRGB, alpha := 255 */
static void
gpc_sRGB(Pixel *out, const Pixel *in, const Background *back)
@@ -1810,7 +1806,7 @@ gpc_cb16(Pixel *out, const Pixel *in, const Background *back)
out->a = 255;
}
/* 16-bit to 16-bit conversions */
/* 16-bit to 16-bit convertions */
/* A: set alpha to 65535 */
static void
gpc_A(Pixel *out, const Pixel *in, const Background *back)
@@ -1901,13 +1897,13 @@ static void (* const gpc_fn_colormapped[8/*in*/][8/*out*/])
};
/* The error arrays record the error in the same matrix; 64 entries, however
* the different algorithms used in libpng for colormap and direct conversions
* the different algorithms used in libpng for colormap and direct convertions
* mean that four separate matrices are used (for each combination of
* colormapped and direct.)
*
* In some cases the conversion between sRGB formats goes via a linear
* intermediate; an sRGB to linear conversion (as above) is followed by a simple
* linear to sRGB step with no other conversions. This is done by a separate
* In some cases the convertion between sRGB formats goes via a linear
* intermediate; an sRGB to linear convertion (as above) is followed by a simple
* linear to sRGB step with no other convertions. This is done by a separate
* error array from an arbitrary 'in' format to one of the four basic outputs
* (since final output is always sRGB not colormapped).
*
@@ -2121,7 +2117,7 @@ typedef struct
}
Transform;
/* Return a 'transform' as above for the given format conversion. */
/* Return a 'transform' as above for the given format convertion. */
static void
transform_from_formats(Transform *result, Image *in_image,
const Image *out_image, png_const_colorp background, int via_linear)
@@ -2186,10 +2182,10 @@ transform_from_formats(Transform *result, Image *in_image,
else
{
/* The caller handles the colormap->pixel value conversion, so the
/* The caller handles the colormap->pixel value convertion, so the
* transform function just gets a pixel value, however because libpng
* currently contains a different implementation for mapping a colormap if
* both input and output are colormapped we need different conversion
* both input and output are colormapped we need different convertion
* functions to deal with errors in the libpng implementation.
*/
if (in_format & out_format & PNG_FORMAT_FLAG_COLORMAP)
@@ -2250,7 +2246,7 @@ transform_from_formats(Transform *result, Image *in_image,
result->background_color.ir = background->red;
result->background_color.ig = background->green;
result->background_color.ib = background->blue;
/* TODO: sometimes libpng uses the power law conversion here, how
/* TODO: sometimes libpng uses the power law convertion here, how
* to handle this?
*/
result->background_color.dr = sRGB_to_d[background->red];
@@ -2263,7 +2259,7 @@ transform_from_formats(Transform *result, Image *in_image,
result->background_color.ir =
result->background_color.ig =
result->background_color.ib = background->green;
/* TODO: sometimes libpng uses the power law conversion here, how
/* TODO: sometimes libpng uses the power law convertion here, how
* to handle this?
*/
result->background_color.dr =
@@ -2277,7 +2273,7 @@ transform_from_formats(Transform *result, Image *in_image,
result->background_color.ir =
result->background_color.ig =
result->background_color.ib = BUFFER_INIT8;
/* TODO: sometimes libpng uses the power law conversion here, how
/* TODO: sometimes libpng uses the power law convertion here, how
* to handle this?
*/
result->background_color.dr =
@@ -2932,8 +2928,8 @@ compare_two_images(Image *a, Image *b, int via_linear,
*/
if (formatb & PNG_FORMAT_FLAG_LINEAR) /* 16-bit checks */
{
png_const_uint_16p pua = aligncastconst(png_const_uint_16p, psa);
png_const_uint_16p pub = aligncastconst(png_const_uint_16p, psb);
png_const_uint_16p pua = (png_const_uint_16p)psa;
png_const_uint_16p pub = (png_const_uint_16p)psb;
switch (bchannels)
{
@@ -3153,7 +3149,6 @@ read_one_file(Image *image)
return read_file(image, FORMAT_NO_CHANGE, NULL);
}
#ifdef PNG_SIMPLIFIED_WRITE_SUPPORTED
static int
write_one_file(Image *output, Image *image, int convert_to_8bit)
{
@@ -3242,7 +3237,6 @@ write_one_file(Image *output, Image *image, int convert_to_8bit)
return logerror(output, output->tmpfile_name,
": read of new file failed", "");
}
#endif
static int
testimage(Image *image, png_uint_32 opts, format_list *pf)
@@ -3330,48 +3324,44 @@ testimage(Image *image, png_uint_32 opts, format_list *pf)
if (!result)
break;
# ifdef PNG_SIMPLIFIED_WRITE_SUPPORTED
/* Write the *copy* just made to a new file to make sure the write
* side works ok. Check the conversion to sRGB if the copy is
* linear.
*/
/* Write the *copy* just made to a new file to make sure the write side
* works ok. Check the conversion to sRGB if the copy is linear.
*/
output.opts = opts;
result = write_one_file(&output, &copy, 0/*convert to 8bit*/);
if (!result)
break;
/* Validate against the original too; the background is needed here
* as well so that compare_two_images knows what color was used.
*/
result = compare_two_images(image, &output, 0, background);
if (!result)
break;
if ((format & PNG_FORMAT_FLAG_LINEAR) != 0 &&
(format & PNG_FORMAT_FLAG_COLORMAP) == 0)
{
/* 'output' is linear, convert to the corresponding sRGB format. */
output.opts = opts;
result = write_one_file(&output, &copy, 0/*convert to 8bit*/);
result = write_one_file(&output, &copy, 1/*convert to 8bit*/);
if (!result)
break;
/* Validate against the original too; the background is needed here
* as well so that compare_two_images knows what color was used.
/* This may involve a conversion via linear; in the ideal world this
* would round-trip correctly, but libpng 1.5.7 is not the ideal
* world so allow a drift (error_via_linear).
*
* 'image' has an alpha channel but 'output' does not then there
* will a strip-alpha-channel operation (because 'output' is
* linear), handle this by composing on black when doing the
* comparison.
*/
result = compare_two_images(image, &output, 0, background);
result = compare_two_images(image, &output, 1/*via_linear*/,
background);
if (!result)
break;
if ((format & PNG_FORMAT_FLAG_LINEAR) != 0 &&
(format & PNG_FORMAT_FLAG_COLORMAP) == 0)
{
/* 'output' is linear, convert to the corresponding sRGB format.
*/
output.opts = opts;
result = write_one_file(&output, &copy, 1/*convert to 8bit*/);
if (!result)
break;
/* This may involve a conversion via linear; in the ideal world
* this would round-trip correctly, but libpng 1.5.7 is not the
* ideal world so allow a drift (error_via_linear).
*
* 'image' has an alpha channel but 'output' does not then there
* will a strip-alpha-channel operation (because 'output' is
* linear), handle this by composing on black when doing the
* comparison.
*/
result = compare_two_images(image, &output, 1/*via_linear*/,
background);
if (!result)
break;
}
# endif /* PNG_SIMPLIFIED_WRITE_SUPPORTED */
}
}
freeimage(&output);
@@ -3407,10 +3397,6 @@ test_one_file(const char *file_name, format_list *formats, png_uint_32 opts,
else
printf("FAIL:");
# ifndef PNG_SIMPLIFIED_WRITE_SUPPORTED
printf(" (no write)");
# endif
print_opts(opts);
printf(" %s\n", file_name);
/* stdout may not be line-buffered if it is piped to a file, so: */
@@ -3690,11 +3676,3 @@ main(int argc, char **argv)
return retval;
}
#else /* !PNG_SIMPLIFIED_READ_SUPPORTED */
int main(void)
{
fprintf(stderr, "pngstest: no read support in libpng, test skipped\n");
return 0;
}
#endif /* PNG_SIMPLIFIED_READ_SUPPORTED */

View File

@@ -1,960 +0,0 @@
/* pngunknown.c - test the read side unknown chunk handling
*
* Last changed in libpng 1.6.0 [(PENDING RELEASE)]
* Copyright (c) 2012 Glenn Randers-Pehrson
* Written by John Cunningham Bowler
*
* This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer
* and license in png.h
*
* NOTES:
* This is a C program that is intended to be linked against libpng. It
* allows the libpng unknown handling code to be tested by interpreting
* arguments to save or discard combinations of chunks. The program is
* currently just a minimal validation for the built-in libpng facilities.
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <setjmp.h>
/* 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
#ifdef PNG_READ_SUPPORTED
#if PNG_LIBPNG_VER < 10500
/* This deliberately lacks the PNG_CONST. */
typedef png_byte *png_const_bytep;
/* This is copied from 1.5.1 png.h: */
#define PNG_INTERLACE_ADAM7_PASSES 7
#define PNG_PASS_START_ROW(pass) (((1U&~(pass))<<(3-((pass)>>1)))&7)
#define PNG_PASS_START_COL(pass) (((1U& (pass))<<(3-(((pass)+1)>>1)))&7)
#define PNG_PASS_ROW_SHIFT(pass) ((pass)>2?(8-(pass))>>1:3)
#define PNG_PASS_COL_SHIFT(pass) ((pass)>1?(7-(pass))>>1:3)
#define PNG_PASS_ROWS(height, pass) (((height)+(((1<<PNG_PASS_ROW_SHIFT(pass))\
-1)-PNG_PASS_START_ROW(pass)))>>PNG_PASS_ROW_SHIFT(pass))
#define PNG_PASS_COLS(width, pass) (((width)+(((1<<PNG_PASS_COL_SHIFT(pass))\
-1)-PNG_PASS_START_COL(pass)))>>PNG_PASS_COL_SHIFT(pass))
#define PNG_ROW_FROM_PASS_ROW(yIn, pass) \
(((yIn)<<PNG_PASS_ROW_SHIFT(pass))+PNG_PASS_START_ROW(pass))
#define PNG_COL_FROM_PASS_COL(xIn, pass) \
(((xIn)<<PNG_PASS_COL_SHIFT(pass))+PNG_PASS_START_COL(pass))
#define PNG_PASS_MASK(pass,off) ( \
((0x110145AFU>>(((7-(off))-(pass))<<2)) & 0xFU) | \
((0x01145AF0U>>(((7-(off))-(pass))<<2)) & 0xF0U))
#define PNG_ROW_IN_INTERLACE_PASS(y, pass) \
((PNG_PASS_MASK(pass,0) >> ((y)&7)) & 1)
#define PNG_COL_IN_INTERLACE_PASS(x, pass) \
((PNG_PASS_MASK(pass,1) >> ((x)&7)) & 1)
/* These are needed too for the default build: */
#define PNG_WRITE_16BIT_SUPPORTED
#define PNG_READ_16BIT_SUPPORTED
/* This comes from pnglibconf.h afer 1.5: */
#define PNG_FP_1 100000
#define PNG_GAMMA_THRESHOLD_FIXED\
((png_fixed_point)(PNG_GAMMA_THRESHOLD * PNG_FP_1))
#endif
#if PNG_LIBPNG_VER < 10600
/* 1.6.0 constifies many APIs. The following exists to allow pngvalid to be
* compiled against earlier versions.
*/
# define png_const_structp png_structp
#endif
/* 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_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')
/* 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))
/* Chunk information */
#define PNG_INFO_tEXt 0x10000000U
#define PNG_INFO_iTXt 0x20000000U
#define PNG_INFO_zTXt 0x40000000U
#define PNG_INFO_sTER 0x01000000U
#define PNG_INFO_vpAg 0x02000000U
#define ABSENT 0
#define START 1
#define END 2
static struct
{
char name[5];
png_uint_32 flag;
png_uint_32 tag;
int unknown; /* Chunk not known to libpng */
int all; /* Chunk set by the '-1' option */
int position; /* position in pngtest.png */
int keep; /* unknown handling setting */
} chunk_info[] = {
/* Critical chunks */
{ "IDAT", PNG_INFO_IDAT, png_IDAT, 0, 0, START, 0 }, /* must be [0] */
{ "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 },
/* No libpng handling */
{ "sTER", PNG_INFO_sTER, png_sTER, 1, 1, START, 0 },
{ "vpAg", PNG_INFO_vpAg, png_vpAg, 1, 0, START, 0 },
};
#define NINFO ((int)((sizeof chunk_info)/(sizeof chunk_info[0])))
static void
clear_keep(void)
{
int i = NINFO;
while (--i >= 0)
chunk_info[i].keep = 0;
}
static int
find(const char *name)
{
int i = NINFO;
while (--i >= 0)
{
if (memcmp(chunk_info[i].name, name, 4) == 0)
break;
}
return i;
}
static int
findb(const png_byte *name)
{
int i = NINFO;
while (--i >= 0)
{
if (memcmp(chunk_info[i].name, name, 4) == 0)
break;
}
return i;
}
static int
find_by_flag(png_uint_32 flag)
{
int i = NINFO;
while (--i >= 0) if (chunk_info[i].flag == flag) return i;
fprintf(stderr, "pngunknown: internal error\n");
exit(4);
}
static int
ancillary(const char *name)
{
return PNG_CHUNK_ANCILLARY(PNG_CHUNK(name[0], name[1], name[2], name[3]));
}
static int
ancillaryb(const png_byte *name)
{
return PNG_CHUNK_ANCILLARY(PNG_CHUNK(name[0], name[1], name[2], name[3]));
}
/* Type of an error_ptr */
typedef struct
{
jmp_buf error_return;
png_structp png_ptr;
png_infop info_ptr, end_ptr;
int error_count;
int warning_count;
const char *program;
const char *file;
const char *test;
} display;
static const char init[] = "initialization";
static const char cmd[] = "command line";
static void
init_display(display *d, const char *program)
{
memset(d, 0, sizeof *d);
d->png_ptr = NULL;
d->info_ptr = d->end_ptr = NULL;
d->error_count = d->warning_count = 0;
d->program = program;
d->file = program;
d->test = init;
}
static void
clean_display(display *d)
{
png_destroy_read_struct(&d->png_ptr, &d->info_ptr, &d->end_ptr);
/* This must not happen - it might cause an app crash */
if (d->png_ptr != NULL || d->info_ptr != NULL || d->end_ptr != NULL)
{
fprintf(stderr, "%s(%s): png_destroy_read_struct error\n", d->file,
d->test);
exit(1);
}
/* Invalidate the test */
d->test = init;
}
PNG_FUNCTION(void, display_exit, (display *d), static PNG_NORETURN)
{
++(d->error_count);
if (d->png_ptr != NULL)
clean_display(d);
/* During initialization and if this is a single command line argument set
* exit now - there is only one test, otherwise longjmp to do the next test.
*/
if (d->test == init || d->test == cmd)
exit(1);
longjmp(d->error_return, 1);
}
static int
display_rc(const display *d, int strict)
{
return d->error_count + (strict ? d->warning_count : 0);
}
/* libpng error and warning callbacks */
PNG_FUNCTION(void, error, (png_structp png_ptr, const char *message),
static PNG_NORETURN)
{
display *d = (display*)png_get_error_ptr(png_ptr);
fprintf(stderr, "%s(%s): libpng error: %s\n", d->file, d->test, message);
display_exit(d);
}
static void
warning(png_structp png_ptr, const char *message)
{
display *d = (display*)png_get_error_ptr(png_ptr);
fprintf(stderr, "%s(%s): libpng warning: %s\n", d->file, d->test, message);
++(d->warning_count);
}
static png_uint_32
get_valid(display *d, png_const_infop info_ptr)
{
png_uint_32 flags = png_get_valid(d->png_ptr, info_ptr, (png_uint_32)~0);
/* Map the text chunks back into the flags */
{
png_textp text;
png_uint_32 ntext = png_get_text(d->png_ptr, info_ptr, &text, NULL);
while (ntext-- > 0) switch (text[ntext].compression)
{
case -1:
flags |= PNG_INFO_tEXt;
break;
case 0:
flags |= PNG_INFO_zTXt;
break;
case 1:
case 2:
flags |= PNG_INFO_iTXt;
break;
default:
fprintf(stderr, "%s(%s): unknown text compression %d\n", d->file,
d->test, text[ntext].compression);
display_exit(d);
}
}
return flags;
}
static png_uint_32
get_unknown(display *d, int def, png_const_infop info_ptr)
{
/* Create corresponding 'unknown' flags */
png_uint_32 flags = 0;
{
png_unknown_chunkp unknown;
int num_unknown = png_get_unknown_chunks(d->png_ptr, info_ptr, &unknown);
while (--num_unknown >= 0)
{
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.
*/
if (chunk < 0) switch (def)
{
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",
unknown[num_unknown].name);
++(d->error_count);
break;
case PNG_HANDLE_CHUNK_IF_SAFE:
if (!ancillaryb(unknown[num_unknown].name))
{
fprintf(stderr,
"%s(%s): if-safe: %s: unknown critical chunk saved\n",
d->file, d->test, unknown[num_unknown].name);
++(d->error_count);
break;
}
/* FALL THROUGH (safe) */
case PNG_HANDLE_CHUNK_ALWAYS:
break;
}
else
flags |= chunk_info[chunk].flag;
}
}
return flags;
}
static int
check(FILE *fp, int argc, const char **argv, png_uint_32p flags/*out*/,
display *d)
{
int i, def = PNG_HANDLE_CHUNK_AS_DEFAULT, npasses, ipass;
png_uint_32 height;
/* Some of these errors are permanently fatal and cause an exit here, others
* are per-test and cause an error return.
*/
d->png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, d, error,
warning);
if (d->png_ptr == NULL)
{
fprintf(stderr, "%s(%s): could not allocate png struct\n", d->file,
d->test);
/* Terminate here, this error is not test specific. */
exit(1);
}
d->info_ptr = png_create_info_struct(d->png_ptr);
d->end_ptr = png_create_info_struct(d->png_ptr);
if (d->info_ptr == NULL || d->end_ptr == NULL)
{
fprintf(stderr, "%s(%s): could not allocate png info\n", d->file,
d->test);
clean_display(d);
exit(1);
}
png_init_io(d->png_ptr, fp);
/* 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).
*/
for (i=0; i<argc; ++i)
{
const char *equals = strchr(argv[i], '=');
if (equals != NULL)
{
int chunk, option;
if (strcmp(equals+1, "default") == 0)
option = PNG_HANDLE_CHUNK_AS_DEFAULT;
else if (strcmp(equals+1, "discard") == 0)
option = PNG_HANDLE_CHUNK_NEVER;
else if (strcmp(equals+1, "if-safe") == 0)
option = PNG_HANDLE_CHUNK_IF_SAFE;
else if (strcmp(equals+1, "save") == 0)
option = PNG_HANDLE_CHUNK_ALWAYS;
else
{
fprintf(stderr, "%s(%s): %s: unrecognized chunk option\n", d->file,
d->test, argv[i]);
display_exit(d);
}
switch (equals - argv[i])
{
case 4: /* chunk name */
chunk = find(argv[i]);
if (chunk >= 0)
{
/* These #if tests have the effect of skipping the arguments
* if SAVE support is unavailable - we can't do a useful test
* 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];
memcpy(name, chunk_info[chunk].name, 5);
png_set_keep_unknown_chunks(d->png_ptr, option, name, 1);
chunk_info[chunk].keep = option;
# endif
continue;
}
break;
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;
continue;
}
break;
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;
for (chunk = 0; chunk < NINFO; ++chunk)
if (chunk_info[chunk].all)
chunk_info[chunk].keep = option;
# endif
continue;
}
break;
default: /* some misplaced = */
break;
}
}
fprintf(stderr, "%s(%s): %s: unrecognized chunk argument\n", d->file,
d->test, argv[i]);
display_exit(d);
}
png_read_info(d->png_ptr, d->info_ptr);
switch (png_get_interlace_type(d->png_ptr, d->info_ptr))
{
case PNG_INTERLACE_NONE:
npasses = 1;
break;
case PNG_INTERLACE_ADAM7:
npasses = PNG_INTERLACE_ADAM7_PASSES;
break;
default:
/* Hard error because it is not test specific */
fprintf(stderr, "%s(%s): invalid interlace type\n", d->file, d->test);
clean_display(d);
exit(1);
}
/* Skip the image data, if IDAT is not being handled then don't do this
* because it will cause a CRC error.
*/
if (chunk_info[0/*IDAT*/].keep == PNG_HANDLE_CHUNK_AS_DEFAULT)
{
png_start_read_image(d->png_ptr);
height = png_get_image_height(d->png_ptr, d->info_ptr);
if (npasses > 1)
{
png_uint_32 width = png_get_image_width(d->png_ptr, d->info_ptr);
for (ipass=0; ipass<npasses; ++ipass)
{
png_uint_32 wPass = PNG_PASS_COLS(width, ipass);
if (wPass > 0)
{
png_uint_32 y;
for (y=0; y<height; ++y) if (PNG_ROW_IN_INTERLACE_PASS(y, ipass))
png_read_row(d->png_ptr, NULL, NULL);
}
}
} /* interlaced */
else /* not interlaced */
{
png_uint_32 y;
for (y=0; y<height; ++y)
png_read_row(d->png_ptr, NULL, NULL);
}
}
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);
/* 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);
clean_display(d);
return def;
}
static void
check_error(display *d, png_uint_32 flags, const char *message)
{
while (flags)
{
png_uint_32 flag = flags & -(png_int_32)flags;
int i = find_by_flag(flag);
fprintf(stderr, "%s(%s): chunk %s: %s\n", d->file, d->test,
chunk_info[i].name, message);
++(d->error_count);
flags &= ~flag;
}
}
static void
check_handling(display *d, int def, png_uint_32 chunks, png_uint_32 known,
png_uint_32 unknown, const char *position)
{
while (chunks)
{
png_uint_32 flag = chunks & -(png_int_32)chunks;
int i = find_by_flag(flag);
int keep = chunk_info[i].keep;
const char *type;
const char *errorx = NULL;
if (chunk_info[i].unknown)
{
if (keep == PNG_HANDLE_CHUNK_AS_DEFAULT)
{
type = "UNKNOWN (default)";
keep = def;
}
else
type = "UNKNOWN (specified)";
if (flag & known)
errorx = "chunk processed";
else switch (keep)
{
case PNG_HANDLE_CHUNK_AS_DEFAULT:
if (flag & unknown)
errorx = "DEFAULT: unknown chunk saved";
break;
case PNG_HANDLE_CHUNK_NEVER:
if (flag & unknown)
errorx = "DISCARD: unknown chunk saved";
break;
case PNG_HANDLE_CHUNK_IF_SAFE:
if (ancillary(chunk_info[i].name))
{
if (!(flag & unknown))
errorx = "IF-SAFE: unknown ancillary chunk lost";
}
else if (flag & unknown)
errorx = "IF-SAFE: unknown critical chunk saved";
break;
case PNG_HANDLE_CHUNK_ALWAYS:
if (!(flag & unknown))
errorx = "SAVE: unknown chunk lost";
break;
default:
errorx = "internal error: bad keep";
break;
}
} /* unknown chunk */
else /* known chunk */
{
type = "KNOWN";
if (flag & known)
{
/* chunk was processed, it won't have been saved because that is
* caught below when checking for inconsistent processing.
*/
if (keep != PNG_HANDLE_CHUNK_AS_DEFAULT)
errorx = "!DEFAULT: known chunk processed";
}
else /* not processed */ switch (keep)
{
case PNG_HANDLE_CHUNK_AS_DEFAULT:
errorx = "DEFAULT: known chunk not processed";
break;
case PNG_HANDLE_CHUNK_NEVER:
if (flag & unknown)
errorx = "DISCARD: known chunk saved";
break;
case PNG_HANDLE_CHUNK_IF_SAFE:
if (ancillary(chunk_info[i].name))
{
if (!(flag & unknown))
errorx = "IF-SAFE: known ancillary chunk lost";
}
else if (flag & unknown)
errorx = "IF-SAFE: known critical chunk saved";
break;
case PNG_HANDLE_CHUNK_ALWAYS:
if (!(flag & unknown))
errorx = "SAVE: known chunk lost";
break;
default:
errorx = "internal error: bad keep (2)";
break;
}
}
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);
}
chunks &= ~flag;
}
}
static void
perform_one_test(FILE *fp, int argc, const char **argv,
png_uint_32 *default_flags, display *d)
{
int def;
png_uint_32 flags[2][4];
rewind(fp);
clear_keep();
memcpy(flags[0], default_flags, sizeof flags[0]);
def = check(fp, argc, argv, flags[1], d);
/* 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
* probably change this by swapping the handling after the image, but this
* test does not do that.)
*/
check_error(d, (flags[0][0]|flags[0][2]) & (flags[0][1]|flags[0][3]),
"chunk handled inconsistently in count tests");
check_error(d, (flags[1][0]|flags[1][2]) & (flags[1][1]|flags[1][3]),
"chunk handled inconsistently in option tests");
/* Now find out what happened to each chunk before and after the IDAT and
* determine if the behavior was correct. First some basic sanity checks,
* any known chunk should be known in the original count, any unknown chunk
* should be either known or unknown in the original.
*/
{
png_uint_32 test;
test = flags[1][0] & ~flags[0][0];
check_error(d, test, "new known chunk before IDAT");
test = flags[1][1] & ~(flags[0][0] | flags[0][1]);
check_error(d, test, "new unknown chunk before IDAT");
test = flags[1][2] & ~flags[0][2];
check_error(d, test, "new known chunk after IDAT");
test = flags[1][3] & ~(flags[0][2] | flags[0][3]);
check_error(d, test, "new unknown chunk after IDAT");
}
/* Now each chunk in the original list should have been handled according to
* the options set for that chunk, regardless of whether libpng knows about
* it or not.
*/
check_handling(d, def, flags[0][0] | flags[0][1], flags[1][0], flags[1][1],
"before IDAT");
check_handling(d, def, flags[0][2] | flags[0][3], flags[1][2], flags[1][3],
"after IDAT");
}
static void
perform_one_test_safe(FILE *fp, int argc, const char **argv,
png_uint_32 *default_flags, display *d, const char *test)
{
if (setjmp(d->error_return) == 0)
{
d->test = test; /* allow use of d->error_return */
perform_one_test(fp, argc, argv, default_flags, d);
d->test = init; /* prevent use of d->error_return */
}
}
static const char *standard_tests[] =
{
"discard", "default=discard", 0,
"save", "default=save", 0,
"if-safe", "default=if-safe", 0,
"vpAg", "vpAg=if-safe", 0,
"sTER", "sTER=if-safe", 0,
"IDAT", "default=discard", "IDAT=save", 0,
"sAPI", "bKGD=save", "cHRM=save", "gAMA=save", "all=discard", "iCCP=save",
"sBIT=save", "sRGB=save", 0,
0/*end*/
};
static PNG_NORETURN void
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);
}
int
main(int argc, const char **argv)
{
FILE *fp;
png_uint_32 default_flags[4/*valid,unknown{before,after}*/];
int strict = 0, default_tests = 0;
const char *count_argv = "default=save";
const char *touch_file = NULL;
display d;
init_display(&d, argv[0]);
while (++argv, --argc > 0)
{
if (strcmp(*argv, "--strict") == 0)
strict = 1;
else if (strcmp(*argv, "--default") == 0)
default_tests = 1;
else if (strcmp(*argv, "--touch") == 0)
{
if (argc > 1)
touch_file = *++argv, --argc;
else
usage(d.program, "--touch: missing file name");
}
else
break;
}
/* A file name is required, but there should be no other arguments if
* --default was specified.
*/
if (argc <= 0)
usage(d.program, "missing test file");
/* GCC BUG: if (default_tests && argc != 1) triggers some weird GCC argc
* optimization which causes warnings with -Wstrict-overflow!
*/
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];
fp = fopen(d.file, "rb");
if (fp == NULL)
{
perror(d.file);
exit(2);
}
/* First find all the chunks, known and unknown, in the test file, a failure
* here aborts the whole test.
*/
if (check(fp, 1, &count_argv, default_flags, &d) !=
PNG_HANDLE_CHUNK_ALWAYS)
{
fprintf(stderr, "%s: %s: internal error\n", d.program, d.file);
exit(3);
}
/* 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);
d.test = init;
}
else
{
const char **test = standard_tests;
/* Set the exit_test pointer here so we can continue after a libpng error.
* NOTE: this leaks memory because the png_struct data from the failing
* test is never freed.
*/
while (*test)
{
const char *this_test = *test++;
const char **next = test;
int count = display_rc(&d, strict), new_count;
const char *result;
int arg_count = 0;
while (*next) ++next, ++arg_count;
perform_one_test_safe(fp, arg_count, test, default_flags, &d,
this_test);
new_count = display_rc(&d, strict);
if (new_count == count)
result = "PASS";
else
result = "FAIL";
printf("%s: %s %s\n", result, d.program, this_test);
test = next+1;
}
}
fclose(fp);
if (display_rc(&d, strict) == 0)
{
/* Success, touch the success file if appropriate */
if (touch_file != NULL)
{
FILE *fsuccess = fopen(touch_file, "wt");
if (fsuccess != NULL)
{
int err = 0;
fprintf(fsuccess, "PNG unknown tests succeeded\n");
fflush(fsuccess);
err = ferror(fsuccess);
if (fclose(fsuccess) || err)
{
fprintf(stderr, "%s: write failed\n", touch_file);
exit(1);
}
}
else
{
fprintf(stderr, "%s: open failed\n", touch_file);
exit(1);
}
}
return 0;
}
return 1;
}
#else
int
main(void)
{
fprintf(stderr,
" test ignored because libpng was not built with unknown chunk support\n");
return 0;
}
#endif

View File

@@ -24,7 +24,6 @@
#define _GNU_SOURCE 1 /* For the floating point exception extension */
#include <signal.h>
#include <stdio.h>
#if (defined HAVE_CONFIG_H) && !(defined PNG_NO_CONFIG_H)
# include <config.h>
@@ -43,8 +42,6 @@
# include "../../png.h"
#endif
#ifdef PNG_WRITE_SUPPORTED /* else pngvalid can do nothing */
#if PNG_LIBPNG_VER < 10500
/* This deliberately lacks the PNG_CONST. */
typedef png_byte *png_const_bytep;
@@ -85,10 +82,10 @@ typedef png_byte *png_const_bytep;
/* 1.6.0 constifies many APIs, the following exists to allow pngvalid to be
* compiled against earlier versions.
*/
# define png_const_structp png_structp
# define png_const_strutp png_structp
#endif
#include <zlib.h> /* For crc32 */
#include "zlib.h" /* For crc32 */
#include <float.h> /* For floating point constants */
#include <stdlib.h> /* For malloc */
@@ -173,7 +170,6 @@ static PNG_CONST char *colour_types[8] =
"grayscale with alpha", invalid, "truecolour with alpha", invalid
};
#ifdef PNG_READ_SUPPORTED
/* Convert a double precision value to fixed point. */
static png_fixed_point
fix(double d)
@@ -181,7 +177,6 @@ fix(double d)
d = floor(d * PNG_FP_1 + .5);
return (png_fixed_point)d;
}
#endif /* PNG_READ_SUPPORTED */
/* 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
@@ -220,7 +215,6 @@ make_four_random_bytes(png_uint_32* seed, png_bytep bytes)
make_random_bytes(seed, bytes, 4);
}
#ifdef PNG_READ_SUPPORTED
static void
randomize(void *pv, size_t size)
{
@@ -249,7 +243,6 @@ random_choice(void)
return x & 1;
}
#endif /* PNG_READ_SUPPORTED */
/* A numeric ID based on PNG file characteristics. The 'do_interlace' field
* simply records whether pngvalid did the interlace itself or whether it
@@ -262,7 +255,7 @@ random_choice(void)
#define COL_FROM_ID(id) ((png_byte)((id)& 0x7U))
#define DEPTH_FROM_ID(id) ((png_byte)(((id) >> 3) & 0x1fU))
#define PALETTE_FROM_ID(id) (((id) >> 8) & 0x1f)
#define PALETTE_FROM_ID(id) ((int)(((id) >> 8) & 0x1f))
#define INTERLACE_FROM_ID(id) ((int)(((id) >> 13) & 0x3))
#define DO_INTERLACE_FROM_ID(id) ((int)(((id)>>15) & 1))
#define WIDTH_FROM_ID(id) (((id)>>16) & 0xff)
@@ -271,7 +264,7 @@ random_choice(void)
/* Utility to construct a standard name for a standard image. */
static size_t
standard_name(char *buffer, size_t bufsize, size_t pos, png_byte colour_type,
int bit_depth, unsigned int npalette, int interlace_type,
int bit_depth, int npalette, int interlace_type,
png_uint_32 w, png_uint_32 h, int do_interlace)
{
pos = safecat(buffer, bufsize, pos, colour_types[colour_type]);
@@ -333,11 +326,10 @@ standard_name_from_id(char *buffer, size_t bufsize, size_t pos, png_uint_32 id)
/* The following defines the number of different palettes to generate for
* each log bit depth of a colour type 3 standard image.
*/
#define PALETTE_COUNT(bit_depth) ((bit_depth) > 4 ? 1U : 16U)
#define PALETTE_COUNT(bit_depth) ((bit_depth) > 4 ? 1 : 16)
static int
next_format(png_bytep colour_type, png_bytep bit_depth,
unsigned int* palette_number)
next_format(png_bytep colour_type, png_bytep bit_depth, int* palette_number)
{
if (*bit_depth == 0)
{
@@ -468,7 +460,6 @@ pixel_copy(png_bytep toBuffer, png_uint_32 toIndex,
memmove(toBuffer+(toIndex>>3), fromBuffer+(fromIndex>>3), pixelSize>>3);
}
#ifdef PNG_READ_SUPPORTED
/* Copy a complete row of pixels, taking into account potential partial
* bytes at the end.
*/
@@ -534,7 +525,6 @@ pixel_cmp(png_const_bytep pa, png_const_bytep pb, png_uint_32 bit_width)
return 1+where;
}
}
#endif /* PNG_READ_SUPPORTED */
/*************************** BASIC PNG FILE WRITING ***************************/
/* A png_store takes data from the sequential writer or provides data
@@ -645,7 +635,6 @@ store_pool_mark(png_bytep mark)
make_four_random_bytes(store_seed, mark);
}
#ifdef PNG_READ_SUPPORTED
/* Use this for random 32 bit values; this function makes sure the result is
* non-zero.
*/
@@ -665,7 +654,6 @@ random_32(void)
return result;
}
}
#endif /* PNG_READ_SUPPORTED */
static void
store_pool_init(png_store *ps, store_pool *pool)
@@ -871,7 +859,6 @@ store_log(png_store* ps, png_const_structp pp, png_const_charp message,
store_verbose(ps, pp, is_error ? "error: " : "warning: ", message);
}
#ifdef PNG_READ_SUPPORTED
/* Internal error function, called with a png_store but no libpng stuff. */
static void
internal_error(png_store *ps, png_const_charp message)
@@ -884,7 +871,6 @@ internal_error(png_store *ps, png_const_charp message)
Throw ps;
}
}
#endif /* PNG_READ_SUPPORTED */
/* Functions to use as PNG callbacks. */
static void
@@ -1022,7 +1008,6 @@ store_ensure_image(png_store *ps, png_const_structp pp, int nImages,
}
}
#ifdef PNG_READ_SUPPORTED
static void
store_image_check(PNG_CONST png_store* ps, png_const_structp pp, int iImage)
{
@@ -1052,7 +1037,6 @@ store_image_check(PNG_CONST png_store* ps, png_const_structp pp, int iImage)
}
}
}
#endif /* PNG_READ_SUPPORTED */
static void
store_write(png_structp ppIn, png_bytep pb, png_size_t st)
@@ -1088,7 +1072,6 @@ store_flush(png_structp ppIn)
UNUSED(ppIn) /*DOES NOTHING*/
}
#ifdef PNG_READ_SUPPORTED
static size_t
store_read_buffer_size(png_store *ps)
{
@@ -1206,7 +1189,6 @@ store_progressive_read(png_store *ps, png_structp pp, png_infop pi)
}
while (store_read_buffer_next(ps));
}
#endif /* PNG_READ_SUPPORTED */
/* The caller must fill this in: */
static store_palette_entry *
@@ -1233,7 +1215,6 @@ store_write_palette(png_store *ps, int npalette)
return ps->palette;
}
#ifdef PNG_READ_SUPPORTED
static store_palette_entry *
store_current_palette(png_store *ps, int *npalette)
{
@@ -1247,7 +1228,6 @@ store_current_palette(png_store *ps, int *npalette)
*npalette = ps->current->npalette;
return ps->current->palette;
}
#endif /* PNG_READ_SUPPORTED */
/***************************** MEMORY MANAGEMENT*** ***************************/
/* A store_memory is simply the header for an allocated block of memory. The
@@ -1522,29 +1502,25 @@ set_store_for_write(png_store *ps, png_infopp ppi,
}
/* Cleanup when finished reading (either due to error or in the success case).
* This routine exists even when there is no read support to make the code
* tidier (avoid a mass of ifdefs) and so easier to maintain.
*/
static void
store_read_reset(png_store *ps)
{
# ifdef PNG_READ_SUPPORTED
if (ps->pread != NULL)
if (ps->pread != NULL)
{
anon_context(ps);
Try
png_destroy_read_struct(&ps->pread, &ps->piread, NULL);
Catch_anonymous
{
anon_context(ps);
Try
png_destroy_read_struct(&ps->pread, &ps->piread, NULL);
Catch_anonymous
{
/* error already output: continue */
}
ps->pread = NULL;
ps->piread = NULL;
/* error already output: continue */
}
# endif
ps->pread = NULL;
ps->piread = NULL;
}
/* Always do this to be safe. */
store_pool_delete(ps, &ps->read_memory_pool);
@@ -1555,7 +1531,6 @@ store_read_reset(png_store *ps)
ps->validated = 0;
}
#ifdef PNG_READ_SUPPORTED
static void
store_read_set(png_store *ps, png_uint_32 id)
{
@@ -1633,7 +1608,6 @@ set_store_for_read(png_store *ps, png_infopp ppi, png_uint_32 id,
return ps->pread;
}
#endif /* PNG_READ_SUPPORTED */
/* The overall cleanup of a store simply calls the above then removes all the
* saved files. This does not delete the store itself.
@@ -1673,19 +1647,6 @@ typedef struct CIE_color
double X, Y, Z;
} CIE_color;
typedef struct color_encoding
{
/* A description of an (R,G,B) encoding of color (as defined above); this
* includes the actual colors of the (R,G,B) triples (1,0,0), (0,1,0) and
* (0,0,1) plus an encoding value that is used to encode the linear
* components R, G and B to give the actual values R^gamma, G^gamma and
* B^gamma that are stored.
*/
double gamma; /* Encoding (file) gamma of space */
CIE_color red, green, blue; /* End points */
} color_encoding;
#ifdef PNG_READ_SUPPORTED
static double
chromaticity_x(CIE_color c)
{
@@ -1698,6 +1659,18 @@ chromaticity_y(CIE_color c)
return c.Y / (c.X + c.Y + c.Z);
}
typedef struct color_encoding
{
/* A description of an (R,G,B) encoding of color (as defined above); this
* includes the actual colors of the (R,G,B) triples (1,0,0), (0,1,0) and
* (0,0,1) plus an encoding value that is used to encode the linear
* components R, G and B to give the actual values R^gamma, G^gamma and
* B^gamma that are stored.
*/
double gamma; /* Encoding (file) gamma of space */
CIE_color red, green, blue; /* End points */
} color_encoding;
static CIE_color
white_point(PNG_CONST color_encoding *encoding)
{
@@ -1769,7 +1742,6 @@ safecat_color_encoding(char *buffer, size_t bufsize, size_t pos,
return pos;
}
#endif /* PNG_READ_SUPPORTED */
typedef struct png_modifier
{
@@ -3148,7 +3120,6 @@ transform_height(png_const_structp pp, png_byte colour_type, png_byte bit_depth)
}
}
#ifdef PNG_READ_SUPPORTED
/* The following can only be defined here, now we have the definitions
* of the transform image sizes.
*/
@@ -3184,7 +3155,6 @@ standard_rowsize(png_const_structp pp, png_uint_32 id)
width *= bit_size(pp, COL_FROM_ID(id), DEPTH_FROM_ID(id));
return (width + 7) / 8;
}
#endif /* PNG_READ_SUPPORTED */
static void
transform_row(png_const_structp pp, png_byte buffer[TRANSFORM_ROWMAX],
@@ -3312,8 +3282,8 @@ transform_row(png_const_structp pp, png_byte buffer[TRANSFORM_ROWMAX],
*/
static void
make_transform_image(png_store* PNG_CONST ps, png_byte PNG_CONST colour_type,
png_byte PNG_CONST bit_depth, unsigned int palette_number,
int interlace_type, png_const_charp name)
png_byte PNG_CONST bit_depth, int palette_number, int interlace_type,
png_const_charp name)
{
context(ps, fault);
@@ -3337,11 +3307,6 @@ make_transform_image(png_store* PNG_CONST ps, png_byte PNG_CONST colour_type,
PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
#ifdef PNG_TEXT_SUPPORTED
# if (defined PNG_READ_zTXt_SUPPORTED) && (defined PNG_WRITE_zTXt_SUPPORTED)
# define TEXT_COMPRESSION PNG_TEXT_COMPRESSION_zTXt
# else
# define TEXT_COMPRESSION PNG_TEXT_COMPRESSION_NONE
# endif
{
static char key[] = "image name"; /* must be writeable */
size_t pos;
@@ -3351,7 +3316,7 @@ make_transform_image(png_store* PNG_CONST ps, png_byte PNG_CONST colour_type,
/* Use a compressed text string to test the correct interaction of text
* compression and IDAT compression.
*/
text.compression = TEXT_COMPRESSION;
text.compression = PNG_TEXT_COMPRESSION_zTXt;
text.key = key;
/* Yuck: the text must be writable! */
pos = safecat(copy, sizeof copy, 0, ps->wname);
@@ -3409,7 +3374,7 @@ make_transform_image(png_store* PNG_CONST ps, png_byte PNG_CONST colour_type,
/* Use a compressed text string to test the correct interaction of text
* compression and IDAT compression.
*/
text.compression = TEXT_COMPRESSION;
text.compression = PNG_TEXT_COMPRESSION_zTXt;
text.key = key;
text.text = comment;
text.text_length = (sizeof comment)-1;
@@ -3445,7 +3410,7 @@ make_transform_images(png_store *ps)
{
png_byte colour_type = 0;
png_byte bit_depth = 0;
unsigned int palette_number = 0;
int palette_number = 0;
/* This is in case of errors. */
safecat(ps->test, sizeof ps->test, 0, "make standard images");
@@ -3493,7 +3458,6 @@ interlace_row(png_bytep buffer, png_const_bytep imageRow,
}
}
#ifdef PNG_READ_SUPPORTED
static void
deinterlace_row(png_bytep buffer, png_const_bytep row,
unsigned int pixel_size, png_uint_32 w, int pass)
@@ -3514,7 +3478,6 @@ deinterlace_row(png_bytep buffer, png_const_bytep row,
++xin;
}
}
#endif /* PNG_READ_SUPPORTED */
/* Build a single row for the 'size' test images; this fills in only the
* first bit_width bits of the sample row.
@@ -3582,7 +3545,7 @@ make_size_image(png_store* PNG_CONST ps, png_byte PNG_CONST colour_type,
/* Use a compressed text string to test the correct interaction of text
* compression and IDAT compression.
*/
text.compression = TEXT_COMPRESSION;
text.compression = PNG_TEXT_COMPRESSION_zTXt;
text.key = key;
/* Yuck: the text must be writable! */
pos = safecat(copy, sizeof copy, 0, ps->wname);
@@ -3682,7 +3645,7 @@ make_size_image(png_store* PNG_CONST ps, png_byte PNG_CONST colour_type,
/* Use a compressed text string to test the correct interaction of text
* compression and IDAT compression.
*/
text.compression = TEXT_COMPRESSION;
text.compression = PNG_TEXT_COMPRESSION_zTXt;
text.key = key;
text.text = comment;
text.text_length = (sizeof comment)-1;
@@ -3758,7 +3721,6 @@ make_size_images(png_store *ps)
make_size(ps, 6, 3, WRITE_BDHI);
}
#ifdef PNG_READ_SUPPORTED
/* Return a row based on image id and 'y' for checking: */
static void
standard_row(png_const_structp pp, png_byte std[STANDARD_ROWMAX],
@@ -3770,7 +3732,6 @@ standard_row(png_const_structp pp, png_byte std[STANDARD_ROWMAX],
size_row(std, WIDTH_FROM_ID(id) * bit_size(pp, COL_FROM_ID(id),
DEPTH_FROM_ID(id)), y);
}
#endif /* PNG_READ_SUPPORTED */
/* Tests - individual test cases */
/* Like 'make_standard' but errors are deliberately introduced into the calls
@@ -4055,7 +4016,6 @@ perform_formatting_test(png_store *volatile ps)
#endif
}
#ifdef PNG_READ_SUPPORTED
/* Because we want to use the same code in both the progressive reader and the
* sequential reader it is necessary to deal with the fact that the progressive
* reader callbacks only have one parameter (png_get_progressive_ptr()), so this
@@ -4663,11 +4623,11 @@ standard_check_text(png_const_structp pp, png_const_textp tp,
pos = safecat(msg, sizeof msg, pos, ": ");
ok = pos;
if (tp->compression != TEXT_COMPRESSION)
if (tp->compression != PNG_TEXT_COMPRESSION_zTXt)
{
char buf[64];
sprintf(buf, "compression [%d->%d], ", TEXT_COMPRESSION,
sprintf(buf, "compression [%d->%d], ", PNG_TEXT_COMPRESSION_zTXt,
tp->compression);
pos = safecat(msg, sizeof msg, pos, buf);
}
@@ -4710,21 +4670,21 @@ standard_check_text(png_const_structp pp, png_const_textp tp,
if (tp->itxt_length != 0)
pos = safecat(msg, sizeof msg, pos, "iTXt length set, ");
if (tp->lang != NULL)
{
pos = safecat(msg, sizeof msg, pos, "iTXt language \"");
pos = safecat(msg, sizeof msg, pos, tp->lang);
pos = safecat(msg, sizeof msg, pos, "\", ");
}
if (tp->lang_key != NULL)
{
pos = safecat(msg, sizeof msg, pos, "iTXt keyword \"");
pos = safecat(msg, sizeof msg, pos, tp->lang_key);
pos = safecat(msg, sizeof msg, pos, "\", ");
}
if (pos > ok)
{
msg[pos-2] = '\0'; /* Remove the ", " at the end */
@@ -7323,7 +7283,7 @@ perform_transform_test(png_modifier *pm)
{
png_byte colour_type = 0;
png_byte bit_depth = 0;
unsigned int palette_number = 0;
int palette_number = 0;
while (next_format(&colour_type, &bit_depth, &palette_number))
{
@@ -8685,7 +8645,7 @@ perform_gamma_threshold_tests(png_modifier *pm)
{
png_byte colour_type = 0;
png_byte bit_depth = 0;
unsigned int palette_number = 0;
int palette_number = 0;
/* Don't test more than one instance of each palette - it's pointless, in
* fact this test is somewhat excessive since libpng doesn't make this
@@ -8750,7 +8710,7 @@ static void perform_gamma_transform_tests(png_modifier *pm)
{
png_byte colour_type = 0;
png_byte bit_depth = 0;
unsigned int palette_number = 0;
int palette_number = 0;
while (next_format(&colour_type, &bit_depth, &palette_number))
{
@@ -8779,8 +8739,11 @@ static void perform_gamma_sbit_tests(png_modifier *pm)
*/
for (sbit=pm->sbitlow; sbit<(1<<READ_BDHI); ++sbit)
{
png_byte colour_type = 0, bit_depth = 0;
unsigned int npalette = 0;
png_byte colour_type, bit_depth;
int npalette;
colour_type = bit_depth = 0;
npalette = 0;
while (next_format(&colour_type, &bit_depth, &npalette))
if ((colour_type & PNG_COLOR_MASK_ALPHA) == 0 &&
@@ -8996,7 +8959,7 @@ perform_gamma_composition_tests(png_modifier *pm, int do_background,
{
png_byte colour_type = 0;
png_byte bit_depth = 0;
unsigned int palette_number = 0;
int palette_number = 0;
/* Skip the non-alpha cases - there is no setting of a transparency colour at
* present.
@@ -9176,7 +9139,6 @@ perform_gamma_test(png_modifier *pm, int summary)
#endif
}
#endif /* PNG_READ_GAMMA_SUPPORTED */
#endif /* PNG_READ_SUPPORTED */
/* INTERLACE MACRO VALIDATION */
/* This is copied verbatim from the specification, it is simply the pass
@@ -9985,9 +9947,7 @@ int main(int argc, char **argv)
{
perform_interlace_macro_validation();
perform_formatting_test(&pm.this);
# ifdef PNG_READ_SUPPORTED
perform_standard_test(&pm);
# endif
perform_standard_test(&pm);
perform_error_test(&pm);
}
@@ -9995,9 +9955,7 @@ int main(int argc, char **argv)
if (pm.test_size)
{
make_size_images(&pm.this);
# ifdef PNG_READ_SUPPORTED
perform_size_test(&pm);
# endif
perform_size_test(&pm);
}
#ifdef PNG_READ_TRANSFORMS_SUPPORTED
@@ -10090,20 +10048,7 @@ int main(int argc, char **argv)
exit(1);
}
}
else
{
fprintf(stderr, "%s: open failed\n", touch);
exit(1);
}
}
return 0;
}
#else /* write not supported */
int main(void)
{
fprintf(stderr, "pngvalid: no write support in libpng, all tests skipped\n");
return 0;
}
#endif

View File

@@ -195,7 +195,7 @@ int validation_ascii_to_fp(int count, int argc, char **argv)
* code above is not optimized and may drift outside the .5 in
* DBL_DIG allowed. In any case a small number of errors may
* occur (very small ones - 1 or 2%) because of rounding in the
* calculations, either in the conversion API or in atof.
* calculations, either in the convertion API or in atof.
*/
if (change >= allow && (isfinite(out) ||
fabs(test/DBL_MAX) <= 1-allow))
@@ -942,7 +942,7 @@ int validation_gamma(int argc, char **argv)
/* Various validation routines are included herein, they require some
* definition for png_warning and png_error, seetings of VALIDATION:
*
* 1: validates the ASCII to floating point conversions
* 1: validates the ASCII to floating point convertions
* 2: validates png_muldiv
* 3: accuracy test of fixed point gamma tables
*/

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

@@ -14,7 +14,7 @@ LD=$(CC)
RM=rm -f
COPY=cp
CFLAGS=-DPNG_USER_CONFIG -DNO_GZCOMPRESS -DZ_SOLO -DNO_GZIP -I. -O1
CFLAGS=-DPNG_USER_CONFIG -DNO_GZCOMPRESS -DNO_GZIP -I. -O1
C=.c
O=.o

View File

@@ -14,7 +14,7 @@ LD=$(CC)
RM=rm -f
COPY=cp
CFLAGS=-DPNG_USER_CONFIG -DZ_SOLO -DNO_GZIP -I. -O1
CFLAGS=-DPNG_USER_CONFIG -DNO_GZIP -I. -O1
C=.c
O=.o

View File

@@ -30,7 +30,7 @@ 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
CFLAGS=-DPNG_USER_CONFIG -DNO_GZCOMPRESS -DNO_GZIP -I. $(XINC) -O1
C=.c
O=.o

View File

@@ -48,8 +48,7 @@ int main(int argc, const char **argv)
png_image image; /* The control structure used by libpng */
/* Initialize the 'png_image' structure. */
memset(&image, 0, (sizeof image));
image.version = PNG_IMAGE_VERSION;
memset(&image, 0, sizeof image);
/* The first argument is the file to read: */
if (png_image_begin_read_from_file(&image, argv[1]))
@@ -76,28 +75,16 @@ int main(int argc, const char **argv)
* be supplied or the output buffer would have to be initialized to the
* actual background of the image.
*
* The fourth argument to png_image_finish_read is the 'row_stride' -
* The final argument to png_image_finish_read is the 'row_stride' -
* this is the number of components allocated for the image in each
* row. It has to be at least as big as the value returned by
* PNG_IMAGE_ROW_STRIDE, but if you just allocate space for the
* default, minimum, size using PNG_IMAGE_SIZE as above you can pass
* zero.
*
* The final argument is a pointer to a buffer for the colormap;
* colormaps have exactly the same format as a row of image pixels (so
* you choose what format to make the colormap by setting
* image.format). A colormap is only returned if
* PNG_FORMAT_FLAG_COLORMAP is also set in image.format, so in this
* case NULL is passed as the final argument. If you do want to force
* all images into an index/color-mapped format then you can use:
*
* PNG_IMAGE_COLORMAP_SIZE(image)
*
* to find the maximum size of the colormap in bytes.
*/
if (buffer != NULL &&
png_image_finish_read(&image, NULL/*background*/, buffer,
0/*row_stride*/, NULL/*colormap*/))
0/*row_stride*/))
{
/* Now write the image out to the second argument. In the write
* call 'convert_to_8bit' allows 16-bit data to be squashed down to
@@ -105,7 +92,7 @@ int main(int argc, const char **argv)
* to the 8-bit format.
*/
if (png_image_write_to_file(&image, argv[2], 0/*convert_to_8bit*/,
buffer, 0/*row_stride*/, NULL/*colormap*/))
buffer, 0/*row_stride*/))
{
/* The image has been written successfully. */
exit(0);
@@ -846,7 +833,7 @@ void write_png(char *file_name /* , ... other image information ... */)
/* Set the palette if there is one. REQUIRED for indexed-color images */
palette = (png_colorp)png_malloc(png_ptr, PNG_MAX_PALETTE_LENGTH
* (sizeof (png_color)));
* png_sizeof(png_color));
/* ... Set palette colors ... */
png_set_PLTE(png_ptr, info_ptr, palette, PNG_MAX_PALETTE_LENGTH);
/* You must not free palette here, because png_set_PLTE only makes a link to
@@ -981,16 +968,12 @@ void write_png(char *file_name /* , ... other image information ... */)
* use the first method if you aren't handling interlacing yourself.
*/
png_uint_32 k, height, width;
/* In this example, "image" is a one-dimensional array of bytes */
png_byte image[height*width*bytes_per_pixel];
png_byte image[height][width*bytes_per_pixel];
png_bytep row_pointers[height];
if (height > PNG_UINT_32_MAX/(sizeof (png_bytep)))
if (height > PNG_UINT_32_MAX/png_sizeof(png_bytep))
png_error (png_ptr, "Image is too tall to process in memory");
/* Set up pointers into your "image" byte array */
for (k = 0; k < height; k++)
row_pointers[k] = image + k*width*bytes_per_pixel;

View File

@@ -1,6 +1,6 @@
libpng-manual.txt - A description on how to use and modify libpng
libpng version 1.6.0beta30 - October 24, 2012
libpng version 1.6.0beta20 - March 29, 2012
Updated and distributed by Glenn Randers-Pehrson
<glennrp at users.sourceforge.net>
Copyright (c) 1998-2011 Glenn Randers-Pehrson
@@ -11,7 +11,7 @@ libpng-manual.txt - A description on how to use and modify libpng
Based on:
libpng versions 0.97, January 1998, through 1.6.0beta30 - October 24, 2012
libpng versions 0.97, January 1998, through 1.6.0beta20 - March 29, 2012
Updated and distributed by Glenn Randers-Pehrson
Copyright (c) 1998-2011 Glenn Randers-Pehrson
@@ -67,7 +67,7 @@ of reducing the amount of time and effort it takes to support the PNG
file format in application programs.
The PNG specification (second edition), November 2003, is available as
a W3C Recommendation and as an ISO Standard (ISO/IEC 15948:2004 (E)) at
a W3C Recommendation and as an ISO Standard (ISO/IEC 15948:2003 (E)) at
<http://www.w3.org/TR/2003/REC-PNG-20031110/
The W3C and ISO documents have identical technical content.
@@ -160,8 +160,8 @@ APIs. Most of these are fairly obvious; for example types corresponding
to integers of particular sizes and types for passing color values.
One exception is how non-integral numbers are handled. For application
convenience most APIs that take such numbers have C (double) arguments;
however, internally PNG, and libpng, use 32 bit signed integers and encode
convenience most APIs that take such numbers have C (double) arguments,
however internally PNG, and libpng, use 32 bit signed integers and encode
the value by multiplying by 100,000. As of libpng 1.5.0 a convenience
macro PNG_FP_1 is defined in png.h along with a type (png_fixed_point)
which is simply (png_int_32).
@@ -572,7 +572,6 @@ chunk types. To change this, you can call:
png_set_keep_unknown_chunks(png_ptr, keep,
chunk_list, num_chunks);
keep - 0: default unknown chunk handling
1: ignore; do not keep
2: keep only if safe-to-copy
@@ -586,16 +585,11 @@ chunk types. To change this, you can call:
chunk_list - list of chunks affected (a byte string,
five bytes per chunk, NULL or '\0' if
num_chunks is positive; ignored if
numchunks <= 0).
num_chunks is 0)
num_chunks - number of chunks affected; if 0, all
unknown chunks are affected. If positive,
only the chunks in the list are affected,
and if negative all unknown chunks and
all known chunks except for the IHDR,
PLTE, tRNS, IDAT, and IEND chunks are
affected.
unknown chunks are affected. If nonzero,
only the chunks in the list are affected
Unknown chunks declared in this way will be saved as raw data onto a
list of png_unknown_chunk structures. If a chunk that is normally
@@ -828,7 +822,7 @@ the screen_gamma value. Pixels with alpha less than 1.0
will still have linear components.
Use this format if you have control over your
compositing software and so don't do other arithmetic
compositing software and do don't do other arithmetic
(such as scaling) on the data you get from libpng. Your
compositing software can simply copy opaque pixels to
the output but still has linear values for the
@@ -1159,15 +1153,6 @@ data has been read, or zero if it is missing. The parameters to the
png_get_<chunk> are set directly if they are simple data types, or a
pointer into the info_ptr is returned for any complex types.
The colorspace data from gAMA, cHRM, sRGB, iCCP, and sBIT chunks
is simply returned to give the application information about how the
image was encoded. Libpng itself only does transformations using the file
gamma when combining semitransparent pixels with the background color, and,
since libpng-1.6.0, when converting between 8-bit sRGB and 16-bit linear pixels
within the simplified API. Libpng also uses the file gamma when converting
RGB to gray, beginning with libpng-1.0.5, if the application calls
png_set_rgb_to_gray()).
png_get_PLTE(png_ptr, info_ptr, &palette,
&num_palette);
@@ -1779,7 +1764,7 @@ the current display (e.g., the background color from a web page). You
need to tell libpng how the color is represented, both the format of the
component values in the color (the number of bits) and the gamma encoding of the
color. The function takes two arguments, background_gamma_mode and need_expand
to convey this information; however, only two combinations are likely to be
to convey this information, however only two combinations are likely to be
useful:
png_color_16 my_background;
@@ -2073,7 +2058,7 @@ the second parameter NULL.
If you don't want libpng to handle the interlacing details, just call
png_read_rows() PNG_INTERLACE_ADAM7_PASSES times to read in all the images.
Each of the images is a valid image by itself; however, you will almost
Each of the images is a valid image by itself, however you will almost
certainly need to distribute the pixels from each sub-image to the
correct place. This is where everything gets very tricky.
@@ -2230,7 +2215,7 @@ sPLT, only the n'th item in the structure is freed, where n is "seq".
The default behavior is only to free data that was allocated internally
by libpng. This can be changed, so that libpng will not free the data,
or so that it will free data that was allocated by the user with png_malloc()
or png_calloc() and passed in via a png_set_*() function, with
or png_zalloc() and passed in via a png_set_*() function, with
png_data_freer(png_ptr, info_ptr, freer, mask)
@@ -2251,7 +2236,7 @@ or png_destroy_*() is supposed to free the data. When the user assumes
responsibility for libpng-allocated data, the application must use
png_free() to free it, and when the user transfers responsibility to libpng
for data that the user has allocated, the user must have used png_malloc()
or png_calloc() to allocate it.
or png_zalloc() to allocate it.
If you allocated your row_pointers in a single block, as suggested above in
the description of the high level read interface, you must not transfer
@@ -3069,9 +3054,8 @@ 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
a writeable buffer of at least 29 bytes.
png_convert_to_rfc1123(png_timep) is provided to convert from PNG
time to an RFC 1123 format string.
Writing unknown chunks
@@ -3433,7 +3417,7 @@ png_destroy_write_struct().
The default behavior is only to free data that was allocated internally
by libpng. This can be changed, so that libpng will not free the data,
or so that it will free data that was allocated by the user with png_malloc()
or png_calloc() and passed in via a png_set_*() function, with
or png_zalloc() and passed in via a png_set_*() function, with
png_data_freer(png_ptr, info_ptr, freer, mask)
@@ -3469,7 +3453,7 @@ When the user assumes responsibility for libpng-allocated data, the
application must use
png_free() to free it, and when the user transfers responsibility to libpng
for data that the user has allocated, the user must have used png_malloc()
or png_calloc() to allocate it.
or png_zalloc() to allocate it.
If you allocated text_ptr.text, text_ptr.lang, and text_ptr.translated_keyword
separately, do not transfer responsibility for freeing text_ptr to libpng,
@@ -3524,13 +3508,12 @@ png_image is a structure that describes the in-memory format of an image
when it is being read or define the in-memory format of an image that you
need to write. The "png_image" structure contains the following members:
png_uint_32 version Set to PNG_IMAGE_VERSION
png_uint_32 width Image width in pixels (columns)
png_uint_32 height Image height in pixels (rows)
png_uint_32 format Image format as defined below
png_uint_32 flags A bit mask containing informational flags
png_controlp opaque Initialize to NULL, free with png_image_free
png_uint_32 colormap_entries; Number of entries in the color-map
png_const_bytep colormap A pointer to the application color-map
png_uint_32 warning_or_error;
char message[64];
@@ -3690,22 +3673,6 @@ First the information about the samples.
a fixed number determined by the format so can easily be allocated on the
stack if necessary.
#define PNG_IMAGE_MAXIMUM_COLORMAP_COMPONENTS(fmt)\
(PNG_IMAGE_SAMPLE_CHANNELS(fmt) * 256)
/* The maximum size of the color-map required by the format expressed in a
* count of components. This can be used to compile-time allocate a
* color-map:
*
* png_uint_16 colormap[PNG_IMAGE_MAXIMUM_COLORMAP_COMPONENTS(linear_fmt)];
*
* png_byte colormap[PNG_IMAGE_MAXIMUM_COLORMAP_COMPONENTS(sRGB_fmt)];
*
* Alternatively use the PNG_IMAGE_COLORMAP_SIZE macro below to use the
* information from one of the png_image_begin_read_ APIs and dynamically
* allocate the required memory.
*/
Corresponding information about the pixels
PNG_IMAGE_PIXEL_(test,fmt)
@@ -3764,8 +3731,7 @@ READ APIs
The PNG header is read from the given memory buffer.
int png_image_finish_read(png_imagep image,
png_colorp background, void *buffer,
png_int_32 row_stride, void *colormap));
png_colorp background, void *buffer, png_int_32 row_stride));
Finish reading the image into the supplied buffer and
clean up the png_image structure.
@@ -3802,7 +3768,6 @@ WRITE APIS
For write you must initialize a png_image structure to describe the image to
be written:
version: must be set to PNG_IMAGE_VERSION
opaque: must be initialized to NULL
width: image width in pixels
height: image height in rows
@@ -3810,17 +3775,15 @@ be written:
flags: set to 0 unless one of the defined flags applies; set
PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB for color format images
where the RGB values do not correspond to the colors in sRGB.
colormap_entries: set to the number of entries in the color-map (0 to 256)
int png_image_write_to_file, (png_imagep image,
const char *file, int convert_to_8bit, const void *buffer,
png_int_32 row_stride, const void *colormap));
png_int_32 row_stride));
Write the image to the named file.
int png_image_write_to_stdio(png_imagep image, FILE *file,
int convert_to_8_bit, const void *buffer,
png_int_32 row_stride, const void *colormap)
int convert_to_8_bit, const void *buffer, png_int_32 row_stride)
Write the image to the given (FILE*).
@@ -3854,13 +3817,12 @@ in pngmem.c, pngrio.c, pngwio.c, and pngerror.c, respectively. To change
these functions, call the appropriate png_set_*_fn() function.
Memory allocation is done through the functions png_malloc(), png_calloc(),
and png_free(). The png_malloc() and png_free() functions currently just
call the standard C functions and png_calloc() calls png_malloc() and then
clears the newly allocated memory to zero; note that png_calloc(png_ptr, size)
is not the same as the calloc(number, size) function provided by stdlib.h.
There is limited support for certain systems with segmented memory
architectures and the types of pointers declared by png.h match this; you
will have to use appropriate pointers in your application. Since it is
and png_free(). These currently just call the standard C functions.
png_calloc() calls png_malloc() and then clears the newly
allocated memory to zero. There is limited support for certain systems
with segmented memory architectures and the types of pointers declared by
png.h match this; you will have to use appropriate pointers in your
application. Since it is
unlikely that the method of handling memory allocation on a platform
will change between applications, these functions must be modified in
the library at compile time. If you prefer to use a different method
@@ -4090,7 +4052,7 @@ available to set these separately for non-IDAT
compressed chunks such as zTXt, iTXt, and iCCP:
#include zlib.h
#if PNG_LIBPNG_VER >= 10504
#if PNG_LIBPNG_VER <= 10504
png_set_text_compression_level(png_ptr, level);
png_set_text_compression_mem_level(png_ptr, level);
@@ -4538,9 +4500,7 @@ png_set_strip_error_numbers() was removed from the library by default.
The png_zalloc() and png_zfree() functions are no longer exported.
The png_zalloc() function no longer zeroes out the memory that it
allocates. Applications that called png_zalloc(png_ptr, number, size)
can call png_calloc(png_ptr, number*size) instead, and can call
png_free() instead of png_zfree().
allocates.
Support for dithering was disabled by default in libpng-1.4.0, because
it has not been well tested and doesn't actually "dither".
@@ -4573,7 +4533,7 @@ This is enabled by default but can be disabled in each png_ptr with
A. Changes that affect users of libpng
There are no substantial API changes between the non-deprecated parts of
the 1.4.5 API and the 1.5.0 API; however, the ability to directly access
the 1.4.5 API and the 1.5.0 API; however the ability to directly access
members of the main libpng control structures, png_struct and png_info,
deprecated in earlier versions of libpng, has been completely removed from
libpng 1.5.
@@ -4584,12 +4544,9 @@ need access to information in zlib.h will need to add the '#include "zlib.h"'
directive. It does not matter whether this is placed prior to or after
the '"#include png.h"' directive.
The png_sprintf(), png_strcpy(), and png_strncpy() macros are no longer used
and were removed.
We moved the png_strlen(), png_memcpy(), png_memset(), and png_memcmp()
macros into a private header file (pngpriv.h) that is not accessible to
applications.
We moved the png_strcpy(), png_strncpy(), png_strlen(), png_memcpy(),
png_memcmp(), png_sprintf, and png_memcpy() macros into a private
header file (pngpriv.h) that is not accessible by applications.
In png_get_iCCP, the type of "profile" was changed from png_charpp
to png_bytepp, and in png_set_iCCP, from png_charp to png_const_bytep.
@@ -4710,12 +4667,12 @@ B. Changes to the build and configuration of libpng
Details of internal changes to the library code can be found in the CHANGES
file and in the GIT repository logs. These will be of no concern to the vast
majority of library users or builders; however, the few who configure libpng
majority of library users or builders, however the few who configure libpng
to a non-default feature set may need to change how this is done.
There should be no need for library builders to alter build scripts if
these use the distributed build support - configure or the makefiles -
however, users of the makefiles may care to update their build scripts
however users of the makefiles may care to update their build scripts
to build pnglibconf.h where the corresponding makefile does not do so.
Building libpng with a non-default configuration has changed completely.
@@ -4821,7 +4778,7 @@ merely stops the function from being exported.
PNG_FLOATING_ARITHMETIC_SUPPORTED chooses between the internal floating
point implementation or the fixed point one. Typically the fixed point
implementation is larger and slower than the floating point implementation
on a system that supports floating point; however, it may be faster on a
on a system that supports floating point, however it may be faster on a
system which lacks floating point hardware and therefore uses a software
emulation.
@@ -4850,7 +4807,7 @@ pngconf.h no longer includes pngusr.h, therefore pngusr.h is ignored after the
build of pnglibconf.h and it is never included in an application build.
The rarely used alternative of adding a list of feature macros to the
CFLAGS setting in the build also still works; however, the macros will be
CFLAGS setting in the build also still works, however the macros will be
copied to pnglibconf.h and this may produce macro redefinition warnings
when the individual C files are compiled.
@@ -4898,10 +4855,6 @@ The following has been removed:
with png_get_io_chunk_type(). The new
function returns a 32-bit integer instead of
a string.
The png_sizeof(), png_strlen(), png_memcpy(), png_memcmp(), and
png_memset() macros are no longer used in the libpng sources and
have been removed. These had already been made invisible to applications
since libpng-1.5.0.
XIII. Detecting libpng
@@ -5019,21 +4972,10 @@ pngtest) appear in
pngpriv.h
above the comment that says
/* Maintainer: Put new private prototypes here ^ */
We put a space after the "sizeof" operator and we omit the
optional parentheses around its argument when the argument
is an expression, not a type name, and we always enclose the
sizeof operator, with its argument, in parentheses:
(sizeof (png_uint_32))
(sizeof array)
Prior to libpng-1.6.0 we used a "png_sizeof()" macro, formatted as
though it were a function.
/* Maintainer: Put new private prototypes here ^ and in libpngpf.3 */
To avoid polluting the global namespace, the names of all exported
functions and variables begin with "png_", and all publicly visible C
functions and variables begin with "png_", and all publicly visible C
preprocessor macros begin with "PNG". We request that applications that
use libpng *not* begin any of their own symbols with either of these strings.
@@ -5047,15 +4989,12 @@ left parenthesis that follows it:
for (i = 2; i > 0; --i)
y[i] = a(x) + (int)b;
We prefer #ifdef and #ifndef to #if defined() and #if !defined()
We prefer #ifdef and #ifndef to #if defined() and if !defined()
when there is only one macro being tested.
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).
We prefer to use underscores in variable names rather than camelCase, except
for a few type names that we inherit from zlib.h.
We do not use the TAB character for indentation in the C sources.
Lines do not exceed 80 characters.
@@ -5064,25 +5003,25 @@ Other rules can be inferred by inspecting the libpng source.
XVI. Y2K Compliance in libpng
October 24, 2012
March 29, 2012
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.0beta30 are Y2K compliant. It is my belief that earlier
upward through 1.6.0beta20 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
that will hold years up to 65535. The other, which is deprecated,
holds the date in text format, and will hold years up to 9999.
Libpng only has three year fields. One is a 2-byte unsigned integer that
will hold years up to 65535. The other two hold the date in text
format, and will hold years up to 9999.
The integer is
"png_uint_16 year" in png_time_struct.
The string is
"char time_buffer[29]" in png_struct. This is no longer used
in libpng-1.6.x and will be removed from libpng-1.7.0.
The strings are
"png_charp time_buffer" in png_struct and
"near_time_buffer", which is a local character string in png.c.
There are seven time-related functions:

185
libpng.3
View File

@@ -1,6 +1,6 @@
.TH LIBPNG 3 "October 24, 2012"
.TH LIBPNG 3 "March 29, 2012"
.SH NAME
libpng \- Portable Network Graphics (PNG) Reference Library 1.6.0beta30
libpng \- Portable Network Graphics (PNG) Reference Library 1.6.0beta20
.SH SYNOPSIS
\fI\fB
@@ -440,7 +440,7 @@ libpng \- Portable Network Graphics (PNG) Reference Library 1.6.0beta30
\fI\fB
\fBint png_image_finish_read (png_imagep \fP\fIimage\fP\fB, png_colorp \fP\fIbackground\fP\fB, void \fP\fI*buffer\fP\fB, png_int_32 \fP\fIrow_stride\fP\fB, void \fI*colormap\fP\fB);\fP
\fBint png_image_finish_read (png_imagep \fP\fIimage\fP\fB, png_colorp \fP\fIbackground\fP\fB, void \fP\fI*buffer\fP\fB, png_int_32 \fIrow_stride\fP\fB);\fP
\fI\fB
@@ -448,11 +448,13 @@ libpng \- Portable Network Graphics (PNG) Reference Library 1.6.0beta30
\fI\fB
\fBint png_image_write_to_file (png_imagep \fP\fIimage\fP\fB, const char \fP\fI*file\fP\fB, int \fP\fIconvert_to_8bit\fP\fB, const void \fP\fI*buffer\fP\fB, png_int_32 \fP\fIrow_stride\fP\fB, void \fI*colormap\fP\fB);\fP
\fBint png_image_write_to_file (png_imagep \fP\fIimage\fP\fB, const char \fP\fI*file\fP\fB, int \fP\fIconvert_to_8bit\fP\fB, const void \fI*buffer,
\fBpng_int_32 \fIrow_stride\fP\fB);\fP
\fI\fB
\fBint png_image_write_to_stdio (png_imagep \fP\fIimage\fP\fB, FILE \fP\fI*file\fP\fB, int \fP\fIconvert_to_8_bit\fP\fB, const void \fP\fI*buffer\fP\fB, png_int_32 \fP\fIrow_stride\fP\fB, void \fI*colormap)\fP\fB);\fP
\fBint png_image_write_to_stdio (png_imagep \fP\fIimage\fP\fB, FILE \fP\fI*file\fP\fB, int \fP\fIconvert_to_8_bit\fP\fB, const void \fP\fI*buffer\fP\fB, png_int_32 \fIrow_stride)\fP\fB);\fP
\fI\fB
@@ -986,6 +988,14 @@ libpng \- Portable Network Graphics (PNG) Reference Library 1.6.0beta30
\fI\fB
\fBvoidpf png_zalloc (voidpf \fP\fIpng_ptr\fP\fB, uInt \fP\fIitems\fP\fB, uInt \fIsize\fP\fB);\fP
\fI\fB
\fBvoid png_zfree (voidpf \fP\fIpng_ptr\fP\fB, voidpf \fIptr\fP\fB);\fP
\fI\fB
.SH DESCRIPTION
The
.I libpng
@@ -997,7 +1007,7 @@ Following is a copy of the libpng-manual.txt file that accompanies libpng.
.SH LIBPNG.TXT
libpng-manual.txt - A description on how to use and modify libpng
libpng version 1.6.0beta30 - October 24, 2012
libpng version 1.6.0beta20 - March 29, 2012
Updated and distributed by Glenn Randers-Pehrson
<glennrp at users.sourceforge.net>
Copyright (c) 1998-2011 Glenn Randers-Pehrson
@@ -1008,7 +1018,7 @@ libpng-manual.txt - A description on how to use and modify libpng
Based on:
libpng versions 0.97, January 1998, through 1.6.0beta30 - October 24, 2012
libpng versions 0.97, January 1998, through 1.6.0beta20 - March 29, 2012
Updated and distributed by Glenn Randers-Pehrson
Copyright (c) 1998-2011 Glenn Randers-Pehrson
@@ -1064,7 +1074,7 @@ of reducing the amount of time and effort it takes to support the PNG
file format in application programs.
The PNG specification (second edition), November 2003, is available as
a W3C Recommendation and as an ISO Standard (ISO/IEC 15948:2004 (E)) at
a W3C Recommendation and as an ISO Standard (ISO/IEC 15948:2003 (E)) at
<http://www.w3.org/TR/2003/REC-PNG-20031110/
The W3C and ISO documents have identical technical content.
@@ -1157,8 +1167,8 @@ APIs. Most of these are fairly obvious; for example types corresponding
to integers of particular sizes and types for passing color values.
One exception is how non-integral numbers are handled. For application
convenience most APIs that take such numbers have C (double) arguments;
however, internally PNG, and libpng, use 32 bit signed integers and encode
convenience most APIs that take such numbers have C (double) arguments,
however internally PNG, and libpng, use 32 bit signed integers and encode
the value by multiplying by 100,000. As of libpng 1.5.0 a convenience
macro PNG_FP_1 is defined in png.h along with a type (png_fixed_point)
which is simply (png_int_32).
@@ -1569,7 +1579,6 @@ chunk types. To change this, you can call:
png_set_keep_unknown_chunks(png_ptr, keep,
chunk_list, num_chunks);
keep - 0: default unknown chunk handling
1: ignore; do not keep
2: keep only if safe-to-copy
@@ -1583,16 +1592,11 @@ chunk types. To change this, you can call:
chunk_list - list of chunks affected (a byte string,
five bytes per chunk, NULL or '\0' if
num_chunks is positive; ignored if
numchunks <= 0).
num_chunks is 0)
num_chunks - number of chunks affected; if 0, all
unknown chunks are affected. If positive,
only the chunks in the list are affected,
and if negative all unknown chunks and
all known chunks except for the IHDR,
PLTE, tRNS, IDAT, and IEND chunks are
affected.
unknown chunks are affected. If nonzero,
only the chunks in the list are affected
Unknown chunks declared in this way will be saved as raw data onto a
list of png_unknown_chunk structures. If a chunk that is normally
@@ -1825,7 +1829,7 @@ the screen_gamma value. Pixels with alpha less than 1.0
will still have linear components.
Use this format if you have control over your
compositing software and so don't do other arithmetic
compositing software and do don't do other arithmetic
(such as scaling) on the data you get from libpng. Your
compositing software can simply copy opaque pixels to
the output but still has linear values for the
@@ -2156,15 +2160,6 @@ data has been read, or zero if it is missing. The parameters to the
png_get_<chunk> are set directly if they are simple data types, or a
pointer into the info_ptr is returned for any complex types.
The colorspace data from gAMA, cHRM, sRGB, iCCP, and sBIT chunks
is simply returned to give the application information about how the
image was encoded. Libpng itself only does transformations using the file
gamma when combining semitransparent pixels with the background color, and,
since libpng-1.6.0, when converting between 8-bit sRGB and 16-bit linear pixels
within the simplified API. Libpng also uses the file gamma when converting
RGB to gray, beginning with libpng-1.0.5, if the application calls
png_set_rgb_to_gray()).
png_get_PLTE(png_ptr, info_ptr, &palette,
&num_palette);
@@ -2776,7 +2771,7 @@ the current display (e.g., the background color from a web page). You
need to tell libpng how the color is represented, both the format of the
component values in the color (the number of bits) and the gamma encoding of the
color. The function takes two arguments, background_gamma_mode and need_expand
to convey this information; however, only two combinations are likely to be
to convey this information, however only two combinations are likely to be
useful:
png_color_16 my_background;
@@ -3070,7 +3065,7 @@ the second parameter NULL.
If you don't want libpng to handle the interlacing details, just call
png_read_rows() PNG_INTERLACE_ADAM7_PASSES times to read in all the images.
Each of the images is a valid image by itself; however, you will almost
Each of the images is a valid image by itself, however you will almost
certainly need to distribute the pixels from each sub-image to the
correct place. This is where everything gets very tricky.
@@ -3227,7 +3222,7 @@ sPLT, only the n'th item in the structure is freed, where n is "seq".
The default behavior is only to free data that was allocated internally
by libpng. This can be changed, so that libpng will not free the data,
or so that it will free data that was allocated by the user with png_malloc()
or png_calloc() and passed in via a png_set_*() function, with
or png_zalloc() and passed in via a png_set_*() function, with
png_data_freer(png_ptr, info_ptr, freer, mask)
@@ -3248,7 +3243,7 @@ or png_destroy_*() is supposed to free the data. When the user assumes
responsibility for libpng-allocated data, the application must use
png_free() to free it, and when the user transfers responsibility to libpng
for data that the user has allocated, the user must have used png_malloc()
or png_calloc() to allocate it.
or png_zalloc() to allocate it.
If you allocated your row_pointers in a single block, as suggested above in
the description of the high level read interface, you must not transfer
@@ -4066,9 +4061,8 @@ 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
a writeable buffer of at least 29 bytes.
png_convert_to_rfc1123(png_timep) is provided to convert from PNG
time to an RFC 1123 format string.
.SS Writing unknown chunks
@@ -4430,7 +4424,7 @@ png_destroy_write_struct().
The default behavior is only to free data that was allocated internally
by libpng. This can be changed, so that libpng will not free the data,
or so that it will free data that was allocated by the user with png_malloc()
or png_calloc() and passed in via a png_set_*() function, with
or png_zalloc() and passed in via a png_set_*() function, with
png_data_freer(png_ptr, info_ptr, freer, mask)
@@ -4466,7 +4460,7 @@ When the user assumes responsibility for libpng-allocated data, the
application must use
png_free() to free it, and when the user transfers responsibility to libpng
for data that the user has allocated, the user must have used png_malloc()
or png_calloc() to allocate it.
or png_zalloc() to allocate it.
If you allocated text_ptr.text, text_ptr.lang, and text_ptr.translated_keyword
separately, do not transfer responsibility for freeing text_ptr to libpng,
@@ -4521,13 +4515,12 @@ png_image is a structure that describes the in-memory format of an image
when it is being read or define the in-memory format of an image that you
need to write. The "png_image" structure contains the following members:
png_uint_32 version Set to PNG_IMAGE_VERSION
png_uint_32 width Image width in pixels (columns)
png_uint_32 height Image height in pixels (rows)
png_uint_32 format Image format as defined below
png_uint_32 flags A bit mask containing informational flags
png_controlp opaque Initialize to NULL, free with png_image_free
png_uint_32 colormap_entries; Number of entries in the color-map
png_const_bytep colormap A pointer to the application color-map
png_uint_32 warning_or_error;
char message[64];
@@ -4687,22 +4680,6 @@ First the information about the samples.
a fixed number determined by the format so can easily be allocated on the
stack if necessary.
#define PNG_IMAGE_MAXIMUM_COLORMAP_COMPONENTS(fmt)\
(PNG_IMAGE_SAMPLE_CHANNELS(fmt) * 256)
/* The maximum size of the color-map required by the format expressed in a
* count of components. This can be used to compile-time allocate a
* color-map:
*
* png_uint_16 colormap[PNG_IMAGE_MAXIMUM_COLORMAP_COMPONENTS(linear_fmt)];
*
* png_byte colormap[PNG_IMAGE_MAXIMUM_COLORMAP_COMPONENTS(sRGB_fmt)];
*
* Alternatively use the PNG_IMAGE_COLORMAP_SIZE macro below to use the
* information from one of the png_image_begin_read_ APIs and dynamically
* allocate the required memory.
*/
Corresponding information about the pixels
PNG_IMAGE_PIXEL_(test,fmt)
@@ -4761,8 +4738,7 @@ READ APIs
The PNG header is read from the given memory buffer.
int png_image_finish_read(png_imagep image,
png_colorp background, void *buffer,
png_int_32 row_stride, void *colormap));
png_colorp background, void *buffer, png_int_32 row_stride));
Finish reading the image into the supplied buffer and
clean up the png_image structure.
@@ -4799,7 +4775,6 @@ WRITE APIS
For write you must initialize a png_image structure to describe the image to
be written:
version: must be set to PNG_IMAGE_VERSION
opaque: must be initialized to NULL
width: image width in pixels
height: image height in rows
@@ -4807,17 +4782,15 @@ be written:
flags: set to 0 unless one of the defined flags applies; set
PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB for color format images
where the RGB values do not correspond to the colors in sRGB.
colormap_entries: set to the number of entries in the color-map (0 to 256)
int png_image_write_to_file, (png_imagep image,
const char *file, int convert_to_8bit, const void *buffer,
png_int_32 row_stride, const void *colormap));
png_int_32 row_stride));
Write the image to the named file.
int png_image_write_to_stdio(png_imagep image, FILE *file,
int convert_to_8_bit, const void *buffer,
png_int_32 row_stride, const void *colormap)
int convert_to_8_bit, const void *buffer, png_int_32 row_stride)
Write the image to the given (FILE*).
@@ -4851,13 +4824,12 @@ in pngmem.c, pngrio.c, pngwio.c, and pngerror.c, respectively. To change
these functions, call the appropriate png_set_*_fn() function.
Memory allocation is done through the functions png_malloc(), png_calloc(),
and png_free(). The png_malloc() and png_free() functions currently just
call the standard C functions and png_calloc() calls png_malloc() and then
clears the newly allocated memory to zero; note that png_calloc(png_ptr, size)
is not the same as the calloc(number, size) function provided by stdlib.h.
There is limited support for certain systems with segmented memory
architectures and the types of pointers declared by png.h match this; you
will have to use appropriate pointers in your application. Since it is
and png_free(). These currently just call the standard C functions.
png_calloc() calls png_malloc() and then clears the newly
allocated memory to zero. There is limited support for certain systems
with segmented memory architectures and the types of pointers declared by
png.h match this; you will have to use appropriate pointers in your
application. Since it is
unlikely that the method of handling memory allocation on a platform
will change between applications, these functions must be modified in
the library at compile time. If you prefer to use a different method
@@ -5088,7 +5060,7 @@ available to set these separately for non-IDAT
compressed chunks such as zTXt, iTXt, and iCCP:
#include zlib.h
#if PNG_LIBPNG_VER >= 10504
#if PNG_LIBPNG_VER <= 10504
png_set_text_compression_level(png_ptr, level);
png_set_text_compression_mem_level(png_ptr, level);
@@ -5536,9 +5508,7 @@ png_set_strip_error_numbers() was removed from the library by default.
The png_zalloc() and png_zfree() functions are no longer exported.
The png_zalloc() function no longer zeroes out the memory that it
allocates. Applications that called png_zalloc(png_ptr, number, size)
can call png_calloc(png_ptr, number*size) instead, and can call
png_free() instead of png_zfree().
allocates.
Support for dithering was disabled by default in libpng-1.4.0, because
it has not been well tested and doesn't actually "dither".
@@ -5571,7 +5541,7 @@ This is enabled by default but can be disabled in each png_ptr with
A. Changes that affect users of libpng
There are no substantial API changes between the non-deprecated parts of
the 1.4.5 API and the 1.5.0 API; however, the ability to directly access
the 1.4.5 API and the 1.5.0 API; however the ability to directly access
members of the main libpng control structures, png_struct and png_info,
deprecated in earlier versions of libpng, has been completely removed from
libpng 1.5.
@@ -5582,12 +5552,9 @@ need access to information in zlib.h will need to add the '#include "zlib.h"'
directive. It does not matter whether this is placed prior to or after
the '"#include png.h"' directive.
The png_sprintf(), png_strcpy(), and png_strncpy() macros are no longer used
and were removed.
We moved the png_strlen(), png_memcpy(), png_memset(), and png_memcmp()
macros into a private header file (pngpriv.h) that is not accessible to
applications.
We moved the png_strcpy(), png_strncpy(), png_strlen(), png_memcpy(),
png_memcmp(), png_sprintf, and png_memcpy() macros into a private
header file (pngpriv.h) that is not accessible by applications.
In png_get_iCCP, the type of "profile" was changed from png_charpp
to png_bytepp, and in png_set_iCCP, from png_charp to png_const_bytep.
@@ -5708,12 +5675,12 @@ B. Changes to the build and configuration of libpng
Details of internal changes to the library code can be found in the CHANGES
file and in the GIT repository logs. These will be of no concern to the vast
majority of library users or builders; however, the few who configure libpng
majority of library users or builders, however the few who configure libpng
to a non-default feature set may need to change how this is done.
There should be no need for library builders to alter build scripts if
these use the distributed build support - configure or the makefiles -
however, users of the makefiles may care to update their build scripts
however users of the makefiles may care to update their build scripts
to build pnglibconf.h where the corresponding makefile does not do so.
Building libpng with a non-default configuration has changed completely.
@@ -5819,7 +5786,7 @@ merely stops the function from being exported.
PNG_FLOATING_ARITHMETIC_SUPPORTED chooses between the internal floating
point implementation or the fixed point one. Typically the fixed point
implementation is larger and slower than the floating point implementation
on a system that supports floating point; however, it may be faster on a
on a system that supports floating point, however it may be faster on a
system which lacks floating point hardware and therefore uses a software
emulation.
@@ -5848,7 +5815,7 @@ pngconf.h no longer includes pngusr.h, therefore pngusr.h is ignored after the
build of pnglibconf.h and it is never included in an application build.
The rarely used alternative of adding a list of feature macros to the
CFLAGS setting in the build also still works; however, the macros will be
CFLAGS setting in the build also still works, however the macros will be
copied to pnglibconf.h and this may produce macro redefinition warnings
when the individual C files are compiled.
@@ -5896,10 +5863,6 @@ The following has been removed:
with png_get_io_chunk_type(). The new
function returns a 32-bit integer instead of
a string.
The png_sizeof(), png_strlen(), png_memcpy(), png_memcmp(), and
png_memset() macros are no longer used in the libpng sources and
have been removed. These had already been made invisible to applications
since libpng-1.5.0.
.SH XIII. Detecting libpng
@@ -6017,21 +5980,10 @@ pngtest) appear in
pngpriv.h
above the comment that says
/* Maintainer: Put new private prototypes here ^ */
We put a space after the "sizeof" operator and we omit the
optional parentheses around its argument when the argument
is an expression, not a type name, and we always enclose the
sizeof operator, with its argument, in parentheses:
(sizeof (png_uint_32))
(sizeof array)
Prior to libpng-1.6.0 we used a "png_sizeof()" macro, formatted as
though it were a function.
/* Maintainer: Put new private prototypes here ^ and in libpngpf.3 */
To avoid polluting the global namespace, the names of all exported
functions and variables begin with "png_", and all publicly visible C
functions and variables begin with "png_", and all publicly visible C
preprocessor macros begin with "PNG". We request that applications that
use libpng *not* begin any of their own symbols with either of these strings.
@@ -6045,15 +5997,12 @@ left parenthesis that follows it:
for (i = 2; i > 0; --i)
y[i] = a(x) + (int)b;
We prefer #ifdef and #ifndef to #if defined() and #if !defined()
We prefer #ifdef and #ifndef to #if defined() and if !defined()
when there is only one macro being tested.
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).
We prefer to use underscores in variable names rather than camelCase, except
for a few type names that we inherit from zlib.h.
We do not use the TAB character for indentation in the C sources.
Lines do not exceed 80 characters.
@@ -6062,25 +6011,25 @@ Other rules can be inferred by inspecting the libpng source.
.SH XVI. Y2K Compliance in libpng
October 24, 2012
March 29, 2012
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.0beta30 are Y2K compliant. It is my belief that earlier
upward through 1.6.0beta20 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
that will hold years up to 65535. The other, which is deprecated,
holds the date in text format, and will hold years up to 9999.
Libpng only has three year fields. One is a 2-byte unsigned integer that
will hold years up to 65535. The other two hold the date in text
format, and will hold years up to 9999.
The integer is
"png_uint_16 year" in png_time_struct.
The string is
"char time_buffer[29]" in png_struct. This is no longer used
in libpng-1.6.x and will be removed from libpng-1.7.0.
The strings are
"png_charp time_buffer" in png_struct and
"near_time_buffer", which is a local character string in png.c.
There are seven time-related functions:
@@ -6273,7 +6222,7 @@ the first widely used release:
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-30 16 10600 16.so.16.0[.0]
1.6.0beta01-20 16 10600 16.so.16.0[.0]
Henceforth the source version will match the shared-library minor
and patch numbers; the shared-library major version number will be
@@ -6330,7 +6279,7 @@ possible without all of you.
Thanks to Frank J. T. Wojcik for helping with the documentation.
Libpng version 1.6.0beta30 - October 24, 2012:
Libpng version 1.6.0beta20 - March 29, 2012:
Initially created in 1995 by Guy Eric Schalnat, then of Group 42, Inc.
Currently maintained by Glenn Randers-Pehrson (glennrp at users.sourceforge.net).
@@ -6353,7 +6302,7 @@ this sentence.
This code is released under the libpng license.
libpng versions 1.2.6, August 15, 2004, through 1.6.0beta30, October 24, 2012, are
libpng versions 1.2.6, August 15, 2004, through 1.6.0beta20, March 29, 2012, are
Copyright (c) 2004,2006-2007 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
@@ -6452,7 +6401,7 @@ certification mark of the Open Source Initiative.
Glenn Randers-Pehrson
glennrp at users.sourceforge.net
October 24, 2012
March 29, 2012
.\" end of man page

View File

@@ -1,6 +1,6 @@
.TH LIBPNGPF 3 "October 24, 2012"
.TH LIBPNGPF 3 "March 29, 2012"
.SH NAME
libpng \- Portable Network Graphics (PNG) Reference Library 1.6.0beta30
libpng \- Portable Network Graphics (PNG) Reference Library 1.6.0beta20
(private functions)
.SH SYNOPSIS
\fB#include \fI"pngpriv.h"

2
png.5
View File

@@ -1,4 +1,4 @@
.TH PNG 5 "October 24, 2012"
.TH PNG 5 "March 29, 2012"
.SH NAME
png \- Portable Network Graphics (PNG) format
.SH DESCRIPTION

1903
png.c

File diff suppressed because it is too large Load Diff

245
png.h
View File

@@ -1,7 +1,7 @@
/* png.h - header file for PNG reference library
*
* libpng version 1.6.0beta30 - October 24, 2012
* libpng version 1.6.0beta20 - March 29, 2012
* Copyright (c) 1998-2012 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.0beta30 - October 24, 2012: Glenn
* libpng versions 0.97, January 1998, through 1.6.0beta20 - March 29, 2012: Glenn
* See also "Contributing Authors", below.
*
* Note about libpng version numbers:
@@ -166,7 +166,7 @@
* 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-30 16 10600 16.so.16.0[.0]
* 1.6.0beta01-20 16 10600 16.so.16.0[.0]
*
* Henceforth the source version will match the shared-library major
* and minor numbers; the shared-library major version number will be
@@ -198,7 +198,7 @@
*
* This code is released under the libpng license.
*
* libpng versions 1.2.6, August 15, 2004, through 1.6.0beta30, October 24, 2012, are
* libpng versions 1.2.6, August 15, 2004, through 1.6.0beta20, March 29, 2012, are
* Copyright (c) 2004, 2006-2012 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,30 +310,28 @@
* Y2K compliance in libpng:
* =========================
*
* October 24, 2012
* March 29, 2012
*
* 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.0beta30 are Y2K compliant. It is my belief that
* upward through 1.6.0beta20 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
* that will hold years up to 65535. The other, which is deprecated,
* holds the date in text format, and will hold years up to 9999.
* that will hold years up to 65535. The other holds the date in text
* format, and will hold years up to 9999.
*
* The integer is
* "png_uint_16 year" in png_time_struct.
*
* The string is
* "char time_buffer[29]" in png_struct. This is no longer used
* in libpng-1.6.x and will be removed from libpng-1.7.0.
* "png_char time_buffer" in png_struct
*
* There are seven time-related functions:
* png.c: png_convert_to_rfc_1123_buffer() in png.c
* (formerly png_convert_to_rfc_1123() prior to libpng-1.5.x and
* png_convert_to_rfc_1152() in error prior to libpng-0.98)
* png.c: png_convert_to_rfc_1123() in png.c
* (formerly png_convert_to_rfc_1152() in error)
* png_convert_from_struct_tm() in pngwrite.c, called in pngwrite.c
* png_convert_from_time_t() in pngwrite.c
* png_get_tIME() in pngget.c
@@ -344,8 +342,8 @@
* All handle dates properly in a Y2K environment. The
* png_convert_from_time_t() function calls gmtime() to convert from system
* clock time, which returns (year - 1900), which we properly convert to
* the full 4-digit year. There is a possibility that libpng applications
* are not passing 4-digit years into the png_convert_to_rfc_1123_buffer()
* the full 4-digit year. There is a possibility that applications using
* libpng are not passing 4-digit years into the png_convert_to_rfc_1123()
* function, or that they are incorrectly passing only a 2-digit year
* instead of "year - 1900" into the png_convert_from_struct_tm() function,
* but this is not under our control. The libpng documentation has always
@@ -376,9 +374,9 @@
*/
/* Version information for png.h - this should match the version in png.c */
#define PNG_LIBPNG_VER_STRING "1.6.0beta30"
#define PNG_LIBPNG_VER_STRING "1.6.0beta20"
#define PNG_HEADER_VERSION_STRING \
" libpng version 1.6.0beta30 - October 24, 2012\n"
" libpng version 1.6.0beta20 - March 29, 2012\n"
#define PNG_LIBPNG_VER_SONUM 16
#define PNG_LIBPNG_VER_DLLNUM 16
@@ -392,7 +390,7 @@
* PNG_LIBPNG_VER_STRING, omitting any leading zero:
*/
#define PNG_LIBPNG_VER_BUILD 30
#define PNG_LIBPNG_VER_BUILD 20
/* Release Status */
#define PNG_LIBPNG_BUILD_ALPHA 1
@@ -522,7 +520,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_0beta30;
typedef char* png_libpng_version_1_6_0beta20;
/* Basic control structions. Read libpng-manual.txt or libpng.3 for more info.
*
@@ -704,26 +702,20 @@ 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_UNKNOWN_CHUNKS_SUPPORTED) || \
defined(PNG_HANDLE_AS_UNKNOWN_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
* know about their semantics.
*
* The data in the structure is set by libpng on read and used on write.
*/
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_byte name[5];
png_byte *data;
png_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
* more bits set than are listed below. Always treat the value as a
* bitmask. On write set only one bit - setting multiple bits may cause the
* chunk to be written in multiple places.
*/
/* libpng-using applications should NOT directly modify this byte. */
png_byte location; /* mode of operation at read time */
}
png_unknown_chunk;
@@ -733,7 +725,8 @@ typedef const png_unknown_chunk * png_const_unknown_chunkp;
typedef png_unknown_chunk * * png_unknown_chunkpp;
#endif
/* Flag values for the unknown chunk location byte. */
/* Values for the unknown chunk location byte */
#define PNG_HAVE_IHDR 0x01
#define PNG_HAVE_PLTE 0x02
#define PNG_AFTER_IDAT 0x08
@@ -901,8 +894,7 @@ typedef PNG_CALLBACK(int, *png_user_chunk_ptr, (png_structp,
png_unknown_chunkp));
#endif
#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
/* not used anywhere */
/* typedef PNG_CALLBACK(void, *png_unknown_chunk_ptr, (png_structp)); */
typedef PNG_CALLBACK(void, *png_unknown_chunk_ptr, (png_structp));
#endif
#ifdef PNG_SETJMP_SUPPORTED
@@ -1040,7 +1032,7 @@ PNG_EXPORT(7, void, png_set_compression_buffer_size, (png_structrp png_ptr,
PNG_EXPORT(8, jmp_buf*, png_set_longjmp_fn, (png_structrp png_ptr,
png_longjmp_ptr longjmp_fn, size_t jmp_buf_size));
# define png_jmpbuf(png_ptr) \
(*png_set_longjmp_fn((png_ptr), longjmp, (sizeof (jmp_buf))))
(*png_set_longjmp_fn((png_ptr), longjmp, sizeof (jmp_buf)))
#else
# define png_jmpbuf(png_ptr) \
(LIBPNG_WAS_COMPILED_WITH__PNG_NO_SETJMP)
@@ -1119,7 +1111,6 @@ PNG_EXPORT(22, void, png_read_info,
* png_struct, this will be removed in future versions.
*/
#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
@@ -1244,7 +1235,7 @@ PNG_FIXED_EXPORT(228, void, png_set_alpha_mode_fixed, (png_structrp png_ptr,
int mode, png_fixed_point output_gamma))
#endif
#if defined(PNG_GAMMA_SUPPORTED) || defined(PNG_READ_ALPHA_MODE_SUPPORTED)
#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_ALPHA_MODE_SUPPORTED)
/* The output_gamma value is a screen gamma in libpng terminology: it expresses
* how to decode the output values, not how they are encoded. The values used
* correspond to the normal numbers used to describe the overall gamma of a
@@ -1550,8 +1541,7 @@ PNG_EXPORT(57, void, png_read_image, (png_structrp png_ptr, png_bytepp image));
#endif
/* Write a row of image data */
PNG_EXPORT(58, void, png_write_row, (png_structrp png_ptr,
png_const_bytep row));
PNG_EXPORT(58, void, png_write_row, (png_structrp png_ptr, png_const_bytep row));
/* Write a few rows of image data: (*row) is not written; however, the type
* is declared as writeable to maintain compatibility with previous versions
@@ -1565,8 +1555,7 @@ PNG_EXPORT(59, void, png_write_rows, (png_structrp png_ptr, png_bytepp row,
PNG_EXPORT(60, void, png_write_image, (png_structrp png_ptr, png_bytepp image));
/* Write the end of the PNG file. */
PNG_EXPORT(61, void, png_write_end, (png_structrp png_ptr,
png_inforp info_ptr));
PNG_EXPORT(61, void, png_write_end, (png_structrp png_ptr, png_inforp info_ptr));
#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
/* Read the end of the PNG file. */
@@ -1834,31 +1823,9 @@ PNG_EXPORT(217, png_uint_32, png_get_current_row_number, (png_const_structrp));
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
* 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
* png_set_ APIs.)
*
* There is no write support - on write, by default, all the chunks in the
* 'unknown' list are written in the specified position.
*
* 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.
* positive: The chunk was handled, libpng will ignore/discard it.
*/
#ifdef PNG_USER_CHUNKS_SUPPORTED
PNG_EXPORT(88, void, png_set_read_user_chunk_fn, (png_structrp png_ptr,
png_voidp user_chunk_ptr, png_user_chunk_ptr read_user_chunk_fn));
#endif
#ifdef PNG_USER_CHUNKS_SUPPORTED
PNG_EXPORT(89, png_voidp, png_get_user_chunk_ptr, (png_const_structrp png_ptr));
#endif
@@ -1871,12 +1838,11 @@ PNG_EXPORT(90, void, png_set_progressive_read_fn, (png_structrp png_ptr,
png_progressive_row_ptr row_fn, png_progressive_end_ptr end_fn));
/* Returns the user pointer associated with the push read functions */
PNG_EXPORT(91, png_voidp, png_get_progressive_ptr,
(png_const_structrp png_ptr));
PNG_EXPORT(91, png_voidp, png_get_progressive_ptr, (png_const_structrp png_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_EXPORT(92, void, png_process_data, (png_structrp png_ptr, png_inforp info_ptr,
png_bytep buffer, png_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
@@ -1944,10 +1910,8 @@ PNG_EXPORTA(99, void, png_data_freer, (png_const_structrp png_ptr,
#define PNG_FREE_ROWS 0x0040
#define PNG_FREE_PCAL 0x0080
#define PNG_FREE_SCAL 0x0100
#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
# define PNG_FREE_UNKN 0x0200
#endif
/* PNG_FREE_LIST 0x0400 removed in 1.6.0 because it is ignored */
#define PNG_FREE_UNKN 0x0200
#define PNG_FREE_LIST 0x0400
#define PNG_FREE_PLTE 0x1000
#define PNG_FREE_TRNS 0x2000
#define PNG_FREE_TEXT 0x4000
@@ -1991,11 +1955,9 @@ PNG_EXPORT(106, void, png_chunk_warning, (png_const_structrp png_ptr,
PNG_EXPORT(107, void, png_benign_error, (png_const_structrp png_ptr,
png_const_charp warning_message));
#ifdef PNG_READ_SUPPORTED
/* Same, chunk name is prepended to message (only during read) */
/* Same, chunk name is prepended to message. */
PNG_EXPORT(108, void, png_chunk_benign_error, (png_const_structrp png_ptr,
png_const_charp warning_message));
#endif
PNG_EXPORT(109, void, png_set_benign_errors,
(png_structrp png_ptr, int allowed));
@@ -2102,11 +2064,9 @@ PNG_EXPORT(129, png_int_32, png_get_y_offset_microns,
#endif /* PNG_EASY_ACCESS_SUPPORTED */
#ifdef PNG_READ_SUPPORTED
/* Returns pointer to signature string read from PNG header */
PNG_EXPORT(130, png_const_bytep, png_get_signature, (png_const_structrp png_ptr,
png_const_inforp info_ptr));
#endif
#ifdef PNG_bKGD_SUPPORTED
PNG_EXPORT(131, png_uint_32, png_get_bKGD, (png_const_structrp png_ptr,
@@ -2354,123 +2314,33 @@ PNG_EXPORT(171, void, png_set_sCAL_s, (png_const_structrp png_ptr,
png_const_charp swidth, png_const_charp sheight));
#endif /* PNG_sCAL_SUPPORTED */
#ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED
/* Provide the default handling for all unknown chunks or, optionally, for
* specific unknown chunks.
*
* 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
* desired handling (keep or discard.)
*
* 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)
* Unknown chunks: for a specific chunk use the global default, when used
* as the default discard the chunk data.
* PNG_HANDLE_CHUNK_NEVER:
* Discard the chunk data.
* PNG_HANDLE_CHUNK_IF_SAFE:
* Keep the chunk data if the chunk is not critical else raise a chunk
* error.
* PNG_HANDLE_CHUNK_ALWAYS:
* Keep the chunk data.
*
* If the chunk data is saved it can be retrieved using png_get_unknown_chunks,
* below. Notice that specifying "AS_DEFAULT" as a global default is equivalent
* to specifying "NEVER", however when "AS_DEFAULT" is used for specific chunks
* it simply resets the behavior to the libpng default.
*
* The per-chunk handling is always used when there is a png_user_chunk_ptr
* callback and the callback returns 0; the chunk is then always stored *unless*
* it is critical and the per-chunk setting is other than ALWAYS. Notice that
* the global default is *not* used in this case. (In effect the per-chunk
* value is incremented to at least IF_SAFE.)
*
* PNG_HANDLE_AS_UNKNOWN_SUPPORTED:
* If this is *not* set known chunks will always be handled by libpng and
* will never be stored in the unknown chunk list. Known chunks listed to
* png_set_keep_unknown_chunks will have no effect. If it is set then known
* chunks listed with a keep other than AS_DEFAULT will *never* be processed
* by libpng, in addition critical chunks must either be processed by the
* callback or saved.
*
* The IHDR and IEND chunks must not be listed. Because this turns off the
* default handling for chunks that would otherwise be recognized the
* behavior of libpng transformations may well become incorrect!
*
* WRITE:
* When writing chunks the options only apply to the chunks specified by
* png_set_unknown_chunks (below), libpng will *always* write known chunks
* required by png_set_ calls and will always write the core critical chunks
* (as required for PLTE).
*
* Each chunk in the png_set_unknown_chunks list is looked up in the
* png_set_keep_unknown_chunks list to find the keep setting, this is then
* interpreted as follows:
*
* PNG_HANDLE_CHUNK_AS_DEFAULT:
* Write safe-to-copy chunks and write other chunks if the global
* default is set to _ALWAYS, otherwise don't write this chunk.
* PNG_HANDLE_CHUNK_NEVER:
* Do not write the chunk.
* PNG_HANDLE_CHUNK_IF_SAFE:
* Write the chunk if it is safe-to-copy, otherwise do not write it.
* PNG_HANDLE_CHUNK_ALWAYS:
* Write the chunk.
*
* Note that the default behavior is effectively the opposite of the read case -
* in read unknown chunks are not stored by default, in write they are written
* by default. Also the behavior of PNG_HANDLE_CHUNK_IF_SAFE is very different
* - on write the safe-to-copy bit is checked, on read the critical bit is
* checked and on read if the chunk is critical an error will be raised.
*
* num_chunks:
* ===========
* If num_chunks is positive, then the "keep" parameter specifies the manner
* for handling only those chunks appearing in the chunk_list array,
* otherwise the chunk list array is ignored.
*
* If num_chunks is 0 the "keep" parameter specifies the default behavior for
* unknown chunks, as described above.
*
* If num_chunks is negative, then the "keep" parameter specifies the manner
* for handling all unknown chunks plus all chunks recognized by libpng
* except for the IHDR, PLTE, tRNS, IDAT, and IEND chunks (which continue to
* be processed by libpng.
*/
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
/* Provide a list of chunks and how they are to be handled, if the built-in
handling or default unknown chunk handling is not desired. Any chunks not
listed will be handled in the default manner. The IHDR and IEND chunks
must not be listed. Because this turns off the default handling for chunks
that would otherwise be recognized the behavior of libpng transformations may
well become incorrect!
keep = 0: PNG_HANDLE_CHUNK_AS_DEFAULT: follow default behavior
= 1: PNG_HANDLE_CHUNK_NEVER: do not keep
= 2: PNG_HANDLE_CHUNK_IF_SAFE: keep only if safe-to-copy
= 3: PNG_HANDLE_CHUNK_ALWAYS: keep even if unsafe-to-copy
*/
PNG_EXPORT(172, void, png_set_keep_unknown_chunks, (png_structrp png_ptr,
int keep, png_const_bytep chunk_list, int num_chunks));
/* The "keep" PNG_HANDLE_CHUNK_ parameter for the specified chunk is returned;
* the result is therefore true (non-zero) if special handling is required,
* false for the default handling.
/* The handling code is returned; the result is therefore true (non-zero) if
* special handling is required, false for the default handling.
*/
PNG_EXPORT(173, int, png_handle_as_unknown, (png_const_structrp png_ptr,
PNG_EXPORT(173, int, png_handle_as_unknown, (png_structrp png_ptr,
png_const_bytep chunk_name));
#endif
#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
PNG_EXPORT(174, void, png_set_unknown_chunks, (png_const_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
* unknowns to the location currently stored in the png_struct. This is
* invariably the wrong value on write. To fix this call the following API
* for each chunk in the list with the correct location. If you know your
* code won't be compiled on earlier versions you can rely on
* png_set_unknown_chunks(write-ptr, png_get_unknown_chunks(read-ptr)) doing
* the correct thing.
*/
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));
#endif
@@ -2509,7 +2379,6 @@ PNG_EXPORT(184, png_uint_32, png_permit_mng_features, (png_structrp png_ptr,
#define PNG_HANDLE_CHUNK_NEVER 1
#define PNG_HANDLE_CHUNK_IF_SAFE 2
#define PNG_HANDLE_CHUNK_ALWAYS 3
#define PNG_HANDLE_CHUNK_LAST 4
/* Strip the prepended error numbers ("#nnn ") from error and warning
* messages before passing them to the error or warning handler.
@@ -2635,10 +2504,10 @@ PNG_EXPORT(216, png_uint_32, png_get_io_chunk_type,
* necessary to find the row in the output image given a row in an interlaced
* image, so two more macros:
*/
#define PNG_ROW_FROM_PASS_ROW(y_in, pass) \
(((y_in)<<PNG_PASS_ROW_SHIFT(pass))+PNG_PASS_START_ROW(pass))
#define PNG_COL_FROM_PASS_COL(x_in, pass) \
(((x_in)<<PNG_PASS_COL_SHIFT(pass))+PNG_PASS_START_COL(pass))
#define PNG_ROW_FROM_PASS_ROW(yIn, pass) \
(((yIn)<<PNG_PASS_ROW_SHIFT(pass))+PNG_PASS_START_ROW(pass))
#define PNG_COL_FROM_PASS_COL(xIn, pass) \
(((xIn)<<PNG_PASS_COL_SHIFT(pass))+PNG_PASS_START_COL(pass))
/* Two macros which return a boolean (0 or 1) saying whether the given row
* or column is in a particular pass. These use a common utility macro that
@@ -2778,7 +2647,7 @@ PNG_EXPORT(207, void, png_save_uint_16, (png_bytep buf, unsigned int i));
* formats do not accomodate 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 ancillary information.
* as a wide variety of APIs to manipulate ancilliary information.
*
* To read a PNG file using the simplified API:
*

View File

@@ -1,7 +1,7 @@
/* pngconf.h - machine configurable file for libpng
*
* libpng version 1.6.0beta30 - October 24, 2012
* libpng version 1.6.0beta20 - March 29, 2012
*
* Copyright (c) 1998-2012 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
@@ -366,28 +366,24 @@
# ifndef PNG_NORETURN
# define PNG_NORETURN __attribute__((__noreturn__))
# endif
# if __GNUC__ >= 3
# ifndef PNG_ALLOCATED
# define PNG_ALLOCATED __attribute__((__malloc__))
# ifndef PNG_ALLOCATED
# define PNG_ALLOCATED __attribute__((__malloc__))
# endif
# ifndef PNG_DEPRECATED
# define PNG_DEPRECATED __attribute__((__deprecated__))
# endif
# ifndef PNG_PRIVATE
# if 0 /* Doesn't work so we use deprecated instead*/
# define PNG_PRIVATE \
__attribute__((warning("This function is not exported by libpng.")))
# else
# define PNG_PRIVATE \
__attribute__((__deprecated__))
# endif
# ifndef PNG_DEPRECATED
# define PNG_DEPRECATED __attribute__((__deprecated__))
# endif
# ifndef PNG_PRIVATE
# if 0 /* Doesn't work so we use deprecated instead*/
# define PNG_PRIVATE \
__attribute__((warning("This function is not exported by libpng.")))
# else
# define PNG_PRIVATE \
__attribute__((__deprecated__))
# endif
# endif
# if ((__GNUC__ != 3) || !defined(__GNUC_MINOR__) || (__GNUC_MINOR__ >= 1))
# ifndef PNG_RESTRICT
# define PNG_RESTRICT __restrict
# endif
# endif /* __GNUC__ == 3.0 */
# endif /* __GNUC__ >= 3 */
# endif
# ifndef PNG_RESTRICT
# define PNG_RESTRICT __restrict
# endif
# elif defined(_MSC_VER) && (_MSC_VER >= 1300)
# ifndef PNG_USE_RESULT
@@ -435,9 +431,6 @@
#ifndef PNG_PRIVATE
# define PNG_PRIVATE /* This is a private libpng function */
#endif
#ifndef PNG_RESTRICT
# define PNG_RESTRICT /* The C99 "restrict" feature */
#endif
#ifndef PNG_FP_EXPORT /* A floating point API. */
# ifdef PNG_FLOATING_POINT_SUPPORTED
# define PNG_FP_EXPORT(ordinal, type, name, args)\
@@ -549,6 +542,12 @@ typedef ptrdiff_t png_ptrdiff_t;
typedef png_size_t png_alloc_size_t;
#endif
/* This macro makes the sizeof operator look and behave like a function, except
* that it can take a type without the enclosing () as an argument so long as
* the type contains no "," characters.
*/
#define png_sizeof(x) (sizeof (x))
/* Prior to 1.6.0 libpng offered limited support for Microsoft C compiler
* implementations of Intel CPU specific support of user-mode segmented address
* spaces, where 16-bit pointers address more than 65536 bytes of memory using

View File

@@ -80,8 +80,7 @@ png_error,(png_const_structrp png_ptr, png_const_charp error_message),
}
#endif
if (png_ptr != NULL && png_ptr->error_fn != NULL)
(*(png_ptr->error_fn))(png_constcast(png_structrp,png_ptr),
error_message);
(*(png_ptr->error_fn))(png_constcast(png_structrp,png_ptr), error_message);
/* If the custom handler doesn't exist, or if it returns,
use the default handler, which will not return. */
@@ -415,7 +414,7 @@ static PNG_CONST char png_digit[16] = {
'A', 'B', 'C', 'D', 'E', 'F'
};
#define PNG_MAX_ERROR_TEXT 196 /* Currently limited be profile_error in png.c */
#define PNG_MAX_ERROR_TEXT 64
#if defined(PNG_WARNINGS_SUPPORTED) || defined(PNG_ERROR_TEXT_SUPPORTED)
static void /* PRIVATE */
png_format_buffer(png_const_structrp png_ptr, png_charp buffer, png_const_charp
@@ -498,8 +497,7 @@ png_chunk_warning(png_const_structrp png_ptr, png_const_charp warning_message)
#ifdef PNG_READ_SUPPORTED
#ifdef PNG_BENIGN_ERRORS_SUPPORTED
void PNGAPI
png_chunk_benign_error(png_const_structrp png_ptr, png_const_charp
error_message)
png_chunk_benign_error(png_const_structrp png_ptr, png_const_charp error_message)
{
if (png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN)
png_chunk_warning(png_ptr, error_message);
@@ -519,7 +517,7 @@ png_fixed_error,(png_const_structrp png_ptr, png_const_charp name),PNG_NORETURN)
# define fixed_message_ln ((sizeof fixed_message)-1)
int iin;
char msg[fixed_message_ln+PNG_MAX_ERROR_TEXT];
memcpy(msg, fixed_message, fixed_message_ln);
png_memcpy(msg, fixed_message, fixed_message_ln);
iin = 0;
if (name != NULL) while (iin < (PNG_MAX_ERROR_TEXT-1) && name[iin] != 0)
{
@@ -557,7 +555,7 @@ png_set_longjmp_fn(png_structrp png_ptr, png_longjmp_ptr longjmp_fn,
{
png_ptr->jmp_buf_size = 0; /* not allocated */
if (jmp_buf_size <= (sizeof png_ptr->jmp_buf_local))
if (jmp_buf_size <= sizeof png_ptr->jmp_buf_local)
png_ptr->jmp_buf_ptr = &png_ptr->jmp_buf_local;
else
@@ -578,7 +576,7 @@ png_set_longjmp_fn(png_structrp png_ptr, png_longjmp_ptr longjmp_fn,
if (size == 0)
{
size = (sizeof png_ptr->jmp_buf_local);
size = sizeof png_ptr->jmp_buf_local;
if (png_ptr->jmp_buf_ptr != &png_ptr->jmp_buf_local)
{
/* This is an internal error in libpng: somehow we have been left
@@ -827,7 +825,7 @@ png_safe_error,(png_structp png_nonconst_ptr, png_const_charp error_message),
*/
if (image != NULL)
{
png_safecat(image->message, (sizeof image->message), 0, error_message);
png_safecat(image->message, sizeof image->message, 0, error_message);
image->warning_or_error |= PNG_IMAGE_ERROR;
/* Retrieve the jmp_buf from within the png_control, making this work for
@@ -839,10 +837,9 @@ png_safe_error,(png_structp png_nonconst_ptr, png_const_charp error_message),
/* Missing longjmp buffer, the following is to help debugging: */
{
size_t pos = png_safecat(image->message, (sizeof image->message), 0,
size_t pos = png_safecat(image->message, sizeof image->message, 0,
"bad longjmp: ");
png_safecat(image->message, (sizeof image->message), pos,
error_message);
png_safecat(image->message, sizeof image->message, pos, error_message);
}
}
@@ -860,16 +857,16 @@ png_safe_warning(png_structp png_nonconst_ptr, png_const_charp warning_message)
/* A warning is only logged if there is no prior warning or error. */
if (image->warning_or_error == 0)
{
png_safecat(image->message, (sizeof image->message), 0, warning_message);
png_safecat(image->message, sizeof image->message, 0, warning_message);
image->warning_or_error |= PNG_IMAGE_WARNING;
}
}
#endif
int /* PRIVATE */
png_safe_execute(png_imagep image_in, int (*function)(png_voidp), png_voidp arg)
png_safe_execute(png_imagep imageIn, int (*function)(png_voidp), png_voidp arg)
{
volatile png_imagep image = image_in;
volatile png_imagep image = imageIn;
volatile int result;
volatile png_voidp saved_error_buf;
jmp_buf safe_jmpbuf;

View File

@@ -112,8 +112,7 @@ png_get_compression_type(png_const_structrp png_ptr, png_const_inforp info_ptr)
}
png_uint_32 PNGAPI
png_get_x_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp
info_ptr)
png_get_x_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp info_ptr)
{
#ifdef PNG_pHYs_SUPPORTED
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
@@ -130,8 +129,7 @@ png_get_x_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp
}
png_uint_32 PNGAPI
png_get_y_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp
info_ptr)
png_get_y_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp info_ptr)
{
#ifdef PNG_pHYs_SUPPORTED
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
@@ -166,8 +164,7 @@ png_get_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp info_ptr)
#ifdef PNG_FLOATING_POINT_SUPPORTED
float PNGAPI
png_get_pixel_aspect_ratio(png_const_structrp png_ptr, png_const_inforp
info_ptr)
png_get_pixel_aspect_ratio(png_const_structrp png_ptr, png_const_inforp info_ptr)
{
#ifdef PNG_READ_pHYs_SUPPORTED
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
@@ -178,9 +175,6 @@ png_get_pixel_aspect_ratio(png_const_structrp png_ptr, png_const_inforp
return ((float)((float)info_ptr->y_pixels_per_unit
/(float)info_ptr->x_pixels_per_unit));
}
#else
PNG_UNUSED(png_ptr)
PNG_UNUSED(info_ptr)
#endif
return ((float)0.0);
@@ -209,9 +203,6 @@ png_get_pixel_aspect_ratio_fixed(png_const_structrp png_ptr,
(png_int_32)info_ptr->x_pixels_per_unit))
return res;
}
#else
PNG_UNUSED(png_ptr)
PNG_UNUSED(info_ptr)
#endif
return 0;
@@ -431,7 +422,6 @@ png_get_pHYs_dpi(png_const_structrp png_ptr, png_const_inforp info_ptr,
#endif /* PNG_EASY_ACCESS_SUPPORTED */
png_byte PNGAPI
png_get_channels(png_const_structrp png_ptr, png_const_inforp info_ptr)
{
@@ -441,7 +431,6 @@ png_get_channels(png_const_structrp png_ptr, png_const_inforp info_ptr)
return (0);
}
#ifdef PNG_READ_SUPPORTED
png_const_bytep PNGAPI
png_get_signature(png_const_structrp png_ptr, png_const_inforp info_ptr)
{
@@ -450,7 +439,6 @@ png_get_signature(png_const_structrp png_ptr, png_const_inforp info_ptr)
return (NULL);
}
#endif
#ifdef PNG_bKGD_SUPPORTED
png_uint_32 PNGAPI
@@ -534,31 +522,31 @@ png_get_cHRM_XYZ(png_const_structrp png_ptr, png_const_inforp info_ptr,
png_debug1(1, "in %s retrieval function", "cHRM_XYZ(float)");
if (red_X != NULL)
*red_X = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_X,
*red_X = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.redX,
"cHRM red X");
if (red_Y != NULL)
*red_Y = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_Y,
*red_Y = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.redY,
"cHRM red Y");
if (red_Z != NULL)
*red_Z = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_Z,
*red_Z = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.redZ,
"cHRM red Z");
if (green_X != NULL)
*green_X = png_float(png_ptr,
info_ptr->colorspace.end_points_XYZ.green_X, "cHRM green X");
info_ptr->colorspace.end_points_XYZ.greenX, "cHRM green X");
if (green_Y != NULL)
*green_Y = png_float(png_ptr,
info_ptr->colorspace.end_points_XYZ.green_Y, "cHRM green Y");
info_ptr->colorspace.end_points_XYZ.greenY, "cHRM green Y");
if (green_Z != NULL)
*green_Z = png_float(png_ptr,
info_ptr->colorspace.end_points_XYZ.green_Z, "cHRM green Z");
info_ptr->colorspace.end_points_XYZ.greenZ, "cHRM green Z");
if (blue_X != NULL)
*blue_X = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.blue_X,
*blue_X = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.blueX,
"cHRM blue X");
if (blue_Y != NULL)
*blue_Y = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.blue_Y,
*blue_Y = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.blueY,
"cHRM blue Y");
if (blue_Z != NULL)
*blue_Z = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.blue_Z,
*blue_Z = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.blueZ,
"cHRM blue Z");
return (PNG_INFO_cHRM);
}
@@ -582,23 +570,23 @@ png_get_cHRM_XYZ_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
png_debug1(1, "in %s retrieval function", "cHRM_XYZ");
if (int_red_X != NULL)
*int_red_X = info_ptr->colorspace.end_points_XYZ.red_X;
*int_red_X = info_ptr->colorspace.end_points_XYZ.redX;
if (int_red_Y != NULL)
*int_red_Y = info_ptr->colorspace.end_points_XYZ.red_Y;
*int_red_Y = info_ptr->colorspace.end_points_XYZ.redY;
if (int_red_Z != NULL)
*int_red_Z = info_ptr->colorspace.end_points_XYZ.red_Z;
*int_red_Z = info_ptr->colorspace.end_points_XYZ.redZ;
if (int_green_X != NULL)
*int_green_X = info_ptr->colorspace.end_points_XYZ.green_X;
*int_green_X = info_ptr->colorspace.end_points_XYZ.greenX;
if (int_green_Y != NULL)
*int_green_Y = info_ptr->colorspace.end_points_XYZ.green_Y;
*int_green_Y = info_ptr->colorspace.end_points_XYZ.greenY;
if (int_green_Z != NULL)
*int_green_Z = info_ptr->colorspace.end_points_XYZ.green_Z;
*int_green_Z = info_ptr->colorspace.end_points_XYZ.greenZ;
if (int_blue_X != NULL)
*int_blue_X = info_ptr->colorspace.end_points_XYZ.blue_X;
*int_blue_X = info_ptr->colorspace.end_points_XYZ.blueX;
if (int_blue_Y != NULL)
*int_blue_Y = info_ptr->colorspace.end_points_XYZ.blue_Y;
*int_blue_Y = info_ptr->colorspace.end_points_XYZ.blueY;
if (int_blue_Z != NULL)
*int_blue_Z = info_ptr->colorspace.end_points_XYZ.blue_Z;
*int_blue_Z = info_ptr->colorspace.end_points_XYZ.blueZ;
return (PNG_INFO_cHRM);
}
@@ -1062,7 +1050,7 @@ png_get_tRNS(png_const_structrp png_ptr, png_inforp info_ptr,
}
#endif
#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
int PNGAPI
png_get_unknown_chunks(png_const_structrp png_ptr, png_const_inforp info_ptr,
png_unknown_chunkpp unknowns)

View File

@@ -55,7 +55,7 @@
struct png_info_def
{
/* The following are necessary for every PNG file */
/* the following are necessary for every PNG file */
png_uint_32 width; /* width of image in pixels (from IHDR) */
png_uint_32 height; /* height of image in pixels (from IHDR) */
png_uint_32 valid; /* valid chunk data (see PNG_INFO_ below) */
@@ -70,15 +70,11 @@ struct png_info_def
png_byte filter_type; /* must be PNG_FILTER_TYPE_BASE (from IHDR) */
png_byte interlace_type; /* One of PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
/* The following are set by png_set_IHDR, called from the application on
* write, but the are never actually used by the write code.
*/
#ifdef PNG_READ_SUPPORTED
/* The following is informational only on read, and not used on writes. */
png_byte channels; /* number of data channels per pixel (1, 2, 3, 4) */
png_byte pixel_depth; /* number of bits per pixel */
png_byte spare_byte; /* to align the data, and for future use */
#ifdef PNG_READ_SUPPORTED
/* This is never set during write */
png_byte signature[8]; /* magic bytes read by libpng from start of file */
#endif
@@ -220,10 +216,11 @@ defined(PNG_READ_BACKGROUND_SUPPORTED)
/* New members added in libpng-1.0.6 */
png_uint_32 free_me; /* flags items libpng is responsible for freeing */
#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) || \
defined(PNG_HANDLE_AS_UNKNOWN_SUPPORTED)
/* Storage for unknown chunks that the library doesn't recognize. */
png_unknown_chunkp unknown_chunks;
unsigned int unknown_chunks_num;
int unknown_chunks_num;
#endif
#ifdef PNG_sPLT_SUPPORTED

View File

@@ -30,7 +30,7 @@ png_destroy_png_struct(png_structrp png_ptr)
* png_get_mem_ptr, so fake a temporary png_struct to support this.
*/
png_struct dummy_struct = *png_ptr;
memset(png_ptr, 0, (sizeof *png_ptr));
memset(png_ptr, 0, sizeof *png_ptr);
png_free(&dummy_struct, png_ptr);
# ifdef PNG_SETJMP_SUPPORTED
@@ -54,7 +54,7 @@ png_calloc,(png_const_structrp png_ptr, png_alloc_size_t size),PNG_ALLOCATED)
ret = png_malloc(png_ptr, size);
if (ret != NULL)
memset(ret, 0, size);
png_memset(ret, 0, size);
return ret;
}

View File

@@ -185,9 +185,6 @@ 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
int keep; /* unknown handling method */
#endif
/* First we make sure we have enough data for the 4 byte chunk name
* and the 4 byte chunk length before proceeding with decoding the
@@ -219,28 +216,14 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
if (chunk_name == png_IDAT)
{
/* This is here above the if/else case statement below because if the
* unknown handling marks 'IDAT' as unknown then the IDAT handling case is
* completely skipped.
*
* TODO: there must be a better way of doing this.
*/
if (png_ptr->mode & PNG_AFTER_IDAT)
png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
/* If we reach an IDAT chunk, this means we have read all of the
* header chunks, and we can start reading the image (or if this
* is called after the image has been read - we have an error).
*/
if (!(png_ptr->mode & PNG_HAVE_IHDR))
png_error(png_ptr, "Missing IHDR before IDAT");
else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
!(png_ptr->mode & PNG_HAVE_PLTE))
png_error(png_ptr, "Missing PLTE before IDAT");
png_ptr->mode |= PNG_HAVE_IDAT;
if (!(png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
if (png_ptr->push_length == 0)
return;
if (png_ptr->mode & PNG_AFTER_IDAT)
png_benign_error(png_ptr, "Too many IDATs found");
}
if (chunk_name == png_IHDR)
@@ -272,7 +255,7 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
}
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
else if ((keep = png_chunk_unknown_handling(png_ptr, chunk_name)) != 0)
else if (png_chunk_unknown_handling(png_ptr, chunk_name))
{
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
{
@@ -280,10 +263,23 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
return;
}
png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length, keep);
if (chunk_name == png_IDAT)
png_ptr->mode |= PNG_HAVE_IDAT;
png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length);
if (chunk_name == png_PLTE)
png_ptr->mode |= PNG_HAVE_PLTE;
else if (chunk_name == png_IDAT)
{
if (!(png_ptr->mode & PNG_HAVE_IHDR))
png_error(png_ptr, "Missing IHDR before IDAT");
else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
!(png_ptr->mode & PNG_HAVE_PLTE))
png_error(png_ptr, "Missing PLTE before IDAT");
}
}
#endif
@@ -299,7 +295,30 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
else if (chunk_name == png_IDAT)
{
/* If we reach an IDAT chunk, this means we have read all of the
* header chunks, and we can start reading the image (or if this
* is called after the image has been read - we have an error).
*/
if (!(png_ptr->mode & PNG_HAVE_IHDR))
png_error(png_ptr, "Missing IHDR before IDAT");
else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
!(png_ptr->mode & PNG_HAVE_PLTE))
png_error(png_ptr, "Missing PLTE before IDAT");
if (png_ptr->mode & PNG_HAVE_IDAT)
{
if (!(png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
if (png_ptr->push_length == 0)
return;
if (png_ptr->mode & PNG_AFTER_IDAT)
png_benign_error(png_ptr, "Too many IDATs found");
}
png_ptr->idat_size = png_ptr->push_length;
png_ptr->mode |= PNG_HAVE_IDAT;
png_ptr->process_mode = PNG_READ_IDAT_MODE;
png_push_have_info(png_ptr, info_ptr);
png_ptr->zstream.avail_out =
@@ -537,8 +556,7 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
png_push_save_buffer(png_ptr);
return;
}
png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length,
PNG_HANDLE_CHUNK_AS_DEFAULT);
png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length);
}
png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
@@ -631,7 +649,7 @@ png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length)
else
save_size = png_ptr->save_buffer_size;
memcpy(ptr, png_ptr->save_buffer_ptr, save_size);
png_memcpy(ptr, png_ptr->save_buffer_ptr, save_size);
length -= save_size;
ptr += save_size;
png_ptr->buffer_size -= save_size;
@@ -648,7 +666,7 @@ png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length)
else
save_size = png_ptr->current_buffer_size;
memcpy(ptr, png_ptr->current_buffer_ptr, save_size);
png_memcpy(ptr, png_ptr->current_buffer_ptr, save_size);
png_ptr->buffer_size -= save_size;
png_ptr->current_buffer_size -= save_size;
png_ptr->current_buffer_ptr += save_size;
@@ -697,13 +715,13 @@ png_push_save_buffer(png_structrp png_ptr)
png_error(png_ptr, "Insufficient memory for save_buffer");
}
memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size);
png_memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size);
png_free(png_ptr, old_buffer);
png_ptr->save_buffer_max = new_max;
}
if (png_ptr->current_buffer_size)
{
memcpy(png_ptr->save_buffer + png_ptr->save_buffer_size,
png_memcpy(png_ptr->save_buffer + png_ptr->save_buffer_size,
png_ptr->current_buffer_ptr, png_ptr->current_buffer_size);
png_ptr->save_buffer_size += png_ptr->current_buffer_size;
png_ptr->current_buffer_size = 0;
@@ -958,7 +976,7 @@ png_push_process_row(png_structrp png_ptr)
* it may not be in the future, so this was changed just to copy the
* interlaced row count:
*/
memcpy(png_ptr->prev_row, png_ptr->row_buf, row_info.rowbytes + 1);
png_memcpy(png_ptr->prev_row, png_ptr->row_buf, row_info.rowbytes + 1);
#ifdef PNG_READ_TRANSFORMS_SUPPORTED
if (png_ptr->transformations)
@@ -1192,7 +1210,7 @@ png_read_push_finish_row(png_structrp png_ptr)
if (png_ptr->interlaced)
{
png_ptr->row_number = 0;
memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
png_memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
do
{

268
pngpriv.h
View File

@@ -170,17 +170,12 @@
* the functions will be used without definitions.)
*
* NOTE: although all the API functions are declared here they are not all
* actually built! Because the declarations are still made it is necessary to
* fake out types that they depend on.
* actually built!
*/
#ifndef PNG_FP_EXPORT
# 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;
# endif
#endif
#ifndef PNG_FIXED_EXPORT
@@ -281,6 +276,13 @@ typedef const png_uint_16p * png_const_uint_16pp;
# define PNG_ZBUF_SIZE 65536L
#endif
/* PNG_STATIC is used to mark internal file scope functions if they need to be
* accessed for implementation tests (see the code in tests/?*).
*/
#ifndef PNG_STATIC
# define PNG_STATIC static
#endif
/* If warnings or errors are turned off the code is disabled or redirected here.
* From 1.5.4 functions have been added to allow very limited formatting of
* error and warning messages - this code will also be disabled here.
@@ -310,15 +312,9 @@ typedef const png_uint_16p * png_const_uint_16pp;
#ifdef __cplusplus
# define png_voidcast(type, value) static_cast<type>(value)
# define png_constcast(type, value) const_cast<type>(value)
# define png_aligncast(type, value) \
static_cast<type>(static_cast<void*>(value))
# define png_aligncastconst(type, value) \
static_cast<type>(static_cast<const void*>(value))
#else
# define png_voidcast(type, value) (value)
# define png_constcast(type, value) ((type)(value))
# define png_aligncast(type, value) ((void*)(value))
# define png_aligncastconst(type, value) ((const void*)(value))
#endif /* __cplusplus */
/* Some fixed point APIs are still required even if not exported because
@@ -390,6 +386,15 @@ typedef const png_uint_16p * png_const_uint_16pp;
# endif
#endif
/* Prior to 1.6.0 if _WINDOWS_ was defined 'lstrlenA' and 'CopyMemory' were used
* in place of the ISOC90 functions; this is no longer done in 1.6.0, however
* the use of png_foo as a macro defined to the C function is retained.
*/
#define png_strlen strlen
#define png_memcmp memcmp
#define png_memcpy memcpy
#define png_memset memset
/* 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 */
@@ -521,8 +526,8 @@ typedef const png_uint_16p * png_const_uint_16pp;
#define PNG_FLAG_ASSUME_sRGB 0x1000 /* Added to libpng-1.5.4 */
#define PNG_FLAG_OPTIMIZE_ALPHA 0x2000 /* Added to libpng-1.5.4 */
#define PNG_FLAG_DETECT_UNINITIALIZED 0x4000 /* Added to libpng-1.5.4 */
/* #define PNG_FLAG_KEEP_UNKNOWN_CHUNKS 0x8000 */
/* #define PNG_FLAG_KEEP_UNSAFE_CHUNKS 0x10000 */
#define PNG_FLAG_KEEP_UNKNOWN_CHUNKS 0x8000
#define PNG_FLAG_KEEP_UNSAFE_CHUNKS 0x10000
#define PNG_FLAG_LIBRARY_MISMATCH 0x20000
#define PNG_FLAG_STRIP_ERROR_NUMBERS 0x40000
#define PNG_FLAG_STRIP_ERROR_TEXT 0x80000
@@ -733,13 +738,8 @@ PNG_INTERNAL_FUNCTION(void,png_free_buffer_list,(png_structrp png_ptr,
/* Free the buffer list used by the compressed write code. */
#endif
#if defined(PNG_FLOATING_POINT_SUPPORTED) && \
!defined(PNG_FIXED_POINT_MACRO_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_sCAL_SUPPORTED) && \
defined(PNG_FLOATING_ARITHMETIC_SUPPORTED))
#if defined PNG_FLOATING_POINT_SUPPORTED &&\
!defined PNG_FIXED_POINT_MACRO_SUPPORTED
PNG_INTERNAL_FUNCTION(png_fixed_point,png_fixed,(png_const_structrp png_ptr,
double fp, png_const_charp text),PNG_EMPTY);
#endif
@@ -922,8 +922,8 @@ PNG_INTERNAL_FUNCTION(void,png_write_tEXt,(png_structrp png_ptr,
#endif
#ifdef PNG_WRITE_zTXt_SUPPORTED
PNG_INTERNAL_FUNCTION(void,png_write_zTXt,(png_structrp png_ptr, png_const_charp
key, png_const_charp text, png_size_t text_len, int compression),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_write_zTXt,(png_structrp png_ptr, png_const_charp key,
png_const_charp text, png_size_t text_len, int compression),PNG_EMPTY);
#endif
#ifdef PNG_WRITE_iTXt_SUPPORTED
@@ -943,8 +943,8 @@ PNG_INTERNAL_FUNCTION(void,png_write_oFFs,(png_structrp png_ptr,
#endif
#ifdef PNG_WRITE_pCAL_SUPPORTED
PNG_INTERNAL_FUNCTION(void,png_write_pCAL,(png_structrp png_ptr,
png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams,
PNG_INTERNAL_FUNCTION(void,png_write_pCAL,(png_structrp png_ptr, png_charp purpose,
png_int_32 X0, png_int_32 X1, int type, int nparams,
png_const_charp units, png_charpp params),PNG_EMPTY);
#endif
@@ -965,16 +965,14 @@ PNG_INTERNAL_FUNCTION(void,png_write_sCAL_s,(png_structrp png_ptr,
#endif
/* Called when finished processing a row of data */
PNG_INTERNAL_FUNCTION(void,png_write_finish_row,(png_structrp png_ptr),
PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_write_finish_row,(png_structrp png_ptr),PNG_EMPTY);
/* Internal use only. Called before first row of data */
PNG_INTERNAL_FUNCTION(void,png_write_start_row,(png_structrp png_ptr),
PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_write_start_row,(png_structrp png_ptr),PNG_EMPTY);
/* Combine a row of data, dealing with alpha, etc. if requested. 'row' is an
* array of png_ptr->width pixels. If the image is not interlaced or this
* is the final pass this just does a memcpy, otherwise the "display" flag
* is the final pass this just does a png_memcpy, otherwise the "display" flag
* is used to determine whether to copy pixels that are not in the current pass.
*
* Because 'png_do_read_interlace' (below) replicates pixels this allows this
@@ -1023,23 +1021,23 @@ PNG_INTERNAL_FUNCTION(void,png_do_write_interlace,(png_row_infop row_info,
/* Unfilter a row: check the filter value before calling this, there is no point
* calling it for PNG_FILTER_VALUE_NONE.
*/
PNG_INTERNAL_FUNCTION(void,png_read_filter_row,(png_structrp pp, png_row_infop
row_info, png_bytep row, png_const_bytep prev_row, int filter),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_read_filter_row,(png_structrp pp, png_row_infop row_info,
png_bytep row, png_const_bytep prev_row, int filter),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_read_filter_row_up_neon,(png_row_infop row_info,
png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub3_neon,(png_row_infop
row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub4_neon,(png_row_infop
row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_read_filter_row_avg3_neon,(png_row_infop
row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_read_filter_row_avg4_neon,(png_row_infop
row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth3_neon,(png_row_infop
row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth4_neon,(png_row_infop
row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub3_neon,(png_row_infop row_info,
png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub4_neon,(png_row_infop row_info,
png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_read_filter_row_avg3_neon,(png_row_infop row_info,
png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_read_filter_row_avg4_neon,(png_row_infop row_info,
png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth3_neon,(png_row_infop row_info,
png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth4_neon,(png_row_infop row_info,
png_bytep row, png_const_bytep prev_row),PNG_EMPTY);
/* Choose the best filter to use and filter the row data */
PNG_INTERNAL_FUNCTION(void,png_write_find_filter,(png_structrp png_ptr,
@@ -1213,120 +1211,113 @@ PNG_INTERNAL_FUNCTION(void,png_do_expand_16,(png_row_infop row_info,
*/
/* Decode the IHDR chunk */
PNG_INTERNAL_FUNCTION(void,png_handle_IHDR,(png_structrp png_ptr,
png_inforp info_ptr, png_uint_32 length),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_handle_PLTE,(png_structrp png_ptr,
png_inforp info_ptr, png_uint_32 length),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_handle_IEND,(png_structrp png_ptr,
png_inforp info_ptr, png_uint_32 length),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_handle_IHDR,(png_structrp png_ptr, png_inforp info_ptr,
png_uint_32 length),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_handle_PLTE,(png_structrp png_ptr, png_inforp info_ptr,
png_uint_32 length),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_handle_IEND,(png_structrp png_ptr, png_inforp info_ptr,
png_uint_32 length),PNG_EMPTY);
#ifdef PNG_READ_bKGD_SUPPORTED
PNG_INTERNAL_FUNCTION(void,png_handle_bKGD,(png_structrp png_ptr,
png_inforp info_ptr, png_uint_32 length),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_handle_bKGD,(png_structrp png_ptr, png_inforp info_ptr,
png_uint_32 length),PNG_EMPTY);
#endif
#ifdef PNG_READ_cHRM_SUPPORTED
PNG_INTERNAL_FUNCTION(void,png_handle_cHRM,(png_structrp png_ptr,
png_inforp info_ptr, png_uint_32 length),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_handle_cHRM,(png_structrp png_ptr, png_inforp info_ptr,
png_uint_32 length),PNG_EMPTY);
#endif
#ifdef PNG_READ_gAMA_SUPPORTED
PNG_INTERNAL_FUNCTION(void,png_handle_gAMA,(png_structrp png_ptr,
png_inforp info_ptr, png_uint_32 length),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_handle_gAMA,(png_structrp png_ptr, png_inforp info_ptr,
png_uint_32 length),PNG_EMPTY);
#endif
#ifdef PNG_READ_hIST_SUPPORTED
PNG_INTERNAL_FUNCTION(void,png_handle_hIST,(png_structrp png_ptr,
png_inforp info_ptr, png_uint_32 length),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_handle_hIST,(png_structrp png_ptr, png_inforp info_ptr,
png_uint_32 length),PNG_EMPTY);
#endif
#ifdef PNG_READ_iCCP_SUPPORTED
PNG_INTERNAL_FUNCTION(void,png_handle_iCCP,(png_structrp png_ptr,
png_inforp info_ptr, png_uint_32 length),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_handle_iCCP,(png_structrp png_ptr, png_inforp info_ptr,
png_uint_32 length),PNG_EMPTY);
#endif /* PNG_READ_iCCP_SUPPORTED */
#ifdef PNG_READ_iTXt_SUPPORTED
PNG_INTERNAL_FUNCTION(void,png_handle_iTXt,(png_structrp png_ptr,
png_inforp info_ptr, png_uint_32 length),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_handle_iTXt,(png_structrp png_ptr, png_inforp info_ptr,
png_uint_32 length),PNG_EMPTY);
#endif
#ifdef PNG_READ_oFFs_SUPPORTED
PNG_INTERNAL_FUNCTION(void,png_handle_oFFs,(png_structrp png_ptr,
png_inforp info_ptr, png_uint_32 length),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_handle_oFFs,(png_structrp png_ptr, png_inforp info_ptr,
png_uint_32 length),PNG_EMPTY);
#endif
#ifdef PNG_READ_pCAL_SUPPORTED
PNG_INTERNAL_FUNCTION(void,png_handle_pCAL,(png_structrp png_ptr,
png_inforp info_ptr, png_uint_32 length),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_handle_pCAL,(png_structrp png_ptr, png_inforp info_ptr,
png_uint_32 length),PNG_EMPTY);
#endif
#ifdef PNG_READ_pHYs_SUPPORTED
PNG_INTERNAL_FUNCTION(void,png_handle_pHYs,(png_structrp png_ptr,
png_inforp info_ptr, png_uint_32 length),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_handle_pHYs,(png_structrp png_ptr, png_inforp info_ptr,
png_uint_32 length),PNG_EMPTY);
#endif
#ifdef PNG_READ_sBIT_SUPPORTED
PNG_INTERNAL_FUNCTION(void,png_handle_sBIT,(png_structrp png_ptr,
png_inforp info_ptr, png_uint_32 length),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_handle_sBIT,(png_structrp png_ptr, png_inforp info_ptr,
png_uint_32 length),PNG_EMPTY);
#endif
#ifdef PNG_READ_sCAL_SUPPORTED
PNG_INTERNAL_FUNCTION(void,png_handle_sCAL,(png_structrp png_ptr,
png_inforp info_ptr, png_uint_32 length),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_handle_sCAL,(png_structrp png_ptr, png_inforp info_ptr,
png_uint_32 length),PNG_EMPTY);
#endif
#ifdef PNG_READ_sPLT_SUPPORTED
PNG_INTERNAL_FUNCTION(void,png_handle_sPLT,(png_structrp png_ptr,
png_inforp info_ptr, png_uint_32 length),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_handle_sPLT,(png_structrp png_ptr, png_inforp info_ptr,
png_uint_32 length),PNG_EMPTY);
#endif /* PNG_READ_sPLT_SUPPORTED */
#ifdef PNG_READ_sRGB_SUPPORTED
PNG_INTERNAL_FUNCTION(void,png_handle_sRGB,(png_structrp png_ptr,
png_inforp info_ptr, png_uint_32 length),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_handle_sRGB,(png_structrp png_ptr, png_inforp info_ptr,
png_uint_32 length),PNG_EMPTY);
#endif
#ifdef PNG_READ_tEXt_SUPPORTED
PNG_INTERNAL_FUNCTION(void,png_handle_tEXt,(png_structrp png_ptr,
png_inforp info_ptr, png_uint_32 length),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_handle_tEXt,(png_structrp png_ptr, png_inforp info_ptr,
png_uint_32 length),PNG_EMPTY);
#endif
#ifdef PNG_READ_tIME_SUPPORTED
PNG_INTERNAL_FUNCTION(void,png_handle_tIME,(png_structrp png_ptr,
png_inforp info_ptr, png_uint_32 length),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_handle_tIME,(png_structrp png_ptr, png_inforp info_ptr,
png_uint_32 length),PNG_EMPTY);
#endif
#ifdef PNG_READ_tRNS_SUPPORTED
PNG_INTERNAL_FUNCTION(void,png_handle_tRNS,(png_structrp png_ptr,
png_inforp info_ptr, png_uint_32 length),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_handle_tRNS,(png_structrp png_ptr, png_inforp info_ptr,
png_uint_32 length),PNG_EMPTY);
#endif
#ifdef PNG_READ_zTXt_SUPPORTED
PNG_INTERNAL_FUNCTION(void,png_handle_zTXt,(png_structrp png_ptr,
PNG_INTERNAL_FUNCTION(void,png_handle_zTXt,(png_structrp png_ptr, png_inforp info_ptr,
png_uint_32 length),PNG_EMPTY);
#endif
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
PNG_INTERNAL_FUNCTION(void,png_handle_unknown,(png_structrp png_ptr,
png_inforp info_ptr, png_uint_32 length),PNG_EMPTY);
#endif
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'
* argument is either non-zero for a known chunk that has been set to be
* handled as unknown or zero for an unknown chunk. By default the function
* just skips the chunk or errors out if it is critical.
*/
#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
#ifdef PNG_SET_UNKNOWN_CHUNKS_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.
*/
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
/* Exactly as png_handle_as_unknown() except that the argument is a 32-bit chunk
* name, not a string.
*/
PNG_INTERNAL_FUNCTION(int,png_chunk_unknown_handling,(png_structrp png_ptr,
png_uint_32 chunk_name),PNG_EMPTY);
#endif
#endif /* PNG_READ_UNKNOWN_CHUNKS_SUPPORTED */
#endif /* PNG_READ_SUPPORTED */
/* Handle the transformations for reading and writing */
#ifdef PNG_READ_TRANSFORMS_SUPPORTED
@@ -1339,8 +1330,7 @@ PNG_INTERNAL_FUNCTION(void,png_do_write_transformations,(png_structrp png_ptr,
#endif
#ifdef PNG_READ_TRANSFORMS_SUPPORTED
PNG_INTERNAL_FUNCTION(void,png_init_read_transformations,(png_structrp png_ptr),
PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_init_read_transformations,(png_structrp png_ptr),PNG_EMPTY);
#endif
#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
@@ -1351,31 +1341,26 @@ PNG_INTERNAL_FUNCTION(void,png_push_read_sig,(png_structrp png_ptr,
PNG_INTERNAL_FUNCTION(void,png_push_check_crc,(png_structrp png_ptr),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_push_crc_skip,(png_structrp png_ptr,
png_uint_32 length),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_push_crc_finish,(png_structrp png_ptr),
PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_push_save_buffer,(png_structrp png_ptr),
PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_push_crc_finish,(png_structrp png_ptr),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_push_save_buffer,(png_structrp png_ptr),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_push_restore_buffer,(png_structrp png_ptr,
png_bytep buffer, png_size_t buffer_length),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_push_read_IDAT,(png_structrp png_ptr),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_process_IDAT_data,(png_structrp png_ptr,
png_bytep buffer, png_size_t buffer_length),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_push_process_row,(png_structrp png_ptr),
PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_push_process_row,(png_structrp png_ptr),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_push_handle_unknown,(png_structrp png_ptr,
png_inforp info_ptr, png_uint_32 length),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_push_have_info,(png_structrp png_ptr,
png_inforp info_ptr),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_push_have_end,(png_structrp png_ptr,
png_inforp info_ptr),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_push_have_row,(png_structrp png_ptr,
png_bytep row),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_push_have_row,(png_structrp png_ptr, png_bytep row),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_push_read_end,(png_structrp png_ptr,
png_inforp info_ptr),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_process_some_data,(png_structrp png_ptr,
png_inforp info_ptr),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_read_push_finish_row,(png_structrp png_ptr),
PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_read_push_finish_row,(png_structrp png_ptr),PNG_EMPTY);
# ifdef PNG_READ_tEXt_SUPPORTED
PNG_INTERNAL_FUNCTION(void,png_push_handle_tEXt,(png_structrp png_ptr,
png_inforp info_ptr, png_uint_32 length),PNG_EMPTY);
@@ -1442,7 +1427,7 @@ PNG_INTERNAL_FUNCTION(int,png_colorspace_set_sRGB,(png_const_structrp png_ptr,
#ifdef PNG_iCCP_SUPPORTED
PNG_INTERNAL_FUNCTION(int,png_colorspace_set_ICC,(png_const_structrp png_ptr,
png_colorspacerp colorspace, png_const_charp name,
png_uint_32 profile_length, png_const_bytep profile, int color_type),
png_uint_32 profile_length, png_const_bytep profile, int preferred),
PNG_EMPTY);
/* The 'name' is used for information only */
@@ -1453,20 +1438,18 @@ PNG_INTERNAL_FUNCTION(int,png_icc_check_length,(png_const_structrp png_ptr,
PNG_INTERNAL_FUNCTION(int,png_icc_check_header,(png_const_structrp png_ptr,
png_colorspacerp colorspace, png_const_charp name,
png_uint_32 profile_length,
png_const_bytep profile /* first 132 bytes only */, int color_type),
PNG_EMPTY);
png_const_bytep profile /* first 132 bytes only */), PNG_EMPTY);
PNG_INTERNAL_FUNCTION(int,png_icc_check_tag_table,(png_const_structrp png_ptr,
png_colorspacerp colorspace, png_const_charp name,
png_uint_32 profile_length,
png_const_bytep profile /* header plus whole tag table */), PNG_EMPTY);
PNG_INTERNAL_FUNCTION(int,png_icc_set_gAMA_and_cHRM,(
png_const_structrp png_ptr, png_colorspacerp colorspace,
png_const_charp name, png_const_bytep profile, uLong adler), PNG_EMPTY);
/* 'adler' is the Adler32 checksum of the uncompressed profile data. It may
* be zero to indicate that it is not available. It is used, if provided,
* as a fast check on the profile when checking to see if it is sRGB. The
* result is false only if an error is detected in the profile; the routine
* may return true without actually setting cHRM and gAMA values.
png_const_charp name, png_const_bytep profile, uLong adler, int preferred),
PNG_EMPTY);
/* 'adler' is the Adler32 checksum of the uncompressed profile data, it may
* be 0 to indicate that it is not available. It is used, if provided, as a
* fast check on the profile when checking to see if it is sRGB.
*/
#endif /* iCCP */
@@ -1563,14 +1546,14 @@ PNG_INTERNAL_FUNCTION(void,png_formatted_warning,(png_const_structrp png_ptr,
png_warning_parameters p, png_const_charp message),PNG_EMPTY);
/* 'message' follows the X/Open approach of using @1, @2 to insert
* parameters previously supplied using the above functions. Errors in
* specifying the parameters will simply result in garbage substitutions.
* specifying the parameters will simple result in garbage substitutions.
*/
#endif
#ifdef PNG_BENIGN_ERRORS_SUPPORTED
/* Application errors (new in 1.6); use these functions (declared below) for
* errors in the parameters or order of API function calls on read. The
* 'warning' should be used for an error that can be handled completely; the
* 'warning' should be used for an error that can be handled completely, the
* 'error' for one which can be handled safely but which may lose application
* information or settings.
*
@@ -1585,7 +1568,7 @@ PNG_INTERNAL_FUNCTION(void,png_formatted_warning,(png_const_structrp png_ptr,
PNG_INTERNAL_FUNCTION(void,png_app_warning,(png_const_structrp png_ptr,
png_const_charp message),PNG_EMPTY);
/* The application provided invalid parameters to an API function or called
* an API function at the wrong time, libpng can completely recover.
* an API function at the wrong time, libpng can completely recovered.
*/
PNG_INTERNAL_FUNCTION(void,png_app_error,(png_const_structrp png_ptr,
@@ -1601,7 +1584,7 @@ PNG_INTERNAL_FUNCTION(void,png_app_error,(png_const_structrp png_ptr,
/* ASCII to FP interfaces, currently only implemented if sCAL
* support is required.
*/
#if defined(PNG_sCAL_SUPPORTED)
#if defined(PNG_READ_sCAL_SUPPORTED)
/* MAX_DIGITS is actually the maximum number of characters in an sCAL
* width or height, derived from the precision (number of significant
* digits - a build time settable option) and assumptions about the
@@ -1619,7 +1602,7 @@ PNG_INTERNAL_FUNCTION(void,png_ascii_from_fp,(png_const_structrp png_ptr,
PNG_INTERNAL_FUNCTION(void,png_ascii_from_fixed,(png_const_structrp png_ptr,
png_charp ascii, png_size_t size, png_fixed_point fp),PNG_EMPTY);
#endif /* FIXED_POINT */
#endif /* sCAL */
#endif /* READ_sCAL */
#if defined(PNG_sCAL_SUPPORTED) || defined(PNG_pCAL_SUPPORTED)
/* An internal API to validate the format of a floating point number.
@@ -1643,7 +1626,7 @@ PNG_INTERNAL_FUNCTION(void,png_ascii_from_fixed,(png_const_structrp png_ptr,
* NOTE: The dangling E problem.
* There is a PNG valid floating point number in the following:
*
* PNG floating point numbers are not greedy.
* PNG floating point numb1.ers are not greedy.
*
* Working this out requires *TWO* character lookahead (because of the
* sign), the parser does not do this - it will fail at the 'r' - this
@@ -1694,14 +1677,14 @@ PNG_INTERNAL_FUNCTION(void,png_ascii_from_fixed,(png_const_structrp png_ptr,
#define PNG_FP_IS_POSITIVE(state) (((state) & PNG_FP_NZ_MASK) == PNG_FP_Z_MASK)
#define PNG_FP_IS_NEGATIVE(state) (((state) & PNG_FP_NZ_MASK) == PNG_FP_NZ_MASK)
/* The actual parser. This can be called repeatedly. It updates
/* The actual parser. This can be called repeatedly, it updates
* the index into the string and the state variable (which must
* be initialized to 0). It returns a result code, as above. There
* be initialzed to 0). It returns a result code, as above. There
* is no point calling the parser any more if it fails to advance to
* the end of the string - it is stuck on an invalid character (or
* terminated by '\0').
*
* Note that the pointer will consume an E or even an E+ and then leave
* Note that the pointer will consume an E or even an E+ then leave
* a 'maybe' state even though a preceding integer.fraction is valid.
* The PNG_FP_WAS_VALID flag indicates that a preceding substring was
* a valid number. It's possible to recover from this by calling
@@ -1741,28 +1724,22 @@ PNG_INTERNAL_FUNCTION(png_fixed_point,png_muldiv_warn,
png_int_32 divided_by),PNG_EMPTY);
#endif
#ifdef PNG_GAMMA_SUPPORTED
#ifdef PNG_READ_GAMMA_SUPPORTED
/* Calculate a reciprocal - used for gamma values. This returns
* 0 if the argument is 0 in order to maintain an undefined value;
* 0 if the argument is 0 in order to maintain an undefined value,
* there are no warnings.
*/
PNG_INTERNAL_FUNCTION(png_fixed_point,png_reciprocal,(png_fixed_point a),
PNG_EMPTY);
#ifdef PNG_READ_GAMMA_SUPPORTED
/* The same but gives a reciprocal of the product of two fixed point
* values. Accuracy is suitable for gamma calculations but this is
* not exact - use png_muldiv for that. Only required at present on read.
* not exact - use png_muldiv for that.
*/
PNG_INTERNAL_FUNCTION(png_fixed_point,png_reciprocal2,(png_fixed_point a,
png_fixed_point b),PNG_EMPTY);
#endif
/* Return true if the gamma value is significantly different from 1.0 */
PNG_INTERNAL_FUNCTION(int,png_gamma_significant,(png_fixed_point gamma_value),
PNG_EMPTY);
#endif
#ifdef PNG_READ_GAMMA_SUPPORTED
/* Internal fixed point gamma correction. These APIs are called as
* required to convert single values - they don't need to be fast,
@@ -1773,6 +1750,8 @@ PNG_INTERNAL_FUNCTION(int,png_gamma_significant,(png_fixed_point gamma_value),
*/
PNG_INTERNAL_FUNCTION(png_uint_16,png_gamma_correct,(png_structrp png_ptr,
unsigned int value, png_fixed_point gamma_value),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(int,png_gamma_significant,(png_fixed_point gamma_value),
PNG_EMPTY);
PNG_INTERNAL_FUNCTION(png_uint_16,png_gamma_16bit_correct,(unsigned int value,
png_fixed_point gamma_value),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(png_byte,png_gamma_8bit_correct,(unsigned int value,
@@ -1826,20 +1805,15 @@ PNG_INTERNAL_FUNCTION(void,png_safe_warning,(png_structp png_ptr,
PNG_INTERNAL_FUNCTION(int,png_safe_execute,(png_imagep image,
int (*function)(png_voidp), png_voidp arg),PNG_EMPTY);
/* Utility to log an error; this also cleans up the png_image; the function
/* Utility to log an error, this also cleans up the png_image, the function
* always returns 0 (false).
*/
PNG_INTERNAL_FUNCTION(int,png_image_error,(png_imagep image,
png_const_charp error_message),PNG_EMPTY);
#ifndef PNG_SIMPLIFIED_READ_SUPPORTED
/* png_image_free is used by the write code but not exported */
PNG_INTERNAL_FUNCTION(void, png_image_free, (png_imagep image), PNG_EMPTY);
#endif /* !SIMPLIFIED_READ */
#endif /* SIMPLIFIED READ/WRITE */
/* Maintainer: Put new private prototypes here ^ */
/* Maintainer: Put new private prototypes here ^ and in libpngpf.3 */
#include "pngdebug.h"

226
pngread.c
View File

@@ -91,10 +91,6 @@ png_create_read_struct_2,(png_const_charp user_png_ver, png_voidp error_ptr,
void PNGAPI
png_read_info(png_structrp png_ptr, png_inforp info_ptr)
{
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
int keep;
#endif
png_debug(1, "in png_read_info");
if (png_ptr == NULL || info_ptr == NULL)
@@ -108,30 +104,13 @@ png_read_info(png_structrp png_ptr, png_inforp info_ptr)
png_uint_32 length = png_read_chunk_header(png_ptr);
png_uint_32 chunk_name = png_ptr->chunk_name;
/* IDAT logic needs to happen here to simplify getting the two flags
* right.
*/
if (chunk_name == png_IDAT)
{
if (!(png_ptr->mode & PNG_HAVE_IHDR))
png_chunk_error(png_ptr, "Missing IHDR before IDAT");
else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
!(png_ptr->mode & PNG_HAVE_PLTE))
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_ptr->mode |= PNG_HAVE_IDAT;
}
else if (png_ptr->mode & PNG_HAVE_IDAT)
png_ptr->mode |= PNG_AFTER_IDAT;
/* This should be a binary subdivision search or a hash for
* matching the chunk name rather than a linear search.
*/
if (chunk_name == png_IDAT)
if (png_ptr->mode & PNG_AFTER_IDAT)
png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
if (chunk_name == png_IHDR)
png_handle_IHDR(png_ptr, info_ptr, length);
@@ -139,16 +118,26 @@ png_read_info(png_structrp png_ptr, png_inforp info_ptr)
png_handle_IEND(png_ptr, info_ptr, length);
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
else if ((keep = png_chunk_unknown_handling(png_ptr, chunk_name)) != 0)
else if (png_chunk_unknown_handling(png_ptr, chunk_name) !=
PNG_HANDLE_CHUNK_AS_DEFAULT)
{
png_handle_unknown(png_ptr, info_ptr, length, keep);
if (chunk_name == png_IDAT)
png_ptr->mode |= PNG_HAVE_IDAT;
png_handle_unknown(png_ptr, info_ptr, length);
if (chunk_name == png_PLTE)
png_ptr->mode |= PNG_HAVE_PLTE;
else if (chunk_name == png_IDAT)
{
png_ptr->idat_size = 0; /* It has been consumed */
if (!(png_ptr->mode & PNG_HAVE_IHDR))
png_error(png_ptr, "Missing IHDR before IDAT");
else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
!(png_ptr->mode & PNG_HAVE_PLTE))
png_error(png_ptr, "Missing PLTE before IDAT");
break;
}
}
@@ -158,7 +147,15 @@ png_read_info(png_structrp png_ptr, png_inforp info_ptr)
else if (chunk_name == png_IDAT)
{
if (!(png_ptr->mode & PNG_HAVE_IHDR))
png_error(png_ptr, "Missing IHDR before IDAT");
else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
!(png_ptr->mode & PNG_HAVE_PLTE))
png_error(png_ptr, "Missing PLTE before IDAT");
png_ptr->idat_size = length;
png_ptr->mode |= PNG_HAVE_IDAT;
break;
}
@@ -248,8 +245,7 @@ png_read_info(png_structrp png_ptr, png_inforp info_ptr)
#endif
else
png_handle_unknown(png_ptr, info_ptr, length,
PNG_HANDLE_CHUNK_AS_DEFAULT);
png_handle_unknown(png_ptr, info_ptr, length);
}
}
#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
@@ -478,7 +474,7 @@ png_read_row(png_structrp png_ptr, png_bytep row, png_bytep dsp_row)
* it may not be in the future, so this was changed just to copy the
* interlaced count:
*/
memcpy(png_ptr->prev_row, png_ptr->row_buf, row_info.rowbytes + 1);
png_memcpy(png_ptr->prev_row, png_ptr->row_buf, row_info.rowbytes + 1);
#ifdef PNG_MNG_FEATURES_SUPPORTED
if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
@@ -687,10 +683,6 @@ png_read_image(png_structrp png_ptr, png_bytepp image)
void PNGAPI
png_read_end(png_structrp png_ptr, png_inforp info_ptr)
{
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
int keep;
#endif
png_debug(1, "in png_read_end");
if (png_ptr == NULL)
@@ -699,10 +691,7 @@ png_read_end(png_structrp png_ptr, png_inforp info_ptr)
/* If png_read_end is called in the middle of reading the rows there may
* still be pending IDAT data and an owned zstream. Deal with this here.
*/
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
if (!png_chunk_unknown_handling(png_ptr, png_IDAT))
#endif
png_read_finish_IDAT(png_ptr);
png_read_finish_IDAT(png_ptr);
#ifdef PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED
/* Report invalid palette index; added at libng-1.5.10 */
@@ -723,14 +712,15 @@ png_read_end(png_structrp png_ptr, png_inforp info_ptr)
png_handle_IEND(png_ptr, info_ptr, length);
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
else if ((keep = png_chunk_unknown_handling(png_ptr, chunk_name)) != 0)
else if (png_chunk_unknown_handling(png_ptr, chunk_name) !=
PNG_HANDLE_CHUNK_AS_DEFAULT)
{
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_handle_unknown(png_ptr, info_ptr, length, keep);
png_handle_unknown(png_ptr, info_ptr, length);
if (chunk_name == png_PLTE)
png_ptr->mode |= PNG_HAVE_PLTE;
}
@@ -835,8 +825,7 @@ png_read_end(png_structrp png_ptr, png_inforp info_ptr)
#endif
else
png_handle_unknown(png_ptr, info_ptr, length,
PNG_HANDLE_CHUNK_AS_DEFAULT);
png_handle_unknown(png_ptr, info_ptr, length);
} while (!(png_ptr->mode & PNG_HAVE_IEND));
}
#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
@@ -877,12 +866,11 @@ 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)
#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
png_free(png_ptr, png_ptr->unknown_chunk.data);
#endif
#ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
png_free(png_ptr, png_ptr->chunk_list);
#endif
@@ -945,7 +933,7 @@ png_read_png(png_structrp png_ptr, png_inforp info_ptr,
* PNG file before the first IDAT (image data chunk).
*/
png_read_info(png_ptr, info_ptr);
if (info_ptr->height > PNG_UINT_32_MAX/(sizeof (png_bytep)))
if (info_ptr->height > PNG_UINT_32_MAX/png_sizeof(png_bytep))
png_error(png_ptr, "Image is too high to process with png_read_png()");
/* -------------- image transformations start here ------------------- */
@@ -1092,7 +1080,7 @@ png_read_png(png_structrp png_ptr, png_inforp info_ptr,
png_uint_32 iptr;
info_ptr->row_pointers = (png_bytepp)png_malloc(png_ptr,
info_ptr->height * (sizeof (png_bytep)));
info_ptr->height * png_sizeof(png_bytep));
for (iptr=0; iptr<info_ptr->height; iptr++)
info_ptr->row_pointers[iptr] = NULL;
@@ -1157,8 +1145,8 @@ typedef struct
png_voidp colormap;
png_const_colorp background;
/* Local variables: */
png_voidp local_row;
png_voidp first_row;
png_bytep local_row;
png_bytep 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 */
@@ -1181,7 +1169,7 @@ png_image_read_init(png_imagep image)
/* And set the rest of the structure to NULL to ensure that the various
* fields are consistent.
*/
memset(image, 0, (sizeof *image));
memset(image, 0, sizeof *image);
image->version = PNG_IMAGE_VERSION;
if (png_ptr != NULL)
@@ -1191,11 +1179,11 @@ png_image_read_init(png_imagep image)
if (info_ptr != NULL)
{
png_controlp control = png_voidcast(png_controlp,
png_malloc_warn(png_ptr, (sizeof *control)));
png_malloc_warn(png_ptr, sizeof *control));
if (control != NULL)
{
memset(control, 0, (sizeof *control));
png_memset(control, 0, sizeof *control);
control->png_ptr = png_ptr;
control->info_ptr = info_ptr;
@@ -1357,10 +1345,6 @@ png_image_begin_read_from_stdio(png_imagep image, FILE* file)
"png_image_begin_read_from_stdio: invalid argument");
}
else if (image != NULL)
return png_image_error(image,
"png_image_begin_read_from_stdio: incorrect PNG_IMAGE_VERSION");
return 0;
}
@@ -1395,10 +1379,6 @@ png_image_begin_read_from_file(png_imagep image, const char *file_name)
"png_image_begin_read_from_file: invalid argument");
}
else if (image != NULL)
return png_image_error(image,
"png_image_begin_read_from_file: incorrect PNG_IMAGE_VERSION");
return 0;
}
#endif /* PNG_STDIO_SUPPORTED */
@@ -1419,7 +1399,7 @@ png_image_memory_read(png_structp png_ptr, png_bytep out, png_size_t need)
if (memory != NULL && size >= need)
{
memcpy(out, memory, need);
png_memcpy(out, memory, need);
cp->memory = memory + need;
cp->size = size - need;
return;
@@ -1460,10 +1440,6 @@ int PNGAPI png_image_begin_read_from_memory(png_imagep image,
"png_image_begin_read_from_memory: invalid argument");
}
else if (image != NULL)
return png_image_error(image,
"png_image_begin_read_from_memory: incorrect PNG_IMAGE_VERSION");
return 0;
}
@@ -1486,26 +1462,31 @@ png_image_skip_unused_chunks(png_structrp png_ptr)
*
* This provides a small performance improvement and eliminates any
* potential vulnerability to security problems in the unused chunks.
*
* TODO: make it so that this is an explicit list to process, not a list
* to ignore?
*/
{
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 */
105, 67, 67, 80, '\0', /* iCCP */
115, 66, 73, 84, '\0', /* sBIT */
115, 82, 71, 66, '\0', /* sRGB */
};
static PNG_CONST png_byte chunks_to_ignore[] = {
104, 73, 83, 84, '\0', /* hIST */
105, 84, 88, 116, '\0', /* iTXt */
111, 70, 70, 115, '\0', /* oFFs */
112, 67, 65, 76, '\0', /* pCAL */
112, 72, 89, 115, '\0', /* pHYs */
115, 67, 65, 76, '\0', /* sCAL */
115, 80, 76, 84, '\0', /* sPLT */
116, 69, 88, 116, '\0', /* tEXt */
116, 73, 77, 69, '\0', /* tIME */
122, 84, 88, 116, '\0' /* zTXt */
};
/* Ignore unknown chunks and all other chunks except for the
* IHDR, PLTE, tRNS, IDAT, and IEND chunks.
*/
png_set_keep_unknown_chunks(png_ptr, PNG_HANDLE_CHUNK_NEVER,
NULL, -1);
/* Ignore unknown chunks */
png_set_keep_unknown_chunks(png_ptr, 1 /* PNG_HANDLE_CHUNK_NEVER */,
NULL, 0);
/* But do not ignore image data handling chunks */
png_set_keep_unknown_chunks(png_ptr, PNG_HANDLE_CHUNK_AS_DEFAULT,
chunks_to_process, (sizeof chunks_to_process)/5);
/* Ignore known but unused chunks */
png_set_keep_unknown_chunks(png_ptr, 1 /* PNG_HANDLE_CHUNK_NEVER */,
chunks_to_ignore, (sizeof chunks_to_ignore)/5);
}
}
@@ -2039,7 +2020,7 @@ png_image_read_colormap(png_voidp argument)
/* png_create_colormap_entry just takes an RGBA and writes the
* corresponding color-map entry using the format from 'image',
* including the required conversion to sRGB or linear as
* including the required convertion to sRGB or linear as
* appropriate. The input values are always either sRGB (if the
* gamma correction flag is 0) or 0..255 scaled file encoded values
* (if the function must gamma correct them).
@@ -2549,8 +2530,7 @@ png_image_read_colormap(png_voidp argument)
/* Compare the newly-created color-map entry with the one the
* PNG_CMAP_RGB algorithm will use. If the two entries don't
* match, add the new one and set this as the background
* index.
* match, add the new one and set this as the background index.
*/
if (memcmp((png_const_bytep)display->colormap +
sample_size * cmap_entries,
@@ -2791,7 +2771,7 @@ png_image_read_and_map(png_voidp argument)
png_uint_32 height = image->height;
png_uint_32 width = image->width;
int proc = display->colormap_processing;
png_bytep first_row = png_voidcast(png_bytep, display->first_row);
png_bytep first_row = display->first_row;
ptrdiff_t step_row = display->row_bytes;
int pass;
@@ -2821,7 +2801,7 @@ png_image_read_and_map(png_voidp argument)
for (; y<height; y += stepy)
{
png_bytep inrow = png_voidcast(png_bytep, display->local_row);
png_bytep inrow = display->local_row;
png_bytep outrow = first_row + y * step_row;
png_const_bytep end_row = outrow + width;
@@ -3031,18 +3011,14 @@ png_image_read_colormapped(png_voidp argument)
* size libpng requires and call the relevant processing routine safely.
*/
{
png_voidp first_row = display->buffer;
png_bytep first_row = png_voidcast(png_bytep, display->buffer);
ptrdiff_t row_bytes = display->row_stride;
/* The following expression is designed to work correctly whether it gives
* a signed or an unsigned result.
*/
if (row_bytes < 0)
{
char *ptr = png_voidcast(char*, first_row);
ptr += (image->height-1) * (-row_bytes);
first_row = png_voidcast(png_voidp, ptr);
}
first_row += (image->height-1) * (-row_bytes);
display->first_row = first_row;
display->row_bytes = row_bytes;
@@ -3051,7 +3027,8 @@ png_image_read_colormapped(png_voidp argument)
if (passes == 0)
{
int result;
png_voidp row = png_malloc(png_ptr, png_get_rowbytes(png_ptr, info_ptr));
png_bytep row = png_voidcast(png_bytep, png_malloc(png_ptr,
png_get_rowbytes(png_ptr, info_ptr)));
display->local_row = row;
result = png_safe_execute(image, png_image_read_and_map, display);
@@ -3068,7 +3045,7 @@ png_image_read_colormapped(png_voidp argument)
while (--passes >= 0)
{
png_uint_32 y = image->height;
png_bytep row = png_voidcast(png_bytep, display->first_row);
png_bytep row = display->first_row;
while (y-- > 0)
{
@@ -3109,6 +3086,7 @@ png_image_read_composite(png_voidp argument)
{
png_uint_32 height = image->height;
png_uint_32 width = image->width;
png_bytep first_row = display->first_row;
ptrdiff_t step_row = display->row_bytes;
unsigned int channels = (image->format & PNG_FORMAT_FLAG_COLOR) ? 3 : 1;
int pass;
@@ -3140,17 +3118,13 @@ png_image_read_composite(png_voidp argument)
for (; y<height; y += stepy)
{
png_bytep inrow = png_voidcast(png_bytep, display->local_row);
png_bytep outrow;
png_const_bytep end_row;
png_bytep inrow = display->local_row;
png_bytep outrow = first_row + y * step_row;
png_const_bytep end_row = outrow + width * channels;
/* Read the row, which is packed: */
png_read_row(png_ptr, inrow, NULL);
outrow = png_voidcast(png_bytep, display->first_row);
outrow += y * step_row;
end_row = outrow + width * channels;
/* Now do the composition on each pixel in this row. */
outrow += startx;
for (; outrow < end_row; outrow += stepx)
@@ -3268,13 +3242,12 @@ png_image_read_background(png_voidp argument)
* Unlike the code above ALPHA_OPTIMIZED has *not* been done.
*/
{
png_bytep first_row = png_voidcast(png_bytep, display->first_row);
png_bytep first_row = display->first_row;
ptrdiff_t step_row = display->row_bytes;
for (pass = 0; pass < passes; ++pass)
{
png_bytep row = png_voidcast(png_bytep,
display->first_row);
png_bytep row = display->first_row;
unsigned int startx, stepx, stepy;
png_uint_32 y;
@@ -3301,8 +3274,7 @@ png_image_read_background(png_voidp argument)
{
for (; y<height; y += stepy)
{
png_bytep inrow = png_voidcast(png_bytep,
display->local_row);
png_bytep inrow = display->local_row;
png_bytep outrow = first_row + y * step_row;
png_const_bytep end_row = outrow + width;
@@ -3346,8 +3318,7 @@ png_image_read_background(png_voidp argument)
for (; y<height; y += stepy)
{
png_bytep inrow = png_voidcast(png_bytep,
display->local_row);
png_bytep inrow = display->local_row;
png_bytep outrow = first_row + y * step_row;
png_const_bytep end_row = outrow + width;
@@ -3393,12 +3364,8 @@ png_image_read_background(png_voidp argument)
* handles the alpha-first option.
*/
{
png_uint_16p first_row = png_voidcast(png_uint_16p,
display->first_row);
/* The division by two is safe because the caller passed in a
* stride which was multiplied by 2 (below) to get row_bytes.
*/
ptrdiff_t step_row = display->row_bytes / 2;
png_bytep first_row = display->first_row;
ptrdiff_t step_row = display->row_bytes;
int preserve_alpha = (image->format & PNG_FORMAT_FLAG_ALPHA) != 0;
unsigned int outchannels = 1+preserve_alpha;
int swap_alpha = 0;
@@ -3436,13 +3403,12 @@ png_image_read_background(png_voidp argument)
for (; y<height; y += stepy)
{
png_const_uint_16p inrow;
png_uint_16p outrow = first_row + y*step_row;
png_uint_16p outrow = (png_uint_16p)(first_row + y*step_row);
png_uint_16p end_row = outrow + width * outchannels;
/* Read the row, which is packed: */
png_read_row(png_ptr, png_voidcast(png_bytep,
display->local_row), NULL);
inrow = png_voidcast(png_const_uint_16p, display->local_row);
png_read_row(png_ptr, display->local_row, NULL);
inrow = (png_const_uint_16p)display->local_row;
/* Now do the pre-multiplication on each pixel in this row.
*/
@@ -3840,7 +3806,7 @@ png_image_read_direct(png_voidp argument)
* display acts as a flag.
*/
{
png_voidp first_row = display->buffer;
png_bytep first_row = png_voidcast(png_bytep, display->buffer);
ptrdiff_t row_bytes = display->row_stride;
if (linear)
@@ -3850,11 +3816,7 @@ png_image_read_direct(png_voidp argument)
* a signed or an unsigned result.
*/
if (row_bytes < 0)
{
char *ptr = png_voidcast(char*, first_row);
ptr += (image->height-1) * (-row_bytes);
first_row = png_voidcast(png_voidp, ptr);
}
first_row += (image->height-1) * (-row_bytes);
display->first_row = first_row;
display->row_bytes = row_bytes;
@@ -3863,7 +3825,8 @@ png_image_read_direct(png_voidp argument)
if (do_local_compose)
{
int result;
png_voidp row = png_malloc(png_ptr, png_get_rowbytes(png_ptr, info_ptr));
png_bytep row = png_voidcast(png_bytep, png_malloc(png_ptr,
png_get_rowbytes(png_ptr, info_ptr)));
display->local_row = row;
result = png_safe_execute(image, png_image_read_composite, display);
@@ -3876,7 +3839,8 @@ png_image_read_direct(png_voidp argument)
else if (do_local_background == 2)
{
int result;
png_voidp row = png_malloc(png_ptr, png_get_rowbytes(png_ptr, info_ptr));
png_bytep row = png_voidcast(png_bytep, png_malloc(png_ptr,
png_get_rowbytes(png_ptr, info_ptr)));
display->local_row = row;
result = png_safe_execute(image, png_image_read_background, display);
@@ -3893,7 +3857,7 @@ png_image_read_direct(png_voidp argument)
while (--passes >= 0)
{
png_uint_32 y = image->height;
png_bytep row = png_voidcast(png_bytep, display->first_row);
png_bytep row = display->first_row;
while (y-- > 0)
{
@@ -3932,7 +3896,7 @@ png_image_finish_read(png_imagep image, png_const_colorp background,
int result;
png_image_read_control display;
memset(&display, 0, (sizeof display));
png_memset(&display, 0, sizeof display);
display.image = image;
display.buffer = buffer;
display.row_stride = row_stride;
@@ -3966,10 +3930,6 @@ png_image_finish_read(png_imagep image, png_const_colorp background,
"png_image_finish_read: invalid argument");
}
else if (image != NULL)
return png_image_error(image,
"png_image_finish_read: damaged PNG_IMAGE_VERSION");
return 0;
}

View File

@@ -364,7 +364,7 @@ png_set_alpha_mode_fixed(png_structrp png_ptr, int mode,
if (compose)
{
/* And obtain alpha pre-multiplication by composing on black: */
memset(&png_ptr->background, 0, (sizeof png_ptr->background));
png_memset(&png_ptr->background, 0, sizeof png_ptr->background);
png_ptr->background_gamma = png_ptr->colorspace.gamma; /* just in case */
png_ptr->background_gamma_type = PNG_BACKGROUND_GAMMA_FILE;
png_ptr->transformations &= ~PNG_BACKGROUND_EXPAND;
@@ -423,7 +423,7 @@ png_set_quantize(png_structrp png_ptr, png_colorp palette,
int i;
png_ptr->quantize_index = (png_bytep)png_malloc(png_ptr,
(png_uint_32)(num_palette * (sizeof (png_byte))));
(png_uint_32)(num_palette * png_sizeof(png_byte)));
for (i = 0; i < num_palette; i++)
png_ptr->quantize_index[i] = (png_byte)i;
}
@@ -440,7 +440,7 @@ png_set_quantize(png_structrp png_ptr, png_colorp palette,
/* Initialize an array to sort colors */
png_ptr->quantize_sort = (png_bytep)png_malloc(png_ptr,
(png_uint_32)(num_palette * (sizeof (png_byte))));
(png_uint_32)(num_palette * png_sizeof(png_byte)));
/* Initialize the quantize_sort array */
for (i = 0; i < num_palette; i++)
@@ -574,9 +574,9 @@ png_set_quantize(png_structrp png_ptr, png_colorp palette,
/* Initialize palette index arrays */
png_ptr->index_to_palette = (png_bytep)png_malloc(png_ptr,
(png_uint_32)(num_palette * (sizeof (png_byte))));
(png_uint_32)(num_palette * png_sizeof(png_byte)));
png_ptr->palette_to_index = (png_bytep)png_malloc(png_ptr,
(png_uint_32)(num_palette * (sizeof (png_byte))));
(png_uint_32)(num_palette * png_sizeof(png_byte)));
/* Initialize the sort array */
for (i = 0; i < num_palette; i++)
@@ -586,7 +586,7 @@ png_set_quantize(png_structrp png_ptr, png_colorp palette,
}
hash = (png_dsortpp)png_calloc(png_ptr, (png_uint_32)(769 *
(sizeof (png_dsortp))));
png_sizeof(png_dsortp)));
num_new_palette = num_palette;
@@ -616,7 +616,7 @@ png_set_quantize(png_structrp png_ptr, png_colorp palette,
{
t = (png_dsortp)png_malloc_warn(png_ptr,
(png_uint_32)(sizeof (png_dsort)));
(png_uint_32)(png_sizeof(png_dsort)));
if (t == NULL)
break;
@@ -741,12 +741,12 @@ png_set_quantize(png_structrp png_ptr, png_colorp palette,
png_size_t num_entries = ((png_size_t)1 << total_bits);
png_ptr->palette_lookup = (png_bytep)png_calloc(png_ptr,
(png_uint_32)(num_entries * (sizeof (png_byte))));
(png_uint_32)(num_entries * png_sizeof(png_byte)));
distance = (png_bytep)png_malloc(png_ptr, (png_uint_32)(num_entries *
(sizeof (png_byte))));
png_sizeof(png_byte)));
memset(distance, 0xff, num_entries * (sizeof (png_byte)));
png_memset(distance, 0xff, num_entries * png_sizeof(png_byte));
for (i = 0; i < num_palette; i++)
{
@@ -1404,7 +1404,7 @@ png_init_read_transformations(png_structrp png_ptr)
#endif
#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
/* Make sure the coefficients for the rgb to gray conversion are set
/* Make sure the coefficients for the rgb to gray convertion are set
* appropriately.
*/
if (png_ptr->transformations & PNG_RGB_TO_GRAY)
@@ -2342,8 +2342,7 @@ png_do_read_transformations(png_structrp png_ptr, png_row_infop row_info)
#ifdef PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED
/* Added at libpng-1.5.10 */
if (row_info->color_type == PNG_COLOR_TYPE_PALETTE &&
png_ptr->num_palette_max >= 0)
if (row_info->color_type == PNG_COLOR_TYPE_PALETTE)
png_do_check_palette_indexes(png_ptr, row_info);
#endif
@@ -3753,10 +3752,8 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
if (v == png_ptr->trans_color.gray)
{
/* Background is already in screen gamma */
*sp = (png_byte)((png_ptr->background.gray >> 8)
& 0xff);
*(sp + 1) = (png_byte)(png_ptr->background.gray
& 0xff);
*sp = (png_byte)((png_ptr->background.gray >> 8) & 0xff);
*(sp + 1) = (png_byte)(png_ptr->background.gray & 0xff);
}
else
@@ -3779,10 +3776,8 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
if (v == png_ptr->trans_color.gray)
{
*sp = (png_byte)((png_ptr->background.gray >> 8)
& 0xff);
*(sp + 1) = (png_byte)(png_ptr->background.gray
& 0xff);
*sp = (png_byte)((png_ptr->background.gray >> 8) & 0xff);
*(sp + 1) = (png_byte)(png_ptr->background.gray & 0xff);
}
}
}
@@ -3862,12 +3857,9 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
/* Background is already in screen gamma */
*sp = (png_byte)((png_ptr->background.red >> 8) & 0xff);
*(sp + 1) = (png_byte)(png_ptr->background.red & 0xff);
*(sp + 2) = (png_byte)((png_ptr->background.green >> 8)
& 0xff);
*(sp + 3) = (png_byte)(png_ptr->background.green
& 0xff);
*(sp + 4) = (png_byte)((png_ptr->background.blue >> 8)
& 0xff);
*(sp + 2) = (png_byte)((png_ptr->background.green >> 8) & 0xff);
*(sp + 3) = (png_byte)(png_ptr->background.green & 0xff);
*(sp + 4) = (png_byte)((png_ptr->background.blue >> 8) & 0xff);
*(sp + 5) = (png_byte)(png_ptr->background.blue & 0xff);
}
@@ -3908,12 +3900,9 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
{
*sp = (png_byte)((png_ptr->background.red >> 8) & 0xff);
*(sp + 1) = (png_byte)(png_ptr->background.red & 0xff);
*(sp + 2) = (png_byte)((png_ptr->background.green >> 8)
& 0xff);
*(sp + 3) = (png_byte)(png_ptr->background.green
& 0xff);
*(sp + 4) = (png_byte)((png_ptr->background.blue >> 8)
& 0xff);
*(sp + 2) = (png_byte)((png_ptr->background.green >> 8) & 0xff);
*(sp + 3) = (png_byte)(png_ptr->background.green & 0xff);
*(sp + 4) = (png_byte)((png_ptr->background.blue >> 8) & 0xff);
*(sp + 5) = (png_byte)(png_ptr->background.blue & 0xff);
}
}
@@ -3968,7 +3957,7 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
*sp = (png_byte)png_ptr->background.gray;
else if (a < 0xff)
png_composite(*sp, *sp, a, png_ptr->background.gray);
png_composite(*sp, *sp, a, png_ptr->background_1.gray);
}
}
}
@@ -3996,8 +3985,7 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
else if (a == 0)
{
/* Background is already in screen gamma */
*sp = (png_byte)((png_ptr->background.gray >> 8)
& 0xff);
*sp = (png_byte)((png_ptr->background.gray >> 8) & 0xff);
*(sp + 1) = (png_byte)(png_ptr->background.gray & 0xff);
}
@@ -4027,8 +4015,7 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
if (a == 0)
{
*sp = (png_byte)((png_ptr->background.gray >> 8)
& 0xff);
*sp = (png_byte)((png_ptr->background.gray >> 8) & 0xff);
*(sp + 1) = (png_byte)(png_ptr->background.gray & 0xff);
}
@@ -4037,7 +4024,7 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
png_uint_16 g, v;
g = (png_uint_16)(((*sp) << 8) + *(sp + 1));
png_composite_16(v, g, a, png_ptr->background.gray);
png_composite_16(v, g, a, png_ptr->background_1.gray);
*sp = (png_byte)((v >> 8) & 0xff);
*(sp + 1) = (png_byte)(v & 0xff);
}
@@ -4158,12 +4145,9 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
/* Background is already in screen gamma */
*sp = (png_byte)((png_ptr->background.red >> 8) & 0xff);
*(sp + 1) = (png_byte)(png_ptr->background.red & 0xff);
*(sp + 2) = (png_byte)((png_ptr->background.green >> 8)
& 0xff);
*(sp + 3) = (png_byte)(png_ptr->background.green
& 0xff);
*(sp + 4) = (png_byte)((png_ptr->background.blue >> 8)
& 0xff);
*(sp + 2) = (png_byte)((png_ptr->background.green >> 8) & 0xff);
*(sp + 3) = (png_byte)(png_ptr->background.green & 0xff);
*(sp + 4) = (png_byte)((png_ptr->background.blue >> 8) & 0xff);
*(sp + 5) = (png_byte)(png_ptr->background.blue & 0xff);
}
@@ -4174,16 +4158,14 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
v = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];
png_composite_16(w, v, a, png_ptr->background_1.red);
if (!optimize)
w = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >>
8];
w = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8];
*sp = (png_byte)((w >> 8) & 0xff);
*(sp + 1) = (png_byte)(w & 0xff);
v = gamma_16_to_1[*(sp + 3) >> gamma_shift][*(sp + 2)];
png_composite_16(w, v, a, png_ptr->background_1.green);
if (!optimize)
w = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >>
8];
w = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8];
*(sp + 2) = (png_byte)((w >> 8) & 0xff);
*(sp + 3) = (png_byte)(w & 0xff);
@@ -4191,8 +4173,7 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
v = gamma_16_to_1[*(sp + 5) >> gamma_shift][*(sp + 4)];
png_composite_16(w, v, a, png_ptr->background_1.blue);
if (!optimize)
w = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >>
8];
w = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8];
*(sp + 4) = (png_byte)((w >> 8) & 0xff);
*(sp + 5) = (png_byte)(w & 0xff);
@@ -4213,12 +4194,9 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
{
*sp = (png_byte)((png_ptr->background.red >> 8) & 0xff);
*(sp + 1) = (png_byte)(png_ptr->background.red & 0xff);
*(sp + 2) = (png_byte)((png_ptr->background.green >> 8)
& 0xff);
*(sp + 3) = (png_byte)(png_ptr->background.green
& 0xff);
*(sp + 4) = (png_byte)((png_ptr->background.blue >> 8)
& 0xff);
*(sp + 2) = (png_byte)((png_ptr->background.green >> 8) & 0xff);
*(sp + 3) = (png_byte)(png_ptr->background.green & 0xff);
*(sp + 4) = (png_byte)((png_ptr->background.blue >> 8) & 0xff);
*(sp + 5) = (png_byte)(png_ptr->background.blue & 0xff);
}

View File

@@ -211,7 +211,7 @@ png_crc_finish(png_structrp png_ptr, png_uint_32 skip)
png_uint_32 len;
png_byte tmpbuf[PNG_INFLATE_BUF_SIZE];
len = (sizeof tmpbuf);
len = sizeof tmpbuf;
if (len > skip)
len = skip;
skip -= len;
@@ -312,16 +312,8 @@ png_read_buffer(png_structrp png_ptr, png_alloc_size_t new_size, int warn)
else if (warn < 2) /* else silent */
{
#ifdef PNG_WARNINGS_SUPPORTED
if (warn)
png_chunk_warning(png_ptr, "insufficient memory to read chunk");
else
#endif
{
#ifdef PNG_ERROR_TEXT_SUPPORTED
png_chunk_error(png_ptr, "insufficient memory to read chunk");
#endif
}
(warn ? png_chunk_warning : png_chunk_error)(png_ptr,
"insufficient memory to read chunk");
}
}
@@ -345,7 +337,7 @@ png_inflate_claim(png_structrp png_ptr, png_uint_32 owner, int window_bits)
* internal error, but is very useful for debugging. i18n requirements
* are minimal.
*/
(void)png_safecat(msg, (sizeof msg), 4, " using zstream");
(void)png_safecat(msg, sizeof msg, 4, " using zstream");
# if PNG_LIBPNG_BUILD_BASE_TYPE >= PNG_LIBPNG_BUILD_RC
png_chunk_warning(png_ptr, msg);
png_ptr->zowner = 0;
@@ -463,7 +455,7 @@ png_inflate(png_structrp png_ptr, png_uint_32 owner, int finish,
* inside it is possible to chunk the input to zlib and simply rely on
* zlib to advance the 'next_in' pointer. This allows arbitrary
* amounts of data to be passed through zlib at the unavoidable cost of
* requiring a window save (memcpy of up to 32768 output bytes)
* requiring a window save (png_memcpy of up to 32768 output bytes)
* every ZLIB_IO_MAX input bytes.
*/
avail_in += png_ptr->zstream.avail_in; /* not consumed last time */
@@ -487,8 +479,8 @@ png_inflate(png_structrp png_ptr, png_uint_32 owner, int finish,
* make available the full buffer, up to 'remaining_space'
*/
png_ptr->zstream.next_out = local_buffer;
if ((sizeof local_buffer) < avail)
avail = (sizeof local_buffer);
if (sizeof local_buffer < avail)
avail = sizeof local_buffer;
}
if (avail_out < avail)
@@ -574,7 +566,7 @@ png_decompress_chunk(png_structrp png_ptr,
if (limit >= prefix_size + (terminate != 0))
{
int ret;
limit -= prefix_size + (terminate != 0);
if (limit < *newlength)
@@ -596,7 +588,7 @@ png_decompress_chunk(png_structrp png_ptr,
ret = png_inflate(png_ptr, png_ptr->chunk_name, 1/*finish*/,
/* input: */ png_ptr->read_buffer + prefix_size, &lzsize,
/* output: */ NULL, newlength);
if (ret == Z_STREAM_END)
{
/* Use 'inflateReset' here, not 'inflateReset2' because this
@@ -633,7 +625,7 @@ png_decompress_chunk(png_structrp png_ptr,
text[prefix_size + *newlength] = 0;
if (prefix_size > 0)
memcpy(text, png_ptr->read_buffer, prefix_size);
png_memcpy(text, png_ptr->read_buffer, prefix_size);
{
png_bytep old_ptr = png_ptr->read_buffer;
@@ -1009,7 +1001,7 @@ png_handle_PLTE(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
* maintainers to ignore it.
*/
#ifdef PNG_READ_tRNS_SUPPORTED
if (png_ptr->num_trans > 0 ||
if (png_ptr->num_trans > 0 ||
(info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS) != 0))
{
/* Cancel this because otherwise it would be used if the transforms
@@ -1402,12 +1394,12 @@ png_handle_iCCP(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
{
Byte profile_header[132];
Byte local_buffer[PNG_INFLATE_BUF_SIZE];
png_alloc_size_t size = (sizeof profile_header);
png_alloc_size_t size = sizeof profile_header;
png_ptr->zstream.next_in = (Bytef*)keyword + (keyword_length+2);
png_ptr->zstream.avail_in = read_length;
(void)png_inflate_read(png_ptr, local_buffer,
(sizeof local_buffer), &length, profile_header, &size,
sizeof local_buffer, &length, profile_header, &size,
0/*finish: don't, because the output is too small*/);
if (size == 0)
@@ -1424,8 +1416,7 @@ png_handle_iCCP(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
* byte header.
*/
if (png_icc_check_header(png_ptr, &png_ptr->colorspace,
keyword, profile_length, profile_header,
png_ptr->color_type))
keyword, profile_length, profile_header))
{
/* Now read the tag table; a variable size buffer is
* needed at this point, allocate one for the whole
@@ -1440,12 +1431,12 @@ png_handle_iCCP(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
if (profile != NULL)
{
memcpy(profile, profile_header,
(sizeof profile_header));
sizeof profile_header);
size = 12 * tag_count;
(void)png_inflate_read(png_ptr, local_buffer,
(sizeof local_buffer), &length,
sizeof local_buffer, &length,
profile + (sizeof profile_header), &size, 0);
/* Still expect a a buffer error because we expect
@@ -1464,7 +1455,7 @@ png_handle_iCCP(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
- 12 * tag_count;
(void)png_inflate_read(png_ptr, local_buffer,
(sizeof local_buffer), &length,
sizeof local_buffer, &length,
profile + (sizeof profile_header) +
12 * tag_count, &size, 1/*finish*/);
@@ -1495,7 +1486,8 @@ png_handle_iCCP(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
*/
ok = png_icc_set_gAMA_and_cHRM(png_ptr,
&png_ptr->colorspace, keyword, profile,
png_ptr->zstream.adler);
png_ptr->zstream.adler,
0/*prefer explicit gAMA/cHRM*/);
/* Steal the profile for info_ptr. */
if (ok && info_ptr != NULL)
@@ -1587,7 +1579,7 @@ png_handle_iCCP(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
else
errmsg = "bad keyword";
}
else
errmsg = "too many profiles";
@@ -1702,7 +1694,7 @@ png_handle_sPLT(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
}
dl = (png_int_32)(data_length / entry_size);
max_dl = PNG_SIZE_MAX / (sizeof (png_sPLT_entry));
max_dl = PNG_SIZE_MAX / png_sizeof(png_sPLT_entry);
if (dl > max_dl)
{
@@ -1713,7 +1705,7 @@ png_handle_sPLT(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
new_palette.nentries = (png_int_32)(data_length / entry_size);
new_palette.entries = (png_sPLT_entryp)png_malloc_warn(
png_ptr, new_palette.nentries * (sizeof (png_sPLT_entry)));
png_ptr, new_palette.nentries * png_sizeof(png_sPLT_entry));
if (new_palette.entries == NULL)
{
@@ -2219,7 +2211,7 @@ png_handle_pCAL(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
png_debug(3, "Allocating pCAL parameters array");
params = png_voidcast(png_charpp, png_malloc_warn(png_ptr,
nparams * (sizeof (png_charp))));
nparams * png_sizeof(png_charp)));
if (params == NULL)
{
@@ -2466,7 +2458,7 @@ png_handle_tEXt(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
text_info.lang_key = NULL;
text_info.itxt_length = 0;
text_info.text = text;
text_info.text_length = strlen(text);
text_info.text_length = png_strlen(text);
if (png_set_text_2(png_ptr, info_ptr, &text_info, 1))
png_warning(png_ptr, "Insufficient memory to process text chunk");
@@ -2732,261 +2724,136 @@ png_handle_iTXt(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
}
#endif
#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
/* Utility function for png_handle_unknown; set up png_ptr::unknown_chunk */
static int
png_cache_unknown_chunk(png_structrp png_ptr, png_uint_32 length)
/* This function is called when we haven't found a handler for a
* chunk. If there isn't a problem with the chunk itself (ie bad
* chunk name, CRC, or a critical chunk), the chunk is silently ignored
* -- unless the PNG_FLAG_UNKNOWN_CHUNKS_SUPPORTED flag is on in which
* case it will be saved away to be written out later.
*/
void /* PRIVATE */
png_handle_unknown(png_structrp png_ptr, png_inforp info_ptr,
png_uint_32 length)
{
png_alloc_size_t limit = PNG_SIZE_MAX;
png_uint_32 skip = 0;
if (png_ptr->unknown_chunk.data != NULL)
png_debug(1, "in png_handle_unknown");
#ifdef PNG_USER_LIMITS_SUPPORTED
if (png_ptr->user_chunk_cache_max != 0)
{
png_free(png_ptr, png_ptr->unknown_chunk.data);
png_ptr->unknown_chunk.data = NULL;
if (png_ptr->user_chunk_cache_max == 1)
{
png_crc_finish(png_ptr, length);
return;
}
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");
return;
}
}
#endif
if (png_ptr->mode & PNG_HAVE_IDAT)
{
if (png_ptr->chunk_name != png_IDAT)
png_ptr->mode |= PNG_AFTER_IDAT;
}
# ifdef PNG_SET_CHUNK_MALLOC_LIMIT_SUPPORTED
if (png_ptr->user_chunk_malloc_max > 0 &&
png_ptr->user_chunk_malloc_max < limit)
limit = png_ptr->user_chunk_malloc_max;
# elif PNG_USER_CHUNK_MALLOC_MAX > 0
if (PNG_USER_CHUNK_MALLOC_MAX < limit)
limit = PNG_USER_CHUNK_MALLOC_MAX;
# endif
if (length <= limit)
if (PNG_CHUNK_CRITICAL(png_ptr->chunk_name))
{
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
if (png_chunk_unknown_handling(png_ptr, png_ptr->chunk_name) !=
PNG_HANDLE_CHUNK_ALWAYS
#ifdef PNG_READ_USER_CHUNKS_SUPPORTED
&& png_ptr->read_user_chunk_fn == NULL
#endif
)
#endif
png_chunk_error(png_ptr, "unknown critical chunk");
}
#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
if ((png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS)
#ifdef PNG_READ_USER_CHUNKS_SUPPORTED
|| (png_ptr->read_user_chunk_fn != NULL)
#endif
)
{
#ifdef PNG_MAX_MALLOC_64K
if (length > 65535)
{
png_crc_finish(png_ptr, length);
png_chunk_benign_error(png_ptr,
"unknown chunk too large to fit in memory");
return;
}
#endif
/* TODO: this code is very close to the unknown handling in pngpread.c,
* maybe it can be put into a common utility routine?
* png_struct::unknown_chunk is just used as a temporary variable, along
* with the data into which the chunk is read. These can be eliminated.
*/
PNG_CSTRING_FROM_CHUNK(png_ptr->unknown_chunk.name, png_ptr->chunk_name);
/* The following is safe because of the PNG_SIZE_MAX init above */
png_ptr->unknown_chunk.size = (png_size_t)length/*SAFE*/;
/* 'mode' is a flag array, only the bottom four bits matter here */
png_ptr->unknown_chunk.location = (png_byte)png_ptr->mode/*SAFE*/;
png_ptr->unknown_chunk.size = (png_size_t)length;
if (length == 0)
png_ptr->unknown_chunk.data = NULL;
else
{
/* Do a 'warn' here - it is handled below. */
png_ptr->unknown_chunk.data = png_voidcast(png_bytep,
png_malloc_warn(png_ptr, length));
}
}
if (png_ptr->unknown_chunk.data == NULL && length > 0)
{
/* This is benign because we clean up correctly */
png_crc_finish(png_ptr, length);
png_chunk_benign_error(png_ptr, "unknown chunk exceeds memory limits");
return 0;
}
else
{
if (length > 0)
png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
png_crc_read(png_ptr, png_ptr->unknown_chunk.data, length);
png_crc_finish(png_ptr, 0);
return 1;
}
}
#endif /* PNG_READ_UNKNOWN_CHUNKS_SUPPORTED */
}
/* Handle an unknown, or known but disabled, chunk */
void /* PRIVATE */
png_handle_unknown(png_structrp png_ptr, png_inforp info_ptr,
png_uint_32 length, int keep)
{
int handled = 0; /* the chunk was handled */
png_debug(1, "in png_handle_unknown");
#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
/* NOTE: this code is based on the code in libpng-1.4.12 except for fixing
* the bug which meant that setting a non-default behavior for a specific
* chunk would be ignored (the default was always used unless a user
* callback was installed).
*
* 'keep' is the value from the png_chunk_unknown_handling, the setting for
* this specific chunk_name, if PNG_HANDLE_AS_UNKNOWN_SUPPORTED, if not it
* will always be PNG_HANDLE_CHUNK_AS_DEFAULT and it needs to be set here.
* This is just an optimization to avoid multiple calls to the lookup
* function.
*/
# ifndef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
# ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED
keep = png_chunk_unknown_handling(png_ptr, png_ptr->chunk_name);
# endif
# endif
/* One of the following methods will read the chunk or skip it (at least one
* of these is always defined because this is the only way to switch on
* PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
*/
# ifdef PNG_READ_USER_CHUNKS_SUPPORTED
/* The user callback takes precedence over the chunk keep value, but the
* keep value is still required to validate a save of a critical chunk.
*/
#ifdef PNG_READ_USER_CHUNKS_SUPPORTED
if (png_ptr->read_user_chunk_fn != NULL)
{
if (png_cache_unknown_chunk(png_ptr, length))
/* Callback to user unknown chunk handler */
int ret;
ret = (*(png_ptr->read_user_chunk_fn))
(png_ptr, &png_ptr->unknown_chunk);
if (ret < 0)
png_chunk_error(png_ptr, "error in user chunk");
if (ret == 0)
{
/* Callback to user unknown chunk handler */
int ret = (*(png_ptr->read_user_chunk_fn))(png_ptr,
&png_ptr->unknown_chunk);
/* ret is:
* 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.
* positive: The chunk was handled, libpng will ignore/discard it.
*/
if (ret < 0)
png_chunk_error(png_ptr, "error in user chunk");
else if (ret == 0)
if (PNG_CHUNK_CRITICAL(png_ptr->chunk_name))
{
/* 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.
*
* The png_app_warning below catches the case that matters, where
* the application has neither set specific save for this chunk
* or global save.
*/
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;
}
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
if (png_chunk_unknown_handling(png_ptr, png_ptr->chunk_name) !=
PNG_HANDLE_CHUNK_ALWAYS)
#endif
png_chunk_error(png_ptr, "unknown critical chunk");
}
else /* chunk was handled */
{
handled = 1;
/* Critical chunks can be safely discarded at this point. */
keep = PNG_HANDLE_CHUNK_NEVER;
}
png_set_unknown_chunks(png_ptr, info_ptr,
&png_ptr->unknown_chunk, 1);
}
else
keep = PNG_HANDLE_CHUNK_NEVER; /* insufficient memory */
}
else
/* Use the SAVE_UNKNOWN_CHUNKS code or skip the chunk */
# endif /* PNG_READ_USER_CHUNKS_SUPPORTED */
#endif
png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
# ifdef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED
{
/* keep is currently just the per-chunk setting, if there was no
* setting change it to the global default now (not that this may
* still be AS_DEFAULT) then obtain the cache of the chunk if required,
* if not simply skip the chunk.
*/
if (keep == PNG_HANDLE_CHUNK_AS_DEFAULT)
keep = png_ptr->unknown_default;
if (keep == PNG_HANDLE_CHUNK_ALWAYS ||
(keep == PNG_HANDLE_CHUNK_IF_SAFE &&
PNG_CHUNK_ANCILLIARY(png_ptr->chunk_name)))
{
if (!png_cache_unknown_chunk(png_ptr, length))
keep = PNG_HANDLE_CHUNK_NEVER;
}
else
png_crc_finish(png_ptr, length);
}
# else
# ifndef PNG_READ_USER_CHUNKS_SUPPORTED
# error no method to support READ_UNKNOWN_CHUNKS
# endif
{
/* If here there is no read callback pointer set and no support is
* compiled in to just save the unknown chunks, so simply skip this
* chunk. If 'keep' is something other than AS_DEFAULT or NEVER then
* the app has erroneously asked for unknown chunk saving when there
* is no support.
*/
if (keep > PNG_HANDLE_CHUNK_NEVER)
png_app_error(png_ptr, "no unknown chunk support available");
png_crc_finish(png_ptr, length);
}
# endif
# ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
/* Now store the chunk in the chunk list if appropriate, and if the limits
* permit it.
*/
if (keep == PNG_HANDLE_CHUNK_ALWAYS ||
(keep == PNG_HANDLE_CHUNK_IF_SAFE &&
PNG_CHUNK_ANCILLIARY(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");
/* FALL THROUGH */
case 1:
/* NOTE: prior to 1.6.0 this case resulted in an unknown critical
* chunk being skipped, now there will be a hard error below.
*/
break;
default: /* not at limit */
--(png_ptr->user_chunk_cache_max);
/* FALL THROUGH */
case 0: /* no limit */
# endif /* PNG_USER_LIMITS_SUPPORTED */
/* Here when the limit isn't reached or when limits are compiled
* out; store the chunk.
*/
png_set_unknown_chunks(png_ptr, info_ptr,
&png_ptr->unknown_chunk, 1);
handled = 1;
# ifdef PNG_USER_LIMITS_SUPPORTED
break;
}
# endif
}
# else /* no store support! */
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
* freed now. Notice that the data is not freed if there is a png_error, but
* it will be freed by destroy_read_struct.
*/
if (png_ptr->unknown_chunk.data != NULL)
png_free(png_ptr, png_ptr->unknown_chunk.data);
png_ptr->unknown_chunk.data = NULL;
png_ptr->unknown_chunk.data = NULL;
}
#else /* !PNG_READ_UNKNOWN_CHUNKS_SUPPORTED */
/* There is no support to read an unknown chunk, so just skip it. */
png_crc_finish(png_ptr, length);
PNG_UNUSED(info_ptr)
PNG_UNUSED(keep)
#endif /* !PNG_READ_UNKNOWN_CHUNKS_SUPPORTED */
else
#endif
skip = length;
/* Check for unhandled critical chunks */
if (!handled && PNG_CHUNK_CRITICAL(png_ptr->chunk_name))
png_chunk_error(png_ptr, "unhandled critical chunk");
png_crc_finish(png_ptr, skip);
#ifndef PNG_READ_USER_CHUNKS_SUPPORTED
PNG_UNUSED(info_ptr) /* Quiet compiler warnings about unused info_ptr */
#endif
}
/* This function is called to verify that a chunk name is valid.
@@ -3077,7 +2944,7 @@ png_combine_row(png_const_structrp png_ptr, png_bytep dp, int display)
/* end_mask is now the bits to *keep* from the destination row */
}
/* For non-interlaced images this reduces to a memcpy(). A memcpy()
/* For non-interlaced images this reduces to a png_memcpy(). A png_memcpy()
* will also happen if interlacing isn't supported or if the application
* does not call png_set_interlace_handling(). In the latter cases the
* caller just gets a sequence of the unexpanded rows from each interlace
@@ -3378,27 +3245,26 @@ png_combine_row(png_const_structrp png_ptr, png_bytep dp, int display)
/* Check for double byte alignment and, if possible, use a
* 16-bit copy. Don't attempt this for narrow images - ones that
* are less than an interlace panel wide. Don't attempt it for
* wide bytes_to_copy either - use the memcpy there.
* wide bytes_to_copy either - use the png_memcpy there.
*/
if (bytes_to_copy < 16 /*else use memcpy*/ &&
if (bytes_to_copy < 16 /*else use png_memcpy*/ &&
png_isaligned(dp, png_uint_16) &&
png_isaligned(sp, png_uint_16) &&
bytes_to_copy % (sizeof (png_uint_16)) == 0 &&
bytes_to_jump % (sizeof (png_uint_16)) == 0)
bytes_to_copy % sizeof (png_uint_16) == 0 &&
bytes_to_jump % sizeof (png_uint_16) == 0)
{
/* Everything is aligned for png_uint_16 copies, but try for
* png_uint_32 first.
*/
if (png_isaligned(dp, png_uint_32) &&
png_isaligned(sp, png_uint_32) &&
bytes_to_copy % (sizeof (png_uint_32)) == 0 &&
bytes_to_jump % (sizeof (png_uint_32)) == 0)
bytes_to_copy % sizeof (png_uint_32) == 0 &&
bytes_to_jump % sizeof (png_uint_32) == 0)
{
png_uint_32p dp32 = png_aligncast(png_uint_32p,dp);
png_const_uint_32p sp32 = png_aligncastconst(
png_const_uint_32p, sp);
png_uint_32p dp32 = (png_uint_32p)dp;
png_const_uint_32p sp32 = (png_const_uint_32p)sp;
unsigned int skip = (bytes_to_jump-bytes_to_copy) /
(sizeof (png_uint_32));
sizeof (png_uint_32);
do
{
@@ -3406,7 +3272,7 @@ png_combine_row(png_const_structrp png_ptr, png_bytep dp, int display)
do
{
*dp32++ = *sp32++;
c -= (sizeof (png_uint_32));
c -= sizeof (png_uint_32);
}
while (c > 0);
@@ -3436,11 +3302,10 @@ png_combine_row(png_const_structrp png_ptr, png_bytep dp, int display)
*/
else
{
png_uint_16p dp16 = png_aligncast(png_uint_16p, dp);
png_const_uint_16p sp16 = png_aligncastconst(
png_const_uint_16p, sp);
png_uint_16p dp16 = (png_uint_16p)dp;
png_const_uint_16p sp16 = (png_const_uint_16p)sp;
unsigned int skip = (bytes_to_jump-bytes_to_copy) /
(sizeof (png_uint_16));
sizeof (png_uint_16);
do
{
@@ -3448,7 +3313,7 @@ png_combine_row(png_const_structrp png_ptr, png_bytep dp, int display)
do
{
*dp16++ = *sp16++;
c -= (sizeof (png_uint_16));
c -= sizeof (png_uint_16);
}
while (c > 0);
@@ -3472,10 +3337,10 @@ png_combine_row(png_const_structrp png_ptr, png_bytep dp, int display)
}
#endif /* PNG_ALIGN_ code */
/* The true default - use a memcpy: */
/* The true default - use a png_memcpy: */
for (;;)
{
memcpy(dp, sp, bytes_to_copy);
png_memcpy(dp, sp, bytes_to_copy);
if (row_width <= bytes_to_jump)
return;
@@ -3496,11 +3361,11 @@ png_combine_row(png_const_structrp png_ptr, png_bytep dp, int display)
else
#endif
/* If here then the switch above wasn't used so just memcpy the whole row
/* If here then the switch above wasn't used so just png_memcpy the whole row
* from the temporary row buffer (notice that this overwrites the end of the
* destination row if it is a partial byte.)
*/
memcpy(dp, sp, PNG_ROWBYTES(pixel_depth, row_width));
png_memcpy(dp, sp, PNG_ROWBYTES(pixel_depth, row_width));
/* Restore the overwritten bits from the last byte if necessary. */
if (end_ptr != NULL)
@@ -3729,11 +3594,11 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
png_byte v[8];
int j;
memcpy(v, sp, pixel_bytes);
png_memcpy(v, sp, pixel_bytes);
for (j = 0; j < jstop; j++)
{
memcpy(dp, v, pixel_bytes);
png_memcpy(dp, v, pixel_bytes);
dp -= pixel_bytes;
}
@@ -3926,7 +3791,7 @@ static int png_have_hwcap(unsigned cap)
if (!f)
return 0;
while (fread(&aux, (sizeof aux), 1, f) > 0)
while (fread(&aux, sizeof(aux), 1, f) > 0)
{
if (aux.a_type == AT_HWCAP &&
aux.a_un.a_val & cap)
@@ -4068,7 +3933,7 @@ png_read_IDAT_data(png_structrp png_ptr, png_bytep output,
else /* check for end */
{
png_ptr->zstream.next_out = tmpbuf;
png_ptr->zstream.avail_out = (sizeof tmpbuf);
png_ptr->zstream.avail_out = sizeof tmpbuf;
}
/* Use NO_FLUSH; this gives zlib the maximum opportunity to optimize the
@@ -4207,7 +4072,7 @@ png_read_finish_row(png_structrp png_ptr)
/* TO DO: don't do this if prev_row isn't needed (requires
* read-ahead of the next row's filter byte.
*/
memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
png_memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
do
{
@@ -4505,7 +4370,7 @@ defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
if (png_ptr->rowbytes > (PNG_SIZE_MAX - 1))
png_error(png_ptr, "Row has too many bytes to allocate in memory");
memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
png_memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
png_debug1(3, "width = %u,", png_ptr->width);
png_debug1(3, "height = %u,", png_ptr->height);

468
pngset.c
View File

@@ -80,15 +80,15 @@ png_set_cHRM_XYZ_fixed(png_const_structrp png_ptr, png_inforp info_ptr,
if (png_ptr == NULL || info_ptr == NULL)
return;
XYZ.red_X = int_red_X;
XYZ.red_Y = int_red_Y;
XYZ.red_Z = int_red_Z;
XYZ.green_X = int_green_X;
XYZ.green_Y = int_green_Y;
XYZ.green_Z = int_green_Z;
XYZ.blue_X = int_blue_X;
XYZ.blue_Y = int_blue_Y;
XYZ.blue_Z = int_blue_Z;
XYZ.redX = int_red_X;
XYZ.redY = int_red_Y;
XYZ.redZ = int_red_Z;
XYZ.greenX = int_green_X;
XYZ.greenY = int_green_Y;
XYZ.greenZ = int_green_Z;
XYZ.blueX = int_blue_X;
XYZ.blueY = int_blue_Y;
XYZ.blueZ = int_blue_Z;
if (png_colorspace_set_endpoints(png_ptr, &info_ptr->colorspace, &XYZ, 2))
info_ptr->colorspace.flags |= PNG_COLORSPACE_FROM_cHRM;
@@ -148,7 +148,7 @@ png_set_gAMA_fixed(png_const_structrp png_ptr, png_inforp info_ptr,
* possible for 1/gamma to overflow the limit of 21474 and this means the
* gamma value must be at least 5/100000 and hence at most 20000.0. For
* safety the limits here are a little narrower. The values are 0.00016 to
* 6250.0, which are truly ridiculous gamma values (and will produce
* 6250.0, which are truly ridiculous gammma values (and will produce
* displays that are all black or all white.)
*/
if (file_gamma < 16 || file_gamma > 625000000)
@@ -201,7 +201,7 @@ png_set_hIST(png_const_structrp png_ptr, png_inforp info_ptr,
* version 1.2.1
*/
info_ptr->hist = png_voidcast(png_uint_16p, png_malloc_warn(png_ptr,
PNG_MAX_PALETTE_LENGTH * (sizeof (png_uint_16))));
PNG_MAX_PALETTE_LENGTH * png_sizeof(png_uint_16)));
if (info_ptr->hist == NULL)
{
@@ -299,7 +299,7 @@ png_set_pCAL(png_const_structrp png_ptr, png_inforp info_ptr,
|| (nparams > 0 && params == NULL))
return;
length = strlen(purpose) + 1;
length = png_strlen(purpose) + 1;
png_debug1(3, "allocating purpose for info (%lu bytes)",
(unsigned long)length);
@@ -315,7 +315,7 @@ png_set_pCAL(png_const_structrp png_ptr, png_inforp info_ptr,
/* Validate params[nparams] */
for (i=0; i<nparams; ++i)
if (params[i] == NULL ||
!png_check_fp_string(params[i], strlen(params[i])))
!png_check_fp_string(params[i], png_strlen(params[i])))
png_error(png_ptr, "Invalid format for pCAL parameter");
info_ptr->pcal_purpose = png_voidcast(png_charp,
@@ -327,7 +327,7 @@ png_set_pCAL(png_const_structrp png_ptr, png_inforp info_ptr,
return;
}
memcpy(info_ptr->pcal_purpose, purpose, length);
png_memcpy(info_ptr->pcal_purpose, purpose, length);
png_debug(3, "storing X0, X1, type, and nparams in info");
info_ptr->pcal_X0 = X0;
@@ -335,7 +335,7 @@ png_set_pCAL(png_const_structrp png_ptr, png_inforp info_ptr,
info_ptr->pcal_type = (png_byte)type;
info_ptr->pcal_nparams = (png_byte)nparams;
length = strlen(units) + 1;
length = png_strlen(units) + 1;
png_debug1(3, "allocating units for info (%lu bytes)",
(unsigned long)length);
@@ -348,10 +348,10 @@ png_set_pCAL(png_const_structrp png_ptr, png_inforp info_ptr,
return;
}
memcpy(info_ptr->pcal_units, units, length);
png_memcpy(info_ptr->pcal_units, units, length);
info_ptr->pcal_params = png_voidcast(png_charpp, png_malloc_warn(png_ptr,
(png_size_t)((nparams + 1) * (sizeof (png_charp)))));
(png_size_t)((nparams + 1) * png_sizeof(png_charp))));
if (info_ptr->pcal_params == NULL)
{
@@ -359,11 +359,11 @@ png_set_pCAL(png_const_structrp png_ptr, png_inforp info_ptr,
return;
}
memset(info_ptr->pcal_params, 0, (nparams + 1) * (sizeof (png_charp)));
png_memset(info_ptr->pcal_params, 0, (nparams + 1) * png_sizeof(png_charp));
for (i = 0; i < nparams; i++)
{
length = strlen(params[i]) + 1;
length = png_strlen(params[i]) + 1;
png_debug2(3, "allocating parameter %d for info (%lu bytes)", i,
(unsigned long)length);
@@ -375,7 +375,7 @@ png_set_pCAL(png_const_structrp png_ptr, png_inforp info_ptr,
return;
}
memcpy(info_ptr->pcal_params[i], params[i], length);
png_memcpy(info_ptr->pcal_params[i], params[i], length);
}
info_ptr->valid |= PNG_INFO_pCAL;
@@ -401,11 +401,11 @@ png_set_sCAL_s(png_const_structrp png_ptr, png_inforp info_ptr,
if (unit != 1 && unit != 2)
png_error(png_ptr, "Invalid sCAL unit");
if (swidth == NULL || (lengthw = strlen(swidth)) == 0 ||
if (swidth == NULL || (lengthw = png_strlen(swidth)) == 0 ||
swidth[0] == 45 /* '-' */ || !png_check_fp_string(swidth, lengthw))
png_error(png_ptr, "Invalid sCAL width");
if (sheight == NULL || (lengthh = strlen(sheight)) == 0 ||
if (sheight == NULL || (lengthh = png_strlen(sheight)) == 0 ||
sheight[0] == 45 /* '-' */ || !png_check_fp_string(sheight, lengthh))
png_error(png_ptr, "Invalid sCAL height");
@@ -424,7 +424,7 @@ png_set_sCAL_s(png_const_structrp png_ptr, png_inforp info_ptr,
return;
}
memcpy(info_ptr->scal_s_width, swidth, lengthw);
png_memcpy(info_ptr->scal_s_width, swidth, lengthw);
++lengthh;
@@ -442,7 +442,7 @@ png_set_sCAL_s(png_const_structrp png_ptr, png_inforp info_ptr,
return;
}
memcpy(info_ptr->scal_s_height, sheight, lengthh);
png_memcpy(info_ptr->scal_s_height, sheight, lengthh);
info_ptr->valid |= PNG_INFO_sCAL;
info_ptr->free_me |= PNG_FREE_SCAL;
@@ -468,9 +468,9 @@ png_set_sCAL(png_const_structrp png_ptr, png_inforp info_ptr, int unit,
char swidth[PNG_sCAL_MAX_DIGITS+1];
char sheight[PNG_sCAL_MAX_DIGITS+1];
png_ascii_from_fp(png_ptr, swidth, (sizeof swidth), width,
png_ascii_from_fp(png_ptr, swidth, sizeof swidth, width,
PNG_sCAL_PRECISION);
png_ascii_from_fp(png_ptr, sheight, (sizeof sheight), height,
png_ascii_from_fp(png_ptr, sheight, sizeof sheight, height,
PNG_sCAL_PRECISION);
png_set_sCAL_s(png_ptr, info_ptr, unit, swidth, sheight);
@@ -498,8 +498,8 @@ png_set_sCAL_fixed(png_const_structrp png_ptr, png_inforp info_ptr, int unit,
char swidth[PNG_sCAL_MAX_DIGITS+1];
char sheight[PNG_sCAL_MAX_DIGITS+1];
png_ascii_from_fixed(png_ptr, swidth, (sizeof swidth), width);
png_ascii_from_fixed(png_ptr, sheight, (sizeof sheight), height);
png_ascii_from_fixed(png_ptr, swidth, sizeof swidth, width);
png_ascii_from_fixed(png_ptr, sheight, sizeof sheight, height);
png_set_sCAL_s(png_ptr, info_ptr, unit, swidth, sheight);
}
@@ -560,9 +560,9 @@ png_set_PLTE(png_structrp png_ptr, png_inforp info_ptr,
* too-large sample values.
*/
png_ptr->palette = png_voidcast(png_colorp, png_calloc(png_ptr,
PNG_MAX_PALETTE_LENGTH * (sizeof (png_color))));
PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color)));
memcpy(png_ptr->palette, palette, num_palette * (sizeof (png_color)));
png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof(png_color));
info_ptr->palette = png_ptr->palette;
info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;
@@ -643,13 +643,11 @@ png_set_iCCP(png_const_structrp png_ptr, png_inforp info_ptr,
/* Set the colorspace first because this validates the profile; do not
* override previously set app cHRM or gAMA here (because likely as not the
* application knows better than libpng what the correct values are.) Pass
* the info_ptr color_type field to png_colorspace_set_ICC because in the
* write case it has not yet been stored in png_ptr.
* application knows better than libpng what the correct values are.)
*/
{
int result = png_colorspace_set_ICC(png_ptr, &info_ptr->colorspace, name,
proflen, profile, info_ptr->color_type);
proflen, profile, 0/* do *not* override the app cHRM or gAMA */);
png_colorspace_sync_info(png_ptr, info_ptr);
@@ -662,7 +660,7 @@ png_set_iCCP(png_const_structrp png_ptr, png_inforp info_ptr,
PNG_COLORSPACE_FROM_gAMA|PNG_COLORSPACE_FROM_cHRM;
}
length = strlen(name)+1;
length = png_strlen(name)+1;
new_iccp_name = png_voidcast(png_charp, png_malloc_warn(png_ptr, length));
if (new_iccp_name == NULL)
@@ -671,7 +669,7 @@ png_set_iCCP(png_const_structrp png_ptr, png_inforp info_ptr,
return;
}
memcpy(new_iccp_name, name, length);
png_memcpy(new_iccp_name, name, length);
new_iccp_profile = png_voidcast(png_bytep,
png_malloc_warn(png_ptr, proflen));
@@ -683,7 +681,7 @@ png_set_iCCP(png_const_structrp png_ptr, png_inforp info_ptr,
return;
}
memcpy(new_iccp_profile, profile, proflen);
png_memcpy(new_iccp_profile, profile, proflen);
png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, 0);
@@ -735,7 +733,7 @@ png_set_text_2(png_const_structrp png_ptr, png_inforp info_ptr,
old_text = info_ptr->text;
info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
(png_size_t)(info_ptr->max_text * (sizeof (png_text))));
(png_size_t)(info_ptr->max_text * png_sizeof(png_text)));
if (info_ptr->text == NULL)
{
@@ -745,8 +743,8 @@ png_set_text_2(png_const_structrp png_ptr, png_inforp info_ptr,
return(1);
}
memcpy(info_ptr->text, old_text, (png_size_t)(old_max_text *
(sizeof (png_text))));
png_memcpy(info_ptr->text, old_text, (png_size_t)(old_max_text *
png_sizeof(png_text)));
png_free(png_ptr, old_text);
}
@@ -755,7 +753,7 @@ png_set_text_2(png_const_structrp png_ptr, png_inforp info_ptr,
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))));
(png_size_t)(info_ptr->max_text * png_sizeof(png_text)));
if (info_ptr->text == NULL)
{
/* Restore to previous condition */
@@ -785,7 +783,7 @@ png_set_text_2(png_const_structrp png_ptr, png_inforp info_ptr,
continue;
}
key_len = strlen(text_ptr[i].key);
key_len = png_strlen(text_ptr[i].key);
if (text_ptr[i].compression <= 0)
{
@@ -799,13 +797,13 @@ png_set_text_2(png_const_structrp png_ptr, png_inforp info_ptr,
/* Set iTXt data */
if (text_ptr[i].lang != NULL)
lang_len = strlen(text_ptr[i].lang);
lang_len = png_strlen(text_ptr[i].lang);
else
lang_len = 0;
if (text_ptr[i].lang_key != NULL)
lang_key_len = strlen(text_ptr[i].lang_key);
lang_key_len = png_strlen(text_ptr[i].lang_key);
else
lang_key_len = 0;
@@ -831,7 +829,7 @@ png_set_text_2(png_const_structrp png_ptr, png_inforp info_ptr,
else
{
text_length = strlen(text_ptr[i].text);
text_length = png_strlen(text_ptr[i].text);
textp->compression = text_ptr[i].compression;
}
@@ -847,16 +845,16 @@ png_set_text_2(png_const_structrp png_ptr, png_inforp info_ptr,
(key_len + lang_len + lang_key_len + text_length + 4),
textp->key);
memcpy(textp->key, text_ptr[i].key,(png_size_t)(key_len));
png_memcpy(textp->key, text_ptr[i].key,(png_size_t)(key_len));
*(textp->key + key_len) = '\0';
if (text_ptr[i].compression > 0)
{
textp->lang = textp->key + key_len + 1;
memcpy(textp->lang, text_ptr[i].lang, lang_len);
png_memcpy(textp->lang, text_ptr[i].lang, lang_len);
*(textp->lang + lang_len) = '\0';
textp->lang_key = textp->lang + lang_len + 1;
memcpy(textp->lang_key, text_ptr[i].lang_key, lang_key_len);
png_memcpy(textp->lang_key, text_ptr[i].lang_key, lang_key_len);
*(textp->lang_key + lang_key_len) = '\0';
textp->text = textp->lang_key + lang_key_len + 1;
}
@@ -869,7 +867,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_memcpy(textp->text, text_ptr[i].text,
(png_size_t)(text_length));
*(textp->text + text_length) = '\0';
@@ -948,7 +946,7 @@ png_set_tRNS(png_structrp png_ptr, png_inforp info_ptr,
png_malloc(png_ptr, PNG_MAX_PALETTE_LENGTH));
if (num_trans > 0 && num_trans <= PNG_MAX_PALETTE_LENGTH)
memcpy(info_ptr->trans_alpha, trans_alpha, (png_size_t)num_trans);
png_memcpy(info_ptr->trans_alpha, trans_alpha, (png_size_t)num_trans);
}
if (trans_color != NULL)
@@ -1001,7 +999,7 @@ png_set_sPLT(png_const_structrp png_ptr,
return;
np = png_voidcast(png_sPLT_tp, png_malloc_warn(png_ptr,
(info_ptr->splt_palettes_num + nentries) * (sizeof (png_sPLT_t))));
(info_ptr->splt_palettes_num + nentries) * png_sizeof(png_sPLT_t)));
if (np == NULL)
{
@@ -1009,8 +1007,8 @@ png_set_sPLT(png_const_structrp png_ptr,
return;
}
memcpy(np, info_ptr->splt_palettes,
info_ptr->splt_palettes_num * (sizeof (png_sPLT_t)));
png_memcpy(np, info_ptr->splt_palettes,
info_ptr->splt_palettes_num * png_sizeof(png_sPLT_t));
png_free(png_ptr, info_ptr->splt_palettes);
info_ptr->splt_palettes=NULL;
@@ -1028,12 +1026,12 @@ png_set_sPLT(png_const_structrp png_ptr,
* NULL, otherwise libpng will crash later on while trying to free the
* uninitialized pointers.
*/
memset(to, 0, (sizeof *to));
png_memset(to, 0, sizeof *to);
if (from->name == NULL || from->entries == NULL)
continue;
length = strlen(from->name) + 1;
length = png_strlen(from->name) + 1;
to->name = png_voidcast(png_charp, png_malloc_warn(png_ptr, length));
if (to->name == NULL)
@@ -1043,9 +1041,9 @@ png_set_sPLT(png_const_structrp png_ptr,
continue;
}
memcpy(to->name, from->name, length);
png_memcpy(to->name, from->name, length);
to->entries = png_voidcast(png_sPLT_entryp, png_malloc_warn(png_ptr,
from->nentries * (sizeof (png_sPLT_entry))));
from->nentries * png_sizeof(png_sPLT_entry)));
if (to->entries == NULL)
{
@@ -1055,8 +1053,8 @@ png_set_sPLT(png_const_structrp png_ptr,
continue;
}
memcpy(to->entries, from->entries,
from->nentries * (sizeof (png_sPLT_entry)));
png_memcpy(to->entries, from->entries,
from->nentries * png_sizeof(png_sPLT_entry));
to->nentries = from->nentries;
to->depth = from->depth;
@@ -1069,144 +1067,79 @@ png_set_sPLT(png_const_structrp png_ptr,
}
#endif /* PNG_sPLT_SUPPORTED */
#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
static png_byte
check_location(png_const_structrp png_ptr, int location)
{
location &= (PNG_HAVE_IHDR|PNG_HAVE_PLTE|PNG_AFTER_IDAT);
/* New in 1.6.0; copy the location and check it. This is an API
* change, previously the app had to use the
* png_set_unknown_chunk_location API below for each chunk.
*/
if (location == 0 && !(png_ptr->mode & PNG_IS_READ_STRUCT))
{
/* Write struct, so unknown chunks come from the app */
png_app_warning(png_ptr,
"png_set_unknown_chunks now expects a valid location");
/* Use the old behavior */
location = (png_byte)(png_ptr->mode &
(PNG_HAVE_IHDR|PNG_HAVE_PLTE|PNG_AFTER_IDAT));
}
if (location == 0)
png_error(png_ptr, "invalid location in png_set_unknown_chunks");
/* Now reduce the location to the top-most set bit by removing each least
* significant bit in turn.
*/
while (location != (location & -location))
location &= ~(location & -location);
/* The cast is safe because 'location' is a bit mask and only the low four
* bits are significant.
*/
return (png_byte)location;
}
#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
void PNGAPI
png_set_unknown_chunks(png_const_structrp png_ptr,
png_inforp info_ptr, png_const_unknown_chunkp unknowns, int num_unknowns)
{
png_unknown_chunkp np;
int i;
if (png_ptr == NULL || info_ptr == NULL || num_unknowns <= 0)
if (png_ptr == NULL || info_ptr == NULL || num_unknowns == 0)
return;
/* Check for the failure cases where support has been disabled at compile
* time. This code is hardly ever compiled - it's here because
* STORE_UNKNOWN_CHUNKS is set by both read and write code (compiling in this
* code) but may be meaningless if the read or write handling of unknown
* chunks is not compiled in.
*/
# if !(defined PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) && \
(defined PNG_READ_SUPPORTED)
if (png_ptr->mode & PNG_IS_READ_STRUCT)
{
png_app_error(png_ptr, "no unknown chunk support on read");
return;
}
# endif
# if !(defined PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED) && \
(defined PNG_WRITE_SUPPORTED)
if (!(png_ptr->mode & PNG_IS_READ_STRUCT))
{
png_app_error(png_ptr, "no unknown chunk support on write");
return;
}
# endif
np = png_voidcast(png_unknown_chunkp, png_malloc_warn(png_ptr,
(png_size_t)(info_ptr->unknown_chunks_num + num_unknowns) *
png_sizeof(png_unknown_chunk)));
/* 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
*/
np = png_voidcast(png_unknown_chunkp, png_malloc(png_ptr,
(info_ptr->unknown_chunks_num + (unsigned int)num_unknowns) *
(sizeof (png_unknown_chunk))));
if (np == NULL)
{
png_warning(png_ptr,
"Out of memory while processing unknown chunk");
return;
}
memcpy(np, info_ptr->unknown_chunks,
info_ptr->unknown_chunks_num * (sizeof (png_unknown_chunk)));
png_memcpy(np, info_ptr->unknown_chunks,
(png_size_t)info_ptr->unknown_chunks_num *
png_sizeof(png_unknown_chunk));
png_free(png_ptr, info_ptr->unknown_chunks);
info_ptr->unknown_chunks = np; /* safe because it is initialized */
info_ptr->free_me |= PNG_FREE_UNKN;
info_ptr->unknown_chunks = NULL;
np += info_ptr->unknown_chunks_num;
/* 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 (i = 0; i < num_unknowns; i++)
{
memcpy(np->name, unknowns->name, (sizeof unknowns->name));
np->name[(sizeof np->name)-1] = '\0';
np->size = unknowns->size;
np->location = check_location(png_ptr, unknowns->location);
png_unknown_chunkp to = np + info_ptr->unknown_chunks_num + i;
png_const_unknown_chunkp from = unknowns + i;
if (unknowns->size == 0)
np->data = NULL;
png_memcpy(to->name, from->name, png_sizeof(from->name));
to->name[png_sizeof(to->name)-1] = '\0';
to->size = from->size;
/* Note our location in the read or write sequence */
to->location = (png_byte)png_ptr->mode;
if (from->size == 0)
to->data=NULL;
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));
memcpy(np->data, unknowns->data, unknowns->size);
to->data = (png_bytep)png_malloc_warn(png_ptr,
(png_size_t)from->size);
if (to->data == NULL)
{
png_warning(png_ptr,
"Out of memory while processing unknown chunk");
to->size = 0;
}
else
png_memcpy(to->data, from->data, from->size);
}
}
info_ptr->unknown_chunks = np;
info_ptr->unknown_chunks_num += num_unknowns;
info_ptr->free_me |= PNG_FREE_UNKN;
}
void PNGAPI
png_set_unknown_chunk_location(png_const_structrp png_ptr, png_inforp info_ptr,
int chunk, int location)
{
/* 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)
{
if ((location & (PNG_HAVE_IHDR|PNG_HAVE_PLTE|PNG_AFTER_IDAT)) == 0)
{
png_app_error(png_ptr, "invalid unknown chunk location");
/* Fake out the pre 1.6.0 behavior: */
if ((location & PNG_HAVE_IDAT)) /* undocumented! */
location = PNG_AFTER_IDAT;
else
location = PNG_HAVE_IHDR; /* also undocumented */
}
info_ptr->unknown_chunks[chunk].location =
check_location(png_ptr, location);
}
if (png_ptr != NULL && info_ptr != NULL && chunk >= 0 && chunk <
info_ptr->unknown_chunks_num)
info_ptr->unknown_chunks[chunk].location = (png_byte)location;
}
#endif
@@ -1227,177 +1160,58 @@ png_permit_mng_features (png_structrp png_ptr, png_uint_32 mng_features)
#endif
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
static unsigned int
add_one_chunk(png_bytep list, unsigned int count, png_const_bytep add, int keep)
{
unsigned int i;
/* Utility function: update the 'keep' state of a chunk if it is already in
* the list, otherwise add it to the list.
*/
for (i=0; i<count; ++i, list += 5) if (memcmp(list, add, 4) == 0)
{
list[4] = (png_byte)keep;
return count;
}
if (keep != PNG_HANDLE_CHUNK_AS_DEFAULT)
{
++count;
memcpy(list, add, 4);
list[4] = (png_byte)keep;
}
return count;
}
void PNGAPI
png_set_keep_unknown_chunks(png_structrp png_ptr, int keep,
png_const_bytep chunk_list, int num_chunks_in)
png_const_bytep chunk_list, int num_chunksIn)
{
png_bytep new_list;
unsigned int num_chunks, old_num_chunks;
png_bytep new_list, p;
unsigned int i, num_chunks, old_num_chunks;
if (png_ptr == NULL)
return;
if (keep < 0 || keep >= PNG_HANDLE_CHUNK_LAST)
if (num_chunksIn <= 0)
{
png_app_error(png_ptr, "png_set_keep_unknown_chunks: invalid keep");
if (keep == PNG_HANDLE_CHUNK_ALWAYS || keep == PNG_HANDLE_CHUNK_IF_SAFE)
png_ptr->flags |= PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
else
png_ptr->flags &= ~PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
if (keep == PNG_HANDLE_CHUNK_ALWAYS)
png_ptr->flags |= PNG_FLAG_KEEP_UNSAFE_CHUNKS;
else
png_ptr->flags &= ~PNG_FLAG_KEEP_UNSAFE_CHUNKS;
return;
}
if (num_chunks_in <= 0)
{
png_ptr->unknown_default = keep;
if (chunk_list == NULL)
return;
/* '0' means just set the flags, so stop here */
if (num_chunks_in == 0)
return;
}
if (num_chunks_in < 0)
{
/* Ignore all unknown chunks and all chunks recognized by
* libpng except for IHDR, PLTE, tRNS, IDAT, and IEND
*/
static PNG_CONST png_byte chunks_to_ignore[] = {
98, 75, 71, 68, '\0', /* bKGD */
99, 72, 82, 77, '\0', /* cHRM */
103, 65, 77, 65, '\0', /* gAMA */
104, 73, 83, 84, '\0', /* hIST */
105, 67, 67, 80, '\0', /* iCCP */
105, 84, 88, 116, '\0', /* iTXt */
111, 70, 70, 115, '\0', /* oFFs */
112, 67, 65, 76, '\0', /* pCAL */
112, 72, 89, 115, '\0', /* pHYs */
115, 66, 73, 84, '\0', /* sBIT */
115, 67, 65, 76, '\0', /* sCAL */
115, 80, 76, 84, '\0', /* sPLT */
115, 84, 69, 82, '\0', /* sTER */
115, 82, 71, 66, '\0', /* sRGB */
116, 69, 88, 116, '\0', /* tEXt */
116, 73, 77, 69, '\0', /* tIME */
122, 84, 88, 116, '\0' /* zTXt */
};
chunk_list = chunks_to_ignore;
num_chunks = (sizeof chunks_to_ignore)/5;
}
else /* num_chunks_in > 0 */
{
if (chunk_list == NULL)
{
/* Prior to 1.6.0 this was silently ignored, now it is an app_error
* which can be switched off.
*/
png_app_error(png_ptr, "png_set_keep_unknown_chunks: no chunk list");
return;
}
num_chunks = num_chunks_in;
}
/* The argument is >0 */
num_chunks = (unsigned int)num_chunksIn;
old_num_chunks = png_ptr->num_chunk_list;
if (png_ptr->chunk_list == NULL)
old_num_chunks = 0;
new_list = png_voidcast(png_bytep, png_malloc(png_ptr,
5 * (num_chunks + old_num_chunks)));
/* Since num_chunks is always restricted to UINT_MAX/5 this can't overflow.
*/
if (num_chunks + old_num_chunks > UINT_MAX/5)
if (png_ptr->chunk_list != NULL)
{
png_app_error(png_ptr, "png_set_keep_unknown_chunks: too many chunks");
return;
png_memcpy(new_list, png_ptr->chunk_list, 5*old_num_chunks);
png_free(png_ptr, png_ptr->chunk_list);
png_ptr->chunk_list=NULL;
}
/* If these chunks are being reset to the default then no more memory is
* required because add_one_chunk above doesn't extend the list if the 'keep'
* parameter is the default.
*/
if (keep)
{
new_list = png_voidcast(png_bytep, png_malloc(png_ptr,
5 * (num_chunks + old_num_chunks)));
png_memcpy(new_list + 5*old_num_chunks, chunk_list,
5*(unsigned int)num_chunks);
if (old_num_chunks > 0)
memcpy(new_list, png_ptr->chunk_list, 5*old_num_chunks);
}
for (p = new_list + 5*old_num_chunks + 4, i = 0; i<num_chunks; i++, p += 5)
*p=(png_byte)keep;
else if (old_num_chunks > 0)
new_list = png_ptr->chunk_list;
else
new_list = NULL;
/* Add the new chunks together with each one's handling code. If the chunk
* already exists the code is updated, otherwise the chunk is added to the
* end. (In libpng 1.6.0 order no longer matters because this code enforces
* the earlier convention that the last setting is the one that is used.)
*/
if (new_list != NULL)
{
png_const_bytep inlist;
png_bytep outlist;
unsigned int i;
for (i=0; i<num_chunks; ++i)
old_num_chunks = add_one_chunk(new_list, old_num_chunks,
chunk_list+5*i, keep);
/* Now remove any spurious 'default' entries. */
num_chunks = 0;
for (i=0, inlist=outlist=new_list; i<old_num_chunks; ++i, inlist += 5)
if (inlist[4])
{
if (outlist != inlist)
memcpy(outlist, inlist, 5);
outlist += 5;
++num_chunks;
}
/* This means the application has removed all the specialized handling. */
if (num_chunks == 0)
{
if (png_ptr->chunk_list != new_list)
png_free(png_ptr, new_list);
new_list = NULL;
}
}
else
num_chunks = 0;
png_ptr->num_chunk_list = num_chunks;
if (png_ptr->chunk_list != new_list)
{
if (png_ptr->chunk_list != NULL)
png_free(png_ptr, png_ptr->chunk_list);
png_ptr->chunk_list = new_list;
}
png_ptr->num_chunk_list = old_num_chunks + num_chunks;
png_ptr->chunk_list = new_list;
png_ptr->free_me |= PNG_FREE_LIST;
}
#endif
@@ -1462,14 +1276,14 @@ png_set_compression_buffer_size(png_structrp png_ptr, png_size_t size)
"Compression buffer size cannot be changed because it is in use");
return;
}
if (size > ZLIB_IO_MAX)
{
png_warning(png_ptr,
"Compression buffer size limited to system maximum");
size = ZLIB_IO_MAX; /* must fit */
}
else if (size < 6)
{
/* Deflate will potentially go into an infinite loop on a SYNC_FLUSH
@@ -1479,7 +1293,7 @@ png_set_compression_buffer_size(png_structrp png_ptr, png_size_t size)
"Compression buffer size cannot be reduced below 6");
return;
}
if (png_ptr->zbuffer_size != size)
{
png_free_buffer_list(png_ptr, &png_ptr->zbuffer_list);
@@ -1555,7 +1369,7 @@ png_set_benign_errors(png_structrp png_ptr, int allowed)
}
#endif /* PNG_BENIGN_ERRORS_SUPPORTED */
#ifdef PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED
#ifdef PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED
/* Do not report invalid palette index; added at libng-1.5.10 */
void PNGAPI
png_set_check_for_invalid_index(png_structrp png_ptr, int allowed)

View File

@@ -94,9 +94,9 @@ typedef struct png_xy
*/
typedef struct png_XYZ
{
png_fixed_point red_X, red_Y, red_Z;
png_fixed_point green_X, green_Y, green_Z;
png_fixed_point blue_X, blue_Y, blue_Z;
png_fixed_point redX, redY, redZ;
png_fixed_point greenX, greenY, greenZ;
png_fixed_point blueX, blueY, blueZ;
} png_XYZ;
#endif /* COLORSPACE */
@@ -119,7 +119,6 @@ typedef struct png_colorspace
#ifdef PNG_COLORSPACE_SUPPORTED
png_xy end_points_xy; /* End points as chromaticities */
png_XYZ end_points_XYZ; /* End points as CIE XYZ colorant values */
png_uint_32 icc_info; /* Record of information from the colorspace */
png_uint_16 rendering_intent; /* Rendering intent of a profile */
#endif
@@ -129,75 +128,6 @@ typedef struct png_colorspace
typedef const png_colorspace * PNG_RESTRICT png_const_colorspacerp;
/* ICC specific flags for the 'icc_info' field. */
/* The first four bits are for information defined from the profile, the
* remainder of the bits indicate the presence of specific tags. The #define
* names are derived from the tag name in the ICC 2010 (v4) specification.
*/
# define PNG_ICC_PCSXYZ 0x00000001U /* PCSXYS, else PCSLAB */
# define PNG_ICC_RGB 0x00000002U /* 'RGB ', else 'GRAY ' */
/* 0x00000004U reserved */
/* 0x00000008U reserved */
/* A utility to return the number of channels on the A side of the transform
* given an info value (can be optimized).
*/
# define PNG_ICC_CHANNELS(info) ((((info)&PNG_ICC_RGB)?2U:0U)+1U)
/* The profile description and copyright must be present in all valid ICC
* profiles, however libpng does not use them so absence is just reported as
* a warning. The media white point should be present too, but if it isn't
* all we lose is the ability to know if it differs from the adopted white
* (i.e. the information that the device maxima are actually colored;
* a non-white substrate for a printer, or an uncorrected scan for example.)
* The chromaticAdaptationTag tells us that the adopted white of the original
* differs from the PCS adopted white (which is identical to the PCS
* illuminant and should always be D50).
*/
# define PNG_ICC_profileDescriptionTag 0x00000010U /* required */
# define PNG_ICC_copyrightTag 0x00000020U /* required */
# define PNG_ICC_mediaWhitePointTag 0x00000040U /* required */
# define PNG_ICC_chromaticAdaptationTag 0x00000080U /* optional */
/* Tags that are required in all profiles (except DeviceLink): */
# define PNG_ICC_REQUIRED_BASE 0x00000070U
/* Other tags have to appear in specific profiles. In general a profile must
* either contain appropriate TRC and (for RGB profiles) matrix tags *or* it
* must contain AToB0 and BToA0 - the CLUT based transforms to an absolute
* colorimetric PCS. In the TRC case the PCS encoding must be PCSXYZ.
*/
# define PNG_ICC_redMatrixColumnTag 0x00000100U
# define PNG_ICC_greenMatrixColumnTag 0x00000200U
# define PNG_ICC_blueMatrixColumnTag 0x00000400U
/* 0x00000800U reserved */
# define PNG_ICC_redTRCTag 0x00001000U
# define PNG_ICC_greenTRCTag 0x00002000U
# define PNG_ICC_blueTRCTag 0x00004000U
# define PNG_ICC_grayTRCTag 0x00008000U
# define PNG_ICC_REQUIRED_RGB_MATRIXTRC 0x00007700U /* Required for RGB TRC */
# define PNG_ICC_ALL_TRC 0x0000f000U /* Includes all TRCTags */
# define PNG_ICC_REQUIRED_MATRIX 0x00000700U /* All MatrixColumnTags */
# define PNG_ICC_AToB0Tag 0x00010000U
# define PNG_ICC_BToA0Tag 0x00020000U
# define PNG_ICC_AToB1Tag 0x00040000U
# define PNG_ICC_BToA1Tag 0x00080000U
# define PNG_ICC_AToB2Tag 0x00100000U
# define PNG_ICC_BToA2Tag 0x00200000U
# define PNG_ICC_AToB_TAGS 0x00050000U /* Just AToB0 and AToB1 */
# define PNG_ICC_ALL_LUT 0x003f0000U
/* 0x00400000U reserved */
/* 0x00800000U reserved */
/* The ICC profile specification allows for shortcuts in the cHRM calculation
* via the colorant table (clrt) or the chromaticity tag (chrm).
*/
# define PNG_ICC_chromaticityTag 0x01000000U
# define PNG_ICC_colorantTableTag 0x02000000U
# define PNG_ICC_gamutTag 0x04000000U
/* General flags for the 'flags' field */
#define PNG_COLORSPACE_HAVE_GAMMA 0x0001
#define PNG_COLORSPACE_HAVE_ENDPOINTS 0x0002
#define PNG_COLORSPACE_HAVE_INTENT 0x0004
@@ -322,9 +252,7 @@ struct png_struct_def
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 */
@@ -426,7 +354,6 @@ struct png_struct_def
#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
@@ -438,16 +365,12 @@ struct png_struct_def
#ifdef PNG_USER_CHUNKS_SUPPORTED
png_voidp user_chunk_ptr;
#ifdef PNG_READ_USER_CHUNKS_SUPPORTED
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 */
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
unsigned int num_chunk_list;
png_bytep chunk_list;
#endif
/* New members added in libpng-1.0.3 */
@@ -512,12 +435,14 @@ struct png_struct_def
#endif
/* New member added in libpng-1.0.25 and 1.2.17 */
#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
/* Temporary storage for unknown chunk that the library doesn't recognize,
* used while reading the chunk.
*/
#ifdef PNG_READ_SUPPORTED
png_unknown_chunk unknown_chunk;
#endif
#endif
/* New member added in libpng-1.2.26 */
png_size_t old_big_row_buf_size;

617
pngtest.c
View File

@@ -33,23 +33,16 @@
#define _POSIX_SOURCE 1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* Defined so I can write to a file on gui/windowing platforms */
/* #define STDERR stderr */
#define STDERR stdout /* For DOS */
#include "png.h"
#ifdef PNG_READ_SUPPORTED /* else nothing can be done */
#include "zlib.h"
#include "png.h"
/* Copied from pngpriv.h but only used in error messages below. */
#ifndef PNG_ZBUF_SIZE
# define PNG_ZBUF_SIZE 8192
#endif
#define FCLOSE(file) fclose(file)
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# define FCLOSE(file) fclose(file)
#ifndef PNG_STDIO_SUPPORTED
typedef FILE * png_FILE_p;
@@ -95,31 +88,20 @@ static char tIME_string[PNG_tIME_STRING_LENGTH] = "tIME chunk is not present";
static int verbose = 0;
static int strict = 0;
static int relaxed = 0;
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
/* Defined so I can write to a file on gui/windowing platforms */
/* #define STDERR stderr */
#define STDERR stdout /* For DOS */
/* 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
#endif
/* Defines for unknown chunk handling if required. */
#ifndef PNG_HANDLE_CHUNK_ALWAYS
# define PNG_HANDLE_CHUNK_ALWAYS 3
#endif
#ifndef PNG_HANDLE_CHUNK_IF_SAFE
# define PNG_HANDLE_CHUNK_IF_SAFE 2
#endif
/* Utility to save typing/errors, the argument must be a name */
#define MEMZERO(var) ((void)memset(&var, 0, sizeof var))
/* Example of using row callbacks to make a simple progress meter */
static int status_pass = 1;
static int status_dots_requested = 0;
@@ -149,7 +131,6 @@ read_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass)
fprintf(stdout, "r");
}
#ifdef PNG_WRITE_SUPPORTED
static void PNGCBAPI
write_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass)
{
@@ -158,7 +139,6 @@ write_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass)
fprintf(stdout, "w");
}
#endif
#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
@@ -289,6 +269,8 @@ count_zero_samples(png_structp png_ptr, png_row_infop row_info, png_bytep data)
}
#endif /* PNG_WRITE_USER_TRANSFORM_SUPPORTED */
static int wrote_question = 0;
#ifndef PNG_STDIO_SUPPORTED
/* START of code to validate stdio-free compilation */
/* These copies of the default read/write functions come from pngrio.c and
@@ -396,31 +378,24 @@ pngtest_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
pngtest_check_io_state(png_ptr, length, PNG_IO_WRITING);
#endif
}
#endif /* !PNG_STDIO_SUPPORTED */
/* This function is called when there is a warning, but the library thinks
* it can continue anyway. Replacement functions don't have to do anything
* here if you don't want to. In the default configuration, png_ptr is
* not used, but it is passed in case it may be useful.
*/
typedef struct
{
PNG_CONST char *file_name;
} pngtest_error_parameters;
static void PNGCBAPI
pngtest_warning(png_structp png_ptr, png_const_charp message)
{
PNG_CONST char *name = "UNKNOWN (ERROR!)";
pngtest_error_parameters *test =
(pngtest_error_parameters*)png_get_error_ptr(png_ptr);
char *test;
test = png_get_error_ptr(png_ptr);
++warning_count;
if (test == NULL)
fprintf(STDERR, "%s: libpng warning: %s\n", name, message);
if (test != NULL && test->file_name != NULL)
name = test->file_name;
fprintf(STDERR, "%s: libpng warning: %s\n", name, message);
else
fprintf(STDERR, "%s: libpng warning: %s\n", test, message);
}
/* This is the default error handling function. Note that replacements for
@@ -431,14 +406,12 @@ pngtest_warning(png_structp png_ptr, png_const_charp message)
static void PNGCBAPI
pngtest_error(png_structp png_ptr, png_const_charp message)
{
++error_count;
pngtest_warning(png_ptr, message);
/* We can return because png_error calls the default handler, which is
* actually OK in this case.
*/
}
#endif /* !PNG_STDIO_SUPPORTED */
/* END of code to validate stdio-free compilation */
/* START of code to validate memory allocation and deallocation */
@@ -489,7 +462,7 @@ PNGCBAPI png_debug_malloc(png_structp png_ptr, png_alloc_size_t size)
memory_infop pinfo;
png_set_mem_fn(png_ptr, NULL, NULL, NULL);
pinfo = (memory_infop)png_malloc(png_ptr,
(sizeof *pinfo));
png_sizeof(*pinfo));
pinfo->size = size;
current_allocation += size;
total_allocation += size;
@@ -583,73 +556,25 @@ png_debug_free(png_structp png_ptr, png_voidp ptr)
/* END of code to test memory allocation/deallocation */
#ifdef PNG_READ_USER_CHUNKS_SUPPORTED
/* Demonstration of user chunk support of the sTER and vpAg chunks */
#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
/* (sTER is a public chunk not yet known by libpng. vpAg is a private
chunk used in ImageMagick to store "virtual page" size). */
static struct user_chunk_data
{
png_const_infop info_ptr;
png_uint_32 vpAg_width, vpAg_height;
png_byte vpAg_units;
png_byte sTER_mode;
int location[2];
}
user_chunk_data;
static png_uint_32 user_chunk_data[4];
/* Used for location and order; zero means nothing. */
#define have_sTER 0x01
#define have_vpAg 0x02
#define before_PLTE 0x10
#define before_IDAT 0x20
#define after_IDAT 0x40
static void
init_callback_info(png_const_infop info_ptr)
{
MEMZERO(user_chunk_data);
user_chunk_data.info_ptr = info_ptr;
}
static int
set_location(png_structp png_ptr, struct user_chunk_data *data, int what)
{
int location;
if ((data->location[0] & what) || (data->location[1] & what))
return 0; /* already have one of these */
/* Find where we are (the code below zeros info_ptr to indicate that the
* chunks before the first IDAT have been read.)
*/
if (data->info_ptr == NULL) /* after IDAT */
location = what | after_IDAT;
else if (png_get_valid(png_ptr, data->info_ptr, PNG_INFO_PLTE))
location = what | before_IDAT;
else
location = what | before_PLTE;
if (data->location[0] == 0)
data->location[0] = location;
else
data->location[1] = location;
return 1; /* handled */
}
/* 0: sTER mode + 1
* 1: vpAg width
* 2: vpAg height
* 3: vpAg units
*/
static int PNGCBAPI read_user_chunk_callback(png_struct *png_ptr,
png_unknown_chunkp chunk)
{
struct user_chunk_data *my_user_chunk_data =
(struct user_chunk_data*)png_get_user_chunk_ptr(png_ptr);
if (my_user_chunk_data == NULL)
png_error(png_ptr, "lost user chunk pointer");
png_uint_32
*my_user_chunk_data;
/* Return one of the following:
* return (-n); chunk had an error
@@ -674,14 +599,9 @@ static int PNGCBAPI read_user_chunk_callback(png_struct *png_ptr,
if (chunk->data[0] != 0 && chunk->data[0] != 1)
return (-1); /* Invalid mode */
if (set_location(png_ptr, my_user_chunk_data, have_sTER))
{
my_user_chunk_data->sTER_mode=chunk->data[0];
return (1);
}
else
return (0); /* duplicate sTER - give it to libpng */
my_user_chunk_data=(png_uint_32 *) png_get_user_chunk_ptr(png_ptr);
my_user_chunk_data[0]=chunk->data[0]+1;
return (1);
}
if (chunk->name[0] != 118 || chunk->name[1] != 112 || /* v p */
@@ -693,119 +613,24 @@ static int PNGCBAPI read_user_chunk_callback(png_struct *png_ptr,
if (chunk->size != 9)
return (-1); /* Error return */
if (!set_location(png_ptr, my_user_chunk_data, have_vpAg))
return (0); /* duplicate vpAg */
my_user_chunk_data=(png_uint_32 *) png_get_user_chunk_ptr(png_ptr);
my_user_chunk_data->vpAg_width = png_get_uint_31(png_ptr, chunk->data);
my_user_chunk_data->vpAg_height = png_get_uint_31(png_ptr, chunk->data + 4);
my_user_chunk_data->vpAg_units = chunk->data[8];
my_user_chunk_data[1]=png_get_uint_31(png_ptr, chunk->data);
my_user_chunk_data[2]=png_get_uint_31(png_ptr, chunk->data + 4);
my_user_chunk_data[3]=(png_uint_32)chunk->data[8];
return (1);
}
#ifdef PNG_WRITE_SUPPORTED
static void
write_sTER_chunk(png_structp write_ptr)
{
png_byte png_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);
}
static void
write_vpAg_chunk(png_structp write_ptr)
{
png_byte png_vpAg[5] = {118, 112, 65, 103, '\0'};
png_byte vpag_chunk_data[9];
if (verbose)
fprintf(STDERR, " vpAg = %lu x %lu, units = %d\n",
(unsigned long)user_chunk_data.vpAg_width,
(unsigned long)user_chunk_data.vpAg_height,
user_chunk_data.vpAg_units);
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);
}
static void
write_chunks(png_structp write_ptr, int location)
{
int i;
/* Notice that this preserves the original chunk order, however chunks
* intercepted by the callback will be written *after* chunks passed to
* libpng. This will actually reverse a pair of sTER chunks or a pair of
* vpAg chunks, resulting in an error later. This is not worth worrying
* about - the chunks should not be duplicated!
*/
for (i=0; i<2; ++i)
{
if (user_chunk_data.location[i] == (location | have_sTER))
write_sTER_chunk(write_ptr);
else if (user_chunk_data.location[i] == (location | have_vpAg))
write_vpAg_chunk(write_ptr);
}
}
#endif /* PNG_WRITE_SUPPORTED */
#else /* !PNG_READ_USER_CHUNKS_SUPPORTED */
# define write_chunks(pp,loc) ((void)0)
#endif
/* END of code to demonstrate user chunk support */
/* START of code to check that libpng has the required text support; this only
* checks for the write support because if read support is missing the chunk
* will simply not be reported back to pngtest.
*/
#ifdef PNG_TEXT_SUPPORTED
static void
pngtest_check_text_support(png_const_structp png_ptr, png_textp text_ptr,
int num_text)
{
while (num_text > 0)
{
switch (text_ptr[--num_text].compression)
{
case PNG_TEXT_COMPRESSION_NONE:
break;
case PNG_TEXT_COMPRESSION_zTXt:
# ifndef PNG_WRITE_zTXt_SUPPORTED
++unsupported_chunks;
# endif
break;
case PNG_ITXT_COMPRESSION_NONE:
case PNG_ITXT_COMPRESSION_zTXt:
# ifndef PNG_WRITE_iTXt_SUPPORTED
++unsupported_chunks;
# endif
break;
default:
/* This is an error */
png_error(png_ptr, "invalid text chunk compression field");
break;
}
}
}
#endif
/* END of code to check that libpng has the required text support */
/* Test one file */
static int
test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
{
static png_FILE_p fpin;
static png_FILE_p fpout; /* "static" prevents setjmp corruption */
pngtest_error_parameters error_parameters;
png_structp read_ptr;
png_infop read_info_ptr, end_info_ptr;
#ifdef PNG_WRITE_SUPPORTED
@@ -823,8 +648,9 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
int num_pass, pass;
int bit_depth, color_type;
char inbuf[256], outbuf[256];
row_buf = NULL;
error_parameters.file_name = inname;
if ((fpin = fopen(inname, "rb")) == NULL)
{
@@ -848,9 +674,20 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
read_ptr =
png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
#endif
png_set_error_fn(read_ptr, &error_parameters, pngtest_error,
pngtest_warning);
#ifndef PNG_STDIO_SUPPORTED
png_set_error_fn(read_ptr, (png_voidp)inname, pngtest_error,
pngtest_warning);
#endif
#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
user_chunk_data[0] = 0;
user_chunk_data[1] = 0;
user_chunk_data[2] = 0;
user_chunk_data[3] = 0;
png_set_read_user_chunk_fn(read_ptr, user_chunk_data,
read_user_chunk_callback);
#endif
#ifdef PNG_WRITE_SUPPORTED
#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
write_ptr =
@@ -860,8 +697,10 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
write_ptr =
png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
#endif
png_set_error_fn(write_ptr, &error_parameters, pngtest_error,
pngtest_warning);
#ifndef PNG_STDIO_SUPPORTED
png_set_error_fn(write_ptr, (png_voidp)inname, pngtest_error,
pngtest_warning);
#endif
#endif
pngtest_debug("Allocating read_info, write_info and end_info structures");
read_info_ptr = png_create_info_struct(read_ptr);
@@ -871,12 +710,6 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
write_end_info_ptr = png_create_info_struct(write_ptr);
#endif
#ifdef PNG_READ_USER_CHUNKS_SUPPORTED
init_callback_info(read_info_ptr);
png_set_read_user_chunk_fn(read_ptr, &user_chunk_data,
read_user_chunk_callback);
#endif
#ifdef PNG_SETJMP_SUPPORTED
pngtest_debug("Setting jmpbuf for read struct");
if (setjmp(png_jmpbuf(read_ptr)))
@@ -916,26 +749,11 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
{
/* Treat png_benign_error() as errors on read */
png_set_benign_errors(read_ptr, 0);
#ifdef PNG_WRITE_SUPPORTED
/* Treat them as errors on write */
png_set_benign_errors(write_ptr, 0);
#endif
/* if strict is not set, then app warnings and errors are treated as
* warnings in release builds, but not in unstable builds; this can be
* changed with '--relaxed'.
*/
}
else if (relaxed)
{
/* Allow application (pngtest) errors and warnings to pass */
png_set_benign_errors(read_ptr, 1);
#ifdef PNG_WRITE_SUPPORTED
png_set_benign_errors(write_ptr, 1);
#endif
/* if strict is not set, then both are treated as warnings. */
}
pngtest_debug("Initializing input and output streams");
@@ -956,6 +774,14 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
# endif
#endif
#ifdef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED
/* Normally one would use Z_DEFAULT_STRATEGY for text compression.
* This is here just to make pngtest replicate the results from libpng
* versions prior to 1.5.4, and to test this new API.
*/
png_set_text_compression_strategy(write_ptr, Z_FILTERED);
#endif
if (status_dots_requested == 1)
{
#ifdef PNG_WRITE_SUPPORTED
@@ -987,37 +813,24 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
png_set_write_user_transform_fn(write_ptr, count_zero_samples);
#endif
#ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED
/* Preserve all the unknown chunks, if possible. If this is disabled then,
* even if the png_{get,set}_unknown_chunks stuff is enabled, we can't use
* libpng to *save* the unknown chunks on read (because we can't switch the
* save option on!)
*
* Notice that if SET_UNKNOWN_CHUNKS is *not* supported read will discard all
* unknown chunks and write will write them all.
*/
#ifdef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED
#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
# ifndef PNG_HANDLE_CHUNK_ALWAYS
# define PNG_HANDLE_CHUNK_ALWAYS 3
# endif
png_set_keep_unknown_chunks(read_ptr, PNG_HANDLE_CHUNK_ALWAYS,
NULL, 0);
#endif
#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
png_set_keep_unknown_chunks(write_ptr, PNG_HANDLE_CHUNK_ALWAYS,
# ifndef PNG_HANDLE_CHUNK_IF_SAFE
# define PNG_HANDLE_CHUNK_IF_SAFE 2
# endif
png_set_keep_unknown_chunks(write_ptr, PNG_HANDLE_CHUNK_IF_SAFE,
NULL, 0);
#endif
#endif
pngtest_debug("Reading info struct");
png_read_info(read_ptr, read_info_ptr);
#ifdef PNG_READ_USER_CHUNKS_SUPPORTED
/* This is a bit of a hack; there is no obvious way in the callback function
* to determine that the chunks before the first IDAT have been read, so
* remove the info_ptr (which is only used to determine position relative to
* PLTE) here to indicate that we are after the IDAT.
*/
user_chunk_data.info_ptr = NULL;
#endif
pngtest_debug("Transferring info struct");
{
int interlace_type, compression_type, filter_type;
@@ -1209,8 +1022,6 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
{
pngtest_debug1("Handling %d iTXt/tEXt/zTXt chunks", num_text);
pngtest_check_text_support(read_ptr, text_ptr, num_text);
if (verbose)
{
int i;
@@ -1236,13 +1047,10 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
png_set_tIME(write_ptr, write_info_ptr, mod_time);
#ifdef PNG_TIME_RFC1123_SUPPORTED
if (png_convert_to_rfc1123_buffer(tIME_string, mod_time))
tIME_string[(sizeof tIME_string) - 1] = '\0';
tIME_string[png_sizeof(tIME_string) - 1] = '\0';
else
{
strncpy(tIME_string, "*** invalid time ***", (sizeof tIME_string));
tIME_string[(sizeof tIME_string) - 1] = '\0';
}
strcpy(tIME_string, "*** invalid time ***");
tIME_chunk_present++;
#endif /* PNG_TIME_RFC1123_SUPPORTED */
@@ -1279,20 +1087,16 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
if (num_unknowns)
{
int i;
png_set_unknown_chunks(write_ptr, write_info_ptr, unknowns,
num_unknowns);
#if PNG_LIBPNG_VER < 10600
/* Copy the locations from the read_info_ptr. The automatically
* generated locations in write_end_info_ptr are wrong prior to 1.6.0
* because they are reset from the write pointer (removed in 1.6.0).
* generated locations in write_info_ptr are wrong because we
* haven't written anything yet.
*/
{
int i;
for (i = 0; i < num_unknowns; i++)
png_set_unknown_chunk_location(write_ptr, write_info_ptr, i,
unknowns[i].location);
}
#endif
for (i = 0; i < num_unknowns; i++)
png_set_unknown_chunk_location(write_ptr, write_info_ptr, i,
unknowns[i].location);
}
}
#endif
@@ -1300,16 +1104,47 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
#ifdef PNG_WRITE_SUPPORTED
pngtest_debug("Writing info struct");
/* Write the info in two steps so that if we write the 'unknown' chunks here
* they go to the correct place.
*/
png_write_info_before_PLTE(write_ptr, write_info_ptr);
write_chunks(write_ptr, before_PLTE); /* before PLTE */
/* If we wanted, we could write info in two steps:
* png_write_info_before_PLTE(write_ptr, write_info_ptr);
*/
png_write_info(write_ptr, write_info_ptr);
write_chunks(write_ptr, before_IDAT); /* after PLTE */
#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
if (user_chunk_data[0] != 0)
{
png_byte png_sTER[5] = {115, 84, 69, 82, '\0'};
unsigned char
ster_chunk_data[1];
if (verbose)
fprintf(STDERR, "\n stereo mode = %lu\n",
(unsigned long)(user_chunk_data[0] - 1));
ster_chunk_data[0]=(unsigned char)(user_chunk_data[0] - 1);
png_write_chunk(write_ptr, png_sTER, ster_chunk_data, 1);
}
if (user_chunk_data[1] != 0 || user_chunk_data[2] != 0)
{
png_byte png_vpAg[5] = {118, 112, 65, 103, '\0'};
unsigned char
vpag_chunk_data[9];
if (verbose)
fprintf(STDERR, " vpAg = %lu x %lu, units = %lu\n",
(unsigned long)user_chunk_data[1],
(unsigned long)user_chunk_data[2],
(unsigned long)user_chunk_data[3]);
png_save_uint_32(vpag_chunk_data, user_chunk_data[1]);
png_save_uint_32(vpag_chunk_data + 4, user_chunk_data[2]);
vpag_chunk_data[8] = (unsigned char)(user_chunk_data[3] & 0xff);
png_write_chunk(write_ptr, png_vpAg, vpag_chunk_data, 9);
}
#endif
#endif
#ifdef SINGLE_ROWBUF_ALLOC
@@ -1393,8 +1228,6 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
{
pngtest_debug1("Handling %d iTXt/tEXt/zTXt chunks", num_text);
pngtest_check_text_support(read_ptr, text_ptr, num_text);
if (verbose)
{
int i;
@@ -1420,13 +1253,10 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
png_set_tIME(write_ptr, write_end_info_ptr, mod_time);
#ifdef PNG_TIME_RFC1123_SUPPORTED
if (png_convert_to_rfc1123_buffer(tIME_string, mod_time))
tIME_string[(sizeof tIME_string) - 1] = '\0';
tIME_string[png_sizeof(tIME_string) - 1] = '\0';
else
{
strncpy(tIME_string, "*** invalid time ***", sizeof tIME_string);
tIME_string[(sizeof tIME_string)-1] = '\0';
}
strcpy(tIME_string, "*** invalid time ***");
tIME_chunk_present++;
#endif /* PNG_TIME_RFC1123_SUPPORTED */
@@ -1441,40 +1271,20 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
if (num_unknowns)
{
int i;
png_set_unknown_chunks(write_ptr, write_end_info_ptr, unknowns,
num_unknowns);
#if PNG_LIBPNG_VER < 10600
/* Copy the locations from the read_info_ptr. The automatically
* generated locations in write_end_info_ptr are wrong prior to 1.6.0
* because they are reset from the write pointer (removed in 1.6.0).
* generated locations in write_end_info_ptr are wrong because we
* haven't written the end_info yet.
*/
{
int i;
for (i = 0; i < num_unknowns; i++)
png_set_unknown_chunk_location(write_ptr, write_end_info_ptr, i,
unknowns[i].location);
}
#endif
for (i = 0; i < num_unknowns; i++)
png_set_unknown_chunk_location(write_ptr, write_end_info_ptr, i,
unknowns[i].location);
}
}
#endif
#ifdef PNG_WRITE_SUPPORTED
#ifdef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED
/* Normally one would use Z_DEFAULT_STRATEGY for text compression.
* This is here just to make pngtest replicate the results from libpng
* versions prior to 1.5.4, and to test this new API.
*/
png_set_text_compression_strategy(write_ptr, Z_FILTERED);
#endif
/* 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
* after IDAT.
*/
write_chunks(write_ptr, after_IDAT);
png_write_end(write_ptr, write_end_info_ptr);
#endif
@@ -1508,40 +1318,6 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
FCLOSE(fpin);
FCLOSE(fpout);
/* Summarize any warnings or errors and in 'strict' mode fail the test.
* Unsupported chunks can result in warnings, in that case ignore the strict
* setting, otherwise fail the test on warnings as well as errors.
*/
if (error_count > 0)
{
/* We don't really expect to get here because of the setjmp handling
* above, but this is safe.
*/
fprintf(STDERR, "\n %s: %d libpng errors found (%d warnings)",
inname, error_count, warning_count);
if (strict != 0)
return (1);
}
# ifdef PNG_WRITE_SUPPORTED
/* If there we no write support nothing was written! */
else if (unsupported_chunks > 0)
{
fprintf(STDERR, "\n %s: unsupported chunks (%d)%s",
inname, unsupported_chunks, strict ? ": IGNORED --strict!" : "");
}
# endif
else if (warning_count > 0)
{
fprintf(STDERR, "\n %s: %d libpng warnings found",
inname, warning_count);
if (strict != 0)
return (1);
}
pngtest_debug("Opening files for comparison");
if ((fpin = fopen(inname, "rb")) == NULL)
{
@@ -1556,85 +1332,71 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
return (1);
}
#ifdef PNG_WRITE_SUPPORTED /* else nothing was written */
for (;;)
{
int wrote_question = 0;
png_size_t num_in, num_out;
for (;;)
num_in = fread(inbuf, 1, 1, fpin);
num_out = fread(outbuf, 1, 1, fpout);
if (num_in != num_out)
{
png_size_t num_in, num_out;
char inbuf[256], outbuf[256];
fprintf(STDERR, "\nFiles %s and %s are of a different size\n",
inname, outname);
num_in = fread(inbuf, 1, sizeof inbuf, fpin);
num_out = fread(outbuf, 1, sizeof outbuf, fpout);
if (num_in != num_out)
if (wrote_question == 0)
{
fprintf(STDERR, "\nFiles %s and %s are of a different size\n",
inname, outname);
fprintf(STDERR,
" Was %s written with the same maximum IDAT chunk size (%d bytes),",
inname, PNG_ZBUF_SIZE);
fprintf(STDERR,
"\n filtering heuristic (libpng default), compression");
fprintf(STDERR,
" level (zlib default),\n and zlib version (%s)?\n\n",
ZLIB_VERSION);
wrote_question = 1;
}
if (wrote_question == 0 && unsupported_chunks == 0)
{
fprintf(STDERR,
FCLOSE(fpin);
FCLOSE(fpout);
if (strict != 0)
return (1);
else
return (0);
}
if (!num_in)
break;
if (memcmp(inbuf, outbuf, num_in))
{
fprintf(STDERR, "\nFiles %s and %s are different\n", inname, outname);
if (wrote_question == 0)
{
fprintf(STDERR,
" Was %s written with the same maximum IDAT chunk size (%d bytes),",
inname, PNG_ZBUF_SIZE);
fprintf(STDERR,
"\n filtering heuristic (libpng default), compression");
fprintf(STDERR,
" level (zlib default),\n and zlib version (%s)?\n\n",
ZLIB_VERSION);
wrote_question = 1;
}
FCLOSE(fpin);
FCLOSE(fpout);
if (strict != 0 && unsupported_chunks == 0)
return (1);
else
return (0);
fprintf(STDERR,
"\n filtering heuristic (libpng default), compression");
fprintf(STDERR,
" level (zlib default),\n and zlib version (%s)?\n\n",
ZLIB_VERSION);
wrote_question = 1;
}
if (!num_in)
break;
FCLOSE(fpin);
FCLOSE(fpout);
if (memcmp(inbuf, outbuf, num_in))
{
fprintf(STDERR, "\nFiles %s and %s are different\n", inname,
outname);
if (strict != 0)
return (1);
if (wrote_question == 0 && unsupported_chunks == 0)
{
fprintf(STDERR,
" Was %s written with the same maximum IDAT chunk size (%d bytes),",
inname, PNG_ZBUF_SIZE);
fprintf(STDERR,
"\n filtering heuristic (libpng default), compression");
fprintf(STDERR,
" level (zlib default),\n and zlib version (%s)?\n\n",
ZLIB_VERSION);
wrote_question = 1;
}
FCLOSE(fpin);
FCLOSE(fpout);
/* NOTE: the unsupported_chunks escape is permitted here because
* unsupported text chunk compression will result in the compression
* mode being changed (to NONE) yet, in the test case, the result
* can be exactly the same size!
*/
if (strict != 0 && unsupported_chunks == 0)
return (1);
else
return (0);
}
else
return (0);
}
}
#endif /* PNG_WRITE_SUPPORTED */
FCLOSE(fpin);
FCLOSE(fpout);
@@ -1720,16 +1482,6 @@ main(int argc, char *argv[])
verbose = 1;
inname = argv[2];
strict++;
relaxed = 0;
}
else if (strcmp(argv[1], "--relaxed") == 0)
{
status_dots_requested = 0;
verbose = 1;
inname = argv[2];
strict = 0;
relaxed++;
}
else
@@ -1938,15 +1690,6 @@ main(int argc, char *argv[])
return (int)(ierror != 0);
}
#else
int
main(void)
{
fprintf(STDERR,
" test ignored because libpng was not built with read support\n");
return 0;
}
#endif
/* Generate a compiler error if there is an old png.h in the search path. */
typedef png_libpng_version_1_6_0beta30 Your_png_h_is_not_version_1_6_0beta30;
typedef png_libpng_version_1_6_0beta20 Your_png_h_is_not_version_1_6_0beta20;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.5 KiB

After

Width:  |  Height:  |  Size: 8.5 KiB

View File

@@ -122,79 +122,32 @@ png_set_filler(png_structrp png_ptr, png_uint_32 filler, int filler_loc)
if (png_ptr == NULL)
return;
/* In libpng 1.6 it is possible to determine whether this is a read or write
* operation and therefore to do more checking here for a valid call.
*/
if (png_ptr->mode & PNG_IS_READ_STRUCT)
{
# ifdef PNG_READ_FILLER_SUPPORTED
/* On read png_set_filler is always valid, regardless of the base PNG
* format, because other transformations can give a format where the
* filler code can execute (basically an 8 or 16-bit component RGB or G
* format.)
*
* NOTE: usr_channels is not used by the read code! (This has led to
* confusion in the past.) The filler is only used in the read code.
*/
png_ptr->filler = (png_uint_16)filler;
# else
png_app_error(png_ptr, "png_set_filler not supported on read");
PNG_UNUSED(filler) /* not used in the write case */
return;
# endif
}
else /* write */
{
# ifdef PNG_WRITE_FILLER_SUPPORTED
/* On write the usr_channels parameter must be set correctly at the
* start to record the number of channels in the app-supplied data.
*/
switch (png_ptr->color_type)
{
case PNG_COLOR_TYPE_RGB:
png_ptr->usr_channels = 4;
break;
case PNG_COLOR_TYPE_GRAY:
if (png_ptr->bit_depth >= 8)
{
png_ptr->usr_channels = 2;
break;
}
else
{
/* There simply isn't any code in libpng to strip out bits
* from bytes when the components are less than a byte in
* size!
*/
png_app_error(png_ptr,
"png_set_filler is invalid for low bit depth gray output");
return;
}
default:
png_app_error(png_ptr,
"png_set_filler: inappropriate color type");
return;
}
# else
png_app_error(png_ptr, "png_set_filler not supported on write");
return;
# endif
}
/* Here on success - libpng supports the operation, set the transformation
* and the flag to say where the filler channel is.
*/
png_ptr->transformations |= PNG_FILLER;
png_ptr->filler = (png_uint_16)filler;
if (filler_loc == PNG_FILLER_AFTER)
png_ptr->flags |= PNG_FLAG_FILLER_AFTER;
else
png_ptr->flags &= ~PNG_FLAG_FILLER_AFTER;
/* This should probably go in the "do_read_filler" routine.
* I attempted to do that in libpng-1.0.1a but that caused problems
* so I restored it in libpng-1.0.2a
*/
if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
{
png_ptr->usr_channels = 4;
}
/* Also I added this in libpng-1.0.2a (what happens when we expand
* a less-than-8-bit grayscale to GA?) */
if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY && png_ptr->bit_depth >= 8)
{
png_ptr->usr_channels = 2;
}
}
/* Added to libpng-1.2.7 */
@@ -207,9 +160,7 @@ png_set_add_alpha(png_structrp png_ptr, png_uint_32 filler, int filler_loc)
return;
png_set_filler(png_ptr, filler, filler_loc);
/* The above may fail to do anything. */
if (png_ptr->transformations & PNG_FILLER)
png_ptr->transformations |= PNG_ADD_ALPHA;
png_ptr->transformations |= PNG_ADD_ALPHA;
}
#endif
@@ -675,7 +626,7 @@ void /* PRIVATE */
png_do_check_palette_indexes(png_structrp png_ptr, png_row_infop row_info)
{
if (png_ptr->num_palette < (1 << row_info->bit_depth) &&
png_ptr->num_palette > 0) /* num_palette can be 0 in MNG files */
png_ptr->num_palette_max >= 0)
{
/* Calculations moved outside switch in an attempt to stop different
* compiler warnings. 'padding' is in *bits* within the last byte, it is
@@ -757,7 +708,7 @@ png_do_check_palette_indexes(png_structrp png_ptr, png_row_infop row_info)
{
for (; rp > png_ptr->row_buf; rp--)
{
if (*rp > png_ptr->num_palette_max)
if (*rp >= png_ptr->num_palette_max)
png_ptr->num_palette_max = (int) *rp;
}

View File

@@ -18,59 +18,6 @@
#ifdef PNG_WRITE_SUPPORTED
#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
/* Write out all the unknown chunks for the current given location */
static void
write_unknown_chunks(png_structrp png_ptr, png_const_inforp info_ptr,
unsigned int where)
{
if (info_ptr->unknown_chunks_num)
{
png_const_unknown_chunkp up;
png_debug(5, "writing extra chunks");
for (up = info_ptr->unknown_chunks;
up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
++up)
if (up->location & where)
{
/* If per-chunk unknown chunk handling is enabled use it, otherwise
* just write the chunks the application has set.
*/
#ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED
int keep = png_handle_as_unknown(png_ptr, up->name);
/* NOTE: this code is radically different from the read side in the
* matter of handling an ancillary unknown chunk. In the read side
* the default behavior is to discard it, in the code below the default
* behavior is to write it. Critical chunks are, however, only
* written if explicitly listed or if the default is set to write all
* unknown chunks.
*
* The default handling is also slightly weird - it is not possible to
* stop the writing of all unsafe-to-copy chunks!
*
* TODO: REVIEW: this would seem to be a bug.
*/
if (keep != PNG_HANDLE_CHUNK_NEVER &&
((up->name[3] & 0x20) /* safe-to-copy overrides everything */ ||
keep == PNG_HANDLE_CHUNK_ALWAYS ||
(keep == PNG_HANDLE_CHUNK_AS_DEFAULT &&
png_ptr->unknown_default == PNG_HANDLE_CHUNK_ALWAYS)))
#endif
{
/* TODO: review, what is wrong with a zero length unknown chunk? */
if (up->size == 0)
png_warning(png_ptr, "Writing zero-length unknown chunk");
png_write_chunk(png_ptr, up->name, up->data, up->size);
}
}
}
}
#endif /* PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED */
/* Writes all the PNG information. This is the suggested way to use the
* library. If you have a new chunk to add, make a function to write it,
* and put it in the correct location here. If you want the chunk written
@@ -107,12 +54,10 @@ png_write_info_before_PLTE(png_structrp png_ptr, png_const_inforp info_ptr)
info_ptr->bit_depth, info_ptr->color_type, info_ptr->compression_type,
info_ptr->filter_type,
#ifdef PNG_WRITE_INTERLACING_SUPPORTED
info_ptr->interlace_type
info_ptr->interlace_type);
#else
0
0);
#endif
);
/* The rest of these check to see if the valid field has the appropriate
* flag set, and if it does, writes the chunk.
*
@@ -180,9 +125,34 @@ png_write_info_before_PLTE(png_structrp png_ptr, png_const_inforp info_ptr)
#endif
#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
write_unknown_chunks(png_ptr, info_ptr, PNG_HAVE_IHDR);
#endif
if (info_ptr->unknown_chunks_num)
{
png_unknown_chunk *up;
png_debug(5, "writing extra chunks");
for (up = info_ptr->unknown_chunks;
up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
up++)
{
int keep = png_handle_as_unknown(png_ptr, up->name);
if (keep != PNG_HANDLE_CHUNK_NEVER &&
up->location &&
!(up->location & PNG_HAVE_PLTE) &&
!(up->location & PNG_HAVE_IDAT) &&
!(up->location & PNG_AFTER_IDAT) &&
((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
(png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
{
if (up->size == 0)
png_warning(png_ptr, "Writing zero-length unknown chunk");
png_write_chunk(png_ptr, up->name, up->data, up->size);
}
}
}
#endif
png_ptr->mode |= PNG_WROTE_INFO_BEFORE_PLTE;
}
}
@@ -332,7 +302,29 @@ png_write_info(png_structrp png_ptr, png_const_inforp info_ptr)
#endif /* tEXt */
#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
write_unknown_chunks(png_ptr, info_ptr, PNG_HAVE_PLTE);
if (info_ptr->unknown_chunks_num)
{
png_unknown_chunk *up;
png_debug(5, "writing extra chunks");
for (up = info_ptr->unknown_chunks;
up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
up++)
{
int keep = png_handle_as_unknown(png_ptr, up->name);
if (keep != PNG_HANDLE_CHUNK_NEVER &&
up->location &&
(up->location & PNG_HAVE_PLTE) &&
!(up->location & PNG_HAVE_IDAT) &&
!(up->location & PNG_AFTER_IDAT) &&
((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
(png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
{
png_write_chunk(png_ptr, up->name, up->data, up->size);
}
}
}
#endif
}
@@ -424,7 +416,27 @@ png_write_end(png_structrp png_ptr, png_inforp info_ptr)
}
#endif
#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
write_unknown_chunks(png_ptr, info_ptr, PNG_AFTER_IDAT);
if (info_ptr->unknown_chunks_num)
{
png_unknown_chunk *up;
png_debug(5, "writing extra chunks");
for (up = info_ptr->unknown_chunks;
up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
up++)
{
int keep = png_handle_as_unknown(png_ptr, up->name);
if (keep != PNG_HANDLE_CHUNK_NEVER &&
up->location &&
(up->location & PNG_AFTER_IDAT) &&
((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
(png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
{
png_write_chunk(png_ptr, up->name, up->data, up->size);
}
}
}
#endif
}
@@ -750,7 +762,7 @@ png_write_row(png_structrp png_ptr, png_const_bytep row)
png_debug1(3, "row_info->rowbytes = %lu", (unsigned long)row_info.rowbytes);
/* Copy user's row into buffer, leaving room for filter byte. */
memcpy(png_ptr->row_buf + 1, row, row_info.rowbytes);
png_memcpy(png_ptr->row_buf + 1, row, row_info.rowbytes);
#ifdef PNG_WRITE_INTERLACING_SUPPORTED
/* Handle interlacing */
@@ -801,8 +813,7 @@ png_write_row(png_structrp png_ptr, png_const_bytep row)
/* Added at libpng-1.5.10 */
#ifdef PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED
/* Check for out-of-range palette index */
if (row_info.color_type == PNG_COLOR_TYPE_PALETTE &&
png_ptr->num_palette_max >= 0)
if(row_info.color_type == PNG_COLOR_TYPE_PALETTE)
png_do_check_palette_indexes(png_ptr, &row_info);
#endif
@@ -846,7 +857,7 @@ png_write_flush(png_structrp png_ptr)
#endif /* PNG_WRITE_FLUSH_SUPPORTED */
#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
static void png_reset_filter_heuristics(png_structrp png_ptr);/* forward decl */
static void png_reset_filter_heuristics(png_structrp png_ptr); /* forward decl */
#endif
/* Free any memory used in png_ptr struct without freeing the struct itself. */
@@ -877,7 +888,7 @@ png_write_destroy(png_structrp png_ptr)
png_free(png_ptr, png_ptr->inv_filter_costs);
#endif
#ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
png_free(png_ptr, png_ptr->chunk_list);
#endif
@@ -1104,7 +1115,7 @@ png_init_filter_heuristics(png_structrp png_ptr, int heuristic_method,
if (num_weights > 0)
{
png_ptr->prev_filters = (png_bytep)png_malloc(png_ptr,
(png_uint_32)((sizeof (png_byte)) * num_weights));
(png_uint_32)(png_sizeof(png_byte) * num_weights));
/* To make sure that the weighting starts out fairly */
for (i = 0; i < num_weights; i++)
@@ -1113,10 +1124,10 @@ png_init_filter_heuristics(png_structrp png_ptr, int heuristic_method,
}
png_ptr->filter_weights = (png_uint_16p)png_malloc(png_ptr,
(png_uint_32)((sizeof (png_uint_16)) * num_weights));
(png_uint_32)(png_sizeof(png_uint_16) * num_weights));
png_ptr->inv_filter_weights = (png_uint_16p)png_malloc(png_ptr,
(png_uint_32)((sizeof (png_uint_16)) * num_weights));
(png_uint_32)(png_sizeof(png_uint_16) * num_weights));
for (i = 0; i < num_weights; i++)
{
@@ -1134,10 +1145,10 @@ png_init_filter_heuristics(png_structrp png_ptr, int heuristic_method,
if (png_ptr->filter_costs == NULL)
{
png_ptr->filter_costs = (png_uint_16p)png_malloc(png_ptr,
(png_uint_32)((sizeof (png_uint_16)) * PNG_FILTER_VALUE_LAST));
(png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
png_ptr->inv_filter_costs = (png_uint_16p)png_malloc(png_ptr,
(png_uint_32)((sizeof (png_uint_16)) * PNG_FILTER_VALUE_LAST));
(png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
}
for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
@@ -1335,7 +1346,7 @@ png_set_compression_window_bits(png_structrp png_ptr, int window_bits)
/* Prior to 1.6.0 this would warn but then set the window_bits value, this
* meant that negative window bits values could be selected which would cause
* libpng to write a non-standard PNG file with raw deflate or gzip
* compressed IDAT or ancillary chunks. Such files can be read and there is
* compressed IDAT or ancilliary chunks. Such files can be read and there is
* no warning on read, so this seems like a very bad idea.
*/
if (window_bits > 15)
@@ -1574,11 +1585,11 @@ png_image_write_init(png_imagep image)
if (info_ptr != NULL)
{
png_controlp control = png_voidcast(png_controlp,
png_malloc_warn(png_ptr, (sizeof *control)));
png_malloc_warn(png_ptr, sizeof *control));
if (control != NULL)
{
memset(control, 0, (sizeof *control));
png_memset(control, 0, sizeof *control);
control->png_ptr = png_ptr;
control->info_ptr = info_ptr;
@@ -1895,8 +1906,8 @@ png_image_set_PLTE(png_image_write_control *display)
png_color palette[256];
png_byte tRNS[256];
memset(tRNS, 255, (sizeof tRNS));
memset(palette, 0, (sizeof palette));
memset(tRNS, 255, sizeof tRNS);
memset(palette, 0, sizeof palette);
for (i=num_trans=0; i<entries; ++i)
{
@@ -2142,7 +2153,7 @@ png_image_write_main(png_voidp argument)
ptrdiff_t row_bytes = display->row_stride;
if (linear)
row_bytes *= (sizeof (png_uint_16));
row_bytes *= sizeof (png_uint_16);
if (row_bytes < 0)
row += (image->height-1) * (-row_bytes);
@@ -2227,7 +2238,7 @@ png_image_write_to_stdio(png_imagep image, FILE *file, int convert_to_8bit,
*/
image->opaque->png_ptr->io_ptr = file;
memset(&display, 0, (sizeof display));
png_memset(&display, 0, sizeof display);
display.image = image;
display.buffer = buffer;
display.row_stride = row_stride;
@@ -2248,10 +2259,6 @@ png_image_write_to_stdio(png_imagep image, FILE *file, int convert_to_8bit,
"png_image_write_to_stdio: invalid argument");
}
else if (image != NULL)
return png_image_error(image,
"png_image_write_to_stdio: incorrect PNG_IMAGE_VERSION");
else
return 0;
}
@@ -2315,10 +2322,6 @@ png_image_write_to_file(png_imagep image, const char *file_name,
"png_image_write_to_file: invalid argument");
}
else if (image != NULL)
return png_image_error(image,
"png_image_write_to_file: incorrect PNG_IMAGE_VERSION");
else
return 0;
}

View File

@@ -235,18 +235,18 @@ png_image_size(png_structrp png_ptr)
*/
png_uint_32 w = png_ptr->width;
unsigned int pd = png_ptr->pixel_depth;
png_alloc_size_t cb_base;
png_alloc_size_t cbBase;
int pass;
for (cb_base=0, pass=0; pass<=6; ++pass)
for (cbBase=0, pass=0; pass<=6; ++pass)
{
png_uint_32 pw = PNG_PASS_COLS(w, pass);
if (pw > 0)
cb_base += (PNG_ROWBYTES(pd, pw)+1) * PNG_PASS_ROWS(h, pass);
cbBase += (PNG_ROWBYTES(pd, pw)+1) * PNG_PASS_ROWS(h, pass);
}
return cb_base;
return cbBase;
}
else
@@ -324,7 +324,7 @@ png_deflate_claim(png_structrp png_ptr, png_uint_32 owner,
* internal error, but is very useful for debugging. i18n requirements
* are minimal.
*/
(void)png_safecat(msg, (sizeof msg), 10, " using zstream");
(void)png_safecat(msg, sizeof msg, 10, " using zstream");
# if PNG_LIBPNG_BUILD_BASE_TYPE >= PNG_LIBPNG_BUILD_RC
png_warning(png_ptr, msg);
@@ -452,27 +452,6 @@ png_deflate_claim(png_structrp png_ptr, png_uint_32 owner,
}
}
/* Clean up (or trim) a linked list of compression buffers. */
void /* PRIVATE */
png_free_buffer_list(png_structrp png_ptr, png_compression_bufferp *listp)
{
png_compression_bufferp list = *listp;
if (list != NULL)
{
*listp = NULL;
do
{
png_compression_bufferp next = list->next;
png_free(png_ptr, list);
list = next;
}
while (list != NULL);
}
}
#ifdef PNG_WRITE_COMPRESSED_TEXT_SUPPORTED
/* This pair of functions encapsulates the operation of (a) compressing a
* text string, and (b) issuing it later as a series of chunk data writes.
@@ -501,6 +480,26 @@ png_text_compress_init(compression_state *comp, png_const_bytep input,
comp->output_len = 0;
}
void /* PRIVATE */
png_free_buffer_list(png_structrp png_ptr, png_compression_bufferp *listp)
{
png_compression_bufferp list = *listp;
if (list != NULL)
{
*listp = NULL;
do
{
png_compression_bufferp next = list->next;
png_free(png_ptr, list);
list = next;
}
while (list != NULL);
}
}
/* Compress the data in the compression state input */
static int
png_text_compress(png_structrp png_ptr, png_uint_32 chunk_name,
@@ -538,7 +537,7 @@ png_text_compress(png_structrp png_ptr, png_uint_32 chunk_name,
png_ptr->zstream.next_in = PNGZ_INPUT_CAST(comp->input);
png_ptr->zstream.avail_in = 0; /* Set below */
png_ptr->zstream.next_out = comp->output;
png_ptr->zstream.avail_out = (sizeof comp->output);
png_ptr->zstream.avail_out = sizeof comp->output;
output_len = png_ptr->zstream.avail_out;
@@ -655,7 +654,7 @@ png_write_compressed_data_out(png_structrp png_ptr, compression_state *comp)
{
png_uint_32 output_len = comp->output_len;
png_const_bytep output = comp->output;
png_uint_32 avail = (sizeof comp->output);
png_uint_32 avail = sizeof comp->output;
png_compression_buffer *next = png_ptr->zbuffer_list;
for (;;)
@@ -677,7 +676,7 @@ png_write_compressed_data_out(png_structrp png_ptr, compression_state *comp)
/* This is an internal error; 'next' must have been NULL! */
if (output_len > 0)
png_error(png_ptr, "error writing ancillary chunked compressed data");
png_error(png_ptr, "error writing ancilliary chunked compressed data");
}
#endif /* PNG_WRITE_COMPRESSED_TEXT_SUPPORTED */
@@ -708,7 +707,7 @@ png_check_keyword(png_structrp png_ptr, png_const_charp key, png_bytep new_key)
*new_key = 0;
return 0;
}
while (*key && key_len < 79)
{
png_byte ch = (png_byte)(0xff & *key++);
@@ -723,7 +722,7 @@ png_check_keyword(png_structrp png_ptr, png_const_charp key, png_bytep new_key)
*/
*new_key++ = 32, ++key_len, space = 1;
/* If the character was not a space then it is invalid. */
/* If the character was not a space then it is inalid. */
if (ch != 32)
bad_character = ch;
}
@@ -1026,8 +1025,6 @@ png_compress_IDAT(png_structrp png_ptr, png_const_bytep input,
{
/* First time. Ensure we have a temporary buffer for compression and
* trim the buffer list if it has more than one entry to free memory.
* If 'WRITE_COMPRESSED_TEXT' is not set the list will never have been
* created at this point, but the check here is quick and safe.
*/
if (png_ptr->zbuffer_list == NULL)
{
@@ -1449,8 +1446,7 @@ png_write_tRNS(png_structrp png_ptr, png_const_bytep trans_alpha,
}
/* Write the chunk out as it is */
png_write_complete_chunk(png_ptr, png_tRNS, trans_alpha,
(png_size_t)num_trans);
png_write_complete_chunk(png_ptr, png_tRNS, trans_alpha, (png_size_t)num_trans);
}
else if (color_type == PNG_COLOR_TYPE_GRAY)
@@ -1608,7 +1604,7 @@ png_write_tEXt(png_structrp png_ptr, png_const_charp key, png_const_charp text,
text_len = 0;
else
text_len = strlen(text);
text_len = png_strlen(text);
if (text_len > PNG_UINT_31_MAX - (key_len+1))
png_error(png_ptr, "tEXt: text too long");
@@ -1642,7 +1638,7 @@ png_write_zTXt(png_structrp png_ptr, png_const_charp key, png_const_charp text,
compression_state comp;
png_debug(1, "in png_write_zTXt");
PNG_UNUSED(text_len) /* Always use strlen */
PNG_UNUSED(text_len); /* Always use strlen */
if (compression == PNG_TEXT_COMPRESSION_NONE)
{
@@ -1697,7 +1693,7 @@ png_write_iTXt(png_structrp png_ptr, int compression, png_const_charp key,
png_debug(1, "in png_write_iTXt");
key_len = png_check_keyword(png_ptr, key, new_key);
if (key_len == 0)
png_error(png_ptr, "iTXt: invalid keyword");
@@ -1823,23 +1819,23 @@ png_write_pCAL(png_structrp png_ptr, png_charp purpose, png_int_32 X0,
if (purpose_len == 0)
png_error(png_ptr, "pCAL: invalid keyword");
++purpose_len; /* terminator */
png_debug1(3, "pCAL purpose length = %d", (int)purpose_len);
units_len = strlen(units) + (nparams == 0 ? 0 : 1);
units_len = png_strlen(units) + (nparams == 0 ? 0 : 1);
png_debug1(3, "pCAL units length = %d", (int)units_len);
total_len = purpose_len + units_len + 10;
params_len = (png_size_tp)png_malloc(png_ptr,
(png_alloc_size_t)(nparams * (sizeof (png_size_t))));
(png_alloc_size_t)(nparams * png_sizeof(png_size_t)));
/* Find the length of each parameter, making sure we don't count the
* null terminator for the last parameter.
*/
for (i = 0; i < nparams; i++)
{
params_len[i] = strlen(params[i]) + (i == nparams - 1 ? 0 : 1);
params_len[i] = png_strlen(params[i]) + (i == nparams - 1 ? 0 : 1);
png_debug2(3, "pCAL parameter %d length = %lu", i,
(unsigned long)params_len[i]);
total_len += params_len[i];
@@ -1876,8 +1872,8 @@ png_write_sCAL_s(png_structrp png_ptr, int unit, png_const_charp width,
png_debug(1, "in png_write_sCAL_s");
wlen = strlen(width);
hlen = strlen(height);
wlen = png_strlen(width);
hlen = png_strlen(height);
total_len = wlen + hlen + 2;
if (total_len > 64)
@@ -1887,8 +1883,8 @@ png_write_sCAL_s(png_structrp png_ptr, int unit, png_const_charp width,
}
buf[0] = (png_byte)unit;
memcpy(buf + 1, width, wlen + 1); /* Append the '\0' here */
memcpy(buf + wlen + 2, height, hlen); /* Do NOT append the '\0' here */
png_memcpy(buf + 1, width, wlen + 1); /* Append the '\0' here */
png_memcpy(buf + wlen + 2, height, hlen); /* Do NOT append the '\0' here */
png_debug1(3, "sCAL total length = %u", (unsigned int)total_len);
png_write_complete_chunk(png_ptr, png_sCAL, buf, total_len);
@@ -2123,7 +2119,7 @@ png_write_finish_row(png_structrp png_ptr)
if (png_ptr->pass < 7)
{
if (png_ptr->prev_row != NULL)
memset(png_ptr->prev_row, 0,
png_memset(png_ptr->prev_row, 0,
(png_size_t)(PNG_ROWBYTES(png_ptr->usr_channels*
png_ptr->usr_bit_depth, png_ptr->width)) + 1);
@@ -2298,7 +2294,7 @@ png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
/* Move the pixel */
if (dp != sp)
memcpy(dp, sp, pixel_bytes);
png_memcpy(dp, sp, pixel_bytes);
/* Next pixel */
dp += pixel_bytes;

View File

@@ -1,27 +0,0 @@
WARNING
=======
Libpng 1.6 does not use the default run-time library when building static
library builds of libpng; instead of the shared DLL runtime it uses a static
runtime. If you need to change this make sure to change the setting on all the
relevant projects:
libpng
zlib
all the test programs
The runtime library settings for each build are as follows:
Release Debug
DLL /MD /MDd
Library /MT /MTd
NOTICE that libpng 1.5 erroneously used /MD for Debug DLL builds; if you used
the debug builds in your app and you changed your app to use /MD you will need
to change it to /MDd for libpng 1.6.
The Visual Studio 2010 defaults for a Win32 DLL or Static Library project are
as follows:
Release Debug
DLL /MD /MDd
Static Library /MD /MDd

View File

@@ -101,7 +101,6 @@
<AdditionalIncludeDirectories>$(ZLibSrcDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<TreatWarningAsError>true</TreatWarningAsError>
<Optimization>Disabled</Optimization>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>

View File

@@ -91,7 +91,6 @@
<FunctionLevelLinking>false</FunctionLevelLinking>
<BrowseInformation>true</BrowseInformation>
<FloatingPointExceptions>false</FloatingPointExceptions>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>

View File

@@ -91,7 +91,6 @@
<FunctionLevelLinking>false</FunctionLevelLinking>
<BrowseInformation>true</BrowseInformation>
<FloatingPointExceptions>false</FloatingPointExceptions>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>

View File

@@ -1,219 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug Library|Win32">
<Configuration>Debug Library</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release Library|Win32">
<Configuration>Release Library</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{9B36B6FE-7FC0-434F-A71F-BBEF8099F1D8}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>pngunknown</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<Import Project="$(SolutionDir)\zlib.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug Library|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release Library|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug Library|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release Library|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>false</LinkIncremental>
<CustomBuildAfterTargets />
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug Library|Win32'">
<LinkIncremental>false</LinkIncremental>
<CustomBuildAfterTargets />
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<CustomBuildAfterTargets />
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release Library|Win32'">
<LinkIncremental>false</LinkIncremental>
<CustomBuildAfterTargets />
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level4</WarningLevel>
<MinimalRebuild>false</MinimalRebuild>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<Optimization>Disabled</Optimization>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;PNG_USE_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(ZLibSrcDir);..\..\..\scripts;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<DisableSpecificWarnings>4996;4127</DisableSpecificWarnings>
<CompileAsManaged>false</CompileAsManaged>
<TreatWarningAsError>true</TreatWarningAsError>
<IntrinsicFunctions>true</IntrinsicFunctions>
<StringPooling>true</StringPooling>
<FunctionLevelLinking>false</FunctionLevelLinking>
<BrowseInformation>true</BrowseInformation>
<FloatingPointExceptions>false</FloatingPointExceptions>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>libpng16.lib;zlib.lib</AdditionalDependencies>
<AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>
</Link>
<CustomBuildStep>
<Message>Executing PNG validation program</Message>
<Command>"$(OutDir)pngunknown.exe" --strict --default --touch "$(IntDir)pngunknown.out" ../../../pngtest.png</Command>
<Outputs>$(IntDir)pngunknown.out</Outputs>
<Inputs>$(OutDir)pngunknown.exe</Inputs>
</CustomBuildStep>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug Library|Win32'">
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level4</WarningLevel>
<MinimalRebuild>false</MinimalRebuild>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<Optimization>Disabled</Optimization>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(ZLibSrcDir);..\..\..\scripts;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<DisableSpecificWarnings>4996;4127</DisableSpecificWarnings>
<CompileAsManaged>false</CompileAsManaged>
<TreatWarningAsError>true</TreatWarningAsError>
<IntrinsicFunctions>true</IntrinsicFunctions>
<StringPooling>true</StringPooling>
<FunctionLevelLinking>false</FunctionLevelLinking>
<BrowseInformation>true</BrowseInformation>
<FloatingPointExceptions>false</FloatingPointExceptions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>libpng16.lib;zlib.lib</AdditionalDependencies>
<AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>
</Link>
<CustomBuildStep>
<Message>Executing PNG validation program</Message>
<Command>"$(OutDir)pngunknown.exe" --strict --default --touch "$(IntDir)pngunknown.out" ../../../pngtest.png</Command>
<Outputs>$(IntDir)pngunknown.out</Outputs>
<Inputs>$(OutDir)pngunknown.exe</Inputs>
</CustomBuildStep>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<Optimization>Full</Optimization>
<FunctionLevelLinking>false</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;PNG_USE_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(ZLibSrcDir);..\..\..\scripts;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<DisableSpecificWarnings>4996;4127</DisableSpecificWarnings>
<CompileAsManaged>false</CompileAsManaged>
<TreatWarningAsError>true</TreatWarningAsError>
<StringPooling>true</StringPooling>
<MinimalRebuild>false</MinimalRebuild>
<BrowseInformation>true</BrowseInformation>
<WholeProgramOptimization>true</WholeProgramOptimization>
<FloatingPointExceptions>false</FloatingPointExceptions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>libpng16.lib;zlib.lib</AdditionalDependencies>
<AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
</Link>
<CustomBuildStep>
<Message>Executing PNG validation program</Message>
<Command>"$(OutDir)pngunknown.exe" --strict --default --touch "$(IntDir)pngunknown.out" ../../../pngtest.png</Command>
<Outputs>$(IntDir)pngunknown.out</Outputs>
<Inputs>$(OutDir)pngunknown.exe</Inputs>
</CustomBuildStep>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release Library|Win32'">
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<Optimization>Full</Optimization>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<FunctionLevelLinking>false</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(ZLibSrcDir);..\..\..\scripts;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<DisableSpecificWarnings>4996;4127</DisableSpecificWarnings>
<CompileAsManaged>false</CompileAsManaged>
<TreatWarningAsError>true</TreatWarningAsError>
<StringPooling>true</StringPooling>
<MinimalRebuild>false</MinimalRebuild>
<BrowseInformation>true</BrowseInformation>
<WholeProgramOptimization>true</WholeProgramOptimization>
<FloatingPointExceptions>false</FloatingPointExceptions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>libpng16.lib;zlib.lib</AdditionalDependencies>
<AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
</Link>
<CustomBuildStep>
<Message>Executing PNG validation program</Message>
<Command>"$(OutDir)pngunknown.exe" --strict --default --touch "$(IntDir)pngunknown.out" ../../../pngtest.png</Command>
<Outputs>$(IntDir)pngunknown.out</Outputs>
<Inputs>$(OutDir)pngunknown.exe</Inputs>
</CustomBuildStep>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\..\contrib\libtests\pngunknown.c" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@@ -21,7 +21,7 @@
<PropertyGroup Label="Globals">
<ProjectGuid>{9B36B6FE-7FC0-434F-A71F-BBEF8099F1D8}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>pngunknown</RootNamespace>
<RootNamespace>pngvalid</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<Import Project="$(SolutionDir)\zlib.props" />
@@ -91,7 +91,6 @@
<FunctionLevelLinking>false</FunctionLevelLinking>
<BrowseInformation>true</BrowseInformation>
<FloatingPointExceptions>false</FloatingPointExceptions>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@@ -101,9 +100,9 @@
</Link>
<CustomBuildStep>
<Message>Executing PNG validation program</Message>
<Command>"$(OutDir)pngunknown.exe" --strict --default --touch "$(IntDir)pngunknown.out" ../../../pngtest.png</Command>
<Outputs>$(IntDir)pngunknown.out</Outputs>
<Inputs>$(OutDir)pngunknown.exe</Inputs>
<Command>"$(OutDir)pngvalid.exe" --touch "$(IntDir)pngvalid.out"</Command>
<Outputs>$(IntDir)pngvalid.out</Outputs>
<Inputs>$(OutDir)pngvalid.exe</Inputs>
</CustomBuildStep>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug Library|Win32'">
@@ -125,7 +124,6 @@
<FunctionLevelLinking>false</FunctionLevelLinking>
<BrowseInformation>true</BrowseInformation>
<FloatingPointExceptions>false</FloatingPointExceptions>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@@ -135,9 +133,9 @@
</Link>
<CustomBuildStep>
<Message>Executing PNG validation program</Message>
<Command>"$(OutDir)pngunknown.exe" --strict --default --touch "$(IntDir)pngunknown.out" ../../../pngtest.png</Command>
<Outputs>$(IntDir)pngunknown.out</Outputs>
<Inputs>$(OutDir)pngunknown.exe</Inputs>
<Command>"$(OutDir)pngvalid.exe" --touch "$(IntDir)pngvalid.out"</Command>
<Outputs>$(IntDir)pngvalid.out</Outputs>
<Inputs>$(OutDir)pngvalid.exe</Inputs>
</CustomBuildStep>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@@ -170,9 +168,9 @@
</Link>
<CustomBuildStep>
<Message>Executing PNG validation program</Message>
<Command>"$(OutDir)pngunknown.exe" --strict --default --touch "$(IntDir)pngunknown.out" ../../../pngtest.png</Command>
<Outputs>$(IntDir)pngunknown.out</Outputs>
<Inputs>$(OutDir)pngunknown.exe</Inputs>
<Command>"$(OutDir)pngvalid.exe" --touch "$(IntDir)pngvalid.out"</Command>
<Outputs>$(IntDir)pngvalid.out</Outputs>
<Inputs>$(OutDir)pngvalid.exe</Inputs>
</CustomBuildStep>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release Library|Win32'">
@@ -206,13 +204,13 @@
</Link>
<CustomBuildStep>
<Message>Executing PNG validation program</Message>
<Command>"$(OutDir)pngunknown.exe" --strict --default --touch "$(IntDir)pngunknown.out" ../../../pngtest.png</Command>
<Outputs>$(IntDir)pngunknown.out</Outputs>
<Inputs>$(OutDir)pngunknown.exe</Inputs>
<Command>"$(OutDir)pngvalid.exe" --touch "$(IntDir)pngvalid.out"</Command>
<Outputs>$(IntDir)pngvalid.out</Outputs>
<Inputs>$(OutDir)pngvalid.exe</Inputs>
</CustomBuildStep>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\..\contrib\libtests\pngunknown.c" />
<ClCompile Include="..\..\..\contrib\libtests\pngvalid.c" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">

View File

@@ -1,7 +1,7 @@
VisualStudio instructions
libpng version 1.6.0beta30 - October 24, 2012
libpng version 1.6.0beta20 - March 29, 2012
Copyright (c) 1998-2010 Glenn Randers-Pehrson
@@ -33,8 +33,8 @@ optimization level (e.g. /Od.)
Linking your application
========================
Normally you should link against the 'release' configuration. This builds a
DLL for libpng with the default runtime options used by Visual Studio 2010.
In particular the runtime library is the "MultiThreaded DLL" version.
DLL for libpng 1.5 with the default runtime options used by Visual Studio
2010. In particular the runtime library is the "MultiThreaded DLL" version.
If you use Visual Studio defaults to build your application you will have no
problems.
@@ -58,8 +58,7 @@ Debug versions have limited support
This solution includes limited support for debug versions of libpng. You
do not need these unless your own solution itself uses debug builds (it is
far more effective to debug on the release builds, there is no point building
a special debug build unless you have heap corruption problems that you can't
track down.)
a special debug build.)
The debug build of libpng is minimally supported. Support for debug builds of
zlib is also minimal. You really don't want to do this.

View File

@@ -1,9 +1,5 @@
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlib", "zlib\zlib.vcxproj", "{60F89955-91C6-3A36-8000-13C592FEC2DF}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pnglibconf", "pnglibconf\pnglibconf.vcxproj", "{EB33566E-DA7F-4D28-9077-88C0B7C77E35}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libpng", "libpng\libpng.vcxproj", "{D6973076-9317-4EF2-A0B8-B7A18AC0713E}"
ProjectSection(ProjectDependencies) = postProject
{60F89955-91C6-3A36-8000-13C592FEC2DF} = {60F89955-91C6-3A36-8000-13C592FEC2DF}
@@ -17,6 +13,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pngtest", "pngtest\pngtest.
{D6973076-9317-4EF2-A0B8-B7A18AC0713E} = {D6973076-9317-4EF2-A0B8-B7A18AC0713E}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlib", "zlib\zlib.vcxproj", "{60F89955-91C6-3A36-8000-13C592FEC2DF}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pngvalid", "pngvalid\pngvalid.vcxproj", "{9B36B6FE-7FC0-434F-A71F-BBEF8099F1D8}"
ProjectSection(ProjectDependencies) = postProject
{60F89955-91C6-3A36-8000-13C592FEC2DF} = {60F89955-91C6-3A36-8000-13C592FEC2DF}
@@ -24,14 +22,9 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pngvalid", "pngvalid\pngval
{D6973076-9317-4EF2-A0B8-B7A18AC0713E} = {D6973076-9317-4EF2-A0B8-B7A18AC0713E}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pngstest", "pngstest\pngstest.vcxproj", "{277AC57F-313B-4D06-B119-A3CDB672D2FF}"
ProjectSection(ProjectDependencies) = postProject
{60F89955-91C6-3A36-8000-13C592FEC2DF} = {60F89955-91C6-3A36-8000-13C592FEC2DF}
{EB33566E-DA7F-4D28-9077-88C0B7C77E35} = {EB33566E-DA7F-4D28-9077-88C0B7C77E35}
{D6973076-9317-4EF2-A0B8-B7A18AC0713E} = {D6973076-9317-4EF2-A0B8-B7A18AC0713E}
EndProjectSection
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pnglibconf", "pnglibconf\pnglibconf.vcxproj", "{EB33566E-DA7F-4D28-9077-88C0B7C77E35}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pngunknown", "pngunknown\pngunknown.vcxproj", "{C5D3156C-8C8C-4936-B35F-2B829BA36FEC}"
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pngstest", "pngstest\pngstest.vcxproj", "{277AC57F-313B-4D06-B119-A3CDB672D2FF}"
ProjectSection(ProjectDependencies) = postProject
{60F89955-91C6-3A36-8000-13C592FEC2DF} = {60F89955-91C6-3A36-8000-13C592FEC2DF}
{EB33566E-DA7F-4D28-9077-88C0B7C77E35} = {EB33566E-DA7F-4D28-9077-88C0B7C77E35}
@@ -94,14 +87,6 @@ Global
{277AC57F-313B-4D06-B119-A3CDB672D2FF}.Release Library|Win32.Build.0 = Release Library|Win32
{277AC57F-313B-4D06-B119-A3CDB672D2FF}.Release|Win32.ActiveCfg = Release|Win32
{277AC57F-313B-4D06-B119-A3CDB672D2FF}.Release|Win32.Build.0 = Release|Win32
{C5D3156C-8C8C-4936-B35F-2B829BA36FEC}.Debug Library|Win32.ActiveCfg = Debug Library|Win32
{C5D3156C-8C8C-4936-B35F-2B829BA36FEC}.Debug Library|Win32.Build.0 = Debug Library|Win32
{C5D3156C-8C8C-4936-B35F-2B829BA36FEC}.Debug|Win32.ActiveCfg = Debug|Win32
{C5D3156C-8C8C-4936-B35F-2B829BA36FEC}.Debug|Win32.Build.0 = Debug|Win32
{C5D3156C-8C8C-4936-B35F-2B829BA36FEC}.Release Library|Win32.ActiveCfg = Release Library|Win32
{C5D3156C-8C8C-4936-B35F-2B829BA36FEC}.Release Library|Win32.Build.0 = Release Library|Win32
{C5D3156C-8C8C-4936-B35F-2B829BA36FEC}.Release|Win32.ActiveCfg = Release|Win32
{C5D3156C-8C8C-4936-B35F-2B829BA36FEC}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@@ -2,7 +2,7 @@
<!--
* zlib.props - location of zlib source
*
* libpng version 1.6.0beta30 - October 24, 2012
* libpng version 1.6.0beta20 - March 29, 2012
*
* Copyright (c) 1998-2011 Glenn Randers-Pehrson
*

View File

@@ -106,7 +106,6 @@
<Optimization>Disabled</Optimization>
<BrowseInformation>true</BrowseInformation>
<FunctionLevelLinking>true</FunctionLevelLinking>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
</ClCompile>
<Link>
<TargetMachine>MachineX86</TargetMachine>

View File

@@ -1,9 +1,9 @@
Makefiles for libpng version 1.6.0beta30 - October 24, 2012
Makefiles for libpng version 1.6.0beta20 - March 29, 2012
pnglibconf.h.prebuilt => Stores configuration settings
makefile.linux => Linux/ELF makefile
(gcc, creates libpng16.so.16.1.6.0beta30)
(gcc, creates libpng16.so.16.1.6.0beta20)
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.0beta30)
(gcc, creates libpng16.so.16.1.6.0beta20)
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.0beta30)
creates libpng16.so.16.1.6.0beta20)
makefile.sgi => Silicon Graphics IRIX makefile (cc, creates static lib)
makefile.solaris => Solaris 2.X makefile (gcc,
creates libpng16.so.16.1.6.0beta30)
creates libpng16.so.16.1.6.0beta20)
makefile.so9 => Solaris 9 makefile (gcc,
creates libpng16.so.16.1.6.0beta30)
creates libpng16.so.16.1.6.0beta20)
makefile.std => Generic UNIX makefile (cc, creates static libpng.a)
makefile.sunos => Sun makefile
makefile.32sunu => Sun Ultra 32-bit makefile

View File

@@ -11,7 +11,7 @@
# Modeled after libxml-config.
version=1.6.0beta30
version=1.6.0beta20
prefix=""
libdir=""
libs=""

View File

@@ -5,6 +5,6 @@ includedir=@includedir@/libpng16
Name: libpng
Description: Loads and saves PNG files
Version: 1.6.0beta30
Version: 1.6.0beta20
Libs: -L${libdir} -lpng16
Cflags: -I${includedir}

View File

@@ -15,8 +15,10 @@ prefix=/usr/local
exec_prefix=$(prefix)
# Where the zlib library and include files are located
ZLIBLIB=/usr/lib
ZLIBINC=/usr/include
#ZLIBLIB=/usr/local/lib
#ZLIBINC=/usr/local/include
ZLIBLIB=../zlib
ZLIBINC=../zlib
# Library name:
LIBNAME = libpng16
@@ -35,7 +37,7 @@ MKDIR_P=mkdir -p
LN_SF=ln -sf
RANLIB=ranlib
RM_F=/bin/rm -f
ARCH=-arch ppc -arch i386 -arch x86_64
ARCH="-arch i386 -arch x86_64"
# CFLAGS=-I$(ZLIBINC) -W -Wall -O3 -funroll-loops
CFLAGS=-I$(ZLIBINC) -W -Wall -O -funroll-loops $(ARCH)
@@ -105,7 +107,7 @@ $(LIBSOMAJ): $(OBJSDLL)
$(CC) -dynamiclib \
-install_name $(LIBPATH)/$(LIBSOMAJ) \
-current_version 16 -compatibility_version 16 \
$(ARCH) -o $(LIBSOMAJ) \
-o $(LIBSOMAJ) \
$(OBJSDLL) -L$(ZLIBLIB) -lz
pngtest: pngtest.o $(LIBSO)
@@ -134,10 +136,10 @@ install-static: install-headers libpng.a
install-shared: install-headers $(LIBSOMAJ) libpng.pc
-@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi
-@$(RM_F) $(DL)/$(LIBSO)
-@$(RM_F) $(DL)/$(LIBSOMAJ)
-@$(RM_F) $(DL)/$(LIBSOREL)
-@$(RM_F) $(DL)/$(OLDSO)
cp $(LIBSOMAJ) $(DL)
chmod 755 $(DL)/$(LIBSOMAJ)
cp $(LIBSOMAJ) $(DL)/$(LIBSOREL)
chmod 755 $(DL)/$(LIBSOREL)
(cd $(DL); \
$(LN_SF) $(LIBSOREL) $(LIBSO); \
$(LN_SF) $(LIBSO) $(OLDSO))

View File

@@ -11,8 +11,8 @@ SHLIB_VER?= 16
LIB= png
SHLIB_MAJOR= ${SHLIB_VER}
SHLIB_MINOR= 0
NO_PROFILE= YES
NO_OBJ= YES
NOPROFILE= YES
NOOBJ= YES
# where make install puts libpng.a and png.h
DESTDIR= ${PREFIX}
@@ -25,10 +25,7 @@ MANDIR= /man/man
SYMLINKS= libpng/png.h ${INCSDIR}/../png.h \
libpng/pngconf.h ${INCSDIR}/../pngconf.h \
libpng/pnglibconf.h ${INCSDIR}/../pnglibconf.h
LDADD+= -lm -lz
#LDADD+= -lm -lz -lssp_nonshared # for OSVERSION < 800000 ?
DPADD+= ${LIBM} ${LIBZ}
CFLAGS+= -I.

View File

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

View File

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

View File

@@ -11,7 +11,7 @@ LIBDIR= ${PREFIX}/lib
MANDIR= ${PREFIX}/man/cat
SHLIB_MAJOR= 16
SHLIB_MINOR= 1.6.0beta30
SHLIB_MINOR= 1.6.0beta20
LIB= png
SRCS= png.c pngerror.c pngget.c pngmem.c pngpread.c \

View File

@@ -21,10 +21,10 @@ file pnglibconf.h scripts/pnglibconf.dfa PNGLCONF_H
# C compiler to generate 'pnglibconf.h' - a list of all the
# configuration options. The file lists the various options
# that can *only* be specified during the libpng build;
# pnglibconf.h freezes the definitions selected for the specific
# pnglibconf.h freezes the definitons selected for the specific
# build.
#
# The syntax is detailed in scripts/options.awk; this is a summary
# The syntax is detailed in scripts/options.awk, this is a summary
# only:
#
# setting <name> [default]
@@ -48,7 +48,7 @@ file pnglibconf.h scripts/pnglibconf.dfa PNGLCONF_H
# The following setting, option and chunk values can all be changed
# while building libpng:
#
# setting: change 'setting' lines to fine tune library performance;
# setting: change 'setting' lines to fine tune library performance,
# changes to the settings don't affect the libpng API functionally
#
# option: change 'option' lines to remove or add capabilities from
@@ -635,55 +635,9 @@ chunk zTXt
option READ_OPT_PLTE requires READ_ANCILLARY_CHUNKS
# Unknown chunk handling
#
# 'UNKNOWN_CHUNKS' is a global option to disable all unknown chunk handling on
# read or write; everything else below requires it (directly or indirectly).
option UNKNOWN_CHUNKS
# There are three main options to control the ability to read and write unknown
# chunks. If either read option is turned on then unknown chunks will be read,
# otherwise they are skipped. If the write option is turned on unknown chunks
# set by png_set_unknown_chunks will be written otherwise it is an error to call
# that API on a write struct.
option WRITE_UNKNOWN_CHUNKS requires WRITE requires UNKNOWN_CHUNKS
option WRITE_UNKNOWN_CHUNKS enables STORE_UNKNOWN_CHUNKS
# The first way to read user chunks is to have libpng save them for a later call
# to png_get_unknown_chunks, the application must call
# png_set_keep_unknown_chunks to cause this to actually happen (see png.h)
option SAVE_UNKNOWN_CHUNKS requires READ requires SET_UNKNOWN_CHUNKS
option SAVE_UNKNOWN_CHUNKS enables READ_UNKNOWN_CHUNKS STORE_UNKNOWN_CHUNKS
# The second approach is to use an application provided callback to process the
# chunks, the callback can either handle the chunk entirely itself or request
# that libpng store the chunk for later retrieval via png_get_unknown_chunks.
#
# Note that there is no 'WRITE_USER_CHUNKS' so the USER_CHUNKS option is always
# the same as READ_USER_CHUNKS at present
option READ_USER_CHUNKS requires READ requires UNKNOWN_CHUNKS
option READ_USER_CHUNKS enables READ_UNKNOWN_CHUNKS USER_CHUNKS
# Two further options are provided to allow detailed control of the handling.
# The first enables png_set_keep_unknown_chunks; this allows the default to be
# changed from discarding unknown chunks and allows per-chunk control. This is
# required to use the SAVE_UNKNOWN_CHUNKS option. If enabled this option also
# applies to write (see png.h), otherwise the write API simply writes all the
# chunks it is given.
#
# The second option extends the unknown handling to allow known chunks to be
# handled as though they were unknown. This option doesn't change any APIs, it
# merely turns on the code to check known as well as unknown chunks.
#
# This option no longer affects the write code. It can be safely disabled and
# will prevent applications stopping libpng reading known chunks.
option SET_UNKNOWN_CHUNKS requires UNKNOWN_CHUNKS
option HANDLE_AS_UNKNOWN requires SET_UNKNOWN_CHUNKS
# The following options are derived from the above and should not be turned on
# explicitly.
option READ_UNKNOWN_CHUNKS requires UNKNOWN_CHUNKS disabled
option STORE_UNKNOWN_CHUNKS requires UNKNOWN_CHUNKS disabled
option READ_UNKNOWN_CHUNKS requires READ
option READ_UNKNOWN_CHUNKS enables UNKNOWN_CHUNKS READ_USER_CHUNKS
option READ_USER_CHUNKS requires READ enables USER_CHUNKS
option CONVERT_tIME requires WRITE_ANCILLARY_CHUNKS
# The "tm" structure is not supported on WindowsCE
@@ -694,6 +648,10 @@ option CONVERT_tIME requires WRITE_ANCILLARY_CHUNKS
option WRITE_FILTER requires WRITE
option WRITE_UNKNOWN_CHUNKS requires WRITE
option HANDLE_AS_UNKNOWN
option SAVE_INT_32 requires WRITE
# png_save_int_32 is required by the ancillary chunks oFFs and pCAL

View File

@@ -3,7 +3,7 @@
/* pnglibconf.h - library build configuration */
/* Libpng 1.6.0beta30 - October 24, 2012 */
/* Libpng 1.6.0beta20 - March 29, 2012 */
/* Copyright (c) 1998-2012 Glenn Randers-Pehrson */
@@ -126,14 +126,12 @@
#define PNG_READ_zTXt_SUPPORTED
/*#undef PNG_SAFE_LIMITS_SUPPORTED*/
#define PNG_SAVE_INT_32_SUPPORTED
#define PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED
#define PNG_sBIT_SUPPORTED
#define PNG_sCAL_SUPPORTED
#define PNG_SEQUENTIAL_READ_SUPPORTED
#define PNG_SET_CHUNK_CACHE_LIMIT_SUPPORTED
#define PNG_SET_CHUNK_MALLOC_LIMIT_SUPPORTED
#define PNG_SETJMP_SUPPORTED
#define PNG_SET_UNKNOWN_CHUNKS_SUPPORTED
#define PNG_SET_USER_LIMITS_SUPPORTED
#define PNG_SIMPLIFIED_READ_AFIRST_SUPPORTED
#define PNG_SIMPLIFIED_READ_BGR_SUPPORTED
@@ -144,7 +142,6 @@
#define PNG_sPLT_SUPPORTED
#define PNG_sRGB_SUPPORTED
#define PNG_STDIO_SUPPORTED
#define PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
#define PNG_tEXt_SUPPORTED
#define PNG_TEXT_SUPPORTED
#define PNG_TIME_RFC1123_SUPPORTED

View File

@@ -5,7 +5,7 @@
LIBRARY
EXPORTS
;Version 1.6.0beta30
;Version 1.6.0beta20
png_access_version_number @1
png_set_sig_bytes @2
png_sig_cmp @3