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.
21 #ifndef CXX_GLOBAL_CSTD
29 using std::istringstream;
30 using std::ostringstream;
39 int hexstrToInt(string const & str)
42 istringstream is(str);
43 is >> std::setbase(16) >> val;
51 string const X11hexname(RGBColor const & col)
55 ostr << '#' << std::setbase(16) << std::setfill('0')
64 RGBColor::RGBColor(string const & x11hexname)
67 BOOST_ASSERT(x11hexname.size() == 7 && x11hexname[0] == '#');
68 r = hexstrToInt(x11hexname.substr(1,2));
69 g = hexstrToInt(x11hexname.substr(3,2));
70 b = hexstrToInt(x11hexname.substr(5,2));
74 RGBColor::RGBColor(HSVColor const & hsv)
77 double const s = hsv.s;
78 double const v = hsv.v;
82 if (h == nohue || s == 0.0) {
85 if (h == 360.0) h = 0.0;
88 int const j = max(0, static_cast<int>(::floor(h)));
91 double const f = h - j;
92 double const p = v * (1.0 - s);
93 double const q = v * (1.0 - (s * f));
94 double const t = v * (1.0 - (s * (1.0 - f)));
131 break; // should never happen.
135 r = static_cast<int>(::floor((rd * 255.0) + 0.5));
136 g = static_cast<int>(::floor((gd * 255.0) + 0.5));
137 b = static_cast<int>(::floor((bd * 255.0) + 0.5));
141 HSVColor::HSVColor(RGBColor const & rgb)
143 double const r = rgb.r / 255.0;
144 double const g = rgb.g / 255.0;
145 double const b = rgb.b / 255.0;
147 double const maxval = max(max(r, g), b);
148 double const minval = min(min(r, g), b);
152 double const diff = maxval - minval;
160 double const rc = (maxval - r) / diff;
161 double const gc = (maxval - g) / diff;
162 double const bc = (maxval - b) / diff;
166 else if (g == maxval)
168 else if (b == maxval)