Path: blob/master/modules/highgui/src/window_winrt.cpp
16337 views
// highgui to XAML bridge for OpenCV12// Copyright (c) Microsoft Open Technologies, Inc.3// All rights reserved.4//5// (3 - clause BSD License)6//7// Redistribution and use in source and binary forms, with or without modification, are permitted provided that8// the following conditions are met:9//10// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the11// following disclaimer.12// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the13// following disclaimer in the documentation and/or other materials provided with the distribution.14// 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or15// promote products derived from this software without specific prior written permission.16//17// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED18// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A19// PARTICULAR PURPOSE ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY20// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO,21// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)22// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT(INCLUDING23// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE24// POSSIBILITY OF SUCH DAMAGE.2526#include "precomp.hpp"2728#include <map>29#include <stdlib.h>30#include <string.h>31#include <stdio.h>32#include <assert.h>33#include <opencv2\highgui.hpp>34#include <opencv2\highgui\highgui_winrt.hpp>35#include <window_winrt_bridge.hpp>3637#define CV_WINRT_NO_GUI_ERROR( funcname ) \38{ \39cvError( CV_StsNotImplemented, funcname, \40"The function is not implemented. ", \41__FILE__, __LINE__ ); \42}4344#define CV_ERROR( Code, Msg ) \45{ \46cvError( (Code), cvFuncName, Msg, __FILE__, __LINE__ ); \47};4849/********************************** WinRT Specific API Implementation ******************************************/5051// Initializes or overrides container contents with default XAML markup structure52void cv::winrt_initContainer(::Windows::UI::Xaml::Controls::Panel^ _container)53{54HighguiBridge::getInstance().setContainer(_container);55}5657/********************************** API Implementation *********************************************************/5859CV_IMPL void cvShowImage(const char* name, const CvArr* arr)60{61CV_FUNCNAME("cvShowImage");6263__BEGIN__;6465CvMat stub, *image;6667if (!name)68CV_ERROR(CV_StsNullPtr, "NULL name");6970CvWindow* window = HighguiBridge::getInstance().namedWindow(name);7172if (!window || !arr)73return;7475CV_CALL(image = cvGetMat(arr, &stub));7677//TODO: use approach from window_w32.cpp or cv::Mat(.., .., CV_8UC4)78// and cvtColor(.., .., CV_BGR2BGRA) to convert image here79// than beforehand.8081window->updateImage(image);82HighguiBridge::getInstance().showWindow(window);8384__END__;85}8687CV_IMPL int cvNamedWindow(const char* name, int flags)88{89CV_FUNCNAME("cvNamedWindow");9091if (!name)92CV_ERROR(CV_StsNullPtr, "NULL name");9394HighguiBridge::getInstance().namedWindow(name);9596return CV_OK;97}9899CV_IMPL void cvDestroyWindow(const char* name)100{101CV_FUNCNAME("cvDestroyWindow");102103if (!name)104CV_ERROR(CV_StsNullPtr, "NULL name string");105106HighguiBridge::getInstance().destroyWindow(name);107}108109CV_IMPL void cvDestroyAllWindows()110{111HighguiBridge::getInstance().destroyAllWindows();112}113114CV_IMPL int cvCreateTrackbar2(const char* trackbar_name, const char* window_name,115int* val, int count, CvTrackbarCallback2 on_notify, void* userdata)116{117CV_FUNCNAME("cvCreateTrackbar2");118119int pos = 0;120121if (!window_name || !trackbar_name)122CV_ERROR(CV_StsNullPtr, "NULL window or trackbar name");123124if (count < 0)125CV_ERROR(CV_StsOutOfRange, "Bad trackbar max value");126127CvWindow* window = HighguiBridge::getInstance().namedWindow(window_name);128129if (!window)130{131CV_ERROR(CV_StsNullPtr, "NULL window");132}133134window->createSlider(trackbar_name, val, count, on_notify, userdata);135136return CV_OK;137}138139CV_IMPL void cvSetTrackbarPos(const char* trackbar_name, const char* window_name, int pos)140{141CV_FUNCNAME("cvSetTrackbarPos");142143CvTrackbar* trackbar = 0;144145if (trackbar_name == 0 || window_name == 0)146CV_ERROR(CV_StsNullPtr, "NULL trackbar or window name");147148CvWindow* window = HighguiBridge::getInstance().findWindowByName(window_name);149if (window)150trackbar = window->findTrackbarByName(trackbar_name);151152if (trackbar)153trackbar->setPosition(pos);154}155156CV_IMPL void cvSetTrackbarMax(const char* trackbar_name, const char* window_name, int maxval)157{158CV_FUNCNAME("cvSetTrackbarMax");159160if (maxval >= 0)161{162if (trackbar_name == 0 || window_name == 0)163CV_ERROR(CV_StsNullPtr, "NULL trackbar or window name");164165CvTrackbar* trackbar = HighguiBridge::getInstance().findTrackbarByName(trackbar_name, window_name);166167if (trackbar)168trackbar->setMaxPosition(maxval);169}170}171172CV_IMPL void cvSetTrackbarMin(const char* trackbar_name, const char* window_name, int minval)173{174CV_FUNCNAME("cvSetTrackbarMin");175176if (minval >= 0)177{178if (trackbar_name == 0 || window_name == 0)179CV_ERROR(CV_StsNullPtr, "NULL trackbar or window name");180181CvTrackbar* trackbar = HighguiBridge::getInstance().findTrackbarByName(trackbar_name, window_name);182183if (trackbar)184trackbar->setMinPosition(minval);185}186}187188CV_IMPL int cvGetTrackbarPos(const char* trackbar_name, const char* window_name)189{190int pos = -1;191192CV_FUNCNAME("cvGetTrackbarPos");193194if (trackbar_name == 0 || window_name == 0)195CV_ERROR(CV_StsNullPtr, "NULL trackbar or window name");196197CvTrackbar* trackbar = HighguiBridge::getInstance().findTrackbarByName(trackbar_name, window_name);198199if (trackbar)200pos = trackbar->getPosition();201202return pos;203}204205/********************************** Not YET implemented API ****************************************************/206207CV_IMPL int cvWaitKey(int delay)208{209CV_WINRT_NO_GUI_ERROR("cvWaitKey");210211// see https://msdn.microsoft.com/en-us/library/windows/desktop/ms724411(v=vs.85).aspx212int time0 = GetTickCount64();213214for (;;)215{216CvWindow* window;217218if (delay <= 0)219{220// TODO: implement appropriate logic here221}222}223}224225CV_IMPL void cvSetMouseCallback(const char* window_name, CvMouseCallback on_mouse, void* param)226{227CV_WINRT_NO_GUI_ERROR("cvSetMouseCallback");228229CV_FUNCNAME("cvSetMouseCallback");230231if (!window_name)232CV_ERROR(CV_StsNullPtr, "NULL window name");233234CvWindow* window = HighguiBridge::getInstance().findWindowByName(window_name);235if (!window)236return;237238// TODO: implement appropriate logic here239}240241/********************************** Disabled or not supported API **********************************************/242243CV_IMPL void cvMoveWindow(const char* name, int x, int y)244{245CV_WINRT_NO_GUI_ERROR("cvMoveWindow");246}247248CV_IMPL void cvResizeWindow(const char* name, int width, int height)249{250CV_WINRT_NO_GUI_ERROR("cvResizeWindow");251}252253CV_IMPL int cvInitSystem(int, char**)254{255CV_WINRT_NO_GUI_ERROR("cvInitSystem");256return CV_StsNotImplemented;257}258259CV_IMPL void* cvGetWindowHandle(const char*)260{261CV_WINRT_NO_GUI_ERROR("cvGetWindowHandle");262return (void*) CV_StsNotImplemented;263}264265CV_IMPL const char* cvGetWindowName(void*)266{267CV_WINRT_NO_GUI_ERROR("cvGetWindowName");268return (const char*) CV_StsNotImplemented;269}270271void cvSetModeWindow_WinRT(const char* name, double prop_value) {272CV_WINRT_NO_GUI_ERROR("cvSetModeWindow");273}274275double cvGetModeWindow_WinRT(const char* name) {276CV_WINRT_NO_GUI_ERROR("cvGetModeWindow");277return CV_StsNotImplemented;278}279280CV_IMPL int cvStartWindowThread() {281CV_WINRT_NO_GUI_ERROR("cvStartWindowThread");282return CV_StsNotImplemented;283}284285