2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1995 Matthias Ettrich
8 * Copyright 1995-2001 The LyX Team.
10 *======================================================*/
14 #include <algorithm> // max
15 #include <cmath> // floor
17 #include FORMS_H_LOCATION
20 #pragma implementation
34 RGBColor::RGBColor(HSVColor const & hsv)
37 double const s = hsv.s;
38 double const v = hsv.v;
42 if (h == nohue || s == 0.0) {
45 if (h == 360.0) h = 0.0;
48 int const j = max(0, static_cast<int>(::floor(h)));
51 double const f = h - j;
52 double const p = v * (1.0 - s);
53 double const q = v * (1.0 - (s * f));
54 double const t = v * (1.0 - (s * (1.0 - f)));
91 break; // should never happen.
95 r = static_cast<int>( ::floor((rd * 255.0) + 0.5) );
96 g = static_cast<int>( ::floor((gd * 255.0) + 0.5) );
97 b = static_cast<int>( ::floor((bd * 255.0) + 0.5) );
101 HSVColor::HSVColor(RGBColor const & rgb)
103 double const r = rgb.r / 255.0;
104 double const g = rgb.g / 255.0;
105 double const b = rgb.b / 255.0;
107 double const maxval = max( max( r, g ), b );
108 double const minval = min( min( r, g ), b );
112 double const diff = maxval - minval;
120 double const rc = (maxval - r) / diff;
121 double const gc = (maxval - g) / diff;
122 double const bc = (maxval - b) / diff;
126 else if (g == maxval)
128 else if (b == maxval)