From 0cee55f654e86fe775c5aa93ce692a259a379290 Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Sun, 26 Jul 2026 18:56:17 +0200 Subject: [PATCH] Viewer: drop the full-size image_rgb mirror GeneratePixmap wrote every pixel twice: once into the QImage and once into image_rgb. The only reader was writePixelLabels, which needs a colour for at most 5000 pixels and only above 30x zoom, so the mirror cost a W*H*3 buffer and a second store per pixel to serve a fraction of a percent of them. Read the colour back from the rendered image instead. 18.1 Mpx colouring loop: 9.5 -> 6.2 ms. Co-Authored-By: Claude Opus 5 (1M context) --- viewer/image_viewer/JFJochImage.cpp | 11 ++++++----- viewer/image_viewer/JFJochImage.h | 1 - 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/viewer/image_viewer/JFJochImage.cpp b/viewer/image_viewer/JFJochImage.cpp index 6ae8bf11..a75b5840 100644 --- a/viewer/image_viewer/JFJochImage.cpp +++ b/viewer/image_viewer/JFJochImage.cpp @@ -659,8 +659,6 @@ void JFJochImage::GeneratePixmap() { uchar *const bits = qimg_buffer_.bits(); const qsizetype stride = qimg_buffer_.bytesPerLine(); - image_rgb.resize(W * H); - // Bad pixel color int r, g, b, a; feature_color.getRgb(&r, &g, &b, &a); @@ -693,7 +691,6 @@ void JFJochImage::GeneratePixmap() { QtConcurrent::blockingMap(rows, [&](int y) { QRgb *scanLine = reinterpret_cast(bits + y * stride); const float *row = &image_fp[y * W]; - rgb *out = &image_rgb[y * W]; for (int x = 0; x < W; ++x) { const float fp = row[x]; @@ -727,7 +724,6 @@ void JFJochImage::GeneratePixmap() { c = lut_data[idx]; } - out[x] = c; scanLine[x] = qRgb(c.r, c.g, c.b); } }); @@ -821,7 +817,12 @@ void JFJochImage::writePixelLabels() { auto *textItem = new QGraphicsSimpleTextItem(*pText); textItem->setFont(font); - if (luminance(image_rgb[idx]) > 128.0) + // Read the colour back from the rendered image rather than keeping a + // full-size mirror of it around for the few pixels that get a label. + const QRgb pxl = qimg_buffer_.pixel(x, y); + if (luminance(rgb{.r = static_cast(qRed(pxl)), + .g = static_cast(qGreen(pxl)), + .b = static_cast(qBlue(pxl))}) > 128.0) textItem->setBrush(Qt::black); else textItem->setBrush(Qt::white); diff --git a/viewer/image_viewer/JFJochImage.h b/viewer/image_viewer/JFJochImage.h index a6955915..2d3199d3 100644 --- a/viewer/image_viewer/JFJochImage.h +++ b/viewer/image_viewer/JFJochImage.h @@ -62,7 +62,6 @@ protected: float foreground = 10.0; float background = 0.0; ColorScale color_scale; - std::vector image_rgb; std::vector image_fp; QPixmap pixmap; QImage qimg_buffer_; // reusable image buffer — avoids 64MB alloc per frame