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
mrpt::img::TColor::red
static constexpr TColor red()
Predefined colors.
Definition: TColor.h:62
mrpt::img::operator+
TColor operator+(const TColor &first, const TColor &second)
Pairwise addition of their corresponding RGBA members.
Definition: TColor.cpp:20
c
const GLubyte * c
Definition: glext.h:6313
mrpt::img::TColor::TColor
constexpr TColor(const unsigned int color_RGB_24bit)
Definition: TColor.h:31
mrpt::img::TColorf::R
float R
Definition: TColor.h:94
mrpt::img::TColor::R
uint8_t R
Definition: TColor.h:48
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
g
GLubyte g
Definition: glext.h:6279
uint8_t
unsigned char uint8_t
Definition: rptypes.h:41
mrpt::img::TColorf::TColorf
TColorf(const TColor &col)
Definition: TColor.h:86
mrpt::img::TColor::operator=
TColor & operator=(const TColor &other)
Definition: TColor.cpp:62
mrpt::img::operator==
bool operator==(const mrpt::img::TCamera &a, const mrpt::img::TCamera &b)
Definition: TCamera.cpp:201
alpha
GLclampf GLclampf GLclampf alpha
Definition: glext.h:3525
mrpt::serialization::CArchive
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:48
mrpt::img::operator<<
std::ostream & operator<<(std::ostream &o, const TColor &c)
Definition: TColor.cpp:85
r
GLdouble GLdouble GLdouble r
Definition: glext.h:3705
mrpt::img::operator-
TColor operator-(const TColor &first, const TColor &second)
Pairwise substraction of their corresponding RGBA members.
Definition: TColor.cpp:31
mrpt::img::TColor::green
static constexpr TColor green()
Definition: TColor.h:63
mrpt::img::TColorf::B
float B
Definition: TColor.h:94
mrpt::img::TColor::B
uint8_t B
Definition: TColor.h:48
mrpt::img::TColor::white
static constexpr TColor white()
Definition: TColor.h:66
mrpt::img::TColor::TColor
constexpr TColor(uint8_t r, uint8_t g, uint8_t b, uint8_t alpha=255)
Definition: TColor.h:25
b
GLubyte GLubyte b
Definition: glext.h:6279
mrpt::img::TColor::gray
static constexpr TColor gray()
Definition: TColor.h:67
mrpt::img::TColorf
A RGB color - floats in the range [0,1].
Definition: TColor.h:79
mrpt::img::TColor
A RGB color - 8bit.
Definition: TColor.h:22
mrpt::img::TColor::blue
static constexpr TColor blue()
Definition: TColor.h:64
mrpt::img::TColor::A
uint8_t A
Definition: TColor.h:48
mrpt::img::TColor::TColor
constexpr TColor()
Definition: TColor.h:24
serialization_frwds.h
mrpt::img::TColor::black
static constexpr TColor black()
Definition: TColor.h:65
mrpt::img::TColorf::G
float G
Definition: TColor.h:94
img
GLint GLvoid * img
Definition: glext.h:3763
mrpt::img::TColor::operator-=
TColor & operator-=(const TColor &other)
Definition: TColor.cpp:52
mrpt::img::TColor::G
uint8_t G
Definition: TColor.h:48
mrpt::img::TColor::TColor
constexpr TColor(const unsigned int color_RGB_24bit, const uint8_t alpha)
Definition: TColor.h:39
mrpt::img::operator>>
mrpt::serialization::CArchive & operator>>(mrpt::serialization::CArchive &i, TColor &c)
Definition: TColor.cpp:103
mrpt::img::TColor::operator+=
TColor & operator+=(const TColor &other)
Definition: TColor.cpp:42
mrpt::img::TColorf::A
float A
Definition: TColor.h:94
first
GLint * first
Definition: glext.h:3827
mrpt::img::TColorf::TColorf
TColorf(float r=0, float g=0, float b=0, float alpha=1.0f)
Definition: TColor.h:81



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST