X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fxforms%2FColor.C;h=ec269bb95f225f496a62cb00ee843270d64c97f8;hb=eba67bc3120dc301bf193c3f3b570f51f00a4654;hp=e69f91fe000f276e0aca596d6c41bf5cad6e1e04;hpb=0c978e6a3fb133c97d95e87715add6bae26f7837;p=lyx.git diff --git a/src/frontends/xforms/Color.C b/src/frontends/xforms/Color.C index e69f91fe00..ec269bb95f 100644 --- a/src/frontends/xforms/Color.C +++ b/src/frontends/xforms/Color.C @@ -10,6 +10,7 @@ *======================================================*/ #include +#include FORMS_H_LOCATION #ifdef __GNUG_ #pragma implementation @@ -24,29 +25,29 @@ using std::min; static int const nohue = -1; -RGB::RGB( HSV const & hsv ) +RGBColor::RGBColor(HSVColor const & hsv) { double h = hsv.h; - double s = hsv.s; - double v = hsv.v; + double const s = hsv.s; + double const v = hsv.v; double rd, gd, bd; - if( h == nohue || s == 0.0 ) { + if (h == nohue || s == 0.0) { rd = gd = bd = v; } else { - if( h == 360.0 ) h = 0.0; + if (h == 360.0) h = 0.0; h /= 60.0; - int j = static_cast( ::floor(h) ); - if( j < 0 ) j = 0; + int const j = max(0, static_cast(::floor(h))); + //if( j < 0 ) j = 0; - double f = h - j; - double p = v * (1.0 - s); - double q = v * (1.0 - (s*f)); - double t = v * (1.0 - (s*(1.0 - f))); + double const f = h - j; + double const p = v * (1.0 - s); + double const q = v * (1.0 - (s * f)); + double const t = v * (1.0 - (s * (1.0 - f))); - switch( j ) { + switch (j) { case 0: rd = v; gd = t; @@ -91,40 +92,38 @@ RGB::RGB( HSV const & hsv ) } -HSV::HSV( RGB const & rgb ) +HSVColor::HSVColor(RGBColor const & rgb) { - // r, g, b lie in the range 0-1, not 0-255. - double r = rgb.r / 255.0; - double g = rgb.g / 255.0; - double b = rgb.b / 255.0; + double const r = rgb.r / 255.0; + double const g = rgb.g / 255.0; + double const b = rgb.b / 255.0; - double maxval = max( max( r, g ), b ); - double minval = max( min( r, g ), b ); + double const maxval = max( max( r, g ), b ); + double const minval = min( min( r, g ), b ); v = maxval; - double diff = maxval - minval; - if( maxval != 0.0 ) + double const diff = maxval - minval; + if (maxval != 0.0) s = diff / maxval; else s = 0.0; h = nohue; - if( s != 0.0 ) { - double rc = (maxval - r) / diff; - double gc = (maxval - g) / diff; - double bc = (maxval - b) / diff; + if (s != 0.0) { + double const rc = (maxval - r) / diff; + double const gc = (maxval - g) / diff; + double const bc = (maxval - b) / diff; - if( r == maxval ) + if (r == maxval) h = bc - gc; - else if( g == maxval ) + else if (g == maxval) h = 2.0 + rc - bc; - else if( b == maxval ) + else if (b == maxval) h = 4.0 + gc - rc; h *= 60.0; - if ( h < 0 ) + if (h < 0) h += 360; } } -