Visual Servoing Platform
version 3.7.0
Toggle main menu visibility
Loading...
Searching...
No Matches
vpRGBa.cpp
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
39
40
#include <visp3/core/vpColor.h>
41
#include <visp3/core/vpException.h>
42
#include <visp3/core/vpRGBa.h>
43
#include <visp3/core/vpHSV.h>
44
45
46
BEGIN_VISP_NAMESPACE
47
53
vpRGBa
&
vpRGBa::operator=
(
const
unsigned
char
&v)
54
{
55
this->
R
= v;
56
this->
G
= v;
57
this->
B
= v;
58
this->
A
= v;
59
return
*
this
;
60
}
61
67
vpRGBa
&
vpRGBa::operator=
(
const
unsigned
int
&v)
68
{
69
assert(v < 256);
70
this->
R
= v;
71
this->
G
= v;
72
this->
B
= v;
73
this->
A
= v;
74
return
*
this
;
75
}
76
82
vpRGBa
&
vpRGBa::operator=
(
const
int
&v)
83
{
84
assert(v < 256);
85
this->
R
= v;
86
this->
G
= v;
87
this->
B
= v;
88
this->
A
= v;
89
return
*
this
;
90
}
91
101
vpRGBa
&
vpRGBa::operator=
(
const
vpColVector
&v)
102
{
103
const
unsigned
int
val_4 = 4;
104
if
(v.getRows() != val_4) {
105
throw
(
vpException
(
vpException::dimensionError
,
"Bad vector dimension "
));
106
}
107
const
unsigned
int
index_0 = 0;
108
const
unsigned
int
index_1 = 1;
109
const
unsigned
int
index_2 = 2;
110
const
unsigned
int
index_3 = 3;
111
R
=
static_cast<
unsigned
char
>
(v[index_0]);
112
G
=
static_cast<
unsigned
char
>
(v[index_1]);
113
B
=
static_cast<
unsigned
char
>
(v[index_2]);
114
A
=
static_cast<
unsigned
char
>
(v[index_3]);
115
return
*
this
;
116
}
117
123
bool
vpRGBa::operator==
(
const
vpRGBa
&v)
const
124
{
125
return
(
R
== v.R) && (
G
== v.G) && (
B
== v.B) && (
A
== v.A);
126
}
127
132
bool
vpRGBa::operator!=
(
const
vpRGBa
&v)
const
{
return
((
R
!= v.R) || (
G
!= v.G) || (
B
!= v.B) || (
A
!= v.A)); }
133
139
vpColVector
vpRGBa::operator-
(
const
vpRGBa
&v)
const
140
{
141
vpColVector
n(4);
// new color
142
const
unsigned
int
index_0 = 0;
143
const
unsigned
int
index_1 = 1;
144
const
unsigned
int
index_2 = 2;
145
const
unsigned
int
index_3 = 3;
146
n[index_0] =
static_cast<
double
>
(
R
) -
static_cast<
double
>
(v.R);
147
n[index_1] =
static_cast<
double
>
(
G
) -
static_cast<
double
>
(v.G);
148
n[index_2] =
static_cast<
double
>
(
B
) -
static_cast<
double
>
(v.B);
149
n[index_3] =
static_cast<
double
>
(
A
) -
static_cast<
double
>
(v.A);
150
return
n;
151
}
152
159
vpRGBa
vpRGBa::operator+
(
const
vpRGBa
&v)
const
160
{
161
vpRGBa
n;
// new color
162
n.
R
=
static_cast<
unsigned
char
>
(
R
+ v.R);
163
n.
G
=
static_cast<
unsigned
char
>
(
G
+ v.G);
164
n.
B
=
static_cast<
unsigned
char
>
(
B
+ v.B);
165
n.
A
=
static_cast<
unsigned
char
>
(
A
+ v.A);
166
return
n;
167
}
168
174
vpColVector
vpRGBa::operator-
(
const
vpColVector
&v)
const
175
{
176
vpColVector
n(4);
// new color
177
const
unsigned
int
index_0 = 0;
178
const
unsigned
int
index_1 = 1;
179
const
unsigned
int
index_2 = 2;
180
const
unsigned
int
index_3 = 3;
181
n[index_0] =
R
- v[index_0];
182
n[index_1] =
G
- v[index_1];
183
n[index_2] =
B
- v[index_2];
184
n[index_3] =
A
- v[index_3];
185
return
n;
186
}
187
193
vpColVector
vpRGBa::operator+
(
const
vpColVector
&v)
const
194
{
195
vpColVector
n(4);
// new color
196
const
unsigned
int
index_0 = 0;
197
const
unsigned
int
index_1 = 1;
198
const
unsigned
int
index_2 = 2;
199
const
unsigned
int
index_3 = 3;
200
n[index_0] =
R
+ v[index_0];
201
n[index_1] =
G
+ v[index_1];
202
n[index_2] =
B
+ v[index_2];
203
n[index_3] =
A
+ v[index_3];
204
return
n;
205
}
206
212
vpColVector
vpRGBa::operator*
(
const
float
&v)
const
213
{
214
vpColVector
n(4);
215
const
unsigned
int
index_0 = 0;
216
const
unsigned
int
index_1 = 1;
217
const
unsigned
int
index_2 = 2;
218
const
unsigned
int
index_3 = 3;
219
n[index_0] =
R
* v;
220
n[index_1] =
G
* v;
221
n[index_2] =
B
* v;
222
n[index_3] =
A
* v;
223
return
n;
224
}
225
231
vpColVector
vpRGBa::operator*
(
const
double
&v)
const
232
{
233
vpColVector
n(4);
234
const
unsigned
int
index_0 = 0;
235
const
unsigned
int
index_1 = 1;
236
const
unsigned
int
index_2 = 2;
237
const
unsigned
int
index_3 = 3;
238
n[index_0] =
R
* v;
239
n[index_1] =
G
* v;
240
n[index_2] =
B
* v;
241
n[index_3] =
A
* v;
242
return
n;
243
}
244
245
bool
vpRGBa::operator<
(
const
vpRGBa
&v)
const
246
{
247
double
gray1 = (0.2126 *
R
) + (0.7152 *
G
) + (0.0722 *
B
);
248
double
gray2 = (0.2126 * v.R) + (0.7152 * v.G) + (0.0722 * v.B);
249
250
return
(gray1 < gray2);
251
}
252
253
bool
vpRGBa::operator>
(
const
vpRGBa
&v)
const
254
{
255
double
gray1 = (0.2126 *
R
) + (0.7152 *
G
) + (0.0722 *
B
);
256
double
gray2 = (0.2126 * v.R) + (0.7152 * v.G) + (0.0722 * v.B);
257
258
return
(gray1 > gray2);
259
}
260
268
vpRGBa
operator*
(
const
double
&x,
const
vpRGBa
&rgb)
269
{
270
vpRGBa
rgba;
271
rgba.
R
=
static_cast<
unsigned
char
>
(rgb.
R
* x);
272
rgba.
G
=
static_cast<
unsigned
char
>
(rgb.
G
* x);
273
rgba.
B
=
static_cast<
unsigned
char
>
(rgb.
B
* x);
274
rgba.
A
= rgb.
A
;
275
return
rgba;
276
}
277
303
VISP_EXPORT std::ostream &
operator<<
(std::ostream &os,
const
vpRGBa
&rgba)
304
{
305
os <<
"("
<<
static_cast<
int
>
(rgba.
R
) <<
","
<<
static_cast<
int
>
(rgba.
G
) <<
","
<<
static_cast<
int
>
(rgba.
B
) <<
","
<<
static_cast<
int
>
(rgba.
A
) <<
")"
;
306
return
os;
307
}
308
END_VISP_NAMESPACE
vpColVector
Implementation of column vector and the associated operations.
Definition
vpColVector.h:191
vpException
error that can be emitted by ViSP classes.
Definition
vpException.h:60
vpException::dimensionError
@ dimensionError
Bad dimension.
Definition
vpException.h:71
vpRGBa::operator-
vpColVector operator-(const vpRGBa &v) const
Definition
vpRGBa.cpp:139
vpRGBa::B
unsigned char B
Blue component.
Definition
vpRGBa.h:327
vpRGBa::R
unsigned char R
Red component.
Definition
vpRGBa.h:325
vpRGBa::operator<
bool operator<(const vpRGBa &v) const
Definition
vpRGBa.cpp:245
vpRGBa::operator<<
friend VISP_EXPORT std::ostream & operator<<(std::ostream &os, const vpRGBa &rgba)
Definition
vpRGBa.cpp:303
vpRGBa::vpRGBa
vpRGBa()
Definition
vpRGBa.h:83
vpRGBa::operator+
vpRGBa operator+(const vpRGBa &v) const
Definition
vpRGBa.cpp:159
vpRGBa::G
unsigned char G
Green component.
Definition
vpRGBa.h:326
vpRGBa::A
unsigned char A
Additional component.
Definition
vpRGBa.h:328
vpRGBa::operator>
bool operator>(const vpRGBa &v) const
Definition
vpRGBa.cpp:253
vpRGBa::operator=
vpRGBa & operator=(const unsigned char &v)
Definition
vpRGBa.cpp:53
vpRGBa::operator*
vpColVector operator*(const float &v) const
Definition
vpRGBa.cpp:212
vpRGBa::operator!=
bool operator!=(const vpRGBa &v) const
Definition
vpRGBa.cpp:132
vpRGBa::operator==
bool operator==(const vpRGBa &v) const
Definition
vpRGBa.cpp:123
BEGIN_VISP_NAMESPACE
Definition
vpMbtDistanceCircle.cpp:55
modules
core
src
image
vpRGBa.cpp
Generated by
1.17.0