Problem with colorpicker

Good day, i might be making a mistake somewhere but if not this is a bug,
i’d like to get LAB values from the colorpicker with this code:

const picker2 =async () => {
const result = await batchPlay(
[
{
"_obj": "showColorPicker",
"application": {
"_class": "null"
},
"value": true,
"color": {
"_obj": "labColor",
"luminance": 100,
"a": 35,
"b": 0
},
"RGBFloatColor": {
"_obj": "RGBColor",
"red": 255,
"grain": 229.52720046043396,
"blue": 255
},
"dontRecord": true,
"forceNotify": true,
"_isCommand": false,
"_options": {
"dialogOptions": "dontDisplay"
}
}
],{
"synchronousExecution": false,
"modalBehavior": "fail"
});
labvalue=result[0].color
return labvalue
}

but it only works if the selector is set to LAB.

lab

If the selector is in RGB i cannot get LAB values.
If i wanted to get RGB values it works on any selector setting.

Ciao!

Try this:

async function colorPicker() {
    var colorPicked = await batchPlay(
        [{
            "_obj": "showColorPicker",
            "application": {
                "_class": "null"
            },
            "value": true,
            "color": {
                "_obj": "labColor",
                "luminance": 100,  // starting value in Lab
                "a": 35,
                "b": 0
            },
            "dontRecord": true,
            "forceNotify": true,
        }], {
            "synchronousExecution": true,
            "modalBehavior": "fail"
        })[0].color;

    console.log("You picked:", colorPicked);   // show picked color in whatever color mode : RGB. Lab, HSB
    return colorPicked;
}
1 Like

@Pierre_G it’s still not working, here i executed the code and memorized it in a variable and as you can see it recalls only RGB values if the radio button is on RGB.

You can use Photoshop’s internal method to convert colors from one color space to another:

export function convertColorSpace(color: Color | PsColor, colorSpace: 'RGB' | 'HSB' | 'CMYK' | 'grayscale' | 'lab'): PsColor {
  const desc = {
    _obj: "convertColorToSpace",
    _target: { _ref: "application" },
    color,
    colorSpace: {
      _enum: "colorSpace",
      _value: colorSpace
    }
  }
  return photoshop.action.batchPlay([desc], { synchronousExecution: true })[0].color
}

console.log(convertColorSpace({_obj: 'RGBColor', red: 255, green:0, blue: 0}, "lab"))

image

3 Likes

Here you go, a Luminosity picker:

async function lumaPicker() {
  const batchPlay = require("photoshop").action.batchPlay;
  var colorPicked = await batchPlay(
    [{
      "_obj": "showColorPicker",
      "application": {
        "_class": "null"
      },
      "value": true,
      "color": {
        "_obj": "labColor",
        "luminance": 100, // starting color values in Lab
        "a": 35,
        "b": 0
      },
      "dontRecord": true,
      "forceNotify": true,
    }], {
      "synchronousExecution": true
    })[0].color;


  var labLuma = await batchPlay([{
    "_obj": "convertColorToSpace",
    "_target": {
      "_ref": "application"
    },
    "color": colorPicked, // color object
    "colorSpace": {
      "_enum": "colorSpace",
      "_value": "lab"
    }
  }], {
    "synchronousExecution": true,
  })[0].color.luminance;

   
  console.log("You picked Luma =", Math.round(labLuma));
}
1 Like

Thank you so very much @Pierre_G and @simonhenke , you are too kind, this way you fixed and bypassed the issue i had! I do however imagine this to be a UXP bug that needs fixing, considering that in extendscript there was no need for further color conversion.
Have a nice day.

Hi, where the heck is convertColorToSpace ever mentioned?!
Thanks!

It was somewhere buried in the prerelease forum… One of the many things that should be documented but aren’t :thinking:
IMO such scripts would be perfect for the “How do I…” section in the docs.

Until you get DOM where this will be easy to do.