PNG coder - bug in transparent background code?
Posted: 2010-02-02T07:43:34-07:00
I've just started trying out the Magick++ API. I'm trying to use something roughly like this:
Image image;
image.read("IceAlpha-0.5.png");
image.writePixels(IndexQuantum, buffer);
This particular image (which can be found here - http://www.libpng.org/pub/png/img_png/IceAlpha-0.5.png ) is an 8-bit palettized PNG with a transparent background.
The problem that I'm seeing is that I'm getting an exception thrown from ExportQuantumPixels (in quantum-export.c), due to this block of code:
case IndexQuantum:
{
if (image->storage_class != PseudoClass)
{
(void) ThrowMagickException(exception,GetMagickModule(),ImageError,
"ColormappedImageRequired","`%s'",image->filename);
return(extent);
}
The storage_class is currently set to DirectClass, which I believe is the bug. The reason it's DirectClass is because of ReadOnePNGImage (in png.c), where it handles the transparent background chunk:
if (ping_info->valid & PNG_INFO_tRNS)
{
ClassType
storage_class;
/*
Image has a transparent background.
*/
storage_class=image->storage_class;
image->matte=MagickTrue;
<snip>
image->storage_class=DirectClass;
}
I'm a n00b to ImageMagick as a whole, so there's a lot going on in this function that I don't understand, but I can't see why the storage_class would get forced to DirectClass here. I would have expected it to preserve the palettized nature of the image.
On the other hand, if it's trying to convert it to direct pixels due to compositing with the background color or something similar, then I guess the bug would be that it's preserving the image colormap that was already created prior to this point, and it needs to release the colormap, reset the number of colors and bit depth, etc.
Image image;
image.read("IceAlpha-0.5.png");
image.writePixels(IndexQuantum, buffer);
This particular image (which can be found here - http://www.libpng.org/pub/png/img_png/IceAlpha-0.5.png ) is an 8-bit palettized PNG with a transparent background.
The problem that I'm seeing is that I'm getting an exception thrown from ExportQuantumPixels (in quantum-export.c), due to this block of code:
case IndexQuantum:
{
if (image->storage_class != PseudoClass)
{
(void) ThrowMagickException(exception,GetMagickModule(),ImageError,
"ColormappedImageRequired","`%s'",image->filename);
return(extent);
}
The storage_class is currently set to DirectClass, which I believe is the bug. The reason it's DirectClass is because of ReadOnePNGImage (in png.c), where it handles the transparent background chunk:
if (ping_info->valid & PNG_INFO_tRNS)
{
ClassType
storage_class;
/*
Image has a transparent background.
*/
storage_class=image->storage_class;
image->matte=MagickTrue;
<snip>
image->storage_class=DirectClass;
}
I'm a n00b to ImageMagick as a whole, so there's a lot going on in this function that I don't understand, but I can't see why the storage_class would get forced to DirectClass here. I would have expected it to preserve the palettized nature of the image.
On the other hand, if it's trying to convert it to direct pixels due to compositing with the background color or something similar, then I guess the bug would be that it's preserving the image colormap that was already created prior to this point, and it needs to release the colormap, reset the number of colors and bit depth, etc.