Skip to content

Commit 15ba3e1

Browse files
committed
Merge pull request opencv#20250 from alalek:highgui_fixes
2 parents 2db243b + 8023888 commit 15ba3e1

7 files changed

+185
-4
lines changed

modules/highgui/CMakeLists.txt

+5
Original file line numberDiff line numberDiff line change
@@ -281,5 +281,10 @@ ocv_target_link_libraries(${the_module} LINK_PRIVATE ${tgts})
281281
set(CONFIG_STR "// Auto-generated file
282282
#define OPENCV_HIGHGUI_BUILTIN_BACKEND_STR \"${OPENCV_HIGHGUI_BUILTIN_BACKEND}\"
283283
")
284+
if(OPENCV_HIGHGUI_BUILTIN_BACKEND STREQUAL "NONE")
285+
set(CONFIG_STR "${CONFIG_STR}
286+
#define OPENCV_HIGHGUI_WITHOUT_BUILTIN_BACKEND 1
287+
")
288+
endif()
284289

285290
ocv_update_file("${CMAKE_CURRENT_BINARY_DIR}/opencv_highgui_config.hpp" "${CONFIG_STR}")

modules/highgui/src/backend.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// It is subject to the license terms in the LICENSE file found in the top-level directory
33
// of this distribution and at http://opencv.org/license.html.
44
#include "precomp.hpp"
5-
#include "opencv_highgui_config.hpp" // generated by CMake
65
#include "backend.hpp"
76

87
#include <opencv2/core/utils/configuration.private.hpp>

modules/highgui/src/plugin_wrapper.impl.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,12 @@ std::vector<FileSystemPath_t> getPluginCandidates(const std::string& baseName)
232232
return results;
233233
}
234234

235+
// NB: require loading of imgcodecs module
236+
static void* g_imwrite = (void*)imwrite;
237+
235238
void PluginUIBackendFactory::loadPlugin()
236239
{
240+
CV_Assert(g_imwrite);
237241
for (const FileSystemPath_t& plugin : getPluginCandidates(baseName_))
238242
{
239243
auto lib = std::make_shared<cv::plugin::impl::DynamicLib>(plugin);

modules/highgui/src/precomp.hpp

+3
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
#endif
4848

4949
#include "opencv2/highgui.hpp"
50+
#if !defined(BUILD_PLUGIN)
51+
#include "opencv_highgui_config.hpp" // generated by CMake
52+
#endif
5053

5154
#include "opencv2/core/utility.hpp"
5255
#if defined(__OPENCV_BUILD)

modules/highgui/src/registry.impl.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,9 @@ class UIBackendRegistry
162162
const BackendInfo& info = enabledBackends[i];
163163
os << info.name << '(' << info.priority << ')';
164164
}
165+
#if !defined(OPENCV_HIGHGUI_WITHOUT_BUILTIN_BACKEND)
165166
os << " + BUILTIN(" OPENCV_HIGHGUI_BUILTIN_BACKEND_STR ")";
167+
#endif
166168
return os.str();
167169
}
168170

modules/highgui/src/window.cpp

+166-3
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,14 @@ static void cleanupTrackbarCallbacksWithData_()
179179

180180
using namespace cv::impl;
181181

182+
#if defined(OPENCV_HIGHGUI_WITHOUT_BUILTIN_BACKEND) && defined(ENABLE_PLUGINS)
183+
static void deprecateNotFoundNoOpBehavior()
184+
{
185+
CV_LOG_ONCE_WARNING(NULL, "This no-op behavior is deprecated. Future versions of OpenCV will trigger exception in this case");
186+
}
187+
#define CV_NOT_FOUND_DEPRECATION deprecateNotFoundNoOpBehavior()
188+
#endif
189+
182190
CV_IMPL void cvSetWindowProperty(const char* name, int prop_id, double prop_value)
183191
{
184192
CV_TRACE_FUNCTION();
@@ -193,6 +201,19 @@ CV_IMPL void cvSetWindowProperty(const char* name, int prop_id, double prop_valu
193201
}
194202
}
195203

204+
#if defined(OPENCV_HIGHGUI_WITHOUT_BUILTIN_BACKEND) && defined(ENABLE_PLUGINS)
205+
auto backend = getCurrentUIBackend();
206+
if (backend)
207+
{
208+
CV_LOG_WARNING(NULL, "Can't find window with name: '" << name << "'. Do nothing");
209+
CV_NOT_FOUND_DEPRECATION;
210+
}
211+
else
212+
{
213+
CV_LOG_WARNING(NULL, "No UI backends available. Use OPENCV_LOG_LEVEL=DEBUG for investigation");
214+
}
215+
return;
216+
#else
196217
switch(prop_id)
197218
{
198219
//change between fullscreen or not.
@@ -249,6 +270,7 @@ CV_IMPL void cvSetWindowProperty(const char* name, int prop_id, double prop_valu
249270

250271
default:;
251272
}
273+
#endif
252274
}
253275

254276
/* return -1 if error */
@@ -268,6 +290,19 @@ CV_IMPL double cvGetWindowProperty(const char* name, int prop_id)
268290
}
269291
}
270292

