Skip to main content
Silly-V
Legend
January 23, 2018
Answered

Convert Sample Color

  • January 23, 2018
  • 5 replies
  • 3081 views

Howdy! I'm mostly versed in AI scripting where there's a handy app.convertSampleColor function which takes in an array of color values and the source & destination spaces to return a new array of converted color values in the new space.

Is there no such function in ID? It would appear that you'd have to have a document open in order to perform a color conversion and read the new swatch color information, whereas with the AI function I do not believe a document needs to be open.

This topic has been closed for replies.
Correct answer Laubender

Hi,

depending on your version of InDesign you could use perhaps:

app.colorTransform()

document.colorTransform()

https://www.indesignjs.de/extendscriptAPI/indesign13/#Document.html#d1e49256__d1e52607

I did not do much with it, because providing numbers to the function is a bit strange.

What also can be done:
Add a new named color to the app or the document. Provide colorValue, model, name and space.

Then assign a new space. The color should be converted to the new space.

var doc = app.documents[0];

var newColor = doc.colors.itemByName("newColor");

if(newColor.isValid){ newColor.remove() };

if(!newColor.isValid)

{

    doc.colors.add

    (

        {

                name : "newColor" ,

                colorValue : [0,0,0,100] ,

                space : ColorSpace.CMYK

        }

    )

};

// Assign new space and color will be converted:

newColor.space = ColorSpace.RGB;

alert( newColor.colorValue );

Test for correct conversions of various color management settings.

This should do it…

Instead of document you could also add colors to the application as well with app.colors.add() instead of app.documents[0].colors.add().

Named colors will be added to the Swatches panel.

Regards,
Uwe

5 replies

Community Expert
October 30, 2019

Hi Rob,

I can confirm what you see. And yes, I did the conversion back to CMYK on a duplicate of the color I converted from LAB to CMYK. Hm. I suspect that somehow InDesign remembers the initial LAB values of a converted color.

 

To test this I added a new color with same CMYK values from scratch using scripting.

Had two rectangles selected. One ( app.selection[0] ) with the converted fill color from LAB 100 | 127 | 0 to CMYK and another one ( app.selection[1] ) that has no fill color at all.

 

Now I cloned the properties of fill color of selection[0] to a new color and applied this to app.selection[1]:

 

 

var fillColor = app.selection[0].fillColor;
var newColor = app.documents[0].colors.add
(
	{ 
		name : "ClonedCMYKColor" ,
		colorValue : fillColor.colorValue ,
		model : fillColor.model ,
		space : fillColor.space
	}
);

app.selection[1].fillColor = newColor;

 

 

The result was this, optically the same, by numbers of colorValue the same:

 

After that I converted both colors to LAB using the GUI.

Both colors now are with the same values:

64.7699966430664,50.7003974914551,-3.05839991569519

 

Astonishing! I started out with LAB 100,127,0 and before I could see a roundtrip between LAB > CMYK > LAB with the same values for the fill color of app.selection[0]. At least I thought so…

 

Another test, this time with a duplicated color of LAB 100,127,0: Converted to CMYK in the GUI without applying the color to an object. After that I converted the color back to LAB with the following wrong result: 33,127,0. Why? I have no idea! Something is very, very odd here.

 

Hm. The differences could be:

In the process of testing I switched on Overprint Preview and finally Separation View.

And this time with the wrong result 33,127,0 I did not apply that color to an object on the page. All guesswork of course!

 

Now after typing all this I did one Undo and tried to repeat that wrong result with 33,127,0; alas now the conversion from CMYK to LAB yields again 100,127,0. I'm really confused what's going on here. It's a mess!

 

All tests done with color management set to:

ISO Coated v2 300% (ECI) with Relative Colorimetric conversion, module: Adobe (ACE).

InDesign CC 2019 version 14.0.3 on Windows 10.

 

Will repeat my tests and report again when:

1. Separation View and Overprint Preview is turned off.

2. Separation View turned on, Overprint Preview turned off.

3. Separation View turned off, Overprint Preview turned on.

 

And: Document saved vs document never saved.

 

