16#include "conversions.h"
19#include <dc1394/dc1394.h>
40 dc->image =
yimg.getRawImage();
47 dc->yuv_byte_order = 0;
52 dc->padding_bytes = 0;
53 dc->total_bytes =
dc->image_bytes;
55 dc->frames_behind = 0;
58 dc->allocated_image_bytes =
dc->image_bytes;
59#ifdef YARP_LITTLE_ENDIAN
97 bool ok = in.
read(reader);
112 if (config.
check(
"size")) {
113 if (config.
find(
"size").asString() ==
"half") {
117 if (config.
check(
"method")) {
118 std::string
method = config.
find(
"method").asString();
119 bayer_method_set =
true;
122 }
else if (
method==
"bilinear") {
124 }
else if (
method==
"downsample") {
127 }
else if (
method==
"edgesense") {
129 }
else if (
method==
"hqlinear") {
131 }
else if (
method==
"nearest") {
133 }
else if (
method==
"simple") {
135 }
else if (
method==
"vng") {
138 yCWarning(
BAYERCARRIER,
"bayer method %s not recognized, try: ahd bilinear downsample edgesense hqlinear nearest simple vng",
method.c_str());
152 local->
setSize(
sizeof(header)+image_data_len);
162 if (src.
width()%8==0) {
171 if (bayer_method_set) {
189 if (x+1>=w-1 || y+1>=h-1) {
190 po = PixelRgb{0,0,0};
204 if (src.
width()%8==0) {
214 if (bayer_method_set) {
217 int w = dest.
width();
223 for (
int y=0; y<h; y++) {
224 for (
int x=0; x<w; x++) {
225 PixelRgb&
po = dest.
pixel(x,y);
233 if (x>0) { g += src.
pixel(x-1,y); ct++; }
234 if (x<w-1) { g += src.
pixel(x+1,y); ct++; }
235 if (y>0) { g += src.
pixel(x,y-1); ct++; }
236 if (y<h-1) { g += src.
pixel(x,y+1); ct++; }
237 if (ct>0) { g /= ct; }
238 po.g =
static_cast<int>(g);
244 }
else if (y%2==
boff) {
247 if (x>0) { b += src.
pixel(x-1,y); ct++; }
248 if (x<w-1) { b += src.
pixel(x+1,y); ct++; }
249 if (ct>0) { b /= ct; }
250 po.b =
static_cast<int>(b);
251 }
else if (x%2==
boffx) {
254 if (y>0) { b += src.
pixel(x,y-1); ct++; }
255 if (y<h-1) { b += src.
pixel(x,y+1); ct++; }
256 if (ct>0) { b /= ct; }
257 po.b =
static_cast<int>(b);
261 if (x>0&&y>0) { b += src.
pixel(x-1,y-1); ct++; }
262 if (x>0&&y<h-1) { b += src.
pixel(x-1,y+1); ct++; }
264 if (x<w-1&&y<h-1) { b += src.
pixel(x+1,y+1); ct++; }
265 if (ct>0) { b /= ct; }
266 po.b =
static_cast<int>(b);
270 if (y%2==roff && x%2==
roffx) {
272 }
else if (y%2==roff) {
275 if (x>0) { r += src.
pixel(x-1,y); ct++; }
276 if (x<w-1) { r += src.
pixel(x+1,y); ct++; }
277 if (ct>0) { r /= ct; }
278 po.r =
static_cast<int>(r);
279 }
else if (x%2==
roffx) {
282 if (y>0) { r += src.
pixel(x,y-1); ct++; }
283 if (y<h-1) { r += src.
pixel(x,y+1); ct++; }
284 if (ct>0) { r /= ct; }
285 po.r =
static_cast<int>(r);
289 if (x>0&&y>0) { r += src.
pixel(x-1,y-1); ct++; }
290 if (x>0&&y<h-1) { r += src.
pixel(x-1,y+1); ct++; }
292 if (x<w-1&&y<h-1) { r += src.
pixel(x+1,y+1); ct++; }
293 if (ct>0) { r /= ct; }
294 po.r =
static_cast<int>(r);
342 if (consumed<
sizeof(header)) {
344 if (len>
sizeof(header)-consumed) {
345 len =
sizeof(header)-consumed;
347 memcpy(b.
get(),(
reinterpret_cast<char*
>(&header))+consumed,len);
352 if (b.
length()==image_data_len) {
355 consumed += image_data_len;
356 return image_data_len;
373bool BayerCarrier::setFormat(
const char *
fmt) {
379 goff = (
f[0]==
'g'||
f[0]==
'G')?0:1;
380 roff = (
f[0]==
'r'||
f[0]==
'R'||
f[1]==
'r'||
f[1]==
'R')?0:1;
381 if (goff==0&&roff==0) {
383 }
else if (goff==0&&roff==1) {
385 }
else if (goff==1&&roff==0) {
387 }
else if (goff==1&&roff==1) {
void setDcImage(yarp::sig::Image &yimg, dc1394video_frame_t *dc, int filter)
Decode bayer images and serve them as regular rgb.
virtual bool processDirect(yarp::os::Bytes &bytes)
virtual bool processBuffered() const
virtual bool debayerHalf(yarp::sig::ImageOf< yarp::sig::PixelMono > &src, yarp::sig::ImageOf< yarp::sig::PixelRgb > &dest)
virtual bool debayerFull(yarp::sig::ImageOf< yarp::sig::PixelMono > &src, yarp::sig::ImageOf< yarp::sig::PixelRgb > &dest)
yarp::os::ConnectionReader & modifyIncomingData(yarp::os::ConnectionReader &reader) override
Modify incoming payload data, if appropriate.
A mini-server for performing network communication in the background.
A simple abstraction for a block of bytes.
An interface for reading from a network connection.
virtual void setParentConnectionReader(ConnectionReader *parentConnectionReader)
Set ConnectionReader to be used for reading the envelope.
virtual bool setSize(size_t len)=0
virtual const Searchable & getConnectionModifiers() const =0
Access modifiers associated with the connection, if any.
static LogCallback printCallback()
Get current print callback.
static LogType minimumPrintLevel()
Get current minimum print level.
Information about a connection between two ports.
A base class for nested structures that can be searched.
virtual bool check(const std::string &key) const =0
Check if there exists a property of the given name.
virtual Value & find(const std::string &key) const =0
Gets a value corresponding to a given keyword.
A single value (typically within a Bottle).
T & pixel(size_t x, size_t y)
Base class for storing images.
void setQuantum(size_t imgQuantum)
size_t width() const
Gets width of image in pixels.
bool read(yarp::os::ConnectionReader &connection) override
Read image from a connection.
unsigned char * getRawImage() const
Access to the internal image buffer.
size_t getRawImageSize() const
Access to the internal buffer size information (this is how much memory has been allocated for the im...
void resize(size_t imgWidth, size_t imgHeight)
Reallocate an image to be of a desired size, throwing away its current contents.
size_t getQuantum() const
The size of a row is constrained to be a multiple of the "quantum".
size_t height() const
Gets height of image in pixels.
#define yCTrace(component,...)
#define yCWarning(component,...)
#define YARP_LOG_COMPONENT(name,...)
An interface to the operating system, including Port based communication.