Blame toonz/sources/stdfx/hsvutil.cpp
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "trop.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "hsvutil.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void OLDRGB2HSV(double r, double g, double b,
|
|
Toshihiro Shimizu |
890ddd |
double *h, double *s, double *v)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
double max, min;
|
|
Toshihiro Shimizu |
890ddd |
double delta;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
max = tmax(r, g, b);
|
|
Toshihiro Shimizu |
890ddd |
min = tmin(r, g, b);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
*v = max;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (max != 0)
|
|
Toshihiro Shimizu |
890ddd |
*s = (max - min) / max;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
*s = 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (*s == 0)
|
|
Toshihiro Shimizu |
890ddd |
*h = 0;
|
|
Toshihiro Shimizu |
890ddd |
else {
|
|
Toshihiro Shimizu |
890ddd |
delta = max - min;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (r == max)
|
|
Toshihiro Shimizu |
890ddd |
*h = (g - b) / delta;
|
|
Toshihiro Shimizu |
890ddd |
else if (g == max)
|
|
Toshihiro Shimizu |
890ddd |
*h = 2 + (b - r) / delta;
|
|
Toshihiro Shimizu |
890ddd |
else if (b == max)
|
|
Toshihiro Shimizu |
890ddd |
*h = 4 + (r - g) / delta;
|
|
Toshihiro Shimizu |
890ddd |
*h = *h * 60;
|
|
Toshihiro Shimizu |
890ddd |
if (*h < 0)
|
|
Toshihiro Shimizu |
890ddd |
*h += 360;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void OLDHSV2RGB(double hue, double sat, double value,
|
|
Toshihiro Shimizu |
890ddd |
double *red, double *green, double *blue)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int i;
|
|
Toshihiro Shimizu |
890ddd |
double p, q, t, f;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// if (hue > 360 || hue < 0)
|
|
Toshihiro Shimizu |
890ddd |
// hue=0;
|
|
Toshihiro Shimizu |
890ddd |
if (hue > 360)
|
|
Toshihiro Shimizu |
890ddd |
hue -= ((int)hue / 360) * 360;
|
|
Toshihiro Shimizu |
890ddd |
//hue-=360;
|
|
Toshihiro Shimizu |
890ddd |
if (hue < 0)
|
|
Toshihiro Shimizu |
890ddd |
hue += (1 - (int)hue / 360) * 360;
|
|
Toshihiro Shimizu |
890ddd |
//hue+=360;
|
|
Toshihiro Shimizu |
890ddd |
if (sat < 0)
|
|
Toshihiro Shimizu |
890ddd |
sat = 0;
|
|
Toshihiro Shimizu |
890ddd |
if (sat > 1)
|
|
Toshihiro Shimizu |
890ddd |
sat = 1;
|
|
Toshihiro Shimizu |
890ddd |
if (value < 0)
|
|
Toshihiro Shimizu |
890ddd |
value = 0;
|
|
Toshihiro Shimizu |
890ddd |
if (value > 1)
|
|
Toshihiro Shimizu |
890ddd |
value = 1;
|
|
Toshihiro Shimizu |
890ddd |
if (sat == 0) {
|
|
Toshihiro Shimizu |
890ddd |
*red = value;
|
|
Toshihiro Shimizu |
890ddd |
*green = value;
|
|
Toshihiro Shimizu |
890ddd |
*blue = value;
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
if (hue == 360)
|
|
Toshihiro Shimizu |
890ddd |
hue = 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
hue = hue / 60;
|
|
Toshihiro Shimizu |
890ddd |
i = (int)hue;
|
|
Toshihiro Shimizu |
890ddd |
f = hue - i;
|
|
Toshihiro Shimizu |
890ddd |
p = value * (1 - sat);
|
|
Toshihiro Shimizu |
890ddd |
q = value * (1 - (sat * f));
|
|
Toshihiro Shimizu |
890ddd |
t = value * (1 - (sat * (1 - f)));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
switch (i) {
|
|
Toshihiro Shimizu |
890ddd |
CASE 0 :
|
|
Toshihiro Shimizu |
890ddd |
*red = value;
|
|
Toshihiro Shimizu |
890ddd |
*green = t;
|
|
Toshihiro Shimizu |
890ddd |
*blue = p;
|
|
Toshihiro Shimizu |
890ddd |
CASE 1 :
|
|
Toshihiro Shimizu |
890ddd |
*red = q;
|
|
Toshihiro Shimizu |
890ddd |
*green = value;
|
|
Toshihiro Shimizu |
890ddd |
*blue = p;
|
|
Toshihiro Shimizu |
890ddd |
CASE 2 :
|
|
Toshihiro Shimizu |
890ddd |
*red = p;
|
|
Toshihiro Shimizu |
890ddd |
*green = value;
|
|
Toshihiro Shimizu |
890ddd |
*blue = t;
|
|
Toshihiro Shimizu |
890ddd |
CASE 3 :
|
|
Toshihiro Shimizu |
890ddd |
*red = p;
|
|
Toshihiro Shimizu |
890ddd |
*green = q;
|
|
Toshihiro Shimizu |
890ddd |
*blue = value;
|
|
Toshihiro Shimizu |
890ddd |
CASE 4 :
|
|
Toshihiro Shimizu |
890ddd |
*red = t;
|
|
Toshihiro Shimizu |
890ddd |
*green = p;
|
|
Toshihiro Shimizu |
890ddd |
*blue = value;
|
|
Toshihiro Shimizu |
890ddd |
CASE 5 :
|
|
Toshihiro Shimizu |
890ddd |
*red = value;
|
|
Toshihiro Shimizu |
890ddd |
*green = p;
|
|
Toshihiro Shimizu |
890ddd |
*blue = q;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|