Regards,
Uwe Laubender

( ACP )

rob day
Community Expert
Community Expert
October 30, 2019

Astonishing! I started out with LAB 100,127,0 and before I could see a roundtrip between LAB > CMYK > LAB with the same values for the fill color of app.selection[0]. At least I thought so…

 

Yes, InDesign’s UI has always "remembered" the starting value—I think it is a bug, others might think it’s a feature. Same thing happens with RGB>CMYK>RGB or CMYK>RGB>CMYK conversions. In the case of CMYK>RGB>CMYK, the problem is more obvious. A built CMYK color like 10|0|0|50 could never convert to RGB and back via color management and keep the original built values.

 

If you use Photoshop’s Convert to Profile you can see what the color managed numbers should be. Even colors inside of the gamut might not make the round trip with no change, a lot depends on the color intent used and the relative position of the color in the space.

 

In ID, if you make a very slight change to the converted value, the conversion back to Lab will be correct (new values with out-of-gamut colors). You can see that in the Color picker:

 

Enter the Lab values

 

 

Make a minimal edit to one of the CMYK values. Here I'm simply adding .0 to the 64% Magenta value:

 

 

Moving the cursor to the Y field repositions the plot in the space view, and the Lab values are now what they should be for the 0|64|5|0 CMYK value:

 

 

 

Community Expert
October 30, 2019

Hi Saurabh,

when with InDesign and you are staying with the same document and do not change the color settings of the document you could start with any LAB value, convert that to CMYK and later that CMYK value can be converted back to the same LAB value.

 

My example below is with process colors:

 

What's also possible:

Start with a CMYK value of 0,0,0,50.

 

Step 1: Convert* that to LAB: 64.4769973754883,-0.66929996013641,-0.59920001029968

Step 2: Convert* the LAB to CMYK: 37.6399993896484,28.1699985265732,28.5400003194809,15.3599992394447

Step 3: Convert* the CMYK to LAB: 64.4769973754883,-0.66929996013641,-0.59920001029968

 

*My numbers are following the color management settings of the document:
ISO Coated v2 300% (ECI) with Relative Colorimetric conversion, module: Adobe (ACE).

Your numbers with step 1 to step 3 could be different.

 

So you see: Two different CMYK values can yield the same LAB values:

 

 

IMPORTANT EDIT:

The shown results in this post for the roundtrip part, step 2 and step 3, could be due to some bugs with InDesign!

See the posts below. Especially the next one by Rob Day. This matter is rather confusing and should be further investigated.

 

Regards,
Uwe Laubender

( ACP )

rob day
Community Expert
Community Expert
October 30, 2019

and do not change the color settings of the document you could start with any LAB value, convert that to CMYK and later that CMYK value can be converted back to the same LAB value.

 

Hi Uwe, InDesign has what seems to be a bug with roundtrip conversions via the UI. An out-of-gamut starting Lab value converted to CMYK and then back to Lab would have to have new Lab values, but if I do that via the UI I get the original Lab values, which can't be right.

 

For example the very out-of-gamut 100|127|0 Lab value converted to Coated GRACol CMYK gives me 0|60|0|0. That CMYK value back to Lab would have to be significantly different because of the gamut clipping, and it is if I make the conversions via scripting in ID. With a script I get 68|46|-5 on the return trip to Lab, which is what I also get doing the conversions in Photoshop with Convert to Profile.

Community Expert
October 29, 2019

Hi Rob,

no, you are not missing anything.

One could assign a different color space or one could use colorTransform().

Assigning the wanted color space is easier.

 

To saurabhm66674513:

Are we talking Illustrator or InDesign here?

 

Note: We are in the InDesign forum here.

Adobe Illustrator is over there:

https://community.adobe.com/t5/Illustrator/bd-p/illustrator

 

Regards,
Uwe Laubender

( ACP )

Participant
October 30, 2019

Hi Laubender, 

I am working on illustrator as of now but gradually needs solution for In-design too.. 

But yeah...this thread prooved to be great help for me. 

