View Single Post
Old 21st June 2006, 03:09   #255
TomyLobo
Major Dude
 
TomyLobo's Avatar
 
Join Date: Feb 2004
Location: Germany
Posts: 580
eeltrans macros for HSL -> RGB conversion:
Quote:
// --- HSL ---
// converts from HSL color space to RGB color space
#define HSL2RGB(H,S,L,R,G,B) (var_2=if(below(L,.5),L * ( 1 + S ),( L + S ) - ( S * L ));var_1=2 * L - var_2;R=Hue_2_RGB(var_1,var_2,H+third);G=Hue_2_RGB(var_1,var_2,H);B=Hue_2_RGB(var_1,var_2,H-third))

// initialization macro for HSL2RGB
#define init_HSL2RGB() third=1/3;

// helper macro for HSL2RGB - needs wrap()
#define Hue_2_RGB(v1,v2,invH) (vH=invH;wrap(vH, 0, 1, 1); v6H=6*vH; if(below(v6H, 1), v1+(v2-v1)*v6H, if(below(2*vH, 1), v2, if(below(3*vH, 2), v1+(v2-v1)*(4-v6H), v1))))

// wraps a value between minval and maxval. range should be (maxval-minval)
#define wrap(var,minval,maxval,range) if(below(var,minval),var=var+range,if(above(var,maxval),var=var-range,0));
Usage:
code:
hue=.3;
sat=1;
lum=.5;
HSL2RGB(hue,sat,lum,red,green,blue);


If you can't say something nice, say something surrealistic.
TomyLobo is offline   Reply With Quote