YARP
Yet Another Robot Platform
WireImage.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * Copyright (C) 2006-2010 RobotCub Consortium
4  * All rights reserved.
5  *
6  * This software may be modified and distributed under the terms of the
7  * BSD-3-Clause license. See the accompanying LICENSE file for details.
8  */
9 
10 #include "WireImage.h"
11 
13 
14 using namespace yarp::os;
15 using namespace yarp::sig;
16 using namespace yarp::wire_rep_utils;
17 
18 FlexImage *WireImage::checkForImage(SizedWriter& writer) {
20  char *header_buf = (char*)(&hdr);
21  size_t header_len = sizeof(hdr);
22  const char *img_buf = nullptr;
23  int img_len = 0;
24  hdr.imgSize = -1;
25  for (size_t i=0; i<writer.length(); i++) {
26  const char *data = writer.data(i);
27  size_t len = writer.length(i);
28  //printf("block %d length %d\n", i, len);
29  if (header_len<len) {
30  len = header_len;
31  }
32  if (len>0) {
33  memcpy(header_buf,data,len);
34  header_len -= len;
35  header_buf += len;
36  }
37  if (header_len == 0) {
38  img_buf = data+len;
39  img_len = writer.length(i)-len;
40  }
41  }
42  if (hdr.imgSize==-1) {
43  return nullptr;
44  }
45  if (hdr.imgSize!=img_len) {
46  return nullptr;
47  }
48  //printf("Passing on a %dx%d image\n", hdr.width, hdr.height);
49  int w = hdr.width;
50  int h = hdr.height;
51  //int row_stride = hdr.imgSize/hdr.height;
52  img.setPixelCode(hdr.id);
53  img.setQuantum(hdr.quantum);
54  img.setExternal((char*)img_buf,w,h);
55  return &img;
56 }
yarp::os::SizedWriter::length
virtual size_t length() const =0
yarp::sig::ImageNetworkHeader
Byte order in image header for network transmission.
Definition: ImageNetworkHeader.h:33
ImageNetworkHeader.h
yarp::sig
Signal processing.
Definition: Image.h:25
yarp::sig::ImageNetworkHeader::width
yarp::os::NetInt32 width
Definition: ImageNetworkHeader.h:47
yarp::sig::ImageNetworkHeader::id
yarp::os::NetInt32 id
Definition: ImageNetworkHeader.h:41
yarp::sig::FlexImage
Image class with user control of representation details.
Definition: Image.h:403
yarp::sig::ImageNetworkHeader::height
yarp::os::NetInt32 height
Definition: ImageNetworkHeader.h:48
yarp::sig::ImageNetworkHeader::quantum
yarp::os::NetInt32 quantum
Definition: ImageNetworkHeader.h:46
yarp::os
An interface to the operating system, including Port based communication.
Definition: AbstractCarrier.h:17
yarp::os::SizedWriter::data
virtual const char * data(size_t index) const =0
yarp::wire_rep_utils
Definition: BlobNetworkHeader.h:18
WireImage.h
yarp::os::SizedWriter
Minimal requirements for an efficient Writer.
Definition: SizedWriter.h:36
yarp::sig::ImageNetworkHeader::imgSize
yarp::os::NetInt32 imgSize
Definition: ImageNetworkHeader.h:45