adding HSV->RGB functions, expect garbage
This commit is contained in:
parent
44165c0a03
commit
8b4603fa21
50
funcs/hsv.c
50
funcs/hsv.c
@ -27,7 +27,11 @@ return (fabsf(a-b)<0.00000000000001); // UGLY HACK ???
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
/*
|
||||
* WARNING : ALL THIS CODE IS SHIT
|
||||
* WARNING : ALL THIS CODE IS STRANGE
|
||||
*
|
||||
|
||||
www.tutorialspoint.com/c-program-to-change-rgb-color-model-to-hsv-color-model
|
||||
|
||||
*/
|
||||
int fimg_rgb2hsv(float rgb[3], float hsv[3], float scale)
|
||||
{
|
||||
@ -62,6 +66,50 @@ fprintf(stderr, "cmin/cmax %f %f\n", cmin, cmax);
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
int fimg_hsv2rgb(float hsv[3], float rgb[3], float scale)
|
||||
{
|
||||
float hh, ff, p, q, t;
|
||||
long i;
|
||||
|
||||
if(hsv[1] <= 0.0) { // < is bogus, just shuts up warnings
|
||||
rgb[0] = rgb[1] = rgb[2] = hsv[2];
|
||||
return 0;
|
||||
}
|
||||
|
||||
hh = hsv[0];
|
||||
if(hh >= 360.0) hh = 0.0;
|
||||
hh /= 60.0;
|
||||
i = (long)hh;
|
||||
ff = hh - i;
|
||||
p = hsv[2] * (1.0 - hsv[1]);
|
||||
q = hsv[2] * (1.0 - (hsv[1] * ff));
|
||||
t = hsv[2] * (1.0 - (hsv[1] * (1.0 - ff)));
|
||||
|
||||
switch(i) {
|
||||
case 0:
|
||||
rgb[0] = hsv[2]; rgb[1] = t; rgb[2] = p;
|
||||
break;
|
||||
case 1:
|
||||
rgb[0] = q; rgb[1] = hsv[2]; rgb[2] = p;
|
||||
break;
|
||||
case 2:
|
||||
rgb[0] = p; rgb[1] = hsv[2]; rgb[2] = t;
|
||||
break;
|
||||
case 3:
|
||||
rgb[0] = p; rgb[1] = q; rgb[2] = hsv[2];
|
||||
break;
|
||||
case 4:
|
||||
rgb[0] = t; rgb[1] = p; rgb[2] = hsv[2];
|
||||
break;
|
||||
case 5:
|
||||
default:
|
||||
rgb[0] = hsv[2]; rgb[1] = p; rgb[2] = q;
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
int fimg_essai_hsv(char *fname)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user