Skip to content
This repository was archived by the owner on May 6, 2021. It is now read-only.

Commit 2e867b5

Browse files
committed
Added support for YUYV
1 parent fb1452e commit 2e867b5

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

deploy/hyperion.tar.gz

122 Bytes
Binary file not shown.

src/hyperion-v4l2/V4L2Grabber.cpp

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ V4L2Grabber::V4L2Grabber(const std::string &device, int input, VideoStandard vid
4141
_ioMethod(IO_METHOD_MMAP),
4242
_fileDescriptor(-1),
4343
_buffers(),
44+
_pixelFormat(0),
4445
_width(width),
4546
_height(height),
4647
_cropWidth(cropHorizontal),
@@ -368,9 +369,15 @@ void V4L2Grabber::init_device(VideoStandard videoStandard, int input)
368369
}
369370

370371
// check pixel format
371-
if (fmt.fmt.pix.pixelformat != V4L2_PIX_FMT_UYVY)
372+
373+
switch (fmt.fmt.pix.pixelformat)
372374
{
373-
throw_exception("Only pixel format UYVY is supported");
375+
case V4L2_PIX_FMT_UYVY:
376+
case V4L2_PIX_FMT_YUYV:
377+
_pixelFormat = fmt.fmt.pix.pixelformat;
378+
break;
379+
default:
380+
throw_exception("Only pixel formats UYVY and YUYV are supported");
374381
}
375382

376383
if (_width > 0 || _height > 0)
@@ -648,9 +655,23 @@ void V4L2Grabber::process_image(const uint8_t * data)
648655
for (int xSource = _cropWidth + _pixelDecimation/2, xDest = 0; xSource < _width - _cropWidth; xSource += _pixelDecimation, ++xDest)
649656
{
650657
int index = (_width * ySource + xSource) * 2;
651-
uint8_t y = data[index+1];
652-
uint8_t u = (xSource%2 == 0) ? data[index] : data[index-2];
653-
uint8_t v = (xSource%2 == 0) ? data[index+2] : data[index];
658+
uint8_t y = 0;
659+
uint8_t u = 0;
660+
uint8_t v = 0;
661+
662+
switch (_pixelFormat)
663+
{
664+
case V4L2_PIX_FMT_UYVY:
665+
y = data[index+1];
666+
u = (xSource%2 == 0) ? data[index ] : data[index-2];
667+
v = (xSource%2 == 0) ? data[index+2] : data[index ];
668+
break;
669+
case V4L2_PIX_FMT_YUYV:
670+
y = data[index];
671+
u = (xSource%2 == 0) ? data[index+1] : data[index-1];
672+
v = (xSource%2 == 0) ? data[index+3] : data[index+1];
673+
break;
674+
}
654675

655676
ColorRgb & rgb = image(xDest, yDest);
656677
yuv2rgb(y, u, v, rgb.red, rgb.green, rgb.blue);

src/hyperion-v4l2/V4L2Grabber.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class V4L2Grabber
8181
int _fileDescriptor;
8282
std::vector<buffer> _buffers;
8383

84+
uint32_t _pixelFormat;
8485
int _width;
8586
int _height;
8687
const int _cropWidth;

0 commit comments

Comments
 (0)