3 * Read the file COPYING
5 * \author Angus Leeming
7 * Full author contact details are available in file CREDITS
13 #pragma implementation
17 #include <algorithm> // max
18 #include <cmath> // floor
19 #include FORMS_H_LOCATION
21 #ifndef CXX_GLOBAL_CSTD
34 RGBColor::RGBColor(HSVColor const & hsv)
37 double const s = hsv.s;
38 double const v = hsv.v;
42 if (h == nohue || s == 0.0) {
45 if (h == 360.0) h = 0.0;
48 int const j = max(0, static_cast<int>(::floor(h)));
51 double const f = h - j;
52 double const p = v * (1.0 - s);
53 double const q = v * (1.0 - (s * f));
54 double const t = v * (1.0 - (s * (1.0 - f)));
91 break; // should never happen.
95 r = static_cast<int>(::floor((rd * 255.0) + 0.5));
96 g = static_cast<int>(::floor((gd * 255.0) + 0.5));
97 b = static_cast<int>(::floor((bd * 255.0) + 0.5));
101 HSVColor::HSVColor(RGBColor const & rgb)
103 double const r = rgb.r / 255.0;
104 double const g = rgb.g / 255.0;
105 double const b = rgb.b / 255.0;
107 double const maxval = max(max(r, g), b);
108 double const minval = min(min(r, g), b);
112 double const diff = maxval - minval;
120 double const rc = (maxval - r) / diff;
121 double const gc = (maxval - g) / diff;
122 double const bc = (maxval - b) / diff;
126 else if (g == maxval)
128 else if (b == maxval)