62 const size_t size=buffer->
getSize(part);
64 pixel.reset(
new uint8_t [size]);
66 memcpy(
pixel.get(),
reinterpret_cast<uint8_t *
>(buffer->
getBase(part)), size);
81 inline unsigned char clamp8(
int v)
83 const int v2=v<0 ? 0:v;
84 return static_cast<unsigned char>(v2>255 ? 255:v2);
91 const uint32_t j=
static_cast<uint32_t
>((i>>2)*6);
92 const uint32_t js=
static_cast<uint32_t
>(i&0x3);
100 const int Cb=
static_cast<int>(row[j+2])-128;
101 const int Cr=
static_cast<int>(row[j+5])-128;
103 const int rc=(90*Cr+32)>>6;
104 const int gc=(-22*Cb-46*Cr+32)>>6;
105 const int bc=(113*Cb+32)>>6;
116 const int Y[4]={row[i], row[i+1], row[i+3], row[i+4]};
117 const int Cb=
static_cast<int>(row[i+2])-128;
118 const int Cr=
static_cast<int>(row[i+5])-128;
120 const int rc=(90*Cr+32)>>6;
121 const int gc=(-22*Cb-46*Cr+32)>>6;
122 const int bc=(113*Cb+32)>>6;
124 for (
int j=0; j<4; j++)
126 *rgb++=clamp8(Y[j]+rc);
127 *rgb++=clamp8(Y[j]+gc);
128 *rgb++=clamp8(Y[j]+bc);
132 void getColor(uint8_t rgb[3],
const std::shared_ptr<const Image> &img,
133 uint32_t ds, uint32_t i, uint32_t k)
141 if (img->getPixelFormat() ==
Mono8)
143 size_t lstep=img->getWidth()+img->getXPadding();
144 const uint8_t *p=img->getPixels()+k*lstep+i;
148 for (uint32_t kk=0; kk<ds; kk++)
150 for (uint32_t ii=0; ii<ds; ii++)
159 rgb[2]=rgb[1]=rgb[0]=
static_cast<uint8_t
>(g/n);
163 size_t lstep=(img->getWidth()>>2)*6+img->getXPadding();
164 const uint8_t *p=img->getPixels()+k*lstep;
171 for (uint32_t kk=0; kk<ds; kk++)
173 for (uint32_t ii=0; ii<ds; ii++)
187 rgb[0]=
static_cast<uint8_t
>(r/n);
188 rgb[1]=
static_cast<uint8_t
>(g/n);
189 rgb[2]=
static_cast<uint8_t
>(b/n);
200 inline void convertGreenGR(uint8_t &r, uint8_t &g, uint8_t &b,
201 const uint8_t *&row0,
const uint8_t *&row1,
const uint8_t *&row2)
203 r=
static_cast<uint8_t
>((
static_cast<int>(*row1)+row1[2]+1)>>1);
205 b=
static_cast<uint8_t
>((
static_cast<int>(row0[1])+row2[1]+1)>>1);
207 row0++; row1++; row2++;
214 inline void convertGreenGB(uint8_t &r, uint8_t &g, uint8_t &b,
215 const uint8_t *&row0,
const uint8_t *&row1,
const uint8_t *&row2)
217 r=
static_cast<uint8_t
>((
static_cast<int>(row0[1])+row2[1]+1)>>1);
219 b=
static_cast<uint8_t
>((
static_cast<int>(*row1)+row1[2]+1)>>1);
221 row0++; row1++; row2++;
228 inline void convertRed(uint8_t &r, uint8_t &g, uint8_t &b,
229 const uint8_t *&row0,
const uint8_t *&row1,
const uint8_t *&row2)
232 g=
static_cast<uint8_t
>((
static_cast<int>(row0[1])+row2[1]+*row1+row1[2]+2)>>2);
233 b=
static_cast<uint8_t
>((
static_cast<int>(*row0)+row0[2]+*row2+row2[2]+2)>>2);
235 row0++; row1++; row2++;
242 inline void convertBlue(uint8_t &r, uint8_t &g, uint8_t &b,
243 const uint8_t *&row0,
const uint8_t *&row1,
const uint8_t *&row2)
245 r=
static_cast<uint8_t
>((
static_cast<int>(*row0)+row0[2]+*row2+row2[2]+2)>>2);
246 g=
static_cast<uint8_t
>((
static_cast<int>(row0[1])+row2[1]+*row1+row1[2]+2)>>2);
249 row0++; row1++; row2++;
256 inline uint8_t rgb2Grey(uint8_t r, uint8_t g, uint8_t b)
258 return static_cast<uint8_t
>((9798*
static_cast<uint32_t
>(r)+
259 19234*static_cast<uint32_t>(g)+
260 3736*
static_cast<uint32_t
>(b))/32768);
263 inline void storeRGBMono(uint8_t *&rgb_out, uint8_t *&mono_out, uint8_t red, uint8_t green,
275 *mono_out++ = rgb2Grey(red, green, blue);
283 void convertBayerGR(uint8_t *rgb_out, uint8_t *mono_out,
284 const uint8_t *row0,
const uint8_t *row1,
const uint8_t *row2,
285 bool greenfirst,
size_t width)
287 uint8_t red, green, blue;
295 convertGreenGR(red, green, blue, row0, row1, row2);
296 storeRGBMono(rgb_out, mono_out, red, green, blue);
305 convertRed(red, green, blue, row0, row1, row2);
306 storeRGBMono(rgb_out, mono_out, red, green, blue);
310 convertGreenGR(red, green, blue, row0, row1, row2);
311 storeRGBMono(rgb_out, mono_out, red, green, blue);
320 convertRed(red, green, blue, row0, row1, row2);
321 storeRGBMono(rgb_out, mono_out, red, green, blue);
329 void convertBayerGB(uint8_t *rgb_out, uint8_t *mono_out,
330 const uint8_t *row0,
const uint8_t *row1,
const uint8_t *row2,
331 bool greenfirst,
size_t width)
333 uint8_t red, green, blue;
341 convertGreenGB(red, green, blue, row0, row1, row2);
342 storeRGBMono(rgb_out, mono_out, red, green, blue);
351 convertBlue(red, green, blue, row0, row1, row2);
352 storeRGBMono(rgb_out, mono_out, red, green, blue);
356 convertGreenGB(red, green, blue, row0, row1, row2);
357 storeRGBMono(rgb_out, mono_out, red, green, blue);
366 convertBlue(red, green, blue, row0, row1, row2);
367 storeRGBMono(rgb_out, mono_out, red, green, blue);
384 for (
size_t k=0; k<
height; k++)
388 for (
size_t i=0; i<
width; i++)
399 std::memcpy(mono_out, raw, width*
sizeof(uint8_t));
410 size_t pstep=(width>>2)*6+xpadding;
411 for (
size_t k=0; k<
height; k++)
413 for (
size_t i=0; i<
width; i+=4)
420 for (
int j=0; j<12; j++)
428 *mono_out++ = raw[0];
429 *mono_out++ = raw[1];
430 *mono_out++ = raw[3];
431 *mono_out++ = raw[4];
442 for (
size_t k=0; k<
height; k++)
446 std::memcpy(rgb_out, raw, 3*width*
sizeof(uint8_t));
453 for (
size_t i=0; i<
width; i++)
455 *mono_out++ = rgb2Grey(raw[j], raw[j+1], raw[j+2]);
479 std::unique_ptr<uint8_t []> buffer(
new uint8_t [(width+2)*3]);
483 row[1]=row[0]+width+2;
484 row[2]=row[1]+width+2;
489 memcpy(row[1]+1, raw+width+xpadding, width*
sizeof(uint8_t));
490 memcpy(row[2]+1, raw, width*
sizeof(uint8_t));
492 row[1][0]=row[1][2]; row[1][width+1]=row[1][width-1];
493 row[2][0]=row[2][2]; row[2][width+1]=row[2][width-1];
497 for (
size_t k=0; k<
height; k++)
508 memcpy(row[2]+1, raw+(k+1)*(width+xpadding), width*
sizeof(uint8_t));
510 row[2][0]=row[2][2]; row[2][width+1]=row[2][width-1];
515 convertBayerGR(rgb_out, mono_out, row[0], row[1], row[2], greenfirst, width);
517 if (rgb_out) rgb_out+=3*
width;
518 if (mono_out) mono_out+=
width;
522 convertBayerGB(rgb_out, mono_out, row[0], row[1], row[2], greenfirst, width);
524 if (rgb_out) rgb_out+=3*
width;
525 if (mono_out) mono_out+=
width;
528 greenfirst=!greenfirst;
size_t getYPadding() const
Returns vertical padding of the data in the buffer in bytes.
size_t getXPadding(std::uint32_t part) const
Returns horizontal padding of the data in the buffer in bytes.
void convYCbCr411toRGB(uint8_t rgb[3], const uint8_t *row, int i)
Conversion of one pixel from YCbCr411 format (6 bytes for four pixels) to RGB.
size_t getWidth(std::uint32_t part) const
Returns the width of the image in pixel.
void convYCbCr411toQuadRGB(uint8_t rgb[12], const uint8_t *row, int i)
Conversion of a group of four pixels from YCbCr411 format (6 bytes for four pixels) to RGB...
The buffer class encapsulates a Genicam buffer that is provided by a stream.
void * getBase(std::uint32_t part) const
Returns the base address of the specified part of the multi-part buffer.
uint64_t getPixelFormat(std::uint32_t part) const
Returns the pixel format of the specified part as defined in the PFNC.
bool convertImage(uint8_t *rgb_out, uint8_t *mono_out, const uint8_t *raw, uint64_t pixelformat, size_t width, size_t height, size_t xpadding)
Converts image to RGB and monochrome format.
Image(const Buffer *buffer, std::uint32_t part)
Copies the image information of the buffer.
uint64_t getTimestampNS() const
Returns the acquisition timestamp of the data in this buffer in ns.
bool isBigEndian() const
Returns if the data is given as big or little endian.
bool getImagePresent(std::uint32_t part) const
Returns if a 2D, 3D or confidence image is present in the specified part.
uint64_t getFrameID() const
Returns the sequentially incremented number of the frame.
size_t getYOffset(std::uint32_t part) const
Returns the vertical offset of the data in the buffer in lines from the image origin to handle areas ...
std::unique_ptr< uint8_t[]> pixel
size_t getXOffset(std::uint32_t part) const
Returns the horizontal offset of the data in the buffer in pixels from the image origin to handle are...
size_t getHeight(std::uint32_t part) const
Returns the height of the image in pixel.
void getColor(uint8_t rgb[3], const std::shared_ptr< const Image > &img, uint32_t ds, uint32_t i, uint32_t k)
Expects an image in Mono8 or YCbCr411_8 format and returns the color as RGB value at the given pixel ...
size_t getSize(std::uint32_t part) const
Returns the size of the specified part of the mult-part buffer.