293+
#if defined(OPENCV_HIGHGUI_WITHOUT_BUILTIN_BACKEND) && defined(ENABLE_PLUGINS)
294+
auto backend = getCurrentUIBackend();
295+
if (backend)
296+
{
297+
CV_LOG_WARNING(NULL, "Can't find window with name: '" << name << "'. Do nothing");
298+
CV_NOT_FOUND_DEPRECATION;
299+
}
300+
else
301+
{
302+
CV_LOG_WARNING(NULL, "No UI backends available. Use OPENCV_LOG_LEVEL=DEBUG for investigation");
303+
}
304+
return -1;
305+
#else
271306
switch(prop_id)
272307
{
273308
case CV_WND_PROP_FULLSCREEN:
@@ -361,13 +396,13 @@ CV_IMPL double cvGetWindowProperty(const char* name, int prop_id)
361396
default:
362397
return -1;
363398
}
399+
#endif
364400
}
365401

366402
cv::Rect cvGetWindowImageRect(const char* name)
367403
{
368404
CV_TRACE_FUNCTION();
369-
if (!name)
370-
return cv::Rect(-1, -1, -1, -1);
405+
CV_Assert(name);
371406

372407
{
373408
auto window = findWindow_(name);
@@ -377,6 +412,20 @@ cv::Rect cvGetWindowImageRect(const char* name)
377412
}
378413
}
379414

415+
#if defined(OPENCV_HIGHGUI_WITHOUT_BUILTIN_BACKEND) && defined(ENABLE_PLUGINS)
416+
auto backend = getCurrentUIBackend();
417+
if (backend)
418+
{
419+
CV_LOG_WARNING(NULL, "Can't find window with name: '" << name << "'. Do nothing");
420+
CV_NOT_FOUND_DEPRECATION;
421+
}
422+
else
423+
{
424+
CV_LOG_WARNING(NULL, "No UI backends available. Use OPENCV_LOG_LEVEL=DEBUG for investigation");
425+
}
426+
return Rect(-1, -1, -1, -1);
427+
#else
428+
380429
#if defined (HAVE_QT)
381430
return cvGetWindowRect_QT(name);
382431
#elif defined(HAVE_WIN32UI)
@@ -386,8 +435,10 @@ cv::Rect cvGetWindowImageRect(const char* name)
386435
#elif defined (HAVE_COCOA)
387436
return cvGetWindowRect_COCOA(name);
388437
#else
389-
return cv::Rect(-1, -1, -1, -1);
438+
return Rect(-1, -1, -1, -1);
390439
#endif
440+
441+
#endif
391442
}
392443

393444
cv::Rect cv::getWindowImageRect(const String& winname)
@@ -483,7 +534,21 @@ void cv::resizeWindow( const String& winname, int width, int height )
483534
}
484535
}
485536

