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 "lyx_forms.h"
19 #include "support/std_sstream.h"
25 #ifndef CXX_GLOBAL_CSTD
33 using std::istringstream;
34 using std::ostringstream;
42 int hexstrToInt(string const & str)
45 istringstream is(str);
46 is >> std::setbase(16) >> val;
54 bool getRGBColor(LColor_color col,
55 unsigned int & r, unsigned int & g, unsigned int & b)
57 string const name = lcolor.getX11Name(col);
58 Display * const display = fl_get_display();
59 Colormap const cmap = fl_state[fl_get_vclass()].colormap;
62 if (XLookupColor(display, cmap, name.c_str(), &xcol, &ccol) == 0) {
76 string const X11hexname(RGBColor const & col)
80 ostr << '#' << std::setbase(16) << std::setfill('0')
89 RGBColor::RGBColor(string const & x11hexname)
92 BOOST_ASSERT(x11hexname.size() == 7 && x11hexname[0] == '#');
93 r = hexstrToInt(x11hexname.substr(1,2));
94 g = hexstrToInt(x11hexname.substr(3,2));
95 b = hexstrToInt(x11hexname.substr(5,2));
99 RGBColor::RGBColor(HSVColor const & hsv)
102 double const s = hsv.s;
103 double const v = hsv.v;
107 if (h == nohue || s == 0.0) {
110 if (h == 360.0) h = 0.0;
113 int const j = max(0, static_cast<int>(::floor(h)));
116 double const f = h - j;
117 double const p = v * (1.0 - s);
118 double const q = v * (1.0 - (s * f));
119 double const t = v * (1.0 - (s * (1.0 - f)));
156 break; // should never happen.
160 r = static_cast<int>(::floor((rd * 255.0) + 0.5));
161 g = static_cast<int>(::floor((gd * 255.0) + 0.5));
162 b = static_cast<int>(::floor((bd * 255.0) + 0.5));
166 HSVColor::HSVColor(RGBColor const & rgb)
168 double const r = rgb.r / 255.0;
169 double const g = rgb.g / 255.0;
170 double const b = rgb.b / 255.0;
172 double const maxval = max(max(r, g), b);
173 double const minval = min(min(r, g), b);
177 double const diff = maxval - minval;
185 double const rc = (maxval - r) / diff;
186 double const gc = (maxval - g) / diff;
187 double const bc = (maxval - b) / diff;
191 else if (g == maxval)
193 else if (b == maxval)