magneeto
12-08-2008, 10:24 PM
hi,
i need an explanation on the algorithm to convert colors in HSV model to RGB model. all the algorithms that i have seen assign the following values to RGB in different regions of the hexacone
h /= 60; // sector 0 to 5
i = floor( h );
f = h - i; // factorial part of h
p = v * ( 1 - s );
q = v * ( 1 - s * f );
t = v * ( 1 - s * ( 1 - f ) );
switch( i ) {
case 0:
*r = v; *g = t; *b = p;
break;
case 1:
*r = q; *g = v; *b = p;
break;
case 2:
*r = p; *g = v; *b = t;
break;
case 3:
*r = p; *g = q; *b = v;
break;
case 4:
*r = t; *g = p; *b = v;
break;
default: // case 5:
*r = v; *g = p; *b = q;
break;
}
i can't understand the mapping of p,q and t and also how they are calculated. an explanation is very much appreciated. thank you.
i need an explanation on the algorithm to convert colors in HSV model to RGB model. all the algorithms that i have seen assign the following values to RGB in different regions of the hexacone
h /= 60; // sector 0 to 5
i = floor( h );
f = h - i; // factorial part of h
p = v * ( 1 - s );
q = v * ( 1 - s * f );
t = v * ( 1 - s * ( 1 - f ) );
switch( i ) {
case 0:
*r = v; *g = t; *b = p;
break;
case 1:
*r = q; *g = v; *b = p;
break;
case 2:
*r = p; *g = v; *b = t;
break;
case 3:
*r = p; *g = q; *b = v;
break;
case 4:
*r = t; *g = p; *b = v;
break;
default: // case 5:
*r = v; *g = p; *b = q;
break;
}
i can't understand the mapping of p,q and t and also how they are calculated. an explanation is very much appreciated. thank you.