Main Page | File List

RGB.h

Go to the documentation of this file.
00001 /**
00002  *\file         RGB.h
00003  *
00004  *\brief        RGB class wrapping pixel color-triple: red, green, and blue.
00005  *
00006  *              Each rgb component is of a float value in [<b><var>0.0, 1.0</var></b>].
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); }   //non const method: return lvalue
00028       float operator[](int idx) const          { return *(rgb+idx); }   //const method: return rvalue
00029 
00030       RGB& operator*=(float scale)             { for(int i=0; i<3; i++) rgb[i] *= scale; return *this; }
00031       RGB operator*(float scale) const         { RGB ret(*this); return ret *= scale; }
00032 
00033       RGB& operator+=(RGB const& rhs)          { for(int i=0; i<3; i++) rgb[i] += rhs[i]; return *this; }
00034       RGB operator+(RGB const& rhs) const      { RGB ret(*this); return ret+=rhs; }
00035   };
00036 
00037   inline ostream& operator << (ostream& os, RGB const& rgb)
00038   {
00039     return os << "(" << rgb[0] << ", " << rgb[1] << ", " << rgb[2] << ",)";
00040   }
00041   
00042 
00043 }//end namespace columbia
00044 
00045 
00046 #endif

Generated on Wed Jul 14 19:41:15 2004 by doxygen 1.3.6