YARP
Yet Another Robot Platform
WireImage.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 "WireImage.h"
8 
10 
11 using namespace yarp::os;
12 using namespace yarp::sig;
13 using namespace yarp::wire_rep_utils;
14 
15 FlexImage *WireImage::checkForImage(SizedWriter& writer) {
17  char *header_buf = (char*)(&hdr);
18  size_t header_len = sizeof(hdr);
19  const char *img_buf = nullptr;
20  int img_len = 0;
21  hdr.imgSize = -1;
22  for (size_t i=0; i<writer.length(); i++) {
23  const char *data = writer.data(i);
24  size_t len = writer.length(i);
25  //printf("block %d length %d\n", i, len);
26  if (header_len<len) {
27  len = header_len;
28  }
29  if (len>0) {
30  memcpy(header_buf,data,len);
31  header_len -= len;
32  header_buf += len;
33  }
34  if (header_len == 0) {
35  img_buf = data+len;
36  img_len = writer.length(i)-len;
37  }
38  }
39  if (hdr.imgSize==-1) {
40  return nullptr;
41  }
42  if (hdr.imgSize!=img_len) {
43  return nullptr;
44  }
45  //printf("Passing on a %dx%d image\n", hdr.width, hdr.height);
46  int w = hdr.width;
47  int h = hdr.height;
48  //int row_stride = hdr.imgSize/hdr.height;
49  img.setPixelCode(hdr.id);
50  img.setQuantum(hdr.quantum);
51  img.setExternal((char*)img_buf,w,h);
52  return &img;
53 }
Minimal requirements for an efficient Writer.
Definition: SizedWriter.h:33
virtual size_t length() const =0
virtual const char * data(size_t index) const =0
Image class with user control of representation details.
Definition: Image.h:414
Byte order in image header for network transmission.
An interface to the operating system, including Port based communication.
Signal processing.
Definition: Image.h:22