mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Re-add Temperture adjustment (#1710)
* Add Temperature adjustment * Add Temperature adjustment - add missing cmake updates * Add missing ENABLE_MDNS guards * Reapply temperature on JSONAPI * Integrate color temperature into RGB transformations * Fix imagestream update * fix cast * Cleanups * Windows Fix * Fix inner loop * Simplify * Reapply default temperature setting * Fix adjustments calculation * Updates
This commit is contained in:
@@ -152,6 +152,13 @@
|
||||
"required" : false,
|
||||
"minimum" : 0.1,
|
||||
"maximum": 10.0
|
||||
},
|
||||
"temperature" :
|
||||
{
|
||||
"type" : "integer",
|
||||
"required" : false,
|
||||
"minimum" : 1000,
|
||||
"maximum": 40000
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
|
@@ -27,6 +27,7 @@
|
||||
#include <utils/jsonschema/QJsonFactory.h>
|
||||
#include <utils/jsonschema/QJsonSchemaChecker.h>
|
||||
#include <utils/ColorSys.h>
|
||||
#include <utils/KelvinToRgb.h>
|
||||
#include <utils/Process.h>
|
||||
#include <utils/JsonUtils.h>
|
||||
|
||||
@@ -640,6 +641,7 @@ void JsonAPI::applyTransforms(const QJsonObject &adjustment, ColorAdjustment *co
|
||||
applyTransform("backlightColored", adjustment, colorAdjustment->_rgbTransform, &RgbTransform::setBacklightColored);
|
||||
applyTransform("brightness", adjustment, colorAdjustment->_rgbTransform, &RgbTransform::setBrightness);
|
||||
applyTransform("brightnessCompensation", adjustment, colorAdjustment->_rgbTransform, &RgbTransform::setBrightnessCompensation);
|
||||
applyTransform("temperature", adjustment, colorAdjustment->_rgbTransform, &RgbTransform::setTemperature);
|
||||
applyTransform("saturationGain", adjustment, colorAdjustment->_okhsvTransform, &OkhsvTransform::setSaturationGain);
|
||||
applyTransform("brightnessGain", adjustment, colorAdjustment->_okhsvTransform, &OkhsvTransform::setBrightnessGain);
|
||||
}
|
||||
@@ -669,6 +671,14 @@ void JsonAPI::applyTransform(const QString &transformName, const QJsonObject &ad
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void JsonAPI::applyTransform(const QString &transformName, const QJsonObject &adjustment, T &transform, void (T::*setFunction)(int))
|
||||
{
|
||||
if (adjustment.contains(transformName)) {
|
||||
(transform.*setFunction)(adjustment[transformName].toInt());
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void JsonAPI::applyTransform(const QString &transformName, const QJsonObject &adjustment, T &transform, void (T::*setFunction)(uint8_t))
|
||||
{
|
||||
|
@@ -84,6 +84,8 @@ QJsonArray JsonInfo::getAdjustmentInfo(const Hyperion* hyperion, Logger* log)
|
||||
adjustment["saturationGain"] = colorAdjustment->_okhsvTransform.getSaturationGain();
|
||||
adjustment["brightnessGain"] = colorAdjustment->_okhsvTransform.getBrightnessGain();
|
||||
|
||||
adjustment["temperature"] = colorAdjustment->_rgbTransform.getTemperature();
|
||||
|
||||
adjustmentArray.append(adjustment);
|
||||
}
|
||||
return adjustmentArray;
|
||||
|
@@ -1,22 +1,23 @@
|
||||
#include <algorithm>
|
||||
|
||||
// Hyperion includes
|
||||
|
||||
#include <utils/Logger.h>
|
||||
#include <hyperion/MultiColorAdjustment.h>
|
||||
|
||||
MultiColorAdjustment::MultiColorAdjustment(int ledCnt)
|
||||
: _ledAdjustments(ledCnt, nullptr)
|
||||
: _ledAdjustments(static_cast<size_t>(ledCnt), nullptr)
|
||||
, _log(Logger::getInstance("ADJUSTMENT"))
|
||||
{
|
||||
}
|
||||
|
||||
MultiColorAdjustment::~MultiColorAdjustment()
|
||||
{
|
||||
// Clean up all the transforms
|
||||
for (ColorAdjustment * adjustment : _adjustment)
|
||||
for (ColorAdjustment* adjustment : _adjustment)
|
||||
{
|
||||
delete adjustment;
|
||||
// BUG: Calling pop_back while iterating is invalid
|
||||
_adjustment.pop_back();
|
||||
}
|
||||
_adjustment.clear();
|
||||
}
|
||||
|
||||
void MultiColorAdjustment::addAdjustment(ColorAdjustment * adjustment)
|
||||
@@ -25,7 +26,7 @@ void MultiColorAdjustment::addAdjustment(ColorAdjustment * adjustment)
|
||||
_adjustment.push_back(adjustment);
|
||||
}
|
||||
|
||||
void MultiColorAdjustment::setAdjustmentForLed(const QString& id, int startLed, int endLed)
|
||||
void MultiColorAdjustment::setAdjustmentForLed(const QString& adjutmentId, int startLed, int endLed)
|
||||
{
|
||||
// abort
|
||||
if(startLed > endLed)
|
||||
@@ -41,8 +42,8 @@ void MultiColorAdjustment::setAdjustmentForLed(const QString& id, int startLed,
|
||||
}
|
||||
|
||||
// Get the identified adjustment (don't care if is nullptr)
|
||||
ColorAdjustment * adjustment = getAdjustment(id);
|
||||
for (int iLed=startLed; iLed<=endLed; ++iLed)
|
||||
ColorAdjustment * adjustment = getAdjustment(adjutmentId);
|
||||
for (size_t iLed=static_cast<size_t>(startLed); iLed<=static_cast<size_t>(endLed); ++iLed)
|
||||
{
|
||||
_ledAdjustments[iLed] = adjustment;
|
||||
}
|
||||
@@ -50,18 +51,18 @@ void MultiColorAdjustment::setAdjustmentForLed(const QString& id, int startLed,
|
||||
|
||||
bool MultiColorAdjustment::verifyAdjustments() const
|
||||
{
|
||||
bool ok = true;
|
||||
bool isAdjustmentDefined = true;
|
||||
for (unsigned iLed=0; iLed<_ledAdjustments.size(); ++iLed)
|
||||
{
|
||||
ColorAdjustment * adjustment = _ledAdjustments[iLed];
|
||||
const ColorAdjustment * adjustment = _ledAdjustments[iLed];
|
||||
|
||||
if (adjustment == nullptr)
|
||||
{
|
||||
Warning(_log, "No calibration set for led %d", iLed);
|
||||
ok = false;
|
||||
Warning(_log, "No calibration set for LED %d", iLed);
|
||||
isAdjustmentDefined = false;
|
||||
}
|
||||
}
|
||||
return ok;
|
||||
return isAdjustmentDefined;
|
||||
}
|
||||
|
||||
QStringList MultiColorAdjustment::getAdjustmentIds() const
|
||||
@@ -69,15 +70,14 @@ QStringList MultiColorAdjustment::getAdjustmentIds() const
|
||||
return _adjustmentIds;
|
||||
}
|
||||
|
||||
ColorAdjustment* MultiColorAdjustment::getAdjustment(const QString& id)
|
||||
ColorAdjustment* MultiColorAdjustment::getAdjustment(const QString& adjustmentId)
|
||||
{
|
||||
// Iterate through the unique adjustments until we find the one with the given id
|
||||
for (ColorAdjustment* adjustment : _adjustment)
|
||||
{
|
||||
if (adjustment->_id == id)
|
||||
{
|
||||
return adjustment;
|
||||
}
|
||||
auto adjustmentIter = std::find_if(_adjustment.begin(), _adjustment.end(), [&adjustmentId](const ColorAdjustment* adjustment) {
|
||||
return adjustment->_id == adjustmentId;
|
||||
});
|
||||
|
||||
if (adjustmentIter != _adjustment.end()) {
|
||||
return *adjustmentIter;
|
||||
}
|
||||
|
||||
// The ColorAdjustment was not found
|
||||
@@ -100,8 +100,7 @@ void MultiColorAdjustment::applyAdjustment(std::vector<ColorRgb>& ledColors)
|
||||
ColorAdjustment* adjustment = _ledAdjustments[i];
|
||||
if (adjustment == nullptr)
|
||||
{
|
||||
//std::cout << "MultiColorAdjustment::applyAdjustment() - No transform set for this led : " << i << std::endl;
|
||||
// No transform set for this led (do nothing)
|
||||
// No transform set for this LED (do nothing)
|
||||
continue;
|
||||
}
|
||||
ColorRgb& color = ledColors[i];
|
||||
@@ -117,27 +116,34 @@ void MultiColorAdjustment::applyAdjustment(std::vector<ColorRgb>& ledColors)
|
||||
{
|
||||
adjustment->_okhsvTransform.transform(ored, ogreen, oblue);
|
||||
}
|
||||
adjustment->_rgbTransform.transform(ored,ogreen,oblue);
|
||||
|
||||
adjustment->_rgbTransform.applyGamma(ored,ogreen,oblue);
|
||||
adjustment->_rgbTransform.getBrightnessComponents(B_RGB, B_CMY, B_W);
|
||||
|
||||
uint32_t nrng = (uint32_t) (255-ored)*(255-ogreen);
|
||||
uint32_t rng = (uint32_t) (ored) *(255-ogreen);
|
||||
uint32_t nrg = (uint32_t) (255-ored)*(ogreen);
|
||||
uint32_t rg = (uint32_t) (ored) *(ogreen);
|
||||
uint32_t nr_ng = static_cast<uint32_t>((UINT8_MAX - ored) * (UINT8_MAX - ogreen));
|
||||
uint32_t r_ng = static_cast<uint32_t>(ored * (UINT8_MAX - ogreen));
|
||||
uint32_t nr_g = static_cast<uint32_t>((UINT8_MAX - ored) * ogreen);
|
||||
uint32_t r_g = static_cast<uint32_t>(ored * ogreen);
|
||||
|
||||
uint8_t black = nrng*(255-oblue)/65025;
|
||||
uint8_t red = rng *(255-oblue)/65025;
|
||||
uint8_t green = nrg *(255-oblue)/65025;
|
||||
uint8_t blue = nrng*(oblue) /65025;
|
||||
uint8_t cyan = nrg *(oblue) /65025;
|
||||
uint8_t magenta = rng *(oblue) /65025;
|
||||
uint8_t yellow = rg *(255-oblue)/65025;
|
||||
uint8_t white = rg *(oblue) /65025;
|
||||
uint8_t black = static_cast<uint8_t>(nr_ng * (UINT8_MAX - oblue) / DOUBLE_UINT8_MAX_SQUARED);
|
||||
uint8_t red = static_cast<uint8_t>(r_ng * (UINT8_MAX - oblue) / DOUBLE_UINT8_MAX_SQUARED);
|
||||
uint8_t green = static_cast<uint8_t>(nr_g * (UINT8_MAX - oblue) / DOUBLE_UINT8_MAX_SQUARED);
|
||||
uint8_t blue = static_cast<uint8_t>(nr_ng * (oblue) / DOUBLE_UINT8_MAX_SQUARED);
|
||||
uint8_t cyan = static_cast<uint8_t>(nr_g * (oblue) / DOUBLE_UINT8_MAX_SQUARED);
|
||||
uint8_t magenta = static_cast<uint8_t>(r_ng * (oblue) / DOUBLE_UINT8_MAX_SQUARED);
|
||||
uint8_t yellow = static_cast<uint8_t>(r_g * (UINT8_MAX - oblue) / DOUBLE_UINT8_MAX_SQUARED);
|
||||
uint8_t white = static_cast<uint8_t>(r_g * (oblue) / DOUBLE_UINT8_MAX_SQUARED);
|
||||
|
||||
uint8_t OR, OG, OB, RR, RG, RB, GR, GG, GB, BR, BG, BB;
|
||||
uint8_t CR, CG, CB, MR, MG, MB, YR, YG, YB, WR, WG, WB;
|
||||
uint8_t OR, OG, OB; // Original Colors
|
||||
uint8_t RR, RG, RB; // Red Adjustments
|
||||
uint8_t GR, GG, GB; // Green Adjustments
|
||||
uint8_t BR, BG, BB; // Blue Adjustments
|
||||
uint8_t CR, CG, CB; // Cyan Adjustments
|
||||
uint8_t MR, MG, MB; // Magenta Adjustments
|
||||
uint8_t YR, YG, YB; // Yellow Adjustments
|
||||
uint8_t WR, WG, WB; // White Adjustments
|
||||
|
||||
adjustment->_rgbBlackAdjustment.apply (black , 255 , OR, OG, OB);
|
||||
adjustment->_rgbBlackAdjustment.apply (black , UINT8_MAX, OR, OG, OB);
|
||||
adjustment->_rgbRedAdjustment.apply (red , B_RGB, RR, RG, RB);
|
||||
adjustment->_rgbGreenAdjustment.apply (green , B_RGB, GR, GG, GB);
|
||||
adjustment->_rgbBlueAdjustment.apply (blue , B_RGB, BR, BG, BB);
|
||||
@@ -149,5 +155,8 @@ void MultiColorAdjustment::applyAdjustment(std::vector<ColorRgb>& ledColors)
|
||||
color.red = OR + RR + GR + BR + CR + MR + YR + WR;
|
||||
color.green = OG + RG + GG + BG + CG + MG + YG + WG;
|
||||
color.blue = OB + RB + GB + BB + CB + MB + YB + WB;
|
||||
|
||||
adjustment->_rgbTransform.applyTemperature(color);
|
||||
adjustment->_rgbTransform.applyBacklight(color.red, color.green, color.green);
|
||||
}
|
||||
}
|
||||
|
@@ -244,6 +244,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",
|
||||
@@ -253,7 +265,7 @@
|
||||
"maximum": 100.0,
|
||||
"default" : 2.2,
|
||||
"step" : 0.1,
|
||||
"propertyOrder" : 17
|
||||
"propertyOrder" : 18
|
||||
},
|
||||
"gammaGreen" :
|
||||
{
|
||||
@@ -264,7 +276,7 @@
|
||||
"maximum": 100.0,
|
||||
"default" : 2.2,
|
||||
"step" : 0.1,
|
||||
"propertyOrder" : 18
|
||||
"propertyOrder" : 19
|
||||
},
|
||||
"gammaBlue" :
|
||||
{
|
||||
@@ -275,7 +287,7 @@
|
||||
"maximum": 100.0,
|
||||
"default" : 2.2,
|
||||
"step" : 0.1,
|
||||
"propertyOrder" : 19
|
||||
"propertyOrder" : 20
|
||||
}
|
||||
},
|
||||
"additionalProperties" : false
|
||||
|
@@ -62,6 +62,7 @@ add_library(hyperion-utils
|
||||
${CMAKE_SOURCE_DIR}/libsrc/utils/RgbToRgbw.cpp
|
||||
${CMAKE_SOURCE_DIR}/include/utils/RgbTransform.h
|
||||
${CMAKE_SOURCE_DIR}/libsrc/utils/RgbTransform.cpp
|
||||
${CMAKE_SOURCE_DIR}/include/utils/KelvinToRgb.h
|
||||
# System info class
|
||||
${CMAKE_SOURCE_DIR}/include/utils/SysInfo.h
|
||||
${CMAKE_SOURCE_DIR}/libsrc/utils/SysInfo.cpp
|
||||
|
@@ -7,3 +7,5 @@ const ColorRgb ColorRgb::GREEN = { 0, 255, 0 };
|
||||
const ColorRgb ColorRgb::BLUE = { 0, 0, 255 };
|
||||
const ColorRgb ColorRgb::YELLOW = { 255, 255, 0 };
|
||||
const ColorRgb ColorRgb::WHITE = { 255, 255, 255 };
|
||||
const ColorRgb ColorRgb::CYAN = { 0, 255, 255 };
|
||||
const ColorRgb ColorRgb::MAGENTA= { 255, 0, 255 };
|
||||
|
@@ -1,44 +1,54 @@
|
||||
#include <utils/RgbChannelAdjustment.h>
|
||||
|
||||
RgbChannelAdjustment::RgbChannelAdjustment(QString channelName)
|
||||
|
||||
RgbChannelAdjustment::RgbChannelAdjustment(const QString& channelName)
|
||||
: RgbChannelAdjustment(0, 0, 0, channelName)
|
||||
{
|
||||
}
|
||||
|
||||
RgbChannelAdjustment::RgbChannelAdjustment(uint8_t adjustR, uint8_t adjustG, uint8_t adjustB, QString channelName )
|
||||
RgbChannelAdjustment::RgbChannelAdjustment(uint8_t adjustR, uint8_t adjustG, uint8_t adjustB, const QString& channelName )
|
||||
: RgbChannelAdjustment({adjustR, adjustG, adjustB}, channelName)
|
||||
{
|
||||
}
|
||||
|
||||
RgbChannelAdjustment::RgbChannelAdjustment(const ColorRgb& adjust, const QString& channelName )
|
||||
: _channelName(channelName)
|
||||
, _log(Logger::getInstance("CHANNEL_" + channelName.toUpper()))
|
||||
, _mapping{ {0}, {0}, {0} }
|
||||
, _brightness(0)
|
||||
{
|
||||
setAdjustment(adjustR, adjustG, adjustB);
|
||||
setAdjustment(adjust);
|
||||
}
|
||||
|
||||
void RgbChannelAdjustment::resetInitialized()
|
||||
{
|
||||
memset(_initialized, false, sizeof(_initialized));
|
||||
memset(_initialized, 0, sizeof(_initialized));
|
||||
}
|
||||
|
||||
void RgbChannelAdjustment::setAdjustment(uint8_t adjustR, uint8_t adjustG, uint8_t adjustB)
|
||||
{
|
||||
_adjust[RED] = adjustR;
|
||||
_adjust[GREEN] = adjustG;
|
||||
_adjust[BLUE] = adjustB;
|
||||
setAdjustment( {adjustR, adjustG, adjustB} );
|
||||
}
|
||||
|
||||
void RgbChannelAdjustment::setAdjustment(const ColorRgb& adjust)
|
||||
{
|
||||
_adjust = adjust;
|
||||
resetInitialized();
|
||||
}
|
||||
|
||||
uint8_t RgbChannelAdjustment::getAdjustmentR() const
|
||||
{
|
||||
return _adjust[RED];
|
||||
return _adjust.red;
|
||||
}
|
||||
|
||||
uint8_t RgbChannelAdjustment::getAdjustmentG() const
|
||||
{
|
||||
return _adjust[GREEN];
|
||||
return _adjust.green;
|
||||
}
|
||||
|
||||
uint8_t RgbChannelAdjustment::getAdjustmentB() const
|
||||
{
|
||||
return _adjust[BLUE];
|
||||
return _adjust.blue;
|
||||
}
|
||||
|
||||
void RgbChannelAdjustment::apply(uint8_t input, uint8_t brightness, uint8_t & red, uint8_t & green, uint8_t & blue)
|
||||
@@ -51,12 +61,13 @@ void RgbChannelAdjustment::apply(uint8_t input, uint8_t brightness, uint8_t & re
|
||||
|
||||
if (!_initialized[input])
|
||||
{
|
||||
_mapping[RED ][input] = qMin( ((_brightness * input * _adjust[RED ]) / 65025), (int)UINT8_MAX);
|
||||
_mapping[GREEN][input] = qMin( ((_brightness * input * _adjust[GREEN]) / 65025), (int)UINT8_MAX);
|
||||
_mapping[BLUE ][input] = qMin( ((_brightness * input * _adjust[BLUE ]) / 65025), (int)UINT8_MAX);
|
||||
const double adjustedInput = _brightness * input / DOUBLE_UINT8_MAX_SQUARED;
|
||||
_mapping.red[input] = static_cast<quint8>(qBound(0, static_cast<int>(_adjust.red * adjustedInput), static_cast<int>(UINT8_MAX)));
|
||||
_mapping.green[input] = static_cast<quint8>(qBound(0 ,static_cast<int>(_adjust.green * adjustedInput), static_cast<int>(UINT8_MAX)));
|
||||
_mapping.blue[input] = static_cast<quint8>(qBound(0, static_cast<int>(_adjust.blue * adjustedInput), static_cast<int>(UINT8_MAX)));
|
||||
_initialized[input] = true;
|
||||
}
|
||||
red = _mapping[RED ][input];
|
||||
green = _mapping[GREEN][input];
|
||||
blue = _mapping[BLUE ][input];
|
||||
red = _mapping.red[input];
|
||||
green = _mapping.green[input];
|
||||
blue = _mapping.blue[input];
|
||||
}
|
||||
|
@@ -1,19 +1,20 @@
|
||||
#include <QtCore/qmath.h>
|
||||
#include <utils/RgbTransform.h>
|
||||
#include <utils/KelvinToRgb.h>
|
||||
|
||||
RgbTransform::RgbTransform()
|
||||
: RgbTransform::RgbTransform(1.0, 1.0, 1.0, 0.0, false, 100, 100)
|
||||
: RgbTransform::RgbTransform(1.0, 1.0, 1.0, 0.0, false, 100, 100, ColorTemperature::DEFAULT)
|
||||
{
|
||||
}
|
||||
|
||||
RgbTransform::RgbTransform(double gammaR, double gammaG, double gammaB, double backlightThreshold, bool backlightColored, uint8_t brightness, uint8_t brightnessCompensation)
|
||||
RgbTransform::RgbTransform(double gammaR, double gammaG, double gammaB, double backlightThreshold, bool backlightColored, uint8_t brightness, uint8_t brightnessCompensation, int temperature)
|
||||
: _brightness(brightness)
|
||||
, _brightnessCompensation(brightnessCompensation)
|
||||
{
|
||||
init(gammaR, gammaG, gammaB, backlightThreshold, backlightColored, _brightness, _brightnessCompensation);
|
||||
init(gammaR, gammaG, gammaB, backlightThreshold, backlightColored, _brightness, _brightnessCompensation, temperature);
|
||||
}
|
||||
|
||||
void RgbTransform::init(double gammaR, double gammaG, double gammaB, double backlightThreshold, bool backlightColored, uint8_t brightness, uint8_t brightnessCompensation)
|
||||
void RgbTransform::init(double gammaR, double gammaG, double gammaB, double backlightThreshold, bool backlightColored, uint8_t brightness, uint8_t brightnessCompensation, int temperature)
|
||||
{
|
||||
_backLightEnabled = true;
|
||||
setGamma(gammaR,gammaG,gammaB);
|
||||
@@ -21,6 +22,7 @@ void RgbTransform::init(double gammaR, double gammaG, double gammaB, double back
|
||||
setBacklightColored(backlightColored);
|
||||
setBrightness(brightness);
|
||||
setBrightnessCompensation(brightnessCompensation);
|
||||
setTemperature(temperature);
|
||||
initializeMapping();
|
||||
}
|
||||
|
||||
@@ -49,18 +51,34 @@ void RgbTransform::setGamma(double gammaR, double gammaG, double gammaB)
|
||||
|
||||
void RgbTransform::initializeMapping()
|
||||
{
|
||||
for (int i = 0; i < 256; ++i)
|
||||
for (int i = 0; i <= UINT8_MAX; ++i)
|
||||
{
|
||||
_mappingR[i] = qMin(qMax((int)(qPow(i / 255.0, _gammaR) * 255), 0), 255);
|
||||
_mappingG[i] = qMin(qMax((int)(qPow(i / 255.0, _gammaG) * 255), 0), 255);
|
||||
_mappingB[i] = qMin(qMax((int)(qPow(i / 255.0, _gammaB) * 255), 0), 255);
|
||||
// Calculate normalized value
|
||||
double normalizedValueR = static_cast<double>(i) / UINT8_MAX;
|
||||
double normalizedValueG = static_cast<double>(i) / UINT8_MAX;
|
||||
double normalizedValueB = static_cast<double>(i) / UINT8_MAX;
|
||||
|
||||
// Apply gamma correction
|
||||
double gammaCorrectedValueR = qPow(normalizedValueR, _gammaR) * UINT8_MAX;
|
||||
double gammaCorrectedValueG = qPow(normalizedValueG, _gammaG) * UINT8_MAX;
|
||||
double gammaCorrectedValueB = qPow(normalizedValueB, _gammaB) * UINT8_MAX;
|
||||
|
||||
// Clamp values to valid range [0, UINT8_MAX]
|
||||
quint8 clampedValueR = static_cast<quint8>(qBound(0.0, gammaCorrectedValueR, static_cast<double>(UINT8_MAX)));
|
||||
quint8 clampedValueG = static_cast<quint8>(qBound(0.0, gammaCorrectedValueG, static_cast<double>(UINT8_MAX)));
|
||||
quint8 clampedValueB = static_cast<quint8>(qBound(0.0, gammaCorrectedValueB, static_cast<double>(UINT8_MAX)));
|
||||
|
||||
// Assign clamped values to _mapping arrays
|
||||
_mappingR[i] = clampedValueR;
|
||||
_mappingG[i] = clampedValueG;
|
||||
_mappingB[i] = clampedValueB;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int RgbTransform::getBacklightThreshold() const
|
||||
{
|
||||
return _backlightThreshold;
|
||||
return static_cast<int>(_backlightThreshold);
|
||||
}
|
||||
|
||||
void RgbTransform::setBacklightThreshold(double backlightThreshold)
|
||||
@@ -116,60 +134,81 @@ void RgbTransform::updateBrightnessComponents()
|
||||
double Fw = _brightnessCompensation*2.0/100.0+1.0;
|
||||
double Fcmy = _brightnessCompensation/100.0+1.0;
|
||||
|
||||
double B_in= 0;
|
||||
_brightness_rgb = 0;
|
||||
_brightness_cmy = 0;
|
||||
_brightness_w = 0;
|
||||
|
||||
if (_brightness > 0)
|
||||
{
|
||||
B_in = (_brightness<50)? -0.09*_brightness+7.5 : -0.04*_brightness+5.0;
|
||||
double B_in = (_brightness < 50) ? -0.09 * _brightness + 7.5 : -0.04 * _brightness + 5.0;
|
||||
|
||||
_brightness_rgb = std::ceil(qMin(255.0,255.0/B_in));
|
||||
_brightness_cmy = std::ceil(qMin(255.0,255.0/(B_in*Fcmy)));
|
||||
_brightness_w = std::ceil(qMin(255.0,255.0/(B_in*Fw)));
|
||||
// Ensure that the result is converted to an integer before assigning to uint8_t
|
||||
_brightness_rgb = static_cast<uint8_t>(std::ceil(qMin(static_cast<double>(UINT8_MAX), UINT8_MAX / B_in)));
|
||||
_brightness_cmy = static_cast<uint8_t>(std::ceil(qMin(static_cast<double>(UINT8_MAX), UINT8_MAX / (B_in * Fcmy))));
|
||||
_brightness_w = static_cast<uint8_t>(std::ceil(qMin(static_cast<double>(UINT8_MAX), UINT8_MAX / (B_in * Fw))));
|
||||
}
|
||||
}
|
||||
|
||||
void RgbTransform::getBrightnessComponents(uint8_t & rgb, uint8_t & cmy, uint8_t & w) const
|
||||
void RgbTransform::getBrightnessComponents(uint8_t & rgb, uint8_t & cmy, uint8_t & white) const
|
||||
{
|
||||
rgb = _brightness_rgb;
|
||||
cmy = _brightness_cmy;
|
||||
w = _brightness_w;
|
||||
white = _brightness_w;
|
||||
}
|
||||
|
||||
void RgbTransform::transform(uint8_t & red, uint8_t & green, uint8_t & blue)
|
||||
void RgbTransform::applyGamma(uint8_t & red, uint8_t & green, uint8_t & blue)
|
||||
{
|
||||
// apply gamma
|
||||
red = _mappingR[red];
|
||||
green = _mappingG[green];
|
||||
blue = _mappingB[blue];
|
||||
}
|
||||
|
||||
void RgbTransform::applyBacklight(uint8_t & red, uint8_t & green, uint8_t & blue) const
|
||||
{
|
||||
// apply brightnesss
|
||||
int rgbSum = red+green+blue;
|
||||
|
||||
if ( _backLightEnabled && _sumBrightnessLow>0 && rgbSum < _sumBrightnessLow)
|
||||
if ( _backLightEnabled && _sumBrightnessLow > 0 && rgbSum < _sumBrightnessLow)
|
||||
{
|
||||
if (_backlightColored)
|
||||
{
|
||||
if (rgbSum == 0)
|
||||
{
|
||||
if (red ==0) red = 1;
|
||||
if (green==0) green = 1;
|
||||
if (blue ==0) blue = 1;
|
||||
if (red ==0) { red = 1; }
|
||||
if (green==0) { green = 1; }
|
||||
if (blue ==0) { blue = 1; }
|
||||
rgbSum = red+green+blue;
|
||||
}
|
||||
double cL =qMin((int)(_sumBrightnessLow /rgbSum), 255);
|
||||
|
||||
red *= cL;
|
||||
green *= cL;
|
||||
blue *= cL;
|
||||
uint8_t cLow = static_cast<uint8_t>(qMin(static_cast<double>(_sumBrightnessLow/rgbSum), static_cast<double>(UINT8_MAX)));
|
||||
red *= cLow;
|
||||
green *= cLow;
|
||||
blue *= cLow;
|
||||
}
|
||||
else
|
||||
{
|
||||
red = qMin((int)(_sumBrightnessLow/3.0), 255);
|
||||
red = static_cast<uint8_t>(qMin(static_cast<double>(_sumBrightnessLow/3.0), static_cast<double>(UINT8_MAX)));
|
||||
green = red;
|
||||
blue = red;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RgbTransform::setTemperature(int temperature)
|
||||
{
|
||||
_temperature = temperature;
|
||||
_temperatureRGB = getRgbFromTemperature(_temperature);
|
||||
}
|
||||
|
||||
int RgbTransform::getTemperature() const
|
||||
{
|
||||
return _temperature;
|
||||
}
|
||||
|
||||
void RgbTransform::applyTemperature(ColorRgb& color) const
|
||||
{
|
||||
color.red = color.red * _temperatureRGB.red / UINT8_MAX;
|
||||
color.green = color.green * _temperatureRGB.green / UINT8_MAX;
|
||||
color.blue = color.blue * _temperatureRGB.blue / UINT8_MAX;
|
||||
}
|
||||
|
Reference in New Issue
Block a user