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