1 #ifndef colors_HSV_Space_H__
2 #define colors_HSV_Space_H__
5 #include "../geo/Vectors.h"
10 #include "../math/utility.h"
42 double const&
hsvMin(
size_t i)
const {
return min(i); }
43 double const&
hMin( )
const {
return min(0); }
44 double const&
sMin( )
const {
return min(1); }
45 double const&
vMin( )
const {
return min(2); }
46 double const&
hsvMax(
size_t i)
const {
return max(i); }
47 double const&
hMax( )
const {
return max(0); }
48 double const&
sMax( )
const {
return max(1); }
49 double const&
vMax( )
const {
return max(2); }
50 double const&
hsv(
size_t i)
const {
return val(i); }
51 double const&
h( )
const {
return hsv(0); }
52 double const&
s( )
const {
return hsv(1); }
53 double const&
v( )
const {
return hsv(2); }
54 double const&
hsv(
size_t i,
double c) {
return val(i, c); }
55 double const&
h(
double c) {
return hsv(0, c); }
56 double const&
s(
double c) {
return hsv(1, c); }
57 double const&
v(
double c) {
return hsv(2, c); }
90 double mx = std::max(std::max(r, g), b);
91 double mn = std::min(std::min(r, g), b);
94 else if(mx == r && g >= b) h =
PI/3.0 * (g-b) / (mx-mn);
95 else if(mx == r && g < b) h =
PI/3.0 * (g-b) / (mx-mn) +
PI * 2.0;
96 else if(mx == g ) h =
PI/3.0 * (b-r) / (mx-mn) +
PI/3.0*2.0;
97 else h =
PI/3.0 * (r-g) / (mx-mn) +
PI/3.0*4.0;
131 int hi = (
int)h / 60 % 6;
132 double f = h / 60.0 - hi;
133 double p = v * (1 - s);
134 double q = v * (1 - f * s);
135 double t = v * (1 - (1 - f) * s);
137 if (hi == 0){ r = v; g = t; b = p; }
138 else if(hi == 1){ r = q; g = v; b = p; }
139 else if(hi == 2){ r = p; g = v; b = t; }
140 else if(hi == 3){ r = p; g = q; b = v; }
141 else if(hi == 4){ r = t; g = p; b = v; }
142 else { r = v; g = p; b = q; }
188 #endif // colors_HSV_Space_H__