[Magick-bugs] convert to windows .ico format inverts alpha channel.

Matthew Litwin mlitwin at sonic.net
Sat Jan 10 14:23:23 PST 2009


For example:
1) convert logo: -resize 32x32 -matte -channel alpha -fx "0.0" logo.png
This results in a fully transparent image.
2) convert logo.png logo.ico
This ico is fully opaque.

This is with "ImageMagick 6.4.8-4 2009-01-10 Q16 http://www.imagemagick.org 
  ", compiled from source under Mac OS X 10.5.5.

This bug is mentioned in a discussion thread at http://www.imagemagick.org/discourse-server/viewtopic.php?f=1&t=12154&start=0
which is where I found a "-channel Alpha -negate" workaround, but I  
could not find the bug in the magick-bugs archives - so here it is!

Looking at the source, the problem seems to be in  
icon.c:WriteICONImage().
ImageMagick, I think, takes 0 to be opaque, and the maximum value to  
be transparent.
For the .ico format, it's the reverse (the closest thing to  
documentation of this I could find for this was http://msdn.microsoft.com/en-us/library/ms532295(VS.85).aspx) 
.

So around line 997 where we have

           if (next->matte == MagickFalse)
              *q++=ScaleQuantumToChar(255);
            else
              *q++=ScaleQuantumToChar(p->opacity);

I think the last line should be
              *q++=ScaleQuantumToChar(255 - p->opacity);


The corresponding line (498) in icon.c:ReadICONImage() does reverse  
the value.
             q->opacity=(Quantum) QuantumRange-ScaleCharToQuantum(
                (unsigned char) ReadBlobByte(image));
and, indeed, conversion from .ico to .png works fine.


I've applied this change in a local build, and it works, though I have  
not tested extensively for negative effects.

Hope this helps,

-Matt Litwin


More information about the Magick-bugs mailing list