17 #ifndef GZ_MATH_COLOR_HH_
18 #define GZ_MATH_COLOR_HH_
26 #include <gz/math/config.hh>
31 inline namespace GZ_MATH_VERSION_NAMESPACE {
66 public:
typedef unsigned int RGBA;
75 public:
typedef unsigned int BGRA;
84 public:
typedef unsigned int ARGB;
93 public:
typedef unsigned int ABGR;
96 public:
Color() =
default;
103 public: constexpr
Color(
const float _r,
const float _g,
const float _b,
104 const float _a = 1.0)
105 : r(_r), g(_g), b(_b), a(_a)
115 public: ~
Color() =
default;
119 public:
void Reset();
126 public:
void Set(
const float _r = 1,
const float _g = 1,
127 const float _b = 1,
const float _a = 1);
138 public:
void SetFromHSV(
const float _h,
const float _s,
const float _v);
148 public:
void SetFromYUV(
const float _y,
const float _u,
const float _v);
153 public:
Color &operator=(
const Color &_pt) =
default;
160 public:
float operator[](
const unsigned int _index);
167 public:
float operator[](
const unsigned int _index)
const;
171 public: RGBA AsRGBA()
const;
175 public: BGRA AsBGRA()
const;
179 public: ARGB AsARGB()
const;
183 public: ABGR AsABGR()
const;
187 public:
void SetFromRGBA(
const RGBA _v);
191 public:
void SetFromBGRA(
const BGRA _v);
195 public:
void SetFromARGB(
const ARGB _v);
199 public:
void SetFromABGR(
const ABGR _v);
204 public:
Color operator+(
const Color &_pt)
const;
209 public:
Color operator+(
const float &_v)
const;
214 public:
const Color &operator+=(
const Color &_pt);
219 public:
Color operator-(
const Color &_pt)
const;
224 public:
Color operator-(
const float &_v)
const;
229 public:
const Color &operator-=(
const Color &_pt);
234 public:
const Color operator/(
const Color &_pt)
const;
239 public:
const Color operator/(
const float &_v)
const;
244 public:
const Color &operator/=(
const Color &_pt);
249 public:
const Color operator*(
const Color &_pt)
const;
254 public:
const Color operator*(
const float &_v)
const;
259 public:
const Color &operator*=(
const Color &_pt);
264 public:
bool operator==(
const Color &_pt)
const;
269 public:
bool operator!=(
const Color &_pt)
const;
272 private: constexpr
void Clamp()
275 if (!(this->r >= 0)) { this->r = 0; }
276 if (!(this->g >= 0)) { this->g = 0; }
277 if (!(this->b >= 0)) { this->b = 0; }
278 if (!(this->a >= 0)) { this->a = 0; }
279 if (this->r > 1) { this->r = this->r/255.0f; }
280 if (this->g > 1) { this->g = this->g/255.0f; }
281 if (this->b > 1) { this->b = this->b/255.0f; }
282 if (this->a > 1) { this->a = 1; }
292 for (
auto i : {0, 1, 2, 3})
309 _in.
setf(std::ios_base::skipws);
310 _in >> _pt.r >> _pt.g >> _pt.b;
320 else if (!_in.
fail())
329 public:
float R()
const;
333 public:
float G()
const;
337 public:
float B()
const;
341 public:
float A()
const;
361 public:
void R(
const float _r);
365 public:
void G(
const float _g);
369 public:
void B(
const float _b);
373 public:
void A(
const float _a);
376 private:
float r = 0;
379 private:
float g = 0;
382 private:
float b = 0;
385 private:
float a = 1;
389 #endif // GZ_MATH_COLOR_HH_