537+
#if defined(OPENCV_HIGHGUI_WITHOUT_BUILTIN_BACKEND) && defined(ENABLE_PLUGINS)
538+
auto backend = getCurrentUIBackend();
539+
if (backend)
540+
{
541+
CV_LOG_WARNING(NULL, "Can't find window with name: '" << winname << "'. Do nothing");
542+
CV_NOT_FOUND_DEPRECATION;
543+
}
544+
else
545+
{
546+
CV_LOG_WARNING(NULL, "No UI backends available. Use OPENCV_LOG_LEVEL=DEBUG for investigation");
547+
}
548+
return;
549+
#else
486550
cvResizeWindow( winname.c_str(), width, height );
551+
#endif
487552
}
488553

489554
void cv::resizeWindow(const String& winname, const cv::Size& size)
@@ -504,7 +569,21 @@ void cv::moveWindow( const String& winname, int x, int y )
504569
}
505570
}
506571

572+
#if defined(OPENCV_HIGHGUI_WITHOUT_BUILTIN_BACKEND) && defined(ENABLE_PLUGINS)
573+
auto backend = getCurrentUIBackend();
574+
if (backend)
575+
{
576+
CV_LOG_WARNING(NULL, "Can't find window with name: '" << winname << "'. Do nothing");
577+
CV_NOT_FOUND_DEPRECATION;
578+
}
579+
else
580+
{
581+
CV_LOG_WARNING(NULL, "No UI backends available. Use OPENCV_LOG_LEVEL=DEBUG for investigation");
582+
}
583+
return;
584+
#else
507585
cvMoveWindow( winname.c_str(), x, y );
586+
#endif
508587
}
509588

510589
void cv::setWindowProperty(const String& winname, int prop_id, double prop_value)
@@ -616,8 +695,22 @@ int cv::createTrackbar(const String& trackbarName, const String& winName,
616695
}
617696
}
618697

698+
#if defined(OPENCV_HIGHGUI_WITHOUT_BUILTIN_BACKEND) && defined(ENABLE_PLUGINS)
699+
auto backend = getCurrentUIBackend();
700+
if (backend)
701+
{
702+
CV_LOG_WARNING(NULL, "Can't find window with name: '" << winName << "'. Do nothing");
703+
CV_NOT_FOUND_DEPRECATION;
704+
}
705+
else
706+
{
707+
CV_LOG_WARNING(NULL, "No UI backends available. Use OPENCV_LOG_LEVEL=DEBUG for investigation");
708+
}
709+
return 0;
710+
#else
619711
return cvCreateTrackbar2(trackbarName.c_str(), winName.c_str(),
620712
value, count, callback, userdata);
713+
#endif
621714
}
622715

623716
void cv::setTrackbarPos( const String& trackbarName, const String& winName, int value )
@@ -635,7 +728,21 @@ void cv::setTrackbarPos( const String& trackbarName, const String& winName, int
635728
}
636729
}
637730

731+
#if defined(OPENCV_HIGHGUI_WITHOUT_BUILTIN_BACKEND) && defined(ENABLE_PLUGINS)
732+
auto backend = getCurrentUIBackend();
733+
if (backend)
734+
{
735+
CV_LOG_WARNING(NULL, "Can't find window with name: '" << winName << "'. Do nothing");
736+
CV_NOT_FOUND_DEPRECATION;
737+
}
738+
else
739+
{
740+
CV_LOG_WARNING(NULL, "No UI backends available. Use OPENCV_LOG_LEVEL=DEBUG for investigation");
741+
}
742+
return;
743+
#else
638744
cvSetTrackbarPos(trackbarName.c_str(), winName.c_str(), value );
745+
#endif
639746
}
640747

641748
void cv::setTrackbarMax(const String& trackbarName, const String& winName, int maxval)
@@ -655,7 +762,21 @@ void cv::setTrackbarMax(const String& trackbarName, const String& winName, int m
655762
}
656763
}
657764

