/* Converted to D from cxtypes.h by mikanya*/ module opencv.c.cxtypes; /*M/////////////////////////////////////////////////////////////////////////////////////// // // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. // // By downloading, copying, installing or using the software you agree to this license. // If you do not agree to this license, do not download, install, // copy or use the software. // // // License Agreement // For Open Source Computer Vision Library // // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. // Copyright (C) 2009, Willow Garage Inc., all rights reserved. // Third party copyrights are property of their respective owners. // // Redistribution and use in source and binary forms, with or without modification, // are permitted provided that the following conditions are met: // // * Redistribution's of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. // // * Redistribution's in binary form must reproduce the above copyright notice, // this list of conditions and the following disclaimer in the documentation // and/or other materials provided with the distribution. // // * The name of the copyright holders may not be used to endorse or promote products // derived from this software without specific prior written permission. // // This software is provided by the copyright holders and contributors "as is" and // any express or implied warranties, including, but not limited to, the implied // warranties of merchantability and fitness for a particular purpose are disclaimed. // In no event shall the Intel Corporation or contributors be liable for any direct, // indirect, incidental, special, exemplary, or consequential damages // (including, but not limited to, procurement of substitute goods or services; // loss of use, data, or profits; or business interruption) however caused // and on any theory of liability, whether in contract, strict liability, // or tort (including negligence or otherwise) arising in any way out of // the use of this software, even if advised of the possibility of such damage. // //M*/ //C #ifndef _CXCORE_TYPES_H_ //C #define _CXCORE_TYPES_H_ //C #if !defined _CRT_SECURE_NO_DEPRECATE && _MSC_VER > 1300 //C #define _CRT_SECURE_NO_DEPRECATE /* to avoid multiple Visual Studio 2005 warnings */ //C #endif //C #if _MSC_VER >= 1500 //C #ifndef _BIND_TO_CURRENT_CRT_VERSION //C #define _BIND_TO_CURRENT_CRT_VERSION 1 //C #endif //C #ifndef _BIND_TO_CURRENT_VCLIBS_VERSION //C #define _BIND_TO_CURRENT_VCLIBS_VERSION 1 //C #endif //C #endif //C #ifndef SKIP_INCLUDES //C #include //C #include //C #include //C #include //private import std.c.assert; private import std.c.stdlib; private import std.c.string; //private import std.c.float; //C #if !defined _MSC_VER && !defined __BORLANDC__ //C #include //C #endif private import std.stdint; /+ #if defined __ICL #define CV_ICC __ICL #elif defined __ICC #define CV_ICC __ICC #elif defined __ECL #define CV_ICC __ECL #elif defined __ECC #define CV_ICC __ECC #endif #if ((defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64) && \ (_MSC_VER >= 1400 || defined CV_ICC)) \ || (defined __SSE2__ && defined __GNUC__ && __GNUC__ >= 4) #include #define CV_SSE2 1 #else #define CV_SSE2 0 #endif #if ((defined __SSE__ || defined __MMX__) && defined __GNUC__ && __GNUC__ >= 3) #include #endif +/ //C #if defined __BORLANDC__ //C #include //C #else //C #include //C #endif private import std.math; //C #ifdef HAVE_IPL //C #ifndef __IPL_H__ //C #if defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64 //C #include //C #else //C #include //C #endif //C #endif //C #elif defined __IPL_H__ //C #define HAVE_IPL //C #endif //C #endif // SKIP_INCLUDES //C #if defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64 //C #define CV_CDECL __cdecl //C #define CV_STDCALL __stdcall //C #else //C #define CV_CDECL //C #define CV_STDCALL //C #endif //C #ifndef CV_EXTERN_C //C #ifdef __cplusplus //C #define CV_EXTERN_C extern "C" //C #define CV_DEFAULT(val) = val //C #else //C #define CV_EXTERN_C //C #define CV_DEFAULT(val) //C #endif //C #endif //C #ifndef CV_EXTERN_C_FUNCPTR //C #ifdef __cplusplus //C #define CV_EXTERN_C_FUNCPTR(x) extern "C" { typedef x; } //C #else //C #define CV_EXTERN_C_FUNCPTR(x) typedef x //C #endif //C #endif //C #ifndef CV_INLINE //C #if defined __cplusplus //C #define CV_INLINE inline //C #elif (defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64 || defined WINCE) && !defined __GNUC__ //C #define CV_INLINE __inline //C #else //C #define CV_INLINE static //C #endif //C #endif /* CV_INLINE */ //C #if (defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64 || defined WINCE) && defined CVAPI_EXPORTS //C #define CV_EXPORTS __declspec(dllexport) //C #else //C #define CV_EXPORTS //C #endif //C #ifndef CVAPI //C #define CVAPI(rettype) CV_EXTERN_C CV_EXPORTS rettype CV_CDECL //C #endif //C #if defined _MSC_VER || defined __BORLANDC__ //C typedef __int64 int64; //C typedef unsigned __int64 uint64; //C #else //C typedef int64_t int64; //C typedef uint64_t uint64; //C #endif alias int64_t int64; alias uint64_t uint64; //C #ifndef HAVE_IPL //C typedef unsigned char uchar; //C typedef unsigned short ushort; //C #endif alias byte uchar; //alias ushort ushort; //C typedef signed char schar; alias byte schar; /* CvArr* is used to pass arbitrary * array-like data structures * into functions where the particular * array type is recognized at runtime: */ //C typedef void CvArr; alias void CvArr; //C typedef union Cv32suf //C { //C int i; //C unsigned u; //C float f; //C } //C Cv32suf; union Cv32suf { int i; uint u; float f; } //C typedef union Cv64suf //C { //C int64 i; //C uint64 u; //C double f; //C } //C Cv64suf; union Cv64suf { int64 i; uint64 u; double f; } /****************************************************************************************\ * Common macros and inline functions * \****************************************************************************************/ //C #define CV_PI 3.1415926535897932384626433832795 //C #define CV_LOG2 0.69314718055994530941723212145818 const CV_PI = 3.1415926535897932384626433832795; const CV_LOG2 = 0.69314718055994530941723212145818; //C #define CV_SWAP(a,b,t) ((t) = (a), (a) = (b), (b) = (t)) void CV_SWAP(T)(ref T a, ref T b, ref T t) { ((t) = (a), (a) = (b), (b) = (t)); } //C #ifndef MIN //C #define MIN(a,b) ((a) > (b) ? (b) : (a)) //C #endif auto MIN(T)(T a, T b) { return ((a) > (b) ? (b) : (a)); } //C #ifndef MAX //C #define MAX(a,b) ((a) < (b) ? (b) : (a)) //C #endif auto MAX(T)(T a, T b) { return ((a) < (b) ? (b) : (a)); } /* min & max without jumps */ //C #define CV_IMIN(a, b) ((a) ^ (((a)^(b)) & (((a) < (b)) - 1))) auto CV_IMIN(T)(T a, T b) { return ((a) ^ (((a)^(b)) & (((a) < (b)) - 1))); } //C #define CV_IMAX(a, b) ((a) ^ (((a)^(b)) & (((a) > (b)) - 1))) auto CV_IMAX(T)(T a, T b) { return ((a) ^ (((a)^(b)) & (((a) > (b)) - 1))); } /* absolute value without jumps */ //C #ifndef __cplusplus //C #define CV_IABS(a) (((a) ^ ((a) < 0 ? -1 : 0)) - ((a) < 0 ? -1 : 0)) //C #else //C #define CV_IABS(a) abs(a) //C #endif //C #define CV_CMP(a,b) (((a) > (b)) - ((a) < (b))) //C #define CV_SIGN(a) CV_CMP((a),0) auto CV_IABS(T)(a) { return abs(a); } auto CV_CMP(T)(T a, T b) { return (((a) > (b)) - ((a) < (b))); } auto CV_CMP(T)(T a) { return CV_CMP((a),0); } //C CV_INLINE int cvRound( double value ) //C { //C #if CV_SSE2 && !defined __APPLE__ //C __m128d t = _mm_set_sd( value ); //C return _mm_cvtsd_si32(t); //C #elif (defined WIN32 || defined _WIN32) && !defined WIN64 && !defined _WIN64 && defined _MSC_VER //C int t; //C __asm //C { //C fld value; //C fistp t; //C } //C return t; //C #elif defined HAVE_LRINT || defined CV_ICC || defined __GNUC__ //C return (int)lrint(value); //C #else //C // while this is not IEEE754-compliant rounding, it's usually a good enough approximation //C return (int)(value + 0.5); //C #endif //C } int cvRound( double value) { return cast(int)lrint(value); } //C CV_INLINE int cvFloor( double value ) //C { //C #ifdef __GNUC__ //C int i = (int)value; //C return i - (i > value); //C #elif CV_SSE2 //C __m128d t = _mm_set_sd( value ); //C int i = _mm_cvtsd_si32(t); //C return i - _mm_movemask_pd(_mm_cmplt_sd(t, _mm_cvtsi32_sd(t,i))); //C #else //C int i = cvRound(value); //C Cv32suf diff; //C diff.f = (float)(value - i); //C return i - (diff.i < 0); //C #endif //C } int cvFloor( double value ) { return cast(int)floor(value); } //C CV_INLINE int cvCeil( double value ) //C { //C #ifdef __GNUC__ //C int i = (int)value; //C return i + (i < value); //C #elif CV_SSE2 //C __m128d t = _mm_set_sd( value ); //C int i = _mm_cvtsd_si32(t); //C return i + _mm_movemask_pd(_mm_cmplt_sd(_mm_cvtsi32_sd(t,i), t)); //C #else //C int i = cvRound(value); //C Cv32suf diff; //C diff.f = (float)(i - value); //C return i + (diff.i < 0); //C #endif //C } int cvCeil( double value ) { return cast(int)ceil(value); } //C #define cvInvSqrt(value) ((float)(1./sqrt(value))) //C #define cvSqrt(value) ((float)sqrt(value)) auto cvInvSqrt(T)(T value) { return cast(float)(1./sqrt(value)); } auto cvInvSqrt(T)(T value) { return cast(float)sqrt(value); } //C CV_INLINE int cvIsNaN( double value ) //C { //C #if 1/*defined _MSC_VER || defined __BORLANDC__ //C return _isnan(value); //C #elif defined __GNUC__ //C return isnan(value); //C #else*/ //C Cv64suf ieee754; //C ieee754.f = value; //C return ((unsigned)(ieee754.u >> 32) & 0x7fffffff) + //C ((unsigned)ieee754.u != 0) > 0x7ff00000; //C #endif //C } int cvIsNaN( double value ) { return isNaN(value); } //C CV_INLINE int cvIsInf( double value ) //C { //C #if 1/*defined _MSC_VER || defined __BORLANDC__ //C return !_finite(value); //C #elif defined __GNUC__ //C return isinf(value); //C #else*/ //C Cv64suf ieee754; //C ieee754.f = value; //C return ((unsigned)(ieee754.u >> 32) & 0x7fffffff) == 0x7ff00000 && //C (unsigned)ieee754.u == 0; //C #endif //C } int cvIsInf( double value ) { return isInfinity(value); } /*************** Random number generation *******************/ //C typedef uint64 CvRNG; alias uint64 CvRNG; //C CV_INLINE CvRNG cvRNG( int64 seed CV_DEFAULT(-1)) //C { //C CvRNG rng = seed ? (uint64)seed : (uint64)(int64)-1; //C return rng; //C } CvRNG cvRNG( int64 seed = -1) { CvRNG rng = seed ? cast(uint64)seed : cast(uint64)cast(int64)-1; return rng; } /* Return random 32-bit unsigned integer: */ //C CV_INLINE unsigned cvRandInt( CvRNG* rng ) //C { //C uint64 temp = *rng; //C temp = (uint64)(unsigned)temp*4164903690U + (temp >> 32); //C *rng = temp; //C return (unsigned)temp; //C } uint cvRandInt( CvRNG* rng ) { uint64 temp = *rng; temp = cast(uint64)cast(uint)temp*4164903690U + (temp >> 32); *rng = temp; return cast(uint)temp; } /* Returns random floating-point number between 0 and 1: */ //C CV_INLINE double cvRandReal( CvRNG* rng ) //C { //C return cvRandInt(rng)*2.3283064365386962890625e-10 /* 2^-32 */; //C } double cvRandReal( CvRNG* rng ) { return cvRandInt(rng)*2.3283064365386962890625e-10 /* 2^-32 */; } /****************************************************************************************\ * Image type (IplImage) * \****************************************************************************************/ //C #ifndef HAVE_IPL /* * The following definitions (until #endif) * is an extract from IPL headers. * Copyright (c) 1995 Intel Corporation. */ //C #define IPL_DEPTH_SIGN 0x80000000 const IPL_DEPTH_SIGN = 0x80000000; //C #define IPL_DEPTH_1U 1 //C #define IPL_DEPTH_8U 8 //C #define IPL_DEPTH_16U 16 //C #define IPL_DEPTH_32F 32 const IPL_DEPTH_1U = 1; const IPL_DEPTH_8U = 8; const IPL_DEPTH_16U = 16; const IPL_DEPTH_32F = 32; //C #define IPL_DEPTH_8S (IPL_DEPTH_SIGN| 8) //C #define IPL_DEPTH_16S (IPL_DEPTH_SIGN|16) //C #define IPL_DEPTH_32S (IPL_DEPTH_SIGN|32) const IPL_DEPTH_8S = (IPL_DEPTH_SIGN| 8); const IPL_DEPTH_16S = (IPL_DEPTH_SIGN|16); const IPL_DEPTH_32S = (IPL_DEPTH_SIGN|32); //C #define IPL_DATA_ORDER_PIXEL 0 //C #define IPL_DATA_ORDER_PLANE 1 const IPL_DATA_ORDER_PIXEL = 0; const IPL_DATA_ORDER_PLANE = 1; //C #define IPL_ORIGIN_TL 0 //C #define IPL_ORIGIN_BL 1 const IPL_ORIGIN_TL = 0; const IPL_ORIGIN_BL = 1; //C #define IPL_ALIGN_4BYTES 4 //C #define IPL_ALIGN_8BYTES 8 //C #define IPL_ALIGN_16BYTES 16 //C #define IPL_ALIGN_32BYTES 32 const IPL_ALIGN_4BYTES = 4; const IPL_ALIGN_8BYTES = 8; const IPL_ALIGN_16BYTES = 16; const IPL_ALIGN_32BYTES = 32; //C #define IPL_ALIGN_DWORD IPL_ALIGN_4BYTES //C #define IPL_ALIGN_QWORD IPL_ALIGN_8BYTES const IPL_ALIGN_DWORD = IPL_ALIGN_4BYTES; const IPL_ALIGN_QWORD = IPL_ALIGN_8BYTES; //C #define IPL_BORDER_CONSTANT 0 //C #define IPL_BORDER_REPLICATE 1 //C #define IPL_BORDER_REFLECT 2 //C #define IPL_BORDER_WRAP 3 const IPL_BORDER_CONSTANT = 0; const IPL_BORDER_REPLICATE = 1; const IPL_BORDER_REFLECT = 2; const IPL_BORDER_WRAP = 3; //C typedef struct _IplImage //C { //C int nSize; /* sizeof(IplImage) */ //C int ID; /* version (=0)*/ //C int nChannels; /* Most of OpenCV functions support 1,2,3 or 4 channels */ //C int alphaChannel; /* Ignored by OpenCV */ //C int depth; /* Pixel depth in bits: IPL_DEPTH_8U, IPL_DEPTH_8S, IPL_DEPTH_16S, //C IPL_DEPTH_32S, IPL_DEPTH_32F and IPL_DEPTH_64F are supported. */ //C char colorModel[4]; /* Ignored by OpenCV */ //C char channelSeq[4]; /* ditto */ //C int dataOrder; /* 0 - interleaved color channels, 1 - separate color channels. //C cvCreateImage can only create interleaved images */ //C int origin; /* 0 - top-left origin, //C 1 - bottom-left origin (Windows bitmaps style). */ //C int align; /* Alignment of image rows (4 or 8). //C OpenCV ignores it and uses widthStep instead. */ //C int width; /* Image width in pixels. */ //C int height; /* Image height in pixels. */ //C struct _IplROI *roi; /* Image ROI. If NULL, the whole image is selected. */ //C struct _IplImage *maskROI; /* Must be NULL. */ //C void *imageId; /* " " */ //C struct _IplTileInfo *tileInfo; /* " " */ //C int imageSize; /* Image data size in bytes //C (==image->height*image->widthStep //C in case of interleaved data)*/ //C char *imageData; /* Pointer to aligned image data. */ //C int widthStep; /* Size of aligned image row in bytes. */ //C int BorderMode[4]; /* Ignored by OpenCV. */ //C int BorderConst[4]; /* Ditto. */ //C char *imageDataOrigin; /* Pointer to very origin of image data //C (not necessarily aligned) - //C needed for correct deallocation */ //C } //C IplImage; struct _IplImage { int nSize; /* sizeof(IplImage) */ int ID; /* version (=0)*/ int nChannels; /* Most of OpenCV functions support 1,2,3 or 4 channels */ int alphaChannel; /* Ignored by OpenCV */ int depth; /* Pixel depth in bits: IPL_DEPTH_8U, IPL_DEPTH_8S, IPL_DEPTH_16S, IPL_DEPTH_32S, IPL_DEPTH_32F and IPL_DEPTH_64F are supported. */ char colorModel[4]; /* Ignored by OpenCV */ char channelSeq[4]; /* ditto */ int dataOrder; /* 0 - interleaved color channels, 1 - separate color channels. cvCreateImage can only create interleaved images */ int origin; /* 0 - top-left origin, 1 - bottom-left origin (Windows bitmaps style). */ int _align; /* Alignment of image rows (4 or 8). OpenCV ignores it and uses widthStep instead. */ int width; /* Image width in pixels. */ int height; /* Image height in pixels. */ _IplROI *roi; /* Image ROI. If NULL, the whole image is selected. */ _IplImage *maskROI; /* Must be NULL. */ void *imageId; /* " " */ _IplTileInfo *tileInfo; /* " " */ int imageSize; /* Image data size in bytes (==image->height*image->widthStep in case of interleaved data)*/ char *imageData; /* Pointer to aligned image data. */ int widthStep; /* Size of aligned image row in bytes. */ int BorderMode[4]; /* Ignored by OpenCV. */ int BorderConst[4]; /* Ditto. */ char *imageDataOrigin; /* Pointer to very origin of image data (not necessarily aligned) - needed for correct deallocation */ } alias _IplImage IplImage; //C typedef struct _IplTileInfo IplTileInfo; struct _IplTileInfo; alias _IplTileInfo IplTileInfo; //C typedef struct _IplROI //C { //C int coi; /* 0 - no COI (all channels are selected), 1 - 0th channel is selected ...*/ //C int xOffset; //C int yOffset; //C int width; //C int height; //C } //C IplROI; struct _IplROI { int coi; /* 0 - no COI (all channels are selected), 1 - 0th channel is selected ...*/ int xOffset; int yOffset; int width; int height; } alias _IplROI IplROI; //C typedef struct _IplConvKernel //C { //C int nCols; //C int nRows; //C int anchorX; //C int anchorY; //C int *values; //C int nShiftR; //C } //C IplConvKernel; struct _IplConvKernel { int nCols; int nRows; int anchorX; int anchorY; int *values; int nShiftR; } alias _IplConvKernel IplConvKernel; //C typedef struct _IplConvKernelFP //C { //C int nCols; //C int nRows; //C int anchorX; //C int anchorY; //C float *values; //C } //C IplConvKernelFP; struct _IplConvKernelFP { int nCols; int nRows; int anchorX; int anchorY; float *values; } alias _IplConvKernelFP IplConvKernelFP; //C #define IPL_IMAGE_HEADER 1 //C #define IPL_IMAGE_DATA 2 //C #define IPL_IMAGE_ROI 4 const IPL_IMAGE_HEADER = 1; const IPL_IMAGE_DATA = 2; const IPL_IMAGE_ROI = 4; //C #endif/*HAVE_IPL*/ /* extra border mode */ //C #define IPL_BORDER_REFLECT_101 4 const IPL_BORDER_REFLECT_101 = 4; //C #define IPL_IMAGE_MAGIC_VAL ((int)sizeof(IplImage)) //C #define CV_TYPE_NAME_IMAGE "opencv-image" const IPL_IMAGE_MAGIC_VAL = cast(int)IplImage.sizeof; const CV_TYPE_NAME_IMAGE = "opencv-image"; //C #define CV_IS_IMAGE_HDR(img) \ //C ((img) != NULL && ((const IplImage*)(img))->nSize == sizeof(IplImage)) auto CV_IS_IMAGE_HDR(T)(T img) { return (img !is null && (cast(const(IplImage)*)img).nSize == IplImage.sizeof); } //C #define CV_IS_IMAGE(img) \ //C (CV_IS_IMAGE_HDR(img) && ((IplImage*)img)->imageData != NULL) auto CV_IS_IMAGE(T)(T img) { return (CV_IS_IMAGE_HDR(img) && (cast(IplImage*)img).imageData !is null); } /* for storing double-precision floating point data in IplImage's */ //C #define IPL_DEPTH_64F 64 const IPL_DEPTH_64F = 64; /* get reference to pixel at (col,row), for multi-channel images (col) should be multiplied by number of channels */ //C #define CV_IMAGE_ELEM( image, elemtype, row, col ) \ //C (((elemtype*)((image)->imageData + (image)->widthStep*(row)))[(col)]) auto CV_IMAGE_ELEM(I,E,R,C)(I* image, T elemtype, R row, C col ) { return ((cast(E*)((image).imageData + (image).widthStep*(row)))[(col)]); } /****************************************************************************************\ * Matrix type (CvMat) * \****************************************************************************************/ //C #define CV_CN_MAX 64 //C #define CV_CN_SHIFT 3 //C #define CV_DEPTH_MAX (1 << CV_CN_SHIFT) const CV_CN_MAX = 64; const CV_CN_SHIFT = 3; const CV_DEPTH_MAX = (1 << CV_CN_SHIFT); //C #define CV_8U 0 //C #define CV_8S 1 //C #define CV_16U 2 //C #define CV_16S 3 //C #define CV_32S 4 //C #define CV_32F 5 //C #define CV_64F 6 //C #define CV_USRTYPE1 7 const CV_8U = 0; const CV_8S = 1; const CV_16U = 2; const CV_16S = 3; const CV_32S = 4; const CV_32F = 5; const CV_64F = 6; const CV_USRTYPE1 = 7; //C #define CV_MAT_DEPTH_MASK (CV_DEPTH_MAX - 1) //C #define CV_MAT_DEPTH(flags) ((flags) & CV_MAT_DEPTH_MASK) const CV_MAT_DEPTH_MASK = (CV_DEPTH_MAX - 1); auto CV_MAT_DEPTH(F)(F flags) { return ((flags) & CV_MAT_DEPTH_MASK); } //C #define CV_MAKETYPE(depth,cn) (CV_MAT_DEPTH(depth) + (((cn)-1) << CV_CN_SHIFT)) //C #define CV_MAKE_TYPE CV_MAKETYPE int CV_MAKETYPE(D,C)(D depth,C cn) { return (CV_MAT_DEPTH(depth) + (((cn)-1) << CV_CN_SHIFT)); } alias CV_MAKETYPE CV_MAKE_TYPE; //C #define CV_8UC1 CV_MAKETYPE(CV_8U,1) //C #define CV_8UC2 CV_MAKETYPE(CV_8U,2) //C #define CV_8UC3 CV_MAKETYPE(CV_8U,3) //C #define CV_8UC4 CV_MAKETYPE(CV_8U,4) //C #define CV_8UC(n) CV_MAKETYPE(CV_8U,(n)) const CV_8UC1 = CV_MAKETYPE(CV_8U,1); const CV_8UC2 = CV_MAKETYPE(CV_8U,2); const CV_8UC3 = CV_MAKETYPE(CV_8U,3); const CV_8UC4 = CV_MAKETYPE(CV_8U,4); auto CV_8UC(T)(T n) { return CV_MAKETYPE(CV_8U,(n)); } //C #define CV_8SC1 CV_MAKETYPE(CV_8S,1) //C #define CV_8SC2 CV_MAKETYPE(CV_8S,2) //C #define CV_8SC3 CV_MAKETYPE(CV_8S,3) //C #define CV_8SC4 CV_MAKETYPE(CV_8S,4) //C #define CV_8SC(n) CV_MAKETYPE(CV_8S,(n)) const CV_8SC1 = CV_MAKETYPE(CV_8S,1); const CV_8SC2 = CV_MAKETYPE(CV_8S,2); const CV_8SC3 = CV_MAKETYPE(CV_8S,3); const CV_8SC4 = CV_MAKETYPE(CV_8S,4); auto CV_8SC(T)(n) { return CV_MAKETYPE(CV_8S,(n)); } //C #define CV_16UC1 CV_MAKETYPE(CV_16U,1) //C #define CV_16UC2 CV_MAKETYPE(CV_16U,2) //C #define CV_16UC3 CV_MAKETYPE(CV_16U,3) //C #define CV_16UC4 CV_MAKETYPE(CV_16U,4) //C #define CV_16UC(n) CV_MAKETYPE(CV_16U,(n)) const CV_16UC1 = CV_MAKETYPE(CV_16U,1); const CV_16UC2 = CV_MAKETYPE(CV_16U,2); const CV_16UC3 = CV_MAKETYPE(CV_16U,3); const CV_16UC4 = CV_MAKETYPE(CV_16U,4); auto CV_16UC(T)(n) { return CV_MAKETYPE(CV_16U,(n)); } //C #define CV_16SC1 CV_MAKETYPE(CV_16S,1) //C #define CV_16SC2 CV_MAKETYPE(CV_16S,2) //C #define CV_16SC3 CV_MAKETYPE(CV_16S,3) //C #define CV_16SC4 CV_MAKETYPE(CV_16S,4) //C #define CV_16SC(n) CV_MAKETYPE(CV_16S,(n)) const CV_16SC1 = CV_MAKETYPE(CV_16S,1); const CV_16SC2 = CV_MAKETYPE(CV_16S,2); const CV_16SC3 = CV_MAKETYPE(CV_16S,3); const CV_16SC4 = CV_MAKETYPE(CV_16S,4); auto CV_16SC(T)(n) { return CV_MAKETYPE(CV_16S,(n)); } //C #define CV_32SC1 CV_MAKETYPE(CV_32S,1) //C #define CV_32SC2 CV_MAKETYPE(CV_32S,2) //C #define CV_32SC3 CV_MAKETYPE(CV_32S,3) //C #define CV_32SC4 CV_MAKETYPE(CV_32S,4) //C #define CV_32SC(n) CV_MAKETYPE(CV_32S,(n)) const CV_32SC1 = CV_MAKETYPE(CV_32S,1); const CV_32SC2 = CV_MAKETYPE(CV_32S,2); const CV_32SC3 = CV_MAKETYPE(CV_32S,3); const CV_32SC4 = CV_MAKETYPE(CV_32S,4); auto CV_32SC(T)(n) { return CV_MAKETYPE(CV_32S,(n)); } //C #define CV_32FC1 CV_MAKETYPE(CV_32F,1) //C #define CV_32FC2 CV_MAKETYPE(CV_32F,2) //C #define CV_32FC3 CV_MAKETYPE(CV_32F,3) //C #define CV_32FC4 CV_MAKETYPE(CV_32F,4) //C #define CV_32FC(n) CV_MAKETYPE(CV_32F,(n)) const CV_32FC1 = CV_MAKETYPE(CV_32F,1); const CV_32FC2 = CV_MAKETYPE(CV_32F,2); const CV_32FC3 = CV_MAKETYPE(CV_32F,3); const CV_32FC4 = CV_MAKETYPE(CV_32F,4); auto CV_32FC(T)(n) { return CV_MAKETYPE(CV_32F,(n)); } //C #define CV_64FC1 CV_MAKETYPE(CV_64F,1) //C #define CV_64FC2 CV_MAKETYPE(CV_64F,2) //C #define CV_64FC3 CV_MAKETYPE(CV_64F,3) //C #define CV_64FC4 CV_MAKETYPE(CV_64F,4) //C #define CV_64FC(n) CV_MAKETYPE(CV_64F,(n)) const CV_64FC1 = CV_MAKETYPE(CV_64F,1); const CV_64FC2 = CV_MAKETYPE(CV_64F,2); const CV_64FC3 = CV_MAKETYPE(CV_64F,3); const CV_64FC4 = CV_MAKETYPE(CV_64F,4); auto CV_64FC(T)(n) { return CV_MAKETYPE(CV_64F,(n)); } //C #define CV_AUTO_STEP 0x7fffffff //C #define CV_WHOLE_ARR cvSlice( 0, 0x3fffffff ) const CV_AUTO_STEP = 0x7fffffff; const CvSlice CV_WHOLE_ARR = cvSlice( 0, 0x3fffffff ); //C #define CV_MAT_CN_MASK ((CV_CN_MAX - 1) << CV_CN_SHIFT) //C #define CV_MAT_CN(flags) ((((flags) & CV_MAT_CN_MASK) >> CV_CN_SHIFT) + 1) //C #define CV_MAT_TYPE_MASK (CV_DEPTH_MAX*CV_CN_MAX - 1) //C #define CV_MAT_TYPE(flags) ((flags) & CV_MAT_TYPE_MASK) //C #define CV_MAT_CONT_FLAG_SHIFT 14 //C #define CV_MAT_CONT_FLAG (1 << CV_MAT_CONT_FLAG_SHIFT) //C #define CV_IS_MAT_CONT(flags) ((flags) & CV_MAT_CONT_FLAG) //C #define CV_IS_CONT_MAT CV_IS_MAT_CONT //C #define CV_MAT_TEMP_FLAG_SHIFT 15 //C #define CV_MAT_TEMP_FLAG (1 << CV_MAT_TEMP_FLAG_SHIFT) //C #define CV_IS_TEMP_MAT(flags) ((flags) & CV_MAT_TEMP_FLAG) const CV_MAT_CN_MASK = ((CV_CN_MAX - 1) << CV_CN_SHIFT); auto CV_MAT_CN(T)(T flags){return ((((flags) & CV_MAT_CN_MASK) >> CV_CN_SHIFT) + 1);} const CV_MAT_TYPE_MASK = (CV_DEPTH_MAX*CV_CN_MAX - 1); auto CV_MAT_TYPE(T)(T flags){return ((flags) & CV_MAT_TYPE_MASK);} const CV_MAT_CONT_FLAG_SHIFT = 14; const CV_MAT_CONT_FLAG = (1 << CV_MAT_CONT_FLAG_SHIFT); auto CV_IS_MAT_CONT(T)(T flags){return ((flags) & CV_MAT_CONT_FLAG);} alias CV_IS_MAT_CONT CV_IS_CONT_MAT; const CV_MAT_TEMP_FLAG_SHIFT = 15; const CV_MAT_TEMP_FLAG = (1 << CV_MAT_TEMP_FLAG_SHIFT); auto CV_IS_TEMP_MAT(T)(T flags){return ((flags) & CV_MAT_TEMP_FLAG);} //C #define CV_MAGIC_MASK 0xFFFF0000 //C #define CV_MAT_MAGIC_VAL 0x42420000 //C #define CV_TYPE_NAME_MAT "opencv-matrix" const CV_MAGIC_MASK = 0xFFFF0000; const CV_MAT_MAGIC_VAL = 0x42420000; const CV_TYPE_NAME_MAT = "opencv-matrix"; //C typedef struct CvMat //C { //C int type; //C int step; //C //C /* for internal use only */ //C int* refcount; //C int hdr_refcount; //C //C union //C { //C uchar* ptr; //C short* s; //C int* i; //C float* fl; //C double* db; //C } data; //C //C #ifdef __cplusplus //C union //C { //C int rows; //C int height; //C }; //C //C union //C { //C int cols; //C int width; //C }; //C #else //C int rows; //C int cols; //C #endif //C //C } //C CvMat; struct CvMat { int type; int step; /* for internal use only */ int* refcount; int hdr_refcount; union DATA { uchar* ptr; short* s; int* i; float* fl; double* db; } DATA data; int rows; int cols; } //C #define CV_IS_MAT_HDR(mat) \ //C ((mat) != NULL && \ //C (((const CvMat*)(mat))->type & CV_MAGIC_MASK) == CV_MAT_MAGIC_VAL && \ //C ((const CvMat*)(mat))->cols > 0 && ((const CvMat*)(mat))->rows > 0) auto CV_IS_MAT_HDR(T)(T mat) { return ((mat) !is null && ((cast(const(CvMat)*)(mat)).type & CV_MAGIC_MASK) == CV_MAT_MAGIC_VAL && (cast(const(CvMat)*)(mat)).cols > 0 && (cast(const(CvMat)*)(mat)).rows > 0); } //C #define CV_IS_MAT(mat) \ //C (CV_IS_MAT_HDR(mat) && ((const CvMat*)(mat))->data.ptr != NULL) auto CV_IS_MAT(T)(T mat) { return (CV_IS_MAT_HDR(mat) && (cast(const(CvMat)*)(mat)).data.ptr !is null); } //C #define CV_IS_MASK_ARR(mat) \ //C (((mat)->type & (CV_MAT_TYPE_MASK & ~CV_8SC1)) == 0) auto CV_IS_MASK_ARR(T)(T mat) { return (((mat).type & (CV_MAT_TYPE_MASK & ~CV_8SC1)) == 0); } //C #define CV_ARE_TYPES_EQ(mat1, mat2) \ //C ((((mat1)->type ^ (mat2)->type) & CV_MAT_TYPE_MASK) == 0) auto CV_ARE_TYPES_EQ(T,U)(T mat1, U mat2) { return ((((mat1).type ^ (mat2).type) & CV_MAT_TYPE_MASK) == 0); } //C #define CV_ARE_CNS_EQ(mat1, mat2) \ //C ((((mat1)->type ^ (mat2)->type) & CV_MAT_CN_MASK) == 0) auto CV_ARE_CNS_EQ(T,U)(T mat1, U mat2) { return ((((mat1).type ^ (mat2).type) & CV_MAT_CN_MASK) == 0); } //C #define CV_ARE_DEPTHS_EQ(mat1, mat2) \ //C ((((mat1)->type ^ (mat2)->type) & CV_MAT_DEPTH_MASK) == 0) auto CV_ARE_DEPTHS_EQ(T,U)(T mat1, U mat2) { return ((((mat1).type ^ (mat2).type) & CV_MAT_DEPTH_MASK) == 0); } //C #define CV_ARE_SIZES_EQ(mat1, mat2) \ //C ((mat1)->rows == (mat2)->rows && (mat1)->cols == (mat2)->cols) auto CV_ARE_SIZES_EQ(T,U)(T mat1, U mat2) { return ((mat1).rows == (mat2).rows && (mat1).cols == (mat2).cols); } //C #define CV_IS_MAT_CONST(mat) \ //C (((mat)->rows|(mat)->cols) == 1) auto CV_IS_MAT_CONST(T)(T mat) { return (((mat).rows|(mat).cols) == 1); } /* Size of each channel item, 0x124489 = 1000 0100 0100 0010 0010 0001 0001 ~ array of sizeof(arr_type_elem) */ //C #define CV_ELEM_SIZE1(type) \ //C ((((sizeof(size_t)<<28)|0x8442211) >> CV_MAT_DEPTH(type)*4) & 15) auto CV_ELEM_SIZE1(T)(T type) { return ((((size_t.sizeof<<28)|0x8442211) >> CV_MAT_DEPTH(type)*4) & 15); } /* 0x3a50 = 11 10 10 01 01 00 00 ~ array of log2(sizeof(arr_type_elem)) */ //C #define CV_ELEM_SIZE(type) \ //C (CV_MAT_CN(type) << ((((sizeof(size_t)/4+1)*16384|0x3a50) >> CV_MAT_DEPTH(type)*2) & 3)) auto CV_ELEM_SIZE(T)(T type) { return (CV_MAT_CN(type) << ((((size_t.sizeof/4+1)*16384|0x3a50) >> CV_MAT_DEPTH(type)*2) & 3)); } /* Inline constructor. No data is allocated internally!!! * (Use together with cvCreateData, or use cvCreateMat instead to * get a matrix with allocated data): */ //C CV_INLINE CvMat cvMat( int rows, int cols, int type, void* data CV_DEFAULT(NULL)) //C { //C CvMat m; //C //C assert( (unsigned)CV_MAT_DEPTH(type) <= CV_64F ); //C type = CV_MAT_TYPE(type); //C m.type = CV_MAT_MAGIC_VAL | CV_MAT_CONT_FLAG | type; //C m.cols = cols; //C m.rows = rows; //C m.step = m.cols*CV_ELEM_SIZE(type); //C m.data.ptr = (uchar*)data; //C m.refcount = NULL; //C m.hdr_refcount = 0; //C //C return m; //C } CvMat cvMat( int rows, int cols, int type, void* data = null) { CvMat m; assert( cast(uint)CV_MAT_DEPTH(type) <= CV_64F ); type = CV_MAT_TYPE(type); m.type = CV_MAT_MAGIC_VAL | CV_MAT_CONT_FLAG | type; m.cols = cols; m.rows = rows; m.step = m.cols*CV_ELEM_SIZE(type); m.data.ptr = cast(uchar*)data; m.refcount = null; m.hdr_refcount = 0; return m; } //C #define CV_MAT_ELEM_PTR_FAST( mat, row, col, pix_size ) \ //C (assert( (unsigned)(row) < (unsigned)(mat).rows && \ //C (unsigned)(col) < (unsigned)(mat).cols ), \ //C (mat).data.ptr + (size_t)(mat).step*(row) + (pix_size)*(col)) auto CV_MAT_ELEM_PTR_FAST(M,R,C,P)( M mat, R row, C col, P pix_size ) { return (assert( cast(uint)(row) < cast(uint)(mat).rows && cast(uint)(col) < cast(uint)(mat).cols ), (mat).data.ptr + cast(size_t)(mat).step*(row) + (pix_size)*(col)); } //C #define CV_MAT_ELEM_PTR( mat, row, col ) \ //C CV_MAT_ELEM_PTR_FAST( mat, row, col, CV_ELEM_SIZE((mat).type) ) auto CV_MAT_ELEM_PTR(M,R,C)( M mat, R row, C col ) { return CV_MAT_ELEM_PTR_FAST( mat, row, col, CV_ELEM_SIZE((mat).type) ); } //C #define CV_MAT_ELEM( mat, elemtype, row, col ) \ //C (*(elemtype*)CV_MAT_ELEM_PTR_FAST( mat, row, col, sizeof(elemtype))) auto CV_MAT_ELEM(M,E,R,C)( M mat, E elemtype, R row, C col ) { return (*cast(E*)CV_MAT_ELEM_PTR_FAST( mat, row, col, sizeof(elemtype))); } //C CV_INLINE double cvmGet( const CvMat* mat, int row, int col ) //C { //C int type; //C //C type = CV_MAT_TYPE(mat->type); //C assert( (unsigned)row < (unsigned)mat->rows && //C (unsigned)col < (unsigned)mat->cols ); //C //C if( type == CV_32FC1 ) //C return ((float*)(mat->data.ptr + (size_t)mat->step*row))[col]; //C else //C { //C assert( type == CV_64FC1 ); //C return ((double*)(mat->data.ptr + (size_t)mat->step*row))[col]; //C } //C } double cvmGet( const(CvMat)* mat, int row, int col ) { int type; type = CV_MAT_TYPE(mat.type); assert( cast(uint)row < cast(uint)mat.rows && cast(uint)col < cast(uint)mat.cols ); if( type == CV_32FC1 ) return (cast(float*)(mat.data.ptr + cast(size_t)mat.step*row))[col]; else { assert( type == CV_64FC1 ); return (cast(double*)(mat.data.ptr + cast(size_t)mat.step*row))[col]; } } //C CV_INLINE void cvmSet( CvMat* mat, int row, int col, double value ) //C { //C int type; //C type = CV_MAT_TYPE(mat->type); //C assert( (unsigned)row < (unsigned)mat->rows && //C (unsigned)col < (unsigned)mat->cols ); //C //C if( type == CV_32FC1 ) //C ((float*)(mat->data.ptr + (size_t)mat->step*row))[col] = (float)value; //C else //C { //C assert( type == CV_64FC1 ); //C ((double*)(mat->data.ptr + (size_t)mat->step*row))[col] = (double)value; //C } //C } void cvmSet( CvMat* mat, int row, int col, double value ) { int type; type = CV_MAT_TYPE(mat.type); assert( cast(uint)row < cast(uint)mat.rows && cast(uint)col < cast(uint)mat.cols ); if( type == CV_32FC1 ) (cast(float*)(mat.data.ptr + cast(size_t)mat.step*row))[col] = cast(float)value; else { assert( type == CV_64FC1 ); (cast(double*)(mat.data.ptr + cast(size_t)mat.step*row))[col] = cast(double)value; } } //C CV_INLINE int cvIplDepth( int type ) //C { //C int depth = CV_MAT_DEPTH(type); //C return CV_ELEM_SIZE1(depth)*8 | (depth == CV_8S || depth == CV_16S || //C depth == CV_32S ? IPL_DEPTH_SIGN : 0); //C } int cvIplDepth( int type ) { int depth = CV_MAT_DEPTH(type); return CV_ELEM_SIZE1(depth)*8 | (depth == CV_8S || depth == CV_16S || depth == CV_32S ? IPL_DEPTH_SIGN : 0); } /****************************************************************************************\ * Multi-dimensional dense array (CvMatND) * \****************************************************************************************/ //C #define CV_MATND_MAGIC_VAL 0x42430000 //C #define CV_TYPE_NAME_MATND "opencv-nd-matrix" const CV_MATND_MAGIC_VAL = 0x42430000; const CV_TYPE_NAME_MATND = "opencv-nd-matrix"; //C #define CV_MAX_DIM 32 //C #define CV_MAX_DIM_HEAP (1 << 16) const CV_MAX_DIM = 32; const CV_MAX_DIM_HEAP = (1 << 16); //C typedef struct CvMatND //C { //C int type; //C int dims; //C //C int* refcount; //C int hdr_refcount; //C //C union //C { //C uchar* ptr; //C float* fl; //C double* db; //C int* i; //C short* s; //C } data; //C //C struct //C { //C int size; //C int step; //C } //C dim[CV_MAX_DIM]; //C } //C CvMatND; struct CvMatND { int type; int dims; int* refcount; int hdr_refcount; union DATA { uchar* ptr; float* fl; double* db; int* i; short* s; } DATA data; struct DIM { int size; int step; } DIM dim[CV_MAX_DIM]; } //C #define CV_IS_MATND_HDR(mat) \ //C ((mat) != NULL && (((const CvMatND*)(mat))->type & CV_MAGIC_MASK) == CV_MATND_MAGIC_VAL) auto CV_IS_MATND_HDR(T)(T mat) { return ((mat) !is null && ((cast(const(CvMatND)*)(mat)).type & CV_MAGIC_MASK) == CV_MATND_MAGIC_VAL); } //C #define CV_IS_MATND(mat) \ //C (CV_IS_MATND_HDR(mat) && ((const CvMatND*)(mat))->data.ptr != NULL) auto CV_IS_MATND(T)(T mat) { return (CV_IS_MATND_HDR(mat) && (cast(const(CvMatND)*)(mat)).data.ptr !is null); } /****************************************************************************************\ * Multi-dimensional sparse array (CvSparseMat) * \****************************************************************************************/ //C #define CV_SPARSE_MAT_MAGIC_VAL 0x42440000 //C #define CV_TYPE_NAME_SPARSE_MAT "opencv-sparse-matrix" const CV_SPARSE_MAT_MAGIC_VAL = 0x42440000; const CV_TYPE_NAME_SPARSE_MAT = "opencv-sparse-matrix"; //C struct CvSet; //C typedef struct CvSparseMat //C { //C int type; //C int dims; //C int* refcount; //C int hdr_refcount; //C //C struct CvSet* heap; //C void** hashtable; //C int hashsize; //C int valoffset; //C int idxoffset; //C int size[CV_MAX_DIM]; //C } //C CvSparseMat; struct CvSparseMat { int type; int dims; int* refcount; int hdr_refcount; CvSet* heap; void** hashtable; int hashsize; int valoffset; int idxoffset; int size[CV_MAX_DIM]; } //C #define CV_IS_SPARSE_MAT_HDR(mat) \ //C ((mat) != NULL && \ //C (((const CvSparseMat*)(mat))->type & CV_MAGIC_MASK) == CV_SPARSE_MAT_MAGIC_VAL) auto CV_IS_SPARSE_MAT_HDR(T)(T mat) { return ((mat) !is null && ((cast(const(CvSparseMat)*)(mat)).type & CV_MAGIC_MASK) == CV_SPARSE_MAT_MAGIC_VAL); } //C #define CV_IS_SPARSE_MAT(mat) \ //C CV_IS_SPARSE_MAT_HDR(mat) auto CV_IS_SPARSE_MAT(T)(T mat) { return CV_IS_SPARSE_MAT_HDR(mat); } /**************** iteration through a sparse array *****************/ //C typedef struct CvSparseNode //C { //C unsigned hashval; //C struct CvSparseNode* next; //C } //C CvSparseNode; struct CvSparseNode { uint hashval; CvSparseNode* next; } //C typedef struct CvSparseMatIterator //C { //C CvSparseMat* mat; //C CvSparseNode* node; //C int curidx; //C } //C CvSparseMatIterator; struct CvSparseMatIterator { CvSparseMat* mat; CvSparseNode* node; int curidx; } //C #define CV_NODE_VAL(mat,node) ((void*)((uchar*)(node) + (mat)->valoffset)) //C #define CV_NODE_IDX(mat,node) ((int*)((uchar*)(node) + (mat)->idxoffset)) auto CV_NODE_VAL(T,U)(T mat, U node) { return (cast(void*)(cast(uchar*)(node) + (mat).valoffset)); } auto CV_NODE_IDX(T,U)(T mat, U node) { return (cast(int*)(cast(uchar*)(node) + (mat).idxoffset)); } /****************************************************************************************\ * Histogram * \****************************************************************************************/ //C typedef int CvHistType; alias int CvHistType; //C #define CV_HIST_MAGIC_VAL 0x42450000 //C #define CV_HIST_UNIFORM_FLAG (1 << 10) const CV_HIST_MAGIC_VAL = 0x42450000; const CV_HIST_UNIFORM_FLAG = (1 << 10); /* indicates whether bin ranges are set already or not */ //C #define CV_HIST_RANGES_FLAG (1 << 11) const CV_HIST_RANGES_FLAG = (1 << 11); //C #define CV_HIST_ARRAY 0 //C #define CV_HIST_SPARSE 1 //C #define CV_HIST_TREE CV_HIST_SPARSE const CV_HIST_ARRAY = 0; const CV_HIST_SPARSE = 1; const CV_HIST_TREE = CV_HIST_SPARSE; /* should be used as a parameter only, it turns to CV_HIST_UNIFORM_FLAG of hist->type */ //C #define CV_HIST_UNIFORM 1 const CV_HIST_UNIFORM = 1; //C typedef struct CvHistogram //C { //C int type; //C CvArr* bins; //C float thresh[CV_MAX_DIM][2]; /* For uniform histograms. */ //C float** thresh2; /* For non-uniform histograms. */ //C CvMatND mat; /* Embedded matrix header for array histograms. */ //C } //C CvHistogram; struct CvHistogram { int type; CvArr* bins; float thresh[CV_MAX_DIM][2]; /* For uniform histograms. */ float** thresh2; /* For non-uniform histograms. */ CvMatND mat; /* Embedded matrix header for array histograms. */ } //C #define CV_IS_HIST( hist ) \ //C ((hist) != NULL && \ //C (((CvHistogram*)(hist))->type & CV_MAGIC_MASK) == CV_HIST_MAGIC_VAL && \ //C (hist)->bins != NULL) auto CV_IS_HIST(T)(T hist ) { return ((hist) !is nullL && ((cast(CvHistogram*)(hist)).type & CV_MAGIC_MASK) == CV_HIST_MAGIC_VAL && (hist).bins !is null); } //C #define CV_IS_UNIFORM_HIST( hist ) \ //C (((hist)->type & CV_HIST_UNIFORM_FLAG) != 0) auto CV_IS_UNIFORM_HIST(T)( T hist ) { return (((hist).type & CV_HIST_UNIFORM_FLAG) != 0); } //C #define CV_IS_SPARSE_HIST( hist ) \ //C CV_IS_SPARSE_MAT((hist)->bins) auto CV_IS_SPARSE_HIST(T)( T hist ) { return CV_IS_SPARSE_MAT((hist).bins); } //C #define CV_HIST_HAS_RANGES( hist ) \ //C (((hist)->type & CV_HIST_RANGES_FLAG) != 0) auto CV_HIST_HAS_RANGES(T)( T hist ) { return (((hist).type & CV_HIST_RANGES_FLAG) != 0); } /****************************************************************************************\ * Other supplementary data type definitions * \****************************************************************************************/ /*************************************** CvRect *****************************************/ //C typedef struct CvRect //C { //C int x; //C int y; //C int width; //C int height; //C } //C CvRect; struct CvRect { int x; int y; int width; int height; } //C CV_INLINE CvRect cvRect( int x, int y, int width, int height ) //C { //C CvRect r; //C //C r.x = x; //C r.y = y; //C r.width = width; //C r.height = height; //C //C return r; //C } CvRect cvRect( int x, int y, int width, int height ) { CvRect r; r.x = x; r.y = y; r.width = width; r.height = height; return r; } //C CV_INLINE IplROI cvRectToROI( CvRect rect, int coi ) //C { //C IplROI roi; //C roi.xOffset = rect.x; //C roi.yOffset = rect.y; //C roi.width = rect.width; //C roi.height = rect.height; //C roi.coi = coi; //C //C return roi; //C } IplROI cvRectToROI( CvRect rect, int coi ) { IplROI roi; roi.xOffset = rect.x; roi.yOffset = rect.y; roi.width = rect.width; roi.height = rect.height; roi.coi = coi; return roi; } //C CV_INLINE CvRect cvROIToRect( IplROI roi ) //C { //C return cvRect( roi.xOffset, roi.yOffset, roi.width, roi.height ); //C } CvRect cvROIToRect( IplROI roi ) { return cvRect( roi.xOffset, roi.yOffset, roi.width, roi.height ); } /*********************************** CvTermCriteria *************************************/ //C #define CV_TERMCRIT_ITER 1 //C #define CV_TERMCRIT_NUMBER CV_TERMCRIT_ITER //C #define CV_TERMCRIT_EPS 2 const CV_TERMCRIT_ITER = 1; const CV_TERMCRIT_NUMBER = CV_TERMCRIT_ITER; const CV_TERMCRIT_EPS = 2; //C typedef struct CvTermCriteria //C { //C int type; /* may be combination of //C CV_TERMCRIT_ITER //C CV_TERMCRIT_EPS */ //C int max_iter; //C double epsilon; //C } //C CvTermCriteria; struct CvTermCriteria { int type; /* may be combination of CV_TERMCRIT_ITER CV_TERMCRIT_EPS */ int max_iter; double epsilon; } //C CV_INLINE CvTermCriteria cvTermCriteria( int type, int max_iter, double epsilon ) //C { //C CvTermCriteria t; //C //C t.type = type; //C t.max_iter = max_iter; //C t.epsilon = (float)epsilon; //C //C return t; //C } CvTermCriteria cvTermCriteria( int type, int max_iter, double epsilon ) { CvTermCriteria t; t.type = type; t.max_iter = max_iter; t.epsilon = cast(float)epsilon; return t; } /******************************* CvPoint and variants ***********************************/ //C typedef struct CvPoint //C { //C int x; //C int y; //C } //C CvPoint; struct CvPoint { int x; int y; } //C CV_INLINE CvPoint cvPoint( int x, int y ) //C { //C CvPoint p; //C //C p.x = x; //C p.y = y; //C //C return p; //C } CvPoint cvPoint( int x, int y ) { CvPoint p; p.x = x; p.y = y; return p; } //C typedef struct CvPoint2D32f //C { //C float x; //C float y; //C } //C CvPoint2D32f; struct CvPoint2D32f { float x; float y; } //C CV_INLINE CvPoint2D32f cvPoint2D32f( double x, double y ) //C { //C CvPoint2D32f p; //C //C p.x = (float)x; //C p.y = (float)y; //C //C return p; //C } CvPoint2D32f cvPoint2D32f( double x, double y ) { CvPoint2D32f p; p.x = cast(float)x; p.y = cast(float)y; return p; } //C CV_INLINE CvPoint2D32f cvPointTo32f( CvPoint point ) //C { //C return cvPoint2D32f( (float)point.x, (float)point.y ); //C } CvPoint2D32f cvPointTo32f( CvPoint point ) { return cvPoint2D32f( cast(float)point.x, cast(float)point.y ); } //C CV_INLINE CvPoint cvPointFrom32f( CvPoint2D32f point ) //C { //C CvPoint ipt; //C ipt.x = cvRound(point.x); //C ipt.y = cvRound(point.y); //C //C return ipt; //C } CvPoint cvPointFrom32f( CvPoint2D32f point ) { CvPoint ipt; ipt.x = cvRound(point.x); ipt.y = cvRound(point.y); return ipt; } //C typedef struct CvPoint3D32f //C { //C float x; //C float y; //C float z; //C } //C CvPoint3D32f; struct CvPoint3D32f { float x; float y; float z; } //C CV_INLINE CvPoint3D32f cvPoint3D32f( double x, double y, double z ) //C { //C CvPoint3D32f p; //C //C p.x = (float)x; //C p.y = (float)y; //C p.z = (float)z; //C //C return p; //C } CvPoint3D32f cvPoint3D32f( double x, double y, double z ) { CvPoint3D32f p; p.x = cast(float)x; p.y = cast(float)y; p.z = cast(float)z; return p; } //C typedef struct CvPoint2D64f //C { //C double x; //C double y; //C } //C CvPoint2D64f; struct CvPoint2D64f { double x; double y; } //C CV_INLINE CvPoint2D64f cvPoint2D64f( double x, double y ) //C { //C CvPoint2D64f p; //C //C p.x = x; //C p.y = y; //C //C return p; //C } CvPoint2D64f cvPoint2D64f( double x, double y ) { CvPoint2D64f p; p.x = x; p.y = y; return p; } //C typedef struct CvPoint3D64f //C { //C double x; //C double y; //C double z; //C } //C CvPoint3D64f; struct CvPoint3D64f { double x; double y; double z; } //C CV_INLINE CvPoint3D64f cvPoint3D64f( double x, double y, double z ) //C { //C CvPoint3D64f p; //C //C p.x = x; //C p.y = y; //C p.z = z; //C //C return p; //C } CvPoint3D64f cvPoint3D64f( double x, double y, double z ) { CvPoint3D64f p; p.x = x; p.y = y; p.z = z; return p; } /******************************** CvSize's & CvBox **************************************/ //C typedef struct //C { //C int width; //C int height; //C } //C CvSize; struct CvSize { int width; int height; } //C CV_INLINE CvSize cvSize( int width, int height ) //C { //C CvSize s; //C //C s.width = width; //C s.height = height; //C //C return s; //C } CvSize cvSize( int width, int height ) { CvSize s; s.width = width; s.height = height; return s; } //C typedef struct CvSize2D32f //C { //C float width; //C float height; //C } //C CvSize2D32f; struct CvSize2D32f { float width; float height; } //C CV_INLINE CvSize2D32f cvSize2D32f( double width, double height ) //C { //C CvSize2D32f s; //C //C s.width = (float)width; //C s.height = (float)height; //C //C return s; //C } CvSize2D32f cvSize2D32f( double width, double height ) { CvSize2D32f s; s.width = cast(float)width; s.height = cast(float)height; return s; } //C typedef struct CvBox2D //C { //C CvPoint2D32f center; /* Center of the box. */ //C CvSize2D32f size; /* Box width and length. */ //C float angle; /* Angle between the horizontal axis */ //C /* and the first side (i.e. length) in degrees */ //C } //C CvBox2D; struct CvBox2D { CvPoint2D32f center; /* Center of the box. */ CvSize2D32f size; /* Box width and length. */ float angle; /* Angle between the horizontal axis */ /* and the first side (i.e. length) in degrees */ } /* Line iterator state: */ //C typedef struct CvLineIterator //C { //C /* Pointer to the current point: */ //C uchar* ptr; //C //C /* Bresenham algorithm state: */ //C int err; //C int plus_delta; //C int minus_delta; //C int plus_step; //C int minus_step; //C } //C CvLineIterator; struct CvLineIterator { /* Pointer to the current point: */ uchar* ptr; /* Bresenham algorithm state: */ int err; int plus_delta; int minus_delta; int plus_step; int minus_step; } /************************************* CvSlice ******************************************/ //C typedef struct CvSlice //C { //C int start_index, end_index; //C } //C CvSlice; struct CvSlice { int start_index; int end_index; } //C CV_INLINE CvSlice cvSlice( int start, int end ) //C { //C CvSlice slice; //C slice.start_index = start; //C slice.end_index = end; //C //C return slice; //C } CvSlice cvSlice( int start, int end ) { CvSlice slice; slice.start_index = start; slice.end_index = end; return slice; } //C #define CV_WHOLE_SEQ_END_INDEX 0x3fffffff //C #define CV_WHOLE_SEQ cvSlice(0, CV_WHOLE_SEQ_END_INDEX) const CV_WHOLE_SEQ_END_INDEX = 0x3fffffff; const CV_WHOLE_SEQ = cvSlice(0, CV_WHOLE_SEQ_END_INDEX); /************************************* CvScalar *****************************************/ //C typedef struct CvScalar //C { //C double val[4]; //C } //C CvScalar; struct CvScalar { double val[4]; } //C CV_INLINE CvScalar cvScalar( double val0, double val1 CV_DEFAULT(0), //C double val2 CV_DEFAULT(0), double val3 CV_DEFAULT(0)) //C { //C CvScalar scalar; //C scalar.val[0] = val0; scalar.val[1] = val1; //C scalar.val[2] = val2; scalar.val[3] = val3; //C return scalar; //C } CvScalar cvScalar( double val0, double val1 = 0, double val2 = 0, double val3 = 0) { CvScalar scalar; scalar.val[0] = val0; scalar.val[1] = val1; scalar.val[2] = val2; scalar.val[3] = val3; return scalar; } //C CV_INLINE CvScalar cvRealScalar( double val0 ) //C { //C CvScalar scalar; //C scalar.val[0] = val0; //C scalar.val[1] = scalar.val[2] = scalar.val[3] = 0; //C return scalar; //C } CvScalar cvRealScalar( double val0 ) { CvScalar scalar; scalar.val[0] = val0; scalar.val[1] = scalar.val[2] = scalar.val[3] = 0; return scalar; } //C CV_INLINE CvScalar cvScalarAll( double val0123 ) //C { //C CvScalar scalar; //C scalar.val[0] = val0123; //C scalar.val[1] = val0123; //C scalar.val[2] = val0123; //C scalar.val[3] = val0123; //C return scalar; //C } CvScalar cvScalarAll( double val0123 ) { CvScalar scalar; scalar.val[0] = val0123; scalar.val[1] = val0123; scalar.val[2] = val0123; scalar.val[3] = val0123; return scalar; } /****************************************************************************************\ * Dynamic Data structures * \****************************************************************************************/ /******************************** Memory storage ****************************************/ //C typedef struct CvMemBlock //C { //C struct CvMemBlock* prev; //C struct CvMemBlock* next; //C } //C CvMemBlock; struct CvMemBlock { CvMemBlock* prev; CvMemBlock* next; } //C #define CV_STORAGE_MAGIC_VAL 0x42890000 const CV_STORAGE_MAGIC_VAL = 0x42890000; //C typedef struct CvMemStorage //C { //C int signature; //C CvMemBlock* bottom; /* First allocated block. */ //C CvMemBlock* top; /* Current memory block - top of the stack. */ //C struct CvMemStorage* parent; /* We get new blocks from parent as needed. */ //C int block_size; /* Block size. */ //C int free_space; /* Remaining free space in current block. */ //C } //C CvMemStorage; struct CvMemStorage { int signature; CvMemBlock* bottom; /* First allocated block. */ CvMemBlock* top; /* Current memory block - top of the stack. */ CvMemStorage* parent; /* We get new blocks from parent as needed. */ int block_size; /* Block size. */ int free_space; /* Remaining free space in current block. */ } //C #define CV_IS_STORAGE(storage) \ //C ((storage) != NULL && \ //C (((CvMemStorage*)(storage))->signature & CV_MAGIC_MASK) == CV_STORAGE_MAGIC_VAL) auto CV_IS_STORAGE(T)(T storage) { return ((storage) !is null && ((cast(CvMemStorage*)(storage)).signature & CV_MAGIC_MASK) == CV_STORAGE_MAGIC_VAL); } //C typedef struct CvMemStoragePos //C { //C CvMemBlock* top; //C int free_space; //C } //C CvMemStoragePos; struct CvMemStoragePos { CvMemBlock* top; int free_space; } /*********************************** Sequence *******************************************/ //C typedef struct CvSeqBlock //C { //C struct CvSeqBlock* prev; /* Previous sequence block. */ //C struct CvSeqBlock* next; /* Next sequence block. */ //C int start_index; /* Index of the first element in the block + */ //C /* sequence->first->start_index. */ //C int count; /* Number of elements in the block. */ //C schar* data; /* Pointer to the first element of the block. */ //C } //C CvSeqBlock; struct CvSeqBlock { CvSeqBlock* prev; /* Previous sequence block. */ CvSeqBlock* next; /* Next sequence block. */ int start_index; /* Index of the first element in the block + */ /* sequence->first->start_index. */ int count; /* Number of elements in the block. */ schar* data; /* Pointer to the first element of the block. */ } //C #define CV_TREE_NODE_FIELDS(node_type) \ //C int flags; /* Miscellaneous flags. */ \ //C int header_size; /* Size of sequence header. */ \ //C struct node_type* h_prev; /* Previous sequence. */ \ //C struct node_type* h_next; /* Next sequence. */ \ //C struct node_type* v_prev; /* 2nd previous sequence. */ \ //C struct node_type* v_next /* 2nd next sequence. */ template CV_TREE_NODE_FIELDS(node_type) { int flags; /* Miscellaneous flags. */ int header_size; /* Size of sequence header. */ node_type* h_prev; /* Previous sequence. */ node_type* h_next; /* Next sequence. */ node_type* v_prev; /* 2nd previous sequence. */ node_type* v_next; /* 2nd next sequence. */ } /* Read/Write sequence. Elements can be dynamically inserted to or deleted from the sequence. */ //C #define CV_SEQUENCE_FIELDS() \ //C CV_TREE_NODE_FIELDS(CvSeq); \ //C int total; /* Total number of elements. */ \ //C int elem_size; /* Size of sequence element in bytes. */ \ //C schar* block_max; /* Maximal bound of the last block. */ \ //C schar* ptr; /* Current write pointer. */ \ //C int delta_elems; /* Grow seq this many at a time. */ \ //C CvMemStorage* storage; /* Where the seq is stored. */ \ //C CvSeqBlock* free_blocks; /* Free blocks list. */ \ //C CvSeqBlock* first; /* Pointer to the first sequence block. */ template CV_SEQUENCE_FIELDS() { mixin CV_TREE_NODE_FIELDS!(CvSeq); int total; /* Total number of elements. */ int elem_size; /* Size of sequence element in bytes. */ schar* block_max; /* Maximal bound of the last block. */ schar* ptr; /* Current write pointer. */ int delta_elems; /* Grow seq this many at a time. */ CvMemStorage* storage; /* Where the seq is stored. */ CvSeqBlock* free_blocks; /* Free blocks list. */ CvSeqBlock* first; /* Pointer to the first sequence block. */ } //C typedef struct CvSeq //C { //C CV_SEQUENCE_FIELDS() //C } //C CvSeq; struct CvSeq { mixin CV_SEQUENCE_FIELDS; } //C #define CV_TYPE_NAME_SEQ "opencv-sequence" //C #define CV_TYPE_NAME_SEQ_TREE "opencv-sequence-tree" const CV_TYPE_NAME_SEQ = "opencv-sequence"; const CV_TYPE_NAME_SEQ_TREE = "opencv-sequence-tree"; /*************************************** Set ********************************************/ /* Set. Order is not preserved. There can be gaps between sequence elements. After the element has been inserted it stays in the same place all the time. The MSB(most-significant or sign bit) of the first field (flags) is 0 iff the element exists. */ //C #define CV_SET_ELEM_FIELDS(elem_type) \ //C int flags; \ //C struct elem_type* next_free; template CV_SET_ELEM_FIELDS(elem_type) { int flags; elem_type* next_free; } //C typedef struct CvSetElem //C { //C CV_SET_ELEM_FIELDS(CvSetElem) //C } //C CvSetElem; struct CvSetElem { mixin CV_SET_ELEM_FIELDS!(CvSetElem); } //C #define CV_SET_FIELDS() \ //C CV_SEQUENCE_FIELDS() \ //C CvSetElem* free_elems; \ //C int active_count; template CV_SET_FIELDS() { mixin CV_SEQUENCE_FIELDS; CvSetElem* free_elems; int active_count; } //C typedef struct CvSet //C { //C CV_SET_FIELDS() //C } //C CvSet; struct CvSet { mixin CV_SET_FIELDS; } //C #define CV_SET_ELEM_IDX_MASK ((1 << 26) - 1) //C #define CV_SET_ELEM_FREE_FLAG (1 << (sizeof(int)*8-1)) const CV_SET_ELEM_IDX_MASK = ((1 << 26) - 1); const CV_SET_ELEM_FREE_FLAG = (1 << (int.sizeof*8-1)); /* Checks whether the element pointed by ptr belongs to a set or not */ //C #define CV_IS_SET_ELEM( ptr ) (((CvSetElem*)(ptr))->flags >= 0) auto CV_IS_SET_ELEM(T)( ptr ) { return ((cast(CvSetElem*)(ptr)).flags >= 0); } /************************************* Graph ********************************************/ /* We represent a graph as a set of vertices. Vertices contain their adjacency lists (more exactly, pointers to first incoming or outcoming edge (or 0 if isolated vertex)). Edges are stored in another set. There is a singly-linked list of incoming/outcoming edges for each vertex. Each edge consists of o Two pointers to the starting and ending vertices (vtx[0] and vtx[1] respectively). A graph may be oriented or not. In the latter case, edges between vertex i to vertex j are not distinguished during search operations. o Two pointers to next edges for the starting and ending vertices, where next[0] points to the next edge in the vtx[0] adjacency list and next[1] points to the next edge in the vtx[1] adjacency list. */ //C #define CV_GRAPH_EDGE_FIELDS() \ //C int flags; \ //C float weight; \ //C struct CvGraphEdge* next[2]; \ //C struct CvGraphVtx* vtx[2]; template CV_GRAPH_EDGE_FIELDS() { int flags; float weight; CvGraphEdge* next[2]; CvGraphVtx* vtx[2]; } //C #define CV_GRAPH_VERTEX_FIELDS() \ //C int flags; \ //C struct CvGraphEdge* first; template CV_GRAPH_VERTEX_FIELDS() { int flags; CvGraphEdge* first; } //C typedef struct CvGraphEdge //C { //C CV_GRAPH_EDGE_FIELDS() //C } //C CvGraphEdge; struct CvGraphEdge { mixin CV_GRAPH_EDGE_FIELDS; } //C typedef struct CvGraphVtx //C { //C CV_GRAPH_VERTEX_FIELDS() //C } //C CvGraphVtx; struct CvGraphVtx { mixin CV_GRAPH_VERTEX_FIELDS; } //C typedef struct CvGraphVtx2D //C { //C CV_GRAPH_VERTEX_FIELDS() //C CvPoint2D32f* ptr; //C } //C CvGraphVtx2D; struct CvGraphVtx2D { mixin CV_GRAPH_VERTEX_FIELDS; CvPoint2D32f* ptr; } /* Graph is "derived" from the set (this is set a of vertices) and includes another set (edges) */ //C #define CV_GRAPH_FIELDS() \ //C CV_SET_FIELDS() \ //C CvSet* edges; template CV_GRAPH_FIELDS() { mixin CV_SET_FIELDS; CvSet* edges; } //C typedef struct CvGraph //C { //C CV_GRAPH_FIELDS() //C } //C CvGraph; struct CvGraph { mixin CV_GRAPH_FIELDS; } //C #define CV_TYPE_NAME_GRAPH "opencv-graph" const CV_TYPE_NAME_GRAPH = "opencv-graph"; /*********************************** Chain/Countour *************************************/ //C typedef struct CvChain //C { //C CV_SEQUENCE_FIELDS() //C CvPoint origin; //C } //C CvChain; struct CvChain { mixin CV_SEQUENCE_FIELDS; CvPoint origin; } //C #define CV_CONTOUR_FIELDS() \ //C CV_SEQUENCE_FIELDS() \ //C CvRect rect; \ //C int color; \ //C int reserved[3]; template CV_CONTOUR_FIELDS() { mixin CV_SEQUENCE_FIELDS; CvRect rect; int color; int reserved[3]; } //C typedef struct CvContour //C { //C CV_CONTOUR_FIELDS() //C } //C CvContour; struct CvContour { mixin CV_CONTOUR_FIELDS; } //C typedef CvContour CvPoint2DSeq; alias CvContour CvPoint2DSeq; /****************************************************************************************\ * Sequence types * \****************************************************************************************/ //C #define CV_SEQ_MAGIC_VAL 0x42990000 const CV_SEQ_MAGIC_VAL = 0x42990000; //C #define CV_IS_SEQ(seq) \ //C ((seq) != NULL && (((CvSeq*)(seq))->flags & CV_MAGIC_MASK) == CV_SEQ_MAGIC_VAL) auto CV_IS_SEQ(T)(T seq) { return ((seq) !is null && ((cast(CvSeq*)(seq)).flags & CV_MAGIC_MASK) == CV_SEQ_MAGIC_VAL); } //C #define CV_SET_MAGIC_VAL 0x42980000 //C #define CV_IS_SET(set) \ //C ((set) != NULL && (((CvSeq*)(set))->flags & CV_MAGIC_MASK) == CV_SET_MAGIC_VAL) const CV_SET_MAGIC_VAL = 0x42980000; auto CV_IS_SET(T)(T set) { return ((set) !is null && ((cast(CvSeq*)(set)).flags & CV_MAGIC_MASK) == CV_SET_MAGIC_VAL); } //C #define CV_SEQ_ELTYPE_BITS 9 //C #define CV_SEQ_ELTYPE_MASK ((1 << CV_SEQ_ELTYPE_BITS) - 1) const CV_SEQ_ELTYPE_BITS = 9; const CV_SEQ_ELTYPE_MASK = ((1 << CV_SEQ_ELTYPE_BITS) - 1); //C #define CV_SEQ_ELTYPE_POINT CV_32SC2 /* (x,y) */ //C #define CV_SEQ_ELTYPE_CODE CV_8UC1 /* freeman code: 0..7 */ //C #define CV_SEQ_ELTYPE_GENERIC 0 //C #define CV_SEQ_ELTYPE_PTR CV_USRTYPE1 //C #define CV_SEQ_ELTYPE_PPOINT CV_SEQ_ELTYPE_PTR /* &(x,y) */ //C #define CV_SEQ_ELTYPE_INDEX CV_32SC1 /* #(x,y) */ //C #define CV_SEQ_ELTYPE_GRAPH_EDGE 0 /* &next_o, &next_d, &vtx_o, &vtx_d */ //C #define CV_SEQ_ELTYPE_GRAPH_VERTEX 0 /* first_edge, &(x,y) */ //C #define CV_SEQ_ELTYPE_TRIAN_ATR 0 /* vertex of the binary tree */ //C #define CV_SEQ_ELTYPE_CONNECTED_COMP 0 /* connected component */ //C #define CV_SEQ_ELTYPE_POINT3D CV_32FC3 /* (x,y,z) */ const CV_SEQ_ELTYPE_POINT = CV_32SC2; /* (x,y) */ const CV_SEQ_ELTYPE_CODE = CV_8UC1; /* freeman code: 0..7 */ const CV_SEQ_ELTYPE_GENERIC = 0; const CV_SEQ_ELTYPE_PTR = CV_USRTYPE1; const CV_SEQ_ELTYPE_PPOINT = CV_SEQ_ELTYPE_PTR; /* &(x,y) */ const CV_SEQ_ELTYPE_INDEX = CV_32SC1; /* #(x,y) */ const CV_SEQ_ELTYPE_GRAPH_EDGE = 0; /* &next_o, &next_d, &vtx_o, &vtx_d */ const CV_SEQ_ELTYPE_GRAPH_VERTEX = 0; /* first_edge, &(x,y) */ const CV_SEQ_ELTYPE_TRIAN_ATR = 0; /* vertex of the binary tree */ const CV_SEQ_ELTYPE_CONNECTED_COMP = 0; /* connected component */ const CV_SEQ_ELTYPE_POINT3D = CV_32FC3; /* (x,y,z) */ //C #define CV_SEQ_KIND_BITS 3 //C #define CV_SEQ_KIND_MASK (((1 << CV_SEQ_KIND_BITS) - 1)<flags & CV_SEQ_ELTYPE_MASK) //C #define CV_SEQ_KIND( seq ) ((seq)->flags & CV_SEQ_KIND_MASK ) auto CV_SEQ_ELTYPE(T)( T seq ) { return ((seq).flags & CV_SEQ_ELTYPE_MASK); } auto CV_SEQ_KIND(T)( T seq ) { return ((seq).flags & CV_SEQ_KIND_MASK ); } /* flag checking */ //C #define CV_IS_SEQ_INDEX( seq ) ((CV_SEQ_ELTYPE(seq) == CV_SEQ_ELTYPE_INDEX) && \ //C (CV_SEQ_KIND(seq) == CV_SEQ_KIND_GENERIC)) auto CV_IS_SEQ_INDEX(T)( T seq ) { return ((CV_SEQ_ELTYPE(seq) == CV_SEQ_ELTYPE_INDEX) && (CV_SEQ_KIND(seq) == CV_SEQ_KIND_GENERIC)); } //C #define CV_IS_SEQ_CURVE( seq ) (CV_SEQ_KIND(seq) == CV_SEQ_KIND_CURVE) //C #define CV_IS_SEQ_CLOSED( seq ) (((seq)->flags & CV_SEQ_FLAG_CLOSED) != 0) //C #define CV_IS_SEQ_CONVEX( seq ) (((seq)->flags & CV_SEQ_FLAG_CONVEX) != 0) //C #define CV_IS_SEQ_HOLE( seq ) (((seq)->flags & CV_SEQ_FLAG_HOLE) != 0) //C #define CV_IS_SEQ_SIMPLE( seq ) ((((seq)->flags & CV_SEQ_FLAG_SIMPLE) != 0) || \ //C CV_IS_SEQ_CONVEX(seq)) auto CV_IS_SEQ_CURVE(T)( T seq ) { return (CV_SEQ_KIND(seq) == CV_SEQ_KIND_CURVE); } auto CV_IS_SEQ_CLOSED(T)( T seq ) { return (((seq).flags & CV_SEQ_FLAG_CLOSED) != 0); } auto CV_IS_SEQ_CONVEX(T)( T seq ) { return (((seq).flags & CV_SEQ_FLAG_CONVEX) != 0); } auto CV_IS_SEQ_HOLE(T)( T seq ) { return (((seq).flags & CV_SEQ_FLAG_HOLE) != 0); } auto CV_IS_SEQ_SIMPLE(T)( T seq ) { return ((((seq).flags & CV_SEQ_FLAG_SIMPLE) != 0) || CV_IS_SEQ_CONVEX(seq)); } /* type checking macros */ //C #define CV_IS_SEQ_POINT_SET( seq ) \ //C ((CV_SEQ_ELTYPE(seq) == CV_32SC2 || CV_SEQ_ELTYPE(seq) == CV_32FC2)) auto CV_IS_SEQ_POINT_SET(T)( seq ) { return ((CV_SEQ_ELTYPE(seq) == CV_32SC2 || CV_SEQ_ELTYPE(seq) == CV_32FC2)); } //C #define CV_IS_SEQ_POINT_SUBSET( seq ) \ //C (CV_IS_SEQ_INDEX( seq ) || CV_SEQ_ELTYPE(seq) == CV_SEQ_ELTYPE_PPOINT) auto CV_IS_SEQ_POINT_SUBSET(T)( seq ) { return (CV_IS_SEQ_INDEX( seq ) || CV_SEQ_ELTYPE(seq) == CV_SEQ_ELTYPE_PPOINT); } //C #define CV_IS_SEQ_POLYLINE( seq ) \ //C (CV_SEQ_KIND(seq) == CV_SEQ_KIND_CURVE && CV_IS_SEQ_POINT_SET(seq)) auto CV_IS_SEQ_POLYLINE(T)( T seq ) { return (CV_SEQ_KIND(seq) == CV_SEQ_KIND_CURVE && CV_IS_SEQ_POINT_SET(seq)); } //C #define CV_IS_SEQ_POLYGON( seq ) \ //C (CV_IS_SEQ_POLYLINE(seq) && CV_IS_SEQ_CLOSED(seq)) auto CV_IS_SEQ_POLYGON(T)( T seq ) { return (CV_IS_SEQ_POLYLINE(seq) && CV_IS_SEQ_CLOSED(seq)); } //C #define CV_IS_SEQ_CHAIN( seq ) \ //C (CV_SEQ_KIND(seq) == CV_SEQ_KIND_CURVE && (seq)->elem_size == 1) auto CV_IS_SEQ_CHAIN(T)( seq ) { return (CV_SEQ_KIND(seq) == CV_SEQ_KIND_CURVE && (seq).elem_size == 1); } //C #define CV_IS_SEQ_CONTOUR( seq ) \ //C (CV_IS_SEQ_CLOSED(seq) && (CV_IS_SEQ_POLYLINE(seq) || CV_IS_SEQ_CHAIN(seq))) auto CV_IS_SEQ_CONTOUR(T)( T seq ) { return (CV_IS_SEQ_CLOSED(seq) && (CV_IS_SEQ_POLYLINE(seq) || CV_IS_SEQ_CHAIN(seq))); } //C #define CV_IS_SEQ_CHAIN_CONTOUR( seq ) \ //C (CV_IS_SEQ_CHAIN( seq ) && CV_IS_SEQ_CLOSED( seq )) auto CV_IS_SEQ_CHAIN_CONTOUR(T)( T seq ) { return (CV_IS_SEQ_CHAIN( seq ) && CV_IS_SEQ_CLOSED( seq )); } //C #define CV_IS_SEQ_POLYGON_TREE( seq ) \ //C (CV_SEQ_ELTYPE (seq) == CV_SEQ_ELTYPE_TRIAN_ATR && \ //C CV_SEQ_KIND( seq ) == CV_SEQ_KIND_BIN_TREE ) auto CV_IS_SEQ_POLYGON_TREE(T)( T seq ) { return (CV_SEQ_ELTYPE (seq) == CV_SEQ_ELTYPE_TRIAN_ATR && CV_SEQ_KIND( seq ) == CV_SEQ_KIND_BIN_TREE ); } //C #define CV_IS_GRAPH( seq ) \ //C (CV_IS_SET(seq) && CV_SEQ_KIND((CvSet*)(seq)) == CV_SEQ_KIND_GRAPH) auto CV_IS_GRAPH(T)( T seq ) { return (CV_IS_SET(seq) && CV_SEQ_KIND(cast(CvSet*)(seq)) == CV_SEQ_KIND_GRAPH); } //C #define CV_IS_GRAPH_ORIENTED( seq ) \ //C (((seq)->flags & CV_GRAPH_FLAG_ORIENTED) != 0) auto CV_IS_GRAPH_ORIENTED(T)( T seq ) { return (((seq).flags & CV_GRAPH_FLAG_ORIENTED) != 0); } //C #define CV_IS_SUBDIV2D( seq ) \ //C (CV_IS_SET(seq) && CV_SEQ_KIND((CvSet*)(seq)) == CV_SEQ_KIND_SUBDIV2D) auto CV_IS_SUBDIV2D(T)( T seq ) { return (CV_IS_SET(seq) && CV_SEQ_KIND(cast(CvSet*)(seq)) == CV_SEQ_KIND_SUBDIV2D); } /****************************************************************************************/ /* Sequence writer & reader */ /****************************************************************************************/ //C #define CV_SEQ_WRITER_FIELDS() \ //C int header_size; \ //C CvSeq* seq; /* the sequence written */ \ //C CvSeqBlock* block; /* current block */ \ //C schar* ptr; /* pointer to free space */ \ //C schar* block_min; /* pointer to the beginning of block*/\ //C schar* block_max; /* pointer to the end of block */ template CV_SEQ_WRITER_FIELDS() { int header_size; CvSeq* seq; /* the sequence written */ CvSeqBlock* block; /* current block */ schar* ptr; /* pointer to free space */ schar* block_min; /* pointer to the beginning of block*/ schar* block_max; /* pointer to the end of block */ } //C typedef struct CvSeqWriter //C { //C CV_SEQ_WRITER_FIELDS() //C } //C CvSeqWriter; struct CvSeqWriter { mixin CV_SEQ_WRITER_FIELDS; } //C #define CV_SEQ_READER_FIELDS() \ //C int header_size; \ //C CvSeq* seq; /* sequence, beign read */ \ //C CvSeqBlock* block; /* current block */ \ //C schar* ptr; /* pointer to element be read next */ \ //C schar* block_min; /* pointer to the beginning of block */\ //C schar* block_max; /* pointer to the end of block */ \ //C int delta_index;/* = seq->first->start_index */ \ //C schar* prev_elem; /* pointer to previous element */ template CV_SEQ_READER_FIELDS() { int header_size; CvSeq* seq; /* sequence, beign read */ CvSeqBlock* block; /* current block */ schar* ptr; /* pointer to element be read next */ schar* block_min; /* pointer to the beginning of block */ schar* block_max; /* pointer to the end of block */ int delta_index;/* = seq->first->start_index */ schar* prev_elem; /* pointer to previous element */ } //C typedef struct CvSeqReader //C { //C CV_SEQ_READER_FIELDS() //C } //C CvSeqReader; struct CvSeqReader { mixin CV_SEQ_READER_FIELDS; } /+ /****************************************************************************************/ /* Operations on sequences */ /****************************************************************************************/ //C #define CV_SEQ_ELEM( seq, elem_type, index ) \ //C /* assert gives some guarantee that parameter is valid */ \ //C ( assert(sizeof((seq)->first[0]) == sizeof(CvSeqBlock) && \ //C (seq)->elem_size == sizeof(elem_type)), \ //C (elem_type*)((seq)->first && (unsigned)index < \ //C (unsigned)((seq)->first->count) ? \ //C (seq)->first->data + (index) * sizeof(elem_type) : \ //C cvGetSeqElem( (CvSeq*)(seq), (index) ))) //C #define CV_GET_SEQ_ELEM( elem_type, seq, index ) CV_SEQ_ELEM( (seq), elem_type, (index) ) auto CV_SEQ_ELEM(T,U,V)( T seq, U elem_type, V index ) { /* assert gives some guarantee that parameter is valid */ return ( assert((seq).first[0].sizeof == (CvSeqBlock).sizeof && (seq).elem_size == (elem_type).sizeof), cast(elem_type*)((seq).first && cast(uint)index < cast(uint)((seq).first.count) ? (seq).first.data + (index) * (elem_type).sizeof : cvGetSeqElem( cast(CvSeq*)(seq), (index) ))); } auto CV_GET_SEQ_ELEM(T,U,V)( T elem_type, U seq, V index ) { return CV_SEQ_ELEM( (seq), elem_type, (index) ); } /* Add element to sequence: */ //C #define CV_WRITE_SEQ_ELEM_VAR( elem_ptr, writer ) \ //C { \ //C if( (writer).ptr >= (writer).block_max ) \ //C { \ //C cvCreateSeqBlock( &writer); \ //C } \ //C memcpy((writer).ptr, elem_ptr, (writer).seq->elem_size);\ //C (writer).ptr += (writer).seq->elem_size; \ //C } auto CV_WRITE_SEQ_ELEM_VAR(T,U)( T elem_ptr, U writer ) { if( (writer).ptr >= (writer).block_max ) { cvCreateSeqBlock( &writer); } memcpy((writer).ptr, elem_ptr, (writer).seq->elem_size); (writer).ptr += (writer).seq->elem_size; } //C #define CV_WRITE_SEQ_ELEM( elem, writer ) \ //C { \ //C assert( (writer).seq->elem_size == sizeof(elem)); \ //C if( (writer).ptr >= (writer).block_max ) \ //C { \ //C cvCreateSeqBlock( &writer); \ //C } \ //C assert( (writer).ptr <= (writer).block_max - sizeof(elem));\ //C memcpy((writer).ptr, &(elem), sizeof(elem)); \ //C (writer).ptr += sizeof(elem); \ //C } auto CV_WRITE_SEQ_ELEM(T,U)( T elem, U writer ) { assert( (writer).seq->elem_size == sizeof(elem)); if( (writer).ptr >= (writer).block_max ) { cvCreateSeqBlock( &writer); } assert( (writer).ptr <= (writer).block_max - sizeof(elem)); memcpy((writer).ptr, &(elem), sizeof(elem)); (writer).ptr += sizeof(elem); } /* Move reader position forward: */ #define CV_NEXT_SEQ_ELEM( elem_size, reader ) \ { \ if( ((reader).ptr += (elem_size)) >= (reader).block_max ) \ { \ cvChangeSeqBlock( &(reader), 1 ); \ } \ } /* Move reader position backward: */ #define CV_PREV_SEQ_ELEM( elem_size, reader ) \ { \ if( ((reader).ptr -= (elem_size)) < (reader).block_min ) \ { \ cvChangeSeqBlock( &(reader), -1 ); \ } \ } /* Read element and move read position forward: */ #define CV_READ_SEQ_ELEM( elem, reader ) \ { \ assert( (reader).seq->elem_size == sizeof(elem)); \ memcpy( &(elem), (reader).ptr, sizeof((elem))); \ CV_NEXT_SEQ_ELEM( sizeof(elem), reader ) \ } /* Read element and move read position backward: */ #define CV_REV_READ_SEQ_ELEM( elem, reader ) \ { \ assert( (reader).seq->elem_size == sizeof(elem)); \ memcpy(&(elem), (reader).ptr, sizeof((elem))); \ CV_PREV_SEQ_ELEM( sizeof(elem), reader ) \ } #define CV_READ_CHAIN_POINT( _pt, reader ) \ { \ (_pt) = (reader).pt; \ if( (reader).ptr ) \ { \ CV_READ_SEQ_ELEM( (reader).code, (reader)); \ assert( ((reader).code & ~7) == 0 ); \ (reader).pt.x += (reader).deltas[(int)(reader).code][0]; \ (reader).pt.y += (reader).deltas[(int)(reader).code][1]; \ } \ } #define CV_CURRENT_POINT( reader ) (*((CvPoint*)((reader).ptr))) #define CV_PREV_POINT( reader ) (*((CvPoint*)((reader).prev_elem))) #define CV_READ_EDGE( pt1, pt2, reader ) \ { \ assert( sizeof(pt1) == sizeof(CvPoint) && \ sizeof(pt2) == sizeof(CvPoint) && \ reader.seq->elem_size == sizeof(CvPoint)); \ (pt1) = CV_PREV_POINT( reader ); \ (pt2) = CV_CURRENT_POINT( reader ); \ (reader).prev_elem = (reader).ptr; \ CV_NEXT_SEQ_ELEM( sizeof(CvPoint), (reader)); \ } /************ Graph macros ************/ /* Return next graph edge for given vertex: */ #define CV_NEXT_GRAPH_EDGE( edge, vertex ) \ (assert((edge)->vtx[0] == (vertex) || (edge)->vtx[1] == (vertex)), \ (edge)->next[(edge)->vtx[1] == (vertex)]) +/ /****************************************************************************************\ * Data structures for persistence (a.k.a serialization) functionality * \****************************************************************************************/ /* "black box" file storage */ //C typedef struct CvFileStorage CvFileStorage; struct CvFileStorage; /* Storage flags: */ //C #define CV_STORAGE_READ 0 //C #define CV_STORAGE_WRITE 1 //C #define CV_STORAGE_WRITE_TEXT CV_STORAGE_WRITE //C #define CV_STORAGE_WRITE_BINARY CV_STORAGE_WRITE //C #define CV_STORAGE_APPEND 2 const CV_STORAGE_READ = 0; const CV_STORAGE_WRITE = 1; const CV_STORAGE_WRITE_TEXT = CV_STORAGE_WRITE; const CV_STORAGE_WRITE_BINARY = CV_STORAGE_WRITE; const CV_STORAGE_APPEND = 2; /* List of attributes: */ //C typedef struct CvAttrList //C { //C const char** attr; /* NULL-terminated array of (attribute_name,attribute_value) pairs. */ //C struct CvAttrList* next; /* Pointer to next chunk of the attributes list. */ //C } //C CvAttrList; struct CvAttrList { const(char)** attr; /* NULL-terminated array of (attribute_name,attribute_value) pairs. */ CvAttrList* next; /* Pointer to next chunk of the attributes list. */ } //C CV_INLINE CvAttrList cvAttrList( const char** attr CV_DEFAULT(NULL), //C CvAttrList* next CV_DEFAULT(NULL) ) //C { //C CvAttrList l; //C l.attr = attr; //C l.next = next; //C //C return l; //C } CvAttrList cvAttrList( const(char)** attr = null, CvAttrList* next = null ) { CvAttrList l; l.attr = attr; l.next = next; return l; } //C struct CvTypeInfo; //C #define CV_NODE_NONE 0 //C #define CV_NODE_INT 1 //C #define CV_NODE_INTEGER CV_NODE_INT //C #define CV_NODE_REAL 2 //C #define CV_NODE_FLOAT CV_NODE_REAL //C #define CV_NODE_STR 3 //C #define CV_NODE_STRING CV_NODE_STR //C #define CV_NODE_REF 4 /* not used */ //C #define CV_NODE_SEQ 5 //C #define CV_NODE_MAP 6 //C #define CV_NODE_TYPE_MASK 7 const CV_NODE_NONE = 0; const CV_NODE_INT = 1; const CV_NODE_INTEGER = CV_NODE_INT; const CV_NODE_REAL = 2; const CV_NODE_FLOAT = CV_NODE_REAL; const CV_NODE_STR = 3; const CV_NODE_STRING = CV_NODE_STR; const CV_NODE_REF = 4; /* not used */ const CV_NODE_SEQ = 5; const CV_NODE_MAP = 6; const CV_NODE_TYPE_MASK = 7; //C #define CV_NODE_TYPE(flags) ((flags) & CV_NODE_TYPE_MASK) auto CV_NODE_TYPE(T)( T flags) { return ((flags) & CV_NODE_TYPE_MASK); } /* file node flags */ //C #define CV_NODE_FLOW 8 /* Used only for writing structures in YAML format. */ //C #define CV_NODE_USER 16 //C #define CV_NODE_EMPTY 32 //C #define CV_NODE_NAMED 64 const CV_NODE_FLOW = 8; /* Used only for writing structures in YAML format. */ const CV_NODE_USER = 16; const CV_NODE_EMPTY = 32; const CV_NODE_NAMED = 64; /+ #define CV_NODE_IS_INT(flags) (CV_NODE_TYPE(flags) == CV_NODE_INT) #define CV_NODE_IS_REAL(flags) (CV_NODE_TYPE(flags) == CV_NODE_REAL) #define CV_NODE_IS_STRING(flags) (CV_NODE_TYPE(flags) == CV_NODE_STRING) #define CV_NODE_IS_SEQ(flags) (CV_NODE_TYPE(flags) == CV_NODE_SEQ) #define CV_NODE_IS_MAP(flags) (CV_NODE_TYPE(flags) == CV_NODE_MAP) #define CV_NODE_IS_COLLECTION(flags) (CV_NODE_TYPE(flags) >= CV_NODE_SEQ) #define CV_NODE_IS_FLOW(flags) (((flags) & CV_NODE_FLOW) != 0) #define CV_NODE_IS_EMPTY(flags) (((flags) & CV_NODE_EMPTY) != 0) #define CV_NODE_IS_USER(flags) (((flags) & CV_NODE_USER) != 0) #define CV_NODE_HAS_NAME(flags) (((flags) & CV_NODE_NAMED) != 0) #define CV_NODE_SEQ_SIMPLE 256 #define CV_NODE_SEQ_IS_SIMPLE(seq) (((seq)->flags & CV_NODE_SEQ_SIMPLE) != 0) +/ //C typedef struct CvString //C { //C int len; //C char* ptr; //C } //C CvString; struct CvString { int len; char* ptr; } /+ /* All the keys (names) of elements in the readed file storage are stored in the hash to speed up the lookup operations: */ typedef struct CvStringHashNode { unsigned hashval; CvString str; struct CvStringHashNode* next; } CvStringHashNode; +/ //Ctypedef struct CvGenericHash CvFileNodeHash; struct CvGenericHash; alias CvGenericHash CvFileNodeHash; /* Basic element of the file storage - scalar or collection: */ //C typedef struct CvFileNode //C { //C int tag; //C struct CvTypeInfo* info; /* type information //C (only for user-defined object, for others it is 0) */ //C union //C { //C double f; /* scalar floating-point number */ //C int i; /* scalar integer number */ //C CvString str; /* text string */ //C CvSeq* seq; /* sequence (ordered collection of file nodes) */ //C CvFileNodeHash* map; /* map (collection of named file nodes) */ //C } data; //C } //C CvFileNode; struct CvFileNode { int tag; CvTypeInfo* info; /* type information (only for user-defined object, for others it is 0) */ union DATA { double f; /* scalar floating-point number */ int i; /* scalar integer number */ CvString str; /* text string */ CvSeq* seq; /* sequence (ordered collection of file nodes) */ CvFileNodeHash* map; /* map (collection of named file nodes) */ } DATA data; } //C #ifdef __cplusplus //C extern "C" { //C #endif //C typedef int (CV_CDECL *CvIsInstanceFunc)( const void* struct_ptr ); //C typedef void (CV_CDECL *CvReleaseFunc)( void** struct_dblptr ); //C typedef void* (CV_CDECL *CvReadFunc)( CvFileStorage* storage, CvFileNode* node ); //C typedef void (CV_CDECL *CvWriteFunc)( CvFileStorage* storage, const char* name, //C const void* struct_ptr, CvAttrList attributes ); //C typedef void* (CV_CDECL *CvCloneFunc)( const void* struct_ptr ); //C #ifdef __cplusplus //C } //C #endif alias int function( const(void)* struct_ptr ) CvIsInstanceFunc; alias void function( void** struct_dblptr ) CvReleaseFunc; alias void* function( CvFileStorage* storage, CvFileNode* node ) CvReadFunc; alias void function( CvFileStorage* storage, const(char)* name, const(void)* struct_ptr, CvAttrList attributes ) CvWriteFunc; alias void* function( const(void)* struct_ptr ) CvCloneFunc; //C typedef struct CvTypeInfo //C { //C int flags; //C int header_size; //C struct CvTypeInfo* prev; //C struct CvTypeInfo* next; //C const char* type_name; //C CvIsInstanceFunc is_instance; //C CvReleaseFunc release; //C CvReadFunc read; //C CvWriteFunc write; //C CvCloneFunc clone; //C } //C CvTypeInfo; struct CvTypeInfo { int flags; int header_size; CvTypeInfo* prev; CvTypeInfo* next; const(char)* type_name; CvIsInstanceFunc is_instance; CvReleaseFunc release; CvReadFunc read; CvWriteFunc write; CvCloneFunc clone; } /+ /**** System data types ******/ typedef struct CvPluginFuncInfo { void** func_addr; void* default_func_addr; const char* func_names; int search_modules; int loaded_from; } CvPluginFuncInfo; typedef struct CvModuleInfo { struct CvModuleInfo* next; const char* name; const char* version; CvPluginFuncInfo* func_tab; } CvModuleInfo; #endif /*_CXCORE_TYPES_H_*/ /* End of file. */ +/