0

Let's say that I have a Color. I extract the rgb values.

Hypothetically

  • r = 90
  • g = 240
  • b = 8

I also have the L value from HSL. Nothing else from HSL.

Explanation of Lightness (L):

L var can take value from 0 to 1.

  • If it's >0.5 then it's brighter. //1 is white
  • If it's <0.5 then it's darker. //0 is black
  • If it's =0.5 then it's neutral.

So my question is:

How can i change the rgb values using the L value?

For example if L = 0.45 then the rgb values decrease a little. Else if L = 0.8 the rgb values add alot. Also i am coding in Java if it helps with the answear.

1 Answers1

1

The answer is:

if L < 0.5 then

r' = r - r * 2 * (0.5 - L);
g' = g - g * 2 * (0,5 - L);
b' = b - b * 2 * (0,5 - L);

else if L > 0.5 then

r' = r + (255 - r) * 2 * (L - 0.5);
g' = g + (255 - g) * 2 * (L - 0.5);
b' = b + (255 - b) * 2 * (L - 0.5);

if L = 0.5 the rgb values stay as they are.