Ignition Math

API Reference

6.4.0
Color.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 #ifndef IGNITION_MATH_COLOR_HH_
18 #define IGNITION_MATH_COLOR_HH_
19 
20 #include <iostream>
21 
22 #include <ignition/math/Helpers.hh>
23 #include <ignition/math/Vector3.hh>
24 #include <ignition/math/config.hh>
25 
26 namespace ignition
27 {
28  namespace math
29  {
30  // Inline bracket to help doxygen filtering.
31  inline namespace IGNITION_MATH_VERSION_NAMESPACE {
32  //
36  class IGNITION_MATH_VISIBLE Color
37  {
39  public: static const Color White;
41  public: static const Color Black;
43  public: static const Color Red;
45  public: static const Color Green;
47  public: static const Color Blue;
49  public: static const Color Yellow;
51  public: static const Color Magenta;
53  public: static const Color Cyan;
54 
57  public: typedef unsigned int RGBA;
58 
61  public: typedef unsigned int BGRA;
62 
65  public: typedef unsigned int ARGB;
66 
69  public: typedef unsigned int ABGR;
70 
72  public: Color();
73 
79  public: Color(const float _r, const float _g, const float _b,
80  const float _a = 1.0);
81 
84  public: Color(const Color &_clr);
85 
87  public: virtual ~Color();
88 
91  public: void Reset();
92 
98  public: void Set(const float _r = 1, const float _g = 1,
99  const float _b = 1, const float _a = 1);
100 
104  public: Vector3f HSV() const;
105 
110  public: void SetFromHSV(const float _h, const float _s, const float _v);
111 
114  public: Vector3f YUV() const;
115 
120  public: void SetFromYUV(const float _y, const float _u, const float _v);
121 
125  public: Color &operator=(const Color &_pt);
126 
131  public: float operator[](const unsigned int _index);
132 
135  public: RGBA AsRGBA() const;
136 
139  public: BGRA AsBGRA() const;
140 
143  public: ARGB AsARGB() const;
144 
147  public: ABGR AsABGR() const;
148 
151  public: void SetFromRGBA(const RGBA _v);
152 
155  public: void SetFromBGRA(const BGRA _v);
156 
159  public: void SetFromARGB(const ARGB _v);
160 
163  public: void SetFromABGR(const ABGR _v);
164 
168  public: Color operator+(const Color &_pt) const;
169 
173  public: Color operator+(const float &_v) const;
174 
178  public: const Color &operator+=(const Color &_pt);
179 
183  public: Color operator-(const Color &_pt) const;
184 
188  public: Color operator-(const float &_v) const;
189 
193  public: const Color &operator-=(const Color &_pt);
194 
198  public: const Color operator/(const Color &_pt) const;
199 
203  public: const Color operator/(const float &_v) const;
204 
208  public: const Color &operator/=(const Color &_pt);
209 
213  public: const Color operator*(const Color &_pt) const;
214 
218  public: const Color operator*(const float &_v) const;
219 
223  public: const Color &operator*=(const Color &_pt);
224 
228  public: bool operator==(const Color &_pt) const;
229 
233  public: bool operator!=(const Color &_pt) const;
234 
236  private: void Clamp();
237 
242  public: friend std::ostream &operator<<(std::ostream &_out,
243  const Color &_pt)
244  {
245  _out << _pt.r << " " << _pt.g << " " << _pt.b << " " << _pt.a;
246  return _out;
247  }
248 
252  public: friend std::istream &operator>> (std::istream &_in, Color &_pt)
253  {
254  // Skip white spaces
255  _in.setf(std::ios_base::skipws);
256  _in >> _pt.r >> _pt.g >> _pt.b >> _pt.a;
257  return _in;
258  }
259 
262  public: float R() const;
263 
266  public: float G() const;
267 
270  public: float B() const;
271 
274  public: float A() const;
275 
278  public: float &R();
279 
282  public: float &G();
283 
286  public: float &B();
287 
290  public: float &A();
291 
294  public: void R(const float _r);
295 
298  public: void G(const float _g);
299 
302  public: void B(const float _b);
303 
306  public: void A(const float _a);
307 
309  private: float r = 0;
310 
312  private: float g = 0;
313 
315  private: float b = 0;
316 
318  private: float a = 1;
319  };
320  }
321  }
322 }
323 #endif
friend std::ostream & operator<<(std::ostream &_out, const Color &_pt)
Stream insertion operator.
Definition: Color.hh:242
T setf(T... args)
unsigned int ARGB
A ARGB packed value as an unsigned int.
Definition: Color.hh:65
static const Color Yellow
(1, 1, 0)
Definition: Color.hh:49
STL class.
unsigned int BGRA
A BGRA packed value as an unsigned int.
Definition: Color.hh:61
static const Color Green
(0, 1, 0)
Definition: Color.hh:45
static const Color White
(1, 1, 1)
Definition: Color.hh:39
static const Color Red
(1, 0, 0)
Definition: Color.hh:43
The Vector3 class represents the generic vector containing 3 elements. Since it&#39;s commonly used to ke...
Definition: Vector3.hh:40
static const Color Blue
(0, 0, 1)
Definition: Color.hh:47
static const Color Cyan
(0, 1, 1)
Definition: Color.hh:53
Definition: Angle.hh:42
unsigned int ABGR
A ABGR packed value as an unsigned int.
Definition: Color.hh:69
STL class.
Defines a color using a red (R), green (G), blue (B), and alpha (A) component. Each color component i...
Definition: Color.hh:36
unsigned int RGBA
A RGBA packed value as an unsigned int.
Definition: Color.hh:57
static const Color Magenta
(1, 0, 1)
Definition: Color.hh:51
static const Color Black
(0, 0, 0)
Definition: Color.hh:41