How to convert CMYK to RGB programmatically in indesign.

Posted by BBDeveloper on Stack Overflow See other posts from Stack Overflow or by BBDeveloper
Published on 2010-04-19T13:51:46Z Indexed on 2010/04/19 13:53 UTC
Read the original article Hit count: 387

Filed under:
|
|
|

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.

© Stack Overflow or respective owner

Related posts about indesign

Related posts about cmyk