YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
ImagePort.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-FileCopyrightText: 2006-2010 RobotCub Consortium
4 * SPDX-License-Identifier: LGPL-2.1-or-later
5 */
6
7// ImagePort.cpp: implementation of the ImagePort class.
8//
10
11#include "ImagePort.h"
12#include <yarp/sig/ImageFile.h>
13
14using namespace yarp::os;
15
16#include <sstream>
17
19{
20 sigHandler = nullptr;
21 counter = 0;
22}
23
25
29#ifdef YARP_LITTLE_ENDIAN
31#else
33#endif
34{
35
37 QSize s = (QSize(img.width(),img.height()));
38 int imgSize = img.getRawImageSize();
39
40 // Allocate a QVideoFrame
41 QVideoFrame frame(imgSize, s, img.getRowSize(), QVideoFrame::Format_RGB32);
42
43 // Maps the buffer
44 frame.map(QAbstractVideoBuffer::WriteOnly);
45 // Takes the ownership of the buffer in write only mode
46 tmpBuf = frame.bits();
47 unsigned char *rawImg = img.getRawImage();
48 //int j = 0;
49 // Inverts the planes because Qt Wants an image in RGB format instead of BGR
50 /* for(int i=0; i<imgSize; i++){
51 tmpBuf[j+2] = rawImg[i];
52 i++;
53 tmpBuf[j+1] = rawImg[i];
54 i++;
55 tmpBuf[j] = rawImg[i];
56 tmpBuf[j+3] = 0;
57 j+=4;
58 }*/
59
60 if (1)
61 {
62 memcpy(tmpBuf, rawImg, imgSize);
63 }
64 else
65 { //flip the image along the y axis
66 for(int x = 0; x < s.height(); x++) {
67 memcpy(tmpBuf + x * img.getRowSize(),
68 rawImg + (s.height() - x - 1) * img.getRowSize(),
69 img.getRowSize());
70 }
71 }
72
73 //unmap the buffer
74 frame.unmap();
75 if(sigHandler){
76 sigHandler->sendVideoFrame(frame);
77 }
78
79}
80
static void handler(int sig)
Definition RFModule.cpp:241
void onRead(yarp::sig::ImageOf< yarp::sig::PixelBgra > &img) override
the function callback
Definition ImagePort.cpp:30
void setSignalHandler(SignalHandler *)
sets the signalhandler to the class
Definition ImagePort.cpp:84
The class that handles some signals.
A mini-server for performing network communication in the background.
Typed image class.
Definition Image.h:605
size_t width() const
Gets width of image in pixels.
Definition Image.h:171
size_t getRowSize() const
Size of the underlying image buffer rows.
Definition Image.h:197
unsigned char * getRawImage() const
Access to the internal image buffer.
Definition Image.cpp:479
size_t getRawImageSize() const
Access to the internal buffer size information (this is how much memory has been allocated for the im...
Definition Image.cpp:488
size_t height() const
Gets height of image in pixels.
Definition Image.h:177
An interface to the operating system, including Port based communication.