From: Glenn Randers-Pehrson Date: Sun, 30 Jul 2017 01:06:12 +0000 (-0400) Subject: Properly set image->colorspace in the PNG decoder X-Git-Tag: 7.0.6-5~22 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7300120255e69b4b850e7ddd6c1fa154c05103cd;p=imagemagick Properly set image->colorspace in the PNG decoder --- diff --git a/ChangeLog b/ChangeLog index 45ce2f6fc..b4d1adcb7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2017-07-29 7.0.6-5 Glenn Randers-Pehrson + * Properly set image->colorspace in the PNG decoder (previously + it was setting image->gamma, but only setting image->colorspace + for grayscale and gray-alpha images. Reference + https://www.imagemagick.org/discourse-server/viewtopic.php?f=3&t=32418). + 2017-07-29 7.0.6-5 Cristy * Off by one error for gradient coder (reference https://www.imagemagick.org/discourse-server/viewtopic.php?f=3&t=32416). diff --git a/coders/png.c b/coders/png.c index e3b8f7052..595c4c3dd 100644 --- a/coders/png.c +++ b/coders/png.c @@ -3154,6 +3154,36 @@ static Image *ReadOnePNGImage(MngInfo *mng_info, image->gamma = image_gamma; } + else + { + double + image_gamma = image->gamma; + + (void)LogMagickEvent(CoderEvent,GetMagickModule(), + " image->gamma=%f",(float) image_gamma); + + if (image_gamma > 0.75) + { + /* Set image->rendering_intent to Undefined, + * image->colorspace to GRAY, and reset image->chromaticity. + */ + image->intensity = Rec709LuminancePixelIntensityMethod; + SetImageColorspace(image,RGBColorspace,exception); + } + else + { + RenderingIntent + save_rendering_intent = image->rendering_intent; + ChromaticityInfo + save_chromaticity = image->chromaticity; + + SetImageColorspace(image,sRGBColorspace,exception); + image->rendering_intent = save_rendering_intent; + image->chromaticity = save_chromaticity; + } + + image->gamma = image_gamma; + } (void)LogMagickEvent(CoderEvent,GetMagickModule(), " image->colorspace=%d",(int) image->colorspace); @@ -4250,8 +4280,16 @@ static Image *ReadPNGImage(const ImageInfo *image_info, image->chromaticity.white_point.y>0.3289f && image->chromaticity.white_point.y<0.3291f)) { + (void) LogMagickEvent(CoderEvent,GetMagickModule(), + "SetImageColorspace to RGBColorspace"); SetImageColorspace(image,RGBColorspace,exception); } + else + { + (void) LogMagickEvent(CoderEvent,GetMagickModule(), + "NOT SetImageColorspace to RGBColorspace, image->gamma=%g", + image->gamma); + } if (logging != MagickFalse) {