mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Add Temperature adjustment
This commit is contained in:
@@ -146,6 +146,13 @@
|
||||
"required" : false,
|
||||
"minimum" : 0.1,
|
||||
"maximum": 10.0
|
||||
},
|
||||
"temperature" :
|
||||
{
|
||||
"type" : "integer",
|
||||
"required" : false,
|
||||
"minimum" : 1000,
|
||||
"maximum": 40000
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
|
@@ -60,6 +60,7 @@
|
||||
#include <HyperionConfig.h>
|
||||
#include <utils/SysInfo.h>
|
||||
#include <utils/ColorSys.h>
|
||||
#include <utils/KelvinToRgb.h>
|
||||
#include <utils/Process.h>
|
||||
#include <utils/JsonUtils.h>
|
||||
|
||||
@@ -519,6 +520,8 @@ void JsonAPI::handleServerInfoCommand(const QJsonObject &message, const QString
|
||||
adjustment["saturationGain"] = colorAdjustment->_okhsvTransform.getSaturationGain();
|
||||
adjustment["brightnessGain"] = colorAdjustment->_okhsvTransform.getBrightnessGain();
|
||||
|
||||
adjustment["temperature"] = 6600;
|
||||
|
||||
adjustmentArray.append(adjustment);
|
||||
}
|
||||
|
||||
@@ -936,6 +939,17 @@ void JsonAPI::handleAdjustmentCommand(const QJsonObject &message, const QString
|
||||
if (adjustment.contains("brightnessGain"))
|
||||
{
|
||||
colorAdjustment->_okhsvTransform.setBrightnessGain(adjustment["brightnessGain"].toDouble());
|
||||
}
|
||||
|
||||
if (adjustment.contains("temperature"))
|
||||
{
|
||||
int temperature = adjustment["temperature"].toInt(6500);
|
||||
ColorRgb rgb = getRgbFromTemperature(temperature);
|
||||
|
||||
ColorCorrection *colorCorrection = _hyperion->getTemperature(adjustmentId);
|
||||
colorCorrection->_rgbCorrection.setcorrectionR(rgb.red);
|
||||
colorCorrection->_rgbCorrection.setcorrectionG(rgb.green);
|
||||
colorCorrection->_rgbCorrection.setcorrectionB(rgb.blue);
|
||||
}
|
||||
|
||||
// commit the changes
|
||||
|
@@ -26,6 +26,7 @@
|
||||
#include <leddevice/LedDeviceWrapper.h>
|
||||
|
||||
#include <hyperion/MultiColorAdjustment.h>
|
||||
#include <hyperion/MultiColorCorrection.h>
|
||||
#include <hyperion/LinearColorSmoothing.h>
|
||||
|
||||
#if defined(ENABLE_EFFECTENGINE)
|
||||
@@ -56,6 +57,7 @@ Hyperion::Hyperion(quint8 instance, bool readonlyMode)
|
||||
, _imageProcessor(nullptr)
|
||||
, _muxer(nullptr)
|
||||
, _raw2ledAdjustment(hyperion::createLedColorsAdjustment(static_cast<int>(_ledString.leds().size()), getSetting(settings::COLOR).object()))
|
||||
, _raw2ledTemperature(hyperion::createLedColorsTemperature(static_cast<int>(_ledString.leds().size()), getSetting(settings::COLOR).object()))
|
||||
, _ledDeviceWrapper(nullptr)
|
||||
, _deviceSmooth(nullptr)
|
||||
#if defined(ENABLE_EFFECTENGINE)
|
||||
@@ -100,6 +102,11 @@ void Hyperion::start()
|
||||
// get newVideoMode from HyperionIManager
|
||||
connect(this, &Hyperion::newVideoMode, this, &Hyperion::handleNewVideoMode);
|
||||
|
||||
if (!_raw2ledTemperature->verifyCorrections())
|
||||
{
|
||||
Warning(_log, "Color temperature incorrectly set");
|
||||
}
|
||||
|
||||
if (!_raw2ledAdjustment->verifyAdjustments())
|
||||
{
|
||||
Warning(_log, "At least one led has no color calibration, please add all leds from your led layout to an 'LED index' field!");
|
||||
@@ -219,6 +226,9 @@ void Hyperion::freeObjects()
|
||||
|
||||
delete _raw2ledAdjustment;
|
||||
|
||||
// delete the color temperature correction
|
||||
delete _raw2ledTemperature;
|
||||
|
||||
#if defined(ENABLE_FORWARDER)
|
||||
delete _messageForwarder;
|
||||
#endif
|
||||
@@ -247,6 +257,15 @@ void Hyperion::handleSettingsUpdate(settings::type type, const QJsonDocument& co
|
||||
{
|
||||
Warning(_log, "At least one led has no color calibration, please add all leds from your led layout to an 'LED index' field!");
|
||||
}
|
||||
|
||||
// change in color recreate ledTemperature
|
||||
delete _raw2ledTemperature;
|
||||
_raw2ledTemperature = hyperion::createLedColorsTemperature(static_cast<int>(_ledString.leds().size()), obj);
|
||||
|
||||
if (!_raw2ledTemperature->verifyCorrections())
|
||||
{
|
||||
Warning(_log, "At least one led has no color calibration, please add all leds from your led layout to an 'LED index' field!");
|
||||
}
|
||||
}
|
||||
else if(type == settings::LEDS)
|
||||
{
|
||||
@@ -279,6 +298,10 @@ void Hyperion::handleSettingsUpdate(settings::type type, const QJsonDocument& co
|
||||
delete _raw2ledAdjustment;
|
||||
_raw2ledAdjustment = hyperion::createLedColorsAdjustment(static_cast<int>(_ledString.leds().size()), getSetting(settings::COLOR).object());
|
||||
|
||||
// change in leds recreate ledTemperature
|
||||
delete _raw2ledTemperature;
|
||||
_raw2ledTemperature = hyperion::createLedColorsTemperature(static_cast<int>(_ledString.leds().size()), getSetting(settings::COLOR).object());
|
||||
|
||||
#if defined(ENABLE_EFFECTENGINE)
|
||||
// start cached effects
|
||||
_effectEngine->startCachedEffects();
|
||||
@@ -494,17 +517,33 @@ QStringList Hyperion::getAdjustmentIds() const
|
||||
return _raw2ledAdjustment->getAdjustmentIds();
|
||||
}
|
||||
|
||||
QStringList Hyperion::getTemperatureIds() const
|
||||
{
|
||||
return _raw2ledTemperature->getCorrectionIds();
|
||||
}
|
||||
|
||||
ColorAdjustment * Hyperion::getAdjustment(const QString& id) const
|
||||
{
|
||||
return _raw2ledAdjustment->getAdjustment(id);
|
||||
}
|
||||
|
||||
ColorCorrection * Hyperion::getTemperature(const QString& id) const
|
||||
{
|
||||
return _raw2ledTemperature->getCorrection(id);
|
||||
}
|
||||
|
||||
void Hyperion::adjustmentsUpdated()
|
||||
{
|
||||
emit adjustmentChanged();
|
||||
update();
|
||||
}
|
||||
|
||||
void Hyperion::temperaturesUpdated()
|
||||
{
|
||||
emit adjustmentChanged();
|
||||
update();
|
||||
}
|
||||
|
||||
bool Hyperion::clear(int priority, bool forceClearAll)
|
||||
{
|
||||
bool isCleared = false;
|
||||
@@ -680,6 +719,7 @@ void Hyperion::update()
|
||||
emit rawLedColors(_ledBuffer);
|
||||
|
||||
_raw2ledAdjustment->applyAdjustment(_ledBuffer);
|
||||
_raw2ledTemperature->applyCorrection(_ledBuffer);
|
||||
|
||||
int i = 0;
|
||||
for (ColorRgb& color : _ledBuffer)
|
||||
|
103
libsrc/hyperion/MultiColorCorrection.cpp
Normal file
103
libsrc/hyperion/MultiColorCorrection.cpp
Normal file
@@ -0,0 +1,103 @@
|
||||
// Hyperion includes
|
||||
#include <utils/Logger.h>
|
||||
#include <hyperion/MultiColorCorrection.h>
|
||||
|
||||
MultiColorCorrection::MultiColorCorrection(int ledCnt) :
|
||||
_ledCorrections(ledCnt, nullptr)
|
||||
, _log(Logger::getInstance("CORRECTION"))
|
||||
{
|
||||
}
|
||||
|
||||
MultiColorCorrection::~MultiColorCorrection()
|
||||
{
|
||||
// Clean up all the correctinos
|
||||
for (ColorCorrection * correction : _correction)
|
||||
{
|
||||
delete correction;
|
||||
}
|
||||
}
|
||||
|
||||
void MultiColorCorrection::addCorrection(ColorCorrection * correction)
|
||||
{
|
||||
_correctionIds.push_back(correction->_id);
|
||||
_correction.push_back(correction);
|
||||
}
|
||||
|
||||
void MultiColorCorrection::setCorrectionForLed(const QString& id, int startLed, int endLed)
|
||||
{
|
||||
// abort
|
||||
if(startLed > endLed)
|
||||
{
|
||||
Error(_log,"startLed > endLed -> %d > %d", startLed, endLed);
|
||||
return;
|
||||
}
|
||||
// catch wrong values
|
||||
if(endLed > static_cast<int>(_ledCorrections.size()-1))
|
||||
{
|
||||
Warning(_log,"The color correction 'LED index' field has LEDs specified which aren't part of your led layout");
|
||||
endLed = static_cast<int>(_ledCorrections.size()-1);
|
||||
}
|
||||
|
||||
// Get the identified correction (don't care if is nullptr)
|
||||
ColorCorrection * correction = getCorrection(id);
|
||||
for (int iLed=startLed; iLed<=endLed; ++iLed)
|
||||
{
|
||||
_ledCorrections[iLed] = correction;
|
||||
}
|
||||
}
|
||||
|
||||
bool MultiColorCorrection::verifyCorrections() const
|
||||
{
|
||||
bool ok = true;
|
||||
for (unsigned iLed=0; iLed<_ledCorrections.size(); ++iLed)
|
||||
{
|
||||
ColorCorrection* adjustment = _ledCorrections[iLed];
|
||||
|
||||
if (adjustment == nullptr)
|
||||
{
|
||||
Warning(_log, "No correction set for led %d", iLed);
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
QStringList & MultiColorCorrection::getCorrectionIds()
|
||||
{
|
||||
return _correctionIds;
|
||||
}
|
||||
|
||||
ColorCorrection* MultiColorCorrection::getCorrection(const QString& id)
|
||||
{
|
||||
// Iterate through the unique corrections until we find the one with the given id
|
||||
for (ColorCorrection * correction : _correction)
|
||||
{
|
||||
if (correction->_id == id)
|
||||
{
|
||||
return correction;
|
||||
}
|
||||
}
|
||||
|
||||
// The ColorCorrection was not found
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void MultiColorCorrection::applyCorrection(std::vector<ColorRgb>& ledColors)
|
||||
{
|
||||
const size_t itCnt = qMin(_ledCorrections.size(), ledColors.size());
|
||||
for (size_t i=0; i<itCnt; ++i)
|
||||
{
|
||||
ColorCorrection * correction = _ledCorrections[i];
|
||||
if (correction == nullptr)
|
||||
{
|
||||
std::cout << "MultiColorCorrection::applyCorrection() - No correction set for this led : " << i << std::endl;
|
||||
// No correction set for this led (do nothing)
|
||||
continue;
|
||||
}
|
||||
ColorRgb& color = ledColors[i];
|
||||
|
||||
color.red = correction->_rgbCorrection.correctionR(color.red);
|
||||
color.green = correction->_rgbCorrection.correctionG(color.green);
|
||||
color.blue = correction->_rgbCorrection.correctionB(color.blue);
|
||||
}
|
||||
}
|
@@ -221,6 +221,18 @@
|
||||
"step" : 0.1,
|
||||
"propertyOrder" : 16
|
||||
},
|
||||
"temperature" :
|
||||
{
|
||||
"type" : "integer",
|
||||
"title" : "edt_conf_color_temperature_title",
|
||||
"required" : true,
|
||||
"minimum" : 1000,
|
||||
"maximum": 40000,
|
||||
"default" : 6600,
|
||||
"step" : 100,
|
||||
"append" : "edt_append_kelvin",
|
||||
"propertyOrder" : 17
|
||||
},
|
||||
"gammaRed" :
|
||||
{
|
||||
"type" : "number",
|
||||
@@ -230,7 +242,7 @@
|
||||
"maximum": 100.0,
|
||||
"default" : 2.2,
|
||||
"step" : 0.1,
|
||||
"propertyOrder" : 17
|
||||
"propertyOrder" : 18
|
||||
},
|
||||
"gammaGreen" :
|
||||
{
|
||||
@@ -241,7 +253,7 @@
|
||||
"maximum": 100.0,
|
||||
"default" : 2.2,
|
||||
"step" : 0.1,
|
||||
"propertyOrder" : 18
|
||||
"propertyOrder" : 19
|
||||
},
|
||||
"gammaBlue" :
|
||||
{
|
||||
@@ -252,7 +264,7 @@
|
||||
"maximum": 100.0,
|
||||
"default" : 2.2,
|
||||
"step" : 0.1,
|
||||
"propertyOrder" : 19
|
||||
"propertyOrder" : 20
|
||||
}
|
||||
},
|
||||
"additionalProperties" : false
|
||||
|
120
libsrc/utils/RgbChannelCorrection.cpp
Normal file
120
libsrc/utils/RgbChannelCorrection.cpp
Normal file
@@ -0,0 +1,120 @@
|
||||
// STL includes
|
||||
#include <cmath>
|
||||
|
||||
// Utils includes
|
||||
#include <utils/RgbChannelCorrection.h>
|
||||
|
||||
RgbChannelCorrection::RgbChannelCorrection() :
|
||||
_correctionR(255),
|
||||
_correctionG(255),
|
||||
_correctionB(255)
|
||||
{
|
||||
initializeMapping();
|
||||
}
|
||||
|
||||
RgbChannelCorrection::RgbChannelCorrection(int correctionR, int correctionG, int correctionB) :
|
||||
_correctionR(correctionR),
|
||||
_correctionG(correctionG),
|
||||
_correctionB(correctionB)
|
||||
{
|
||||
initializeMapping();
|
||||
}
|
||||
|
||||
RgbChannelCorrection::~RgbChannelCorrection()
|
||||
{
|
||||
}
|
||||
|
||||
uint8_t RgbChannelCorrection::getcorrectionR() const
|
||||
{
|
||||
return _correctionR;
|
||||
}
|
||||
|
||||
void RgbChannelCorrection::setcorrectionR(uint8_t correctionR)
|
||||
{
|
||||
_correctionR = correctionR;
|
||||
initializeMapping();
|
||||
}
|
||||
|
||||
uint8_t RgbChannelCorrection::getcorrectionG() const
|
||||
{
|
||||
return _correctionG;
|
||||
}
|
||||
|
||||
void RgbChannelCorrection::setcorrectionG(uint8_t correctionG)
|
||||
{
|
||||
_correctionG = correctionG;
|
||||
initializeMapping();
|
||||
}
|
||||
|
||||
uint8_t RgbChannelCorrection::getcorrectionB() const
|
||||
{
|
||||
return _correctionB;
|
||||
}
|
||||
|
||||
void RgbChannelCorrection::setcorrectionB(uint8_t correctionB)
|
||||
{
|
||||
_correctionB = correctionB;
|
||||
initializeMapping();
|
||||
}
|
||||
|
||||
uint8_t RgbChannelCorrection::correctionR(uint8_t inputR) const
|
||||
{
|
||||
return _mappingR[inputR];
|
||||
}
|
||||
|
||||
uint8_t RgbChannelCorrection::correctionG(uint8_t inputG) const
|
||||
{
|
||||
return _mappingG[inputG];
|
||||
}
|
||||
|
||||
uint8_t RgbChannelCorrection::correctionB(uint8_t inputB) const
|
||||
{
|
||||
return _mappingB[inputB];
|
||||
}
|
||||
|
||||
void RgbChannelCorrection::initializeMapping()
|
||||
{
|
||||
// initialize the mapping
|
||||
for (int i = 0; i < 256; ++i)
|
||||
{
|
||||
int outputR = (i * _correctionR) / 255;
|
||||
if (outputR < -255)
|
||||
{
|
||||
outputR = -255;
|
||||
}
|
||||
else if (outputR > 255)
|
||||
{
|
||||
outputR = 255;
|
||||
}
|
||||
_mappingR[i] = outputR;
|
||||
}
|
||||
for (int i = 0; i < 256; ++i)
|
||||
{
|
||||
int outputG = (i * _correctionG) / 255;
|
||||
if (outputG < -255)
|
||||
{
|
||||
outputG = -255;
|
||||
}
|
||||
else if (outputG > 255)
|
||||
{
|
||||
outputG = 255;
|
||||
}
|
||||
_mappingG[i] = outputG;
|
||||
}
|
||||
for (int i = 0; i < 256; ++i)
|
||||
{
|
||||
int outputB = (i * _correctionB) / 255;
|
||||
if (outputB < -255)
|
||||
{
|
||||
outputB = -255;
|
||||
}
|
||||
else if (outputB > 255)
|
||||
{
|
||||
outputB = 255;
|
||||
}
|
||||
_mappingB[i] = outputB;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user