Graphics Reference
In-Depth Information
{
float h, s, v;
float r = rgbcolor.r;
float g = rgbcolor.g;
float b = rgbcolor.b;
float v = float maxval = max( r, max( g, b ) );
float minval = min( r, min( g, b ) );
if (maxval==0.) s = 0.0;
else s = (maxval - minval)/maxval;
if (s == 0.)
h = 0.; // actually h is indeterminate in this case
else
{
float delta = maxval - minval;
if ( r == maxval ) h = (g - b)/delta;
else
if (g == maxval) h = 2.0 + (b - r)/delta;
else
if (b == maxval) h = 4.0 + (r - g)/delta;
h *= 60.;
if (h < 0.0) h += 360.;
}
return vec3( h, s, v );
}
vec3
convertHSV2RGB( vec3 hsvcolor )
{
float h = hsvcolor.x;
float s = hsvcolor.y;
float v = hsvcolor.z;
if (s == 0.0) // achromatic- saturation is 0
{
return vec3(v,v,v); // return value as gray
}
else // chromatic case
{
if (h > 360.0) h = 360.0; // h must be in [0, 360)
if (h < 0.0) h = 0.0; // h must be in [0, 360)
h /= 60.;
int k = int(h);
float f = h - float(k);
float p = v * (1.0 - s);
float q = v * (1.0 - (s * f));
float t = v * (1.0 - (s * (1.0 - f)));
Search WWH ::




Custom Search