diff --git a/rtengine/capturesharpening.cc b/rtengine/capturesharpening.cc index e8770f95a..910de6fd3 100644 --- a/rtengine/capturesharpening.cc +++ b/rtengine/capturesharpening.cc @@ -541,6 +541,7 @@ BENCHFUN double progress = startVal; const double progressStep = (endVal - startVal) * rtengine::SQR(tileSize) / (W * H); + constexpr float minBlend = 0.01f; #ifdef _OPENMP #pragma omp parallel @@ -563,11 +564,17 @@ BENCHFUN if (endOfRow || endOfCol) { // special handling for small tiles at end of row or column if (checkIterStop) { + float maxVal = 0.f; for (int k = 0, ii = endOfCol ? H - fullTileSize + border : i; k < tileSize; ++k, ++ii) { for (int l = 0, jj = endOfRow ? W - fullTileSize + border : j; l < tileSize; ++l, ++jj) { iterCheck[k][l] = oldLuminance[ii][jj] * clipmask[ii][jj] * 0.5f; + maxVal = std::max(maxVal, clipmask[ii][jj]); } } + if (maxVal < minBlend) { + // no pixel of the tile has a blend factor >= minBlend => skip the tile + continue; + } } for (int k = 0, ii = endOfCol ? H - fullTileSize : i - border; k < fullTileSize; ++k, ++ii) { for (int l = 0, jj = endOfRow ? W - fullTileSize : j - border; l < fullTileSize; ++l, ++jj) { @@ -577,11 +584,17 @@ BENCHFUN } } else { if (checkIterStop) { + float maxVal = 0.f; for (int ii = 0; ii < tileSize; ++ii) { for (int jj = 0; jj < tileSize; ++jj) { iterCheck[ii][jj] = oldLuminance[i + ii][j + jj] * clipmask[i + ii][j + jj] * 0.5f; + maxVal = std::max(maxVal, clipmask[i + ii][j + jj]); } } + if (maxVal < minBlend) { + // no pixel of the tile has a blend factor >= minBlend => skip the tile + continue; + } } for (int ii = i; ii < i + fullTileSize; ++ii) { for (int jj = j; jj < j + fullTileSize; ++jj) {