]> granicus.if.org Git - imagemagick/commitdiff
Preserve colorspace info from gAMA, cHRM, and sRGB chunks.
authorglennrp <glennrp@git.imagemagick.org>
Thu, 17 May 2012 02:33:23 +0000 (02:33 +0000)
committerglennrp <glennrp@git.imagemagick.org>
Thu, 17 May 2012 02:33:23 +0000 (02:33 +0000)
coders/png.c

index 37fd9efe10b7ebac3d2fa3a45c1a27a97119cce6..21ad20c59d9c67eca38f2932c866d5c92079c955 100644 (file)
@@ -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))