16#include "conversions.h"
19#include <dc1394/dc1394.h>
41 dc->size[0] =
static_cast<uint32_t
>(yimg.
width());
42 dc->size[1] =
static_cast<uint32_t
>(yimg.
height());
46 dc->color_filter =
static_cast<dc1394color_filter_t
>(filter);
47 dc->yuv_byte_order = 0;
49 dc->stride =
static_cast<uint32_t
>(yimg.
getRowSize());
50 dc->video_mode = DC1394_VIDEO_MODE_640x480_RGB8;
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
60 dc->little_endian = DC1394_TRUE;
62 dc->little_endian = DC1394_FALSE;
64 dc->data_in_padding = DC1394_FALSE;
97 bool ok = in.
read(reader);
105 need_reset = (0!=memcmp(&header_in_cmp,&header_in,
sizeof(header_in)));
109 int m = DC1394_BAYER_METHOD_BILINEAR;
112 if (config.
check(
"size")) {
117 if (config.
check(
"method")) {
119 bayer_method_set =
true;
121 m = DC1394_BAYER_METHOD_AHD;
122 }
else if (method==
"bilinear") {
123 m = DC1394_BAYER_METHOD_BILINEAR;
124 }
else if (method==
"downsample") {
125 m = DC1394_BAYER_METHOD_DOWNSAMPLE;
127 }
else if (method==
"edgesense") {
128 m = DC1394_BAYER_METHOD_EDGESENSE;
129 }
else if (method==
"hqlinear") {
130 m = DC1394_BAYER_METHOD_HQLINEAR;
131 }
else if (method==
"nearest") {
132 m = DC1394_BAYER_METHOD_NEAREST;
133 }
else if (method==
"simple") {
134 m = DC1394_BAYER_METHOD_SIMPLE;
135 }
else if (method==
"vng") {
136 m = DC1394_BAYER_METHOD_VNG;
138 yCWarning(BAYERCARRIER,
"bayer method %s not recognized, try: ahd bilinear downsample edgesense hqlinear nearest simple vng", method.c_str());
145 setFormat(config.
check(
"order",
Value(
"grbg")).asString().c_str());
147 yCTrace(BAYERCARRIER,
"Need reset.");
152 local->
setSize(
sizeof(header)+image_data_len);
162 if (src.
width()%8==0) {
163 dc1394video_frame_t dc_src;
164 dc1394video_frame_t dc_dest;
167 dc1394_debayer_frames(&dc_src,&dc_dest,DC1394_BAYER_METHOD_DOWNSAMPLE);
171 if (bayer_method_set) {
172 yCWarning(BAYERCARRIER,
"Not using dc1394 debayer methods (image width not a multiple of 8)");
178 int wo = dest.
width();
181 int roffx = roff?goff:goff1;
183 int boffx = boff?goff:goff1;
184 for (
int yo=0; yo<ho; yo++) {
185 for (
int xo=0; xo<wo; xo++) {
189 if (x+1>=w-1 || y+1>=h-1) {
193 po.
r = src.
pixel(x+roffx,y+roff);
194 po.
b = src.
pixel(x+boffx,y+boff);
204 if (src.
width()%8==0) {
205 dc1394video_frame_t dc_src;
206 dc1394video_frame_t dc_dest;
209 dc1394_debayer_frames(&dc_src,&dc_dest,
210 static_cast<dc1394bayer_method_t
>(bayer_method));
214 if (bayer_method_set) {
215 yCWarning(BAYERCARRIER,
"Not using dc1394 debayer methods (image width not a multiple of 8)");
217 int w = dest.
width();
220 int roffx = roff?goff:goff1;
222 int boffx = boff?goff:goff1;
223 for (
int y=0; y<h; y++) {
224 for (
int x=0; x<w; x++) {
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);
242 if (y%2==boff && x%2==boffx) {
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++; }
263 if (x<w-1&&y>0) { 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++; }
291 if (x<w-1&&y>0) { 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);
307 yCTrace(BAYERCARRIER,
"Copy-based conversion.");
327 yCTrace(BAYERCARRIER,
"Copyless conversion");
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) {
374 dcformat = DC1394_COLOR_FILTER_GRBG;
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) {
382 dcformat = DC1394_COLOR_FILTER_GRBG;
383 }
else if (goff==0&&roff==1) {
384 dcformat = DC1394_COLOR_FILTER_GBRG;
385 }
else if (goff==1&&roff==0) {
386 dcformat = DC1394_COLOR_FILTER_RGGB;
387 }
else if (goff==1&&roff==1) {
388 dcformat = DC1394_COLOR_FILTER_BGGR;
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 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).
virtual std::string asString() const
Get string value.
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.
void setExternal(const void *data, size_t imgWidth, size_t imgHeight)
Use this to wrap an external image.
size_t getRowSize() const
Size of the underlying image buffer rows.
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.
virtual int getPixelCode() const
Gets pixel type identifier.
#define yCTrace(component,...)
#define yCWarning(component,...)
#define YARP_LOG_COMPONENT(name,...)
An interface to the operating system, including Port based communication.
unsigned char PixelMono
Monochrome pixel type.