22 #ifndef _COLOR_H2397_INCLUDED_
23 #define _COLOR_H2397_INCLUDED_
35 Color(
float _x,
float _y,
float _z) : r(_x), g(_y), b(_z) { };
37 Color(
const unsigned char *c) : r((float)c[0]/255.0f), g((float)c[1]/255.0f), b((float)c[2]/255.0f) { }
39 inline float length()
const {
return sqrtf(r*r + g*g + b*b); }
42 inline float avg()
const {
return (r + g + b)/3.0f; }
49 inline void clampTop() {
if (r>1) r=1;
if (g>1) g=1;
if (b>1) b=1; }
50 inline void clampBottom() {
if (r<0) r=0;
if (g<0) g=0;
if (b<0) b=0; }
73 inline bool equalsTheta (
const Color& v,
float theta) {
return ((fabs(v.
r-r)<theta) && (fabs(v.
g-g)<theta) && (fabs(v.
b-b)<theta)); }
78 inline void toHSV(
float *h,
float *s,
float *v ) {
79 float min, max, delta;
94 *h = ( g -
b ) / delta;
96 *h = 2 + ( b -
r ) / delta;
98 *h = 4 + ( r -
g ) / delta;
119 q = v * ( 1 - s * f );
120 t = v * ( 1 - s * ( 1 - f ) );
Color & operator+=(const Color &v)
Color & operator*=(float f)
Color compProduct(const Color &cl)
static Color fromHSV(float h, float s, float v)
bool equalsTheta(const Color &v, float theta)
friend Color operator*(const Color &v, float f)
Color & operator/=(float f)
bool operator==(const Color &v)
bool operator!=(const Color &v)
friend Color operator+(const Color &v1, const Color &v2)
Color & operator-=(const Color &v)
Color(float _x, float _y, float _z)
friend Color operator/(const Color &v, float f)
void toHSV(float *h, float *s, float *v)
Color(const unsigned char *c)
friend Color operator-(const Color &v)