Page 1 of 1

Colour Space Conversion

Posted: 2013-04-14T07:31:37-07:00
by Alan Hadley
Is there a direct way using the Magick Core api to convert a colour in one colour space to the equivalent in another. I do not mean an image, I want to change say the background colour that I get as an rgb triplet into the corresponding colour in an images colour space. e.g. I tried drawing a red circle on a cmyk image and it was not red so I need to convert red to red in the image space.

The only way I have thought of is to create a one pixel image and convert that, any other ideas?

I am actually using version 7 but I suspect someone has come across the same problem before.

Alan Hadley

Re: Colour Space Conversion

Posted: 2013-04-14T07:49:18-07:00
by magick
ImageMagick includes a number of pixel colorspace transforms, look for them in magick/gem.h and magick/colorspace-private.h.

Re: Colour Space Conversion

Posted: 2013-04-14T23:03:12-07:00
by Alan Hadley
Thank's but I was looking for a general method, I have used the one pixel method mentioned above and it works OK for most colour spaces, the two that fail in a major way are GREY and YCC, LMS shows a slight change. But as I know nothing about colour space things in general, just following my nose, I do not know the significance of this. I can now create blank images in almost any colour space using a colour picker dialog to set the colour. I now need to use the same method for all of the other functions that need a colour e.g. Tint, Gradient etc., but that should be simple now that I have a method.

Alan Hadley

Re: Colour Space Conversion

Posted: 2013-04-14T23:21:12-07:00
by anthony
Perhaps if you explain what you want the color for..

In Imagemagick as the background color setting? just as text output?

Re: Colour Space Conversion

Posted: 2013-04-15T04:20:06-07:00
by Alan Hadley
To pass into various functions. For if I want to draw a red circle I could use something like "fill #ff000000 circle 50,50 10,50" in the sRGB colour space it works fine but in any other the #ff000000 needs to be something else. I realize that I can't use named colours in a Draw string because there is no practical way of transforming them. My raw data is three/four/five colour components which I pass to a string processing function to build the #ff000000 so all I need is a way of changing the three components so that I they match the colourspace of the target image.

The above example is not the only one any function which takes a PixelInfo structure or an equivalent in an earlier version of IM will need the colour in the correct colour space.

Alan Hadley

Re: Colour Space Conversion

Posted: 2013-04-15T21:43:25-07:00
by anthony
It is planned to eventually have the color name convert as appropriately to match the colorspace.

As such if Draw draws in linear-RGB colorspace (which is what it should draw in to get anti-aliasing right) then a fill 'named-color' will be converted to linear-RGB for that purpose. This is why color storage now has some colorspace attached to the color.

I just don't think this step of the process has been done as yet.

The other way if have a single pixel image and convert that, then extract the color values.

I do not believe any API (except MagickCore) has access to the color conversion routines (in gem.c)