Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 Assistant: Dynamically set brightness for higher dynamic range (#1922)

---

Expand All @@ -41,6 +42,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)

---

Expand Down
12 changes: 6 additions & 6 deletions include/utils/RgbTransform.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion libsrc/hyperion/MultiColorAdjustment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,6 @@ void MultiColorAdjustment::applyAdjustment(std::vector<ColorRgb>& 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);
}
}
22 changes: 9 additions & 13 deletions libsrc/leddevice/dev_net/LedDeviceHomeAssistant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,6 @@ bool LedDeviceHomeAssistant::powerOff()

int LedDeviceHomeAssistant::write(const std::vector<ColorRgb>& ledValues)
{
int retVal = 0;

QJsonObject serviceAttributes{ {ENTITY_ID, QJsonArray::fromStringList(_lightEntityIds)} };
ColorRgb ledValue = ledValues.at(0);

Expand All @@ -415,20 +413,18 @@ int LedDeviceHomeAssistant::write(const std::vector<ColorRgb>& 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);
Expand All @@ -438,8 +434,8 @@ int LedDeviceHomeAssistant::write(const std::vector<ColorRgb>& ledValues)
if (response.error())
{
Warning(_log, "Updating lights failed with error: '%s'", QSTRING_CSTR(response.getErrorReason()));
retVal = -1;
return -1;
}

return retVal;
return 0;
}
2 changes: 1 addition & 1 deletion libsrc/leddevice/schemas/schema-homeassistant.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"type": "boolean",
"format": "checkbox",
"title": "edt_dev_spec_brightnessOverwrite_title",
"default": true,
"default": false,
"required": true,
"access": "advanced",
"propertyOrder": 6
Expand Down
60 changes: 29 additions & 31 deletions libsrc/utils/RgbTransform.cpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
#include <QtCore/qmath.h>
#include <utils/RgbTransform.h>

#include <QtMath>
#include <QtGlobal>

#include <utils/KelvinToRgb.h>

RgbTransform::RgbTransform()
: 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, 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);
Expand Down Expand Up @@ -64,9 +67,9 @@ void RgbTransform::initializeMapping()
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)));
auto clampedValueR = static_cast<quint8>(qBound(0.0, gammaCorrectedValueR, static_cast<double>(UINT8_MAX)));
auto clampedValueG = static_cast<quint8>(qBound(0.0, gammaCorrectedValueG, static_cast<double>(UINT8_MAX)));
auto clampedValueB = static_cast<quint8>(qBound(0.0, gammaCorrectedValueB, static_cast<double>(UINT8_MAX)));

// Assign clamped values to _mapping arrays
_mappingR[i] = clampedValueR;
Expand All @@ -78,13 +81,13 @@ void RgbTransform::initializeMapping()

int RgbTransform::getBacklightThreshold() const
{
return static_cast<int>(_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<uint8_t>(qBound(0, _backlightThreshold, static_cast<int>(UINT8_MAX)));
}

bool RgbTransform::getBacklightColored() const
Expand Down Expand Up @@ -153,10 +156,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];
Expand All @@ -166,31 +169,26 @@ void RgbTransform::applyGamma(uint8_t & red, uint8_t & green, uint8_t & 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)
{
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<uint8_t>(qMin(static_cast<double>(_sumBrightnessLow/rgbSum), static_cast<double>(UINT8_MAX)));
red *= cLow;
green *= cLow;
blue *= cLow;
red = qMax(red, _sumBrightnessLow);
green = qMax(green, _sumBrightnessLow);
blue = qMax(blue, _sumBrightnessLow);
}
else
{
red = static_cast<uint8_t>(qMin(static_cast<double>(_sumBrightnessLow/3.0), static_cast<double>(UINT8_MAX)));
green = red;
blue = red;
// Average of min and max channel values for backlight decision
int minVal = qMin<int>(red, qMin<int>(green, blue));
int maxVal = qMax<int>(red, qMax<int>(green, blue));
int avVal = (minVal + maxVal) / 2;
if (avVal < _sumBrightnessLow)
{
red = _sumBrightnessLow;
green = _sumBrightnessLow;
blue = _sumBrightnessLow;
}
}
}
}
Expand Down
Loading