PixelSetColor problem with CMYK images

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
sithney

PixelSetColor problem with CMYK images

Post by sithney »

Hello,

I have a problem where PixelSetColor seems to set the wrong color when using CMYK images.
When using RGB values as rgb(r,g,b) the colors seem to either be CMYK values, or not work at all.
In the sample program shown, rgb(255,0,0) produces Cyan text.
Any help with this would be appreciated.

Here is my sample code:

#include "wand/MagickWand.h"
int main() {
char *file = "cmyk.jpg"; /* this must be a CMYK file */
char *output_file = "out.pdf";
MagickWand *image = NewMagickWand();
DrawingWand *draw = NewDrawingWand();
PixelWand *pixel = NewPixelWand();

MagickReadImage(image, file);
PixelSetColor(pixel, "rgb(255,0,0)");
DrawSetFillColor(draw, pixel);
DrawAnnotation(draw, 100, 100, "hello");
MagickDrawImage(image, draw);
MagickWriteImage(image, output_file);
return 0;
}
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: PixelSetColor problem with CMYK images

Post by magick »

Most ImageMagick algorithms have direct support for CMYK and CMYKA, however, the drawing engine is based on the SVG specification which does not include support for CMYK. Therefore, for drawing you must first convert your image to RGB, draw on it, and then convert from RGB back to CMYK.
rohitkrishna
Posts: 43
Joined: 2011-10-01T14:34:04-07:00
Authentication code: 8675308

Re: PixelSetColor problem with CMYK images

Post by rohitkrishna »

Maay be you can use cmyk(100,100,100,10) instead of r,g,b(0,0,255)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: PixelSetColor problem with CMYK images

Post by fmw42 »

rohitkrishna wrote:Maay be you can use cmyk(100,100,100,10) instead of r,g,b(0,0,255)

The limitation is with the image colorspace and not the color value. So I don't think that will help as -draw only works with images in RGB colorspace. So IM will either convert your cmyk color value to its rgb equivalent or -draw will object to the cmyk value supplied or use it as an rgba value. However, I will defer to the IM developers if I am wrong.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: PixelSetColor problem with CMYK images

Post by anthony »

Draw currently just assumes the color and image colorspace is RGB.

Actually it is worse than that as draw it seems to assume linear RGB, while colors are given as sRGB colors. See
http://www.imagemagick.org/Usage/draw/#colorspace

These are all aspects that will be fixed in the early version numbers of IMv7 (still in alpha while I work on the CLI interface)
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply