From ccc36af759d30fb50b1deda241d038402a393b17 Mon Sep 17 00:00:00 2001 From: glennrp Date: Mon, 8 Sep 2014 23:22:03 +0000 Subject: [PATCH] Fix incorrect decoding of 16-bit GrayAlpha PNG files that have a gAMA chunk. The red channel contained the gray levels but green and blue channels were zero or perhaps undefined. --- coders/png.c | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/coders/png.c b/coders/png.c index 7a6485107..808e90c3c 100644 --- a/coders/png.c +++ b/coders/png.c @@ -3100,8 +3100,20 @@ static Image *ReadOnePNGImage(MngInfo *mng_info, */ image->intensity = Rec709LuminancePixelIntensityMethod; SetImageColorspace(image,GRAYColorspace,exception); - image->gamma = image_gamma; } + else + { + RenderingIntent + save_rendering_intent = image->rendering_intent; + ChromaticityInfo + save_chromaticity = image->chromaticity; + + SetImageColorspace(image,GRAYColorspace,exception); + image->rendering_intent = save_rendering_intent; + image->chromaticity = save_chromaticity; + } + + image->gamma = image_gamma; } (void)LogMagickEvent(CoderEvent,GetMagickModule(), @@ -3305,7 +3317,8 @@ static Image *ReadOnePNGImage(MngInfo *mng_info, /* Convert image to DirectClass pixel packets. */ - image->alpha_trait=(((int) ping_color_type == PNG_COLOR_TYPE_RGB_ALPHA) || + image->alpha_trait= + (((int) ping_color_type == PNG_COLOR_TYPE_RGB_ALPHA) || ((int) ping_color_type == PNG_COLOR_TYPE_GRAY_ALPHA) || (png_get_valid(ping,ping_info,PNG_INFO_tRNS))) ? BlendPixelTrait : UndefinedPixelTrait; @@ -3619,6 +3632,12 @@ static Image *ReadOnePNGImage(MngInfo *mng_info, png_read_end(ping,end_info); + if (logging != MagickFalse) + { + (void) LogMagickEvent(CoderEvent,GetMagickModule(), + " image->storage_class=%d\n",(int) image->storage_class); + } + if (image_info->number_scenes != 0 && mng_info->scenes_found-1 < (ssize_t) image_info->first_scene && image->delay != 0) { @@ -4164,13 +4183,19 @@ static Image *ReadPNGImage(const ImageInfo *image_info,ExceptionInfo *exception) image->chromaticity.white_point.x<0.3128f && image->chromaticity.white_point.y>0.3289f && image->chromaticity.white_point.y<0.3291f)) - SetImageColorspace(image,RGBColorspace,exception); + { + SetImageColorspace(image,RGBColorspace,exception); + } if (logging != MagickFalse) - (void) LogMagickEvent(CoderEvent,GetMagickModule(), - " page.w: %.20g, page.h: %.20g,page.x: %.20g, page.y: %.20g.", - (double) image->page.width,(double) image->page.height, - (double) image->page.x,(double) image->page.y); + { + (void) LogMagickEvent(CoderEvent,GetMagickModule(), + " page.w: %.20g, page.h: %.20g,page.x: %.20g, page.y: %.20g.", + (double) image->page.width,(double) image->page.height, + (double) image->page.x,(double) image->page.y); + (void) LogMagickEvent(CoderEvent,GetMagickModule(), + " image->colorspace: %d", (int) image->colorspace); + } if (logging != MagickFalse) (void) LogMagickEvent(CoderEvent,GetMagickModule(),"exit ReadPNGImage()"); -- 2.40.0