/*************************************************************************** * Func: hsi2rgb * * * * Desc: converts a value from HSI to RGB color space * * * * Params: r - normalized red * * g - normalized green * * b - normalized blue * * h - hue in degrees * * s - normalized saturation * * i - normalized intensity * ***************************************************************************/ void hsi2rgb(float *r,float *g,float *b,float h,float s,float i) { float angle1, angle2, scale, temp, denom; /* temp variables */ if(i==0.0) /* BLACK */ { *r = 0.0; *g = 0.0; *b = 0.0; return; } if(s==0.0) /* gray-scale H is undefined*/ { *r = i; *g = i; *b = i; return; } if(h<0.0) h+=360.0; scale = 3.0 * i; if(h<=120.0) { angle1=h*0.017453293; /* convert to radians - mul by pi/180 */ angle2=(60.0-h)*0.017453293; *b = (1.0-s)/3.0; *r = (1.0 + (s*cos(angle1)/cos(angle2)))/3.0; *g = 1.0-*r-*b; *b *= scale; *r *= scale; *g *= scale; } else if((h>120.0) && (h<=240.0)) { h -= 120.0; angle1=h*0.017453293; /* convert to radians - mul by pi/180 */ angle2=(60.0-h)*0.017453293; *r = (1.0-s)/3.0; *g = (1.0 + (s*cos(angle1)/cos(angle2)))/3.0; *b = 1.0 - *r - *g; *r *= scale; *g *= scale; *b *= scale; } else { h -= 240.0; angle1=h*0.017453293; /* convert to radians - mul by pi/180 */ angle2=(60.0-h)*0.017453293; *g = (1.0-s)/3.0; *b = (1.0 + (s*cos(angle1)/cos(angle2)))/3.0; *r = 1.0 - *g - *b; *r *= scale; *g *= scale; *b *= scale; } }