Visual Servoing Platform  version 3.0.0
vpRGBa.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2015 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
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 http://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  * Authors:
34  * Eric Marchand
35  * Fabien Spindler
36  *
37  *****************************************************************************/
38 
46 #include <visp3/core/vpRGBa.h>
47 #include <visp3/core/vpColor.h>
48 #include <visp3/core/vpDebug.h>
49 #include <visp3/core/vpException.h>
50 
51 
57 vpRGBa &
58 vpRGBa::operator=(const unsigned char &v)
59 {
60  this->R = v;
61  this->G = v;
62  this->B = v;
63  this->A = v;
64  return *this;
65 }
66 
70 vpRGBa &
72 {
73  this->R = v.R;
74  this->G = v.G;
75  this->B = v.B;
76  this->A = v.A;
77  return *this;
78 }
79 
89 vpRGBa &
91 {
92  if (v.getRows() != 4) {
93  vpERROR_TRACE("Bad vector dimension ") ;
94  throw(vpException(vpException::dimensionError, "Bad vector dimension "));
95  }
96  R = (unsigned char)v[0];
97  G = (unsigned char)v[1];
98  B = (unsigned char)v[2];
99  A = (unsigned char)v[3];
100  return *this;
101 }
102 
109 {
110  if (R != v.R)
111  return false;
112  if (G != v.G)
113  return false;
114  if (B != v.B)
115  return false;
116  if (A != v.A)
117  return false;
118 
119  return true ;
120 }
127 {
128  return (R != v.R || G != v.G || B != v.B || A != v.A);
129 }
130 
137 vpRGBa::operator-(const vpRGBa &v) const
138 {
139  vpColVector n(4); // new color
140  n[0] = (double)R - (double)v.R;
141  n[1] = (double)G - (double)v.G;
142  n[2] = (double)B - (double)v.B;
143  n[3] = (double)A - (double)v.A;
144  return n;
145 }
146 
153 vpRGBa
154 vpRGBa::operator+(const vpRGBa &v) const
155 {
156  vpRGBa n; // new color
157  n.R = static_cast<unsigned char>( R + v.R );
158  n.G = static_cast<unsigned char>( G + v.G );
159  n.B = static_cast<unsigned char>( B + v.B );
160  n.A = static_cast<unsigned char>( A + v.A );
161  return n;
162 }
163 
171 {
172  vpColVector n(4); // new color
173  n[0] = R - v[0];
174  n[1] = G - v[1];
175  n[2] = B - v[2];
176  n[3] = A - v[3];
177  return n;
178 }
179 
187 {
188  vpColVector n(4); // new color
189  n[0] = R + v[0];
190  n[1] = G + v[1];
191  n[2] = B + v[2];
192  n[3] = A + v[3];
193  return n;
194 }
195 
202 vpRGBa::operator*(const float &v) const
203 {
204  vpColVector n(4);
205  n[0] = R * v;
206  n[1] = G * v;
207  n[2] = B * v;
208  n[3] = A * v;
209  return n;
210 }
211 
218 vpRGBa::operator*(const double &v) const
219 {
220  vpColVector n(4);
221  n[0] = R * v;
222  n[1] = G * v;
223  n[2] = B * v;
224  n[3] = A * v;
225  return n;
226 }
227 
228 bool
229 vpRGBa::operator<(const vpRGBa &v) const
230 {
231  double gray1 = 0.2126*R+0.7152*G+0.0722*B;
232  double gray2 = 0.2126*v.R+0.7152*v.G+0.0722*v.B;
233 
234  return (gray1 < gray2);
235 }
236 
237 bool
238 vpRGBa::operator>(const vpRGBa &v) const
239 {
240  double gray1 = 0.2126*R+0.7152*G+0.0722*B;
241  double gray2 = 0.2126*v.R+0.7152*v.G+0.0722*v.B;
242 
243  return (gray1 > gray2);
244 }
245 
246 vpRGBa operator*(const double &x, const vpRGBa &rgb)
247 {
248  return rgb*x;
249 }
250 
251 /*
252  * Local variables:
253  * c-basic-offset: 2
254  * End:
255  */
unsigned char B
Blue component.
Definition: vpRGBa.h:144
vpColVector operator*(const double &x, const vpColVector &v)
#define vpERROR_TRACE
Definition: vpDebug.h:391
vpRGBa operator+(const vpRGBa &v) const
Definition: vpRGBa.cpp:154
error that can be emited by ViSP classes.
Definition: vpException.h:73
unsigned char G
Green component.
Definition: vpRGBa.h:143
Class that defines a RGB 32 bits structure.
Definition: vpRGBa.h:64
bool operator>(const vpRGBa &v) const
Definition: vpRGBa.cpp:238
bool operator==(const vpRGBa &v)
Definition: vpRGBa.cpp:108
unsigned char A
Additionnal component.
Definition: vpRGBa.h:145
unsigned int getRows() const
Return the number of rows of the 2D array.
Definition: vpArray2D.h:152
vpRGBa & operator=(const unsigned char &v)
Definition: vpRGBa.cpp:58
Implementation of column vector and the associated operations.
Definition: vpColVector.h:72
bool operator<(const vpRGBa &v) const
Definition: vpRGBa.cpp:229
unsigned char R
Red component.
Definition: vpRGBa.h:142
vpColVector operator*(const float &v) const
Definition: vpRGBa.cpp:202
vpColVector operator-(const vpRGBa &v) const
Definition: vpRGBa.cpp:137
bool operator!=(const vpRGBa &v)
Definition: vpRGBa.cpp:126