Visual Servoing Platform  version 3.6.1 under development (2024-07-27)
vpRGBa.h
1 /*
2  * ViSP, open source Visual Servoing Platform software.
3  * Copyright (C) 2005 - 2024 by Inria. All rights reserved.
4  *
5  * This software is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See https://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * Description:
31  * RGBA pixel.
32  */
33 
40 #ifndef VP_RGBA_H
41 #define VP_RGBA_H
42 
43 #include <assert.h>
44 
45 #include <visp3/core/vpConfig.h>
46 #include <visp3/core/vpColVector.h>
47 
64 class VISP_EXPORT vpRGBa
65 {
66 public:
67  enum AlphaDefault { alpha_default = 255 };
68 
74  inline vpRGBa() : R(0), G(0), B(0), A(vpRGBa::alpha_default) { }
75 
86  inline vpRGBa(unsigned char r, unsigned char g, unsigned char b, unsigned char a = vpRGBa::alpha_default)
87  : R(r), G(g), B(b), A(a)
88  { }
89 
97  VP_EXPLICIT inline vpRGBa(unsigned char v) : R(v), G(v), B(v), A(v) { }
98 
106  VP_EXPLICIT inline vpRGBa(unsigned int v) : R(v), G(v), B(v), A(v)
107  {
108  assert(v < 256);
109  }
110 
118  VP_EXPLICIT inline vpRGBa(int v) : R(v), G(v), B(v), A(v)
119  {
120  assert(v < 256);
121  }
122 
126  inline vpRGBa(const vpRGBa &v) : R(v.R), G(v.G), B(v.B), A(v.A) { }
127 
136  VP_EXPLICIT inline vpRGBa(const vpColVector &v) : R(0), G(0), B(0), A(vpRGBa::alpha_default) { *this = v; }
137 
138  // We cannot add here the following destructor without changing the
139  // hypothesis that the size of this class is 4. With the destructor it
140  // becomes 16 that does break a lot of things around image conversions
141  // virtual ~vpRGBa() {}; // Not to implement
142 
143  vpRGBa &operator=(const unsigned char &v);
144  vpRGBa &operator=(const unsigned int &v);
145  vpRGBa &operator=(const int &v);
146  vpRGBa &operator=(const vpRGBa &v);
147 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
148  vpRGBa &operator=(const vpRGBa &&v);
149 #endif
150  vpRGBa &operator=(const vpColVector &v);
151  bool operator==(const vpRGBa &v) const;
152  bool operator!=(const vpRGBa &v) const;
153 
154  vpColVector operator-(const vpRGBa &v) const;
155  vpRGBa operator+(const vpRGBa &v) const;
156  vpColVector operator-(const vpColVector &v) const;
157  vpColVector operator+(const vpColVector &v) const;
158  vpColVector operator*(const float &v) const;
159  vpColVector operator*(const double &v) const;
160 
161  bool operator<(const vpRGBa &v) const;
162  bool operator>(const vpRGBa &v) const;
163 
164  friend VISP_EXPORT std::ostream &operator<<(std::ostream &os, const vpRGBa &rgba);
165 
166 public:
167  unsigned char R;
168  unsigned char G;
169  unsigned char B;
170  unsigned char A;
171 
172  friend VISP_EXPORT vpRGBa operator*(const double &x, const vpRGBa &rgb);
173 };
174 END_VISP_NAMESPACE
175 #endif
Implementation of column vector and the associated operations.
Definition: vpColVector.h:191
Definition: vpRGBa.h:65
unsigned char B
Blue component.
Definition: vpRGBa.h:169
VP_EXPLICIT vpRGBa(const vpColVector &v)
Definition: vpRGBa.h:136
vpRGBa(unsigned char r, unsigned char g, unsigned char b, unsigned char a=vpRGBa::alpha_default)
Definition: vpRGBa.h:86
VP_EXPLICIT vpRGBa(unsigned int v)
Definition: vpRGBa.h:106
unsigned char R
Red component.
Definition: vpRGBa.h:167
VP_EXPLICIT vpRGBa(int v)
Definition: vpRGBa.h:118
vpRGBa(const vpRGBa &v)
Definition: vpRGBa.h:126
vpRGBa()
Definition: vpRGBa.h:74
unsigned char G
Green component.
Definition: vpRGBa.h:168
AlphaDefault
Definition: vpRGBa.h:67
@ alpha_default
Definition: vpRGBa.h:67
VP_EXPLICIT vpRGBa(unsigned char v)
Definition: vpRGBa.h:97
unsigned char A
Additionnal component.
Definition: vpRGBa.h:170
vpMatrix operator*(const double &x, const vpMatrix &A)