1 /*M///////////////////////////////////////////////////////////////////////////////////////
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
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.
10 // Intel License Agreement
11 // For Open Source Computer Vision Library
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
14 // Third party copyrights are property of their respective owners.
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
19 // * Redistribution's of source code must retain the above copyright notice,
20 // this list of conditions and the following disclaimer.
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.
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.
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.
42 /* The header is mostly for internal use and it is likely to change.
43 It contains some macro definitions that are used in cxcore, cv, cvaux
44 and, probably, other libraries. If you need some of this functionality,
45 the safe way is to copy it into your code and rename the macros.
47 #ifndef _CXCORE_MISC_H_
48 #define _CXCORE_MISC_H_
59 /****************************************************************************************\
60 * Compile-time tuning parameters *
61 \****************************************************************************************/
63 /* maximal size of vector to run matrix operations on it inline (i.e. w/o ipp calls) */
64 #define CV_MAX_INLINE_MAT_OP_SIZE 10
66 /* maximal linear size of matrix to allocate it on stack. */
67 #define CV_MAX_LOCAL_MAT_SIZE 32
69 /* maximal size of local memory storage */
70 #define CV_MAX_LOCAL_SIZE \
71 (CV_MAX_LOCAL_MAT_SIZE*CV_MAX_LOCAL_MAT_SIZE*(int)sizeof(double))
73 /* default image row align (in bytes) */
74 #define CV_DEFAULT_IMAGE_ROW_ALIGN 4
76 /* matrices are continuous by default */
77 #define CV_DEFAULT_MAT_ROW_ALIGN 1
79 /* maximum size of dynamic memory buffer.
80 cvAlloc reports an error if a larger block is requested. */
81 #define CV_MAX_ALLOC_SIZE (((size_t)1 << (sizeof(size_t)*8-2)))
83 /* the alignment of all the allocated buffers */
84 #define CV_MALLOC_ALIGN 32
86 /* default alignment for dynamic data strucutures, resided in storages. */
87 #define CV_STRUCT_ALIGN ((int)sizeof(double))
89 /* default storage block size */
90 #define CV_STORAGE_BLOCK_SIZE ((1<<16) - 128)
92 /* default memory block for sparse array elements */
93 #define CV_SPARSE_MAT_BLOCK (1<<12)
95 /* initial hash table size */
96 #define CV_SPARSE_HASH_SIZE0 (1<<10)
98 /* maximal average node_count/hash_size ratio beyond which hash table is resized */
99 #define CV_SPARSE_HASH_RATIO 3
101 /* max length of strings */
102 #define CV_MAX_STRLEN 1024
104 /* maximum possible number of threads in parallel implementations */
106 #define CV_MAX_THREADS 128
108 #define CV_MAX_THREADS 1
111 #if 0 /*def CV_CHECK_FOR_NANS*/
112 #define CV_CHECK_NANS( arr ) cvCheckArray((arr))
114 #define CV_CHECK_NANS( arr )
117 /****************************************************************************************\
118 * Common declarations *
119 \****************************************************************************************/
121 /* get alloca declaration */
124 #define alloca __builtin_alloca
125 #elif defined WIN32 || defined WIN64
126 #if defined _MSC_VER || defined __BORLANDC__
129 #elif defined HAVE_ALLOCA_H
131 #elif defined HAVE_ALLOCA
137 /* ! DO NOT make it an inline function */
138 #define cvStackAlloc(size) cvAlignPtr( alloca((size) + CV_MALLOC_ALIGN), CV_MALLOC_ALIGN )
140 #if defined _MSC_VER || defined __BORLANDC__
141 #define CV_BIG_INT(n) n##I64
142 #define CV_BIG_UINT(n) n##UI64
144 #define CV_BIG_INT(n) n##LL
145 #define CV_BIG_UINT(n) n##ULL
148 #define CV_IMPL CV_EXTERN_C
150 #if defined WIN32 && !defined WIN64 && (_MSC_VER >= 1200 || defined CV_ICC)
151 #define CV_DBG_BREAK() __asm int 3
153 #define CV_DBG_BREAK() assert(0);
156 /* default step, set in case of continuous data
157 to work around checks for valid step in some ipp functions */
158 #define CV_STUB_STEP (1 << 30)
160 #define CV_SIZEOF_FLOAT ((int)sizeof(float))
161 #define CV_SIZEOF_SHORT ((int)sizeof(short))
163 #define CV_ORIGIN_TL 0
164 #define CV_ORIGIN_BL 1
166 /* IEEE754 constants and macros */
167 #define CV_POS_INF 0x7f800000
168 #define CV_NEG_INF 0x807fffff /* CV_TOGGLE_FLT(0xff800000) */
169 #define CV_1F 0x3f800000
170 #define CV_TOGGLE_FLT(x) ((x)^((int)(x) < 0 ? 0x7fffffff : 0))
171 #define CV_TOGGLE_DBL(x) \
172 ((x)^((int64)(x) < 0 ? CV_BIG_INT(0x7fffffffffffffff) : 0))
174 #define CV_NOP(a) (a)
175 #define CV_ADD(a, b) ((a) + (b))
176 #define CV_SUB(a, b) ((a) - (b))
177 #define CV_MUL(a, b) ((a) * (b))
178 #define CV_AND(a, b) ((a) & (b))
179 #define CV_OR(a, b) ((a) | (b))
180 #define CV_XOR(a, b) ((a) ^ (b))
181 #define CV_ANDN(a, b) (~(a) & (b))
182 #define CV_ORN(a, b) (~(a) | (b))
183 #define CV_SQR(a) ((a) * (a))
185 #define CV_LT(a, b) ((a) < (b))
186 #define CV_LE(a, b) ((a) <= (b))
187 #define CV_EQ(a, b) ((a) == (b))
188 #define CV_NE(a, b) ((a) != (b))
189 #define CV_GT(a, b) ((a) > (b))
190 #define CV_GE(a, b) ((a) >= (b))
192 #define CV_NONZERO(a) ((a) != 0)
193 #define CV_NONZERO_FLT(a) (((a)+(a)) != 0)
195 /* general-purpose saturation macros */
196 #define CV_CAST_8U(t) (uchar)(!((t) & ~255) ? (t) : (t) > 0 ? 255 : 0)
197 #define CV_CAST_8S(t) (char)(!(((t)+128) & ~255) ? (t) : (t) > 0 ? 127 : -128)
198 #define CV_CAST_16U(t) (ushort)(!((t) & ~65535) ? (t) : (t) > 0 ? 65535 : 0)
199 #define CV_CAST_16S(t) (short)(!(((t)+32768) & ~65535) ? (t) : (t) > 0 ? 32767 : -32768)
200 #define CV_CAST_32S(t) (int)(t)
201 #define CV_CAST_64S(t) (int64)(t)
202 #define CV_CAST_32F(t) (float)(t)
203 #define CV_CAST_64F(t) (double)(t)
205 #define CV_PASTE2(a,b) a##b
206 #define CV_PASTE(a,b) CV_PASTE2(a,b)
209 #define CV_MAKE_STR(a) #a
211 #define CV_DEFINE_MASK \
212 float maskTab[2]; maskTab[0] = 0.f; maskTab[1] = 1.f;
213 #define CV_ANDMASK( m, x ) ((x) & (((m) == 0) - 1))
215 /* (x) * ((m) == 1 ? 1.f : (m) == 0 ? 0.f : <ERR> */
216 #define CV_MULMASK( m, x ) (maskTab[(m) != 0]*(x))
218 /* (x) * ((m) == -1 ? 1.f : (m) == 0 ? 0.f : <ERR> */
219 #define CV_MULMASK1( m, x ) (maskTab[(m)+1]*(x))
221 #define CV_ZERO_OBJ(x) memset((x), 0, sizeof(*(x)))
223 #define CV_DIM(static_array) ((int)(sizeof(static_array)/sizeof((static_array)[0])))
225 #define CV_UN_ENTRY_C1(worktype) \
226 worktype s0 = scalar[0]
228 #define CV_UN_ENTRY_C2(worktype) \
229 worktype s0 = scalar[0], s1 = scalar[1]
231 #define CV_UN_ENTRY_C3(worktype) \
232 worktype s0 = scalar[0], s1 = scalar[1], s2 = scalar[2]
234 #define CV_UN_ENTRY_C4(worktype) \
235 worktype s0 = scalar[0], s1 = scalar[1], s2 = scalar[2], s3 = scalar[3]
237 #define cvUnsupportedFormat "Unsupported format"
239 CV_INLINE void* cvAlignPtr( const void* ptr, int align=32 )
241 assert( (align & (align-1)) == 0 );
242 return (void*)( ((size_t)ptr + align - 1) & ~(size_t)(align-1) );
245 CV_INLINE int cvAlign( int size, int align )
247 assert( (align & (align-1)) == 0 && size < INT_MAX );
248 return (size + align - 1) & -align;
251 CV_INLINE CvSize cvGetMatSize( const CvMat* mat )
253 CvSize size = { mat->width, mat->height };
257 #define CV_DESCALE(x,n) (((x) + (1 << ((n)-1))) >> (n))
258 #define CV_FLT_TO_FIX(x,n) cvRound((x)*(1<<(n)))
261 /* This is a small engine for performing fast division of multiple numbers
262 by the same constant. Most compilers do it too if they know the divisor value
263 at compile-time. The algorithm was taken from Agner Fog's optimization guide
264 at http://www.agner.org/assem */
265 typedef struct CvFastDiv
267 unsigned delta, scale, divisor;
271 #define CV_FAST_DIV_SHIFT 32
273 CV_INLINE CvFastDiv cvFastDiv( int divisor )
277 assert( divisor >= 1 );
278 uint64 temp = ((uint64)1 << CV_FAST_DIV_SHIFT)/divisor;
280 fastdiv.divisor = divisor;
281 fastdiv.delta = (unsigned)(((temp & 1) ^ 1) + divisor - 1);
282 fastdiv.scale = (unsigned)((temp + 1) >> 1);
287 #define CV_FAST_DIV( x, fastdiv ) \
288 ((int)(((int64)((x)*2 + (int)(fastdiv).delta))*(int)(fastdiv).scale>>CV_FAST_DIV_SHIFT))
290 #define CV_FAST_UDIV( x, fastdiv ) \
291 ((int)(((uint64)((x)*2 + (fastdiv).delta))*(fastdiv).scale>>CV_FAST_DIV_SHIFT))
294 #define CV_MEMCPY_CHAR( dst, src, len ) \
296 size_t _icv_memcpy_i_, _icv_memcpy_len_ = (len); \
297 char* _icv_memcpy_dst_ = (char*)(dst); \
298 const char* _icv_memcpy_src_ = (const char*)(src); \
300 for( _icv_memcpy_i_ = 0; _icv_memcpy_i_ < _icv_memcpy_len_; _icv_memcpy_i_++ ) \
301 _icv_memcpy_dst_[_icv_memcpy_i_] = _icv_memcpy_src_[_icv_memcpy_i_]; \
305 #define CV_MEMCPY_INT( dst, src, len ) \
307 size_t _icv_memcpy_i_, _icv_memcpy_len_ = (len); \
308 int* _icv_memcpy_dst_ = (int*)(dst); \
309 const int* _icv_memcpy_src_ = (const int*)(src); \
310 assert( ((size_t)_icv_memcpy_src_&(sizeof(int)-1)) == 0 && \
311 ((size_t)_icv_memcpy_dst_&(sizeof(int)-1)) == 0 ); \
313 for(_icv_memcpy_i_=0;_icv_memcpy_i_<_icv_memcpy_len_;_icv_memcpy_i_++) \
314 _icv_memcpy_dst_[_icv_memcpy_i_] = _icv_memcpy_src_[_icv_memcpy_i_]; \
318 #define CV_MEMCPY_AUTO( dst, src, len ) \
320 size_t _icv_memcpy_i_, _icv_memcpy_len_ = (len); \
321 char* _icv_memcpy_dst_ = (char*)(dst); \
322 const char* _icv_memcpy_src_ = (const char*)(src); \
323 if( (_icv_memcpy_len_ & (sizeof(int)-1)) == 0 ) \
325 assert( ((size_t)_icv_memcpy_src_&(sizeof(int)-1)) == 0 && \
326 ((size_t)_icv_memcpy_dst_&(sizeof(int)-1)) == 0 ); \
327 for( _icv_memcpy_i_ = 0; _icv_memcpy_i_ < _icv_memcpy_len_; \
328 _icv_memcpy_i_+=sizeof(int) ) \
330 *(int*)(_icv_memcpy_dst_+_icv_memcpy_i_) = \
331 *(const int*)(_icv_memcpy_src_+_icv_memcpy_i_); \
336 for(_icv_memcpy_i_ = 0; _icv_memcpy_i_ < _icv_memcpy_len_; _icv_memcpy_i_++)\
337 _icv_memcpy_dst_[_icv_memcpy_i_] = _icv_memcpy_src_[_icv_memcpy_i_]; \
342 #define CV_ZERO_CHAR( dst, len ) \
344 size_t _icv_memcpy_i_, _icv_memcpy_len_ = (len); \
345 char* _icv_memcpy_dst_ = (char*)(dst); \
347 for( _icv_memcpy_i_ = 0; _icv_memcpy_i_ < _icv_memcpy_len_; _icv_memcpy_i_++ ) \
348 _icv_memcpy_dst_[_icv_memcpy_i_] = '\0'; \
352 #define CV_ZERO_INT( dst, len ) \
354 size_t _icv_memcpy_i_, _icv_memcpy_len_ = (len); \
355 int* _icv_memcpy_dst_ = (int*)(dst); \
356 assert( ((size_t)_icv_memcpy_dst_&(sizeof(int)-1)) == 0 ); \
358 for(_icv_memcpy_i_=0;_icv_memcpy_i_<_icv_memcpy_len_;_icv_memcpy_i_++) \
359 _icv_memcpy_dst_[_icv_memcpy_i_] = 0; \
363 /****************************************************************************************\
365 Generic implementation of QuickSort algorithm.
366 ----------------------------------------------
367 Using this macro user can declare customized sort function that can be much faster
368 than built-in qsort function because of lower overhead on elements
369 comparison and exchange. The macro takes less_than (or LT) argument - a macro or function
370 that takes 2 arguments returns non-zero if the first argument should be before the second
371 one in the sorted sequence and zero otherwise.
375 Suppose that the task is to sort points by ascending of y coordinates and if
376 y's are equal x's should ascend.
379 ------------------------------------------------------------------------------
380 #define cmp_pts( pt1, pt2 ) \
381 ((pt1).y < (pt2).y || ((pt1).y < (pt2).y && (pt1).x < (pt2).x))
383 [static] CV_IMPLEMENT_QSORT( icvSortPoints, CvPoint, cmp_pts )
384 ------------------------------------------------------------------------------
386 After that the function "void icvSortPoints( CvPoint* array, size_t total, int aux );"
387 is available to user.
389 aux is an additional parameter, which can be used when comparing elements.
390 The current implementation was derived from *BSD system qsort():
392 * Copyright (c) 1992, 1993
393 * The Regents of the University of California. All rights reserved.
395 * Redistribution and use in source and binary forms, with or without
396 * modification, are permitted provided that the following conditions
398 * 1. Redistributions of source code must retain the above copyright
399 * notice, this list of conditions and the following disclaimer.
400 * 2. Redistributions in binary form must reproduce the above copyright
401 * notice, this list of conditions and the following disclaimer in the
402 * documentation and/or other materials provided with the distribution.
403 * 3. All advertising materials mentioning features or use of this software
404 * must display the following acknowledgement:
405 * This product includes software developed by the University of
406 * California, Berkeley and its contributors.
407 * 4. Neither the name of the University nor the names of its contributors
408 * may be used to endorse or promote products derived from this software
409 * without specific prior written permission.
411 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
412 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
413 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
414 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
415 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
416 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
417 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
418 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
419 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
420 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
423 \****************************************************************************************/
425 #define CV_IMPLEMENT_QSORT_EX( func_name, T, LT, user_data_type ) \
426 void func_name( T *array, size_t total, user_data_type aux ) \
428 int isort_thresh = 7; \
444 stack[0].lb = array; \
445 stack[0].ub = array + (total - 1); \
449 T* left = stack[sp].lb; \
450 T* right = stack[sp--].ub; \
454 int i, n = (int)(right - left) + 1, m; \
458 if( n <= isort_thresh ) \
461 for( ptr = left + 1; ptr <= right; ptr++ ) \
463 for( ptr2 = ptr; ptr2 > left && LT(ptr2[0],ptr2[-1]); ptr2--) \
464 CV_SWAP( ptr2[0], ptr2[-1], t ); \
482 pivot = left + (n/2); \
487 a = left, b = left + d, c = left + 2*d; \
488 left = LT(*a, *b) ? (LT(*b, *c) ? b : (LT(*a, *c) ? c : a)) \
489 : (LT(*c, *b) ? b : (LT(*a, *c) ? a : c)); \
491 a = pivot - d, b = pivot, c = pivot + d; \
492 pivot = LT(*a, *b) ? (LT(*b, *c) ? b : (LT(*a, *c) ? c : a)) \
493 : (LT(*c, *b) ? b : (LT(*a, *c) ? a : c)); \
495 a = right - 2*d, b = right - d, c = right; \
496 right = LT(*a, *b) ? (LT(*b, *c) ? b : (LT(*a, *c) ? c : a)) \
497 : (LT(*c, *b) ? b : (LT(*a, *c) ? a : c)); \
500 a = left, b = pivot, c = right; \
501 pivot = LT(*a, *b) ? (LT(*b, *c) ? b : (LT(*a, *c) ? c : a)) \
502 : (LT(*c, *b) ? b : (LT(*a, *c) ? a : c)); \
503 if( pivot != left0 ) \
505 CV_SWAP( *pivot, *left0, t ); \
508 left = left1 = left0 + 1; \
509 right = right1 = right0; \
513 while( left <= right && !LT(*pivot, *left) ) \
515 if( !LT(*left, *pivot) ) \
518 CV_SWAP( *left1, *left, t ); \
525 while( left <= right && !LT(*right, *pivot) ) \
527 if( !LT(*pivot, *right) ) \
529 if( right < right1 ) \
530 CV_SWAP( *right1, *right, t ); \
539 CV_SWAP( *left, *right, t ); \
545 if( swap_cnt == 0 ) \
547 left = left0, right = right0; \
551 n = MIN( (int)(left1 - left0), (int)(left - left1) ); \
552 for( i = 0; i < n; i++ ) \
553 CV_SWAP( left0[i], left[i-n], t ); \
555 n = MIN( (int)(right0 - right1), (int)(right1 - right) ); \
556 for( i = 0; i < n; i++ ) \
557 CV_SWAP( left[i], right0[i-n+1], t ); \
558 n = (int)(left - left1); \
559 m = (int)(right1 - right); \
566 stack[++sp].lb = left0; \
567 stack[sp].ub = left0 + n - 1; \
568 left = right0 - m + 1, right = right0; \
572 stack[++sp].lb = right0 - m + 1; \
573 stack[sp].ub = right0; \
574 left = left0, right = left0 + n - 1; \
578 left = left0, right = left0 + n - 1; \
581 left = right0 - m + 1, right = right0; \
589 #define CV_IMPLEMENT_QSORT( func_name, T, cmp ) \
590 CV_IMPLEMENT_QSORT_EX( func_name, T, cmp, int )
592 /****************************************************************************************\
593 * Structures and macros for integration with IPP *
594 \****************************************************************************************/
596 /* IPP-compatible return codes */
597 typedef enum CvStatus
599 CV_BADMEMBLOCK_ERR = -113,
600 CV_INPLACE_NOT_SUPPORTED_ERR= -112,
601 CV_UNMATCHED_ROI_ERR = -111,
602 CV_NOTFOUND_ERR = -110,
603 CV_BADCONVERGENCE_ERR = -109,
605 CV_BADDEPTH_ERR = -107,
606 CV_BADROI_ERR = -106,
607 CV_BADHEADER_ERR = -105,
608 CV_UNMATCHED_FORMATS_ERR = -104,
609 CV_UNSUPPORTED_COI_ERR = -103,
610 CV_UNSUPPORTED_CHANNELS_ERR = -102,
611 CV_UNSUPPORTED_DEPTH_ERR = -101,
612 CV_UNSUPPORTED_FORMAT_ERR = -100,
614 CV_BADARG_ERR = -49, //ipp comp
615 CV_NOTDEFINED_ERR = -48, //ipp comp
617 CV_BADCHANNELS_ERR = -47, //ipp comp
618 CV_BADRANGE_ERR = -44, //ipp comp
619 CV_BADSTEP_ERR = -29, //ipp comp
621 CV_BADFLAG_ERR = -12,
622 CV_DIV_BY_ZERO_ERR = -11, //ipp comp
623 CV_BADCOEF_ERR = -10,
625 CV_BADFACTOR_ERR = -7,
626 CV_BADPOINT_ERR = -6,
627 CV_BADSCALE_ERR = -4,
628 CV_OUTOFMEM_ERR = -3,
636 #define CV_ERROR_FROM_STATUS( result ) \
637 CV_ERROR( cvErrorFromIppStatus( result ), "OpenCV function failed" )
639 #define IPPI_CALL( Func ) \
641 CvStatus ippi_call_result; \
642 ippi_call_result = Func; \
644 if( ippi_call_result < 0 ) \
645 CV_ERROR_FROM_STATUS( (ippi_call_result)); \
648 #define CV_PLUGIN_NONE 0
649 #define CV_PLUGIN_OPTCV 1 /* custom "emerged" ippopencv library */
650 #define CV_PLUGIN_IPPCV 2 /* IPP: computer vision */
651 #define CV_PLUGIN_IPPI 3 /* IPP: image processing */
652 #define CV_PLUGIN_IPPS 4 /* IPP: signal processing */
653 #define CV_PLUGIN_IPPVM 5 /* IPP: vector math functions */
654 #define CV_PLUGIN_IPPCC 6 /* IPP: color space conversion */
655 #define CV_PLUGIN_MKL 8 /* Intel Math Kernel Library */
657 #define CV_PLUGIN_MAX 16
659 #define CV_PLUGINS1(lib1) ((lib1)&15)
660 #define CV_PLUGINS2(lib1,lib2) (((lib1)&15)|(((lib2)&15)<<4))
661 #define CV_PLUGINS3(lib1,lib2,lib3) (((lib1)&15)|(((lib2)&15)<<4)|(((lib2)&15)<<8))
663 #define CV_NOTHROW throw()
666 #define IPCVAPI(type,declspec,name,args) \
667 /* function pointer */ \
668 typedef type (declspec* name##_t) args; \
669 extern name##_t name##_p; \
670 type declspec name args;
673 #define IPCVAPI_EX(type,name,ipp_name,ipp_search_modules,args) \
674 IPCVAPI(type,CV_STDCALL,name,args)
676 #define IPCVAPI_C_EX(type,name,ipp_name,ipp_search_modules,args)\
677 IPCVAPI(type,CV_CDECL,name,args)
680 #define IPCVAPI_IMPL(type,name,args,arg_names) \
681 static type CV_STDCALL name##_f args; \
682 name##_t name##_p = name##_f; \
683 type CV_STDCALL name args { return name##_p arg_names; } \
684 static type CV_STDCALL name##_f args
687 /* IPP types' enumeration */
688 typedef enum CvDataType {
691 cv16u, cv16s, cv16sc,
692 cv32u, cv32s, cv32sc,
694 cv64u, cv64s, cv64sc,
698 typedef enum CvHintAlgorithm {
704 typedef enum CvCmpOp {
712 typedef struct CvFuncTable
714 void* fn_2d[CV_DEPTH_MAX];
718 typedef struct CvBigFuncTable
720 void* fn_2d[CV_DEPTH_MAX*CV_CN_MAX];
725 typedef struct CvBtFuncTable
731 typedef CvStatus (CV_STDCALL *CvFunc2D_1A)(void* arr, int step, CvSize size);
733 typedef CvStatus (CV_STDCALL *CvFunc2D_1A1P)(void* arr, int step, CvSize size, void* param);
735 typedef CvStatus (CV_STDCALL *CvFunc2D_1A1P1I)(void* arr, int step, CvSize size,
736 void* param, int flag);
738 typedef CvStatus (CV_STDCALL *CvFunc2DnC_1A1P)( void* arr, int step, CvSize size,
739 int cn, int coi, void* param );
741 typedef CvStatus (CV_STDCALL *CvFunc2DnC_1A1P)( void* arr, int step, CvSize size,
742 int cn, int coi, void* param );
744 typedef CvStatus (CV_STDCALL *CvFunc2D_1A2P)( void* arr, int step, CvSize size,
745 void* param1, void* param2 );
747 typedef CvStatus (CV_STDCALL *CvFunc2DnC_1A2P)( void* arr, int step,
748 CvSize size, int cn, int coi,
749 void* param1, void* param2 );
751 typedef CvStatus (CV_STDCALL *CvFunc2D_1A4P)( void* arr, int step, CvSize size,
752 void* param1, void* param2,
753 void* param3, void* param4 );
755 typedef CvStatus (CV_STDCALL *CvFunc2DnC_1A4P)( void* arr, int step,
756 CvSize size, int cn, int coi,
757 void* param1, void* param2,
758 void* param3, void* param4 );
760 typedef CvStatus (CV_STDCALL *CvFunc2D_2A)( void* arr0, int step0,
761 void* arr1, int step1, CvSize size );
763 typedef CvStatus (CV_STDCALL *CvFunc2D_2A1P)( void* arr0, int step0,
764 void* arr1, int step1,
765 CvSize size, void* param );
767 typedef CvStatus (CV_STDCALL *CvFunc2DnC_2A1P)( void* arr0, int step0,
768 void* arr1, int step1,
770 int coi, void* param );
772 typedef CvStatus (CV_STDCALL *CvFunc2DnC_2A1P)( void* arr0, int step0,
773 void* arr1, int step1,
775 int coi, void* param );
777 typedef CvStatus (CV_STDCALL *CvFunc2D_2A2P)( void* arr0, int step0,
778 void* arr1, int step1, CvSize size,
779 void* param1, void* param2 );
781 typedef CvStatus (CV_STDCALL *CvFunc2DnC_2A2P)( void* arr0, int step0,
782 void* arr1, int step1,
783 CvSize size, int cn, int coi,
784 void* param1, void* param2 );
786 typedef CvStatus (CV_STDCALL *CvFunc2D_2A1P1I)( void* arr0, int step0,
787 void* arr1, int step1, CvSize size,
788 void* param, int flag );
790 typedef CvStatus (CV_STDCALL *CvFunc2D_2A4P)( void* arr0, int step0,
791 void* arr1, int step1, CvSize size,
792 void* param1, void* param2,
793 void* param3, void* param4 );
795 typedef CvStatus (CV_STDCALL *CvFunc2DnC_2A4P)( void* arr0, int step0,
796 void* arr1, int step1, CvSize size,
798 void* param1, void* param2,
799 void* param3, void* param4 );
801 typedef CvStatus (CV_STDCALL *CvFunc2D_3A)( void* arr0, int step0,
802 void* arr1, int step1,
803 void* arr2, int step2, CvSize size );
805 typedef CvStatus (CV_STDCALL *CvFunc2D_3A1P)( void* arr0, int step0,
806 void* arr1, int step1,
807 void* arr2, int step2,
808 CvSize size, void* param );
810 typedef CvStatus (CV_STDCALL *CvFunc2D_3A1I)( void* arr0, int step0,
811 void* arr1, int step1,
812 void* arr2, int step2,
813 CvSize size, int flag );
815 typedef CvStatus (CV_STDCALL *CvFunc2DnC_3A1P)( void* arr0, int step0,
816 void* arr1, int step1,
817 void* arr2, int step2,
819 int coi, void* param );
821 typedef CvStatus (CV_STDCALL *CvFunc2D_4A)( void* arr0, int step0,
822 void* arr1, int step1,
823 void* arr2, int step2,
824 void* arr3, int step3,
827 typedef CvStatus (CV_STDCALL *CvFunc0D)( const void* src, void* dst, int param );
829 #define CV_DEF_INIT_FUNC_TAB_2D( FUNCNAME, FLAG ) \
830 static void icvInit##FUNCNAME##FLAG##Table( CvFuncTable* tab ) \
834 tab->fn_2d[CV_8U] = (void*)icv##FUNCNAME##_8u_##FLAG; \
835 tab->fn_2d[CV_8S] = (void*)icv##FUNCNAME##_8s_##FLAG; \
836 tab->fn_2d[CV_16U] = (void*)icv##FUNCNAME##_16u_##FLAG; \
837 tab->fn_2d[CV_16S] = (void*)icv##FUNCNAME##_16s_##FLAG; \
838 tab->fn_2d[CV_32S] = (void*)icv##FUNCNAME##_32s_##FLAG; \
839 tab->fn_2d[CV_32F] = (void*)icv##FUNCNAME##_32f_##FLAG; \
840 tab->fn_2d[CV_64F] = (void*)icv##FUNCNAME##_64f_##FLAG; \
844 #define CV_DEF_INIT_BIG_FUNC_TAB_2D( FUNCNAME, FLAG ) \
845 static void icvInit##FUNCNAME##FLAG##Table( CvBigFuncTable* tab ) \
849 tab->fn_2d[CV_8UC1] = (void*)icv##FUNCNAME##_8u_C1##FLAG; \
850 tab->fn_2d[CV_8UC2] = (void*)icv##FUNCNAME##_8u_C2##FLAG; \
851 tab->fn_2d[CV_8UC3] = (void*)icv##FUNCNAME##_8u_C3##FLAG; \
852 tab->fn_2d[CV_8UC4] = (void*)icv##FUNCNAME##_8u_C4##FLAG; \
854 tab->fn_2d[CV_8SC1] = (void*)icv##FUNCNAME##_8s_C1##FLAG; \
855 tab->fn_2d[CV_8SC2] = (void*)icv##FUNCNAME##_8s_C2##FLAG; \
856 tab->fn_2d[CV_8SC3] = (void*)icv##FUNCNAME##_8s_C3##FLAG; \
857 tab->fn_2d[CV_8SC4] = (void*)icv##FUNCNAME##_8s_C4##FLAG; \
859 tab->fn_2d[CV_16UC1] = (void*)icv##FUNCNAME##_16u_C1##FLAG; \
860 tab->fn_2d[CV_16UC2] = (void*)icv##FUNCNAME##_16u_C2##FLAG; \
861 tab->fn_2d[CV_16UC3] = (void*)icv##FUNCNAME##_16u_C3##FLAG; \
862 tab->fn_2d[CV_16UC4] = (void*)icv##FUNCNAME##_16u_C4##FLAG; \
864 tab->fn_2d[CV_16SC1] = (void*)icv##FUNCNAME##_16s_C1##FLAG; \
865 tab->fn_2d[CV_16SC2] = (void*)icv##FUNCNAME##_16s_C2##FLAG; \
866 tab->fn_2d[CV_16SC3] = (void*)icv##FUNCNAME##_16s_C3##FLAG; \
867 tab->fn_2d[CV_16SC4] = (void*)icv##FUNCNAME##_16s_C4##FLAG; \
869 tab->fn_2d[CV_32SC1] = (void*)icv##FUNCNAME##_32s_C1##FLAG; \
870 tab->fn_2d[CV_32SC2] = (void*)icv##FUNCNAME##_32s_C2##FLAG; \
871 tab->fn_2d[CV_32SC3] = (void*)icv##FUNCNAME##_32s_C3##FLAG; \
872 tab->fn_2d[CV_32SC4] = (void*)icv##FUNCNAME##_32s_C4##FLAG; \
874 tab->fn_2d[CV_32FC1] = (void*)icv##FUNCNAME##_32f_C1##FLAG; \
875 tab->fn_2d[CV_32FC2] = (void*)icv##FUNCNAME##_32f_C2##FLAG; \
876 tab->fn_2d[CV_32FC3] = (void*)icv##FUNCNAME##_32f_C3##FLAG; \
877 tab->fn_2d[CV_32FC4] = (void*)icv##FUNCNAME##_32f_C4##FLAG; \
879 tab->fn_2d[CV_64FC1] = (void*)icv##FUNCNAME##_64f_C1##FLAG; \
880 tab->fn_2d[CV_64FC2] = (void*)icv##FUNCNAME##_64f_C2##FLAG; \
881 tab->fn_2d[CV_64FC3] = (void*)icv##FUNCNAME##_64f_C3##FLAG; \
882 tab->fn_2d[CV_64FC4] = (void*)icv##FUNCNAME##_64f_C4##FLAG; \
885 #define CV_DEF_INIT_FUNC_TAB_0D( FUNCNAME ) \
886 static void icvInit##FUNCNAME##Table( CvFuncTable* tab ) \
888 tab->fn_2d[CV_8U] = (void*)icv##FUNCNAME##_8u; \
889 tab->fn_2d[CV_8S] = (void*)icv##FUNCNAME##_8s; \
890 tab->fn_2d[CV_16U] = (void*)icv##FUNCNAME##_16u; \
891 tab->fn_2d[CV_16S] = (void*)icv##FUNCNAME##_16s; \
892 tab->fn_2d[CV_32S] = (void*)icv##FUNCNAME##_32s; \
893 tab->fn_2d[CV_32F] = (void*)icv##FUNCNAME##_32f; \
894 tab->fn_2d[CV_64F] = (void*)icv##FUNCNAME##_64f; \
897 #define CV_DEF_INIT_FUNC_TAB_1D CV_DEF_INIT_FUNC_TAB_0D
900 #define CV_DEF_INIT_PIXSIZE_TAB_2D( FUNCNAME, FLAG ) \
901 static void icvInit##FUNCNAME##FLAG##Table( CvBtFuncTable* table ) \
903 table->fn_2d[1] = (void*)icv##FUNCNAME##_8u_C1##FLAG; \
904 table->fn_2d[2] = (void*)icv##FUNCNAME##_8u_C2##FLAG; \
905 table->fn_2d[3] = (void*)icv##FUNCNAME##_8u_C3##FLAG; \
906 table->fn_2d[4] = (void*)icv##FUNCNAME##_16u_C2##FLAG; \
907 table->fn_2d[6] = (void*)icv##FUNCNAME##_16u_C3##FLAG; \
908 table->fn_2d[8] = (void*)icv##FUNCNAME##_32s_C2##FLAG; \
909 table->fn_2d[12] = (void*)icv##FUNCNAME##_32s_C3##FLAG; \
910 table->fn_2d[16] = (void*)icv##FUNCNAME##_64s_C2##FLAG; \
911 table->fn_2d[24] = (void*)icv##FUNCNAME##_64s_C3##FLAG; \
912 table->fn_2d[32] = (void*)icv##FUNCNAME##_64s_C4##FLAG; \
915 #define CV_GET_FUNC_PTR( func, table_entry ) \
916 func = (table_entry); \
919 CV_ERROR( CV_StsUnsupportedFormat, "" )
922 #endif /*_CXCORE_MISC_H_*/