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

Commit 38da422

Browse files
committed
Merge branch 'add_x11' of https://github.com/tvdzwan/hyperion into add_x11
2 parents 134df57 + c6ec92c commit 38da422

File tree

2 files changed

+17
-104
lines changed

2 files changed

+17
-104
lines changed

include/grabber/V4L2Grabber.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <utils/ColorRgb.h>
1414
#include <utils/PixelFormat.h>
1515
#include <utils/VideoMode.h>
16+
#include <utils/ImageResampler.h>
1617

1718
// grabber includes
1819
#include <grabber/VideoStandard.h>
@@ -108,22 +109,17 @@ private slots:
108109
PixelFormat _pixelFormat;
109110
int _width;
110111
int _height;
112+
int _lineLength;
111113
int _frameByteSize;
112-
int _cropLeft;
113-
int _cropRight;
114-
int _cropTop;
115-
int _cropBottom;
116114
int _frameDecimation;
117-
int _horizontalPixelDecimation;
118-
int _verticalPixelDecimation;
119115
int _noSignalCounterThreshold;
120116

121117
ColorRgb _noSignalThresholdColor;
122118

123-
VideoMode _mode3D;
124-
125119
int _currentFrame;
126120
int _noSignalCounter;
127121

128122
QSocketNotifier * _streamNotifier;
123+
124+
ImageResampler _imageResampler;
129125
};

libsrc/grabber/v4l2/V4L2Grabber.cpp

Lines changed: 13 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,6 @@
1818

1919
#define CLEAR(x) memset(&(x), 0, sizeof(x))
2020

21-
static inline uint8_t clamp(int x)
22-
{
23-
return (x<0) ? 0 : ((x>255) ? 255 : uint8_t(x));
24-
}
25-
26-
static void yuv2rgb(uint8_t y, uint8_t u, uint8_t v, uint8_t & r, uint8_t & g, uint8_t & b)
27-
{
28-
// see: http://en.wikipedia.org/wiki/YUV#Y.27UV444_to_RGB888_conversion
29-
int c = y - 16;
30-
int d = u - 128;
31-
int e = v - 128;
32-
33-
r = clamp((298 * c + 409 * e + 128) >> 8);
34-
g = clamp((298 * c - 100 * d - 208 * e + 128) >> 8);
35-
b = clamp((298 * c + 516 * d + 128) >> 8);
36-
}
37-
38-
3921
V4L2Grabber::V4L2Grabber(const std::string & device,
4022
int input,
4123
VideoStandard videoStandard,
@@ -52,21 +34,19 @@ V4L2Grabber::V4L2Grabber(const std::string & device,
5234
_pixelFormat(pixelFormat),
5335
_width(width),
5436
_height(height),
37+
_lineLength(-1),
5538
_frameByteSize(-1),
56-
_cropLeft(0),
57-
_cropRight(0),
58-
_cropTop(0),
59-
_cropBottom(0),
6039
_frameDecimation(std::max(1, frameDecimation)),
61-
_horizontalPixelDecimation(std::max(1, horizontalPixelDecimation)),
62-
_verticalPixelDecimation(std::max(1, verticalPixelDecimation)),
6340
_noSignalCounterThreshold(50),
6441
_noSignalThresholdColor(ColorRgb{0,0,0}),
65-
_mode3D(VIDEO_2D),
6642
_currentFrame(0),
6743
_noSignalCounter(0),
68-
_streamNotifier(nullptr)
44+
_streamNotifier(nullptr),
45+
_imageResampler()
6946
{
47+
_imageResampler.setHorizontalPixelDecimation(std::max(1, horizontalPixelDecimation));
48+
_imageResampler.setVerticalPixelDecimation(std::max(1, verticalPixelDecimation));
49+
7050
open_device();
7151
init_device(videoStandard, input);
7252
}
@@ -81,15 +61,12 @@ V4L2Grabber::~V4L2Grabber()
8161

8262
void V4L2Grabber::setCropping(int cropLeft, int cropRight, int cropTop, int cropBottom)
8363
{
84-
_cropLeft = cropLeft;
85-
_cropRight = cropRight;
86-
_cropTop = cropTop;
87-
_cropBottom = cropBottom;
64+
_imageResampler.setCropping(cropLeft, cropRight, cropTop, cropBottom);
8865
}
8966

9067
void V4L2Grabber::set3D(VideoMode mode)
9168
{
92-
_mode3D = mode;
69+
_imageResampler.set3D(mode);
9370
}
9471

9572
void V4L2Grabber::setSignalThreshold(double redSignalThreshold, double greenSignalThreshold, double blueSignalThreshold, int noSignalCounterThreshold)
@@ -414,6 +391,9 @@ void V4L2Grabber::init_device(VideoStandard videoStandard, int input)
414391
}
415392
}
416393

