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) <noreply@anthropic.com>
This commit is contained in:
2026-07-26 18:56:17 +02:00
co-authored by Claude Opus 5
parent 96e10fd1f0
commit 0cee55f654
2 changed files with 6 additions and 6 deletions
+6 -5
View File
@@ -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<QRgb*>(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<uint8_t>(qRed(pxl)),
.g = static_cast<uint8_t>(qGreen(pxl)),
.b = static_cast<uint8_t>(qBlue(pxl))}) > 128.0)
textItem->setBrush(Qt::black);
else
textItem->setBrush(Qt::white);
-1
View File
@@ -62,7 +62,6 @@ protected:
float foreground = 10.0;
float background = 0.0;
ColorScale color_scale;
std::vector<rgb> image_rgb;
std::vector<float> image_fp;
QPixmap pixmap;
QImage qimg_buffer_; // reusable image buffer — avoids 64MB alloc per frame