How rgbToHsl really works ?

Moderators: Disciple, zlovatt

Post Reply
mienda
Posts: 5
Joined: November 6th, 2010, 4:40 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.
Dan Ebberts
Posts: 320
Joined: June 26th, 2004, 10:01 am
Location: Folsom, CA
Contact:

I think the luma/lightness channel is defined to be the average of the largest and smallest color channels. So pure red, blue or green would be 0.5 and white would be 1.0, etc.

Dan
mienda
Posts: 5
Joined: November 6th, 2010, 4:40 am

Hi Dan,
thanks for your reply.
You right, so I tried an other operation.
This one is ok only for a pure red sample: L0= Math.round ( (Math.max(rgb[0],rgb[1],rgb[2]) + Math.min(rgb[0],rgb[1],rgb[2]) /2)*100) And these one give me the same good result but only on a grayscale sample! L1= Math.round(50*(Math.max(rgb[0],rgb[1],rgb[2]) + Math.min(rgb[0],rgb[1],rgb[2])))
L2= Math.round((hsla[2])*100); Obviously I missed something, Do you think I have to write a condition ? (if a RGB channel = 0 for ex)
Or the problem is in the operation to get the average between channel max and channel mini.

Thank's again.
Dan Ebberts
Posts: 320
Joined: June 26th, 2004, 10:01 am
Location: Folsom, CA
Contact:

I'm not sure exactly what you're after, but I ran a quick test, and this slider expression always gives me 0.00 no matter what color I choose for the Fill effect:

c = effect("Fill")("Color");
L1 = rgbToHsl(c)[2];
L2 = (Math.max(c[0],c[1],c[2]) + Math.min(c[0],c[1],c[2]))/2

L2 - L1


What version of AE are you using? As I recall, Math.min() and Math.max() didn't use to work correctly with more than two arguments.


Dan
mienda
Posts: 5
Joined: November 6th, 2010, 4:40 am

Hi Dan,
I think it works now.
You can find below the project, I use AE cs6 (in french) but I think it's ok for the expressions.

I use a lot the color picker for color grading cell Animation to match perfectly with the backgrounds.
And often everything is pre-composed so to have an "external" color picker is very useful.

Thank's again
Attachments
Colorpicker.zip
Colorpicker RGB and TSL
(1.36 MiB) Downloaded 1246 times
Post Reply