]> granicus.if.org Git - imagemagick/commitdiff
Fix colortype selection for PNG grayscale output.
authorglennrp <glennrp@git.imagemagick.org>
Sun, 2 Jan 2011 03:07:57 +0000 (03:07 +0000)
committerglennrp <glennrp@git.imagemagick.org>
Sun, 2 Jan 2011 03:07:57 +0000 (03:07 +0000)
ChangeLog
coders/png.c

index a6277f4df8e213aa16fcaf9d7c6090ab7da85439..1e258eb1d43292bca879362f6741ec39310c7666 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,8 @@
   * The PNG decoder now checks whether the image actually has any transparency
     when the input file contains an alpha channel.  (Reference
     http://www.imagemagick.org/discourse-server/viewtopic.php?f=3&t=17748)
+  * Recently changes sometimes caused the PNG encoder to select colortype=2
+    (Truecolor) instead of 0 (Grayscale) for grayscale images.
 
 2010-12-26  6.6.6-8 Cristy  <quetzlzacatenango@image...>
   * -posterize fails with more than 40 levels (reference
index 50f32870d5c69ee0581c9c6731cd1ad513e5f2f0..13c4df883d5b9aada98337465ed8845fca24a514 100644 (file)
@@ -2489,7 +2489,9 @@ static Image *ReadOnePNGImage(MngInfo *mng_info,
               /* Is there a transparent pixel in the row? */
               for (x=(ssize_t) image->columns-1; x >= 0; x--)
               {
-                if (q->opacity != OpaqueOpacity)
+                if ((ping_color_type == PNG_COLOR_TYPE_RGBA ||
+                    ping_color_type == PNG_COLOR_TYPE_GRAY_ALPHA) &&
+                   (q->opacity != OpaqueOpacity))
                   {
                     found_transparent_pixel = MagickTrue;
                     break;
@@ -2765,8 +2767,11 @@ static Image *ReadOnePNGImage(MngInfo *mng_info,
           (void) LogMagickEvent(CoderEvent,GetMagickModule(),
             "    Found transparent pixel");
         else
-          (void) LogMagickEvent(CoderEvent,GetMagickModule(),
-            "    No transparent pixel was found");
+          {
+            (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+              "    No transparent pixel was found");
+            ping_color_type&=0x03;
+          }
       }
     }
 
@@ -7623,28 +7628,43 @@ static MagickBooleanType WriteOnePNGImage(MngInfo *mng_info,
               image_matte=MagickTrue;
             }
 
+          if (image_info->type == PaletteType ||
+              image_info->type == PaletteMatteType)
+            ping_color_type=(png_byte) PNG_COLOR_TYPE_PALETTE;
+
           if (image_info->type == UndefinedType ||
              image_info->type == OptimizeType)
             {
-
-              if ((image_info->type == GrayscaleType) &&
-                 image_matte == MagickFalse && ping_have_color != MagickFalse)
+              if (ping_have_color == MagickFalse)
                 {
-                  ping_color_type=(png_byte) PNG_COLOR_TYPE_GRAY;
-                  image_matte=MagickFalse;
-                }
+                  if (image_matte == MagickFalse)
+                    {
+                      ping_color_type=(png_byte) PNG_COLOR_TYPE_GRAY;
+                      image_matte=MagickFalse;
+                    }
 
-              else if ((image_info->type == GrayscaleMatteType) &&
-                  image_matte == MagickTrue && ping_have_color != MagickFalse)
-                {
-                  ping_color_type=(png_byte) PNG_COLOR_TYPE_GRAY_ALPHA;
-                  image_matte=MagickTrue;
+                  else 
+                    {
+                      ping_color_type=(png_byte) PNG_COLOR_TYPE_GRAY_ALPHA;
+                      image_matte=MagickTrue;
+                    }
                 }
+              else
+                {
+                  if (image_matte == MagickFalse)
+                    {
+                      ping_color_type=(png_byte) PNG_COLOR_TYPE_RGB;
+                      image_matte=MagickFalse;
+                    }
 
-              else if (image_info->type == PaletteType ||
-                  image_info->type == PaletteMatteType)
-                ping_color_type=(png_byte) PNG_COLOR_TYPE_PALETTE;
+                  else 
+                    {
+                      ping_color_type=(png_byte) PNG_COLOR_TYPE_RGBA;
+                      image_matte=MagickTrue;
+                    }
+                 }
             }
+
         }
 
       if (logging != MagickFalse)