POV-Ray : Newsgroups : povray.general : ANN: RGB<->HLS macros Server Time
1 Nov 2024 18:18:37 EDT (-0400)
  ANN: RGB<->HLS macros (Message 1 to 4 of 4)  
From: David Fontaine
Subject: ANN: RGB<->HLS macros
Date: 24 May 2000 00:02:32
Message: <392B5379.4C4DCC36@faricy.net>
I made some macros to convert HLS to RGB *AND* RGB to HLS. They're at
http://www.faricy.net/~davidf/povre.html
I find it is often hard to get a desired color when hand-coding becaue
changing one component changes the hue, but with HLS you can change the
color tone without changing hue.

--
David Fontaine     <dav### [at] faricynet>     ICQ 55354965
Please visit my website: http://www.faricy.net/~davidf/


Post a reply to this message

From: Peter Popov
Subject: Re: ANN: RGB<->HLS macros
Date: 24 May 2000 17:57:50
Message: <msjois8fo53e5152nboh53ml7dmuaqqpmq@4ax.com>
On Tue, 23 May 2000 22:58:49 -0500, David Fontaine <dav### [at] faricynet>
wrote:

>I made some macros to convert HLS to RGB *AND* RGB to HLS. They're at
>http://www.faricy.net/~davidf/povre.html
>I find it is often hard to get a desired color when hand-coding becaue
>changing one component changes the hue, but with HLS you can change the
>color tone without changing hue.

Sounds very, very useful (though I've *almost* learned to do this in
my head :) )


Peter Popov ICQ : 15002700
Personal e-mail : pet### [at] usanet
TAG      e-mail : pet### [at] tagpovrayorg


Post a reply to this message

From: David Fontaine
Subject: Re: ANN: RGB<->HLS macros
Date: 24 May 2000 18:56:16
Message: <392C5D2A.3233D985@faricy.net>
Peter Popov wrote:

> 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.


The lightness (chroma) is easy, (max(RGB)+min(RGB))/2


The saturation (value) is (min(RGB)-max(RGB))/(2|L-0.5|-1)
if we let the unit square from (0,0) to (1,1) represent (S,L) values from
(0,.5)-(1,0), we can use the equations
y=1-n/x, where n is the value (max(RGB)-min(RGB)), line is the locus of all
(S,L) values satisfying that n value
y=2|0.5-L|, using the previously calculated L value, line represents the
locus of that particular L value.
Solving for the set we get:
x=-(max(RGB)-min(RGB))/(2|0.5-L|-1), x corresponding to saturation.


The hue is easy compared to all that.
first find where the maximum and minimum values in the RGB vector are and
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))

--
David Fontaine     <dav### [at] faricynet>     ICQ 55354965
Please visit my website: http://www.faricy.net/~davidf/


Post a reply to this message

From: Jan Walzer
Subject: Re: ANN: RGB<->HLS macros
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.