Apply maemo2 patch
[opencv] / otherlibs / highgui / highgui.h
1 /*M///////////////////////////////////////////////////////////////////////////////////////
2 //
3 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4 //
5 //  By downloading, copying, installing or using the software you agree to this license.
6 //  If you do not agree to this license, do not download, install,
7 //  copy or use the software.
8 //
9 //
10 //                        Intel License Agreement
11 //                For Open Source Computer Vision Library
12 //
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
14 // Third party copyrights are property of their respective owners.
15 //
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
18 //
19 //   * Redistribution's of source code must retain the above copyright notice,
20 //     this list of conditions and the following disclaimer.
21 //
22 //   * Redistribution's in binary form must reproduce the above copyright notice,
23 //     this list of conditions and the following disclaimer in the documentation
24 //     and/or other materials provided with the distribution.
25 //
26 //   * The name of Intel Corporation may not be used to endorse or promote products
27 //     derived from this software without specific prior written permission.
28 //
29 // This software is provided by the copyright holders and contributors "as is" and
30 // any express or implied warranties, including, but not limited to, the implied
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
32 // In no event shall the Intel Corporation or contributors be liable for any direct,
33 // indirect, incidental, special, exemplary, or consequential damages
34 // (including, but not limited to, procurement of substitute goods or services;
35 // loss of use, data, or profits; or business interruption) however caused
36 // and on any theory of liability, whether in contract, strict liability,
37 // or tort (including negligence or otherwise) arising in any way out of
38 // the use of this software, even if advised of the possibility of such damage.
39 //
40 //M*/
41
42 #ifndef _HIGH_GUI_
43 #define _HIGH_GUI_
44
45 #ifndef SKIP_INCLUDES
46
47   #include "cxcore.h"
48   #if defined WIN32 || defined WIN64
49     #include <windows.h>
50   #endif
51
52 #else // SKIP_INCLUDES
53
54   #if defined WIN32 || defined WIN64
55     #define CV_CDECL __cdecl
56     #define CV_STDCALL __stdcall
57   #else
58     #define CV_CDECL
59     #define CV_STDCALL
60   #endif
61
62   #ifndef CV_EXTERN_C
63     #ifdef __cplusplus
64       #define CV_EXTERN_C extern "C"
65       #define CV_DEFAULT(val) = val
66     #else
67       #define CV_EXTERN_C
68       #define CV_DEFAULT(val)
69     #endif
70   #endif
71
72   #ifndef CV_EXTERN_C_FUNCPTR
73     #ifdef __cplusplus
74       #define CV_EXTERN_C_FUNCPTR(x) extern "C" { typedef x; }
75     #else
76       #define CV_EXTERN_C_FUNCPTR(x) typedef x
77     #endif
78   #endif
79
80   #ifndef CV_INLINE
81     #if defined __cplusplus
82       #define CV_INLINE inline
83     #elif (defined WIN32 || defined WIN64) && !defined __GNUC__
84       #define CV_INLINE __inline
85     #else
86       #define CV_INLINE static
87     #endif
88   #endif /* CV_INLINE */
89
90   #if (defined WIN32 || defined WIN64) && defined CVAPI_EXPORTS
91     #define CV_EXPORTS __declspec(dllexport)
92   #else
93     #define CV_EXPORTS
94   #endif
95
96   #ifndef CVAPI
97     #define CVAPI(rettype) CV_EXTERN_C CV_EXPORTS rettype CV_CDECL
98   #endif
99
100 #endif // SKIP_INCLUDES
101
102 #if defined(_CH_)
103   #pragma package <chopencv>
104   #include <chdl.h>
105   LOAD_CHDL(highgui)
106 #endif
107
108 #ifdef __cplusplus
109   extern "C" {
110 #endif /* __cplusplus */
111
112 /****************************************************************************************\
113 *                                  Basic GUI functions                                   *
114 \****************************************************************************************/
115
116 /* this function is used to set some external parameters in case of X Window */
117 CVAPI(int) cvInitSystem( int argc, char** argv );
118
119 CVAPI(int) cvStartWindowThread();
120
121 #define CV_WINDOW_AUTOSIZE  1
122 /* create window */
123 CVAPI(int) cvNamedWindow( const char* name, int flags CV_DEFAULT(CV_WINDOW_AUTOSIZE) );
124
125 /* display image within window (highgui windows remember their content) */
126 CVAPI(void) cvShowImage( const char* name, const CvArr* image );
127
128 /* resize/move window */
129 CVAPI(void) cvResizeWindow( const char* name, int width, int height );
130 CVAPI(void) cvMoveWindow( const char* name, int x, int y );
131
132
133 /* destroy window and all the trackers associated with it */
134 CVAPI(void) cvDestroyWindow( const char* name );
135
136 CVAPI(void) cvDestroyAllWindows(void);
137
138 /* get native window handle (HWND in case of Win32 and Widget in case of X Window) */
139 CVAPI(void*) cvGetWindowHandle( const char* name );
140
141 /* get name of highgui window given its native handle */
142 CVAPI(const char*) cvGetWindowName( void* window_handle );
143
144
145 typedef void (CV_CDECL *CvTrackbarCallback)(int pos);
146
147 /* create trackbar and display it on top of given window, set callback */
148 CVAPI(int) cvCreateTrackbar( const char* trackbar_name, const char* window_name,
149                              int* value, int count, CvTrackbarCallback on_change );
150
151 /* retrieve or set trackbar position */
152 CVAPI(int) cvGetTrackbarPos( const char* trackbar_name, const char* window_name );
153 CVAPI(void) cvSetTrackbarPos( const char* trackbar_name, const char* window_name, int pos );
154
155 #define CV_EVENT_MOUSEMOVE      0
156 #define CV_EVENT_LBUTTONDOWN    1
157 #define CV_EVENT_RBUTTONDOWN    2
158 #define CV_EVENT_MBUTTONDOWN    3
159 #define CV_EVENT_LBUTTONUP      4
160 #define CV_EVENT_RBUTTONUP      5
161 #define CV_EVENT_MBUTTONUP      6
162 #define CV_EVENT_LBUTTONDBLCLK  7
163 #define CV_EVENT_RBUTTONDBLCLK  8
164 #define CV_EVENT_MBUTTONDBLCLK  9
165
166 #define CV_EVENT_FLAG_LBUTTON   1
167 #define CV_EVENT_FLAG_RBUTTON   2
168 #define CV_EVENT_FLAG_MBUTTON   4
169 #define CV_EVENT_FLAG_CTRLKEY   8
170 #define CV_EVENT_FLAG_SHIFTKEY  16
171 #define CV_EVENT_FLAG_ALTKEY    32
172
173 typedef void (CV_CDECL *CvMouseCallback )(int event, int x, int y, int flags, void* param);
174
175 /* assign callback for mouse events */
176 CVAPI(void) cvSetMouseCallback( const char* window_name, CvMouseCallback on_mouse,
177                                 void* param CV_DEFAULT(NULL));
178
179 /* 8bit, color or not */
180 #define CV_LOAD_IMAGE_UNCHANGED  -1
181 /* 8bit, gray */
182 #define CV_LOAD_IMAGE_GRAYSCALE   0
183 /* ?, color */
184 #define CV_LOAD_IMAGE_COLOR       1
185 /* any depth, ? */
186 #define CV_LOAD_IMAGE_ANYDEPTH    2
187 /* ?, any color */
188 #define CV_LOAD_IMAGE_ANYCOLOR    4
189
190 /* load image from file
191   iscolor can be a combination of above flags where CV_LOAD_IMAGE_UNCHANGED
192   overrides the other flags
193   using CV_LOAD_IMAGE_ANYCOLOR alone is equivalent to CV_LOAD_IMAGE_UNCHANGED
194   unless CV_LOAD_IMAGE_ANYDEPTH is specified images are converted to 8bit
195 */
196 CVAPI(IplImage*) cvLoadImage( const char* filename, int iscolor CV_DEFAULT(CV_LOAD_IMAGE_COLOR));
197 CVAPI(CvMat*) cvLoadImageM( const char* filename, int iscolor CV_DEFAULT(CV_LOAD_IMAGE_COLOR));
198
199 /* save image to file */
200 CVAPI(int) cvSaveImage( const char* filename, const CvArr* image );
201
202 #define CV_CVTIMG_FLIP      1
203 #define CV_CVTIMG_SWAP_RB   2
204 /* utility function: convert one image to another with optional vertical flip */
205 CVAPI(void) cvConvertImage( const CvArr* src, CvArr* dst, int flags CV_DEFAULT(0));
206
207 /* wait for key event infinitely (delay<=0) or for "delay" milliseconds */
208 CVAPI(int) cvWaitKey(int delay CV_DEFAULT(0));
209
210
211 /****************************************************************************************\
212 *                         Working with Video Files and Cameras                           *
213 \****************************************************************************************/
214
215 /* "black box" capture structure */
216 typedef struct CvCapture CvCapture;
217
218 /* start capturing frames from video file */
219 CVAPI(CvCapture*) cvCreateFileCapture( const char* filename );
220
221 #define CV_CAP_ANY      0     // autodetect
222
223 #define CV_CAP_MIL      100   // MIL proprietary drivers
224
225 #define CV_CAP_VFW      200   // platform native
226 #define CV_CAP_V4L      200
227 #define CV_CAP_V4L2     200
228
229 #define CV_CAP_FIREWARE 300   // IEEE 1394 drivers
230 #define CV_CAP_FIREWIRE 300
231 #define CV_CAP_IEEE1394 300
232 #define CV_CAP_DC1394   300
233 #define CV_CAP_CMU1394  300
234
235 #define CV_CAP_STEREO   400   // TYZX proprietary drivers
236 #define CV_CAP_TYZX     400
237 #define CV_TYZX_LEFT    400
238 #define CV_TYZX_RIGHT   401
239 #define CV_TYZX_COLOR   402
240 #define CV_TYZX_Z       403
241
242 #define CV_CAP_QT       500   // QuickTime
243
244 #define CV_CAP_UNICAP   600   // Unicap drivers
245
246 /* start capturing frames from camera: index = camera_index + domain_offset (CV_CAP_*) */
247 CVAPI(CvCapture*) cvCreateCameraCapture( int index );
248
249 /* grab a frame, return 1 on success, 0 on fail.
250   this function is thought to be fast               */
251 CVAPI(int) cvGrabFrame( CvCapture* capture );
252
253 /* get the frame grabbed with cvGrabFrame(..)
254   This function may apply some frame processing like
255   frame decompression, flipping etc.
256   !!!DO NOT RELEASE or MODIFY the retrieved frame!!! */
257 CVAPI(IplImage*) cvRetrieveFrame( CvCapture* capture );
258
259 /* Just a combination of cvGrabFrame and cvRetrieveFrame
260    !!!DO NOT RELEASE or MODIFY the retrieved frame!!!      */
261 CVAPI(IplImage*) cvQueryFrame( CvCapture* capture );
262
263 /* stop capturing/reading and free resources */
264 CVAPI(void) cvReleaseCapture( CvCapture** capture );
265
266 #define CV_CAP_PROP_POS_MSEC       0
267 #define CV_CAP_PROP_POS_FRAMES     1
268 #define CV_CAP_PROP_POS_AVI_RATIO  2
269 #define CV_CAP_PROP_FRAME_WIDTH    3
270 #define CV_CAP_PROP_FRAME_HEIGHT   4
271 #define CV_CAP_PROP_FPS            5
272 #define CV_CAP_PROP_FOURCC         6
273 #define CV_CAP_PROP_FRAME_COUNT    7
274 #define CV_CAP_PROP_FORMAT         8
275 #define CV_CAP_PROP_MODE           9
276 #define CV_CAP_PROP_BRIGHTNESS    10
277 #define CV_CAP_PROP_CONTRAST      11
278 #define CV_CAP_PROP_SATURATION    12
279 #define CV_CAP_PROP_HUE           13
280 #define CV_CAP_PROP_GAIN          14
281 #define CV_CAP_PROP_CONVERT_RGB   15
282
283
284 /* retrieve or set capture properties */
285 CVAPI(double) cvGetCaptureProperty( CvCapture* capture, int property_id );
286 CVAPI(int)    cvSetCaptureProperty( CvCapture* capture, int property_id, double value );
287
288 /* "black box" video file writer structure */
289 typedef struct CvVideoWriter CvVideoWriter;
290
291 #define CV_FOURCC(c1,c2,c3,c4)  \
292     (((c1)&255) + (((c2)&255)<<8) + (((c3)&255)<<16) + (((c4)&255)<<24))
293
294 #define CV_FOURCC_PROMPT -1  /* Open Codec Selection Dialog (Windows only) */
295 #define CV_FOURCC_DEFAULT -1 /* Use default codec for specified filename (Linux only) */
296
297 /* initialize video file writer */
298 CVAPI(CvVideoWriter*) cvCreateVideoWriter( const char* filename, int fourcc,
299                                            double fps, CvSize frame_size,
300                                            int is_color CV_DEFAULT(1));
301
302 //CVAPI(CvVideoWriter*) cvCreateImageSequenceWriter( const char* filename,
303 //                                                   int is_color CV_DEFAULT(1));
304
305 /* write frame to video file */
306 CVAPI(int) cvWriteFrame( CvVideoWriter* writer, const IplImage* image );
307
308 /* close video file writer */
309 CVAPI(void) cvReleaseVideoWriter( CvVideoWriter** writer );
310
311 /****************************************************************************************\
312 *                              Obsolete functions/synonyms                               *
313 \****************************************************************************************/
314
315 #ifndef HIGHGUI_NO_BACKWARD_COMPATIBILITY
316     #define HIGHGUI_BACKWARD_COMPATIBILITY
317 #endif
318
319 #ifdef HIGHGUI_BACKWARD_COMPATIBILITY
320
321 #define cvCaptureFromFile cvCreateFileCapture
322 #define cvCaptureFromCAM cvCreateCameraCapture
323 #define cvCaptureFromAVI cvCaptureFromFile
324 #define cvCreateAVIWriter cvCreateVideoWriter
325 #define cvWriteToAVI cvWriteFrame
326 #define cvAddSearchPath(path)
327 #define cvvInitSystem cvInitSystem
328 #define cvvNamedWindow cvNamedWindow
329 #define cvvShowImage cvShowImage
330 #define cvvResizeWindow cvResizeWindow
331 #define cvvDestroyWindow cvDestroyWindow
332 #define cvvCreateTrackbar cvCreateTrackbar
333 #define cvvLoadImage(name) cvLoadImage((name),1)
334 #define cvvSaveImage cvSaveImage
335 #define cvvAddSearchPath cvAddSearchPath
336 #define cvvWaitKey(name) cvWaitKey(0)
337 #define cvvWaitKeyEx(name,delay) cvWaitKey(delay)
338 #define cvvConvertImage cvConvertImage
339 #define HG_AUTOSIZE CV_WINDOW_AUTOSIZE
340 #define set_preprocess_func cvSetPreprocessFuncWin32
341 #define set_postprocess_func cvSetPostprocessFuncWin32
342
343 #ifdef WIN32
344
345 typedef int (CV_CDECL * CvWin32WindowCallback)(HWND, UINT, WPARAM, LPARAM, int*);
346 CVAPI(void) cvSetPreprocessFuncWin32( CvWin32WindowCallback on_preprocess );
347 CVAPI(void) cvSetPostprocessFuncWin32( CvWin32WindowCallback on_postprocess );
348
349 CV_INLINE int iplWidth( const IplImage* img );
350 CV_INLINE int iplWidth( const IplImage* img )
351 {
352     return !img ? 0 : !img->roi ? img->width : img->roi->width;
353 }
354
355 CV_INLINE int iplHeight( const IplImage* img );
356 CV_INLINE int iplHeight( const IplImage* img )
357 {
358     return !img ? 0 : !img->roi ? img->height : img->roi->height;
359 }
360
361 #endif
362
363 #endif /* obsolete functions */
364
365 /* For use with Win32 */
366 #ifdef WIN32
367
368 CV_INLINE RECT NormalizeRect( RECT r );
369 CV_INLINE RECT NormalizeRect( RECT r )
370 {
371     int t;
372
373     if( r.left > r.right )
374     {
375         t = r.left;
376         r.left = r.right;
377         r.right = t;
378     }
379
380     if( r.top > r.bottom )
381     {
382         t = r.top;
383         r.top = r.bottom;
384         r.bottom = t;
385     }
386
387     return r;
388 }
389
390 CV_INLINE CvRect RectToCvRect( RECT sr );
391 CV_INLINE CvRect RectToCvRect( RECT sr )
392 {
393     sr = NormalizeRect( sr );
394     return cvRect( sr.left, sr.top, sr.right - sr.left, sr.bottom - sr.top );
395 }
396
397 CV_INLINE RECT CvRectToRect( CvRect sr );
398 CV_INLINE RECT CvRectToRect( CvRect sr )
399 {
400     RECT dr;
401     dr.left = sr.x;
402     dr.top = sr.y;
403     dr.right = sr.x + sr.width;
404     dr.bottom = sr.y + sr.height;
405
406     return dr;
407 }
408
409 CV_INLINE IplROI RectToROI( RECT r );
410 CV_INLINE IplROI RectToROI( RECT r )
411 {
412     IplROI roi;
413     r = NormalizeRect( r );
414     roi.xOffset = r.left;
415     roi.yOffset = r.top;
416     roi.width = r.right - r.left;
417     roi.height = r.bottom - r.top;
418     roi.coi = 0;
419
420     return roi;
421 }
422
423 #endif /* WIN32 */
424
425 #ifdef __cplusplus
426 }  /* end of extern "C" */
427 #endif /* __cplusplus */
428
429
430 #if defined __cplusplus && (!defined WIN32 || !defined (__GNUC__)) && !defined CV_NO_CVV_IMAGE
431
432 #define CImage CvvImage
433
434 /* CvvImage class definition */
435 class CV_EXPORTS CvvImage
436 {
437 public:
438     CvvImage();
439     virtual ~CvvImage();
440
441     /* Create image (BGR or grayscale) */
442     virtual bool  Create( int width, int height, int bits_per_pixel, int image_origin = 0 );
443
444     /* Load image from specified file */
445     virtual bool  Load( const char* filename, int desired_color = 1 );
446
447     /* Load rectangle from the file */
448     virtual bool  LoadRect( const char* filename,
449                             int desired_color, CvRect r );
450
451 #ifdef WIN32
452     virtual bool  LoadRect( const char* filename,
453                             int desired_color, RECT r )
454     {
455         return LoadRect( filename, desired_color,
456                          cvRect( r.left, r.top, r.right - r.left, r.bottom - r.top ));
457     }
458 #endif
459
460     /* Save entire image to specified file. */
461     virtual bool  Save( const char* filename );
462
463     /* Get copy of input image ROI */
464     virtual void  CopyOf( CvvImage& image, int desired_color = -1 );
465     virtual void  CopyOf( IplImage* img, int desired_color = -1 );
466
467     IplImage* GetImage() { return m_img; };
468     virtual void  Destroy(void);
469
470     /* width and height of ROI */
471     int Width() { return !m_img ? 0 : !m_img->roi ? m_img->width : m_img->roi->width; };
472     int Height() { return !m_img ? 0 : !m_img->roi ? m_img->height : m_img->roi->height;};
473     int Bpp() { return m_img ? (m_img->depth & 255)*m_img->nChannels : 0; };
474
475     virtual void  Fill( int color );
476
477     /* draw to highgui window */
478     virtual void  Show( const char* window );
479
480 #ifdef WIN32
481     /* draw part of image to the specified DC */
482     virtual void  Show( HDC dc, int x, int y, int width, int height,
483                         int from_x = 0, int from_y = 0 );
484     /* draw the current image ROI to the specified rectangle of the destination DC */
485     virtual void  DrawToHDC( HDC hDCDst, RECT* pDstRect );
486 #endif
487
488 protected:
489
490     IplImage*  m_img;
491 };
492
493 #endif /* __cplusplus */
494
495 #endif /* _HIGH_GUI_ */