MRPT  2.0.1
TColor.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, 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 
10 #include "img-precomp.h" // Precompiled headers
11 
12 #include <mrpt/img/TColor.h>
14 #include <mrpt/system/os.h>
15 
16 using namespace mrpt::img;
18 
19 // Check "#pragma pack(push, 1)" is doing its job:
20 static_assert(sizeof(TColor) == 4 * sizeof(uint8_t));
21 static_assert(sizeof(TColorf) == 4 * sizeof(float));
22 
23 TColor mrpt::img::operator+(const TColor& first, const TColor& second)
24 {
25  TColor ret;
26  ret.R = first.R + second.R;
27  ret.G = first.G + second.G;
28  ret.B = first.B + second.B;
29  ret.A = first.A + second.A;
30 
31  return ret;
32 }
33 
34 TColor mrpt::img::operator-(const TColor& first, const TColor& second)
35 {
36  TColor ret;
37  ret.R = first.R - second.R;
38  ret.G = first.G - second.G;
39  ret.B = first.B - second.B;
40  ret.A = first.A - second.A;
41 
42  return ret;
43 }
44 
46 {
47  this->R += other.R;
48  this->G += other.G;
49  this->B += other.B;
50  this->A += other.A;
51 
52  return *this;
53 }
54 
56 {
57  this->R -= other.R;
58  this->G -= other.G;
59  this->B -= other.B;
60  this->A -= other.A;
61 
62  return *this;
63 }
64 
65 TColor& TColor::operator=(const TColor& other) = default;
66 
67 bool mrpt::img::operator==(const TColor& first, const TColor& second)
68 {
69  bool ret = first.R == second.R && first.G == second.G &&
70  first.B == second.B && first.A == second.A;
71 
72  return ret;
73 }
74 
75 // bool operator!=(const TColor& first, const TColor& second) {
76 // return (!(first == second));
77 //}
78 
79 // Text streaming:
80 std::ostream& mrpt::img::operator<<(std::ostream& o, const TColor& c)
81 {
82  char buf[200];
84  buf, sizeof(buf), "RGBA=[%u,%u,%u,%u]", static_cast<unsigned int>(c.R),
85  static_cast<unsigned int>(c.G), static_cast<unsigned int>(c.B),
86  static_cast<unsigned int>(c.A));
87  o << buf;
88  return o;
89 }
90 
91 // Binary streaming:
93 {
94  o << c.R << c.G << c.B << c.A;
95  return o;
96 }
97 
99 {
100  i >> c.R >> c.G >> c.B >> c.A;
101  return i;
102 }
103 
104 // Text streaming:
105 std::ostream& mrpt::img::operator<<(std::ostream& o, const TColorf& c)
106 {
107  char buf[200];
109  buf, sizeof(buf), "RGBAf=[%f,%f,%f,%f]", c.R, c.G, c.B, c.A);
110  o << buf;
111  return o;
112 }
113 
114 // Binary streaming:
116 {
117  o << c.R << c.G << c.B << c.A;
118  return o;
119 }
120 
122 {
123  i >> c.R >> c.G >> c.B >> c.A;
124  return i;
125 }
uint8_t B
Definition: TColor.h:51
uint8_t G
Definition: TColor.h:51
TColor operator+(const TColor &first, const TColor &second)
Pairwise addition of their corresponding RGBA members.
Definition: TColor.cpp:23
TColor & operator-=(const TColor &other)
Definition: TColor.cpp:55
uint8_t R
Definition: TColor.h:51
bool operator==(const mrpt::img::TCamera &a, const mrpt::img::TCamera &b)
Definition: TCamera.cpp:231
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:54
An RGBA color - floats in the range [0,1].
Definition: TColor.h:88
TColor operator-(const TColor &first, const TColor &second)
Pairwise substraction of their corresponding RGBA members.
Definition: TColor.cpp:34
TColor & operator=(const TColor &other)
TColor & operator+=(const TColor &other)
Definition: TColor.cpp:45
A RGB color - 8bit.
Definition: TColor.h:25
std::ostream & operator<<(std::ostream &o, const TColor &c)
Definition: TColor.cpp:80
mrpt::serialization::CArchive & operator>>(mrpt::serialization::CArchive &i, TColor &c)
Definition: TColor.cpp:98
int sprintf(char *buf, size_t bufSize, const char *format,...) noexcept MRPT_printf_format_check(3
An OS-independent version of sprintf (Notice the bufSize param, which may be ignored in some compiler...
uint8_t A
Definition: TColor.h:51



Page generated by Doxygen 1.8.14 for MRPT 2.0.1 Git: 0fef1a6d7 Fri Apr 3 23:00:21 2020 +0200 at vie abr 3 23:20:28 CEST 2020