Skip to content

Commit

Permalink
Re-add Temperture adjustment (#1710)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Lord-Grey authored Dec 28, 2024
1 parent bc3ea9d commit d16142d
Show file tree
Hide file tree
Showing 22 changed files with 374 additions and 157 deletions.
12 changes: 6 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,12 @@ if(HYPERION_LIGHT)

# Disable Services
SET ( DEFAULT_EFFECTENGINE OFF )
#SET ( DEFAULT_EXPERIMENTAL OFF )
#SET ( DEFAULT_MDNS OFF )
#SET ( DEFAULT_REMOTE_CTL OFF )
#SET ( ENABLE_JSONCHECKS OFF )
#SET ( ENABLE_DEPLOY_DEPENDENCIES OFF )
SET ( DEFAULT_EXPERIMENTAL OFF )
#SET ( DEFAULT_MDNS OFF )
SET ( DEFAULT_REMOTE_CTL OFF )

SET ( ENABLE_JSONCHECKS ON )
SET ( ENABLE_DEPLOY_DEPENDENCIES ON )
endif()
message(STATUS "Grabber options:")

Expand Down
9 changes: 7 additions & 2 deletions assets/webconfig/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@
"edt_append_degree": "°",
"edt_append_frames": "frames",
"edt_append_hz": "Hz",
"edt_append_kelvin": "K",
"edt_append_leds": "LEDs",
"edt_append_ms": "ms",
"edt_append_ns": "ns",
Expand Down Expand Up @@ -319,6 +320,8 @@
"edt_conf_color_blue_title": "Blue",
"edt_conf_color_brightnessComp_expl": "Compensates brightness differences between red green blue, cyan magenta yellow and white. 100 means full compensation, 0 no compensation",
"edt_conf_color_brightnessComp_title": "Brightness compensation",
"edt_conf_color_brightnessGain_expl": "Adjusts the brightness of colors. 1.0 means no change, over 1.0 increases brightness, under 1.0 decreases brightness.",
"edt_conf_color_brightnessGain_title": "Brightness gain",
"edt_conf_color_brightness_expl": "set overall brightness of LEDs",
"edt_conf_color_brightness_title": "Brightness",
"edt_conf_color_channelAdjustment_header_expl": "Create color profiles that could be assigned to a specific component. Adjust color, gamma, brightness, compensation and more.",
Expand All @@ -345,10 +348,10 @@
"edt_conf_color_magenta_title": "Magenta",
"edt_conf_color_red_expl": "The calibrated red value.",
"edt_conf_color_red_title": "Red",
"edt_conf_color_temperature_expl": "Adjusts the corlor temperature.",
"edt_conf_color_temperature_title": "Temperature",
"edt_conf_color_saturationGain_expl": "Adjusts the saturation of colors. 1.0 means no change, over 1.0 increases saturation, under 1.0 desaturates.",
"edt_conf_color_saturationGain_title": "Saturation gain",
"edt_conf_color_brightnessGain_expl": "Adjusts the brightness of colors. 1.0 means no change, over 1.0 increases brightness, under 1.0 decreases brightness.",
"edt_conf_color_brightnessGain_title": "Brightness gain",
"edt_conf_color_reducedPixelSetFactorFactor_expl": "Evaluate only a set of pixels per LED area defined, Low ~25%, Medium ~10%, High ~6%",
"edt_conf_color_reducedPixelSetFactorFactor_title": "Reduced pixel processing",
"edt_conf_color_white_expl": "The calibrated white value.",
Expand Down Expand Up @@ -535,6 +538,8 @@
"edt_conf_smooth_heading_title": "Smoothing",
"edt_conf_smooth_interpolationRate_expl": "Speed of the calculation of smooth intermediate frames.",
"edt_conf_smooth_interpolationRate_title": "Interpolation Rate",
"edt_conf_smooth_outputRate_expl": "The output speed to your LED controller.",
"edt_conf_smooth_outputRate_title": "Output Rate",
"edt_conf_smooth_time_ms_expl": "How long should the smoothing gather pictures?",
"edt_conf_smooth_time_ms_title": "Time",
"edt_conf_smooth_type_expl": "Type of smoothing.",
Expand Down
7 changes: 4 additions & 3 deletions assets/webconfig/js/content_remote.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,12 @@ $(document).ready(function () {
sColor[key].key == "brightnessCompensation" ||
sColor[key].key == "backlightThreshold" ||
sColor[key].key == "saturationGain" ||
sColor[key].key == "brightnessGain") {
sColor[key].key == "brightnessGain" ||
sColor[key].key == "temperature" ) {

property = '<input id="cr_' + sColor[key].key + '" type="number" class="form-control" min="' + sColor[key].minimum + '" max="' + sColor[key].maximum + '" step="' + sColor[key].step + '" value="' + value + '"/>';
if (sColor[key].append === "edt_append_percent") {
property = '<div class="input-group">' + property + '<span class="input-group-addon">' + $.i18n("edt_append_percent") + '</span></div>';
if (sColor[key].append && sColor[key].append !== "" ) {
property = '<div class="input-group">' + property + '<span class="input-group-addon">' + $.i18n(sColor[key].append) + '</span></div>';
}
}
else {
Expand Down
3 changes: 2 additions & 1 deletion include/api/JsonAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@ private slots:
///
void handleSystemCommand(const QJsonObject &message, const JsonApiCommand& cmd);


void applyColorAdjustments(const QJsonObject &adjustment, ColorAdjustment *colorAdjustment);
void applyColorAdjustment(const QString &colorName, const QJsonObject &adjustment, RgbChannelAdjustment &rgbAdjustment);
void applyGammaTransform(const QString &transformName, const QJsonObject &adjustment, RgbTransform &rgbTransform, char channel);
Expand All @@ -296,6 +295,8 @@ private slots:
template<typename T>
void applyTransform(const QString &transformName, const QJsonObject &adjustment, T &transform, void (T::*setFunction)(double));
template<typename T>
void applyTransform(const QString &transformName, const QJsonObject &adjustment, T &transform, void (T::*setFunction)(int));
template<typename T>
void applyTransform(const QString &transformName, const QJsonObject &adjustment, T &transform, void (T::*setFunction)(uint8_t));

void handleTokenRequired(const JsonApiCommand& cmd);
Expand Down
2 changes: 1 addition & 1 deletion include/hyperion/ColorAdjustment.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef COLORADJUSTMENT_H
#define COLORADJUSTMENT_H

// STL includes
// Qt includes
#include <QString>

// Utils includes
Expand Down
6 changes: 3 additions & 3 deletions include/hyperion/MultiColorAdjustment.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class MultiColorAdjustment
*/
void addAdjustment(ColorAdjustment * adjustment);

void setAdjustmentForLed(const QString& id, int startLed, int endLed);
void setAdjustmentForLed(const QString& adjutmentId, int startLed, int endLed);

bool verifyAdjustments() const;

Expand All @@ -41,11 +41,11 @@ class MultiColorAdjustment
///
/// Returns the pointer to the ColorAdjustment with the given id
///
/// @param id The identifier of the ColorAdjustment
/// @param adjutmentId The identifier of the ColorAdjustment
///
/// @return The ColorAdjustment with the given id (or nullptr if it does not exist)
///
ColorAdjustment* getAdjustment(const QString& id);
ColorAdjustment* getAdjustment(const QString& adjutmentId);

///
/// Performs the color adjustment from raw-color to led-color
Expand Down
4 changes: 4 additions & 0 deletions include/utils/ColorRgb.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ struct ColorRgb
static const ColorRgb YELLOW;
/// 'White' RgbColor (255, 255, 255)
static const ColorRgb WHITE;
/// 'Cyan' RgbColor (0, 255, 255)
static const ColorRgb CYAN;
/// 'Magenta' RgbColor (255, 0,255)
static const ColorRgb MAGENTA;

ColorRgb() = default;

Expand Down
75 changes: 75 additions & 0 deletions include/utils/KelvinToRgb.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#ifndef KELVINTORGB_H
#define KELVINTORGB_H

#include <cmath>

#include <utils/ColorRgb.h>

// Constants
namespace ColorTemperature {
constexpr int MINIMUM {1000};
constexpr int MAXIMUM {40000};
constexpr int DEFAULT {6600};
}
//End of constants

static ColorRgb getRgbFromTemperature(int temperature)
{
//Temperature input in Kelvin valid in the range 1000 K to 40000 K. White light = 6600K
temperature = qBound(ColorTemperature::MINIMUM, temperature, ColorTemperature::MAXIMUM);

// All calculations require temperature / 100, so only do the conversion once.
temperature /= 100;

// Compute each color in turn.
int red;
int green;
int blue;

// red
if (temperature <= 66)
{
red = UINT8_MAX;
}
else
{
// Note: the R-squared value for this approximation is 0.988.
red = static_cast<int>(329.698727446 * (pow(temperature - 60, -0.1332047592)));
}

// green
if (temperature <= 66)
{
// Note: the R-squared value for this approximation is 0.996.
green = static_cast<int>(99.4708025861 * log(temperature) - 161.1195681661);

}
else
{
// Note: the R-squared value for this approximation is 0.987.
green = static_cast<int>(288.1221695283 * (pow(temperature - 60, -0.0755148492)));
}

// blue
if (temperature >= 66)
{
blue = UINT8_MAX;
}
else if (temperature <= 19)
{
blue = 0;
}
else
{
// Note: the R-squared value for this approximation is 0.998.
blue = static_cast<int>(138.5177312231 * log(temperature - 10) - 305.0447927307);
}

return {
static_cast<uint8_t>(qBound(0, red, static_cast<int>(UINT8_MAX))),
static_cast<uint8_t>(qBound(0, green, static_cast<int>(UINT8_MAX))),
static_cast<uint8_t>(qBound(0, blue, static_cast<int>(UINT8_MAX))),
};
}

#endif // KELVINTORGB_H
31 changes: 20 additions & 11 deletions include/utils/RgbChannelAdjustment.h
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
#pragma once

// STL includes
#include <cstdint>

#include <QString>
#include <utils/Logger.h>
#include <utils/ColorRgb.h>

/// Correction for a single color byte value
/// All configuration values are unsigned int and assume the color value to be between 0 and 255
class RgbChannelAdjustment
{
public:

/// Default constructor
RgbChannelAdjustment(QString channelName="");
explicit RgbChannelAdjustment(const QString& channelName="");

explicit RgbChannelAdjustment(const ColorRgb& adjust, const QString& channelName="");

/// Constructor
/// @param adjustR
/// @param adjustG
/// @param adjustB
RgbChannelAdjustment(uint8_t adjustR, uint8_t adjustG, uint8_t adjustB, QString channelName="");
explicit RgbChannelAdjustment(uint8_t adjustR, uint8_t adjustG, uint8_t adjustB, const QString& channelName="");

///
/// Transform the given array value
Expand All @@ -40,6 +44,7 @@ class RgbChannelAdjustment
/// @param adjustB
///
void setAdjustment(uint8_t adjustR, uint8_t adjustG, uint8_t adjustB);
void setAdjustment(const ColorRgb& adjust);

/// @return The current adjustR value
uint8_t getAdjustmentR() const;
Expand All @@ -51,24 +56,28 @@ class RgbChannelAdjustment
uint8_t getAdjustmentB() const;

private:
/// color channels
enum ColorChannel { RED=0, GREEN=1, BLUE=2 };

struct ColorMapping {
uint8_t red[256];
uint8_t green[256];
uint8_t blue[256];
};

/// reset init of color mapping
void resetInitialized();

/// The adjustment of RGB channel
uint8_t _adjust[3];

/// The mapping from input color to output color
uint8_t _mapping[3][256];

/// Name of this channel, usefull for debug messages
QString _channelName;

/// Logger instance
Logger * _log;

/// The adjustment of RGB channel
ColorRgb _adjust;

/// The mapping from input color to output color
ColorMapping _mapping;

/// bitfield to determine white value is alreade initialized
bool _initialized[256];

Expand Down
62 changes: 42 additions & 20 deletions include/utils/RgbTransform.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// STL includes
#include <cstdint>

#include <utils/ColorRgb.h>

///
/// Color transformation to adjust the saturation and value of a RGB color value
///
Expand All @@ -23,8 +25,9 @@ class RgbTransform
/// @param backlightThreshold The used lower brightness
/// @param backlightColored use color in backlight
/// @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);
RgbTransform(double gammaR, double gammaG, double gammaB, double backlightThreshold, bool backlightColored, uint8_t brightness, uint8_t brightnessCompensation, int temperature);

/// @return The current red gamma value
double getGammaR() const;
Expand Down Expand Up @@ -79,18 +82,33 @@ class RgbTransform
///
/// @note The values are updated in place.
///
void getBrightnessComponents(uint8_t & rgb, uint8_t & cmy, uint8_t & w) const;
void getBrightnessComponents(uint8_t & rgb, uint8_t & cmy, uint8_t & white) const;

///
/// Apply the transform the the given RGB values.
/// Apply Gamma the the given RGB values.
///
/// @param red The red color component
/// @param green The green color component
/// @param blue The blue color component
///
/// @note The values are updated in place.
///
void transform(uint8_t & red, uint8_t & green, uint8_t & blue);
void applyGamma(uint8_t & red, uint8_t & green, uint8_t & blue);

///
/// Apply Backlight the the given RGB values.
///
/// @param red The red color component
/// @param green The green color component
/// @param blue The blue color component
///
/// @note The values are updated in place.
///
void applyBacklight(uint8_t & red, uint8_t & green, uint8_t & blue) const;

int getTemperature() const;
void setTemperature(int temperature);
void applyTemperature(ColorRgb& color) const;

private:
///
Expand All @@ -103,34 +121,38 @@ class RgbTransform
/// @param backlightColored en/disable color in backlight
/// @param brightness The used brightness
/// @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);
void init(double gammaR, double gammaG, double gammaB, double backlightThreshold, bool backlightColored, uint8_t brightness, uint8_t brightnessCompensation, int temperature);

/// (re)-initilize the color mapping
void initializeMapping(); /// The saturation gain

void updateBrightnessComponents();

/// backlight variables
bool _backLightEnabled
, _backlightColored;
double _backlightThreshold
, _sumBrightnessLow;
bool _backLightEnabled;
bool _backlightColored;
double _backlightThreshold;
double _sumBrightnessLow;

/// gamma variables
double _gammaR
, _gammaG
, _gammaB;
double _gammaR;
double _gammaG;
double _gammaB;

/// The mapping from input color to output color
uint8_t _mappingR[256]
, _mappingG[256]
, _mappingB[256];
uint8_t _mappingR[256];
uint8_t _mappingG[256];
uint8_t _mappingB[256];

/// brightness variables
uint8_t _brightness
, _brightnessCompensation
, _brightness_rgb
, _brightness_cmy
, _brightness_w;
uint8_t _brightness;
uint8_t _brightnessCompensation;
uint8_t _brightness_rgb;
uint8_t _brightness_cmy;
uint8_t _brightness_w;

int _temperature;
ColorRgb _temperatureRGB;
};
Loading

0 comments on commit d16142d

Please sign in to comment.