48 #ifndef __OPENCV_CORE_INTERNAL_HPP__
49 #define __OPENCV_CORE_INTERNAL_HPP__
56 #if defined WIN32 || defined _WIN32
65 #if !defined WIN32 && !defined WINCE
77 # undef _CV_ALWAYS_PROFILE_
78 # define _CV_ALWAYS_NO_PROFILE_
88 #define __BEGIN__ __CV_BEGIN__
89 #define __END__ __CV_END__
90 #define EXIT __CV_EXIT__
103 # define IPPI_CALL(func) CV_Assert((func) >= 0)
106 #if defined __SSE2__ || defined _M_X64 || (defined _M_IX86_FP && _M_IX86_FP >= 2)
107 # include "emmintrin.h"
110 # if defined __SSE3__ || (defined _MSC_VER && _MSC_VER >= 1500)
111 # include "pmmintrin.h"
114 # if defined __SSSE3__ || (defined _MSC_VER && _MSC_VER >= 1500)
115 # include "tmmintrin.h"
118 # if defined __SSE4_1__ || (defined _MSC_VER && _MSC_VER >= 1500)
119 # include <smmintrin.h>
122 # if defined __SSE4_2__ || (defined _MSC_VER && _MSC_VER >= 1500)
123 # include <nmmintrin.h>
126 # if defined __AVX__ || (defined _MSC_FULL_VER && _MSC_FULL_VER >= 160040219)
129 # include <immintrin.h>
131 # if defined(_XCR_XFEATURE_ENABLED_MASK)
132 # define __xgetbv() _xgetbv(_XCR_XFEATURE_ENABLED_MASK)
134 # define __xgetbv() 0
140 #if (defined WIN32 || defined _WIN32) && defined(_M_ARM)
142 # include "arm_neon.h"
144 # define CPU_HAS_NEON_FEATURE (true)
145 #elif defined(__ARM_NEON__)
146 # include <arm_neon.h>
148 # define CPU_HAS_NEON_FEATURE (true)
177 # include "tbb/tbb_stddef.h"
178 # if TBB_VERSION_MAJOR*100 + TBB_VERSION_MINOR >= 202
179 # include "tbb/tbb.h"
180 # include "tbb/task.h"
189 # if defined __GNUC__ && defined __APPLE__
190 # pragma GCC diagnostic ignored "-Wshadow"
192 # include <Eigen/Core>
204 template<
typename Body>
static inline
207 tbb::parallel_for(range, body);
210 template<
typename Iterator,
typename Body>
static inline
211 void parallel_do( Iterator
first, Iterator last,
const Body& body )
213 tbb::parallel_do(first, last, body);
218 template<
typename Body>
static inline
221 tbb::parallel_reduce(range, body);
240 template<
typename Body>
static inline
248 template<
typename Iterator,
typename Body>
static inline
249 void parallel_do( Iterator
first, Iterator last,
const Body& body )
251 for( ; first != last; ++
first )
257 template<
typename Body>
static inline
269 #define CV_INIT_ALGORITHM(classname, algname, memberinit) \
270 static ::cv::Algorithm* create##classname() \
272 return new classname; \
275 static ::cv::AlgorithmInfo& classname##_info() \
277 static ::cv::AlgorithmInfo classname##_info_var(algname, create##classname); \
278 return classname##_info_var; \
281 static ::cv::AlgorithmInfo& classname##_info_auto = classname##_info(); \
283 ::cv::AlgorithmInfo* classname::info() const \
285 static volatile bool initialized = false; \
289 initialized = true; \
293 return &classname##_info(); \
299 #define CV_MAX_INLINE_MAT_OP_SIZE 10
302 #define CV_MAX_LOCAL_MAT_SIZE 32
305 #define CV_MAX_LOCAL_SIZE \
306 (CV_MAX_LOCAL_MAT_SIZE*CV_MAX_LOCAL_MAT_SIZE*(int)sizeof(double))
309 #define CV_DEFAULT_IMAGE_ROW_ALIGN 4
312 #define CV_DEFAULT_MAT_ROW_ALIGN 1
316 #define CV_MAX_ALLOC_SIZE (((size_t)1 << (sizeof(size_t)*8-2)))
319 #define CV_MALLOC_ALIGN 16
322 #define CV_STRUCT_ALIGN ((int)sizeof(double))
325 #define CV_STORAGE_BLOCK_SIZE ((1<<16) - 128)
328 #define CV_SPARSE_MAT_BLOCK (1<<12)
331 #define CV_SPARSE_HASH_SIZE0 (1<<10)
334 #define CV_SPARSE_HASH_RATIO 3
337 #define CV_MAX_STRLEN 1024
340 # define CV_CHECK_NANS( arr ) cvCheckArray((arr))
342 # define CV_CHECK_NANS( arr )
350 # define CV_DECL_ALIGNED(x) __attribute__ ((aligned (x)))
351 #elif defined _MSC_VER
352 # define CV_DECL_ALIGNED(x) __declspec(align(x))
354 # define CV_DECL_ALIGNED(x)
358 # define CV_IMPL CV_EXTERN_C
361 #define CV_DBG_BREAK() { volatile int* crashMe = 0; *crashMe = 0; }
365 #define CV_STUB_STEP (1 << 30)
367 #define CV_SIZEOF_FLOAT ((int)sizeof(float))
368 #define CV_SIZEOF_SHORT ((int)sizeof(short))
370 #define CV_ORIGIN_TL 0
371 #define CV_ORIGIN_BL 1
374 #define CV_POS_INF 0x7f800000
375 #define CV_NEG_INF 0x807fffff
376 #define CV_1F 0x3f800000
377 #define CV_TOGGLE_FLT(x) ((x)^((int)(x) < 0 ? 0x7fffffff : 0))
378 #define CV_TOGGLE_DBL(x) \
379 ((x)^((int64)(x) < 0 ? CV_BIG_INT(0x7fffffffffffffff) : 0))
381 #define CV_NOP(a) (a)
382 #define CV_ADD(a, b) ((a) + (b))
383 #define CV_SUB(a, b) ((a) - (b))
384 #define CV_MUL(a, b) ((a) * (b))
385 #define CV_AND(a, b) ((a) & (b))
386 #define CV_OR(a, b) ((a) | (b))
387 #define CV_XOR(a, b) ((a) ^ (b))
388 #define CV_ANDN(a, b) (~(a) & (b))
389 #define CV_ORN(a, b) (~(a) | (b))
390 #define CV_SQR(a) ((a) * (a))
392 #define CV_LT(a, b) ((a) < (b))
393 #define CV_LE(a, b) ((a) <= (b))
394 #define CV_EQ(a, b) ((a) == (b))
395 #define CV_NE(a, b) ((a) != (b))
396 #define CV_GT(a, b) ((a) > (b))
397 #define CV_GE(a, b) ((a) >= (b))
399 #define CV_NONZERO(a) ((a) != 0)
400 #define CV_NONZERO_FLT(a) (((a)+(a)) != 0)
403 #define CV_CAST_8U(t) (uchar)(!((t) & ~255) ? (t) : (t) > 0 ? 255 : 0)
404 #define CV_CAST_8S(t) (schar)(!(((t)+128) & ~255) ? (t) : (t) > 0 ? 127 : -128)
405 #define CV_CAST_16U(t) (ushort)(!((t) & ~65535) ? (t) : (t) > 0 ? 65535 : 0)
406 #define CV_CAST_16S(t) (short)(!(((t)+32768) & ~65535) ? (t) : (t) > 0 ? 32767 : -32768)
407 #define CV_CAST_32S(t) (int)(t)
408 #define CV_CAST_64S(t) (int64)(t)
409 #define CV_CAST_32F(t) (float)(t)
410 #define CV_CAST_64F(t) (double)(t)
412 #define CV_PASTE2(a,b) a##b
413 #define CV_PASTE(a,b) CV_PASTE2(a,b)
416 #define CV_MAKE_STR(a) #a
418 #define CV_ZERO_OBJ(x) memset((x), 0, sizeof(*(x)))
420 #define CV_DIM(static_array) ((int)(sizeof(static_array)/sizeof((static_array)[0])))
422 #define cvUnsupportedFormat "Unsupported format"
426 assert( (align & (align-1)) == 0 );
427 return (
void*)( ((size_t)ptr + align - 1) & ~(size_t)(align-1) );
432 assert( (align & (align-1)) == 0 && size < INT_MAX );
433 return (size + align - 1) & -align;
444 #define CV_DESCALE(x,n) (((x) + (1 << ((n)-1))) >> (n))
445 #define CV_FLT_TO_FIX(x,n) cvRound((x)*(1<<(n)))
509 #define CV_IMPLEMENT_QSORT_EX( func_name, T, LT, user_data_type ) \
510 void func_name( T *array, size_t total, user_data_type aux ) \
512 int isort_thresh = 7; \
528 stack[0].lb = array; \
529 stack[0].ub = array + (total - 1); \
533 T* left = stack[sp].lb; \
534 T* right = stack[sp--].ub; \
538 int i, n = (int)(right - left) + 1, m; \
542 if( n <= isort_thresh ) \
545 for( ptr = left + 1; ptr <= right; ptr++ ) \
547 for( ptr2 = ptr; ptr2 > left && LT(ptr2[0],ptr2[-1]); ptr2--) \
548 CV_SWAP( ptr2[0], ptr2[-1], t ); \
566 pivot = left + (n/2); \
571 a = left, b = left + d, c = left + 2*d; \
572 left = LT(*a, *b) ? (LT(*b, *c) ? b : (LT(*a, *c) ? c : a)) \
573 : (LT(*c, *b) ? b : (LT(*a, *c) ? a : c)); \
575 a = pivot - d, b = pivot, c = pivot + d; \
576 pivot = LT(*a, *b) ? (LT(*b, *c) ? b : (LT(*a, *c) ? c : a)) \
577 : (LT(*c, *b) ? b : (LT(*a, *c) ? a : c)); \
579 a = right - 2*d, b = right - d, c = right; \
580 right = LT(*a, *b) ? (LT(*b, *c) ? b : (LT(*a, *c) ? c : a)) \
581 : (LT(*c, *b) ? b : (LT(*a, *c) ? a : c)); \
584 a = left, b = pivot, c = right; \
585 pivot = LT(*a, *b) ? (LT(*b, *c) ? b : (LT(*a, *c) ? c : a)) \
586 : (LT(*c, *b) ? b : (LT(*a, *c) ? a : c)); \
587 if( pivot != left0 ) \
589 CV_SWAP( *pivot, *left0, t ); \
592 left = left1 = left0 + 1; \
593 right = right1 = right0; \
597 while( left <= right && !LT(*pivot, *left) ) \
599 if( !LT(*left, *pivot) ) \
602 CV_SWAP( *left1, *left, t ); \
609 while( left <= right && !LT(*right, *pivot) ) \
611 if( !LT(*pivot, *right) ) \
613 if( right < right1 ) \
614 CV_SWAP( *right1, *right, t ); \
623 CV_SWAP( *left, *right, t ); \
629 if( swap_cnt == 0 ) \
631 left = left0, right = right0; \
635 n = MIN( (int)(left1 - left0), (int)(left - left1) ); \
636 for( i = 0; i < n; i++ ) \
637 CV_SWAP( left0[i], left[i-n], t ); \
639 n = MIN( (int)(right0 - right1), (int)(right1 - right) ); \
640 for( i = 0; i < n; i++ ) \
641 CV_SWAP( left[i], right0[i-n+1], t ); \
642 n = (int)(left - left1); \
643 m = (int)(right1 - right); \
650 stack[++sp].lb = left0; \
651 stack[sp].ub = left0 + n - 1; \
652 left = right0 - m + 1, right = right0; \
656 stack[++sp].lb = right0 - m + 1; \
657 stack[sp].ub = right0; \
658 left = left0, right = left0 + n - 1; \
662 left = left0, right = left0 + n - 1; \
665 left = right0 - m + 1, right = right0; \
673 #define CV_IMPLEMENT_QSORT( func_name, T, cmp ) \
674 CV_IMPLEMENT_QSORT_EX( func_name, T, cmp, int )
720 #define CV_NOTHROW throw()
733 #define CV_INIT_FUNC_TAB( tab, FUNCNAME, FLAG ) \
734 (tab).fn_2d[CV_8U] = (void*)FUNCNAME##_8u##FLAG; \
735 (tab).fn_2d[CV_8S] = 0; \
736 (tab).fn_2d[CV_16U] = (void*)FUNCNAME##_16u##FLAG; \
737 (tab).fn_2d[CV_16S] = (void*)FUNCNAME##_16s##FLAG; \
738 (tab).fn_2d[CV_32S] = (void*)FUNCNAME##_32s##FLAG; \
739 (tab).fn_2d[CV_32F] = (void*)FUNCNAME##_32f##FLAG; \
740 (tab).fn_2d[CV_64F] = (void*)FUNCNAME##_64f##FLAG
751 virtual void genBuffers(
int n,
unsigned int*
buffers)
const = 0;
752 virtual void deleteBuffers(
int n,
const unsigned int* buffers)
const = 0;
754 virtual void bufferData(
unsigned int target, ptrdiff_t
size,
const void*
data,
unsigned int usage)
const = 0;
755 virtual void bufferSubData(
unsigned int target, ptrdiff_t
offset, ptrdiff_t size,
const void* data)
const = 0;
757 virtual void bindBuffer(
unsigned int target,
unsigned int buffer)
const = 0;
759 virtual void* mapBuffer(
unsigned int target,
unsigned int access)
const = 0;
760 virtual void unmapBuffer(
unsigned int target)
const = 0;
762 virtual void generateBitmapFont(
const std::string& family,
int height,
int weight,
bool italic,
bool underline,
int start,
int count,
int base)
const = 0;
764 virtual bool isGlContextInitialized()
const = 0;
773 namespace cv {
namespace ogl {
777 #define CV_CheckGlError() CV_DbgAssert( (cv::ogl::checkError(__FILE__, __LINE__, CV_Func)) )
781 #endif // __OPENCV_CORE_INTERNAL_HPP__
BlockedRange()
Definition: internal.hpp:230
Definition: internal.hpp:684
tbb::concurrent_vector< Rect > ConcurrentRectVector
Definition: internal.hpp:224
Definition: internal.hpp:692
Definition: internal.hpp:689
Definition: internal.hpp:695
tbb::split Split
Definition: internal.hpp:216
tbb::blocked_range< int > BlockedRange
Definition: internal.hpp:202
Definition: internal.hpp:694
const CvMat CvMat int method CV_DEFAULT(CV_FM_RANSAC)
Definition: internal.hpp:710
Definition: internal.hpp:713
void * fn_2d[CV_DEPTH_MAX]
Definition: internal.hpp:724
Definition: types_c.h:1138
CvCmpFunc func
Definition: core_c.h:1072
Definition: internal.hpp:685
int height
Definition: types_c.h:1141
CvSize size
Definition: calib3d.hpp:212
int cols
Definition: types_c.h:672
CV_INLINE IppiSize ippiSize(int width, int height)
Definition: internal.hpp:95
CV_EXPORTS bool icvCheckGlError(const char *file, const int line, const char *func="")
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: core_c.h:403
Definition: internal.hpp:714
int _end
Definition: internal.hpp:237
Definition: internal.hpp:255
Definition: internal.hpp:693
void * fn_2d[CV_DEPTH_MAX *4]
Definition: internal.hpp:730
Definition: internal.hpp:706
Definition: internal.hpp:701
BlockedRange(int b, int e, int g=1)
Definition: internal.hpp:231
Definition: internal.hpp:699
int width
Definition: highgui_c.h:130
Definition: internal.hpp:686
GLint * first
Definition: legacy.hpp:1133
CvStatus
Definition: internal.hpp:681
const void * first
Definition: core_c.h:1452
CvArr const CvMat * mat
Definition: core_c.h:700
CV_INLINE int cvAlign(int size, int align)
Definition: internal.hpp:430
CV_EXPORTS void split(const Mat &src, Mat *mvbegin)
copies each plane of a multi-channel array to a dedicated array
GLenum GLsizei GLsizei height
Definition: internal.hpp:709
Definition: internal.hpp:696
GLintptr GLsizeiptr GLbitfield access
int width
Definition: types_c.h:1140
int _begin
Definition: internal.hpp:237
Definition: internal.hpp:722
int end() const
Definition: internal.hpp:233
GLuint GLuint GLsizei count
Definition: core_c.h:973
CV_INLINE void * cvAlignPtr(const void *ptr, int align CV_DEFAULT(32))
Definition: internal.hpp:424
int grainsize() const
Definition: internal.hpp:234
Definition: internal.hpp:707
Definition: types_c.h:645
Definition: internal.hpp:698
int _grainsize
Definition: internal.hpp:237
Definition: internal.hpp:705
Definition: internal.hpp:690
GLboolean GLboolean GLboolean b
Definition: legacy.hpp:633
tbb::concurrent_vector< double > ConcurrentDoubleVector
Definition: internal.hpp:225
CV_EXPORTS void icvSetOpenGlFuncTab(const CvOpenGlFuncTab *tab)
const char const char const char int line
Definition: core_c.h:1743
int rows
Definition: types_c.h:666
Definition: internal.hpp:728
const char * ptr
Definition: core_c.h:942
Definition: internal.hpp:712
Definition: internal.hpp:227
CV_EXPORTS bool checkError(const char *file, const int line, const char *func="")
CV_EXPORTS const char * currentParallelFramework()
GLsizeiptr const GLvoid GLenum usage
Definition: internal.hpp:691
Definition: internal.hpp:702
Definition: internal.hpp:703
struct CvFuncTable CvFuncTable
struct CvBigFuncTable CvBigFuncTable
Definition: internal.hpp:687
Definition: internal.hpp:683
CV_INLINE CvSize cvGetMatSize(const CvMat *mat)
Definition: internal.hpp:436
GLsizeiptr size
Definition: core_c.h:939
Definition: internal.hpp:746
Definition: internal.hpp:711
Definition: internal.hpp:715
Definition: internal.hpp:716
CV_EXPORTS_W void line(CV_IN_OUT Mat &img, Point pt1, Point pt2, const Scalar &color, int thickness=1, int lineType=8, int shift=0)
draws the line segment (pt1, pt2) in the image
int begin() const
Definition: internal.hpp:232