Suppose that ImageMagic attempts to load a PNG image that has a color
palette and a tRNS chunk, such as
http://www.cultinfo.ru/cultura/2005-09/dekabr.png

It fills the palette, loads the index data, sets image->matte to
MagickFalse, and then processes the tRNS chunk. At this point, it
decides to convert the image to DirectClass, set image->matte to
MagickTrue, and fill the opacity as needed. But it only sets the
opacity of the leftmost column, leaving uninitialized junk elsewhere.
The patch below fixes it.

--- png.c
+++ png.c
@@ -2599,50 +2599,55 @@
       for (y=0; y < (long) image->rows; y++)
       {
         image->storage_class=storage_class;
         q=GetImagePixels(image,0,y,image->columns,1);
         if (q == (PixelPacket *) NULL)
           break;
         indexes=GetIndexes(image);

-        q->opacity=OpaqueOpacity;
         if (storage_class == PseudoClass)
           {
             IndexPacket
               index;

             if ((int) ping_info->color_type == PNG_COLOR_TYPE_PALETTE)
               for (x=0; x < (long) image->columns; x++)
               {
                 index=indexes[x];
                 if (index < ping_info->num_trans)
                   q->opacity=ScaleCharToQuantum((unsigned char)
                     (255-ping_info->trans[(long) index]));
+                else
+                  q->opacity=OpaqueOpacity;
                 q++;
               }
             else if (ping_info->color_type == PNG_COLOR_TYPE_GRAY)
               for (x=0; x < (long) image->columns; x++)
               {
                 index=indexes[x];
                 q->red=image->colormap[(long) index].red;
                 q->green=q->red;
                 q->blue=q->red;
                 if (q->red == transparent_color.opacity)
                   q->opacity=(Quantum) TransparentOpacity;
+                else
+                  q->opacity=OpaqueOpacity;
                 q++;
               }
           }
         else
           for (x=(long) image->columns-1; x >= 0; x--)
           {
             if (ScaleQuantumToChar(q->red) == transparent_color.red &&
                 ScaleQuantumToChar(q->green) == transparent_color.green &&
                 ScaleQuantumToChar(q->blue) == transparent_color.blue)
                q->opacity=(Quantum) TransparentOpacity;
+            else
+               q->opacity=OpaqueOpacity;
             q++;
           }
         if (SyncImagePixels(image) == MagickFalse)
           break;
       }
       image->storage_class=DirectClass;
     }
 #if (MAGICKCORE_QUANTUM_DEPTH == 8)


-- 
Alexander E. Patrakov
_______________________________________________
Magick-developers mailing list
Magick-developers@imagemagick.org
http://studio.imagemagick.org/mailman/listinfo/magick-developers

Reply via email to