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"
17 #include "support/std_sstream.h"
23 #ifndef CXX_GLOBAL_CSTD
31 using std::istringstream;
32 using std::ostringstream;
39 int hexstrToInt(string const & str)
42 istringstream is(str);
43 is >> std::setbase(16) >> val;
51 bool getRGBColor(LColor::color col,
52 unsigned int & r, unsigned int & g, unsigned int & b)
54 string const name = lcolor.getX11Name(col);
55 Display * const display = fl_get_display();
56 Colormap const cmap = fl_state[fl_get_vclass()].colormap;
59 if (XLookupColor(display, cmap, name.c_str(), &xcol, &ccol) == 0) {
73 string const X11hexname(RGBColor const & col)
77 ostr << '#' << std::setbase(16) << std::setfill('0')
86 RGBColor::RGBColor(string const & x11hexname)
89 BOOST_ASSERT(x11hexname.size() == 7 && x11hexname[0] == '#');
90 r = hexstrToInt(x11hexname.substr(1,2));
91 g = hexstrToInt(x11hexname.substr(3,2));
92 b = hexstrToInt(x11hexname.substr(5,2));
96 RGBColor::RGBColor(HSVColor const & hsv)
99 double const s = hsv.s;
100 double const v = hsv.v;
104 if (h == nohue || s == 0.0) {
107 if (h == 360.0) h = 0.0;
110 int const j = max(0, static_cast<int>(::floor(h)));
113 double const f = h - j;
114 double const p = v * (1.0 - s);
115 double const q = v * (1.0 - (s * f));
116 double const t = v * (1.0 - (s * (1.0 - f)));
153 break; // should never happen.
157 r = static_cast<int>(::floor((rd * 255.0) + 0.5));
158 g = static_cast<int>(::floor((gd * 255.0) + 0.5));
159 b = static_cast<int>(::floor((bd * 255.0) + 0.5));
163 HSVColor::HSVColor(RGBColor const & rgb)
165 double const r = rgb.r / 255.0;
166 double const g = rgb.g / 255.0;
167 double const b = rgb.b / 255.0;
169 double const maxval = max(max(r, g), b);
170 double const minval = min(min(r, g), b);
174 double const diff = maxval - minval;
182 double const rc = (maxval - r) / diff;
183 double const gc = (maxval - g) / diff;
184 double const bc = (maxval - b) / diff;
188 else if (g == maxval)
190 else if (b == maxval)