Skip to content

Commit

Permalink
Added support for highgui module on WinRT 8.1+
Browse files Browse the repository at this point in the history
Signed-off-by: Maxim Kostin <v-maxkos@microsoft.com>
  • Loading branch information
mkostin committed Jun 25, 2015
1 parent 8298644 commit e3cbc93
Show file tree
Hide file tree
Showing 8 changed files with 863 additions and 341 deletions.
31 changes: 25 additions & 6 deletions modules/highgui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ file(GLOB highgui_ext_hdrs
"${CMAKE_CURRENT_LIST_DIR}/include/opencv2/${name}/*.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/opencv2/${name}/*.h")

# Removing WinRT API headers by default
status(" ${name}: Removing WinRT API headers by default")
list(REMOVE_ITEM highgui_ext_hdrs "${CMAKE_CURRENT_LIST_DIR}/include/opencv2/${name}/highgui_winrt.hpp")

if(HAVE_QT5)
set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
Expand Down Expand Up @@ -66,12 +70,23 @@ elseif(HAVE_QT)
if(${_have_flag})
set_source_files_properties(${_RCC_OUTFILES} PROPERTIES COMPILE_FLAGS -Wno-missing-declarations)
endif()
elseif(WINRT AND NOT WINRT_8_0)
# Dependencies used by the implementation referenced
# below are not available on WinRT 8.0.
# Enabling it for WiRT 8.1+ only.
status(" ${name}: WinRT detected")
list(APPEND highgui_srcs ${CMAKE_CURRENT_LIST_DIR}/src/window_winrt.cpp)
elseif(WINRT)
if(NOT WINRT_8_0)
# Dependencies used by the implementation referenced
# below are not available on WinRT 8.0.
# Enabling it for WiRT 8.1+ only.

# WinRT 8.1+ detected. Adding WinRT API header.
status(" ${name}: WinRT detected. Adding WinRT API header")
list(APPEND highgui_ext_hdrs "${CMAKE_CURRENT_LIST_DIR}/include/opencv2/${name}/highgui_winrt.hpp")


list(APPEND highgui_srcs
${CMAKE_CURRENT_LIST_DIR}/src/window_winrt.cpp
${CMAKE_CURRENT_LIST_DIR}/src/window_winrt_bridge.cpp)
list(APPEND highgui_hdrs
${CMAKE_CURRENT_LIST_DIR}/src/window_winrt_bridge.hpp)
endif()

# libraries below are neither available nor required
# on ARM devices and/or Windows Phone
Expand All @@ -81,6 +96,10 @@ elseif(WINRT AND NOT WINRT_8_0)
status(" ${name}: Windows Phone detected")
elseif(OpenCV_ARCH STREQUAL "ARM")
status(" ${name}: ARM detected")
if(WINRT_STORE)
list(REMOVE_ITEM HIGHGUI_LIBRARIES "ws2_32")
status(" ${name}: Removing 'ws2_32.lib'")
endif()
endif()
status(" ${name}: Removing 'comctl32.lib, gdi32.lib, ole32.lib, setupapi.lib'")
status(" ${name}: Leaving '${HIGHGUI_LIBRARIES}'")
Expand Down
41 changes: 40 additions & 1 deletion modules/highgui/include/opencv2/highgui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ It provides easy interface to:
attached to the control panel is a trackbar, or the control panel is empty, a new buttonbar is
created. Then, a new button is attached to it.
See below the example used to generate the figure: :
See below the example used to generate the figure:
@code
int main(int argc, char *argv[])
int value = 50;
Expand Down Expand Up @@ -122,6 +122,45 @@ It provides easy interface to:
}
@endcode
@defgroup highgui_winrt WinRT support
This figure explains new functionality implemented with WinRT GUI. The new GUI provides an Image control,
and a slider panel. Slider panel holds trackbars attached to it.
Sliders are attached below the image control. Every new slider is added below the previous one.
See below the example used to generate the figure:
@code
void sample_app::MainPage::ShowWindow()
{
static cv::String windowName("sample");
cv::winrt_initContainer(this->cvContainer);
cv::namedWindow(windowName); // not required
cv::Mat image = cv::imread("Assets/sample.jpg");
cv::Mat converted = cv::Mat(image.rows, image.cols, CV_8UC4);
cvtColor(image, converted, CV_BGR2BGRA);
cv::imshow(windowName, converted); // this will create window if it hasn't been created before
int state = 42;
cv::TrackbarCallback callback = [](int pos, void* userdata)
{
if (pos == 0) {
cv::destroyWindow(windowName);
}
};
cv::TrackbarCallback callbackTwin = [](int pos, void* userdata)
{
if (pos >= 70) {
cv::destroyAllWindows();
}
};
cv::createTrackbar("Sample trackbar", windowName, &state, 100, callback);
cv::createTrackbar("Twin brother", windowName, &state, 100, callbackTwin);
}
@endcode
@defgroup highgui_c C API
@}
*/
Expand Down
48 changes: 48 additions & 0 deletions modules/highgui/include/opencv2/highgui/highgui_winrt.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// highgui (UX) support for Windows Runtime

