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;
|
|
|
|
|
2016-12-19 23:59:50 +01:00
|
|
|
ImageProcessor::ImageProcessor(const LedString& ledString, const QJsonObject & blackborderConfig)
|
|
|
|
: QObject()
|
|
|
|
, _log(Logger::getInstance("BLACKBORDER"))
|
|
|
|
, _ledString(ledString)
|
|
|
|
, _borderProcessor(new BlackBorderProcessor(blackborderConfig) )
|
|
|
|
, _imageToLeds(nullptr)
|
|
|
|
, _mappingType(0)
|
2013-08-13 11:10:45 +02:00
|
|
|
{
|
2016-12-19 23:59:50 +01:00
|
|
|
// this is when we want to change the mapping for all input sources
|
|
|
|
// connect(Hyperion::getInstance(), SIGNAL(imageToLedsMappingChanged(int)), this, SLOT(setLedMappingType(int)));
|
2013-08-13 11:10:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ImageProcessor::~ImageProcessor()
|
|
|
|
{
|
2014-01-20 20:46:38 +01:00
|
|
|
delete _imageToLeds;
|
2013-08-23 07:09:09 +02:00
|
|
|
delete _borderProcessor;
|
2013-08-13 11:10:45 +02:00
|
|
|
}
|
|
|
|
|
2013-11-28 14:38:07 +01:00
|
|
|
unsigned ImageProcessor::getLedCount() const
|
|
|
|
{
|
2014-01-20 20:46:38 +01:00
|
|
|
return _ledString.leds().size();
|
2013-11-28 14:38:07 +01:00
|
|
|
}
|
|
|
|
|
2013-08-13 11:10:45 +02:00
|
|
|
void ImageProcessor::setSize(const unsigned width, const unsigned height)
|
|
|
|
{
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clean up the old buffer and mapping
|
2014-01-20 20:46:38 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-07-15 10:28:12 +02:00
|
|
|
void ImageProcessor::enableBlackBorderDetector(bool enable)
|
2014-04-30 22:53:05 +02:00
|
|
|
{
|
2016-07-15 10:28:12 +02:00
|
|
|
_borderProcessor->setEnabled(enable);
|
2014-04-30 22:53:05 +02:00
|
|
|
}
|
|
|
|
|
2016-08-11 07:13:55 +02:00
|
|
|
bool ImageProcessor::blackBorderDetectorEnabled()
|
|
|
|
{
|
|
|
|
return _borderProcessor->enabled();
|
|
|
|
}
|
|
|
|
|
2016-12-19 23:59:50 +01:00
|
|
|
void ImageProcessor::setLedMappingType(int mapType)
|
|
|
|
{
|
|
|
|
Debug(_log, "set led mapping to type %d", mapType);
|
|
|
|
_mappingType = mapType;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ImageProcessor::ledMappingType()
|
|
|
|
{
|
|
|
|
return _mappingType;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ImageProcessor::mappingTypeToInt(QString mappingType)
|
|
|
|
{
|
|
|
|
if (mappingType == "unicolor_mean" )
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-12-20 19:55:54 +01:00
|
|
|
QString ImageProcessor::mappingTypeToStr(int mappingType)
|
|
|
|
{
|
|
|
|
if (mappingType == 1 )
|
|
|
|
return "unicolor_mean";
|
|
|
|
|
2016-12-21 18:24:03 +01:00
|
|
|
return "multicolor_mean";
|
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;
|
|
|
|
}
|
|
|
|
|