00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef OST_COLOR_HH
00020 #define OST_COLOR_HH
00021
00022
00023
00024
00025
00026 #include <iosfwd>
00027
00028 #include <boost/operators.hpp>
00029
00030 #include <ost/gfx/module_config.hh>
00031 #include <ost/geom/geom.hh>
00032
00033 namespace ost { namespace gfx {
00034
00052 class DLLEXPORT_OST_GFX Color :
00053 private boost::additive<Color>,
00054 private boost::additive<Color, float>,
00055 private boost::multiplicative<Color, float>{
00056
00057 public:
00059 Color();
00060
00062 void SetRGB(float r, float g, float b);
00064 geom::Vec3 GetRGB() const;
00066 geom::Vec4 GetRGBA() const;
00068 float GetRed() const;
00070 void SetRed(float);
00072 float GetGreen() const;
00074 void SetGreen(float);
00076 float GetBlue() const;
00078 void SetBlue(float);
00080 void SetHSV(float h, float s, float v);
00082 geom::Vec3 GetHSV() const;
00084 geom::Vec4 GetHSVA() const;
00086 float GetHue() const;
00088 void SetHue(float);
00090 float GetSat() const;
00092 void SetSat(float);
00094 float GetVal() const;
00096 void SetVal(float);
00098 float GetAlpha() const;
00100 void SetAlpha(float);
00101
00102
00114 operator const float* () const;
00115 operator float* ();
00116
00117 Color& operator*=(float rhs);
00118 Color& operator+=(float rhs);
00119
00120 Color& operator+=(const Color& rhs);
00121 Color& operator-=(const Color& rhs);
00122 Color& operator-=(float rhs);
00123 Color& operator/=(float rhs);
00124
00126
00128 geom::Vec3 ToHSV() const {return GetHSV();}
00129
00131 Color(float r, float g, float b, float a=1.0);
00132
00134 float Red() const {return GetRed();}
00136 float Green() const {return GetGreen();}
00138 float Blue() const {return GetBlue();}
00140 float Alpha() const {return GetAlpha();}
00141
00143 static Color FromRGB(unsigned char r, unsigned char g,
00144 unsigned char b, unsigned char a = 0xff) {
00145 static float f=1.0/255.0;
00146 return Color(f*static_cast<float>(r),f*static_cast<float>(g),
00147 f*static_cast<float>(b),f*static_cast<float>(a));
00148 }
00149
00151
00152 private:
00153 void to_hsv() const;
00154 void to_rgb() const;
00155
00156 mutable float rgba_[4];
00157 mutable float hsv_[3];
00158 mutable bool rgb_dirty_;
00159 mutable bool hsv_dirty_;
00160 };
00161
00162 #undef RGB
00164 Color DLLEXPORT_OST_GFX RGB(float r, float g, float b);
00165
00167 Color DLLEXPORT_OST_GFX RGBb(uchar r, uchar g, uchar b);
00168
00170 Color DLLEXPORT_OST_GFX RGBi(unsigned int r, unsigned int g, unsigned int b);
00171
00173 Color DLLEXPORT_OST_GFX RGBA(float r, float g, float b, float a);
00174
00176 Color DLLEXPORT_OST_GFX RGBAb(uchar r, uchar g, uchar b, uchar a);
00177
00179 Color DLLEXPORT_OST_GFX RGBAi(unsigned int r, unsigned int g, unsigned int b, unsigned int a);
00180
00181
00202 Color DLLEXPORT_OST_GFX HSV(float h, float s, float v);
00203
00217 Color DLLEXPORT_OST_GFX HSVi(int h, int s, int v);
00218
00224 Color DLLEXPORT_OST_GFX HSVA(float h, float s, float v, float a);
00225
00231 Color DLLEXPORT_OST_GFX HSVAi(int h, int s, int v, int a);
00232
00233
00235 DLLEXPORT_OST_GFX std::ostream& operator<<(std::ostream&, const Color& c);
00236
00237 }}
00238
00239 #endif
00240