2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1995 Matthias Ettrich
8 * Copyright 1995-2000 The LyX Team.
10 *======================================================*/
14 #include <algorithm> // max
15 #include <cmath> // floor
17 #include FORMS_H_LOCATION
20 #pragma implementation
28 static int const nohue = -1;
30 RGBColor::RGBColor(HSVColor const & hsv)
33 double const s = hsv.s;
34 double const v = hsv.v;
38 if (h == nohue || s == 0.0) {
41 if (h == 360.0) h = 0.0;
44 int const j = max(0, static_cast<int>(::floor(h)));
47 double const f = h - j;
48 double const p = v * (1.0 - s);
49 double const q = v * (1.0 - (s * f));
50 double const t = v * (1.0 - (s * (1.0 - f)));
87 break; // should never happen.
91 r = static_cast<int>( ::floor((rd * 255.0) + 0.5) );
92 g = static_cast<int>( ::floor((gd * 255.0) + 0.5) );
93 b = static_cast<int>( ::floor((bd * 255.0) + 0.5) );
97 HSVColor::HSVColor(RGBColor const & rgb)
99 double const r = rgb.r / 255.0;
100 double const g = rgb.g / 255.0;
101 double const b = rgb.b / 255.0;
103 double const maxval = max( max( r, g ), b );
104 double const minval = min( min( r, g ), b );
108 double const diff = maxval - minval;
116 double const rc = (maxval - r) / diff;
117 double const gc = (maxval - g) / diff;
118 double const bc = (maxval - b) / diff;
122 else if (g == maxval)
124 else if (b == maxval)