Special thanks to @rob_day  for his concept on Gamut and screen shot to provide a clear cut answer. 

thanks again @Laubender . 

Will really be in touch with your pages .

 

 

 

 

Community Expert
October 29, 2019

saurabhm66674513 said on Oct 28, 2019:

Have you found solution to trasform from CMYK to LAB ??  I am kind of new to adobe scripting... and will be happy to get your answer

 

Hi saurabhm66674513,

did you look into my sample codes?

 

Can you provide a sample you'd like to convert?

The result will always depend on the color management settings of the document.

 

Regards,
Uwe Laubender

( ACP )

 

**Please use the Reply button from the Top post on any page. It ensures posts are in date/time order.**

Participant
October 29, 2019

thanks ... for your prompt reply Laubender, 

I am trying to acheive this in Illustrator ... 

Lets say I have a LAB spot Color of Values 

  mySPOTlab=[89.99916927472105, -56.74431793281322, 12.61283695195025]  in my Swatch pannel.

I used this color LAB values on my document.

While extracting color from the document. I get CMYK value for this( since document i created is in CMYK mode). 

say myCMYK=[44.99916927472105, 43.74431793281322, 100,4.2879];

and now for my validation if I convert this CMYK back to LAB , I am not getting the same values . 

var result =app.convertSampleColor(ImageColorSpace.CMYK, mySPOTlab, ImageColorSpace.LAB, ColorConvertPurpose.defaultpurpose);
Idealy  mySPOTlab==result. 
but it is not so... 
 

 

rob day
Community Expert
Community Expert
October 29, 2019

mySPOTlab=[89.99916927472105, -56.74431793281322, 12.61283695195025]...

and now for my validation if I convert this CMYK back to LAB , I am not getting the same values .

 

Your starting spot Lab value is far out-of-gamut to any real world CMYK space, so the conversion back to Lab from CMYK could never match.

 

LaubenderCommunity ExpertCorrect answer
Community Expert
January 23, 2018

Hi,

depending on your version of InDesign you could use perhaps:

app.colorTransform()

document.colorTransform()

https://www.indesignjs.de/extendscriptAPI/indesign13/#Document.html#d1e49256__d1e52607

I did not do much with it, because providing numbers to the function is a bit strange.

What also can be done:
Add a new named color to the app or the document. Provide colorValue, model, name and space.

Then assign a new space. The color should be converted to the new space.

var doc = app.documents[0];

var newColor = doc.colors.itemByName("newColor");

if(newColor.isValid){ newColor.remove() };

if(!newColor.isValid)

{

    doc.colors.add

    (

        {

                name : "newColor" ,

                colorValue : [0,0,0,100] ,

                space : ColorSpace.CMYK

        }

    )

};

// Assign new space and color will be converted:

newColor.space = ColorSpace.RGB;

alert( newColor.colorValue );

Test for correct conversions of various color management settings.

This should do it…

Instead of document you could also add colors to the application as well with app.colors.add() instead of app.documents[0].colors.add().

Named colors will be added to the Swatches panel.

Regards,
Uwe

Silly-V
Silly-VAuthor
Legend
January 23, 2018

Thank you, I did not see the colorTransform, but I suppose it's cause I didn't have the 13.0 object model in my OMV - so I was wondering, what's the deal with all the different object model lists for Indesign? There's entries from 3.0 all the way to 13.0

Appreciate your help!

Community Expert
January 23, 2018

You can run older code for older DOM versions in newer versions of InDesign.

For that you have to set the right version in the scriptPreferences of the app.

At least you can try that.

A warning: You must not forget to reset it when running code that is meant for the newer DOM version.

It's under:

app.scriptPreferences.version

My CS6 8.1 returns exactly that: "8.1"

Note: This is a string, not a floating number!

I never had to change that in my versions of InDesign. Search here in the forums or on the web, you might see some examples.

As I said, be cautious with that…

DOM documentation is not saying much about it:

Adobe InDesign CS6 (8.0) Object Model JS: ScriptPreference

FWIW: colorTransform() was added with: InDesign CC 2014.1

Regards,

Uwe