Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/highgui/src/window_winrt.cpp
16337 views
1
// highgui to XAML bridge for OpenCV
2
3
// Copyright (c) Microsoft Open Technologies, Inc.
4
// All rights reserved.
5
//
6
// (3 - clause BSD License)
7
//
8
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that
9
// the following conditions are met:
10
//
11
// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
12
// following disclaimer.
13
// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
14
// following disclaimer in the documentation and/or other materials provided with the distribution.
15
// 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or
16
// promote products derived from this software without specific prior written permission.
17
//
18
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
19
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20
// PARTICULAR PURPOSE ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
21
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO,
22
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT(INCLUDING
24
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25
// POSSIBILITY OF SUCH DAMAGE.
26
27
#include "precomp.hpp"
28
29
#include <map>
30
#include <stdlib.h>
31
#include <string.h>
32
#include <stdio.h>
33
#include <assert.h>
34
#include <opencv2\highgui.hpp>
35
#include <opencv2\highgui\highgui_winrt.hpp>
36
#include <window_winrt_bridge.hpp>
37
38
#define CV_WINRT_NO_GUI_ERROR( funcname ) \
39
{ \
40
cvError( CV_StsNotImplemented, funcname, \
41
"The function is not implemented. ", \
42
__FILE__, __LINE__ ); \
43
}
44
45
#define CV_ERROR( Code, Msg ) \
46
{ \
47
cvError( (Code), cvFuncName, Msg, __FILE__, __LINE__ ); \
48
};
49
50
/********************************** WinRT Specific API Implementation ******************************************/
51
52
// Initializes or overrides container contents with default XAML markup structure
53
void cv::winrt_initContainer(::Windows::UI::Xaml::Controls::Panel^ _container)
54
{
55
HighguiBridge::getInstance().setContainer(_container);
56
}
57
58
/********************************** API Implementation *********************************************************/
59
60
CV_IMPL void cvShowImage(const char* name, const CvArr* arr)
61
{
62
CV_FUNCNAME("cvShowImage");
63
64
__BEGIN__;
65
66
CvMat stub, *image;
67
68
if (!name)
69
CV_ERROR(CV_StsNullPtr, "NULL name");
70
71
CvWindow* window = HighguiBridge::getInstance().namedWindow(name);
72
73
if (!window || !arr)
74
return;
75
76
CV_CALL(image = cvGetMat(arr, &stub));
77
78
//TODO: use approach from window_w32.cpp or cv::Mat(.., .., CV_8UC4)
79
// and cvtColor(.., .., CV_BGR2BGRA) to convert image here
80
// than beforehand.
81
82
window->updateImage(image);
83
HighguiBridge::getInstance().showWindow(window);
84
85
__END__;
86
}
87
88
CV_IMPL int cvNamedWindow(const char* name, int flags)
89
{
90
CV_FUNCNAME("cvNamedWindow");
91
92
if (!name)
93
CV_ERROR(CV_StsNullPtr, "NULL name");
94
95
HighguiBridge::getInstance().namedWindow(name);
96
97
return CV_OK;
98
}
99
100
CV_IMPL void cvDestroyWindow(const char* name)
101
{
102
CV_FUNCNAME("cvDestroyWindow");
103
104
if (!name)
105
CV_ERROR(CV_StsNullPtr, "NULL name string");
106
107
HighguiBridge::getInstance().destroyWindow(name);
108
}
109
110
CV_IMPL void cvDestroyAllWindows()
111
{
112
HighguiBridge::getInstance().destroyAllWindows();
113
}
114
115
CV_IMPL int cvCreateTrackbar2(const char* trackbar_name, const char* window_name,
116
int* val, int count, CvTrackbarCallback2 on_notify, void* userdata)
117
{
118
CV_FUNCNAME("cvCreateTrackbar2");
119
120
int pos = 0;
121
122
if (!window_name || !trackbar_name)
123
CV_ERROR(CV_StsNullPtr, "NULL window or trackbar name");
124
125
if (count < 0)
126
CV_ERROR(CV_StsOutOfRange, "Bad trackbar max value");
127
128
CvWindow* window = HighguiBridge::getInstance().namedWindow(window_name);
129
130
if (!window)
131
{
132
CV_ERROR(CV_StsNullPtr, "NULL window");
133
}
134
135
window->createSlider(trackbar_name, val, count, on_notify, userdata);
136
137
return CV_OK;
138
}
139
140
CV_IMPL void cvSetTrackbarPos(const char* trackbar_name, const char* window_name, int pos)
141
{
142
CV_FUNCNAME("cvSetTrackbarPos");
143
144
CvTrackbar* trackbar = 0;
145
146
if (trackbar_name == 0 || window_name == 0)
147
CV_ERROR(CV_StsNullPtr, "NULL trackbar or window name");
148
149
CvWindow* window = HighguiBridge::getInstance().findWindowByName(window_name);
150
if (window)
151
trackbar = window->findTrackbarByName(trackbar_name);
152
153
if (trackbar)
154
trackbar->setPosition(pos);
155
}
156
157
CV_IMPL void cvSetTrackbarMax(const char* trackbar_name, const char* window_name, int maxval)
158
{
159
CV_FUNCNAME("cvSetTrackbarMax");
160
161
if (maxval >= 0)
162
{
163
if (trackbar_name == 0 || window_name == 0)
164
CV_ERROR(CV_StsNullPtr, "NULL trackbar or window name");
165
166
CvTrackbar* trackbar = HighguiBridge::getInstance().findTrackbarByName(trackbar_name, window_name);
167
168
if (trackbar)
169
trackbar->setMaxPosition(maxval);
170
}
171
}
172
173
CV_IMPL void cvSetTrackbarMin(const char* trackbar_name, const char* window_name, int minval)
174
{
175
CV_FUNCNAME("cvSetTrackbarMin");
176
177
if (minval >= 0)
178
{
179
if (trackbar_name == 0 || window_name == 0)
180
CV_ERROR(CV_StsNullPtr, "NULL trackbar or window name");
181
182
CvTrackbar* trackbar = HighguiBridge::getInstance().findTrackbarByName(trackbar_name, window_name);
183
184
if (trackbar)
185
trackbar->setMinPosition(minval);
186
}
187
}
188
189
CV_IMPL int cvGetTrackbarPos(const char* trackbar_name, const char* window_name)
190
{
191
int pos = -1;
192
193
CV_FUNCNAME("cvGetTrackbarPos");
194
195
if (trackbar_name == 0 || window_name == 0)
196
CV_ERROR(CV_StsNullPtr, "NULL trackbar or window name");
197
198
CvTrackbar* trackbar = HighguiBridge::getInstance().findTrackbarByName(trackbar_name, window_name);
199
200
if (trackbar)
201
pos = trackbar->getPosition();
202
203
return pos;
204
}
205
206
/********************************** Not YET implemented API ****************************************************/
207
208
CV_IMPL int cvWaitKey(int delay)
209
{
210
CV_WINRT_NO_GUI_ERROR("cvWaitKey");
211
212
// see https://msdn.microsoft.com/en-us/library/windows/desktop/ms724411(v=vs.85).aspx
213
int time0 = GetTickCount64();
214
215
for (;;)
216
{
217
CvWindow* window;
218
219
if (delay <= 0)
220
{
221
// TODO: implement appropriate logic here
222
}
223
}
224
}
225
226
CV_IMPL void cvSetMouseCallback(const char* window_name, CvMouseCallback on_mouse, void* param)
227
{
228
CV_WINRT_NO_GUI_ERROR("cvSetMouseCallback");
229
230
CV_FUNCNAME("cvSetMouseCallback");
231
232
if (!window_name)
233
CV_ERROR(CV_StsNullPtr, "NULL window name");
234
235
CvWindow* window = HighguiBridge::getInstance().findWindowByName(window_name);
236
if (!window)
237
return;
238
239
// TODO: implement appropriate logic here
240
}
241
242
/********************************** Disabled or not supported API **********************************************/
243
244
CV_IMPL void cvMoveWindow(const char* name, int x, int y)
245
{
246
CV_WINRT_NO_GUI_ERROR("cvMoveWindow");
247
}
248
249
CV_IMPL void cvResizeWindow(const char* name, int width, int height)
250
{
251
CV_WINRT_NO_GUI_ERROR("cvResizeWindow");
252
}
253
254
CV_IMPL int cvInitSystem(int, char**)
255
{
256
CV_WINRT_NO_GUI_ERROR("cvInitSystem");
257
return CV_StsNotImplemented;
258
}
259
260
CV_IMPL void* cvGetWindowHandle(const char*)
261
{
262
CV_WINRT_NO_GUI_ERROR("cvGetWindowHandle");
263
return (void*) CV_StsNotImplemented;
264
}
265
266
CV_IMPL const char* cvGetWindowName(void*)
267
{
268
CV_WINRT_NO_GUI_ERROR("cvGetWindowName");
269
return (const char*) CV_StsNotImplemented;
270
}
271
272
void cvSetModeWindow_WinRT(const char* name, double prop_value) {
273
CV_WINRT_NO_GUI_ERROR("cvSetModeWindow");
274
}
275
276
double cvGetModeWindow_WinRT(const char* name) {
277
CV_WINRT_NO_GUI_ERROR("cvGetModeWindow");
278
return CV_StsNotImplemented;
279
}
280
281
CV_IMPL int cvStartWindowThread() {
282
CV_WINRT_NO_GUI_ERROR("cvStartWindowThread");
283
return CV_StsNotImplemented;
284
}
285