mirror of
https://github.com/opencv/opencv.git
synced 2026-07-30 15:53:03 +04:00
Merge pull request #25561 from Kumataro:fix25560
highgui: wayland: expand image width if title bar cannot be shown Close #25560 ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work - [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [ ] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
@@ -623,6 +623,9 @@ private:
|
||||
cv::Rect last_img_area_;
|
||||
bool image_changed_ = false;
|
||||
|
||||
int real_img_width = 0;
|
||||
cv::Scalar const outarea_color_ = CV_RGB(0, 0, 0);
|
||||
|
||||
void *param_ = nullptr;
|
||||
CvMouseCallback callback_ = nullptr;
|
||||
};
|
||||
@@ -1582,6 +1585,28 @@ cv_wl_viewer::cv_wl_viewer(cv_wl_window *window, int flags)
|
||||
void cv_wl_viewer::set_image(cv::Mat const &image) {
|
||||
image_ = image.clone();
|
||||
image_changed_ = true;
|
||||
|
||||
// See https://github.com/opencv/opencv/issues/25560
|
||||
// If image_ width is too small enough to show title and buttons, expand it.
|
||||
|
||||
// Keep real image width to limit x position for callback functions
|
||||
real_img_width = image_.size().width;
|
||||
|
||||
// Minimum width of title is not defined, so use button width * 3 instead of it.
|
||||
const int view_min_width = cv_wl_titlebar::btn_width * 3 + cv_wl_titlebar::titlebar_min_width;
|
||||
|
||||
const int margin = view_min_width - real_img_width;
|
||||
if(margin > 0)
|
||||
{
|
||||
copyMakeBorder(image_, // src
|
||||
image_, // dst
|
||||
0, // top
|
||||
0, // bottom
|
||||
0, // left
|
||||
margin, // right
|
||||
cv::BORDER_CONSTANT, // borderType
|
||||
outarea_color_ ); // value(color)
|
||||
}
|
||||
}
|
||||
|
||||
void cv_wl_viewer::set_mouse_callback(CvMouseCallback callback, void *param) {
|
||||
@@ -1634,6 +1659,8 @@ void cv_wl_viewer::on_mouse(int event, cv::Point const &p, int flag) {
|
||||
int x = static_cast<int>((p.x - last_img_area_.x) * ((double) image_.size().width / last_img_area_.width));
|
||||
int y = static_cast<int>((p.y - last_img_area_.y) *
|
||||
((double) image_.size().height / last_img_area_.height));
|
||||
|
||||
x = cv::min(x, real_img_width);
|
||||
callback_(event, x, y, flag, param_);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -215,6 +215,21 @@ TEST(Highgui_GUI, trackbar)
|
||||
EXPECT_NO_THROW(destroyAllWindows());
|
||||
}
|
||||
|
||||
// See https://github.com/opencv/opencv/issues/25560
|
||||
#if !defined(ENABLE_PLUGINS)
|
||||
TEST(Highgui_GUI, DISABLED_small_width_image)
|
||||
#else
|
||||
TEST(Highgui_GUI, small_width_image)
|
||||
#endif
|
||||
{
|
||||
const std::string window_name("trackbar_test_window");
|
||||
cv::Mat src(1,1,CV_8UC3,cv::Scalar(0));
|
||||
EXPECT_NO_THROW(destroyAllWindows());
|
||||
ASSERT_NO_THROW(namedWindow(window_name));
|
||||
ASSERT_NO_THROW(imshow(window_name, src));
|
||||
EXPECT_NO_THROW(waitKey(10));
|
||||
EXPECT_NO_THROW(destroyAllWindows());
|
||||
}
|
||||
|
||||
TEST(Highgui_GUI, currentUIFramework)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user