#2909 RGB to HSL conversion

SlimerDude Mon 19 Feb

Hi, I noted that the Color conversion of RGB to HSL isn't quite right - in particular the .l() or Lightness is consistently too high.

Fantom Shell v1.0.79 ('?' for help)
fansh> using graphics
Add using: using graphics
fansh> Color("red").l
1.0

Whereas the luminosity of red should half that at 0.5. If using graphics::Color then the hsl of red actually produces white - e.g. hsl(0deg, 100%, 100%).

I know the maths behind RGB to HSL can get a little complicated but it'd be very useful if the formula used could re-visited.

For instance this article suggests luminance may be calculated as follows:

Now calculate the Luminace value by adding the max and min values and divide by 2.

Whereas the current algorithm only takes the maximum value.

andy Tue 20 Feb

Yeah that doesn't look right - we'll take a look.

andy Tue 19 Mar

Ticket promoted to #2909 and assigned to andy

andy Tue 19 Mar

Ticket resolved in 1.0.80

HSL behavior should now match browser implementations.

SlimerDude Wed 20 Mar

Brilliant - thanks Andy!

Could you reference the formulas used in the conversions?

Login or Signup to reply.