YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
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>
14
28{
29private:
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);
54public:
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) {
151 }
152 return sizeof(header)+image_data_len;
153 }
154
156 return parent->getWriter();
157 }
158
160 return parent->readEnvelope();
161 }
162
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
199 void flushWriter() override {
200 parent->flushWriter();
201 }
202
204 // InputStream methods
205
208
209 void close() override {
210 }
211
212 bool isOk() const override {
213 return happy;
214 }
215
217 // BayerCarrier methods
218
220 parent = &reader;
221 }
222
225
228
229 /*
230 * The const version of the processBuffered() method performs a const_cast,
231 * and calls the non-const version. This allows to call it in const methods.
232 * Conceptually this is not completely wrong because it does not modify
233 * the external state of the class, but just some internal representation.
234 */
235 virtual bool processBuffered() const;
236
237 virtual bool processBuffered();
238
239 virtual bool processDirect(yarp::os::Bytes& bytes);
240
241};
242
243
244#endif
Decode bayer images and serve them as regular rgb.
virtual bool processDirect(yarp::os::Bytes &bytes)
void flushWriter() override
std::int64_t expectInt64() override
Read a 64-bit integer from the network connection.
size_t getSize() const override
Checks how much data is available.
bool isTextMode() const override
Check if carrier is textual in nature.
yarp::conf::float32_t expectFloat32() override
Read a 32-bit floating point number from the network connection.
std::int16_t expectInt16() override
Read a 16-bit integer from the network connection.
std::string getName() const override
Get the name of this connection type ("tcp", "mcast", "shmem", ...)
yarp::os::Contact getRemoteContact() const override
Gets information about who is supplying the data being read, if that information is available.
void setParent(yarp::os::ConnectionReader &reader)
std::string expectText(const char terminatingChar='\n') override
Read some text from the network connection.
virtual bool processBuffered() const
std::int8_t expectInt8() override
Read a 8-bit integer from the network connection.
void close() override
Close the carrier.
bool setSize(size_t len) override
yarp::os::Contact getLocalContact() const override
Gets information about who is receiving the data, if that information is available.
void requestDrop() override
Tag the connection to be dropped after the current message.
virtual bool debayerHalf(yarp::sig::ImageOf< yarp::sig::PixelMono > &src, yarp::sig::ImageOf< yarp::sig::PixelRgb > &dest)
yarp::os::Portable * getReference() const override
Get a direct pointer to the object being sent, if possible.
yarp::os::ConnectionWriter * getWriter() override
Gets a way to reply to the message, if possible.
bool expectBlock(char *data, size_t len) override
Read a block of data from the network connection.
bool convertTextMode() override
Reads in a standard description in text mode, and converts it to a standard description in binary.
std::string toString() const override
Get name of carrier.
bool isValid() const override
Check if this object is really a connection, or just an empty placeholder.
std::int32_t expectInt32() override
Read a 32-bit integer from the network connection.
virtual bool debayerFull(yarp::sig::ImageOf< yarp::sig::PixelMono > &src, yarp::sig::ImageOf< yarp::sig::PixelRgb > &dest)
bool isActive() const override
Check if carrier is alive and error free.
bool isError() const override
Carrier * create() const override
Factory method.
bool pushInt(int x) override
Store an integer to return on the next call to expectInt()
const yarp::os::Searchable & getConnectionModifiers() const override
Access modifiers associated with the connection, if any.
yarp::conf::float64_t expectFloat64() override
Read a 64-bit floating point number from the network connection.
yarp::os::Bytes readEnvelope() override
Read a message envelope, if available.
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.
bool isBareMode() const override
Check if carrier excludes type information from payload.
A simple abstraction for a block of bytes.
Definition Bytes.h:24
An interface for reading from a network connection.
virtual void flushWriter()=0
virtual void requestDrop()=0
Tag the connection to be dropped after the current message.
virtual ConnectionWriter * getWriter()=0
Gets a way to reply to the message, if possible.
static ConnectionReader * createConnectionReader(InputStream &is)
Create an instance of YARP's standard connection reader implementation.
virtual Portable * getReference() const =0
Get a direct pointer to the object being sent, if possible.
virtual Contact getRemoteContact() const =0
Gets information about who is supplying the data being read, if that information is available.
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 const Searchable & getConnectionModifiers() const =0
Access modifiers associated with the connection, if any.
An interface for writing to a network connection.
Represents how to reach a part of a YARP network.
Definition Contact.h:33
A dummy connection to test yarp::os::Portable implementations.
Simple specification of the minimum functions needed from input streams.
Definition InputStream.h:25
virtual int read()
Read and return a single byte.
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:25
A base class for nested structures that can be searched.
Definition Searchable.h:31
Byte order in image header for network transmission.
Typed image class.
Definition Image.h:605
::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