views:

406

answers:

2

Hi,

I have a CMYK colorspace in indesign, i want to convert that as RGB color space, I got some codes, but I am getting incorrect data.

Some of the codes which I tried are given below

    double cyan = 35.0;
    double magenta = 29.0;
    double yellow = 0.0;
    double black = 16.0;

    cyan = Math.min(255, cyan + black); //black is from K
    magenta = Math.min(255, magenta + black);
    yellow = Math.min(255, yellow + black);
    l_res[0] = 255 - cyan;
    l_res[1] = 255 - magenta;
    l_res[2] = 255 - yellow;

@Override
public float[] toRGB(float[] p_colorvalue) {
    float[] l_res = {0,0,0};
    if (p_colorvalue.length >= 4)
    {
        float l_black = (float)1.0 - p_colorvalue[3];
        l_res[0] = l_black * ((float)1.0 - p_colorvalue[0]);
        l_res[1] = l_black * ((float)1.0 - p_colorvalue[1]);
        l_res[2] = l_black * ((float)1.0 - p_colorvalue[2]);
    }
    return (l_res);
}

The values are C=35, M = 29, Y = 0, K = 16 in CMYK color space and the correct RGB values are R = 142, G = 148, B = 186.

In adobe indesign, using swatches we can change the mode to CMYK or to RGB.

But I want to do that programmatically, Can I get any algorithm to convert CMYK to RGB which will give the correct RGB values.

And one more question, if the alpha value for RGB is 1 then what will be the alpha value for CMYK?

Can anyone help me to solve these issues... Thanks in advance.

+2  A: 

To answer your last question:

If the alpha is 1 in RGB colour space it will be 1 in CMYK colour space to. Both spaces are just specifying the colours, not the transparency.

On your CMYK to RGB conversion problem, you should note that

There is no exact conversion between the CMYK and RGB models - both color spaces cover different color gamuts

Source

There's also a discussion on this Wikipedia page

ChrisF
Thanks for your reply. The values are C=35, M = 29, Y = 0, K = 16 in CMYK colorspace and corresponding correct RGB values are R = 142, G = 148, B = 186.When I used the above given RGB color with alpha as 1 in iphone then I am getting the exact color, but if I use CMYK with alpha as 1 then I am not getting the same color there is some difference between these two colors. Thats y i specifically asked about alpha.
SWDeveloper
A: 

Color is subjective.

When converting CMYK to RGB there are direct conversion formulas, as you have found out and seem to have code for. They are, however, too precise.

When converting from CMYK to RGB you need to use a color profile which describes the device and substrate the CMYK inks would be laid down on.

Therefore:

  1. You have image.tif which is a CMYK image.
  2. You need to apply an ICC profile describing the intended output device for that image. (i.e. USWebCoatedSWOP.icc for an image to be created on a flexographic printing press using a coated substrate.)

Following these steps will get you the proper colored image and "correct" RGB values.

So, applying that knowledge to your situation, you would need to programmatically apply an ICC profile.

If you insist on doing the math yourself, (I recommend you avoid this!!!) you can read all about it on the ICC website or code something yourself using LittleCMS.

I don't believe that a COM based programming interface is exposed through InDesign. However, Photoshop, Illustrator and Acrobat all expose some COM based APIs.

I don't know if this is possible using Adobe's exposed API calls, however, I can say that it is possible to do this programmatically through CorelDRAW.

Edit: Apparently, InDesign does have automation capability, however, I could not find any functionality to apply color profiles programmatically. See section (1.5.9. Color).