Colortoning lab regions: Move guid fill into main loop, #4914

This commit is contained in:
heckflosse
2018-11-02 19:02:05 +01:00
parent 47d6ee44f8
commit e199d1ea10

View File

@@ -87,6 +87,7 @@ 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);
#ifdef _OPENMP #ifdef _OPENMP
#pragma omp parallel if (multiThread) #pragma omp parallel if (multiThread)
@@ -99,7 +100,7 @@ BENCHFUN
constexpr float c_factor = 327.68f / 48000.f; constexpr float c_factor = 327.68f / 48000.f;
#endif #endif
#ifdef _OPENMP #ifdef _OPENMP
#pragma omp for #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__
@@ -108,54 +109,41 @@ BENCHFUN
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]; float l = lab->L[y][x] / 32768.f;
guide[y][x] = LIM01(l);
#ifdef __SSE2__ #ifdef __SSE2__
// use precalculated values // use precalculated values
float c1 = cBuffer[x]; 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 // 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 a = lab->a[y][x];
float b = lab->b[y][x];
float c, h; float c, h;
Color::Lab2Lch(a, b, c, h); Color::Lab2Lch(lab->a[y][x], lab->b[y][x], c, h);
float c1 = xlin2log(c * c_factor, 10.f); c = xlin2log(c * c_factor, 10.f);
#endif #endif
float h1 = Color::huelab_to_huehsv2(h); h = Color::huelab_to_huehsv2(h);
h1 = h1 + 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 (h1 > 1.f) { if (h > 1.f) {
h1 -= 1.f; h -= 1.f;
} }
h1 = xlin2log(h1, 3.f); h = xlin2log(h, 3.f);
float l1 = l / 32768.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(h1) : 1.f) * (cm ? cm->getVal(c1) : 1.f) * (lm ? lm->getVal(l1) : 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;
} }
} }
} }
} }
{
array2D<float> guide(lab->W, lab->H, lab->L);
#ifdef _OPENMP
#pragma omp parallel for if (multiThread)
#endif
for (int y = 0; y < lab->H; ++y) {
for (int x = 0; x < lab->W; ++x) {
guide[y][x] = LIM01(lab->L[y][x] / 32768.f);
}
}
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);
} }
}
if (show_mask_idx >= 0) { if (show_mask_idx >= 0) {
#ifdef _OPENMP #ifdef _OPENMP