Colortoning lab regions: Disabled timing code and removed double declaration of c_factor, #4914
This commit is contained in:
parent
e199d1ea10
commit
64af0e7602
@ -24,11 +24,12 @@
|
|||||||
|
|
||||||
#include "improcfun.h"
|
#include "improcfun.h"
|
||||||
#include "guidedfilter.h"
|
#include "guidedfilter.h"
|
||||||
#define BENCHMARK
|
//#define BENCHMARK
|
||||||
#include "StopWatch.h"
|
#include "StopWatch.h"
|
||||||
#include "sleef.c"
|
#include "sleef.c"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
#ifdef __SSE2__
|
#ifdef __SSE2__
|
||||||
void fastlin2log(float *x, float factor, float base, int w)
|
void fastlin2log(float *x, float factor, float base, int w)
|
||||||
{
|
{
|
||||||
@ -46,6 +47,7 @@ void fastlin2log(float *x, float factor, float base, int w)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace rtengine {
|
namespace rtengine {
|
||||||
@ -87,59 +89,59 @@ BENCHFUN
|
|||||||
abmask[i](lab->W, lab->H);
|
abmask[i](lab->W, lab->H);
|
||||||
Lmask[i](lab->W, lab->H);
|
Lmask[i](lab->W, lab->H);
|
||||||
}
|
}
|
||||||
|
|
||||||
array2D<float> guide(lab->W, lab->H);
|
array2D<float> guide(lab->W, lab->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;
|
||||||
|
|
||||||
#ifdef _OPENMP
|
#ifdef _OPENMP
|
||||||
#pragma omp parallel if (multiThread)
|
#pragma omp parallel if (multiThread)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
#ifdef __SSE2__
|
#ifdef __SSE2__
|
||||||
float cBuffer[lab->W];
|
float cBuffer[lab->W];
|
||||||
float hBuffer[lab->W];
|
float hBuffer[lab->W];
|
||||||
// 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;
|
|
||||||
#endif
|
#endif
|
||||||
#ifdef _OPENMP
|
#ifdef _OPENMP
|
||||||
#pragma omp for schedule(dynamic, 16)
|
#pragma omp for schedule(dynamic, 16)
|
||||||
#endif
|
#endif
|
||||||
for (int y = 0; y < lab->H; ++y) {
|
for (int y = 0; y < lab->H; ++y) {
|
||||||
#ifdef __SSE2__
|
#ifdef __SSE2__
|
||||||
// vectorized precalculation
|
// vectorized precalculation
|
||||||
Color::Lab2Lch(lab->a[y], lab->b[y], cBuffer, hBuffer, lab->W);
|
Color::Lab2Lch(lab->a[y], lab->b[y], cBuffer, hBuffer, lab->W);
|
||||||
fastlin2log(cBuffer, c_factor, 10.f, lab->W);
|
fastlin2log(cBuffer, c_factor, 10.f, lab->W);
|
||||||
#endif
|
#endif
|
||||||
for (int x = 0; x < lab->W; ++x) {
|
for (int x = 0; x < lab->W; ++x) {
|
||||||
float l = lab->L[y][x] / 32768.f;
|
const float l = lab->L[y][x] / 32768.f;
|
||||||
guide[y][x] = LIM01(l);
|
guide[y][x] = LIM01(l);
|
||||||
#ifdef __SSE2__
|
#ifdef __SSE2__
|
||||||
// use precalculated values
|
// use precalculated values
|
||||||
float c = cBuffer[x];
|
const float c = cBuffer[x];
|
||||||
float h = hBuffer[x];
|
float h = hBuffer[x];
|
||||||
#else
|
#else
|
||||||
// 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
|
float c, h;
|
||||||
constexpr float c_factor = 327.68f / 48000.f;
|
Color::Lab2Lch(lab->a[y][x], lab->b[y][x], c, h);
|
||||||
float c, h;
|
c = xlin2log(c * c_factor, 10.f);
|
||||||
Color::Lab2Lch(lab->a[y][x], lab->b[y][x], c, h);
|
|
||||||
c = xlin2log(c * c_factor, 10.f);
|
|
||||||
#endif
|
#endif
|
||||||
h = Color::huelab_to_huehsv2(h);
|
h = Color::huelab_to_huehsv2(h);
|
||||||
h += 1.f/6.f; // offset the hue because we start from purple instead of red
|
h += 1.f/6.f; // offset the hue because we start from purple instead of red
|
||||||
if (h > 1.f) {
|
if (h > 1.f) {
|
||||||
h -= 1.f;
|
h -= 1.f;
|
||||||
}
|
}
|
||||||
h = xlin2log(h, 3.f);
|
h = xlin2log(h, 3.f);
|
||||||
|
|
||||||
for (int i = begin_idx; i < end_idx; ++i) {
|
for (int i = begin_idx; i < end_idx; ++i) {
|
||||||
auto &hm = hmask[i];
|
auto &hm = hmask[i];
|
||||||
auto &cm = cmask[i];
|
auto &cm = cmask[i];
|
||||||
auto &lm = lmask[i];
|
auto &lm = lmask[i];
|
||||||
float blend = LIM01((hm ? hm->getVal(h) : 1.f) * (cm ? cm->getVal(c) : 1.f) * (lm ? lm->getVal(l) : 1.f));
|
float blend = LIM01((hm ? hm->getVal(h) : 1.f) * (cm ? cm->getVal(c) : 1.f) * (lm ? lm->getVal(l) : 1.f));
|
||||||
Lmask[i][y][x] = abmask[i][y][x] = blend;
|
Lmask[i][y][x] = abmask[i][y][x] = blend;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = begin_idx; i < end_idx; ++i) {
|
for (int i = begin_idx; i < end_idx; ++i) {
|
||||||
rtengine::guidedFilter(guide, abmask[i], abmask[i], max(int(4 / scale + 0.5), 1), 0.001, multiThread);
|
rtengine::guidedFilter(guide, abmask[i], abmask[i], max(int(4 / scale + 0.5), 1), 0.001, multiThread);
|
||||||
rtengine::guidedFilter(guide, Lmask[i], Lmask[i], max(int(25 / scale + 0.5), 1), 0.0001, multiThread);
|
rtengine::guidedFilter(guide, Lmask[i], Lmask[i], max(int(25 / scale + 0.5), 1), 0.0001, multiThread);
|
||||||
@ -176,7 +178,7 @@ BENCHFUN
|
|||||||
abca[i] = abcoord(r.a);
|
abca[i] = abcoord(r.a);
|
||||||
abcb[i] = abcoord(r.b);
|
abcb[i] = abcoord(r.b);
|
||||||
rs[i] = 1.f + r.saturation / 100.f;
|
rs[i] = 1.f + r.saturation / 100.f;
|
||||||
rl[i] = 1.f + float(r.lightness) / 500.f;
|
rl[i] = 1.f + r.lightness / 500.f;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _OPENMP
|
#ifdef _OPENMP
|
||||||
|
Loading…
x
Reference in New Issue
Block a user