Main MRPT website > C++ reference
MRPT logo
TColor.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | The Mobile Robot Programming Toolkit (MRPT) C++ library |
3  | |
4  | http://www.mrpt.org/ |
5  | |
6  | Copyright (C) 2005-2012 University of Malaga |
7  | |
8  | This software was written by the Machine Perception and Intelligent |
9  | Robotics Lab, University of Malaga (Spain). |
10  | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> |
11  | |
12  | This file is part of the MRPT project. |
13  | |
14  | MRPT is free software: you can redistribute it and/or modify |
15  | it under the terms of the GNU General Public License as published by |
16  | the Free Software Foundation, either version 3 of the License, or |
17  | (at your option) any later version. |
18  | |
19  | MRPT is distributed in the hope that it will be useful, |
20  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
21  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22  | GNU General Public License for more details. |
23  | |
24  | You should have received a copy of the GNU General Public License |
25  | along with MRPT. If not, see <http://www.gnu.org/licenses/>. |
26  | |
27  +---------------------------------------------------------------------------+ */
28 
29 #ifndef mrpt_utils_tcolor_H
30 #define mrpt_utils_tcolor_H
31 
32 #include <mrpt/utils/mrpt_stdint.h> // compiler-independent version of "stdint.h"
33 #include <mrpt/utils/mrpt_inttypes.h> // compiler-independent version of "inttypes.h"
34 
35 namespace mrpt
36 {
37  namespace utils
38  {
39 
40  /** A RGB color - 8bit
41  * \ingroup mrpt_base_grp */
43  {
44  inline TColor() : R(0),G(0),B(0),A(255) { }
45  inline TColor(uint8_t r,uint8_t g,uint8_t b, uint8_t alpha=255) : R(r),G(g),B(b),A(alpha) { }
46  inline explicit TColor(const unsigned int color_RGB_24bit) : R(uint8_t(color_RGB_24bit>>16)),G(uint8_t(color_RGB_24bit>>8)),B(uint8_t(color_RGB_24bit)),A(255) { }
47  inline TColor(const unsigned int color_RGB_24bit, const uint8_t alpha) : R(uint8_t(color_RGB_24bit>>16)),G(uint8_t(color_RGB_24bit>>8)),B(uint8_t(color_RGB_24bit)),A(alpha) { }
48  uint8_t R,G,B,A;
49 
50  /** Operator for implicit conversion into an int binary representation 0xRRGGBB */
51  inline operator unsigned int(void) const { return (((unsigned int)R)<<16) | (((unsigned int)G)<<8) | B; }
52 
53  static TColor red; //!< Predefined colors
54  static TColor green;//!< Predefined colors
55  static TColor blue;//!< Predefined colors
56  static TColor white;//!< Predefined colors
57  static TColor black;//!< Predefined colors
58  static TColor gray; //!< Predefined colors
59  };
60 
61  /** A RGB color - floats in the range [0,1]
62  * \ingroup mrpt_base_grp */
64  {
65  TColorf(float r=0,float g=0,float b=0, float alpha=1.0f) : R(r),G(g),B(b),A(alpha) { }
66  explicit TColorf(const TColor &col) : R(col.R*(1.f/255)),G(col.G*(1.f/255)),B(col.B*(1.f/255)),A(col.A*(1.f/255)) { }
67  float R,G,B,A;
68  };
69 
70  } // end namespace
71 }
72 
73 #endif
74 



Page generated by Doxygen 1.8.3 for MRPT 0.9.6 SVN: at Fri Feb 15 22:05:02 EST 2013