Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpImageConvert_yarp.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 * Convert image types.
32 */
33
37
38#include <visp3/core/vpConfig.h>
39
40#ifdef VISP_HAVE_YARP
41
42#include <visp3/core/vpImageConvert.h>
43
82void vpImageConvert::convert(const vpImage<unsigned char> &src, yarp::sig::ImageOf<yarp::sig::PixelMono> *dest,
83 bool copyData)
84{
85 if (copyData) {
86 dest->resize(src.getWidth(), src.getHeight());
87 for (unsigned int i = 0; i < src.getHeight(); ++i) {
88 for (unsigned int j = 0; j < src.getWidth(); ++j) {
89 dest->pixel(j, i) = src[i][j];
90 }
91 }
92 }
93 else {
94 dest->setExternal(src.bitmap, static_cast<int>(src.getCols()), static_cast<int>(src.getRows()));
95 }
96}
97
140void vpImageConvert::convert(const yarp::sig::ImageOf<yarp::sig::PixelMono> *src, vpImage<unsigned char> &dest,
141 bool copyData)
142{
143 dest.resize(src->height(), src->width());
144 (void)(copyData);
145 for (unsigned int i = 0; i < dest.getHeight(); ++i) {
146 for (unsigned int j = 0; j < dest.getWidth(); ++j) {
147 dest[i][j] = src->pixel(j, i);
148 }
149 }
150}
151
190void vpImageConvert::convert(const vpImage<vpRGBa> &src, yarp::sig::ImageOf<yarp::sig::PixelRgba> *dest, bool copyData)
191{
192 if (copyData) {
193 dest->resize(src.getWidth(), src.getHeight());
194 memcpy(dest->getRawImage(), src.bitmap, src.getHeight() * src.getWidth() * sizeof(vpRGBa));
195 }
196 else {
197 dest->setExternal(src.bitmap, static_cast<int>(src.getCols()), static_cast<int>(src.getRows()));
198 }
199}
200
243void vpImageConvert::convert(const yarp::sig::ImageOf<yarp::sig::PixelRgba> *src, vpImage<vpRGBa> &dest, bool copyData)
244{
245 dest.resize(src->height(), src->width());
246 (void)(copyData);
247 for (unsigned int i = 0; i < dest.getHeight(); ++i) {
248 for (unsigned int j = 0; j < dest.getWidth(); ++j) {
249 dest[i][j].R = src->pixel(j, i).r;
250 dest[i][j].G = src->pixel(j, i).g;
251 dest[i][j].B = src->pixel(j, i).b;
252 dest[i][j].A = src->pixel(j, i).a;
253 }
254 }
255}
256
293void vpImageConvert::convert(const vpImage<vpRGBa> &src, yarp::sig::ImageOf<yarp::sig::PixelRgb> *dest)
294{
295 const unsigned int srcRows = src.getRows(), srcWidth = src.getWidth();
296 dest->resize(src.getWidth(), src.getHeight());
297 for (unsigned int i = 0; i < srcRows; ++i) {
298 for (unsigned int j = 0; j < srcWidth; ++j) {
299 dest->pixel(j, i).r = src[i][j].R;
300 dest->pixel(j, i).g = src[i][j].G;
301 dest->pixel(j, i).b = src[i][j].B;
302 }
303 }
304}
305
348void vpImageConvert::convert(const yarp::sig::ImageOf<yarp::sig::PixelRgb> *src, vpImage<vpRGBa> &dest)
349{
350 const int srcHeight = src->height(), srcWidth = src->width();
351 dest.resize(srcHeight, srcWidth);
352 for (int i = 0; i < srcHeight; ++i) {
353 for (int j = 0; j < srcWidth; ++j) {
354 dest[i][j].R = src->pixel(j, i).r;
355 dest[i][j].G = src->pixel(j, i).g;
356 dest[i][j].B = src->pixel(j, i).b;
357 dest[i][j].A = vpRGBa::alpha_default;
358 }
359 }
360}
361
362END_VISP_NAMESPACE
363
364#endif
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
Definition of the vpImage class member functions.
Definition vpImage.h:131
unsigned int getWidth() const
Definition vpImage.h:242
unsigned int getCols() const
Definition vpImage.h:171
Type * bitmap
points toward the bitmap
Definition vpImage.h:135
unsigned int getHeight() const
Definition vpImage.h:181
unsigned int getRows() const
Definition vpImage.h:212
@ alpha_default
Definition vpRGBa.h:76