Skip to content

Commit d16142d

Browse files
authoredDec 28, 2024··
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
1 parent bc3ea9d commit d16142d

22 files changed

+374
-157
lines changed
 

‎CMakeLists.txt

+6-6
Original file line numberDiff line numberDiff line change
@@ -263,12 +263,12 @@ if(HYPERION_LIGHT)
263263

264264
# Disable Services
265265
SET ( DEFAULT_EFFECTENGINE OFF )
266-
#SET ( DEFAULT_EXPERIMENTAL OFF )
267-
#SET ( DEFAULT_MDNS OFF )
268-
#SET ( DEFAULT_REMOTE_CTL OFF )
269-
270-
#SET ( ENABLE_JSONCHECKS OFF )
271-
#SET ( ENABLE_DEPLOY_DEPENDENCIES OFF )
266+
SET ( DEFAULT_EXPERIMENTAL OFF )
267+
#SET ( DEFAULT_MDNS OFF )
268+
SET ( DEFAULT_REMOTE_CTL OFF )
269+
270+
SET ( ENABLE_JSONCHECKS ON )
271+
SET ( ENABLE_DEPLOY_DEPENDENCIES ON )
272272
endif()
273273
message(STATUS "Grabber options:")
274274

‎assets/webconfig/i18n/en.json

+7-2
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@
248248
"edt_append_degree": "°",
249249
"edt_append_frames": "frames",
250250
"edt_append_hz": "Hz",
251+
"edt_append_kelvin": "K",
251252
"edt_append_leds": "LEDs",
252253
"edt_append_ms": "ms",
253254
"edt_append_ns": "ns",
@@ -319,6 +320,8 @@
319320
"edt_conf_color_blue_title": "Blue",
320321
"edt_conf_color_brightnessComp_expl": "Compensates brightness differences between red green blue, cyan magenta yellow and white. 100 means full compensation, 0 no compensation",
321322
"edt_conf_color_brightnessComp_title": "Brightness compensation",
323+
"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.",
324+
"edt_conf_color_brightnessGain_title": "Brightness gain",
322325
"edt_conf_color_brightness_expl": "set overall brightness of LEDs",
323326
"edt_conf_color_brightness_title": "Brightness",
324327
"edt_conf_color_channelAdjustment_header_expl": "Create color profiles that could be assigned to a specific component. Adjust color, gamma, brightness, compensation and more.",
@@ -345,10 +348,10 @@
345348
"edt_conf_color_magenta_title": "Magenta",
346349
"edt_conf_color_red_expl": "The calibrated red value.",
347350
"edt_conf_color_red_title": "Red",
351+
"edt_conf_color_temperature_expl": "Adjusts the corlor temperature.",
352+
"edt_conf_color_temperature_title": "Temperature",
348353
"edt_conf_color_saturationGain_expl": "Adjusts the saturation of colors. 1.0 means no change, over 1.0 increases saturation, under 1.0 desaturates.",
349354
"edt_conf_color_saturationGain_title": "Saturation gain",
350-
"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.",
351-
"edt_conf_color_brightnessGain_title": "Brightness gain",
352355
"edt_conf_color_reducedPixelSetFactorFactor_expl": "Evaluate only a set of pixels per LED area defined, Low ~25%, Medium ~10%, High ~6%",
353356
"edt_conf_color_reducedPixelSetFactorFactor_title": "Reduced pixel processing",
354357
"edt_conf_color_white_expl": "The calibrated white value.",
@@ -535,6 +538,8 @@
535538
"edt_conf_smooth_heading_title": "Smoothing",
536539
"edt_conf_smooth_interpolationRate_expl": "Speed of the calculation of smooth intermediate frames.",
537540
"edt_conf_smooth_interpolationRate_title": "Interpolation Rate",
541+
"edt_conf_smooth_outputRate_expl": "The output speed to your LED controller.",
542+
"edt_conf_smooth_outputRate_title": "Output Rate",
538543
"edt_conf_smooth_time_ms_expl": "How long should the smoothing gather pictures?",
539544
"edt_conf_smooth_time_ms_title": "Time",
540545
"edt_conf_smooth_type_expl": "Type of smoothing.",

