From: Lance Brown <lbrown@pr...> - 2010-05-20 07:18:41
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.
if (image->colorspace == CMYKColorspace)
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
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 -
if (image->matte || image->colorspace == CMYKColorspace)
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,