00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef _RGB_H
00012 #define _RGB_H
00013
00014 #include <iostream>
00015 #include <algorithm>
00016
00017 using namespace std;
00018
00019 class RGB
00020 {
00021 float rgb[3];
00022
00023 public:
00024 RGB(float r=0., float g=0., float b=0.) { rgb[0] = r; rgb[1] = g; rgb[2] = b; }
00025 RGB(float* ptr) { copy(ptr, ptr+3, rgb); }
00026
00027
00028 float& operator[](int idx) { return *(rgb+idx); }
00029 float operator[](int idx) const { return *(rgb+idx); }
00030
00031 RGB& operator*=(RGB const& rhs) { for(int i=0; i<3; i++) rgb[i] *= rhs[i]; return *this; }
00032 RGB operator*(RGB const&rhs) const { RGB ret(*this); return ret *= rhs; }
00033
00034 RGB& operator*=(float scale) { for(int i=0; i<3; i++) rgb[i] *= scale; return *this; }
00035 RGB operator*(float scale) const { RGB ret(*this); return ret *= scale; }
00036
00037 RGB& operator/=(float scale) { for(int i=0; i<3; i++) rgb[i] /= scale; return *this; }
00038 RGB operator/(float scale) const { RGB ret(*this); return ret /= scale; }
00039
00040 RGB& operator+=(RGB const& rhs) { for(int i=0; i<3; i++) rgb[i] += rhs[i]; return *this; }
00041 RGB operator+(RGB const& rhs) const { RGB ret(*this); return ret+=rhs; }
00042
00043 RGB& operator-=(RGB const& rhs) { for(int i=0; i<3; i++) rgb[i] -= rhs[i]; return *this; }
00044 RGB operator-(RGB const& rhs) const { RGB ret(*this); return ret-=rhs; }
00045
00046 bool operator==(RGB const& rhs) const { return equal(rgb, rgb+3, rhs.rgb); }
00047 bool operator!=(RGB const& rhs) const { return ! ( (*this) == rhs ); }
00048
00049 friend ostream& operator << (ostream& os, RGB const& rgb) { return os << "(" << rgb[0] << ", " << rgb[1] << ", " << rgb[2] << ")"; }
00050 };
00051
00052
00053 #endif