From: glennrp Date: Thu, 17 May 2012 02:33:23 +0000 (+0000) Subject: Preserve colorspace info from gAMA, cHRM, and sRGB chunks. X-Git-Tag: 7.0.1-0~5584 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8d0bca5eb90971dbd2100bb5d7a8de9e39f76595;p=imagemagick Preserve colorspace info from gAMA, cHRM, and sRGB chunks. --- diff --git a/coders/png.c b/coders/png.c index 37fd9efe1..21ad20c59 100644 --- a/coders/png.c +++ b/coders/png.c @@ -2723,13 +2723,25 @@ static Image *ReadOnePNGImage(MngInfo *mng_info, image->columns=ping_width; image->rows=ping_height; - /* Note that the following sets image->gamma to 1.0, image->rendering_intent - to Undefined, and resets image->chromaticity, overriding any ancillary - chunk data from the PNG file. - */ if (((int) ping_color_type == PNG_COLOR_TYPE_GRAY) || ((int) ping_color_type == PNG_COLOR_TYPE_GRAY_ALPHA)) - SetImageColorspace(image,GRAYColorspace,exception); + { + if (!png_get_valid(ping,ping_info,PNG_INFO_gAMA) && + !png_get_valid(ping,ping_info,PNG_INFO_cHRM) && + !png_get_valid(ping,ping_info,PNG_INFO_sRGB)) + { + /* Set image->gamma to 1.0, image->rendering_intent to Undefined, + * and reset image->chromaticity. + */ + SetImageColorspace(image,GRAYColorspace,exception); + } + + else + { + /* Use colorspace data from PNG ancillary chunks */ + image->colorspace=GRAYColorspace; + } + } if (((int) ping_color_type == PNG_COLOR_TYPE_PALETTE) || ((int) ping_color_type == PNG_COLOR_TYPE_GRAY))