How rgbToHsl really works ?
Posted: July 1st, 2014, 7:22 am
Hi I spent lot of time to get luma value from a rgb color.
I get my reference value for HSL in the info panel, I just have to put the mouse on the right color.
for example:
if the rgb color is a gray at 30% (0.3020 , 0.3020 , 0.3020) in decimal.
the results of this expression is:
rgbToHsl(0.3020 , 0.3020 , 0.3020)[2] = 30 (it's ok)
But it doesn't work for this pure red color (1,0,0) luma should be at 100%.
rgbToHsl(1 , 0 , 0)[2] = 50
same for this
rgbToHsl(0 , 0.75 , 0)[2] = 37 (should be 75%)
So I tried an other way:
Math.round ((Math.max(rgb[0],rgb[1],rgb[2]) + Math.min(rgb[0],rgb[1],rgb[2]) /2)*100)
This time a get the right luma value if I choose a color sample but a wrong result for a grayscale sample !
What do you think ?
I want the expression on a text layer to make a kind of color picker to show only the luma. It's quite simple but I want it reliable.
I get my reference value for HSL in the info panel, I just have to put the mouse on the right color.
for example:
if the rgb color is a gray at 30% (0.3020 , 0.3020 , 0.3020) in decimal.
the results of this expression is:
rgbToHsl(0.3020 , 0.3020 , 0.3020)[2] = 30 (it's ok)
But it doesn't work for this pure red color (1,0,0) luma should be at 100%.
rgbToHsl(1 , 0 , 0)[2] = 50
same for this
rgbToHsl(0 , 0.75 , 0)[2] = 37 (should be 75%)
So I tried an other way:
Math.round ((Math.max(rgb[0],rgb[1],rgb[2]) + Math.min(rgb[0],rgb[1],rgb[2]) /2)*100)
This time a get the right luma value if I choose a color sample but a wrong result for a grayscale sample !
What do you think ?
I want the expression on a text layer to make a kind of color picker to show only the luma. It's quite simple but I want it reliable.