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
Decode bayer images and serve them as regular rgb.
Definition: BayerCarrier.h:31
yarp::os::Portable * getReference() const override
Get a direct pointer to the object being sent, if possible.
Definition: BayerCarrier.h:164
virtual bool processDirect(yarp::os::Bytes &bytes)
std::int64_t expectInt64() override
Read a 64-bit integer from the network connection.
Definition: BayerCarrier.h:121
size_t getSize() const override
Checks how much data is available.
Definition: BayerCarrier.h:149
yarp::os::ConnectionWriter * getWriter() override
Gets a way to reply to the message, if possible.
Definition: BayerCarrier.h:156
bool isTextMode() const override
Check if the connection is text mode.
Definition: BayerCarrier.h:137
yarp::conf::float32_t expectFloat32() override
Read a 32-bit floating point number from the network connection.
Definition: BayerCarrier.h:129
std::int16_t expectInt16() override
Read a 16-bit integer from the network connection.
Definition: BayerCarrier.h:113
std::string getName() const override
Get the name of this connection type ("tcp", "mcast", "shmem", ...)
Definition: BayerCarrier.h:87
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
void setParent(yarp::os::ConnectionReader &reader)
Definition: BayerCarrier.h:216
std::string expectText(const char terminatingChar='\n') override
Read some text from the network connection.
Definition: BayerCarrier.h:105
Carrier * create() const override
Factory method.
Definition: BayerCarrier.h:83
virtual bool processBuffered() const
const yarp::os::Searchable & getConnectionModifiers() const override
Access modifiers associated with the connection, if any.
Definition: BayerCarrier.h:192
std::int8_t expectInt8() override
Read a 8-bit integer from the network connection.
Definition: BayerCarrier.h:109
void close() override
Terminate the stream.
Definition: BayerCarrier.h:206
bool setSize(size_t len) override
Definition: BayerCarrier.h:196
yarp::os::Contact getLocalContact() const override
Gets information about who is receiving the data, if that information is available.
Definition: BayerCarrier.h:172
void requestDrop() override
Tag the connection to be dropped after the current message.
Definition: BayerCarrier.h:188
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:101
bool convertTextMode() override
Reads in a standard description in text mode, and converts it to a standard description in binary.
Definition: BayerCarrier.h:145
std::string toString() const override
Get name of carrier.
Definition: BayerCarrier.h:91
bool isValid() const override
Definition: BayerCarrier.h:176
std::int32_t expectInt32() override
Read a 32-bit integer from the network connection.
Definition: BayerCarrier.h:117
virtual bool debayerFull(yarp::sig::ImageOf< yarp::sig::PixelMono > &src, yarp::sig::ImageOf< yarp::sig::PixelRgb > &dest)
bool isActive() const override
Definition: BayerCarrier.h:180
bool isError() const override
Definition: BayerCarrier.h:184
bool pushInt(int x) override
Store an integer to return on the next call to expectInt()
Definition: BayerCarrier.h:125
yarp::conf::float64_t expectFloat64() override
Read a 64-bit floating point number from the network connection.
Definition: BayerCarrier.h:133
yarp::os::Bytes readEnvelope() override
Read a message envelope, if available.
Definition: BayerCarrier.h:160
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:209
bool isBareMode() const override
Check if the connection is bare mode.
Definition: BayerCarrier.h:141
A simple abstraction for a block of bytes.
Definition: Bytes.h:28
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:39
A dummy connection to test yarp::os::Portable implementations.
Simple specification of the minimum functions needed from input streams.
Definition: InputStream.h:29
virtual int read()
Read and return a single byte.
Definition: InputStream.cpp:23
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:29
A base class for nested structures that can be searched.
Definition: Searchable.h:69
Byte order in image header for network transmission.
::ssize_t ssize_t
Definition: numeric.h:60
double float64_t
Definition: numeric.h:51
float float32_t
Definition: numeric.h:50
The main, catch-all namespace for YARP.
Definition: environment.h:18