ImProcCoordinator::updateVectorscope(): parallelize loops

This commit is contained in:
Ingo Weyrich 2020-08-16 11:46:17 +02:00
parent 3af822b6f7
commit 9e040b3bc2
2 changed files with 67 additions and 19 deletions

View File

@ -211,6 +211,24 @@ public:
}
}
array2D<T>& operator+=(const array2D<T>& 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;

View File

@ -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<int> 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<float[]> a(new float[vectorscopeScale]);
const std::unique_ptr<float[]> b(new float[vectorscopeScale]);
const std::unique_ptr<float[]> 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<int> 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;
}
}
}
}