3 * Copyright 2002 the LyX Team
4 * Read the file COPYING
6 * \author Angus Leeming, a.leeming@ic.ac.uk
12 #pragma implementation
16 #include <algorithm> // max
17 #include <cmath> // floor
18 #include FORMS_H_LOCATION
29 RGBColor::RGBColor(HSVColor const & hsv)
32 double const s = hsv.s;
33 double const v = hsv.v;
37 if (h == nohue || s == 0.0) {
40 if (h == 360.0) h = 0.0;
43 int const j = max(0, static_cast<int>(::floor(h)));
46 double const f = h - j;
47 double const p = v * (1.0 - s);
48 double const q = v * (1.0 - (s * f));
49 double const t = v * (1.0 - (s * (1.0 - f)));
86 break; // should never happen.
90 r = static_cast<int>(::floor((rd * 255.0) + 0.5));
91 g = static_cast<int>(::floor((gd * 255.0) + 0.5));
92 b = static_cast<int>(::floor((bd * 255.0) + 0.5));
96 HSVColor::HSVColor(RGBColor const & rgb)
98 double const r = rgb.r / 255.0;
99 double const g = rgb.g / 255.0;
100 double const b = rgb.b / 255.0;
102 double const maxval = max( max( r, g), b);
103 double const minval = min( min( r, g), b);
107 double const diff = maxval - minval;
115 double const rc = (maxval - r) / diff;
116 double const gc = (maxval - g) / diff;
117 double const bc = (maxval - b) / diff;
121 else if (g == maxval)
123 else if (b == maxval)