[libpng16] 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 a 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.
This commit is contained in:
John Bowler 2012-09-04 11:19:00 -05:00 committed by Glenn Randers-Pehrson
parent 53f7051b1b
commit b98681b49a
22 changed files with 1597 additions and 177 deletions

View File

@ -1,5 +1,5 @@
Libpng 1.6.0beta29 - September 1, 2012
Libpng 1.6.0beta29 - September 4, 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.
@ -482,7 +482,7 @@ Version 1.6.0beta28 [August 29, 2012]
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 1, 2012]
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.
@ -494,6 +494,15 @@ Version 1.6.0beta29 [September 1, 2012]
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 a 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.
Send comments/corrections/commendations to png-mng-implement at lists.sf.net
(subscription required; visit

11
CHANGES
View File

@ -4233,7 +4233,7 @@ Version 1.6.0beta28 [August 29, 2012]
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 1, 2012]
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.
@ -4246,6 +4246,15 @@ Version 1.6.0beta29 [September 1, 2012]
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 a 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.
Send comments/corrections/commendations to png-mng-implement at lists.sf.net
(subscription required; visit

View File

@ -10,7 +10,7 @@ this sentence.
This code is released under the libpng license.
libpng versions 1.2.6, August 15, 2004, through 1.6.0beta29, August 29, 2012, are
libpng versions 1.2.6, August 15, 2004, through 1.6.0beta29, September 4, 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
@ -108,4 +108,4 @@ certification mark of the Open Source Initiative.
Glenn Randers-Pehrson
glennrp at users.sourceforge.net
August 29, 2012
September 4, 2012

2
README
View File

@ -1,4 +1,4 @@
README for libpng version 1.6.0beta29 - August 29, 2012 (shared library 16.0)
README for libpng version 1.6.0beta29 - September 4, 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

@ -1,6 +1,6 @@
libpng-manual.txt - A description on how to use and modify libpng
libpng version 1.6.0beta29 - September 1, 2012
libpng version 1.6.0beta29 - September 4, 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.0beta29 - September 1, 2012
libpng versions 0.97, January 1998, through 1.6.0beta29 - September 4, 2012
Updated and distributed by Glenn Randers-Pehrson
Copyright (c) 1998-2011 Glenn Randers-Pehrson
@ -5064,7 +5064,7 @@ Other rules can be inferred by inspecting the libpng source.
XVI. Y2K Compliance in libpng
September 1, 2012
September 4, 2012
Since the PNG Development group is an ad-hoc body, we can't make
an official declaration.

View File

@ -1,4 +1,4 @@
.TH LIBPNG 3 "September 1, 2012"
.TH LIBPNG 3 "September 4, 2012"
.SH NAME
libpng \- Portable Network Graphics (PNG) Reference Library 1.6.0beta29
.SH SYNOPSIS
@ -997,7 +997,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.0beta29 - September 1, 2012
libpng version 1.6.0beta29 - September 4, 2012
Updated and distributed by Glenn Randers-Pehrson
<glennrp at users.sourceforge.net>
Copyright (c) 1998-2011 Glenn Randers-Pehrson
@ -1008,7 +1008,7 @@ libpng-manual.txt - A description on how to use and modify libpng
Based on:
libpng versions 0.97, January 1998, through 1.6.0beta29 - September 1, 2012
libpng versions 0.97, January 1998, through 1.6.0beta29 - September 4, 2012
Updated and distributed by Glenn Randers-Pehrson
Copyright (c) 1998-2011 Glenn Randers-Pehrson
@ -6062,7 +6062,7 @@ Other rules can be inferred by inspecting the libpng source.
.SH XVI. Y2K Compliance in libpng
September 1, 2012
September 4, 2012
Since the PNG Development group is an ad-hoc body, we can't make
an official declaration.
@ -6330,7 +6330,7 @@ possible without all of you.
Thanks to Frank J. T. Wojcik for helping with the documentation.
Libpng version 1.6.0beta29 - September 1, 2012:
Libpng version 1.6.0beta29 - September 4, 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 +6353,7 @@ this sentence.
This code is released under the libpng license.
libpng versions 1.2.6, August 15, 2004, through 1.6.0beta29, September 1, 2012, are
libpng versions 1.2.6, August 15, 2004, through 1.6.0beta29, September 4, 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 +6452,7 @@ certification mark of the Open Source Initiative.
Glenn Randers-Pehrson
glennrp at users.sourceforge.net
September 1, 2012
September 4, 2012
.\" end of man page

View File

@ -1,4 +1,4 @@
.TH LIBPNGPF 3 "August 29, 2012"
.TH LIBPNGPF 3 "September 4, 2012"
.SH NAME
libpng \- Portable Network Graphics (PNG) Reference Library 1.6.0beta29
(private functions)

2
png.5
View File

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

1576
png.c

File diff suppressed because it is too large Load Diff

10
png.h
View File

@ -1,7 +1,7 @@
/* png.h - header file for PNG reference library
*
* libpng version 1.6.0beta29 - August 29, 2012
* libpng version 1.6.0beta29 - September 4, 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.0beta29 - August 29, 2012: Glenn
* libpng versions 0.97, January 1998, through 1.6.0beta29 - September 4, 2012: Glenn
* See also "Contributing Authors", below.
*
* Note about libpng version numbers:
@ -198,7 +198,7 @@
*
* This code is released under the libpng license.
*
* libpng versions 1.2.6, August 15, 2004, through 1.6.0beta29, August 29, 2012, are
* libpng versions 1.2.6, August 15, 2004, through 1.6.0beta29, September 4, 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,7 +310,7 @@
* Y2K compliance in libpng:
* =========================
*
* August 29, 2012
* September 4, 2012
*
* Since the PNG Development group is an ad-hoc body, we can't make
* an official declaration.
@ -378,7 +378,7 @@
/* Version information for png.h - this should match the version in png.c */
#define PNG_LIBPNG_VER_STRING "1.6.0beta29"
#define PNG_HEADER_VERSION_STRING \
" libpng version 1.6.0beta29 - August 29, 2012\n"
" libpng version 1.6.0beta29 - September 4, 2012\n"
#define PNG_LIBPNG_VER_SONUM 16
#define PNG_LIBPNG_VER_DLLNUM 16

View File

@ -1,7 +1,7 @@
/* pngconf.h - machine configurable file for libpng
*
* libpng version 1.6.0beta29 - August 29, 2012
* libpng version 1.6.0beta29 - September 4, 2012
*
* Copyright (c) 1998-2012 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)

View File

@ -272,7 +272,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)))
else if ((keep = png_chunk_unknown_handling(png_ptr, chunk_name)) != 0)
{
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
{

View File

@ -1442,8 +1442,8 @@ 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 preferred,
int color_type), PNG_EMPTY);
png_uint_32 profile_length, png_const_bytep profile, int color_type),
PNG_EMPTY);
/* The 'name' is used for information only */
/* Routines for checking parts of an ICC profile. */
@ -1461,8 +1461,7 @@ PNG_INTERNAL_FUNCTION(int,png_icc_check_tag_table,(png_const_structrp png_ptr,
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, int preferred),
PNG_EMPTY);
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

View File

@ -139,7 +139,7 @@ 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)))
else if ((keep = png_chunk_unknown_handling(png_ptr, chunk_name)) != 0)
{
png_handle_unknown(png_ptr, info_ptr, length, keep);
@ -723,7 +723,7 @@ 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)))
else if ((keep = png_chunk_unknown_handling(png_ptr, chunk_name)) != 0)
{
if (chunk_name == png_IDAT)
{

View File

@ -1495,8 +1495,7 @@ 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,
0/*prefer explicit gAMA/cHRM*/);
png_ptr->zstream.adler);
/* Steal the profile for info_ptr. */
if (ok && info_ptr != NULL)

