2013-08-13 11:10:45 +02:00
|
|
|
|
2013-08-23 07:09:09 +02:00
|
|
|
// Hyperion includes
|
2016-12-19 23:59:50 +01:00
|
|
|
#include <hyperion/Hyperion.h>
|
2013-08-23 07:09:09 +02:00
|
|
|
#include <hyperion/ImageProcessor.h>
|
2013-11-11 10:00:37 +01:00
|
|
|
#include <hyperion/ImageToLedsMap.h>
|
2014-01-26 14:23:08 +01:00
|
|
|
|
|
|
|
// Blacborder includes
|
|
|
|
#include <blackborder/BlackBorderProcessor.h>
|
2013-08-13 11:10:45 +02:00
|
|
|
|
|
|
|
using namespace hyperion;
|
|
|
|
|
2018-12-27 23:11:32 +01:00
|
|
|
// global transform method
|
2020-08-08 23:12:43 +02:00
|
|
|
int ImageProcessor::mappingTypeToInt(const QString& mappingType)
|
2018-12-27 23:11:32 +01:00
|
|
|
{
|
|
|
|
if (mappingType == "unicolor_mean" )
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
// global transform method
|
|
|
|
QString ImageProcessor::mappingTypeToStr(int mappingType)
|
|
|
|
{
|
|
|
|
if (mappingType == 1 )
|
|
|
|
return "unicolor_mean";
|
|
|
|
|
|
|
|
return "multicolor_mean";
|
|
|
|
}
|
|
|
|
|
|
|
|
ImageProcessor::ImageProcessor(const LedString& ledString, Hyperion* hyperion)
|
|
|
|
: QObject(hyperion)
|
2016-12-19 23:59:50 +01:00
|
|
|
, _log(Logger::getInstance("BLACKBORDER"))
|
|
|
|
, _ledString(ledString)
|
2018-12-27 23:11:32 +01:00
|
|
|
, _borderProcessor(new BlackBorderProcessor(hyperion, this))
|
2016-12-19 23:59:50 +01:00
|
|
|
, _imageToLeds(nullptr)
|
|
|
|
, _mappingType(0)
|
2018-12-27 23:11:32 +01:00
|
|
|
, _userMappingType(0)
|
|
|
|
, _hardMappingType(0)
|
|
|
|
, _hyperion(hyperion)
|
2013-08-13 11:10:45 +02:00
|
|
|
{
|
2018-12-27 23:11:32 +01:00
|
|
|
// init
|
|
|
|
handleSettingsUpdate(settings::COLOR, _hyperion->getSetting(settings::COLOR));
|
|
|
|
// listen for changes in color - ledmapping
|
|
|
|
connect(_hyperion, &Hyperion::settingsChanged, this, &ImageProcessor::handleSettingsUpdate);
|
2013-08-13 11:10:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ImageProcessor::~ImageProcessor()
|
|
|
|
{
|
2014-01-20 20:46:38 +01:00
|
|
|
delete _imageToLeds;
|
2013-08-13 11:10:45 +02:00
|
|
|
}
|
|
|
|
|
2020-08-08 13:09:15 +02:00
|
|
|
void ImageProcessor::handleSettingsUpdate(settings::type type, const QJsonDocument& config)
|
2013-11-28 14:38:07 +01:00
|
|
|
{
|
2018-12-27 23:11:32 +01:00
|
|
|
if(type == settings::COLOR)
|
|
|
|
{
|
|
|
|
const QJsonObject& obj = config.object();
|
|
|
|
int newType = mappingTypeToInt(obj["imageToLedMappingType"].toString());
|
|
|
|
if(_userMappingType != newType)
|
|
|
|
{
|
|
|
|
setLedMappingType(newType);
|
|
|
|
}
|
|
|
|
}
|
2013-11-28 14:38:07 +01:00
|
|
|
}
|
|
|
|
|
2020-08-08 13:09:15 +02:00
|
|
|
void ImageProcessor::setSize(unsigned width, unsigned height)
|
2013-08-13 11:10:45 +02:00
|
|
|
{
|
|
|
|
// Check if the existing buffer-image is already the correct dimensions
|
2014-01-20 20:46:38 +01:00
|
|
|
if (_imageToLeds && _imageToLeds->width() == width && _imageToLeds->height() == height)
|
2013-08-13 11:10:45 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-12 09:19:59 +02:00
|
|
|
// Clean up the old buffer and mapping
|
|
|
|
delete _imageToLeds;
|
2013-08-13 11:10:45 +02:00
|
|
|
|
|
|
|
// Construct a new buffer and mapping
|
2017-08-12 07:55:32 +02:00
|
|
|
_imageToLeds = (width>0 && height>0) ? (new ImageToLedsMap(width, height, 0, 0, _ledString.leds())) : nullptr;
|
2013-08-13 11:10:45 +02:00
|
|
|
}
|
|
|
|
|
2018-12-27 23:11:32 +01:00
|
|
|
void ImageProcessor::setLedString(const LedString& ledString)
|
2014-04-30 22:53:05 +02:00
|
|
|
{
|
2020-03-22 22:07:19 +01:00
|
|
|
if ( _imageToLeds != nullptr)
|
|
|
|
{
|
|
|
|
_ledString = ledString;
|
2014-04-30 22:53:05 +02:00
|
|
|
|
2020-03-22 22:07:19 +01:00
|
|
|
// get current width/height
|
|
|
|
unsigned width = _imageToLeds->width();
|
|
|
|
unsigned height = _imageToLeds->height();
|
2018-12-27 23:11:32 +01:00
|
|
|
|
2020-03-22 22:07:19 +01:00
|
|
|
// Clean up the old buffer and mapping
|
|
|
|
delete _imageToLeds;
|
2018-12-27 23:11:32 +01:00
|
|
|
|
2020-03-22 22:07:19 +01:00
|
|
|
// Construct a new buffer and mapping
|
|
|
|
_imageToLeds = new ImageToLedsMap(width, height, 0, 0, _ledString.leds());
|
|
|
|
}
|
2016-08-11 07:13:55 +02:00
|
|
|
}
|
|
|
|
|
2018-12-27 23:11:32 +01:00
|
|
|
void ImageProcessor::setBlackbarDetectDisable(bool enable)
|
2016-12-19 23:59:50 +01:00
|
|
|
{
|
2018-12-27 23:11:32 +01:00
|
|
|
_borderProcessor->setHardDisable(enable);
|
2016-12-19 23:59:50 +01:00
|
|
|
}
|
|
|
|
|
2020-08-08 23:12:43 +02:00
|
|
|
bool ImageProcessor::blackBorderDetectorEnabled() const
|
2016-12-19 23:59:50 +01:00
|
|
|
{
|
2018-12-27 23:11:32 +01:00
|
|
|
return _borderProcessor->enabled();
|
2016-12-19 23:59:50 +01:00
|
|
|
}
|
|
|
|
|
2018-12-27 23:11:32 +01:00
|
|
|
void ImageProcessor::setLedMappingType(int mapType)
|
2016-12-19 23:59:50 +01:00
|
|
|
{
|
2018-12-27 23:11:32 +01:00
|
|
|
// if the _hardMappingType is >-1 we aren't allowed to overwrite it
|
|
|
|
_userMappingType = mapType;
|
|
|
|
Debug(_log, "set user led mapping to %s", QSTRING_CSTR(mappingTypeToStr(mapType)));
|
|
|
|
if(_hardMappingType == -1)
|
|
|
|
{
|
|
|
|
_mappingType = mapType;
|
|
|
|
}
|
2016-12-19 23:59:50 +01:00
|
|
|
}
|
|
|
|
|
2018-12-27 23:11:32 +01:00
|
|
|
void ImageProcessor::setHardLedMappingType(int mapType)
|
2016-12-20 19:55:54 +01:00
|
|
|
{
|
2018-12-27 23:11:32 +01:00
|
|
|
// force the maptype, if set to -1 we use the last requested _userMappingType
|
|
|
|
_hardMappingType = mapType;
|
|
|
|
if(mapType == -1)
|
|
|
|
_mappingType = _userMappingType;
|
|
|
|
else
|
|
|
|
_mappingType = mapType;
|
2016-12-20 19:55:54 +01:00
|
|
|
}
|
|
|
|
|
2013-11-08 22:18:10 +01:00
|
|
|
bool ImageProcessor::getScanParameters(size_t led, double &hscanBegin, double &hscanEnd, double &vscanBegin, double &vscanEnd) const
|
|
|
|
{
|
2014-01-20 20:46:38 +01:00
|
|
|
if (led < _ledString.leds().size())
|
2013-11-08 22:18:10 +01:00
|
|
|
{
|
2014-01-20 20:46:38 +01:00
|
|
|
const Led & l = _ledString.leds()[led];
|
2013-11-08 22:18:10 +01:00
|
|
|
hscanBegin = l.minX_frac;
|
|
|
|
hscanEnd = l.maxX_frac;
|
|
|
|
vscanBegin = l.minY_frac;
|
|
|
|
vscanEnd = l.maxY_frac;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|