OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
color.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // This file is part of the OpenStructure project <www.openstructure.org>
3 //
4 // Copyright (C) 2008-2011 by the OpenStructure authors
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License as published by the Free
8 // Software Foundation; either version 3.0 of the License, or (at your option)
9 // any later version.
10 // This library is distributed in the hope that it will be useful, but WITHOUT
11 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 // details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this library; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 //------------------------------------------------------------------------------
19 #ifndef OST_COLOR_HH
20 #define OST_COLOR_HH
21 
22 /*
23  Author: Ansgar Philippsen, Marco Biasini
24 */
25 
26 #include <iosfwd>
27 
28 #include <boost/operators.hpp>
29 
30 #include <ost/gfx/module_config.hh>
31 #include <ost/geom/geom.hh>
32 
33 namespace ost { namespace gfx {
34 
53  private boost::additive<Color>,
54  private boost::additive<Color, float>,
55  private boost::multiplicative<Color, float>{
56 
57 public:
59  Color();
60 
62  void SetRGB(float r, float g, float b);
64  geom::Vec3 GetRGB() const;
66  geom::Vec4 GetRGBA() const;
68  float GetRed() const;
70  void SetRed(float);
72  float GetGreen() const;
74  void SetGreen(float);
76  float GetBlue() const;
78  void SetBlue(float);
80  void SetHSV(float h, float s, float v);
82  geom::Vec3 GetHSV() const;
84  geom::Vec4 GetHSVA() const;
86  float GetHue() const;
88  void SetHue(float);
90  float GetSat() const;
92  void SetSat(float);
94  float GetVal() const;
96  void SetVal(float);
98  float GetAlpha() const;
100  void SetAlpha(float);
101 
102 
114  operator const float* () const;
115  operator float* ();
116 
117  Color& operator*=(float rhs);
118  Color& operator+=(float rhs);
119 
120  Color& operator+=(const Color& rhs);
121  Color& operator-=(const Color& rhs);
122  Color& operator-=(float rhs);
123  Color& operator/=(float rhs);
124 
126 
128  geom::Vec3 ToHSV() const {return GetHSV();}
129 
131  Color(float r, float g, float b, float a=1.0);
132 
134  float Red() const {return GetRed();}
136  float Green() const {return GetGreen();}
138  float Blue() const {return GetBlue();}
140  float Alpha() const {return GetAlpha();}
141 
143  static Color FromRGB(unsigned char r, unsigned char g,
144  unsigned char b, unsigned char a = 0xff) {
145  static float f=1.0/255.0;
146  return Color(f*static_cast<float>(r),f*static_cast<float>(g),
147  f*static_cast<float>(b),f*static_cast<float>(a));
148  }
149 
151 
152 private:
153  void to_hsv() const;
154  void to_rgb() const;
155 
156  mutable float rgba_[4];
157  mutable float hsv_[3];
158  mutable bool rgb_dirty_;
159  mutable bool hsv_dirty_;
160 };
161 
162 #undef RGB
163 Color DLLEXPORT_OST_GFX RGB(float r, float g, float b);
165 
167 Color DLLEXPORT_OST_GFX RGBb(uchar r, uchar g, uchar b);
168 
170 Color DLLEXPORT_OST_GFX RGBi(unsigned int r, unsigned int g, unsigned int b);
171 
173 Color DLLEXPORT_OST_GFX RGBA(float r, float g, float b, float a);
174 
176 Color DLLEXPORT_OST_GFX RGBAb(uchar r, uchar g, uchar b, uchar a);
177 
179 Color DLLEXPORT_OST_GFX RGBAi(unsigned int r, unsigned int g, unsigned int b, unsigned int a);
180 
181 
202 Color DLLEXPORT_OST_GFX HSV(float h, float s, float v);
203 
217  Color DLLEXPORT_OST_GFX HSVi(int h, int s, int v);
218 
224 Color DLLEXPORT_OST_GFX HSVA(float h, float s, float v, float a);
225 
231 Color DLLEXPORT_OST_GFX HSVAi(int h, int s, int v, int a);
232 
233 
235 DLLEXPORT_OST_GFX std::ostream& operator<<(std::ostream&, const Color& c);
236 
237 }}
238 
239 #endif
240 
Color DLLEXPORT_OST_GFX HSV(float h, float s, float v)
HSV color spec from floats.
Color DLLEXPORT_OST_GFX RGBi(unsigned int r, unsigned int g, unsigned int b)
RGB color spec from integers (0-65535)
float Blue() const
DEPRECATED.
Definition: color.hh:138
geom::Vec3 ToHSV() const
DEPRECATED.
Definition: color.hh:128
Color DLLEXPORT_OST_GFX HSVA(float h, float s, float v, float a)
HSVA color spec from floats.
float Green() const
DEPRECATED.
Definition: color.hh:136
Color DLLEXPORT_OST_GFX RGB(float r, float g, float b)
RGB color spec from floats (0.0-1.0)
#define DLLEXPORT_OST_GFX
float Alpha() const
DEPRECATED.
Definition: color.hh:140
Color DLLEXPORT_OST_GFX HSVAi(int h, int s, int v, int a)
HSVA color spec from integers.
Color DLLEXPORT_OST_GFX RGBAi(unsigned int r, unsigned int g, unsigned int b, unsigned int a)
RGBA color spec from integers (0-65535)
Color DLLEXPORT_OST_GFX RGBA(float r, float g, float b, float a)
RGBA color spec from floats (0.0-1.0)
Color DLLEXPORT_OST_GFX RGBAb(uchar r, uchar g, uchar b, uchar a)
RGBA color spec from bytes (0-255)
Three dimensional vector class, using Real precision.
Definition: vec3.hh:42
Color DLLEXPORT_OST_GFX RGBb(uchar r, uchar g, uchar b)
RGB color spec from bytes (0-255)
Color DLLEXPORT_OST_GFX HSVi(int h, int s, int v)
HSV color spec from integers.
unsigned char uchar
Definition: base.hh:33
static Color FromRGB(unsigned char r, unsigned char g, unsigned char b, unsigned char a=0xff)
DEPRECATED.
Definition: color.hh:143
float Red() const
DEPRECATED.
Definition: color.hh:134
DLLEXPORT_OST_GFX std::ostream & operator<<(std::ostream &, const Color &c)
string form