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-2018, 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 #pragma once
10 
11 #include <cstdint>
12 #include <iosfwd>
13 #include <iostream>
15 
16 namespace mrpt
17 {
18 namespace img
19 {
20 /** A RGB color - 8bit
21  * \ingroup mrpt_img_grp */
22 struct TColor
23 {
24  constexpr inline TColor() : R(0), G(0), B(0), A(255) {}
25  constexpr inline TColor(
27  : R(r), G(g), B(b), A(alpha)
28  {
29  }
30 
31  constexpr inline explicit TColor(const unsigned int color_RGB_24bit)
32  : R(uint8_t(color_RGB_24bit >> 16)),
33  G(uint8_t(color_RGB_24bit >> 8)),
34  B(uint8_t(color_RGB_24bit)),
35  A(255)
36  {
37  }
38 
39  constexpr inline TColor(
40  const unsigned int color_RGB_24bit, const uint8_t alpha)
41  : R(uint8_t(color_RGB_24bit >> 16)),
42  G(uint8_t(color_RGB_24bit >> 8)),
43  B(uint8_t(color_RGB_24bit)),
44  A(alpha)
45  {
46  }
47 
48  uint8_t R, G, B, A;
49 
50  /** Operator for implicit conversion into an int binary representation
51  * 0xRRGGBB */
52  inline operator unsigned int(void) const
53  {
54  return (((unsigned int)R) << 16) | (((unsigned int)G) << 8) | B;
55  }
56 
57  TColor& operator=(const TColor& other);
58  TColor& operator+=(const TColor& other);
59  TColor& operator-=(const TColor& other);
60 
61  /** Predefined colors */
62  static constexpr TColor red() { return TColor(255, 0, 0); }
63  static constexpr TColor green() { return TColor(0, 255, 0); }
64  static constexpr TColor blue() { return TColor(0, 0, 255); }
65  static constexpr TColor black() { return TColor(0, 0, 0); }
66  static constexpr TColor white() { return TColor(255, 255, 255); }
67  static constexpr TColor gray() { return TColor(127, 127, 127); }
68 };
69 // Text streaming:
70 std::ostream& operator<<(std::ostream& o, const TColor& c);
71 // Binary streaming:
73  mrpt::serialization::CArchive& o, const TColor& c);
75  mrpt::serialization::CArchive& i, TColor& c);
76 
77 /** A RGB color - floats in the range [0,1]
78  * \ingroup mrpt_img_grp */
79 struct TColorf
80 {
81  TColorf(float r = 0, float g = 0, float b = 0, float alpha = 1.0f)
82  : R(r), G(g), B(b), A(alpha)
83  {
84  }
85 
86  explicit TColorf(const TColor& col)
87  : R(col.R * (1.f / 255)),
88  G(col.G * (1.f / 255)),
89  B(col.B * (1.f / 255)),
90  A(col.A * (1.f / 255))
91  {
92  }
93 
94  float R, G, B, A;
95 };
96 
97 /**\brief Pairwise addition of their corresponding RGBA members
98  */
99 TColor operator+(const TColor& first, const TColor& second);
100 /**\brief Pairwise substraction of their corresponding RGBA members
101  */
102 TColor operator-(const TColor& first, const TColor& second);
103 bool operator==(const TColor& first, const TColor& second);
104 // bool operator!=(const TColor& first, const TColor& second);
105 
106 // Text streaming:
107 std::ostream& operator<<(std::ostream& o, const TColorf& c);
108 // Binary streaming:
113 
114 } // namespace img
115 } // namespace mrpt
GLclampf GLclampf GLclampf alpha
Definition: glext.h:3525
GLint * first
Definition: glext.h:3827
static constexpr TColor blue()
Definition: TColor.h:64
uint8_t B
Definition: TColor.h:48
uint8_t G
Definition: TColor.h:48
constexpr TColor(const unsigned int color_RGB_24bit, const uint8_t alpha)
Definition: TColor.h:39
TColor operator+(const TColor &first, const TColor &second)
Pairwise addition of their corresponding RGBA members.
Definition: TColor.cpp:20
TColor & operator-=(const TColor &other)
Definition: TColor.cpp:52
unsigned char uint8_t
Definition: rptypes.h:41
static constexpr TColor gray()
Definition: TColor.h:67
const GLubyte * c
Definition: glext.h:6313
GLint GLvoid * img
Definition: glext.h:3763
static constexpr TColor black()
Definition: TColor.h:65
GLubyte g
Definition: glext.h:6279
GLubyte GLubyte b
Definition: glext.h:6279
constexpr TColor(uint8_t r, uint8_t g, uint8_t b, uint8_t alpha=255)
Definition: TColor.h:25
static constexpr TColor green()
Definition: TColor.h:63
uint8_t R
Definition: TColor.h:48
bool operator==(const mrpt::img::TCamera &a, const mrpt::img::TCamera &b)
Definition: TCamera.cpp:201
constexpr TColor()
Definition: TColor.h:24
static constexpr TColor red()
Predefined colors.
Definition: TColor.h:62
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:48
GLdouble GLdouble GLdouble r
Definition: glext.h:3705
constexpr TColor(const unsigned int color_RGB_24bit)
Definition: TColor.h:31
TColorf(float r=0, float g=0, float b=0, float alpha=1.0f)
Definition: TColor.h:81
TColorf(const TColor &col)
Definition: TColor.h:86
A RGB color - floats in the range [0,1].
Definition: TColor.h:79
TColor operator-(const TColor &first, const TColor &second)
Pairwise substraction of their corresponding RGBA members.
Definition: TColor.cpp:31
TColor & operator=(const TColor &other)
Definition: TColor.cpp:62
TColor & operator+=(const TColor &other)
Definition: TColor.cpp:42
A RGB color - 8bit.
Definition: TColor.h:22
std::ostream & operator<<(std::ostream &o, const TColor &c)
Definition: TColor.cpp:85
static constexpr TColor white()
Definition: TColor.h:66
mrpt::serialization::CArchive & operator>>(mrpt::serialization::CArchive &i, TColor &c)
Definition: TColor.cpp:103
uint8_t A
Definition: TColor.h:48



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at lun oct 28 00:14:14 CET 2019