Colortoning Lab regions: use xlogf and xexpf from sleef.c, #4914
This commit is contained in:
parent
5e30b5ac58
commit
41b802bdd3
@ -24,6 +24,9 @@
|
|||||||
|
|
||||||
#include "improcfun.h"
|
#include "improcfun.h"
|
||||||
#include "guidedfilter.h"
|
#include "guidedfilter.h"
|
||||||
|
#define BENCHMARK
|
||||||
|
#include "StopWatch.h"
|
||||||
|
#include "sleef.c"
|
||||||
|
|
||||||
namespace rtengine {
|
namespace rtengine {
|
||||||
|
|
||||||
@ -32,7 +35,7 @@ void ImProcFunctions::labColorCorrectionRegions(LabImage *lab)
|
|||||||
if (!params->colorToning.enabled || params->colorToning.method != "LabRegions") {
|
if (!params->colorToning.enabled || params->colorToning.method != "LabRegions") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
BENCHFUN
|
||||||
int n = params->colorToning.labregions.size();
|
int n = params->colorToning.labregions.size();
|
||||||
int show_mask_idx = params->colorToning.labregionsShowMask;
|
int show_mask_idx = params->colorToning.labregionsShowMask;
|
||||||
if (show_mask_idx >= n) {
|
if (show_mask_idx >= n) {
|
||||||
@ -77,13 +80,13 @@ void ImProcFunctions::labColorCorrectionRegions(LabImage *lab)
|
|||||||
Color::Lab2Lch(a, b, c, h);
|
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
|
// 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;
|
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);
|
float h1 = Color::huelab_to_huehsv2(h);
|
||||||
h1 = h1 + 1.f/6.f; // offset the hue because we start from purple instead of red
|
h1 = h1 + 1.f/6.f; // offset the hue because we start from purple instead of red
|
||||||
if (h1 > 1.f) {
|
if (h1 > 1.f) {
|
||||||
h1 -= 1.f;
|
h1 -= 1.f;
|
||||||
}
|
}
|
||||||
h1 = lin2log(h1, 3.f);
|
h1 = xlin2log(h1, 3.f);
|
||||||
float l1 = l / 32768.f;
|
float l1 = l / 32768.f;
|
||||||
|
|
||||||
for (int i = begin_idx; i < end_idx; ++i) {
|
for (int i = begin_idx; i < end_idx; ++i) {
|
||||||
@ -132,7 +135,7 @@ void ImProcFunctions::labColorCorrectionRegions(LabImage *lab)
|
|||||||
const auto abcoord =
|
const auto abcoord =
|
||||||
[](float x) -> float
|
[](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
|
#ifdef _OPENMP
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#define L2U .69314718055966295651160180568695068359375
|
#define L2U .69314718055966295651160180568695068359375
|
||||||
#define L2L .28235290563031577122588448175013436025525412068e-12
|
#define L2L .28235290563031577122588448175013436025525412068e-12
|
||||||
#define R_LN2 1.442695040888963407359924681001892137426645954152985934135449406931
|
#define R_LN2 1.442695040888963407359924681001892137426645954152985934135449406931
|
||||||
|
#define pow_F(a,b) (xexpf(b*xlogf(a)))
|
||||||
|
|
||||||
__inline int64_t doubleToRawLongBits(double d) {
|
__inline int64_t doubleToRawLongBits(double d) {
|
||||||
union {
|
union {
|
||||||
@ -1263,6 +1264,16 @@ __inline float xdivf( float d, int n){
|
|||||||
return uflint.floatval;
|
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
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user