17#ifndef IGNITION_MATH_COLOR_HH_
18#define IGNITION_MATH_COLOR_HH_
24#include <ignition/math/config.hh>
30 inline namespace IGNITION_MATH_VERSION_NAMESPACE
35 class IGNITION_MATH_VISIBLE
Color
56 public:
typedef unsigned int RGBA;
60 public:
typedef unsigned int BGRA;
64 public:
typedef unsigned int ARGB;
68 public:
typedef unsigned int ABGR;
78 public:
Color(
const float _r,
const float _g,
const float _b,
79 const float _a = 1.0);
97 public:
void Set(
const float _r = 1,
const float _g = 1,
98 const float _b = 1,
const float _a = 1);
109 public:
void SetFromHSV(
const float _h,
const float _s,
const float _v);
119 public:
void SetFromYUV(
const float _y,
const float _u,
const float _v);
235 private:
void Clamp();
244 _out << _pt.r <<
" " << _pt.g <<
" " << _pt.b <<
" " << _pt.a;
251 public:
friend std::istream &operator>> (std::istream &_in,
Color &_pt)
254 _in.setf(std::ios_base::skipws);
255 _in >> _pt.r >> _pt.g >> _pt.b >> _pt.a;
261 public:
float R()
const;
265 public:
float G()
const;
269 public:
float B()
const;
273 public:
float A()
const;
293 public:
void R(
const float _r);
297 public:
void G(
const float _g);
301 public:
void B(
const float _b);
305 public:
void A(
const float _a);
308 private:
float r = 0;
311 private:
float g = 0;
314 private:
float b = 0;
317 private:
float a = 1;
Defines a color using a red (R), green (G), blue (B), and alpha (A) component.
Definition Color.hh:36
float operator[](const unsigned int _index)
Array index operator.
float & A()
Get a mutable reference to the alpha value.
bool operator==(const Color &_pt) const
Equality operator.
Color(const Color &_clr)
Copy Constructor.
float & B()
Get a mutable reference to the blue value.
unsigned int ARGB
Definition Color.hh:64
const Color operator*(const Color &_pt) const
Multiplication operator.
void G(const float _g)
Set the green value.
unsigned int ABGR
Definition Color.hh:68
float A() const
Get the alpha value.
void SetFromBGRA(const BGRA _v)
Set from uint32 BGRA packed value.
const Color & operator-=(const Color &_pt)
Subtraction equal operator.
virtual ~Color()
Destructor.
Color operator+(const Color &_pt) const
Addition operator (this + _pt)
void SetFromHSV(const float _h, const float _s, const float _v)
Set a color based on HSV values.
static const Color Green
(0, 1, 0)
Definition Color.hh:44
static const Color White
(1, 1, 1)
Definition Color.hh:38
void SetFromABGR(const ABGR _v)
Set from uint32 ABGR packed value.
static const Color Black
(0, 0, 0)
Definition Color.hh:40
void A(const float _a)
Set the alpha value.
const Color operator/(const Color &_pt) const
Division operator.
Vector3f HSV() const
Get the color in HSV colorspace.
void R(const float _r)
Set the red value.
bool operator!=(const Color &_pt) const
Inequality operator.
Color operator+(const float &_v) const
Add _v to all color components.
void Reset()
Reset the color to default values to red=0, green=0, blue=0, alpha=1.
static const Color Blue
(0, 0, 1)
Definition Color.hh:46
static const Color Red
(1, 0, 0)
Definition Color.hh:42
Color operator-(const float &_v) const
Subtract _v from all color components.
BGRA AsBGRA() const
Get as uint32 BGRA packed value.
void SetFromYUV(const float _y, const float _u, const float _v)
Set from yuv.
friend std::ostream & operator<<(std::ostream &_out, const Color &_pt)
Stream insertion operator.
Definition Color.hh:241
float & R()
Get a mutable reference to the red value.
unsigned int BGRA
Definition Color.hh:60
RGBA AsRGBA() const
Get as uint32 RGBA packed value.
float R() const
Get the red value.
const Color & operator/=(const Color &_pt)
Division equal operator.
const Color & operator+=(const Color &_pt)
Addition equal operator.
Color(const float _r, const float _g, const float _b, const float _a=1.0)
Constructor.
static const Color Cyan
(0, 1, 1)
Definition Color.hh:52
static const Color Yellow
(1, 1, 0)
Definition Color.hh:48
ARGB AsARGB() const
Get as uint32 ARGB packed value.
ABGR AsABGR() const
Get as uint32 ABGR packed value.
Color & operator=(const Color &_pt)
Equal operator.
static const Color Magenta
(1, 0, 1)
Definition Color.hh:50
float B() const
Get the blue value.
const Color operator*(const float &_v) const
Multiply all color components by _v.
const Color & operator*=(const Color &_pt)
Multiplication equal operator.
Vector3f YUV() const
Get the color in YUV colorspace.
float G() const
Get the green value.
void Set(const float _r=1, const float _g=1, const float _b=1, const float _a=1)
Set the contents of the vector.
const Color operator/(const float &_v) const
Divide all color component by _v.
unsigned int RGBA
Definition Color.hh:56
Color operator-(const Color &_pt) const
Subtraction operator.
void B(const float _b)
Set the blue value.
void SetFromARGB(const ARGB _v)
Set from uint32 ARGB packed value.
float & G()
Get a mutable reference to the green value.
void SetFromRGBA(const RGBA _v)
Set from uint32 RGBA packed value.
The Vector3 class represents the generic vector containing 3 elements.
Definition Vector3.hh:40