69 pixel.reset(
new uint8_t [size]);
71 memcpy(
pixel.get(),
reinterpret_cast<uint8_t *
>(buffer->
getBase(part)), size);
86 inline unsigned char clamp8(
int v)
88 const int v2=v<0 ? 0:v;
89 return static_cast<unsigned char>(v2>255 ? 255:v2);
96 const uint32_t j=
static_cast<uint32_t
>((i>>2)*6);
97 const uint32_t js=
static_cast<uint32_t
>(i&0x3);
105 const int Cb=
static_cast<int>(row[j+2])-128;
106 const int Cr=
static_cast<int>(row[j+5])-128;
109 const int rc=((90*Cr+16384+32)>>6)-256;
110 const int gc=((-22*Cb-46*Cr+16384+32)>>6)-256;
111 const int bc=((113*Cb+16384+32)>>6)-256;
122 const int Y[4]={row[i], row[i+1], row[i+3], row[i+4]};
123 const int Cb=
static_cast<int>(row[i+2])-128;
124 const int Cr=
static_cast<int>(row[i+5])-128;
127 const int rc=((90*Cr+16384+32)>>6)-256;
128 const int gc=((-22*Cb-46*Cr+16384+32)>>6)-256;
129 const int bc=((113*Cb+16384+32)>>6)-256;
131 for (
int j=0; j<4; j++)
133 *rgb++=clamp8(Y[j]+rc);
134 *rgb++=clamp8(Y[j]+gc);
135 *rgb++=clamp8(Y[j]+bc);
141 const uint32_t j=
static_cast<uint32_t
>((i>>1)*4);
142 const uint32_t js=
static_cast<uint32_t
>(i&0x1)*2;
144 const int Y=row[j+js];
145 const int Cb=
static_cast<int>(row[j+1])-128;
146 const int Cr=
static_cast<int>(row[j+3])-128;
149 const int rc=((90*Cr+16384+32)>>6)-256;
150 const int gc=((-22*Cb-46*Cr+16384+32)>>6)-256;
151 const int bc=((113*Cb+16384+32)>>6)-256;
162 for (
int k=0; k<8; k+=4)
164 const int Y[2]={row[i+k], row[i+2+k]};
165 const int Cb=
static_cast<int>(row[i+1+k])-128;
166 const int Cr=
static_cast<int>(row[i+3+k])-128;
169 const int rc=((90*Cr+16384+32)>>6)-256;
170 const int gc=((-22*Cb-46*Cr+16384+32)>>6)-256;
171 const int bc=((113*Cb+16384+32)>>6)-256;
173 for (
int j=0; j<2; j++)
175 *rgb++=clamp8(Y[j]+rc);
176 *rgb++=clamp8(Y[j]+gc);
177 *rgb++=clamp8(Y[j]+bc);
182 void getColor(uint8_t rgb[3],
const std::shared_ptr<const Image> &img,
183 uint32_t ds, uint32_t i, uint32_t k)
191 if (img->getPixelFormat() ==
Mono8)
193 size_t lstep=img->getWidth()+img->getXPadding();
194 const uint8_t *p=img->getPixels()+k*lstep+i;
198 for (uint32_t kk=0; kk<ds; kk++)
200 for (uint32_t ii=0; ii<ds; ii++)
209 rgb[2]=rgb[1]=rgb[0]=
static_cast<uint8_t
>(g/n);
211 else if (img->getPixelFormat() ==
RGB8)
213 size_t lstep=3*img->getWidth()+img->getXPadding();
214 const uint8_t *p=img->getPixels()+k*lstep+3*i;
221 for (uint32_t kk=0; kk<ds; kk++)
224 for (uint32_t ii=0; ii<ds; ii++)
235 rgb[0]=
static_cast<uint8_t
>(r/n);
236 rgb[1]=
static_cast<uint8_t
>(g/n);
237 rgb[2]=
static_cast<uint8_t
>(b/n);
241 size_t lstep=(img->getWidth()>>2)*6+img->getXPadding();
242 const uint8_t *p=img->getPixels()+k*lstep;
249 for (uint32_t kk=0; kk<ds; kk++)
251 for (uint32_t ii=0; ii<ds; ii++)
265 rgb[0]=
static_cast<uint8_t
>(r/n);
266 rgb[1]=
static_cast<uint8_t
>(g/n);
267 rgb[2]=
static_cast<uint8_t
>(b/n);
271 size_t lstep=(img->getWidth()>>2)*8+img->getXPadding();
272 const uint8_t *p=img->getPixels()+k*lstep;
279 for (uint32_t kk=0; kk<ds; kk++)
281 for (uint32_t ii=0; ii<ds; ii++)
295 rgb[0]=
static_cast<uint8_t
>(r/n);
296 rgb[1]=
static_cast<uint8_t
>(g/n);
297 rgb[2]=
static_cast<uint8_t
>(b/n);
308 inline void convertGreenGR(uint8_t &r, uint8_t &g, uint8_t &b,
309 const uint8_t *&row0,
const uint8_t *&row1,
const uint8_t *&row2)
311 r=
static_cast<uint8_t
>((
static_cast<int>(*row1)+row1[2]+1)>>1);
313 b=
static_cast<uint8_t
>((
static_cast<int>(row0[1])+row2[1]+1)>>1);
315 row0++; row1++; row2++;
322 inline void convertGreenGB(uint8_t &r, uint8_t &g, uint8_t &b,
323 const uint8_t *&row0,
const uint8_t *&row1,
const uint8_t *&row2)
325 r=
static_cast<uint8_t
>((
static_cast<int>(row0[1])+row2[1]+1)>>1);
327 b=
static_cast<uint8_t
>((
static_cast<int>(*row1)+row1[2]+1)>>1);
329 row0++; row1++; row2++;
336 inline void convertRed(uint8_t &r, uint8_t &g, uint8_t &b,
337 const uint8_t *&row0,
const uint8_t *&row1,
const uint8_t *&row2)
340 g=
static_cast<uint8_t
>((
static_cast<int>(row0[1])+row2[1]+*row1+row1[2]+2)>>2);
341 b=
static_cast<uint8_t
>((
static_cast<int>(*row0)+row0[2]+*row2+row2[2]+2)>>2);
343 row0++; row1++; row2++;
350 inline void convertBlue(uint8_t &r, uint8_t &g, uint8_t &b,
351 const uint8_t *&row0,
const uint8_t *&row1,
const uint8_t *&row2)
353 r=
static_cast<uint8_t
>((
static_cast<int>(*row0)+row0[2]+*row2+row2[2]+2)>>2);
354 g=
static_cast<uint8_t
>((
static_cast<int>(row0[1])+row2[1]+*row1+row1[2]+2)>>2);
357 row0++; row1++; row2++;
364 inline uint8_t rgb2Grey(uint8_t r, uint8_t g, uint8_t b)
366 return static_cast<uint8_t
>((9798*
static_cast<uint32_t
>(r)+
367 19234*static_cast<uint32_t>(g)+
368 3736*
static_cast<uint32_t
>(b)+16384)>>15);
371 inline void storeRGBMono(uint8_t *&rgb_out, uint8_t *&mono_out, uint8_t red, uint8_t green,
383 *mono_out++ = rgb2Grey(red, green, blue);
391 void convertBayerGR(uint8_t *rgb_out, uint8_t *mono_out,
392 const uint8_t *row0,
const uint8_t *row1,
const uint8_t *row2,
393 bool greenfirst,
size_t width)
395 uint8_t red, green, blue;
403 convertGreenGR(red, green, blue, row0, row1, row2);
404 storeRGBMono(rgb_out, mono_out, red, green, blue);
413 convertRed(red, green, blue, row0, row1, row2);
414 storeRGBMono(rgb_out, mono_out, red, green, blue);
418 convertGreenGR(red, green, blue, row0, row1, row2);
419 storeRGBMono(rgb_out, mono_out, red, green, blue);
428 convertRed(red, green, blue, row0, row1, row2);
429 storeRGBMono(rgb_out, mono_out, red, green, blue);
437 void convertBayerGB(uint8_t *rgb_out, uint8_t *mono_out,
438 const uint8_t *row0,
const uint8_t *row1,
const uint8_t *row2,
439 bool greenfirst,
size_t width)
441 uint8_t red, green, blue;
449 convertGreenGB(red, green, blue, row0, row1, row2);
450 storeRGBMono(rgb_out, mono_out, red, green, blue);
459 convertBlue(red, green, blue, row0, row1, row2);
460 storeRGBMono(rgb_out, mono_out, red, green, blue);
464 convertGreenGB(red, green, blue, row0, row1, row2);
465 storeRGBMono(rgb_out, mono_out, red, green, blue);
474 convertBlue(red, green, blue, row0, row1, row2);
475 storeRGBMono(rgb_out, mono_out, red, green, blue);
492 for (
size_t k=0; k<
height; k++)
496 for (
size_t i=0; i<
width; i++)
507 std::memcpy(mono_out, raw, width*
sizeof(uint8_t));
518 size_t pstep=(width>>2)*6+xpadding;
519 for (
size_t k=0; k<
height; k++)
521 for (
size_t i=0; i<
width; i+=4)
528 for (
int j=0; j<12; j++)
537 *mono_out++ = raw[j];
538 *mono_out++ = raw[j+1];
539 *mono_out++ = raw[j+3];
540 *mono_out++ = raw[j+4];
552 size_t pstep=(width>>2)*8+xpadding;
553 for (
size_t k=0; k<
height; k++)
555 for (
size_t i=0; i<
width; i+=4)
562 for (
int j=0; j<12; j++)
571 *mono_out++ = raw[j];
572 *mono_out++ = raw[j+2];
573 *mono_out++ = raw[j+4];
574 *mono_out++ = raw[j+6];
585 for (
size_t k=0; k<
height; k++)
589 std::memcpy(rgb_out, raw, 3*width*
sizeof(uint8_t));
596 for (
size_t i=0; i<
width; i++)
598 *mono_out++ = rgb2Grey(raw[j], raw[j+1], raw[j+2]);
622 std::unique_ptr<uint8_t []> buffer(
new uint8_t [(width+2)*3]);
626 row[1]=row[0]+width+2;
627 row[2]=row[1]+width+2;
632 memcpy(row[1]+1, raw+width+xpadding, width*
sizeof(uint8_t));
633 memcpy(row[2]+1, raw, width*
sizeof(uint8_t));
635 row[1][0]=row[1][2]; row[1][width+1]=row[1][width-1];
636 row[2][0]=row[2][2]; row[2][width+1]=row[2][width-1];
640 for (
size_t k=0; k<
height; k++)
651 memcpy(row[2]+1, raw+(k+1)*(width+xpadding), width*
sizeof(uint8_t));
653 row[2][0]=row[2][2]; row[2][width+1]=row[2][width-1];
658 convertBayerGR(rgb_out, mono_out, row[0], row[1], row[2], greenfirst, width);
660 if (rgb_out) rgb_out+=3*
width;
661 if (mono_out) mono_out+=
width;
665 convertBayerGB(rgb_out, mono_out, row[0], row[1], row[2], greenfirst, width);
667 if (rgb_out) rgb_out+=3*
width;
668 if (mono_out) mono_out+=
width;
671 greenfirst=!greenfirst;
bool isBigEndian() const
Returns if the data is given as big or little endian.
size_t getSizeFilled() const
Returns the number of bytes written into the buffer last time it has been filled. ...
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...
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...
bool getImagePresent(std::uint32_t part) const
Returns if a 2D, 3D or confidence image is present in the specified part.
The buffer class encapsulates a Genicam buffer that is provided by a stream.
size_t getHeight(std::uint32_t part) const
Returns the height of the image in pixel.
void convYCbCr422toQuadRGB(uint8_t rgb[12], const uint8_t *row, int i)
Conversion of a group of four pixels from YCbCr422 format (8 bytes for 4 pixels) to RGB...
void convYCbCr422toRGB(uint8_t rgb[3], const uint8_t *row, int i)
Conversion of one pixel from YCbCr422 format (4 bytes for 2 pixels) to RGB.
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.
uint64_t getTimestampNS() const
Returns the acquisition timestamp of the data in this buffer in ns.
size_t getYPadding() const
Returns vertical padding of the data in the buffer in bytes.
Image(const Buffer *buffer, std::uint32_t part)
Copies the image information of the buffer.
size_t getSize(std::uint32_t part) const
Returns the size of the specified part of the mult-part buffer.
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 ...
uint64_t getPixelFormat(std::uint32_t part) const
Returns the pixel format of the specified part as defined in the PFNC.
void * getBase(std::uint32_t part) const
Returns the base address of the specified part of the multi-part buffer.
bool isFormatSupported(uint64_t pixelformat, bool only_color)
Returns true if the given pixel format is supported by the convertImage() function.
std::unique_ptr< uint8_t []> pixel
uint64_t getFrameID() const
Returns the sequentially incremented number of the frame.
size_t getXPadding(std::uint32_t part) const
Returns horizontal padding of the data in the buffer in bytes.
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, RGB8, YCbCr411_8, YCbCr422_8 or YUV422_8 format and returns the color as R...