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
36 bool getRGBColor(LColor::color col,
37 unsigned int & r, unsigned int & g, unsigned int & b)
39 string const name = lcolor.getX11Name(col);
40 Display * const display = fl_get_display();
41 Colormap const cmap = fl_state[fl_get_vclass()].colormap;
44 if (XLookupColor(display, cmap, name.c_str(), &xcol, &ccol) == 0) {
58 RGBColor::RGBColor(HSVColor const & hsv)
61 double const s = hsv.s;
62 double const v = hsv.v;
66 if (h == nohue || s == 0.0) {
69 if (h == 360.0) h = 0.0;
72 int const j = max(0, static_cast<int>(::floor(h)));
75 double const f = h - j;
76 double const p = v * (1.0 - s);
77 double const q = v * (1.0 - (s * f));
78 double const t = v * (1.0 - (s * (1.0 - f)));
115 break; // should never happen.
119 r = static_cast<int>(::floor((rd * 255.0) + 0.5));
120 g = static_cast<int>(::floor((gd * 255.0) + 0.5));
121 b = static_cast<int>(::floor((bd * 255.0) + 0.5));
125 HSVColor::HSVColor(RGBColor const & rgb)
127 double const r = rgb.r / 255.0;
128 double const g = rgb.g / 255.0;
129 double const b = rgb.b / 255.0;
131 double const maxval = max(max(r, g), b);
132 double const minval = min(min(r, g), b);
136 double const diff = maxval - minval;
144 double const rc = (maxval - r) / diff;
145 double const gc = (maxval - g) / diff;
146 double const bc = (maxval - b) / diff;
150 else if (g == maxval)
152 else if (b == maxval)