Skip to content

Commit 6b5bc18

Browse files
committed
Precalculate isIdentity in OkhsvTransform
1 parent a9ea1b1 commit 6b5bc18

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

include/utils/OkhsvTransform.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ class OkhsvTransform
4848
void transform(uint8_t & red, uint8_t & green, uint8_t & blue);
4949

5050
private:
51+
/// Sets _isIdentity to true if both gain values are at their neutral setting
52+
void updateIsIdentity();
53+
54+
/// Gain settings
5155
float _saturationGain
5256
, _valueGain;
57+
58+
/// Is true if the gain settings result in an identity transformation
59+
bool _isIdentity;
5360
};

libsrc/utils/OkhsvTransform.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ OkhsvTransform::OkhsvTransform()
1313
{
1414
_saturationGain = 1.0;
1515
_valueGain = 1.0;
16+
_isIdentity = true;
1617
}
1718

1819
OkhsvTransform::OkhsvTransform(float saturationGain, float valueGain)
1920
{
2021
_saturationGain = saturationGain;
2122
_valueGain = valueGain;
23+
updateIsIdentity();
2224
}
2325

2426
float OkhsvTransform::getSaturationGain() const
@@ -29,6 +31,7 @@ float OkhsvTransform::getSaturationGain() const
2931
void OkhsvTransform::setSaturationGain(float saturationGain)
3032
{
3133
_saturationGain = saturationGain;
34+
updateIsIdentity();
3235
}
3336

3437
float OkhsvTransform::getValueGain() const
@@ -39,11 +42,12 @@ float OkhsvTransform::getValueGain() const
3942
void OkhsvTransform::setValueGain(float valueGain)
4043
{
4144
_valueGain = valueGain;
45+
updateIsIdentity();
4246
}
4347

4448
bool OkhsvTransform::isIdentity() const
4549
{
46-
return getSaturationGain() == 1.0f && getValueGain() == 1.0f;
50+
return _isIdentity;
4751
}
4852

4953
void OkhsvTransform::transform(uint8_t & red, uint8_t & green, uint8_t & blue)
@@ -58,3 +62,8 @@ void OkhsvTransform::transform(uint8_t & red, uint8_t & green, uint8_t & blue)
5862

5963
ColorSys::okhsv2rgb(hue, saturation, value, red, green, blue);
6064
}
65+
66+
void OkhsvTransform::updateIsIdentity()
67+
{
68+
_isIdentity = _saturationGain == 1.f && _valueGain == 1.5;
69+
}

0 commit comments

Comments
 (0)