Go to the documentation of this file.
17 #ifndef GZ_MATH_COLOR_HH_
18 #define GZ_MATH_COLOR_HH_
25 #include <gz/math/config.hh>
32 inline namespace IGNITION_MATH_VERSION_NAMESPACE {
41 class IGNITION_MATH_VISIBLE
Color
67 public:
typedef unsigned int RGBA;
76 public:
typedef unsigned int BGRA;
85 public:
typedef unsigned int ARGB;
94 public:
typedef unsigned int ABGR;
104 public:
Color(
const float _r,
const float _g,
const float _b,
105 const float _a = 1.0);
112 public:
virtual ~
Color();
116 public:
void Reset();
123 public:
void Set(
const float _r = 1,
const float _g = 1,
124 const float _b = 1,
const float _a = 1);
135 public:
void SetFromHSV(
const float _h,
const float _s,
const float _v);
145 public:
void SetFromYUV(
const float _y,
const float _u,
const float _v);
156 public:
float operator[](
const unsigned int _index);
160 public:
RGBA AsRGBA()
const;
164 public:
BGRA AsBGRA()
const;
168 public:
ARGB AsARGB()
const;
172 public:
ABGR AsABGR()
const;
176 public:
void SetFromRGBA(
const RGBA _v);
180 public:
void SetFromBGRA(
const BGRA _v);
184 public:
void SetFromARGB(
const ARGB _v);
188 public:
void SetFromABGR(
const ABGR _v);
193 public:
Color operator+(
const Color &_pt)
const;
198 public:
Color operator+(
const float &_v)
const;
203 public:
const Color &operator+=(
const Color &_pt);
208 public:
Color operator-(
const Color &_pt)
const;
213 public:
Color operator-(
const float &_v)
const;
218 public:
const Color &operator-=(
const Color &_pt);
223 public:
const Color operator/(
const Color &_pt)
const;
228 public:
const Color operator/(
const float &_v)
const;
233 public:
const Color &operator/=(
const Color &_pt);
238 public:
const Color operator*(
const Color &_pt)
const;
243 public:
const Color operator*(
const float &_v)
const;
248 public:
const Color &operator*=(
const Color &_pt);
253 public:
bool operator==(
const Color &_pt)
const;
258 public:
bool operator!=(
const Color &_pt)
const;
261 private:
void Clamp();
270 _out << _pt.r <<
" " << _pt.g <<
" " << _pt.b <<
" " << _pt.a;
281 _in.
setf(std::ios_base::skipws);
282 _in >> _pt.r >> _pt.g >> _pt.b;
292 else if (!_in.
fail())
301 public:
float R()
const;
305 public:
float G()
const;
309 public:
float B()
const;
313 public:
float A()
const;
333 public:
void R(
const float _r);
337 public:
void G(
const float _g);
341 public:
void B(
const float _b);
345 public:
void A(
const float _a);
348 private:
float r = 0;
351 private:
float g = 0;
354 private:
float b = 0;
357 private:
float a = 1;
Color & operator=(const Color &_pt)
Equal operator.
const Color operator*(const Color &_pt) const
Multiplication operator.
const Color & operator+=(const Color &_pt)
Addition equal operator.
Definition: gz/math/AdditivelySeparableScalarField3.hh:27
Defines a color using a red (R), green (G), blue (B), and alpha (A) component. Each color component i...
Definition: gz/math/Color.hh:41
float B() const
Get the blue value.
void SetFromRGBA(const RGBA _v)
Set from uint32 RGBA packed value.
static const Color Black
(0, 0, 0)
Definition: gz/math/Color.hh:46
void SetFromHSV(const float _h, const float _s, const float _v)
Set a color based on HSV values.
void Reset()
Reset the color to default values to red=0, green=0, blue=0, alpha=1.
bool operator!=(const Color &_pt) const
Inequality operator.
friend std::istream & operator>>(std::istream &_in, Color &_pt)
Stream insertion operator.
Definition: gz/math/Color.hh:278
friend std::ostream & operator<<(std::ostream &_out, const Color &_pt)
Stream insertion operator.
Definition: gz/math/Color.hh:267
static const Color Blue
(0, 0, 1)
Definition: gz/math/Color.hh:52
void SetFromARGB(const ARGB _v)
Set from uint32 ARGB packed value.
unsigned int ARGB
A ARGB packed value as an unsigned int Each 8 bits corresponds to a channel.
Definition: gz/math/Color.hh:85
void Set(const float _r=1, const float _g=1, const float _b=1, const float _a=1)
Set the contents of the vector.
float operator[](const unsigned int _index)
Array index operator.
ABGR AsABGR() const
Get as uint32 ABGR packed value.
The Vector3 class represents the generic vector containing 3 elements. Since it's commonly used to ke...
Definition: gz/math/Vector3.hh:41
static const Color Green
(0, 1, 0)
Definition: gz/math/Color.hh:50
static const Color Cyan
(0, 1, 1)
Definition: gz/math/Color.hh:58
RGBA AsRGBA() const
Get as uint32 RGBA packed value.
static const Color Magenta
(1, 0, 1)
Definition: gz/math/Color.hh:56
float R() const
Get the red value.
void SetFromBGRA(const BGRA _v)
Set from uint32 BGRA packed value.
const Color & operator-=(const Color &_pt)
Subtraction equal operator.
Color operator-(const Color &_pt) const
Subtraction operator.
Color operator+(const Color &_pt) const
Addition operator (this + _pt)
void SetFromABGR(const ABGR _v)
Set from uint32 ABGR packed value.
unsigned int ABGR
A ABGR packed value as an unsigned int Each 8 bits corresponds to a channel.
Definition: gz/math/Color.hh:94
const Color & operator/=(const Color &_pt)
Division equal operator.
unsigned int RGBA
A RGBA packed value as an unsigned int Each 8 bits corresponds to a channel.
Definition: gz/math/Color.hh:67
Vector3f HSV() const
Get the color in HSV colorspace.
static const Color Red
(1, 0, 0)
Definition: gz/math/Color.hh:48
virtual ~Color()
Destructor.
static const Color Yellow
(1, 1, 0)
Definition: gz/math/Color.hh:54
BGRA AsBGRA() const
Get as uint32 BGRA packed value.
const Color & operator*=(const Color &_pt)
Multiplication equal operator.
const Color operator/(const Color &_pt) const
Division operator.
Vector3f YUV() const
Get the color in YUV colorspace.
ARGB AsARGB() const
Get as uint32 ARGB packed value.
bool operator==(const Color &_pt) const
Equality operator.
float G() const
Get the green value.
static const Color White
(1, 1, 1)
Definition: gz/math/Color.hh:44
void SetFromYUV(const float _y, const float _u, const float _v)
Set from yuv.
unsigned int BGRA
A BGRA packed value as an unsigned int Each 8 bits corresponds to a channel.
Definition: gz/math/Color.hh:76
float A() const
Get the alpha value.