Missing black channel using Magick++, C++
Posted: 2009-10-16T13:26:52-07:00
I working with a program that has images in its own internal format. I needed to use some of ImageMagick's processing power so I created an image with Magick++ and I find that Black channel is always empty. Here's my code:
When I run it, I find that a proper tif is created in /tmp/test.png as expected, but the output text file is incorrect. Here's what I get:
The output should show C, M, Y and K (black) channels but the black channel is always 0. Notice how the image is inverted. This makes sense since CMYK is a subtractive image space. Is that my error? Should I be inverting the image back? I'm not sure I'm going to lose date. In the printing world, C=100%, M=100%, Y=100%, K=0% is different color than C=M=Y=K=100%. That distinction seems to be lost here. The 1st line is a "super black" and the 6th line is just a plain old black, yet the PixelPacket has converted them to the exact same color.
I appreciate any advice. Thank you. (Oh, I'm running ImageMagick-6.5.6-5 under Mac OS X 10.5.7 if that matters)
John
Code: Select all
#include <iostream>
#include <Magick++.h>
unsigned char imageData[] = {
0xff, 0xff, 0xff, 0xff, // super black
0x00, 0x00, 0x00, 0x00, // white
0xff, 0x00, 0x00, 0x00, // cyan
0x00, 0xff, 0x00, 0x00, // magenta
0x00, 0x00, 0xff, 0x00, // yellow
0x00, 0x00, 0x00, 0xff, // black
0x00, 0xff, 0xff, 0x00, // red
0xff, 0x00, 0xff, 0x00, // green
0xff, 0xff, 0x00, 0x00, // blue
0x00, 0x00, 0x00, 0x00, // white
0xff, 0xff, 0xff, 0xff // super black
};
#define IMAGE_WIDTH 11
#define IMAGE_HEIGHT 1
unsigned char outputImage[IMAGE_WIDTH * IMAGE_HEIGHT * 4];
int main (int argc, char * const argv[]) {
std::cout << "Hello, World!\n";
Magick::Image image( IMAGE_WIDTH, IMAGE_HEIGHT, "CMYK", Magick::CharPixel, imageData );
//image.type(Magick::TrueColorType);
image.write("/tmp/test.png");
image.modifyImage();
//image.blur(30, 10);
image.syncPixels();
Magick::Pixels view(image);
Magick::PixelPacket *pixels = view.get(0,0,IMAGE_WIDTH,IMAGE_HEIGHT);
FILE *f = fopen("/tmp/test.txt", "w");
for ( int row = 0; row < IMAGE_HEIGHT ; ++row )
for ( int column = 0; column < IMAGE_WIDTH ; ++column ) {
fprintf(f, "%8d\t%8d\t%8d\t%8d\n",
pixels->red, pixels->green, pixels->blue, pixels->opacity);
pixels++;
}
fprintf(f, "\n");
fclose(f);
return 0;
}
Code: Select all
0 0 0 0
65535 65535 65535 0
0 65535 65535 0
65535 0 65535 0
65535 65535 0 0
0 0 0 0
65535 0 0 0
0 65535 0 0
0 0 65535 0
65535 65535 65535 0
0 0 0 0
I appreciate any advice. Thank you. (Oh, I'm running ImageMagick-6.5.6-5 under Mac OS X 10.5.7 if that matters)
John