View File

@ -649,8 +649,7 @@ png_set_iCCP(png_const_structrp png_ptr, png_inforp info_ptr,
*/
{
int result = png_colorspace_set_ICC(png_ptr, &info_ptr->colorspace, name,
proflen, profile, 0/* do *not* override the app cHRM or gAMA */,
info_ptr->color_type);
proflen, profile, info_ptr->color_type);
png_colorspace_sync_info(png_ptr, info_ptr);
@ -1072,7 +1071,7 @@ png_set_sPLT(png_const_structrp png_ptr,
#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
static png_byte
check_location(png_const_structrp png_ptr, unsigned int location)
check_location(png_const_structrp png_ptr, int location)
{
location &= (PNG_HAVE_IHDR|PNG_HAVE_PLTE|PNG_AFTER_IDAT);
@ -1086,8 +1085,8 @@ check_location(png_const_structrp png_ptr, unsigned int location)
png_app_warning(png_ptr,
"png_set_unknown_chunks now expects a valid location");
/* Use the old behavior */
location = png_ptr->mode &
(PNG_HAVE_IHDR|PNG_HAVE_PLTE|PNG_AFTER_IDAT);
location = (png_byte)(png_ptr->mode &
(PNG_HAVE_IHDR|PNG_HAVE_PLTE|PNG_AFTER_IDAT));
}
if (location == 0)
@ -1097,7 +1096,7 @@ check_location(png_const_structrp png_ptr, unsigned int location)
* significant bit in turn.
*/
while (location != (location & -location))
location &= (png_byte)~(location & -location);
location &= ~(location & -location);
/* The cast is safe because 'location' is a bit mask and only the low four
* bits are significant.
@ -1206,7 +1205,7 @@ png_set_unknown_chunk_location(png_const_structrp png_ptr, png_inforp info_ptr,
}
info_ptr->unknown_chunks[chunk].location =
check_location(png_ptr, (png_byte)location);
check_location(png_ptr, location);
}
}
#endif

View File

@ -119,6 +119,7 @@ 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
@ -128,6 +129,75 @@ 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

View File

@ -403,19 +403,24 @@ pngtest_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
* 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!)";
PNG_CONST char **test= (PNG_CONST char **)png_get_error_ptr(png_ptr);
pngtest_error_parameters *test =
(pngtest_error_parameters*)png_get_error_ptr(png_ptr);
++warning_count;
if (test == NULL || *test == NULL)
fprintf(STDERR, "%s: libpng warning: %s\n", name, message);
if (test != NULL && test->file_name != NULL)
name = test->file_name;
else
fprintf(STDERR, "%s: libpng warning: %s\n", *test, message);
fprintf(STDERR, "%s: libpng warning: %s\n", name, message);
}
/* This is the default error handling function. Note that replacements for
@ -800,7 +805,7 @@ 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 */
static PNG_CONST char *fp_name;
pngtest_error_parameters error_parameters;
png_structp read_ptr;
png_infop read_info_ptr, end_info_ptr;
#ifdef PNG_WRITE_SUPPORTED
@ -819,7 +824,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
int bit_depth, color_type;
row_buf = NULL;
fp_name = inname;
error_parameters.file_name = inname;
if ((fpin = fopen(inname, "rb")) == NULL)
{
@ -843,7 +848,8 @@ 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, &fp_name, pngtest_error, pngtest_warning);
png_set_error_fn(read_ptr, &error_parameters, pngtest_error,
pngtest_warning);
#ifdef PNG_WRITE_SUPPORTED
#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
@ -854,7 +860,8 @@ 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, &fp_name, pngtest_error, pngtest_warning);
png_set_error_fn(write_ptr, &error_parameters, pngtest_error,
pngtest_warning);
#endif
pngtest_debug("Allocating read_info, write_info and end_info structures");
read_info_ptr = png_create_info_struct(read_ptr);

View File

@ -1,7 +1,7 @@
VisualStudio instructions
libpng version 1.6.0beta29 - August 29, 2012
libpng version 1.6.0beta29 - September 4, 2012
Copyright (c) 1998-2010 Glenn Randers-Pehrson

View File

@ -2,7 +2,7 @@
<!--
* zlib.props - location of zlib source
*
* libpng version 1.6.0beta29 - August 29, 2012
* libpng version 1.6.0beta29 - September 4, 2012
*
* Copyright (c) 1998-2011 Glenn Randers-Pehrson
*

View File

@ -1,5 +1,5 @@
Makefiles for libpng version 1.6.0beta29 - August 29, 2012
Makefiles for libpng version 1.6.0beta29 - September 4, 2012
pnglibconf.h.prebuilt => Stores configuration settings
makefile.linux => Linux/ELF makefile

View File

@ -3,7 +3,7 @@
/* pnglibconf.h - library build configuration */
/* Libpng 1.6.0beta29 - August 29, 2012 */
/* Libpng 1.6.0beta29 - September 4, 2012 */
/* Copyright (c) 1998-2012 Glenn Randers-Pehrson */