From d09734fe0d22b71ae93b26d18222aa08234257d5 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sun, 5 Apr 2026 22:18:39 +0200 Subject: [PATCH] Small feature: hovering over an image will not just display the image parameters in the status bar, but also the value of the pixel the mouse is over --- src/img/img/imgObject.cc | 1 - src/img/img/imgObject.h | 4 ++-- src/img/img/imgService.cc | 39 +++++++++++++++++++++++++++++++++++++-- src/img/img/imgService.h | 2 +- 4 files changed, 40 insertions(+), 6 deletions(-) diff --git a/src/img/img/imgObject.cc b/src/img/img/imgObject.cc index 96acfe403..6642ccdcb 100644 --- a/src/img/img/imgObject.cc +++ b/src/img/img/imgObject.cc @@ -1295,7 +1295,6 @@ Object::box () const // include landmarks for (std::vector ::const_iterator l = m_landmarks.begin (); l != m_landmarks.end (); ++l) { - b += m_trans * *l; } diff --git a/src/img/img/imgObject.h b/src/img/img/imgObject.h index f45d94031..a48e72551 100644 --- a/src/img/img/imgObject.h +++ b/src/img/img/imgObject.h @@ -794,7 +794,7 @@ public: /** * @brief Set the transformation matrix * - * This transformation matrix converts pixel coordinates (0,0 being the lower left corner and each pixel having the dimension of pixel_width and pixel_height) + * This transformation matrix converts pixel coordinates (0,0 being the center and each pixel having the dimension of pixel_width and pixel_height) * to micron coordinates. The coordinate of the pixel is the lower left corner of the pixel. */ void set_matrix (const db::Matrix3d &trans); @@ -802,7 +802,7 @@ public: /** * @brief Return the pixel-to-micron transformation * - * This transformation converts pixel coordinates (0,0 being the lower left corner and each pixel having the dimension of pixel_width and pixel_height) + * This transformation converts pixel coordinates (0,0 being the center and each pixel having the dimension of pixel_width and pixel_height) * to micron coordinates. The coordinate of the pixel is the lower left corner of the pixel. */ const db::Matrix3d &matrix () const diff --git a/src/img/img/imgService.cc b/src/img/img/imgService.cc index 03bdf85ed..dd8ca8b04 100644 --- a/src/img/img/imgService.cc +++ b/src/img/img/imgService.cc @@ -1309,6 +1309,7 @@ Service::transient_select (const db::DPoint &pos) clear_transient_selection (); bool any_selected = false; + std::string data_string; // compute search box double l = catch_distance (); @@ -1336,12 +1337,41 @@ Service::transient_select (const db::DPoint &pos) mp_transient_view = new img::View (this, imin, img::View::mode_transient); } + if (mp_transient_view->image_object ()) { + + const img::Object *image = mp_transient_view->image_object (); + + db::DPoint pixel = image->matrix ().inverted ().trans (pos); + if (pixel.x () > image->width () * -0.5 - 0.5 + db::epsilon && pixel.x () < image->width () * 0.5 + 0.5 - db::epsilon && + pixel.y () > image->height () * -0.5 - 0.5 + db::epsilon && pixel.y () < image->height () * 0.5 + 0.5 - db::epsilon) { + + db::Point pixel_index = db::Point (pixel + db::DVector (image->width () * 0.5 - 0.5, image->height () * 0.5 - 0.5)); + + // check once again to account to rounding issues + if (pixel_index.x () >= 0 && pixel_index.x () < image->width () && + pixel_index.y () >= 0 && pixel_index.y () < image->height ()) { + + if (image->is_color ()) { + data_string = tl::sprintf ("RGB: %.5g,%.5g,%.5g", + image->pixel (pixel_index.x (), pixel_index.y (), 0), + image->pixel (pixel_index.x (), pixel_index.y (), 1), + image->pixel (pixel_index.x (), pixel_index.y (), 2)); + } else { + data_string = tl::sprintf ("%.5g", image->pixel (pixel_index.x (), pixel_index.y ())); + } + + } + + } + + } + any_selected = true; } if (any_selected && ! editables ()->has_selection ()) { - display_status (true); + display_status (true, data_string); } return any_selected; @@ -1464,11 +1494,13 @@ Service::select (const db::DBox &box, lay::Editable::SelectionMode mode) } void -Service::display_status (bool transient) +Service::display_status (bool transient, const std::string &data_string) { View *selected_view = transient ? mp_transient_view : (m_selected_image_views.size () == 1 ? m_selected_image_views [0] : 0); if (! selected_view) { + view ()->message (std::string ()); + } else { const img::Object *image = selected_view->image_object (); @@ -1478,6 +1510,9 @@ Service::display_status (bool transient) msg = tl::to_string (tr ("selected: ")); } msg += tl::sprintf (tl::to_string (tr ("image(%dx%d)")), image->width (), image->height ()); + if (! data_string.empty ()) { + msg += " [" + data_string + "]"; + } view ()->message (msg); } diff --git a/src/img/img/imgService.h b/src/img/img/imgService.h index ff7f9a2d8..a709ab2ca 100644 --- a/src/img/img/imgService.h +++ b/src/img/img/imgService.h @@ -586,7 +586,7 @@ private: /** * @brief Display a message about the current selection */ - void display_status (bool transient); + void display_status (bool transient, const std::string &data_string = std::string ()); /** * @brief Gets a value indicating the (new) top z position