2016-07-24 15:18:34 +02:00
|
|
|
// Hyperion includes
|
|
|
|
#include <hyperion/Hyperion.h>
|
|
|
|
#include <hyperion/ImageProcessorFactory.h>
|
|
|
|
#include <hyperion/ImageProcessor.h>
|
|
|
|
|
|
|
|
// X11 grabber includes
|
|
|
|
#include <grabber/X11Wrapper.h>
|
|
|
|
#include <grabber/X11Grabber.h>
|
|
|
|
|
|
|
|
X11Wrapper::X11Wrapper(bool useXGetImage, int cropLeft, int cropRight, int cropTop, int cropBottom, int horizontalPixelDecimation, int verticalPixelDecimation, const unsigned updateRate_Hz, const int priority)
|
2016-08-11 07:13:55 +02:00
|
|
|
: GrabberWrapper("X11", priority)
|
|
|
|
, _updateInterval_ms(1000/updateRate_Hz)
|
2016-07-24 15:18:34 +02:00
|
|
|
, _timeout_ms(2 * _updateInterval_ms)
|
|
|
|
, _grabber(new X11Grabber(useXGetImage, cropLeft, cropRight, cropTop, cropBottom, horizontalPixelDecimation, verticalPixelDecimation))
|
|
|
|
, _ledColors(Hyperion::getInstance()->getLedCount(), ColorRgb{0,0,0})
|
|
|
|
, _init(false)
|
|
|
|
, _x11SetupSuccess(false)
|
|
|
|
{
|
|
|
|
// Configure the timer to generate events every n milliseconds
|
|
|
|
_timer.setInterval(_updateInterval_ms);
|
|
|
|
}
|
|
|
|
|
|
|
|
X11Wrapper::~X11Wrapper()
|
|
|
|
{
|
|
|
|
delete _grabber;
|
|
|
|
}
|
|
|
|
|
2016-08-11 07:13:55 +02:00
|
|
|
bool X11Wrapper::start()
|
2016-07-24 15:18:34 +02:00
|
|
|
{
|
|
|
|
if (! _init )
|
|
|
|
{
|
|
|
|
_init = true;
|
|
|
|
_x11SetupSuccess = _grabber->Setup();
|
|
|
|
if ( _x11SetupSuccess )
|
|
|
|
{
|
|
|
|
_x11SetupSuccess = (_grabber->updateScreenDimensions() >= 0);
|
|
|
|
_processor->setSize(_grabber->getImageWidth(), _grabber->getImageHeight());
|
|
|
|
_image.resize(_grabber->getImageWidth(), _grabber->getImageHeight());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Start the timer with the pre configured interval
|
|
|
|
if ( _x11SetupSuccess )
|
|
|
|
{
|
2016-08-11 07:13:55 +02:00
|
|
|
GrabberWrapper::start();
|
2016-07-24 15:18:34 +02:00
|
|
|
}
|
|
|
|
|
2016-08-11 07:13:55 +02:00
|
|
|
ErrorIf( ! _x11SetupSuccess, _log, "X11 Grabber start failed");
|
|
|
|
return _x11SetupSuccess;
|
2016-07-24 15:18:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void X11Wrapper::action()
|
|
|
|
{
|
|
|
|
int result = _grabber->updateScreenDimensions();
|
|
|
|
if (result < 0 )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ( result > 0 )
|
|
|
|
{
|
|
|
|
_processor->setSize(_grabber->getImageWidth(), _grabber->getImageHeight());
|
|
|
|
_image.resize(_grabber->getImageWidth(), _grabber->getImageHeight());
|
|
|
|
}
|
|
|
|
// Grab frame into the allocated image
|
|
|
|
_grabber->grabFrame(_image);
|
|
|
|
|
2016-12-24 10:02:12 +01:00
|
|
|
emit emitImage(_priority, _image, _timeout_ms);
|
2016-07-24 15:18:34 +02:00
|
|
|
|
|
|
|
_processor->process(_image, _ledColors);
|
2016-10-10 18:29:54 +02:00
|
|
|
setColors(_ledColors, _timeout_ms);
|
2016-07-24 15:18:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void X11Wrapper::setVideoMode(const VideoMode mode)
|
|
|
|
{
|
|
|
|
_grabber->setVideoMode(mode);
|
|
|
|
}
|