ColorSpace.h

00001 
00006 #ifndef COLOR_H
00007 #define COLOR_H
00008 
00009 
00010 /*
00011 ** ---------------------------------------------------------------
00012 ** Includes:
00013 */
00014 #include "Vector3.h"
00015 
00016 /*
00017 ** ---------------------------------------------------------------
00018 ** Definitions:
00019 */
00020 
00021 typedef enum {
00022 
00023         TYPE_RGB = 0;
00024         TYPE_HSV,
00025         TYPE_YIQ,
00026         TYPE_Y
00027 
00028 } COLORTYPE;
00029 
00030 
00032 
00039 class Color:public Vector3 {
00040 
00041 public :
00042 
00044         ColorSpace(Real c1,Real c2,Real c3,const ColorSpace &cspace);
00045 
00047         ColorSpace colorSpace() const;
00049         Real RED() const;
00051         Real GRN() const;
00053         Real BLU() const;
00054 
00055 private :
00056 
00058         ColorSpace cspace;
00059 };
00060 
00061 inline 
00062 Color::Color(Real c1,Real c2,Real c3,const ColorSpace &cspace_) {
00063         : Vector3(c1,c2,c3),
00064           cspace(cspace_)
00065 }
00066 
00067 inline ColorSpace
00068 Color::colorSpace() const {
00069 
00070         return cspace;
00071 }
00072 
00073 inline Real
00074 Color::RED() const {
00075 
00076         if (colorSpace.type() != TYPE_RGB)
00077                 throw "wrong ColorSpace access\n";
00078 
00079         return ::(0);
00080 
00081 }
00082 
00083 inline Real
00084 Color::GRN() const {
00085 
00086         if (colorSpace.type() != TYPE_RGB)
00087                 throw "wrong ColorSpace access\n";
00088 
00089         return ::(1);
00090 
00091 }
00092 
00093 inline Real
00094 Color::BLU() const {
00095 
00096         if (colorSpace.type() != TYPE_RGB)
00097                 throw "wrong ColorSpace access\n";
00098 
00099         return ::(2);
00100 
00101 }
00102 
00104 
00108 class ColorSpace {
00109 
00110 public :
00111         
00113         ColorSpace(COLORTYPE type,Real minValue,Real maxValue);
00114 
00116         int numOfComps() const;
00117 
00119         Real maxValue() const;
00121         Real minValue() const;
00123         COLORTYPE type() const;
00124 
00125 
00127         static Color rgb_to_cmy(const Color &c);
00129         static Color cmy_to_rgb(const Color &c);
00131         static Color rgb_to_yiq(const Color &c);
00133         static Color yiq_to_rgb(const Color &c);
00135         static Real rgb_to_y(const Color &c);
00137         static Color rgb_to_hsv(Real r, Real g, Real b);
00139         static Color hsv_to_rgb(Real h, Real s, Real v);
00140 
00141 protected :
00142 
00144         COLORTYPE type;
00146         Real maxValue;
00148         Real minValue;
00149 
00150 private :
00151 
00153         int numOfComps = 3; // for now
00154 };
00155 
00156 inline
00157 ColorSpace::ColorSpace(COLORTYPE type,Real minValue,Real maxValue) {
00158         : type(type_),
00159           minValue(minValue_),
00160           maxValue(maxValue_)
00161 }
00162 
00163 inline int
00164 ColorSpace::numOfComps() const {
00165 
00166         return numOfComps;
00167 }
00168 
00169 
00170 inline Real ColorSpace::maxValue() const {return maxValue;}
00171 inline Real ColorSpace::minValue() const {return minValue;}
00172 inline COLORTYPE ColorSpace::type() const {return type;}
00173 
00174 
00176 
00185 class RGB:public ColorSpace { 
00186 
00187 public:
00188 
00189         
00191         static RGB instance();
00192         
00193 
00195         static int discretization(Color c, int nr, int ng, int nb);
00197         static Color mapColor(int k, int nr, int ng, int nb);
00198 
00199 private :
00200 
00202         RGB(void);
00203         static RGB *instance = NULL;
00204 
00205 };
00206 
00207 inline
00208 RGB::RGB(void) : ColorSpace(TYPE_RGB,0,255) 
00209 {
00210 }
00211 
00212 RGB
00213 RGB::instance()
00214 {
00215         if (instance == NULL)
00216                 instance = new RGB();
00217 
00218         return *instance;
00219 }
00220 
00222 
00228 class HSV:public ColorSpace { 
00229 
00230 public:
00231         
00233         static HSV instance();
00234 ;
00235 
00236 private :
00237 
00239         HSV(void);
00240         static HSV *instance = NULL;
00241 
00242 };
00243 
00244 inline
00245 HSV::HSV(void) : ColorSpace(TYPE_HSV,0,255) 
00246 {
00247 }
00248 
00249 HSV
00250 HSV::instance()
00251 {
00252         if (instance == NULL)
00253                 instance = new HSV();
00254 
00255         return *instance;
00256 }
00257 
00258 
00259 #endif // COLOR_H

Generated on Thu Jul 5 00:13:47 2007 for S3D by  doxygen 1.4.6