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

Make Color Sampler in LAB mode

Contributor ,
May 25, 2021 May 25, 2021

I am trying to create a new color sampler using a LAB readout, but cant get this homecooked function of mine to work. not sure if i have the putEnumerated for lab in right context in the descriptor. Any ideas....

 

newColorSampler (100, 200)

function newColorSampler(xpos, ypos){


function s2t(s) {return stringIDToTypeID(s)}
    var d1 = new ActionDescriptor()
        var r1 = new ActionReference()
        r1.putClass( s2t( "colorSampler" ))
    d1.putReference( s2t( "null" ), r1 )
      d1.putEnumerated(s2t("colorSpace"),s2t("colorSpace"), s2t("labColor"))
        var d2 = new ActionDescriptor()
        d2.putUnitDouble( s2t( "horizontal" ), s2t( "pixelsUnit" ), xpos )
        d2.putUnitDouble( s2t( "vertical" ), s2t( "pixelsUnit" ), ypos )
        d1.putObject(s2t( "position" ), s2t( "paint" ), d2 )
executeAction(s2t( "make" ), d1, DialogModes.NO )}
TOPICS
Actions and scripting
3.7K
Translate
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

People's Champ , May 26, 2021 May 26, 2021
No, it won't work like that. Moreover, you did not write it correctly.
Almost all lists are read-only properties.
Such as for example histogram, compsList, printerList, targetLayers, etc.
They cannot be changed with the "set" command.
 
Logically it should be like this
var class_name = "colorSampler";

var d = new ActionDescriptor();
var r = new ActionReference()
r.putIndex(stringIDToTypeID(class_name), 1);


d.putReference(stringIDToTypeID("null"), r);
var d1 = new ActionDescriptor();

//d
...
Translate
Adobe
LEGEND ,
May 25, 2021 May 25, 2021
with((cS = activeDocument.colorSamplers)[cS.length - 1].color.lab) [l, a, b]
Translate
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
Contributor ,
May 25, 2021 May 25, 2021

thats useful

Translate
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
People's Champ ,
May 25, 2021 May 25, 2021

The logic is correct. But it won't work. Probably the developers of photoshop did not foresee such an opportunity or simply did not notice.

Translate
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
LEGEND ,
May 25, 2021 May 25, 2021

The info palette shows results depending on selected Color Mode.

Translate
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
People's Champ ,
May 25, 2021 May 25, 2021
This property is stored in the ColoSampler itself. It can be read, but there is no way to change it at least in 2020.
Translate
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
LEGEND ,
May 25, 2021 May 25, 2021

Or else it stores binary SolidColor, then checks color mode and displayes result in such mode.

Translate
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
People's Champ ,
May 25, 2021 May 25, 2021

It was necessary to create in this mode. It was a question.

Translate
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
LEGEND ,
May 25, 2021 May 25, 2021

Not possible, to do it you have to change color mode first, or get lab colour result by script.

Translate
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
People's Champ ,
May 25, 2021 May 25, 2021

This will be Actual Color, not pure LAB Color. It will change depending on the document mode.

Translate
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
People's Champ ,
May 25, 2021 May 25, 2021

ColorSampler is a bad tool in scripts.

Here is a real ColorSampler 31x31.

See what the code shows

alert (activeDocument.colorSamplers [0] .color.rgb.red)

colorsample.png

Translate
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
LEGEND ,
May 25, 2021 May 25, 2021

Then 1x1 px selctions instead of ColorSamplers can be solution?

Translate
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
People's Champ ,
May 25, 2021 May 25, 2021

Probably meant 31x31?

Translate
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
LEGEND ,
May 25, 2021 May 25, 2021

Yes, that's right, by maybe Gibson Editions won't need this extensive scope 🙂

Translate
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
Contributor ,
May 25, 2021 May 25, 2021

I am reading the numbers in LAB but my document is in RGB.

 

its strange, as i can read the enumeration in LAB if ive changed the color sampler manually. 

 

I dont know whether it is described inside toolPreferences perhaps... 

 

Translate
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
Contributor ,
May 25, 2021 May 25, 2021

for the panel options that is. 

Translate
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
LEGEND ,
May 26, 2021 May 26, 2021

