• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
3

Script to convert CIE Lab to CIE Lch?

Enthusiast ,
Mar 18, 2024 Mar 18, 2024

Copy link to clipboard

Copied

Looking for a way to work around InDesign limited color management capability.

Suppose I have some object selected on the page, the script would have to be able to extract the CIE Lab values out of the selected object, convert to Chroma and Hue angle, and paste the values in a new text frame. Doable? Easily?

 

TOPICS
Performance

Views

293

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , Mar 18, 2024 Mar 18, 2024

Well, here's a simple script that displays an alert with the CIE Chroma and CIE Hue angle information.
InDesign HSB is useless because it is based on RGB. 
I am not by any means a JavaScript specialist.


capture.png

The code is quite simple:

// Roger Breton / March 18 2024

// Get the active document
var doc = app.activeDocument;

// Check if there's a selection
if (doc.selection.length > 0) {
    // Get the first selected item
    var selectedItem = doc.selection[0];

    // Check if the selected item has a fill color
   
...

Votes

Translate

Translate
Community Expert ,
Mar 18, 2024 Mar 18, 2024

Copy link to clipboard

Copied

I have no solution here but if there is one, there are a couple of color folks who will provide it.

 

I'm just curious how extracting/calculating this fairly esoteric color value... and then just pasting in text values, is of use. For some manual entry at a later point? Seems as if any color value calculator could do that...


┋┊ InDesign to Kindle (& EPUB): A Professional Guide, v3.1 ┊ (Amazon) ┊┋

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Mar 18, 2024 Mar 18, 2024

Copy link to clipboard

Copied

Well, here's a simple script that displays an alert with the CIE Chroma and CIE Hue angle information.
InDesign HSB is useless because it is based on RGB. 
I am not by any means a JavaScript specialist.


capture.png

The code is quite simple:

// Roger Breton / March 18 2024

// Get the active document
var doc = app.activeDocument;

// Check if there's a selection
if (doc.selection.length > 0) {
    // Get the first selected item
    var selectedItem = doc.selection[0];

    // Check if the selected item has a fill color
    if (selectedItem.fillColor !== undefined) {
        // Retrieve the fill color
        var fillColor = selectedItem.fillColor;
        var fillModel = selectedItem.fillColor.model.toString(); // SPOT
        var fillColorSpace = selectedItem.fillColor.space.toString(); // LAB
   

        var l_value = selectedItem.fillColor.colorValue[0];
        var a_value = selectedItem.fillColor.colorValue[1];
        var b_value = selectedItem.fillColor.colorValue[2];

        var l_float = parseFloat(l_value);
        var a_float = parseFloat(a_value);
        var b_float = parseFloat(b_value);

       
        // Calculate CIE Chroma (C)
        var chroma = Math.sqrt(Math.pow(a_value, 2) + Math.pow(b_value, 2));

        // Calculate Hue Angle (H) in radians
        var hue_radians = Math.atan2(b_value, a_value);

        // Convert Hue Angle to degrees
        var hue_degrees = (hue_radians * 180) / Math.PI;
        if (hue_degrees < 0) {
            hue_degrees += 360; // Make it positive
        }

        // Print the fill color details
        alert("Fill Color:\n\n" +
              "Color Model: " + fillModel + "\n" +
              "Color Space: " + fillColorSpace + "\n" +
              "L : " + l_value.toFixed(2) + "\n" +
              "A : " + a_value.toFixed(2) + "\n" +
              "B : " + b_value.toFixed(2) + "\n" +
              "Chroma : " + chroma.toFixed(2) + "\n" +
              "Hue Angle : " + hue_degrees.toFixed(2) + " degrees");
    } else {
        alert("The selected item does not have a fill color.");
    }
} else {
    alert("No item is currently selected.");
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Mar 18, 2024 Mar 18, 2024

Copy link to clipboard

Copied

LATEST

It's difficult to directly interpret the a and b values of a Lab color.
The Hue angle is much more intuitive. 
Suppose I have two blue colors. If I know one has a hue angle of 257 and the other has a hue angle of 290 degrees then I can visualize abstractly the difference in appearance of those two colors. One (290) is more "purple" than the other, you see? 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 18, 2024 Mar 18, 2024

Copy link to clipboard

Copied

Hi @Roger Breton A conversion to HSB would be the only option. InDesign’s HSB is not device independent, it’s color managed via the assigned RGB profile, so its apperance would change depending on the RGB profile assignment.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines