YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
WireImage4mjpeg.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: BSD-3-Clause
5 */
6
7#include "WireImage4mjpeg.h"
8
10
11using namespace yarp::os;
12using namespace yarp::sig;
13
16 char *header_buf = (char*)(&hdr);
17 size_t header_len = sizeof(hdr);
18 const char *img_buf = nullptr;
19 int img_len = 0;
20 hdr.imgSize = -1;
21 for (size_t i=0; i<writer.length(); i++) {
22 const char *data = writer.data(i);
23 size_t len = writer.length(i);
24 //printf("block %d length %d\n", i, len);
25 if (header_len<len) {
26 len = header_len;
27 }
28 if (len>0) {
29 memcpy(header_buf,data,len);
30 header_len -= len;
31 header_buf += len;
32 }
33 if (header_len == 0) {
34 img_buf = data+len;
35 img_len = writer.length(i)-len;
36 }
37 }
38 if (hdr.imgSize==-1) {
39 return nullptr;
40 }
41 if (hdr.imgSize!=img_len) {
42 return nullptr;
43 }
44 //printf("Passing on a %dx%d image\n", hdr.width, hdr.height);
45 int w = hdr.width;
46 int h = hdr.height;
47 //int row_stride = hdr.imgSize/hdr.height;
48 img.setPixelCode(hdr.id);
49 img.setQuantum(hdr.quantum);
50 img.setExternal((char*)img_buf,w,h);
51 return &img;
52}
yarp::sig::FlexImage * checkForImage(yarp::os::SizedWriter &writer)
A mini-server for performing network communication in the background.
Minimal requirements for an efficient Writer.
Definition SizedWriter.h:32
virtual const char * data(size_t index) const =0
virtual size_t length() const =0
Image class with user control of representation details.
Definition Image.h:363
void setQuantum(size_t imgQuantum)
Definition Image.h:378
void setPixelCode(int imgPixelCode)
Definition Image.h:366
Byte order in image header for network transmission.
void setExternal(const void *data, size_t imgWidth, size_t imgHeight)
Use this to wrap an external image.
Definition Image.cpp:691
An interface to the operating system, including Port based communication.