765+
#if defined(OPENCV_HIGHGUI_WITHOUT_BUILTIN_BACKEND) && defined(ENABLE_PLUGINS)
766+
auto backend = getCurrentUIBackend();
767+
if (backend)
768+
{
769+
CV_LOG_WARNING(NULL, "Can't find window with name: '" << winName << "'. Do nothing");
770+
CV_NOT_FOUND_DEPRECATION;
771+
}
772+
else
773+
{
774+
CV_LOG_WARNING(NULL, "No UI backends available. Use OPENCV_LOG_LEVEL=DEBUG for investigation");
775+
}
776+
return;
777+
#else
658778
cvSetTrackbarMax(trackbarName.c_str(), winName.c_str(), maxval);
779+
#endif
659780
}
660781

661782
void cv::setTrackbarMin(const String& trackbarName, const String& winName, int minval)
@@ -675,7 +796,21 @@ void cv::setTrackbarMin(const String& trackbarName, const String& winName, int m
675796
}
676797
}
677798

799+
#if defined(OPENCV_HIGHGUI_WITHOUT_BUILTIN_BACKEND) && defined(ENABLE_PLUGINS)
800+
auto backend = getCurrentUIBackend();
801+
if (backend)
802+
{
803+
CV_LOG_WARNING(NULL, "Can't find window with name: '" << winName << "'. Do nothing");
804+
CV_NOT_FOUND_DEPRECATION;
805+
}
806+
else
807+
{
808+
CV_LOG_WARNING(NULL, "No UI backends available. Use OPENCV_LOG_LEVEL=DEBUG for investigation");
809+
}
810+
return;
811+
#else
678812
cvSetTrackbarMin(trackbarName.c_str(), winName.c_str(), minval);
813+
#endif
679814
}
680815

681816
int cv::getTrackbarPos( const String& trackbarName, const String& winName )
@@ -693,7 +828,21 @@ int cv::getTrackbarPos( const String& trackbarName, const String& winName )
693828
}
694829
}
695830

831+
#if defined(OPENCV_HIGHGUI_WITHOUT_BUILTIN_BACKEND) && defined(ENABLE_PLUGINS)
832+
auto backend = getCurrentUIBackend();
833+
if (backend)
834+
{
835+
CV_LOG_WARNING(NULL, "Can't find window with name: '" << winName << "'. Do nothing");
836+
CV_NOT_FOUND_DEPRECATION;
837+
}
838+
else
839+
{
840+
CV_LOG_WARNING(NULL, "No UI backends available. Use OPENCV_LOG_LEVEL=DEBUG for investigation");
841+
}
842+
return -1;
843+
#else
696844
return cvGetTrackbarPos(trackbarName.c_str(), winName.c_str());
845+
#endif
697846
}
698847

699848
void cv::setMouseCallback( const String& windowName, MouseCallback onMouse, void* param)
@@ -709,7 +858,21 @@ void cv::setMouseCallback( const String& windowName, MouseCallback onMouse, void
709858
}
710859
}
711860

861+
#if defined(OPENCV_HIGHGUI_WITHOUT_BUILTIN_BACKEND) && defined(ENABLE_PLUGINS)
862+
auto backend = getCurrentUIBackend();
863+
if (backend)
864+
{
865+
CV_LOG_WARNING(NULL, "Can't find window with name: '" << windowName << "'. Do nothing");
866+
CV_NOT_FOUND_DEPRECATION;
867+
}
868+
else
869+
{
870+
CV_LOG_WARNING(NULL, "No UI backends available. Use OPENCV_LOG_LEVEL=DEBUG for investigation");
871+
}
872+
return;
873+
#else
712874
cvSetMouseCallback(windowName.c_str(), onMouse, param);
875+
#endif
713876
}
714877

715878
int cv::getMouseWheelDelta( int flags )

modules/highgui/src/window_gtk.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -2331,6 +2331,11 @@ class GTKTrackbar : public UITrackbar
23312331
class GTKBackendUI : public UIBackend
23322332
{
23332333
public:
2334+
GTKBackendUI()
2335+
{
2336+
// NB: avoid static initialization order fiasco
2337+
(void)getGTKWindows();
2338+
}
23342339
~GTKBackendUI() CV_OVERRIDE
23352340
{
23362341
destroyAllWindows();

0 commit comments

Comments
 (0)