Skip to content

Commit a9ea1b1

Browse files
committed
Clamped values during transform
1 parent fe501fb commit a9ea1b1

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

libsrc/utils/OkhsvTransform.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1+
#include <algorithm>
2+
13
#include <utils/OkhsvTransform.h>
24
#include <utils/ColorSys.h>
35

6+
/// Clamps between 0.f and 1.f. Should generally be branchless
7+
float clamp(float value)
8+
{
9+
return std::max(0.f, std::min(value, 1.f));
10+
}
11+
412
OkhsvTransform::OkhsvTransform()
513
{
614
_saturationGain = 1.0;
@@ -45,8 +53,8 @@ void OkhsvTransform::transform(uint8_t & red, uint8_t & green, uint8_t & blue)
4553
, value;
4654
ColorSys::rgb2okhsv(red, green, blue, hue, saturation, value);
4755

48-
saturation *= _saturationGain;
49-
value *= _valueGain;
56+
saturation = clamp(saturation * _saturationGain);
57+
value = clamp(value * _valueGain);
5058

5159
ColorSys::okhsv2rgb(hue, saturation, value, red, green, blue);
5260
}

0 commit comments

Comments
 (0)