mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
implement optional color correction for V4L only (#267)
* remove color temperatire, its the same as color adjustment * remove temperature from schema * implement most part of v4l only colro settings, now hyperion update knows from which component the colors come * update configs * fix webui config write * reomve correction and temperature from hyperion-remote
This commit is contained in:
@@ -20,7 +20,6 @@
|
||||
#include <hyperion/Hyperion.h>
|
||||
#include <hyperion/ImageProcessorFactory.h>
|
||||
#include <hyperion/ColorTransform.h>
|
||||
#include <hyperion/ColorCorrection.h>
|
||||
#include <hyperion/ColorAdjustment.h>
|
||||
|
||||
// Leddevice includes
|
||||
@@ -28,7 +27,6 @@
|
||||
#include <leddevice/LedDeviceFactory.h>
|
||||
|
||||
#include "MultiColorTransform.h"
|
||||
#include "MultiColorCorrection.h"
|
||||
#include "MultiColorAdjustment.h"
|
||||
#include "LinearColorSmoothing.h"
|
||||
|
||||
@@ -90,23 +88,6 @@ ColorTransform * Hyperion::createColorTransform(const QJsonObject & transformCon
|
||||
}
|
||||
|
||||
|
||||
ColorCorrection * Hyperion::createColorCorrection(const QJsonObject & correctionConfig)
|
||||
{
|
||||
const std::string id = correctionConfig["id"].toString("default").toStdString();
|
||||
|
||||
RgbChannelAdjustment * rgbCorrection = createRgbChannelCorrection(correctionConfig["correctionValues"].toObject());
|
||||
|
||||
ColorCorrection * correction = new ColorCorrection();
|
||||
correction->_id = id;
|
||||
correction->_rgbCorrection = *rgbCorrection;
|
||||
|
||||
// Cleanup the allocated individual transforms
|
||||
delete rgbCorrection;
|
||||
|
||||
return correction;
|
||||
}
|
||||
|
||||
|
||||
ColorAdjustment * Hyperion::createColorAdjustment(const QJsonObject & adjustmentConfig)
|
||||
{
|
||||
const std::string id = adjustmentConfig["id"].toString("default").toStdString();
|
||||
@@ -205,83 +186,6 @@ MultiColorTransform * Hyperion::createLedColorsTransform(const unsigned ledCnt,
|
||||
return transform;
|
||||
}
|
||||
|
||||
MultiColorCorrection * Hyperion::createLedColorsTemperature(const unsigned ledCnt, const QJsonObject & colorConfig)
|
||||
{
|
||||
// Create the result, the corrections are added to this
|
||||
MultiColorCorrection * correction = new MultiColorCorrection(ledCnt);
|
||||
Logger * log = Logger::getInstance("Core");
|
||||
|
||||
const QString jsonKey = colorConfig.contains("temperature") ? "temperature" : "correction";
|
||||
const QJsonValue correctionConfig = colorConfig[jsonKey];
|
||||
if (correctionConfig.isNull())
|
||||
{
|
||||
// Old style color correction config (just one for all leds)
|
||||
ColorCorrection * colorCorrection = createColorCorrection(colorConfig);
|
||||
correction->addCorrection(colorCorrection);
|
||||
correction->setCorrectionForLed(colorCorrection->_id, 0, ledCnt-1);
|
||||
}
|
||||
else if (correctionConfig.isObject())
|
||||
{
|
||||
ColorCorrection * colorCorrection = createColorCorrection(correctionConfig.toObject());
|
||||
correction->addCorrection(colorCorrection);
|
||||
correction->setCorrectionForLed(colorCorrection->_id, 0, ledCnt-1);
|
||||
}
|
||||
else if (correctionConfig.isArray())
|
||||
{
|
||||
const QRegExp overallExp("([0-9]+(\\-[0-9]+)?)(,[ ]*([0-9]+(\\-[0-9]+)?))*");
|
||||
|
||||
const QJsonArray & correctionConfigArray = correctionConfig.toArray();
|
||||
for (signed i = 0; i < correctionConfigArray.size(); ++i)
|
||||
{
|
||||
const QJsonObject & config = correctionConfigArray.at(i).toObject();
|
||||
ColorCorrection * colorCorrection = createColorCorrection(config);
|
||||
correction->addCorrection(colorCorrection);
|
||||
|
||||
const QString ledIndicesStr = config["leds"].toString("").trimmed();
|
||||
if (ledIndicesStr.compare("*") == 0)
|
||||
{
|
||||
// Special case for indices '*' => all leds
|
||||
correction->setCorrectionForLed(colorCorrection->_id, 0, ledCnt-1);
|
||||
Info(log, "ColorTemperature '%s' => [0; %d]", colorCorrection->_id.c_str(), ledCnt-1);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!overallExp.exactMatch(ledIndicesStr))
|
||||
{
|
||||
Error(log, "Given led indices %d not correct format: %s", i, ledIndicesStr.toStdString().c_str());
|
||||
continue;
|
||||
}
|
||||
|
||||
std::stringstream ss;
|
||||
const QStringList ledIndexList = ledIndicesStr.split(",");
|
||||
for (int i=0; i<ledIndexList.size(); ++i) {
|
||||
if (i > 0)
|
||||
{
|
||||
ss << ", ";
|
||||
}
|
||||
if (ledIndexList[i].contains("-"))
|
||||
{
|
||||
QStringList ledIndices = ledIndexList[i].split("-");
|
||||
int startInd = ledIndices[0].toInt();
|
||||
int endInd = ledIndices[1].toInt();
|
||||
|
||||
correction->setCorrectionForLed(colorCorrection->_id, startInd, endInd);
|
||||
ss << startInd << "-" << endInd;
|
||||
}
|
||||
else
|
||||
{
|
||||
int index = ledIndexList[i].toInt();
|
||||
correction->setCorrectionForLed(colorCorrection->_id, index, index);
|
||||
ss << index;
|
||||
}
|
||||
}
|
||||
Info(log, "ColorTemperature '%s' => [%s]", colorCorrection->_id.c_str(), ss.str().c_str());
|
||||
}
|
||||
}
|
||||
return correction;
|
||||
}
|
||||
|
||||
|
||||
MultiColorAdjustment * Hyperion::createLedColorsAdjustment(const unsigned ledCnt, const QJsonObject & colorConfig)
|
||||
{
|
||||
// Create the result, the transforms are added to this
|
||||
@@ -385,16 +289,6 @@ RgbChannelTransform* Hyperion::createRgbChannelTransform(const QJsonObject& colo
|
||||
return transform;
|
||||
}
|
||||
|
||||
RgbChannelAdjustment* Hyperion::createRgbChannelCorrection(const QJsonObject& colorConfig)
|
||||
{
|
||||
const int varR = colorConfig["red"].toInt(255);
|
||||
const int varG = colorConfig["green"].toInt(255);
|
||||
const int varB = colorConfig["blue"].toInt(255);
|
||||
|
||||
RgbChannelAdjustment* correction = new RgbChannelAdjustment(varR, varG, varB);
|
||||
return correction;
|
||||
}
|
||||
|
||||
RgbChannelAdjustment* Hyperion::createRgbChannelAdjustment(const QJsonObject& colorConfig, const RgbChannel color)
|
||||
{
|
||||
int varR=0, varG=0, varB=0;
|
||||
@@ -628,7 +522,6 @@ Hyperion::Hyperion(const Json::Value &jsonConfig, const QJsonObject &qjsonConfig
|
||||
, _ledStringClone(createLedStringClone(qjsonConfig["leds"], createColorOrder(qjsonConfig["device"].toObject())))
|
||||
, _muxer(_ledString.leds().size())
|
||||
, _raw2ledTransform(createLedColorsTransform(_ledString.leds().size(), qjsonConfig["color"].toObject()))
|
||||
, _raw2ledTemperature(createLedColorsTemperature(_ledString.leds().size(), qjsonConfig["color"].toObject()))
|
||||
, _raw2ledAdjustment(createLedColorsAdjustment(_ledString.leds().size(), qjsonConfig["color"].toObject()))
|
||||
, _effectEngine(nullptr)
|
||||
, _messageForwarder(createMessageForwarder(qjsonConfig["forwarder"].toObject()))
|
||||
@@ -638,6 +531,8 @@ Hyperion::Hyperion(const Json::Value &jsonConfig, const QJsonObject &qjsonConfig
|
||||
, _timer()
|
||||
, _log(Logger::getInstance("Core"))
|
||||
, _hwLedCount(_ledString.leds().size())
|
||||
, _colorAdjustmentV4Lonly(false)
|
||||
, _colorTransformV4Lonly(false)
|
||||
, _sourceAutoSelectEnabled(true)
|
||||
, _configHash()
|
||||
, _ledGridSize(getLedLayoutGridSize(qjsonConfig["leds"]))
|
||||
@@ -648,10 +543,6 @@ Hyperion::Hyperion(const Json::Value &jsonConfig, const QJsonObject &qjsonConfig
|
||||
{
|
||||
throw std::runtime_error("Color adjustment incorrectly set");
|
||||
}
|
||||
if (!_raw2ledTemperature->verifyCorrections())
|
||||
{
|
||||
throw std::runtime_error("Color temperature incorrectly set");
|
||||
}
|
||||
if (!_raw2ledTransform->verifyTransforms())
|
||||
{
|
||||
throw std::runtime_error("Color transformation incorrectly set");
|
||||
@@ -660,11 +551,15 @@ Hyperion::Hyperion(const Json::Value &jsonConfig, const QJsonObject &qjsonConfig
|
||||
const QJsonObject& color = qjsonConfig["color"].toObject();
|
||||
_transformEnabled = color["transform_enable"].toBool(true);
|
||||
_adjustmentEnabled = color["channelAdjustment_enable"].toBool(true);
|
||||
_temperatureEnabled = color["temperature_enable"].toBool(true);
|
||||
|
||||
_colorTransformV4Lonly = color["transform_v4l_only"].toBool(false);
|
||||
_colorAdjustmentV4Lonly = color["channelAdjustment_v4l_only"].toBool(false);
|
||||
|
||||
InfoIf(!_transformEnabled , _log, "Color transformation disabled" );
|
||||
InfoIf(!_adjustmentEnabled , _log, "Color adjustment disabled" );
|
||||
InfoIf(!_temperatureEnabled, _log, "Color temperature disabled" );
|
||||
|
||||
InfoIf(_colorTransformV4Lonly , _log, "Color transformation for v4l inputs only" );
|
||||
InfoIf(_colorAdjustmentV4Lonly , _log, "Color adjustment for v4l inputs only" );
|
||||
|
||||
// initialize the image processor factory
|
||||
ImageProcessorFactory::getInstance().init(
|
||||
@@ -709,7 +604,6 @@ Hyperion::~Hyperion()
|
||||
delete _effectEngine;
|
||||
delete _device;
|
||||
delete _raw2ledTransform;
|
||||
delete _raw2ledTemperature;
|
||||
delete _raw2ledAdjustment;
|
||||
delete _messageForwarder;
|
||||
}
|
||||
@@ -807,10 +701,10 @@ void Hyperion::setColor(int priority, const ColorRgb &color, const int timeout_m
|
||||
std::vector<ColorRgb> ledColors(_ledString.leds().size(), color);
|
||||
|
||||
// set colors
|
||||
setColors(priority, ledColors, timeout_ms, clearEffects);
|
||||
setColors(priority, ledColors, timeout_ms, clearEffects, hyperion::COMP_COLOR);
|
||||
}
|
||||
|
||||
void Hyperion::setColors(int priority, const std::vector<ColorRgb>& ledColors, const int timeout_ms, bool clearEffects)
|
||||
void Hyperion::setColors(int priority, const std::vector<ColorRgb>& ledColors, const int timeout_ms, bool clearEffects, hyperion::Components component)
|
||||
{
|
||||
// clear effects if this call does not come from an effect
|
||||
if (clearEffects)
|
||||
@@ -821,11 +715,11 @@ void Hyperion::setColors(int priority, const std::vector<ColorRgb>& ledColors, c
|
||||
if (timeout_ms > 0)
|
||||
{
|
||||
const uint64_t timeoutTime = QDateTime::currentMSecsSinceEpoch() + timeout_ms;
|
||||
_muxer.setInput(priority, ledColors, timeoutTime);
|
||||
_muxer.setInput(priority, ledColors, timeoutTime, component);
|
||||
}
|
||||
else
|
||||
{
|
||||
_muxer.setInput(priority, ledColors);
|
||||
_muxer.setInput(priority, ledColors, -1, component);
|
||||
}
|
||||
|
||||
if (! _sourceAutoSelectEnabled || priority == _muxer.getCurrentPriority())
|
||||
@@ -839,11 +733,6 @@ const std::vector<std::string> & Hyperion::getTransformIds() const
|
||||
return _raw2ledTransform->getTransformIds();
|
||||
}
|
||||
|
||||
const std::vector<std::string> & Hyperion::getTemperatureIds() const
|
||||
{
|
||||
return _raw2ledTemperature->getCorrectionIds();
|
||||
}
|
||||
|
||||
const std::vector<std::string> & Hyperion::getAdjustmentIds() const
|
||||
{
|
||||
return _raw2ledAdjustment->getAdjustmentIds();
|
||||
@@ -854,11 +743,6 @@ ColorTransform * Hyperion::getTransform(const std::string& id)
|
||||
return _raw2ledTransform->getTransform(id);
|
||||
}
|
||||
|
||||
ColorCorrection * Hyperion::getTemperature(const std::string& id)
|
||||
{
|
||||
return _raw2ledTemperature->getCorrection(id);
|
||||
}
|
||||
|
||||
ColorAdjustment * Hyperion::getAdjustment(const std::string& id)
|
||||
{
|
||||
return _raw2ledAdjustment->getAdjustment(id);
|
||||
@@ -869,16 +753,6 @@ void Hyperion::transformsUpdated()
|
||||
update();
|
||||
}
|
||||
|
||||
void Hyperion::correctionsUpdated()
|
||||
{
|
||||
update();
|
||||
}
|
||||
|
||||
void Hyperion::temperaturesUpdated()
|
||||
{
|
||||
update();
|
||||
}
|
||||
|
||||
void Hyperion::adjustmentsUpdated()
|
||||
{
|
||||
update();
|
||||
@@ -962,11 +836,14 @@ void Hyperion::update()
|
||||
_ledBuffer.reserve(_hwLedCount);
|
||||
_ledBuffer = priorityInfo.ledColors;
|
||||
|
||||
// Apply the correction and the transform to each led and color-channel
|
||||
// Avoid applying correction, the same task is performed by adjustment
|
||||
if (_transformEnabled) _raw2ledTransform->applyTransform(_ledBuffer);
|
||||
if (_adjustmentEnabled) _raw2ledAdjustment->applyAdjustment(_ledBuffer);
|
||||
if (_temperatureEnabled) _raw2ledTemperature->applyCorrection(_ledBuffer);
|
||||
if ( _transformEnabled && (!_colorTransformV4Lonly || priorityInfo.componentId == hyperion::COMP_V4L) )
|
||||
{
|
||||
_raw2ledTransform->applyTransform(_ledBuffer);
|
||||
}
|
||||
if ( _adjustmentEnabled && (!_colorAdjustmentV4Lonly || priorityInfo.componentId == hyperion::COMP_V4L) )
|
||||
{
|
||||
_raw2ledAdjustment->applyAdjustment(_ledBuffer);
|
||||
}
|
||||
|
||||
// init colororder vector, if empty
|
||||
if (_ledStringColorOrder.empty())
|
||||
|
Reference in New Issue
Block a user