hyperion.ng/include/utils/OkhsvTransform.h
xkns 2fb2fc9dd7
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>
2022-08-17 23:26:19 +02:00

64 lines
1.5 KiB
C++

#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