mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
Switched added to hyperion-v4l2 to process the video stream as a 3D SBS or TAB
Former-commit-id: cdd121f172f4e42e301f63a3a2a51ec97ac97e3b
This commit is contained in:
parent
bad5b34796
commit
62c1d36195
@ -1 +1 @@
|
||||
fb67681c8c942ffe2236a4ea3a41d4102c3fbb2e
|
||||
f3afa39f64294a9ce71af8e424e4bab72d2b29cb
|
@ -42,10 +42,6 @@ V4L2Grabber::V4L2Grabber(
|
||||
VideoStandard videoStandard,
|
||||
int width,
|
||||
int height,
|
||||
int cropLeft,
|
||||
int cropRight,
|
||||
int cropTop,
|
||||
int cropBottom,
|
||||
int frameDecimation,
|
||||
int horizontalPixelDecimation,
|
||||
int verticalPixelDecimation) :
|
||||
@ -56,13 +52,14 @@ V4L2Grabber::V4L2Grabber(
|
||||
_pixelFormat(0),
|
||||
_width(width),
|
||||
_height(height),
|
||||
_cropLeft(cropLeft),
|
||||
_cropRight(cropRight),
|
||||
_cropTop(cropTop),
|
||||
_cropBottom(cropBottom),
|
||||
_cropLeft(0),
|
||||
_cropRight(0),
|
||||
_cropTop(0),
|
||||
_cropBottom(0),
|
||||
_frameDecimation(std::max(1, frameDecimation)),
|
||||
_horizontalPixelDecimation(std::max(1, horizontalPixelDecimation)),
|
||||
_verticalPixelDecimation(std::max(1, verticalPixelDecimation)),
|
||||
_mode3D(MODE_NONE),
|
||||
_currentFrame(0),
|
||||
_callback(nullptr),
|
||||
_callbackArg(nullptr)
|
||||
@ -77,6 +74,19 @@ V4L2Grabber::~V4L2Grabber()
|
||||
close_device();
|
||||
}
|
||||
|
||||
void V4L2Grabber::setCropping(int cropLeft, int cropRight, int cropTop, int cropBottom)
|
||||
{
|
||||
_cropLeft = cropLeft;
|
||||
_cropRight = cropRight;
|
||||
_cropTop = cropTop;
|
||||
_cropBottom = cropBottom;
|
||||
}
|
||||
|
||||
void V4L2Grabber::set3D(Mode3D mode)
|
||||
{
|
||||
_mode3D = mode;
|
||||
}
|
||||
|
||||
void V4L2Grabber::setCallback(V4L2Grabber::ImageCallback callback, void *arg)
|
||||
{
|
||||
_callback = callback;
|
||||
@ -659,14 +669,29 @@ bool V4L2Grabber::process_image(const void *p, int size)
|
||||
|
||||
void V4L2Grabber::process_image(const uint8_t * data)
|
||||
{
|
||||
int width = (_width - _cropLeft - _cropRight + _horizontalPixelDecimation/2) / _horizontalPixelDecimation;
|
||||
int height = (_height - _cropTop - _cropBottom + _verticalPixelDecimation/2) / _verticalPixelDecimation;
|
||||
int width = _width;
|
||||
int height = _height;
|
||||
|
||||
Image<ColorRgb> image(width, height);
|
||||
|
||||
for (int ySource = _cropTop + _verticalPixelDecimation/2, yDest = 0; ySource < _height - _cropBottom; ySource += _verticalPixelDecimation, ++yDest)
|
||||
switch (_mode3D)
|
||||
{
|
||||
for (int xSource = _cropLeft + _horizontalPixelDecimation/2, xDest = 0; xSource < _width - _cropRight; xSource += _horizontalPixelDecimation, ++xDest)
|
||||
case MODE_3DSBS:
|
||||
width = _width/2;
|
||||
break;
|
||||
case MODE_3DTAB:
|
||||
height = _height/2;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// create output structure
|
||||
int outputWidth = (width - _cropLeft - _cropRight + _horizontalPixelDecimation/2) / _horizontalPixelDecimation;
|
||||
int outputHeight = (height - _cropTop - _cropBottom + _verticalPixelDecimation/2) / _verticalPixelDecimation;
|
||||
Image<ColorRgb> image(outputWidth, outputHeight);
|
||||
|
||||
for (int ySource = _cropTop + _verticalPixelDecimation/2, yDest = 0; ySource < height - _cropBottom; ySource += _verticalPixelDecimation, ++yDest)
|
||||
{
|
||||
for (int xSource = _cropLeft + _horizontalPixelDecimation/2, xDest = 0; xSource < width - _cropRight; xSource += _horizontalPixelDecimation, ++xDest)
|
||||
{
|
||||
int index = (_width * ySource + xSource) * 2;
|
||||
uint8_t y = 0;
|
||||
|
@ -20,6 +20,10 @@ public:
|
||||
PAL, NTSC, NO_CHANGE
|
||||
};
|
||||
|
||||
enum Mode3D {
|
||||
MODE_NONE, MODE_3DSBS, MODE_3DTAB
|
||||
};
|
||||
|
||||
public:
|
||||
V4L2Grabber(
|
||||
const std::string & device,
|
||||
@ -27,15 +31,18 @@ public:
|
||||
VideoStandard videoStandard,
|
||||
int width,
|
||||
int height,
|
||||
int cropLeft,
|
||||
int cropRight,
|
||||
int cropTop,
|
||||
int cropBottom,
|
||||
int frameDecimation,
|
||||
int horizontalPixelDecimation,
|
||||
int verticalPixelDecimation);
|
||||
virtual ~V4L2Grabber();
|
||||
|
||||
void setCropping(int cropLeft,
|
||||
int cropRight,
|
||||
int cropTop,
|
||||
int cropBottom);
|
||||
|
||||
void set3D(Mode3D mode);
|
||||
|
||||
void setCallback(ImageCallback callback, void * arg);
|
||||
|
||||
void start();
|
||||
@ -96,13 +103,15 @@ private:
|
||||
uint32_t _pixelFormat;
|
||||
int _width;
|
||||
int _height;
|
||||
const int _cropLeft;
|
||||
const int _cropRight;
|
||||
const int _cropTop;
|
||||
const int _cropBottom;
|
||||
const int _frameDecimation;
|
||||
const int _horizontalPixelDecimation;
|
||||
const int _verticalPixelDecimation;
|
||||
int _cropLeft;
|
||||
int _cropRight;
|
||||
int _cropTop;
|
||||
int _cropBottom;
|
||||
int _frameDecimation;
|
||||
int _horizontalPixelDecimation;
|
||||
int _verticalPixelDecimation;
|
||||
|
||||
Mode3D _mode3D;
|
||||
|
||||
int _currentFrame;
|
||||
|
||||
|
@ -54,6 +54,8 @@ int main(int argc, char** argv)
|
||||
IntParameter & argFrameDecimation = parameters.add<IntParameter> ('f', "frame-decimator", "Decimation factor for the video frames [default=1]");
|
||||
SwitchParameter<> & argScreenshot = parameters.add<SwitchParameter<>> (0x0, "screenshot", "Take a single screenshot, save it to file and quit");
|
||||
DoubleParameter & argSignalThreshold = parameters.add<DoubleParameter> ('t', "signal-threshold", "The signal threshold for detecting the presence of a signal. Value should be between 0.0 and 1.0.");
|
||||
SwitchParameter<> & arg3DSBS = parameters.add<SwitchParameter<>> (0x0, "3DSBS", "Interpret the incoming video stream as 3D side-by-side");
|
||||
SwitchParameter<> & arg3DTAB = parameters.add<SwitchParameter<>> (0x0, "3DTAB", "Interpret the incoming video stream as 3D top-and-bottom");
|
||||
StringParameter & argAddress = parameters.add<StringParameter> ('a', "address", "Set the address of the hyperion server [default: 127.0.0.1:19445]");
|
||||
IntParameter & argPriority = parameters.add<IntParameter> ('p', "priority", "Use the provided priority channel (the lower the number, the higher the priority) [default: 800]");
|
||||
SwitchParameter<> & argSkipReply = parameters.add<SwitchParameter<>> (0x0, "skip-reply", "Do not receive and check reply messages from Hyperion");
|
||||
@ -88,21 +90,38 @@ int main(int argc, char** argv)
|
||||
if (!argCropTop.isSet()) argCropTop.setDefault(argCropHeight.getValue());
|
||||
if (!argCropBottom.isSet()) argCropBottom.setDefault(argCropHeight.getValue());
|
||||
|
||||
// initialize the grabber
|
||||
V4L2Grabber grabber(
|
||||
argDevice.getValue(),
|
||||
argInput.getValue(),
|
||||
argVideoStandard.getValue(),
|
||||
argWidth.getValue(),
|
||||
argHeight.getValue(),
|
||||
std::max(0, argCropLeft.getValue()),
|
||||
std::max(0, argCropRight.getValue()),
|
||||
std::max(0, argCropTop.getValue()),
|
||||
std::max(0, argCropBottom.getValue()),
|
||||
std::max(1, argFrameDecimation.getValue()),
|
||||
std::max(1, argSizeDecimation.getValue()),
|
||||
std::max(1, argSizeDecimation.getValue()));
|
||||
|
||||
// set cropping values
|
||||
grabber.setCropping(
|
||||
std::max(0, argCropLeft.getValue()),
|
||||
std::max(0, argCropRight.getValue()),
|
||||
std::max(0, argCropTop.getValue()),
|
||||
std::max(0, argCropBottom.getValue()));
|
||||
|
||||
// set 3D mode if applicable
|
||||
if (arg3DSBS.isSet())
|
||||
{
|
||||
grabber.set3D(V4L2Grabber::MODE_3DSBS);
|
||||
}
|
||||
else if (arg3DTAB.isSet())
|
||||
{
|
||||
grabber.set3D(V4L2Grabber::MODE_3DTAB);
|
||||
}
|
||||
|
||||
// start the grabber
|
||||
grabber.start();
|
||||
|
||||
// run the grabber
|
||||
if (argScreenshot.isSet())
|
||||
{
|
||||
grabber.setCallback(&saveScreenshot, nullptr);
|
||||
@ -114,6 +133,8 @@ int main(int argc, char** argv)
|
||||
grabber.setCallback(&ImageHandler::imageCallback, &handler);
|
||||
grabber.capture();
|
||||
}
|
||||
|
||||
// stop the grabber
|
||||
grabber.stop();
|
||||
}
|
||||
catch (const std::runtime_error & e)
|
||||
|
Loading…
Reference in New Issue
Block a user