diff --git a/viewer/image_viewer/JFJochImage.cpp b/viewer/image_viewer/JFJochImage.cpp index 50ab8cd8..6ae8bf11 100644 --- a/viewer/image_viewer/JFJochImage.cpp +++ b/viewer/image_viewer/JFJochImage.cpp @@ -651,7 +651,13 @@ void JFJochImage::Redraw() { } void JFJochImage::GeneratePixmap() { - QImage qimg(int(W), int(H), QImage::Format_RGB32); + if (qimg_buffer_.width() != int(W) || qimg_buffer_.height() != int(H)) + qimg_buffer_ = QImage(int(W), int(H), QImage::Format_RGB32); + + // Take the data pointer once, here: scanLine() is non-const, so calling it from the + // workers below would have each of them detach the (possibly shared) buffer in parallel. + uchar *const bits = qimg_buffer_.bits(); + const qsizetype stride = qimg_buffer_.bytesPerLine(); image_rgb.resize(W * H); @@ -685,7 +691,7 @@ void JFJochImage::GeneratePixmap() { for (int y = 0; y < H; ++y) rows.push_back(y); QtConcurrent::blockingMap(rows, [&](int y) { - QRgb *scanLine = reinterpret_cast(qimg.scanLine(y)); + QRgb *scanLine = reinterpret_cast(bits + y * stride); const float *row = &image_fp[y * W]; rgb *out = &image_rgb[y * W]; @@ -726,7 +732,7 @@ void JFJochImage::GeneratePixmap() { } }); - pixmap = QPixmap::fromImage(qimg); + pixmap = QPixmap::fromImage(qimg_buffer_); pixmap.setDevicePixelRatio(1.0); }