From 75a34ef87ee1f5faa5286dc7817d14b0cfc1a7b9 Mon Sep 17 00:00:00 2001 From: heckflosse Date: Tue, 4 Dec 2018 14:51:13 +0100 Subject: [PATCH 1/3] Improve caclulation of dual demosaic contrast threshold --- rtengine/rt_algo.cc | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/rtengine/rt_algo.cc b/rtengine/rt_algo.cc index 3925fc1ec..4552593cc 100644 --- a/rtengine/rt_algo.cc +++ b/rtengine/rt_algo.cc @@ -207,15 +207,16 @@ void buildBlendMask(float** luminance, float **blend, int W, int H, float &contr if (autoContrast) { for (int pass = 0; pass < 2; ++pass) { const int tilesize = 80 / (pass + 1); - const int numTilesW = W / tilesize; - const int numTilesH = H / tilesize; + const int skip = pass < 1 ? tilesize : tilesize / 4; + const int numTilesW = W / skip - 3 * pass; + const int numTilesH = H / skip - 3 * pass; std::vector>> variances(numTilesH, std::vector>(numTilesW)); #pragma omp parallel for for (int i = 0; i < numTilesH; ++i) { - int tileY = i * tilesize; + int tileY = i * skip; for (int j = 0; j < numTilesW; ++j) { - int tileX = j * tilesize; + int tileX = j * skip; #ifdef __SSE2__ vfloat avgv = ZEROV; for (int y = tileY; y < tileY + tilesize; ++y) { @@ -268,10 +269,9 @@ void buildBlendMask(float** luminance, float **blend, int W, int H, float &contr } } - const int minY = tilesize * minI; - const int minX = tilesize * minJ; + const int minY = skip * minI; + const int minX = skip * minJ; -// std::cout << pass << ": minvar : " << minvar << std::endl; if (minvar <= 1.f || pass == 1) { // a variance <= 1 means we already found a flat region and can skip second pass // in second pass we allow a variance of 2 From 09c55ca6eccae42892139791cc560643f7368c25 Mon Sep 17 00:00:00 2001 From: heckflosse Date: Tue, 4 Dec 2018 23:13:20 +0100 Subject: [PATCH 2/3] Small speedup and code cleanup for autocontrast calculation --- rtengine/rt_algo.cc | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/rtengine/rt_algo.cc b/rtengine/rt_algo.cc index 4552593cc..a258287bf 100644 --- a/rtengine/rt_algo.cc +++ b/rtengine/rt_algo.cc @@ -203,20 +203,19 @@ void buildBlendMask(float** luminance, float **blend, int W, int H, float &contr } } } else { - constexpr float scale = 0.0625f / 327.68f; if (autoContrast) { for (int pass = 0; pass < 2; ++pass) { const int tilesize = 80 / (pass + 1); const int skip = pass < 1 ? tilesize : tilesize / 4; const int numTilesW = W / skip - 3 * pass; const int numTilesH = H / skip - 3 * pass; - std::vector>> variances(numTilesH, std::vector>(numTilesW)); + std::vector> variances(numTilesH, std::vector(numTilesW)); - #pragma omp parallel for + #pragma omp parallel for schedule(dynamic) for (int i = 0; i < numTilesH; ++i) { - int tileY = i * skip; + const int tileY = i * skip; for (int j = 0; j < numTilesW; ++j) { - int tileX = j * skip; + const int tileX = j * skip; #ifdef __SSE2__ vfloat avgv = ZEROV; for (int y = tileY; y < tileY + tilesize; ++y) { @@ -226,7 +225,7 @@ void buildBlendMask(float** luminance, float **blend, int W, int H, float &contr } float avg = vhadd(avgv); #else - float avg = 0.; + float avg = 0.f; for (int y = tileY; y < tileY + tilesize; ++y) { for (int x = tileX; x < tileX + tilesize; ++x) { avg += luminance[y][x]; @@ -234,6 +233,11 @@ void buildBlendMask(float** luminance, float **blend, int W, int H, float &contr } #endif avg /= SQR(tilesize); + if (avg < 2000.f || avg > 20000.f) { + // too dark or too bright => skip the tile + variances[i][j] = RT_INFINITY_F; + continue; + } #ifdef __SSE2__ vfloat varv = ZEROV; avgv = F2V(avg); @@ -244,16 +248,15 @@ void buildBlendMask(float** luminance, float **blend, int W, int H, float &contr } float var = vhadd(varv); #else - float var = 0.0; + float var = 0.f; for (int y = tileY; y < tileY + tilesize; ++y) { for (int x = tileX; x < tileX + tilesize; ++x) { var += SQR(luminance[y][x] - avg); } } - #endif +#endif var /= (SQR(tilesize) * avg); - variances[i][j].first = var; - variances[i][j].second = avg; + variances[i][j] = var; } } @@ -261,8 +264,8 @@ void buildBlendMask(float** luminance, float **blend, int W, int H, float &contr int minI = 0, minJ = 0; for (int i = 0; i < numTilesH; ++i) { for (int j = 0; j < numTilesW; ++j) { - if (variances[i][j].first < minvar && variances[i][j].second > 2000.f && variances[i][j].second < 20000.f) { - minvar = variances[i][j].first; + if (variances[i][j] < minvar) { + minvar = variances[i][j]; minI = i; minJ = j; } @@ -295,6 +298,7 @@ void buildBlendMask(float** luminance, float **blend, int W, int H, float &contr } } } else { + constexpr float scale = 0.0625f / 327.68f; #ifdef _OPENMP #pragma omp parallel #endif From 1b0baf78ff8fb2e4830a76444128066736df23a3 Mon Sep 17 00:00:00 2001 From: heckflosse Date: Wed, 5 Dec 2018 15:17:12 +0100 Subject: [PATCH 3/3] buildBlendMask() cleanup --- rtengine/rt_algo.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rtengine/rt_algo.cc b/rtengine/rt_algo.cc index a258287bf..af2083d8e 100644 --- a/rtengine/rt_algo.cc +++ b/rtengine/rt_algo.cc @@ -22,8 +22,6 @@ #include #include #include -#include -#include #ifdef _OPENMP #include #endif @@ -206,12 +204,14 @@ void buildBlendMask(float** luminance, float **blend, int W, int H, float &contr if (autoContrast) { for (int pass = 0; pass < 2; ++pass) { const int tilesize = 80 / (pass + 1); - const int skip = pass < 1 ? tilesize : tilesize / 4; + const int skip = pass == 0 ? tilesize : tilesize / 4; const int numTilesW = W / skip - 3 * pass; const int numTilesH = H / skip - 3 * pass; std::vector> variances(numTilesH, std::vector(numTilesW)); +#ifdef _OPENMP #pragma omp parallel for schedule(dynamic) +#endif for (int i = 0; i < numTilesH; ++i) { const int tileY = i * skip; for (int j = 0; j < numTilesW; ++j) {