Viewer: coalesce foreground/background recolours

Ctrl+wheel, Shift+wheel and the foreground slider each recoloured the whole
image synchronously, once per input event. On a large detector the recolour is
slower than the events arrive, so they queued up and the view lagged behind the
cursor for as long as the user kept scrolling.

Defer the recolour to a zero-delay single shot and drop the intermediate
values: at most one recolour is in flight, and it always uses the newest
foreground/background.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-07-26 18:59:45 +02:00
co-authored by Claude Opus 5
parent 8cfc820767
commit 42953a46e2
2 changed files with 18 additions and 4 deletions
+13 -4
View File
@@ -67,10 +67,20 @@ void JFJochImage::onScroll(int value) {
updateOverlay();
}
void JFJochImage::ScheduleRenderImage() {
if (render_pending_)
return;
render_pending_ = true;
QTimer::singleShot(0, this, [this] {
render_pending_ = false;
RenderImage();
Redraw();
});
}
void JFJochImage::changeBackground(float val) {
background = val;
RenderImage();
Redraw();
ScheduleRenderImage();
}
void JFJochImage::changeForeground(float val) {
@@ -78,8 +88,7 @@ void JFJochImage::changeForeground(float val) {
emit autoForegroundChanged(false);
foreground = val;
// Regenerate the image
RenderImage();
Redraw();
ScheduleRenderImage();
}
void JFJochImage::setColorMap(int color_map) {
+5
View File
@@ -119,6 +119,11 @@ protected:
void updateOverlay();
void RenderImage();
// Re-render once the event queue drains. The foreground slider and the wheel emit far
// faster than a large image can be recoloured, so intermediate values are dropped
// instead of queueing a full recolour per event.
void ScheduleRenderImage();
bool render_pending_ = false;
void Redraw();
void CalcROI();