Flasher Archive
[Previous] [Next] - [Index] [Thread Index] - [Previous in Thread] [Next in Thread]
| Subject: | FLASH: OT: RGB to HSL conversion |
| From: | RedStar |
| Date: | Thu, 3 Feb 2000 22:03:18 GMT |
Samuel,
I think you mean RGB to HSL conversion ?
If so here goes
1 - Convert the RGB values to the range [0;1]
Example : Let's convert the Shocked Orange R 255 G 153 B 0
First step R 1.0 G 0.6 B 0
2 - Find the min and max values of R,G,B
In the example maxcolour:=1.0 mincolour:=0
3 - Luminance :=(maxcolour+mincolour)/2
In the example L:=(1.0 + 0)/2=0.5
4 - If maxcolour=mincolour (this would mean the colour is some kind of
grey) then
S:=0 and H:=0 (in fact H is undefined but let's say it's 0)
5 - If maxcolour and mincolour are not equal then test L and do
If L < 0.5 then S=(maxcolour-mincolour)/(maxcolour+mincolour)
If L >=0.5 then S=(maxcolour-mincolour)/(2.0-maxcolour-mincolour)
In the example L=0.5 then
S=(1-0)/(2-1-0)=1/1=1
6 - If R=maxcolour then H=(G-B)/(maxcolour-mincolour)
If G=maxcolour then H=2.0+(B-R)/(maxcolour-mincolour)
If B=maxcolour then H=4.0+(R-G)/(maxcolour-mincolour)
In the example :
R=maxcolour so
H=(0.6-0)/(1-0)=0.6
Following our example we now have H=0.6,S=1 and L=0.5
You can use these values or continue by further converting H into an
angle in degrees and L and S to percentage.
To convert H just multiply by 60.0 and if H is negative add 360 so the
final conversion would give :
H=36 S=100% L=50%
.redstar.
flasher is generously supported by...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
flashforward2000 and The Flash Film Festival
"The World�s Premier Flash Solutions Conference and Expo"
March 27-29, Nob Hill Masonic Center, San Francisco, California
-Register before Feb 25 and save $200!!-- www.flashforward2000.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To unsubscribe or change your list settings go to
http://www.chinwag.com/flasher or email help
Replies
FLASH: RVB to HSL, Samuel Morello
[Previous] [Next] - [Index] [Thread Index] - [Next in Thread] [Previous in Thread]

