ViSP  2.8.0
vpRGBa.cpp
1 /****************************************************************************
2  *
3  * $Id: vpRGBa.cpp 4056 2013-01-05 13:04:42Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2013 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 void
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 }
69 
73 void
75 {
76  this->R = v.R;
77  this->G = v.G;
78  this->B = v.B;
79  this->A = v.A;
80 }
81 
91 void
93 {
94  if (v.getRows() != 4) {
95  vpERROR_TRACE("Bad vector dimension ") ;
96  throw(vpException(vpException::dimensionError, "Bad vector dimension "));
97  }
98  R = (unsigned char)v[0];
99  G = (unsigned char)v[1];
100  B = (unsigned char)v[2];
101  A = (unsigned char)v[3];
102 }
103 
110 {
111  if (R != v.R)
112  return false;
113  if (G != v.G)
114  return false;
115  if (B != v.B)
116  return false;
117  if (A != v.A)
118  return false;
119 
120  return true ;
121 }
128 {
129  if (R == v.R)
130  return false;
131  if (G == v.G)
132  return false;
133  if (B == v.B)
134  return false;
135  if (A == v.A)
136  return false;
137 
138  return true ;
139 }
140 
147 vpRGBa::operator-(const vpRGBa &v) const
148 {
149  vpColVector n(4); // new color
150  n[0] = (double)R - (double)v.R;
151  n[1] = (double)G - (double)v.G;
152  n[2] = (double)B - (double)v.B;
153  n[3] = (double)A - (double)v.A;
154  return n;
155 }
156 
163 vpRGBa
164 vpRGBa::operator+(const vpRGBa &v) const
165 {
166  vpRGBa n; // new color
167  n.R = static_cast<unsigned char>( R + v.R );
168  n.G = static_cast<unsigned char>( G + v.G );
169  n.B = static_cast<unsigned char>( B + v.B );
170  n.A = static_cast<unsigned char>( A + v.A );
171  return n;
172 }
173 
181 {
182  vpColVector n(4); // new color
183  n[0] = R - v[0];
184  n[1] = G - v[1];
185  n[2] = B - v[2];
186  n[3] = A - v[3];
187  return n;
188 }
189 
197 {
198  vpColVector n(4); // new color
199  n[0] = R + v[0];
200  n[1] = G + v[1];
201  n[2] = B + v[2];
202  n[3] = A + v[3];
203  return n;
204 }
205 
212 vpRGBa::operator*(const float &v) const
213 {
214  vpColVector n(4);
215  n[0] = R * v;
216  n[1] = G * v;
217  n[2] = B * v;
218  n[3] = A * v;
219  return n;
220 }
221 
228 vpRGBa::operator*(const double &v) const
229 {
230  vpColVector n(4);
231  n[0] = R * v;
232  n[1] = G * v;
233  n[2] = B * v;
234  n[3] = A * v;
235  return n;
236 }
237 
238 bool
239 vpRGBa::operator<(const vpRGBa &v) const
240 {
241  double gray1 = 0.2126*R+0.7152*G+0.0722*B;
242  double gray2 = 0.2126*v.R+0.7152*v.G+0.0722*v.B;
243 
244  return (gray1 < gray2);
245 }
246 
247 bool
248 vpRGBa::operator>(const vpRGBa &v) const
249 {
250  double gray1 = 0.2126*R+0.7152*G+0.0722*B;
251  double gray2 = 0.2126*v.R+0.7152*v.G+0.0722*v.B;
252 
253  return (gray1 > gray2);
254 }
255 
256 vpRGBa operator*(const double &x, const vpRGBa &rgb)
257 {
258  return rgb*x;
259 }
260 
261 /*
262  * Local variables:
263  * c-basic-offset: 2
264  * End:
265  */
#define vpERROR_TRACE
Definition: vpDebug.h:379
unsigned char B
Blue component.
Definition: vpRGBa.h:155
VISP_EXPORT vpImagePoint operator*(const vpImagePoint &ip1, const double scale)
Definition: vpImagePoint.h:468
vpRGBa operator+(const vpRGBa &v) const
Definition: vpRGBa.cpp:164
error that can be emited by ViSP classes.
Definition: vpException.h:75
unsigned char G
Green component.
Definition: vpRGBa.h:154
Class that defines a RGB 32 bits structure.
Definition: vpRGBa.h:68
bool operator>(const vpRGBa &v) const
Definition: vpRGBa.cpp:248
bool operator==(const vpRGBa &v)
Definition: vpRGBa.cpp:109
void operator=(const unsigned char &v)
Definition: vpRGBa.cpp:62
unsigned char A
Additionnal component.
Definition: vpRGBa.h:156
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:239
unsigned char R
Red component.
Definition: vpRGBa.h:153
vpColVector operator*(const float &v) const
Definition: vpRGBa.cpp:212
unsigned int getRows() const
Return the number of rows of the matrix.
Definition: vpMatrix.h:157
vpColVector operator-(const vpRGBa &v) const
Definition: vpRGBa.cpp:147
bool operator!=(const vpRGBa &v)
Definition: vpRGBa.cpp:127