Main MRPT website > C++ reference for MRPT 1.9.9
TColor.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #ifndef mrpt_utils_tcolor_H
11 #define mrpt_utils_tcolor_H
12 
13 #include <cstdint>
14 #include <iosfwd>
15 #include <iostream>
16 
17 namespace mrpt
18 {
19 namespace utils
20 {
21 class CStream;
22 
23 /** A RGB color - 8bit
24  * \ingroup mrpt_base_grp */
25 struct TColor
26 {
27  constexpr inline TColor() : R(0), G(0), B(0), A(255) {}
28  constexpr inline TColor(uint8_t r, uint8_t g, uint8_t b, uint8_t alpha = 255)
29  : R(r), G(g), B(b), A(alpha)
30  {
31  }
32 
33  constexpr inline explicit TColor(const unsigned int color_RGB_24bit)
34  : R(uint8_t(color_RGB_24bit >> 16)),
35  G(uint8_t(color_RGB_24bit >> 8)),
36  B(uint8_t(color_RGB_24bit)),
37  A(255)
38  {
39  }
40 
41  constexpr inline TColor(const unsigned int color_RGB_24bit, const uint8_t alpha)
42  : R(uint8_t(color_RGB_24bit >> 16)),
43  G(uint8_t(color_RGB_24bit >> 8)),
44  B(uint8_t(color_RGB_24bit)),
45  A(alpha)
46  {
47  }
48 
49  uint8_t R, G, B, A;
50 
51  /** Operator for implicit conversion into an int binary representation
52  * 0xRRGGBB */
53  inline operator unsigned int(void) const
54  {
55  return (((unsigned int)R) << 16) | (((unsigned int)G) << 8) | B;
56  }
57 
58  TColor& operator=(const TColor& other);
59  TColor& operator+=(const TColor& other);
60  TColor& operator-=(const TColor& other);
61 
62  /** Predefined colors */
63  static constexpr TColor red() { return TColor(255, 0, 0); }
64  static constexpr TColor green() { return TColor(0, 255, 0); }
65  static constexpr TColor blue() { return TColor(0, 0, 255); }
66  static constexpr TColor black() { return TColor(0, 0, 0); }
67  static constexpr TColor white() { return TColor(255, 255, 255); }
68  static constexpr TColor gray() { return TColor(127, 127, 127); }
69 };
70 // Text streaming:
71 std::ostream& operator<<(std::ostream& o, const TColor& c);
72 // Binary streaming:
73 CStream& operator<<(mrpt::utils::CStream& o, const TColor& c);
74 CStream& operator>>(mrpt::utils::CStream& i, TColor& c);
75 
76 /** A RGB color - floats in the range [0,1]
77  * \ingroup mrpt_base_grp */
78 struct TColorf
79 {
80  TColorf(float r = 0, float g = 0, float b = 0, float alpha = 1.0f)
81  : R(r), G(g), B(b), A(alpha)
82  {
83  }
84 
85  explicit TColorf(const TColor& col)
86  : R(col.R * (1.f / 255)),
87  G(col.G * (1.f / 255)),
88  B(col.B * (1.f / 255)),
89  A(col.A * (1.f / 255))
90  {
91  }
92 
93  float R, G, B, A;
94 };
95 
96 /**\brief Pairwise addition of their corresponding RGBA members
97  */
98 TColor operator+(const TColor& first, const TColor& second);
99 /**\brief Pairwise substraction of their corresponding RGBA members
100  */
101 TColor operator-(const TColor& first, const TColor& second);
102 bool operator==(const TColor& first, const TColor& second);
103 // bool operator!=(const TColor& first, const TColor& second);
104 
105 // Text streaming:
106 std::ostream& operator<<(std::ostream& o, const TColorf& c);
107 // Binary streaming:
110 
111 } // end namespace
112 } // end of namespace
113 
114 #endif
static constexpr TColor white()
Definition: TColor.h:67
GLclampf GLclampf GLclampf alpha
Definition: glext.h:3525
constexpr TColor(const unsigned int color_RGB_24bit)
Definition: TColor.h:33
TColor & operator+=(const TColor &other)
Definition: TColor.cpp:40
TColorf(float r=0, float g=0, float b=0, float alpha=1.0f)
Definition: TColor.h:80
GLint * first
Definition: glext.h:3827
bool operator==(const mrpt::utils::TCamera &a, const mrpt::utils::TCamera &b)
Definition: TCamera.cpp:204
unsigned char uint8_t
Definition: rptypes.h:41
static constexpr TColor green()
Definition: TColor.h:64
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:41
TColor & operator-=(const TColor &other)
Definition: TColor.cpp:50
const GLubyte * c
Definition: glext.h:6313
TColor operator-(const TColor &first, const TColor &second)
Pairwise substraction of their corresponding RGBA members.
Definition: TColor.cpp:29
GLubyte g
Definition: glext.h:6279
A RGB color - 8bit.
Definition: TColor.h:25
GLubyte GLubyte b
Definition: glext.h:6279
constexpr TColor()
Definition: TColor.h:27
CStream & operator<<(mrpt::utils::CStream &s, const char *a)
Definition: CStream.cpp:123
static constexpr TColor gray()
Definition: TColor.h:68
constexpr TColor(const unsigned int color_RGB_24bit, const uint8_t alpha)
Definition: TColor.h:41
TColor operator+(const TColor &first, const TColor &second)
Pairwise addition of their corresponding RGBA members.
Definition: TColor.cpp:18
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
GLdouble GLdouble GLdouble r
Definition: glext.h:3705
static constexpr TColor red()
Predefined colors.
Definition: TColor.h:63
TColorf(const TColor &col)
Definition: TColor.h:85
static constexpr TColor black()
Definition: TColor.h:66
constexpr TColor(uint8_t r, uint8_t g, uint8_t b, uint8_t alpha=255)
Definition: TColor.h:28
A RGB color - floats in the range [0,1].
Definition: TColor.h:78
static constexpr TColor blue()
Definition: TColor.h:65
CStream & operator>>(mrpt::utils::CStream &in, char *a)
Definition: CStream.cpp:407
TColor & operator=(const TColor &other)
Definition: TColor.cpp:60



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019