1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2001 The LyX Team.
9 *======================================================*/
13 #include <algorithm> // max
14 #include <cmath> // floor
16 #include FORMS_H_LOCATION
19 #pragma implementation
33 RGBColor::RGBColor(HSVColor const & hsv)
36 double const s = hsv.s;
37 double const v = hsv.v;
41 if (h == nohue || s == 0.0) {
44 if (h == 360.0) h = 0.0;
47 int const j = max(0, static_cast<int>(::floor(h)));
50 double const f = h - j;
51 double const p = v * (1.0 - s);
52 double const q = v * (1.0 - (s * f));
53 double const t = v * (1.0 - (s * (1.0 - f)));
90 break; // should never happen.
94 r = static_cast<int>( ::floor((rd * 255.0) + 0.5) );
95 g = static_cast<int>( ::floor((gd * 255.0) + 0.5) );
96 b = static_cast<int>( ::floor((bd * 255.0) + 0.5) );
100 HSVColor::HSVColor(RGBColor const & rgb)
102 double const r = rgb.r / 255.0;
103 double const g = rgb.g / 255.0;
104 double const b = rgb.b / 255.0;
106 double const maxval = max( max( r, g ), b );
107 double const minval = min( min( r, g ), b );
111 double const diff = maxval - minval;
119 double const rc = (maxval - r) / diff;
120 double const gc = (maxval - g) / diff;
121 double const bc = (maxval - b) / diff;
125 else if (g == maxval)
127 else if (b == maxval)