mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
2fb2fc9dd7
* 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>
70 lines
1.4 KiB
C++
70 lines
1.4 KiB
C++
#include <algorithm>
|
|
|
|
#include <utils/OkhsvTransform.h>
|
|
#include <utils/ColorSys.h>
|
|
|
|
/// Clamps between 0.f and 1.f. Should generally be branchless
|
|
double clamp(double value)
|
|
{
|
|
return std::max(0.0, std::min(value, 1.0));
|
|
}
|
|
|
|
OkhsvTransform::OkhsvTransform()
|
|
{
|
|
_saturationGain = 1.0;
|
|
_brightnessGain = 1.0;
|
|
_isIdentity = true;
|
|
}
|
|
|
|
OkhsvTransform::OkhsvTransform(double saturationGain, double brightnessGain)
|
|
{
|
|
_saturationGain = saturationGain;
|
|
_brightnessGain = brightnessGain;
|
|
updateIsIdentity();
|
|
}
|
|
|
|
double OkhsvTransform::getSaturationGain() const
|
|
{
|
|
return _saturationGain;
|
|
}
|
|
|
|
void OkhsvTransform::setSaturationGain(double saturationGain)
|
|
{
|
|
_saturationGain = saturationGain;
|
|
updateIsIdentity();
|
|
}
|
|
|
|
double OkhsvTransform::getBrightnessGain() const
|
|
{
|
|
return _brightnessGain;
|
|
}
|
|
|
|
void OkhsvTransform::setBrightnessGain(double brightnessGain)
|
|
{
|
|
_brightnessGain= brightnessGain;
|
|
updateIsIdentity();
|
|
}
|
|
|
|
bool OkhsvTransform::isIdentity() const
|
|
{
|
|
return _isIdentity;
|
|
}
|
|
|
|
void OkhsvTransform::transform(uint8_t & red, uint8_t & green, uint8_t & blue) const
|
|
{
|
|
double hue;
|
|
double saturation;
|
|
double brightness;
|
|
ColorSys::rgb2okhsv(red, green, blue, hue, saturation, brightness);
|
|
|
|
saturation = clamp(saturation * _saturationGain);
|
|
brightness = clamp(brightness * _brightnessGain);
|
|
|
|
ColorSys::okhsv2rgb(hue, saturation, brightness, red, green, blue);
|
|
}
|
|
|
|
void OkhsvTransform::updateIsIdentity()
|
|
{
|
|
_isIdentity = _saturationGain == 1.0 && _brightnessGain == 1.0;
|
|
}
|