From 9e040b3bc297530c80723e500ede6cd618c471af Mon Sep 17 00:00:00 2001 From: Ingo Weyrich Date: Sun, 16 Aug 2020 11:46:17 +0200 Subject: [PATCH] ImProcCoordinator::updateVectorscope(): parallelize loops --- rtengine/array2D.h | 18 ++++++++++ rtengine/improccoordinator.cc | 68 +++++++++++++++++++++++++---------- 2 files changed, 67 insertions(+), 19 deletions(-) diff --git a/rtengine/array2D.h b/rtengine/array2D.h index a8eebde54..ca4db3d06 100644 --- a/rtengine/array2D.h +++ b/rtengine/array2D.h @@ -211,6 +211,24 @@ public: } } + array2D& operator+=(const array2D& rhs) + { + if (rhs.getWidth() == this->getWidth() && rhs.getHeight() == this->getHeight()) { + for (int i = 0; i < getHeight(); ++i) { +#ifdef _OPENMP + #pragma omp simd +#endif + + for (int j = 0; j < getWidth(); ++j) { + rows[i][j] += rhs[i][j]; + } + } + } + + return *this; + } + + int getWidth() const { return width; diff --git a/rtengine/improccoordinator.cc b/rtengine/improccoordinator.cc index 1da11ab4e..e3882785c 100644 --- a/rtengine/improccoordinator.cc +++ b/rtengine/improccoordinator.cc @@ -1863,35 +1863,65 @@ BENCHFUN vectorscopeScale = (x2 - x1) * (y2 - y1); if (hListener->vectorscopeType() == 0) { // HS - for (int i = y1; i < y2; ++i) { - int ofs = (i * pW + x1) * 3; - for (int j = x1; j < x2; ++j) { - const float red = 257.f * workimg->data[ofs++]; - const float green = 257.f * workimg->data[ofs++]; - const float blue = 257.f * workimg->data[ofs++]; - float h, s, l; - Color::rgb2hslfloat(red, green, blue, h, s, l); - const auto sincosval = xsincosf(2.f * RT_PI_F * h); - const int col = s * sincosval.y * (size / 2) + size / 2; - const int row = s * sincosval.x * (size / 2) + size / 2; - if (col >= 0 && col < size && row >= 0 && row < size) { - vectorscope[row][col]++; +#ifdef _OPENMP + #pragma omp parallel +#endif + { + array2D vectorscopeThr(size, size, ARRAY2D_CLEAR_DATA); +#ifdef _OPENMP + #pragma omp for nowait +#endif + for (int i = y1; i < y2; ++i) { + int ofs = (i * pW + x1) * 3; + for (int j = x1; j < x2; ++j) { + const float red = 257.f * workimg->data[ofs++]; + const float green = 257.f * workimg->data[ofs++]; + const float blue = 257.f * workimg->data[ofs++]; + float h, s, l; + Color::rgb2hslfloat(red, green, blue, h, s, l); + const auto sincosval = xsincosf(2.f * RT_PI_F * h); + const int col = s * sincosval.y * (size / 2) + size / 2; + const int row = s * sincosval.x * (size / 2) + size / 2; + if (col >= 0 && col < size && row >= 0 && row < size) { + vectorscopeThr[row][col]++; + } } } +#ifdef _OPENMP + #pragma omp critical +#endif + { + vectorscope += vectorscopeThr; + } } } else if (hListener->vectorscopeType() == 1) { // CH const std::unique_ptr a(new float[vectorscopeScale]); const std::unique_ptr b(new float[vectorscopeScale]); const std::unique_ptr L(new float[vectorscopeScale]); ipf.rgb2lab(*workimg, x1, y1, x2 - x1, y2 - y1, L.get(), a.get(), b.get(), params->icm); - for (int i = y1; i < y2; ++i) { - for (int j = x1, ofs_lab = (i - y1) * (x2 - x1); j < x2; ++j, ++ofs_lab) { - const int col = (size / 96000.f) * a[ofs_lab] + size / 2; - const int row = (size / 96000.f) * b[ofs_lab] + size / 2; - if (col >= 0 && col < size && row >= 0 && row < size) { - vectorscope[row][col]++; +#ifdef _OPENMP + #pragma omp parallel +#endif + { + array2D vectorscopeThr(size, size, ARRAY2D_CLEAR_DATA); +#ifdef _OPENMP + #pragma omp for nowait +#endif + for (int i = y1; i < y2; ++i) { + for (int j = x1, ofs_lab = (i - y1) * (x2 - x1); j < x2; ++j, ++ofs_lab) { + const int col = (size / 96000.f) * a[ofs_lab] + size / 2; + const int row = (size / 96000.f) * b[ofs_lab] + size / 2; + if (col >= 0 && col < size && row >= 0 && row < size) { + vectorscopeThr[row][col]++; + } } } +#ifdef _OPENMP + #pragma omp critical +#endif + { + vectorscope += vectorscopeThr; + } } } }