3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Angus Leeming
8 * Full author contact details are available in file CREDITS
14 #pragma implementation
18 #include <algorithm> // max
19 #include <cmath> // floor
20 #include FORMS_H_LOCATION
22 #ifndef CXX_GLOBAL_CSTD
35 RGBColor::RGBColor(HSVColor const & hsv)
38 double const s = hsv.s;
39 double const v = hsv.v;
43 if (h == nohue || s == 0.0) {
46 if (h == 360.0) h = 0.0;
49 int const j = max(0, static_cast<int>(::floor(h)));
52 double const f = h - j;
53 double const p = v * (1.0 - s);
54 double const q = v * (1.0 - (s * f));
55 double const t = v * (1.0 - (s * (1.0 - f)));
92 break; // should never happen.
96 r = static_cast<int>(::floor((rd * 255.0) + 0.5));
97 g = static_cast<int>(::floor((gd * 255.0) + 0.5));
98 b = static_cast<int>(::floor((bd * 255.0) + 0.5));
102 HSVColor::HSVColor(RGBColor const & rgb)
104 double const r = rgb.r / 255.0;
105 double const g = rgb.g / 255.0;
106 double const b = rgb.b / 255.0;
108 double const maxval = max(max(r, g), b);
109 double const minval = min(min(r, g), b);
113 double const diff = maxval - minval;
121 double const rc = (maxval - r) / diff;
122 double const gc = (maxval - g) / diff;
123 double const bc = (maxval - b) / diff;
127 else if (g == maxval)
129 else if (b == maxval)