YARP
Yet Another Robot Platform
BayerCarrier.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * All rights reserved.
4  *
5  * This software may be modified and distributed under the terms of the
6  * BSD-3-Clause license. See the accompanying LICENSE file for details.
7  */
8 
9 #ifndef BAYERCARRIER_INC
10 #define BAYERCARRIER_INC
11 
14 #include <yarp/sig/Image.h>
16 #include <yarp/os/DummyConnector.h>
17 
27 class BayerCarrier :
31 {
32 private:
38  size_t image_data_len, consumed;
39 
42 
43  bool need_reset;
44  bool have_result;
45  bool happy;
46  bool half;
47  bool bayer_method_set;
48 
49  int bayer_method;
50 
51  // format offsets
52  int goff; // x offset to green on even rows
53  int roff; // y offset to red on even columns
54  int dcformat;
55 
56  bool setFormat(const char *fmt);
57 public:
58 
60  // ModifyingCarrier methods
61 
62 
64  image_data_len(0),
65  consumed(0),
66  local(yarp::os::ConnectionReader::createConnectionReader(*this)),
67  parent(nullptr),
68  need_reset(true),
69  have_result(false),
70  happy(local!=0),
71  half(false),
72  bayer_method_set(false),
73  bayer_method(-1),
74  goff(0),
75  roff(1),
76  dcformat(-1)
77  {}
78 
80  if (local) delete local;
81  }
82 
83  Carrier *create() const override {
84  return new BayerCarrier();
85  }
86 
87  std::string getName() const override {
88  return "bayer";
89  }
90 
91  std::string toString() const override {
92  return "bayer_carrier";
93  }
94 
96 
97 
99  // ConnectionReader methods
100 
101  bool expectBlock(char *data, size_t len) override {
102  return local->expectBlock(data,len);
103  }
104 
105  std::string expectText(const char terminatingChar = '\n') override {
106  return local->expectText(terminatingChar);
107  }
108 
109  std::int8_t expectInt8() override {
110  return local->expectInt8();
111  }
112 
113  std::int16_t expectInt16() override {
114  return local->expectInt64();
115  }
116 
117  std::int32_t expectInt32() override {
118  return local->expectInt32();
119  }
120 
121  std::int64_t expectInt64() override {
122  return local->expectInt64();
123  }
124 
125  bool pushInt(int x) override {
126  return local->pushInt(x);
127  }
128 
130  return local->expectFloat32();
131  }
132 
134  return local->expectFloat64();
135  }
136 
137  bool isTextMode() const override {
138  return false;
139  }
140 
141  bool isBareMode() const override {
142  return false;
143  }
144 
145  bool convertTextMode() override {
146  return true;
147  }
148 
149  size_t getSize() const override {
150  if (image_data_len) {
151  processBuffered();
152  }
153  return sizeof(header)+image_data_len;
154  }
155 
157  return parent->getWriter();
158  }
159 
161  return parent->readEnvelope();
162  }
163 
164  yarp::os::Portable* getReference() const override {
165  return parent->getReference();
166  }
167 
169  return parent->getRemoteContact();
170  }
171 
173  return parent->getLocalContact();
174  }
175 
176  bool isValid() const override {
177  return true;
178  }
179 
180  bool isActive() const override {
181  return parent->isActive();
182  }
183 
184  bool isError() const override {
185  return parent->isError()||!happy;
186  }
187 
188  void requestDrop() override {
189  parent->requestDrop();
190  }
191 
193  return parent->getConnectionModifiers();
194  }
195 
196  bool setSize(size_t len) override {
197  return parent->setSize(len);
198  }
199 
201  // InputStream methods
202 
205 
206  void close() override {
207  }
208 
209  bool isOk() const override {
210  return happy;
211  }
212 
214  // BayerCarrier methods
215 
217  parent = &reader;
218  }
219 
222 
225 
226  /*
227  * The const version of the processBuffered() method performs a const_cast,
228  * and calls the non-const version. This allows to call it in const methods.
229  * Conceptually this is not completely wrong because it does not modify
230  * the external state of the class, but just some internal representation.
231  */
232  virtual bool processBuffered() const;
233 
234  virtual bool processBuffered();
235 
236  virtual bool processDirect(yarp::os::Bytes& bytes);
237 
238 };
239 
240 
241 #endif
yarp::os::DummyConnector
A dummy connection to test yarp::os::Portable implementations.
Definition: DummyConnector.h:35
BayerCarrier::readEnvelope
yarp::os::Bytes readEnvelope() override
Read a message envelope, if available.
Definition: BayerCarrier.h:160
BayerCarrier::expectFloat64
yarp::conf::float64_t expectFloat64() override
Read a 64-bit floating point number from the network connection.
Definition: BayerCarrier.h:133
BayerCarrier::processBuffered
virtual bool processBuffered() const
Definition: BayerCarrier.cpp:304
yarp::os::ConnectionReader::readEnvelope
virtual Bytes readEnvelope()
Read a message envelope, if available.
Definition: ConnectionReader.cpp:18
yarp::os::Portable
This is a base class for objects that can be both read from and be written to the YARP network.
Definition: Portable.h:29
yarp::sig::ImageNetworkHeader
Byte order in image header for network transmission.
Definition: ImageNetworkHeader.h:33
yarp::os::Searchable
A base class for nested structures that can be searched.
Definition: Searchable.h:69
yarp::os::ConnectionReader::getConnectionModifiers
virtual const Searchable & getConnectionModifiers() const =0
Access modifiers associated with the connection, if any.
ImageNetworkHeader.h
BayerCarrier::pushInt
bool pushInt(int x) override
Store an integer to return on the next call to expectInt()
Definition: BayerCarrier.h:125
BayerCarrier::getRemoteContact
yarp::os::Contact getRemoteContact() const override
Gets information about who is supplying the data being read, if that information is available.
Definition: BayerCarrier.h:168
BayerCarrier::requestDrop
void requestDrop() override
Tag the connection to be dropped after the current message.
Definition: BayerCarrier.h:188
BayerCarrier::expectInt32
std::int32_t expectInt32() override
Read a 32-bit integer from the network connection.
Definition: BayerCarrier.h:117
yarp::os::ModifyingCarrier
A starter class for implementing simple modifying carriers.
Definition: ModifyingCarrier.h:23
BayerCarrier::isError
bool isError() const override
Definition: BayerCarrier.h:184
BayerCarrier::getReference
yarp::os::Portable * getReference() const override
Get a direct pointer to the object being sent, if possible.
Definition: BayerCarrier.h:164
BayerCarrier::isActive
bool isActive() const override
Definition: BayerCarrier.h:180
BayerCarrier::~BayerCarrier
~BayerCarrier()
Definition: BayerCarrier.h:79
yarp::os::ConnectionReader::expectInt8
virtual std::int8_t expectInt8()=0
Read a 8-bit integer from the network connection.
BayerCarrier::expectFloat32
yarp::conf::float32_t expectFloat32() override
Read a 32-bit floating point number from the network connection.
Definition: BayerCarrier.h:129
BayerCarrier::expectBlock
bool expectBlock(char *data, size_t len) override
Read a block of data from the network connection.
Definition: BayerCarrier.h:101
BayerCarrier::isTextMode
bool isTextMode() const override
Check if the connection is text mode.
Definition: BayerCarrier.h:137
yarp::sig::ImageOf< yarp::sig::PixelMono >
BayerCarrier::isValid
bool isValid() const override
Definition: BayerCarrier.h:176
yarp::os::ConnectionReader::expectFloat64
virtual yarp::conf::float64_t expectFloat64()=0
Read a 64-bit floating point number from the network connection.
BayerCarrier::expectText
std::string expectText(const char terminatingChar='\n') override
Read some text from the network connection.
Definition: BayerCarrier.h:105
BayerCarrier::convertTextMode
bool convertTextMode() override
Reads in a standard description in text mode, and converts it to a standard description in binary.
Definition: BayerCarrier.h:145
BayerCarrier::create
Carrier * create() const override
Factory method.
Definition: BayerCarrier.h:83
BayerCarrier::expectInt16
std::int16_t expectInt16() override
Read a 16-bit integer from the network connection.
Definition: BayerCarrier.h:113
yarp::os::ConnectionReader::expectInt32
virtual std::int32_t expectInt32()=0
Read a 32-bit integer from the network connection.
yarp::os::ConnectionReader::expectInt64
virtual std::int64_t expectInt64()=0
Read a 64-bit integer from the network connection.
BayerCarrier::setParent
void setParent(yarp::os::ConnectionReader &reader)
Definition: BayerCarrier.h:216
yarp::os::ConnectionWriter
An interface for writing to a network connection.
Definition: ConnectionWriter.h:40
DummyConnector.h
yarp::os::ConnectionReader::isError
virtual bool isError() const =0
BayerCarrier::isBareMode
bool isBareMode() const override
Check if the connection is bare mode.
Definition: BayerCarrier.h:141
yarp::conf::ssize_t
::ssize_t ssize_t
Definition: numeric.h:60
BayerCarrier::modifyIncomingData
yarp::os::ConnectionReader & modifyIncomingData(yarp::os::ConnectionReader &reader) override
Modify incoming payload data, if appropriate.
Definition: BayerCarrier.cpp:70
yarp::os::ConnectionReader::createConnectionReader
static ConnectionReader * createConnectionReader(InputStream &is)
Create an instance of YARP's standard connection reader implementation.
Definition: ConnectionReader.cpp:28
BayerCarrier::close
void close() override
Terminate the stream.
Definition: BayerCarrier.h:206
BayerCarrier::processDirect
virtual bool processDirect(yarp::os::Bytes &bytes)
Definition: BayerCarrier.cpp:325
ModifyingCarrier.h
yarp::os::ConnectionReader::getWriter
virtual ConnectionWriter * getWriter()=0
Gets a way to reply to the message, if possible.
BayerCarrier::getWriter
yarp::os::ConnectionWriter * getWriter() override
Gets a way to reply to the message, if possible.
Definition: BayerCarrier.h:156
BayerCarrier::setSize
bool setSize(size_t len) override
Definition: BayerCarrier.h:196
yarp::os::Bytes
A simple abstraction for a block of bytes.
Definition: Bytes.h:28
BayerCarrier::BayerCarrier
BayerCarrier()
Definition: BayerCarrier.h:63
BayerCarrier::toString
std::string toString() const override
Get name of carrier.
Definition: BayerCarrier.h:91
BayerCarrier::debayerFull
virtual bool debayerFull(yarp::sig::ImageOf< yarp::sig::PixelMono > &src, yarp::sig::ImageOf< yarp::sig::PixelRgb > &dest)
Definition: BayerCarrier.cpp:204
BayerCarrier::getName
std::string getName() const override
Get the name of this connection type ("tcp", "mcast", "shmem", ...)
Definition: BayerCarrier.h:87
yarp::conf::float32_t
float float32_t
Definition: numeric.h:50
yarp::os::ConnectionReader::isActive
virtual bool isActive() const =0
Image.h
BayerCarrier::debayerHalf
virtual bool debayerHalf(yarp::sig::ImageOf< yarp::sig::PixelMono > &src, yarp::sig::ImageOf< yarp::sig::PixelRgb > &dest)
Definition: BayerCarrier.cpp:162
yarp::os::ConnectionReader
An interface for reading from a network connection.
Definition: ConnectionReader.h:40
BayerCarrier::getLocalContact
yarp::os::Contact getLocalContact() const override
Gets information about who is receiving the data, if that information is available.
Definition: BayerCarrier.h:172
yarp::os::ConnectionReader::setSize
virtual bool setSize(size_t len)=0
BayerCarrier
Decode bayer images and serve them as regular rgb.
Definition: BayerCarrier.h:31
yarp::os::ConnectionReader::getLocalContact
virtual Contact getLocalContact() const =0
Gets information about who is receiving the data, if that information is available.
yarp::os::ConnectionReader::getReference
virtual Portable * getReference() const =0
Get a direct pointer to the object being sent, if possible.
yarp::os::ConnectionReader::pushInt
virtual bool pushInt(int x)=0
Store an integer to return on the next call to expectInt()
BayerCarrier::isOk
bool isOk() const override
Check if the stream is ok or in an error state.
Definition: BayerCarrier.h:209
yarp::os::InputStream::read
virtual int read()
Read and return a single byte.
Definition: InputStream.cpp:23
yarp::os::ConnectionReader::expectText
virtual std::string expectText(const char terminatingChar='\n')=0
Read some text from the network connection.
yarp
The main, catch-all namespace for YARP.
Definition: environment.h:18
BayerCarrier::getSize
size_t getSize() const override
Checks how much data is available.
Definition: BayerCarrier.h:149
yarp::os::ConnectionReader::expectFloat32
virtual yarp::conf::float32_t expectFloat32()=0
Read a 32-bit floating point number from the network connection.
yarp::os::Contact
Represents how to reach a part of a YARP network.
Definition: Contact.h:39
yarp::conf::float64_t
double float64_t
Definition: numeric.h:51
BayerCarrier::expectInt8
std::int8_t expectInt8() override
Read a 8-bit integer from the network connection.
Definition: BayerCarrier.h:109
BayerCarrier::getConnectionModifiers
const yarp::os::Searchable & getConnectionModifiers() const override
Access modifiers associated with the connection, if any.
Definition: BayerCarrier.h:192
yarp::os::ConnectionReader::expectBlock
virtual bool expectBlock(char *data, size_t len)=0
Read a block of data from the network connection.
yarp::os::ConnectionReader::getRemoteContact
virtual Contact getRemoteContact() const =0
Gets information about who is supplying the data being read, if that information is available.
yarp::os::InputStream
Simple specification of the minimum functions needed from input streams.
Definition: InputStream.h:29
yarp::os::ConnectionReader::requestDrop
virtual void requestDrop()=0
Tag the connection to be dropped after the current message.
BayerCarrier::expectInt64
std::int64_t expectInt64() override
Read a 64-bit integer from the network connection.
Definition: BayerCarrier.h:121
ConnectionReader.h