0

I fetch cmyk value for color and convert it into RGB and this RGB color is displayed in an html extension. But Color picker shows different values for RGB color due to which we get difference in color shades.i use normal java script method to convert CMYK to RGB.

Following formula that i used to convert CMYK to RGB--

CMYK to CMY

C = 1 - ( R / 255 )

M = 1 - ( G / 255 )

Y = 1 - ( B / 255 )

and then CMY TO RGB

R = ( 1 - C ) * 255

G = ( 1 - M ) * 255

B = ( 1 - Y ) * 255

Color picker shows different color as calculated from normal functions.

For eg : Color is Red.

In general

RGB : 255,0,0

CMYK : 0%,100%,100%,0%

HEXCODE : #FF0000

but in illustrator on double click of color picker it shows as

RGB : 237,28,36

CMYK : 0%,100%,100%,0%

HEXCODE : #ED1C24

So, is there any method or formula which can get the same values as calculated from the color picker .

Please Help ,thanks in advance.

please find attached image link for reference.

http://screencast.com/t/sYa1Y301Qa2

ngLover
  • 4,439
  • 3
  • 20
  • 42

4 Answers4

4

In Illustrator scripting you will find use in the app.convertSampleColor() function.

This function takes in the source and destination space names as well as an array of color values and returns an illustrator-accurate converted color array in the destination space.

Vasily Hall
  • 891
  • 10
  • 22
  • And the command `app.executeMenuCommand('doc-color-rgb')` wouldn't hurt. – Yuri Khristich Oct 04 '20 at 20:17
  • 1
    That's going to ruin someone's document. The OP asked how to display rgb values of an AI document in an extension, if you convert the user's document to a whole different color space that's something the user didn't ask for. If someone is using that extension in print and it does this and they save the document, it could mean utter disaster. – Vasily Hall Oct 04 '20 at 22:00
  • 1
    okay. Thank you for the clarification. It's actually depends on what's the purpose of the script. If you have no need to modify the given file you don't have to save it. But if you want to get an rgb document it makes sense to change its color space before the saving. The later task is a more often thing in my workflow. So I decided to share this command. – Yuri Khristich Oct 04 '20 at 22:35
1

CMYK to RGB conversion:

The R,G,B values are given in the range of 0-255.

The red (R) color is calculated from the cyan (C) and black (K) colors:

R = 255 × (1-C) × (1-K)

The green color (G) is calculated from the magenta (M) and black (K) colors:

G = 255 × (1-M) × (1-K)

The blue color (B) is calculated from the yellow (Y) and black (K) colors:

B = 255 × (1-Y) × (1-K)

Magicprog.fr
  • 4,072
  • 4
  • 26
  • 35
  • Thanks for quick reply but this formula does not match the same output as color picker gives in illustrator. – ngLover Jun 18 '15 at 11:28
1

There is no simple or a general conversion formula for RGB to CMYK. Basically, RGB is about present of optical color, while CMYK is about present of ink color. When you increase R, G and B you get brighter color, while in general CMYK acts opposite. I think these two articles can help you understand them in depth: Adobe RGB and Color space

The problem is that if you want to have exact values as softwares like illustrator or photoshop, you need to use ICC profile which is not accessible inside javascript (see this question: Is there any client-side technology able to convert sRGB to CMYK through an ICC color profile?).

However there are some mathematical conversions like just you did, or this python version, which converts the CMYK to CMY then to RGB (they are not standard ICC colors):

C = C * (1.0 - K) + K
M = M * (1.0 - K) + K
Y = Y * (1.0 - K) + K

R = 255 * (1.0 - C)
G = 255 * (1.0 - M)
B = 255 * (1.0 - Y)
Community
  • 1
  • 1
Mehdi
  • 4,202
  • 5
  • 20
  • 36
-1

PLEASE EXCUSE ME IN MY BAD ENGLISH !!

I THINK THAT I FIGURED IT OUT

THE PROBLEM IS THAT CMYK CYAN RETURNS TO LIGHT-CYAN IN RGB

AND ALSO CMYK PINK RETURNS TO REAL-BLUE IN RGB

SO I ADDED SOME VALUES :

IF CYAN > MAGENTA .. WE ADD 25% OF CYAN VALUE TO MAGENTA VALUE

ELSE IF CYAN < MAGENTA .. WE CUT 50% OF CYAN VALUE TO SHOW REAL-PINK

IT WORKED FOR ME AND HERE IS THE EXTENDSCRIPT CODE :

function CMYKTORGB1(_c, _m, _y, _k) {
    var C = _c / 100;   // THE PROBLEM THAT IT RETURNS LIGHT-CYAN IN RGB
    var M = _m / 100;
    var Y = _y / 100;
    var K = _k / 100;
    var _mc = 0;

    if (_c > 0) {
        if (_m >= _c) {
            _mc = _c / 2;
            C = (_c - _mc) / 100;   // THIS WILL FIX BLUE-PINK VALUE
        }
        else {
            _mc = _c / 4;
            M = (_m + _mc) / 100;   // THIS WILL FIX LIGHT-CYAN VALUE
        }
    }

    var R = 255 * (1 - C) * (1 - K);
    var G = 255 * (1 - M) * (1 - K);
    var B = 255 * (1 - Y) * (1 - K);

    if (R < 0) { R = 0; }
    if (G < 0) { G = 0; }
    if (B < 0) { B = 0; }

    return [R, G, B];
}

OR THIS FUNTION IT WORKING TOO :

function CMYKTORGB2(_c, _m, _y, _k) {
    var C = _c / 100;               // THE PROBLEM THAT IT RETURNS LIGHT-CYAN IN RGB
    var M = _m / 100;
    var Y = _y / 100;
    var K = _k / 100;
    var _mc = 0;

    if (_c > 0) {
        if (_m >= _c) {
            _mc = _c / 2;
            C = (_c - _mc) / 100;       // THIS WILL FIX BLUE-PINK VALUE
        }
        else {
            _mc = _c / 4;
            M = (_m + _mc) / 100;       // THIS WILL FIX LIGHT-CYAN VALUE
        }
    }

    var _C = C * (1.0 - K) + K
    var _M = M * (1.0 - K) + K
    var _Y = Y * (1.0 - K) + K

    var R = 255 * (1.0 - C)
    var G = 255 * (1.0 - M)
    var B = 255 * (1.0 - Y)

    if (R < 0) { R = 0; }
    if (G < 0) { G = 0; }
    if (B < 0) { B = 0; }

    return [R, G, B];
}