POV-Ray : Newsgroups : povray.general : ANN: RGB<->HLS macros : Re: ANN: RGB<->HLS macros Server Time
9 Aug 2024 19:35:08 EDT (-0400)
  Re: ANN: RGB<->HLS macros  
From: Jan Walzer
Date: 28 May 2000 16:01:50
Message: <39317b2e@news.povray.org>
> > Sounds very, very useful (though I've *almost* learned to do this in
> > my head :) )
>
> Really? Well, HLS to RGB is easy, but the RGB back ot HLS is a real
bizatch
> to get the algorithm for. I basically just looked for patterns in the RGB
> values for different HLS inputs.

Sure ... why shouldn't he ... of course, I think the rgb2HLS-part is the
more easy way...
HLS2RGB is quite "harder" if you don't know the direction of the rainbow ...

> The lightness (chroma) is easy, (max(RGB)+min(RGB))/2
> The saturation (value) is (min(RGB)-max(RGB))/(2|L-0.5|-1)
[...snip...]
> use the following lookup chart:
>    M=max, m=min,
>    RGB n
>    -----
>    M-m 0
>    -Mm 1
>    mM- 2
>    m-M 3
>    -mM 4
>    Mm- 5
> Then the hue is
> n+mod(n,2)-2(mod(n,2)-0.5)*(med(RGB)-min(RGB))/(max(RGB)-min(RGB))
... ohhh .. all those formulas ... Have you tried to determine the
RGB-values of a color from your feeling ???
Of course, you wont get the desired color on your first try, but If I see a
RGB-vector I think I can imagine the real Color, vice versa ...

For this I find it harder to recognise a color from a HLS-vector...
But I find such macro very useful to create a nice colorslide by code ...
this would be much more easier ..

I'll try it out ... If it runs: "Quite well done !" ... ;-)

 --

 ,',    Jan Walzer      \V/  http://wa.lzer.net     ,',
',','   student of      >|<  mailto:jan### [at] lzernet ',','
  '   ComputerScience   /A\  +49-177-7403863         '


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.