Possible bug when writing CMYK raw data to buffer
Lance Brown <[email protected]> Thu, 20 May 2010 07:05:55 +0000
| Newsgroups | gmane.comp.video.graphicsmagick.bugs |
|---|---|
| Message-ID | <[email protected]> |
Hi all,
I am using the full release source version 1.3.12. I am using the Magick++ API
I have been trying to write raw CMYK pixel data from an Image to a memory buffer. I used the following command -
image.write(0, 0, width, height, "CMYK", CharPixel, allPixels);
i.e. write all the char sized pixel data in image (colorspace == CMYKColorspace) to the buffer "allPixels"
However when I inspected the K channel of the buffer every element was set to 0. The CMY values were fine BUT not the K.
When I stepped through the Image.write() function I found in the file "GraphicsMagick-1.3.12\magick\constitute.c" function DispatchImage() on line 2176 the K part of the "CMYK" DispatchType map was being set to OpacityMapQuantum.
case 'K':
{
switch_map[i]=OpacityMapQuantum;
if (image->colorspace == CMYKColorspace)
break;
ThrowException(exception,OptionError,ColorSeparatedImageRequired,map);
return(MagickFail);
}
This is fine as OpacityMapQuantum is the fourth part of the PixelPacket, i.e. where we expect to find K. However later in the same function when the Black element of the pixel is actually being copied (line 2260) I find
case OpacityMapQuantum:
{
if (image->matte)
quantum=GetOpacitySample(p);
break;
}
So unless my image also happens to have matte set the Black pixel element will NOT be copied to quantum and quantum will stay as its initialised value of 0. If we are going to continue to shortcut and have the K channel use OpacityMapQuantum could this simply be fixed with something simple like -
case OpacityMapQuantum:
{
if (image->matte || image->colorspace == CMYKColorspace)
quantum=GetOpacitySample(p);
break;
}
For now I have a workaround of setting my image matte to true before writing the data to the buffer. This fixes my problem.
Hope this helps,
Lance Brown
Software Engineer
Precision Mechatronics
------------------------------------------------------------------------------