mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
ImageToLED - Add reduced pixel processing, make dominant color advanced configurable
This commit is contained in:
@@ -4,13 +4,40 @@
|
||||
#include <hyperion/ImageProcessor.h>
|
||||
#include <hyperion/ImageToLedsMap.h>
|
||||
|
||||
// Blacborder includes
|
||||
// Blackborder includes
|
||||
#include <blackborder/BlackBorderProcessor.h>
|
||||
|
||||
#include <QSharedPointer>
|
||||
#include <QRgb>
|
||||
|
||||
using namespace hyperion;
|
||||
|
||||
void ImageProcessor::registerProcessingUnit(
|
||||
int width,
|
||||
int height,
|
||||
int horizontalBorder,
|
||||
int verticalBorder)
|
||||
{
|
||||
if (width > 0 && height > 0)
|
||||
{
|
||||
_imageToLedColors = QSharedPointer<ImageToLedsMap>(new ImageToLedsMap(
|
||||
_log,
|
||||
_mappingType,
|
||||
width,
|
||||
height,
|
||||
horizontalBorder,
|
||||
verticalBorder,
|
||||
_ledString.leds(),
|
||||
_reducedPixelSetFactorFactor,
|
||||
_accuraryLevel
|
||||
));
|
||||
}
|
||||
else
|
||||
{
|
||||
_imageToLedColors = QSharedPointer<ImageToLedsMap>(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
// global transform method
|
||||
int ImageProcessor::mappingTypeToInt(const QString& mappingType)
|
||||
{
|
||||
@@ -62,10 +89,12 @@ ImageProcessor::ImageProcessor(const LedString& ledString, Hyperion* hyperion)
|
||||
, _log(nullptr)
|
||||
, _ledString(ledString)
|
||||
, _borderProcessor(new BlackBorderProcessor(hyperion, this))
|
||||
, _imageToLeds(nullptr)
|
||||
, _imageToLedColors(nullptr)
|
||||
, _mappingType(0)
|
||||
, _userMappingType(0)
|
||||
, _hardMappingType(0)
|
||||
, _hardMappingType(-1)
|
||||
, _accuraryLevel(0)
|
||||
, _reducedPixelSetFactorFactor(1)
|
||||
, _hyperion(hyperion)
|
||||
{
|
||||
QString subComponent = hyperion->property("instance").toString();
|
||||
@@ -79,7 +108,6 @@ ImageProcessor::ImageProcessor(const LedString& ledString, Hyperion* hyperion)
|
||||
|
||||
ImageProcessor::~ImageProcessor()
|
||||
{
|
||||
delete _imageToLeds;
|
||||
}
|
||||
|
||||
void ImageProcessor::handleSettingsUpdate(settings::type type, const QJsonDocument& config)
|
||||
@@ -92,39 +120,40 @@ void ImageProcessor::handleSettingsUpdate(settings::type type, const QJsonDocume
|
||||
{
|
||||
setLedMappingType(newType);
|
||||
}
|
||||
|
||||
int reducedPixelSetFactorFactor = obj["reducedPixelSetFactorFactor"].toString().toInt();
|
||||
setReducedPixelSetFactorFactor(reducedPixelSetFactorFactor);
|
||||
|
||||
int accuracyLevel = obj["accuracyLevel"].toInt();
|
||||
setAccuracyLevel(accuracyLevel);
|
||||
}
|
||||
}
|
||||
|
||||
void ImageProcessor::setSize(unsigned width, unsigned height)
|
||||
void ImageProcessor::setSize(int width, int height)
|
||||
{
|
||||
// Check if the existing buffer-image is already the correct dimensions
|
||||
if (_imageToLeds && _imageToLeds->width() == width && _imageToLeds->height() == height)
|
||||
if (!_imageToLedColors.isNull() && _imageToLedColors->width() == width && _imageToLedColors->height() == height)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Clean up the old buffer and mapping
|
||||
delete _imageToLeds;
|
||||
|
||||
// Construct a new buffer and mapping
|
||||
_imageToLeds = (width>0 && height>0) ? (new ImageToLedsMap(width, height, 0, 0, _ledString.leds())) : nullptr;
|
||||
registerProcessingUnit(width, height, 0, 0);
|
||||
}
|
||||
|
||||
void ImageProcessor::setLedString(const LedString& ledString)
|
||||
{
|
||||
if ( _imageToLeds != nullptr)
|
||||
Debug(_log,"");
|
||||
if ( !_imageToLedColors.isNull() )
|
||||
{
|
||||
_ledString = ledString;
|
||||
|
||||
// get current width/height
|
||||
unsigned width = _imageToLeds->width();
|
||||
unsigned height = _imageToLeds->height();
|
||||
|
||||
// Clean up the old buffer and mapping
|
||||
delete _imageToLeds;
|
||||
int width = _imageToLedColors->width();
|
||||
int height = _imageToLedColors->height();
|
||||
|
||||
// Construct a new buffer and mapping
|
||||
_imageToLeds = new ImageToLedsMap(width, height, 0, 0, _ledString.leds());
|
||||
registerProcessingUnit(width, height, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,15 +167,55 @@ bool ImageProcessor::blackBorderDetectorEnabled() const
|
||||
return _borderProcessor->enabled();
|
||||
}
|
||||
|
||||
void ImageProcessor::setReducedPixelSetFactorFactor(int count)
|
||||
{
|
||||
int currentReducedPixelSetFactor= _reducedPixelSetFactorFactor;
|
||||
|
||||
_reducedPixelSetFactorFactor = count;
|
||||
Debug(_log, "Set reduced pixel set factor to %d", _reducedPixelSetFactorFactor);
|
||||
|
||||
if (currentReducedPixelSetFactor != _reducedPixelSetFactorFactor && !_imageToLedColors.isNull())
|
||||
{
|
||||
int width = _imageToLedColors->width();
|
||||
int height = _imageToLedColors->height();
|
||||
|
||||
// Construct a new buffer and mapping
|
||||
registerProcessingUnit(width, height, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void ImageProcessor::setAccuracyLevel(int level)
|
||||
{
|
||||
_accuraryLevel = level;
|
||||
Debug(_log, "Set processing accuracy level to %d", _accuraryLevel);
|
||||
|
||||
if (!_imageToLedColors.isNull())
|
||||
{
|
||||
_imageToLedColors->setAccuracyLevel(_accuraryLevel);
|
||||
}
|
||||
}
|
||||
|
||||
void ImageProcessor::setLedMappingType(int mapType)
|
||||
{
|
||||
int currentMappingType = _mappingType;
|
||||
|
||||
// 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)));
|
||||
|
||||
Debug(_log, "Set user LED mapping to %s", QSTRING_CSTR(mappingTypeToStr(mapType)));
|
||||
|
||||
if(_hardMappingType == -1)
|
||||
{
|
||||
_mappingType = mapType;
|
||||
}
|
||||
|
||||
if (currentMappingType != _mappingType && !_imageToLedColors.isNull())
|
||||
{
|
||||
int width = _imageToLedColors->width();
|
||||
int height = _imageToLedColors->height();
|
||||
|
||||
registerProcessingUnit(width, height, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void ImageProcessor::setHardLedMappingType(int mapType)
|
||||
|
||||
@@ -3,17 +3,28 @@
|
||||
using namespace hyperion;
|
||||
|
||||
ImageToLedsMap::ImageToLedsMap(
|
||||
Logger* log,
|
||||
int mappingType,
|
||||
int width,
|
||||
int height,
|
||||
int horizontalBorder,
|
||||
int verticalBorder,
|
||||
const std::vector<Led>& leds)
|
||||
: _width(width)
|
||||
const std::vector<Led>& leds,
|
||||
int reducedPixelSetFactor,
|
||||
int accuracyLevel)
|
||||
: _log(log)
|
||||
, _mappingType(mappingType)
|
||||
, _width(width)
|
||||
, _height(height)
|
||||
, _horizontalBorder(horizontalBorder)
|
||||
, _verticalBorder(verticalBorder)
|
||||
, _nextPixelCount(reducedPixelSetFactor)
|
||||
, _clusterCount()
|
||||
, _colorsMap()
|
||||
{
|
||||
_nextPixelCount = reducedPixelSetFactor + 1;
|
||||
setAccuracyLevel(accuracyLevel);
|
||||
|
||||
// Sanity check of the size of the borders (and width and height)
|
||||
Q_ASSERT(_width > 2*_verticalBorder);
|
||||
Q_ASSERT(_height > 2*_horizontalBorder);
|
||||
@@ -30,6 +41,7 @@ ImageToLedsMap::ImageToLedsMap(
|
||||
|
||||
size_t totalCount = 0;
|
||||
size_t totalCapacity = 0;
|
||||
int ledCounter = 0;
|
||||
|
||||
for (const Led& led : leds)
|
||||
{
|
||||
@@ -65,14 +77,27 @@ ImageToLedsMap::ImageToLedsMap(
|
||||
const int realYLedCount = qAbs(maxYLedCount - minY_idx);
|
||||
const int realXLedCount = qAbs(maxXLedCount - minX_idx);
|
||||
|
||||
size_t totalSize = realYLedCount* realXLedCount;
|
||||
bool skipPixelProcessing {false};
|
||||
if (_nextPixelCount > 1)
|
||||
{
|
||||
skipPixelProcessing = true;
|
||||
}
|
||||
|
||||
size_t totalSize = static_cast<size_t>(realYLedCount * realXLedCount);
|
||||
|
||||
if (!skipPixelProcessing && totalSize > 1600)
|
||||
{
|
||||
skipPixelProcessing = true;
|
||||
_nextPixelCount = 2;
|
||||
Warning(_log, "Mapping LED/light [%d]. The current mapping area contains %d pixels which is huge. Therefore every %d pixels will be skipped. You can enable reduced processing to hide that warning.", ledCounter, totalSize, _nextPixelCount);
|
||||
}
|
||||
|
||||
std::vector<int> ledColors;
|
||||
ledColors.reserve(totalSize);
|
||||
|
||||
for (int y = minY_idx; y < maxYLedCount; ++y)
|
||||
for (int y = minY_idx; y < maxYLedCount; y += _nextPixelCount)
|
||||
{
|
||||
for (int x = minX_idx; x < maxXLedCount; ++x)
|
||||
for (int x = minX_idx; x < maxXLedCount; x += _nextPixelCount)
|
||||
{
|
||||
ledColors.push_back( y * width + x);
|
||||
}
|
||||
@@ -84,9 +109,10 @@ ImageToLedsMap::ImageToLedsMap(
|
||||
totalCount += ledColors.size();
|
||||
totalCapacity += ledColors.capacity();
|
||||
|
||||
ledCounter++;
|
||||
}
|
||||
Debug(Logger::getInstance("HYPERION"), "Total index number is: %d (memory: %d). image size: %d x %d, LED areas: %d",
|
||||
totalCount, totalCapacity, width, height, leds.size());
|
||||
Debug(_log, "Total index number is: %d (memory: %d). Reduced pixel set factor: %d, Accuracy level: %d, Image size: %d x %d, LED areas: %d",
|
||||
totalCount, totalCapacity, reducedPixelSetFactor, accuracyLevel, width, height, leds.size());
|
||||
|
||||
}
|
||||
|
||||
@@ -99,3 +125,16 @@ int ImageToLedsMap::height() const
|
||||
{
|
||||
return _height;
|
||||
}
|
||||
|
||||
void ImageToLedsMap::setAccuracyLevel (int accuracyLevel)
|
||||
{
|
||||
if (accuracyLevel > 4 )
|
||||
{
|
||||
Warning(_log, "Accuracy level %d is too high, it will be set to 4", accuracyLevel);
|
||||
accuracyLevel = 4;
|
||||
}
|
||||
//Set cluster number for dominant color advanced
|
||||
_clusterCount = accuracyLevel + 1;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -16,13 +16,37 @@
|
||||
},
|
||||
"propertyOrder" : 1
|
||||
},
|
||||
"accuracyLevel": {
|
||||
"type": "integer",
|
||||
"title": "edt_conf_color_accuracyLevel_title",
|
||||
"minimum": 1,
|
||||
"maximum": 4,
|
||||
"default": 2,
|
||||
"propertyOrder": 2,
|
||||
"options": {
|
||||
"dependencies": {
|
||||
"imageToLedMappingType": "dominant_color_advanced"
|
||||
}
|
||||
}
|
||||
},
|
||||
"reducedPixelSetFactorFactor": {
|
||||
"type": "string",
|
||||
"title": "edt_conf_color_reducedPixelSetFactorFactor_title",
|
||||
"default": 0,
|
||||
"enum" : ["0", "1", "2", "3"],
|
||||
"default" : "0",
|
||||
"options" : {
|
||||
"enum_titles" : ["edt_conf_enum_disabled", "edt_conf_enum_low", "edt_conf_enum_medium", "edt_conf_enum_high"]
|
||||
},
|
||||
"propertyOrder": 3
|
||||
},
|
||||
"channelAdjustment" :
|
||||
{
|
||||
"type" : "array",
|
||||
"title" : "edt_conf_color_channelAdjustment_header_title",
|
||||
"minItems": 1,
|
||||
"required" : true,
|
||||
"propertyOrder" : 3,
|
||||
"propertyOrder" : 4,
|
||||
"items" :
|
||||
{
|
||||
"type" : "object",
|
||||
|
||||
Reference in New Issue
Block a user