ViSP  2.9.0
vpRGBa.cpp
1 /****************************************************************************
2  *
3  * $Id: vpRGBa.cpp 4574 2014-01-09 08:48:51Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2014 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  *
34  * Description:
35  * RGBA pixel.
36  *
37  * Authors:
38  * Eric Marchand
39  * Fabien Spindler
40  *
41  *****************************************************************************/
42 
50 #include <visp/vpRGBa.h>
51 #include <visp/vpColor.h>
52 #include <visp/vpDebug.h>
53 #include <visp/vpException.h>
54 
55 
61 vpRGBa &
62 vpRGBa::operator=(const unsigned char &v)
63 {
64  this->R = v;
65  this->G = v;
66  this->B = v;
67  this->A = v;
68  return *this;
69 }
70 
74 vpRGBa &
76 {
77  this->R = v.R;
78  this->G = v.G;
79  this->B = v.B;
80  this->A = v.A;
81  return *this;
82 }
83 
93 vpRGBa &
95 {
96  if (v.getRows() != 4) {
97  vpERROR_TRACE("Bad vector dimension ") ;
98  throw(vpException(vpException::dimensionError, "Bad vector dimension "));
99  }
100  R = (unsigned char)v[0];
101  G = (unsigned char)v[1];
102  B = (unsigned char)v[2];
103  A = (unsigned char)v[3];
104  return *this;
105 }
106 
113 {
114  if (R != v.R)
115  return false;
116  if (G != v.G)
117  return false;
118  if (B != v.B)
119  return false;
120  if (A != v.A)
121  return false;
122 
123  return true ;
124 }
131 {
132  if (R == v.R)
133  return false;
134  if (G == v.G)
135  return false;
136  if (B == v.B)
137  return false;
138  if (A == v.A)
139  return false;
140 
141  return true ;
142 }
143 
150 vpRGBa::operator-(const vpRGBa &v) const
151 {
152  vpColVector n(4); // new color
153  n[0] = (double)R - (double)v.R;
154  n[1] = (double)G - (double)v.G;
155  n[2] = (double)B - (double)v.B;
156  n[3] = (double)A - (double)v.A;
157  return n;
158 }
159 
166 vpRGBa
167 vpRGBa::operator+(const vpRGBa &v) const
168 {
169  vpRGBa n; // new color
170  n.R = static_cast<unsigned char>( R + v.R );
171  n.G = static_cast<unsigned char>( G + v.G );
172  n.B = static_cast<unsigned char>( B + v.B );
173  n.A = static_cast<unsigned char>( A + v.A );
174  return n;
175 }
176 
184 {
185  vpColVector n(4); // new color
186  n[0] = R - v[0];
187  n[1] = G - v[1];
188  n[2] = B - v[2];
189  n[3] = A - v[3];
190  return n;
191 }
192 
200 {
201  vpColVector n(4); // new color
202  n[0] = R + v[0];
203  n[1] = G + v[1];
204  n[2] = B + v[2];
205  n[3] = A + v[3];
206  return n;
207 }
208 
215 vpRGBa::operator*(const float &v) const
216 {
217  vpColVector n(4);
218  n[0] = R * v;
219  n[1] = G * v;
220  n[2] = B * v;
221  n[3] = A * v;
222  return n;
223 }
224 
231 vpRGBa::operator*(const double &v) const
232 {
233  vpColVector n(4);
234  n[0] = R * v;
235  n[1] = G * v;
236  n[2] = B * v;
237  n[3] = A * v;
238  return n;
239 }
240 
241 bool
242 vpRGBa::operator<(const vpRGBa &v) const
243 {
244  double gray1 = 0.2126*R+0.7152*G+0.0722*B;
245  double gray2 = 0.2126*v.R+0.7152*v.G+0.0722*v.B;
246 
247  return (gray1 < gray2);
248 }
249 
250 bool
251 vpRGBa::operator>(const vpRGBa &v) const
252 {
253  double gray1 = 0.2126*R+0.7152*G+0.0722*B;
254  double gray2 = 0.2126*v.R+0.7152*v.G+0.0722*v.B;
255 
256  return (gray1 > gray2);
257 }
258 
259 vpRGBa operator*(const double &x, const vpRGBa &rgb)
260 {
261  return rgb*x;
262 }
263 
264 /*
265  * Local variables:
266  * c-basic-offset: 2
267  * End:
268  */
#define vpERROR_TRACE
Definition: vpDebug.h:395
unsigned char B
Blue component.
Definition: vpRGBa.h:148
vpRGBa operator+(const vpRGBa &v) const
Definition: vpRGBa.cpp:167
error that can be emited by ViSP classes.
Definition: vpException.h:76
unsigned char G
Green component.
Definition: vpRGBa.h:147
Class that defines a RGB 32 bits structure.
Definition: vpRGBa.h:68
vpColVector operator*(const double &x, const vpColVector &B)
multiplication by a scalar Ci = x*Bi
bool operator>(const vpRGBa &v) const
Definition: vpRGBa.cpp:251
bool operator==(const vpRGBa &v)
Definition: vpRGBa.cpp:112
unsigned char A
Additionnal component.
Definition: vpRGBa.h:149
vpRGBa & operator=(const unsigned char &v)
Definition: vpRGBa.cpp:62
Class that provides a data structure for the column vectors as well as a set of operations on these v...
Definition: vpColVector.h:72
bool operator<(const vpRGBa &v) const
Definition: vpRGBa.cpp:242
unsigned char R
Red component.
Definition: vpRGBa.h:146
vpColVector operator*(const float &v) const
Definition: vpRGBa.cpp:215
unsigned int getRows() const
Return the number of rows of the matrix.
Definition: vpMatrix.h:161
vpColVector operator-(const vpRGBa &v) const
Definition: vpRGBa.cpp:150
bool operator!=(const vpRGBa &v)
Definition: vpRGBa.cpp:130