From ebdc8702962dfae775ddbe146d1a6ab1b5320474 Mon Sep 17 00:00:00 2001 From: Vadim Pisarevsky Date: Wed, 31 Oct 2018 10:40:58 +0300 Subject: [PATCH] fixed imshow on mac; before that just the window titlebar was shown, without the window content. --- modules/highgui/src/window_cocoa.mm | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/modules/highgui/src/window_cocoa.mm b/modules/highgui/src/window_cocoa.mm index 4e6da5a62b..962abe09c1 100644 --- a/modules/highgui/src/window_cocoa.mm +++ b/modules/highgui/src/window_cocoa.mm @@ -230,7 +230,7 @@ CV_IMPL void cvShowImage( const char* name, const CvArr* arr) if (oldImageSize.height != imageSize.height || oldImageSize.width != imageSize.width) { //Set new view size considering sliders (reserve height and min width) - NSSize scaledImageSize; + NSSize scaledImageSize = imageSize; if ([[window contentView] respondsToSelector:@selector(convertSizeFromBacking:)]) { // Only resize for retina displays if the image is bigger than the screen @@ -239,13 +239,14 @@ CV_IMPL void cvShowImage( const char* name, const CvArr* arr) screenSize.height -= titleBarHeight; if (imageSize.width > screenSize.width || imageSize.height > screenSize.height) { + CGFloat fx = screenSize.width/std::max(imageSize.width, (CGFloat)1.f); + CGFloat fy = screenSize.height/std::max(imageSize.height, (CGFloat)1.f); + CGFloat min_f = std::min(fx, fy); scaledImageSize = [[window contentView] convertSizeFromBacking:imageSize]; + scaledImageSize.width = std::min(scaledImageSize.width, min_f*imageSize.width); + scaledImageSize.height = std::min(scaledImageSize.height, min_f*imageSize.height); } } - else - { - scaledImageSize = imageSize; - } NSSize contentSize = vrectOld.size; contentSize.height = scaledImageSize.height + [window contentView].sliderHeight; contentSize.width = std::max(scaledImageSize.width, MIN_SLIDER_WIDTH); @@ -735,6 +736,7 @@ void cv::setWindowTitle(const String& winname, const String& title) static NSSize constrainAspectRatio(NSSize base, NSSize constraint) { CGFloat heightDiff = (base.height / constraint.height); CGFloat widthDiff = (base.width / constraint.width); + if (heightDiff == 0) heightDiff = widthDiff; if (widthDiff == heightDiff) { return base; }