Main MRPT website > C++ reference for MRPT 1.5.7
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-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 #ifndef mrpt_utils_tcolor_H
11 #define mrpt_utils_tcolor_H
12 
13 #include <mrpt/utils/mrpt_stdint.h> // compiler-independent version of "stdint.h"
14 #include <mrpt/base/link_pragmas.h>
15 #include <iosfwd>
16 #include <iostream>
17 
18 namespace mrpt
19 {
20  namespace utils
21  {
22  class CStream;
23 
24  /** A RGB color - 8bit
25  * \ingroup mrpt_base_grp */
27  {
28  inline TColor() :
29  R(0),
30  G(0),
31  B(0),
32  A(255) { }
33 
35  R(r),
36  G(g),
37  B(b),
38  A(alpha) { }
39 
40  inline explicit TColor(const unsigned int color_RGB_24bit) :
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(255) { }
45 
46  inline TColor(
47  const unsigned int color_RGB_24bit,
48  const uint8_t alpha):
49  R(uint8_t(color_RGB_24bit>>16)),
50  G(uint8_t(color_RGB_24bit>>8)),
51  B(uint8_t(color_RGB_24bit)),
52  A(alpha) { }
53 
54  uint8_t R,G,B,A;
55 
56  /** Operator for implicit conversion into an int binary representation 0xRRGGBB */
57  inline operator unsigned int(void) const {
58  return (((unsigned int)R)<<16) | (((unsigned int)G)<<8) | B;
59  }
60 
61  TColor& operator=(const TColor& other);
62  TColor& operator+=(const TColor& other);
63  TColor& operator-=(const TColor& other);
64 
65  static TColor red; //!< Predefined colors
66  static TColor green;//!< Predefined colors
67  static TColor blue;//!< Predefined colors
68  static TColor white;//!< Predefined colors
69  static TColor black;//!< Predefined colors
70  static TColor gray; //!< Predefined colors
71  };
72  // Text streaming:
73  std::ostream BASE_IMPEXP & operator << (std::ostream& o, const TColor & c);
74  // Binary streaming:
77 
78  /** A RGB color - floats in the range [0,1]
79  * \ingroup mrpt_base_grp */
81  {
82  TColorf(float r=0, float g=0, float b=0, float alpha=1.0f):
83  R(r),
84  G(g),
85  B(b),
86  A(alpha) { }
87 
88  explicit TColorf(const TColor &col) :
89  R(col.R*(1.f/255)),
90  G(col.G*(1.f/255)),
91  B(col.B*(1.f/255)),
92  A(col.A*(1.f/255)) { }
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 BASE_IMPEXP & operator << (std::ostream& o, const TColorf & c);
108  // Binary streaming:
111 
112  } // end namespace
113 } // end of namespace
114 
115 #endif
116 
GLclampf GLclampf GLclampf alpha
Definition: glext.h:3510
TColorf(float r=0, float g=0, float b=0, float alpha=1.0f)
Definition: TColor.h:82
GLint * first
Definition: glext.h:3703
static TColor blue
Predefined colors.
Definition: TColor.h:67
unsigned char uint8_t
Definition: rptypes.h:43
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
const GLubyte * c
Definition: glext.h:5590
std::vector< T1 > & operator+=(std::vector< T1 > &a, const std::vector< T2 > &b)
a+=b (element-wise sum)
Definition: ops_vectors.h:70
TColor operator-(const TColor &first, const TColor &second)
Pairwise substraction of their corresponding RGBA members.
Definition: TColor.cpp:36
GLubyte g
Definition: glext.h:5575
A RGB color - 8bit.
Definition: TColor.h:26
GLubyte GLubyte b
Definition: glext.h:5575
TColor(const unsigned int color_RGB_24bit, const uint8_t alpha)
Definition: TColor.h:46
CStream BASE_IMPEXP & operator<<(mrpt::utils::CStream &s, const char *a)
Definition: CStream.cpp:130
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
TColor(uint8_t r, uint8_t g, uint8_t b, uint8_t alpha=255)
Definition: TColor.h:34
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
GLdouble GLdouble GLdouble r
Definition: glext.h:3618
const float R
TColorf(const TColor &col)
Definition: TColor.h:88
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
TColor(const unsigned int color_RGB_24bit)
Definition: TColor.h:40
static TColor gray
Predefined colors.
Definition: TColor.h:70
static TColor green
Predefined colors.
Definition: TColor.h:66



Page generated by Doxygen 1.8.14 for MRPT 1.5.7 Git: 5902e14cc Wed Apr 24 15:04:01 2019 +0200 at lun oct 28 01:39:17 CET 2019