mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Adjustment merge + new brightness settings (#359)
* add new rgbtransform * activate rgbtransform * integrate new transform and gamma in adjustment, disable transform * fix brighness limit * advance upper and lower thresholds * start removing color transform * adjust configs/schema * implement json for new color adjustment * finish hyperion-remote extension for new adjustment settings * fix typos * rename luminance to brightness fix jsonapi for new adjustment * fix some bugs in adjustments * fix i18n * fix gamma via json * now brighness values goes from 0-1 with 0.5 is the default for all brighness is equal between the channels. less 0.5 all channels scaled down to new brighness, above 0.5 if possible channel gets brighter - but brighness is not equal between the channels anymore brighness value curve is now exponential instead of linear - this feels more natural * hslv cleanup
This commit is contained in:
@@ -4,68 +4,36 @@
|
||||
#include <cstdint>
|
||||
|
||||
///
|
||||
/// Color transformation to adjust the saturation and value of a RGB color value
|
||||
/// Color transformation to adjust the saturation and luminance of a RGB color value
|
||||
///
|
||||
class HsvTransform
|
||||
class ColorSys
|
||||
{
|
||||
public:
|
||||
///
|
||||
/// Default constructor
|
||||
/// Translates an RGB (red, green, blue) color to an HSL (hue, saturation, luminance) color
|
||||
///
|
||||
HsvTransform();
|
||||
/// @param[in] red The red RGB-component
|
||||
/// @param[in] green The green RGB-component
|
||||
/// @param[in] blue The blue RGB-component
|
||||
/// @param[out] hue The hue HSL-component
|
||||
/// @param[out] saturation The saturation HSL-component
|
||||
/// @param[out] luminance The luminance HSL-component
|
||||
///
|
||||
|
||||
static void rgb2hsl(uint8_t red, uint8_t green, uint8_t blue, uint16_t & hue, float & saturation, float & luminance);
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
/// Translates an HSL (hue, saturation, luminance) color to an RGB (red, green, blue) color
|
||||
///
|
||||
/// @param saturationGain The used saturation gain
|
||||
/// @param valueGain The used value gain
|
||||
/// @param[in] hue The hue HSL-component
|
||||
/// @param[in] saturation The saturation HSL-component
|
||||
/// @param[in] luminance The luminance HSL-component
|
||||
/// @param[out] red The red RGB-component
|
||||
/// @param[out] green The green RGB-component
|
||||
/// @param[out] blue The blue RGB-component
|
||||
///
|
||||
HsvTransform(double saturationGain, double valueGain);
|
||||
|
||||
///
|
||||
/// Destructor
|
||||
///
|
||||
~HsvTransform();
|
||||
|
||||
///
|
||||
/// Updates the saturation gain
|
||||
///
|
||||
/// @param saturationGain New saturationGain
|
||||
///
|
||||
void setSaturationGain(double saturationGain);
|
||||
|
||||
///
|
||||
/// Returns the saturation gain
|
||||
///
|
||||
/// @return The current Saturation gain
|
||||
///
|
||||
double getSaturationGain() const;
|
||||
|
||||
///
|
||||
/// Updates the value gain
|
||||
///
|
||||
/// @param valueGain New value gain
|
||||
///
|
||||
void setValueGain(double valueGain);
|
||||
|
||||
///
|
||||
/// Returns the value gain
|
||||
///
|
||||
/// @return The current value gain
|
||||
///
|
||||
double getValueGain() const;
|
||||
|
||||
///
|
||||
/// Apply the transform 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) const;
|
||||
|
||||
static void hsl2rgb(uint16_t hue, float saturation, float luminance, uint8_t & red, uint8_t & green, uint8_t & blue);
|
||||
///
|
||||
/// Translates an RGB (red, green, blue) color to an HSV (hue, saturation, value) color
|
||||
///
|
||||
@@ -97,10 +65,4 @@ public:
|
||||
/// number and scaled between 0 and 360
|
||||
///
|
||||
static void hsv2rgb(uint16_t hue, uint8_t saturation, uint8_t value, uint8_t & red, uint8_t & green, uint8_t & blue);
|
||||
|
||||
private:
|
||||
/// The saturation gain
|
||||
double _saturationGain;
|
||||
/// The value gain
|
||||
double _valueGain;
|
||||
};
|
@@ -1,116 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
// STL includes
|
||||
#include <cstdint>
|
||||
|
||||
///
|
||||
/// Color transformation to adjust the saturation and luminance of a RGB color value
|
||||
///
|
||||
class HslTransform
|
||||
{
|
||||
public:
|
||||
///
|
||||
/// Default constructor
|
||||
///
|
||||
HslTransform();
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
/// @param saturationGain The used saturation gain
|
||||
/// @param luminanceGain The used luminance gain
|
||||
///
|
||||
HslTransform(double saturationGain, double luminanceGain, double luminanceMinimum);
|
||||
|
||||
///
|
||||
/// Destructor
|
||||
///
|
||||
~HslTransform();
|
||||
|
||||
///
|
||||
/// Updates the saturation gain
|
||||
///
|
||||
/// @param saturationGain New saturationGain
|
||||
///
|
||||
void setSaturationGain(double saturationGain);
|
||||
|
||||
///
|
||||
/// Returns the saturation gain
|
||||
///
|
||||
/// @return The current Saturation gain
|
||||
///
|
||||
double getSaturationGain() const;
|
||||
|
||||
///
|
||||
/// Updates the luminance gain
|
||||
///
|
||||
/// @param luminanceGain New luminance gain
|
||||
///
|
||||
void setLuminanceGain(double luminanceGain);
|
||||
|
||||
///
|
||||
/// Returns the luminance gain
|
||||
///
|
||||
/// @return The current luminance gain
|
||||
///
|
||||
double getLuminanceGain() const;
|
||||
|
||||
///
|
||||
/// Updates the luminance minimum
|
||||
///
|
||||
/// @param luminanceMinimum New luminance minimum
|
||||
///
|
||||
void setLuminanceMinimum(double luminanceMinimum);
|
||||
|
||||
///
|
||||
/// Returns the luminance minimum
|
||||
///
|
||||
/// @return The current luminance minimum
|
||||
///
|
||||
double getLuminanceMinimum() const;
|
||||
|
||||
///
|
||||
/// Apply the transform 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) const;
|
||||
|
||||
///
|
||||
/// Translates an RGB (red, green, blue) color to an HSL (hue, saturation, luminance) color
|
||||
///
|
||||
/// @param[in] red The red RGB-component
|
||||
/// @param[in] green The green RGB-component
|
||||
/// @param[in] blue The blue RGB-component
|
||||
/// @param[out] hue The hue HSL-component
|
||||
/// @param[out] saturation The saturation HSL-component
|
||||
/// @param[out] luminance The luminance HSL-component
|
||||
///
|
||||
|
||||
static void rgb2hsl(uint8_t red, uint8_t green, uint8_t blue, uint16_t & hue, float & saturation, float & luminance);
|
||||
|
||||
///
|
||||
/// Translates an HSL (hue, saturation, luminance) color to an RGB (red, green, blue) color
|
||||
///
|
||||
/// @param[in] hue The hue HSL-component
|
||||
/// @param[in] saturation The saturation HSL-component
|
||||
/// @param[in] luminance The luminance HSL-component
|
||||
/// @param[out] red The red RGB-component
|
||||
/// @param[out] green The green RGB-component
|
||||
/// @param[out] blue The blue RGB-component
|
||||
///
|
||||
|
||||
static void hsl2rgb(uint16_t hue, float saturation, float luminance, uint8_t & red, uint8_t & green, uint8_t & blue);
|
||||
|
||||
private:
|
||||
/// The saturation gain
|
||||
double _saturationGain;
|
||||
/// The luminance gain
|
||||
double _luminanceGain;
|
||||
/// The luminance minimum
|
||||
double _luminanceMinimum;
|
||||
};
|
@@ -1,86 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
// STL includes
|
||||
#include <cstdint>
|
||||
|
||||
/// Transform for a single color byte value
|
||||
///
|
||||
/// Transforms are applied in the following order:
|
||||
/// 1) a threshold is applied. All values below threshold will be set to zero
|
||||
/// 2) gamma color correction is applied
|
||||
/// 3) the output value is scaled from the [0:1] to [blacklevel:whitelevel]
|
||||
/// 4) finally, in case of a weird choice of parameters, the output is clamped between [0:1]
|
||||
///
|
||||
/// All configuration values are doubles and assume the color value to be between 0 and 1
|
||||
class RgbChannelTransform
|
||||
{
|
||||
public:
|
||||
/// Default constructor
|
||||
RgbChannelTransform();
|
||||
|
||||
/// Constructor
|
||||
/// @param threshold The minimum threshold
|
||||
/// @param gamma The gamma of the gamma-curve correction
|
||||
/// @param blacklevel The minimum value for the RGB-Channel
|
||||
/// @param whitelevel The maximum value for the RGB-Channel
|
||||
RgbChannelTransform(double threshold, double gamma, double blacklevel, double whitelevel);
|
||||
|
||||
/// Destructor
|
||||
~RgbChannelTransform();
|
||||
|
||||
/// setAdjustment RGB
|
||||
/// @param threshold The minimum threshold
|
||||
/// @param gamma The gamma of the gamma-curve correction
|
||||
/// @param blacklevel The minimum value for the RGB-Channel
|
||||
/// @param whitelevel The maximum value for the RGB-Channel
|
||||
void setTransform(double threshold, double gamma, double blacklevel, double whitelevel);
|
||||
|
||||
/// @return The current threshold value
|
||||
double getThreshold() const;
|
||||
|
||||
/// @param threshold New threshold value
|
||||
void setThreshold(double threshold);
|
||||
|
||||
/// @return The current gamma value
|
||||
double getGamma() const;
|
||||
|
||||
/// @param gamma New gamma value
|
||||
void setGamma(double gamma);
|
||||
|
||||
/// @return The current blacklevel value
|
||||
double getBlacklevel() const;
|
||||
|
||||
/// @param blacklevel New blacklevel value
|
||||
void setBlacklevel(double blacklevel);
|
||||
|
||||
/// @return The current whitelevel value
|
||||
double getWhitelevel() const;
|
||||
|
||||
/// @param whitelevel New whitelevel value
|
||||
void setWhitelevel(double whitelevel);
|
||||
|
||||
/// Transform the given byte value
|
||||
/// @param input The input color byte
|
||||
/// @return The transformed byte value
|
||||
uint8_t transform(uint8_t input) const
|
||||
{
|
||||
return _mapping[input];
|
||||
}
|
||||
|
||||
private:
|
||||
/// (re)-initilize the color mapping
|
||||
void initializeMapping();
|
||||
|
||||
private:
|
||||
/// The threshold value
|
||||
double _threshold;
|
||||
/// The gamma value
|
||||
double _gamma;
|
||||
/// The blacklevel
|
||||
double _blacklevel;
|
||||
/// The whitelevel
|
||||
double _whitelevel;
|
||||
|
||||
/// The mapping from input color to output color
|
||||
uint8_t _mapping[256];
|
||||
};
|
96
include/utils/RgbTransform.h
Normal file
96
include/utils/RgbTransform.h
Normal file
@@ -0,0 +1,96 @@
|
||||
#pragma once
|
||||
|
||||
// STL includes
|
||||
#include <cstdint>
|
||||
|
||||
///
|
||||
/// Color transformation to adjust the saturation and value of a RGB color value
|
||||
///
|
||||
class RgbTransform
|
||||
{
|
||||
public:
|
||||
///
|
||||
/// Default constructor
|
||||
///
|
||||
RgbTransform();
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
/// @param gammaR The used red gamma
|
||||
/// @param gammaG The used green gamma
|
||||
/// @param gammab The used blue gamma
|
||||
/// @param brightnessLow The used lower brightness
|
||||
/// @param brightnessHigh The used higher brightness
|
||||
///
|
||||
RgbTransform(double gammaR, double gammaG, double gammaB, double brightnessLow, double brightnessHigh);
|
||||
|
||||
///
|
||||
/// Destructor
|
||||
///
|
||||
~RgbTransform();
|
||||
|
||||
/// @return The current red gamma value
|
||||
double getGammaR() const;
|
||||
|
||||
/// @return The current green gamma value
|
||||
double getGammaG() const;
|
||||
|
||||
/// @return The current blue gamma value
|
||||
double getGammaB() const;
|
||||
|
||||
/// @param gamma New gamma value
|
||||
void setGamma(double gammaR,double gammaG=-1, double gammaB=-1);
|
||||
|
||||
/// @return The current lower brightness
|
||||
double getBrightnessMin() const;
|
||||
|
||||
/// @param gamma New lower brightness
|
||||
void setBrightnessMin(double brightness);
|
||||
|
||||
/// @return The current lower brightness
|
||||
double getBrightness() const;
|
||||
|
||||
/// @param gamma New lower brightness
|
||||
void setBrightness(double brightness);
|
||||
|
||||
///
|
||||
/// Apply the transform 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);
|
||||
|
||||
private:
|
||||
///
|
||||
/// init
|
||||
///
|
||||
/// @param gammaR The used red gamma
|
||||
/// @param gammaG The used green gamma
|
||||
/// @param gammab The used blue gamma
|
||||
/// @param brightnessLow The used lower brightness
|
||||
/// @param brightnessHigh The used higher brightness
|
||||
///
|
||||
void init(double gammaR, double gammaG, double gammaB, double brightnessLow, double brightnessHigh);
|
||||
|
||||
/// (re)-initilize the color mapping
|
||||
void initializeMapping(); /// The saturation gain
|
||||
|
||||
double _brightnessLow;
|
||||
double _brightnessHigh;
|
||||
double _sumBrightnessLow;
|
||||
double _sumBrightnessHigh;
|
||||
|
||||
double _gammaR;
|
||||
double _gammaG;
|
||||
double _gammaB;
|
||||
|
||||
/// The mapping from input color to output color
|
||||
uint8_t _mappingR[256];
|
||||
uint8_t _mappingG[256];
|
||||
uint8_t _mappingB[256];
|
||||
};
|
Reference in New Issue
Block a user