diff --git a/rtengine/iplabregions.cc b/rtengine/iplabregions.cc index 2a4d431e6..49a426afa 100644 --- a/rtengine/iplabregions.cc +++ b/rtengine/iplabregions.cc @@ -24,6 +24,9 @@ #include "improcfun.h" #include "guidedfilter.h" +#define BENCHMARK +#include "StopWatch.h" +#include "sleef.c" namespace rtengine { @@ -32,7 +35,7 @@ void ImProcFunctions::labColorCorrectionRegions(LabImage *lab) if (!params->colorToning.enabled || params->colorToning.method != "LabRegions") { return; } - +BENCHFUN int n = params->colorToning.labregions.size(); int show_mask_idx = params->colorToning.labregionsShowMask; if (show_mask_idx >= n) { @@ -64,7 +67,7 @@ void ImProcFunctions::labColorCorrectionRegions(LabImage *lab) abmask[i](lab->W, lab->H); Lmask[i](lab->W, lab->H); } - + #ifdef _OPENMP #pragma omp parallel for if (multiThread) #endif @@ -77,13 +80,13 @@ void ImProcFunctions::labColorCorrectionRegions(LabImage *lab) Color::Lab2Lch(a, b, c, h); // magic constant c_factor: normally chromaticity is in [0; 42000] (see color.h), but here we use the constant to match how the chromaticity pipette works (see improcfun.cc lines 4705-4706 and color.cc line 1930 constexpr float c_factor = 327.68f / 48000.f; - float c1 = lin2log(c * c_factor, 10.f); + float c1 = xlin2log(c * c_factor, 10.f); float h1 = Color::huelab_to_huehsv2(h); h1 = h1 + 1.f/6.f; // offset the hue because we start from purple instead of red if (h1 > 1.f) { h1 -= 1.f; } - h1 = lin2log(h1, 3.f); + h1 = xlin2log(h1, 3.f); float l1 = l / 32768.f; for (int i = begin_idx; i < end_idx; ++i) { @@ -132,7 +135,7 @@ void ImProcFunctions::labColorCorrectionRegions(LabImage *lab) const auto abcoord = [](float x) -> float { - return 12000.f * SGN(x) * log2lin(std::abs(x), 4.f); + return 12000.f * SGN(x) * xlog2lin(std::abs(x), 4.f); }; #ifdef _OPENMP diff --git a/rtengine/sleef.c b/rtengine/sleef.c index 901d04f7d..cc92be108 100644 --- a/rtengine/sleef.c +++ b/rtengine/sleef.c @@ -23,6 +23,7 @@ #define L2U .69314718055966295651160180568695068359375 #define L2L .28235290563031577122588448175013436025525412068e-12 #define R_LN2 1.442695040888963407359924681001892137426645954152985934135449406931 +#define pow_F(a,b) (xexpf(b*xlogf(a))) __inline int64_t doubleToRawLongBits(double d) { union { @@ -1263,6 +1264,16 @@ __inline float xdivf( float d, int n){ return uflint.floatval; } +__inline float xlin2log(float x, float base) +{ + constexpr float one(1); + return xlogf(x * (base - one) + one) / xlogf(base); +} +__inline float xlog2lin(float x, float base) +{ + constexpr float one(1); + return (pow_F(base, x) - one) / (base - one); +} #endif