17 #ifndef IGNITION_MATH_COLOR_HH_
18 #define IGNITION_MATH_COLOR_HH_
25 #include <ignition/math/config.hh>
32 inline namespace IGNITION_MATH_VERSION_NAMESPACE {
37 class IGNITION_MATH_VISIBLE
Color
58 public:
typedef unsigned int RGBA;
62 public:
typedef unsigned int BGRA;
66 public:
typedef unsigned int ARGB;
70 public:
typedef unsigned int ABGR;
80 public:
Color(
const float _r,
const float _g,
const float _b,
81 const float _a = 1.0);
99 public:
void Set(
const float _r = 1,
const float _g = 1,
100 const float _b = 1,
const float _a = 1);
111 public:
void SetFromHSV(
const float _h,
const float _s,
const float _v);
121 public:
void SetFromYUV(
const float _y,
const float _u,
const float _v);
237 private:
void Clamp();
246 _out << _pt.r <<
" " << _pt.g <<
" " << _pt.b <<
" " << _pt.a;
257 _in.
setf(std::ios_base::skipws);
258 _in >> _pt.r >> _pt.g >> _pt.b;
268 else if (!_in.
fail())
277 public:
float R()
const;
281 public:
float G()
const;
285 public:
float B()
const;
289 public:
float A()
const;
309 public:
void R(
const float _r);
313 public:
void G(
const float _g);
317 public:
void B(
const float _b);
321 public:
void A(
const float _a);
324 private:
float r = 0;
327 private:
float g = 0;
330 private:
float b = 0;
333 private:
float a = 1;
Defines a color using a red (R), green (G), blue (B), and alpha (A) component. Each color component i...
Definition: Color.hh:38
void SetFromHSV(const float _h, const float _s, const float _v)
Set a color based on HSV values.
float & R()
Get a mutable reference to the red value.
Color & operator=(const Color &_pt)
Equal operator.
static const Color Blue
(0, 0, 1)
Definition: Color.hh:48
void SetFromYUV(const float _y, const float _u, const float _v)
Set from yuv.
Color operator+(const float &_v) const
Add _v to all color components.
void SetFromRGBA(const RGBA _v)
Set from uint32 RGBA packed value.
float A() const
Get the alpha value.
const Color & operator-=(const Color &_pt)
Subtraction equal operator.
float R() const
Get the red value.
Color operator-(const float &_v) const
Subtract _v from all color components.
void SetFromARGB(const ARGB _v)
Set from uint32 ARGB packed value.
static const Color Cyan
(0, 1, 1)
Definition: Color.hh:54
static const Color Yellow
(1, 1, 0)
Definition: Color.hh:50
const Color operator*(const Color &_pt) const
Multiplication operator.
void Reset()
Reset the color to default values to red=0, green=0, blue=0, alpha=1.
static const Color Red
(1, 0, 0)
Definition: Color.hh:44
float & G()
Get a mutable reference to the green value.
const Color operator/(const float &_v) const
Divide all color component by _v.
const Color & operator*=(const Color &_pt)
Multiplication equal operator.
const Color & operator/=(const Color &_pt)
Division equal operator.
static const Color Magenta
(1, 0, 1)
Definition: Color.hh:52
Color operator-(const Color &_pt) const
Subtraction operator.
void SetFromBGRA(const BGRA _v)
Set from uint32 BGRA packed value.
bool operator!=(const Color &_pt) const
Inequality operator.
RGBA AsRGBA() const
Get as uint32 RGBA packed value.
ARGB AsARGB() const
Get as uint32 ARGB packed value.
static const Color White
(1, 1, 1)
Definition: Color.hh:40
virtual ~Color()
Destructor.
unsigned int BGRA
A BGRA packed value as an unsigned int.
Definition: Color.hh:62
const Color & operator+=(const Color &_pt)
Addition equal operator.
static const Color Black
(0, 0, 0)
Definition: Color.hh:42
BGRA AsBGRA() const
Get as uint32 BGRA packed value.
void A(const float _a)
Set the alpha value.
const Color operator*(const float &_v) const
Multiply all color components by _v.
Color(const Color &_clr)
Copy Constructor.
float & A()
Get a mutable reference to the alpha value.
void R(const float _r)
Set the red value.
bool operator==(const Color &_pt) const
Equality operator.
ABGR AsABGR() const
Get as uint32 ABGR packed 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.
float operator[](const unsigned int _index)
Array index operator.
unsigned int RGBA
A RGBA packed value as an unsigned int.
Definition: Color.hh:58
static const Color Green
(0, 1, 0)
Definition: Color.hh:46
Color(const float _r, const float _g, const float _b, const float _a=1.0)
Constructor.
void G(const float _g)
Set the green value.
Color operator+(const Color &_pt) const
Addition operator (this + _pt)
void SetFromABGR(const ABGR _v)
Set from uint32 ABGR packed value.
Vector3f HSV() const
Get the color in HSV colorspace.
Vector3f YUV() const
Get the color in YUV colorspace.
unsigned int ARGB
A ARGB packed value as an unsigned int.
Definition: Color.hh:66
unsigned int ABGR
A ABGR packed value as an unsigned int.
Definition: Color.hh:70
float & B()
Get a mutable reference to the blue value.
const Color operator/(const Color &_pt) const
Division operator.
void B(const float _b)
Set the blue value.
float B() const
Get the blue value.
friend std::ostream & operator<<(std::ostream &_out, const Color &_pt)
Stream insertion operator.
Definition: Color.hh:243
float G() const
Get the green value.
The Vector3 class represents the generic vector containing 3 elements. Since it's commonly used to ke...
Definition: Vector3.hh:42