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);
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);
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;
Defines a color using a red (R), green (G), blue (B), and alpha (A) component. Each color component i...
Definition: gz/math/Color.hh:42
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: gz/math/Color.hh:52
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: gz/math/Color.hh:58
static const Color Yellow
(1, 1, 0)
Definition: gz/math/Color.hh:54
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: gz/math/Color.hh:48
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: gz/math/Color.hh:56
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: gz/math/Color.hh:44
virtual ~Color()
Destructor.
unsigned int BGRA
A BGRA packed value as an unsigned int Each 8 bits corresponds to a channel.
Definition: gz/math/Color.hh:76
const Color & operator+=(const Color &_pt)
Addition equal operator.
static const Color Black
(0, 0, 0)
Definition: gz/math/Color.hh:46
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 Each 8 bits corresponds to a channel.
Definition: gz/math/Color.hh:67
static const Color Green
(0, 1, 0)
Definition: gz/math/Color.hh:50
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 Each 8 bits corresponds to a channel.
Definition: gz/math/Color.hh:85
unsigned int ABGR
A ABGR packed value as an unsigned int Each 8 bits corresponds to a channel.
Definition: gz/math/Color.hh:94
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: gz/math/Color.hh:267
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: gz/math/Vector3.hh:42
Definition: gz/math/AdditivelySeparableScalarField3.hh:28