MRPT  1.9.9
TColor.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2019, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #pragma once
10 
12 #include <cstdint>
13 #include <iosfwd>
14 #include <iostream>
15 
16 namespace mrpt::img
17 {
18 /** A RGB color - 8bit
19  * \ingroup mrpt_img_grp */
20 struct TColor
21 {
22  constexpr inline TColor() = default;
23  constexpr inline TColor(
24  uint8_t r, uint8_t g, uint8_t b, uint8_t alpha = 255)
25  : R(r), G(g), B(b), A(alpha)
26  {
27  }
28 
29  constexpr inline explicit TColor(const unsigned int color_RGB_24bit)
30  : R(uint8_t(color_RGB_24bit >> 16)),
31  G(uint8_t(color_RGB_24bit >> 8)),
32  B(uint8_t(color_RGB_24bit)),
33  A(255)
34  {
35  }
36 
37  constexpr inline TColor(
38  const unsigned int color_RGB_24bit, const uint8_t alpha)
39  : R(uint8_t(color_RGB_24bit >> 16)),
40  G(uint8_t(color_RGB_24bit >> 8)),
41  B(uint8_t(color_RGB_24bit)),
42  A(alpha)
43  {
44  }
45 
46  uint8_t R{0}, G{0}, B{0}, A{255};
47 
48  /** Operator for implicit conversion into an int binary representation
49  * 0xRRGGBB */
50  inline operator unsigned int() const
51  {
52  return (((unsigned int)R) << 16) | (((unsigned int)G) << 8) | B;
53  }
54 
55  TColor(const TColor& other) { *this = other; }
56  TColor& operator=(const TColor& other);
57  TColor& operator+=(const TColor& other);
58  TColor& operator-=(const TColor& other);
59 
60  /** Predefined colors */
61  static constexpr TColor red() { return TColor(255, 0, 0); }
62  static constexpr TColor green() { return TColor(0, 255, 0); }
63  static constexpr TColor blue() { return TColor(0, 0, 255); }
64  static constexpr TColor black() { return TColor(0, 0, 0); }
65  static constexpr TColor white() { return TColor(255, 255, 255); }
66  static constexpr TColor gray() { return TColor(127, 127, 127); }
67 };
68 // Text streaming:
69 std::ostream& operator<<(std::ostream& o, const TColor& c);
70 // Binary streaming:
72  mrpt::serialization::CArchive& o, const TColor& c);
74  mrpt::serialization::CArchive& i, TColor& c);
75 
76 /** A RGB color - floats in the range [0,1]
77  * \ingroup mrpt_img_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:
112 
113 } // namespace mrpt::img
GLclampf GLclampf GLclampf alpha
Definition: glext.h:3529
GLint * first
Definition: glext.h:3833
static constexpr TColor blue()
Definition: TColor.h:63
uint8_t B
Definition: TColor.h:46
uint8_t G
Definition: TColor.h:46
constexpr TColor(const unsigned int color_RGB_24bit, const uint8_t alpha)
Definition: TColor.h:37
TColor operator+(const TColor &first, const TColor &second)
Pairwise addition of their corresponding RGBA members.
Definition: TColor.cpp:19
TColor & operator-=(const TColor &other)
Definition: TColor.cpp:51
static constexpr TColor gray()
Definition: TColor.h:66
const GLubyte * c
Definition: glext.h:6406
static constexpr TColor black()
Definition: TColor.h:64
TColor(const TColor &other)
Definition: TColor.h:55
GLubyte g
Definition: glext.h:6372
GLubyte GLubyte b
Definition: glext.h:6372
constexpr TColor(uint8_t r, uint8_t g, uint8_t b, uint8_t alpha=255)
Definition: TColor.h:23
static constexpr TColor green()
Definition: TColor.h:62
uint8_t R
Definition: TColor.h:46
bool operator==(const mrpt::img::TCamera &a, const mrpt::img::TCamera &b)
Definition: TCamera.cpp:231
static constexpr TColor red()
Predefined colors.
Definition: TColor.h:61
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:54
GLdouble GLdouble GLdouble r
Definition: glext.h:3711
constexpr TColor(const unsigned int color_RGB_24bit)
Definition: TColor.h:29
TColorf(float r=0, float g=0, float b=0, float alpha=1.0f)
Definition: TColor.h:80
TColorf(const TColor &col)
Definition: TColor.h:85
A RGB color - floats in the range [0,1].
Definition: TColor.h:78
constexpr TColor()=default
TColor operator-(const TColor &first, const TColor &second)
Pairwise substraction of their corresponding RGBA members.
Definition: TColor.cpp:30
TColor & operator=(const TColor &other)
TColor & operator+=(const TColor &other)
Definition: TColor.cpp:41
A RGB color - 8bit.
Definition: TColor.h:20
std::ostream & operator<<(std::ostream &o, const TColor &c)
Definition: TColor.cpp:76
static constexpr TColor white()
Definition: TColor.h:65
mrpt::serialization::CArchive & operator>>(mrpt::serialization::CArchive &i, TColor &c)
Definition: TColor.cpp:94



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 70be1f8ba Thu Nov 14 20:53:42 2019 +0100 at jue nov 14 21:00:10 CET 2019