Main MRPT website > C++ reference for MRPT 1.5.6
TColor.cpp
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2017, 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 
10 #include "base-precomp.h" // Precompiled headers
11 
12 #include <mrpt/utils/CStream.h>
13 #include <mrpt/utils/TColor.h>
14 #include <mrpt/system/os.h>
15 
16 using namespace mrpt::utils;
17 
18 // Static colors:
19 TColor TColor::red = TColor(255,0,0);
20 TColor TColor::green = TColor(0,255,0);
21 TColor TColor::blue = TColor(0,0,255);
22 TColor TColor::black = TColor(0,0,0);
23 TColor TColor::white = TColor(255,255,255);
24 TColor TColor::gray = TColor(127,127,127);
25 
27  TColor ret;
28  ret.R = first.R + second.R;
29  ret.G = first.G + second.G;
30  ret.B = first.B + second.B;
31  ret.A = first.A + second.A;
32 
33  return ret;
34 }
35 
37  TColor ret;
38  ret.R = first.R - second.R;
39  ret.G = first.G - second.G;
40  ret.B = first.B - second.B;
41  ret.A = first.A - second.A;
42 
43  return ret;
44 }
45 
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  this->R -= other.R;
57  this->G -= other.G;
58  this->B -= other.B;
59  this->A -= other.A;
60 
61  return *this;
62 }
63 
65  this->R = other.R;
66  this->G = other.G;
67  this->B = other.B;
68  this->A = other.A;
69 
70  return *this;
71 }
72 
73 bool mrpt::utils::operator==(const TColor& first, const TColor& second) {
74  bool ret =
75  first.R == second.R &&
76  first.G == second.G &&
77  first.B == second.B &&
78  first.A == second.A;
79 
80  return ret;
81 }
82 
83 //bool operator!=(const TColor& first, const TColor& second) {
84  //return (!(first == second));
85 //}
86 
87 // Text streaming:
88 std::ostream & mrpt::utils::operator << (std::ostream& o, const TColor & c)
89 {
90  char buf[200];
91  mrpt::system::os::sprintf(buf,sizeof(buf),"RGBA=[%u,%u,%u,%u]",static_cast<unsigned int>(c.R),static_cast<unsigned int>(c.G),static_cast<unsigned int>(c.B),static_cast<unsigned int>(c.A) );
92  o << buf;
93  return o;
94 }
95 
96 // Binary streaming:
98 {
99  o << c.R<<c.G<<c.B<<c.A;
100  return o;
101 }
102 
104 {
105  i >> c.R>>c.G>>c.B>>c.A;
106  return i;
107 }
108 
109 
110 // Text streaming:
111 std::ostream & mrpt::utils::operator << (std::ostream& o, const TColorf & c)
112 {
113  char buf[200];
114  mrpt::system::os::sprintf(buf,sizeof(buf),"RGBAf=[%f,%f,%f,%f]",c.R,c.G,c.B,c.A);
115  o << buf;
116  return o;
117 }
118 
119 // Binary streaming:
121 {
122  o << c.R<<c.G<<c.B<<c.A;
123  return o;
124 }
125 
127 {
128  i >> c.R>>c.G>>c.B>>c.A;
129  return i;
130 }
TColor & operator+=(const TColor &other)
Definition: TColor.cpp:46
const GLfloat * c
Definition: glew.h:10088
static TColor blue
Predefined colors.
Definition: TColor.h:67
static TColor white
Predefined colors.
Definition: TColor.h:68
::mrpt::utils::CStream & operator>>(mrpt::utils::CStream &in, CImagePtr &pObj)
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:38
TColor & operator-=(const TColor &other)
Definition: TColor.cpp:55
TColor operator-(const TColor &first, const TColor &second)
Pairwise substraction of their corresponding RGBA members.
Definition: TColor.cpp:36
A RGB color - 8bit.
Definition: TColor.h:26
CStream BASE_IMPEXP & operator<<(mrpt::utils::CStream &s, const char *a)
Definition: CStream.cpp:130
GLint * first
Definition: glew.h:1433
TColor operator+(const TColor &first, const TColor &second)
Pairwise addition of their corresponding RGBA members.
Definition: TColor.cpp:26
static TColor red
Predefined colors.
Definition: TColor.h:65
A RGB color - floats in the range [0,1].
Definition: TColor.h:80
static TColor black
Predefined colors.
Definition: TColor.h:69
bool operator==(const CArray< T, N > &x, const CArray< T, N > &y)
Definition: CArray.h:277
int BASE_IMPEXP sprintf(char *buf, size_t bufSize, const char *format,...) MRPT_NO_THROWS MRPT_printf_format_check(3
An OS-independent version of sprintf (Notice the bufSize param, which may be ignored in some compiler...
Definition: os.cpp:191
static TColor gray
Predefined colors.
Definition: TColor.h:70
TColor & operator=(const TColor &other)
Definition: TColor.cpp:64
static TColor green
Predefined colors.
Definition: TColor.h:66



Page generated by Doxygen 1.8.6 for MRPT 1.5.6 Git: 4c65e84 Tue Apr 24 08:18:17 2018 +0200 at mar abr 24 08:26:17 CEST 2018