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
15 #include <algorithm> // max
16 #include <cmath> // floor
17 #include "lyx_forms.h"
19 #ifndef CXX_GLOBAL_CSTD
33 bool getRGBColor(LColor::color col,
34 unsigned int & r, unsigned int & g, unsigned int & b)
36 string const name = lcolor.getX11Name(col);
37 Display * const display = fl_get_display();
38 Colormap const cmap = fl_state[fl_get_vclass()].colormap;
41 if (XLookupColor(display, cmap, name.c_str(), &xcol, &ccol) == 0) {
55 RGBColor::RGBColor(HSVColor const & hsv)
58 double const s = hsv.s;
59 double const v = hsv.v;
63 if (h == nohue || s == 0.0) {
66 if (h == 360.0) h = 0.0;
69 int const j = max(0, static_cast<int>(::floor(h)));
72 double const f = h - j;
73 double const p = v * (1.0 - s);
74 double const q = v * (1.0 - (s * f));
75 double const t = v * (1.0 - (s * (1.0 - f)));
112 break; // should never happen.
116 r = static_cast<int>(::floor((rd * 255.0) + 0.5));
117 g = static_cast<int>(::floor((gd * 255.0) + 0.5));
118 b = static_cast<int>(::floor((bd * 255.0) + 0.5));
122 HSVColor::HSVColor(RGBColor const & rgb)
124 double const r = rgb.r / 255.0;
125 double const g = rgb.g / 255.0;
126 double const b = rgb.b / 255.0;
128 double const maxval = max(max(r, g), b);
129 double const minval = min(min(r, g), b);
133 double const diff = maxval - minval;
141 double const rc = (maxval - r) / diff;
142 double const gc = (maxval - g) / diff;
143 double const bc = (maxval - b) / diff;
147 else if (g == maxval)
149 else if (b == maxval)