// Copyright (c) Microsoft Open Technologies, Inc.
// All rights reserved.
//
// (3 - clause BSD License)
//
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that
// the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
// following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
// following disclaimer in the documentation and/or other materials provided with the distribution.
// 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or
// promote products derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
// PARTICULAR PURPOSE ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT(INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.

using namespace Windows::UI::Xaml::Controls;

namespace cv
{

//! @addtogroup highgui_winrt
//! @{

/********************************** WinRT Specific API *************************************************/

/** @brief Initializes container component that will be used to hold generated window content.
@param container Container (Panel^) reference that will be used to hold generated window content: controls and image.
@note
Must be called to assign WinRT container that will hold created windows content.
*/
CV_EXPORTS void winrt_initContainer(::Windows::UI::Xaml::Controls::Panel^ container);

//! @} videoio_winrt

} // cv
4 changes: 3 additions & 1 deletion modules/highgui/src/precomp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,18 @@
#define CV_WINDOW_MAGIC_VAL 0x00420042
#define CV_TRACKBAR_MAGIC_VAL 0x00420043

//Yannick Verdie 2010
//Yannick Verdie 2010, Max Kostin 2015
void cvSetModeWindow_W32(const char* name, double prop_value);
void cvSetModeWindow_GTK(const char* name, double prop_value);
void cvSetModeWindow_CARBON(const char* name, double prop_value);
void cvSetModeWindow_COCOA(const char* name, double prop_value);
void cvSetModeWindow_WinRT(const char* name, double prop_value);

double cvGetModeWindow_W32(const char* name);
double cvGetModeWindow_GTK(const char* name);
double cvGetModeWindow_CARBON(const char* name);
double cvGetModeWindow_COCOA(const char* name);
double cvGetModeWindow_WinRT(const char* name);

double cvGetPropWindowAutoSize_W32(const char* name);
double cvGetPropWindowAutoSize_GTK(const char* name);
Expand Down
15 changes: 10 additions & 5 deletions modules/highgui/src/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ CV_IMPL void cvSetWindowProperty(const char* name, int prop_id, double prop_valu
cvSetModeWindow_CARBON(name,prop_value);
#elif defined (HAVE_COCOA)
cvSetModeWindow_COCOA(name,prop_value);
#elif defined (WINRT)
cvSetModeWindow_WinRT(name, prop_value);
#endif

break;

case CV_WND_PROP_AUTOSIZE:
Expand Down Expand Up @@ -104,6 +107,8 @@ CV_IMPL double cvGetWindowProperty(const char* name, int prop_id)
return cvGetModeWindow_CARBON(name);
#elif defined (HAVE_COCOA)
return cvGetModeWindow_COCOA(name);
#elif defined (WINRT)
return cvGetModeWindow_WinRT(name);
#else
return -1;
#endif
Expand Down Expand Up @@ -481,12 +486,12 @@ int cv::createButton(const String&, ButtonCallback, void*, int , bool )

#endif

#if defined (HAVE_WIN32UI) // see window_w32.cpp
#elif defined (HAVE_GTK) // see window_gtk.cpp
#elif defined (HAVE_COCOA) // see window_carbon.cpp
#if defined (HAVE_WIN32UI) // see window_w32.cpp
#elif defined (HAVE_GTK) // see window_gtk.cpp
#elif defined (HAVE_COCOA) // see window_carbon.cpp
#elif defined (HAVE_CARBON)
#elif defined (HAVE_QT) // see window_QT.cpp
#elif defined (WINRT) && !defined (WINRT_8_0) // see window_winrt.cpp
#elif defined (HAVE_QT) // see window_QT.cpp
#elif defined (WINRT) && !defined (WINRT_8_0) // see window_winrt.cpp

#else

Expand Down
Loading

0 comments on commit e3cbc93

Please sign in to comment.