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 *======================================================*/
13 #include FORMS_H_LOCATION
16 #pragma implementation
19 #include <algorithm> // max
20 #include <cmath> // floor
26 static int const nohue = -1;
28 RGBColor::RGBColor(HSVColor const & hsv)
31 double const s = hsv.s;
32 double const v = hsv.v;
36 if (h == nohue || s == 0.0) {
39 if (h == 360.0) h = 0.0;
42 int const j = max(0, static_cast<int>(::floor(h)));
45 double const f = h - j;
46 double const p = v * (1.0 - s);
47 double const q = v * (1.0 - (s * f));
48 double const t = v * (1.0 - (s * (1.0 - f)));
85 break; // should never happen.
89 r = static_cast<int>( ::floor((rd * 255.0) + 0.5) );
90 g = static_cast<int>( ::floor((gd * 255.0) + 0.5) );
91 b = static_cast<int>( ::floor((bd * 255.0) + 0.5) );
95 HSVColor::HSVColor(RGBColor const & rgb)
97 double const r = rgb.r / 255.0;
98 double const g = rgb.g / 255.0;
99 double const b = rgb.b / 255.0;
101 double const maxval = max( max( r, g ), b );
102 double const minval = min( min( r, g ), b );
106 double const diff = maxval - minval;
114 double const rc = (maxval - r) / diff;
115 double const gc = (maxval - g) / diff;
116 double const bc = (maxval - b) / diff;
120 else if (g == maxval)
122 else if (b == maxval)