What you mean by changing color sampler manually?

Translate
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
Contributor ,
May 26, 2021 May 26, 2021

Screenshot 2021-05-26 at 13.37.19.png

 

This is the stucture i have found

function s2t(s) {return stringIDToTypeID(s)}
function t2s(t){return typeIDToStringID(t)}
function c2t(s) {return charIDToTypeID(s)}

var r1=new ActionReference();
var d1=new ActionDescriptor();

r1.putEnumerated(s2t("document"),s2t("ordinal"),s2t("targetEnum"));
d1=executeActionGet(r1);
l1 = d1.getList (s2t ("colorSamplerList"))
l1.count
d2 = l1.getObjectValue(0) //colorSampler 3 items // position (obj), color(obj), colorspace(enum)

o1 = d2.getObjectValue(s2t ("position")) // 2 items
o2 = d2.getObjectValue(s2t ("color")) //3 items
o3 = d2.getEnumerationValue(stringIDToTypeID("colorSpace"))


L = o2.getDouble(stringIDToTypeID("luminance"))
A = o2.getDouble(stringIDToTypeID("a"))
B = o2.getDouble(stringIDToTypeID("b"))

Translate
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
Contributor ,
May 26, 2021 May 26, 2021

This is where im up to, any ideas how to make it work?...

I've never used lists before so not sure if im describing the list correctly... 

 

Also not sure if "to" is correct for putObject

function s2t(s) {return stringIDToTypeID(s)}

var r1 = new ActionReference();
var d1 = new ActionDescriptor();
var d2 = new ActionDescriptor();
var l1 = new ActionList()
//l1.putList(s2t("colorSamplerList"), 0)

r1.putProperty(s2t("property"),s2t("colorSamplerList")); 
r1.putEnumerated(s2t("document"),s2t ("ordinal"), s2t ("targetEnum")); 
 d1.putReference( s2t( "target" ), r1 )
 l1.putInteger( 0 )
d2.putList(s2t("colorSampler"), l1); 
d2.putEnumerated(s2t("colorSpace"),s2t("colorSpace"), s2t("labColor"))

 d1.putObject(s2t("to"), s2t("colorSampler"),d2);
 
executeAction( s2t("set"), d1, DialogModes.NO );
//FAILS

 

 

This is an example of Structure in JSON

{"_obj":"object","colorSamplerList":[

{"_obj":"colorSampler",
"color":{"_obj":"labColor","a":0.0,"b":0.01,"luminance":99.73},
"colorSpace":{"_enum":"colorSpace","_value":"labColor"},
"position":{"_obj":"paint","horizontal":{"_unit":"pixelsUnit","_value":100.0},"vertical":{"_unit":"pixelsUnit","_value":200.0}}},

{"_obj":"colorSampler",
"color{"_obj":"RGBColor","blue":254.99221789883269,"grain":255.0,"red":255.0},
"colorSpace":{"_enum":"colorSpace","_value":"RGBColor"},
"position":{"_obj":"paint","horizontal":{"_unit":"pixelsUnit","_value":138.5},"vertical":{"_unit":"pixelsUnit","_value":111.5}}}]}

 

 

 

Translate
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
People's Champ ,
May 26, 2021 May 26, 2021
No, it won't work like that. Moreover, you did not write it correctly.
Almost all lists are read-only properties.
Such as for example histogram, compsList, printerList, targetLayers, etc.
They cannot be changed with the "set" command.
 
Logically it should be like this
var class_name = "colorSampler";

var d = new ActionDescriptor();
var r = new ActionReference()
r.putIndex(stringIDToTypeID(class_name), 1);


d.putReference(stringIDToTypeID("null"), r);
var d1 = new ActionDescriptor();

//d1.put... some properties

d.putObject(stringIDToTypeID("to"), stringIDToTypeID(class_name), d1);
executeAction(stringIDToTypeID("set"), d, DialogModes.NO);
 
but doesn't work.
Although if you change "colorSampler" to "compsClass" everything works fine. This is a flaw in Photoshop. There are a lot of them.
Translate
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
Contributor ,
May 26, 2021 May 26, 2021
LATEST

Thank you so much for you expertise, thats really helpful.

Translate
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