mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Saturation & Brightness/Value Gain using Oklab color space (#1477)
* Imported Oklab reference implementation * Add Okhsv conversions * Fixed formatting error * Add saturation and value gain to schemas * Add english translation for saturation, value gain * Created OkhsvTransform * Make OkhsvTransform configurable * Apply OkhvsTransform * Clamped values during transform * Precalculate isIdentity in OkhsvTransform * Skip OkhsvTransform if it is the identity function * Added changelog message * Allow for full desaturation * Imported recommended changes by LordGrey * Fixed typo in constant * Fixed anti-pattern in ok_color.h * Correct indentions * Correct remote-control * Limited maximum gain settings to practical range * Renane valueGain to brightnessGain for clarity and understanding Co-authored-by: LordGrey <lordgrey.emmel@gmail.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
#ifndef COLORADJUSTMENT_H
|
||||
#define COLORADJUSTMENT_H
|
||||
|
||||
// STL includes
|
||||
#include <QString>
|
||||
@@ -6,6 +7,7 @@
|
||||
// Utils includes
|
||||
#include <utils/RgbChannelAdjustment.h>
|
||||
#include <utils/RgbTransform.h>
|
||||
#include <utils/OkhsvTransform.h>
|
||||
|
||||
class ColorAdjustment
|
||||
{
|
||||
@@ -31,4 +33,7 @@ public:
|
||||
RgbChannelAdjustment _rgbYellowAdjustment;
|
||||
|
||||
RgbTransform _rgbTransform;
|
||||
OkhsvTransform _okhsvTransform;
|
||||
};
|
||||
|
||||
#endif // COLORADJUSTMENT_H
|
||||
|
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
#ifndef COLORSYS_H
|
||||
#define COLORSYS_H
|
||||
|
||||
// STL includes
|
||||
#include <cstdint>
|
||||
@@ -76,4 +77,34 @@ public:
|
||||
/// @param[out] green The green RGB-component
|
||||
/// @param[out] blue The blue RGB-component
|
||||
static void yuv2rgb(uint8_t y, uint8_t u, uint8_t v, uint8_t & r, uint8_t & g, uint8_t & b);
|
||||
|
||||
///
|
||||
/// Translates an RGB (red, green, blue) color to an Okhsv (hue, saturation, value) 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 Okhsv-component
|
||||
/// @param[out] saturation The saturation Okhsv-component
|
||||
/// @param[out] value The value Okhsv-component
|
||||
///
|
||||
/// @note See https://bottosson.github.io/posts/colorpicker/#okhsv
|
||||
///
|
||||
static void rgb2okhsv(uint8_t red, uint8_t green, uint8_t blue, double & hue, double & saturation, double & value);
|
||||
|
||||
///
|
||||
/// Translates an Okhsv (hue, saturation, value) color to an RGB (red, green, blue) color
|
||||
///
|
||||
/// @param[in] hue The hue Okhsv-component
|
||||
/// @param[in] saturation The saturation Okhsv-component
|
||||
/// @param[in] value The value Okhsv-component
|
||||
/// @param[out] red The red RGB-component
|
||||
/// @param[out] green The green RGB-component
|
||||
/// @param[out] blue The blue RGB-component
|
||||
///
|
||||
/// @note See https://bottosson.github.io/posts/colorpicker/#okhsv
|
||||
///
|
||||
static void okhsv2rgb(double hue, double saturation, double value, uint8_t & red, uint8_t & green, uint8_t & blue);
|
||||
};
|
||||
|
||||
#endif // COLORSYS_H
|
||||
|
63
include/utils/OkhsvTransform.h
Normal file
63
include/utils/OkhsvTransform.h
Normal file
@@ -0,0 +1,63 @@
|
||||
#ifndef OKHSVTRANSFORM_H
|
||||
#define OKHSVTRANSFORM_H
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
///
|
||||
/// Color transformation to adjust the saturation and value of Okhsv colors
|
||||
///
|
||||
class OkhsvTransform
|
||||
{
|
||||
public:
|
||||
///
|
||||
/// Default constructor
|
||||
///
|
||||
OkhsvTransform();
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
/// @param saturationGain gain factor to apply to saturation
|
||||
/// @param brightnessGain gain factor to apply to value/brightness
|
||||
///
|
||||
OkhsvTransform(double saturationGain, double brightnessGain);
|
||||
|
||||
/// @return The current saturation gain value
|
||||
double getSaturationGain() const;
|
||||
|
||||
/// @param saturationGain new saturation gain
|
||||
void setSaturationGain(double saturationGain);
|
||||
|
||||
/// @return The current brightness gain value
|
||||
double getBrightnessGain() const;
|
||||
|
||||
/// @param brightnessGain new value/brightness gain
|
||||
void setBrightnessGain(double brightnessGain);
|
||||
|
||||
/// @return true if the current gain settings result in an identity transformation
|
||||
bool isIdentity() 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;
|
||||
|
||||
private:
|
||||
/// Sets _isIdentity to true if both gain values are at their neutral setting
|
||||
void updateIsIdentity();
|
||||
|
||||
/// Gain settings
|
||||
double _saturationGain;
|
||||
double _brightnessGain;
|
||||
|
||||
/// Is true if the gain settings result in an identity transformation
|
||||
bool _isIdentity;
|
||||
};
|
||||
|
||||
#endif // OKHSVTRANSFORM_H
|
@@ -81,6 +81,14 @@ namespace hyperion {
|
||||
return RgbTransform(gammaR, gammaG, gammaB, backlightThreshold, backlightColored, static_cast<uint8_t>(brightness), static_cast<uint8_t>(brightnessComp));
|
||||
}
|
||||
|
||||
OkhsvTransform createOkhsvTransform(const QJsonObject& colorConfig)
|
||||
{
|
||||
const double saturationGain = colorConfig["saturationGain"].toDouble(1.0);
|
||||
const double brightnessGain = colorConfig["brightnessGain"].toDouble(1.0);
|
||||
|
||||
return OkhsvTransform(saturationGain, brightnessGain);
|
||||
}
|
||||
|
||||
RgbChannelAdjustment createRgbChannelAdjustment(const QJsonObject& colorConfig, const QString& channelName, int defaultR, int defaultG, int defaultB)
|
||||
{
|
||||
const QJsonArray& channelConfig = colorConfig[channelName].toArray();
|
||||
@@ -107,6 +115,7 @@ namespace hyperion {
|
||||
adjustment->_rgbMagentaAdjustment = createRgbChannelAdjustment(adjustmentConfig, "magenta", 255, 0,255);
|
||||
adjustment->_rgbYellowAdjustment = createRgbChannelAdjustment(adjustmentConfig, "yellow" , 255,255, 0);
|
||||
adjustment->_rgbTransform = createRgbTransform(adjustmentConfig);
|
||||
adjustment->_okhsvTransform = createOkhsvTransform(adjustmentConfig);
|
||||
|
||||
return adjustment;
|
||||
}
|
||||
|
Reference in New Issue
Block a user