summaryrefslogtreecommitdiff
path: root/pngrutil.c
diff options
context:
space:
mode:
authorJohn Bowler <jbowler@acm.org>2011-05-12 21:48:29 -0500
committerGlenn Randers-Pehrson <glennrp at users.sourceforge.net>2011-05-12 21:48:29 -0500
commitcb0b29631f36c667eb353421fdf7b81e96637d2d (patch)
treef69058611d4f48f02987ea9d652e76f636d179f6 /pngrutil.c
parented4d32baa451c4e7f15f6b55d8e885083d4d85f5 (diff)
downloadlibpng-cb0b29631f36c667eb353421fdf7b81e96637d2d.tar.gz
[devel] Documented png_set_alpha_mode(), other changes in libpng.3 and
libpng-manual.txt. The cHRM chunk now sets the defaults for png_set_rgb_to_gray() (when negative parameters are supplied by the caller), while in the absence of cHRM sRGB/Rec 709 values are still used. The bKGD chunk no longer overwrites the background value set by png_set_background(), allowing the latter to be used before the file header is read. It never performed any useful function to override the default anyway. Send comments/corrections/commendations to png-mng-implement at lists.sf.net: (subscription required; visit
Diffstat (limited to 'pngrutil.c')
-rw-r--r--pngrutil.c63
1 files changed, 47 insertions, 16 deletions
diff --git a/pngrutil.c b/pngrutil.c
index d52f1007b..feab4103b 100644
--- a/pngrutil.c
+++ b/pngrutil.c
@@ -1020,6 +1020,33 @@ png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
}
#endif /* PNG_READ_sRGB_SUPPORTED */
+#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
+ /* Store the _white values as default coefficients for the rgb to gray
+ * operation if it is supported.
+ */
+ if ((png_ptr->transformations & PNG_RGB_TO_GRAY) == 0)
+ {
+ /* png_set_background has not been called, the coefficients must be in
+ * range for the following to work without overflow.
+ */
+ if (y_red <= (1<<17) && y_green <= (1<<17) && y_blue <= (1<<17))
+ {
+ /* The y values are chromaticities: Y/X+Y+Z, the weights for the gray
+ * transformation are simply the normalized Y values for red, green and
+ * blue scaled by 32768.
+ */
+ png_uint_32 w = y_red + y_green + y_blue;
+
+ png_ptr->rgb_to_gray_red_coeff = (png_uint_16)(((png_uint_32)y_red *
+ 32768)/w);
+ png_ptr->rgb_to_gray_green_coeff = (png_uint_16)(((png_uint_32)y_green
+ * 32768)/w);
+ png_ptr->rgb_to_gray_blue_coeff = (png_uint_16)(((png_uint_32)y_blue *
+ 32768)/w);
+ }
+ }
+#endif
+
png_set_cHRM_fixed(png_ptr, info_ptr, x_white, y_white, x_red, y_red,
x_green, y_green, x_blue, y_blue);
}
@@ -1544,6 +1571,7 @@ png_handle_bKGD(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
{
png_size_t truelen;
png_byte buf[6];
+ png_color_16 background;
png_debug(1, "in png_handle_bKGD");
@@ -1600,7 +1628,7 @@ png_handle_bKGD(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
*/
if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
{
- png_ptr->background.index = buf[0];
+ background.index = buf[0];
if (info_ptr && info_ptr->num_palette)
{
@@ -1610,33 +1638,36 @@ png_handle_bKGD(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
return;
}
- png_ptr->background.red =
- (png_uint_16)png_ptr->palette[buf[0]].red;
+ background.red = (png_uint_16)png_ptr->palette[buf[0]].red;
+ background.green = (png_uint_16)png_ptr->palette[buf[0]].green;
+ background.blue = (png_uint_16)png_ptr->palette[buf[0]].blue;
+ }
- png_ptr->background.green =
- (png_uint_16)png_ptr->palette[buf[0]].green;
+ else
+ background.red = background.green = background.blue = 0;
- png_ptr->background.blue =
- (png_uint_16)png_ptr->palette[buf[0]].blue;
- }
+ background.gray = 0;
}
else if (!(png_ptr->color_type & PNG_COLOR_MASK_COLOR)) /* GRAY */
{
- png_ptr->background.red =
- png_ptr->background.green =
- png_ptr->background.blue =
- png_ptr->background.gray = png_get_uint_16(buf);
+ background.index = 0;
+ background.red =
+ background.green =
+ background.blue =
+ background.gray = png_get_uint_16(buf);
}
else
{
- png_ptr->background.red = png_get_uint_16(buf);
- png_ptr->background.green = png_get_uint_16(buf + 2);
- png_ptr->background.blue = png_get_uint_16(buf + 4);
+ background.index = 0;
+ background.red = png_get_uint_16(buf);
+ background.green = png_get_uint_16(buf + 2);
+ background.blue = png_get_uint_16(buf + 4);
+ background.gray = 0;
}
- png_set_bKGD(png_ptr, info_ptr, &(png_ptr->background));
+ png_set_bKGD(png_ptr, info_ptr, &background);
}
#endif