2013-08-13 11:10:45 +02:00
|
|
|
#pragma once
|
|
|
|
|
2016-12-19 23:59:50 +01:00
|
|
|
#include <QString>
|
|
|
|
|
2013-08-13 11:10:45 +02:00
|
|
|
// Utils includes
|
2013-11-11 10:00:37 +01:00
|
|
|
#include <utils/Image.h>
|
2013-08-13 11:10:45 +02:00
|
|
|
|
2013-08-23 07:09:09 +02:00
|
|
|
// Hyperion includes
|
|
|
|
#include <hyperion/LedString.h>
|
2013-11-11 10:00:37 +01:00
|
|
|
#include <hyperion/ImageToLedsMap.h>
|
2016-07-12 15:13:06 +02:00
|
|
|
#include <utils/Logger.h>
|
2014-01-26 14:23:08 +01:00
|
|
|
|
2018-12-27 23:11:32 +01:00
|
|
|
// settings
|
|
|
|
#include <utils/settings.h>
|
|
|
|
|
2014-01-26 14:23:08 +01:00
|
|
|
// Black border includes
|
|
|
|
#include <blackborder/BlackBorderProcessor.h>
|
2013-08-13 11:10:45 +02:00
|
|
|
|
2018-12-27 23:11:32 +01:00
|
|
|
class Hyperion;
|
|
|
|
|
2013-09-06 21:26:58 +02:00
|
|
|
///
|
|
|
|
/// The ImageProcessor translates an RGB-image to RGB-values for the leds. The processing is
|
|
|
|
/// performed in two steps. First the average color per led-region is computed. Second a
|
|
|
|
/// color-tranform is applied based on a gamma-correction.
|
|
|
|
///
|
2017-10-12 11:55:03 +02:00
|
|
|
class ImageProcessor : public QObject
|
2013-08-13 11:10:45 +02:00
|
|
|
{
|
2016-12-19 23:59:50 +01:00
|
|
|
Q_OBJECT
|
|
|
|
|
2013-08-13 11:10:45 +02:00
|
|
|
public:
|
2013-11-28 14:38:07 +01:00
|
|
|
///
|
2018-12-27 23:11:32 +01:00
|
|
|
/// Constructs an image-processor for translating an image to led-color values based on the
|
|
|
|
/// given led-string specification
|
|
|
|
/// @param[in] ledString LedString data
|
|
|
|
/// @param[in] hyperion Hyperion instance pointer
|
2013-11-28 14:38:07 +01:00
|
|
|
///
|
2018-12-27 23:11:32 +01:00
|
|
|
ImageProcessor(const LedString& ledString, Hyperion* hyperion);
|
|
|
|
|
|
|
|
~ImageProcessor();
|
2013-11-28 14:38:07 +01:00
|
|
|
|
2013-09-06 21:26:58 +02:00
|
|
|
///
|
|
|
|
/// Specifies the width and height of 'incomming' images. This will resize the buffer-image to
|
|
|
|
/// match the given size.
|
|
|
|
/// NB All earlier obtained references will be invalid.
|
|
|
|
///
|
|
|
|
/// @param[in] width The new width of the buffer-image
|
|
|
|
/// @param[in] height The new height of the buffer-image
|
|
|
|
///
|
2020-08-08 13:09:15 +02:00
|
|
|
void setSize(unsigned width, unsigned height);
|
2013-08-13 11:10:45 +02:00
|
|
|
|
2018-12-27 23:11:32 +01:00
|
|
|
///
|
|
|
|
/// @brief Update the led string (eg on settings change)
|
|
|
|
///
|
|
|
|
void setLedString(const LedString& ledString);
|
|
|
|
|
2016-08-11 07:13:55 +02:00
|
|
|
/// Returns starte of black border detector
|
|
|
|
bool blackBorderDetectorEnabled();
|
2017-10-12 11:55:03 +02:00
|
|
|
|
2018-12-27 23:11:32 +01:00
|
|
|
/// Returns the current _userMappingType, this may not be the current applied type!
|
2020-08-08 13:09:15 +02:00
|
|
|
int getUserLedMappingType() { return _userMappingType; };
|
2018-12-27 23:11:32 +01:00
|
|
|
|
|
|
|
/// Returns the current _mappingType
|
2020-08-08 13:09:15 +02:00
|
|
|
int ledMappingType() { return _mappingType; };
|
2016-12-19 23:59:50 +01:00
|
|
|
|
|
|
|
static int mappingTypeToInt(QString mappingType);
|
2016-12-20 19:55:54 +01:00
|
|
|
static QString mappingTypeToStr(int mappingType);
|
2016-12-19 23:59:50 +01:00
|
|
|
|
2018-12-27 23:11:32 +01:00
|
|
|
///
|
|
|
|
/// @brief Set the Hyperion::update() requestes led mapping type. This type is used in favour of type set with setLedMappingType.
|
|
|
|
/// If you don't want to force a mapType set this to -1 (user choice will be set)
|
|
|
|
/// @param mapType The new mapping type
|
|
|
|
///
|
|
|
|
void setHardLedMappingType(int mapType);
|
|
|
|
|
2016-12-19 23:59:50 +01:00
|
|
|
public slots:
|
2018-12-27 23:11:32 +01:00
|
|
|
/// Enable or disable the black border detector based on component
|
|
|
|
void setBlackbarDetectDisable(bool enable);
|
2016-12-19 23:59:50 +01:00
|
|
|
|
2018-12-27 23:11:32 +01:00
|
|
|
///
|
|
|
|
/// @brief Set the user requested led mapping.
|
|
|
|
/// The type set with setHardLedMappingType() will be used in favour to respect comp specific settings
|
|
|
|
/// @param mapType The new mapping type
|
|
|
|
///
|
2016-12-19 23:59:50 +01:00
|
|
|
void setLedMappingType(int mapType);
|
|
|
|
|
2017-08-12 07:55:32 +02:00
|
|
|
public:
|
|
|
|
///
|
|
|
|
/// Specifies the width and height of 'incomming' images. This will resize the buffer-image to
|
|
|
|
/// match the given size.
|
|
|
|
/// NB All earlier obtained references will be invalid.
|
|
|
|
///
|
|
|
|
/// @param[in] image The dimensions taken from image
|
|
|
|
///
|
|
|
|
template <typename Pixel_T>
|
|
|
|
void setSize(const Image<Pixel_T> &image)
|
|
|
|
{
|
|
|
|
setSize(image.width(), image.height());
|
|
|
|
}
|
|
|
|
|
2013-09-06 21:26:58 +02:00
|
|
|
///
|
|
|
|
/// Processes the image to a list of led colors. This will update the size of the buffer-image
|
|
|
|
/// if required and call the image-to-leds mapping to determine the mean color per led.
|
|
|
|
///
|
|
|
|
/// @param[in] image The image to translate to led values
|
|
|
|
///
|
|
|
|
/// @return The color value per led
|
|
|
|
///
|
2013-11-11 10:00:37 +01:00
|
|
|
template <typename Pixel_T>
|
|
|
|
std::vector<ColorRgb> process(const Image<Pixel_T>& image)
|
|
|
|
{
|
2016-12-19 23:59:50 +01:00
|
|
|
std::vector<ColorRgb> colors;
|
2017-08-12 07:55:32 +02:00
|
|
|
if (image.width()>0 && image.height()>0)
|
|
|
|
{
|
|
|
|
// Ensure that the buffer-image is the proper size
|
|
|
|
setSize(image);
|
|
|
|
|
|
|
|
// Check black border detection
|
|
|
|
verifyBorder(image);
|
|
|
|
|
|
|
|
// Create a result vector and call the 'in place' functionl
|
|
|
|
switch (_mappingType)
|
|
|
|
{
|
|
|
|
case 1: colors = _imageToLeds->getUniLedColor(image); break;
|
|
|
|
default: colors = _imageToLeds->getMeanLedColor(image);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2016-12-19 23:59:50 +01:00
|
|
|
{
|
2018-12-27 23:11:32 +01:00
|
|
|
Warning(_log, "ImageProcessor::process called with image size 0");
|
2016-12-19 23:59:50 +01:00
|
|
|
}
|
2013-11-11 10:00:37 +01:00
|
|
|
|
|
|
|
// return the computed colors
|
|
|
|
return colors;
|
|
|
|
}
|
2013-08-13 11:10:45 +02:00
|
|
|
|
2013-09-06 21:26:58 +02:00
|
|
|
///
|
|
|
|
/// Determines the led colors of the image in the buffer.
|
|
|
|
///
|
2013-09-09 22:35:28 +02:00
|
|
|
/// @param[in] image The image to translate to led values
|
2013-09-06 21:26:58 +02:00
|
|
|
/// @param[out] ledColors The color value per led
|
|
|
|
///
|
2013-11-11 10:00:37 +01:00
|
|
|
template <typename Pixel_T>
|
|
|
|
void process(const Image<Pixel_T>& image, std::vector<ColorRgb>& ledColors)
|
|
|
|
{
|
2017-08-12 07:55:32 +02:00
|
|
|
if ( image.width()>0 && image.height()>0)
|
2016-12-19 23:59:50 +01:00
|
|
|
{
|
2017-08-12 07:55:32 +02:00
|
|
|
// Ensure that the buffer-image is the proper size
|
|
|
|
setSize(image);
|
|
|
|
|
|
|
|
// Check black border detection
|
|
|
|
verifyBorder(image);
|
|
|
|
|
2019-07-02 19:06:36 +02:00
|
|
|
// Determine the mean or uni colors of each led (using the existing mapping)
|
2017-08-12 07:55:32 +02:00
|
|
|
switch (_mappingType)
|
|
|
|
{
|
|
|
|
case 1: _imageToLeds->getUniLedColor(image, ledColors); break;
|
|
|
|
default: _imageToLeds->getMeanLedColor(image, ledColors);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-27 23:11:32 +01:00
|
|
|
Warning(_log, "Called with image size 0");
|
2016-12-19 23:59:50 +01:00
|
|
|
}
|
2013-11-11 10:00:37 +01:00
|
|
|
}
|
2013-08-13 11:10:45 +02:00
|
|
|
|
2013-11-08 22:18:10 +01:00
|
|
|
///
|
|
|
|
/// Get the hscan and vscan parameters for a single led
|
|
|
|
///
|
|
|
|
/// @param[in] led Index of the led
|
|
|
|
/// @param[out] hscanBegin begin of the hscan
|
|
|
|
/// @param[out] hscanEnd end of the hscan
|
|
|
|
/// @param[out] vscanBegin begin of the hscan
|
|
|
|
/// @param[out] vscanEnd end of the hscan
|
|
|
|
/// @return true if the parameters could be retrieved
|
|
|
|
bool getScanParameters(size_t led, double & hscanBegin, double & hscanEnd, double & vscanBegin, double & vscanEnd) const;
|
|
|
|
|
2013-08-13 11:10:45 +02:00
|
|
|
private:
|
2013-09-06 21:26:58 +02:00
|
|
|
///
|
|
|
|
/// Performs black-border detection (if enabled) on the given image
|
|
|
|
///
|
|
|
|
/// @param[in] image The image to perform black-border detection on
|
|
|
|
///
|
2013-11-11 10:00:37 +01:00
|
|
|
template <typename Pixel_T>
|
|
|
|
void verifyBorder(const Image<Pixel_T> & image)
|
|
|
|
{
|
2016-09-08 16:32:42 +02:00
|
|
|
if (!_borderProcessor->enabled() && ( _imageToLeds->horizontalBorder()!=0 || _imageToLeds->verticalBorder()!=0 ))
|
|
|
|
{
|
2018-12-27 23:11:32 +01:00
|
|
|
Debug(_log, "Reset border");
|
2016-09-08 16:32:42 +02:00
|
|
|
_borderProcessor->process(image);
|
|
|
|
delete _imageToLeds;
|
|
|
|
_imageToLeds = new hyperion::ImageToLedsMap(image.width(), image.height(), 0, 0, _ledString.leds());
|
|
|
|
}
|
2017-10-12 11:55:03 +02:00
|
|
|
|
2016-07-15 10:28:12 +02:00
|
|
|
if(_borderProcessor->enabled() && _borderProcessor->process(image))
|
2013-11-11 10:00:37 +01:00
|
|
|
{
|
|
|
|
const hyperion::BlackBorder border = _borderProcessor->getCurrentBorder();
|
|
|
|
|
|
|
|
// Clean up the old mapping
|
2014-01-20 20:46:38 +01:00
|
|
|
delete _imageToLeds;
|
2013-11-11 10:00:37 +01:00
|
|
|
|
|
|
|
if (border.unknown)
|
|
|
|
{
|
|
|
|
// Construct a new buffer and mapping
|
2014-01-20 20:46:38 +01:00
|
|
|
_imageToLeds = new hyperion::ImageToLedsMap(image.width(), image.height(), 0, 0, _ledString.leds());
|
2013-11-11 10:00:37 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Construct a new buffer and mapping
|
2014-01-20 20:46:38 +01:00
|
|
|
_imageToLeds = new hyperion::ImageToLedsMap(image.width(), image.height(), border.horizontalSize, border.verticalSize, _ledString.leds());
|
2013-11-11 10:00:37 +01:00
|
|
|
}
|
|
|
|
|
2017-10-12 11:55:03 +02:00
|
|
|
//Debug(Logger::getInstance("BLACKBORDER"), "CURRENT BORDER TYPE: unknown=%d hor.size=%d vert.size=%d",
|
|
|
|
// border.unknown, border.horizontalSize, border.verticalSize );
|
2013-11-11 10:00:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-27 23:11:32 +01:00
|
|
|
private slots:
|
2020-08-08 13:09:15 +02:00
|
|
|
void handleSettingsUpdate(settings::type type, const QJsonDocument& config);
|
2018-12-27 23:11:32 +01:00
|
|
|
|
2013-08-13 11:10:45 +02:00
|
|
|
private:
|
2016-12-19 23:59:50 +01:00
|
|
|
Logger * _log;
|
2013-09-06 21:26:58 +02:00
|
|
|
/// The Led-string specification
|
2018-12-27 23:11:32 +01:00
|
|
|
LedString _ledString;
|
2013-08-13 11:10:45 +02:00
|
|
|
|
2013-08-23 07:09:09 +02:00
|
|
|
/// The processor for black border detection
|
2013-11-11 10:00:37 +01:00
|
|
|
hyperion::BlackBorderProcessor * _borderProcessor;
|
2013-08-23 07:09:09 +02:00
|
|
|
|
2013-09-06 21:26:58 +02:00
|
|
|
/// The mapping of image-pixels to leds
|
2014-01-20 20:46:38 +01:00
|
|
|
hyperion::ImageToLedsMap* _imageToLeds;
|
2016-12-19 23:59:50 +01:00
|
|
|
|
|
|
|
/// Type of image 2 led mapping
|
|
|
|
int _mappingType;
|
2018-12-27 23:11:32 +01:00
|
|
|
/// Type of last requested user type
|
|
|
|
int _userMappingType;
|
|
|
|
/// Type of last requested hard type
|
|
|
|
int _hardMappingType;
|
|
|
|
|
|
|
|
/// Hyperion instance pointer
|
|
|
|
Hyperion* _hyperion;
|
2013-08-13 11:10:45 +02:00
|
|
|
};
|