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 *======================================================*/
15 #pragma implementation
18 #include <algorithm> // max
19 #include <cmath> // floor
25 static int const nohue = -1;
27 RGB::RGB( HSV const & hsv )
35 if( h == nohue || s == 0.0 ) {
38 if( h == 360.0 ) h = 0.0;
41 int j = static_cast<int>( ::floor(h) );
45 double p = v * (1.0 - s);
46 double q = v * (1.0 - (s*f));
47 double t = v * (1.0 - (s*(1.0 - f)));
84 break; // should never happen.
88 r = static_cast<int>( ::floor((rd * 255.0) + 0.5) );
89 g = static_cast<int>( ::floor((gd * 255.0) + 0.5) );
90 b = static_cast<int>( ::floor((bd * 255.0) + 0.5) );
94 HSV::HSV( RGB const & rgb )
96 // r, g, b lie in the range 0-1, not 0-255.
97 double r = rgb.r / 255.0;
98 double g = rgb.g / 255.0;
99 double b = rgb.b / 255.0;
101 double maxval = max( max( r, g ), b );
102 double minval = max( min( r, g ), b );
106 double diff = maxval - minval;
114 double rc = (maxval - r) / diff;
115 double gc = (maxval - g) / diff;
116 double bc = (maxval - b) / diff;
120 else if( g == maxval )
122 else if( b == maxval )