Copy link to clipboard
Copied
I'm having trouble returning the expected values from Photoshop's LAB colour values
In RGB colour space
var myRGB = [146, 163, 173]; // LAB 60 94 -60
var lab = RGB_to_LAB(myRGB);
lab[0] = round_up(lab[0], 0);
lab[1] = round_up(lab[1], 0);
lab[2] = round_up(lab[2], 0);
alert(lab) // 66, -5, -7
// should be 60 94 -60
function RGB_to_LAB(RGB)
{
var colour = new SolidColor;
colour.rgb.red = RGB[0];
colour.rgb.green = RGB[1];
colour.rgb.blue = RGB[2];
return [
colour.lab.l,
colour.lab.a,
colour.lab.b
]
}
function round_up(num, prec)
{
prec = Math.pow(10, prec);
return Math.ceil(num * prec) / prec;
}
I *assuming* the values displayed in the Color Picker are rounded up.
I'm sure it's got to do with gamma/ color settings, I'm using sRGB IEC61966-2.1
How do I compensate for any discrepancies?
I'm having to feed colours into a colour range function which only works with LAB colours. Nice.
2 Correct answers
(sc = new SolidColor).rgb.hexValue = 'ff00ff'; lab = sc.lab; while
(!isNaN(lab[zro = lab.reflect.properties[0]])) {alert(lab[zro]); delete lab[zro]}
Change content of alert to:
Math.round(zro < 'l' ? (lab[zro] + 128) / 255 * 256 - 128 : lab[zro])
Explore related tutorials & articles
Copy link to clipboard
Copied
Sorry that first line should be:
var myRGB = [255, 0, 255]; / 60 94 -60
Copy link to clipboard
Copied
(sc = new SolidColor).rgb.hexValue = 'ff00ff'; lab = sc.lab; while
(!isNaN(lab[zro = lab.reflect.properties[0]])) {alert(lab[zro]); delete lab[zro]}
Copy link to clipboard
Copied
That's close. The value came out as
60.16845703125, 92.6736744371094, -60.763671875
// rounded up
61, 93, -60 // should be 60 94 -60
Copy link to clipboard
Copied
Change content of alert to:
Math.round(zro < 'l' ? (lab[zro] + 128) / 255 * 256 - 128 : lab[zro])
Copy link to clipboard
Copied
That seems to be just a part of the correction script. This link has more info and the other components as well
http://www.rags-int-inc.com/PhotoTechStuff/ColorCalculator/AdobeMath.html

