Visual Servoing Platform  version 3.6.1 under development (2025-02-01)
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 
48 #if ((__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L)))
49 #include <type_traits>
50 #endif
51 
52 
53 BEGIN_VISP_NAMESPACE
69 class VISP_EXPORT vpRGBa
70 {
71 public:
72  enum AlphaDefault { alpha_default = 255 };
73 
79  inline vpRGBa() : R(0), G(0), B(0), A(vpRGBa::alpha_default) { }
80 
91  inline vpRGBa(unsigned char r, unsigned char g, unsigned char b, unsigned char a = vpRGBa::alpha_default)
92  : R(r), G(g), B(b), A(a)
93  { }
94 
102  VP_EXPLICIT inline vpRGBa(unsigned char v) : R(v), G(v), B(v), A(v) { }
103 
111  VP_EXPLICIT inline vpRGBa(unsigned int v) : R(v), G(v), B(v), A(v)
112  {
113  assert(v < 256);
114  }
115 
123  VP_EXPLICIT inline vpRGBa(int v) : R(v), G(v), B(v), A(v)
124  {
125  assert(v < 256);
126  }
127 
131 #if ((__cplusplus >= 201103L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201103L))) // Check if cxx11 or higher
132  inline vpRGBa(const vpRGBa &v) = default;
133 #else
134  inline vpRGBa(const vpRGBa &v) : R(v.R), G(v.G), B(v.B), A(v.A) { }
135 #endif
136 
145  VP_EXPLICIT inline vpRGBa(const vpColVector &v) : R(0), G(0), B(0), A(vpRGBa::alpha_default) { *this = v; }
146 
147  // We cannot add here the following destructor without changing the
148  // hypothesis that the size of this class is 4. With the destructor it
149  // becomes 16 that does break a lot of things around image conversions
150  // virtual ~vpRGBa() {}; // Not to implement
151 
152  vpRGBa &operator=(const unsigned char &v);
153  vpRGBa &operator=(const unsigned int &v);
154  vpRGBa &operator=(const int &v);
155 #if ((__cplusplus >= 201103L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201103L))) // Check if cxx11 or higher
156  vpRGBa &operator=(vpRGBa &&v) = default;
157  vpRGBa &operator=(const vpRGBa &v) = default;
158 #else
160  {
161  this->R = v.R;
162  this->G = v.G;
163  this->B = v.B;
164  this->A = v.A;
165  return *this;
166  }
167 #endif
168  vpRGBa &operator=(const vpColVector &v);
169  bool operator==(const vpRGBa &v) const;
170  bool operator!=(const vpRGBa &v) const;
171 
172  vpColVector operator-(const vpRGBa &v) const;
173  vpRGBa operator+(const vpRGBa &v) const;
174  vpColVector operator-(const vpColVector &v) const;
175  vpColVector operator+(const vpColVector &v) const;
176  vpColVector operator*(const float &v) const;
177  vpColVector operator*(const double &v) const;
178 
179  bool operator<(const vpRGBa &v) const;
180  bool operator>(const vpRGBa &v) const;
181 
182  friend VISP_EXPORT std::ostream &operator<<(std::ostream &os, const vpRGBa &rgba);
183 
184 public:
185  unsigned char R;
186  unsigned char G;
187  unsigned char B;
188  unsigned char A;
189 
190  friend VISP_EXPORT vpRGBa operator*(const double &x, const vpRGBa &rgb);
191 };
192 
193 #if ((__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L)))
194 static_assert(std::is_trivially_assignable_v<vpRGBa, vpRGBa>);
195 static_assert(std::is_trivially_copyable_v<vpRGBa>);
196 #endif
197 
198 END_VISP_NAMESPACE
199 #endif
Implementation of column vector and the associated operations.
Definition: vpColVector.h:191
Definition: vpRGBa.h:70
unsigned char B
Blue component.
Definition: vpRGBa.h:187
VP_EXPLICIT vpRGBa(const vpColVector &v)
Definition: vpRGBa.h:145
vpRGBa(unsigned char r, unsigned char g, unsigned char b, unsigned char a=vpRGBa::alpha_default)
Definition: vpRGBa.h:91
VP_EXPLICIT vpRGBa(unsigned int v)
Definition: vpRGBa.h:111
unsigned char R
Red component.
Definition: vpRGBa.h:185
VP_EXPLICIT vpRGBa(int v)
Definition: vpRGBa.h:123
vpRGBa(const vpRGBa &v)
Definition: vpRGBa.h:134
vpRGBa()
Definition: vpRGBa.h:79
vpRGBa & operator=(const vpRGBa &v)
Definition: vpRGBa.h:159
unsigned char G
Green component.
Definition: vpRGBa.h:186
AlphaDefault
Definition: vpRGBa.h:72
@ alpha_default
Definition: vpRGBa.h:72
VP_EXPLICIT vpRGBa(unsigned char v)
Definition: vpRGBa.h:102
unsigned char A
Additional component.
Definition: vpRGBa.h:188
vpMatrix operator*(const double &x, const vpMatrix &A)