From 81d6842b8eb927ab105620a9a0716a7debe6b8c9 Mon Sep 17 00:00:00 2001 From: Tony Date: Wed, 2 Oct 2013 21:16:40 +0100 Subject: [PATCH 01/21] These changes introduce Gtk3 support into the highgui module. A new option WITH_GTK3 has been added to the cmake configure system to enable compilation under Gtk version 3.The flag HAVE_GTK3 is also introduced to select the new Gtk3 code in the source files. (Gtk2 is disbled when Gtk3 is selected). window_gtk.cpp has been modified to remove obsolete (and deleted from libgtk 3) and introduce new Gtk3 code in its place when compiled for Gtk3. To compile for Gtk2, disable WITH_GTK3 in cmake. To build for Gtk3 both WITH_GTK and WITH_GTK3 must be selected. --- CMakeLists.txt | 2 + cmake/OpenCVFindLibsGUI.cmake | 8 +- cmake/templates/cvconfig.h.cmake | 3 + modules/highgui/CMakeLists.txt | 2 +- modules/highgui/src/window.cpp | 11 ++ modules/highgui/src/window_gtk.cpp | 207 ++++++++++++++++++++++++++--- 6 files changed, 211 insertions(+), 22 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 00c35a949..c989e81a0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -120,6 +120,7 @@ OCV_OPTION(WITH_FFMPEG "Include FFMPEG support" ON OCV_OPTION(WITH_GSTREAMER "Include Gstreamer support" ON IF (UNIX AND NOT APPLE AND NOT ANDROID) ) OCV_OPTION(WITH_GSTREAMER_1_X "Include Gstreamer 1.x support" OFF) OCV_OPTION(WITH_GTK "Include GTK support" ON IF (UNIX AND NOT APPLE AND NOT ANDROID) ) +OCV_OPTION(WITH_GTK3 "Include GTK3 support" ON IF (UNIX AND WITH_GTK AND NOT APPLE AND NOT ANDROID) ) OCV_OPTION(WITH_IPP "Include Intel IPP support" OFF IF (MSVC OR X86 OR X86_64) ) OCV_OPTION(WITH_JASPER "Include JPEG2K support" ON IF (NOT IOS) ) OCV_OPTION(WITH_JPEG "Include JPEG support" ON) @@ -603,6 +604,7 @@ else() endif() else() status(" GTK+ 2.x:" HAVE_GTK THEN "YES (ver ${ALIASOF_gtk+-2.0_VERSION})" ELSE NO) + status(" GTK+ 3.x:" HAVE_GTK3 THEN "YES (ver ${ALIASOF_gtk+-3.0_VERSION})" ELSE NO) status(" GThread :" HAVE_GTHREAD THEN "YES (ver ${ALIASOF_gthread-2.0_VERSION})" ELSE NO) status(" GtkGlExt:" HAVE_GTKGLEXT THEN "YES (ver ${ALIASOF_gtkglext-1.0_VERSION})" ELSE NO) endif() diff --git a/cmake/OpenCVFindLibsGUI.cmake b/cmake/OpenCVFindLibsGUI.cmake index c80beca05..d09ed892b 100644 --- a/cmake/OpenCVFindLibsGUI.cmake +++ b/cmake/OpenCVFindLibsGUI.cmake @@ -39,9 +39,13 @@ if(WITH_QT) endif() # --- GTK --- -ocv_clear_vars(HAVE_GTK HAVE_GTHREAD HAVE_GTKGLEXT) +ocv_clear_vars(HAVE_GTK HAVE_GTK3 HAVE_GTHREAD HAVE_GTKGLEXT) if(WITH_GTK AND NOT HAVE_QT) - CHECK_MODULE(gtk+-2.0 HAVE_GTK) + if(WITH_GTK3) + CHECK_MODULE(gtk+-3.0 HAVE_GTK3) + else() + CHECK_MODULE(gtk+-2.0 HAVE_GTK) + endif() CHECK_MODULE(gthread-2.0 HAVE_GTHREAD) if(WITH_OPENGL) CHECK_MODULE(gtkglext-1.0 HAVE_GTKGLEXT) diff --git a/cmake/templates/cvconfig.h.cmake b/cmake/templates/cvconfig.h.cmake index 56c5d5aad..68e2d13c9 100644 --- a/cmake/templates/cvconfig.h.cmake +++ b/cmake/templates/cvconfig.h.cmake @@ -82,6 +82,9 @@ /* GTK+ 2.x toolkit */ #cmakedefine HAVE_GTK +/* GTK+ 3.x toolkit */ +#cmakedefine HAVE_GTK3 + /* Define to 1 if you have the header file. */ #cmakedefine HAVE_INTTYPES_H 1 diff --git a/modules/highgui/CMakeLists.txt b/modules/highgui/CMakeLists.txt index 011bb0dc3..e8505f416 100644 --- a/modules/highgui/CMakeLists.txt +++ b/modules/highgui/CMakeLists.txt @@ -106,7 +106,7 @@ elseif(HAVE_QT) endif() elseif(HAVE_WIN32UI) list(APPEND highgui_srcs src/window_w32.cpp) -elseif(HAVE_GTK) +elseif(HAVE_GTK OR HAVE_GTK3) list(APPEND highgui_srcs src/window_gtk.cpp) elseif(HAVE_CARBON) list(APPEND highgui_srcs src/window_carbon.cpp) diff --git a/modules/highgui/src/window.cpp b/modules/highgui/src/window.cpp index 428ef51ef..6d5047075 100644 --- a/modules/highgui/src/window.cpp +++ b/modules/highgui/src/window.cpp @@ -61,6 +61,8 @@ CV_IMPL void cvSetWindowProperty(const char* name, int prop_id, double prop_valu cvSetModeWindow_W32(name,prop_value); #elif defined (HAVE_GTK) cvSetModeWindow_GTK(name,prop_value); + #elif defined (HAVE_GTK3) + cvSetModeWindow_GTK(name,prop_value); #elif defined (HAVE_CARBON) cvSetModeWindow_CARBON(name,prop_value); #elif defined (HAVE_COCOA) @@ -100,6 +102,8 @@ CV_IMPL double cvGetWindowProperty(const char* name, int prop_id) return cvGetModeWindow_W32(name); #elif defined (HAVE_GTK) return cvGetModeWindow_GTK(name); + #elif defined (HAVE_GTK3) + return cvGetModeWindow_GTK(name); #elif defined (HAVE_CARBON) return cvGetModeWindow_CARBON(name); #elif defined (HAVE_COCOA) @@ -117,6 +121,8 @@ CV_IMPL double cvGetWindowProperty(const char* name, int prop_id) return cvGetPropWindowAutoSize_W32(name); #elif defined (HAVE_GTK) return cvGetPropWindowAutoSize_GTK(name); + #elif defined (HAVE_GTK3) + return cvGetPropWindowAutoSize_GTK(name); #else return -1; #endif @@ -130,6 +136,8 @@ CV_IMPL double cvGetWindowProperty(const char* name, int prop_id) return cvGetRatioWindow_W32(name); #elif defined (HAVE_GTK) return cvGetRatioWindow_GTK(name); + #elif defined (HAVE_GTK3) + return cvGetRatioWindow_GTK(name); #else return -1; #endif @@ -143,6 +151,8 @@ CV_IMPL double cvGetWindowProperty(const char* name, int prop_id) return cvGetOpenGlProp_W32(name); #elif defined (HAVE_GTK) return cvGetOpenGlProp_GTK(name); + #elif defined (HAVE_GTK3) + return cvGetOpenGlProp_GTK(name); #else return -1; #endif @@ -472,6 +482,7 @@ int cv::createButton(const String&, ButtonCallback, void*, int , bool ) #if defined(HAVE_WIN32UI) // see window_w32.cpp #elif defined (HAVE_GTK) // see window_gtk.cpp +#elif defined (HAVE_GTK3) // see window_gtk.cpp #elif defined (HAVE_COCOA) // see window_carbon.cpp #elif defined (HAVE_CARBON) #elif defined (HAVE_QT) //YV see window_QT.cpp diff --git a/modules/highgui/src/window_gtk.cpp b/modules/highgui/src/window_gtk.cpp index c467155a3..95fee5163 100644 --- a/modules/highgui/src/window_gtk.cpp +++ b/modules/highgui/src/window_gtk.cpp @@ -43,7 +43,7 @@ #ifndef WIN32 -#ifdef HAVE_GTK +#if defined (HAVE_GTK) || defined (HAVE_GTK3) #include "gtk/gtk.h" #include "gdk/gdkkeysyms.h" @@ -150,32 +150,77 @@ cvImageWidget_realize (GtkWidget *widget) GdkWindowAttr attributes; gint attributes_mask; +#if defined(HAVE_GTK3) + GtkAllocation allocation; + gtk_widget_get_allocation(widget, &allocation); +#endif //HAVE_GTK3 + //printf("cvImageWidget_realize\n"); g_return_if_fail (widget != NULL); g_return_if_fail (CV_IS_IMAGE_WIDGET (widget)); - gtk_widget_set_realized(widget, true); + gtk_widget_set_realized(widget, TRUE); +#if defined(HAVE_GTK3) + attributes.x = allocation.x; + attributes.y = allocation.y; + attributes.width = allocation.width; + attributes.height = allocation.height; +#else attributes.x = widget->allocation.x; attributes.y = widget->allocation.y; attributes.width = widget->allocation.width; attributes.height = widget->allocation.height; +#endif //HAVE_GTK3 + attributes.wclass = GDK_INPUT_OUTPUT; attributes.window_type = GDK_WINDOW_CHILD; attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK; attributes.visual = gtk_widget_get_visual (widget); - attributes.colormap = gtk_widget_get_colormap (widget); +#if defined(HAVE_GTK3) + attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL; + gtk_widget_set_window( + widget, + gdk_window_new( + gtk_widget_get_parent_window(widget), + &attributes, + attributes_mask + ) + ); + + gtk_widget_set_style( + widget, + gtk_style_attach( + gtk_widget_get_style(widget), + gtk_widget_get_window(widget) + ) + ); + + gdk_window_set_user_data ( + gtk_widget_get_window(widget), + widget + ); + + gtk_style_set_background ( + gtk_widget_get_style(widget), + gtk_widget_get_window(widget), + GTK_STATE_ACTIVE + ); + #else + // The following lines are included to prevent breaking + // compatibility with older Gtk2 (window = gdk_window_new (widget->parent->window, &attributes, attributes_mask); widget->style = gtk_style_attach (widget->style, widget->window); - gdk_window_set_user_data (widget->window, widget); gtk_style_set_background (widget->style, widget->window, GTK_STATE_ACTIVE); +#endif // HAVE_GTK3 } static CvSize cvImageWidget_calc_size( int im_width, int im_height, int max_width, int max_height ){ @@ -218,6 +263,26 @@ cvImageWidget_size_request (GtkWidget *widget, //printf("%d %d\n",requisition->width, requisition->height); } +#if defined (HAVE_GTK3) +static void +cvImageWidget_get_preferred_width (GtkWidget *widget, gint *minimal_width, gint *natural_width) +{ + GtkRequisition requisition; + + cvImageWidget_size_request (widget, &requisition); + *minimal_width = *natural_width = requisition.width; +} + +static void +cvImageWidget_get_preferred_height (GtkWidget *widget, gint *minimal_height, gint *natural_height) +{ + GtkRequisition requisition; + + cvImageWidget_size_request (widget, &requisition); + *minimal_height = *natural_height = requisition.height; +} +#endif //HAVE_GTK3 + static void cvImageWidget_set_size(GtkWidget * widget, int max_width, int max_height){ CvImageWidget * image_widget = CV_IMAGE_WIDGET( widget ); @@ -237,7 +302,7 @@ static void cvImageWidget_set_size(GtkWidget * widget, int max_width, int max_he cvReleaseMat( &image_widget->scaled_image ); } if( !image_widget->scaled_image ){ - image_widget->scaled_image = cvCreateMat( scaled_image_size.height, scaled_image_size.width, CV_8UC3 ); + image_widget->scaled_image = cvCreateMat( scaled_image_size.height, scaled_image_size.width, CV_8UC3 ); } @@ -255,7 +320,11 @@ cvImageWidget_size_allocate (GtkWidget *widget, g_return_if_fail (CV_IS_IMAGE_WIDGET (widget)); g_return_if_fail (allocation != NULL); +#if defined (HAVE_GTK3) + gtk_widget_set_allocation(widget, allocation); +#else widget->allocation = *allocation; +#endif //HAVE_GTK3 image_widget = CV_IMAGE_WIDGET (widget); @@ -279,26 +348,37 @@ cvImageWidget_size_allocate (GtkWidget *widget, ((image_widget->flags & CV_WINDOW_AUTOSIZE) || (image_widget->flags & CV_WINDOW_NO_IMAGE)) ) { +#if defined (HAVE_GTK3) + allocation->width = image_widget->original_image->cols; + allocation->height = image_widget->original_image->rows; + gtk_widget_set_allocation(widget, allocation); +#else widget->allocation.width = image_widget->original_image->cols; widget->allocation.height = image_widget->original_image->rows; - gdk_window_move_resize( widget->window, allocation->x, allocation->y, - image_widget->original_image->cols, image_widget->original_image->rows ); +#endif //HAVE_GTK3 + gdk_window_move_resize( gtk_widget_get_window(widget), + allocation->x, allocation->y, + image_widget->original_image->cols, image_widget->original_image->rows ); if(image_widget->flags & CV_WINDOW_NO_IMAGE){ image_widget->flags &= ~CV_WINDOW_NO_IMAGE; gtk_widget_queue_resize( GTK_WIDGET(widget) ); } } else{ - gdk_window_move_resize (widget->window, + gdk_window_move_resize (gtk_widget_get_window(widget), allocation->x, allocation->y, allocation->width, allocation->height ); - } } } +#if defined (HAVE_GTK3) +static void +cvImageWidget_destroy (GtkWidget *object) +#else static void cvImageWidget_destroy (GtkObject *object) +#endif //HAVE_GTK3 { CvImageWidget *image_widget; @@ -310,24 +390,39 @@ cvImageWidget_destroy (GtkObject *object) cvReleaseMat( &image_widget->scaled_image ); cvReleaseMat( &image_widget->original_image ); +#if defined (HAVE_GTK3) + if (GTK_WIDGET_CLASS (parent_class)->destroy) + (* GTK_WIDGET_CLASS (parent_class)->destroy) (object); +#else if (GTK_OBJECT_CLASS (parent_class)->destroy) (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); +#endif //HAVE_GTK3 } static void cvImageWidget_class_init (CvImageWidgetClass * klass) { +#if defined (HAVE_GTK3) + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); +#else GtkObjectClass *object_class; GtkWidgetClass *widget_class; object_class = (GtkObjectClass*) klass; widget_class = (GtkWidgetClass*) klass; +#endif //HAVE_GTK3 parent_class = GTK_WIDGET_CLASS( g_type_class_peek (gtk_widget_get_type ()) ); +#if defined (HAVE_GTK3) + widget_class->destroy = cvImageWidget_destroy; + widget_class->get_preferred_width = cvImageWidget_get_preferred_width; + widget_class->get_preferred_height = cvImageWidget_get_preferred_height; +#else object_class->destroy = cvImageWidget_destroy; + widget_class->size_request = cvImageWidget_size_request; +#endif //HAVE_GTK3 widget_class->realize = cvImageWidget_realize; - widget_class->size_request = cvImageWidget_size_request; widget_class->size_allocate = cvImageWidget_size_allocate; widget_class->button_press_event = NULL; widget_class->button_release_event = NULL; @@ -347,13 +442,15 @@ GType cvImageWidget_get_type (void){ if (!image_type) { - image_type = g_type_register_static_simple( GTK_TYPE_WIDGET, - (gchar*) "CvImageWidget", - sizeof(CvImageWidgetClass), - (GClassInitFunc) cvImageWidget_class_init, - sizeof(CvImageWidget), - (GInstanceInitFunc) cvImageWidget_init, - (GTypeFlags)NULL); + image_type = g_type_register_static_simple( + GTK_TYPE_WIDGET, + (gchar*) "CvImageWidget", + sizeof(CvImageWidgetClass), + (GClassInitFunc) cvImageWidget_class_init, + sizeof(CvImageWidget), + (GInstanceInitFunc) cvImageWidget_init, + (GTypeFlags)NULL + ); } return image_type; @@ -642,8 +739,12 @@ double cvGetRatioWindow_GTK(const char* name) if (!window) EXIT; // keep silence here +#if defined (HAVE_GTK3) + result = static_cast( + gtk_widget_get_allocated_width(window->widget)) / gtk_widget_get_allocated_height(window->widget); +#else result = static_cast(window->widget->allocation.width) / window->widget->allocation.height; - +#endif // HAVE_GTK3 __END__; return result; @@ -738,7 +839,56 @@ namespace #endif // HAVE_OPENGL +#if defined (HAVE_GTK3) +static gboolean cvImageWidget_draw(GtkWidget* widget, cairo_t *cr, gpointer data) +{ +#ifdef HAVE_OPENGL + CvWindow* window = (CvWindow*)data; + if (window->useGl) + { + drawGl(window); + return TRUE; + } +#else + (void)data; +#endif + + CvImageWidget *image_widget = NULL; + GdkPixbuf *pixbuf = NULL; + + g_return_val_if_fail (widget != NULL, FALSE); + g_return_val_if_fail (CV_IS_IMAGE_WIDGET (widget), FALSE); + + cr = gdk_cairo_create(gtk_widget_get_window(widget)); + image_widget = CV_IMAGE_WIDGET (widget); + + if( image_widget->scaled_image ){ + // center image in available region + int x0 = (gtk_widget_get_allocated_width(widget) - image_widget->scaled_image->cols)/2; + int y0 = (gtk_widget_get_allocated_height(widget) - image_widget->scaled_image->rows)/2; + + pixbuf = gdk_pixbuf_new_from_data(image_widget->scaled_image->data.ptr, GDK_COLORSPACE_RGB, false, + 8, MIN(image_widget->scaled_image->cols, gtk_widget_get_allocated_width(widget)), + MIN(image_widget->scaled_image->rows, gtk_widget_get_allocated_height(widget)), + image_widget->scaled_image->step, NULL, NULL); + + gdk_cairo_set_source_pixbuf(cr, pixbuf, x0, y0); + } + else if( image_widget->original_image ){ + pixbuf = gdk_pixbuf_new_from_data(image_widget->original_image->data.ptr, GDK_COLORSPACE_RGB, false, + 8, MIN(image_widget->original_image->cols, gtk_widget_get_allocated_width(widget)), + MIN(image_widget->original_image->rows, gtk_widget_get_allocated_height(widget)), + image_widget->original_image->step, NULL, NULL); + gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0); + } + + cairo_paint(cr); + cairo_destroy(cr); + return TRUE; +} + +#else static gboolean cvImageWidget_expose(GtkWidget* widget, GdkEventExpose* event, gpointer data) { #ifdef HAVE_OPENGL @@ -776,6 +926,7 @@ static gboolean cvImageWidget_expose(GtkWidget* widget, GdkEventExpose* event, g 8, MIN(image_widget->scaled_image->cols, widget->allocation.width), MIN(image_widget->scaled_image->rows, widget->allocation.height), image_widget->scaled_image->step, NULL, NULL); + gdk_cairo_set_source_pixbuf(cr, pixbuf, x0, y0); } else if( image_widget->original_image ){ @@ -790,6 +941,7 @@ static gboolean cvImageWidget_expose(GtkWidget* widget, GdkEventExpose* event, g cairo_destroy(cr); return TRUE; } +#endif //HAVE_GTK3 CV_IMPL int cvNamedWindow( const char* name, int flags ) { @@ -862,8 +1014,13 @@ CV_IMPL int cvNamedWindow( const char* name, int flags ) G_CALLBACK(icvOnMouse), window ); g_signal_connect( window->frame, "delete-event", G_CALLBACK(icvOnClose), window ); +#if defined(HAVE_GTK3) + g_signal_connect( window->widget, "draw", + G_CALLBACK(cvImageWidget_draw), window ); +#else g_signal_connect( window->widget, "expose-event", G_CALLBACK(cvImageWidget_expose), window ); +#endif //HAVE_GTK3 gtk_widget_add_events (window->widget, GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK) ; @@ -1420,6 +1577,13 @@ CV_IMPL const char* cvGetWindowName( void* window_handle ) return window_name; } +#if defined (HAVE_GTK3) +#define GDK_Escape GDK_KEY_Escape +#define GDK_Return GDK_KEY_Return +#define GDK_Linefeed GDK_KEY_Linefeed +#define GDK_Tab GDK_KEY_Tab +#endif //HAVE_GTK3 + static gboolean icvOnKeyPress( GtkWidget * /*widget*/, GdkEventKey* event, gpointer /*user_data*/ ) { @@ -1550,8 +1714,13 @@ static gboolean icvOnMouse( GtkWidget *widget, GdkEvent *event, gpointer user_da image_widget->original_image && image_widget->scaled_image ){ // image origin is not necessarily at (0,0) +#if defined (HAVE_GTK3) + int x0 = (gtk_widget_get_allocated_width(widget) - image_widget->scaled_image->cols)/2; + int y0 = (gtk_widget_get_allocated_height(widget) - image_widget->scaled_image->rows)/2; +#else int x0 = (widget->allocation.width - image_widget->scaled_image->cols)/2; int y0 = (widget->allocation.height - image_widget->scaled_image->rows)/2; +#endif //HAVE_GTK3 pt.x = cvRound( ((pt32f.x-x0)*image_widget->original_image->cols)/ image_widget->scaled_image->cols ); pt.y = cvRound( ((pt32f.y-y0)*image_widget->original_image->rows)/ @@ -1629,7 +1798,7 @@ CV_IMPL int cvWaitKey( int delay ) } -#endif // HAVE_GTK +#endif // HAVE_GTK || HAVE_GTK3 #endif // WIN32 /* End of file. */ From c1cd70e25abc1391aa3055fd09a22ae5197d7292 Mon Sep 17 00:00:00 2001 From: Tony Date: Fri, 4 Oct 2013 23:09:45 +0100 Subject: [PATCH 02/21] Disable OpenGL when Gtk3 is selected The OpenGL library is not supported on Gtk3 which uses the cairo library for rendering. Cairo, in turn uses hardware acceleration when supported by the underlying system. Some improvement to performance may be gained by useing the cairo-gl and cairo-glx libraries included on modern Gtk3 systems. See the cairo documentation for further information. The following link may also be of interest. http://lists.cairographics.org/archives/cairo/2012-October/023609.html --- cmake/OpenCVFindLibsGUI.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/OpenCVFindLibsGUI.cmake b/cmake/OpenCVFindLibsGUI.cmake index d09ed892b..ad9519648 100644 --- a/cmake/OpenCVFindLibsGUI.cmake +++ b/cmake/OpenCVFindLibsGUI.cmake @@ -47,7 +47,7 @@ if(WITH_GTK AND NOT HAVE_QT) CHECK_MODULE(gtk+-2.0 HAVE_GTK) endif() CHECK_MODULE(gthread-2.0 HAVE_GTHREAD) - if(WITH_OPENGL) + if(WITH_OPENGL AND NOT HAVE_GTK3) CHECK_MODULE(gtkglext-1.0 HAVE_GTKGLEXT) endif() endif() From d4df373999318f28b08de9ccddf651a856de62e4 Mon Sep 17 00:00:00 2001 From: Tony Date: Wed, 9 Oct 2013 20:50:35 +0100 Subject: [PATCH 03/21] Code cleanup Remove redundent #if defs from code --- modules/highgui/src/window.cpp | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/modules/highgui/src/window.cpp b/modules/highgui/src/window.cpp index 6d5047075..94f56e2e4 100644 --- a/modules/highgui/src/window.cpp +++ b/modules/highgui/src/window.cpp @@ -59,9 +59,7 @@ CV_IMPL void cvSetWindowProperty(const char* name, int prop_id, double prop_valu cvSetModeWindow_QT(name,prop_value); #elif defined(HAVE_WIN32UI) cvSetModeWindow_W32(name,prop_value); - #elif defined (HAVE_GTK) - cvSetModeWindow_GTK(name,prop_value); - #elif defined (HAVE_GTK3) + #elif defined (HAVE_GTK) | defined (HAVE_GTK3) cvSetModeWindow_GTK(name,prop_value); #elif defined (HAVE_CARBON) cvSetModeWindow_CARBON(name,prop_value); @@ -100,9 +98,7 @@ CV_IMPL double cvGetWindowProperty(const char* name, int prop_id) return cvGetModeWindow_QT(name); #elif defined(HAVE_WIN32UI) return cvGetModeWindow_W32(name); - #elif defined (HAVE_GTK) - return cvGetModeWindow_GTK(name); - #elif defined (HAVE_GTK3) + #elif defined (HAVE_GTK) | defined(HAVE_GTK3) return cvGetModeWindow_GTK(name); #elif defined (HAVE_CARBON) return cvGetModeWindow_CARBON(name); @@ -119,9 +115,7 @@ CV_IMPL double cvGetWindowProperty(const char* name, int prop_id) return cvGetPropWindow_QT(name); #elif defined(HAVE_WIN32UI) return cvGetPropWindowAutoSize_W32(name); - #elif defined (HAVE_GTK) - return cvGetPropWindowAutoSize_GTK(name); - #elif defined (HAVE_GTK3) + #elif defined (HAVE_GTK) | defined(HAVE_GTK3) return cvGetPropWindowAutoSize_GTK(name); #else return -1; @@ -134,9 +128,7 @@ CV_IMPL double cvGetWindowProperty(const char* name, int prop_id) return cvGetRatioWindow_QT(name); #elif defined(HAVE_WIN32UI) return cvGetRatioWindow_W32(name); - #elif defined (HAVE_GTK) - return cvGetRatioWindow_GTK(name); - #elif defined (HAVE_GTK3) + #elif defined (HAVE_GTK) | defined(HAVE_GTK3) return cvGetRatioWindow_GTK(name); #else return -1; @@ -149,9 +141,7 @@ CV_IMPL double cvGetWindowProperty(const char* name, int prop_id) return cvGetOpenGlProp_QT(name); #elif defined(HAVE_WIN32UI) return cvGetOpenGlProp_W32(name); - #elif defined (HAVE_GTK) - return cvGetOpenGlProp_GTK(name); - #elif defined (HAVE_GTK3) + #elif defined (HAVE_GTK) | defined(HAVE_GTK3) return cvGetOpenGlProp_GTK(name); #else return -1; From 5368f12b333e05ef79f161451b0e68621e236135 Mon Sep 17 00:00:00 2001 From: Tony Date: Tue, 15 Oct 2013 21:49:20 +0100 Subject: [PATCH 04/21] Rework gtk3 window resize and draw cleanup The gtk3 resize functions fail to shrink the window after it has been resized. This edit changes this and allows the window to be shrunk back to its original size. This edit also cleans up the draw/expose functions. --- modules/highgui/src/window_gtk.cpp | 73 +++++++++++++++++++++--------- 1 file changed, 52 insertions(+), 21 deletions(-) diff --git a/modules/highgui/src/window_gtk.cpp b/modules/highgui/src/window_gtk.cpp index 95fee5163..d20999648 100644 --- a/modules/highgui/src/window_gtk.cpp +++ b/modules/highgui/src/window_gtk.cpp @@ -232,6 +232,56 @@ static CvSize cvImageWidget_calc_size( int im_width, int im_height, int max_widt return cvSize( cvRound(max_height*aspect), max_height ); } +#if defined (HAVE_GTK3) +static void +cvImageWidget_get_preferred_width (GtkWidget *widget, gint *minimal_width, gint *natural_width) +{ + g_return_if_fail (widget != NULL); + g_return_if_fail (CV_IS_IMAGE_WIDGET (widget)); + CvImageWidget * image_widget = CV_IMAGE_WIDGET( widget ); + + if(image_widget->original_image != NULL) { + *minimal_width = image_widget->flags & CV_WINDOW_AUTOSIZE ? + gdk_window_get_width(gtk_widget_get_window(widget)) : image_widget->original_image->cols; + } + else { + *minimal_width = 320; + } + + if(image_widget->scaled_image != NULL) { + *natural_width = *minimal_width < image_widget->scaled_image->cols ? + image_widget->scaled_image->cols : *minimal_width; + } + else { + *natural_width = *minimal_width; + } +} + +static void +cvImageWidget_get_preferred_height (GtkWidget *widget, gint *minimal_height, gint *natural_height) +{ + g_return_if_fail (widget != NULL); + g_return_if_fail (CV_IS_IMAGE_WIDGET (widget)); + CvImageWidget * image_widget = CV_IMAGE_WIDGET( widget ); + + if(image_widget->original_image != NULL) { + *minimal_height = image_widget->flags & CV_WINDOW_AUTOSIZE ? + gdk_window_get_height(gtk_widget_get_window(widget)) : image_widget->original_image->rows; + } + else { + *minimal_height = 240; + } + + if(image_widget->scaled_image != NULL) { + *natural_height = *minimal_height < image_widget->scaled_image->rows ? + image_widget->scaled_image->cols : *minimal_height; + } + else { + *natural_height = *minimal_height; + } +} + +#else static void cvImageWidget_size_request (GtkWidget *widget, GtkRequisition *requisition) @@ -262,25 +312,6 @@ cvImageWidget_size_request (GtkWidget *widget, } //printf("%d %d\n",requisition->width, requisition->height); } - -#if defined (HAVE_GTK3) -static void -cvImageWidget_get_preferred_width (GtkWidget *widget, gint *minimal_width, gint *natural_width) -{ - GtkRequisition requisition; - - cvImageWidget_size_request (widget, &requisition); - *minimal_width = *natural_width = requisition.width; -} - -static void -cvImageWidget_get_preferred_height (GtkWidget *widget, gint *minimal_height, gint *natural_height) -{ - GtkRequisition requisition; - - cvImageWidget_size_request (widget, &requisition); - *minimal_height = *natural_height = requisition.height; -} #endif //HAVE_GTK3 static void cvImageWidget_set_size(GtkWidget * widget, int max_width, int max_height){ @@ -860,7 +891,6 @@ static gboolean cvImageWidget_draw(GtkWidget* widget, cairo_t *cr, gpointer data g_return_val_if_fail (widget != NULL, FALSE); g_return_val_if_fail (CV_IS_IMAGE_WIDGET (widget), FALSE); - cr = gdk_cairo_create(gtk_widget_get_window(widget)); image_widget = CV_IMAGE_WIDGET (widget); if( image_widget->scaled_image ){ @@ -884,7 +914,7 @@ static gboolean cvImageWidget_draw(GtkWidget* widget, cairo_t *cr, gpointer data } cairo_paint(cr); - cairo_destroy(cr); + g_object_unref(pixbuf); return TRUE; } @@ -938,6 +968,7 @@ static gboolean cvImageWidget_expose(GtkWidget* widget, GdkEventExpose* event, g } cairo_paint(cr); + g_object_unref(pixbuf); cairo_destroy(cr); return TRUE; } From 69dc8405832e971c4642d4219d36419f2f8a99c9 Mon Sep 17 00:00:00 2001 From: Tony Date: Tue, 26 Nov 2013 21:35:03 +0000 Subject: [PATCH 05/21] mprove Gtk2/3 options in cmake Update to cmake files for to include minimum versions, and tidy up gtk operation. Files updated: CMakeLists.txt: WITH_GTK now uses Gtk3 by default. If not found then Gtk2 is used. WITH_GTK_2_X forces Gtk2.x use cmake/OpenCVFindLibsGUI.cmake Updated selection logic to implement methodology described above. Implemented warning if Gtk3 not found (and not overridden) Implemented error if Gtk does not meet minimum required version cmake/OpenCVMinDepVersions.cmake Added minimum Gtk version of 2.18.0 --- CMakeLists.txt | 2 +- cmake/OpenCVFindLibsGUI.cmake | 15 ++++++++++++--- cmake/OpenCVMinDepVersions.cmake | 1 + 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c989e81a0..ba0f27bfa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -120,7 +120,7 @@ OCV_OPTION(WITH_FFMPEG "Include FFMPEG support" ON OCV_OPTION(WITH_GSTREAMER "Include Gstreamer support" ON IF (UNIX AND NOT APPLE AND NOT ANDROID) ) OCV_OPTION(WITH_GSTREAMER_1_X "Include Gstreamer 1.x support" OFF) OCV_OPTION(WITH_GTK "Include GTK support" ON IF (UNIX AND NOT APPLE AND NOT ANDROID) ) -OCV_OPTION(WITH_GTK3 "Include GTK3 support" ON IF (UNIX AND WITH_GTK AND NOT APPLE AND NOT ANDROID) ) +OCV_OPTION(WITH_GTK_2_X "Use GTK version 2" OFF IF (UNIX AND NOT APPLE AND NOT ANDROID) ) OCV_OPTION(WITH_IPP "Include Intel IPP support" OFF IF (MSVC OR X86 OR X86_64) ) OCV_OPTION(WITH_JASPER "Include JPEG2K support" ON IF (NOT IOS) ) OCV_OPTION(WITH_JPEG "Include JPEG support" ON) diff --git a/cmake/OpenCVFindLibsGUI.cmake b/cmake/OpenCVFindLibsGUI.cmake index ad9519648..5bb6d57f5 100644 --- a/cmake/OpenCVFindLibsGUI.cmake +++ b/cmake/OpenCVFindLibsGUI.cmake @@ -41,12 +41,21 @@ endif() # --- GTK --- ocv_clear_vars(HAVE_GTK HAVE_GTK3 HAVE_GTHREAD HAVE_GTKGLEXT) if(WITH_GTK AND NOT HAVE_QT) - if(WITH_GTK3) - CHECK_MODULE(gtk+-3.0 HAVE_GTK3) - else() + if(WITH_GTK_2_X) CHECK_MODULE(gtk+-2.0 HAVE_GTK) + if(HAVE_GTK AND (ALIASOF_gtk+-2.0_VERSION VERSION_LESS MIN_VER_GTK)) + message (FATAL_ERROR "Gtk support requires a minimum gtk+ version of ${MIN_VER_GTK} (${ALIASOF_gtk+-2.0_VERSION} found)") + endif() + else() + CHECK_MODULE(gtk+-3.0 HAVE_GTK3) + if(NOT HAVE_GTK3) + message(WARNING "Unable to locate Gtk3 development libraries") + endif() endif() CHECK_MODULE(gthread-2.0 HAVE_GTHREAD) + if(HAVE_GTK OR HAVE_GTK3 AND NOT HAVE_GTHREAD) + message(FATAL_ERROR "gthread not found. This library is required when building with Gtk support") + endif() if(WITH_OPENGL AND NOT HAVE_GTK3) CHECK_MODULE(gtkglext-1.0 HAVE_GTKGLEXT) endif() diff --git a/cmake/OpenCVMinDepVersions.cmake b/cmake/OpenCVMinDepVersions.cmake index b659a8379..b70a60cf6 100644 --- a/cmake/OpenCVMinDepVersions.cmake +++ b/cmake/OpenCVMinDepVersions.cmake @@ -1,3 +1,4 @@ set(MIN_VER_CMAKE 2.8.7) set(MIN_VER_PYTHON 2.6) set(MIN_VER_ZLIB 1.2.3) +set(MIN_VER_GTK 2.18.0) From 7f671406db37ae03259eddd218079a5afd121bd3 Mon Sep 17 00:00:00 2001 From: Tony Date: Mon, 31 Mar 2014 22:05:09 +0100 Subject: [PATCH 06/21] Use GTK_VERSION_MAJOR to switch between GTK+ version two and three specific code. As a result of this, HAVE_GTK3 no longer needs to be exposed. The use of HAVE_GTK, and HAVE_ GTK3 have been changed to mirror the method used by HAVE_QT and HAVE_QT5. On branch gtk3 Changes to be committed: modified: CMakeLists.txt modified: cmake/OpenCVFindLibsGUI.cmake modified: cmake/templates/cvconfig.h.in modified: modules/highgui/src/window.cpp modified: modules/highgui/src/window_gtk.cpp --- CMakeLists.txt | 11 +- cmake/OpenCVFindLibsGUI.cmake | 10 +- cmake/templates/cvconfig.h.in | 3 - modules/highgui/src/window.cpp | 11 +- modules/highgui/src/window_gtk.cpp | 238 ++++++++++++++++++++++++++--- 5 files changed, 241 insertions(+), 32 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ec5086c1e..f15f701a7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -748,8 +748,15 @@ else() status(" Cocoa:" YES) endif() else() - status(" GTK+ 2.x:" HAVE_GTK THEN "YES (ver ${ALIASOF_gtk+-2.0_VERSION})" ELSE NO) - status(" GTK+ 3.x:" HAVE_GTK3 THEN "YES (ver ${ALIASOF_gtk+-3.0_VERSION})" ELSE NO) + if(HAVE_GTK3) + status(" GTK+ 3.x:" HAVE_GTK THEN "YES (ver ${ALIASOF_gtk+-3.0_VERSION})" ELSE NO) + elseif(HAVE_GTK) + status(" GTK+ 2.x:" HAVE_GTK THEN "YES (ver ${ALIASOF_gtk+-2.0_VERSION})" ELSE NO) + else() + if(DEFINED WITH_GTK) + staus(" GTK+:" NO) + endif() + endif() status(" GThread :" HAVE_GTHREAD THEN "YES (ver ${ALIASOF_gthread-2.0_VERSION})" ELSE NO) status(" GtkGlExt:" HAVE_GTKGLEXT THEN "YES (ver ${ALIASOF_gtkglext-1.0_VERSION})" ELSE NO) endif() diff --git a/cmake/OpenCVFindLibsGUI.cmake b/cmake/OpenCVFindLibsGUI.cmake index 5bb6d57f5..0ef693bbd 100644 --- a/cmake/OpenCVFindLibsGUI.cmake +++ b/cmake/OpenCVFindLibsGUI.cmake @@ -44,17 +44,19 @@ if(WITH_GTK AND NOT HAVE_QT) if(WITH_GTK_2_X) CHECK_MODULE(gtk+-2.0 HAVE_GTK) if(HAVE_GTK AND (ALIASOF_gtk+-2.0_VERSION VERSION_LESS MIN_VER_GTK)) - message (FATAL_ERROR "Gtk support requires a minimum gtk+ version of ${MIN_VER_GTK} (${ALIASOF_gtk+-2.0_VERSION} found)") + message (FATAL_ERROR "GTK support requires a minimum version of ${MIN_VER_GTK} (${ALIASOF_gtk+-2.0_VERSION} found)") endif() else() CHECK_MODULE(gtk+-3.0 HAVE_GTK3) - if(NOT HAVE_GTK3) - message(WARNING "Unable to locate Gtk3 development libraries") + if(HAVE_GTK3) + set(HAVE_GTK ON) + else() + message(WARNING "Unable to locate GTK3 development libraries") endif() endif() CHECK_MODULE(gthread-2.0 HAVE_GTHREAD) if(HAVE_GTK OR HAVE_GTK3 AND NOT HAVE_GTHREAD) - message(FATAL_ERROR "gthread not found. This library is required when building with Gtk support") + message(FATAL_ERROR "gthread not found. This library is required when building with GTK support") endif() if(WITH_OPENGL AND NOT HAVE_GTK3) CHECK_MODULE(gtkglext-1.0 HAVE_GTKGLEXT) diff --git a/cmake/templates/cvconfig.h.in b/cmake/templates/cvconfig.h.in index 0a916682c..3f316da46 100644 --- a/cmake/templates/cvconfig.h.in +++ b/cmake/templates/cvconfig.h.in @@ -85,9 +85,6 @@ /* GTK+ 2.x toolkit */ #cmakedefine HAVE_GTK -/* GTK+ 3.x toolkit */ -#cmakedefine HAVE_GTK3 - /* Define to 1 if you have the header file. */ #cmakedefine HAVE_INTTYPES_H 1 diff --git a/modules/highgui/src/window.cpp b/modules/highgui/src/window.cpp index ecd5fb06d..03ff988d7 100644 --- a/modules/highgui/src/window.cpp +++ b/modules/highgui/src/window.cpp @@ -59,7 +59,7 @@ CV_IMPL void cvSetWindowProperty(const char* name, int prop_id, double prop_valu cvSetModeWindow_QT(name,prop_value); #elif defined(HAVE_WIN32UI) cvSetModeWindow_W32(name,prop_value); - #elif defined (HAVE_GTK) | defined (HAVE_GTK3) + #elif defined (HAVE_GTK) cvSetModeWindow_GTK(name,prop_value); #elif defined (HAVE_CARBON) cvSetModeWindow_CARBON(name,prop_value); @@ -98,7 +98,7 @@ CV_IMPL double cvGetWindowProperty(const char* name, int prop_id) return cvGetModeWindow_QT(name); #elif defined(HAVE_WIN32UI) return cvGetModeWindow_W32(name); - #elif defined (HAVE_GTK) | defined(HAVE_GTK3) + #elif defined (HAVE_GTK) return cvGetModeWindow_GTK(name); #elif defined (HAVE_CARBON) return cvGetModeWindow_CARBON(name); @@ -115,7 +115,7 @@ CV_IMPL double cvGetWindowProperty(const char* name, int prop_id) return cvGetPropWindow_QT(name); #elif defined(HAVE_WIN32UI) return cvGetPropWindowAutoSize_W32(name); - #elif defined (HAVE_GTK) | defined(HAVE_GTK3) + #elif defined (HAVE_GTK) return cvGetPropWindowAutoSize_GTK(name); #else return -1; @@ -128,7 +128,7 @@ CV_IMPL double cvGetWindowProperty(const char* name, int prop_id) return cvGetRatioWindow_QT(name); #elif defined(HAVE_WIN32UI) return cvGetRatioWindow_W32(name); - #elif defined (HAVE_GTK) | defined(HAVE_GTK3) + #elif defined (HAVE_GTK) return cvGetRatioWindow_GTK(name); #else return -1; @@ -141,7 +141,7 @@ CV_IMPL double cvGetWindowProperty(const char* name, int prop_id) return cvGetOpenGlProp_QT(name); #elif defined(HAVE_WIN32UI) return cvGetOpenGlProp_W32(name); - #elif defined (HAVE_GTK) | defined(HAVE_GTK3) + #elif defined (HAVE_GTK) return cvGetOpenGlProp_GTK(name); #else return -1; @@ -477,7 +477,6 @@ int cv::createButton(const String&, ButtonCallback, void*, int , bool ) #if defined(HAVE_WIN32UI) // see window_w32.cpp #elif defined (HAVE_GTK) // see window_gtk.cpp -#elif defined (HAVE_GTK3) // see window_gtk.cpp #elif defined (HAVE_COCOA) // see window_carbon.cpp #elif defined (HAVE_CARBON) #elif defined (HAVE_QT) //YV see window_QT.cpp diff --git a/modules/highgui/src/window_gtk.cpp b/modules/highgui/src/window_gtk.cpp index 02c256444..a8dacff7d 100644 --- a/modules/highgui/src/window_gtk.cpp +++ b/modules/highgui/src/window_gtk.cpp @@ -43,13 +43,17 @@ #ifndef WIN32 -#ifdef HAVE_GTK +#if defined (HAVE_GTK) #include "gtk/gtk.h" #include "gdk/gdkkeysyms.h" #include #include +#if (GTK_MAJOR_VERSION == 3) + #define GTK_VERSION3 +#endif //GTK_MAJOR_VERSION >= 3 + #ifdef HAVE_OPENGL #include #include @@ -150,32 +154,77 @@ cvImageWidget_realize (GtkWidget *widget) GdkWindowAttr attributes; gint attributes_mask; +#if defined(GTK_VERSION3) + GtkAllocation allocation; + gtk_widget_get_allocation(widget, &allocation); +#endif //GTK_VERSION3 + //printf("cvImageWidget_realize\n"); g_return_if_fail (widget != NULL); g_return_if_fail (CV_IS_IMAGE_WIDGET (widget)); gtk_widget_set_realized(widget, TRUE); +#if defined(GTK_VERSION3) + attributes.x = allocation.x; + attributes.y = allocation.y; + attributes.width = allocation.width; + attributes.height = allocation.height; +#else attributes.x = widget->allocation.x; attributes.y = widget->allocation.y; attributes.width = widget->allocation.width; attributes.height = widget->allocation.height; +#endif //GTK_VERSION3 + attributes.wclass = GDK_INPUT_OUTPUT; attributes.window_type = GDK_WINDOW_CHILD; attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK; attributes.visual = gtk_widget_get_visual (widget); - attributes.colormap = gtk_widget_get_colormap (widget); +#if defined(GTK_VERSION3) + attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL; + gtk_widget_set_window( + widget, + gdk_window_new( + gtk_widget_get_parent_window(widget), + &attributes, + attributes_mask + ) + ); + + gtk_widget_set_style( + widget, + gtk_style_attach( + gtk_widget_get_style(widget), + gtk_widget_get_window(widget) + ) + ); + + gdk_window_set_user_data ( + gtk_widget_get_window(widget), + widget + ); + + gtk_style_set_background ( + gtk_widget_get_style(widget), + gtk_widget_get_window(widget), + GTK_STATE_ACTIVE + ); + #else + // The following lines are included to prevent breaking + // compatibility with older Gtk2 (window = gdk_window_new (widget->parent->window, &attributes, attributes_mask); widget->style = gtk_style_attach (widget->style, widget->window); - gdk_window_set_user_data (widget->window, widget); gtk_style_set_background (widget->style, widget->window, GTK_STATE_ACTIVE); +#endif // GTK_VERSION3 } static CvSize cvImageWidget_calc_size( int im_width, int im_height, int max_width, int max_height ){ @@ -187,6 +236,56 @@ static CvSize cvImageWidget_calc_size( int im_width, int im_height, int max_widt return cvSize( cvRound(max_height*aspect), max_height ); } +#if defined (GTK_VERSION3) +static void +cvImageWidget_get_preferred_width (GtkWidget *widget, gint *minimal_width, gint *natural_width) +{ + g_return_if_fail (widget != NULL); + g_return_if_fail (CV_IS_IMAGE_WIDGET (widget)); + CvImageWidget * image_widget = CV_IMAGE_WIDGET( widget ); + + if(image_widget->original_image != NULL) { + *minimal_width = image_widget->flags & CV_WINDOW_AUTOSIZE ? + gdk_window_get_width(gtk_widget_get_window(widget)) : image_widget->original_image->cols; + } + else { + *minimal_width = 320; + } + + if(image_widget->scaled_image != NULL) { + *natural_width = *minimal_width < image_widget->scaled_image->cols ? + image_widget->scaled_image->cols : *minimal_width; + } + else { + *natural_width = *minimal_width; + } +} + +static void +cvImageWidget_get_preferred_height (GtkWidget *widget, gint *minimal_height, gint *natural_height) +{ + g_return_if_fail (widget != NULL); + g_return_if_fail (CV_IS_IMAGE_WIDGET (widget)); + CvImageWidget * image_widget = CV_IMAGE_WIDGET( widget ); + + if(image_widget->original_image != NULL) { + *minimal_height = image_widget->flags & CV_WINDOW_AUTOSIZE ? + gdk_window_get_height(gtk_widget_get_window(widget)) : image_widget->original_image->rows; + } + else { + *minimal_height = 240; + } + + if(image_widget->scaled_image != NULL) { + *natural_height = *minimal_height < image_widget->scaled_image->rows ? + image_widget->scaled_image->cols : *minimal_height; + } + else { + *natural_height = *minimal_height; + } +} + +#else static void cvImageWidget_size_request (GtkWidget *widget, GtkRequisition *requisition) @@ -217,6 +316,7 @@ cvImageWidget_size_request (GtkWidget *widget, } //printf("%d %d\n",requisition->width, requisition->height); } +#endif //GTK_VERSION3 static void cvImageWidget_set_size(GtkWidget * widget, int max_width, int max_height){ CvImageWidget * image_widget = CV_IMAGE_WIDGET( widget ); @@ -237,7 +337,7 @@ static void cvImageWidget_set_size(GtkWidget * widget, int max_width, int max_he cvReleaseMat( &image_widget->scaled_image ); } if( !image_widget->scaled_image ){ - image_widget->scaled_image = cvCreateMat( scaled_image_size.height, scaled_image_size.width, CV_8UC3 ); + image_widget->scaled_image = cvCreateMat( scaled_image_size.height, scaled_image_size.width, CV_8UC3 ); } @@ -255,7 +355,11 @@ cvImageWidget_size_allocate (GtkWidget *widget, g_return_if_fail (CV_IS_IMAGE_WIDGET (widget)); g_return_if_fail (allocation != NULL); +#if defined (GTK_VERSION3) + gtk_widget_set_allocation(widget, allocation); +#else widget->allocation = *allocation; +#endif //GTK_VERSION3 image_widget = CV_IMAGE_WIDGET (widget); @@ -279,26 +383,37 @@ cvImageWidget_size_allocate (GtkWidget *widget, ((image_widget->flags & CV_WINDOW_AUTOSIZE) || (image_widget->flags & CV_WINDOW_NO_IMAGE)) ) { +#if defined (GTK_VERSION3) + allocation->width = image_widget->original_image->cols; + allocation->height = image_widget->original_image->rows; + gtk_widget_set_allocation(widget, allocation); +#else widget->allocation.width = image_widget->original_image->cols; widget->allocation.height = image_widget->original_image->rows; - gdk_window_move_resize( widget->window, allocation->x, allocation->y, - image_widget->original_image->cols, image_widget->original_image->rows ); +#endif //GTK_VERSION3 + gdk_window_move_resize( gtk_widget_get_window(widget), + allocation->x, allocation->y, + image_widget->original_image->cols, image_widget->original_image->rows ); if(image_widget->flags & CV_WINDOW_NO_IMAGE){ image_widget->flags &= ~CV_WINDOW_NO_IMAGE; gtk_widget_queue_resize( GTK_WIDGET(widget) ); } } else{ - gdk_window_move_resize (widget->window, + gdk_window_move_resize (gtk_widget_get_window(widget), allocation->x, allocation->y, allocation->width, allocation->height ); - } } } +#if defined (GTK_VERSION3) +static void +cvImageWidget_destroy (GtkWidget *object) +#else static void cvImageWidget_destroy (GtkObject *object) +#endif //GTK_VERSION3 { CvImageWidget *image_widget; @@ -310,24 +425,39 @@ cvImageWidget_destroy (GtkObject *object) cvReleaseMat( &image_widget->scaled_image ); cvReleaseMat( &image_widget->original_image ); +#if defined (GTK_VERSION3) + if (GTK_WIDGET_CLASS (parent_class)->destroy) + (* GTK_WIDGET_CLASS (parent_class)->destroy) (object); +#else if (GTK_OBJECT_CLASS (parent_class)->destroy) (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); +#endif //GTK_VERSION3 } static void cvImageWidget_class_init (CvImageWidgetClass * klass) { +#if defined (GTK_VERSION3) + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); +#else GtkObjectClass *object_class; GtkWidgetClass *widget_class; object_class = (GtkObjectClass*) klass; widget_class = (GtkWidgetClass*) klass; +#endif //GTK_VERSION3 parent_class = GTK_WIDGET_CLASS( g_type_class_peek (gtk_widget_get_type ()) ); +#if defined (GTK_VERSION3) + widget_class->destroy = cvImageWidget_destroy; + widget_class->get_preferred_width = cvImageWidget_get_preferred_width; + widget_class->get_preferred_height = cvImageWidget_get_preferred_height; +#else object_class->destroy = cvImageWidget_destroy; + widget_class->size_request = cvImageWidget_size_request; +#endif //GTK_VERSION3 widget_class->realize = cvImageWidget_realize; - widget_class->size_request = cvImageWidget_size_request; widget_class->size_allocate = cvImageWidget_size_allocate; widget_class->button_press_event = NULL; widget_class->button_release_event = NULL; @@ -347,13 +477,15 @@ GType cvImageWidget_get_type (void){ if (!image_type) { - image_type = g_type_register_static_simple( GTK_TYPE_WIDGET, - (gchar*) "CvImageWidget", - sizeof(CvImageWidgetClass), - (GClassInitFunc) cvImageWidget_class_init, - sizeof(CvImageWidget), - (GInstanceInitFunc) cvImageWidget_init, - (GTypeFlags)NULL); + image_type = g_type_register_static_simple( + GTK_TYPE_WIDGET, + (gchar*) "CvImageWidget", + sizeof(CvImageWidgetClass), + (GClassInitFunc) cvImageWidget_class_init, + sizeof(CvImageWidget), + (GInstanceInitFunc) cvImageWidget_init, + (GTypeFlags)NULL + ); } return image_type; @@ -642,8 +774,12 @@ double cvGetRatioWindow_GTK(const char* name) if (!window) EXIT; // keep silence here +#if defined (GTK_VERSION3) + result = static_cast( + gtk_widget_get_allocated_width(window->widget)) / gtk_widget_get_allocated_height(window->widget); +#else result = static_cast(window->widget->allocation.width) / window->widget->allocation.height; - +#endif // GTK_VERSION3 __END__; return result; @@ -738,7 +874,55 @@ namespace #endif // HAVE_OPENGL +#if defined (GTK_VERSION3) +static gboolean cvImageWidget_draw(GtkWidget* widget, cairo_t *cr, gpointer data) +{ +#ifdef HAVE_OPENGL + CvWindow* window = (CvWindow*)data; + if (window->useGl) + { + drawGl(window); + return TRUE; + } +#else + (void)data; +#endif + + CvImageWidget *image_widget = NULL; + GdkPixbuf *pixbuf = NULL; + + g_return_val_if_fail (widget != NULL, FALSE); + g_return_val_if_fail (CV_IS_IMAGE_WIDGET (widget), FALSE); + + image_widget = CV_IMAGE_WIDGET (widget); + + if( image_widget->scaled_image ){ + // center image in available region + int x0 = (gtk_widget_get_allocated_width(widget) - image_widget->scaled_image->cols)/2; + int y0 = (gtk_widget_get_allocated_height(widget) - image_widget->scaled_image->rows)/2; + + pixbuf = gdk_pixbuf_new_from_data(image_widget->scaled_image->data.ptr, GDK_COLORSPACE_RGB, false, + 8, MIN(image_widget->scaled_image->cols, gtk_widget_get_allocated_width(widget)), + MIN(image_widget->scaled_image->rows, gtk_widget_get_allocated_height(widget)), + image_widget->scaled_image->step, NULL, NULL); + + gdk_cairo_set_source_pixbuf(cr, pixbuf, x0, y0); + } + else if( image_widget->original_image ){ + pixbuf = gdk_pixbuf_new_from_data(image_widget->original_image->data.ptr, GDK_COLORSPACE_RGB, false, + 8, MIN(image_widget->original_image->cols, gtk_widget_get_allocated_width(widget)), + MIN(image_widget->original_image->rows, gtk_widget_get_allocated_height(widget)), + image_widget->original_image->step, NULL, NULL); + gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0); + } + + cairo_paint(cr); + g_object_unref(pixbuf); + return TRUE; +} + +#else static gboolean cvImageWidget_expose(GtkWidget* widget, GdkEventExpose* event, gpointer data) { #ifdef HAVE_OPENGL @@ -776,6 +960,7 @@ static gboolean cvImageWidget_expose(GtkWidget* widget, GdkEventExpose* event, g 8, MIN(image_widget->scaled_image->cols, widget->allocation.width), MIN(image_widget->scaled_image->rows, widget->allocation.height), image_widget->scaled_image->step, NULL, NULL); + gdk_cairo_set_source_pixbuf(cr, pixbuf, x0, y0); } else if( image_widget->original_image ){ @@ -787,9 +972,11 @@ static gboolean cvImageWidget_expose(GtkWidget* widget, GdkEventExpose* event, g } cairo_paint(cr); + g_object_unref(pixbuf); cairo_destroy(cr); return TRUE; } +#endif //GTK_VERSION3 CV_IMPL int cvNamedWindow( const char* name, int flags ) { @@ -862,8 +1049,13 @@ CV_IMPL int cvNamedWindow( const char* name, int flags ) G_CALLBACK(icvOnMouse), window ); g_signal_connect( window->frame, "delete-event", G_CALLBACK(icvOnClose), window ); +#if defined(GTK_VERSION3) + g_signal_connect( window->widget, "draw", + G_CALLBACK(cvImageWidget_draw), window ); +#else g_signal_connect( window->widget, "expose-event", G_CALLBACK(cvImageWidget_expose), window ); +#endif //GTK_VERSION3 gtk_widget_add_events (window->widget, GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK) ; @@ -1420,6 +1612,13 @@ CV_IMPL const char* cvGetWindowName( void* window_handle ) return window_name; } +#if defined (GTK_VERSION3) +#define GDK_Escape GDK_KEY_Escape +#define GDK_Return GDK_KEY_Return +#define GDK_Linefeed GDK_KEY_Linefeed +#define GDK_Tab GDK_KEY_Tab +#endif //GTK_VERSION3 + static gboolean icvOnKeyPress( GtkWidget * /*widget*/, GdkEventKey* event, gpointer /*user_data*/ ) { @@ -1550,8 +1749,13 @@ static gboolean icvOnMouse( GtkWidget *widget, GdkEvent *event, gpointer user_da image_widget->original_image && image_widget->scaled_image ){ // image origin is not necessarily at (0,0) +#if defined (GTK_VERSION3) + int x0 = (gtk_widget_get_allocated_width(widget) - image_widget->scaled_image->cols)/2; + int y0 = (gtk_widget_get_allocated_height(widget) - image_widget->scaled_image->rows)/2; +#else int x0 = (widget->allocation.width - image_widget->scaled_image->cols)/2; int y0 = (widget->allocation.height - image_widget->scaled_image->rows)/2; +#endif //GTK_VERSION3 pt.x = cvFloor( ((pt32f.x-x0)*image_widget->original_image->cols)/ image_widget->scaled_image->cols ); pt.y = cvFloor( ((pt32f.y-y0)*image_widget->original_image->rows)/ From 7daec9e9a803c7a318eda415b6cb7773ea700666 Mon Sep 17 00:00:00 2001 From: Tony Date: Tue, 1 Apr 2014 23:01:18 +0100 Subject: [PATCH 07/21] Improve GTK+ library selection logic. The new logic will select GTK+3 by default if WITH_GTK is selected. If the GTK+3 libraries are not found, then GTK+2 libraries will be selected if found. This can be overridden by using WITH_GTK_2_X to force selection of GTK+2 (if found). --- cmake/OpenCVFindLibsGUI.cmake | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/cmake/OpenCVFindLibsGUI.cmake b/cmake/OpenCVFindLibsGUI.cmake index 0ef693bbd..a1da6f63b 100644 --- a/cmake/OpenCVFindLibsGUI.cmake +++ b/cmake/OpenCVFindLibsGUI.cmake @@ -41,18 +41,14 @@ endif() # --- GTK --- ocv_clear_vars(HAVE_GTK HAVE_GTK3 HAVE_GTHREAD HAVE_GTKGLEXT) if(WITH_GTK AND NOT HAVE_QT) - if(WITH_GTK_2_X) + if(NOT WITH_GTK_2_X) + CHECK_MODULE(gtk+-3.0 HAVE_GTK3) + set(HAVE_GTK TRUE) + elseif(NOT HAVE_GTK3) CHECK_MODULE(gtk+-2.0 HAVE_GTK) if(HAVE_GTK AND (ALIASOF_gtk+-2.0_VERSION VERSION_LESS MIN_VER_GTK)) message (FATAL_ERROR "GTK support requires a minimum version of ${MIN_VER_GTK} (${ALIASOF_gtk+-2.0_VERSION} found)") endif() - else() - CHECK_MODULE(gtk+-3.0 HAVE_GTK3) - if(HAVE_GTK3) - set(HAVE_GTK ON) - else() - message(WARNING "Unable to locate GTK3 development libraries") - endif() endif() CHECK_MODULE(gthread-2.0 HAVE_GTHREAD) if(HAVE_GTK OR HAVE_GTK3 AND NOT HAVE_GTHREAD) From 838bb4bdeb3f283ab13a20a507a1d639135a0812 Mon Sep 17 00:00:00 2001 From: Tony Date: Tue, 8 Apr 2014 21:21:40 +0100 Subject: [PATCH 08/21] Fix bug in GTK+3 logic introduced by previous merge During merging of conflicting versions of this file, I erroneously deleted several lines in the GUI reporting section. This is repaired in this commit. --- CMakeLists.txt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 66a63f0ca..e8e75bf29 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -749,7 +749,15 @@ else() status(" Cocoa:" YES) endif() else() - status(" GTK+ 2.x:" HAVE_GTK THEN "YES (ver ${ALIASOF_gtk+-2.0_VERSION})" ELSE NO) + if(HAVE_GTK3) + status(" GTK+ 3.x:" HAVE_GTK THEN "YES (ver ${ALIASOF_gtk+-3.0_VERSION})" ELSE NO) + elseif(HAVE_GTK) + status(" GTK+ 2.x:" HAVE_GTK THEN "YES (ver ${ALIASOF_gtk+-2.0_VERSION})" ELSE NO) + else() + if(DEFINED WITH_GTK) + staus(" GTK+:" NO) + endif() + endif() status(" GThread :" HAVE_GTHREAD THEN "YES (ver ${ALIASOF_gthread-2.0_VERSION})" ELSE NO) status(" GtkGlExt:" HAVE_GTKGLEXT THEN "YES (ver ${ALIASOF_gtkglext-1.0_VERSION})" ELSE NO) endif() From 8592022bd894d2f0984541ec7752263d804ec9cc Mon Sep 17 00:00:00 2001 From: Tony Date: Tue, 8 Apr 2014 23:13:27 +0100 Subject: [PATCH 09/21] Change quotes around GTK headers for angle brackets The linux buildbots have started to fail compilation due to not finding the gtk headers. The quotes have been changed to angle brackets to indicate to the compiler that these are system includes. --- modules/highgui/src/window_gtk.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/highgui/src/window_gtk.cpp b/modules/highgui/src/window_gtk.cpp index a8dacff7d..0d53276b8 100644 --- a/modules/highgui/src/window_gtk.cpp +++ b/modules/highgui/src/window_gtk.cpp @@ -45,8 +45,8 @@ #if defined (HAVE_GTK) -#include "gtk/gtk.h" -#include "gdk/gdkkeysyms.h" +#include +#include #include #include From 2f9dad5ce894ba0dd0d6faf40e96ac01c6b1c37d Mon Sep 17 00:00:00 2001 From: Tony Date: Wed, 9 Apr 2014 22:07:59 +0100 Subject: [PATCH 10/21] Correct error with GTK3 not found selection When GTK3 is not found, HAVE_GTK was being set to TRUE. This edit ensures that HAVE_GTK is only set if GTK3 or GTK2 (meeting minimum version requirements) is present. Selection logic for printing 'GTK: No' when the libraries are not found has also been removed so the message is printed when GTK is not found or selected in common with other libraries. Changes committed: modified: CMakeLists.txt modified: cmake/OpenCVFindLibsGUI.cmake --- CMakeLists.txt | 6 ++---- cmake/OpenCVFindLibsGUI.cmake | 7 ++++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e8e75bf29..1e47bbcad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -752,11 +752,9 @@ else() if(HAVE_GTK3) status(" GTK+ 3.x:" HAVE_GTK THEN "YES (ver ${ALIASOF_gtk+-3.0_VERSION})" ELSE NO) elseif(HAVE_GTK) - status(" GTK+ 2.x:" HAVE_GTK THEN "YES (ver ${ALIASOF_gtk+-2.0_VERSION})" ELSE NO) + status(" GTK+ 2.x:" HAVE_GTK THEN "YES (ver ${ALIASOF_gtk+-2.0_VERSION})" ELSE NO) else() - if(DEFINED WITH_GTK) - staus(" GTK+:" NO) - endif() + status(" GTK+:" NO) endif() status(" GThread :" HAVE_GTHREAD THEN "YES (ver ${ALIASOF_gthread-2.0_VERSION})" ELSE NO) status(" GtkGlExt:" HAVE_GTKGLEXT THEN "YES (ver ${ALIASOF_gtkglext-1.0_VERSION})" ELSE NO) diff --git a/cmake/OpenCVFindLibsGUI.cmake b/cmake/OpenCVFindLibsGUI.cmake index a1da6f63b..0ae3787d5 100644 --- a/cmake/OpenCVFindLibsGUI.cmake +++ b/cmake/OpenCVFindLibsGUI.cmake @@ -43,15 +43,16 @@ ocv_clear_vars(HAVE_GTK HAVE_GTK3 HAVE_GTHREAD HAVE_GTKGLEXT) if(WITH_GTK AND NOT HAVE_QT) if(NOT WITH_GTK_2_X) CHECK_MODULE(gtk+-3.0 HAVE_GTK3) - set(HAVE_GTK TRUE) - elseif(NOT HAVE_GTK3) + set(HAVE_GTK HAVE_GTK3) + else() CHECK_MODULE(gtk+-2.0 HAVE_GTK) if(HAVE_GTK AND (ALIASOF_gtk+-2.0_VERSION VERSION_LESS MIN_VER_GTK)) message (FATAL_ERROR "GTK support requires a minimum version of ${MIN_VER_GTK} (${ALIASOF_gtk+-2.0_VERSION} found)") + set(HAVE_GTK FALSE) endif() endif() CHECK_MODULE(gthread-2.0 HAVE_GTHREAD) - if(HAVE_GTK OR HAVE_GTK3 AND NOT HAVE_GTHREAD) + if(HAVE_GTK AND NOT HAVE_GTHREAD) message(FATAL_ERROR "gthread not found. This library is required when building with GTK support") endif() if(WITH_OPENGL AND NOT HAVE_GTK3) From 8fd11f477bc6b27330ef8d20c55e9e36b46eedd9 Mon Sep 17 00:00:00 2001 From: Tony Date: Thu, 10 Apr 2014 23:28:23 +0100 Subject: [PATCH 11/21] Fix logic error in OpenCVFindLibsGUI.cmake When with_gtk is selected but GTK3 is not present the current logic fails to check for GTK2. This edit corrects this. --- cmake/OpenCVFindLibsGUI.cmake | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmake/OpenCVFindLibsGUI.cmake b/cmake/OpenCVFindLibsGUI.cmake index 0ae3787d5..c182628e3 100644 --- a/cmake/OpenCVFindLibsGUI.cmake +++ b/cmake/OpenCVFindLibsGUI.cmake @@ -44,7 +44,8 @@ if(WITH_GTK AND NOT HAVE_QT) if(NOT WITH_GTK_2_X) CHECK_MODULE(gtk+-3.0 HAVE_GTK3) set(HAVE_GTK HAVE_GTK3) - else() + endif() + if(NOT HAVE_GTK) CHECK_MODULE(gtk+-2.0 HAVE_GTK) if(HAVE_GTK AND (ALIASOF_gtk+-2.0_VERSION VERSION_LESS MIN_VER_GTK)) message (FATAL_ERROR "GTK support requires a minimum version of ${MIN_VER_GTK} (${ALIASOF_gtk+-2.0_VERSION} found)") From 512cb4fceda94c237707bde0ae21a6a106ac35c2 Mon Sep 17 00:00:00 2001 From: Tony Date: Sat, 12 Apr 2014 22:43:42 +0100 Subject: [PATCH 12/21] Correction to enable compilation on platform with only GTK2 libs modified: CMakeLists.txt modified: cmake/OpenCVFindLibsGUI.cmake --- CMakeLists.txt | 10 +++++----- cmake/OpenCVFindLibsGUI.cmake | 4 +++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9b1a2fe25..a741aacaf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -749,14 +749,14 @@ else() endif() else() if(HAVE_GTK3) - status(" GTK+ 3.x:" HAVE_GTK THEN "YES (ver ${ALIASOF_gtk+-3.0_VERSION})" ELSE NO) + status(" GTK+ 3.x:" HAVE_GTK THEN "YES (ver ${ALIASOF_gtk+-3.0_VERSION})" ELSE NO) elseif(HAVE_GTK) - status(" GTK+ 2.x:" HAVE_GTK THEN "YES (ver ${ALIASOF_gtk+-2.0_VERSION})" ELSE NO) + status(" GTK+ 2.x:" HAVE_GTK THEN "YES (ver ${ALIASOF_gtk+-2.0_VERSION})" ELSE NO) else() - status(" GTK+:" NO) + status(" GTK+:" NO) endif() - status(" GThread :" HAVE_GTHREAD THEN "YES (ver ${ALIASOF_gthread-2.0_VERSION})" ELSE NO) - status(" GtkGlExt:" HAVE_GTKGLEXT THEN "YES (ver ${ALIASOF_gtkglext-1.0_VERSION})" ELSE NO) + status(" GThread :" HAVE_GTHREAD THEN "YES (ver ${ALIASOF_gthread-2.0_VERSION})" ELSE NO) + status(" GtkGlExt:" HAVE_GTKGLEXT THEN "YES (ver ${ALIASOF_gtkglext-1.0_VERSION})" ELSE NO) endif() endif() endif() diff --git a/cmake/OpenCVFindLibsGUI.cmake b/cmake/OpenCVFindLibsGUI.cmake index c182628e3..14bfe4cce 100644 --- a/cmake/OpenCVFindLibsGUI.cmake +++ b/cmake/OpenCVFindLibsGUI.cmake @@ -43,7 +43,9 @@ ocv_clear_vars(HAVE_GTK HAVE_GTK3 HAVE_GTHREAD HAVE_GTKGLEXT) if(WITH_GTK AND NOT HAVE_QT) if(NOT WITH_GTK_2_X) CHECK_MODULE(gtk+-3.0 HAVE_GTK3) - set(HAVE_GTK HAVE_GTK3) + if(HAVE_GTK3) + set(HAVE_GTK TRUE) + endif() endif() if(NOT HAVE_GTK) CHECK_MODULE(gtk+-2.0 HAVE_GTK) From 16383412703ccb2fcf1e94529faf3ef9fea8156a Mon Sep 17 00:00:00 2001 From: Tony Date: Mon, 31 Mar 2014 22:05:09 +0100 Subject: [PATCH 13/21] Use GTK_VERSION_MAJOR to switch between GTK+ version two and three specific code. As a result of this, HAVE_GTK3 no longer needs to be exposed. The use of HAVE_GTK, and HAVE_ GTK3 have been changed to mirror the method used by HAVE_QT and HAVE_QT5. On branch gtk3 Changes to be committed: modified: CMakeLists.txt modified: cmake/OpenCVFindLibsGUI.cmake modified: cmake/templates/cvconfig.h.in modified: modules/highgui/src/window.cpp modified: modules/highgui/src/window_gtk.cpp --- CMakeLists.txt | 14 +- cmake/OpenCVFindLibsGUI.cmake | 10 +- cmake/templates/cvconfig.h.in | 3 - modules/highgui/src/window.cpp | 11 +- modules/highgui/src/window_gtk.cpp | 238 ++++++++++++++++++++++++++--- 5 files changed, 238 insertions(+), 38 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c1e4e7c1a..601fb817f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -127,6 +127,7 @@ OCV_OPTION(WITH_FFMPEG "Include FFMPEG support" ON OCV_OPTION(WITH_GSTREAMER "Include Gstreamer support" ON IF (UNIX AND NOT APPLE AND NOT ANDROID) ) OCV_OPTION(WITH_GSTREAMER_0_10 "Enable Gstreamer 0.10 support (instead of 1.x)" OFF ) OCV_OPTION(WITH_GTK "Include GTK support" ON IF (UNIX AND NOT APPLE AND NOT ANDROID) ) +OCV_OPTION(WITH_GTK_2_X "Use GTK version 2" OFF IF (UNIX AND NOT APPLE AND NOT ANDROID) ) OCV_OPTION(WITH_IPP "Include Intel IPP support" ON IF (NOT IOS) ) OCV_OPTION(WITH_JASPER "Include JPEG2K support" ON IF (NOT IOS) ) OCV_OPTION(WITH_JPEG "Include JPEG support" ON) @@ -157,7 +158,7 @@ OCV_OPTION(WITH_OPENCLAMDFFT "Include AMD OpenCL FFT library support" ON OCV_OPTION(WITH_OPENCLAMDBLAS "Include AMD OpenCL BLAS library support" ON IF (NOT ANDROID AND NOT IOS) ) OCV_OPTION(WITH_DIRECTX "Include DirectX support" ON IF WIN32 ) OCV_OPTION(WITH_INTELPERC "Include Intel Perceptual Computing support" OFF IF WIN32 ) -OCV_OPTION(WITH_IPP_A "Include Intel IPP_A support" OFF IF (MSVC OR X86 OR X86_64) ) + # OpenCV build components # =================================================== @@ -748,6 +749,7 @@ else() endif() else() status(" GTK+ 2.x:" HAVE_GTK THEN "YES (ver ${ALIASOF_gtk+-2.0_VERSION})" ELSE NO) + status(" GTK+ 3.x:" HAVE_GTK3 THEN "YES (ver ${ALIASOF_gtk+-3.0_VERSION})" ELSE NO) status(" GThread :" HAVE_GTHREAD THEN "YES (ver ${ALIASOF_gthread-2.0_VERSION})" ELSE NO) status(" GtkGlExt:" HAVE_GTKGLEXT THEN "YES (ver ${ALIASOF_gtkglext-1.0_VERSION})" ELSE NO) endif() @@ -916,17 +918,13 @@ endif(DEFINED WITH_INTELPERC) status("") status(" Other third-party libraries:") -if(WITH_IPP AND HAVE_IPP) - status(" Use IPP:" "${IPP_VERSION_STR} [${IPP_VERSION_MAJOR}.${IPP_VERSION_MINOR}.${IPP_VERSION_BUILD}]") +if(WITH_IPP AND IPP_FOUND) + status(" Use IPP:" "${IPP_LATEST_VERSION_STR} [${IPP_LATEST_VERSION_MAJOR}.${IPP_LATEST_VERSION_MINOR}.${IPP_LATEST_VERSION_BUILD}]") status(" at:" "${IPP_ROOT_DIR}") else() - status(" Use IPP:" WITH_IPP AND NOT HAVE_IPP THEN "IPP not found" ELSE NO) + status(" Use IPP:" WITH_IPP AND NOT IPP_FOUND THEN "IPP not found" ELSE NO) endif() -if(DEFINED WITH_IPP_A) -status(" Use IPP Async:" HAVE_IPP_A THEN "YES" ELSE NO) -endif(DEFINED WITH_IPP_A) - status(" Use Eigen:" HAVE_EIGEN THEN "YES (ver ${EIGEN_WORLD_VERSION}.${EIGEN_MAJOR_VERSION}.${EIGEN_MINOR_VERSION})" ELSE NO) status(" Use TBB:" HAVE_TBB THEN "YES (ver ${TBB_VERSION_MAJOR}.${TBB_VERSION_MINOR} interface ${TBB_INTERFACE_VERSION})" ELSE NO) status(" Use OpenMP:" HAVE_OPENMP THEN YES ELSE NO) diff --git a/cmake/OpenCVFindLibsGUI.cmake b/cmake/OpenCVFindLibsGUI.cmake index 70752c3fb..65847e5a0 100644 --- a/cmake/OpenCVFindLibsGUI.cmake +++ b/cmake/OpenCVFindLibsGUI.cmake @@ -44,17 +44,19 @@ if(WITH_GTK AND NOT HAVE_QT) if(WITH_GTK_2_X) CHECK_MODULE(gtk+-2.0 HAVE_GTK) if(HAVE_GTK AND (ALIASOF_gtk+-2.0_VERSION VERSION_LESS MIN_VER_GTK)) - message (FATAL_ERROR "Gtk support requires a minimum gtk+ version of ${MIN_VER_GTK} (${ALIASOF_gtk+-2.0_VERSION} found)") + message (FATAL_ERROR "GTK support requires a minimum version of ${MIN_VER_GTK} (${ALIASOF_gtk+-2.0_VERSION} found)") endif() else() CHECK_MODULE(gtk+-3.0 HAVE_GTK3) - if(NOT HAVE_GTK3) - message(WARNING "Unable to locate Gtk3 development libraries") + if(HAVE_GTK3) + set(HAVE_GTK ON) + else() + message(WARNING "Unable to locate GTK3 development libraries") endif() endif() CHECK_MODULE(gthread-2.0 HAVE_GTHREAD) if(HAVE_GTK OR HAVE_GTK3 AND NOT HAVE_GTHREAD) - message(FATAL_ERROR "gthread not found. This library is required when building with Gtk support") + message(FATAL_ERROR "gthread not found. This library is required when building with GTK support") endif() if(WITH_OPENGL AND NOT HAVE_GTK3) CHECK_MODULE(gtkglext-1.0 HAVE_GTKGLEXT) diff --git a/cmake/templates/cvconfig.h.in b/cmake/templates/cvconfig.h.in index 588e13854..f81049495 100644 --- a/cmake/templates/cvconfig.h.in +++ b/cmake/templates/cvconfig.h.in @@ -85,9 +85,6 @@ /* GTK+ 2.x toolkit */ #cmakedefine HAVE_GTK -/* GTK+ 3.x toolkit */ -#cmakedefine HAVE_GTK3 - /* Define to 1 if you have the header file. */ #cmakedefine HAVE_INTTYPES_H 1 diff --git a/modules/highgui/src/window.cpp b/modules/highgui/src/window.cpp index ecd5fb06d..03ff988d7 100644 --- a/modules/highgui/src/window.cpp +++ b/modules/highgui/src/window.cpp @@ -59,7 +59,7 @@ CV_IMPL void cvSetWindowProperty(const char* name, int prop_id, double prop_valu cvSetModeWindow_QT(name,prop_value); #elif defined(HAVE_WIN32UI) cvSetModeWindow_W32(name,prop_value); - #elif defined (HAVE_GTK) | defined (HAVE_GTK3) + #elif defined (HAVE_GTK) cvSetModeWindow_GTK(name,prop_value); #elif defined (HAVE_CARBON) cvSetModeWindow_CARBON(name,prop_value); @@ -98,7 +98,7 @@ CV_IMPL double cvGetWindowProperty(const char* name, int prop_id) return cvGetModeWindow_QT(name); #elif defined(HAVE_WIN32UI) return cvGetModeWindow_W32(name); - #elif defined (HAVE_GTK) | defined(HAVE_GTK3) + #elif defined (HAVE_GTK) return cvGetModeWindow_GTK(name); #elif defined (HAVE_CARBON) return cvGetModeWindow_CARBON(name); @@ -115,7 +115,7 @@ CV_IMPL double cvGetWindowProperty(const char* name, int prop_id) return cvGetPropWindow_QT(name); #elif defined(HAVE_WIN32UI) return cvGetPropWindowAutoSize_W32(name); - #elif defined (HAVE_GTK) | defined(HAVE_GTK3) + #elif defined (HAVE_GTK) return cvGetPropWindowAutoSize_GTK(name); #else return -1; @@ -128,7 +128,7 @@ CV_IMPL double cvGetWindowProperty(const char* name, int prop_id) return cvGetRatioWindow_QT(name); #elif defined(HAVE_WIN32UI) return cvGetRatioWindow_W32(name); - #elif defined (HAVE_GTK) | defined(HAVE_GTK3) + #elif defined (HAVE_GTK) return cvGetRatioWindow_GTK(name); #else return -1; @@ -141,7 +141,7 @@ CV_IMPL double cvGetWindowProperty(const char* name, int prop_id) return cvGetOpenGlProp_QT(name); #elif defined(HAVE_WIN32UI) return cvGetOpenGlProp_W32(name); - #elif defined (HAVE_GTK) | defined(HAVE_GTK3) + #elif defined (HAVE_GTK) return cvGetOpenGlProp_GTK(name); #else return -1; @@ -477,7 +477,6 @@ int cv::createButton(const String&, ButtonCallback, void*, int , bool ) #if defined(HAVE_WIN32UI) // see window_w32.cpp #elif defined (HAVE_GTK) // see window_gtk.cpp -#elif defined (HAVE_GTK3) // see window_gtk.cpp #elif defined (HAVE_COCOA) // see window_carbon.cpp #elif defined (HAVE_CARBON) #elif defined (HAVE_QT) //YV see window_QT.cpp diff --git a/modules/highgui/src/window_gtk.cpp b/modules/highgui/src/window_gtk.cpp index 02c256444..a8dacff7d 100644 --- a/modules/highgui/src/window_gtk.cpp +++ b/modules/highgui/src/window_gtk.cpp @@ -43,13 +43,17 @@ #ifndef WIN32 -#ifdef HAVE_GTK +#if defined (HAVE_GTK) #include "gtk/gtk.h" #include "gdk/gdkkeysyms.h" #include #include +#if (GTK_MAJOR_VERSION == 3) + #define GTK_VERSION3 +#endif //GTK_MAJOR_VERSION >= 3 + #ifdef HAVE_OPENGL #include #include @@ -150,32 +154,77 @@ cvImageWidget_realize (GtkWidget *widget) GdkWindowAttr attributes; gint attributes_mask; +#if defined(GTK_VERSION3) + GtkAllocation allocation; + gtk_widget_get_allocation(widget, &allocation); +#endif //GTK_VERSION3 + //printf("cvImageWidget_realize\n"); g_return_if_fail (widget != NULL); g_return_if_fail (CV_IS_IMAGE_WIDGET (widget)); gtk_widget_set_realized(widget, TRUE); +#if defined(GTK_VERSION3) + attributes.x = allocation.x; + attributes.y = allocation.y; + attributes.width = allocation.width; + attributes.height = allocation.height; +#else attributes.x = widget->allocation.x; attributes.y = widget->allocation.y; attributes.width = widget->allocation.width; attributes.height = widget->allocation.height; +#endif //GTK_VERSION3 + attributes.wclass = GDK_INPUT_OUTPUT; attributes.window_type = GDK_WINDOW_CHILD; attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK; attributes.visual = gtk_widget_get_visual (widget); - attributes.colormap = gtk_widget_get_colormap (widget); +#if defined(GTK_VERSION3) + attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL; + gtk_widget_set_window( + widget, + gdk_window_new( + gtk_widget_get_parent_window(widget), + &attributes, + attributes_mask + ) + ); + + gtk_widget_set_style( + widget, + gtk_style_attach( + gtk_widget_get_style(widget), + gtk_widget_get_window(widget) + ) + ); + + gdk_window_set_user_data ( + gtk_widget_get_window(widget), + widget + ); + + gtk_style_set_background ( + gtk_widget_get_style(widget), + gtk_widget_get_window(widget), + GTK_STATE_ACTIVE + ); + #else + // The following lines are included to prevent breaking + // compatibility with older Gtk2 (window = gdk_window_new (widget->parent->window, &attributes, attributes_mask); widget->style = gtk_style_attach (widget->style, widget->window); - gdk_window_set_user_data (widget->window, widget); gtk_style_set_background (widget->style, widget->window, GTK_STATE_ACTIVE); +#endif // GTK_VERSION3 } static CvSize cvImageWidget_calc_size( int im_width, int im_height, int max_width, int max_height ){ @@ -187,6 +236,56 @@ static CvSize cvImageWidget_calc_size( int im_width, int im_height, int max_widt return cvSize( cvRound(max_height*aspect), max_height ); } +#if defined (GTK_VERSION3) +static void +cvImageWidget_get_preferred_width (GtkWidget *widget, gint *minimal_width, gint *natural_width) +{ + g_return_if_fail (widget != NULL); + g_return_if_fail (CV_IS_IMAGE_WIDGET (widget)); + CvImageWidget * image_widget = CV_IMAGE_WIDGET( widget ); + + if(image_widget->original_image != NULL) { + *minimal_width = image_widget->flags & CV_WINDOW_AUTOSIZE ? + gdk_window_get_width(gtk_widget_get_window(widget)) : image_widget->original_image->cols; + } + else { + *minimal_width = 320; + } + + if(image_widget->scaled_image != NULL) { + *natural_width = *minimal_width < image_widget->scaled_image->cols ? + image_widget->scaled_image->cols : *minimal_width; + } + else { + *natural_width = *minimal_width; + } +} + +static void +cvImageWidget_get_preferred_height (GtkWidget *widget, gint *minimal_height, gint *natural_height) +{ + g_return_if_fail (widget != NULL); + g_return_if_fail (CV_IS_IMAGE_WIDGET (widget)); + CvImageWidget * image_widget = CV_IMAGE_WIDGET( widget ); + + if(image_widget->original_image != NULL) { + *minimal_height = image_widget->flags & CV_WINDOW_AUTOSIZE ? + gdk_window_get_height(gtk_widget_get_window(widget)) : image_widget->original_image->rows; + } + else { + *minimal_height = 240; + } + + if(image_widget->scaled_image != NULL) { + *natural_height = *minimal_height < image_widget->scaled_image->rows ? + image_widget->scaled_image->cols : *minimal_height; + } + else { + *natural_height = *minimal_height; + } +} + +#else static void cvImageWidget_size_request (GtkWidget *widget, GtkRequisition *requisition) @@ -217,6 +316,7 @@ cvImageWidget_size_request (GtkWidget *widget, } //printf("%d %d\n",requisition->width, requisition->height); } +#endif //GTK_VERSION3 static void cvImageWidget_set_size(GtkWidget * widget, int max_width, int max_height){ CvImageWidget * image_widget = CV_IMAGE_WIDGET( widget ); @@ -237,7 +337,7 @@ static void cvImageWidget_set_size(GtkWidget * widget, int max_width, int max_he cvReleaseMat( &image_widget->scaled_image ); } if( !image_widget->scaled_image ){ - image_widget->scaled_image = cvCreateMat( scaled_image_size.height, scaled_image_size.width, CV_8UC3 ); + image_widget->scaled_image = cvCreateMat( scaled_image_size.height, scaled_image_size.width, CV_8UC3 ); } @@ -255,7 +355,11 @@ cvImageWidget_size_allocate (GtkWidget *widget, g_return_if_fail (CV_IS_IMAGE_WIDGET (widget)); g_return_if_fail (allocation != NULL); +#if defined (GTK_VERSION3) + gtk_widget_set_allocation(widget, allocation); +#else widget->allocation = *allocation; +#endif //GTK_VERSION3 image_widget = CV_IMAGE_WIDGET (widget); @@ -279,26 +383,37 @@ cvImageWidget_size_allocate (GtkWidget *widget, ((image_widget->flags & CV_WINDOW_AUTOSIZE) || (image_widget->flags & CV_WINDOW_NO_IMAGE)) ) { +#if defined (GTK_VERSION3) + allocation->width = image_widget->original_image->cols; + allocation->height = image_widget->original_image->rows; + gtk_widget_set_allocation(widget, allocation); +#else widget->allocation.width = image_widget->original_image->cols; widget->allocation.height = image_widget->original_image->rows; - gdk_window_move_resize( widget->window, allocation->x, allocation->y, - image_widget->original_image->cols, image_widget->original_image->rows ); +#endif //GTK_VERSION3 + gdk_window_move_resize( gtk_widget_get_window(widget), + allocation->x, allocation->y, + image_widget->original_image->cols, image_widget->original_image->rows ); if(image_widget->flags & CV_WINDOW_NO_IMAGE){ image_widget->flags &= ~CV_WINDOW_NO_IMAGE; gtk_widget_queue_resize( GTK_WIDGET(widget) ); } } else{ - gdk_window_move_resize (widget->window, + gdk_window_move_resize (gtk_widget_get_window(widget), allocation->x, allocation->y, allocation->width, allocation->height ); - } } } +#if defined (GTK_VERSION3) +static void +cvImageWidget_destroy (GtkWidget *object) +#else static void cvImageWidget_destroy (GtkObject *object) +#endif //GTK_VERSION3 { CvImageWidget *image_widget; @@ -310,24 +425,39 @@ cvImageWidget_destroy (GtkObject *object) cvReleaseMat( &image_widget->scaled_image ); cvReleaseMat( &image_widget->original_image ); +#if defined (GTK_VERSION3) + if (GTK_WIDGET_CLASS (parent_class)->destroy) + (* GTK_WIDGET_CLASS (parent_class)->destroy) (object); +#else if (GTK_OBJECT_CLASS (parent_class)->destroy) (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); +#endif //GTK_VERSION3 } static void cvImageWidget_class_init (CvImageWidgetClass * klass) { +#if defined (GTK_VERSION3) + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); +#else GtkObjectClass *object_class; GtkWidgetClass *widget_class; object_class = (GtkObjectClass*) klass; widget_class = (GtkWidgetClass*) klass; +#endif //GTK_VERSION3 parent_class = GTK_WIDGET_CLASS( g_type_class_peek (gtk_widget_get_type ()) ); +#if defined (GTK_VERSION3) + widget_class->destroy = cvImageWidget_destroy; + widget_class->get_preferred_width = cvImageWidget_get_preferred_width; + widget_class->get_preferred_height = cvImageWidget_get_preferred_height; +#else object_class->destroy = cvImageWidget_destroy; + widget_class->size_request = cvImageWidget_size_request; +#endif //GTK_VERSION3 widget_class->realize = cvImageWidget_realize; - widget_class->size_request = cvImageWidget_size_request; widget_class->size_allocate = cvImageWidget_size_allocate; widget_class->button_press_event = NULL; widget_class->button_release_event = NULL; @@ -347,13 +477,15 @@ GType cvImageWidget_get_type (void){ if (!image_type) { - image_type = g_type_register_static_simple( GTK_TYPE_WIDGET, - (gchar*) "CvImageWidget", - sizeof(CvImageWidgetClass), - (GClassInitFunc) cvImageWidget_class_init, - sizeof(CvImageWidget), - (GInstanceInitFunc) cvImageWidget_init, - (GTypeFlags)NULL); + image_type = g_type_register_static_simple( + GTK_TYPE_WIDGET, + (gchar*) "CvImageWidget", + sizeof(CvImageWidgetClass), + (GClassInitFunc) cvImageWidget_class_init, + sizeof(CvImageWidget), + (GInstanceInitFunc) cvImageWidget_init, + (GTypeFlags)NULL + ); } return image_type; @@ -642,8 +774,12 @@ double cvGetRatioWindow_GTK(const char* name) if (!window) EXIT; // keep silence here +#if defined (GTK_VERSION3) + result = static_cast( + gtk_widget_get_allocated_width(window->widget)) / gtk_widget_get_allocated_height(window->widget); +#else result = static_cast(window->widget->allocation.width) / window->widget->allocation.height; - +#endif // GTK_VERSION3 __END__; return result; @@ -738,7 +874,55 @@ namespace #endif // HAVE_OPENGL +#if defined (GTK_VERSION3) +static gboolean cvImageWidget_draw(GtkWidget* widget, cairo_t *cr, gpointer data) +{ +#ifdef HAVE_OPENGL + CvWindow* window = (CvWindow*)data; + if (window->useGl) + { + drawGl(window); + return TRUE; + } +#else + (void)data; +#endif + + CvImageWidget *image_widget = NULL; + GdkPixbuf *pixbuf = NULL; + + g_return_val_if_fail (widget != NULL, FALSE); + g_return_val_if_fail (CV_IS_IMAGE_WIDGET (widget), FALSE); + + image_widget = CV_IMAGE_WIDGET (widget); + + if( image_widget->scaled_image ){ + // center image in available region + int x0 = (gtk_widget_get_allocated_width(widget) - image_widget->scaled_image->cols)/2; + int y0 = (gtk_widget_get_allocated_height(widget) - image_widget->scaled_image->rows)/2; + + pixbuf = gdk_pixbuf_new_from_data(image_widget->scaled_image->data.ptr, GDK_COLORSPACE_RGB, false, + 8, MIN(image_widget->scaled_image->cols, gtk_widget_get_allocated_width(widget)), + MIN(image_widget->scaled_image->rows, gtk_widget_get_allocated_height(widget)), + image_widget->scaled_image->step, NULL, NULL); + + gdk_cairo_set_source_pixbuf(cr, pixbuf, x0, y0); + } + else if( image_widget->original_image ){ + pixbuf = gdk_pixbuf_new_from_data(image_widget->original_image->data.ptr, GDK_COLORSPACE_RGB, false, + 8, MIN(image_widget->original_image->cols, gtk_widget_get_allocated_width(widget)), + MIN(image_widget->original_image->rows, gtk_widget_get_allocated_height(widget)), + image_widget->original_image->step, NULL, NULL); + gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0); + } + + cairo_paint(cr); + g_object_unref(pixbuf); + return TRUE; +} + +#else static gboolean cvImageWidget_expose(GtkWidget* widget, GdkEventExpose* event, gpointer data) { #ifdef HAVE_OPENGL @@ -776,6 +960,7 @@ static gboolean cvImageWidget_expose(GtkWidget* widget, GdkEventExpose* event, g 8, MIN(image_widget->scaled_image->cols, widget->allocation.width), MIN(image_widget->scaled_image->rows, widget->allocation.height), image_widget->scaled_image->step, NULL, NULL); + gdk_cairo_set_source_pixbuf(cr, pixbuf, x0, y0); } else if( image_widget->original_image ){ @@ -787,9 +972,11 @@ static gboolean cvImageWidget_expose(GtkWidget* widget, GdkEventExpose* event, g } cairo_paint(cr); + g_object_unref(pixbuf); cairo_destroy(cr); return TRUE; } +#endif //GTK_VERSION3 CV_IMPL int cvNamedWindow( const char* name, int flags ) { @@ -862,8 +1049,13 @@ CV_IMPL int cvNamedWindow( const char* name, int flags ) G_CALLBACK(icvOnMouse), window ); g_signal_connect( window->frame, "delete-event", G_CALLBACK(icvOnClose), window ); +#if defined(GTK_VERSION3) + g_signal_connect( window->widget, "draw", + G_CALLBACK(cvImageWidget_draw), window ); +#else g_signal_connect( window->widget, "expose-event", G_CALLBACK(cvImageWidget_expose), window ); +#endif //GTK_VERSION3 gtk_widget_add_events (window->widget, GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK) ; @@ -1420,6 +1612,13 @@ CV_IMPL const char* cvGetWindowName( void* window_handle ) return window_name; } +#if defined (GTK_VERSION3) +#define GDK_Escape GDK_KEY_Escape +#define GDK_Return GDK_KEY_Return +#define GDK_Linefeed GDK_KEY_Linefeed +#define GDK_Tab GDK_KEY_Tab +#endif //GTK_VERSION3 + static gboolean icvOnKeyPress( GtkWidget * /*widget*/, GdkEventKey* event, gpointer /*user_data*/ ) { @@ -1550,8 +1749,13 @@ static gboolean icvOnMouse( GtkWidget *widget, GdkEvent *event, gpointer user_da image_widget->original_image && image_widget->scaled_image ){ // image origin is not necessarily at (0,0) +#if defined (GTK_VERSION3) + int x0 = (gtk_widget_get_allocated_width(widget) - image_widget->scaled_image->cols)/2; + int y0 = (gtk_widget_get_allocated_height(widget) - image_widget->scaled_image->rows)/2; +#else int x0 = (widget->allocation.width - image_widget->scaled_image->cols)/2; int y0 = (widget->allocation.height - image_widget->scaled_image->rows)/2; +#endif //GTK_VERSION3 pt.x = cvFloor( ((pt32f.x-x0)*image_widget->original_image->cols)/ image_widget->scaled_image->cols ); pt.y = cvFloor( ((pt32f.y-y0)*image_widget->original_image->rows)/ From f318b5bc9d3c77f24930ac0d3e143f742dc04aec Mon Sep 17 00:00:00 2001 From: Tony Date: Tue, 1 Apr 2014 23:01:18 +0100 Subject: [PATCH 14/21] Improve GTK+ library selection logic. The new logic will select GTK+3 by default if WITH_GTK is selected. If the GTK+3 libraries are not found, then GTK+2 libraries will be selected if found. This can be overridden by using WITH_GTK_2_X to force selection of GTK+2 (if found). --- cmake/OpenCVFindLibsGUI.cmake | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/cmake/OpenCVFindLibsGUI.cmake b/cmake/OpenCVFindLibsGUI.cmake index 65847e5a0..c9f3fbb6b 100644 --- a/cmake/OpenCVFindLibsGUI.cmake +++ b/cmake/OpenCVFindLibsGUI.cmake @@ -41,18 +41,14 @@ endif() # --- GTK --- ocv_clear_vars(HAVE_GTK HAVE_GTK3 HAVE_GTHREAD HAVE_GTKGLEXT) if(WITH_GTK AND NOT HAVE_QT) - if(WITH_GTK_2_X) + if(NOT WITH_GTK_2_X) + CHECK_MODULE(gtk+-3.0 HAVE_GTK3) + set(HAVE_GTK TRUE) + elseif(NOT HAVE_GTK3) CHECK_MODULE(gtk+-2.0 HAVE_GTK) if(HAVE_GTK AND (ALIASOF_gtk+-2.0_VERSION VERSION_LESS MIN_VER_GTK)) message (FATAL_ERROR "GTK support requires a minimum version of ${MIN_VER_GTK} (${ALIASOF_gtk+-2.0_VERSION} found)") endif() - else() - CHECK_MODULE(gtk+-3.0 HAVE_GTK3) - if(HAVE_GTK3) - set(HAVE_GTK ON) - else() - message(WARNING "Unable to locate GTK3 development libraries") - endif() endif() CHECK_MODULE(gthread-2.0 HAVE_GTHREAD) if(HAVE_GTK OR HAVE_GTK3 AND NOT HAVE_GTHREAD) From a28ad40c2a4e960cb5a38f8edf37dc63c03e0d0d Mon Sep 17 00:00:00 2001 From: Tony Date: Tue, 8 Apr 2014 21:21:40 +0100 Subject: [PATCH 15/21] Fix bug in GTK+3 logic introduced by previous merge During merging of conflicting versions of this file, I erroneously deleted several lines in the GUI reporting section. This is repaired in this commit. --- CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 601fb817f..9b5ccd73e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -749,7 +749,6 @@ else() endif() else() status(" GTK+ 2.x:" HAVE_GTK THEN "YES (ver ${ALIASOF_gtk+-2.0_VERSION})" ELSE NO) - status(" GTK+ 3.x:" HAVE_GTK3 THEN "YES (ver ${ALIASOF_gtk+-3.0_VERSION})" ELSE NO) status(" GThread :" HAVE_GTHREAD THEN "YES (ver ${ALIASOF_gthread-2.0_VERSION})" ELSE NO) status(" GtkGlExt:" HAVE_GTKGLEXT THEN "YES (ver ${ALIASOF_gtkglext-1.0_VERSION})" ELSE NO) endif() From 65f63421fab1700f531f6c932fe222878c426900 Mon Sep 17 00:00:00 2001 From: Tony Date: Tue, 8 Apr 2014 23:13:27 +0100 Subject: [PATCH 16/21] Change quotes around GTK headers for angle brackets The linux buildbots have started to fail compilation due to not finding the gtk headers. The quotes have been changed to angle brackets to indicate to the compiler that these are system includes. --- modules/highgui/src/window_gtk.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/highgui/src/window_gtk.cpp b/modules/highgui/src/window_gtk.cpp index a8dacff7d..0d53276b8 100644 --- a/modules/highgui/src/window_gtk.cpp +++ b/modules/highgui/src/window_gtk.cpp @@ -45,8 +45,8 @@ #if defined (HAVE_GTK) -#include "gtk/gtk.h" -#include "gdk/gdkkeysyms.h" +#include +#include #include #include From c0dbc083ea0d13999de1d3d98d5ab33e0dc4a11d Mon Sep 17 00:00:00 2001 From: Tony Date: Wed, 9 Apr 2014 22:07:59 +0100 Subject: [PATCH 17/21] Correct error with GTK3 not found selection When GTK3 is not found, HAVE_GTK was being set to TRUE. This edit ensures that HAVE_GTK is only set if GTK3 or GTK2 (meeting minimum version requirements) is present. Selection logic for printing 'GTK: No' when the libraries are not found has also been removed so the message is printed when GTK is not found or selected in common with other libraries. Changes committed: modified: CMakeLists.txt modified: cmake/OpenCVFindLibsGUI.cmake --- CMakeLists.txt | 10 +++++++++- cmake/OpenCVFindLibsGUI.cmake | 7 ++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9b5ccd73e..c08164950 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -748,7 +748,15 @@ else() status(" Cocoa:" YES) endif() else() - status(" GTK+ 2.x:" HAVE_GTK THEN "YES (ver ${ALIASOF_gtk+-2.0_VERSION})" ELSE NO) + if(HAVE_GTK3) + status(" GTK+ 3.x:" HAVE_GTK THEN "YES (ver ${ALIASOF_gtk+-3.0_VERSION})" ELSE NO) + elseif(HAVE_GTK) + status(" GTK+ 2.x:" HAVE_GTK THEN "YES (ver ${ALIASOF_gtk+-2.0_VERSION})" ELSE NO) + else() + if(DEFINED WITH_GTK) + staus(" GTK+:" NO) + endif() + endif() status(" GThread :" HAVE_GTHREAD THEN "YES (ver ${ALIASOF_gthread-2.0_VERSION})" ELSE NO) status(" GtkGlExt:" HAVE_GTKGLEXT THEN "YES (ver ${ALIASOF_gtkglext-1.0_VERSION})" ELSE NO) endif() diff --git a/cmake/OpenCVFindLibsGUI.cmake b/cmake/OpenCVFindLibsGUI.cmake index c9f3fbb6b..f44261c3c 100644 --- a/cmake/OpenCVFindLibsGUI.cmake +++ b/cmake/OpenCVFindLibsGUI.cmake @@ -43,15 +43,16 @@ ocv_clear_vars(HAVE_GTK HAVE_GTK3 HAVE_GTHREAD HAVE_GTKGLEXT) if(WITH_GTK AND NOT HAVE_QT) if(NOT WITH_GTK_2_X) CHECK_MODULE(gtk+-3.0 HAVE_GTK3) - set(HAVE_GTK TRUE) - elseif(NOT HAVE_GTK3) + set(HAVE_GTK HAVE_GTK3) + else() CHECK_MODULE(gtk+-2.0 HAVE_GTK) if(HAVE_GTK AND (ALIASOF_gtk+-2.0_VERSION VERSION_LESS MIN_VER_GTK)) message (FATAL_ERROR "GTK support requires a minimum version of ${MIN_VER_GTK} (${ALIASOF_gtk+-2.0_VERSION} found)") + set(HAVE_GTK FALSE) endif() endif() CHECK_MODULE(gthread-2.0 HAVE_GTHREAD) - if(HAVE_GTK OR HAVE_GTK3 AND NOT HAVE_GTHREAD) + if(HAVE_GTK AND NOT HAVE_GTHREAD) message(FATAL_ERROR "gthread not found. This library is required when building with GTK support") endif() if(WITH_OPENGL AND NOT HAVE_GTK3) From cb4fffc72a7e811803ed036d473f446237264908 Mon Sep 17 00:00:00 2001 From: Tony Date: Thu, 10 Apr 2014 23:28:23 +0100 Subject: [PATCH 18/21] Fix logic error in OpenCVFindLibsGUI.cmake When with_gtk is selected but GTK3 is not present the current logic fails to check for GTK2. This edit corrects this. --- cmake/OpenCVFindLibsGUI.cmake | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmake/OpenCVFindLibsGUI.cmake b/cmake/OpenCVFindLibsGUI.cmake index f44261c3c..05de58cad 100644 --- a/cmake/OpenCVFindLibsGUI.cmake +++ b/cmake/OpenCVFindLibsGUI.cmake @@ -44,7 +44,8 @@ if(WITH_GTK AND NOT HAVE_QT) if(NOT WITH_GTK_2_X) CHECK_MODULE(gtk+-3.0 HAVE_GTK3) set(HAVE_GTK HAVE_GTK3) - else() + endif() + if(NOT HAVE_GTK) CHECK_MODULE(gtk+-2.0 HAVE_GTK) if(HAVE_GTK AND (ALIASOF_gtk+-2.0_VERSION VERSION_LESS MIN_VER_GTK)) message (FATAL_ERROR "GTK support requires a minimum version of ${MIN_VER_GTK} (${ALIASOF_gtk+-2.0_VERSION} found)") From 265148b97493fee7429363c580229e558d82e7fb Mon Sep 17 00:00:00 2001 From: Tony Date: Sat, 12 Apr 2014 22:43:42 +0100 Subject: [PATCH 19/21] Correction to enable compilation on platform with only GTK2 libs modified: CMakeLists.txt modified: cmake/OpenCVFindLibsGUI.cmake --- CMakeLists.txt | 10 ++++++++++ cmake/OpenCVFindLibsGUI.cmake | 4 +++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c08164950..93b3ee651 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -749,6 +749,7 @@ else() endif() else() if(HAVE_GTK3) +<<<<<<< HEAD status(" GTK+ 3.x:" HAVE_GTK THEN "YES (ver ${ALIASOF_gtk+-3.0_VERSION})" ELSE NO) elseif(HAVE_GTK) status(" GTK+ 2.x:" HAVE_GTK THEN "YES (ver ${ALIASOF_gtk+-2.0_VERSION})" ELSE NO) @@ -758,6 +759,15 @@ else() endif() endif() status(" GThread :" HAVE_GTHREAD THEN "YES (ver ${ALIASOF_gthread-2.0_VERSION})" ELSE NO) +======= + status(" GTK+ 3.x:" HAVE_GTK THEN "YES (ver ${ALIASOF_gtk+-3.0_VERSION})" ELSE NO) + elseif(HAVE_GTK) + status(" GTK+ 2.x:" HAVE_GTK THEN "YES (ver ${ALIASOF_gtk+-2.0_VERSION})" ELSE NO) + else() + status(" GTK+:" NO) + endif() + status(" GThread :" HAVE_GTHREAD THEN "YES (ver ${ALIASOF_gthread-2.0_VERSION})" ELSE NO) +>>>>>>> Correction to enable compilation on platform with only GTK2 libs status(" GtkGlExt:" HAVE_GTKGLEXT THEN "YES (ver ${ALIASOF_gtkglext-1.0_VERSION})" ELSE NO) endif() endif() diff --git a/cmake/OpenCVFindLibsGUI.cmake b/cmake/OpenCVFindLibsGUI.cmake index 05de58cad..1c13619d5 100644 --- a/cmake/OpenCVFindLibsGUI.cmake +++ b/cmake/OpenCVFindLibsGUI.cmake @@ -43,7 +43,9 @@ ocv_clear_vars(HAVE_GTK HAVE_GTK3 HAVE_GTHREAD HAVE_GTKGLEXT) if(WITH_GTK AND NOT HAVE_QT) if(NOT WITH_GTK_2_X) CHECK_MODULE(gtk+-3.0 HAVE_GTK3) - set(HAVE_GTK HAVE_GTK3) + if(HAVE_GTK3) + set(HAVE_GTK TRUE) + endif() endif() if(NOT HAVE_GTK) CHECK_MODULE(gtk+-2.0 HAVE_GTK) From fd5e1806574b4249d831abb71e7255deca0bafc7 Mon Sep 17 00:00:00 2001 From: Tony Date: Sun, 13 Apr 2014 15:52:22 +0100 Subject: [PATCH 20/21] Rebase branch gtk3 --- CMakeLists.txt | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 93b3ee651..081e5a15f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -158,7 +158,7 @@ OCV_OPTION(WITH_OPENCLAMDFFT "Include AMD OpenCL FFT library support" ON OCV_OPTION(WITH_OPENCLAMDBLAS "Include AMD OpenCL BLAS library support" ON IF (NOT ANDROID AND NOT IOS) ) OCV_OPTION(WITH_DIRECTX "Include DirectX support" ON IF WIN32 ) OCV_OPTION(WITH_INTELPERC "Include Intel Perceptual Computing support" OFF IF WIN32 ) - +OCV_OPTION(WITH_IPP_A "Include Intel IPP_A support" OFF IF (MSVC OR X86 OR X86_64) ) # OpenCV build components # =================================================== @@ -749,17 +749,6 @@ else() endif() else() if(HAVE_GTK3) -<<<<<<< HEAD - status(" GTK+ 3.x:" HAVE_GTK THEN "YES (ver ${ALIASOF_gtk+-3.0_VERSION})" ELSE NO) - elseif(HAVE_GTK) - status(" GTK+ 2.x:" HAVE_GTK THEN "YES (ver ${ALIASOF_gtk+-2.0_VERSION})" ELSE NO) - else() - if(DEFINED WITH_GTK) - staus(" GTK+:" NO) - endif() - endif() - status(" GThread :" HAVE_GTHREAD THEN "YES (ver ${ALIASOF_gthread-2.0_VERSION})" ELSE NO) -======= status(" GTK+ 3.x:" HAVE_GTK THEN "YES (ver ${ALIASOF_gtk+-3.0_VERSION})" ELSE NO) elseif(HAVE_GTK) status(" GTK+ 2.x:" HAVE_GTK THEN "YES (ver ${ALIASOF_gtk+-2.0_VERSION})" ELSE NO) @@ -767,7 +756,6 @@ else() status(" GTK+:" NO) endif() status(" GThread :" HAVE_GTHREAD THEN "YES (ver ${ALIASOF_gthread-2.0_VERSION})" ELSE NO) ->>>>>>> Correction to enable compilation on platform with only GTK2 libs status(" GtkGlExt:" HAVE_GTKGLEXT THEN "YES (ver ${ALIASOF_gtkglext-1.0_VERSION})" ELSE NO) endif() endif() @@ -935,13 +923,17 @@ endif(DEFINED WITH_INTELPERC) status("") status(" Other third-party libraries:") -if(WITH_IPP AND IPP_FOUND) - status(" Use IPP:" "${IPP_LATEST_VERSION_STR} [${IPP_LATEST_VERSION_MAJOR}.${IPP_LATEST_VERSION_MINOR}.${IPP_LATEST_VERSION_BUILD}]") +if(WITH_IPP AND HAVE_IPP) + status(" Use IPP:" "${IPP_VERSION_STR} [${IPP_VERSION_MAJOR}.${IPP_VERSION_MINOR}.${IPP_VERSION_BUILD}]") status(" at:" "${IPP_ROOT_DIR}") else() - status(" Use IPP:" WITH_IPP AND NOT IPP_FOUND THEN "IPP not found" ELSE NO) + status(" Use IPP:" WITH_IPP AND NOT HAVE_IPP THEN "IPP not found" ELSE NO) endif() +if(DEFINED WITH_IPP_A) +status(" Use IPP Async:" HAVE_IPP_A THEN "YES" ELSE NO) +endif(DEFINED WITH_IPP_A) + status(" Use Eigen:" HAVE_EIGEN THEN "YES (ver ${EIGEN_WORLD_VERSION}.${EIGEN_MAJOR_VERSION}.${EIGEN_MINOR_VERSION})" ELSE NO) status(" Use TBB:" HAVE_TBB THEN "YES (ver ${TBB_VERSION_MAJOR}.${TBB_VERSION_MINOR} interface ${TBB_INTERFACE_VERSION})" ELSE NO) status(" Use OpenMP:" HAVE_OPENMP THEN YES ELSE NO) From f0887a99e201cc8caca4694af28a60bb0b85bc41 Mon Sep 17 00:00:00 2001 From: Tony Date: Tue, 3 Jun 2014 21:29:54 +0100 Subject: [PATCH 21/21] On branch gtk3 Changes to be committed: modified: CMakeLists.txt Corrected merge error from last resync --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a741aacaf..081e5a15f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -923,11 +923,11 @@ endif(DEFINED WITH_INTELPERC) status("") status(" Other third-party libraries:") -if((WITH_IPP OR WITH_ICV) AND HAVE_IPP) +if(WITH_IPP AND HAVE_IPP) status(" Use IPP:" "${IPP_VERSION_STR} [${IPP_VERSION_MAJOR}.${IPP_VERSION_MINOR}.${IPP_VERSION_BUILD}]") status(" at:" "${IPP_ROOT_DIR}") else() - status(" Use IPP:" (WITH_IPP OR WITH_ICV) AND NOT HAVE_IPP THEN "IPP not found" ELSE NO) + status(" Use IPP:" WITH_IPP AND NOT HAVE_IPP THEN "IPP not found" ELSE NO) endif() if(DEFINED WITH_IPP_A)