00001 /*M/////////////////////////////////////////////////////////////////////////////////////// 00002 // 00003 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 00004 // 00005 // By downloading, copying, installing or using the software you agree to this license. 00006 // If you do not agree to this license, do not download, install, 00007 // copy or use the software. 00008 // 00009 // 00010 // License Agreement 00011 // For Open Source Computer Vision Library 00012 // 00013 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. 00014 // Copyright (C) 2009, Willow Garage Inc., all rights reserved. 00015 // Third party copyrights are property of their respective owners. 00016 // 00017 // Redistribution and use in source and binary forms, with or without modification, 00018 // are permitted provided that the following conditions are met: 00019 // 00020 // * Redistribution's of source code must retain the above copyright notice, 00021 // this list of conditions and the following disclaimer. 00022 // 00023 // * Redistribution's in binary form must reproduce the above copyright notice, 00024 // this list of conditions and the following disclaimer in the documentation 00025 // and/or other materials provided with the distribution. 00026 // 00027 // * The name of the copyright holders may not be used to endorse or promote products 00028 // derived from this software without specific prior written permission. 00029 // 00030 // This software is provided by the copyright holders and contributors "as is" and 00031 // any express or implied warranties, including, but not limited to, the implied 00032 // warranties of merchantability and fitness for a particular purpose are disclaimed. 00033 // In no event shall the Intel Corporation or contributors be liable for any direct, 00034 // indirect, incidental, special, exemplary, or consequential damages 00035 // (including, but not limited to, procurement of substitute goods or services; 00036 // loss of use, data, or profits; or business interruption) however caused 00037 // and on any theory of liability, whether in contract, strict liability, 00038 // or tort (including negligence or otherwise) arising in any way out of 00039 // the use of this software, even if advised of the possibility of such damage. 00040 // 00041 //M*/ 00042 00043 /* The header is for internal use and it is likely to change. 00044 It contains some macro definitions that are used in cxcore, cv, cvaux 00045 and, probably, other libraries. If you need some of this functionality, 00046 the safe way is to copy it into your code and rename the macros. 00047 */ 00048 #ifndef __OPENCV_CORE_INTERNAL_HPP__ 00049 #define __OPENCV_CORE_INTERNAL_HPP__ 00050 00051 #include <vector> 00052 00053 #if defined WIN32 || defined _WIN32 00054 # ifndef WIN32 00055 # define WIN32 00056 # endif 00057 # ifndef _WIN32 00058 # define _WIN32 00059 # endif 00060 #endif 00061 00062 #if defined WIN32 || defined WINCE 00063 #ifndef _WIN32_WINNT // This is needed for the declaration of TryEnterCriticalSection in winbase.h with Visual Studio 2005 (and older?) 00064 #define _WIN32_WINNT 0x0400 // http://msdn.microsoft.com/en-us/library/ms686857(VS.85).aspx 00065 #endif 00066 #include <windows.h> 00067 #undef small 00068 #undef min 00069 #undef max 00070 #else 00071 #include <pthread.h> 00072 #include <sys/mman.h> 00073 #endif 00074 00075 #ifdef __BORLANDC__ 00076 #ifndef WIN32 00077 #define WIN32 00078 #endif 00079 #ifndef _WIN32 00080 #define _WIN32 00081 #endif 00082 #define CV_DLL 00083 #undef _CV_ALWAYS_PROFILE_ 00084 #define _CV_ALWAYS_NO_PROFILE_ 00085 #endif 00086 00087 #ifndef FALSE 00088 #define FALSE 0 00089 #endif 00090 #ifndef TRUE 00091 #define TRUE 1 00092 #endif 00093 00094 #define __BEGIN__ __CV_BEGIN__ 00095 #define __END__ __CV_END__ 00096 #define EXIT __CV_EXIT__ 00097 00098 #ifdef HAVE_IPP 00099 #include "ipp.h" 00100 00101 CV_INLINE IppiSize ippiSize(int width, int height) 00102 { 00103 IppiSize size = { width, height }; 00104 return size; 00105 } 00106 #endif 00107 00108 #if defined __SSE2__ || _MSC_VER >= 1300 00109 #include "emmintrin.h" 00110 #define CV_SSE 1 00111 #define CV_SSE2 1 00112 #if defined __SSE3__ || _MSC_VER >= 1500 00113 #include "pmmintrin.h" 00114 #define CV_SSE3 1 00115 #endif 00116 #else 00117 #define CV_SSE 0 00118 #define CV_SSE2 0 00119 #define CV_SSE3 0 00120 #endif 00121 00122 #if defined ANDROID && defined __ARM_NEON__ 00123 #include "arm_neon.h" 00124 #define CV_NEON 1 00125 00126 #define CPU_HAS_NEON_FEATURE (true) 00127 //TODO: make real check using stuff from "cpu-features.h" 00128 //((bool)android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON) 00129 #else 00130 #define CV_NEON 0 00131 #define CPU_HAS_NEON_FEATURE (false) 00132 #endif 00133 00134 #ifndef IPPI_CALL 00135 #define IPPI_CALL(func) CV_Assert((func) >= 0) 00136 #endif 00137 00138 #ifdef HAVE_TBB 00139 #include "tbb/tbb_stddef.h" 00140 #if TBB_VERSION_MAJOR*100 + TBB_VERSION_MINOR >= 202 00141 #include "tbb/tbb.h" 00142 #include "tbb/task.h" 00143 #undef min 00144 #undef max 00145 #else 00146 #undef HAVE_TBB 00147 #endif 00148 #endif 00149 00150 #ifdef HAVE_EIGEN 00151 #include <Eigen/Core> 00152 #include "opencv2/core/eigen.hpp" 00153 #endif 00154 00155 #ifdef __cplusplus 00156 00157 #ifdef HAVE_TBB 00158 namespace cv 00159 { 00160 typedef tbb::blocked_range<int> BlockedRange; 00161 00162 template<typename Body> static inline 00163 void parallel_for( const BlockedRange& range, const Body& body ) 00164 { 00165 tbb::parallel_for(range, body); 00166 } 00167 00168 template<typename Iterator, typename Body> static inline 00169 void parallel_do( Iterator first, Iterator last, const Body& body ) 00170 { 00171 tbb::parallel_do(first, last, body); 00172 } 00173 00174 typedef tbb::split Split; 00175 00176 template<typename Body> static inline 00177 void parallel_reduce( const BlockedRange& range, Body& body ) 00178 { 00179 tbb::parallel_reduce(range, body); 00180 } 00181 00182 typedef tbb::concurrent_vector<Rect> ConcurrentRectVector; 00183 } 00184 #else 00185 namespace cv 00186 { 00187 class BlockedRange 00188 { 00189 public: 00190 BlockedRange() : _begin(0), _end(0), _grainsize(0) {} 00191 BlockedRange(int b, int e, int g=1) : _begin(b), _end(e), _grainsize(g) {} 00192 int begin() const { return _begin; } 00193 int end() const { return _end; } 00194 int grainsize() const { return _grainsize; } 00195 00196 protected: 00197 int _begin, _end, _grainsize; 00198 }; 00199 00200 00201 #ifdef HAVE_THREADING_FRAMEWORK 00202 #include "threading_framework.hpp" 00203 00204 template<typename Body> 00205 static void parallel_for( const BlockedRange& range, const Body& body ) 00206 { 00207 tf::parallel_for<Body>(range, body); 00208 } 00209 typedef tf::ConcurrentVector<Rect> ConcurrentRectVector; 00210 #else 00211 template<typename Body> static inline 00212 void parallel_for( const BlockedRange& range, const Body& body ) 00213 { 00214 body(range); 00215 } 00216 typedef std::vector<Rect> ConcurrentRectVector; 00217 #endif 00218 00219 template<typename Iterator, typename Body> static inline 00220 void parallel_do( Iterator first, Iterator last, const Body& body ) 00221 { 00222 for( ; first != last; ++first ) 00223 body(*first); 00224 } 00225 00226 class Split {}; 00227 00228 template<typename Body> static inline 00229 void parallel_reduce( const BlockedRange& range, Body& body ) 00230 { 00231 body(range); 00232 } 00233 00234 } 00235 #endif 00236 #endif 00237 00238 /* maximal size of vector to run matrix operations on it inline (i.e. w/o ipp calls) */ 00239 #define CV_MAX_INLINE_MAT_OP_SIZE 10 00240 00241 /* maximal linear size of matrix to allocate it on stack. */ 00242 #define CV_MAX_LOCAL_MAT_SIZE 32 00243 00244 /* maximal size of local memory storage */ 00245 #define CV_MAX_LOCAL_SIZE \ 00246 (CV_MAX_LOCAL_MAT_SIZE*CV_MAX_LOCAL_MAT_SIZE*(int)sizeof(double)) 00247 00248 /* default image row align (in bytes) */ 00249 #define CV_DEFAULT_IMAGE_ROW_ALIGN 4 00250 00251 /* matrices are continuous by default */ 00252 #define CV_DEFAULT_MAT_ROW_ALIGN 1 00253 00254 /* maximum size of dynamic memory buffer. 00255 cvAlloc reports an error if a larger block is requested. */ 00256 #define CV_MAX_ALLOC_SIZE (((size_t)1 << (sizeof(size_t)*8-2))) 00257 00258 /* the alignment of all the allocated buffers */ 00259 #define CV_MALLOC_ALIGN 16 00260 00261 /* default alignment for dynamic data strucutures, resided in storages. */ 00262 #define CV_STRUCT_ALIGN ((int)sizeof(double)) 00263 00264 /* default storage block size */ 00265 #define CV_STORAGE_BLOCK_SIZE ((1<<16) - 128) 00266 00267 /* default memory block for sparse array elements */ 00268 #define CV_SPARSE_MAT_BLOCK (1<<12) 00269 00270 /* initial hash table size */ 00271 #define CV_SPARSE_HASH_SIZE0 (1<<10) 00272 00273 /* maximal average node_count/hash_size ratio beyond which hash table is resized */ 00274 #define CV_SPARSE_HASH_RATIO 3 00275 00276 /* max length of strings */ 00277 #define CV_MAX_STRLEN 1024 00278 00279 #if 0 /*def CV_CHECK_FOR_NANS*/ 00280 #define CV_CHECK_NANS( arr ) cvCheckArray((arr)) 00281 #else 00282 #define CV_CHECK_NANS( arr ) 00283 #endif 00284 00285 /****************************************************************************************\ 00286 * Common declarations * 00287 \****************************************************************************************/ 00288 00289 /* get alloca declaration */ 00290 #ifdef __GNUC__ 00291 #undef alloca 00292 #define alloca __builtin_alloca 00293 #define CV_HAVE_ALLOCA 1 00294 #elif defined WIN32 || defined _WIN32 || \ 00295 defined WINCE || defined _MSC_VER || defined __BORLANDC__ 00296 #include <malloc.h> 00297 #define CV_HAVE_ALLOCA 1 00298 #elif defined HAVE_ALLOCA_H 00299 #include <alloca.h> 00300 #define CV_HAVE_ALLOCA 1 00301 #elif defined HAVE_ALLOCA 00302 #include <stdlib.h> 00303 #define CV_HAVE_ALLOCA 1 00304 #else 00305 #undef CV_HAVE_ALLOCA 00306 #endif 00307 00308 #ifdef __GNUC__ 00309 #define CV_DECL_ALIGNED(x) __attribute__ ((aligned (x))) 00310 #elif defined _MSC_VER 00311 #define CV_DECL_ALIGNED(x) __declspec(align(x)) 00312 #else 00313 #define CV_DECL_ALIGNED(x) 00314 #endif 00315 00316 #if CV_HAVE_ALLOCA 00317 /* ! DO NOT make it an inline function */ 00318 #define cvStackAlloc(size) cvAlignPtr( alloca((size) + CV_MALLOC_ALIGN), CV_MALLOC_ALIGN ) 00319 #endif 00320 00321 #ifndef CV_IMPL 00322 #define CV_IMPL CV_EXTERN_C 00323 #endif 00324 00325 #define CV_DBG_BREAK() { volatile int* crashMe = 0; *crashMe = 0; } 00326 00327 /* default step, set in case of continuous data 00328 to work around checks for valid step in some ipp functions */ 00329 #define CV_STUB_STEP (1 << 30) 00330 00331 #define CV_SIZEOF_FLOAT ((int)sizeof(float)) 00332 #define CV_SIZEOF_SHORT ((int)sizeof(short)) 00333 00334 #define CV_ORIGIN_TL 0 00335 #define CV_ORIGIN_BL 1 00336 00337 /* IEEE754 constants and macros */ 00338 #define CV_POS_INF 0x7f800000 00339 #define CV_NEG_INF 0x807fffff /* CV_TOGGLE_FLT(0xff800000) */ 00340 #define CV_1F 0x3f800000 00341 #define CV_TOGGLE_FLT(x) ((x)^((int)(x) < 0 ? 0x7fffffff : 0)) 00342 #define CV_TOGGLE_DBL(x) \ 00343 ((x)^((int64)(x) < 0 ? CV_BIG_INT(0x7fffffffffffffff) : 0)) 00344 00345 #define CV_NOP(a) (a) 00346 #define CV_ADD(a, b) ((a) + (b)) 00347 #define CV_SUB(a, b) ((a) - (b)) 00348 #define CV_MUL(a, b) ((a) * (b)) 00349 #define CV_AND(a, b) ((a) & (b)) 00350 #define CV_OR(a, b) ((a) | (b)) 00351 #define CV_XOR(a, b) ((a) ^ (b)) 00352 #define CV_ANDN(a, b) (~(a) & (b)) 00353 #define CV_ORN(a, b) (~(a) | (b)) 00354 #define CV_SQR(a) ((a) * (a)) 00355 00356 #define CV_LT(a, b) ((a) < (b)) 00357 #define CV_LE(a, b) ((a) <= (b)) 00358 #define CV_EQ(a, b) ((a) == (b)) 00359 #define CV_NE(a, b) ((a) != (b)) 00360 #define CV_GT(a, b) ((a) > (b)) 00361 #define CV_GE(a, b) ((a) >= (b)) 00362 00363 #define CV_NONZERO(a) ((a) != 0) 00364 #define CV_NONZERO_FLT(a) (((a)+(a)) != 0) 00365 00366 /* general-purpose saturation macros */ 00367 #define CV_CAST_8U(t) (uchar)(!((t) & ~255) ? (t) : (t) > 0 ? 255 : 0) 00368 #define CV_CAST_8S(t) (schar)(!(((t)+128) & ~255) ? (t) : (t) > 0 ? 127 : -128) 00369 #define CV_CAST_16U(t) (ushort)(!((t) & ~65535) ? (t) : (t) > 0 ? 65535 : 0) 00370 #define CV_CAST_16S(t) (short)(!(((t)+32768) & ~65535) ? (t) : (t) > 0 ? 32767 : -32768) 00371 #define CV_CAST_32S(t) (int)(t) 00372 #define CV_CAST_64S(t) (int64)(t) 00373 #define CV_CAST_32F(t) (float)(t) 00374 #define CV_CAST_64F(t) (double)(t) 00375 00376 #define CV_PASTE2(a,b) a##b 00377 #define CV_PASTE(a,b) CV_PASTE2(a,b) 00378 00379 #define CV_EMPTY 00380 #define CV_MAKE_STR(a) #a 00381 00382 #define CV_ZERO_OBJ(x) memset((x), 0, sizeof(*(x))) 00383 00384 #define CV_DIM(static_array) ((int)(sizeof(static_array)/sizeof((static_array)[0]))) 00385 00386 #define cvUnsupportedFormat "Unsupported format" 00387 00388 CV_INLINE void* cvAlignPtr( const void* ptr, int align CV_DEFAULT(32) ) 00389 { 00390 assert( (align & (align-1)) == 0 ); 00391 return (void*)( ((size_t)ptr + align - 1) & ~(size_t)(align-1) ); 00392 } 00393 00394 CV_INLINE int cvAlign( int size, int align ) 00395 { 00396 assert( (align & (align-1)) == 0 && size < INT_MAX ); 00397 return (size + align - 1) & -align; 00398 } 00399 00400 CV_INLINE CvSize cvGetMatSize( const CvMat* mat ) 00401 { 00402 CvSize size; 00403 size.width = mat->cols; 00404 size.height = mat->rows; 00405 return size; 00406 } 00407 00408 #define CV_DESCALE(x,n) (((x) + (1 << ((n)-1))) >> (n)) 00409 #define CV_FLT_TO_FIX(x,n) cvRound((x)*(1<<(n))) 00410 00411 /****************************************************************************************\ 00412 00413 Generic implementation of QuickSort algorithm. 00414 ---------------------------------------------- 00415 Using this macro user can declare customized sort function that can be much faster 00416 than built-in qsort function because of lower overhead on elements 00417 comparison and exchange. The macro takes less_than (or LT) argument - a macro or function 00418 that takes 2 arguments returns non-zero if the first argument should be before the second 00419 one in the sorted sequence and zero otherwise. 00420 00421 Example: 00422 00423 Suppose that the task is to sort points by ascending of y coordinates and if 00424 y's are equal x's should ascend. 00425 00426 The code is: 00427 ------------------------------------------------------------------------------ 00428 #define cmp_pts( pt1, pt2 ) \ 00429 ((pt1).y < (pt2).y || ((pt1).y < (pt2).y && (pt1).x < (pt2).x)) 00430 00431 [static] CV_IMPLEMENT_QSORT( icvSortPoints, CvPoint, cmp_pts ) 00432 ------------------------------------------------------------------------------ 00433 00434 After that the function "void icvSortPoints( CvPoint* array, size_t total, int aux );" 00435 is available to user. 00436 00437 aux is an additional parameter, which can be used when comparing elements. 00438 The current implementation was derived from *BSD system qsort(): 00439 00440 * Copyright (c) 1992, 1993 00441 * The Regents of the University of California. All rights reserved. 00442 * 00443 * Redistribution and use in source and binary forms, with or without 00444 * modification, are permitted provided that the following conditions 00445 * are met: 00446 * 1. Redistributions of source code must retain the above copyright 00447 * notice, this list of conditions and the following disclaimer. 00448 * 2. Redistributions in binary form must reproduce the above copyright 00449 * notice, this list of conditions and the following disclaimer in the 00450 * documentation and/or other materials provided with the distribution. 00451 * 3. All advertising materials mentioning features or use of this software 00452 * must display the following acknowledgement: 00453 * This product includes software developed by the University of 00454 * California, Berkeley and its contributors. 00455 * 4. Neither the name of the University nor the names of its contributors 00456 * may be used to endorse or promote products derived from this software 00457 * without specific prior written permission. 00458 * 00459 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 00460 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00461 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00462 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 00463 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00464 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00465 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00466 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00467 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00468 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00469 * SUCH DAMAGE. 00470 00471 \****************************************************************************************/ 00472 00473 #define CV_IMPLEMENT_QSORT_EX( func_name, T, LT, user_data_type ) \ 00474 void func_name( T *array, size_t total, user_data_type aux ) \ 00475 { \ 00476 int isort_thresh = 7; \ 00477 T t; \ 00478 int sp = 0; \ 00479 \ 00480 struct \ 00481 { \ 00482 T *lb; \ 00483 T *ub; \ 00484 } \ 00485 stack[48]; \ 00486 \ 00487 aux = aux; \ 00488 \ 00489 if( total <= 1 ) \ 00490 return; \ 00491 \ 00492 stack[0].lb = array; \ 00493 stack[0].ub = array + (total - 1); \ 00494 \ 00495 while( sp >= 0 ) \ 00496 { \ 00497 T* left = stack[sp].lb; \ 00498 T* right = stack[sp--].ub; \ 00499 \ 00500 for(;;) \ 00501 { \ 00502 int i, n = (int)(right - left) + 1, m; \ 00503 T* ptr; \ 00504 T* ptr2; \ 00505 \ 00506 if( n <= isort_thresh ) \ 00507 { \ 00508 insert_sort: \ 00509 for( ptr = left + 1; ptr <= right; ptr++ ) \ 00510 { \ 00511 for( ptr2 = ptr; ptr2 > left && LT(ptr2[0],ptr2[-1]); ptr2--) \ 00512 CV_SWAP( ptr2[0], ptr2[-1], t ); \ 00513 } \ 00514 break; \ 00515 } \ 00516 else \ 00517 { \ 00518 T* left0; \ 00519 T* left1; \ 00520 T* right0; \ 00521 T* right1; \ 00522 T* pivot; \ 00523 T* a; \ 00524 T* b; \ 00525 T* c; \ 00526 int swap_cnt = 0; \ 00527 \ 00528 left0 = left; \ 00529 right0 = right; \ 00530 pivot = left + (n/2); \ 00531 \ 00532 if( n > 40 ) \ 00533 { \ 00534 int d = n / 8; \ 00535 a = left, b = left + d, c = left + 2*d; \ 00536 left = LT(*a, *b) ? (LT(*b, *c) ? b : (LT(*a, *c) ? c : a)) \ 00537 : (LT(*c, *b) ? b : (LT(*a, *c) ? a : c)); \ 00538 \ 00539 a = pivot - d, b = pivot, c = pivot + d; \ 00540 pivot = LT(*a, *b) ? (LT(*b, *c) ? b : (LT(*a, *c) ? c : a)) \ 00541 : (LT(*c, *b) ? b : (LT(*a, *c) ? a : c)); \ 00542 \ 00543 a = right - 2*d, b = right - d, c = right; \ 00544 right = LT(*a, *b) ? (LT(*b, *c) ? b : (LT(*a, *c) ? c : a)) \ 00545 : (LT(*c, *b) ? b : (LT(*a, *c) ? a : c)); \ 00546 } \ 00547 \ 00548 a = left, b = pivot, c = right; \ 00549 pivot = LT(*a, *b) ? (LT(*b, *c) ? b : (LT(*a, *c) ? c : a)) \ 00550 : (LT(*c, *b) ? b : (LT(*a, *c) ? a : c)); \ 00551 if( pivot != left0 ) \ 00552 { \ 00553 CV_SWAP( *pivot, *left0, t ); \ 00554 pivot = left0; \ 00555 } \ 00556 left = left1 = left0 + 1; \ 00557 right = right1 = right0; \ 00558 \ 00559 for(;;) \ 00560 { \ 00561 while( left <= right && !LT(*pivot, *left) ) \ 00562 { \ 00563 if( !LT(*left, *pivot) ) \ 00564 { \ 00565 if( left > left1 ) \ 00566 CV_SWAP( *left1, *left, t ); \ 00567 swap_cnt = 1; \ 00568 left1++; \ 00569 } \ 00570 left++; \ 00571 } \ 00572 \ 00573 while( left <= right && !LT(*right, *pivot) ) \ 00574 { \ 00575 if( !LT(*pivot, *right) ) \ 00576 { \ 00577 if( right < right1 ) \ 00578 CV_SWAP( *right1, *right, t ); \ 00579 swap_cnt = 1; \ 00580 right1--; \ 00581 } \ 00582 right--; \ 00583 } \ 00584 \ 00585 if( left > right ) \ 00586 break; \ 00587 CV_SWAP( *left, *right, t ); \ 00588 swap_cnt = 1; \ 00589 left++; \ 00590 right--; \ 00591 } \ 00592 \ 00593 if( swap_cnt == 0 ) \ 00594 { \ 00595 left = left0, right = right0; \ 00596 goto insert_sort; \ 00597 } \ 00598 \ 00599 n = MIN( (int)(left1 - left0), (int)(left - left1) ); \ 00600 for( i = 0; i < n; i++ ) \ 00601 CV_SWAP( left0[i], left[i-n], t ); \ 00602 \ 00603 n = MIN( (int)(right0 - right1), (int)(right1 - right) ); \ 00604 for( i = 0; i < n; i++ ) \ 00605 CV_SWAP( left[i], right0[i-n+1], t ); \ 00606 n = (int)(left - left1); \ 00607 m = (int)(right1 - right); \ 00608 if( n > 1 ) \ 00609 { \ 00610 if( m > 1 ) \ 00611 { \ 00612 if( n > m ) \ 00613 { \ 00614 stack[++sp].lb = left0; \ 00615 stack[sp].ub = left0 + n - 1; \ 00616 left = right0 - m + 1, right = right0; \ 00617 } \ 00618 else \ 00619 { \ 00620 stack[++sp].lb = right0 - m + 1; \ 00621 stack[sp].ub = right0; \ 00622 left = left0, right = left0 + n - 1; \ 00623 } \ 00624 } \ 00625 else \ 00626 left = left0, right = left0 + n - 1; \ 00627 } \ 00628 else if( m > 1 ) \ 00629 left = right0 - m + 1, right = right0; \ 00630 else \ 00631 break; \ 00632 } \ 00633 } \ 00634 } \ 00635 } 00636 00637 #define CV_IMPLEMENT_QSORT( func_name, T, cmp ) \ 00638 CV_IMPLEMENT_QSORT_EX( func_name, T, cmp, int ) 00639 00640 /****************************************************************************************\ 00641 * Structures and macros for integration with IPP * 00642 \****************************************************************************************/ 00643 00644 /* IPP-compatible return codes */ 00645 typedef enum CvStatus 00646 { 00647 CV_BADMEMBLOCK_ERR = -113, 00648 CV_INPLACE_NOT_SUPPORTED_ERR= -112, 00649 CV_UNMATCHED_ROI_ERR = -111, 00650 CV_NOTFOUND_ERR = -110, 00651 CV_BADCONVERGENCE_ERR = -109, 00652 00653 CV_BADDEPTH_ERR = -107, 00654 CV_BADROI_ERR = -106, 00655 CV_BADHEADER_ERR = -105, 00656 CV_UNMATCHED_FORMATS_ERR = -104, 00657 CV_UNSUPPORTED_COI_ERR = -103, 00658 CV_UNSUPPORTED_CHANNELS_ERR = -102, 00659 CV_UNSUPPORTED_DEPTH_ERR = -101, 00660 CV_UNSUPPORTED_FORMAT_ERR = -100, 00661 00662 CV_BADARG_ERR = -49, //ipp comp 00663 CV_NOTDEFINED_ERR = -48, //ipp comp 00664 00665 CV_BADCHANNELS_ERR = -47, //ipp comp 00666 CV_BADRANGE_ERR = -44, //ipp comp 00667 CV_BADSTEP_ERR = -29, //ipp comp 00668 00669 CV_BADFLAG_ERR = -12, 00670 CV_DIV_BY_ZERO_ERR = -11, //ipp comp 00671 CV_BADCOEF_ERR = -10, 00672 00673 CV_BADFACTOR_ERR = -7, 00674 CV_BADPOINT_ERR = -6, 00675 CV_BADSCALE_ERR = -4, 00676 CV_OUTOFMEM_ERR = -3, 00677 CV_NULLPTR_ERR = -2, 00678 CV_BADSIZE_ERR = -1, 00679 CV_NO_ERR = 0, 00680 CV_OK = CV_NO_ERR 00681 } 00682 CvStatus; 00683 00684 #define CV_NOTHROW throw() 00685 00686 typedef struct CvFuncTable 00687 { 00688 void* fn_2d[CV_DEPTH_MAX]; 00689 } 00690 CvFuncTable; 00691 00692 typedef struct CvBigFuncTable 00693 { 00694 void* fn_2d[CV_DEPTH_MAX*4]; 00695 } 00696 CvBigFuncTable; 00697 00698 #define CV_INIT_FUNC_TAB( tab, FUNCNAME, FLAG ) \ 00699 (tab).fn_2d[CV_8U] = (void*)FUNCNAME##_8u##FLAG; \ 00700 (tab).fn_2d[CV_8S] = 0; \ 00701 (tab).fn_2d[CV_16U] = (void*)FUNCNAME##_16u##FLAG; \ 00702 (tab).fn_2d[CV_16S] = (void*)FUNCNAME##_16s##FLAG; \ 00703 (tab).fn_2d[CV_32S] = (void*)FUNCNAME##_32s##FLAG; \ 00704 (tab).fn_2d[CV_32F] = (void*)FUNCNAME##_32f##FLAG; \ 00705 (tab).fn_2d[CV_64F] = (void*)FUNCNAME##_64f##FLAG 00706 00707 #endif