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