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(
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& operator=(const TColor& other);
56  TColor& operator+=(const TColor& other);
57  TColor& operator-=(const TColor& other);
58 
59  /** Predefined colors */
60  static constexpr TColor red() { return TColor(255, 0, 0); }
61  static constexpr TColor green() { return TColor(0, 255, 0); }
62  static constexpr TColor blue() { return TColor(0, 0, 255); }
63  static constexpr TColor black() { return TColor(0, 0, 0); }
64  static constexpr TColor white() { return TColor(255, 255, 255); }
65  static constexpr TColor gray() { return TColor(127, 127, 127); }
66 };
67 // Text streaming:
68 std::ostream& operator<<(std::ostream& o, const TColor& c);
69 // Binary streaming:
71  mrpt::serialization::CArchive& o, const TColor& c);
73  mrpt::serialization::CArchive& i, TColor& c);
74 
75 /** A RGB color - floats in the range [0,1]
76  * \ingroup mrpt_img_grp */
77 struct TColorf
78 {
79  TColorf(float r = 0, float g = 0, float b = 0, float alpha = 1.0f)
80  : R(r), G(g), B(b), A(alpha)
81  {
82  }
83 
84  explicit TColorf(const TColor& col)
85  : R(col.R * (1.f / 255)),
86  G(col.G * (1.f / 255)),
87  B(col.B * (1.f / 255)),
88  A(col.A * (1.f / 255))
89  {
90  }
91 
92  float R, G, B, A;
93 };
94 
95 /**\brief Pairwise addition of their corresponding RGBA members
96  */
97 TColor operator+(const TColor& first, const TColor& second);
98 /**\brief Pairwise substraction of their corresponding RGBA members
99  */
100 TColor operator-(const TColor& first, const TColor& second);
101 bool operator==(const TColor& first, const TColor& second);
102 // bool operator!=(const TColor& first, const TColor& second);
103 
104 // Text streaming:
105 std::ostream& operator<<(std::ostream& o, const TColorf& c);
106 // Binary streaming:
111 
112 } // namespace mrpt::img
GLclampf GLclampf GLclampf alpha
Definition: glext.h:3529
GLint * first
Definition: glext.h:3833
static constexpr TColor blue()
Definition: TColor.h:62
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
unsigned char uint8_t
Definition: rptypes.h:44
static constexpr TColor gray()
Definition: TColor.h:65
const GLubyte * c
Definition: glext.h:6406
static constexpr TColor black()
Definition: TColor.h:63
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:61
uint8_t R
Definition: TColor.h:46
bool operator==(const mrpt::img::TCamera &a, const mrpt::img::TCamera &b)
Definition: TCamera.cpp:202
static constexpr TColor red()
Predefined colors.
Definition: TColor.h:60
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:53
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:79
TColorf(const TColor &col)
Definition: TColor.h:84
A RGB color - floats in the range [0,1].
Definition: TColor.h:77
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:64
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: 8fe78517f Sun Jul 14 19:43:28 2019 +0200 at lun oct 28 02:10:00 CET 2019