Small (~ 4%) speedup for perceptual tone curve

This commit is contained in:
heckflosse 2017-12-31 16:58:06 +01:00
parent 4c3e7b8efa
commit 057861b882
2 changed files with 9 additions and 10 deletions

View File

@ -1822,7 +1822,7 @@ float PerceptualToneCurve::calculateToneCurveContrastValue() const
return maxslope;
}
void PerceptualToneCurve::Apply(float &r, float &g, float &b, PerceptualToneCurveState & state) const
void PerceptualToneCurve::Apply(float &r, float &g, float &b, const PerceptualToneCurveState &state) const
{
float x, y, z;
@ -2012,14 +2012,13 @@ void PerceptualToneCurve::Apply(float &r, float &g, float &b, PerceptualToneCurv
// we use the RGB-HSV hue-stable "Adobe" curve as reference. For S-curve contrast it increases
// saturation greatly, but desaturates extreme highlights and thus provide a smooth transition to
// the white point. However the desaturation effect is quite strong so we make a weighting
float ah, as, av, h, s, v;
Color::rgb2hsv(ar, ag, ab, ah, as, av);
Color::rgb2hsv(r, g, b, h, s, v);
float as = Color::rgb2s(ar, ag, ab);
float s = Color::rgb2s(r, g, b);
float sat_scale = as <= 0.f ? 1.f : s / as; // saturation scale compared to Adobe curve
float keep = 0.2f;
const float lolim = 1.00f; // only mix in the Adobe curve if we have increased saturation compared to it
const float hilim = 1.20f;
constexpr float lolim = 1.00f; // only mix in the Adobe curve if we have increased saturation compared to it
constexpr float hilim = 1.20f;
if (sat_scale < lolim) {
// saturation is low enough, don't desaturate
@ -2041,9 +2040,9 @@ void PerceptualToneCurve::Apply(float &r, float &g, float &b, PerceptualToneCurv
if (keep < 1.f) {
// mix in some of the Adobe curve result
r = r * keep + (1.f - keep) * ar;
g = g * keep + (1.f - keep) * ag;
b = b * keep + (1.f - keep) * ab;
r = intp(keep, r, ar);
g = intp(keep, g, ag);
b = intp(keep, b, ab);
}
}

View File

@ -868,7 +868,7 @@ private:
public:
static void init();
void initApplyState(PerceptualToneCurveState & state, Glib::ustring workingSpace) const;
void Apply(float& r, float& g, float& b, PerceptualToneCurveState & state) const;
void Apply(float& r, float& g, float& b, const PerceptualToneCurveState &state) const;
};
// Standard tone curve