From cc38abe8ee753be3e0d784f4245941fdb8f4321d Mon Sep 17 00:00:00 2001 From: Thomas Emmel Date: Fri, 7 Nov 2025 10:54:32 +0100 Subject: [PATCH 1/7] Fix - The color of the backlight threshold is green, not white/gray --- CHANGELOG.md | 1 + include/utils/RgbTransform.h | 12 ++--- libsrc/hyperion/MultiColorAdjustment.cpp | 2 +- libsrc/utils/RgbTransform.cpp | 57 +++++++++++------------- 4 files changed, 34 insertions(+), 38 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca6a6c0ce..88f3275d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - LED-devices are not retrying to establish connectivity, if supported by the device - LED-devices are resolving IP-addresses for API and UDP two times in sequence - LED-device updates queue up and let Hyperion crash (#1887) + - The color of the backlight threshold is green, not white/gray (#1899) --- diff --git a/include/utils/RgbTransform.h b/include/utils/RgbTransform.h index f1d84456b..3eb25ab0b 100644 --- a/include/utils/RgbTransform.h +++ b/include/utils/RgbTransform.h @@ -27,7 +27,7 @@ class RgbTransform /// @param brightnessHigh The used higher brightness /// @param temeprature The given color temperature (in Kelvin) /// - RgbTransform(double gammaR, double gammaG, double gammaB, double backlightThreshold, bool backlightColored, uint8_t brightness, uint8_t brightnessCompensation, int temperature); + RgbTransform(double gammaR, double gammaG, double gammaB, int backlightThreshold, bool backlightColored, uint8_t brightness, uint8_t brightnessCompensation, int temperature); /// @return The current red gamma value double getGammaR() const; @@ -47,7 +47,7 @@ class RgbTransform int getBacklightThreshold() const; /// @param backlightThreshold New lower brightness - void setBacklightThreshold(double backlightThreshold); + void setBacklightThreshold(int backlightThreshold); /// @return The current state bool getBacklightColored() const; @@ -93,7 +93,7 @@ class RgbTransform /// /// @note The values are updated in place. /// - void applyGamma(uint8_t & red, uint8_t & green, uint8_t & blue); + void applyGamma(uint8_t & red, uint8_t & green, uint8_t & blue) const; /// /// Apply Backlight the the given RGB values. @@ -123,7 +123,7 @@ class RgbTransform /// @param brightnessCompensation The used brightness compensation /// @param temeprature apply the given color temperature (in Kelvin) /// - void init(double gammaR, double gammaG, double gammaB, double backlightThreshold, bool backlightColored, uint8_t brightness, uint8_t brightnessCompensation, int temperature); + void init(double gammaR, double gammaG, double gammaB, int backlightThreshold, bool backlightColored, uint8_t brightness, uint8_t brightnessCompensation, int temperature); /// (re)-initilize the color mapping void initializeMapping(); /// The saturation gain @@ -133,8 +133,8 @@ class RgbTransform /// backlight variables bool _backLightEnabled; bool _backlightColored; - double _backlightThreshold; - double _sumBrightnessLow; + int _backlightThreshold; + uint8_t _sumBrightnessLow; /// gamma variables double _gammaR; diff --git a/libsrc/hyperion/MultiColorAdjustment.cpp b/libsrc/hyperion/MultiColorAdjustment.cpp index 74fb0959f..b905bd466 100644 --- a/libsrc/hyperion/MultiColorAdjustment.cpp +++ b/libsrc/hyperion/MultiColorAdjustment.cpp @@ -159,6 +159,6 @@ void MultiColorAdjustment::applyAdjustment(std::vector& ledColors) color.blue = OB + RB + GB + BB + CB + MB + YB + WB; adjustment->_rgbTransform.applyTemperature(color); - adjustment->_rgbTransform.applyBacklight(color.red, color.green, color.green); + adjustment->_rgbTransform.applyBacklight(color.red, color.green, color.blue); } } diff --git a/libsrc/utils/RgbTransform.cpp b/libsrc/utils/RgbTransform.cpp index 086e2d82f..20a88b175 100644 --- a/libsrc/utils/RgbTransform.cpp +++ b/libsrc/utils/RgbTransform.cpp @@ -7,14 +7,14 @@ RgbTransform::RgbTransform() { } -RgbTransform::RgbTransform(double gammaR, double gammaG, double gammaB, double backlightThreshold, bool backlightColored, uint8_t brightness, uint8_t brightnessCompensation, int temperature) +RgbTransform::RgbTransform(double gammaR, double gammaG, double gammaB, int backlightThreshold, bool backlightColored, uint8_t brightness, uint8_t brightnessCompensation, int temperature) : _brightness(brightness) , _brightnessCompensation(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, int temperature) +void RgbTransform::init(double gammaR, double gammaG, double gammaB, int backlightThreshold, bool backlightColored, uint8_t brightness, uint8_t brightnessCompensation, int temperature) { _backLightEnabled = true; setGamma(gammaR,gammaG,gammaB); @@ -64,9 +64,9 @@ void RgbTransform::initializeMapping() double gammaCorrectedValueB = qPow(normalizedValueB, _gammaB) * UINT8_MAX; // Clamp values to valid range [0, UINT8_MAX] - quint8 clampedValueR = static_cast(qBound(0.0, gammaCorrectedValueR, static_cast(UINT8_MAX))); - quint8 clampedValueG = static_cast(qBound(0.0, gammaCorrectedValueG, static_cast(UINT8_MAX))); - quint8 clampedValueB = static_cast(qBound(0.0, gammaCorrectedValueB, static_cast(UINT8_MAX))); + auto clampedValueR = static_cast(qBound(0.0, gammaCorrectedValueR, static_cast(UINT8_MAX))); + auto clampedValueG = static_cast(qBound(0.0, gammaCorrectedValueG, static_cast(UINT8_MAX))); + auto clampedValueB = static_cast(qBound(0.0, gammaCorrectedValueB, static_cast(UINT8_MAX))); // Assign clamped values to _mapping arrays _mappingR[i] = clampedValueR; @@ -78,13 +78,13 @@ void RgbTransform::initializeMapping() int RgbTransform::getBacklightThreshold() const { - return static_cast(_backlightThreshold); + return _backlightThreshold; } - -void RgbTransform::setBacklightThreshold(double backlightThreshold) + +void RgbTransform::setBacklightThreshold(int backlightThreshold) { _backlightThreshold = backlightThreshold; - _sumBrightnessLow = 765.0 * ((qPow(2.0,(_backlightThreshold/100)*2)-1) / 3.0); + _sumBrightnessLow = static_cast(qBound(0, _backlightThreshold, UINT8_MAX)); } bool RgbTransform::getBacklightColored() const @@ -153,10 +153,10 @@ void RgbTransform::getBrightnessComponents(uint8_t & rgb, uint8_t & cmy, uint8_t { rgb = _brightness_rgb; cmy = _brightness_cmy; - white = _brightness_w; + white = _brightness_w; } -void RgbTransform::applyGamma(uint8_t & red, uint8_t & green, uint8_t & blue) +void RgbTransform::applyGamma(uint8_t & red, uint8_t & green, uint8_t & blue) const { // apply gamma red = _mappingR[red]; @@ -164,33 +164,28 @@ void RgbTransform::applyGamma(uint8_t & red, uint8_t & green, uint8_t & blue) blue = _mappingB[blue]; } -void RgbTransform::applyBacklight(uint8_t & red, uint8_t & green, uint8_t & blue) const +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) { if (_backlightColored) { - if (rgbSum == 0) - { - if (red ==0) { red = 1; } - if (green==0) { green = 1; } - if (blue ==0) { blue = 1; } - rgbSum = red+green+blue; - } - - uint8_t cLow = static_cast(qMin(static_cast(_sumBrightnessLow/rgbSum), static_cast(UINT8_MAX))); - red *= cLow; - green *= cLow; - blue *= cLow; + red = qMax(red, _sumBrightnessLow); + green = qMax(green, _sumBrightnessLow); + blue = qMax(blue, _sumBrightnessLow); } else { - red = static_cast(qMin(static_cast(_sumBrightnessLow/3.0), static_cast(UINT8_MAX))); - green = red; - blue = red; + // Average of min and max channel values for backlight decision + int minVal = qMin(red, qMin(green, blue)); + int maxVal = qMax(red, qMax(green, blue)); + int avVal = (minVal + maxVal) / 2; + if (avVal < _sumBrightnessLow) + { + red = _sumBrightnessLow; + green = _sumBrightnessLow; + blue = _sumBrightnessLow; + } } } } From 814287c98cb85ba4359699a4d5ca4828d731913a Mon Sep 17 00:00:00 2001 From: Thomas Emmel Date: Fri, 7 Nov 2025 11:07:33 +0100 Subject: [PATCH 2/7] Update includes --- libsrc/utils/RgbTransform.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libsrc/utils/RgbTransform.cpp b/libsrc/utils/RgbTransform.cpp index 20a88b175..050bb3e70 100644 --- a/libsrc/utils/RgbTransform.cpp +++ b/libsrc/utils/RgbTransform.cpp @@ -1,5 +1,8 @@ -#include #include + +#include +#include + #include RgbTransform::RgbTransform() From 703c16a898aaeaa45ada0dfe1225ccebbf2d5985 Mon Sep 17 00:00:00 2001 From: Thomas Emmel Date: Fri, 7 Nov 2025 11:13:45 +0100 Subject: [PATCH 3/7] Fix header --- libsrc/utils/RgbTransform.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsrc/utils/RgbTransform.cpp b/libsrc/utils/RgbTransform.cpp index 050bb3e70..617a8f492 100644 --- a/libsrc/utils/RgbTransform.cpp +++ b/libsrc/utils/RgbTransform.cpp @@ -1,7 +1,7 @@ #include #include -#include +#include #include From f88d979557af450de321a1a1d6f53b3ac80bcfe9 Mon Sep 17 00:00:00 2001 From: LordGrey <48840279+Lord-Grey@users.noreply.github.com> Date: Tue, 7 Oct 2025 21:43:29 +0200 Subject: [PATCH 4/7] HA: Apply luminance formula (#1922) --- CHANGELOG.md | 1 + .../dev_net/LedDeviceHomeAssistant.cpp | 22 ++++++++----------- .../schemas/schema-homeassistant.json | 2 +- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 88f3275d6..73d3d6be2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Hue Bridge - Alternate certificate support - Linux: New DRM/KMS screen grabber with plane-based capture - not feature complete yet - Logging/Tracing: Introduced qlogging categories to enable dynamic tracing +- Home Assistent: dynamically set brightness for higher dynamic range (#1922) --- diff --git a/libsrc/leddevice/dev_net/LedDeviceHomeAssistant.cpp b/libsrc/leddevice/dev_net/LedDeviceHomeAssistant.cpp index 02078ee5d..3b373348b 100644 --- a/libsrc/leddevice/dev_net/LedDeviceHomeAssistant.cpp +++ b/libsrc/leddevice/dev_net/LedDeviceHomeAssistant.cpp @@ -401,8 +401,6 @@ bool LedDeviceHomeAssistant::powerOff() int LedDeviceHomeAssistant::write(const std::vector& ledValues) { - int retVal = 0; - QJsonObject serviceAttributes{ {ENTITY_ID, QJsonArray::fromStringList(_lightEntityIds)} }; ColorRgb ledValue = ledValues.at(0); @@ -415,20 +413,18 @@ int LedDeviceHomeAssistant::write(const std::vector& ledValues) _restApi->setPath(API_LIGHT_TURN_ON); serviceAttributes.insert(RGB_COLOR, QJsonArray{ ledValue.red, ledValue.green, ledValue.blue }); - int brightness = _brightness; - - // Some devices cannot deal with a black color and brightness > 0 - if (ledValue == ColorRgb::BLACK) + int brightness; + if (!_isBrightnessOverwrite) { - brightness = 0; + brightness = qBound(0, qRound(0.2126 * ledValue.red + 0.7152 * ledValue.green + 0.0722 * ledValue.blue), 255); } - - // Add brightness attribute if applicable - if (brightness == 0 || _isBrightnessOverwrite) + else { - serviceAttributes.insert(BRIGHTNESS, brightness); + brightness = _brightness; } + serviceAttributes.insert(BRIGHTNESS, brightness); + if (_transitionTime > 0) { serviceAttributes.insert(TRANSITION, _transitionTime); @@ -438,8 +434,8 @@ int LedDeviceHomeAssistant::write(const std::vector& ledValues) if (response.error()) { Warning(_log, "Updating lights failed with error: '%s'", QSTRING_CSTR(response.getErrorReason())); - retVal = -1; + return -1; } - return retVal; + return 0; } diff --git a/libsrc/leddevice/schemas/schema-homeassistant.json b/libsrc/leddevice/schemas/schema-homeassistant.json index 03cf2cee4..f0bb9836d 100644 --- a/libsrc/leddevice/schemas/schema-homeassistant.json +++ b/libsrc/leddevice/schemas/schema-homeassistant.json @@ -53,7 +53,7 @@ "type": "boolean", "format": "checkbox", "title": "edt_dev_spec_brightnessOverwrite_title", - "default": true, + "default": false, "required": true, "access": "advanced", "propertyOrder": 6 From bf3b10713bfd0eff3aa8d492fabde9119745afcf Mon Sep 17 00:00:00 2001 From: Thomas Emmel Date: Fri, 7 Nov 2025 11:28:48 +0100 Subject: [PATCH 5/7] Update for Windows --- libsrc/utils/RgbTransform.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsrc/utils/RgbTransform.cpp b/libsrc/utils/RgbTransform.cpp index 617a8f492..0abfdd5c9 100644 --- a/libsrc/utils/RgbTransform.cpp +++ b/libsrc/utils/RgbTransform.cpp @@ -87,7 +87,7 @@ int RgbTransform::getBacklightThreshold() const void RgbTransform::setBacklightThreshold(int backlightThreshold) { _backlightThreshold = backlightThreshold; - _sumBrightnessLow = static_cast(qBound(0, _backlightThreshold, UINT8_MAX)); + _sumBrightnessLow = static_cast(qBound(0, _backlightThreshold, static_cast(UINT8_MAX))); } bool RgbTransform::getBacklightColored() const From 9e9bb14f0b3ee59cf4a7d25c2c9bf75d044cf9c2 Mon Sep 17 00:00:00 2001 From: Thomas Emmel Date: Fri, 7 Nov 2025 11:34:24 +0100 Subject: [PATCH 6/7] Fix typo --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 73d3d6be2..e941ac9b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,7 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Hue Bridge - Alternate certificate support - Linux: New DRM/KMS screen grabber with plane-based capture - not feature complete yet - Logging/Tracing: Introduced qlogging categories to enable dynamic tracing -- Home Assistent: dynamically set brightness for higher dynamic range (#1922) +- Home Assistant: Dynamically set brightness for higher dynamic range (#1922) --- From 493585b03045fd25b8d8ccafc8358753efcd7344 Mon Sep 17 00:00:00 2001 From: LordGrey <48840279+Lord-Grey@users.noreply.github.com> Date: Fri, 7 Nov 2025 14:53:50 +0100 Subject: [PATCH 7/7] RgbTransform.cpp aktualisieren Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- libsrc/utils/RgbTransform.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsrc/utils/RgbTransform.cpp b/libsrc/utils/RgbTransform.cpp index 0abfdd5c9..c86fa82ed 100644 --- a/libsrc/utils/RgbTransform.cpp +++ b/libsrc/utils/RgbTransform.cpp @@ -167,7 +167,7 @@ void RgbTransform::applyGamma(uint8_t & red, uint8_t & green, uint8_t & blue) co blue = _mappingB[blue]; } -void RgbTransform::applyBacklight(uint8_t &red, uint8_t &green, uint8_t &blue) const +void RgbTransform::applyBacklight(uint8_t & red, uint8_t & green, uint8_t & blue) const { if (_backLightEnabled && _sumBrightnessLow > 0) {