‎assets/webconfig/js/content_remote.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,12 @@ $(document).ready(function () {
7575
sColor[key].key == "brightnessCompensation" ||
7676
sColor[key].key == "backlightThreshold" ||
7777
sColor[key].key == "saturationGain" ||
78-
sColor[key].key == "brightnessGain") {
78+
sColor[key].key == "brightnessGain" ||
79+
sColor[key].key == "temperature" ) {
7980

8081
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 + '"/>';
81-
if (sColor[key].append === "edt_append_percent") {
82-
property = '<div class="input-group">' + property + '<span class="input-group-addon">' + $.i18n("edt_append_percent") + '</span></div>';
82+
if (sColor[key].append && sColor[key].append !== "" ) {
83+
property = '<div class="input-group">' + property + '<span class="input-group-addon">' + $.i18n(sColor[key].append) + '</span></div>';
8384
}
8485
}
8586
else {

‎include/api/JsonAPI.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,6 @@ private slots:
285285
///
286286
void handleSystemCommand(const QJsonObject &message, const JsonApiCommand& cmd);
287287

288-
289288
void applyColorAdjustments(const QJsonObject &adjustment, ColorAdjustment *colorAdjustment);
290289
void applyColorAdjustment(const QString &colorName, const QJsonObject &adjustment, RgbChannelAdjustment &rgbAdjustment);
291290
void applyGammaTransform(const QString &transformName, const QJsonObject &adjustment, RgbTransform &rgbTransform, char channel);
@@ -296,6 +295,8 @@ private slots:
296295
template<typename T>
297296
void applyTransform(const QString &transformName, const QJsonObject &adjustment, T &transform, void (T::*setFunction)(double));
298297
template<typename T>
298+
void applyTransform(const QString &transformName, const QJsonObject &adjustment, T &transform, void (T::*setFunction)(int));
299+
template<typename T>
299300
void applyTransform(const QString &transformName, const QJsonObject &adjustment, T &transform, void (T::*setFunction)(uint8_t));
300301

301302
void handleTokenRequired(const JsonApiCommand& cmd);

‎include/hyperion/ColorAdjustment.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef COLORADJUSTMENT_H
22
#define COLORADJUSTMENT_H
33

4-
// STL includes
4+
// Qt includes
55
#include <QString>
66

77
// Utils includes

‎include/hyperion/MultiColorAdjustment.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class MultiColorAdjustment
2626
*/
2727
void addAdjustment(ColorAdjustment * adjustment);
2828

29-
void setAdjustmentForLed(const QString& id, int startLed, int endLed);
29+
void setAdjustmentForLed(const QString& adjutmentId, int startLed, int endLed);
3030

3131
bool verifyAdjustments() const;
3232

@@ -41,11 +41,11 @@ class MultiColorAdjustment
4141
///
4242
/// Returns the pointer to the ColorAdjustment with the given id
4343
///
44-
/// @param id The identifier of the ColorAdjustment
44+
/// @param adjutmentId The identifier of the ColorAdjustment
4545
///
4646
/// @return The ColorAdjustment with the given id (or nullptr if it does not exist)
4747
///
48-
ColorAdjustment* getAdjustment(const QString& id);
48+
ColorAdjustment* getAdjustment(const QString& adjutmentId);
4949

5050
///
5151
/// Performs the color adjustment from raw-color to led-color

‎include/utils/ColorRgb.h

+4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ struct ColorRgb
3333
static const ColorRgb YELLOW;
3434
/// 'White' RgbColor (255, 255, 255)
3535
static const ColorRgb WHITE;
36+
/// 'Cyan' RgbColor (0, 255, 255)
37+
static const ColorRgb CYAN;
38+
/// 'Magenta' RgbColor (255, 0,255)
39+
static const ColorRgb MAGENTA;
3640

3741
ColorRgb() = default;
3842

‎include/utils/KelvinToRgb.h

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#ifndef KELVINTORGB_H
2+
#define KELVINTORGB_H
3+
4+
#include <cmath>
5+
6+
#include <utils/ColorRgb.h>
7+
8+
// Constants
9+
namespace ColorTemperature {
10+
constexpr int MINIMUM {1000};
11+
constexpr int MAXIMUM {40000};
12+
constexpr int DEFAULT {6600};
13+
}
14+
//End of constants
15+
16+
static ColorRgb getRgbFromTemperature(int temperature)
17+
{
18+
//Temperature input in Kelvin valid in the range 1000 K to 40000 K. White light = 6600K
19+
temperature = qBound(ColorTemperature::MINIMUM, temperature, ColorTemperature::MAXIMUM);
20+
21+
// All calculations require temperature / 100, so only do the conversion once.
22+
temperature /= 100;
23+
24+
// Compute each color in turn.
25+
int red;
26+
int green;
27+
int blue;
28+
29+
// red
30+
if (temperature <= 66)
31+
{
32+
red = UINT8_MAX;
33+
}
34+
else
35+
{
36+
// Note: the R-squared value for this approximation is 0.988.
37+
red = static_cast<int>(329.698727446 * (pow(temperature - 60, -0.1332047592)));
38+
}
39+
40+
// green
41+
if (temperature <= 66)
42+
{
43+
// Note: the R-squared value for this approximation is 0.996.
44+
green = static_cast<int>(99.4708025861 * log(temperature) - 161.1195681661);
45+
46+
}
47+
else
48+
{
49+
// Note: the R-squared value for this approximation is 0.987.
50+
green = static_cast<int>(288.1221695283 * (pow(temperature - 60, -0.0755148492)));
51+
}
52+
53+
// blue
54+
if (temperature >= 66)
55+
{
56+
blue = UINT8_MAX;
57+
}
58+
else if (temperature <= 19)
59+
{
60+
blue = 0;
61+
}
62+
else
63+
{
64+
// Note: the R-squared value for this approximation is 0.998.
65+
blue = static_cast<int>(138.5177312231 * log(temperature - 10) - 305.0447927307);
66+
}
67+
68+
return {
69+
static_cast<uint8_t>(qBound(0, red, static_cast<int>(UINT8_MAX))),
70+
static_cast<uint8_t>(qBound(0, green, static_cast<int>(UINT8_MAX))),
71+
static_cast<uint8_t>(qBound(0, blue, static_cast<int>(UINT8_MAX))),
72+
};
73+
}
74+
75+
#endif // KELVINTORGB_H

‎include/utils/RgbChannelAdjustment.h

+20-11
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
#pragma once
22

3-
// STL includes
43
#include <cstdint>
4+
55
#include <QString>
66
#include <utils/Logger.h>
7+
#include <utils/ColorRgb.h>
78

89
/// Correction for a single color byte value
910
/// All configuration values are unsigned int and assume the color value to be between 0 and 255
1011
class RgbChannelAdjustment
1112
{
1213
public:
14+
1315
/// Default constructor
14-
RgbChannelAdjustment(QString channelName="");
16+
explicit RgbChannelAdjustment(const QString& channelName="");
17+
18+
explicit RgbChannelAdjustment(const ColorRgb& adjust, const QString& channelName="");
1519

1620
/// Constructor
1721
/// @param adjustR
1822
/// @param adjustG
1923
/// @param adjustB
20-
RgbChannelAdjustment(uint8_t adjustR, uint8_t adjustG, uint8_t adjustB, QString channelName="");
24+
explicit RgbChannelAdjustment(uint8_t adjustR, uint8_t adjustG, uint8_t adjustB, const QString& channelName="");
2125

2226
///
2327
/// Transform the given array value
@@ -40,6 +44,7 @@ class RgbChannelAdjustment
4044
/// @param adjustB
4145
///
4246
void setAdjustment(uint8_t adjustR, uint8_t adjustG, uint8_t adjustB);
47+
void setAdjustment(const ColorRgb& adjust);
4348

4449
/// @return The current adjustR value
4550
uint8_t getAdjustmentR() const;
@@ -51,24 +56,28 @@ class RgbChannelAdjustment
5156
uint8_t getAdjustmentB() const;
5257

5358
private:
54-
/// color channels
55-
enum ColorChannel { RED=0, GREEN=1, BLUE=2 };
59+
60+
struct ColorMapping {
61+
uint8_t red[256];
62+
uint8_t green[256];
63+
uint8_t blue[256];
64+
};
5665

5766
/// reset init of color mapping
5867
void resetInitialized();
5968

60-
/// The adjustment of RGB channel
61-
uint8_t _adjust[3];
62-
63-
/// The mapping from input color to output color
64-
uint8_t _mapping[3][256];
65-
6669
/// Name of this channel, usefull for debug messages
6770
QString _channelName;
6871

6972
/// Logger instance
7073
Logger * _log;
7174

75+
/// The adjustment of RGB channel
76+
ColorRgb _adjust;
77+
78+
/// The mapping from input color to output color
79+
ColorMapping _mapping;
80+
7281
/// bitfield to determine white value is alreade initialized
7382
bool _initialized[256];
7483

‎include/utils/RgbTransform.h

+42-20
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// STL includes
44
#include <cstdint>
55

6+
#include <utils/ColorRgb.h>
7+
68
///
79
/// Color transformation to adjust the saturation and value of a RGB color value
810
///
@@ -23,8 +25,9 @@ class RgbTransform
2325
/// @param backlightThreshold The used lower brightness
2426
/// @param backlightColored use color in backlight
2527
/// @param brightnessHigh The used higher brightness
28+
/// @param temeprature The given color temperature (in Kelvin)
2629
///
27-
RgbTransform(double gammaR, double gammaG, double gammaB, double backlightThreshold, bool backlightColored, uint8_t brightness, uint8_t brightnessCompensation);
30+
RgbTransform(double gammaR, double gammaG, double gammaB, double backlightThreshold, bool backlightColored, uint8_t brightness, uint8_t brightnessCompensation, int temperature);
2831

2932
/// @return The current red gamma value
3033
double getGammaR() const;
@@ -79,18 +82,33 @@ class RgbTransform
7982
///
8083
/// @note The values are updated in place.
8184
///
82-
void getBrightnessComponents(uint8_t & rgb, uint8_t & cmy, uint8_t & w) const;
85+
void getBrightnessComponents(uint8_t & rgb, uint8_t & cmy, uint8_t & white) const;
8386

8487
///
85-
/// Apply the transform the the given RGB values.
88+
/// Apply Gamma the the given RGB values.
8689
///
8790
/// @param red The red color component
8891
/// @param green The green color component
8992
/// @param blue The blue color component
9093
///
9194
/// @note The values are updated in place.
9295
///
93-
void transform(uint8_t & red, uint8_t & green, uint8_t & blue);
96+
void applyGamma(uint8_t & red, uint8_t & green, uint8_t & blue);
97+
98+
///
99+
/// Apply Backlight the the given RGB values.
100+
///
101+
/// @param red The red color component
102+
/// @param green The green color component
103+
/// @param blue The blue color component
104+
///
105+
/// @note The values are updated in place.
106+
///
107+
void applyBacklight(uint8_t & red, uint8_t & green, uint8_t & blue) const;
108+
109+
int getTemperature() const;
110+
void setTemperature(int temperature);
111+
void applyTemperature(ColorRgb& color) const;
94112

95113
private:
96114
///
@@ -103,34 +121,38 @@ class RgbTransform
103121
/// @param backlightColored en/disable color in backlight
104122
/// @param brightness The used brightness
105123
/// @param brightnessCompensation The used brightness compensation
124+
/// @param temeprature apply the given color temperature (in Kelvin)
106125
///
107-
void init(double gammaR, double gammaG, double gammaB, double backlightThreshold, bool backlightColored, uint8_t brightness, uint8_t brightnessCompensation);
126+
void init(double gammaR, double gammaG, double gammaB, double backlightThreshold, bool backlightColored, uint8_t brightness, uint8_t brightnessCompensation, int temperature);
108127

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

112131
void updateBrightnessComponents();
113132

114133
/// backlight variables
115-
bool _backLightEnabled
116-
, _backlightColored;
117-
double _backlightThreshold
118-
, _sumBrightnessLow;
134+
bool _backLightEnabled;
135+
bool _backlightColored;
136+
double _backlightThreshold;
137+
double _sumBrightnessLow;
119138

120139
/// gamma variables
121-
double _gammaR
122-
, _gammaG
123-
, _gammaB;
140+
double _gammaR;
141+
double _gammaG;
142+
double _gammaB;
124143

125144
/// The mapping from input color to output color
126-
uint8_t _mappingR[256]
127-
, _mappingG[256]
128-
, _mappingB[256];
145+
uint8_t _mappingR[256];
146+
uint8_t _mappingG[256];
147+
uint8_t _mappingB[256];
129148

130149
/// brightness variables
131-
uint8_t _brightness
132-
, _brightnessCompensation
133-
, _brightness_rgb
134-
, _brightness_cmy
135-
, _brightness_w;
150+
uint8_t _brightness;
151+
uint8_t _brightnessCompensation;
152+
uint8_t _brightness_rgb;
153+
uint8_t _brightness_cmy;
154+
uint8_t _brightness_w;
155+
156+
int _temperature;
157+
ColorRgb _temperatureRGB;
136158
};

0 commit comments

Comments
 (0)
Please sign in to comment.