00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #ifndef HxColor_h
00013 #define HxColor_h
00014
00015 #include "HxIoFwd.h"
00016 #include "HxString.h"
00017 #include "HxVec3Double.h"
00018
00022 enum HxColorModel { RGB, CMY, XYZ, Lab, Luv, OOO, HSI };
00023
00026 class L_HXBASIS HxColor {
00027 public:
00029 HxColor();
00030
00032 HxColor(HxVec3Double color, HxColorModel space = RGB);
00033
00035 HxColor(const HxColor& rhs);
00036
00038 HxColor& operator=(const HxColor& rhs);
00039
00041 const HxVec3Double& value() const;
00042
00046 HxColor convert(const HxColorModel space) const;
00047
00049 HxColor toRGB() const;
00050
00052 HxColor toCMY() const;
00053
00055 HxColor toXYZ() const;
00056
00058 HxColor toLab() const;
00059
00061 HxColor toLuv() const;
00062
00064 HxColor toOOO() const;
00065
00067 HxColor toHSI() const;
00068
00070 int operator==(const HxColor& v) const;
00071
00073 int operator!=(const HxColor& v) const;
00074
00076 STD_OSTREAM& put(STD_OSTREAM& os) const;
00077
00079 HxString toString() const;
00080
00081 private:
00082 HxVec3Double _value;
00083 HxColorModel _space;
00084 };
00085
00086
00087 inline STD_OSTREAM&
00088 HxColor::put(STD_OSTREAM& os) const
00089 {
00090 return os << toString();
00091 }
00092
00093 inline STD_OSTREAM&
00094 operator<<(STD_OSTREAM& os, const HxColor c)
00095 {
00096 return c.put(os);
00097 }
00098
00099
00100 inline
00101 HxColor::HxColor()
00102 : _value(0,0,0), _space(RGB)
00103 {
00104 }
00105
00106 inline
00107 HxColor::HxColor(HxVec3Double color, HxColorModel space)
00108 : _value(color), _space(space)
00109 {
00110 }
00111
00112 inline
00113 HxColor::HxColor(const HxColor& rhs)
00114 : _value(rhs._value), _space(rhs._space)
00115 {
00116 }
00117
00118 inline HxColor&
00119 HxColor::operator=(const HxColor& rhs)
00120 {
00121 _value = rhs._value;
00122 _space = rhs._space;
00123 return *this;
00124 }
00125
00126 inline const HxVec3Double&
00127 HxColor::value() const
00128 {
00129 return _value;
00130 }
00131
00132 inline HxColor
00133 HxColor::convert(const HxColorModel space) const
00134 {
00135 switch (space) {
00136 case RGB: return toRGB();
00137 case CMY: return toCMY();
00138 case XYZ: return toXYZ();
00139 case Lab: return toLab();
00140 case Luv: return toLuv();
00141 case OOO: return toOOO();
00142 case HSI: return toHSI();
00143 }
00144 return HxColor();
00145 }
00146
00147 inline int
00148 HxColor::operator==(const HxColor& c) const
00149 {
00150 return (_space == c._space) && (_value == c._value);
00151 }
00152
00153 inline int
00154 HxColor::operator!=(const HxColor& c) const
00155 {
00156 return !(*this == c);
00157 }
00158
00159 #endif