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"
24 #ifndef CXX_GLOBAL_CSTD
32 using std::istringstream;
33 using std::ostringstream;
43 int hexstrToInt(string const & str)
46 istringstream is(str);
47 is >> std::setbase(16) >> val;
55 bool getRGBColor(LColor_color col,
56 unsigned int & r, unsigned int & g, unsigned int & b)
58 string const name = lcolor.getX11Name(col);
59 Display * const display = fl_get_display();
60 Colormap const cmap = fl_state[fl_get_vclass()].colormap;
63 if (XLookupColor(display, cmap, name.c_str(), &xcol, &ccol) == 0) {
77 string const X11hexname(RGBColor const & col)
81 ostr << '#' << std::setbase(16) << std::setfill('0')
90 RGBColor::RGBColor(string const & x11hexname)
93 BOOST_ASSERT(x11hexname.size() == 7 && x11hexname[0] == '#');
94 r = hexstrToInt(x11hexname.substr(1,2));
95 g = hexstrToInt(x11hexname.substr(3,2));
96 b = hexstrToInt(x11hexname.substr(5,2));
100 RGBColor::RGBColor(HSVColor const & hsv)
103 double const s = hsv.s;
104 double const v = hsv.v;
108 if (h == nohue || s == 0.0) {
111 if (h == 360.0) h = 0.0;
114 int const j = max(0, static_cast<int>(::floor(h)));
117 double const f = h - j;
118 double const p = v * (1.0 - s);
119 double const q = v * (1.0 - (s * f));
120 double const t = v * (1.0 - (s * (1.0 - f)));
157 break; // should never happen.
161 r = static_cast<int>(::floor((rd * 255.0) + 0.5));
162 g = static_cast<int>(::floor((gd * 255.0) + 0.5));
163 b = static_cast<int>(::floor((bd * 255.0) + 0.5));
167 HSVColor::HSVColor(RGBColor const & rgb)
169 double const r = rgb.r / 255.0;
170 double const g = rgb.g / 255.0;
171 double const b = rgb.b / 255.0;
173 double const maxval = max(max(r, g), b);
174 double const minval = min(min(r, g), b);
178 double const diff = maxval - minval;
186 double const rc = (maxval - r) / diff;
187 double const gc = (maxval - g) / diff;
188 double const bc = (maxval - b) / diff;
192 else if (g == maxval)
194 else if (b == maxval)
203 } // namespace frontend