Color.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 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 _GAZEBO_COLOR_HH_
18 #define _GAZEBO_COLOR_HH_
19 
20 #include <iostream>
21 #include <ignition/math/Color.hh>
22 #include <ignition/math/Vector3.hh>
23 
25 #include "gazebo/util/system.hh"
26 
27 namespace gazebo
28 {
29  namespace common
30  {
33 
36  class GZ_COMMON_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;
52 
55  public: typedef unsigned int RGBA;
56 
59  public: typedef unsigned int BGRA;
60 
63  public: typedef unsigned int ARGB;
64 
67  public: typedef unsigned int ABGR;
68 
70  public: Color() GAZEBO_DEPRECATED(9.0);
71 
77  public: Color(float _r, float _g, float _b, float _a = 1.0)
78  GAZEBO_DEPRECATED(9.0);
79 
82  // cppcheck-suppress noExplicitConstructor
83  public: Color(const ignition::math::Color &_color) GAZEBO_DEPRECATED(9.0);
84 
87  public: Color &operator=(const ignition::math::Color &_color)
88  GAZEBO_DEPRECATED(9.0);
89 
91  public: ignition::math::Color Ign() const;
92 
95  public: Color(const Color &_clr) GAZEBO_DEPRECATED(9.0);
96 
98  public: virtual ~Color() GAZEBO_DEPRECATED(9.0);
99 
101  public: void Reset();
102 
108  public: void Set(float _r = 1, float _g = 1 , float _b = 1, float _a = 1);
109 
112  public: ignition::math::Vector3d HSV() const;
113 
118  public: void SetFromHSV(float _h, float _s, float _v);
119 
122  public: ignition::math::Vector3d YUV() const;
123 
128  public: void SetFromYUV(float _y, float _u, float _v);
129 
133  public: Color &operator =(const Color &_pt) GAZEBO_DEPRECATED(9.0);
134 
138  public: float operator[](unsigned int _index);
139 
142  public: RGBA GetAsRGBA() const;
143 
146  public: BGRA GetAsBGRA() const;
147 
150  public: ARGB GetAsARGB() const;
151 
154  public: ABGR GetAsABGR() const;
155 
158  public: void SetFromRGBA(const RGBA _v);
159 
162  public: void SetFromBGRA(const BGRA _v);
163 
166  public: void SetFromARGB(const ARGB _v);
167 
170  public: void SetFromABGR(const ABGR _v);
171 
175  public: Color operator+(const Color &_pt) const;
176 
180  public: Color operator+(const float &_v) const;
181 
185  public: const Color &operator+=(const Color &_pt);
186 
190  public: Color operator-(const Color &_pt) const;
191 
195  public: Color operator-(const float &_v) const;
196 
200  public: const Color &operator-=(const Color &_pt);
201 
205  public: const Color operator/(const Color &_pt) const;
206 
210  public: const Color operator/(const float &_v) const;
211 
215  public: const Color &operator/=(const Color &_pt);
216 
220  public: const Color operator*(const Color &_pt) const;
221 
225  public: const Color operator*(const float &_v) const;
226 
230  public: const Color &operator*=(const Color &_pt);
231 
235  public: bool operator ==(const Color &_pt) const;
236 
240  public: bool operator!=(const Color &_pt) const;
241 
243  private: void Clamp();
244 
249  public: friend std::ostream &operator<< (std::ostream &_out,
250  const Color &_pt)
251  {
252  _out << _pt.r << " " << _pt.g << " " << _pt.b << " " << _pt.a;
253  return _out;
254  }
255 
259  public: friend std::istream &operator>> (std::istream &_in, Color &_pt)
260  {
261  // Skip white spaces
262  _in.setf(std::ios_base::skipws);
263  _in >> _pt.r >> _pt.g >> _pt.b >> _pt.a;
264  return _in;
265  }
266 
267  // The values
268  public: float r, g, b, a;
269  };
271  }
272 }
273 #endif
static const Color Blue
(0, 0, 1)
Definition: Color.hh:47
float a
Definition: Color.hh:268
float b
Definition: Color.hh:268
static const Color White
(1, 1, 1)
Definition: Color.hh:39
static const Color Red
(1, 0, 0)
Definition: Color.hh:43
unsigned int RGBA
Definition: Color.hh:55
unsigned int ABGR
Definition: Color.hh:67
unsigned int ARGB
Definition: Color.hh:63
static const Color Green
(0, 1, 0)
Definition: Color.hh:45
float r
Definition: Color.hh:268
GAZEBO_VISIBLE void Set(common::Image &_img, const msgs::Image &_msg)
Convert a msgs::Image to a common::Image.
Defines a color.
Definition: Color.hh:36
#define GAZEBO_DEPRECATED(version)
Definition: system.hh:328
static const Color Yellow
(1, 1, 0)
Definition: Color.hh:49
static const Color Black
(0, 0, 0)
Definition: Color.hh:41
static const Color Magenta
(1, 0, 1)
Definition: Color.hh:51
float g
Definition: Color.hh:268
unsigned int BGRA
Definition: Color.hh:59