diff --git a/viewer/windows/JFJochMagnifierWindow.cpp b/viewer/windows/JFJochMagnifierWindow.cpp index 06f1f109..198072bf 100644 --- a/viewer/windows/JFJochMagnifierWindow.cpp +++ b/viewer/windows/JFJochMagnifierWindow.cpp @@ -5,6 +5,7 @@ #include "../image_viewer/JFJochSimpleImage.h" #include "../SimpleImage.h" +#include #include JFJochMagnifierWindow::JFJochMagnifierWindow(QWidget *parent) @@ -17,6 +18,26 @@ JFJochMagnifierWindow::JFJochMagnifierWindow(QWidget *parent) } void JFJochMagnifierWindow::imageLoaded(std::shared_ptr image) { + m_pending_image = std::move(image); + // The window is closed most of the time, and rendering a close-up nobody is looking at costs + // a full conversion and recolour of the whole detector image on every frame. + if (!isVisible()) { + m_pending_dirty = true; + return; + } + ApplyPendingImage(); +} + +void JFJochMagnifierWindow::showEvent(QShowEvent *event) { + JFJochHelperWindow::showEvent(event); + if (m_pending_dirty) + ApplyPendingImage(); +} + +void JFJochMagnifierWindow::ApplyPendingImage() { + m_pending_dirty = false; + const std::shared_ptr &image = m_pending_image; + if (!image) { m_have_image = false; m_image->setImage(nullptr); diff --git a/viewer/windows/JFJochMagnifierWindow.h b/viewer/windows/JFJochMagnifierWindow.h index 91ec2621..5676155a 100644 --- a/viewer/windows/JFJochMagnifierWindow.h +++ b/viewer/windows/JFJochMagnifierWindow.h @@ -18,6 +18,15 @@ class JFJochMagnifierWindow : public JFJochHelperWindow { double m_magnification = 12.0; bool m_have_image = false; + // Building the close-up converts and colours the whole detector image, so it is only done + // while the window is actually up. The frame is remembered either way; holding the + // shared_ptr also keeps alive the buffer the SimpleImage points into. + std::shared_ptr m_pending_image; + bool m_pending_dirty = false; + void ApplyPendingImage(); + + void showEvent(QShowEvent *event) override; + public: explicit JFJochMagnifierWindow(QWidget *parent = nullptr);