[libpng16] Changed chunk handler warnings into benign errors, incrementally
load iCCP
This commit is contained in:
parent
51624965e2
commit
b11b31aea2
5
ANNOUNCE
5
ANNOUNCE
@ -1,5 +1,5 @@
|
||||
|
||||
Libpng 1.6.0beta20 - March 19, 2012
|
||||
Libpng 1.6.0beta20 - March 21, 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.
|
||||
@ -339,7 +339,8 @@ Version 1.6.0beta19 [March 18,2012]
|
||||
Avoid the double gamma correction warning in the simplified API.
|
||||
This allows the --strict option to pass in the pngstest checks
|
||||
|
||||
Version 1.6.0beta20 [March 19, 2012]
|
||||
Version 1.6.0beta20 [March 21, 2012]
|
||||
Changed chunk handler warnings into benign errors, incrementally load iCCP
|
||||
|
||||
Send comments/corrections/commendations to png-mng-implement at lists.sf.net
|
||||
(subscription required; visit
|
||||
|
3
CHANGES
3
CHANGES
@ -4090,7 +4090,8 @@ Version 1.6.0beta19 [March 18, 2012]
|
||||
Avoid the double gamma correction warning in the simplified API.
|
||||
This allows the --strict option to pass in the pngstest checks
|
||||
|
||||
Version 1.6.0beta20 [March 19, 2012]
|
||||
Version 1.6.0beta20 [March 21, 2012]
|
||||
Changed chunk handler warnings into benign errors, incrementally load iCCP
|
||||
|
||||
Send comments/corrections/commendations to png-mng-implement at lists.sf.net
|
||||
(subscription required; visit
|
||||
|
@ -1061,6 +1061,7 @@ int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
FILE *fp = stdout;
|
||||
const char *file_name = NULL;
|
||||
int color_type = 8; /* invalid */
|
||||
int bit_depth = 32; /* invalid */
|
||||
png_fixed_point gamma = 0; /* not set */
|
||||
@ -1189,6 +1190,7 @@ main(int argc, char **argv)
|
||||
exit(1);
|
||||
}
|
||||
|
||||
file_name = arg;
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -1204,5 +1206,12 @@ main(int argc, char **argv)
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return write_png(fp, color_type, bit_depth, gamma, head_insert);
|
||||
{
|
||||
int ret = write_png(fp, color_type, bit_depth, gamma, head_insert);
|
||||
|
||||
if (ret != 0 && file_name != NULL)
|
||||
remove(file_name);
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
@ -3099,7 +3099,7 @@ read_one_file(Image *image)
|
||||
{
|
||||
long int cb = ftell(f);
|
||||
|
||||
if (cb >= 0 && (unsigned long int)cb < (size_t)~(size_t)0)
|
||||
if (cb > 0 && (unsigned long int)cb < (size_t)~(size_t)0)
|
||||
{
|
||||
png_bytep b = voidcast(png_bytep, malloc((size_t)cb));
|
||||
|
||||
@ -3118,17 +3118,22 @@ read_one_file(Image *image)
|
||||
{
|
||||
free(b);
|
||||
return logclose(image, f, image->file_name,
|
||||
": read failed");
|
||||
": read failed: ");
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
return logclose(image, f, image->file_name,
|
||||
": out of memory");
|
||||
": out of memory: ");
|
||||
}
|
||||
|
||||
else if (cb == 0)
|
||||
return logclose(image, f, image->file_name,
|
||||
": zero length: ");
|
||||
|
||||
else
|
||||
return logclose(image, f, image->file_name, ": tell failed");
|
||||
return logclose(image, f, image->file_name,
|
||||
": tell failed: ");
|
||||
}
|
||||
|
||||
else
|
||||
@ -3169,7 +3174,7 @@ write_one_file(Image *output, Image *image, int convert_to_8bit)
|
||||
}
|
||||
|
||||
else
|
||||
return logclose(image, f, "tmpfile", ": flush");
|
||||
return logclose(image, f, "tmpfile", ": flush: ");
|
||||
}
|
||||
|
||||
else
|
||||
|
23
png.h
23
png.h
@ -1,7 +1,7 @@
|
||||
|
||||
/* png.h - header file for PNG reference library
|
||||
*
|
||||
* libpng version 1.6.0beta20 - March 19, 2012
|
||||
* libpng version 1.6.0beta20 - March 21, 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.0beta20 - March 19, 2012: Glenn
|
||||
* libpng versions 0.97, January 1998, through 1.6.0beta20 - March 21, 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.0beta20, March 19, 2012, are
|
||||
* libpng versions 1.2.6, August 15, 2004, through 1.6.0beta20, March 21, 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:
|
||||
* =========================
|
||||
*
|
||||
* March 19, 2012
|
||||
* March 21, 2012
|
||||
*
|
||||
* Since the PNG Development group is an ad-hoc body, we can't make
|
||||
* an official declaration.
|
||||
@ -376,7 +376,7 @@
|
||||
/* Version information for png.h - this should match the version in png.c */
|
||||
#define PNG_LIBPNG_VER_STRING "1.6.0beta20"
|
||||
#define PNG_HEADER_VERSION_STRING \
|
||||
" libpng version 1.6.0beta20 - March 19, 2012\n"
|
||||
" libpng version 1.6.0beta20 - March 21, 2012\n"
|
||||
|
||||
#define PNG_LIBPNG_VER_SONUM 16
|
||||
#define PNG_LIBPNG_VER_DLLNUM 16
|
||||
@ -1095,9 +1095,9 @@ PNG_EXPORTA(19, void, png_info_init_3, (png_infopp info_ptr,
|
||||
|
||||
/* Writes all the PNG information before the image. */
|
||||
PNG_EXPORT(20, void, png_write_info_before_PLTE,
|
||||
(png_structrp png_ptr, png_inforp info_ptr));
|
||||
(png_structrp png_ptr, png_const_inforp info_ptr));
|
||||
PNG_EXPORT(21, void, png_write_info,
|
||||
(png_structrp png_ptr, png_inforp info_ptr));
|
||||
(png_structrp png_ptr, png_const_inforp info_ptr));
|
||||
|
||||
#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
|
||||
/* Read the information before the actual image data. */
|
||||
@ -1892,9 +1892,12 @@ PNG_EXPORT(98, void, png_free_data, (png_const_structrp png_ptr,
|
||||
/* Reassign responsibility for freeing existing data, whether allocated
|
||||
* by libpng or by the application; this works on the png_info structure passed
|
||||
* in, it does not change the state for other png_info structures.
|
||||
*
|
||||
* It is unlikely that this function works correctly as of 1.6.0 and using it
|
||||
* may result either in memory leaks or double free of allocated data.
|
||||
*/
|
||||
PNG_EXPORT(99, void, png_data_freer, (png_const_structrp png_ptr,
|
||||
png_inforp info_ptr, int freer, png_uint_32 mask));
|
||||
PNG_EXPORTA(99, void, png_data_freer, (png_const_structrp png_ptr,
|
||||
png_inforp info_ptr, int freer, png_uint_32 mask), PNG_DEPRECATED);
|
||||
|
||||
/* Assignments for png_data_freer */
|
||||
#define PNG_DESTROY_WILL_FREE_DATA 1
|
||||
@ -2084,14 +2087,12 @@ PNG_FP_EXPORT(230, png_uint_32, png_get_cHRM_XYZ, (png_const_structrp png_ptr,
|
||||
png_const_inforp info_ptr, double *red_X, double *red_Y, double *red_Z,
|
||||
double *green_X, double *green_Y, double *green_Z, double *blue_X,
|
||||
double *blue_Y, double *blue_Z))
|
||||
#ifdef PNG_FIXED_POINT_SUPPORTED /* Otherwise not implemented */
|
||||
PNG_FIXED_EXPORT(134, png_uint_32, png_get_cHRM_fixed,
|
||||
(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
png_fixed_point *int_white_x, png_fixed_point *int_white_y,
|
||||
png_fixed_point *int_red_x, png_fixed_point *int_red_y,
|
||||
png_fixed_point *int_green_x, png_fixed_point *int_green_y,
|
||||
png_fixed_point *int_blue_x, png_fixed_point *int_blue_y))
|
||||
#endif
|
||||
PNG_FIXED_EXPORT(231, png_uint_32, png_get_cHRM_XYZ_fixed,
|
||||
(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
png_fixed_point *int_red_X, png_fixed_point *int_red_Y,
|
||||
|
@ -1,7 +1,7 @@
|
||||
|
||||
/* pngconf.h - machine configurable file for libpng
|
||||
*
|
||||
* libpng version 1.6.0beta20 - March 19, 2012
|
||||
* libpng version 1.6.0beta20 - March 21, 2012
|
||||
*
|
||||
* Copyright (c) 1998-2012 Glenn Randers-Pehrson
|
||||
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
|
||||
|
227
pngget.c
227
pngget.c
@ -463,87 +463,47 @@ png_get_bKGD(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
* same time to correct the rgb grayscale coefficient defaults obtained from the
|
||||
* cHRM chunk in 1.5.4
|
||||
*/
|
||||
png_uint_32 PNGFAPI
|
||||
png_get_cHRM_XYZ_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
png_fixed_point *int_red_X, png_fixed_point *int_red_Y,
|
||||
png_fixed_point *int_red_Z, png_fixed_point *int_green_X,
|
||||
png_fixed_point *int_green_Y, png_fixed_point *int_green_Z,
|
||||
png_fixed_point *int_blue_X, png_fixed_point *int_blue_Y,
|
||||
png_fixed_point *int_blue_Z)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
|
||||
{
|
||||
png_xy xy;
|
||||
png_XYZ XYZ;
|
||||
|
||||
png_debug1(1, "in %s retrieval function", "cHRM_XYZ");
|
||||
|
||||
xy.whitex = info_ptr->x_white;
|
||||
xy.whitey = info_ptr->y_white;
|
||||
xy.redx = info_ptr->x_red;
|
||||
xy.redy = info_ptr->y_red;
|
||||
xy.greenx = info_ptr->x_green;
|
||||
xy.greeny = info_ptr->y_green;
|
||||
xy.bluex = info_ptr->x_blue;
|
||||
xy.bluey = info_ptr->y_blue;
|
||||
|
||||
/* The *_checked function handles error reporting, so just return 0 if
|
||||
* there is a failure here.
|
||||
*/
|
||||
if (png_XYZ_from_xy_checked(png_ptr, &XYZ, xy))
|
||||
{
|
||||
if (int_red_X != NULL)
|
||||
*int_red_X = XYZ.redX;
|
||||
if (int_red_Y != NULL)
|
||||
*int_red_Y = XYZ.redY;
|
||||
if (int_red_Z != NULL)
|
||||
*int_red_Z = XYZ.redZ;
|
||||
if (int_green_X != NULL)
|
||||
*int_green_X = XYZ.greenX;
|
||||
if (int_green_Y != NULL)
|
||||
*int_green_Y = XYZ.greenY;
|
||||
if (int_green_Z != NULL)
|
||||
*int_green_Z = XYZ.greenZ;
|
||||
if (int_blue_X != NULL)
|
||||
*int_blue_X = XYZ.blueX;
|
||||
if (int_blue_Y != NULL)
|
||||
*int_blue_Y = XYZ.blueY;
|
||||
if (int_blue_Z != NULL)
|
||||
*int_blue_Z = XYZ.blueZ;
|
||||
|
||||
return (PNG_INFO_cHRM);
|
||||
}
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
# ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
png_uint_32 PNGAPI
|
||||
png_get_cHRM(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
double *white_x, double *white_y, double *red_x, double *red_y,
|
||||
double *green_x, double *green_y, double *blue_x, double *blue_y)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
|
||||
/* Quiet API change: this code used to only return the end points if a cHRM
|
||||
* chunk was present, but the end points can also come from iCCP or sRGB
|
||||
* chunks, so in 1.6.0 the png_get_ APIs return the end points regardless and
|
||||
* the png_set_ APIs merely check that set end points are mutually
|
||||
* consistent.
|
||||
*/
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS))
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "cHRM");
|
||||
|
||||
if (white_x != NULL)
|
||||
*white_x = png_float(png_ptr, info_ptr->x_white, "cHRM white X");
|
||||
*white_x = png_float(png_ptr,
|
||||
info_ptr->colorspace.end_points_xy.whitex, "cHRM white X");
|
||||
if (white_y != NULL)
|
||||
*white_y = png_float(png_ptr, info_ptr->y_white, "cHRM white Y");
|
||||
*white_y = png_float(png_ptr,
|
||||
info_ptr->colorspace.end_points_xy.whitey, "cHRM white Y");
|
||||
if (red_x != NULL)
|
||||
*red_x = png_float(png_ptr, info_ptr->x_red, "cHRM red X");
|
||||
*red_x = png_float(png_ptr, info_ptr->colorspace.end_points_xy.redx,
|
||||
"cHRM red X");
|
||||
if (red_y != NULL)
|
||||
*red_y = png_float(png_ptr, info_ptr->y_red, "cHRM red Y");
|
||||
*red_y = png_float(png_ptr, info_ptr->colorspace.end_points_xy.redy,
|
||||
"cHRM red Y");
|
||||
if (green_x != NULL)
|
||||
*green_x = png_float(png_ptr, info_ptr->x_green, "cHRM green X");
|
||||
*green_x = png_float(png_ptr,
|
||||
info_ptr->colorspace.end_points_xy.greenx, "cHRM green X");
|
||||
if (green_y != NULL)
|
||||
*green_y = png_float(png_ptr, info_ptr->y_green, "cHRM green Y");
|
||||
*green_y = png_float(png_ptr,
|
||||
info_ptr->colorspace.end_points_xy.greeny, "cHRM green Y");
|
||||
if (blue_x != NULL)
|
||||
*blue_x = png_float(png_ptr, info_ptr->x_blue, "cHRM blue X");
|
||||
*blue_x = png_float(png_ptr, info_ptr->colorspace.end_points_xy.bluex,
|
||||
"cHRM blue X");
|
||||
if (blue_y != NULL)
|
||||
*blue_y = png_float(png_ptr, info_ptr->y_blue, "cHRM blue Y");
|
||||
*blue_y = png_float(png_ptr, info_ptr->colorspace.end_points_xy.bluey,
|
||||
"cHRM blue Y");
|
||||
return (PNG_INFO_cHRM);
|
||||
}
|
||||
|
||||
@ -556,30 +516,38 @@ png_get_cHRM_XYZ(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
double *green_Y, double *green_Z, double *blue_X, double *blue_Y,
|
||||
double *blue_Z)
|
||||
{
|
||||
png_XYZ XYZ;
|
||||
|
||||
if (png_get_cHRM_XYZ_fixed(png_ptr, info_ptr,
|
||||
&XYZ.redX, &XYZ.redY, &XYZ.redZ, &XYZ.greenX, &XYZ.greenY, &XYZ.greenZ,
|
||||
&XYZ.blueX, &XYZ.blueY, &XYZ.blueZ) & PNG_INFO_cHRM)
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS))
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "cHRM_XYZ(float)");
|
||||
|
||||
if (red_X != NULL)
|
||||
*red_X = png_float(png_ptr, XYZ.redX, "cHRM 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, XYZ.redY, "cHRM 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, XYZ.redZ, "cHRM 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, XYZ.greenX, "cHRM green X");
|
||||
*green_X = png_float(png_ptr,
|
||||
info_ptr->colorspace.end_points_XYZ.greenX, "cHRM green X");
|
||||
if (green_Y != NULL)
|
||||
*green_Y = png_float(png_ptr, XYZ.greenY, "cHRM green Y");
|
||||
*green_Y = png_float(png_ptr,
|
||||
info_ptr->colorspace.end_points_XYZ.greenY, "cHRM green Y");
|
||||
if (green_Z != NULL)
|
||||
*green_Z = png_float(png_ptr, XYZ.greenZ, "cHRM green Z");
|
||||
*green_Z = png_float(png_ptr,
|
||||
info_ptr->colorspace.end_points_XYZ.greenZ, "cHRM green Z");
|
||||
if (blue_X != NULL)
|
||||
*blue_X = png_float(png_ptr, XYZ.blueX, "cHRM 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, XYZ.blueY, "cHRM 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, XYZ.blueZ, "cHRM blue Z");
|
||||
*blue_Z = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.blueZ,
|
||||
"cHRM blue Z");
|
||||
return (PNG_INFO_cHRM);
|
||||
}
|
||||
|
||||
@ -588,6 +556,43 @@ png_get_cHRM_XYZ(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
# endif
|
||||
|
||||
# ifdef PNG_FIXED_POINT_SUPPORTED
|
||||
png_uint_32 PNGAPI
|
||||
png_get_cHRM_XYZ_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
png_fixed_point *int_red_X, png_fixed_point *int_red_Y,
|
||||
png_fixed_point *int_red_Z, png_fixed_point *int_green_X,
|
||||
png_fixed_point *int_green_Y, png_fixed_point *int_green_Z,
|
||||
png_fixed_point *int_blue_X, png_fixed_point *int_blue_Y,
|
||||
png_fixed_point *int_blue_Z)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS))
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "cHRM_XYZ");
|
||||
|
||||
if (int_red_X != NULL)
|
||||
*int_red_X = info_ptr->colorspace.end_points_XYZ.redX;
|
||||
if (int_red_Y != NULL)
|
||||
*int_red_Y = info_ptr->colorspace.end_points_XYZ.redY;
|
||||
if (int_red_Z != NULL)
|
||||
*int_red_Z = info_ptr->colorspace.end_points_XYZ.redZ;
|
||||
if (int_green_X != NULL)
|
||||
*int_green_X = info_ptr->colorspace.end_points_XYZ.greenX;
|
||||
if (int_green_Y != NULL)
|
||||
*int_green_Y = info_ptr->colorspace.end_points_XYZ.greenY;
|
||||
if (int_green_Z != NULL)
|
||||
*int_green_Z = info_ptr->colorspace.end_points_XYZ.greenZ;
|
||||
if (int_blue_X != NULL)
|
||||
*int_blue_X = info_ptr->colorspace.end_points_XYZ.blueX;
|
||||
if (int_blue_Y != NULL)
|
||||
*int_blue_Y = info_ptr->colorspace.end_points_XYZ.blueY;
|
||||
if (int_blue_Z != NULL)
|
||||
*int_blue_Z = info_ptr->colorspace.end_points_XYZ.blueZ;
|
||||
return (PNG_INFO_cHRM);
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
png_uint_32 PNGAPI
|
||||
png_get_cHRM_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x,
|
||||
@ -596,24 +601,25 @@ png_get_cHRM_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "cHRM");
|
||||
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS))
|
||||
{
|
||||
if (white_x != NULL)
|
||||
*white_x = info_ptr->x_white;
|
||||
*white_x = info_ptr->colorspace.end_points_xy.whitex;
|
||||
if (white_y != NULL)
|
||||
*white_y = info_ptr->y_white;
|
||||
*white_y = info_ptr->colorspace.end_points_xy.whitey;
|
||||
if (red_x != NULL)
|
||||
*red_x = info_ptr->x_red;
|
||||
*red_x = info_ptr->colorspace.end_points_xy.redx;
|
||||
if (red_y != NULL)
|
||||
*red_y = info_ptr->y_red;
|
||||
*red_y = info_ptr->colorspace.end_points_xy.redy;
|
||||
if (green_x != NULL)
|
||||
*green_x = info_ptr->x_green;
|
||||
*green_x = info_ptr->colorspace.end_points_xy.greenx;
|
||||
if (green_y != NULL)
|
||||
*green_y = info_ptr->y_green;
|
||||
*green_y = info_ptr->colorspace.end_points_xy.greeny;
|
||||
if (blue_x != NULL)
|
||||
*blue_x = info_ptr->x_blue;
|
||||
*blue_x = info_ptr->colorspace.end_points_xy.bluex;
|
||||
if (blue_y != NULL)
|
||||
*blue_y = info_ptr->y_blue;
|
||||
*blue_y = info_ptr->colorspace.end_points_xy.bluey;
|
||||
return (PNG_INFO_cHRM);
|
||||
}
|
||||
|
||||
@ -623,35 +629,43 @@ png_get_cHRM_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
#endif
|
||||
|
||||
#ifdef PNG_gAMA_SUPPORTED
|
||||
png_uint_32 PNGFAPI
|
||||
# ifdef PNG_FIXED_POINT_SUPPORTED
|
||||
png_uint_32 PNGAPI
|
||||
png_get_gAMA_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
png_fixed_point *file_gamma)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "gAMA");
|
||||
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
|
||||
&& file_gamma != NULL)
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) &&
|
||||
file_gamma != NULL)
|
||||
{
|
||||
*file_gamma = info_ptr->gamma;
|
||||
*file_gamma = info_ptr->colorspace.gamma;
|
||||
return (PNG_INFO_gAMA);
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
# endif
|
||||
|
||||
# ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
png_uint_32 PNGAPI
|
||||
png_get_gAMA(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
double *file_gamma)
|
||||
{
|
||||
png_fixed_point igamma;
|
||||
png_uint_32 ok = png_get_gAMA_fixed(png_ptr, info_ptr, &igamma);
|
||||
png_debug1(1, "in %s retrieval function", "gAMA(float)");
|
||||
|
||||
if (ok)
|
||||
*file_gamma = png_float(png_ptr, igamma, "png_get_gAMA");
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) &&
|
||||
file_gamma != NULL)
|
||||
{
|
||||
*file_gamma = png_float(png_ptr, info_ptr->colorspace.gamma,
|
||||
"png_get_gAMA");
|
||||
return (PNG_INFO_gAMA);
|
||||
}
|
||||
|
||||
return ok;
|
||||
return (0);
|
||||
}
|
||||
|
||||
# endif
|
||||
#endif
|
||||
|
||||
@ -665,7 +679,7 @@ png_get_sRGB(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)
|
||||
&& file_srgb_intent != NULL)
|
||||
{
|
||||
*file_srgb_intent = (int)info_ptr->srgb_intent;
|
||||
*file_srgb_intent = info_ptr->colorspace.rendering_intent;
|
||||
return (PNG_INFO_sRGB);
|
||||
}
|
||||
|
||||
@ -687,11 +701,11 @@ png_get_iCCP(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
{
|
||||
*name = info_ptr->iccp_name;
|
||||
*profile = info_ptr->iccp_profile;
|
||||
/* Compression_type is a dummy so the API won't have to change
|
||||
* if we introduce multiple compression types later.
|
||||
*proflen = png_get_uint_32(info_ptr->iccp_profile);
|
||||
/* This is somewhat irrelevant since the profile data returned has
|
||||
* actually been uncompressed.
|
||||
*/
|
||||
*proflen = info_ptr->iccp_proflen;
|
||||
*compression_type = info_ptr->iccp_compression;
|
||||
*compression_type = PNG_COMPRESSION_TYPE_BASE;
|
||||
return (PNG_INFO_iCCP);
|
||||
}
|
||||
|
||||
@ -1133,15 +1147,6 @@ png_get_io_chunk_type (png_const_structrp png_ptr)
|
||||
{
|
||||
return png_ptr->chunk_name;
|
||||
}
|
||||
|
||||
#if PNG_LIBPNG_VER < 10600
|
||||
png_const_bytep PNGAPI
|
||||
png_get_io_chunk_name (png_structrp png_ptr)
|
||||
{
|
||||
PNG_CSTRING_FROM_CHUNK(png_ptr->io_chunk_string, png_ptr->chunk_name);
|
||||
return png_ptr->io_chunk_string;
|
||||
}
|
||||
#endif
|
||||
#endif /* ?PNG_IO_STATE_SUPPORTED */
|
||||
|
||||
#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
|
||||
|
52
pnginfo.h
52
pnginfo.h
@ -70,11 +70,13 @@ 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 */
|
||||
|
||||
#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 */
|
||||
png_byte signature[8]; /* magic bytes read by libpng from start of file */
|
||||
#endif
|
||||
|
||||
/* The rest of the data is optional. If you are reading, check the
|
||||
* valid field to see if the information in these are valid. If you
|
||||
@ -82,18 +84,25 @@ struct png_info_def
|
||||
* and initialize the appropriate fields below.
|
||||
*/
|
||||
|
||||
#if defined(PNG_gAMA_SUPPORTED)
|
||||
/* The gAMA chunk describes the gamma characteristics of the system
|
||||
* on which the image was created, normally in the range [1.0, 2.5].
|
||||
* Data is valid if (valid & PNG_INFO_gAMA) is non-zero.
|
||||
#if defined PNG_COLORSPACE_SUPPORTED || defined PNG_GAMMA_SUPPORTED
|
||||
/* png_colorspace only contains 'flags' if neither GAMMA or COLORSPACE are
|
||||
* defined. When COLORSPACE is switched on all the colorspace-defining
|
||||
* chunks should be enabled, when GAMMA is switched on all the gamma-defining
|
||||
* chunks should be enabled. If this is not done it becomes possible to read
|
||||
* inconsistent PNG files and assign a probably incorrect interpretation to
|
||||
* the information. (In other words, by carefully choosing which chunks to
|
||||
* recognize the system configuration can select an interpretation for PNG
|
||||
* files containing ambiguous data and this will result in inconsistent
|
||||
* behavior between different libpng builds!)
|
||||
*/
|
||||
png_fixed_point gamma;
|
||||
png_colorspace colorspace;
|
||||
#endif
|
||||
|
||||
#ifdef PNG_sRGB_SUPPORTED
|
||||
/* GR-P, 0.96a */
|
||||
/* Data valid if (valid & PNG_INFO_sRGB) non-zero. */
|
||||
png_byte srgb_intent; /* sRGB rendering intent [0, 1, 2, or 3] */
|
||||
#ifdef PNG_iCCP_SUPPORTED
|
||||
/* iCCP chunk data. */
|
||||
png_charp iccp_name; /* profile name */
|
||||
png_bytep iccp_profile; /* International Color Consortium profile data */
|
||||
png_uint_32 iccp_proflen; /* ICC profile data length */
|
||||
#endif
|
||||
|
||||
#ifdef PNG_TEXT_SUPPORTED
|
||||
@ -183,23 +192,6 @@ defined(PNG_READ_BACKGROUND_SUPPORTED)
|
||||
png_uint_16p hist;
|
||||
#endif
|
||||
|
||||
#ifdef PNG_cHRM_SUPPORTED
|
||||
/* The cHRM chunk describes the CIE color characteristics of the monitor
|
||||
* on which the PNG was created. This data allows the viewer to do gamut
|
||||
* mapping of the input image to ensure that the viewer sees the same
|
||||
* colors in the image as the creator. Values are in the range
|
||||
* [0.0, 0.8]. Data valid if (valid & PNG_INFO_cHRM) non-zero.
|
||||
*/
|
||||
png_fixed_point x_white;
|
||||
png_fixed_point y_white;
|
||||
png_fixed_point x_red;
|
||||
png_fixed_point y_red;
|
||||
png_fixed_point x_green;
|
||||
png_fixed_point y_green;
|
||||
png_fixed_point x_blue;
|
||||
png_fixed_point y_blue;
|
||||
#endif
|
||||
|
||||
#ifdef PNG_pCAL_SUPPORTED
|
||||
/* The pCAL chunk describes a transformation between the stored pixel
|
||||
* values and original physical data values used to create the image.
|
||||
@ -231,14 +223,6 @@ defined(PNG_READ_BACKGROUND_SUPPORTED)
|
||||
int unknown_chunks_num;
|
||||
#endif
|
||||
|
||||
#ifdef PNG_iCCP_SUPPORTED
|
||||
/* iCCP chunk data. */
|
||||
png_charp iccp_name; /* profile name */
|
||||
png_bytep iccp_profile; /* International Color Consortium profile data */
|
||||
png_uint_32 iccp_proflen; /* ICC profile data length */
|
||||
png_byte iccp_compression; /* Always zero */
|
||||
#endif
|
||||
|
||||
#ifdef PNG_sPLT_SUPPORTED
|
||||
/* Data on sPLT chunks (there may be more than one). */
|
||||
png_sPLT_tp splt_palettes;
|
||||
|
135
pngpriv.h
135
pngpriv.h
@ -186,8 +186,8 @@
|
||||
#endif
|
||||
|
||||
#include "png.h"
|
||||
#include "pnginfo.h"
|
||||
#include "pngstruct.h"
|
||||
#include "pnginfo.h"
|
||||
|
||||
/* pngconf.h does not set PNG_DLL_EXPORT unless it is required, so: */
|
||||
#ifndef PNG_DLL_EXPORT
|
||||
@ -457,16 +457,16 @@ typedef const png_uint_16p * png_const_uint_16pp;
|
||||
#define PNG_HAVE_IDAT 0x04
|
||||
/* #define PNG_AFTER_IDAT 0x08 (defined in png.h) */
|
||||
#define PNG_HAVE_IEND 0x10
|
||||
#define PNG_HAVE_gAMA 0x20
|
||||
#define PNG_HAVE_cHRM 0x40
|
||||
#define PNG_HAVE_sRGB 0x80
|
||||
/* 0x20 (unused) */
|
||||
/* 0x40 (unused) */
|
||||
/* 0x80 (unused) */
|
||||
#define PNG_HAVE_CHUNK_HEADER 0x100
|
||||
#define PNG_WROTE_tIME 0x200
|
||||
#define PNG_WROTE_INFO_BEFORE_PLTE 0x400
|
||||
#define PNG_BACKGROUND_IS_GRAY 0x800
|
||||
#define PNG_HAVE_PNG_SIGNATURE 0x1000
|
||||
#define PNG_HAVE_CHUNK_AFTER_IDAT 0x2000 /* Have another chunk after IDAT */
|
||||
#define PNG_HAVE_iCCP 0x4000
|
||||
/* 0x4000 (unused) */
|
||||
#define PNG_IS_READ_STRUCT 0x8000 /* Else is a write struct */
|
||||
|
||||
/* Flags for the transformations the PNG library does on the image data */
|
||||
@ -875,17 +875,9 @@ PNG_INTERNAL_FUNCTION(void,png_write_sBIT,(png_structrp png_ptr,
|
||||
#endif
|
||||
|
||||
#ifdef PNG_WRITE_cHRM_SUPPORTED
|
||||
# ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
PNG_INTERNAL_FUNCTION(void,png_write_cHRM,(png_structrp png_ptr,
|
||||
double white_x, double white_y,
|
||||
double red_x, double red_y, double green_x, double green_y,
|
||||
double blue_x, double blue_y),PNG_EMPTY);
|
||||
# endif
|
||||
PNG_INTERNAL_FUNCTION(void,png_write_cHRM_fixed,(png_structrp png_ptr,
|
||||
png_fixed_point int_white_x, png_fixed_point int_white_y,
|
||||
png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point
|
||||
int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x,
|
||||
png_fixed_point int_blue_y),PNG_EMPTY);
|
||||
const png_xy *xy), PNG_EMPTY);
|
||||
/* The xy value must have been previously validated */
|
||||
#endif
|
||||
|
||||
#ifdef PNG_WRITE_sRGB_SUPPORTED
|
||||
@ -895,9 +887,11 @@ PNG_INTERNAL_FUNCTION(void,png_write_sRGB,(png_structrp png_ptr,
|
||||
|
||||
#ifdef PNG_WRITE_iCCP_SUPPORTED
|
||||
PNG_INTERNAL_FUNCTION(void,png_write_iCCP,(png_structrp png_ptr,
|
||||
png_const_charp name, int compression_type,
|
||||
png_const_bytep profile, png_uint_32 proflen),PNG_EMPTY);
|
||||
/* Note to maintainer: profile should be png_bytep */
|
||||
png_const_charp name, png_const_bytep profile), PNG_EMPTY);
|
||||
/* The profile must have been previously validated for correctness, the
|
||||
* length comes from the first four bytes. Only the base, deflate,
|
||||
* compression is supported.
|
||||
*/
|
||||
#endif
|
||||
|
||||
#ifdef PNG_WRITE_sPLT_SUPPORTED
|
||||
@ -1395,50 +1389,71 @@ PNG_INTERNAL_FUNCTION(void,png_do_write_intrapixel,(png_row_infop row_info,
|
||||
png_bytep row),PNG_EMPTY);
|
||||
#endif
|
||||
|
||||
/* Added at libpng version 1.6.0 */
|
||||
#ifdef PNG_GAMMA_SUPPORTED
|
||||
PNG_INTERNAL_FUNCTION(int,png_colorspace_set_gamma,(png_const_structrp png_ptr,
|
||||
png_colorspacerp colorspace, png_fixed_point gAMA, int preferred),
|
||||
PNG_EMPTY);
|
||||
|
||||
PNG_INTERNAL_FUNCTION(void,png_colorspace_sync_info,(png_const_structrp png_ptr,
|
||||
png_inforp info_ptr), PNG_EMPTY);
|
||||
/* Synchronize the info 'valid' flags with the colorspace */
|
||||
|
||||
PNG_INTERNAL_FUNCTION(void,png_colorspace_sync,(png_const_structrp png_ptr,
|
||||
png_inforp info_ptr), PNG_EMPTY);
|
||||
/* Copy the png_struct colorspace to the info_struct and call the above to
|
||||
* synchronize the flags. Checks for NULL info_ptr and does nothing.
|
||||
*/
|
||||
#endif
|
||||
|
||||
/* Added at libpng version 1.4.0 */
|
||||
#ifdef PNG_CHECK_cHRM_SUPPORTED
|
||||
PNG_INTERNAL_FUNCTION(int,png_check_cHRM_fixed,(png_const_structrp png_ptr,
|
||||
png_fixed_point int_white_x, png_fixed_point int_white_y,
|
||||
png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point
|
||||
int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x,
|
||||
png_fixed_point int_blue_y),PNG_EMPTY);
|
||||
#endif
|
||||
|
||||
#ifdef PNG_CHECK_cHRM_SUPPORTED
|
||||
/* Added at libpng version 1.2.34 and 1.4.0 */
|
||||
/* Currently only used by png_check_cHRM_fixed */
|
||||
PNG_INTERNAL_FUNCTION(void,png_64bit_product,(long v1, long v2,
|
||||
unsigned long *hi_product, unsigned long *lo_product),PNG_EMPTY);
|
||||
#endif
|
||||
|
||||
#ifdef PNG_cHRM_SUPPORTED
|
||||
/* Added at libpng version 1.5.5 */
|
||||
typedef struct png_xy
|
||||
{
|
||||
png_fixed_point redx, redy;
|
||||
png_fixed_point greenx, greeny;
|
||||
png_fixed_point bluex, bluey;
|
||||
png_fixed_point whitex, whitey;
|
||||
} png_xy;
|
||||
|
||||
typedef struct png_XYZ
|
||||
{
|
||||
png_fixed_point redX, redY, redZ;
|
||||
png_fixed_point greenX, greenY, greenZ;
|
||||
png_fixed_point blueX, blueY, blueZ;
|
||||
} png_XYZ;
|
||||
|
||||
/* The conversion APIs return 0 on success, non-zero on a parameter error. They
|
||||
* allow conversion between the above representations of a color encoding. When
|
||||
* converting from XYZ end points to chromaticities the absolute magnitude of
|
||||
* the end points is lost, when converting back the sum of the Y values of the
|
||||
* three end points will be 1.0
|
||||
#ifdef PNG_COLORSPACE_SUPPORTED
|
||||
/* These internal functions are for maintaining the colorspace structure within
|
||||
* a png_info or png_struct (or, indeed, both).
|
||||
*/
|
||||
PNG_INTERNAL_FUNCTION(int,png_xy_from_XYZ,(png_xy *xy, png_XYZ XYZ),PNG_EMPTY);
|
||||
PNG_INTERNAL_FUNCTION(int,png_XYZ_from_xy,(png_XYZ *XYZ, png_xy xy),PNG_EMPTY);
|
||||
PNG_INTERNAL_FUNCTION(int,png_XYZ_from_xy_checked,(png_const_structrp png_ptr,
|
||||
png_XYZ *XYZ, png_xy xy),PNG_EMPTY);
|
||||
#endif
|
||||
PNG_INTERNAL_FUNCTION(int,png_colorspace_set_chromaticities,
|
||||
(png_const_structrp png_ptr, png_colorspacerp colorspace, const png_xy *xy,
|
||||
int preferred), PNG_EMPTY);
|
||||
|
||||
PNG_INTERNAL_FUNCTION(int,png_colorspace_set_endpoints,
|
||||
(png_const_structrp png_ptr, png_colorspacerp colorspace, const png_XYZ *XYZ,
|
||||
int preferred), PNG_EMPTY);
|
||||
|
||||
#ifdef PNG_sRGB_SUPPORTED
|
||||
PNG_INTERNAL_FUNCTION(int,png_colorspace_set_sRGB,(png_const_structrp png_ptr,
|
||||
png_colorspacerp colorspace, int intent, int preferred), PNG_EMPTY);
|
||||
#endif /* sRGB */
|
||||
|
||||
#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),
|
||||
PNG_EMPTY);
|
||||
/* The 'name' is used for information only */
|
||||
|
||||
/* Routines for checking parts of an ICC profile. */
|
||||
PNG_INTERNAL_FUNCTION(int,png_icc_check_length,(png_const_structrp png_ptr,
|
||||
png_colorspacerp colorspace, png_const_charp name,
|
||||
png_uint_32 profile_length), PNG_EMPTY);
|
||||
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 */), 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(void,png_icc_set_gAMA_and_cHRM,(
|
||||
png_const_structrp png_ptr, png_colorspacerp colorspace,
|
||||
png_const_charp name, png_const_bytep profile, int preferred), PNG_EMPTY);
|
||||
#endif /* iCCP */
|
||||
|
||||
#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
|
||||
PNG_INTERNAL_FUNCTION(void,png_colorspace_set_rgb_coefficients,
|
||||
(png_structrp png_ptr), PNG_EMPTY);
|
||||
/* Set the rgb_to_gray coefficients from the colorspace Y values */
|
||||
#endif /* READ_RGB_TO_GRAY */
|
||||
#endif /* COLORSPACE */
|
||||
|
||||
/* Added at libpng version 1.4.0 */
|
||||
PNG_INTERNAL_FUNCTION(void,png_check_IHDR,(png_const_structrp png_ptr,
|
||||
|
57
pngread.c
57
pngread.c
@ -1278,41 +1278,17 @@ png_image_read_header(png_voidp argument)
|
||||
|
||||
image->format = format;
|
||||
|
||||
/* Now try to work out whether the color data does not match sRGB. */
|
||||
if ((format & PNG_FORMAT_FLAG_COLOR) != 0 &&
|
||||
(info_ptr->valid & PNG_INFO_sRGB) == 0)
|
||||
{
|
||||
/* gamma is irrelevant because libpng does gamma correction, what
|
||||
* matters is if the cHRM chunk doesn't match or, in the absence of
|
||||
* cRHM, if the iCCP profile appears to have different end points.
|
||||
*/
|
||||
if (info_ptr->valid & PNG_INFO_cHRM)
|
||||
{
|
||||
/* TODO: this is a copy'n'paste from pngrutil.c, make a common
|
||||
* checking function. This checks for a 1% error.
|
||||
*/
|
||||
/* The cHRM chunk is used in preference to iCCP */
|
||||
if (PNG_OUT_OF_RANGE(info_ptr->x_white, 31270, 1000) ||
|
||||
PNG_OUT_OF_RANGE(info_ptr->y_white, 32900, 1000) ||
|
||||
PNG_OUT_OF_RANGE(info_ptr->x_red, 64000, 1000) ||
|
||||
PNG_OUT_OF_RANGE(info_ptr->y_red, 33000, 1000) ||
|
||||
PNG_OUT_OF_RANGE(info_ptr->x_green, 30000, 1000) ||
|
||||
PNG_OUT_OF_RANGE(info_ptr->y_green, 60000, 1000) ||
|
||||
PNG_OUT_OF_RANGE(info_ptr->x_blue, 15000, 1000) ||
|
||||
PNG_OUT_OF_RANGE(info_ptr->y_blue, 6000, 1000))
|
||||
image->flags |= PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB;
|
||||
}
|
||||
|
||||
else if (info_ptr->valid & PNG_INFO_iCCP)
|
||||
{
|
||||
# if 0
|
||||
/* TODO: IMPLEMENT THIS! */
|
||||
/* Here if we just have an iCCP chunk. */
|
||||
if (!png_iCCP_is_sRGB(png_ptr, info_ptr))
|
||||
# endif
|
||||
image->flags |= PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB;
|
||||
}
|
||||
}
|
||||
#ifdef PNG_COLORSPACE_SUPPORTED
|
||||
/* Does the colorspace match sRGB? If there is no color endpoint
|
||||
* (colorant) information assume yes, otherwise require the
|
||||
* 'ENDPOINTS_MATCHE_sRGB' colorspace flag to have been set. If the
|
||||
* colorspace has been determined to be invalid ignore it.
|
||||
*/
|
||||
if ((format & PNG_FORMAT_FLAG_COLOR) != 0 && ((png_ptr->colorspace.flags
|
||||
& (PNG_COLORSPACE_HAVE_ENDPOINTS|PNG_COLORSPACE_ENDPOINTS_MATCH_sRGB|
|
||||
PNG_COLORSPACE_INVALID)) == PNG_COLORSPACE_HAVE_ENDPOINTS))
|
||||
image->flags |= PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* We need the maximum number of entries regardless of the format the
|
||||
@ -1529,7 +1505,7 @@ png_image_skip_unused_chunks(png_structrp png_ptr)
|
||||
static void
|
||||
set_file_encoding(png_image_read_control *display)
|
||||
{
|
||||
png_fixed_point g = display->image->opaque->png_ptr->gamma;
|
||||
png_fixed_point g = display->image->opaque->png_ptr->colorspace.gamma;
|
||||
if (png_gamma_significant(g))
|
||||
{
|
||||
if (png_gamma_not_sRGB(g))
|
||||
@ -2388,7 +2364,8 @@ png_image_read_colormap(png_voidp argument)
|
||||
* alternative of double gamma correction.
|
||||
*/
|
||||
if ((png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA ||
|
||||
png_ptr->num_trans > 0) && png_gamma_not_sRGB(png_ptr->gamma))
|
||||
png_ptr->num_trans > 0) &&
|
||||
png_gamma_not_sRGB(png_ptr->colorspace.gamma))
|
||||
{
|
||||
cmap_entries = make_gray_file_colormap(display);
|
||||
data_encoding = E_FILE;
|
||||
@ -2421,7 +2398,7 @@ png_image_read_colormap(png_voidp argument)
|
||||
gray = png_sRGB_table[gray]; /* now E_LINEAR */
|
||||
|
||||
gray = PNG_DIV257(png_gamma_16bit_correct(gray,
|
||||
png_ptr->gamma)); /* now E_FILE */
|
||||
png_ptr->colorspace.gamma)); /* now E_FILE */
|
||||
|
||||
/* And make sure the corresponding palette entry contains
|
||||
* exactly the required sRGB value.
|
||||
@ -3582,8 +3559,8 @@ png_image_read_direct(png_voidp argument)
|
||||
* yet; it's set below. png_struct::gamma, however, is set to the
|
||||
* final value.
|
||||
*/
|
||||
if (png_muldiv(>est, output_gamma, png_ptr->gamma, PNG_FP_1) &&
|
||||
!png_gamma_significant(gtest))
|
||||
if (png_muldiv(>est, output_gamma, png_ptr->colorspace.gamma,
|
||||
PNG_FP_1) && !png_gamma_significant(gtest))
|
||||
do_local_background = 0;
|
||||
|
||||
else if (mode == PNG_ALPHA_STANDARD)
|
||||
|
63
pngrtran.c
63
pngrtran.c
@ -349,8 +349,11 @@ png_set_alpha_mode_fixed(png_structrp png_ptr, int mode,
|
||||
* the side effect that the gamma in a second call to png_set_alpha_mode will
|
||||
* be ignored.)
|
||||
*/
|
||||
if (png_ptr->gamma == 0)
|
||||
png_ptr->gamma = file_gamma;
|
||||
if (png_ptr->colorspace.gamma == 0)
|
||||
{
|
||||
png_ptr->colorspace.gamma = file_gamma;
|
||||
png_ptr->colorspace.flags |= PNG_COLORSPACE_HAVE_GAMMA;
|
||||
}
|
||||
|
||||
/* But always set the output gamma: */
|
||||
png_ptr->screen_gamma = output_gamma;
|
||||
@ -362,7 +365,7 @@ png_set_alpha_mode_fixed(png_structrp png_ptr, int mode,
|
||||
{
|
||||
/* And obtain alpha pre-multiplication by composing on black: */
|
||||
png_memset(&png_ptr->background, 0, sizeof png_ptr->background);
|
||||
png_ptr->background_gamma = png_ptr->gamma; /* just in case */
|
||||
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;
|
||||
|
||||
@ -825,7 +828,8 @@ png_set_gamma_fixed(png_structrp png_ptr, png_fixed_point scrn_gamma,
|
||||
* file if a gAMA chunk was present. png_set_alpha_mode provides a
|
||||
* different, easier, way to default the file gamma.
|
||||
*/
|
||||
png_ptr->gamma = file_gamma;
|
||||
png_ptr->colorspace.gamma = file_gamma;
|
||||
png_ptr->colorspace.flags |= PNG_COLORSPACE_HAVE_GAMMA;
|
||||
png_ptr->screen_gamma = scrn_gamma;
|
||||
}
|
||||
|
||||
@ -971,6 +975,7 @@ png_set_rgb_to_gray_fixed(png_structrp png_ptr, int error_action,
|
||||
png_error(png_ptr, "invalid error action to rgb_to_gray");
|
||||
break;
|
||||
}
|
||||
|
||||
if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
|
||||
#ifdef PNG_READ_EXPAND_SUPPORTED
|
||||
png_ptr->transformations |= PNG_EXPAND;
|
||||
@ -1006,7 +1011,7 @@ png_set_rgb_to_gray_fixed(png_structrp png_ptr, int error_action,
|
||||
else
|
||||
{
|
||||
if (red >= 0 && green >= 0)
|
||||
png_warning(png_ptr,
|
||||
png_app_warning(png_ptr,
|
||||
"ignoring out of range rgb_to_gray coefficients");
|
||||
|
||||
/* Use the defaults, from the cHRM chunk if set, else the historical
|
||||
@ -1286,17 +1291,17 @@ png_init_read_transformations(png_structrp png_ptr)
|
||||
*/
|
||||
int gamma_correction = 0;
|
||||
|
||||
if (png_ptr->gamma != 0) /* has been set */
|
||||
if (png_ptr->colorspace.gamma != 0) /* has been set */
|
||||
{
|
||||
if (png_ptr->screen_gamma != 0) /* screen set too */
|
||||
gamma_correction = png_gamma_threshold(png_ptr->gamma,
|
||||
gamma_correction = png_gamma_threshold(png_ptr->colorspace.gamma,
|
||||
png_ptr->screen_gamma);
|
||||
|
||||
else
|
||||
/* Assume the output matches the input; a long time default behavior
|
||||
* of libpng, although the standard has nothing to say about this.
|
||||
*/
|
||||
png_ptr->screen_gamma = png_reciprocal(png_ptr->gamma);
|
||||
png_ptr->screen_gamma = png_reciprocal(png_ptr->colorspace.gamma);
|
||||
}
|
||||
|
||||
else if (png_ptr->screen_gamma != 0)
|
||||
@ -1305,7 +1310,7 @@ png_init_read_transformations(png_structrp png_ptr)
|
||||
* png_set_alpha_mode (even if the alpha handling mode isn't required
|
||||
* or isn't changed from the default.)
|
||||
*/
|
||||
png_ptr->gamma = png_reciprocal(png_ptr->screen_gamma);
|
||||
png_ptr->colorspace.gamma = png_reciprocal(png_ptr->screen_gamma);
|
||||
|
||||
else /* neither are set */
|
||||
/* Just in case the following prevents any processing - file and screen
|
||||
@ -1313,7 +1318,10 @@ png_init_read_transformations(png_structrp png_ptr)
|
||||
* third gamma value other than png_set_background with 'UNIQUE', and,
|
||||
* prior to 1.5.4
|
||||
*/
|
||||
png_ptr->screen_gamma = png_ptr->gamma = PNG_FP_1;
|
||||
png_ptr->screen_gamma = png_ptr->colorspace.gamma = PNG_FP_1;
|
||||
|
||||
/* We have a gamma value now. */
|
||||
png_ptr->colorspace.flags |= PNG_COLORSPACE_HAVE_GAMMA;
|
||||
|
||||
/* Now turn the gamma transformation on or off as appropriate. Notice
|
||||
* that PNG_GAMMA just refers to the file->screen correction. Alpha
|
||||
@ -1395,9 +1403,16 @@ png_init_read_transformations(png_structrp png_ptr)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_EXPAND_SUPPORTED) && \
|
||||
defined(PNG_READ_BACKGROUND_SUPPORTED) && \
|
||||
defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
|
||||
#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
|
||||
/* Make sure the coefficients for the rgb to gray convertion are set
|
||||
* appropriately.
|
||||
*/
|
||||
if (png_ptr->transformations & PNG_RGB_TO_GRAY)
|
||||
png_colorspace_set_rgb_coefficients(png_ptr);
|
||||
#endif
|
||||
|
||||
#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
|
||||
#if defined PNG_READ_EXPAND_SUPPORTED && defined PNG_READ_BACKGROUND_SUPPORTED
|
||||
/* Detect gray background and attempt to enable optimization for
|
||||
* gray --> RGB case.
|
||||
*
|
||||
@ -1439,7 +1454,8 @@ png_init_read_transformations(png_structrp png_ptr)
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* PNG_READ_GRAY_TO_RGB_SUPPORTED (etc) */
|
||||
#endif /* PNG_READ_EXPAND_SUPPORTED && PNG_READ_BACKGROUND_SUPPORTED */
|
||||
#endif /* PNG_READ_GRAY_TO_RGB_SUPPORTED */
|
||||
|
||||
/* For indexed PNG data (PNG_COLOR_TYPE_PALETTE) many of the transformations
|
||||
* can be performed directly on the palette, and some (such as rgb to gray)
|
||||
@ -1535,10 +1551,10 @@ png_init_read_transformations(png_structrp png_ptr)
|
||||
*/
|
||||
if ((png_ptr->transformations & PNG_GAMMA)
|
||||
|| ((png_ptr->transformations & PNG_RGB_TO_GRAY)
|
||||
&& (png_gamma_significant(png_ptr->gamma) ||
|
||||
&& (png_gamma_significant(png_ptr->colorspace.gamma) ||
|
||||
png_gamma_significant(png_ptr->screen_gamma)))
|
||||
|| ((png_ptr->transformations & PNG_COMPOSE)
|
||||
&& (png_gamma_significant(png_ptr->gamma)
|
||||
&& (png_gamma_significant(png_ptr->colorspace.gamma)
|
||||
|| png_gamma_significant(png_ptr->screen_gamma)
|
||||
# ifdef PNG_READ_BACKGROUND_SUPPORTED
|
||||
|| (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_UNIQUE
|
||||
@ -1595,8 +1611,8 @@ png_init_read_transformations(png_structrp png_ptr)
|
||||
break;
|
||||
|
||||
case PNG_BACKGROUND_GAMMA_FILE:
|
||||
g = png_reciprocal(png_ptr->gamma);
|
||||
gs = png_reciprocal2(png_ptr->gamma,
|
||||
g = png_reciprocal(png_ptr->colorspace.gamma);
|
||||
gs = png_reciprocal2(png_ptr->colorspace.gamma,
|
||||
png_ptr->screen_gamma);
|
||||
break;
|
||||
|
||||
@ -1704,8 +1720,9 @@ png_init_read_transformations(png_structrp png_ptr)
|
||||
break;
|
||||
|
||||
case PNG_BACKGROUND_GAMMA_FILE:
|
||||
g = png_reciprocal(png_ptr->gamma);
|
||||
gs = png_reciprocal2(png_ptr->gamma, png_ptr->screen_gamma);
|
||||
g = png_reciprocal(png_ptr->colorspace.gamma);
|
||||
gs = png_reciprocal2(png_ptr->colorspace.gamma,
|
||||
png_ptr->screen_gamma);
|
||||
break;
|
||||
|
||||
case PNG_BACKGROUND_GAMMA_UNIQUE:
|
||||
@ -1944,8 +1961,12 @@ png_read_transform_info(png_structrp png_ptr, png_inforp info_ptr)
|
||||
* however it seems that the code in png_init_read_transformations, which has
|
||||
* been called before this from png_read_update_info->png_read_start_row
|
||||
* sometimes does the gamma transform and cancels the flag.
|
||||
*
|
||||
* TODO: this looks wrong; the info_ptr should end up with a gamma equal to
|
||||
* the screen_gamma value. The following probably results in weirdness if
|
||||
* the info_ptr is used by the app after the rows have been read.
|
||||
*/
|
||||
info_ptr->gamma = png_ptr->gamma;
|
||||
info_ptr->colorspace.gamma = png_ptr->colorspace.gamma;
|
||||
#endif
|
||||
|
||||
if (info_ptr->bit_depth == 16)
|
||||
|
1078
pngrutil.c
1078
pngrutil.c
File diff suppressed because it is too large
Load Diff
110
pngset.c
110
pngset.c
@ -42,26 +42,27 @@ png_set_cHRM_fixed(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y,
|
||||
png_fixed_point blue_x, png_fixed_point blue_y)
|
||||
{
|
||||
png_xy xy;
|
||||
|
||||
png_debug1(1, "in %s storage function", "cHRM fixed");
|
||||
|
||||
if (png_ptr == NULL || info_ptr == NULL)
|
||||
return;
|
||||
|
||||
# ifdef PNG_CHECK_cHRM_SUPPORTED
|
||||
if (png_check_cHRM_fixed(png_ptr,
|
||||
white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y))
|
||||
# endif
|
||||
{
|
||||
info_ptr->x_white = white_x;
|
||||
info_ptr->y_white = white_y;
|
||||
info_ptr->x_red = red_x;
|
||||
info_ptr->y_red = red_y;
|
||||
info_ptr->x_green = green_x;
|
||||
info_ptr->y_green = green_y;
|
||||
info_ptr->x_blue = blue_x;
|
||||
info_ptr->y_blue = blue_y;
|
||||
info_ptr->valid |= PNG_INFO_cHRM;
|
||||
}
|
||||
xy.redx = red_x;
|
||||
xy.redy = red_y;
|
||||
xy.greenx = green_x;
|
||||
xy.greeny = green_y;
|
||||
xy.bluex = blue_x;
|
||||
xy.bluey = blue_y;
|
||||
xy.whitex = white_x;
|
||||
xy.whitey = white_y;
|
||||
|
||||
if (png_colorspace_set_chromaticities(png_ptr, &info_ptr->colorspace, &xy,
|
||||
2/* override with app values*/))
|
||||
info_ptr->colorspace.flags |= PNG_COLORSPACE_FROM_cHRM;
|
||||
|
||||
png_colorspace_sync_info(png_ptr, info_ptr);
|
||||
}
|
||||
|
||||
void PNGFAPI
|
||||
@ -73,7 +74,6 @@ png_set_cHRM_XYZ_fixed(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
png_fixed_point int_blue_Z)
|
||||
{
|
||||
png_XYZ XYZ;
|
||||
png_xy xy;
|
||||
|
||||
png_debug1(1, "in %s storage function", "cHRM XYZ fixed");
|
||||
|
||||
@ -90,11 +90,10 @@ png_set_cHRM_XYZ_fixed(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
XYZ.blueY = int_blue_Y;
|
||||
XYZ.blueZ = int_blue_Z;
|
||||
|
||||
if (png_xy_from_XYZ(&xy, XYZ))
|
||||
png_error(png_ptr, "XYZ values out of representable range");
|
||||
if (png_colorspace_set_endpoints(png_ptr, &info_ptr->colorspace, &XYZ, 2))
|
||||
info_ptr->colorspace.flags |= PNG_COLORSPACE_FROM_cHRM;
|
||||
|
||||
png_set_cHRM_fixed(png_ptr, info_ptr, xy.whitex, xy.whitey, xy.redx, xy.redy,
|
||||
xy.greenx, xy.greeny, xy.bluex, xy.bluey);
|
||||
png_colorspace_sync_info(png_ptr, info_ptr);
|
||||
}
|
||||
|
||||
# ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
@ -153,12 +152,15 @@ png_set_gAMA_fixed(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
* displays that are all black or all white.)
|
||||
*/
|
||||
if (file_gamma < 16 || file_gamma > 625000000)
|
||||
png_warning(png_ptr, "Out of range gamma value ignored");
|
||||
png_app_error(png_ptr, "Out of range gamma value ignored");
|
||||
|
||||
else
|
||||
{
|
||||
info_ptr->gamma = file_gamma;
|
||||
info_ptr->valid |= PNG_INFO_gAMA;
|
||||
if (png_colorspace_set_gamma(png_ptr, &info_ptr->colorspace, file_gamma,
|
||||
2/* overrided with app value */))
|
||||
info_ptr->colorspace.flags |= PNG_COLORSPACE_FROM_gAMA;
|
||||
|
||||
png_colorspace_sync_info(png_ptr, info_ptr);
|
||||
}
|
||||
}
|
||||
|
||||
@ -593,8 +595,10 @@ png_set_sRGB(png_const_structrp png_ptr, png_inforp info_ptr, int srgb_intent)
|
||||
if (png_ptr == NULL || info_ptr == NULL)
|
||||
return;
|
||||
|
||||
info_ptr->srgb_intent = (png_byte)srgb_intent;
|
||||
info_ptr->valid |= PNG_INFO_sRGB;
|
||||
(void)png_colorspace_set_sRGB(png_ptr, &info_ptr->colorspace, srgb_intent,
|
||||
2/* app value overrides*/);
|
||||
|
||||
png_colorspace_sync_info(png_ptr, info_ptr);
|
||||
}
|
||||
|
||||
void PNGAPI
|
||||
@ -606,21 +610,15 @@ png_set_sRGB_gAMA_and_cHRM(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
if (png_ptr == NULL || info_ptr == NULL)
|
||||
return;
|
||||
|
||||
png_set_sRGB(png_ptr, info_ptr, srgb_intent);
|
||||
if (png_colorspace_set_sRGB(png_ptr, &info_ptr->colorspace, srgb_intent,
|
||||
2/* app value overrides*/))
|
||||
{
|
||||
/* And cause the gAMA and cHRM to be written too */
|
||||
info_ptr->colorspace.flags |=
|
||||
PNG_COLORSPACE_FROM_gAMA|PNG_COLORSPACE_FROM_cHRM;
|
||||
}
|
||||
|
||||
# ifdef PNG_gAMA_SUPPORTED
|
||||
png_set_gAMA_fixed(png_ptr, info_ptr, PNG_GAMMA_sRGB_INVERSE);
|
||||
# endif
|
||||
|
||||
# ifdef PNG_cHRM_SUPPORTED
|
||||
png_set_cHRM_fixed(png_ptr, info_ptr,
|
||||
/* color x y */
|
||||
/* white */ 31270, 32900,
|
||||
/* red */ 64000, 33000,
|
||||
/* green */ 30000, 60000,
|
||||
/* blue */ 15000, 6000
|
||||
);
|
||||
# endif /* cHRM */
|
||||
png_colorspace_sync_info(png_ptr, info_ptr);
|
||||
}
|
||||
#endif /* sRGB */
|
||||
|
||||
@ -640,12 +638,34 @@ png_set_iCCP(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL)
|
||||
return;
|
||||
|
||||
if (compression_type != PNG_COMPRESSION_TYPE_BASE)
|
||||
png_app_error(png_ptr, "Invalid iCCP compression method");
|
||||
|
||||
/* 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.)
|
||||
*/
|
||||
{
|
||||
int result = png_colorspace_set_ICC(png_ptr, &info_ptr->colorspace, name,
|
||||
proflen, profile, 0/* do *not* override the app cHRM or gAMA */);
|
||||
|
||||
png_colorspace_sync_info(png_ptr, info_ptr);
|
||||
|
||||
/* Don't do any of the copying if the profile was bad, or inconsistent. */
|
||||
if (!result)
|
||||
return;
|
||||
|
||||
/* But do write the gAMA and cHRM chunks from the profile. */
|
||||
info_ptr->colorspace.flags |=
|
||||
PNG_COLORSPACE_FROM_gAMA|PNG_COLORSPACE_FROM_cHRM;
|
||||
}
|
||||
|
||||
length = png_strlen(name)+1;
|
||||
new_iccp_name = png_voidcast(png_charp, png_malloc_warn(png_ptr, length));
|
||||
|
||||
if (new_iccp_name == NULL)
|
||||
{
|
||||
png_warning(png_ptr, "Insufficient memory to process iCCP chunk");
|
||||
png_benign_error(png_ptr, "Insufficient memory to process iCCP chunk");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -655,8 +675,8 @@ png_set_iCCP(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
|
||||
if (new_iccp_profile == NULL)
|
||||
{
|
||||
png_free (png_ptr, new_iccp_name);
|
||||
png_warning(png_ptr,
|
||||
png_free(png_ptr, new_iccp_name);
|
||||
png_benign_error(png_ptr,
|
||||
"Insufficient memory to process iCCP profile");
|
||||
return;
|
||||
}
|
||||
@ -668,10 +688,6 @@ png_set_iCCP(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
info_ptr->iccp_proflen = proflen;
|
||||
info_ptr->iccp_name = new_iccp_name;
|
||||
info_ptr->iccp_profile = new_iccp_profile;
|
||||
/* Compression is always zero but is here so the API and info structure
|
||||
* does not have to change if we introduce multiple compression types
|
||||
*/
|
||||
info_ptr->iccp_compression = (png_byte)compression_type;
|
||||
info_ptr->free_me |= PNG_FREE_ICCP;
|
||||
info_ptr->valid |= PNG_INFO_iCCP;
|
||||
}
|
||||
@ -1081,7 +1097,7 @@ png_set_unknown_chunks(png_const_structrp png_ptr,
|
||||
to->size = from->size;
|
||||
|
||||
/* Note our location in the read or write sequence */
|
||||
to->location = (png_byte)(png_ptr->mode & 0xff);
|
||||
to->location = (png_byte)png_ptr->mode;
|
||||
|
||||
if (from->size == 0)
|
||||
to->data=NULL;
|
||||
|
89
pngstruct.h
89
pngstruct.h
@ -69,6 +69,76 @@ typedef struct png_compression_buffer
|
||||
(offsetof(png_compression_buffer, output) + (pp)->zbuffer_size)
|
||||
#endif
|
||||
|
||||
/* Colorspace support; structures used in png_struct, png_info and in internal
|
||||
* functions to hold and communicate information about the color space.
|
||||
*
|
||||
* PNG_COLORSPACE_SUPPORTED is only required if the application will perform
|
||||
* colorspace corrections, otherwise all the colorspace information can be
|
||||
* skipped and the size of libpng can be reduced (significantly) by compiling
|
||||
* out the colorspace support.
|
||||
*/
|
||||
#ifdef PNG_COLORSPACE_SUPPORTED
|
||||
/* The chromaticities of the red, green and blue colorants and the chromaticity
|
||||
* of the corresponding white point (i.e. of rgb(1.0,1.0,1.0)).
|
||||
*/
|
||||
typedef struct png_xy
|
||||
{
|
||||
png_fixed_point redx, redy;
|
||||
png_fixed_point greenx, greeny;
|
||||
png_fixed_point bluex, bluey;
|
||||
png_fixed_point whitex, whitey;
|
||||
} png_xy;
|
||||
|
||||
/* The same data as above but encoded as CIE XYZ values. When this data comes
|
||||
* from chromaticities the sum of the Y values is assumed to be 1.0
|
||||
*/
|
||||
typedef struct png_XYZ
|
||||
{
|
||||
png_fixed_point redX, redY, redZ;
|
||||
png_fixed_point greenX, greenY, greenZ;
|
||||
png_fixed_point blueX, blueY, blueZ;
|
||||
} png_XYZ;
|
||||
#endif /* COLORSPACE */
|
||||
|
||||
#if defined PNG_COLORSPACE_SUPPORTED || defined PNG_GAMMA_SUPPORTED
|
||||
/* A colorspace is all the above plus, potentially, profile information,
|
||||
* however at present libpng does not use the profile internally so it is only
|
||||
* stored in the png_info struct (if iCCP is supported.) The rendering intent
|
||||
* is retained here and is checked.
|
||||
*
|
||||
* The file gamma encoding information is also stored here and gamma correction
|
||||
* is done by libpng, whereas color correction must currently be done by the
|
||||
* application.
|
||||
*/
|
||||
typedef struct png_colorspace
|
||||
{
|
||||
#ifdef PNG_GAMMA_SUPPORTED
|
||||
png_fixed_point gamma; /* File gamma */
|
||||
#endif
|
||||
|
||||
#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_16 rendering_intent; /* Rendering intent of a profile */
|
||||
#endif
|
||||
|
||||
/* Flags are always defined to simplify the code. */
|
||||
png_uint_16 flags; /* As defined below */
|
||||
} png_colorspace, * PNG_RESTRICT png_colorspacerp;
|
||||
|
||||
typedef const png_colorspace * PNG_RESTRICT png_const_colorspacerp;
|
||||
|
||||
#define PNG_COLORSPACE_HAVE_GAMMA 0x0001
|
||||
#define PNG_COLORSPACE_HAVE_ENDPOINTS 0x0002
|
||||
#define PNG_COLORSPACE_HAVE_INTENT 0x0004
|
||||
#define PNG_COLORSPACE_FROM_gAMA 0x0008
|
||||
#define PNG_COLORSPACE_FROM_cHRM 0x0010
|
||||
#define PNG_COLORSPACE_ENDPOINTS_MATCH_sRGB 0x0020
|
||||
#define PNG_COLORSPACE_MATCHES_sRGB 0x0040 /* exact match on profile */
|
||||
#define PNG_COLORSPACE_INVALID 0x8000
|
||||
#define PNG_COLORSPACE_CANCEL(flags) (0xffff ^ (flags))
|
||||
#endif /* COLORSPACE || GAMMA */
|
||||
|
||||
struct png_struct_def
|
||||
{
|
||||
#ifdef PNG_SETJMP_SUPPORTED
|
||||
@ -153,10 +223,12 @@ struct png_struct_def
|
||||
png_bytep row_buf; /* buffer to save current (unfiltered) row.
|
||||
* This is a pointer into big_row_buf
|
||||
*/
|
||||
#ifdef PNG_WRITE_SUPPORTED
|
||||
png_bytep sub_row; /* buffer to save "sub" row when filtering */
|
||||
png_bytep up_row; /* buffer to save "up" row when filtering */
|
||||
png_bytep avg_row; /* buffer to save "avg" row when filtering */
|
||||
png_bytep paeth_row; /* buffer to save "Paeth" row when filtering */
|
||||
#endif
|
||||
png_size_t info_rowbytes; /* Added in 1.5.4: cache of updated row bytes */
|
||||
|
||||
png_uint_32 idat_size; /* current IDAT size for read */
|
||||
@ -186,11 +258,6 @@ struct png_struct_def
|
||||
/* pixel depth used for the row buffers */
|
||||
png_byte transformed_pixel_depth;
|
||||
/* pixel depth after read/write transforms */
|
||||
#if PNG_LIBPNG_VER < 10600
|
||||
png_byte io_chunk_string[5];
|
||||
/* string name of chunk */
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
|
||||
png_uint_16 filler; /* filler bytes for pixel expansion */
|
||||
#endif
|
||||
@ -213,7 +280,6 @@ struct png_struct_def
|
||||
|
||||
#ifdef PNG_READ_GAMMA_SUPPORTED
|
||||
int gamma_shift; /* number of "insignificant" bits in 16-bit gamma */
|
||||
png_fixed_point gamma; /* file gamma value */
|
||||
png_fixed_point screen_gamma; /* screen gamma value (display_exponent) */
|
||||
|
||||
png_bytep gamma_table; /* gamma table for 8-bit depth files */
|
||||
@ -307,11 +373,6 @@ struct png_struct_def
|
||||
png_bytep chunk_list;
|
||||
#endif
|
||||
|
||||
#ifdef PNG_READ_sRGB_SUPPORTED
|
||||
/* Added in 1.5.5 to record an sRGB chunk in the png. */
|
||||
png_byte is_sRGB;
|
||||
#endif
|
||||
|
||||
/* New members added in libpng-1.0.3 */
|
||||
#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
|
||||
png_byte rgb_to_gray_status;
|
||||
@ -405,5 +466,11 @@ struct png_struct_def
|
||||
|
||||
void (*read_filter[PNG_FILTER_VALUE_LAST-1])(png_row_infop row_info,
|
||||
png_bytep row, png_const_bytep prev_row);
|
||||
|
||||
#ifdef PNG_READ_SUPPORTED
|
||||
#if defined PNG_COLORSPACE_SUPPORTED || defined PNG_GAMMA_SUPPORTED
|
||||
png_colorspace colorspace;
|
||||
#endif
|
||||
#endif
|
||||
};
|
||||
#endif /* PNGSTRUCT_H */
|
||||
|
71
pngwrite.c
71
pngwrite.c
@ -28,7 +28,7 @@
|
||||
* them in png_write_end(), and compressing them.
|
||||
*/
|
||||
void PNGAPI
|
||||
png_write_info_before_PLTE(png_structrp png_ptr, png_inforp info_ptr)
|
||||
png_write_info_before_PLTE(png_structrp png_ptr, png_const_inforp info_ptr)
|
||||
{
|
||||
png_debug(1, "in png_write_info_before_PLTE");
|
||||
|
||||
@ -60,32 +60,61 @@ png_write_info_before_PLTE(png_structrp png_ptr, png_inforp info_ptr)
|
||||
#endif
|
||||
/* The rest of these check to see if the valid field has the appropriate
|
||||
* flag set, and if it does, writes the chunk.
|
||||
*
|
||||
* 1.6.0: COLORSPACE support controls the writing of these chunks too, and
|
||||
* the chunks will be written if the WRITE routine is there and information
|
||||
* is available in the COLORSPACE. (See png_colorspace_sync_info in png.c
|
||||
* for where the valid flags get set.)
|
||||
*
|
||||
* Under certain circumstances the colorspace can be invalidated without
|
||||
* syncing the info_struct 'valid' flags; this happens if libpng detects and
|
||||
* error and calls png_error while the color space is being set, yet the
|
||||
* application continues writing the PNG. So check the 'invalid' flag here
|
||||
* too.
|
||||
*/
|
||||
#ifdef PNG_WRITE_gAMA_SUPPORTED
|
||||
if (info_ptr->valid & PNG_INFO_gAMA)
|
||||
png_write_gAMA_fixed(png_ptr, info_ptr->gamma);
|
||||
#endif
|
||||
#ifdef PNG_WRITE_sRGB_SUPPORTED
|
||||
if (info_ptr->valid & PNG_INFO_sRGB)
|
||||
png_write_sRGB(png_ptr, (int)info_ptr->srgb_intent);
|
||||
#ifdef PNG_GAMMA_SUPPORTED
|
||||
# ifdef PNG_WRITE_gAMA_SUPPORTED
|
||||
if (!(info_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) &&
|
||||
(info_ptr->colorspace.flags & PNG_COLORSPACE_FROM_gAMA) &&
|
||||
(info_ptr->valid & PNG_INFO_gAMA))
|
||||
png_write_gAMA_fixed(png_ptr, info_ptr->colorspace.gamma);
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef PNG_WRITE_iCCP_SUPPORTED
|
||||
if (info_ptr->valid & PNG_INFO_iCCP)
|
||||
png_write_iCCP(png_ptr, info_ptr->iccp_name, PNG_COMPRESSION_TYPE_BASE,
|
||||
info_ptr->iccp_profile, info_ptr->iccp_proflen);
|
||||
#endif
|
||||
#ifdef PNG_COLORSPACE_SUPPORTED
|
||||
/* Write only one of sRGB or an ICC profile, favour sRGB if the profile
|
||||
* matches sRGB.
|
||||
*/
|
||||
# ifdef PNG_WRITE_sRGB_SUPPORTED
|
||||
if (!(info_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) &&
|
||||
(info_ptr->valid & PNG_INFO_sRGB))
|
||||
png_write_sRGB(png_ptr, info_ptr->colorspace.rendering_intent);
|
||||
|
||||
# ifdef PNG_WRITE_iCCP_SUPPORTED
|
||||
else
|
||||
# endif
|
||||
# endif /* WRITE_sRGB */
|
||||
|
||||
# ifdef PNG_WRITE_iCCP_SUPPORTED
|
||||
if (!(info_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) &&
|
||||
(info_ptr->valid & PNG_INFO_iCCP))
|
||||
png_write_iCCP(png_ptr, info_ptr->iccp_name,
|
||||
info_ptr->iccp_profile);
|
||||
# endif
|
||||
#endif /* COLORSPACE */
|
||||
|
||||
#ifdef PNG_WRITE_sBIT_SUPPORTED
|
||||
if (info_ptr->valid & PNG_INFO_sBIT)
|
||||
png_write_sBIT(png_ptr, &(info_ptr->sig_bit), info_ptr->color_type);
|
||||
#endif
|
||||
#ifdef PNG_WRITE_cHRM_SUPPORTED
|
||||
if (info_ptr->valid & PNG_INFO_cHRM)
|
||||
png_write_cHRM_fixed(png_ptr,
|
||||
info_ptr->x_white, info_ptr->y_white,
|
||||
info_ptr->x_red, info_ptr->y_red,
|
||||
info_ptr->x_green, info_ptr->y_green,
|
||||
info_ptr->x_blue, info_ptr->y_blue);
|
||||
|
||||
#ifdef PNG_COLORSPACE_SUPPORTED
|
||||
# ifdef PNG_WRITE_cHRM_SUPPORTED
|
||||
if (!(info_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) &&
|
||||
(info_ptr->colorspace.flags & PNG_COLORSPACE_FROM_cHRM) &&
|
||||
(info_ptr->valid & PNG_INFO_cHRM))
|
||||
png_write_cHRM_fixed(png_ptr, &info_ptr->colorspace.end_points_xy);
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
|
||||
@ -122,7 +151,7 @@ png_write_info_before_PLTE(png_structrp png_ptr, png_inforp info_ptr)
|
||||
}
|
||||
|
||||
void PNGAPI
|
||||
png_write_info(png_structrp png_ptr, png_inforp info_ptr)
|
||||
png_write_info(png_structrp png_ptr, png_const_inforp info_ptr)
|
||||
{
|
||||
#if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
|
||||
int i;
|
||||
|
44
pngwutil.c
44
pngwutil.c
@ -1200,20 +1200,23 @@ png_write_sRGB(png_structrp png_ptr, int srgb_intent)
|
||||
#ifdef PNG_WRITE_iCCP_SUPPORTED
|
||||
/* Write an iCCP chunk */
|
||||
void /* PRIVATE */
|
||||
png_write_iCCP(png_structrp png_ptr, png_const_charp name, int compression_type,
|
||||
png_const_bytep profile, png_uint_32 profile_len)
|
||||
png_write_iCCP(png_structrp png_ptr, png_const_charp name,
|
||||
png_const_bytep profile)
|
||||
{
|
||||
png_uint_32 name_len;
|
||||
png_uint_32 profile_len;
|
||||
png_byte new_name[81]; /* 1 byte for the compression byte */
|
||||
compression_state comp;
|
||||
|
||||
png_debug(1, "in png_write_iCCP");
|
||||
|
||||
if (compression_type != PNG_COMPRESSION_TYPE_BASE)
|
||||
png_error(png_ptr, "Unknown compression type for iCCP chunk");
|
||||
|
||||
/* These are all internal problems: the profile should have been checked
|
||||
* before when it was stored.
|
||||
*/
|
||||
if (profile == NULL)
|
||||
png_error(png_ptr, "No profile for iCCP chunk");
|
||||
png_error(png_ptr, "No profile for iCCP chunk"); /* internal error */
|
||||
|
||||
profile_len = png_get_uint_32(profile);
|
||||
|
||||
if (profile_len < 132)
|
||||
png_error(png_ptr, "ICC profile too short");
|
||||
@ -1401,35 +1404,26 @@ png_write_sBIT(png_structrp png_ptr, png_const_color_8p sbit, int color_type)
|
||||
#ifdef PNG_WRITE_cHRM_SUPPORTED
|
||||
/* Write the cHRM chunk */
|
||||
void /* PRIVATE */
|
||||
png_write_cHRM_fixed(png_structrp png_ptr, png_fixed_point white_x,
|
||||
png_fixed_point white_y, png_fixed_point red_x, png_fixed_point red_y,
|
||||
png_fixed_point green_x, png_fixed_point green_y, png_fixed_point blue_x,
|
||||
png_fixed_point blue_y)
|
||||
png_write_cHRM_fixed(png_structrp png_ptr, const png_xy *xy)
|
||||
{
|
||||
png_byte buf[32];
|
||||
|
||||
png_debug(1, "in png_write_cHRM");
|
||||
|
||||
/* Each value is saved in 1/100,000ths */
|
||||
#ifdef PNG_CHECK_cHRM_SUPPORTED
|
||||
if (png_check_cHRM_fixed(png_ptr, white_x, white_y, red_x, red_y,
|
||||
green_x, green_y, blue_x, blue_y))
|
||||
#endif
|
||||
{
|
||||
png_save_uint_32(buf, (png_uint_32)white_x);
|
||||
png_save_uint_32(buf + 4, (png_uint_32)white_y);
|
||||
png_save_int_32(buf, xy->whitex);
|
||||
png_save_int_32(buf + 4, xy->whitey);
|
||||
|
||||
png_save_uint_32(buf + 8, (png_uint_32)red_x);
|
||||
png_save_uint_32(buf + 12, (png_uint_32)red_y);
|
||||
png_save_int_32(buf + 8, xy->redx);
|
||||
png_save_int_32(buf + 12, xy->redy);
|
||||
|
||||
png_save_uint_32(buf + 16, (png_uint_32)green_x);
|
||||
png_save_uint_32(buf + 20, (png_uint_32)green_y);
|
||||
png_save_int_32(buf + 16, xy->greenx);
|
||||
png_save_int_32(buf + 20, xy->greeny);
|
||||
|
||||
png_save_uint_32(buf + 24, (png_uint_32)blue_x);
|
||||
png_save_uint_32(buf + 28, (png_uint_32)blue_y);
|
||||
png_save_int_32(buf + 24, xy->bluex);
|
||||
png_save_int_32(buf + 28, xy->bluey);
|
||||
|
||||
png_write_complete_chunk(png_ptr, png_cHRM, buf, (png_size_t)32);
|
||||
}
|
||||
png_write_complete_chunk(png_ptr, png_cHRM, buf, 32);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -286,15 +286,15 @@ $1 == "option" && NF >= 2{
|
||||
# Else fall through to the error handler
|
||||
}
|
||||
|
||||
# chunk NAME [requires OPT] [on|off|disabled]
|
||||
# chunk NAME [requires OPT] [enables LIST] [on|off|disabled]
|
||||
# Expands to the 'option' settings appropriate to the reading and
|
||||
# writing of an ancilliary PNG chunk 'NAME':
|
||||
#
|
||||
# option READ_NAME requires READ_ANCILLARY_CHUNKS [READ_OPT]
|
||||
# option READ_NAME enables NAME
|
||||
# option READ_NAME enables NAME LIST
|
||||
# [option READ_NAME off]
|
||||
# option WRITE_NAME requires WRITE_ANCILLARY_CHUNKS [WRITE_OPT]
|
||||
# option WRITE_NAME enables NAME
|
||||
# option WRITE_NAME enables NAME LIST
|
||||
# [option WRITE_NAME off]
|
||||
|
||||
pre != 0 && $1 == "chunk" && NF >= 2{
|
||||
@ -303,6 +303,7 @@ pre != 0 && $1 == "chunk" && NF >= 2{
|
||||
onoff = ""
|
||||
reqread = ""
|
||||
reqwrite = ""
|
||||
enables = ""
|
||||
i = 3 # indicates format error
|
||||
if (NF > 2) {
|
||||
# read the keywords/additional OPTS
|
||||
@ -315,21 +316,25 @@ pre != 0 && $1 == "chunk" && NF >= 2{
|
||||
else
|
||||
break # on/off conflict
|
||||
}
|
||||
req = 0
|
||||
} else if ($(i) == "requires")
|
||||
req = 1
|
||||
else if (req != 1)
|
||||
break # bad line: handled below
|
||||
else {
|
||||
else if ($(i) == "enables")
|
||||
req = 2
|
||||
else if (req == 1){
|
||||
reqread = reqread " READ_" $(i)
|
||||
reqwrite = reqwrite " WRITE_" $(i)
|
||||
}
|
||||
} else if (req == 2)
|
||||
enables = enables " " $(i)
|
||||
else
|
||||
break # bad line: handled below
|
||||
}
|
||||
}
|
||||
|
||||
if (i > NF) {
|
||||
# Output new 'option' lines to the intermediate file (out)
|
||||
print "option READ_" $2, "requires READ_ANCILLARY_CHUNKS" reqread, "enables", $2, onoff >out
|
||||
print "option WRITE_" $2, "requires WRITE_ANCILLARY_CHUNKS" reqwrite, "enables", $2, onoff >out
|
||||
print "option READ_" $2, "requires READ_ANCILLARY_CHUNKS" reqread, "enables", $2 enables , onoff >out
|
||||
print "option WRITE_" $2, "requires WRITE_ANCILLARY_CHUNKS" reqwrite, "enables", $2 enables, onoff >out
|
||||
next
|
||||
}
|
||||
# Else hit the error handler below - bad line format!
|
||||
|
@ -32,8 +32,12 @@ file pnglibconf.h scripts/pnglibconf.dfa PNGLCONF_H
|
||||
# option <name> [requires ...] [if ...] [enables ...] [disabled]
|
||||
# #define PNG_<name>_SUPPORTED if the requirements are met and
|
||||
# enable the other options listed
|
||||
# chunk <name> [requires ...] [disabled]
|
||||
# Enable chunk processing for the given ancillary chunk
|
||||
# chunk <name> [requires ...] [enables ...] [disabled]
|
||||
# Enable chunk processing for the given ancillary chunk; any
|
||||
# 'requires something' expands to READ_something for read and
|
||||
# WRITE_something for write, but the enables list members are
|
||||
# used as given (e.g. enables GAMMA just expands to that on the
|
||||
# correspond READ_name and WRITE_name lines.)
|
||||
#
|
||||
# Note that the 'on' and 'off' keywords, while valid on both option
|
||||
# and chunk, should not be used in this file because they force the
|
||||
@ -461,9 +465,18 @@ option WRITE_TEXT requires WRITE_ANCILLARY_CHUNKS enables TEXT
|
||||
# API is implemented, they get recorded in pnglibconf.h, but
|
||||
# can't be changed by the application.
|
||||
|
||||
# Check the correctness of cHRM chunks
|
||||
# Colorspace support (enabled as required); just the support for colorant
|
||||
# information. Gamma support, likewise, is just support for the gamma
|
||||
# information, READ_GAMMA is required for gamma transformations (so it
|
||||
# is possible to read PNG gamma without enabling all the libpng transform
|
||||
# code - do this for applications that do their own gamma processing)
|
||||
#
|
||||
# As of 1.6.0 COLORSPACE is only useful if the application processes the
|
||||
# information; this is because the library does not do any colorspace
|
||||
# processing, it just validates the data in the PNG file.
|
||||
|
||||
option CHECK_cHRM requires cHRM
|
||||
option GAMMA disabled
|
||||
option COLORSPACE enables GAMMA disabled
|
||||
|
||||
#
|
||||
# Artificially align memory - the code typically aligns to 8 byte
|
||||
@ -560,18 +573,18 @@ setting IDAT_READ_SIZE default PNG_ZBUF_SIZE
|
||||
|
||||
# Ancillary chunks
|
||||
chunk bKGD
|
||||
chunk cHRM
|
||||
chunk gAMA
|
||||
chunk cHRM enables COLORSPACE
|
||||
chunk gAMA enables GAMMA
|
||||
chunk hIST
|
||||
chunk iCCP
|
||||
chunk iCCP enables COLORSPACE GAMMA
|
||||
chunk iTXt
|
||||
chunk oFFs
|
||||
chunk pCAL
|
||||
chunk sCAL
|
||||
chunk pHYs
|
||||
chunk sBIT
|
||||
chunk sCAL
|
||||
chunk sPLT
|
||||
chunk sRGB
|
||||
chunk sRGB enables COLORSPACE GAMMA
|
||||
chunk tEXt requires TEXT
|
||||
chunk tIME
|
||||
chunk tRNS
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
/* pnglibconf.h - library build configuration */
|
||||
|
||||
/* Libpng 1.6.0beta20 - March 19, 2012 */
|
||||
/* Libpng 1.6.0beta20 - March 21, 2012 */
|
||||
|
||||
/* Copyright (c) 1998-2012 Glenn Randers-Pehrson */
|
||||
|
||||
@ -44,9 +44,9 @@
|
||||
/*#undef PNG_BENIGN_WRITE_ERRORS_SUPPORTED*/
|
||||
#define PNG_bKGD_SUPPORTED
|
||||
#define PNG_BUILD_GRAYSCALE_PALETTE_SUPPORTED
|
||||
#define PNG_CHECK_cHRM_SUPPORTED
|
||||
#define PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED
|
||||
#define PNG_cHRM_SUPPORTED
|
||||
#define PNG_COLORSPACE_SUPPORTED
|
||||
#define PNG_CONSOLE_IO_SUPPORTED
|
||||
#define PNG_CONVERT_tIME_SUPPORTED
|
||||
#define PNG_EASY_ACCESS_SUPPORTED
|
||||
@ -58,6 +58,7 @@
|
||||
#define PNG_FORMAT_AFIRST_SUPPORTED
|
||||
#define PNG_FORMAT_BGR_SUPPORTED
|
||||
#define PNG_gAMA_SUPPORTED
|
||||
#define PNG_GAMMA_SUPPORTED
|
||||
#define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
|
||||
#define PNG_hIST_SUPPORTED
|
||||
#define PNG_iCCP_SUPPORTED
|
||||
|
Loading…
Reference in New Issue
Block a user