Copy link to clipboard
Copied
Photoshop 2020
Using VBS scripting interface (via a Python script)
16 bit grayscale document
I have a script that creates a ColorSampler in my active grayscale document that returns the RGB and Gray values. It works great, but I'm confused about how to properly interpret the returned values in relation to what I see in the Info panel of Photoshop. In PS, I've set the Info panel readouts for 16-bit RGB and 16-bit Grayscale (K). I understand that these 16-bit readouts are actually "15bit +1" integers, and will range in values from 0 - 32768 (black-to-white).
The scripting interface, however, gives me the following:
For RGB, each value is a float (double) with range of 0.0 - 255.0
For Gray, each value is a float (double) of the ink density "K" with range of 100.0 - 0.0
I have verified in the PS VBS Scripting PDF that these are the intended return types.
My questions:
Why does the interface return floats when the Info Panel is showing the 16-bit values as a "15+1" integer?
I'm pretty sure that the interface floats are truly reflecting the actual 16-bit value of the pixels, but how do I correlate the float values to the "15bit +1" displayed value? Is there a way to convert from one to the other?
Example: I have a large patch of identical pixels. Inside this patch I get the following:
Info Panel 16-bit RGB = 1543
Info Panel 16-bit K = 1543
PS VBS Scripting Interface RGB = 12.00759888
PS VBS Scripting Interface Gray = 95.29
It would be nice if I could deal with the simple 0-32768 integer values in my script. Is there a way to convert?
Thanks.
1 Correct answer
var x = 12.00759888;
alert(Math.round(32768/255 * x));
var x = 95.29;
alert(Math.round(32768/100 * (100-x)));
Explore related tutorials & articles
Copy link to clipboard
Copied
var x = 12.00759888;
alert(Math.round(32768/255 * x));
var x = 95.29;
alert(Math.round(32768/100 * (100-x)));
Copy link to clipboard
Copied
You can just convert the number:
#target photoshop
var factor = 32768/255
var doc = activeDocument
var sp = [100,100]
doc.colorSamplers.removeAll();
var cs = doc.colorSamplers.add(sp)
var redN = cs.color.rgb.red
$.writeln(Math.round(redN * factor))
Copy link to clipboard
Copied
Thanks to both of you (Chuck and r-bin) for responding so quickly. Normally I can figure out these number range/type conversions but it was just escaping me this time. I knew it had to be simple.
Thanks.

