/* $Id: color.cpp,v 1.3 2005/06/28 13:55:18 chfreund Exp $ */ /******************************************************************************/ #include "color.hpp" /******************************************************************************/ Uint32 Color::HSVToUint32( const real h, const real s, const real v ) { const real h2 = (h - (int)( h )) * 6.0; const int l = (int) h2; const real f = h2 - l, m = v*(1.0-s), n = v*(1.0-(s*f)), i = v*(1.0-(s*(1.0-f))); Uint32 color; switch (l) { case 0: color = ((((Uint8) (255.0*v) << 8) | (Uint8) (255.0*i)) << 8) | (Uint8) (255.0*m); break; case 1: color = ((((Uint8) (255.0*n) << 8) | (Uint8) (255.0*v)) << 8) | (Uint8) (255.0*m); break; case 2: color = ((((Uint8) (255.0*m) << 8) | (Uint8) (255.0*v)) << 8) | (Uint8) (255.0*i); break; case 3: color = ((((Uint8) (255.0*m) << 8) | (Uint8) (255.0*n)) << 8) | (Uint8) (255.0*v); break; case 4: color = ((((Uint8) (255.0*i) << 8) | (Uint8) (255.0*m)) << 8) | (Uint8) (255.0*v); break; default: color = ((((Uint8) (255.0*v) << 8) | (Uint8) (255.0*m)) << 8) | (Uint8) (255.0*n); break; } return color; } /******************************************************************************/