]> granicus.if.org Git - imagemagick/commitdiff
Export the correct channel (#1388).
authorDirk Lemstra <dirk@lemstra.org>
Fri, 16 Nov 2018 06:08:01 +0000 (07:08 +0100)
committerDirk Lemstra <dirk@lemstra.org>
Fri, 16 Nov 2018 06:08:24 +0000 (07:08 +0100)
coders/png.c

index b1cf32259a215198ddddb865a182b10d98a3d436..4f7e09896eb153fe359f4f88df81f39fe13b7b0c 100644 (file)
@@ -11377,9 +11377,19 @@ static MagickBooleanType WriteOnePNGImage(MngInfo *mng_info,
        ping_have_non_bw == MagickFalse)
     {
       /* Palette, Bilevel, or Opaque Monochrome */
+      QuantumType
+        quantum_type;
+
       register const Quantum
         *p;
 
+      quantum_type=RedQuantum;
+      if (mng_info->IsPalette)
+        {
+          quantum_type=GrayQuantum;
+          if (mng_info->write_png_colortype-1 == PNG_COLOR_TYPE_PALETTE)
+            quantum_type=IndexQuantum;
+        }
       SetQuantumDepth(image,quantum_info,8);
       for (pass=0; pass < num_passes; pass++)
       {
@@ -11397,27 +11407,8 @@ static MagickBooleanType WriteOnePNGImage(MngInfo *mng_info,
           if (p == (const Quantum *) NULL)
             break;
 
-          if (mng_info->IsPalette)
-            {
-              (void) ExportQuantumPixels(image,(CacheView *) NULL,
-                quantum_info,GrayQuantum,ping_pixels,exception);
-              if (mng_info->write_png_colortype-1 == PNG_COLOR_TYPE_PALETTE &&
-                  mng_info->write_png_depth &&
-                  mng_info->write_png_depth != old_bit_depth)
-                {
-                  /* Undo pixel scaling */
-                  for (i=0; i < (ssize_t) image->columns; i++)
-                     *(ping_pixels+i)=(unsigned char) (*(ping_pixels+i)
-                     >> (8-old_bit_depth));
-                }
-            }
-
-          else
-            {
-              (void) ExportQuantumPixels(image,(CacheView *) NULL,
-                quantum_info,RedQuantum,ping_pixels,exception);
-            }
-
+          (void) ExportQuantumPixels(image,(CacheView *) NULL,
+            quantum_info,quantum_type,ping_pixels,exception);
           if (mng_info->write_png_colortype-1 != PNG_COLOR_TYPE_PALETTE)
             for (i=0; i < (ssize_t) image->columns; i++)
                *(ping_pixels+i)=(unsigned char) ((*(ping_pixels+i) > 127) ?