394+
// set the line length
395+
_lineLength = fmt.fmt.pix.bytesperline;
396+
417397
// set the settings
418398
if (-1 == xioctl(VIDIOC_S_FMT, &fmt))
419399
{
@@ -688,71 +668,8 @@ bool V4L2Grabber::process_image(const void *p, int size)
688668

689669
void V4L2Grabber::process_image(const uint8_t * data)
690670
{
691-
int width = _width;
692-
int height = _height;
693-
694-
switch (_mode3D)
695-
{
696-
case VIDEO_3DSBS:
697-
width = _width/2;
698-
break;
699-
case VIDEO_3DTAB:
700-
height = _height/2;
701-
break;
702-
default:
703-
break;
704-
}
705-
706-
// create output structure
707-
int outputWidth = (width - _cropLeft - _cropRight + _horizontalPixelDecimation/2) / _horizontalPixelDecimation;
708-
int outputHeight = (height - _cropTop - _cropBottom + _verticalPixelDecimation/2) / _verticalPixelDecimation;
709-
710-
// TODO: should this be the following (like X11):
711-
//int outputWidth = (width - _cropLeft - _cropRight + _horizontalPixelDecimation/2 - 1) / _horizontalPixelDecimation + 1;
712-
//int outputHeight = (height - _cropTop - _cropBottom + _verticalPixelDecimation/2 - 1) / _verticalPixelDecimation + 1;
713-
714-
Image<ColorRgb> image(outputWidth, outputHeight);
715-
716-
for (int ySource = _cropTop + _verticalPixelDecimation/2, yDest = 0; ySource < height - _cropBottom; ySource += _verticalPixelDecimation, ++yDest)
717-
{
718-
for (int xSource = _cropLeft + _horizontalPixelDecimation/2, xDest = 0; xSource < width - _cropRight; xSource += _horizontalPixelDecimation, ++xDest)
719-
{
720-
ColorRgb & rgb = image(xDest, yDest);
721-
722-
switch (_pixelFormat)
723-
{
724-
case PIXELFORMAT_UYVY:
725-
{
726-
int index = (_width * ySource + xSource) * 2;
727-
uint8_t y = data[index+1];
728-
uint8_t u = (xSource%2 == 0) ? data[index ] : data[index-2];
729-
uint8_t v = (xSource%2 == 0) ? data[index+2] : data[index ];
730-
yuv2rgb(y, u, v, rgb.red, rgb.green, rgb.blue);
731-
}
732-
break;
733-
case PIXELFORMAT_YUYV:
734-
{
735-
int index = (_width * ySource + xSource) * 2;
736-
uint8_t y = data[index];
737-
uint8_t u = (xSource%2 == 0) ? data[index+1] : data[index-1];
738-
uint8_t v = (xSource%2 == 0) ? data[index+3] : data[index+1];
739-
yuv2rgb(y, u, v, rgb.red, rgb.green, rgb.blue);
740-
}
741-
break;
742-
case PIXELFORMAT_RGB32:
743-
{
744-
int index = (_width * ySource + xSource) * 4;
745-
rgb.red = data[index ];
746-
rgb.green = data[index+1];
747-
rgb.blue = data[index+2];
748-
}
749-
break;
750-
default:
751-
// this should not be possible
752-
break;
753-
}
754-
}
755-
}
671+
Image<ColorRgb> image(0, 0);
672+
_imageResampler.processImage(data, _width, _height, _lineLength, _pixelFormat, image);
756673

757674
// check signal (only in center of the resulting image, because some grabbers have noise values along the borders)
758675
bool noSignal = true;

0 commit comments

Comments
 (0)