]> rtime.felk.cvut.cz Git - opencv.git/commitdiff
no message
authorvp153 <vp153@73c94f0f-984f-4a5f-82bc-2d8db8d8ee08>
Wed, 18 Aug 2004 13:48:02 +0000 (13:48 +0000)
committervp153 <vp153@73c94f0f-984f-4a5f-82bc-2d8db8d8ee08>
Wed, 18 Aug 2004 13:48:02 +0000 (13:48 +0000)
git-svn-id: https://code.ros.org/svn/opencv/trunk@32 73c94f0f-984f-4a5f-82bc-2d8db8d8ee08

67 files changed:
opencv/include/opencv/cv.h
opencv/include/opencv/cv.hpp
opencv/include/opencv/cvcompat.h
opencv/include/opencv/cvstreams.h
opencv/include/opencv/cvtypes.h
opencv/src/cv/Makefile.am
opencv/src/cv/Makefile.in [deleted file]
opencv/src/cv/_cv.h
opencv/src/cv/_cvgeom.h
opencv/src/cv/_cvimgproc.h [new file with mode: 0644]
opencv/src/cv/_cvipp.h [new file with mode: 0644]
opencv/src/cv/_cvlist.h
opencv/src/cv/_cvmatrix.h
opencv/src/cv/cvaccum.cpp
opencv/src/cv/cvapprox.cpp
opencv/src/cv/cvcalccontrasthistogram.cpp
opencv/src/cv/cvcalcimagehomography.cpp
opencv/src/cv/cvcalibinit.cpp
opencv/src/cv/cvcalibration.cpp
opencv/src/cv/cvcamshift.cpp
opencv/src/cv/cvcanny.cpp
opencv/src/cv/cvcolor.cpp
opencv/src/cv/cvcondens.cpp
opencv/src/cv/cvcontours.cpp
opencv/src/cv/cvcontourtree.cpp
opencv/src/cv/cvconvhull.cpp
opencv/src/cv/cvconvolve.cpp [new file with mode: 0644]
opencv/src/cv/cvcorner.cpp
opencv/src/cv/cvcornersubpix.cpp
opencv/src/cv/cvderiv.cpp
opencv/src/cv/cvdistransform.cpp
opencv/src/cv/cvdominants.cpp
opencv/src/cv/cvemd.cpp
opencv/src/cv/cvfeatureselect.cpp
opencv/src/cv/cvfloodfill.cpp
opencv/src/cv/cvfundam.cpp
opencv/src/cv/cvgeometry.cpp
opencv/src/cv/cvhaar.cpp [new file with mode: 0644]
opencv/src/cv/cvhistogram.cpp
opencv/src/cv/cvhough.cpp
opencv/src/cv/cvimgwarp.cpp [new file with mode: 0644]
opencv/src/cv/cvlinefit.cpp
opencv/src/cv/cvlkpyramid.cpp
opencv/src/cv/cvmatchcontours.cpp
opencv/src/cv/cvmoments.cpp
opencv/src/cv/cvmorph.cpp
opencv/src/cv/cvmotempl.cpp
opencv/src/cv/cvoptflowbm.cpp
opencv/src/cv/cvoptflowhs.cpp
opencv/src/cv/cvoptflowlk.cpp
opencv/src/cv/cvpgh.cpp
opencv/src/cv/cvposit.cpp
opencv/src/cv/cvpyramids.cpp
opencv/src/cv/cvpyrsegmentation.cpp
opencv/src/cv/cvrotcalipers.cpp
opencv/src/cv/cvsamplers.cpp
opencv/src/cv/cvshapedescr.cpp
opencv/src/cv/cvsmooth.cpp
opencv/src/cv/cvsnakes.cpp
opencv/src/cv/cvsubdivision2d.cpp
opencv/src/cv/cvsumpixels.cpp
opencv/src/cv/cvswitcher.cpp
opencv/src/cv/cvtables.cpp
opencv/src/cv/cvtemplmatch.cpp
opencv/src/cv/cvthresh.cpp
opencv/src/cv/cvundistort.cpp
opencv/src/cv/cvutils.cpp

index 2264d6f58773ca94405ff5c1b4369397074891c1..602d61c2304a6ee64a9d1808466c4078a4e2928d 100644 (file)
 #define _CV_H_
 
 #ifdef __IPL_H__
-#define HAVE_IPL /* On Windows IPL is needed by default */
+#define HAVE_IPL
 #endif
 
 #if defined(_CH_)
-#include <cvch.h>
-CV_CH_LOAD_CODE(cv,Cv)
-#endif
-
-#ifdef HAVE_IPL
-#ifndef _INC_WINDOWS
-    #define CV_PRETEND_WINDOWS
-    #define _INC_WINDOWS
-    typedef struct tagBITMAPINFOHEADER BITMAPINFOHEADER;
-    typedef int BOOL;
-#endif
-#include "ipl.h"
-#ifdef CV_PRETEND_WINDOWS
-    #undef _INC_WINDOWS
-#endif
+#pragma package <opencv>
+#include <chdl.h>
+LOAD_CHDL_CODE(cv,Cv)
 #endif
 
+#include "cxcore.h"
 #include "cvtypes.h"
-#include "cverror.h"
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-/****************************************************************************************\
-*                                     Allocation/deallocation                            *
-\****************************************************************************************/
-
-/* <malloc> wrapper.
-   If there is no enough memory the function
-   (as well as other OpenCV functions that call cvAlloc)
-   raises an error. */
-OPENCVAPI  void*  cvAlloc( int size );
-
-/* <free> wrapper.
-   Here and further all the memory releasing functions
-   (that all call cvFree) take double pointer which is used
-   to clear user pointer to the data after releasing it.
-   Passing pointer to NULL pointer is Ok: nothing happens in this case
-*/
-OPENCVAPI  void   cvFree( void** ptr );
-
-/* Allocates and initializes IplImage header */
-OPENCVAPI  IplImage*  cvCreateImageHeader( CvSize size, int depth, int channels );
-
-/* Inializes IplImage header */
-OPENCVAPI IplImage* cvInitImageHeader( IplImage* image, CvSize size, int depth,
-                                       int channels, int origin CV_DEFAULT(0),
-                                       int align CV_DEFAULT(4));
-
-/* Creates IPL image (header and data) */
-OPENCVAPI  IplImage*  cvCreateImage( CvSize size, int depth, int channels );
-
-/* Releases (i.e. deallocates) IPL image header */
-OPENCVAPI  void  cvReleaseImageHeader( IplImage** image );
-
-/* Releases IPL image header and data */
-OPENCVAPI  void  cvReleaseImage( IplImage** image );
-
-/* Creates a copy of IPL image (widthStep may differ) */
-OPENCVAPI IplImage* cvCloneImage( const IplImage* image );
-
-/* Sets a Channel Of Interest (only a few functions support COI) - 
-   use cvCopy to extract the selected channel and/or put it back */
-OPENCVAPI  void  cvSetImageCOI( IplImage* image, int coi );
-
-/* Retrieves image Channel Of Interest */
-OPENCVAPI  int  cvGetImageCOI( IplImage* image );
-
-/* Sets image ROI (region of interest) (COI is not changed) */
-OPENCVAPI  void  cvSetImageROI( IplImage* image, CvRect rect );
-
-/* Resets image ROI and COI */
-OPENCVAPI  void  cvResetImageROI( IplImage* image );
-
-/* Retrieves image ROI */
-OPENCVAPI  CvRect cvGetImageROI( const IplImage* image );
-
-/* Allocates and initalizes CvMat header */
-OPENCVAPI  CvMat*  cvCreateMatHeader( int rows, int cols, int type );
-
-#define CV_AUTOSTEP  0x7fffffff
-
-/* Initializes CvMat header */
-OPENCVAPI CvMat* cvInitMatHeader( CvMat* mat, int rows, int cols,
-                                  int type, void* data CV_DEFAULT(NULL),
-                                  int step CV_DEFAULT(CV_AUTOSTEP) );
-
-/* Allocates and initializes CvMat header and allocates data */
-OPENCVAPI  CvMat*  cvCreateMat( int rows, int cols, int type );
-
-/* Releases CvMat header and deallocates matrix data
-   (reference counting is used for data) */
-OPENCVAPI  void  cvReleaseMat( CvMat** mat );
-
-/* Decrements CvMat data reference counter and deallocates the data if
-   it reaches 0 */
-CV_INLINE  void  cvDecRefData( CvArr* arr );
-CV_INLINE  void  cvDecRefData( CvArr* arr )
-{
-    if( CV_IS_MAT( arr ) || CV_IS_MATND( arr ))
-    {
-        CvMat* mat = (CvMat*)arr; /* the first few fields of CvMat and CvMatND are the same */
-        mat->data.ptr = NULL;
-        if( mat->refcount != NULL && --*mat->refcount == 0 )
-        {
-            uchar* data = (uchar*)mat->refcount + 2*sizeof(mat->refcount);
-            cvFree( (void**)&data );
-        }
-        mat->refcount = NULL;
-    }
-}
-
-/* Increments CvMat data reference counter */
-CV_INLINE  int  cvIncRefData( CvArr* arr );
-CV_INLINE  int  cvIncRefData( CvArr* arr )
-{
-    int refcount = 0;
-    if( CV_IS_MAT( arr ) || CV_IS_MATND( arr ))
-    {
-        CvMat* mat = (CvMat*)arr;
-        if( mat->refcount != NULL )
-            refcount = ++*mat->refcount;
-    }
-    return refcount;
-}
-
-
-/* Creates an exact copy of the input matrix (except, may be, step value) */
-OPENCVAPI CvMat* cvCloneMat( const CvMat* mat );
-
-
-/* Makes a new matrix from <rect> subrectangle of input array.
-   No data is copied */
-OPENCVAPI CvMat* cvGetSubRect( const CvArr* arr, CvMat* submat, CvRect rect );
-#define cvGetSubArr cvGetSubRect
-
-/* Partial case of the cvGetSubArr:
-    row span of the input array is selected
-    (end_row is not included into the span). */
-OPENCVAPI CvMat* cvGetRows( const CvArr* arr, CvMat* submat,
-                            int start_row, int end_row );
-
-CV_INLINE  void  cvGetRow( const CvArr* arr, CvMat* submat, int row );
-CV_INLINE  void  cvGetRow( const CvArr* arr, CvMat* submat, int row )
-{
-    cvGetRows( arr, submat, row, row + 1 );
-}
-
-
-/* Partial case of the cvGetSubArr:
-    column span of the input array is selected
-    (end_col is not included into the span) */
-OPENCVAPI CvMat* cvGetCols( const CvArr* arr, CvMat* submat,
-                               int start_col, int end_col );
-
-CV_INLINE  void  cvGetCol( const CvArr* arr, CvMat* submat, int col );
-CV_INLINE  void  cvGetCol( const CvArr* arr, CvMat* submat, int col )
-{
-    cvGetCols( arr, submat, col, col + 1 );
-}
-
-/* Partial case of the cvGetSubArr:
-    a single diagonal of the input array is selected
-   (diag = 0 means main diagonal, >0 means some diagonal above the main one,
-   <0 - below the main one).
-   The diagonal will be represented as a column (nx1 matrix). */
-OPENCVAPI CvMat* cvGetDiag( const CvArr* arr, CvMat* submat,
-                            int diag CV_DEFAULT(0));
-
-/* low-level scalar <-> raw data conversion functions */
-OPENCVAPI void cvScalarToRawData( const CvScalar* scalar, void* data, int type,
-                                  int extend_to_12 CV_DEFAULT(0) );
-
-OPENCVAPI void cvRawDataToScalar( const void* data, int type, CvScalar* scalar );
-
-/* Allocates and initializes CvMatND header */
-OPENCVAPI  CvMatND*  cvCreateMatNDHeader( int dims, const int* sizes, int type );
-
-/* Allocates and initializes CvMatND header and allocates data */
-OPENCVAPI  CvMatND*  cvCreateMatND( int dims, const int* sizes, int type );
-
-/* Initializes preallocated CvMatND header */
-OPENCVAPI  CvMatND*  cvInitMatNDHeader( CvMatND* mat, int dims, const int* sizes,
-                                        int type, void* data CV_DEFAULT(NULL) );
-
-/* Releases CvMatND */
-CV_INLINE  void  cvReleaseMatND( CvMatND** mat );
-CV_INLINE  void  cvReleaseMatND( CvMatND** mat )
-{
-    cvReleaseMat( (CvMat**)mat );
-}
-
-/* Creates a copy of CvMatND (except, may be, steps) */
-OPENCVAPI  CvMatND* cvCloneMatND( const CvMatND* mat );
-
-/* Allocates and initializes CvSparseMat header and allocates data */
-OPENCVAPI  CvSparseMat*  cvCreateSparseMat( int dims, const int* sizes, int type );
-
-/* Releases CvSparseMat */
-OPENCVAPI  void  cvReleaseSparseMat( CvSparseMat** mat );
-
-/* Creates a copy of CvSparseMat (except, may be, zero items) */
-OPENCVAPI  CvSparseMat* cvCloneSparseMat( const CvSparseMat* mat );
-
-/* Initializes sparse array iterator
-   (returns the first node or NULL if the array is empty) */
-OPENCVAPI  CvSparseNode* cvInitSparseMatIterator( const CvSparseMat* mat,
-                                                  CvSparseMatIterator* matIterator );
-
-// returns next sparse array node (or NULL if there is no more nodes)
-CV_INLINE CvSparseNode* cvGetNextSparseNode( CvSparseMatIterator* matIterator );
-CV_INLINE CvSparseNode* cvGetNextSparseNode( CvSparseMatIterator* matIterator )
-{
-    if( matIterator->node->next )
-        return matIterator->node = matIterator->node->next;
-    else
-    {
-        int idx;
-        for( idx = ++matIterator->curidx; idx < matIterator->mat->hashsize; idx++ )
-        {
-            CvSparseNode* node = (CvSparseNode*)matIterator->mat->hashtable[idx];
-            if( node )
-            {
-                matIterator->curidx = idx;
-                return matIterator->node = node;
-            }
-        }
-        return NULL;
-    }
-}
-
-/* Returns type of array elements:
-   CV_8UC1 ... CV_64FC4 ... */
-OPENCVAPI  int cvGetElemType( const CvArr* arr );
-
-/* Retrieves number of an array dimensions and
-   optionally sizes of the dimensions */
-OPENCVAPI  int cvGetDims( const CvArr* arr, int* sizes CV_DEFAULT(NULL) );
-
-
-/* Retrieves size of a particular array dimension.
-   For 2d arrays cvGetDimSize(arr,0) returns number of rows (image height)
-   and cvGetDimSize(arr,1) returns number of columns (image width) */
-OPENCVAPI  int cvGetDimSize( const CvArr* arr, int index );
-
-
-/* ptr = &arr(idx1,idx2,...). All indexes are zero-based,
-   the major dimensions go first (e.g. (y,x) for 2D, (z,y,x) for 3D */
-OPENCVAPI uchar* cvPtr1D( const CvArr* arr, int idx1, int* type CV_DEFAULT(NULL));
-OPENCVAPI uchar* cvPtr2D( const CvArr* arr, int idx1, int idx2, int* type CV_DEFAULT(NULL) );
-OPENCVAPI uchar* cvPtr3D( const CvArr* arr, int idx1, int idx2, int idx3,
-                          int* type CV_DEFAULT(NULL));
-
-/* For CvMat or IplImage number of indices should be 2
-   (row index (y) goes first, column index (x) goes next).
-   For CvMatND or CvSparseMat number of infices should match number of <dims> and
-   indices order should match the array dimension order. */
-OPENCVAPI uchar* cvPtrND( const CvArr* arr, int* idx, int* type CV_DEFAULT(NULL) );
-
-/* value = arr(idx1,idx2,...) */
-OPENCVAPI CvScalar cvGet1D( const CvArr* arr, int idx1 );
-OPENCVAPI CvScalar cvGet2D( const CvArr* arr, int idx1, int idx2 );
-OPENCVAPI CvScalar cvGet3D( const CvArr* arr, int idx1, int idx2, int idx3 );
-OPENCVAPI CvScalar cvGetND( const CvArr* arr, int* idx );
-
-/* for 1-channel arrays */
-OPENCVAPI double cvGetReal1D( const CvArr* arr, int idx1 );
-OPENCVAPI double cvGetReal2D( const CvArr* arr, int idx1, int idx2 );
-OPENCVAPI double cvGetReal3D( const CvArr* arr, int idx1, int idx2, int idx3 );
-OPENCVAPI double cvGetRealND( const CvArr* arr, int* idx );
-
-/* arr(idx1,idx2,...) = value */
-OPENCVAPI void cvSet1D( CvArr* arr, int idx1, CvScalar value );
-OPENCVAPI void cvSet2D( CvArr* arr, int idx1, int idx2, CvScalar value );
-OPENCVAPI void cvSet3D( CvArr* arr, int idx1, int idx2, int idx3, CvScalar value );
-OPENCVAPI void cvSetND( CvArr* arr, int* idx, CvScalar value );
-
-/* for 1-channel arrays */
-OPENCVAPI void cvSetReal1D( CvArr* arr, int idx1, double value );
-OPENCVAPI void cvSetReal2D( CvArr* arr, int idx1, int idx2, double value );
-OPENCVAPI void cvSetReal3D( CvArr* arr, int idx1,
-                            int idx2, int idx3, double value );
-OPENCVAPI void cvSetRealND( CvArr* arr, int* idx, double value );
-
-/* Converts CvArr (IplImage or CvMat,...) to CvMat.
-   If the last parameter is non-zero, function can
-   convert multi(>2)-dimensional array to CvMat as long as
-   the last array's dimension is continous. The resultant
-   matrix will be have appropriate (a huge) number of rows */
-OPENCVAPI CvMat* cvGetMat( const CvArr* src, CvMat* header,
-                           int* coi CV_DEFAULT(NULL),
-                           int allowND CV_DEFAULT(0));
-
-/* Converts CvArr (IplImage or CvMat) to IplImage */
-OPENCVAPI IplImage* cvGetImage( const CvArr* array, IplImage* img );
-
-
-/* Changes a shape of multi-dimensional array.
-   new_cn == 0 means that number of channels remains unchanged.
-   new_dims == 0 means that number and sizes of dimensions remain the same
-   (unless they need to be changed to set the new number of channels)
-   if new_dims == 1, there is no need to specify new dimension sizes
-   The resultant configuration should be achievable w/o data copying.
-   If the resultant array is sparse, CvSparseMat header should be passed
-   to the function else if the result is 1 or 2 dimensional,
-   CvMat header should be passed to the function
-   else CvMatND header should be passed */
-OPENCVAPI CvArr* cvReshapeMatND( const CvArr* array,
-                                 int sizeof_header, CvArr* header,
-                                 int new_cn, int new_dims, int* new_sizes );
-
-#define cvReshapeND( arr, header, new_cn, new_dims, new_sizes )   \
-      cvReshapeMatND( (arr), sizeof(*(header)), (header),         \
-                      (new_cn), (new_dims), (new_sizes))
-
-OPENCVAPI CvMat* cvReshape( const CvArr* array, CvMat* header,
-                            int new_cn, int new_rows CV_DEFAULT(0) );
-
-/* Repeats source 2d array several times in both horizontal and
-   vertical direction to fit destination array */
-OPENCVAPI void cvRepeat( const CvArr* src, CvArr* dst );
-
-/* Allocates array data */
-OPENCVAPI  void  cvCreateData( CvArr* array );
-
-/* Releases array data */
-OPENCVAPI  void  cvReleaseData( CvArr* array );
-
-/* Attaches user data to the array header. The step is reffered to
-   the pre-last dimension. That is, all the planes of the array
-   must be joint (w/o gaps) */
-OPENCVAPI  void  cvSetData( CvArr* array, void* data, int step );
-
-/* Retrieves raw data of CvMat, IplImage or CvMatND.
-   In the latter case the function raises an error if
-   the array can not be represented as a matrix */
-OPENCVAPI void cvGetRawData( const CvArr* array, uchar** data,
-                             int* step CV_DEFAULT(NULL),
-                             CvSize* roi_size CV_DEFAULT(NULL));
-
-/* Returns width and height of array in elements */
-OPENCVAPI  CvSize cvGetSize( const CvArr* arr );
-
-/* Copies source array to destination array */
-OPENCVAPI  void  cvCopy( const CvArr* src, CvArr* dst,
-                         const CvArr* mask CV_DEFAULT(NULL) );
-
-/* Sets all or "masked" elements of input array
-   to the same <scalar> value*/
-OPENCVAPI  void  cvSet( CvArr* arr, CvScalar scalar,
-                        const CvArr* mask CV_DEFAULT(NULL) );
-
-/* Clears all the array elements (sets them to 0) */
-OPENCVAPI  void  cvSetZero( CvArr* mat );
-#define cvZero  cvSetZero
-
-
-/* Splits a multi-channel array into the set of single-channel arrays or
-   extracts particular [color] plane */
-OPENCVAPI  void  cvCvtPixToPlane( const void *src, void *dst0, void *dst1,
-                                  void *dst2, void *dst3 );
-
-/* Merges a set of single-channel arrays into the single multi-channel array
-   or inserts one particular [color] plane to the array */
-OPENCVAPI  void  cvCvtPlaneToPix( const void *src0, const void *src1,
-                                  const void *src2, const void *src3,
-                                  void *dst );
-
-/* Performs linear transformation on every source array element:
-   dst(x,y,c) = scale*src(x,y,c)+shift.
-   Arbitrary combination of input and output array depths are allowed
-   (number of channels must be the same), thus the function can be used
-   for depth conversion */
-OPENCVAPI  void  cvConvertScale( const CvArr *src, CvArr *dst,
-                                 double scale CV_DEFAULT(1),
-                                 double shift CV_DEFAULT(0) );
-#define cvCvtScale cvConvertScale
-#define cvScale  cvConvertScale
-#define cvConvert( src, dst )  cvConvertScale( (src), (dst), 1, 0 )
-
-
-/* Performs linear transformation on every source array element,
-   stores absolute value of the result:
-   dst(x,y,c) = abs(scale*src(x,y,c)+shift).
-   destination array must have 8u type.
-   In other cases one may use cvConvertScale + cvAbsDiffS */
-OPENCVAPI  void  cvConvertScaleAbs( const void *src, void *dst,
-                                    double scale CV_DEFAULT(1),
-                                    double shift CV_DEFAULT(0) );
-#define cvCvtScaleAbs  cvConvertScaleAbs
-
-
-/* Finds minimum rectangle containing two given rectangles */
-OPENCVAPI  CvRect  cvMaxRect( const CvRect* rect1, const CvRect* rect2 );
-
-/* Finds coordinates of the box vertices */
-OPENCVAPI  void cvBoxPoints( CvBox2D box, CvPoint2D32f pt[4] );
-
-
-/****************************************************************************************\
-*                   Arithmetic, logic and comparison operations                          *
-\****************************************************************************************/
-
-/* dst(mask) = srcA(mask) + srcB(mask) */
-OPENCVAPI  void  cvAdd( const CvArr* srcA, const CvArr* srcB, CvArr* dst,
-                        const CvArr* mask CV_DEFAULT(NULL));
-
-/* dst(mask) = src(mask) + value */
-OPENCVAPI  void  cvAddS( const CvArr* src, CvScalar value, CvArr* dst,
-                         const CvArr* mask CV_DEFAULT(NULL));
-
-/* dst(mask) = srcA(mask) - srcB(mask) */
-OPENCVAPI  void  cvSub( const CvArr* srcA, const CvArr* srcB, CvArr* dst,
-                        const CvArr* mask CV_DEFAULT(NULL));
-
-/* dst(mask) = src(mask) - value = src(mask) + (-value) */
-CV_INLINE  void  cvSubS( const CvArr* src, CvScalar value, CvArr* dst,
-                         const CvArr* mask CV_DEFAULT(NULL));
-CV_INLINE  void  cvSubS( const CvArr* src, CvScalar value, CvArr* dst,
-                         const CvArr* mask )
-{
-    cvAddS( src, cvScalar( -value.val[0], -value.val[1], -value.val[2], -value.val[3]),
-            dst, mask );
-}
-
-/* dst(mask) = value - src(mask) */
-OPENCVAPI  void  cvSubRS( const CvArr* src, CvScalar value, CvArr* dst,
-                          const CvArr* mask CV_DEFAULT(NULL));
-
-/* dst(idx) = srcA(idx) * srcB(idx) * scale (element-wise multiplication with scale) */
-OPENCVAPI  void  cvMul( const CvArr* srcA, const CvArr* srcB,
-                        CvArr* dst, double scale CV_DEFAULT(1) );
-
-/* element-wise division/inversion with scaling: 
-    dst(idx) = srcA(idx) * scale / srcB(idx)
-    or dst(idx) = scale / srcB(idx) if srcA == 0 */
-OPENCVAPI  void  cvDiv( const CvArr* srcA, const CvArr* srcB,
-                        CvArr* dst, double scale CV_DEFAULT(1));
-
-/* dst = srcA * scale + srcB */
-OPENCVAPI  void  cvScaleAdd( const CvArr* srcA, CvScalar scale,
-                             const CvArr* srcB, CvArr* dst );
-
-/* dst = srcA * alpha + srcB * beta + gamma */
-OPENCVAPI  void  cvAddWeighted( const CvArr* srcA, double alpha,
-                                const CvArr* srcB, double beta,
-                                double gamma, CvArr* dst );
-
-/* result = sum(srcA(i) * srcB*(i))  (srcB is conjugated)
-             i                                           */
-OPENCVAPI  double  cvDotProduct( const CvArr* srcA, const CvArr* srcB );
-
-
-/* dst(idx) = src1(idx) & src2(idx) */
-OPENCVAPI void cvAnd( const CvArr* src1, const CvArr* src2,
-                      CvArr* dst, const CvArr* mask CV_DEFAULT(NULL));
-
-/* dst(idx) = src(idx) & value */
-OPENCVAPI void cvAndS( const CvArr* src, CvScalar value,
-                       CvArr* dst, const CvArr* mask CV_DEFAULT(NULL));
-
-/* dst(idx) = src1(idx) | src2(idx) */
-OPENCVAPI void cvOr( const CvArr* src1, const CvArr* src2,
-                     CvArr* dst, const CvArr* mask CV_DEFAULT(NULL));
-
-/* dst(idx) = src(idx) | value */
-OPENCVAPI void cvOrS( const CvArr* src, CvScalar value,
-                      CvArr* dst, const CvArr* mask CV_DEFAULT(NULL));
-
-/* dst(idx) = src1(idx) ^ src2(idx) */
-OPENCVAPI void cvXor( const CvArr* src1, const CvArr* src2,
-                      CvArr* dst, const CvArr* mask CV_DEFAULT(NULL));
-
-/* dst(idx) = src(idx) ^ value */
-OPENCVAPI void cvXorS( const CvArr* src, CvScalar value,
-                       CvArr* dst, const CvArr* mask CV_DEFAULT(NULL));
-
-/* dst(idx) = ~src(idx) */
-OPENCVAPI void cvNot( const CvArr* src, CvArr* dst );
-
-/* dst(idx) = lower(idx) <= src(idx) < upper(idx) */
-OPENCVAPI void cvInRange( const CvArr* src, const CvArr* lower,
-                          const CvArr* upper, CvArr* dst );
-
-/* dst(idx) = lower <= src(idx) < upper */
-OPENCVAPI void cvInRangeS( const CvArr* src, CvScalar lower,
-                           CvScalar upper, CvArr* dst );
-
-#define CV_CMP_EQ   0
-#define CV_CMP_GT   1
-#define CV_CMP_GE   2
-#define CV_CMP_LT   3
-#define CV_CMP_LE   4
-#define CV_CMP_NE   5
-
-/* The comparison operation support single-channel arrays only.
-   Destination image should be 8uC1 or 8sC1 */
-
-/* dst(idx) = src1(idx) _cmp_op_ src2(idx) */
-OPENCVAPI void cvCmp( const CvArr* src1, const CvArr* src2, CvArr* dst, int cmpOp );
-
-/* dst(idx) = src1(idx) _cmp_op_ scalar */
-OPENCVAPI void cvCmpS( const CvArr* src1, double scalar, CvArr* dst, int cmpOp );
-
-/* dst(idx) = min(src1(idx),src2(idx)) */
-OPENCVAPI void cvMin( const CvArr* src1, const CvArr* src2, CvArr* dst );
-
-/* dst(idx) = max(src1(idx),src2(idx)) */
-OPENCVAPI void cvMax( const CvArr* src1, const CvArr* src2, CvArr* dst );
-
-/* dst(idx) = min(src(idx),scalar) */
-OPENCVAPI void cvMinS( const CvArr* src, double scalar, CvArr* dst );
-
-/* dst(idx) = max(src(idx),scalar) */
-OPENCVAPI void cvMaxS( const CvArr* src, double scalar, CvArr* dst );
-
-
-/****************************************************************************************\
-*                                Math operations                                         *
-\****************************************************************************************/
-
-/* Does cartesian->polar coordinates conversion.
-   Either of output components (magnitude or angle) is optional */
-OPENCVAPI  void  cvCartToPolar( const CvArr* x, const CvArr* y,
-                                CvArr* magnitude, CvArr* angle CV_DEFAULT(NULL),
-                                int angle_in_degrees CV_DEFAULT(0));
-
-/* Does polar->cartesian coordinates conversion.
-   Either of output components (magnitude or angle) is optional.
-   If magnitude is missing it is assumed to be all 1's */
-OPENCVAPI  void  cvPolarToCart( const CvArr* magnitude, const CvArr* angle,
-                                CvArr* x, CvArr* y,
-                                int angle_in_degrees CV_DEFAULT(0));
-
-/* Does powering: dst(idx) = src(idx)^power */
-OPENCVAPI  void  cvPow( const CvArr* src, CvArr* dst, double power );
-
-/* Does exponention: dst(idx) = exp(src(idx)).
-   Overflow is not handled yet. Underflow is handled.
-   Maximal relative error is ~7e-6 */
-OPENCVAPI  void  cvExp( const CvArr* src, CvArr* dst );
-
-/* Calculates natural logarithms: dst(idx) = log(abs(src(idx))).
-   Logarithm of 0 gives large negative number(~-700)
-   Maximal relative error is ~3e-7
-*/
-OPENCVAPI  void  cvLog( const CvArr* src, CvArr* dst );
-
-/* Checks array values for NaNs, Infs or simply for too large numbers
-   (if CV_CHECK is set). If CV_CHECK_QUIET is set,
-   no runtime errors is raised (function returns zero value in case of "bad" values).
-   Otherwise cvError is called */ 
-#define  CV_CHECK_RANGE    1
-#define  CV_CHECK_QUIET    2
-OPENCVAPI  int  cvCheckArr( const CvArr* arr, int flags CV_DEFAULT(0),
-                            double minVal CV_DEFAULT(0), double maxVal CV_DEFAULT(0));
-#define cvCheckArray cvCheckArr
-
-/* RNG state */
-typedef struct CvRandState
-{
-    uint64    state;    /* RNG state (the current seed and carry)*/
-    int       disttype; /* distribution type */
-    CvScalar  param[2]; /* parameters of RNG */
-}
-CvRandState;
-
-/* Initalized RNG state */
-#define CV_RAND_UNI      0
-#define CV_RAND_NORMAL   1
-OPENCVAPI  void  cvRandInit( CvRandState* state, double param1,
-                             double param2, int seed,
-                             int disttype CV_DEFAULT(CV_RAND_UNI));
-
-/* Changes RNG range while preserving RNG state */
-OPENCVAPI  void  cvRandSetRange( CvRandState* state, double param1, double param2,
-                                 int index CV_DEFAULT(-1));
-
-/* Fills array with random numbers */
-OPENCVAPI  void  cvRand( CvRandState* state, CvArr* arr );
-
-/* Returns 32-bit random number (ranges are not used)
-   and updates RNG state */
-CV_INLINE  unsigned  cvRandNext( CvRandState* state );
-CV_INLINE  unsigned  cvRandNext( CvRandState* state )
-{
-    uint64 temp = 0;
-
-    if( state )
-    {
-        temp = state->state;
-        temp = (uint64)(unsigned)temp*1554115554 + (temp >> 32);
-        state->state = temp;
-    }
-
-    return (unsigned)temp;
-}
-
-
-/****************************************************************************************\
-*                                Matrix operations                                       *
-\****************************************************************************************/
-
-/* Calculates cross product of two 3d vectors */
-OPENCVAPI  void  cvCrossProduct( const CvArr* srcA, const CvArr* srcB, CvArr* dst );
-
-/* Matrix transform: dst = A*B + C, C is optional */
-OPENCVAPI  void  cvMatMulAdd( const CvArr* srcA, const CvArr* srcB,
-                              const CvArr* srcC, CvArr* dst );
-#define cvMatMul( srcA, srcB, dst )  cvMatMulAdd( (srcA), (srcB), NULL, (dst))
-
-#define CV_GEMM_A_T 1
-#define CV_GEMM_B_T 2
-#define CV_GEMM_C_T 4
-/* Extended matrix transform:
-   dst = alpha*op(A)*op(B) + beta*op(C), where op(X) is X or X^T */
-OPENCVAPI  void  cvGEMM( const CvArr* srcA, const CvArr* srcB, double alpha,
-                         const CvArr* srcC, double beta, CvArr* dst,
-                         int tABC CV_DEFAULT(0));
-#define cvMatMulAddEx cvGEMM
-
-/* Transforms each element of source array and stores
-   resultant vectors in destination array */
-OPENCVAPI  void  cvMatMulAddS( const CvArr* src, CvArr* dst,
-                               const CvMat* transform,
-                               const CvMat* shiftvec CV_DEFAULT(NULL));
-#define cvTransform cvMatMulAddS
-
-/* Calculates A*A^T (order=0) or A^T*A (order=1) */
-OPENCVAPI void cvMulTransposed( const CvArr* srcarr,
-                                CvArr* dstarr, int order );
-
-/* Tranposes matrix. Square matrices can be transposed in-place */
-OPENCVAPI  void  cvTranspose( const CvArr* src, CvArr* dst );
-#define cvT cvTranspose
-
-
-/* Mirror array data around horizontal (flip=0),
-   vertical (flip=1) or both(flip=-1) axises:
-   cvFlip(src) flips images vertically and sequences horizontally (inplace) */
-OPENCVAPI  void  cvFlip( const CvArr* src, CvArr* dst CV_DEFAULT(NULL),
-                         int flip_mode CV_DEFAULT(0));
-#define cvMirror cvFlip
-
-
-#define CV_SVD_MODIFY_A   1
-#define CV_SVD_U_T        2
-#define CV_SVD_V_T        4
-
-/* Performs Singular Value Decomposition of a matrix */
-OPENCVAPI  void   cvSVD( CvArr* A, CvArr* W CV_DEFAULT(NULL),
-                         CvArr* U CV_DEFAULT(NULL),
-                         CvArr* V CV_DEFAULT(NULL),
-                         int flags CV_DEFAULT(0));
-
-/* Performs Singular Value Back Substitution:
-   flags must be the same as in cvSVD */
-OPENCVAPI  void   cvSVBkSb( const CvArr* warr, const CvArr* uarr,
-                            const CvArr* varr, const CvArr* barr,
-                            CvArr* xarr, int flags );
-
-#define CV_LU  0
-#define CV_SVD 1
-/* Inverts matrix */
-OPENCVAPI  double  cvInvert( const CvArr* src, CvArr* dst,
-                             int method CV_DEFAULT(CV_LU));
-#define cvInv cvInvert
-
-/* Solves linear system Ax = b
-   (returns 0 if A is singular) */
-OPENCVAPI  int  cvSolve( const CvArr* A, const CvArr* b, CvArr* x,
-                         int method CV_DEFAULT(CV_LU));
-
-/* Calculates determinant of input matrix */
-OPENCVAPI  double cvDet( const CvArr* mat );
-
-/* Calculates trace of the matrix (sum of elements on the main diagonal) */
-OPENCVAPI  CvScalar cvTrace( const CvArr* mat );
-
-/* Finds eigen values and vectors of a _symmetric_ matrix */
-OPENCVAPI  void  cvEigenVV( CvArr* src, CvArr* evects, CvArr* evals, double eps );
-
-/* Makes an identity matrix (mat_ij = i == j) */
-OPENCVAPI  void  cvSetIdentity( CvArr* mat, CvScalar value CV_DEFAULT(cvScalar(1)) );
-
-/* Does perspective transform on every element of input array */
-OPENCVAPI  void  cvPerspectiveTransform( const CvArr* src, CvArr* dst, const CvArr* mat );
-
-/* Calculates covariation matrix for a set of vectors */
-OPENCVAPI  void  cvCalcCovarMatrix( const CvArr** vects, CvArr* covarMatrix, CvArr* avg );
-
-/* Calculates Mahalanobis(weighted) distance */
-OPENCVAPI  double  cvMahalanobis( const CvArr* srcA, const CvArr* srcB, CvArr* mat );
-#define cvMahalonobis  cvMahalanobis
-
-/****************************************************************************************\
-*                                    Array Statistics                                    *
-\****************************************************************************************/
-
-/* Finds sum of array elements */
-OPENCVAPI  CvScalar  cvSum( const CvArr* array );
-
-
-/* Calculates number of non-zero pixels */
-OPENCVAPI  int  cvCountNonZero( const CvArr* array );
-
-
-/* Calculates mean value of array elements */
-OPENCVAPI  CvScalar  cvAvg( const CvArr* array, const CvArr* mask CV_DEFAULT(NULL) );
-
-/* Calculates mean and standard deviation of pixel values */
-OPENCVAPI  void  cvAvgSdv( const CvArr* array, CvScalar* mean, CvScalar* std_dev,
-                           const CvArr* mask CV_DEFAULT(NULL) );
-
-/* Finds global minimum, maximum among the input array elements and positions
-   of the extremums */
-OPENCVAPI  void  cvMinMaxLoc( const CvArr* array, double* min_val, double* max_val,
-                              CvPoint* min_loc CV_DEFAULT(NULL),
-                              CvPoint* max_loc CV_DEFAULT(NULL),
-                              const CvArr* mask CV_DEFAULT(NULL) );
-
-/* spatial and central moments */
-typedef struct CvMoments
-{
-    double  m00, m10, m01, m20, m11, m02, m30, m21, m12, m03; /* spatial moments */
-    double  mu20, mu11, mu02, mu30, mu21, mu12, mu03; /* central moments */
-    double  inv_sqrt_m00; /* m00 != 0 ? 1/sqrt(m00) : 0 */
-} CvMoments;
-
-/* Calculates all spatial and central moments up to the 3rd order */
-OPENCVAPI void cvMoments( const CvArr* array, CvMoments* moments, int binary CV_DEFAULT(0));
-
-/* Retrieve particular spatial, central or normalized central moments */
-OPENCVAPI  double  cvGetSpatialMoment( CvMoments* moments, int x_order, int y_order );
-OPENCVAPI  double  cvGetCentralMoment( CvMoments* moments, int x_order, int y_order );
-OPENCVAPI  double  cvGetNormalizedCentralMoment( CvMoments* moments,
-                                                 int x_order, int y_order );
-
-/* Hu invariants */
-typedef struct CvHuMoments
-{
-    double hu1, hu2, hu3, hu4, hu5, hu6, hu7; /* Hu invariants */
-} CvHuMoments;
-
-/* Calculates 7 Hu's invariants from precalculated spatial and central moments */
-OPENCVAPI void cvGetHuMoments( CvMoments*  moments, CvHuMoments*  hu_moments );
-
-/* types of array norm */
-#define CV_C            1
-#define CV_L1           2
-#define CV_L2           4
-#define CV_NORM_MASK    7
-#define CV_RELATIVE     8
-#define CV_DIFF         16
-
-#define CV_DIFF_C       (CV_DIFF | CV_C)
-#define CV_DIFF_L1      (CV_DIFF | CV_L1)
-#define CV_DIFF_L2      (CV_DIFF | CV_L2)
-#define CV_RELATIVE_C   (CV_RELATIVE | CV_C)
-#define CV_RELATIVE_L1  (CV_RELATIVE | CV_L1)
-#define CV_RELATIVE_L2  (CV_RELATIVE | CV_L2)
-
-/* Finds norm, difference norm or relative difference norm for an array (two arrays) */
-OPENCVAPI  double  cvNorm( const CvArr* imgA, const CvArr* imgB CV_DEFAULT(NULL),
-                           int normType CV_DEFAULT(CV_L2),
-                           const CvArr* mask CV_DEFAULT(NULL) );
-
-/****************************************************************************************\
-*                              Dynamic data structures                                   *
-\****************************************************************************************/
-
-/* Creates new memory storage.
-   block_size == 0 means that default,
-   somewhat optimal size, is used (currently, it is 64K) */
-OPENCVAPI  CvMemStorage*  cvCreateMemStorage( int block_size CV_DEFAULT(0));
-
-
-/* Creates a memory storage that will borrow memory blocks from parent storage */
-OPENCVAPI  CvMemStorage*  cvCreateChildMemStorage( CvMemStorage* parent );
-
-
-/* Releases memory storage. All the children of a parent must be released before
-   the parent. A child storage returns all the blocks to parent when it is released */
-OPENCVAPI  void  cvReleaseMemStorage( CvMemStorage** storage );
-
-
-/* Clears memory storage. This is the only way(!!!) (besides cvRestoreMemStoragePos)
-   to reuse memory allocated for the storage - cvClearSeq,cvClearSet ...
-   do not free any memory.
-   A child storage returns all the blocks to the parent when it is cleared */
-OPENCVAPI  void  cvClearMemStorage( CvMemStorage* storage );
-
-/* Remember a storage "free memory" position */
-OPENCVAPI  void  cvSaveMemStoragePos( const CvMemStorage* storage, CvMemStoragePos* pos );
-
-/* Restore a storage "free memory" position */
-OPENCVAPI  void  cvRestoreMemStoragePos( CvMemStorage* storage, CvMemStoragePos* pos );
-
-/* Allocates continuous buffer of the specified size in the storage */
-OPENCVAPI  void* cvMemStorageAlloc( CvMemStorage* storage, int size );
-
-/* Creates new empty sequence that will reside in the specified storage */
-OPENCVAPI  CvSeq*  cvCreateSeq( int seq_flags, int header_size,
-                             int elem_size, CvMemStorage* storage );
-
-/* Changes default size (granularity) of sequence blocks.
-   The default size is ~1Kbyte */
-OPENCVAPI  void  cvSetSeqBlockSize( CvSeq* seq, int delta_elements );
-
-
-/* Adds new element to the end of sequence. Returns pointer to the element */
-OPENCVAPI  char*  cvSeqPush( CvSeq* seq, void* element CV_DEFAULT(NULL));
-
-
-/* Adds new element to the beginning of sequence. Returns pointer to it */
-OPENCVAPI  char*  cvSeqPushFront( CvSeq* seq, void* element CV_DEFAULT(NULL));
-
-
-/* Removes the last element from sequence and optionally saves it */
-OPENCVAPI  void  cvSeqPop( CvSeq* seq, void* element CV_DEFAULT(NULL));
-
-
-/* Removes the first element from sequence and optioanally saves it */
-OPENCVAPI  void  cvSeqPopFront( CvSeq* seq, void* element CV_DEFAULT(NULL));
-
-
-#define CV_FRONT 1
-#define CV_BACK 0
-/* Adds several new elements to the end of sequence */
-OPENCVAPI  void  cvSeqPushMulti( CvSeq* seq, void* elements,
-                                 int count, int in_front CV_DEFAULT(0) );
-
-/* Removes several elements from the end of sequence and optionally saves them */
-OPENCVAPI  void  cvSeqPopMulti( CvSeq* seq, void* elements,
-                                int count, int in_front CV_DEFAULT(0) );
-
-/* Inserts a new element in the middle of sequence.
-   cvSeqInsert(seq,0,elem) == cvSeqPushFront(seq,elem) */
-OPENCVAPI  char*  cvSeqInsert( CvSeq* seq, int before_index,
-                               void* element CV_DEFAULT(NULL));
-
-/* Removes specified sequence element */
-OPENCVAPI  void  cvSeqRemove( CvSeq* seq, int index );
-
-
-/* Removes all the elements from the sequence. The freed memory
-   can be reused later only by the same sequence unless cvClearMemStorage
-   or cvRestoreMemStoragePos is called */
-OPENCVAPI  void  cvClearSeq( CvSeq* seq );
-
-
-/* Retrives pointer to specified sequence element.
-   Negative indices are supported and mean counting from the end
-   (e.g -1 means the last sequence element) */
-OPENCVAPI  char*  cvGetSeqElem( CvSeq* seq, int index, CvSeqBlock** block CV_DEFAULT(NULL) );
-
-
-/* Calculates index of the specified sequence element.
-   Returns -1 if element does not belong to the sequence */
-OPENCVAPI int  cvSeqElemIdx( const CvSeq* seq, const void* element,
-                             CvSeqBlock** block CV_DEFAULT(NULL) );
-
-/* Initializes sequence writer. The new elements will be added to the end of sequence */
-OPENCVAPI  void  cvStartAppendToSeq( CvSeq* seq, CvSeqWriter* writer );
-
-
-/* Combination of cvCreateSeq and cvStartAppendToSeq */
-OPENCVAPI  void  cvStartWriteSeq( int seq_flags, int header_size,
-                                  int elem_size, CvMemStorage* storage,
-                                  CvSeqWriter* writer );
-
-/* Closes sequence writer, updates sequence header and returns pointer
-   to the resultant sequence
-   (which may be useful if the sequence was created using cvStartWriteSeq))
-*/
-OPENCVAPI  CvSeq*  cvEndWriteSeq( CvSeqWriter* writer );
-
-
-/* Updates sequence header. May be useful to get access to some of previously
-   written elements via cvGetSeqElem or sequence reader */
-OPENCVAPI  void   cvFlushSeqWriter( CvSeqWriter* writer );
-
-
-/* Initializes sequence reader.
-   The sequence can be read in forward or backward direction */
-OPENCVAPI void cvStartReadSeq( const CvSeq* seq, CvSeqReader* reader,
-                               int reverse CV_DEFAULT(0) );
-
-
-/* Returns current sequence reader position (currently observed sequence element) */
-OPENCVAPI  int  cvGetSeqReaderPos( CvSeqReader* reader );
-
-
-/* Changes sequence reader position. It may seek to an absolute or
-   to relative to the current position */
-OPENCVAPI  void   cvSetSeqReaderPos( CvSeqReader* reader, int index,
-                                     int is_relative CV_DEFAULT(0));
-
-/* Copies sequence content to an array */
-OPENCVAPI  void*  cvCvtSeqToArray( CvSeq* seq, CvArr* array,
-                                   CvSlice slice CV_DEFAULT(CV_WHOLE_SEQ) );
-
-/* Creates sequence header for array.
-   After that all the operations on sequences that do not alter the content
-   can be applied to the resultant sequence */
-OPENCVAPI  CvSeq* cvMakeSeqHeaderForArray( int seq_type, int header_size,
-                                           int elem_size, void* elements, int total,
-                                           CvSeq* seq, CvSeqBlock* block );
-
-/* Extracts sequence slice (with or without copying sequence elements */
-OPENCVAPI CvSeq* cvSeqSlice( CvSeq* seq, CvSlice slice,
-                             CvMemStorage* storage CV_DEFAULT(NULL),
-                             int copy_data CV_DEFAULT(0));
-
-CV_INLINE CvSeq* cvCloneSeq( CvSeq* seq, CvMemStorage* storage CV_DEFAULT(NULL));
-CV_INLINE CvSeq* cvCloneSeq( CvSeq* seq, CvMemStorage* storage )
-{
-    return cvSeqSlice( seq, CV_WHOLE_SEQ, storage, 1 );
-}
-
-/* Removes sequence slice */
-OPENCVAPI  void  cvSeqRemoveSlice( CvSeq* seq, CvSlice slice );
-
-/* Inserts a sequence or array into another sequence */
-OPENCVAPI  void  cvSeqInsertSlice( CvSeq* seq, int index, const CvArr* from_arr );
-
-/* a < b ? -1 : a > b ? 1 : 0 */
-CV_EXTERN_C_FUNCPTR( int (CV_CDECL* CvCmpFunc)
-                     (const void* a, const void* b, void* userdata ));
-
-/* Sorts sequence in-place given element comparison function */
-OPENCVAPI  void cvSeqSort( CvSeq* seq, CvCmpFunc func, void* userdata );
-
-/* Reverses order of sequence elements in-place */
-OPENCVAPI  void cvSeqInvert( CvSeq* seq );
-
-/* Splits sequence into set of equivalency classes
-   using specified equivalency criteria */
-OPENCVAPI  int  cvPartitionSeq( CvSeq* seq, CvMemStorage* storage, CvSeq** comps,
-                                CvCmpFunc is_equal, void* userdata, int is_set );
-
-/************ Internal sequence functions ************/
-OPENCVAPI  void  cvChangeSeqBlock( CvSeqReader* reader, int direction );
-OPENCVAPI  void  cvCreateSeqBlock( CvSeqWriter* writer );
-
-
-/* Creates a new set */
-OPENCVAPI  CvSet*  cvCreateSet( int set_flags, int header_size,
-                                int elem_size, CvMemStorage* storage );
-
-/* Adds new element to the set and returns pointer to it */
-OPENCVAPI  int  cvSetAdd( CvSet* set_header, CvSetElem* element CV_DEFAULT(NULL),
-                          CvSetElem** inserted_element CV_DEFAULT(NULL) );
-
-/* Fast variant of cvSetAdd */
-CV_INLINE  CvSetElem* cvSetNew( CvSet* set_header );
-CV_INLINE  CvSetElem* cvSetNew( CvSet* set_header )
-{
-    CvSetElem* elem = set_header->free_elems;
-    if( elem )
-    {
-        set_header->free_elems = elem->next_free;
-        elem->flags = elem->flags & CV_SET_ELEM_IDX_MASK;
-    }
-    else
-        cvSetAdd( set_header, NULL, (CvSetElem**)&elem );
-    return elem;
-}
-
-/* Removes set element given its pointer */
-CV_INLINE  void cvSetRemoveByPtr( CvSet* set_header, void* _elem );
-CV_INLINE  void cvSetRemoveByPtr( CvSet* set_header, void* _elem )
-{
-    CvSetElem* elem = (CvSetElem*)_elem;
-    assert( elem->flags >= 0 && (elem->flags & CV_SET_ELEM_IDX_MASK) < set_header->total );
-    elem->next_free = set_header->free_elems;
-    elem->flags = (elem->flags & CV_SET_ELEM_IDX_MASK) | CV_SET_ELEM_FREE_FLAG;
-    set_header->free_elems = elem;
-}
-
-
-/* Removes element from the set by its index  */
-OPENCVAPI  void   cvSetRemove( CvSet* set_header, int index );
-
-
-/* Returns a set element by index. If the element doesn't belong to the set,
-   NULL is returned */
-OPENCVAPI  CvSetElem*  cvGetSetElem( CvSet* set_header, int index );
-
-
-/* Removes all the elements from the set */
-OPENCVAPI  void  cvClearSet( CvSet* set_header );
-
-
-/* Creates new graph */
-OPENCVAPI  CvGraph*   cvCreateGraph( int graph_flags, int header_size,
-                                  int vtx_size, int edge_size,
-                                  CvMemStorage* storage );
-
-/* Adds new vertex to the graph */
-OPENCVAPI  int  cvGraphAddVtx( CvGraph* graph, CvGraphVtx* vertex CV_DEFAULT(NULL),
-                               CvGraphVtx** inserted_vertex CV_DEFAULT(NULL) );
-
-
-/* Removes vertex from the graph together with all incident edges */
-OPENCVAPI  void   cvGraphRemoveVtx( CvGraph* graph, int index );
-OPENCVAPI  void   cvGraphRemoveVtxByPtr( CvGraph* graph, CvGraphVtx* vtx );
-
-
-/* Link two vertices specifed by indices or pointers if they
-   are not connected or return pointer to already existing edge
-   connecting the vertices.
-   Functions return 1 if a new edge was created, 0 otherwise */
-OPENCVAPI  int  cvGraphAddEdge( CvGraph* graph,
-                                int start_idx, int end_idx,
-                                CvGraphEdge* edge CV_DEFAULT(NULL),
-                                CvGraphEdge** inserted_edge CV_DEFAULT(NULL) );
-
-OPENCVAPI  int  cvGraphAddEdgeByPtr( CvGraph* graph,
-                               CvGraphVtx* start_vtx, CvGraphVtx* end_vtx,
-                               CvGraphEdge* edge CV_DEFAULT(NULL),
-                               CvGraphEdge** inserted_edge CV_DEFAULT(NULL) );
-
-/* Remove edge connecting two vertices */
-OPENCVAPI  void  cvGraphRemoveEdge( CvGraph* graph, int start_idx, int end_idx );
-OPENCVAPI  void  cvGraphRemoveEdgeByPtr( CvGraph* graph, CvGraphVtx* start_vtx,
-                                         CvGraphVtx* end_vtx );
-
-/* Find edge connecting two vertices */
-OPENCVAPI  CvGraphEdge*  cvFindGraphEdge( CvGraph* graph, int start_idx, int end_idx );
-OPENCVAPI  CvGraphEdge*  cvFindGraphEdgeByPtr( CvGraph* graph, CvGraphVtx* start_vtx,
-                                               CvGraphVtx* end_vtx );
-#define cvGraphFindEdge cvFindGraphEdge
-#define cvGraphFindEdgeByPtr cvFindGraphEdgeByPtr
-
-/* Remove all vertices and edges from the graph */
-OPENCVAPI  void  cvClearGraph( CvGraph* graph );
-
-
-/* Count number of edges incident to the vertex */
-OPENCVAPI  int  cvGraphVtxDegree( CvGraph* graph, int vtx_idx );
-OPENCVAPI  int  cvGraphVtxDegreeByPtr( CvGraph* graph, CvGraphVtx* vtx );
-
-
-/* Retrieves graph vertex by given index */
-#define cvGetGraphVtx( graph, idx ) (CvGraphVtx*)cvGetSetElem((CvSet*)(graph), (idx))
-
-/* Retrieves index of a graph vertex given its pointer */
-#define cvGraphVtxIdx( graph, vtx ) ((vtx)->flags & CV_SET_ELEM_IDX_MASK)
-
-/* Retrieves index of a graph edge given its pointer */
-#define cvGraphEdgeIdx( graph, edge ) ((edge)->flags & CV_SET_ELEM_IDX_MASK)
-
-
-#define  CV_GRAPH_VERTEX        1
-#define  CV_GRAPH_TREE_EDGE     2
-#define  CV_GRAPH_BACK_EDGE     4
-#define  CV_GRAPH_FORWARD_EDGE  8
-#define  CV_GRAPH_CROSS_EDGE    16
-#define  CV_GRAPH_ANY_EDGE      30
-#define  CV_GRAPH_NEW_TREE      32
-#define  CV_GRAPH_BACKTRACKING  64
-#define  CV_GRAPH_OVER          -1
-
-#define  CV_GRAPH_ALL_ITEMS    -1
-
-/* flags for graph vertices and edges */
-#define  CV_GRAPH_ITEM_VISITED_FLAG  (1 << 30)
-#define  CV_IS_GRAPH_VERTEX_VISITED(vtx) \
-    (((CvGraphVtx*)(vtx))->flags & CV_GRAPH_ITEM_VISITED_FLAG)
-#define  CV_IS_GRAPH_EDGE_VISITED(edge) \
-    (((CvGraphEdge*)(edge))->flags & CV_GRAPH_ITEM_VISITED_FLAG)
-#define  CV_GRAPH_SEARCH_TREE_NODE_FLAG   (1 << 29)
-#define  CV_GRAPH_FORWARD_EDGE_FLAG       (1 << 28)
-
-typedef struct CvGraphScanner
-{
-    CvGraphVtx* vtx;       /* current graph vertex (or current edge origin) */
-    CvGraphVtx* dst;       /* current graph edge destination vertex */
-    CvGraphEdge* edge;     /* current edge */
-
-    CvGraph* graph;        /* the graph */
-    CvSeq*   stack;        /* the graph vertex stack */
-    int      index;        /* the lower bound of certainly visited vertices */
-    int      mask;         /* event mask */
-}
-CvGraphScanner;
-
-/* Initializes graph traversal process.
-   <mask> indicates what events one wants to handle. */
-OPENCVAPI void  cvStartScanGraph( CvGraph* graph, CvGraphScanner* scanner,
-                                  CvGraphVtx* vtx CV_DEFAULT(NULL),
-                                  int mask CV_DEFAULT(CV_GRAPH_ALL_ITEMS));
-
-/* Initializes graph traversal process.
-   <mask> indicates what events one wants to handle. */
-OPENCVAPI void  cvEndScanGraph( CvGraphScanner* scanner );
-
-/* Get next graph element */
-OPENCVAPI int  cvNextGraphItem( CvGraphScanner* scanner );
-
-/* Creates a copy of graph */
-OPENCVAPI CvGraph* cvCloneGraph( const CvGraph* graph, CvMemStorage* storage );
-
 /****************************************************************************************\
 *                                    Image Processing                                    *
 \****************************************************************************************/
 
-/* Does look-up transformation. Elements of the source array
-   (that should be 8uC1 or 8sC1) are used as indexes in lutarr 256-element table */
-OPENCVAPI  void cvLUT( const CvArr* srcarr, CvArr* dstarr, const CvArr* lutarr );
-
-
-/* Smoothes array (remove noise) */
 #define CV_BLUR_NO_SCALE 0
 #define CV_BLUR  1
 #define CV_GAUSSIAN  2
 #define CV_MEDIAN 3
 #define CV_BILATERAL 4
 
-OPENCVAPI  void cvSmooth( const CvArr* srcarr, CvArr* dstarr,
-                          int smoothtype CV_DEFAULT(CV_GAUSSIAN),
-                          int param1 CV_DEFAULT(3),
-                          int param2 CV_DEFAULT(0));
+/* Smoothes array (removes noise) */
+CVAPI(void) cvSmooth( const CvArr* src, CvArr* dst,
+                      int smoothtype CV_DEFAULT(CV_GAUSSIAN),
+                      int param1 CV_DEFAULT(3),
+                      int param2 CV_DEFAULT(0),
+                      double param3 CV_DEFAULT(0) );
+
+/* Linear filter */
+CVAPI(void) cvFilter2D( const CvArr* src, CvArr* dst, const CvMat* kernel,
+                        CvPoint anchor CV_DEFAULT(cvPoint(-1,-1)));
+#define cvConvolve2D cvFilter2D
 
 /* Finds integral image: SUM(X,Y) = sum(x<X,y<Y)I(x,y) */
-OPENCVAPI void cvIntegral( const CvArr* image, CvArr* sumImage,
-                           CvArr* sumSqImage CV_DEFAULT(NULL),
-                           CvArr* tiltedSumImage CV_DEFAULT(NULL));
+CVAPI(void) cvIntegral( const CvArr* image, CvArr* sum,
+                       CvArr* sqsum CV_DEFAULT(NULL),
+                       CvArr* tilted_sum CV_DEFAULT(NULL));
 
 /*
    Down-samples image with prior gaussian smoothing.
    dst_width = floor(src_width/2)[+1],
    dst_height = floor(src_height/2)[+1]
 */
-OPENCVAPI  void  cvPyrDown( const CvArr* src, CvArr* dst,
-                            int filter CV_DEFAULT(CV_GAUSSIAN_5x5) );
+CVAPI(void)  cvPyrDown( const CvArr* src, CvArr* dst,
+                        int filter CV_DEFAULT(CV_GAUSSIAN_5x5) );
 
 /* 
    Up-samples image with posterior gaussian smoothing.
    dst_width = src_width*2,
    dst_height = src_height*2
 */
-OPENCVAPI  void  cvPyrUp( const CvArr* src, CvArr* dst,
-                          int filter CV_DEFAULT(CV_GAUSSIAN_5x5) );
+CVAPI(void)  cvPyrUp( const CvArr* src, CvArr* dst,
+                      int filter CV_DEFAULT(CV_GAUSSIAN_5x5) );
 
 
 /* Builds the whole pyramid at once. Output array of CvMat headers (levels[*])
    is initialized with the headers of subsequent pyramid levels */
-/*OPENCVAPI  void  cvCalcPyramid( const CvArr* src, CvArr* container,
-                                CvMat* levels, int levelCount,
-                                int filter CV_DEFAULT(CV_GAUSSIAN_5x5) );*/
+/*CVAPI  void  cvCalcPyramid( const CvArr* src, CvArr* container,
+                              CvMat* levels, int level_count,
+                              int filter CV_DEFAULT(CV_GAUSSIAN_5x5) );*/
 
 
 /* Segments image using son-father links (modification of Burt's algorithm).
    CvSeq<CvConnectedComp*> is returned to *comp */
-OPENCVAPI void cvPyrSegmentation( IplImage* src,
-                               IplImage* dst,
-                               CvMemStorage *storage,
-                               CvSeq **comp,
-                               int level, double threshold1,
-                               double threshold2 );
+CVAPI(void) cvPyrSegmentation( IplImage* src,
+                              IplImage* dst,
+                              CvMemStorage* storage,
+                              CvSeq** comp,
+                              int level, double threshold1,
+                              double threshold2 );
 
 
 #define CV_SCHARR -1
 
-/* calculates some image derivative using Sobel (apertureSize = 1,3,5,7)
-   or Scharr (apertureSize = -1) operator.
+/* calculates some image derivative using Sobel (aperture_size = 1,3,5,7)
+   or Scharr (aperture_size = -1) operator.
    Scharr can be used only for the first dx or dy derivative */
-OPENCVAPI void cvSobel( const CvArr* src, CvArr* dst,
-                        int xorder, int yorder,
-                        int apertureSize CV_DEFAULT(3));
+CVAPI(void) cvSobel( const CvArr* src, CvArr* dst,
+                    int xorder, int yorder,
+                    int aperture_size CV_DEFAULT(3));
 
 /* Calculates Laplace operator: (d2/dx + d2/dy)I */
-OPENCVAPI void cvLaplace( const CvArr* src, CvArr* dst,
-                          int apertureSize CV_DEFAULT(3) );
+CVAPI(void) cvLaplace( const CvArr* src, CvArr* dst,
+                      int aperture_size CV_DEFAULT(3) );
 
 /* Constants for color conversion */
 #define  CV_BGR2BGRA    0
@@ -1266,47 +174,79 @@ OPENCVAPI void cvLaplace( const CvArr* src, CvArr* dst,
 #define  CV_GRAY2BGR565 20
 #define  CV_BGR5652GRAY 21
 
-#define  CV_BGR2XYZ     22
-#define  CV_RGB2XYZ     23
-#define  CV_XYZ2BGR     24
-#define  CV_XYZ2RGB     25
+#define  CV_BGR2BGR555  22
+#define  CV_RGB2BGR555  23
+#define  CV_BGR5552BGR  24
+#define  CV_BGR5552RGB  25
+#define  CV_BGRA2BGR555 26
+#define  CV_RGBA2BGR555 27
+#define  CV_BGR5552BGRA 28
+#define  CV_BGR5552RGBA 29
 
-#define  CV_BGR2YCrCb   26
-#define  CV_RGB2YCrCb   27
-#define  CV_YCrCb2BGR   28
-#define  CV_YCrCb2RGB   29
+#define  CV_GRAY2BGR555 30
+#define  CV_BGR5552GRAY 31
 
-#define  CV_BGR2HSV     30
-#define  CV_RGB2HSV     31
+#define  CV_BGR2XYZ     32
+#define  CV_RGB2XYZ     33
+#define  CV_XYZ2BGR     34
+#define  CV_XYZ2RGB     35
 
-#define  CV_BGR2Lab     34
-#define  CV_RGB2Lab     35
+#define  CV_BGR2YCrCb   36
+#define  CV_RGB2YCrCb   37
+#define  CV_YCrCb2BGR   38
+#define  CV_YCrCb2RGB   39
 
-#define  CV_BayerBG2BGR 40
-#define  CV_BayerGB2BGR 41
-#define  CV_BayerRG2BGR 42
-#define  CV_BayerGR2BGR 43
+#define  CV_BGR2HSV     40
+#define  CV_RGB2HSV     41
+
+#define  CV_BGR2Lab     44
+#define  CV_RGB2Lab     45
+
+#define  CV_BayerBG2BGR 46
+#define  CV_BayerGB2BGR 47
+#define  CV_BayerRG2BGR 48
+#define  CV_BayerGR2BGR 49
 
 #define  CV_BayerBG2RGB CV_BayerRG2BGR
 #define  CV_BayerGB2RGB CV_BayerGR2BGR
 #define  CV_BayerRG2RGB CV_BayerBG2BGR
 #define  CV_BayerGR2RGB CV_BayerGB2BGR
 
-#define  CV_COLORCVT_MAX  48
-
-/* Converts input array from one color space to another.
-   Only 8-bit images are supported now */
-OPENCVAPI  void  cvCvtColor( const CvArr* src, CvArr* dst, int colorCvtCode );
+#define  CV_COLORCVT_MAX  56
 
+/* Converts input array from one color space to another */
+CVAPI(void)  cvCvtColor( const CvArr* src, CvArr* dst, int code );
 
 #define  CV_INTER_NN        0
 #define  CV_INTER_LINEAR    1
-/*#define  CV_INTER_CUBIC     2 - not implemented yet */
+#define  CV_INTER_CUBIC     2
+#define  CV_INTER_AREA      3
+
+#define  CV_WARP_FILL_OUTLIERS 8
+#define  CV_WARP_INVERSE_MAP  16
+
+/* Resizes image (input array is resized to fit the destination array) */
+CVAPI(void)  cvResize( const CvArr* src, CvArr* dst,
+                       int interpolation CV_DEFAULT( CV_INTER_LINEAR ));
+
+/* Warps image with affine transform */ 
+CVAPI(void)  cvWarpAffine( const CvArr* src, CvArr* dst, const CvMat* map_matrix,
+                           int flags CV_DEFAULT(CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS),
+                           CvScalar fillval CV_DEFAULT(cvScalarAll(0)) );
+
+/* Computes rotation_matrix matrix */
+CVAPI(CvMat*)  cv2DRotationMatrix( CvPoint2D32f center, double angle,
+                                   double scale, CvMat* map_matrix );
 
-/* Resizes 1D-2D array. Destination size is determined by the size of destination array */
-OPENCVAPI  void  cvResize( const CvArr* src, CvArr* dst,
-                           int method CV_DEFAULT( CV_INTER_LINEAR ));
+/* Warps image with perspective (projective) transform */
+CVAPI(void)  cvWarpPerspective( const CvArr* src, CvArr* dst, const CvMat* map_matrix,
+                                int flags CV_DEFAULT(CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS),
+                                CvScalar fillval CV_DEFAULT(cvScalarAll(0)) );
 
+/* Computes perspective transform matrix for mapping src[i] to dst[i] (i=0,1,2,3) */
+CVAPI(CvMat*) cvWarpPerspectiveQMatrix( const CvPoint2D32f* src,
+                                       const CvPoint2D32f* dst,
+                                       CvMat* map_matrix );
 
 #define  CV_SHAPE_RECT      0
 #define  CV_SHAPE_CROSS     1
@@ -1314,25 +254,25 @@ OPENCVAPI  void  cvResize( const CvArr* src, CvArr* dst,
 #define  CV_SHAPE_CUSTOM    100
 
 /* creates structuring element used for morphological operations */
-OPENCVAPI  IplConvKernel*  cvCreateStructuringElementEx(
-            int  cols, int  rows, int  anchorX, int  anchorY,
+CVAPI(IplConvKernel*)  cvCreateStructuringElementEx(
+            int cols, int  rows, int  anchor_x, int  anchor_y,
             int shape, int* values CV_DEFAULT(NULL) );
 
 /* releases structuring element */
-OPENCVAPI  void  cvReleaseStructuringElement( IplConvKernel** element );
+CVAPI(void)  cvReleaseStructuringElement( IplConvKernel** element );
 
 
 /* erodes input image (applies minimum filter) one or more times.
    If element pointer is NULL, 3x3 rectangular element is used */
-OPENCVAPI  void  cvErode( const CvArr* src, CvArr* dst,
-                          IplConvKernel* element CV_DEFAULT(NULL),
-                          int iterations CV_DEFAULT(1) );
+CVAPI(void)  cvErode( const CvArr* src, CvArr* dst,
+                      IplConvKernel* element CV_DEFAULT(NULL),
+                      int iterations CV_DEFAULT(1) );
 
 /* dilates input image (applies maximum filter) one or more times.
    If element pointer is NULL, 3x3 rectangular element is used */
-OPENCVAPI  void  cvDilate( const CvArr* src, CvArr* dst,
-                           IplConvKernel* element CV_DEFAULT(NULL),
-                           int iterations CV_DEFAULT(1) );
+CVAPI(void)  cvDilate( const CvArr* src, CvArr* dst,
+                       IplConvKernel* element CV_DEFAULT(NULL),
+                       int iterations CV_DEFAULT(1) );
 
 #define CV_MOP_OPEN         2
 #define CV_MOP_CLOSE        3
@@ -1341,163 +281,50 @@ OPENCVAPI  void  cvDilate( const CvArr* src, CvArr* dst,
 #define CV_MOP_BLACKHAT     6
 
 /* performs complex morphological transformation */
-OPENCVAPI  void  cvMorphologyEx( const CvArr* src, CvArr* dst,
-                                 CvArr* temp, IplConvKernel* element,
-                                 int operation, int iterations CV_DEFAULT(1) );
-
-
-/****************************************************************************************\
-*                                     Drawing                                            *
-\****************************************************************************************/
-
-/****************************************************************************************\
-*       Drawing functions work with arbitrary 8-bit images or single-channel images      *
-*       with larger depth: 16s, 32s, 32f, 64f                                            *
-*       All the functions include parameter color that means rgb value (that may be      *
-*       constructed with CV_RGB macro) for color images and brightness                   *
-*       for grayscale images.                                                            *
-*       If a drawn figure is partially or completely outside the image, it is clipped.   *
-\****************************************************************************************/
+CVAPI(void)  cvMorphologyEx( const CvArr* src, CvArr* dst,
+                             CvArr* temp, IplConvKernel* element,
+                             int operation, int iterations CV_DEFAULT(1) );
 
-#define CV_RGB( r, g, b )  (int)((uchar)(b) + ((uchar)(g) << 8) + ((uchar)(r) << 16))
-#define CV_FILLED -1
-
-/* Draws 4-connected or 8-connected line segment connecting two points */
-OPENCVAPI  void  cvLine( CvArr* array, CvPoint pt1, CvPoint pt2,
-                         double color, int thickness CV_DEFAULT(1),
-                         int connectivity CV_DEFAULT(8) );
-
-/* Draws 8-connected line segment connecting two points with antialiazing.
-   Ending coordinates may be specified with sub-pixel accuracy
-   (scale is number of fractional bits in the coordinates) */
-OPENCVAPI  void  cvLineAA( CvArr* array, CvPoint pt1, CvPoint pt2,
-                           double color, int scale CV_DEFAULT(0));
-
-/* Draws a rectangle given two opposite corners of the rectangle (pt1 & pt2),
-   if thickness<0 (e.g. thickness == CV_FILLED), the filled box is drawn */
-OPENCVAPI  void  cvRectangle( CvArr* array, CvPoint pt1, CvPoint pt2,
-                              double color, int thickness CV_DEFAULT(1));
-
-/* Draws a circle with specified center and radius.
-   Thickness works in the same way as with cvRectangle */
-OPENCVAPI  void  cvCircle( CvArr* array, CvPoint center, int radius,
-                           double color, int thickness CV_DEFAULT(1));
-
-/* Draws antialiazed circle with specified center and radius.
-   Both the center and radius can be specified with sub-pixel accuracy */
-OPENCVAPI  void  cvCircleAA( CvArr* array, CvPoint center, int radius,
-                             double color, int scale CV_DEFAULT(0) );
-
-/* Draws ellipse outline, filled ellipse, elliptic arc or filled elliptic sector,
-   depending on <thickness>, <startAngle> and <endAngle> parameters. The resultant figure
-   is rotated by <angle>. All the angles are in degrees */
-OPENCVAPI  void  cvEllipse( CvArr* array, CvPoint center, CvSize axes,
-                            double angle, double startAngle, double endAngle,
-                            double color, int thickness CV_DEFAULT(1));
-
-CV_INLINE  void  cvEllipseBox( CvArr* array, CvBox2D box,
-                               double color, int thickness CV_DEFAULT(1));
-CV_INLINE  void  cvEllipseBox( CvArr* array, CvBox2D box,
-                               double color, int thickness )
-{
-    cvEllipse( array, cvPointFrom32f( box.center ),
-               cvSize( cvRound(box.size.height*0.5),
-                       cvRound(box.size.width*0.5)),
-               box.angle*180/CV_PI, 0, 360, color, thickness );
-}
-
-
-/* Draws the whole ellipse or elliptic arc with antialiazing */
-OPENCVAPI  void  cvEllipseAA( CvArr* array, CvPoint center, CvSize axes,
-                              double angle, double startAngle,
-                              double endAngle, double color,
-                              int scale CV_DEFAULT(0) );
-
-/* Fills convex or monotonous (every horizontal line intersects the polygon twice at the most,
-   except, may be, horizontal sides) polygon. Connectivity or monotony is not checked */
-OPENCVAPI  void  cvFillConvexPoly( CvArr* array, CvPoint* pts, int npts, double color );
-
-
-/* Fills an area bounded by one or more arbitrary polygons (with possible intersections or
-   self-intersections */
-OPENCVAPI  void  cvFillPoly( CvArr* array, CvPoint** pts,
-                             int* npts, int contours, double color );
-
-/* Draws one or more polygonal curves */
-OPENCVAPI  void  cvPolyLine( CvArr* array, CvPoint** pts, int* npts, int contours,
-                             int closed, double color,
-                             int thickness CV_DEFAULT(1),
-                             int connectivity CV_DEFAULT(8));
 
-/* Draws one or more antialiazed polygonal curves */
-OPENCVAPI  void  cvPolyLineAA( CvArr* array, CvPoint** pts, int* npts, int contours,
-                               int closed, double color, int scale CV_DEFAULT(0) );
-
-/* Font metrics and structure */
-#define CV_FONT_VECTOR0  0
+/* Calculates all spatial and central moments up to the 3rd order */
+CVAPI(void) cvMoments( const CvArr* arr, CvMoments* moments, int binary CV_DEFAULT(0));
 
-typedef struct CvFont
-{
-    const int*  data; /* font data and metrics */
-    CvSize      size; /* horizontal and vertical scale factors,
-                         (8:8) fix-point numbers */
-    int         italic_scale; /* slope coefficient: 0 - normal, >0 - italic */
-    int         thickness; /* letters thickness */
-    int         dx; /* horizontal interval between letters */
-} CvFont;
-
-/* Initializes font structure used further in cvPutText */
-OPENCVAPI  void  cvInitFont( CvFont* font, int font_face,
-                             double hscale, double vscale,
-                             double italic_scale CV_DEFAULT(0),
-                             int thickness CV_DEFAULT(1) );
-
-/* Renders text stroke with specified font and color at specified location.
-   CvFont should be initialized with cvInitFont */
-OPENCVAPI  void  cvPutText( CvArr* array, const char* text, CvPoint org,
-                            CvFont* font, double color );
-
-/* Calculates bounding box of text stroke (useful for alignment) */
-OPENCVAPI  void  cvGetTextSize( const char* text_string, CvFont* font,
-                                CvSize* text_size, int* ymin );
+/* Retrieve particular spatial, central or normalized central moments */
+CVAPI(double)  cvGetSpatialMoment( CvMoments* moments, int x_order, int y_order );
+CVAPI(double)  cvGetCentralMoment( CvMoments* moments, int x_order, int y_order );
+CVAPI(double)  cvGetNormalizedCentralMoment( CvMoments* moments,
+                                             int x_order, int y_order );
 
+/* Calculates 7 Hu's invariants from precalculated spatial and central moments */
+CVAPI(void) cvGetHuMoments( CvMoments*  moments, CvHuMoments*  hu_moments );
 
 /*********************************** data sampling **************************************/
 
-/* Line iterator state */
-typedef struct CvLineIterator
-{
-    uchar* ptr;
-    int  err;
-    int  plus_delta;
-    int  minus_delta;
-    int  plus_step;
-    int  minus_step;
-} CvLineIterator;
-
 /* Initializes line iterator. Initially ptr will point to pt1 location in the array.
    Returns the number of points on the line between the endings. */
-OPENCVAPI  int  cvInitLineIterator( const CvArr* array, CvPoint pt1, CvPoint pt2,
-                                    CvLineIterator* lineIterator,
-                                    int connectivity CV_DEFAULT(8));
+CVAPI(int)  cvInitLineIterator( const CvArr* image, CvPoint pt1, CvPoint pt2,
+                                CvLineIterator* line_iterator,
+                                int connectivity CV_DEFAULT(8));
 
 /* Moves iterator to the next line point */
-#define CV_NEXT_LINE_POINT( iterator )                                          \
-{                                                                               \
-    int mask =  (iterator).err < 0 ? -1 : 0;                                    \
-    (iterator).err += (iterator).minus_delta + ((iterator).plus_delta & mask);  \
-    (iterator).ptr += (iterator).minus_step + ((iterator).plus_step & mask);    \
+#define CV_NEXT_LINE_POINT( line_iterator )                         \
+{                                                                   \
+    int mask =  (line_iterator).err < 0 ? -1 : 0;                   \
+    (line_iterator).err += (line_iterator).minus_delta +            \
+                            ((line_iterator).plus_delta & mask);    \
+    (line_iterator).ptr += (line_iterator).minus_step +             \
+                            ((line_iterator).plus_step & mask);     \
 }
 
 /* Grabs the raster line data into the destination buffer.
    Returns the number of retrieved points. */
-OPENCVAPI  int  cvSampleLine( const CvArr* array, CvPoint pt1, CvPoint pt2, void* buffer,
-                              int connectivity CV_DEFAULT(8));
+CVAPI(int)  cvSampleLine( const CvArr* image, CvPoint pt1, CvPoint pt2, void* buffer,
+                          int connectivity CV_DEFAULT(8));
 
 /* Retrieves the rectangular image region with specified center from the input array.
  dst(x,y) <- src(x + center.x - dst_width/2, y + center.y - dst_height/2).
  Values of pixels with fractional coordinates are retrieved using bilinear interpolation*/
-OPENCVAPI  void  cvGetRectSubPix( const CvArr* src, CvArr* dst, CvPoint2D32f center );
+CVAPI(void)  cvGetRectSubPix( const CvArr* src, CvArr* dst, CvPoint2D32f center );
 
 
 /* Retrieves quadrangle from the input array.
@@ -1505,10 +332,10 @@ OPENCVAPI  void  cvGetRectSubPix( const CvArr* src, CvArr* dst, CvPoint2D32f cen
                 ( a21  a22 | b2 )   (bilinear interpolation is used to retrieve pixels
                                      with fractional coordinates)
 */
-OPENCVAPI  void  cvGetQuadrangleSubPix( const CvArr* src, CvArr* dstarr,
-                                        const CvArr* matrixarr,
-                                        int fillOutliers CV_DEFAULT(0),
-                                        CvScalar fillvalue CV_DEFAULT(cvScalarAll(0)));
+CVAPI(void)  cvGetQuadrangleSubPix( const CvArr* src, CvArr* dst,
+                                    const CvMat* map_matrix,
+                                    int fill_outliers CV_DEFAULT(0),
+                                    CvScalar fill_value CV_DEFAULT(cvScalarAll(0)));
 
 /* Methods for comparing two array */
 #define  CV_TM_SQDIFF        0
@@ -1520,60 +347,31 @@ OPENCVAPI  void  cvGetQuadrangleSubPix( const CvArr* src, CvArr* dstarr,
 
 /* Measures similarity between template and overlapped windows in the source image
    and fills the resultant image with the measurements */
-OPENCVAPI  void  cvMatchTemplate( const CvArr* array, const CvArr* templ,
-                                  CvArr* result, int method );
-
-CV_EXTERN_C_FUNCPTR( float (CV_CDECL * CvDistanceFunction)
-                     ( const float* a, const float* b, void* user_param ));
+CVAPI(void)  cvMatchTemplate( const CvArr* image, const CvArr* templ,
+                              CvArr* result, int method );
 
 /* Computes earth mover distance between two weigted point sets
    (called signatures in image retrieval terminology) */
-OPENCVAPI  float  cvCalcEMD2( const CvArr* signature1,
-                              const CvArr* signature2,
-                              CvDisType dist_type,
-                              CvDistanceFunction dist_func CV_DEFAULT(0),
-                              const CvArr* cost_matrix CV_DEFAULT(0),
-                              CvArr* flow CV_DEFAULT(0),
-                              float* lower_bound CV_DEFAULT(0),
-                              void* user_param CV_DEFAULT(0));
+CVAPI(float)  cvCalcEMD2( const CvArr* signature1,
+                          const CvArr* signature2,
+                          int distance_type,
+                          CvDistanceFunction distance_func CV_DEFAULT(NULL),
+                          const CvArr* cost_matrix CV_DEFAULT(NULL),
+                          CvArr* flow CV_DEFAULT(NULL),
+                          float* lower_bound CV_DEFAULT(NULL),
+                          void* userdata CV_DEFAULT(NULL));
 
 /****************************************************************************************\
 *                              Contours retrieving                                       *
 \****************************************************************************************/
 
-/*
-Internal structure that is used for sequental retrieving contours from the image.
-It supports both hierarchical and plane variants of Suzuki algorithm.
-*/
-typedef struct _CvContourScanner* CvContourScanner;
-
-typedef enum CvContourRetrievalMode
-{
-    CV_RETR_EXTERNAL = 0,
-    CV_RETR_LIST     = 1,
-    CV_RETR_CCOMP    = 2,
-    CV_RETR_TREE     = 3
-}
-CvContourRetrievalMode;
-
-typedef enum CvChainApproxMethod
-{
-    CV_CHAIN_CODE             = 0,
-    CV_CHAIN_APPROX_NONE      = 1,
-    CV_CHAIN_APPROX_SIMPLE    = 2,
-    CV_CHAIN_APPROX_TC89_L1   = 3,
-    CV_CHAIN_APPROX_TC89_KCOS = 4,
-    CV_LINK_RUNS              = 5
-} CvChainApproxMethod;
-
-
 /* Retrieves outer and possibly inner boundaries of white (non-zero) connected
    components on the black (zero) background */
-OPENCVAPI  int  cvFindContours( CvArr* array, CvMemStorage* storage,
-                           CvSeq**  firstContour,
-                           int  headerSize CV_DEFAULT(sizeof(CvContour)),
-                           CvContourRetrievalMode mode CV_DEFAULT( CV_RETR_LIST ),
-                           CvChainApproxMethod method CV_DEFAULT(CV_CHAIN_APPROX_SIMPLE));
+CVAPI(int)  cvFindContours( CvArr* image, CvMemStorage* storage, CvSeq** first_contour,
+                            int header_size CV_DEFAULT(sizeof(CvContour)),
+                            int mode CV_DEFAULT(CV_RETR_LIST),
+                            int method CV_DEFAULT(CV_CHAIN_APPROX_SIMPLE),
+                            CvPoint offset CV_DEFAULT(cvPoint(0,0)));
 
 
 /* Initalizes contour retrieving process.
@@ -1581,114 +379,61 @@ OPENCVAPI  int  cvFindContours( CvArr* array, CvMemStorage* storage,
    Call cvFindNextContour until null pointer is returned
    or some other condition becomes true.
    Call cvEndFindContours at the end. */
-OPENCVAPI  CvContourScanner   cvStartFindContours( CvArr* array, CvMemStorage* storage,
-                                        int header_size, CvContourRetrievalMode mode,
-                                        CvChainApproxMethod method );
+CVAPI(CvContourScanner)  cvStartFindContours( CvArr* image, CvMemStorage* storage,
+                            int header_size CV_DEFAULT(sizeof(CvContour)),
+                            int mode CV_DEFAULT(CV_RETR_LIST),
+                            int method CV_DEFAULT(CV_CHAIN_APPROX_SIMPLE),
+                            CvPoint offset CV_DEFAULT(cvPoint(0,0)));
 
 /* Retrieves next contour */
-OPENCVAPI  CvSeq*  cvFindNextContour( CvContourScanner scanner );
+CVAPI(CvSeq*)  cvFindNextContour( CvContourScanner scanner );
 
 
 /* Substitutes the last retrieved contour with the new one
    (if the substitutor is null, the last retrieved contour is removed from the tree) */
-OPENCVAPI  void   cvSubstituteContour( CvContourScanner scanner, CvSeq* newContour );
+CVAPI(void)   cvSubstituteContour( CvContourScanner scanner, CvSeq* new_contour );
 
 
 /* Releases contour scanner and returns pointer to the first outer contour */
-OPENCVAPI  CvSeq*  cvEndFindContours( CvContourScanner* scanner );
-
-/* Draws contour outlines or filled interiors on the image */
-OPENCVAPI void  cvDrawContours( CvArr *img, CvSeq* contour,
-                                double external_color, double hole_color,
-                                int max_level, int thickness CV_DEFAULT(1),
-                                int connectivity CV_DEFAULT(8));
-
-/******************* Iteration through the sequence tree *****************/
-typedef struct CvTreeNodeIterator
-{
-    const void* node;
-    int level;
-    int maxLevel;
-}
-CvTreeNodeIterator;
-
-OPENCVAPI void cvInitTreeNodeIterator( CvTreeNodeIterator* treeIterator,
-                                   const void* first, int maxLevel );
-OPENCVAPI void* cvNextTreeNode( CvTreeNodeIterator* treeIterator );
-OPENCVAPI void* cvPrevTreeNode( CvTreeNodeIterator* treeIterator );
-
-/* Inserts sequence into tree with specified "parent" sequence.
-   If parent is equal to frame (e.g. the most external contour),
-   then added contour will have null pointer to parent. */
-OPENCVAPI void cvInsertNodeIntoTree( void* node, void* parent, void* frame );
-
-/* Removes contour from tree (together with the contour children). */
-OPENCVAPI void cvRemoveNodeFromTree( void* node, void* frame );
-
-/* Gathers pointers to all the sequences,
-   accessible from the <first>, to the single sequence */
-OPENCVAPI CvSeq* cvTreeToNodeSeq( const void* first, int header_size,
-                                  CvMemStorage* storage );
+CVAPI(CvSeq*)  cvEndFindContours( CvContourScanner* scanner );
 
 /* Approximates a single Freeman chain or a tree of chains to polygonal curves */
-OPENCVAPI  CvSeq* cvApproxChains( CvSeq* src_seq, CvMemStorage* storage,
-                            CvChainApproxMethod method CV_DEFAULT(CV_CHAIN_APPROX_SIMPLE),
+CVAPI(CvSeq*) cvApproxChains( CvSeq* src_seq, CvMemStorage* storage,
+                            int method CV_DEFAULT(CV_CHAIN_APPROX_SIMPLE),
                             double parameter CV_DEFAULT(0),
                             int  minimal_perimeter CV_DEFAULT(0),
                             int  recursive CV_DEFAULT(0));
 
 
-/* Freeman chain reader state */
-typedef struct CvChainPtReader
-{
-    CV_SEQ_READER_FIELDS()
-    char      code;
-    CvPoint  pt;
-    char      deltas[8][2];
-    int       reserved[2];
-} CvChainPtReader;
-
 /* Initalizes Freeman chain reader.
    The reader is used to iteratively get coordinates of all the chain points.
    If the original codes should be read, a simple sequence reader can be used */
-OPENCVAPI  void  cvStartReadChainPoints( CvChain* chain, CvChainPtReader* reader );
+CVAPI(void)  cvStartReadChainPoints( CvChain* chain, CvChainPtReader* reader );
 
 /* Retrieve the next chain point */
-OPENCVAPI  CvPoint   cvReadChainPoint( CvChainPtReader* reader );
+CVAPI(CvPoint)   cvReadChainPoint( CvChainPtReader* reader );
 
 
 /****************************************************************************************\
 *                                  Motion Analysis                                       *
 \****************************************************************************************/
 
-/********************************** change detection ************************************/
-
-/* Finds absolute difference between to arrays
-   dst(x,y,c) = abs(srcA(x,y,c) - srcB(x,y,c)) */
-OPENCVAPI  void  cvAbsDiff( const CvArr* srcA, const CvArr* srcB, CvArr* dst );
-
-
-/* Finds absolute difference between an array and scalar
-   dst(x,y,c) = abs(srcA(x,y,c) - value(c)) */
-OPENCVAPI  void  cvAbsDiffS( const CvArr* src, CvArr* dst, CvScalar value );
-#define cvAbs( src, dst ) cvAbsDiffS( (src), (dst), cvScalarAll(0))
-
 /************************************ optical flow ***************************************/
 
 /* Calculates optical flow for 2 images using classical Lucas & Kanade algorithm */
-OPENCVAPI  void  cvCalcOpticalFlowLK( const CvArr* srcA, const CvArr* srcB,
-                                      CvSize winSize, CvArr* velx, CvArr* vely );
+CVAPI(void)  cvCalcOpticalFlowLK( const CvArr* prev, const CvArr* curr,
+                                  CvSize win_size, CvArr* velx, CvArr* vely );
 
 /* Calculates optical flow for 2 images using block matching algorithm */
-OPENCVAPI  void  cvCalcOpticalFlowBM( const CvArr* srcA, const CvArr* srcB,
-                                      CvSize blockSize, CvSize shiftSize,
-                                      CvSize maxRange, int usePrevious,
-                                      CvArr* velx, CvArr* vely );
+CVAPI(void)  cvCalcOpticalFlowBM( const CvArr* prev, const CvArr* curr,
+                                  CvSize block_size, CvSize shift_size,
+                                  CvSize max_range, int use_previous,
+                                  CvArr* velx, CvArr* vely );
 
 /* Calculates Optical flow for 2 images using Horn & Schunck algorithm */
-OPENCVAPI  void  cvCalcOpticalFlowHS( const CvArr* srcA, const CvArr* srcB,
-                                      int usePrevious, CvArr* velx, CvArr* vely,
-                                      double lambda, CvTermCriteria criteria );
+CVAPI(void)  cvCalcOpticalFlowHS( const CvArr* prev, const CvArr* curr,
+                                  int use_previous, CvArr* velx, CvArr* vely,
+                                  double lambda, CvTermCriteria criteria );
 
 #define  CV_LKFLOW_PYR_A_READY       1
 #define  CV_LKFLOW_PYR_B_READY       2
@@ -1699,29 +444,29 @@ OPENCVAPI  void  cvCalcOpticalFlowHS( const CvArr* srcA, const CvArr* srcB,
    every point at every pyramid level.
    Calculates optical flow between two images for certain set of points (i.e.
    it is a "sparse" optical flow, which is opposite to the previous 3 methods) */
-OPENCVAPI  void  cvCalcOpticalFlowPyrLK( const CvArr*  imgA, const CvArr*  imgB,
-                                         CvArr*  pyrA, CvArr*  pyrB,
-                                         CvPoint2D32f* featuresA,
-                                         CvPoint2D32f* featuresB,
-                                         int       count,
-                                         CvSize    winSize,
-                                         int       level,
-                                         char*     status,
-                                         float*    error,
-                                         CvTermCriteria criteria,
-                                         int       flags );
+CVAPI(void)  cvCalcOpticalFlowPyrLK( const CvArr*  prev, const CvArr*  curr,
+                                     CvArr*  prev_pyr, CvArr*  curr_pyr,
+                                     const CvPoint2D32f* prev_features,
+                                     CvPoint2D32f* curr_features,
+                                     int       count,
+                                     CvSize    win_size,
+                                     int       level,
+                                     char*     status,
+                                     float*    track_error,
+                                     CvTermCriteria criteria,
+                                     int       flags );
 
 
 /* Modification of a previous sparse optical flow algorithm to calculate
    affine flow */
-OPENCVAPI  void  cvCalcAffineFlowPyrLK( const CvArr*  imgA, const CvArr*  imgB,
-                                        CvArr*  pyrA, CvArr*  pyrB,
-                                        CvPoint2D32f* featuresA,
-                                        CvPoint2D32f* featuresB,
-                                        float*  matrices, int  count,
-                                        CvSize  winSize, int  level,
-                                        char*  status, float* error,
-                                        CvTermCriteria criteria, int flags );
+/*CVAPI  void  cvCalcAffineFlowPyrLK( const CvArr*  prev, const CvArr*  curr,
+                                     CvArr*  prev_pyr, CvArr*  curr_pyr,
+                                     CvPoint2D32f* prev_features,
+                                     CvPoint2D32f* curr_features,
+                                     float*  matrices, int  count,
+                                     CvSize  win_size, int  level,
+                                     char*  status, float* track_error,
+                                     CvTermCriteria criteria, int flags );*/
 
 /********************************* motion templates *************************************/
 
@@ -1736,45 +481,45 @@ OPENCVAPI  void  cvCalcAffineFlowPyrLK( const CvArr*  imgA, const CvArr*  imgB,
 \****************************************************************************************/
 
 /* Updates motion history image given motion silhouette */
-OPENCVAPI  void    cvUpdateMotionHistory( const CvArr* silhouette, CvArr* mhi,
-                                          double timestamp, double mhiDuration );
+CVAPI(void)    cvUpdateMotionHistory( const CvArr* silhouette, CvArr* mhi,
+                                      double timestamp, double duration );
 
 /* Calculates gradient of the motion history image and fills
    a mask indicating where the gradient is valid */
-OPENCVAPI  void    cvCalcMotionGradient( const CvArr* mhi, CvArr* mask, CvArr* orientation,
-                                         double delta1, double delta2,
-                                         int aperture_size CV_DEFAULT(3));
+CVAPI(void)    cvCalcMotionGradient( const CvArr* mhi, CvArr* mask, CvArr* orientation,
+                                     double delta1, double delta2,
+                                     int aperture_size CV_DEFAULT(3));
 
 /* Calculates average motion direction within a selected motion region 
    (region can be selected by setting ROIs and/or by composing a valid gradient mask
    with the region mask) */
-OPENCVAPI  double  cvCalcGlobalOrientation( const CvArr* orientation, const CvArr* mask,
-                                            const CvArr* mhi, double curr_mhi_timestamp,
-                                            double mhi_duration );
+CVAPI(double)  cvCalcGlobalOrientation( const CvArr* orientation, const CvArr* mask,
+                                        const CvArr* mhi, double timestamp,
+                                        double duration );
 
 /* Splits a motion history image into a few parts corresponding to separate independent motions
    (e.g. left hand, right hand) */
-OPENCVAPI  CvSeq*  cvSegmentMotion( const CvArr* mhi, CvArr* seg_mask,
-                                    CvMemStorage* storage,
-                                    double timestamp, double seg_thresh );
+CVAPI(CvSeq*)  cvSegmentMotion( const CvArr* mhi, CvArr* seg_mask,
+                                CvMemStorage* storage,
+                                double timestamp, double seg_thresh );
 
 /*********************** Background statistics accumulation *****************************/
 
 /* Adds image to accumulator */
-OPENCVAPI  void  cvAcc( const CvArr* image, CvArr* sum,
-                        const CvArr* mask CV_DEFAULT(NULL) );
+CVAPI(void)  cvAcc( const CvArr* image, CvArr* sum,
+                    const CvArr* mask CV_DEFAULT(NULL) );
 
 /* Adds squared image to accumulator */
-OPENCVAPI  void  cvSquareAcc( const CvArr* image, CvArr* sqSum,
-                              const CvArr* mask CV_DEFAULT(NULL) );
+CVAPI(void)  cvSquareAcc( const CvArr* image, CvArr* sqsum,
+                          const CvArr* mask CV_DEFAULT(NULL) );
 
 /* Adds a product of two images to accumulator */
-OPENCVAPI  void  cvMultiplyAcc( const CvArr* imgA, const CvArr* imgB, CvArr* acc,
-                                const CvArr* mask CV_DEFAULT(NULL) );
+CVAPI(void)  cvMultiplyAcc( const CvArr* image1, const CvArr* image2, CvArr* acc,
+                            const CvArr* mask CV_DEFAULT(NULL) );
 
-/* Adds image to accumulator with weights: imgU = imgU*(1-alpha) + imgY*alpha */
-OPENCVAPI  void  cvRunningAvg( const CvArr* imgY, CvArr* imgU, double alpha,
-                               const CvArr* mask CV_DEFAULT(NULL) );
+/* Adds image to accumulator with weights: acc = acc*(1-alpha) + image*alpha */
+CVAPI(void)  cvRunningAvg( const CvArr* image, CvArr* acc, double alpha,
+                           const CvArr* mask CV_DEFAULT(NULL) );
 
 
 /****************************************************************************************\
@@ -1783,191 +528,55 @@ OPENCVAPI  void  cvRunningAvg( const CvArr* imgY, CvArr* imgU, double alpha,
 
 /* Implements CAMSHIFT algorithm - determines object position, size and orientation
    from the object histogram back project (extension of meanshift) */
-OPENCVAPI int  cvCamShift( const CvArr* imgProb, CvRect  windowIn,
-                           CvTermCriteria criteria, CvConnectedComp* out,
-                           CvBox2D* box );
+CVAPI(int)  cvCamShift( const CvArr* prob_image, CvRect  window,
+                       CvTermCriteria criteria, CvConnectedComp* comp,
+                       CvBox2D* box CV_DEFAULT(NULL) );
 
 /* Implements MeanShift algorithm - determines object position
    from the object histogram back project */
-OPENCVAPI int  cvMeanShift( const CvArr* imgProb, CvRect  windowIn,
-                            CvTermCriteria criteria, CvConnectedComp* out );
-
-typedef struct CvConDensation
-{
-    int MP;
-    int DP;
-    float* DynamMatr;       /* Matrix of the linear Dynamics system  */
-    float* State;           /* Vector of State                       */
-    int SamplesNum;         /* Number of the Samples                 */
-    float** flSamples;      /* array of the Sample Vectors           */
-    float** flNewSamples;   /* temporary array of the Sample Vectors */
-    float* flConfidence;    /* Confidence for each Sample            */
-    float* flCumulative;    /* Cumulative confidence                 */
-    float* Temp;            /* Temporary vector                      */
-    float* RandomSample;    /* RandomVector to update sample set     */
-    CvRandState* RandS;     /* Array of structures to generate random vectors */
-} CvConDensation;
+CVAPI(int)  cvMeanShift( const CvArr* prob_image, CvRect  window,
+                        CvTermCriteria criteria, CvConnectedComp* comp );
 
 /* Creates ConDensation filter state */
-OPENCVAPI CvConDensation*  cvCreateConDensation( int DP, int MP, int SamplesNum);
+CVAPI(CvConDensation*)  cvCreateConDensation( int dynam_params,
+                                             int measure_params,
+                                             int sample_count );
 
 /* Releases ConDensation filter state */
-OPENCVAPI void  cvReleaseConDensation( CvConDensation** ConDensation);
+CVAPI(void)  cvReleaseConDensation( CvConDensation** condens );
 
 /* Updates ConDensation filter by time (predict future state of the system) */
-OPENCVAPI void  cvConDensUpdateByTime( CvConDensation* ConDens);
+CVAPI(void)  cvConDensUpdateByTime( CvConDensation* condens);
 
 /* Initializes ConDensation filter samples  */
-OPENCVAPI void  cvConDensInitSampleSet( CvConDensation* conDens, CvMat* lowerBound,CvMat* upperBound);
-
-/*
-standard Kalman filter (in G. Welch' and G. Bishop's notation):
-
-  x(k)=A*x(k-1)+B*u(k)+w(k)  p(w)~N(0,Q)
-  z(k)=H*x(k)+v(k),   p(v)~N(0,R)
-*/
-typedef struct CvKalman
-{
-    int MP;                     /* number of measurement vector dimensions */
-    int DP;                     /* number of state vector dimensions */
-    int CP;                     /* number of control vector dimensions */
-
-    /* backward compatibility fields */
-#if 1
-    float* PosterState;         /* =state_pre->data.fl */
-    float* PriorState;          /* =state_post->data.fl */
-    float* DynamMatr;           /* =transition_matrix->data.fl */
-    float* MeasurementMatr;     /* =measurement_matrix->data.fl */
-    float* MNCovariance;        /* =measurement_noise_cov->data.fl */
-    float* PNCovariance;        /* =process_noise_cov->data.fl */
-    float* KalmGainMatr;        /* =gain->data.fl */
-    float* PriorErrorCovariance;/* =error_cov_pre->data.fl */
-    float* PosterErrorCovariance;/* =error_cov_post->data.fl */
-    float* Temp1;               /* temp1->data.fl */
-    float* Temp2;               /* temp2->data.fl */
-#endif
-
-    CvMat* state_pre;           /* predicted state (x'(k)):
-                                    x(k)=A*x(k-1)+B*u(k) */
-    CvMat* state_post;          /* corrected state (x(k)):
-                                    x(k)=x'(k)+K(k)*(z(k)-H*x'(k)) */
-    CvMat* transition_matrix;   /* state transition matrix (A) */
-    CvMat* control_matrix;      /* control matrix (B)
-                                   (it is not used if there is no control)*/
-    CvMat* measurement_matrix;  /* measurement matrix (H) */
-    CvMat* process_noise_cov;   /* process noise covariance matrix (Q) */
-    CvMat* measurement_noise_cov; /* measurement noise covariance matrix (R) */
-    CvMat* error_cov_pre;       /* priori error estimate covariance matrix (P'(k)):
-                                    P'(k)=A*P(k-1)*At + Q)*/
-    CvMat* gain;                /* Kalman gain matrix (K(k)):
-                                    K(k)=P'(k)*Ht*inv(H*P'(k)*Ht+R)*/
-    CvMat* error_cov_post;      /* posteriori error estimate covariance matrix (P(k)):
-                                    P(k)=(I-K(k)*H)*P'(k) */
-    CvMat* temp1;               /* temporary matrices */
-    CvMat* temp2;
-    CvMat* temp3;
-    CvMat* temp4;
-    CvMat* temp5;
-
-}
-CvKalman;
+CVAPI(void)  cvConDensInitSampleSet( CvConDensation* condens, CvMat* lower_bound, CvMat* upper_bound );
 
 /* Creates Kalman filter and sets A, B, Q, R and state to some initial values */
-OPENCVAPI CvKalman* cvCreateKalman( int dynamParams, int measureParams,
-                                    int controlParams CV_DEFAULT(0));
+CVAPI(CvKalman*) cvCreateKalman( int dynam_params, int measure_params,
+                                int control_params CV_DEFAULT(0));
 
 /* Releases Kalman filter state */
-OPENCVAPI void  cvReleaseKalman( CvKalman** Kalman);
+CVAPI(void)  cvReleaseKalman( CvKalman** kalman);
 
 /* Updates Kalman filter by time (predicts future state of the system) */
-OPENCVAPI const CvMat*  cvKalmanPredict( CvKalman* Kalman,
-                                         const CvMat* control CV_DEFAULT(NULL));
+CVAPI(const CvMat*)  cvKalmanPredict( CvKalman* kalman,
+                                     const CvMat* control CV_DEFAULT(NULL));
 
 /* Updates Kalman filter by measurement
    (corrects state of the system and internal matrices) */
-OPENCVAPI const CvMat*  cvKalmanCorrect( CvKalman* Kalman, const CvMat* measurement );
+CVAPI(const CvMat*)  cvKalmanCorrect( CvKalman* kalman, const CvMat* measurement );
 
 /****************************************************************************************\
 *                              Planar subdivisions                                       *
 \****************************************************************************************/
 
-/************ Data structures and related enumerations ************/
-
-typedef long CvSubdiv2DEdge;
-
-#define CV_QUADEDGE2D_FIELDS()     \
-    int flags;                     \
-    struct CvSubdiv2DPoint* pt[4]; \
-    CvSubdiv2DEdge  next[4];
-
-#define CV_SUBDIV2D_POINT_FIELDS()\
-    int            flags;      \
-    CvSubdiv2DEdge first;      \
-    CvPoint2D32f   pt;
-
-#define CV_SUBDIV2D_VIRTUAL_POINT_FLAG (1 << 30)
-
-typedef struct CvQuadEdge2D
-{
-    CV_QUADEDGE2D_FIELDS()
-}
-CvQuadEdge2D;
-
-typedef struct CvSubdiv2DPoint
-{
-    CV_SUBDIV2D_POINT_FIELDS()
-}
-CvSubdiv2DPoint;
-
-#define CV_SUBDIV2D_FIELDS()    \
-    CV_GRAPH_FIELDS()           \
-    int  quad_edges;            \
-    int  is_geometry_valid;     \
-    CvSubdiv2DEdge recent_edge; \
-    CvPoint2D32f  topleft;      \
-    CvPoint2D32f  bottomright;
-    
-typedef struct CvSubdiv2D
-{
-    CV_SUBDIV2D_FIELDS()
-}
-CvSubdiv2D;
-
-
-typedef enum CvSubdiv2DPointLocation
-{
-    CV_PTLOC_ERROR = -2,
-    CV_PTLOC_OUTSIDE_RECT = -1,
-    CV_PTLOC_INSIDE = 0,
-    CV_PTLOC_VERTEX = 1,
-    CV_PTLOC_ON_EDGE = 2
-}
-CvSubdiv2DPointLocation;
-
-typedef enum CvNextEdgeType
-{
-    CV_NEXT_AROUND_ORG   = 0x00,
-    CV_NEXT_AROUND_DST   = 0x22,
-    CV_PREV_AROUND_ORG   = 0x11,
-    CV_PREV_AROUND_DST   = 0x33,
-    CV_NEXT_AROUND_LEFT  = 0x13,
-    CV_NEXT_AROUND_RIGHT = 0x31,
-    CV_PREV_AROUND_LEFT  = 0x20,
-    CV_PREV_AROUND_RIGHT = 0x02
-}
-CvNextEdgeType;
-
-/* get the next edge with the same origin point (counterwise) */
-#define  CV_SUBDIV2D_NEXT_EDGE( edge )  (((CvQuadEdge2D*)((edge) & ~3))->next[(edge)&3])
-
-
 /* Initializes Delaunay triangulation */
-OPENCVAPI  void  cvInitSubdivDelaunay2D( CvSubdiv2D* subdiv, CvRect rect );
+CVAPI(void)  cvInitSubdivDelaunay2D( CvSubdiv2D* subdiv, CvRect rect );
 
 /* Creates new subdivision */
-OPENCVAPI  CvSubdiv2D*  cvCreateSubdiv2D( int subdiv_type, int header_size,
-                                       int vtx_size, int quadedge_size,
-                                       CvMemStorage* storage );
+CVAPI(CvSubdiv2D*)  cvCreateSubdiv2D( int subdiv_type, int header_size,
+                                      int vtx_size, int quadedge_size,
+                                      CvMemStorage* storage );
 
 /************************* high-level subdivision functions ***************************/
 
@@ -1984,26 +593,26 @@ CV_INLINE  CvSubdiv2D* cvCreateSubdivDelaunay2D( CvRect rect, CvMemStorage* stor
 
 
 /* Inserts new point to the Delaunay triangulation */
-OPENCVAPI  CvSubdiv2DPoint*  cvSubdivDelaunay2DInsert( CvSubdiv2D* subdiv, CvPoint2D32f pt);
+CVAPI(CvSubdiv2DPoint*)  cvSubdivDelaunay2DInsert( CvSubdiv2D* subdiv, CvPoint2D32f pt);
 
 /* Locates a point within the Delaunay triangulation (finds the edge
    the point is left to or belongs to, or the triangulation point the given
    point coinsides with */
-OPENCVAPI  CvSubdiv2DPointLocation  cvSubdiv2DLocate(
+CVAPI(CvSubdiv2DPointLocation)  cvSubdiv2DLocate(
                                CvSubdiv2D* subdiv, CvPoint2D32f pt,
-                               CvSubdiv2DEdge *_edge,
-                               CvSubdiv2DPoint** _point CV_DEFAULT(NULL) );
+                               CvSubdiv2DEdgeedge,
+                               CvSubdiv2DPoint** vertex CV_DEFAULT(NULL) );
 
 /* Calculates Voronoi tesselation (i.e. coordinates of Voronoi points) */
-OPENCVAPI  void  cvCalcSubdivVoronoi2D( CvSubdiv2D* subdiv );
+CVAPI(void)  cvCalcSubdivVoronoi2D( CvSubdiv2D* subdiv );
 
 
 /* Removes all Voronoi points from the tesselation */
-OPENCVAPI  void  cvClearSubdivVoronoi2D( CvSubdiv2D* subdiv );
+CVAPI(void)  cvClearSubdivVoronoi2D( CvSubdiv2D* subdiv );
 
 
 /* Finds the nearest to the given point vertex in subdivision. */
-OPENCVAPI CvSubdiv2DPoint* cvFindNearestPoint2D( CvSubdiv2D* subdiv, CvPoint2D32f pt );
+CVAPI(CvSubdiv2DPoint*) cvFindNearestPoint2D( CvSubdiv2D* subdiv, CvPoint2D32f pt );
 
 
 /************ Basic quad-edge navigation and operations ************/
@@ -2067,225 +676,225 @@ CV_INLINE  double  cvTriangleArea( CvPoint2D32f a, CvPoint2D32f b, CvPoint2D32f
 
 /* Approximates a single polygonal curve (contour) or
    a tree of polygonal curves (contours) */
-OPENCVAPI  CvSeq*  cvApproxPoly( const void* src_seq,
-                                 int header_size, CvMemStorage* storage,
-                                 int method, double parameter,
-                                 int parameter2 CV_DEFAULT(0));
+CVAPI(CvSeq*)  cvApproxPoly( const void* src_seq,
+                             int header_size, CvMemStorage* storage,
+                             int method, double parameter,
+                             int parameter2 CV_DEFAULT(0));
+
+#define CV_DOMINANT_IPAN 1
+
+/* Finds high-curvature points of the contour */
+CVAPI(CvSeq*) cvFindDominantPoints( CvSeq* contour, CvMemStorage* storage,
+                                   int method CV_DEFAULT(CV_DOMINANT_IPAN),
+                                   double parameter1 CV_DEFAULT(0),
+                                   double parameter2 CV_DEFAULT(0),
+                                   double parameter3 CV_DEFAULT(0),
+                                   double parameter4 CV_DEFAULT(0));
 
 /* Calculates perimeter of a contour or a part of contour */
-OPENCVAPI  double  cvArcLength( const void* curve,
-                                CvSlice slice CV_DEFAULT(CV_WHOLE_SEQ),
-                                int is_closed CV_DEFAULT(-1));
+CVAPI(double)  cvArcLength( const void* curve,
+                            CvSlice slice CV_DEFAULT(CV_WHOLE_SEQ),
+                            int is_closed CV_DEFAULT(-1));
 #define cvContourPerimeter( contour ) cvArcLength( contour, CV_WHOLE_SEQ, 1 )
 
 /* Calculates contour boundning rectangle (update=1) or
    just retrieves pre-calculated rectangle (update=0) */
-OPENCVAPI  CvRect  cvBoundingRect( const void* points, int update CV_DEFAULT(0) );
+CVAPI(CvRect)  cvBoundingRect( CvArr* points, int update CV_DEFAULT(0) );
 
 /* Calculates area of a contour or contour segment */
-OPENCVAPI  double  cvContourArea( const void* contour,
-                                  CvSlice slice CV_DEFAULT(CV_WHOLE_SEQ));
+CVAPI(double)  cvContourArea( const CvArr* contour,
+                              CvSlice slice CV_DEFAULT(CV_WHOLE_SEQ));
 
 /* Finds minimum area rotated rectangle bounding a set of points */
-OPENCVAPI  CvBox2D  cvMinAreaRect2( const void* points,
-                                    CvMemStorage* storage CV_DEFAULT(NULL));
+CVAPI(CvBox2D)  cvMinAreaRect2( const CvArr* points,
+                                CvMemStorage* storage CV_DEFAULT(NULL));
 
 /* Finds minimum enclosing circle for a set of points */
-OPENCVAPI  void  cvMinEnclosingCircle( const void* points,
-                                       CvPoint2D32f* center, float* radius );
+CVAPI(int)  cvMinEnclosingCircle( const CvArr* points,
+                                  CvPoint2D32f* center, float* radius );
 
 #define CV_CONTOURS_MATCH_I1  1
 #define CV_CONTOURS_MATCH_I2  2
 #define CV_CONTOURS_MATCH_I3  3
 
 /* Compares two contours by matching their moments */
-OPENCVAPI  double  cvMatchShapes( const void* contour1, const void* contour2,
-                                  int method, double parameter CV_DEFAULT(0));
-
-/* Contour tree header */
-typedef struct CvContourTree
-{
-    CV_SEQUENCE_FIELDS()
-    CvPoint p1;            /* the first point of the binary tree root segment */
-    CvPoint p2;            /* the last point of the binary tree root segment */
-} CvContourTree;
+CVAPI(double)  cvMatchShapes( const void* object1, const void* object2,
+                              int method, double parameter CV_DEFAULT(0));
 
 /* Builds hierarhical representation of a contour */
-OPENCVAPI  CvContourTree*   cvCreateContourTree( CvSeq* contour, CvMemStorage* storage,
-                                                 double threshold );
+CVAPI(CvContourTree*)  cvCreateContourTree( const CvSeq* contour,
+                                            CvMemStorage* storage,
+                                            double threshold );
 
 /* Reconstruct (completelly or partially) contour a from contour tree */
-OPENCVAPI  CvSeq*  cvContourFromContourTree( CvContourTree *tree,
-                                          CvMemStorage* storage,
-                                          CvTermCriteria criteria );
+CVAPI(CvSeq*)  cvContourFromContourTree( const CvContourTree* tree,
+                                         CvMemStorage* storage,
+                                         CvTermCriteria criteria );
 
 /* Compares two contour trees */
 #define  CV_CONTOUR_TREES_MATCH_I1  1
 
-OPENCVAPI  double  cvMatchContourTrees( CvContourTree *tree1,
-                                        CvContourTree *tree2,
-                                        int method, double threshold );
+CVAPI(double)  cvMatchContourTrees( const CvContourTree* tree1,
+                                    const CvContourTree* tree2,
+                                    int method, double threshold );
 
 /* Calculates histogram of a contour */
-OPENCVAPI  void  cvCalcPGH( const CvSeq* contour, CvHistogram* hist );
+CVAPI(void)  cvCalcPGH( const CvSeq* contour, CvHistogram* hist );
 
 #define CV_CLOCKWISE         1
 #define CV_COUNTER_CLOCKWISE 2
 
 /* Calculates exact convex hull of 2d point set */
-OPENCVAPI CvSeq* cvConvexHull2( const CvArr* input,
-                                void* hull_storage CV_DEFAULT(NULL),
-                                int orientation CV_DEFAULT(CV_CLOCKWISE),
-                                int return_points CV_DEFAULT(0));
+CVAPI(CvSeq*) cvConvexHull2( const CvArr* input,
+                             void* hull_storage CV_DEFAULT(NULL),
+                             int orientation CV_DEFAULT(CV_CLOCKWISE),
+                             int return_points CV_DEFAULT(0));
 
 /* Checks whether the contour is convex or not (returns 1 if convex, 0 if not) */
-OPENCVAPI  int  cvCheckContourConvexity( const CvArr* contour );
-
-/* Finds a sequence of convexity defects of given contour */
-typedef struct CvConvexityDefect
-{
-    CvPoint* start; /* point of the contour where the defect begins */
-    CvPoint* end; /* point of the contour where the defect ends */
-    CvPoint* depth_point; /* the farthest from the convex hull point within the defect */
-    float depth; /* distance between the farthest point and the convex hull */
-} CvConvexityDefect;
-
+CVAPI(int)  cvCheckContourConvexity( const CvArr* contour );
 
 /* Finds convexity defects for the contour */
-OPENCVAPI CvSeq*  cvConvexityDefects( const CvArr* contour, const CvArr* convexhull,
-                                      CvMemStorage* storage CV_DEFAULT(NULL));
+CVAPI(CvSeq*)  cvConvexityDefects( const CvArr* contour, const CvArr* convexhull,
+                                   CvMemStorage* storage CV_DEFAULT(NULL));
 
 /* Fits ellipse into a set of 2d points */
-OPENCVAPI CvBox2D cvFitEllipse2( const CvArr* points );
+CVAPI(CvBox2D) cvFitEllipse2( const CvArr* points );
+
+/* Finds minimum rectangle containing two given rectangles */
+CVAPI(CvRect)  cvMaxRect( const CvRect* rect1, const CvRect* rect2 );
+
+/* Finds coordinates of the box vertices */
+CVAPI(void) cvBoxPoints( CvBox2D box, CvPoint2D32f pt[4] );
 
 /****************************************************************************************\
 *                                  Histogram functions                                   *
 \****************************************************************************************/
 
 /* Creates new histogram */
-OPENCVAPI  CvHistogram*  cvCreateHist( int dims, int* sizes, int type,
-                                       float** ranges CV_DEFAULT(NULL),
-                                       int uniform CV_DEFAULT(1));
+CVAPI(CvHistogram*)  cvCreateHist( int dims, int* sizes, int type,
+                                   float** ranges CV_DEFAULT(NULL),
+                                   int uniform CV_DEFAULT(1));
 
 /* Assignes histogram bin ranges */
-OPENCVAPI void  cvSetHistBinRanges( CvHistogram* hist, float** ranges,
-                                    int uniform CV_DEFAULT(1));
+CVAPI(void)  cvSetHistBinRanges( CvHistogram* hist, float** ranges,
+                                int uniform CV_DEFAULT(1));
 
 /* Creates histogram header for array */
-OPENCVAPI  CvHistogram*  cvMakeHistHeaderForArray(
+CVAPI(CvHistogram*)  cvMakeHistHeaderForArray(
                             int  dims, int* sizes, CvHistogram* hist,
                             float* data, float** ranges CV_DEFAULT(NULL),
                             int uniform CV_DEFAULT(1));
 
 /* Releases histogram */
-OPENCVAPI  void  cvReleaseHist( CvHistogram** hist );
+CVAPI(void)  cvReleaseHist( CvHistogram** hist );
 
 /* Clears all the histogram bins */
-OPENCVAPI  void  cvClearHist( CvHistogram* hist );
+CVAPI(void)  cvClearHist( CvHistogram* hist );
 
 /* Finds indices and values of minimum and maximum histogram bins */
-OPENCVAPI  void  cvGetMinMaxHistValue( const CvHistogram* hist,
-                                    float* value_min, float* value_max,
-                                    int* idx_min CV_DEFAULT(NULL),
-                                    int* idx_max CV_DEFAULT(NULL));
+CVAPI(void)  cvGetMinMaxHistValue( const CvHistogram* hist,
+                                   float* min_value, float* max_value,
+                                   int* min_idx CV_DEFAULT(NULL),
+                                   int* max_idx CV_DEFAULT(NULL));
 
 
 /* Normalizes histogram by dividing all bins by sum of the bins, multiplied by <factor>.
    After that sum of histogram bins is equal to <factor> */
-OPENCVAPI  void  cvNormalizeHist( CvHistogram* hist, double factor );
+CVAPI(void)  cvNormalizeHist( CvHistogram* hist, double factor );
 
 
 /* Clear all histogram bins that are below the threshold */
-OPENCVAPI  void  cvThreshHist( CvHistogram* hist, double thresh );
+CVAPI(void)  cvThreshHist( CvHistogram* hist, double threshold );
 
 #define CV_COMP_CORREL      0
 #define CV_COMP_CHISQR      1
 #define CV_COMP_INTERSECT   2
 
 /* Compares two histogram */
-OPENCVAPI  double  cvCompareHist( const CvHistogram* hist1,
-                                  const CvHistogram* hist2,
-                                  int method);
+CVAPI(double)  cvCompareHist( const CvHistogram* hist1,
+                              const CvHistogram* hist2,
+                              int method);
 
 /* Copies one histogram to another. Destination histogram is created if
    the destination pointer is NULL */
-OPENCVAPI void  cvCopyHist( const CvHistogram* src, CvHistogram** dst );
+CVAPI(void)  cvCopyHist( const CvHistogram* src, CvHistogram** dst );
 
 
 /* Calculates bayesian probabilistic histograms
    (each or src and dst is an array of <number> histograms */
-OPENCVAPI void  cvCalcBayesianProb( CvHistogram** src, int number,
-                                    CvHistogram** dst);
+CVAPI(void)  cvCalcBayesianProb( CvHistogram** src, int number,
+                                CvHistogram** dst);
 
 /* Calculates array histogram */
-OPENCVAPI  void  cvCalcArrHist( CvArr** arr, CvHistogram* hist,
-                                int doNotClear CV_DEFAULT(0),
-                                const CvArr* mask CV_DEFAULT(NULL) );
+CVAPI(void)  cvCalcArrHist( CvArr** arr, CvHistogram* hist,
+                            int accumulate CV_DEFAULT(0),
+                            const CvArr* mask CV_DEFAULT(NULL) );
 
-CV_INLINE  void  cvCalcHist( IplImage** img, CvHistogram* hist,
-                             int doNotClear CV_DEFAULT(0),
+CV_INLINE  void  cvCalcHist( IplImage** image, CvHistogram* hist,
+                             int accumulate CV_DEFAULT(0),
                              const CvArr* mask CV_DEFAULT(NULL) );
-CV_INLINE  void  cvCalcHist( IplImage** img, CvHistogram* hist,
-                             int doNotClear, const CvArr* mask )
+CV_INLINE  void  cvCalcHist( IplImage** image, CvHistogram* hist,
+                             int accumulate, const CvArr* mask )
 {
-    cvCalcArrHist( (CvArr**)img, hist, doNotClear, mask );
+    cvCalcArrHist( (CvArr**)image, hist, accumulate, mask );
 }
 
 /* Calculates back project */
-OPENCVAPI  void  cvCalcArrBackProject( CvArr** img, CvArr* dst,
-                                       const CvHistogram* hist );
-#define  cvCalcBackProject(img, dst, hist) cvCalcArrBackProject((CvArr**)img, dst, hist)
+CVAPI(void)  cvCalcArrBackProject( CvArr** image, CvArr* dst,
+                                   const CvHistogram* hist );
+#define  cvCalcBackProject(image, dst, hist) cvCalcArrBackProject((CvArr**)image, dst, hist)
 
 
 /* Does some sort of template matching but compares histograms of
    template and each window location */
-OPENCVAPI  void  cvCalcArrBackProjectPatch( CvArr** img, CvArr* dst, CvSize range,
-                                            CvHistogram* hist, int method,
-                                            double normFactor );
-#define  cvCalcBackProjectPatch( img, dst, range, hist, method, normFactor ) \
-     cvCalcArrBackProjectPatch( (CvArr**)img, dst, range, hist, method, normFactor )
+CVAPI(void)  cvCalcArrBackProjectPatch( CvArr** image, CvArr* dst, CvSize range,
+                                        CvHistogram* hist, int method,
+                                        double factor );
+#define  cvCalcBackProjectPatch( image, dst, range, hist, method, factor ) \
+     cvCalcArrBackProjectPatch( (CvArr**)image, dst, range, hist, method, factor )
 
 
 /* calculates probabilistic density (divides one histogram by another) */
-OPENCVAPI  void  cvCalcProbDensity( const CvHistogram* hist, const CvHistogram* hist_mask,
-                                    CvHistogram* hist_dens, double scale CV_DEFAULT(255) );
+CVAPI(void)  cvCalcProbDensity( const CvHistogram* hist1, const CvHistogram* hist2,
+                                CvHistogram* dst_hist, double scale CV_DEFAULT(255) );
 
 
 #define  CV_VALUE  1
 #define  CV_ARRAY  2
 /* Updates active contour in order to minimize its cummulative
    (internal and external) energy. */
-OPENCVAPI  void  cvSnakeImage( const IplImage* src, CvPoint* points,
-                            int  length, float* alpha,
-                            float* beta, float* gamma,
-                            int coeffUsage, CvSize  win,
-                            CvTermCriteria criteria, int calcGradient CV_DEFAULT(1));
+CVAPI(void)  cvSnakeImage( const IplImage* image, CvPoint* points,
+                           int  length, float* alpha,
+                           float* beta, float* gamma,
+                           int coeff_usage, CvSize  win,
+                           CvTermCriteria criteria, int calc_gradient CV_DEFAULT(1));
 
 /* Calculates the cooficients of the homography matrix */
-OPENCVAPI  void  cvCalcImageHomography(float *line, CvPoint3D32f* center,
-                                     float* intrinsic, float* homography);
+CVAPI(void)  cvCalcImageHomography( float* line, CvPoint3D32f* center,
+                                    float* intrinsic, float* homography );
 
 #define CV_DIST_MASK_3   3
 #define CV_DIST_MASK_5   5 
 
 /* Applies distance transform to binary image */
-OPENCVAPI  void  cvDistTransform( const CvArr* src, CvArr* dst,
-                                  CvDisType disType CV_DEFAULT(CV_DIST_L2),
-                                  int maskSize CV_DEFAULT(3),
-                                  const float* mask CV_DEFAULT(NULL));
+CVAPI(void)  cvDistTransform( const CvArr* src, CvArr* dst,
+                              int distance_type CV_DEFAULT(CV_DIST_L2),
+                              int mask_size CV_DEFAULT(3),
+                              const float* mask CV_DEFAULT(NULL));
 
 
-/* Defines for Threshold functions */
-#define CV_THRESH_BINARY      0  /* val = (val>thresh? MAX:0)      */
-#define CV_THRESH_BINARY_INV  1  /* val = (val>thresh? 0:MAX)      */
-#define CV_THRESH_TRUNC       2  /* val = (val>thresh? thresh:val) */
-#define CV_THRESH_TOZERO      3  /* val = (val>thresh? val:0)      */
-#define CV_THRESH_TOZERO_INV  4  /* val = (val>thresh? 0:val)      */
+/* Types of thresholding */
+#define CV_THRESH_BINARY      0  /* value = value > threshold ? max_value : 0       */
+#define CV_THRESH_BINARY_INV  1  /* value = value > threshold ? 0 : max_value       */
+#define CV_THRESH_TRUNC       2  /* value = value > threshold ? threshold : value   */
+#define CV_THRESH_TOZERO      3  /* value = value > threshold ? value : 0           */
+#define CV_THRESH_TOZERO_INV  4  /* value = value > threshold ? 0 : value           */
 
-/* Applies fixed-level threshold to grayscale image. This is the basic operation
-   to be performed before retrieving contours */
-OPENCVAPI  void  cvThreshold( const CvArr*  src, CvArr*  dst,
-                              double  thresh, double  maxValue, int type );
+/* Applies fixed-level threshold to grayscale image.
+   This is a basic operation applied before retrieving contours */
+CVAPI(void)  cvThreshold( const CvArr*  src, CvArr*  dst,
+                          double  threshold, double  max_value,
+                          int threshold_type );
 
 #define CV_ADAPTIVE_THRESH_MEAN_C  0
 #define CV_ADAPTIVE_THRESH_GAUSSIAN_C  1
@@ -2295,232 +904,106 @@ OPENCVAPI  void  cvThreshold( const CvArr*  src, CvArr*  dst,
    CV_ADAPTIVE_THRESH_GAUSSIAN_C are:
    neighborhood size (3, 5, 7 etc.),
    and a constant subtracted from mean (...,-3,-2,-1,0,1,2,3,...) */
-OPENCVAPI  void  cvAdaptiveThreshold( const CvArr* src, CvArr* dst, double maxValue,
-                                      int method CV_DEFAULT(CV_ADAPTIVE_THRESH_MEAN_C),
-                                      int type CV_DEFAULT(CV_THRESH_BINARY),
-                                      int blockSize CV_DEFAULT(3),
-                                      double param1 CV_DEFAULT(5));
+CVAPI(void)  cvAdaptiveThreshold( const CvArr* src, CvArr* dst, double max_value,
+                                  int adaptive_method CV_DEFAULT(CV_ADAPTIVE_THRESH_MEAN_C),
+                                  int threshold_type CV_DEFAULT(CV_THRESH_BINARY),
+                                  int block_size CV_DEFAULT(3),
+                                  double param1 CV_DEFAULT(5));
 
 #define CV_FLOODFILL_FIXED_RANGE (1 << 16)
 #define CV_FLOODFILL_MASK_ONLY   (1 << 17)
 
 /* Fills the connected component until the color difference gets large enough */
-OPENCVAPI  void  cvFloodFill( CvArr* array, CvPoint seedPoint,
-                              double newVal, double loDiff CV_DEFAULT(0),
-                              double upDiff CV_DEFAULT(0),
-                              CvConnectedComp* comp CV_DEFAULT(NULL),
-                              int flags CV_DEFAULT(4),
-                              CvArr* mask CV_DEFAULT(NULL));
+CVAPI(void)  cvFloodFill( CvArr* image, CvPoint seed_point,
+                          CvScalar new_val, CvScalar lo_diff CV_DEFAULT(cvScalarAll(0)),
+                          CvScalar up_diff CV_DEFAULT(cvScalarAll(0)),
+                          CvConnectedComp* comp CV_DEFAULT(NULL),
+                          int flags CV_DEFAULT(4),
+                          CvArr* mask CV_DEFAULT(NULL));
 
 /****************************************************************************************\
 *                                  Feature detection                                     *
 \****************************************************************************************/
 
 /* Runs canny edge detector */
-OPENCVAPI  void  cvCanny( const CvArr* src, CvArr* dst, double low_threshold,
-                          double high_threshold, int  aperture_size CV_DEFAULT(3) );
+CVAPI(void)  cvCanny( const CvArr* image, CvArr* edges, double threshold1,
+                      double threshold2, int  aperture_size CV_DEFAULT(3) );
 
 /* Calculates constraint image for corner detection
    Dx^2 * Dyy + Dxx * Dy^2 - 2 * Dx * Dy * Dxy.
    Applying threshold to the result gives coordinates of corners */
-OPENCVAPI void cvPreCornerDetect( const CvArr* src, CvArr* dst,
-                                  int aperture_size CV_DEFAULT(3) );
+CVAPI(void) cvPreCornerDetect( const CvArr* image, CvArr* corners,
+                              int aperture_size CV_DEFAULT(3) );
 
 /* Calculates eigen values and vectors of 2x2
    gradient matrix at every image pixel */
-OPENCVAPI void  cvCornerEigenValsAndVecs( const CvArr* src, CvArr* eigenvv,
-                                          int blockSize,
-                                          int aperture_size CV_DEFAULT(3) );
+CVAPI(void)  cvCornerEigenValsAndVecs( const CvArr* image, CvArr* eigenvv,
+                                      int block_size, int aperture_size CV_DEFAULT(3) );
 
 /* Calculates minimal eigenvalue for 2x2 gradient matrix at
    every image pixel */
-OPENCVAPI void  cvCornerMinEigenVal( const CvArr* src, CvArr* eigenval,
-                                     int blockSize, int aperture_size CV_DEFAULT(3) );
+CVAPI(void)  cvCornerMinEigenVal( const CvArr* image, CvArr* eigenval,
+                                 int block_size, int aperture_size CV_DEFAULT(3) );
 
 /* Adjust corner position using some sort of gradient search */
-OPENCVAPI  void  cvFindCornerSubPix( const CvArr* src,CvPoint2D32f*  corners,
-                                     int count, CvSize win,CvSize zero_zone,
-                                     CvTermCriteria  criteria );
+CVAPI(void)  cvFindCornerSubPix( const CvArr* image, CvPoint2D32f* corners,
+                                 int count, CvSize win, CvSize zero_zone,
+                                 CvTermCriteria  criteria );
 
 /* Finds a sparse set of points within the selected region
    that seem to be easy to track */
-OPENCVAPI void  cvGoodFeaturesToTrack( const CvArr* image, CvArr* eig_image,
-                                       CvArr* temp_image, CvPoint2D32f* corners,
-                                       int* corner_count, double  quality_level,
-                                       double  min_distance,
-                                       const CvArr* mask CV_DEFAULT(NULL));
+CVAPI(void)  cvGoodFeaturesToTrack( const CvArr* image, CvArr* eig_image,
+                                   CvArr* temp_image, CvPoint2D32f* corners,
+                                   int* corner_count, double  quality_level,
+                                   double  min_distance,
+                                   const CvArr* mask CV_DEFAULT(NULL));
 
 #define CV_HOUGH_STANDARD 0
 #define CV_HOUGH_PROBABILISTIC 1
 #define CV_HOUGH_MULTI_SCALE 2
 
 /* Finds lines on binary image using one of several methods.
-   lineStorage is either memory storage or 1 x maxNumberOfLines CvMat, its
+   line_storage is either memory storage or 1 x <max number of lines> CvMat, its
    number of columns is changed by the function.
    method is one of CV_HOUGH_*;
    rho, theta and threshold are used for each of those methods;
-   param1 ~ lineLength, param2 ~ lineGap - for probabilistic,
+   param1 ~ line length, param2 ~ line gap - for probabilistic,
    param1 ~ srn, param2 ~ stn - for multi-scale */
-OPENCVAPI  CvSeq*  cvHoughLines2( CvArr* image, void* line_storage, int method, 
-                                  double rho, double theta, int threshold,
-                                  double param1 CV_DEFAULT(0), double param2 CV_DEFAULT(0));
-
-/* Projects 2d points to one of standard coordinate planes
-   (i.e. removes one of coordinates) */
-OPENCVAPI  void  cvProject3D( CvPoint3D32f* points3D, int count,
-                              CvPoint2D32f* points2D, int xIndx, int yIndx );
+CVAPI(CvSeq*)  cvHoughLines2( CvArr* image, void* line_storage, int method, 
+                              double rho, double theta, int threshold,
+                              double param1 CV_DEFAULT(0), double param2 CV_DEFAULT(0));
 
 /* Fits a line into set of 2d or 3d points in a robust way (M-estimator technique) */
-OPENCVAPI  void  cvFitLine( const CvArr* points, CvDisType dist, double param,
-                            double reps, double aeps, float* line );
-
-
-#define CV_EIGOBJ_NO_CALLBACK     0
-#define CV_EIGOBJ_INPUT_CALLBACK  1
-#define CV_EIGOBJ_OUTPUT_CALLBACK 2
-#define CV_EIGOBJ_BOTH_CALLBACK   3
-
-
-CV_EXTERN_C_FUNCPTR(CvStatus (CV_CDECL * CvCallback)
-                    (int index, void* buffer, void* userData));
-
-typedef union
-{
-    CvCallback callback;
-    void* data;
-}
-CvInput;
-
-/* Calculates covariation matrix of a set of arrays */
-OPENCVAPI  void  cvCalcCovarMatrixEx( int nObjects, void* input, int ioFlags,
-                                      int ioBufSize, uchar* buffer, void* userData,
-                                      IplImage* avg, float* covarMatrix );
-
-/* Calculates eigen values and vectors of covariation matrix of a set of
-   arrays */
-OPENCVAPI  void  cvCalcEigenObjects( int nObjects, void* input, void* output,
-                                    int ioFlags, int ioBufSize, void* userData,
-                                    CvTermCriteria* calcLimit, IplImage* avg,
-                                    float* eigVals );
-
-/* Calculates dot product (obj - avg) * eigObj (i.e. projects image to eigen vector) */
-OPENCVAPI  double  cvCalcDecompCoeff( IplImage* obj, IplImage* eigObj, IplImage* avg );
-
-/* Projects image to eigen space (finds all decomposion coefficients */
-OPENCVAPI  void  cvEigenDecomposite( IplImage* obj, int nEigObjs, void* eigInput,
-                                    int ioFlags, void* userData, IplImage* avg,
-                                    float* coeffs );
-
-/* Projects original objects used to calculate eigen space basis to that space */
-OPENCVAPI  void  cvEigenProjection( void* eigInput, int nEigObjs, int ioFlags,
-                                   void* userData, float* coeffs, IplImage* avg,
-                                   IplImage* proj );
-
-/*********************************** HMM structures *************************************/
-typedef struct CvEHMMState
-{
-    int num_mix;      /*number of mixtures in this state*/
-    float* mu;        /*mean vectors corresponding to each mixture*/
-    float* inv_var; /* square root of inversed variances corresp. to each mixture*/
-    float* log_var_val; /* sum of 0.5 (LN2PI + ln(variance[i]) ) for i=1,n */
-    float* weight;   /*array of mixture weights. Summ of all weights in state is 1. */
-
-} CvEHMMState;
-
-typedef struct CvEHMM
-{
-    int level; /* 0 - lowest(i.e its states are real states), ..... */
-    int num_states; /* number of HMM states */
-    float*  transP;/*transition probab. matrices for states */
-    float** obsProb; /* if level == 0 - array of brob matrices corresponding to hmm
-                        if level == 1 - martix of matrices */
-    union
-    {
-        CvEHMMState* state; /* if level == 0 points to real states array,
-                               if not - points to embedded hmms */
-        struct CvEHMM* ehmm; /* pointer to an embedded model or NULL, if it is a leaf */
-    } u;
-
-} CvEHMM;
-
-/* Creates 2D HMM */
-OPENCVAPI  CvEHMM*  cvCreate2DHMM( int* stateNumber, int* numMix, int obsSize );
-
-
-/* Releases HMM */
-OPENCVAPI  void  cvRelease2DHMM( CvEHMM** hmm );
-
-
-
-#define CV_COUNT_OBS(roi, win, delta, numObs )                                       \
-{                                                                                    \
-   (numObs)->width  =((roi)->width  -(win)->width  +(delta)->width)/(delta)->width;  \
-   (numObs)->height =((roi)->height -(win)->height +(delta)->height)/(delta)->height;\
-}
-
-typedef struct CvImgObsInfo
-{
-    int obs_x;
-    int obs_y;
-    int obs_size;
-    float* obs;//consequtive observations
-
-    int* state;/* array of pairs superstate/state to which observation belong */
-    int* mix;  /* number of mixture to which observation belong */
-
-} CvImgObsInfo;/*struct for 1 image*/
-
-/* Creates storage for observation vectors */
-OPENCVAPI  CvImgObsInfo*  cvCreateObsInfo( CvSize numObs, int obsSize );
-
-/* Releases storage for observation vectors */
-OPENCVAPI  void  cvReleaseObsInfo( CvImgObsInfo** obs_info );
-
-
-/* The function takes an image on input and and returns the sequnce of observations
-   to be used with an embedded HMM; Each observation is top-left block of DCT
-   coefficient matrix */
-OPENCVAPI  void  cvImgToObs_DCT( const CvArr* array, float* obs, CvSize dctSize,
-                                 CvSize obsSize, CvSize delta );
-
+CVAPI(void)  cvFitLine( const CvArr* points, int dist_type, double param,
+                        double reps, double aeps, float* line );
 
-/* Uniformly segments all observation vectors extracted from image */
-OPENCVAPI  void  cvUniformImgSegm( CvImgObsInfo* obs_info, CvEHMM* ehmm );
-
-/* Does mixture segmentation of the states of embedded HMM */
-OPENCVAPI  void  cvInitMixSegm( CvImgObsInfo** obs_info_array,
-                               int num_img, CvEHMM* hmm );
-
-/* Function calculates means, variances, weights of every Gaussian mixture
-   of every low-level state of embedded HMM */
-OPENCVAPI  void  cvEstimateHMMStateParams( CvImgObsInfo** obs_info_array,
-                                        int num_img, CvEHMM* hmm );
+/****************************************************************************************\
+*                         Haar-like Object Detection functions                           *
+\****************************************************************************************/
 
-/* Function computes transition probability matrices of embedded HMM
-   given observations segmentation */
-OPENCVAPI  void  cvEstimateTransProb( CvImgObsInfo** obs_info_array,
-                                   int num_img, CvEHMM* hmm );
+/* Loads haar classifier cascade from a directory.
+   It is obsolete: convert your cascade to xml and use cvLoad instead */
+CVAPI(CvHaarClassifierCascade*) cvLoadHaarClassifierCascade(
+                    const char* directory, CvSize orig_window_size);
 
-/* Function computes probabilities of appearing observations at any state
-   (i.e. computes P(obs|state) for every pair(obs,state)) */
-OPENCVAPI  void  cvEstimateObsProb( CvImgObsInfo* obs_info,
-                                   CvEHMM* hmm );
+CVAPI(void) cvReleaseHaarClassifierCascade( CvHaarClassifierCascade** cascade );
 
-/* Runs Viterbi algorithm for embedded HMM */
-OPENCVAPI  float  cvEViterbi( CvImgObsInfo* obs_info, CvEHMM* hmm );
+#define CV_HAAR_DO_CANNY_PRUNING 1
 
+CVAPI(CvSeq*) cvHaarDetectObjects( const CvArr* image,
+                     CvHaarClassifierCascade* cascade,
+                     CvMemStorage* storage, double scale_factor CV_DEFAULT(1.1),
+                     int min_neighbors CV_DEFAULT(3), int flags CV_DEFAULT(0),
+                     CvSize min_size CV_DEFAULT(cvSize(0,0)));
 
-/* Function clusters observation vectors from several images
-   given observations segmentation.
-   Euclidean distance used for clustering vectors.
-   Centers of clusters are given means of every mixture */
-OPENCVAPI  void  cvMixSegmL2( CvImgObsInfo** obs_info_array,
-                             int num_img, CvEHMM* hmm );
+/* sets images for haar classifier cascade */
+CVAPI(void) cvSetImagesForHaarClassifierCascade( CvHaarClassifierCascade* cascade,
+                                                const CvArr* sum, const CvArr* sqsum,
+                                                const CvArr* tilted_sum, double scale );
 
-/* The function implements the K-means algorithm for clustering an array of sample
-   vectors in a specified number of classes */
-OPENCVAPI  void  cvKMeans2( const CvArr* samples, int cluster_count,
-                            CvArr* cluster_idx, CvTermCriteria termcrit );
+/* runs the cascade on the specified window */
+CVAPI(int) cvRunHaarClassifierCascade( CvHaarClassifierCascade* cascade,
+                                      CvPoint pt, int start_stage CV_DEFAULT(0));
 
 /****************************************************************************************\
 *                     Camera Calibration and Rectification functions                     *
@@ -2528,495 +1011,166 @@ OPENCVAPI  void  cvKMeans2( const CvArr* samples, int cluster_count,
 
 /* The function corrects radial and tangential image distortion using known
    matrix of the camera intrinsic parameters and distortion coefficients */
-OPENCVAPI  void  cvUnDistortOnce( const CvArr* srcImage, CvArr* dstImage,
-                                  const float* intrMatrix,
-                                  const float* distCoeffs,
-                                  int interpolate CV_DEFAULT(1) );
+CVAPI(void)  cvUnDistortOnce( const CvArr* src, CvArr* dst,
+                              const float* intrinsic_matrix,
+                              const float* distortion_coeffs,
+                              int interpolate CV_DEFAULT(1) );
 
 /* The function calculates map of distorted points indices and
    interpolation coefficients for cvUnDistort function using known
    matrix of the camera intrinsic parameters and distortion coefficients */
-OPENCVAPI  void  cvUnDistortInit( const CvArr* srcImage, CvArr* undistMap,
-                                  const float* intrMatrix,
-                                  const float* distCoeffs,
-                                  int interpolate CV_DEFAULT(1) );
+CVAPI(void)  cvUnDistortInit( const CvArr* src, CvArr* undistortion_map,
+                              const float* intrinsic_matrix,
+                              const float* distortion_coeffs,
+                              int interpolate CV_DEFAULT(1) );
 
 /* The function corrects radial and tangential image distortion
    using previousely calculated (via cvUnDistortInit) map */
-OPENCVAPI  void  cvUnDistort( const CvArr* srcImage, CvArr* dstImage,
-                              const CvArr* undistMap, int interpolate CV_DEFAULT(1));
+CVAPI(void)  cvUnDistort( const CvArr* src, CvArr* dst, const CvArr* undistortion_map,
+                          int interpolate CV_DEFAULT(1));
 #define cvRemap cvUnDistort
 
 
 /* The function converts floating-point pixel coordinate map to
    faster fixed-point map, used by cvUnDistort (cvRemap) */
-OPENCVAPI  void  cvConvertMap( const CvArr* srcImage, const CvArr* flUndistMap,
-                               CvArr* undistMap, int iterpolate CV_DEFAULT(1) );
+CVAPI(void)  cvConvertMap( const CvArr* src, const CvArr* map_xy,
+                           CvArr* map_fast, int iterpolate CV_DEFAULT(1) );
 
 /* Calibrates camera using multiple views of calibration pattern */
-OPENCVAPI  void  cvCalibrateCamera( int           numImages,
-                                    int*          numPoints,
-                                    CvSize        imageSize,
-                                    CvPoint2D32f* imagePoints32f,
-                                    CvPoint3D32f* objectPoints32f,
-                                    CvVect32f     distortion32f,
-                                    CvMatr32f     cameraMatrix32f,
-                                    CvVect32f     transVects32f,
-                                    CvMatr32f     rotMatrs32f,
-                                    int           useIntrinsicGuess);
+CVAPI(void)  cvCalibrateCamera( int           image_count,
+                                int*          point_counts,
+                                CvSize        image_size,
+                                CvPoint2D32f* image_points,
+                                CvPoint3D32f* object_points,
+                                CvVect32f     distortion_coeffs,
+                                CvMatr32f     camera_matrix,
+                                CvVect32f     translation_vectors,
+                                CvMatr32f     rotation_matrixes,
+                                int           use_intrinsic_guess);
 
 /* Variant of the previous function that takes double-precision parameters */
-OPENCVAPI  void  cvCalibrateCamera_64d( int           numImages,
-                                       int*          numPoints,
-                                       CvSize        imageSize,
-                                       CvPoint2D64d* imagePoints,
-                                       CvPoint3D64d* objectPoints,
-                                       CvVect64d     distortion,
-                                       CvMatr64d     cameraMatrix,
-                                       CvVect64d     transVects,
-                                       CvMatr64d     rotMatrs,
-                                       int           useIntrinsicGuess );
+CVAPI(void)  cvCalibrateCamera_64d( int           image_count,
+                                    int*          point_counts,
+                                    CvSize        image_size,
+                                    CvPoint2D64d* image_points,
+                                    CvPoint3D64d* object_points,
+                                    CvVect64d     distortion_coeffs,
+                                    CvMatr64d     camera_matrix,
+                                    CvVect64d     translation_vectors,
+                                    CvMatr64d     rotation_matrixes,
+                                    int           use_intrinsic_guess);
 
 /* Find 3d position of object given intrinsic camera parameters,
    3d model of the object and projection of the object into view plane */
-OPENCVAPI  void  cvFindExtrinsicCameraParams( int           numPoints,
-                                             CvSize        imageSize,
-                                             CvPoint2D32f* imagePoints32f,
-                                             CvPoint3D32f* objectPoints32f,
-                                             CvVect32f     focalLength32f,
-                                             CvPoint2D32f  principalPoint32f,
-                                             CvVect32f     distortion32f,
-                                             CvVect32f     rotVect32f,
-                                             CvVect32f     transVect32f);
+CVAPI(void)  cvFindExtrinsicCameraParams( int           point_count,
+                                          CvSize        image_size,
+                                          CvPoint2D32f* image_points,
+                                          CvPoint3D32f* object_points,
+                                          CvVect32f     focal_length,
+                                          CvPoint2D32f  principal_point,
+                                          CvVect32f     distortion_coeffs,
+                                          CvVect32f     rotation_vector,
+                                          CvVect32f     translation_vector);
 
 /* Variant of the previous function that takes double-precision parameters */
-OPENCVAPI  void  cvFindExtrinsicCameraParams_64d( int           numPoints,
-                                                 CvSize        imageSize,
-                                                 CvPoint2D64d* imagePoints,
-                                                 CvPoint3D64d* objectPoints,
-                                                 CvVect64d     focalLength,
-                                                 CvPoint2D64d  principalPoint,
-                                                 CvVect64d     distortion,
-                                                 CvVect64d     rotVect,
-                                                 CvVect64d     transVect);
+CVAPI(void)  cvFindExtrinsicCameraParams_64d( int           point_count,
+                                              CvSize        image_size,
+                                              CvPoint2D64d* image_points,
+                                              CvPoint3D64d* object_points,
+                                              CvVect64d     focal_length,
+                                              CvPoint2D64d  principal_point,
+                                              CvVect64d     distortion_coeffs,
+                                              CvVect64d     rotation_vector,
+                                              CvVect64d     translation_vector);
 
 
 /* Rodrigues transform */
 #define CV_RODRIGUES_M2V  0
 #define CV_RODRIGUES_V2M  1
 
-/* Converts rotation matrix to rotation vector or vice versa */
-OPENCVAPI  void  cvRodrigues( CvMat* rotMatrix, CvMat* rotVector,
-                              CvMat* jacobian, int convType);
+/* Converts rotation_matrix matrix to rotation_matrix vector or vice versa */
+CVAPI(void)  cvRodrigues( CvMat* rotation_matrix, CvMat* rotation_vector,
+                          CvMat* jacobian, int conv_type);
 
 /* Does reprojection of 3d object points to the view plane */
-OPENCVAPI  void  cvProjectPoints( int             numPoints,
-                                 CvPoint3D64d*   objectPoints,
-                                 CvVect64d       rotVect,
-                                 CvVect64d       transVect,
-                                 CvVect64d       focalLength,
-                                 CvPoint2D64d    principalPoint,
-                                 CvVect64d       distortion,
-                                 CvPoint2D64d*   imagePoints,
-                                 CvVect64d       derivPointsRot,
-                                 CvVect64d       derivPointsTrans,
-                                 CvVect64d       derivPointsFocal,
-                                 CvVect64d       derivPointsPrincipal,
-                                 CvVect64d       derivPointsDistort);
+CVAPI(void)  cvProjectPoints( int             point_count,
+                              CvPoint3D64d*   object_points,
+                              CvVect64d       rotation_vector,
+                              CvVect64d       translation_vector,
+                              CvVect64d       focal_length,
+                              CvPoint2D64d    principal_point,
+                              CvVect64d       distortion,
+                              CvPoint2D64d*   image_points,
+                              CvVect64d       deriv_points_rotation_matrix,
+                              CvVect64d       deriv_points_translation_vect,
+                              CvVect64d       deriv_points_focal,
+                              CvVect64d       deriv_points_principal_point,
+                              CvVect64d       deriv_points_distortion_coeffs);
 
 /* Simpler version of the previous function */
-OPENCVAPI void cvProjectPointsSimple(  int numPoints,
-                                    CvPoint3D64d * objectPoints,
-                                    CvVect64d rotMatr,
-                                    CvVect64d transVect,
-                                    CvMatr64d cameraMatrix,
-                                    CvVect64d distortion,
-                                    CvPoint2D64d* imagePoints);
+CVAPI(void) cvProjectPointsSimple( int point_count,
+                                  CvPoint3D64d * object_points,
+                                  CvVect64d rotation_matrix,
+                                  CvVect64d translation_vector,
+                                  CvMatr64d camera_matrix,
+                                  CvVect64d distortion,
+                                  CvPoint2D64d* image_points);
                                     
-/* Detects corners on a chess-board - "brand" OpenCV calibration pattern */
-OPENCVAPI  int  cvFindChessBoardCornerGuesses( const CvArr* array, CvArr* thresh,
-                                               CvMemStorage* storage, CvSize etalon_size,
-                                               CvPoint2D32f* corners,
-                                               int *corner_count CV_DEFAULT(NULL));
-
+/* Detects corners on a chess-board */
+CVAPI(int)  cvFindChessBoardCornerGuesses( const CvArr* image, CvArr* thresh,
+                                           CvMemStorage* storage, CvSize board_size,
+                                           CvPoint2D32f* corners,
+                                           int* corner_count CV_DEFAULT(NULL));
 
 typedef struct CvPOSITObject CvPOSITObject;
 
 /* Allocates and initializes CvPOSITObject structure before doing cvPOSIT */
-OPENCVAPI  CvPOSITObject*  cvCreatePOSITObject( CvPoint3D32f* points, int numPoints );
+CVAPI(CvPOSITObject*)  cvCreatePOSITObject( CvPoint3D32f* points, int point_count );
 
 
 /* Runs POSIT (POSe from ITeration) algorithm for determining 3d position of
    an object given its model and projection in a weak-perspective case */
-OPENCVAPI  void  cvPOSIT(  CvPOSITObject* pObject, CvPoint2D32f* imagePoints,
-                           double focalLength, CvTermCriteria criteria,
-                           CvMatr32f rotation, CvVect32f translation);
+CVAPI(void)  cvPOSIT(  CvPOSITObject* posit_object, CvPoint2D32f* image_points,
+                       double focal_length, CvTermCriteria criteria,
+                       CvMatr32f rotation_matrix, CvVect32f translation_vector);
 
 /* Releases CvPOSITObject structure */
-OPENCVAPI  void  cvReleasePOSITObject( CvPOSITObject**  ppObject );
+CVAPI(void)  cvReleasePOSITObject( CvPOSITObject**  posit_object );
 
 
 /****************************************************************************************\
-*                                      ViewMorphing                                      *
+*                                 Epipolar Geometry                                      *
 \****************************************************************************************/
-OPENCVAPI void cvMake2DPoints(CvMat* srcPoint,CvMat* dstPoint);
-OPENCVAPI void cvMake3DPoints(CvMat* srcPoint,CvMat* dstPoint);
-OPENCVAPI int cvSolveCubic(CvMat* coeffs,CvMat* result);
+CVAPI(void) cvMake2DPoints( CvMat* src, CvMat* dst );
+CVAPI(void) cvMake3DPoints( CvMat* src, CvMat* dst );
+CVAPI(int) cvSolveCubic( CvMat* coeffs, CvMat* roots );
 
 /* Calculates fundamental matrix given a set of corresponding points */
 #define CV_FM_7POINT 1
 #define CV_FM_8POINT 2
 #define CV_FM_RANSAC 3
 #define CV_FM_LMEDS  4 
-OPENCVAPI  int cvFindFundamentalMat( CvMat* points1, CvMat* points2,
-                                     CvMat* fundMatr, int method,
-                                     double param1, double param2,
-                                     CvMat* status );
+CVAPI(int) cvFindFundamentalMat( CvMat* points1, CvMat* points2,
+                                 CvMat* fundamental_matrix, int method,
+                                 double param1, double param2,
+                                 CvMat* status CV_DEFAULT(0) );
 
 /* For each input point on one of images
    computes parameters of the corresponding
    epipolar line on the other image */
-OPENCVAPI  void cvComputeCorrespondEpilines(CvMat* points,
-                                            int pointImageID,
-                                            CvMat* fundMatr,
-                                            CvMat* corrLines);
-
-/*************************** View Morphing Functions ************************/
-
-/* The order of the function corresponds to the order they should appear in
-   the view morphing pipeline */ 
-
-/* Finds ending points of scanlines on left and right images of stereo-pair */
-OPENCVAPI  void  cvMakeScanlines( const CvMatrix3* matrix,
-                                CvSize     imgSize,
-                                int*       scanlines_1,
-                                int*       scanlines_2,
-                                int*       lens_1,
-                                int*       lens_2,
-                                int*       numlines);
-
-/* Grab pixel values from scanlines and stores them sequentially
-   (some sort of perspective image transform) */
-OPENCVAPI  void  cvPreWarpImage( int       numLines,
-                               IplImage* img,
-                               uchar*    dst,
-                               int*      dst_nums,
-                               int*      scanlines);
-
-/* Approximate each grabbed scanline by a sequence of runs
-   (lossy run-length compression) */
-OPENCVAPI  void  cvFindRuns( int    numLines,
-                           uchar* prewarp_1,
-                           uchar* prewarp_2,
-                           int*   line_lens_1,
-                           int*   line_lens_2,
-                           int*   runs_1,
-                           int*   runs_2,
-                           int*   num_runs_1,
-                           int*   num_runs_2);
-
-/* Compares two sets of compressed scanlines */
-OPENCVAPI  void  cvDynamicCorrespondMulti( int  lines,
-                                         int* first,
-                                         int* first_runs,
-                                         int* second,
-                                         int* second_runs,
-                                         int* first_corr,
-                                         int* second_corr);
-
-/* Finds scanline ending coordinates for some intermediate "virtual" camera position */
-OPENCVAPI  void  cvMakeAlphaScanlines( int*  scanlines_1,
-                                     int*  scanlines_2,
-                                     int*  scanlines_a,
-                                     int*  lens,
-                                     int   numlines,
-                                     float alpha);
-
-/* Blends data of the left and right image scanlines to get
-   pixel values of "virtual" image scanlines */
-OPENCVAPI  void  cvMorphEpilinesMulti( int    lines,
-                                     uchar* first_pix,
-                                     int*   first_num,
-                                     uchar* second_pix,
-                                     int*   second_num,
-                                     uchar* dst_pix,
-                                     int*   dst_num,
-                                     float  alpha,
-                                     int*   first,
-                                     int*   first_runs,
-                                     int*   second,
-                                     int*   second_runs,
-                                     int*   first_corr,
-                                     int*   second_corr);
-
-/* Does reverse warping of the morphing result to make
-   it fill the destination image rectangle */
-OPENCVAPI  void  cvPostWarpImage( int       numLines,
-                                uchar*    src,
-                                int*      src_nums,
-                                IplImage* img,
-                                int*      scanlines);
-
-/* Deletes Moire (missed pixels that appear due to discretization) */
-OPENCVAPI  void  cvDeleteMoire( IplImage*  img);
-
-/****************************************************************************************\
-*                                    System functions                                    *
-\****************************************************************************************/
-
-/* Loads optimized libraries (with manual and automatical processor type specification) */
-OPENCVAPI  int  cvLoadPrimitives( const char* proc_type CV_DEFAULT(NULL) );
-
-/* Exports low-level functions from OpenCV */
-OPENCVAPI  int  cvFillInternalFuncsTable(void* table);
-
-/* Retrieves information about OpenCV and loaded optimized primitives */
-OPENCVAPI  void  cvGetLibraryInfo( const char** version, int* loaded,
-                                   const char** loaded_modules );
-
-/* Get current OpenCV error status */
-OPENCVAPI CVStatus cvGetErrStatus( void );
-
-/* Sets error status silently */
-OPENCVAPI void cvSetErrStatus( CVStatus status );
-
-
-/* Retrives current error processing mode */
-OPENCVAPI int  cvGetErrMode( void );
-
-/* Sets error processing mode */
-OPENCVAPI void cvSetErrMode( int mode );
-
-/* Sets error status and performs some additonal actions (error message box,
-   writing message to stderr, terminate application etc.)
-   depending on the current error mode */
-OPENCVAPI CVStatus cvError( CVStatus code, const char *func,
-                         const char *context, const char *file, int line);
-
-/* Retrieves textual description of the error given its code */
-OPENCVAPI const char* cvErrorStr( CVStatus status );
-
-
-/* Assigns a new error-handling function */
-OPENCVAPI CVErrorCallBack cvRedirectError(CVErrorCallBack cvErrorFunc);
-
-
-/*
-    Output to:
-        cvNulDevReport - nothing
-        cvStdErrReport - console(printf)
-        cvGuiBoxReport - MessageBox(WIN32)
-*/
-OPENCVAPI CVStatus cvNulDevReport( CVStatus status, const char *funcName,
-                                const char *context, const char *file, int line );
-
-OPENCVAPI CVStatus cvStdErrReport( CVStatus status, const char *funcName,
-                                const char *context, const char *file, int line );
-
-OPENCVAPI CVStatus cvGuiBoxReport( CVStatus status, const char *funcName,
-                                const char *context, const char *file, int line);
-
-/* Get call stack */
-OPENCVAPI void cvGetCallStack(CvStackRecord** stack, int* size);
-
-/* Push the record to the call stack */
-OPENCVAPI void cvStartProfile( const char* call, const char* file, int line );
-
-/* Pop the record from the stack */
-OPENCVAPI void cvEndProfile( const char* file, int line );
+CVAPI(void) cvComputeCorrespondEpilines( const CvMat* points,
+                                         int which_image,
+                                         const CvMat* fundamental_matrix,
+                                         CvMat* correspondent_lines );
 
-CV_EXTERN_C_FUNCPTR(void (CV_CDECL* CvStartProfileFunc)(const char*,const char*,int));
-CV_EXTERN_C_FUNCPTR(void (CV_CDECL* CvEndProfileFunc)(const char*,int));
-
-/* management functions */
-OPENCVAPI void cvSetProfile( CvStartProfileFunc startProfile,
-                             CvEndProfileFunc endProfile );
-OPENCVAPI void cvRemoveProfile();                  
-
-
-CV_EXTERN_C_FUNCPTR(void* (CV_STDCALL *CvAllocFunc)(int, const char*, int));
-CV_EXTERN_C_FUNCPTR(int (CV_STDCALL *CvFreeFunc)(void**, const char*, int));
-
-/* Set user-defined memory managment functions (substitutors for malloc and free) that
-   will be called by cvAlloc, cvFree and higher-level functions (e.g. cvCreateImage) */
-OPENCVAPI void cvSetMemoryManager( CvAllocFunc allocFunc CV_DEFAULT(0),
-                                   CvFreeFunc freeFunc CV_DEFAULT(0));
-
-
-CV_EXTERN_C_FUNCPTR(IplImage* (CV_STDCALL* Cv_iplCreateImageHeader)
-                            (int,int,int,char*,char*,int,int,int,int,int,
-                            IplROI*,IplImage*,void*,IplTileInfo*));
-CV_EXTERN_C_FUNCPTR(void (CV_STDCALL* Cv_iplAllocateImageData)(IplImage*,int,int));
-
-CV_EXTERN_C_FUNCPTR(void (CV_STDCALL* Cv_iplDeallocate)(IplImage*,int));
-
-CV_EXTERN_C_FUNCPTR(IplROI* (CV_STDCALL* Cv_iplCreateROI)(int,int,int,int,int));
-
-CV_EXTERN_C_FUNCPTR(IplImage* (CV_STDCALL* Cv_iplCloneImage)(const IplImage*));
-
-
-/* Makes OpenCV use IPL functions for IplImage allocation/deallocation */
-OPENCVAPI void
-cvSetIPLAllocators( Cv_iplCreateImageHeader createHeader,
-                    Cv_iplAllocateImageData allocateData,
-                    Cv_iplDeallocate deallocate,
-                    Cv_iplCreateROI createROI,
-                    Cv_iplCloneImage cloneImage );
-
-#define CV_TURN_ON_IPL_COMPATIBILITY()                                  \
-    cvSetIPLAllocators( iplCreateImageHeader, iplAllocateImage,         \
-                        iplDeallocate, iplCreateROI, iplCloneImage )
-
-/****************************************************************************************\
-*                                    Data Persistence                                    *
-\****************************************************************************************/
-
-/********************************** High-level functions ********************************/
-
-/* "black box" file storage */
-typedef struct CvFileStorage CvFileStorage;
-
-/* storage flags */
-#define CV_STORAGE_READ          0
-#define CV_STORAGE_WRITE_TEXT    1
-#define CV_STORAGE_WRITE_BINARY  2
-
-/* write flags */
-#define CV_WRITE_TREE      2 /* flag for storing sequence trees */
-
-/* opens existing or creates new file storage */
-OPENCVAPI  CvFileStorage*  cvOpenFileStorage( const char* filename,
-                                              CvMemStorage* storage,
-                                              int flags );
-
-/* closes file storage and deallocates buffers */
-OPENCVAPI  void cvReleaseFileStorage( CvFileStorage** storage );
-
-/* list of attributes */
-typedef struct CvAttrList
-{
-    char** attr; /* NULL-terminated array of (attribute_name,attribute_value) pairs */
-    struct CvAttrList* next; /* pointer to next chunk of the attributes list */
-}
-CvAttrList;
-
-CV_INLINE CvAttrList cvAttrList( char** attr CV_DEFAULT(NULL),
-                                 CvAttrList* next CV_DEFAULT(NULL) );
-CV_INLINE CvAttrList cvAttrList( char** attr, CvAttrList* next )
-{
-    CvAttrList list;
-    list.attr = attr;
-    list.next = next;
-
-    return list;
-}
-
-OPENCVAPI const char* cvAttrValue( const CvAttrList* attr, const char* attr_name );
-
-struct CvTypeInfo;
-
-typedef struct CvFileNode
-{
-    CV_TREE_NODE_FIELDS(CvFileNode)
-    const char* tagname;
-    const char* name;
-    CvAttrList* attr;
-    struct CvFileNode* hash_next;
-    unsigned hash_val;
-    int elem_size;
-    struct CvTypeInfo* typeinfo;
-    const char* body;
-    const void* content;
-}
-CvFileNode;
-
-
-/* writes matrix, image, sequence, graph etc. */
-OPENCVAPI  void cvWrite( CvFileStorage* storage, const char* name,
-                         const void* struct_ptr,
-                         CvAttrList attributes CV_DEFAULT(cvAttrList()),
-                         int flags CV_DEFAULT(0));
-
-/* writes opening tag of a compound object (used internally by cvWrite) */
-OPENCVAPI  void cvStartWriteStruct( CvFileStorage* storage, const char* name,
-                                    const char* type_name CV_DEFAULT(NULL),
-                                    const void* struct_ptr CV_DEFAULT(NULL),
-                                    CvAttrList attributes CV_DEFAULT(cvAttrList()));
-
-/* writes closing tag of a compound object (used internally by cvWrite) */
-OPENCVAPI  void cvEndWriteStruct( CvFileStorage* storage );
-
-/* writes a basic type value or a C structure of such values */
-OPENCVAPI  void cvWriteElem( CvFileStorage* storage,
-                             const char* name,
-                             const char* elem_spec,
-                             const void* data_ptr );
-
-/* finds the specified noe of file storage */
-OPENCVAPI  CvFileNode* cvGetFileNode( CvFileStorage* storage, const char* name );
-
-/* reads matrix, image, sequence, graph etc. */
-OPENCVAPI  const void* cvReadFileNode( CvFileStorage* storage, CvFileNode* node,
-                                       CvAttrList** list CV_DEFAULT(NULL));
-
-CV_INLINE  const void* cvRead( CvFileStorage* storage, const char* name,
-                               CvAttrList** list CV_DEFAULT(NULL) );
-CV_INLINE  const void* cvRead( CvFileStorage* storage, const char* name, CvAttrList** list )
-{
-    return cvReadFileNode( storage, cvGetFileNode( storage, name ), list );
-}
-
-/* read a basic type value or a C structure of such values */
-OPENCVAPI  int cvReadElem( CvFileStorage* storage, const char* name, void* data_ptr );
-
-/*********************************** Adding own types ***********************************/
-
-CV_EXTERN_C_FUNCPTR(int (CV_CDECL *CvIsInstanceFunc)(const void* struct_ptr));
-CV_EXTERN_C_FUNCPTR(void (CV_CDECL *CvReleaseFunc)(void** struct_dblptr));
-CV_EXTERN_C_FUNCPTR(void* (CV_CDECL *CvReadFunc)( CvFileStorage* storage,
-                                                  CvFileNode* node ));
-CV_EXTERN_C_FUNCPTR(void (CV_CDECL *CvWriteFunc)( CvFileStorage* storage,
-                                                  const char* name,
-                                                  const void* struct_ptr,
-                                                  CvAttrList attributes,
-                                                  int flags ));
-CV_EXTERN_C_FUNCPTR(void* (CV_CDECL *CvCloneFunc)( const void* struct_ptr));
-
-typedef struct CvTypeInfo
-{
-    int flags;
-    int header_size;
-    struct CvTypeInfo* prev;
-    struct CvTypeInfo* next;
-    const char* type_name;
-    CvIsInstanceFunc is_instance;
-    CvReleaseFunc release;
-    CvReadFunc read;
-    CvWriteFunc write;
-    CvCloneFunc clone;
+#ifdef __cplusplus
 }
-CvTypeInfo;
-
-OPENCVAPI  CvTypeInfo* cvRegisterType( CvTypeInfo* info_data );
-OPENCVAPI  void        cvUnregisterType( const char* type_name );
-OPENCVAPI  CvTypeInfo* cvFirstType(void);
-OPENCVAPI  CvTypeInfo* cvFindType( const char* type_name );
-OPENCVAPI  CvTypeInfo* cvTypeOf( const void* struct_ptr );
-
-/* universal functions */
-OPENCVAPI void cvRelease( void** struct_ptr );
-OPENCVAPI void* cvClone( const void* struct_ptr );
+#endif
 
 /****************************************************************************************\
 *                                 Backward compatibility                                 *
 \****************************************************************************************/
 
-#ifdef __cplusplus
-}
-#endif
-
-
 #ifndef _CV_NO_BACKWARD_COMPATIBILITY
 #include "cvcompat.h"
 #endif
index a82ab9bf877d0ca04420b8ecc5f5e753c5d1907f..a1a6adc18f7a71b87d62c253515db645e5efec5f 100644 (file)
 #ifndef _CV_HPP_
 #define _CV_HPP_
 
-#include "cv.h"
-
-#ifdef __cplusplus
-
-/****************************************************************************************\
-*                                      Image class                                       *
-\****************************************************************************************/
-
-struct CV_DLL_ENTRY CvImage : public IplImage
-{
-    CvImage();
-    CvImage( CvSize size, int depth, int channels );
-    ~CvImage();
-
-    uchar* image_data();
-    const uchar* image_data() const;
-
-    CvSize image_roi_size() const;
-    int    byte_per_pixel() const;
-
-    CvImage& operator = ( const CvImage& another )
-    { return copy( another ); }
-    
-    CvImage& copy( const CvImage& another );
-};
-
-class CV_DLL_ENTRY CvCamShiftTracker
-{
-public:
-    
-    CvCamShiftTracker();
-    virtual ~CvCamShiftTracker();
-    
-    /**** Characteristics of the object that are calculated by track_object method *****/
-    float   get_orientation() const // orientation of the object in degrees 
-    { return m_box.angle; }
-    float   get_length() const // the larger linear size of the object
-    { return m_box.size.height; }
-    float   get_width() const // the smaller linear size of the object
-    { return m_box.size.width; }
-    CvPoint2D32f get_center() const // center of the object
-    { return m_box.center; }
-    CvRect get_window() const // bounding rectangle for the object
-    { return m_comp.rect; }
-    
-    /*********************** Tracking parameters ************************/
-    int     get_threshold() const // thresholding value that applied to back project
-    { return m_threshold; }
-
-    int     get_hist_dims( int* dims = 0 ) const // returns number of histogram dimensions and sets
-    { return m_hist ? cvGetDims( m_hist->bins, dims ) : 0; } 
-    
-    int     get_min_ch_val( int channel ) const // get the minimum allowed value of the specified channel
-    { return m_min_ch_val[channel]; }
-    
-    int     get_max_ch_val( int channel ) const // get the maximum allowed value of the specified channel
-    { return m_max_ch_val[channel]; }
-    
-    // set initial object rectangle (must be called before initial calculation of the histogram)
-    bool    set_window( CvRect window)
-    { m_comp.rect = window; return true; }
-    
-    bool    set_threshold( int threshold ) // threshold applied to the histogram bins
-    { m_threshold = threshold; return true; }
-
-    bool    set_hist_bin_range( int dim, int min_val, int max_val );
-
-    bool    set_hist_dims( int c_dims, int* dims );// set the histogram parameters
-    
-    bool    set_min_ch_val( int channel, int val ) // set the minimum allowed value of the specified channel
-    { m_min_ch_val[channel] = val; return true; }
-    bool    set_max_ch_val( int channel, int val ) // set the maximum allowed value of the specified channel
-    { m_max_ch_val[channel] = val; return true; }
-
-    /************************ The processing methods *********************************/
-    // update object position
-    virtual bool  track_object( const IplImage* cur_frame );
-    
-    // update object histogram
-    virtual bool  update_histogram( const IplImage* cur_frame );
-
-    // reset histogram
-    virtual void  reset_histogram();
-
-    /************************ Retrieving internal data *******************************/
-    // get back project image
-    virtual IplImage* get_back_project()
-    { return m_back_project; }
-
-    float query( int* bin ) const
-    { return m_hist ? cvQueryHistValue_nD( m_hist, bin ) : 0.f; }
-    
-protected:
-
-    // internal method for color conversion: fills m_color_planes group
-    virtual void color_transform( const IplImage* img ); 
-
-    CvHistogram* m_hist;
-
-    CvBox2D    m_box;
-    CvConnectedComp m_comp;
-
-    float      m_hist_ranges_data[CV_MAX_DIM][2];
-    float*     m_hist_ranges[CV_MAX_DIM];
-
-    int        m_min_ch_val[CV_MAX_DIM];
-    int        m_max_ch_val[CV_MAX_DIM];
-    int        m_threshold;
-
-    IplImage*  m_color_planes[CV_MAX_DIM];
-    IplImage*  m_back_project;
-    IplImage*  m_temp;
-    IplImage*  m_mask;
-};
-
-#endif /* __cplusplus */
 #endif /* _CV_HPP_ */
 
 /* End of file. */
index fc5aa93606deafc6c736fffd39191366806af2da..2304ba53a5948c7263add52845b641361048f8bc 100644 (file)
 
 #include <string.h>
 
-#if _MSC_VER>=1200 && !defined __ICL
-    #define CV_UNREFERENCED(arg)  (arg)
-#else
+#ifdef __cplusplus
     #define CV_UNREFERENCED(arg)
+#else
+    #define CV_UNREFERENCED(arg) arg
 #endif
 
 #define CvMatType int
@@ -150,9 +150,9 @@ CV_INLINE void  cvMean_StdDev( const CvArr* image, double* mean,
 }
 
 
-CV_INLINE void cvmPerspectiveProject( const CvArr* mat, const CvArr* src,
+CV_INLINE void cvmPerspectiveProject( const CvMat* mat, const CvArr* src,
                                       CvArr* dst );
-CV_INLINE void cvmPerspectiveProject( const CvArr* mat, const CvArr* src,
+CV_INLINE void cvmPerspectiveProject( const CvMat* mat, const CvArr* src,
                                       CvArr* dst )
 {
     CvMat tsrc, tdst;
@@ -173,9 +173,94 @@ CV_INLINE void cvFillImage( CvArr* mat, double color )
     right_bottom.x--;
     right_bottom.y--;
 
-    cvRectangle( mat, left_top, right_bottom, color, CV_FILLED );
+    cvRectangle( mat, left_top, right_bottom,
+                 cvColorToScalar( color, cvGetElemType(mat)),
+                 CV_FILLED, 8, 0 );
+}
+
+
+#define cvCvtPixToPlane cvSplit
+#define cvCvtPlaneToPix cvMerge
+
+typedef struct CvRandState
+{
+    CvRNG     state;    /* RNG state (the current seed and carry)*/
+    int       disttype; /* distribution type */
+    CvScalar  param[2]; /* parameters of RNG */
+}
+CvRandState;
+
+
+/* Changes RNG range while preserving RNG state */
+CV_INLINE  void  cvRandSetRange( CvRandState* state, double param1,
+                                 double param2, int index CV_DEFAULT(-1));
+CV_INLINE  void  cvRandSetRange( CvRandState* state, double param1,
+                                 double param2, int index )
+{
+    if( !state )
+    {
+        cvError( CV_StsNullPtr, "cvRandSetRange", "Null pointer to RNG state", "cvcompat.h", 0 );
+        return;
+    }
+
+    if( (unsigned)(index + 1) > 4 )
+    {
+        cvError( CV_StsOutOfRange, "cvRandSetRange", "index is not in -1..3", "cvcompat.h", 0 );
+        return;
+    }
+
+    if( index < 0 )
+    {
+        state->param[0].val[0] = state->param[0].val[1] =
+        state->param[0].val[2] = state->param[0].val[3] = param1;
+        state->param[1].val[0] = state->param[1].val[1] = 
+        state->param[1].val[2] = state->param[1].val[3] = param2;
+    }
+    else
+    {
+        state->param[0].val[index] = param1;
+        state->param[1].val[index] = param2;
+    }
+}
+
+
+CV_INLINE  void  cvRandInit( CvRandState* state, double param1,
+                             double param2, int seed,
+                             int disttype CV_DEFAULT(CV_RAND_UNI));
+CV_INLINE  void  cvRandInit( CvRandState* state, double param1,
+                             double param2, int seed, int disttype )
+{
+    if( !state )
+    {
+        cvError( CV_StsNullPtr, "cvRandInit", "Null pointer to RNG state", "cvcompat.h", 0 );
+        return;
+    }
+
+    if( disttype != CV_RAND_UNI && disttype != CV_RAND_NORMAL )
+    {
+        cvError( CV_StsBadFlag, "cvRandInit", "Unknown distribution type", "cvcompat.h", 0 );
+        return;
+    }
+
+    state->state = (uint64)(seed ? seed : -1);
+    state->disttype = disttype;
+    cvRandSetRange( state, param1, param2, -1 );
+}
+
+
+/* Fills array with random numbers */
+CV_INLINE void cvRand( CvRandState* state, CvArr* arr );
+CV_INLINE void cvRand( CvRandState* state, CvArr* arr )
+{
+    if( !state )
+    {
+        cvError( CV_StsNullPtr, "cvRand", "Null pointer to RNG state", "cvcompat.h", 0 );
+        return;
+    }
+    cvRandArr( &state->state, arr, state->disttype, state->param[0], state->param[1] ); 
 }
 
+#define cvRandNext( _state ) cvRandInt( &(_state)->state )
 
 CV_INLINE void cvbRand( CvRandState* state, float* dst, int len );
 CV_INLINE void cvbRand( CvRandState* state, float* dst, int len )
@@ -270,8 +355,8 @@ CV_INLINE  void  cvbFastLog( const double* x, float* y, int len )
 }
 
 
-CV_INLINE  CvRect  cvContourBoundingRect( const void* point_set, int update CV_DEFAULT(0));
-CV_INLINE  CvRect  cvContourBoundingRect( const void* point_set, int update )
+CV_INLINE  CvRect  cvContourBoundingRect( void* point_set, int update CV_DEFAULT(0));
+CV_INLINE  CvRect  cvContourBoundingRect( void* point_set, int update )
 {
     return cvBoundingRect( point_set, update );
 }
@@ -279,9 +364,8 @@ CV_INLINE  CvRect  cvContourBoundingRect( const void* point_set, int update )
 
 CV_INLINE double cvPseudoInverse( const CvArr* src, CvArr* dst,
                                   int flags CV_DEFAULT(0));
-CV_INLINE double cvPseudoInverse( const CvArr* src, CvArr* dst, int flags )
+CV_INLINE double cvPseudoInverse( const CvArr* src, CvArr* dst, int CV_UNREFERENCED(flags) )
 {
-    CV_UNREFERENCED( flags );
     return cvInvert( src, dst, CV_SVD );
 }
 
@@ -327,13 +411,11 @@ CV_INLINE double cvPseudoInverse( const CvArr* src, CvArr* dst, int flags )
 /* Calculates exact convex hull of 2d point set */
 CV_INLINE void cvConvexHull( CvPoint* points, int num_points, CvRect* bound_rect,
                              int orientation, int* hull, int* hullsize );
-CV_INLINE void cvConvexHull( CvPoint* points, int num_points, CvRect* bound_rect,
+CV_INLINE void cvConvexHull( CvPoint* points, int num_points, CvRect* CV_UNREFERENCED(bound_rect),
                              int orientation, int* hull, int* hullsize )
 {
     CvMat points1 = cvMat( 1, num_points, CV_32SC2, points );
     CvMat hull1 = cvMat( 1, num_points, CV_32SC1, hull );
-
-    CV_UNREFERENCED( bound_rect );
     
     cvConvexHull2( &points1, &hull1, orientation, 0 );
     *hullsize = hull1.cols;
@@ -359,7 +441,8 @@ CV_INLINE void cvMinAreaRect( CvPoint* points, int n,
                               CvPoint2D32f* vect1,
                               CvPoint2D32f* vect2 );
 CV_INLINE void cvMinAreaRect( CvPoint* points, int n,
-                              int left, int bottom, int right, int top,
+                              int CV_UNREFERENCED(left), int CV_UNREFERENCED(bottom),
+                              int CV_UNREFERENCED(right), int CV_UNREFERENCED(top),
                               CvPoint2D32f* anchor,
                               CvPoint2D32f* vect1,
                               CvPoint2D32f* vect2 )
@@ -378,10 +461,13 @@ CV_INLINE void cvMinAreaRect( CvPoint* points, int n,
     CV_UNREFERENCED( (left, bottom, right, top) );
 }
 
+typedef int CvDisType;
+typedef int CvChainApproxMethod;
+typedef int CvContourRetrievalMode;
 
-CV_INLINE  void  cvFitLine3D( CvPoint3D32f* points, int count, CvDisType dist,
+CV_INLINE  void  cvFitLine3D( CvPoint3D32f* points, int count, int dist,
                               void *param, float reps, float aeps, float* line );
-CV_INLINE  void  cvFitLine3D( CvPoint3D32f* points, int count, CvDisType dist,
+CV_INLINE  void  cvFitLine3D( CvPoint3D32f* points, int count, int dist,
                               void *param, float reps, float aeps, float* line )
 {
     CvMat mat = cvMat( 1, count, CV_32FC3, points );
@@ -391,9 +477,9 @@ CV_INLINE  void  cvFitLine3D( CvPoint3D32f* points, int count, CvDisType dist,
 }
 
 /* Fits a line into set of 2d points in a robust way (M-estimator technique) */ 
-CV_INLINE  void  cvFitLine2D( CvPoint2D32f* points, int count, CvDisType dist,
+CV_INLINE  void  cvFitLine2D( CvPoint2D32f* points, int count, int dist,
                               void *param, float reps, float aeps, float* line );
-CV_INLINE  void  cvFitLine2D( CvPoint2D32f* points, int count, CvDisType dist,
+CV_INLINE  void  cvFitLine2D( CvPoint2D32f* points, int count, int dist,
                               void *param, float reps, float aeps, float* line )
 {
     CvMat mat = cvMat( 1, count, CV_32FC2, points );
@@ -410,6 +496,26 @@ CV_INLINE  void cvFitEllipse( const CvPoint2D32f* points, int count, CvBox2D* bo
     *box = cvFitEllipse2( &mat );
 }
 
+/* Projects 2d points to one of standard coordinate planes
+   (i.e. removes one of coordinates) */
+CV_INLINE  void  cvProject3D( CvPoint3D32f* points3D, int count,
+                              CvPoint2D32f* points2D,
+                              int xIndx CV_DEFAULT(0),
+                              int yIndx CV_DEFAULT(1));
+CV_INLINE  void  cvProject3D( CvPoint3D32f* points3D, int count,
+                              CvPoint2D32f* points2D, int xIndx, int yIndx )
+{
+    CvMat src = cvMat( 1, count, CV_32FC3, points3D );
+    CvMat dst = cvMat( 1, count, CV_32FC2, points2D );
+    float m[6] = {0,0,0,0,0,0};
+    CvMat M = cvMat( 2, 3, CV_32F, m );
+    
+    assert( (unsigned)xIndx < 3 && (unsigned)yIndx < 3 );
+    m[xIndx] = m[yIndx+3] = 1.f;
+
+    cvTransform( &src, &dst, &M, NULL );
+}
+
 
 /* Retrieves value of the particular bin
    of x-dimensional (x=1,2,3,...) histogram */
@@ -448,7 +554,7 @@ CV_INLINE  int  cvHoughLines( CvArr* image, double rho,
     cvHoughLines2( image, &linesMat, CV_HOUGH_STANDARD,
                    rho, theta, threshold, 0, 0 );
 
-    return linesMat.rows;
+    return linesMat.cols;
 }
 
 
@@ -465,7 +571,7 @@ CV_INLINE  int  cvHoughLinesP( CvArr* image, double rho,
     cvHoughLines2( image, &linesMat, CV_HOUGH_PROBABILISTIC,
                    rho, theta, threshold, lineLength, lineGap );
 
-    return linesMat.rows;
+    return linesMat.cols;
 }
 
 
@@ -480,7 +586,7 @@ CV_INLINE  int  cvHoughLinesSDiv( CvArr* image, double rho, int srn,
     cvHoughLines2( image, &linesMat, CV_HOUGH_MULTI_SCALE,
                    rho, theta, threshold, srn, stn );
 
-    return linesMat.rows;
+    return linesMat.cols;
 }
 
 
@@ -488,15 +594,12 @@ CV_INLINE  int  cvHoughLinesSDiv( CvArr* image, double rho, int srn,
 CV_INLINE  void  cvFindFundamentalMatrix( int* points1, int* points2,
                             int numpoints, int method, float* matrix );
 CV_INLINE  void  cvFindFundamentalMatrix( int* points1, int* points2,
-                            int numpoints, int method, float* matrix )
+                            int numpoints, int CV_UNREFERENCED(method), float* matrix )
 {
     CvMat* pointsMat1;
     CvMat* pointsMat2;
     CvMat fundMatr = cvMat(3,3,CV_32F,matrix);
     int i, curr = 0;
-#ifndef __BORLANDC__
-    method = method;
-#endif
 
     pointsMat1 = cvCreateMat(3,numpoints,CV_64F);
     pointsMat2 = cvCreateMat(3,numpoints,CV_64F);
@@ -522,13 +625,13 @@ CV_INLINE  void  cvFindFundamentalMatrix( int* points1, int* points2,
 
 CV_INLINE  float  cvCalcEMD( const float* signature1, int size1,
                              const float* signature2, int size2,
-                             int dims, CvDisType dist_type CV_DEFAULT(CV_DIST_L2),
+                             int dims, int dist_type CV_DEFAULT(CV_DIST_L2),
                              CvDistanceFunction dist_func CV_DEFAULT(0),
                              float* lower_bound CV_DEFAULT(0),
                              void* user_param CV_DEFAULT(0));
 CV_INLINE  float  cvCalcEMD( const float* signature1, int size1,
                              const float* signature2, int size2,
-                             int dims, CvDisType dist_type,
+                             int dims, int dist_type,
                              CvDistanceFunction dist_func,
                              float* lower_bound, void* user_param )
 {
@@ -555,26 +658,82 @@ CV_INLINE  void  cvKMeans( int num_clusters, float** samples,
     cvReleaseMat( &samples_mat );
 }
 
+
+CV_INLINE void  cvStartScanGraph( CvGraph* graph, CvGraphScanner* scanner,
+                                  CvGraphVtx* vtx CV_DEFAULT(NULL),
+                                  int mask CV_DEFAULT(CV_GRAPH_ALL_ITEMS));
+CV_INLINE void  cvStartScanGraph( CvGraph* graph, CvGraphScanner* scanner,
+                                  CvGraphVtx* vtx, int mask )
+{
+    CvGraphScanner* temp_scanner;
+    
+    if( !scanner )
+        cvError( CV_StsNullPtr, "cvStartScanGraph", "Null scanner pointer", "cvcompat.h", 0 );
+
+    temp_scanner = cvCreateGraphScanner( graph, vtx, mask );
+    *scanner = *temp_scanner;
+    cvFree( (void**)&temp_scanner );
+}
+
+
+CV_INLINE  void  cvEndScanGraph( CvGraphScanner* scanner );
+CV_INLINE  void  cvEndScanGraph( CvGraphScanner* scanner )
+{
+    if( !scanner )
+        cvError( CV_StsNullPtr, "cvEndScanGraph", "Null scanner pointer", "cvcompat.h", 0 );
+
+    if( scanner->stack )
+    {
+        CvGraphScanner* temp_scanner = (CvGraphScanner*)cvAlloc( sizeof(*temp_scanner) );
+        *temp_scanner = *scanner;
+        cvReleaseGraphScanner( &temp_scanner );
+        memset( scanner, 0, sizeof(*scanner) );
+    }
+}
+
+
 #define cvKalmanUpdateByTime  cvKalmanPredict
 #define cvKalmanUpdateByMeasurement cvKalmanCorrect
 
-/* Creates hand mask image given several points on the hand */
-OPENCVAPI  void  cvCreateHandMask( CvSeq* hand_points,
-                                   IplImage *img_mask, CvRect *roi);
+/* old drawing functions */
+CV_INLINE  void  cvLineAA( CvArr* img, CvPoint pt1, CvPoint pt2,
+                           double color, int scale CV_DEFAULT(0));
+CV_INLINE  void  cvLineAA( CvArr* img, CvPoint pt1, CvPoint pt2,
+                           double color, int scale )
+{
+    cvLine( img, pt1, pt2, cvColorToScalar(color, cvGetElemType(img)), 1, CV_AA, scale );
+}
 
-/* Finds hand region in range image data */
-OPENCVAPI  void  cvFindHandRegion (CvPoint3D32f* points, int count,
-                                CvSeq* indexs,
-                                float* line, CvSize2D32f size, int flag,
-                                CvPoint3D32f* center,
-                                CvMemStorage* storage, CvSeq **numbers);
+CV_INLINE  void  cvCircleAA( CvArr* img, CvPoint center, int radius,
+                             double color, int scale CV_DEFAULT(0) );
+CV_INLINE  void  cvCircleAA( CvArr* img, CvPoint center, int radius,
+                             double color, int scale )
+{
+    cvCircle( img, center, radius, cvColorToScalar(color, cvGetElemType(img)), 1, CV_AA, scale );
+}
+
+CV_INLINE  void  cvEllipseAA( CvArr* img, CvPoint center, CvSize axes,
+                              double angle, double start_angle,
+                              double end_angle, double color,
+                              int scale CV_DEFAULT(0) );
+CV_INLINE  void  cvEllipseAA( CvArr* img, CvPoint center, CvSize axes,
+                              double angle, double start_angle,
+                              double end_angle, double color, int scale )
+{
+    cvEllipse( img, center, axes, angle, start_angle, end_angle,
+               cvColorToScalar(color, cvGetElemType(img)), 1, CV_AA, scale );
+}
+
+CV_INLINE  void  cvPolyLineAA( CvArr* img, CvPoint** pts, int* npts, int contours,
+                               int is_closed, double color, int scale CV_DEFAULT(0) );
+CV_INLINE  void  cvPolyLineAA( CvArr* img, CvPoint** pts, int* npts, int contours,
+                               int is_closed, double color, int scale )
+{
+    cvPolyLine( img, pts, npts, contours, is_closed,
+                cvColorToScalar(color, cvGetElemType(img)),
+                1, CV_AA, scale );
+}
 
-/* Finds hand region in range image data (advanced version) */
-OPENCVAPI  void  cvFindHandRegionA( CvPoint3D32f* points, int count,
-                                CvSeq* indexs,
-                                float* line, CvSize2D32f size, int jc,
-                                CvPoint3D32f* center,
-                                CvMemStorage* storage, CvSeq **numbers);
 
 /****************************************************************************************\
 *                                   Pixel Access Macros                                  *
@@ -737,7 +896,7 @@ typedef struct _CvPixelPosition32f
 /*  pos    - position structure                                                 */
 /*  shift  - direction ( it's value must be one of the CV_SHIFT_\85 constants ) */
 /*  cs     - number of the image channels                                       */
-#define CV_MOVE_PARAM( pos, shift, cs )                                           \
+#define CV_MOVE_PARAM( pos, shift, cs )                                             \
     ( (pos).currline += (pos).step_arr[(shift)>>2], (pos).x += ((shift)&3)-2,       \
     ((pos).currline != (pos).topline && (pos).currline != (pos).bottomline &&       \
     (pos).x >= 0 && (pos).x < (pos).width) ? (pos).currline + (pos).x*(cs) : 0 )
@@ -747,7 +906,7 @@ typedef struct _CvPixelPosition32f
 /*  pos    - position structure                                                  */
 /*  shift  - direction ( it's value must be one of the CV_SHIFT_\85 constants )  */
 /*  cs     - number of the image channels                                        */
-#define CV_MOVE_PARAM_WRAP( pos, shift, cs )                                      \
+#define CV_MOVE_PARAM_WRAP( pos, shift, cs )                                        \
     ( (pos).currline += (pos).step_arr[(shift)>>2],                                 \
     (pos).currline = ((pos).currline == (pos).topline ?                             \
     (pos).bottomline - (pos).step :                                                 \
index 211cd86b28753b5f03c176ec9b8e48d6306c48b2..b5d20885f3c7e77b95c00074f6ee259c6f4368c6 100644 (file)
@@ -54,19 +54,18 @@ You need DirectShow SDK that is now a part of DirectX SDK.
 
 2. Install it TOGETHER WITH SAMPLES.
 
-3. Open <DirectXSDKInstallFolder>\samples\Multimedia\DirectShow\BaseClasses\baseclasses.dsw.
+3. Open <DirectXSDKInstallFolder>\samples\C++\DirectShow\BaseClasses\baseclasses.{dsw|sln}.
    If there is no such file, it is that you either didn't install samples or the path has changed,
-   in the latter case search for streams.h and open a workspace file
-   (workspace files for Developer Studio .NET have different extension) located in the same folder.
+   in the latter case search for streams.h and open a workspace file located in the same folder.
 
 4. Build the library in both Release in Debug configurations.
 
-5. Copy the built libraries (in DirectX 8.x they are called strmbase.lib and strmbasd.lib)
+5. Copy the built libraries (in DirectX 9.x they are called strmbase.lib and strmbasd.lib)
    to <DirectXSDKInstallFolder>\lib.
 
 6. In Developer Studio add the following paths:
       <DirectXSDKInstallFolder>\include
-      <DirectXSDKInstallFolder>\samples\Multimedia\DirectShow\BaseClasses
+      <DirectXSDKInstallFolder>\samples\C++\DirectShow\BaseClasses
     to the includes' search path (at Tools->Options->Directories->Include files
                                   in case of Developer Studio 6.0)
    Add
@@ -84,5 +83,5 @@ You need DirectShow SDK that is now a part of DirectX SDK.
 
 #endif
 
-#endif /* _CV_ERROR_EXT_H_ */
+#endif /*_CVSTREAMS_H_*/
 
index f168c1df1de3ffb90ef162d2d88e6da8a7ecd708..b636b8bdf90aed524a957b07285ae63f5e7fbe1f 100644 (file)
 #include <assert.h>
 #include <stdlib.h>
 
-#ifndef WIN32
-    #define CV_CDECL
-    #define CV_STDCALL
-#else
-    #define CV_CDECL __cdecl
-    #define CV_STDCALL __stdcall
-#endif
-
-#ifndef CV_EXTERN_C
-    #ifdef __cplusplus
-        #define CV_EXTERN_C extern "C"
-        #define CV_DEFAULT(val) = val
-    #else
-        #define CV_EXTERN_C
-        #define CV_DEFAULT(val)
-    #endif
-#endif
-
-#ifndef CV_EXTERN_C_FUNCPTR
-    #ifdef __cplusplus
-        #define CV_EXTERN_C_FUNCPTR(x) extern "C" { typedef x; }
-    #else
-        #define CV_EXTERN_C_FUNCPTR(x) typedef x
-    #endif
-#endif
-
-#if defined WIN32 && defined CV_DLL
-    #define CV_DLL_ENTRY __declspec(dllexport)
-#else
-    #define CV_DLL_ENTRY
-#endif
-
-#ifndef OPENCVAPI
-    #define OPENCVAPI CV_EXTERN_C CV_DLL_ENTRY
-#endif
-
-#ifndef CV_INLINE
-#ifdef WIN32
-    #define CV_INLINE __inline
-#elif defined __cplusplus
-    #define CV_INLINE inline
-#else
-    #define CV_INLINE static
-#endif
-#endif /* CV_INLINE */
-
-#if defined _MSC_VER || defined __BORLANDC__
-typedef __int64 int64;
-typedef unsigned __int64 uint64;
-#else
-typedef long long int64;
-typedef unsigned long long uint64;
-#endif
-
-#ifndef __IPL_H__
-typedef unsigned char uchar;
-#endif
-
-
-/* CvArr is used to pass arbitrary array-like data structures
-   into the functions and where the particular
-   array type is recognized at runtime */ 
-typedef void CvArr;
-
-
-/****************************************************************************************\
-*                                  Image type (IplImage)                                 *
-\****************************************************************************************/
-
-#ifndef HAVE_IPL
-
-/*
- * The following definitions (until #endif)
- * is an extract from IPL headers.
- * Copyright (c) 1995 Intel Corporation.
- */
-#define IPL_DEPTH_SIGN 0x80000000
-
-#define IPL_DEPTH_1U     1
-#define IPL_DEPTH_8U     8
-#define IPL_DEPTH_16U   16
-#define IPL_DEPTH_32F   32
-
-#define IPL_DEPTH_8S  (IPL_DEPTH_SIGN| 8)
-#define IPL_DEPTH_16S (IPL_DEPTH_SIGN|16)
-#define IPL_DEPTH_32S (IPL_DEPTH_SIGN|32)
-
-#define IPL_DATA_ORDER_PIXEL  0
-#define IPL_DATA_ORDER_PLANE  1
-
-#define IPL_ORIGIN_TL 0
-#define IPL_ORIGIN_BL 1
-
-#define IPL_ALIGN_4BYTES   4
-#define IPL_ALIGN_8BYTES   8
-#define IPL_ALIGN_16BYTES 16
-#define IPL_ALIGN_32BYTES 32
-
-#define IPL_ALIGN_DWORD   IPL_ALIGN_4BYTES
-#define IPL_ALIGN_QWORD   IPL_ALIGN_8BYTES
-
-typedef 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 */
-    struct _IplROI *roi;/* image ROI. if NULL, the whole image is selected */
-    struct _IplImage *maskROI; /* must be NULL */
-    void  *imageId;     /* ditto */
-    struct _IplTileInfo *tileInfo; /* ditto */
-    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 */
-}
-IplImage;
-
-typedef struct _IplTileInfo IplTileInfo;
-
-typedef struct _IplROI {
-    int  coi; /* 0 - no COI (all channels are selected), 1 - 0th channel is selected ...*/
-    int  xOffset;
-    int  yOffset;
-    int  width;
-    int  height;
-}
-IplROI;
-
-typedef struct _IplConvKernel
-{
-    int  nCols;
-    int  nRows;
-    int  anchorX;
-    int  anchorY;
-    int *values;
-    int  nShiftR;
-}
-IplConvKernel;
-
-typedef struct _IplConvKernelFP
-{
-    int  nCols;
-    int  nRows;
-    int  anchorX;
-    int  anchorY;
-    float *values;
-}
-IplConvKernelFP;
-
-#define IPL_IMAGE_HEADER 1
-#define IPL_IMAGE_DATA   2
-#define IPL_IMAGE_ROI    4
-
-#endif/*HAVE_IPL*/
-
-#define IPL_IMAGE_MAGIC_VAL  ((int)sizeof(IplImage))
-
-/* for file storages make the value independent from arch */
-#define IPL_IMAGE_FILE_MAGIC_VAL  112
-
-#define CV_IS_IMAGE_HDR(img) \
-    ((img) != NULL && ((const IplImage*)(img))->nSize == sizeof(IplImage))
-
-#define CV_IS_IMAGE(img) \
-    (CV_IS_IMAGE_HDR(img) && ((IplImage*)img)->imageData != NULL)
-
-#define IPL_DEPTH_64F  64 /* for storing double-precision
-                             floating point data in IplImage's */
-
-/* get pointer to pixel at (col,row),
-   for multi-channel images (col) should be multiplied by number of channels */
-#define CV_IMAGE_ELEM( image, elemtype, row, col )       \
-    (((elemtype*)((image)->imageData + (image)->widthStep*(row))[(col)])
-
-
-/****************************************************************************************\
-*                                  Matrix type (CvMat)                                   *
-\****************************************************************************************/
-
-#define CV_8U   0
-#define CV_8S   1
-#define CV_16S  2
-#define CV_32S  3
-#define CV_32F  4
-#define CV_64F  5
-#define CV_USRTYPE1 6
-#define CV_USRTYPE2 7
-
-#define CV_8UC1 (CV_8U + 0*8)
-#define CV_8UC2 (CV_8U + 1*8)
-#define CV_8UC3 (CV_8U + 2*8)
-#define CV_8UC4 (CV_8U + 3*8)
-
-#define CV_8SC1 (CV_8S + 0*8)
-#define CV_8SC2 (CV_8S + 1*8)
-#define CV_8SC3 (CV_8S + 2*8)
-#define CV_8SC4 (CV_8S + 3*8)
-
-#define CV_16SC1 (CV_16S + 0*8)
-#define CV_16SC2 (CV_16S + 1*8)
-#define CV_16SC3 (CV_16S + 2*8)
-#define CV_16SC4 (CV_16S + 3*8)
-
-#define CV_32SC1 (CV_32S + 0*8)
-#define CV_32SC2 (CV_32S + 1*8)
-#define CV_32SC3 (CV_32S + 2*8)
-#define CV_32SC4 (CV_32S + 3*8)
-
-#define CV_32FC1 (CV_32F + 0*8)
-#define CV_32FC2 (CV_32F + 1*8)
-#define CV_32FC3 (CV_32F + 2*8)
-#define CV_32FC4 (CV_32F + 3*8)
-
-#define CV_64FC1 (CV_64F + 0*8)
-#define CV_64FC2 (CV_64F + 1*8)
-#define CV_64FC3 (CV_64F + 2*8)
-#define CV_64FC4 (CV_64F + 3*8)
-
-#define CV_AUTO_STEP  0x7fffffff
-#define CV_WHOLE_ARR  cvSlice( 0, 0x3fffffff )
-
-#define CV_MAT_CN_MASK          (3 << 3)
-#define CV_MAT_CN(flags)        ((((flags) & CV_MAT_CN_MASK) >> 3) + 1)
-#define CV_MAT_DEPTH_MASK       7
-#define CV_MAT_DEPTH(flags)     ((flags) & CV_MAT_DEPTH_MASK)
-#define CV_MAT_TYPE_MASK        31
-#define CV_MAT_TYPE(flags)      ((flags) & CV_MAT_TYPE_MASK)
-#define CV_MAT_FMT_MASK         511
-#define CV_MAT_FMT(flags)       ((flags) & CV_MAT_FMT_MASK)
-#define CV_MAT_CONT_FLAG_SHIFT  9
-#define CV_MAT_CONT_FLAG        (1 << CV_MAT_CONT_FLAG_SHIFT)
-#define CV_IS_MAT_CONT(flags)   ((flags) & CV_MAT_CONT_FLAG) 
-#define CV_IS_CONT_MAT          CV_IS_MAT_CONT
-#define CV_MAT_TEMP_FLAG_SHIFT  10
-#define CV_MAT_TEMP_FLAG        (1 << CV_MAT_TEMP_FLAG_SHIFT)
-#define CV_IS_TEMP_MAT(flags)   ((flags) & CV_MAT_TEMP_FLAG)
-
-#define CV_MAGIC_MASK       0xFFFF0000
-#define CV_MAT_MAGIC_VAL    0x42420000
-
-typedef struct CvMat
-{
-    int type;
-    int step;
-
-    /* for internal use only */
-    int* refcount;
-
-    union
-    {
-        uchar* ptr;
-        short* s;
-        int* i;
-        float* fl;
-        double* db;
-    } data;
-
-#ifdef __cplusplus
-    union
-    {
-        int rows;
-        int height;
-    };
-
-    union
-    {
-        int cols;
-        int width;
-    };
-#else
-    int rows;
-    int cols;
-#endif
-
-} CvMat;
-
-
-#define CV_IS_MAT_HDR(mat) \
-    ((mat) != NULL && (((const CvMat*)(mat))->type & CV_MAGIC_MASK) == CV_MAT_MAGIC_VAL)
-
-#define CV_IS_MAT(mat) \
-    (CV_IS_MAT_HDR(mat) && ((const CvMat*)(mat))->data.ptr != NULL)
-
-#define CV_IS_MASK_ARR(mat) \
-    (((mat)->type & (CV_MAT_TYPE_MASK & ~CV_8SC1)) == 0)
-
-#define CV_ARE_TYPES_EQ(mat1, mat2) \
-    ((((mat1)->type ^ (mat2)->type) & CV_MAT_TYPE_MASK) == 0)
-
-#define CV_ARE_CNS_EQ(mat1, mat2) \
-    ((((mat1)->type ^ (mat2)->type) & CV_MAT_CN_MASK) == 0)
-
-#define CV_ARE_DEPTHS_EQ(mat1, mat2) \
-    ((((mat1)->type ^ (mat2)->type) & CV_MAT_DEPTH_MASK) == 0)
-
-#define CV_ARE_SIZES_EQ(mat1, mat2) \
-    ((mat1)->height == (mat2)->height && (mat1)->width == (mat2)->width)
-
-#define CV_IS_MAT_CONST(mat)  \
-    (((mat)->height|(mat)->width) == 1)
-
-#define CV_ELEM_SIZE(type) \
-    (CV_MAT_CN(type) << ((0xe90 >> 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 */
-CV_INLINE CvMat cvMat( int rows, int cols, int type, void* data CV_DEFAULT(NULL));
-CV_INLINE CvMat cvMat( int rows, int cols, int type, void* data )
-{
-    CvMat m;
-
-    assert( (unsigned)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 = (uchar*)data;
-    m.refcount = NULL;
-
-    return m; 
-}
-
-
-#define CV_MAT_ELEM_PTR_FAST( mat, row, col, pix_size )  \
-    (assert( (unsigned)(row) < (unsigned)(mat).rows &&   \
-             (unsigned)(col) < (unsigned)(mat).cols ),   \
-     (mat).data.ptr + (mat).step*(row) + (pix_size)*(col))
-
-#define CV_MAT_ELEM_PTR( mat, row, col )                 \
-    CV_MAT_ELEM_PTR_FAST( mat, row, col, CV_ELEM_SIZE((mat).type) )
-
-#define CV_MAT_ELEM( mat, elemtype, row, col )           \
-    (*(elemtype*)CV_MAT_ELEM_PTR_FAST( mat, row, col, sizeof(elemtype)))
-
-
-CV_INLINE  double  cvmGet( const CvMat* mat, int i, int j );
-CV_INLINE  double  cvmGet( const CvMat* mat, int i, int j )
-{
-    int type;
-
-    type = CV_MAT_TYPE(mat->type);
-    assert( (unsigned)i < (unsigned)mat->rows &&
-            (unsigned)j < (unsigned)mat->cols );
-
-    if( type == CV_32FC1 )
-        return ((float*)(mat->data.ptr + i*mat->step))[j];
-    else
-    {
-        assert( type == CV_64FC1 );
-        return ((double*)(mat->data.ptr + i*mat->step))[j];
-    }
-}
-
-
-CV_INLINE  void  cvmSet( CvMat* mat, int i, int j, double val );
-CV_INLINE  void  cvmSet( CvMat* mat, int i, int j, double val )
-{
-    int type;
-    type = CV_MAT_TYPE(mat->type);
-    assert( (unsigned)i < (unsigned)mat->rows &&
-            (unsigned)j < (unsigned)mat->cols );
-
-    if( type == CV_32FC1 )
-        ((float*)(mat->data.ptr + i*mat->step))[j] = (float)val;
-    else
-    {
-        assert( type == CV_64FC1 );
-        ((double*)(mat->data.ptr + i*mat->step))[j] = (double)val;
-    }
-}
-
-/****************************************************************************************\
-*                       Multi-dimensional dense array (CvMatND)                          *
-\****************************************************************************************/
-
-#define CV_MATND_MAGIC_VAL    0x42430000
-#define CV_MAX_DIM 16
-
-#define CV_MAT_LIKE_FLAG_SHIFT  11
-#define CV_MAT_LIKE_FLAG        (1 << CV_MAT_LIKE_FLAG_SHIFT)
-
-typedef struct CvMatND
-{
-    int type;
-    int dims;
-
-    int* refcount;
-    union
-    {
-        uchar* ptr;
-        float* fl;
-        double* db;
-        int* i;
-        short* s;
-    } data;
-
-    struct
-    {
-        int size;
-        int step;
-    }
-    dim[CV_MAX_DIM];
-}
-CvMatND;
-
-#define CV_IS_MATND_HDR(mat) \
-    ((mat) != NULL && (((const CvMatND*)(mat))->type & CV_MAGIC_MASK) == CV_MATND_MAGIC_VAL)
-
-#define CV_IS_MATND(mat) \
-    (CV_IS_MATND_HDR(mat) && ((const CvMatND*)(mat))->data.ptr != NULL)
-
-
-/****************************************************************************************\
-*                      Multi-dimensional sparse array (CvSparseMat)                      *
-\****************************************************************************************/
-
-#define CV_SPARSE_MAT_MAGIC_VAL    0x42440000
-
-struct CvSet;
-
-typedef struct CvSparseMat
-{
-    int type;
-    int dims;
-    int* refcount;
-    struct CvSet* heap;
-    void** hashtable;
-    int hashsize;
-    int total;
-    int valoffset;
-    int idxoffset;
-    int size[CV_MAX_DIM];   
-}
-CvSparseMat;
-
-#define CV_IS_SPARSE_MAT_HDR(mat) \
-    ((mat) != NULL && \
-    (((const CvSparseMat*)(mat))->type & CV_MAGIC_MASK) == CV_SPARSE_MAT_MAGIC_VAL)
-
-#define CV_IS_SPARSE_MAT(mat) \
-    CV_IS_SPARSE_MAT_HDR(mat)
-
-/**************** iteration through a sparse array *****************/
-
-typedef struct CvSparseNode
-{
-    unsigned hashval;
-    struct CvSparseNode* next;
-}
-CvSparseNode;
-
-typedef struct CvSparseMatIterator
-{
-    CvSparseMat* mat;
-    CvSparseNode* node;
-    int curidx;
-}
-CvSparseMatIterator;
-
-#define CV_NODE_VAL(mat,node)   ((void*)((uchar*)(node) + (mat)->valoffset))
-#define CV_NODE_IDX(mat,node)   ((int*)((uchar*)(node) + (mat)->idxoffset))
-
-/****************************************************************************************\
-*                                         Histogram                                      *
-\****************************************************************************************/
-
-typedef int CvHistType;
-
-#define CV_HIST_MAGIC_VAL     0x42450000
-#define CV_HIST_UNIFORM_FLAG  (1 << 10)
-
-/* indicates whether bin ranges are set already or not */
-#define CV_HIST_RANGES_FLAG   (1 << 11)
-
-#define CV_HIST_ARRAY         0
-#define CV_HIST_SPARSE        1
-#define CV_HIST_TREE          CV_HIST_SPARSE
-
-#define CV_HIST_UNIFORM       1 /* should be used as a parameter only,
-                                   it turns to CV_HIST_UNIFORM_FLAG of hist->type */
-
-typedef 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 */
-}
-CvHistogram;
-
-#define CV_IS_HIST( hist ) \
-    ((hist) != NULL  && \
-     (((CvHistogram*)(hist))->type & CV_MAGIC_MASK) == CV_HIST_MAGIC_VAL && \
-     (hist)->bins != NULL)
-
-#define CV_IS_UNIFORM_HIST( hist ) \
-    (((hist)->type & CV_HIST_UNIFORM_FLAG) != 0)
-
-#define CV_IS_SPARSE_HIST( hist ) \
-    CV_IS_SPARSE_MAT((hist)->bins)
-
-#define CV_HIST_HAS_RANGES( hist ) \
-    (((hist)->type & CV_HIST_RANGES_FLAG) != 0) 
-
-/****************************************************************************************\
-*                      Other supplementary data type definitions                         *
-\****************************************************************************************/
-
-/* ************************************************************* *\
-   substitutions for round(x), floor(x), ceil(x):
-   the algorithm was taken from Agner Fog's optimization guide
-   at http://www.agner.org/assem
-\* ************************************************************* */
-CV_INLINE  int  cvRound( double val );
-CV_INLINE  int  cvRound( double val )
-{
-    double temp = val + 6755399441055744.0;
-    return (int)*((uint64*)&temp);
-}
-
-
-CV_INLINE  int  cvFloor( double val );
-CV_INLINE  int  cvFloor( double val )
-{
-    double temp = val + 6755399441055744.0;
-    float diff = (float)(val - (int)*((uint64*)&temp));
-
-    return (int)*((uint64*)&temp) - (*(int*)&diff < 0);
-}
-
-
-CV_INLINE  int  cvCeil( double val );
-CV_INLINE  int  cvCeil( double val )
-{
-    double temp = val + 6755399441055744.0;
-    float diff = (float)((int)*((uint64*)&temp) - val);
-
-    return (int)*((uint64*)&temp) + (*(int*)&diff < 0);
-}
-
-/*************************************** CvRect *****************************************/
-
-typedef struct CvRect
-{
-    int x;
-    int y;
-    int width;
-    int height;
-}
-CvRect;
-
-CV_INLINE  CvRect  cvRect( int x, int y, int width, int height );
-CV_INLINE  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;
-}
-
-
-CV_INLINE  IplROI  cvRectToROI( CvRect rect, int coi CV_DEFAULT(0));
-CV_INLINE  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;
-}
-
-
-CV_INLINE  CvRect  cvROIToRect( IplROI roi );
-CV_INLINE  CvRect  cvROIToRect( IplROI roi )
-{
-    return cvRect( roi.xOffset, roi.yOffset, roi.width, roi.height );
-}
-
-/*********************************** CvTermCriteria *************************************/
-
-#define CV_TERMCRIT_ITER    1
-#define CV_TERMCRIT_NUMB    CV_TERMCRIT_ITER
-#define CV_TERMCRIT_EPS     2
-
-typedef struct CvTermCriteria
-{
-    int    type;  /* may be combination of
-                     CV_TERMCRIT_ITER
-                     CV_TERMCRIT_EPS */
-    int    maxIter;
-    double epsilon;
-}
-CvTermCriteria;
-
-CV_INLINE  CvTermCriteria  cvTermCriteria( int type, int maxIter, double epsilon );
-CV_INLINE  CvTermCriteria  cvTermCriteria( int type, int maxIter, double epsilon )
-{
-    CvTermCriteria t;
-
-    t.type = type;
-    t.maxIter = maxIter;
-    t.epsilon = (float)epsilon;
-
-    return t;
-}
-
-
-/******************************* CvPoint and variants ***********************************/
-
-typedef struct CvPoint
-{
-    int x;
-    int y;
-}
-CvPoint;
-
-
-CV_INLINE  CvPoint  cvPoint( int x, int y );
-CV_INLINE  CvPoint  cvPoint( int x, int y )
-{
-    CvPoint p;
-
-    p.x = x;
-    p.y = y;
-
-    return p;
-}
-
-
-typedef struct CvPoint2D32f
-{
-    float x;
-    float y;
-}
-CvPoint2D32f;
-
-
-CV_INLINE  CvPoint2D32f  cvPoint2D32f( double x, double y );
-CV_INLINE  CvPoint2D32f  cvPoint2D32f( double x, double y )
-{
-    CvPoint2D32f p;
-
-    p.x = (float)x;
-    p.y = (float)y;
-
-    return p;
-}
-
-
-CV_INLINE  CvPoint2D32f  cvPointTo32f( CvPoint pt );
-CV_INLINE  CvPoint2D32f  cvPointTo32f( CvPoint pt )
+/* spatial and central moments */
+typedef struct CvMoments
 {
-    return cvPoint2D32f( (float)pt.x, (float)pt.y );    
+    double  m00, m10, m01, m20, m11, m02, m30, m21, m12, m03; /* spatial moments */
+    double  mu20, mu11, mu02, mu30, mu21, mu12, mu03; /* central moments */
+    double  inv_sqrt_m00; /* m00 != 0 ? 1/sqrt(m00) : 0 */
 }
+CvMoments;
 
-
-CV_INLINE  CvPoint  cvPointFrom32f( CvPoint2D32f pt );
-CV_INLINE  CvPoint  cvPointFrom32f( CvPoint2D32f pt )
+/* Hu invariants */
+typedef struct CvHuMoments
 {
-    return cvPoint( cvRound(pt.x), cvRound(pt.y) );    
+    double hu1, hu2, hu3, hu4, hu5, hu6, hu7; /* Hu invariants */
 }
+CvHuMoments;
 
-
-typedef struct CvPoint3D32f
-{
-    float x;
-    float y;
-    float z;
-}
-CvPoint3D32f;
-
-
-CV_INLINE  CvPoint3D32f  cvPoint3D32f( double x, double y, double z );
-CV_INLINE  CvPoint3D32f  cvPoint3D32f( double x, double y, double z )
+/* Line iterator state */
+typedef struct CvLineIterator
 {
-    CvPoint3D32f p;
-
-    p.x = (float)x;
-    p.y = (float)y;
-    p.z = (float)z;
-
-    return p;
-}           
-
-
-typedef struct CvPoint2D64d
-{
-    double x;
-    double y;
+    uchar* ptr;
+    int  err;
+    int  plus_delta;
+    int  minus_delta;
+    int  plus_step;
+    int  minus_step;
 }
-CvPoint2D64d;
-
+CvLineIterator;
 
-typedef struct CvPoint3D64d
-{
-    double x;
-    double y;
-    double z;
-}
-CvPoint3D64d;
-
-
-/******************************** CvSize's & CvBox **************************************/
+/**************************** Connected Component  **************************************/
 
-typedef struct
+typedef struct CvConnectedComp
 {
-    int width;
-    int height;
+    double area;    /* area of the connected component  */
+    CvScalar value; /* average color of the connected component */
+    CvRect rect;    /* ROI of the component  */
+    CvSeq* contour; /* optional component boundary
+                      (the contour might have child contours corresponding to the holes)*/
 }
-CvSize;
+CvConnectedComp;
 
-CV_INLINE  CvSize  cvSize( int width, int height );
-CV_INLINE  CvSize  cvSize( int width, int height )
-{
-    CvSize s;
+/*
+Internal structure that is used for sequental retrieving contours from the image.
+It supports both hierarchical and plane variants of Suzuki algorithm.
+*/
+typedef struct _CvContourScanner* CvContourScanner;
 
-    s.width = width;
-    s.height = height;
+/* contour retrieval mode */
+#define CV_RETR_EXTERNAL 0
+#define CV_RETR_LIST     1
+#define CV_RETR_CCOMP    2
+#define CV_RETR_TREE     3
 
-    return s;
-}
+/* contour approximation method */
+#define CV_CHAIN_CODE               0
+#define CV_CHAIN_APPROX_NONE        1
+#define CV_CHAIN_APPROX_SIMPLE      2
+#define CV_CHAIN_APPROX_TC89_L1     3
+#define CV_CHAIN_APPROX_TC89_KCOS   4
+#define CV_LINK_RUNS                5
 
-typedef struct CvSize2D32f
+/* Freeman chain reader state */
+typedef struct CvChainPtReader
 {
-    float width;
-    float height;
+    CV_SEQ_READER_FIELDS()
+    char      code;
+    CvPoint  pt;
+    char      deltas[8][2];
+    int       reserved[2];
 }
-CvSize2D32f;
-
-
-CV_INLINE  CvSize2D32f  cvSize2D32f( double width, double height );
-CV_INLINE  CvSize2D32f  cvSize2D32f( double width, double height )
-{
-    CvSize2D32f s;
+CvChainPtReader;
 
-    s.width = (float)width;
-    s.height = (float)height;
-
-    return s;
-}
+/* initializes 8-element array for fast access to 3x3 neighborhood of a pixel */
+#define  CV_INIT_3X3_DELTAS( deltas, step, nch )            \
+    ((deltas)[0] =  (nch),  (deltas)[1] = -(step) + (nch),  \
+     (deltas)[2] = -(step), (deltas)[3] = -(step) - (nch),  \
+     (deltas)[4] = -(nch),  (deltas)[5] =  (step) - (nch),  \
+     (deltas)[6] =  (step), (deltas)[7] =  (step) + (nch))
 
-typedef struct CvBox2D
+/* Contour tree header */
+typedef struct CvContourTree
 {
-    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 radians */
+    CV_SEQUENCE_FIELDS()
+    CvPoint p1;            /* the first point of the binary tree root segment */
+    CvPoint p2;            /* the last point of the binary tree root segment */
 }
-CvBox2D;
+CvContourTree;
 
-/************************************* CvSlice ******************************************/
-
-typedef struct CvSlice
+/* Finds a sequence of convexity defects of given contour */
+typedef struct CvConvexityDefect
 {
-    int  startIndex, endIndex;
-} CvSlice;
-
-CV_INLINE  CvSlice  cvSlice( int start, int end );
-CV_INLINE  CvSlice  cvSlice( int start, int end )
-{
-    CvSlice slice;
-    slice.startIndex = start;
-    slice.endIndex = end;
-
-    return slice;
+    CvPoint* start; /* point of the contour where the defect begins */
+    CvPoint* end; /* point of the contour where the defect ends */
+    CvPoint* depth_point; /* the farthest from the convex hull point within the defect */
+    float depth; /* distance between the farthest point and the convex hull */
 }
+CvConvexityDefect;
 
-#define CV_WHOLE_SEQ  cvSlice(0, 0x3fffffff)
+/************ Data structures and related enumerations for Planar Subdivisions ************/
 
+typedef size_t CvSubdiv2DEdge;
 
-/************************************* CvScalar *****************************************/
+#define CV_QUADEDGE2D_FIELDS()     \
+    int flags;                     \
+    struct CvSubdiv2DPoint* pt[4]; \
+    CvSubdiv2DEdge  next[4];
 
-typedef struct CvScalar
-{
-    double val[4];
-}
-CvScalar;
+#define CV_SUBDIV2D_POINT_FIELDS()\
+    int            flags;      \
+    CvSubdiv2DEdge first;      \
+    CvPoint2D32f   pt;
 
+#define CV_SUBDIV2D_VIRTUAL_POINT_FLAG (1 << 30)
 
-CV_INLINE  CvScalar  cvScalar( double a, double b CV_DEFAULT(0),
-                               double c CV_DEFAULT(0), double d CV_DEFAULT(0));
-CV_INLINE  CvScalar  cvScalar( double a, double b, double c, double d )
+typedef struct CvQuadEdge2D
 {
-    CvScalar scalar;
-    scalar.val[0] = a; scalar.val[1] = b;
-    scalar.val[2] = c; scalar.val[3] = d;
-    return scalar;
+    CV_QUADEDGE2D_FIELDS()
 }
+CvQuadEdge2D;
 
-
-CV_INLINE  CvScalar  cvRealScalar( double a );
-CV_INLINE  CvScalar  cvRealScalar( double a )
+typedef struct CvSubdiv2DPoint
 {
-    CvScalar scalar;
-    scalar.val[0] = a;
-    scalar.val[1] = scalar.val[2] = scalar.val[3] = 0;
-    return scalar;
+    CV_SUBDIV2D_POINT_FIELDS()
 }
+CvSubdiv2DPoint;
 
-CV_INLINE  CvScalar  cvScalarAll( double a );
-CV_INLINE  CvScalar  cvScalarAll( double a )
+#define CV_SUBDIV2D_FIELDS()    \
+    CV_GRAPH_FIELDS()           \
+    int  quad_edges;            \
+    int  is_geometry_valid;     \
+    CvSubdiv2DEdge recent_edge; \
+    CvPoint2D32f  topleft;      \
+    CvPoint2D32f  bottomright;
+    
+typedef struct CvSubdiv2D
 {
-    CvScalar scalar;
-    scalar.val[0] = scalar.val[1] = scalar.val[2] = scalar.val[3] = a;
-    return scalar;
+    CV_SUBDIV2D_FIELDS()
 }
+CvSubdiv2D;
 
 
-/**************************** Connected Component  **************************************/
-
-struct CvSeq;
-
-typedef struct CvConnectedComp
+typedef enum CvSubdiv2DPointLocation
 {
-    double area;  /* area of the connected component  */
-    double value; /* average brightness of the connected component
-                     (or packed RGB color) */
-    CvRect rect;  /* ROI of the component  */
-    struct CvSeq* contour; /* optional component boundary
-                     (the contour might have child contours corresponding to the holes)*/
+    CV_PTLOC_ERROR = -2,
+    CV_PTLOC_OUTSIDE_RECT = -1,
+    CV_PTLOC_INSIDE = 0,
+    CV_PTLOC_VERTEX = 1,
+    CV_PTLOC_ON_EDGE = 2
 }
-CvConnectedComp;
-
-
-/*************** Utility definitions, macros and inline functions ***********************/
-
-#define CV_PI   3.1415926535897932384626433832795
-
-#define CV_SWAP(a,b,t) ((t) = (a), (a) = (b), (b) = (t))
-
-#ifndef MIN
-#define MIN(a,b)  ((a) > (b) ? (b) : (a))
-#endif
+CvSubdiv2DPointLocation;
 
-#ifndef MAX
-#define MAX(a,b)  ((a) < (b) ? (b) : (a))
-#endif
-
-/* min & max without jumps */
-#define  CV_IMIN(a, b)  ((a) ^ (((a)^(b)) & (((a) < (b)) - 1)))
-
-#define  CV_IMAX(a, b)  ((a) ^ (((a)^(b)) & (((a) > (b)) - 1)))
-
-/* absolute value without jumps */
-#define  CV_IABS(a)     (((a) ^ ((a) < 0 ? -1 : 0)) - ((a) < 0 ? -1 : 0))
-#define  CV_SIGN(a)     (((a) < 0 ? -1 : 0) | ((a) > 0))
-
-/* initializes 8-element array for fast access to 3x3 neighborhood of a pixel */
-#define  CV_INIT_3X3_DELTAS( deltas, step, nch )            \
-    ((deltas)[0] =  (nch),  (deltas)[1] = -(step) + (nch),  \
-     (deltas)[2] = -(step), (deltas)[3] = -(step) - (nch),  \
-     (deltas)[4] = -(nch),  (deltas)[5] =  (step) - (nch),  \
-     (deltas)[6] =  (step), (deltas)[7] =  (step) + (nch))
-
-/* ************************************************************************** *\
-   Fast square root and inverse square root by
-   Bruce W. Holloway, Jeremy M., James Van Buskirk, Vesa Karvonen and others.
-   Taken from Paul Hsieh's site http://www.azillionmonkeys.com/qed/sqroot.html.
-\* ************************************************************************** */
-#define CV_SQRT_MAGIC  0xbe6f0000
-
-CV_INLINE  float  cvInvSqrt( float arg );
-CV_INLINE  float  cvInvSqrt( float arg )
+typedef enum CvNextEdgeType
 {
-    float x, y;
-    unsigned iarg = *((unsigned*)&arg);
-    *((unsigned*)&x) = (CV_SQRT_MAGIC - iarg)>>1;
-
-    y = arg*0.5f;
-    x*= 1.5f - y*x*x;
-    x*= 1.5f - y*x*x;
-
-    return x;
+    CV_NEXT_AROUND_ORG   = 0x00,
+    CV_NEXT_AROUND_DST   = 0x22,
+    CV_PREV_AROUND_ORG   = 0x11,
+    CV_PREV_AROUND_DST   = 0x33,
+    CV_NEXT_AROUND_LEFT  = 0x13,
+    CV_NEXT_AROUND_RIGHT = 0x31,
+    CV_PREV_AROUND_LEFT  = 0x20,
+    CV_PREV_AROUND_RIGHT = 0x02
 }
+CvNextEdgeType;
 
-
-CV_INLINE  float  cvSqrt( float arg );
-CV_INLINE  float  cvSqrt( float arg )
-{
-    float x, y;
-    unsigned iarg = *((unsigned*)&arg);
-    *((unsigned*)&x) = (CV_SQRT_MAGIC - iarg)>>1;
-
-    y = arg*0.5f;
-    x*= 1.5f - y*x*x;
-    x*= 1.5f - y*x*x;
-
-    return x*arg;
-}
+/* get the next edge with the same origin point (counterwise) */
+#define  CV_SUBDIV2D_NEXT_EDGE( edge )  (((CvQuadEdge2D*)((edge) & ~3))->next[(edge)&3])
 
 
 /* Defines for Distance Transform */
-typedef enum CvDisType
-{
-    CV_DIST_USER         = -1, /* User defined distance */
-    CV_DIST_L1           = 1, /* distance = |x1-x2| + |y1-y2| */
-    CV_DIST_L2           = 2, /* the simple euclidean distance */
-    CV_DIST_C            = 3, /* distance = max(|x1-x2|,|y1-y2|) */
-    CV_DIST_L12          = 4, /* L1-L2 metric: distance = 2(sqrt(1+x*x/2) - 1)) */
-    CV_DIST_FAIR         = 5, /* distance = c^2(|x|/c-log(1+|x|/c)), c = 1.3998 */
-    CV_DIST_WELSCH       = 6, /* distance = c^2/2(1-exp(-(x/c)^2)), c = 2.9846 */
-    CV_DIST_HUBER        = 7  /* distance = |x|<c ? x^2/2 : c(|x|-c/2), c=1.345 */
-}
-CvDisType;
+#define CV_DIST_USER    -1  /* User defined distance */
+#define CV_DIST_L1      1   /* distance = |x1-x2| + |y1-y2| */
+#define CV_DIST_L2      2   /* the simple euclidean distance */
+#define CV_DIST_C       3   /* distance = max(|x1-x2|,|y1-y2|) */
+#define CV_DIST_L12     4   /* L1-L2 metric: distance = 2(sqrt(1+x*x/2) - 1)) */
+#define CV_DIST_FAIR    5   /* distance = c^2(|x|/c-log(1+|x|/c)), c = 1.3998 */
+#define CV_DIST_WELSCH  6   /* distance = c^2/2(1-exp(-(x/c)^2)), c = 2.9846 */
+#define CV_DIST_HUBER   7   /* distance = |x|<c ? x^2/2 : c(|x|-c/2), c=1.345 */
 
 
 /* Filters used in pyramid decomposition */
@@ -987,540 +231,164 @@ typedef enum CvFilter
 CvFilter;
 
 /****************************************************************************************/
-/*                                   Data structures                                    */
+/*                                    Older definitions                                 */
 /****************************************************************************************/
 
-/******************************** Memory storage ****************************************/
-
-typedef struct CvMemBlock
-{
-    struct CvMemBlock*  prev;
-    struct CvMemBlock*  next;
-}
-CvMemBlock;
-
-#define CV_STORAGE_MAGIC_VAL    0x42890000
-
-typedef struct CvMemStorage
-{
-    int     signature;
-    CvMemBlock* bottom;/* first allocated block */
-    CvMemBlock* top;   /* current memory block - top of the stack */
-    struct  CvMemStorage* parent; /* borrows new blocks from */
-    int     block_size;  /* block size */
-    int     free_space;  /* free space in the current block */
-}
-CvMemStorage;
-
-#define CV_IS_STORAGE(storage)  \
-    ((storage) != NULL &&       \
-    (((CvMemStorage*)(storage))->signature & CV_MAGIC_MASK) == CV_STORAGE_MAGIC_VAL)
-
-
-typedef struct CvMemStoragePos
-{
-    CvMemBlock* top;
-    int  free_space;
-}
-CvMemStoragePos;
-
-
-/*********************************** Sequence *******************************************/
+typedef float*   CvVect32f;
+typedef float*   CvMatr32f;
+typedef double*  CvVect64d;
+typedef double*  CvMatr64d;
 
-typedef struct CvSeqBlock
+typedef struct CvMatrix3
 {
-    struct CvSeqBlock*  prev; /* previous sequence block */
-    struct 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 */
-    char*  data;              /* pointer to the first element of the block */
+    float m[3][3];
 }
-CvSeqBlock;
-
-
-#define CV_TREE_NODE_FIELDS(node_type)                          \
-    int       flags;         /* micsellaneous flags */          \
-    int       header_size;   /* size of sequence header */      \
-    struct    node_type* h_prev; /* previous sequence */        \
-    struct    node_type* h_next; /* next sequence */            \
-    struct    node_type* v_prev; /* 2nd previous sequence */    \
-    struct    node_type* v_next; /* 2nd next sequence */
-
-/*
-   Read/Write sequence.
-   Elements can be dynamically inserted to or deleted from the sequence.
-*/
-#define CV_SEQUENCE_FIELDS()                                            \
-    CV_TREE_NODE_FIELDS(CvSeq)                                          \
-    int       total;          /* total number of elements */            \
-    int       elem_size;      /* size of sequence element in bytes */   \
-    char*     block_max;      /* maximal bound of the last block */     \
-    char*     ptr;            /* current write pointer */               \
-    int       delta_elems;    /* how many elements allocated when the seq grows */  \
-    CvMemStorage* storage;    /* where the seq is stored */             \
-    CvSeqBlock* free_blocks;  /* free blocks list */                    \
-    CvSeqBlock* first; /* pointer to the first sequence block */
-
+CvMatrix3;
 
-typedef struct CvSeq
-{
-    CV_SEQUENCE_FIELDS()
-}
-CvSeq;
 
+#ifdef __cplusplus
+extern "C" {
+#endif
 
-/*************************************** Set ********************************************/
-/*
-  Set.
-  Order isn't keeped. There can be gaps between sequence elements.
-  After the element has been inserted it stays on the same place all the time.
-  The MSB(most-significant or sign bit) of the first field is 0 iff the element exists.
-*/
-#define CV_SET_ELEM_FIELDS(elem_type)   \
-    int  flags;                         \
-    struct elem_type* next_free;
+typedef float (CV_CDECL * CvDistanceFunction)( const float* a, const float* b, void* user_param );
 
-typedef struct CvSetElem
-{
-    CV_SET_ELEM_FIELDS(CvSetElem)
+#ifdef __cplusplus
 }
-CvSetElem;
-
-#define CV_SET_FIELDS()      \
-    CV_SEQUENCE_FIELDS()     \
-    CvSetElem* free_elems;
+#endif
 
-typedef struct CvSet
+typedef struct CvConDensation
 {
-    CV_SET_FIELDS()
+    int MP;
+    int DP;
+    float* DynamMatr;       /* Matrix of the linear Dynamics system  */
+    float* State;           /* Vector of State                       */
+    int SamplesNum;         /* Number of the Samples                 */
+    float** flSamples;      /* arr of the Sample Vectors             */
+    float** flNewSamples;   /* temporary array of the Sample Vectors */
+    float* flConfidence;    /* Confidence for each Sample            */
+    float* flCumulative;    /* Cumulative confidence                 */
+    float* Temp;            /* Temporary vector                      */
+    float* RandomSample;    /* RandomVector to update sample set     */
+    struct CvRandState* RandS; /* Array of structures to generate random vectors */
 }
-CvSet;
-
-
-#define CV_SET_ELEM_IDX_MASK   ((1 << 24) - 1)
-#define CV_SET_ELEM_FREE_FLAG  (1 << (sizeof(int)*8-1))
-
-/* Checks whether the element pointed by ptr belongs to a set or not */
-#define CV_IS_SET_ELEM( ptr )  (((CvSetElem*)(ptr))->flags >= 0)
-
-/************************************* Graph ********************************************/
+CvConDensation;
 
 /*
-  Graph is represented 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 single-linked list of incoming/outcoming edges for each vertex.
+standard Kalman filter (in G. Welch' and G. Bishop's notation):
 
-  Each edge consists of:
-    two pointers to the starting and the ending vertices (vtx[0] and vtx[1],
-    respectively). Graph may be oriented or not. In the second case, edges between
-    vertex i to vertex j are not distingueshed (during the search operations).
-
-    two pointers to next edges for the starting and the ending vertices.
-    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.
+  x(k)=A*x(k-1)+B*u(k)+w(k)  p(w)~N(0,Q)
+  z(k)=H*x(k)+v(k),   p(v)~N(0,R)
 */
-#define CV_GRAPH_EDGE_FIELDS()      \
-    int flags;                      \
-    float weight;                   \
-    struct CvGraphEdge* next[2];    \
-    struct CvGraphVtx* vtx[2];
-    
-
-#define CV_GRAPH_VERTEX_FIELDS()    \
-    int flags;                      \
-    struct CvGraphEdge* first;
-    
-
-typedef struct CvGraphEdge
-{
-    CV_GRAPH_EDGE_FIELDS()
-}
-CvGraphEdge;
-
-typedef struct CvGraphVtx
-{
-    CV_GRAPH_VERTEX_FIELDS()
-}
-CvGraphVtx;
+typedef struct CvKalman
+{
+    int MP;                     /* number of measurement vector dimensions */
+    int DP;                     /* number of state vector dimensions */
+    int CP;                     /* number of control vector dimensions */
+
+    /* backward compatibility fields */
+#if 1
+    float* PosterState;         /* =state_pre->data.fl */
+    float* PriorState;          /* =state_post->data.fl */
+    float* DynamMatr;           /* =transition_matrix->data.fl */
+    float* MeasurementMatr;     /* =measurement_matrix->data.fl */
+    float* MNCovariance;        /* =measurement_noise_cov->data.fl */
+    float* PNCovariance;        /* =process_noise_cov->data.fl */
+    float* KalmGainMatr;        /* =gain->data.fl */
+    float* PriorErrorCovariance;/* =error_cov_pre->data.fl */
+    float* PosterErrorCovariance;/* =error_cov_post->data.fl */
+    float* Temp1;               /* temp1->data.fl */
+    float* Temp2;               /* temp2->data.fl */
+#endif
 
-typedef struct CvGraphVtx2D
-{
-    CV_GRAPH_VERTEX_FIELDS()
-    CvPoint2D32f* ptr;
+    CvMat* state_pre;           /* predicted state (x'(k)):
+                                    x(k)=A*x(k-1)+B*u(k) */
+    CvMat* state_post;          /* corrected state (x(k)):
+                                    x(k)=x'(k)+K(k)*(z(k)-H*x'(k)) */
+    CvMat* transition_matrix;   /* state transition matrix (A) */
+    CvMat* control_matrix;      /* control matrix (B)
+                                   (it is not used if there is no control)*/
+    CvMat* measurement_matrix;  /* measurement matrix (H) */
+    CvMat* process_noise_cov;   /* process noise covariance matrix (Q) */
+    CvMat* measurement_noise_cov; /* measurement noise covariance matrix (R) */
+    CvMat* error_cov_pre;       /* priori error estimate covariance matrix (P'(k)):
+                                    P'(k)=A*P(k-1)*At + Q)*/
+    CvMat* gain;                /* Kalman gain matrix (K(k)):
+                                    K(k)=P'(k)*Ht*inv(H*P'(k)*Ht+R)*/
+    CvMat* error_cov_post;      /* posteriori error estimate covariance matrix (P(k)):
+                                    P(k)=(I-K(k)*H)*P'(k) */
+    CvMat* temp1;               /* temporary matrices */
+    CvMat* temp2;
+    CvMat* temp3;
+    CvMat* temp4;
+    CvMat* temp5;
+}
+CvKalman;
+
+
+/*********************** Haar-like Object Detection structures **************************/
+#define CV_HAAR_MAGIC_VAL    0x42500000
+#define CV_TYPE_NAME_HAAR    "opencv-haar-classifier"
+
+#define CV_IS_HAAR_CLASSIFIER( haar )                                                    \
+    ((haar) != NULL &&                                                                   \
+    (((const CvHaarClassifierCascade*)(haar))->flags & CV_MAGIC_MASK)==CV_HAAR_MAGIC_VAL)
+
+#define CV_HAAR_FEATURE_MAX  3
+
+typedef struct CvHaarFeature
+{
+    int  tilted;
+    struct
+    {
+        CvRect r;
+        float weight;
+    } rect[CV_HAAR_FEATURE_MAX];
 }
-CvGraphVtx2D;
+CvHaarFeature;
 
-/*
-   Graph is "derived" from the set (this is set a of vertices)
-   and includes another set (edges)
-*/
-#define  CV_GRAPH_FIELDS()   \
-    CV_SET_FIELDS()          \
-    CvSet* edges;
-
-typedef struct CvGraph
+typedef struct CvHaarClassifier
 {
-    CV_GRAPH_FIELDS()
+    int count;
+    CvHaarFeature* haar_feature;
+    float* threshold;
+    int* left;
+    int* right;
+    float* alpha;
 }
-CvGraph;
-
-/*********************************** Chain/Countour *************************************/
+CvHaarClassifier;
 
-typedef struct CvChain
+typedef struct CvHaarStageClassifier
 {
-    CV_SEQUENCE_FIELDS()
-    CvPoint  origin;
-}
-CvChain;
-
-#define CV_CONTOUR_FIELDS()  \
-    CV_SEQUENCE_FIELDS()     \
-    CvRect rect;             \
-    int color;               \
-    int reserved[3];
+    int  count;
+    float threshold;
+    CvHaarClassifier* classifier;
 
-typedef struct CvContour
-{
-    CV_CONTOUR_FIELDS()
+    int next;
+    int child;
+    int parent;
 }
-CvContour;
-
-typedef CvContour CvPoint2DSeq;
-
-/****************************************************************************************\
-*                                    Sequence types                                      *
-\****************************************************************************************/
-
-#define CV_SEQ_MAGIC_VAL             0x42990000
-#define CV_IS_SEQ(seq) \
-    ((seq) != NULL && (((CvSeq*)(seq))->flags & CV_MAGIC_MASK) == CV_SEQ_MAGIC_VAL)
-
-#define CV_SET_MAGIC_VAL             0x42980000
-#define CV_IS_SET(set) \
-    ((set) != NULL && (((CvSeq*)(set))->flags & CV_MAGIC_MASK) == CV_SET_MAGIC_VAL)
-
-#define CV_SEQ_ELTYPE_BITS           5
-#define CV_SEQ_ELTYPE_MASK           ((1 << CV_SEQ_ELTYPE_BITS) - 1)
-
-#define CV_SEQ_ELTYPE_POINT          CV_32SC2  /* (x,y) */
-#define CV_SEQ_ELTYPE_CODE           CV_8UC1   /* freeman code: 0..7 */
-#define CV_SEQ_ELTYPE_GENERIC        0
-#define CV_SEQ_ELTYPE_PTR            CV_USRTYPE1 
-#define CV_SEQ_ELTYPE_PPOINT         CV_SEQ_ELTYPE_PTR  /* &(x,y) */
-#define CV_SEQ_ELTYPE_INDEX          CV_32SC1  /* #(x,y) */
-#define CV_SEQ_ELTYPE_GRAPH_EDGE     0  /* &next_o, &next_d, &vtx_o, &vtx_d */
-#define CV_SEQ_ELTYPE_GRAPH_VERTEX   0  /* first_edge, &(x,y) */
-#define CV_SEQ_ELTYPE_TRIAN_ATR      0  /* vertex of the binary tree   */
-#define CV_SEQ_ELTYPE_CONNECTED_COMP 0  /* connected component  */
-#define CV_SEQ_ELTYPE_POINT3D        CV_32FC3  /* (x,y,z)  */
-
-#define CV_SEQ_KIND_BITS        5
-#define CV_SEQ_KIND_MASK        (((1 << CV_SEQ_KIND_BITS) - 1)<<CV_SEQ_ELTYPE_BITS)
-
-/* types of sequences */
-#define CV_SEQ_KIND_GENERIC     (0 << CV_SEQ_ELTYPE_BITS)
-#define CV_SEQ_KIND_CURVE       (1 << CV_SEQ_ELTYPE_BITS)
-#define CV_SEQ_KIND_BIN_TREE    (2 << CV_SEQ_ELTYPE_BITS)
-
-/* types of sparse sequences (sets) */
-#define CV_SEQ_KIND_GRAPH       (3 << CV_SEQ_ELTYPE_BITS)
-#define CV_SEQ_KIND_SUBDIV2D    (4 << CV_SEQ_ELTYPE_BITS)
-
-#define CV_SEQ_FLAG_SHIFT       (CV_SEQ_KIND_BITS + CV_SEQ_ELTYPE_BITS)
-
-/* flags for curves */
-#define CV_SEQ_FLAG_CLOSED     (1 << CV_SEQ_FLAG_SHIFT)
-#define CV_SEQ_FLAG_SIMPLE     (2 << CV_SEQ_FLAG_SHIFT)
-#define CV_SEQ_FLAG_CONVEX     (4 << CV_SEQ_FLAG_SHIFT)
-#define CV_SEQ_FLAG_HOLE       (8 << CV_SEQ_FLAG_SHIFT)
+CvHaarStageClassifier;
 
-/* flags for graphs */
-#define CV_GRAPH_FLAG_ORIENTED (1 << CV_SEQ_FLAG_SHIFT)
+typedef struct CvHidHaarClassifierCascade CvHidHaarClassifierCascade;
 
-#define CV_GRAPH               CV_SEQ_KIND_GRAPH
-#define CV_ORIENTED_GRAPH      (CV_SEQ_KIND_GRAPH|CV_GRAPH_FLAG_ORIENTED)
-
-/* point sets */
-#define CV_SEQ_POINT_SET       (CV_SEQ_KIND_GENERIC| CV_SEQ_ELTYPE_POINT)
-#define CV_SEQ_POINT3D_SET     (CV_SEQ_KIND_GENERIC| CV_SEQ_ELTYPE_POINT3D)
-#define CV_SEQ_POLYLINE        (CV_SEQ_KIND_CURVE  | CV_SEQ_ELTYPE_POINT)
-#define CV_SEQ_POLYGON         (CV_SEQ_FLAG_CLOSED | CV_SEQ_POLYLINE )
-#define CV_SEQ_CONTOUR         CV_SEQ_POLYGON
-#define CV_SEQ_SIMPLE_POLYGON  (CV_SEQ_FLAG_SIMPLE | CV_SEQ_POLYGON  )
-
-/* chain-coded curves */
-#define CV_SEQ_CHAIN           (CV_SEQ_KIND_CURVE  | CV_SEQ_ELTYPE_CODE)
-#define CV_SEQ_CHAIN_CONTOUR   (CV_SEQ_FLAG_CLOSED | CV_SEQ_CHAIN)
-
-/* binary tree for the contour */
-#define CV_SEQ_POLYGON_TREE    (CV_SEQ_KIND_BIN_TREE  | CV_SEQ_ELTYPE_TRIAN_ATR)
-
-/* sequence of the connected components */
-#define CV_SEQ_CONNECTED_COMP  (CV_SEQ_KIND_GENERIC  | CV_SEQ_ELTYPE_CONNECTED_COMP)
-
-/* sequence of the integer numbers */
-#define CV_SEQ_INDEX           (CV_SEQ_KIND_GENERIC  | CV_SEQ_ELTYPE_INDEX)
-
-#define CV_SEQ_ELTYPE( seq )   ((seq)->flags & CV_SEQ_ELTYPE_MASK)
-#define CV_SEQ_KIND( seq )     ((seq)->flags & CV_SEQ_KIND_MASK )
-
-/* flag checking */
-#define CV_IS_SEQ_INDEX( seq )      ((CV_SEQ_ELTYPE(seq) == CV_SEQ_ELTYPE_INDEX) && \
-                                     (CV_SEQ_KIND(seq) == CV_SEQ_KIND_GENERIC))
-
-#define CV_IS_SEQ_CURVE( seq )      (CV_SEQ_KIND(seq) == CV_SEQ_KIND_CURVE)
-#define CV_IS_SEQ_CLOSED( seq )     (((seq)->flags & CV_SEQ_FLAG_CLOSED) != 0)
-#define CV_IS_SEQ_CONVEX( seq )     (((seq)->flags & CV_SEQ_FLAG_CONVEX) != 0)
-#define CV_IS_SEQ_HOLE( seq )       (((seq)->flags & CV_SEQ_FLAG_HOLE) != 0)
-#define CV_IS_SEQ_SIMPLE( seq )     (((seq)->flags & CV_SEQ_FLAG_SIMPLE) != 0) || \
-                                    CV_IS_SEQ_CONVEX(seq))
-
-/* type checking macros */
-#define CV_IS_SEQ_POINT_SET( seq ) \
-    ((CV_SEQ_ELTYPE(seq) == CV_32SC2 || CV_SEQ_ELTYPE(seq) == CV_32FC2))
-
-#define CV_IS_SEQ_POINT_SUBSET( seq ) \
-    (CV_IS_SEQ_INDEX( seq ) || CV_SEQ_ELTYPE(seq) == CV_SEQ_ELTYPE_PPOINT)
-
-#define CV_IS_SEQ_POLYLINE( seq )   \
-    (CV_SEQ_KIND(seq) == CV_SEQ_KIND_CURVE && CV_IS_SEQ_POINT_SET(seq))
-
-#define CV_IS_SEQ_POLYGON( seq )   \
-    (CV_IS_SEQ_POLYLINE(seq) && CV_IS_SEQ_CLOSED(seq))
-
-#define CV_IS_SEQ_CHAIN( seq )   \
-    (CV_SEQ_KIND(seq) == CV_SEQ_KIND_CURVE && (seq)->elem_size == 1)
-
-#define CV_IS_SEQ_CONTOUR( seq )   \
-    (CV_IS_SEQ_CLOSED(seq) && (CV_IS_SEQ_POLYLINE(seq) || CV_IS_SEQ_CHAIN(seq)))
-
-#define CV_IS_SEQ_CHAIN_CONTOUR( seq ) \
-    (CV_IS_SEQ_CHAIN( seq ) && CV_IS_SEQ_CLOSED( seq ))
-
-#define CV_IS_SEQ_POLYGON_TREE( seq ) \
-    (CV_SEQ_ELTYPE (seq) ==  CV_SEQ_ELTYPE_TRIAN_ATR &&    \
-    CV_SEQ_KIND( seq ) ==  CV_SEQ_KIND_BIN_TREE )
-
-#define CV_IS_GRAPH( seq )    \
-    (CV_IS_SET(seq) && CV_SEQ_KIND((CvSet*)(seq)) == CV_SEQ_KIND_GRAPH)
-
-#define CV_IS_GRAPH_ORIENTED( seq )   \
-    (((seq)->flags & CV_GRAPH_FLAG_ORIENTED) != 0)
-
-#define CV_IS_SUBDIV2D( seq )  \
-    (CV_IS_SET(seq) && CV_SEQ_KIND((CvSet*)(seq)) == CV_SEQ_KIND_SUBDIV2D)
-
-/****************************************************************************************/
-/*                            Sequence writer & reader                                  */
-/****************************************************************************************/
-
-#define CV_SEQ_WRITER_FIELDS()                                     \
-    int          header_size;                                      \
-    CvSeq*       seq;        /* the sequence written */            \
-    CvSeqBlock*  block;      /* current block */                   \
-    char*        ptr;        /* pointer to free space */           \
-    char*        block_min;  /* pointer to the beginning of block*/\
-    char*        block_max;  /* pointer to the end of block */
-
-typedef struct CvSeqWriter
+typedef struct CvHaarClassifierCascade
 {
-    CV_SEQ_WRITER_FIELDS()
-    int  reserved[4]; /* some reserved fields */
+    int  flags;
+    int  count;
+    CvSize orig_window_size;
+    CvSize real_window_size;
+    double scale;
+    CvHaarStageClassifier* stage_classifier;
+    CvHidHaarClassifierCascade* hid_cascade;
 }
-CvSeqWriter;
-
+CvHaarClassifierCascade;
 
-#define CV_SEQ_READER_FIELDS()                                      \
-    int          header_size;                                       \
-    CvSeq*       seq;        /* sequence, beign read */             \
-    CvSeqBlock*  block;      /* current block */                    \
-    char*        ptr;        /* pointer to element be read next */  \
-    char*        block_min;  /* pointer to the beginning of block */\
-    char*        block_max;  /* pointer to the end of block */      \
-    int          delta_index;/* = seq->first->start_index   */      \
-    char*        prev_elem;  /* pointer to previous element */
-
-
-typedef struct CvSeqReader
+typedef struct CvAvgComp
 {
-    CV_SEQ_READER_FIELDS()
-    int  reserved[4];
-}
-CvSeqReader;
-
-/****************************************************************************************/
-/*                                Operations on sequences                               */
-/****************************************************************************************/
-
-#define  CV_GET_SEQ_ELEM( elem_type, seq, index )                \
-/* assert gives some guarantee that <seq> parameter is valid */  \
-(   assert(sizeof((seq)->first[0]) == sizeof(CvSeqBlock) &&      \
-    (seq)->elem_size == sizeof(elem_type)),                      \
-    (elem_type*)((seq)->first && (unsigned)index <               \
-    (unsigned)((seq)->first->count) ?                            \
-    (seq)->first->data + (index) * sizeof(elem_type) :           \
-    cvGetSeqElem( (CvSeq*)(seq), (index), NULL )))
-
-
-/* macro that adds element to sequence */
-#define CV_WRITE_SEQ_ELEM_VAR( elem_ptr, writer )     \
-{                                                     \
-    if( (writer).ptr >= (writer).block_max )          \
-    {                                                 \
-        cvCreateSeqBlock( &writer);                   \
-    }                                                 \
-    memcpy((writer).ptr, elem_ptr, (writer).seq->elem_size);\
-    (writer).ptr += (writer).seq->elem_size;          \
-}
-
-#define CV_WRITE_SEQ_ELEM( elem, 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, (*((CvSeqReader*)&(reader)))); \
-        assert( ((reader).code & ~7) == 0 );                            \
-        (reader).pt.x += (reader).deltas[(reader).code][0];             \
-        (reader).pt.y += (reader).deltas[(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 ************/
-
-/* returns 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)])
-
-/****************************************************************************************/
-
-/**** For error processing and debugging purposes ******/ 
-typedef struct
-{
-    const char* file;
-    int         line;
-}
-CvStackRecord;                               
-
-
-/****************************************************************************************/
-/*                                    Older definitions                                 */
-/****************************************************************************************/
-
-typedef float*   CvVect32f;
-typedef float*   CvMatr32f;
-typedef double*  CvVect64d;
-typedef double*  CvMatr64d;
-
-typedef struct CvMatrix3
-{
-    float m[3][3];
-}
-CvMatrix3;
-
-typedef enum CvStatus
-{         
-    CV_INPLACE_NOT_SUPPORTED_ERR= -112,
-    CV_UNMATCHED_ROI_ERR        = -111,
-    CV_NOTFOUND_ERR             = -110,
-    CV_BADCONVERGENCE_ERR       = -109,
-
-    CV_BADDEPTH_ERR             = -107,
-    CV_BADROI_ERR               = -106,
-    CV_BADHEADER_ERR            = -105,
-    CV_UNMATCHED_FORMATS_ERR    = -104,
-    CV_UNSUPPORTED_COI_ERR      = -103,
-    CV_UNSUPPORTED_CHANNELS_ERR = -102,
-    CV_UNSUPPORTED_DEPTH_ERR    = -101,
-    CV_UNSUPPORTED_FORMAT_ERR   = -100,
-
-                       
-    CV_BADARG_ERR      = -49,  //ipp comp
-    CV_NOTDEFINED_ERR  = -48,  //ipp comp
-
-    CV_BADCHANNELS_ERR = -47,  //ipp comp
-    CV_BADRANGE_ERR    = -44,  //ipp comp
-    CV_BADSTEP_ERR     = -29,  //ipp comp
-
-    CV_BADFLAG_ERR     =  -12,
-    CV_DIV_BY_ZERO_ERR =  -11, //ipp comp
-    CV_BADCOEF_ERR     =  -10,
-
-    CV_BADFACTOR_ERR   =  -7,
-    CV_BADPOINT_ERR    =  -6,
-    CV_BADSCALE_ERR    =  -4,
-    CV_OUTOFMEM_ERR    =  -3,
-    CV_NULLPTR_ERR     =  -2,
-    CV_BADSIZE_ERR     =  -1,
-    CV_NO_ERR          =   0,
-    CV_OK              =   CV_NO_ERR
+    CvRect rect;
+    int neighbors;
 }
-CvStatus;
+CvAvgComp;
 
 #endif /*_CVTYPES_H_*/
 
index f345829b77e7b115b5d2a7a8dc9b93196f0f32f0..7ed4c840ada5d02b91df087b0bb425f9bc581014 100644 (file)
@@ -1,63 +1,28 @@
-lib_LTLIBRARIES = libopencv.la
+lib_LTLIBRARIES = libcv.la
+
+libcv_la_SOURCES = cvaccum.cpp cvadapthresh.cpp cvapprox.cpp \
+    cvcalccontrasthistogram.cpp cvcalcimagehomography.cpp \
+    cvcalibinit.cpp cvcalibration.cpp cvcamshift.cpp cvcanny.cpp \
+    cvcolor.cpp cvcondens.cpp cvcontours.cpp cvcontourtree.cpp \
+    cvconvhull.cpp cvconvolve.cpp cvcorner.cpp cvcornersubpix.cpp \
+    cvderiv.cpp cvdistransform.cpp cvdominants.cpp cvemd.cpp \
+    cvfeatureselect.cpp cvfloodfill.cpp cvfundam.cpp cvgeometry.cpp \
+    cvhaar.cpp cvhistogram.cpp cvhough.cpp cvimgwarp.cpp cvkalman.cpp \
+    cvlinefit.cpp cvlkpyramid.cpp cvmatchcontours.cpp cvmineval.cpp \
+    cvmoments.cpp cvmorph.cpp cvmotempl.cpp cvoptflowbm.cpp \
+    cvoptflowhs.cpp cvoptflowlk.cpp cvpgh.cpp cvposit.cpp cvprecomp.cpp \
+    cvprecorner.cpp cvpyramids.cpp cvpyrsegmentation.cpp \
+    cvrotcalipers.cpp cvsamplers.cpp cvshapedescr.cpp cvsmooth.cpp \
+    cvsnakes.cpp cvsubdivision2d.cpp cvsumpixels.cpp cvswitcher.cpp \
+    cvtables.cpp cvtemplmatch.cpp cvthresh.cpp cvundistort.cpp \
+    cvutils.cpp
 
-libopencv_la_SOURCES = \
-camshift.cpp                 cveigendecomposite.cpp  cvmorphing.cpp        \
-cvabsdiff.cpp                cveigenobjectswrap.cpp  cvmotempl.cpp         \
-cvaccum.cpp                  cveigenprojection.cpp   cvnorm.cpp            \
-cvadapthresh.cpp             cvellipsefit.cpp        cvoptflowbm.cpp       \
-cvaffine.cpp                 cvemd.cpp               cvoptflowhs.cpp       \
-cvalloc.cpp                  cverror.cpp             cvoptflowlk.cpp       \
-cvapprox.cpp                 cvfeatureselect.cpp     cvouttext.cpp         \
-cvarithm.cpp                 cvfindhandregion.cpp    cvpersistence.cpp     \
-cvarray.cpp                  cvfloodfill.cpp         cvpgh.cpp             \
-cvcalccontrasthistogram.cpp  cvfundam.cpp            cvposit.cpp           \
-cvcalccovarmatrix.cpp        cvgeometry.cpp          cvprecomp.cpp         \
-cvcalceigenobjects.cpp       cvhistogram.cpp         cvprecorner.cpp       \
-cvcalcimagehomography.cpp    cvhmm.cpp               cvprewarp.cpp         \
-cvcalibinit.cpp              cvhmmobs.cpp            cvprint.cpp           \
-cvcalibration.cpp            cvhmmwrap.cpp           cvproject.cpp         \
-cvcamshift.cpp               cvhough.cpp             cvpyramids.cpp        \
-cvcanny.cpp                  cvimage.cpp             cvpyrsegmentation.cpp \
-cvcmp.cpp                    cvjacobieigens.cpp      cvrand.cpp            \
-cvcolor.cpp                  cvkalman.cpp            cvrotcalipers.cpp     \
-cvcondens.cpp                cvlinefit.cpp           cvsamplers.cpp        \
-cvcontours.cpp               cvlines.cpp             cvscanlines.cpp       \
-cvcontourtree.cpp            cvlkpyramid.cpp         cvshapedescr.cpp      \
-cvconvert.cpp                cvlmeds.cpp             cvsmooth.cpp          \
-cvconvhull.cpp               cvlogic.cpp             cvsnakes.cpp          \
-cvcopy.cpp                   cvmatchcontours.cpp     cvsubdivision2d.cpp   \
-cvcorner.cpp                 cvmathfuncs.cpp         cvsumpixels.cpp       \
-cvcornersubpix.cpp           cvmatmul.cpp            cvsvd.cpp             \
-cvcorrespond.cpp             cvmatrix64d.cpp         cvswitcher.cpp        \
-cvcreatehandmask.cpp         cvmatrix.cpp            cvtables.cpp          \
-cvdatastructs.cpp            cvmean.cpp              cvtemplmatch.cpp      \
-cvderiv.cpp                  cvmeansdv.cpp           cvthresh.cpp          \
-cvdetectwr.cpp               cvmineval.cpp           cvundistort.cpp       \
-cvdistransform.cpp           cvminmaxloc.cpp         cvutils.cpp           \
-cvdominants.cpp              cvmoments.cpp                                 \
-cvdrawing.cpp                cvmorph.cpp
 
-SOMAJOR = @MMAJOR@
-SOMINOR = @MMINOR@
-SOSUBMINOR = @MSUBMINOR@
-
-# here you should add all header files, which contains the functionality
-# of your shared lib (published for the users)
 include_HEADERS =
+noinst_HEADERS = _cv.h _cvgeom.h _cvimgproc.h _cvipp.h _cvlist.h _cvmatrix.h
+EXTRA_DIST = cv.dsp cv.vcproj cv.rc resource.h
 
-# here you should add all header files, which shouldn't be installed
-noinst_HEADERS =  \
-_cvarr.h          _cvfuncn.h  _cvlist.h     _cvtables.h  _ipcv.h                  \
-_cvdatastructs.h  _cvgeom.h   _cvmatrix.h   _cvutils.h   _optcv.h                 \
-_cverror.h        _cv.h       _cvoptions.h  _cvvm.h
-
-EXTRA_DIST = cv.rc resource.h
-
-#libopencv_la_LDFLAGS = $(all_libraries) -no-undefined -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) -release $(LT_RELEASE) @LDFLAGS@
-libopencv_la_LDFLAGS = -no-undefined -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) -release $(LT_RELEASE)
-
+libcv_la_LDFLAGS = -no-undefined -version-info @LT_VERSION@ @LDFLAGS@
 LIBS = -ldl -lpthread -lm
 
-INCLUDES = -I. -I../include -I../..
-CXXFLAGS = @CXXFLAGS@ -Wall
-
+INCLUDES = -I. -I../include -I../../cxcore/include -I../..
diff --git a/opencv/src/cv/Makefile.in b/opencv/src/cv/Makefile.in
deleted file mode 100644 (file)
index f8ae7c2..0000000
+++ /dev/null
@@ -1,1130 +0,0 @@
-# Makefile.in generated automatically by automake 1.4-p5 from Makefile.am
-
-# Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc.
-# This Makefile.in is free software; the Free Software Foundation
-# gives unlimited permission to copy and/or distribute it,
-# with or without modifications, as long as this notice is preserved.
-
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
-# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
-# PARTICULAR PURPOSE.
-
-
-SHELL = @SHELL@
-
-srcdir = @srcdir@
-top_srcdir = @top_srcdir@
-VPATH = @srcdir@
-prefix = @prefix@
-exec_prefix = @exec_prefix@
-
-bindir = @bindir@
-sbindir = @sbindir@
-libexecdir = @libexecdir@
-datadir = @datadir@
-sysconfdir = @sysconfdir@
-sharedstatedir = @sharedstatedir@
-localstatedir = @localstatedir@
-libdir = @libdir@
-infodir = @infodir@
-mandir = @mandir@
-includedir = @includedir@
-oldincludedir = /usr/include
-
-DESTDIR =
-
-pkgdatadir = $(datadir)/@PACKAGE@
-pkglibdir = $(libdir)/@PACKAGE@
-pkgincludedir = $(includedir)/@PACKAGE@
-
-top_builddir = ../..
-
-ACLOCAL = @ACLOCAL@
-AUTOCONF = @AUTOCONF@
-AUTOMAKE = @AUTOMAKE@
-AUTOHEADER = @AUTOHEADER@
-
-INSTALL = @INSTALL@
-INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS)
-INSTALL_DATA = @INSTALL_DATA@
-INSTALL_SCRIPT = @INSTALL_SCRIPT@
-transform = @program_transform_name@
-
-NORMAL_INSTALL = :
-PRE_INSTALL = :
-POST_INSTALL = :
-NORMAL_UNINSTALL = :
-PRE_UNINSTALL = :
-POST_UNINSTALL = :
-host_alias = @host_alias@
-host_triplet = @host@
-ADDONS = @ADDONS@
-AS = @AS@
-CC = @CC@
-CXX = @CXX@
-DEBUG = @DEBUG@
-DLLTOOL = @DLLTOOL@
-ECHO = @ECHO@
-EXEEXT = @EXEEXT@
-IPL_INCLUDE = @IPL_INCLUDE@
-IPL_LIB = @IPL_LIB@
-LIBTOOL = @LIBTOOL@
-LN_S = @LN_S@
-MAKEINFO = @MAKEINFO@
-MMAJOR = @MMAJOR@
-MMINOR = @MMINOR@
-MSUBMINOR = @MSUBMINOR@
-OBJDUMP = @OBJDUMP@
-OBJEXT = @OBJEXT@
-PACKAGE = @PACKAGE@
-RANLIB = @RANLIB@
-STRIP = @STRIP@
-TCLTKLIB = @TCLTKLIB@
-TESTDIR = @TESTDIR@
-VERSION = @VERSION@
-with_apps = @with_apps@
-with_tests = @with_tests@
-
-lib_LTLIBRARIES = libopencv.la
-
-libopencv_la_SOURCES = camshift.cpp cvabsdiff.cpp cvaccum.cpp cvadapthresh.cpp cvaffine.cpp cvalloc.cpp cvapprox.cpp cvarithm.cpp cvarray.cpp cvblur.cpp cvcalccontrasthistogram.cpp cvcalccovarmatrix.cpp cvcalccovarmatrixex.cpp cvcalceigenobjects.cpp cvcalcimagehomography.cpp cvcalcprobdensity.cpp cvcalibinit.cpp cvcalibration.cpp cvcamshift.cpp cvcanny.cpp cvcolor.cpp cvcondens.cpp cvcontourarea.cpp cvcontours.cpp cvcontoursmoments.cpp cvcontourtree.cpp cvconvert.cpp cvconvgen.cpp cvconvhull.cpp cvcopy.cpp cvcorner.cpp cvcornersubpix.cpp cvcorrespond.cpp cvcreatehandmask.cpp cvdatastructs.cpp cvdetectwr.cpp cvdistransform.cpp cvdominants.cpp cvdrawing.cpp cveigendecomposite.cpp cveigenobjectswrap.cpp cveigenprojection.cpp cvellipsefit.cpp cvemd.cpp cverror.cpp cvfeatureselect.cpp cvfilterwr.cpp cvfindhandregion.cpp cvfindhandregiona.cpp cvfloodfill.cpp cvfundam.cpp cvgeometry.cpp cvgeometrywrap.cpp cvgesturerecognition.cpp cvhistogram.cpp cvhmm.cpp cvhmmobs.cpp cvhmmwrap.cpp cvhough.cpp cvhoughdiv.cpp cvhoughp.cpp cvhoughwrap.cpp cvimage.cpp cvinitconvol.cpp cvjacobieigens.cpp cvkalman.cpp cvlaplace.cpp cvlinefit.cpp cvlines.cpp cvlkpyramid.cpp cvlmeds.cpp cvlogic.cpp cvmatchcontours.cpp cvmathfuncs.cpp cvmatmul.cpp cvmatrix.cpp cvmatrix64d.cpp cvmaxrect.cpp cvmean.cpp cvmeansdv.cpp cvmineval.cpp cvminmaxloc.cpp cvmoments.cpp cvmorph.cpp cvmorphing.cpp cvmorphwrap.cpp cvmotempl.cpp cvmotseg.cpp cvnorm.cpp cvoptflowbm.cpp cvoptflowhs.cpp cvoptflowlk.cpp cvouttext.cpp cvpgh.cpp cvposit.cpp cvprecomp.cpp cvprecorner.cpp cvprewarp.cpp cvprint.cpp cvproject.cpp cvpyramids.cpp cvpyrsegmentation.cpp cvrand.cpp cvrotcalipers.cpp cvsamplers.cpp cvscanlines.cpp cvscharr.cpp cvshapedescr.cpp cvsnakes.cpp cvsubdivision2d.cpp cvsumpixels.cpp cvsvd.cpp cvswitcher.cpp cvtables.cpp cvtemplmatch.cpp cvthresh.cpp cvundistort.cpp cvutilitieswrap.cpp cvutils.cpp
-
-SOMAJOR = @MMAJOR@
-SOMINOR = @MMINOR@
-SOSUBMINOR = @MSUBMINOR@
-
-# here you should add all header files, which contains the functionality
-# of your shared lib (published for the users)
-include_HEADERS = 
-
-# here you should add all header files, which shouldn't be installed
-noinst_HEADERS = _cv.h _cvarr.h _cvdatastructs.h _cverror.h _cvfuncn.h _cvgeom.h _cvlist.h _cvmatrix.h _cvmorphology.h _cvoptions.h _cvtables.h _cvutils.h _cvvm.h _cvwrap.h _ipcv.h _optcv.h
-
-libopencv_la_LDFLAGS = $(all_libraries) -no-undefined -version-info $(SOMAJOR):$(SOMINOR):$(SOSUBMINOR) $(LDFLAGS)
-
-# add here the libraries which have to be include
-# for building the shared lib
-#
-#  please consider also the usage of the make environment variables
-#  like
-#  $(LIB_KDEUI), $(LIB_QT), $(LIB_HTML), etc.
-#  instead of the hardcoded entries, which have placed
-#  in here.
-#  The following line is only a suggestion!
-#
-libopencv_la_LIBADD = 
-
-LIBS =  -ldl -lpthread -lm
-
-INCLUDES =  -I../include -I../_include
-CFLAGS =  -Wall @DEBUG@
-CXXFLAGS =  -Wall @DEBUG@
-mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
-CONFIG_HEADER = ../../config.h
-CONFIG_CLEAN_FILES = 
-LTLIBRARIES =  $(lib_LTLIBRARIES)
-
-
-DEFS = @DEFS@ -I. -I$(srcdir) -I../..
-CPPFLAGS = @CPPFLAGS@
-LDFLAGS = @LDFLAGS@
-X_CFLAGS = @X_CFLAGS@
-X_LIBS = @X_LIBS@
-X_EXTRA_LIBS = @X_EXTRA_LIBS@
-X_PRE_LIBS = @X_PRE_LIBS@
-libopencv_la_DEPENDENCIES = 
-libopencv_la_OBJECTS =  camshift.lo cvabsdiff.lo cvaccum.lo \
-cvadapthresh.lo cvaffine.lo cvalloc.lo cvapprox.lo cvarithm.lo \
-cvarray.lo cvblur.lo cvcalccontrasthistogram.lo cvcalccovarmatrix.lo \
-cvcalccovarmatrixex.lo cvcalceigenobjects.lo cvcalcimagehomography.lo \
-cvcalcprobdensity.lo cvcalibinit.lo cvcalibration.lo cvcamshift.lo \
-cvcanny.lo cvcolor.lo cvcondens.lo cvcontourarea.lo cvcontours.lo \
-cvcontoursmoments.lo cvcontourtree.lo cvconvert.lo cvconvgen.lo \
-cvconvhull.lo cvcopy.lo cvcorner.lo cvcornersubpix.lo cvcorrespond.lo \
-cvcreatehandmask.lo cvdatastructs.lo cvdetectwr.lo cvdistransform.lo \
-cvdominants.lo cvdrawing.lo cveigendecomposite.lo cveigenobjectswrap.lo \
-cveigenprojection.lo cvellipsefit.lo cvemd.lo cverror.lo \
-cvfeatureselect.lo cvfilterwr.lo cvfindhandregion.lo \
-cvfindhandregiona.lo cvfloodfill.lo cvfundam.lo cvgeometry.lo \
-cvgeometrywrap.lo cvgesturerecognition.lo cvhistogram.lo cvhmm.lo \
-cvhmmobs.lo cvhmmwrap.lo cvhough.lo cvhoughdiv.lo cvhoughp.lo \
-cvhoughwrap.lo cvimage.lo cvinitconvol.lo cvjacobieigens.lo cvkalman.lo \
-cvlaplace.lo cvlinefit.lo cvlines.lo cvlkpyramid.lo cvlmeds.lo \
-cvlogic.lo cvmatchcontours.lo cvmathfuncs.lo cvmatmul.lo cvmatrix.lo \
-cvmatrix64d.lo cvmaxrect.lo cvmean.lo cvmeansdv.lo cvmineval.lo \
-cvminmaxloc.lo cvmoments.lo cvmorph.lo cvmorphing.lo cvmorphwrap.lo \
-cvmotempl.lo cvmotseg.lo cvnorm.lo cvoptflowbm.lo cvoptflowhs.lo \
-cvoptflowlk.lo cvouttext.lo cvpgh.lo cvposit.lo cvprecomp.lo \
-cvprecorner.lo cvprewarp.lo cvprint.lo cvproject.lo cvpyramids.lo \
-cvpyrsegmentation.lo cvrand.lo cvrotcalipers.lo cvsamplers.lo \
-cvscanlines.lo cvscharr.lo cvshapedescr.lo cvsnakes.lo \
-cvsubdivision2d.lo cvsumpixels.lo cvsvd.lo cvswitcher.lo cvtables.lo \
-cvtemplmatch.lo cvthresh.lo cvundistort.lo cvutilitieswrap.lo \
-cvutils.lo
-CXXCOMPILE = $(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
-LTCXXCOMPILE = $(LIBTOOL) --mode=compile $(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
-CXXLD = $(CXX)
-CXXLINK = $(LIBTOOL) --mode=link $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(LDFLAGS) -o $@
-HEADERS =  $(include_HEADERS) $(noinst_HEADERS)
-
-DIST_COMMON =  Makefile.am Makefile.in
-
-
-DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
-
-TAR = gtar
-GZIP_ENV = --best
-SOURCES = $(libopencv_la_SOURCES)
-OBJECTS = $(libopencv_la_OBJECTS)
-
-all: all-redirect
-.SUFFIXES:
-.SUFFIXES: .S .c .cpp .lo .o .obj .s
-$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) 
-       cd $(top_srcdir) && $(AUTOMAKE) --gnu --include-deps cv/src/Makefile
-
-Makefile: $(srcdir)/Makefile.in  $(top_builddir)/config.status
-       cd $(top_builddir) \
-         && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status
-
-
-mostlyclean-libLTLIBRARIES:
-
-clean-libLTLIBRARIES:
-       -test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES)
-
-distclean-libLTLIBRARIES:
-
-maintainer-clean-libLTLIBRARIES:
-
-install-libLTLIBRARIES: $(lib_LTLIBRARIES)
-       @$(NORMAL_INSTALL)
-       $(mkinstalldirs) $(DESTDIR)$(libdir)
-       @list='$(lib_LTLIBRARIES)'; for p in $$list; do \
-         if test -f $$p; then \
-           echo "$(LIBTOOL)  --mode=install $(INSTALL) $$p $(DESTDIR)$(libdir)/$$p"; \
-           $(LIBTOOL)  --mode=install $(INSTALL) $$p $(DESTDIR)$(libdir)/$$p; \
-         else :; fi; \
-       done
-
-uninstall-libLTLIBRARIES:
-       @$(NORMAL_UNINSTALL)
-       list='$(lib_LTLIBRARIES)'; for p in $$list; do \
-         $(LIBTOOL)  --mode=uninstall rm -f $(DESTDIR)$(libdir)/$$p; \
-       done
-
-.c.o:
-       $(COMPILE) -c $<
-
-# FIXME: We should only use cygpath when building on Windows,
-# and only if it is available.
-.c.obj:
-       $(COMPILE) -c `cygpath -w $<`
-
-.s.o:
-       $(COMPILE) -c $<
-
-.S.o:
-       $(COMPILE) -c $<
-
-mostlyclean-compile:
-       -rm -f *.o core *.core
-       -rm -f *.$(OBJEXT)
-
-clean-compile:
-
-distclean-compile:
-       -rm -f *.tab.c
-
-maintainer-clean-compile:
-
-.c.lo:
-       $(LIBTOOL) --mode=compile $(COMPILE) -c $<
-
-.s.lo:
-       $(LIBTOOL) --mode=compile $(COMPILE) -c $<
-
-.S.lo:
-       $(LIBTOOL) --mode=compile $(COMPILE) -c $<
-
-mostlyclean-libtool:
-       -rm -f *.lo
-
-clean-libtool:
-       -rm -rf .libs _libs
-
-distclean-libtool:
-
-maintainer-clean-libtool:
-
-libopencv.la: $(libopencv_la_OBJECTS) $(libopencv_la_DEPENDENCIES)
-       $(CXXLINK) -rpath $(libdir) $(libopencv_la_LDFLAGS) $(libopencv_la_OBJECTS) $(libopencv_la_LIBADD) $(LIBS)
-.cpp.o:
-       $(CXXCOMPILE) -c $<
-.cpp.obj:
-       $(CXXCOMPILE) -c `cygpath -w $<`
-.cpp.lo:
-       $(LTCXXCOMPILE) -c $<
-
-install-includeHEADERS: $(include_HEADERS)
-       @$(NORMAL_INSTALL)
-       $(mkinstalldirs) $(DESTDIR)$(includedir)
-       @list='$(include_HEADERS)'; for p in $$list; do \
-         if test -f "$$p"; then d= ; else d="$(srcdir)/"; fi; \
-         echo " $(INSTALL_DATA) $$d$$p $(DESTDIR)$(includedir)/$$p"; \
-         $(INSTALL_DATA) $$d$$p $(DESTDIR)$(includedir)/$$p; \
-       done
-
-uninstall-includeHEADERS:
-       @$(NORMAL_UNINSTALL)
-       list='$(include_HEADERS)'; for p in $$list; do \
-         rm -f $(DESTDIR)$(includedir)/$$p; \
-       done
-
-tags: TAGS
-
-ID: $(HEADERS) $(SOURCES) $(LISP)
-       list='$(SOURCES) $(HEADERS)'; \
-       unique=`for i in $$list; do echo $$i; done | \
-         awk '    { files[$$0] = 1; } \
-              END { for (i in files) print i; }'`; \
-       here=`pwd` && cd $(srcdir) \
-         && mkid -f$$here/ID $$unique $(LISP)
-
-TAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) $(LISP)
-       tags=; \
-       here=`pwd`; \
-       list='$(SOURCES) $(HEADERS)'; \
-       unique=`for i in $$list; do echo $$i; done | \
-         awk '    { files[$$0] = 1; } \
-              END { for (i in files) print i; }'`; \
-       test -z "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \
-         || (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags  $$unique $(LISP) -o $$here/TAGS)
-
-mostlyclean-tags:
-
-clean-tags:
-
-distclean-tags:
-       -rm -f TAGS ID
-
-maintainer-clean-tags:
-
-distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)
-
-subdir = cv/src
-
-distdir: $(DISTFILES)
-       @for file in $(DISTFILES); do \
-         d=$(srcdir); \
-         if test -d $$d/$$file; then \
-           cp -pr $$d/$$file $(distdir)/$$file; \
-         else \
-           test -f $(distdir)/$$file \
-           || ln $$d/$$file $(distdir)/$$file 2> /dev/null \
-           || cp -p $$d/$$file $(distdir)/$$file || :; \
-         fi; \
-       done
-camshift.lo camshift.o : camshift.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h ../include/cv.hpp \
-       ../include/cvstorage.hpp
-cvabsdiff.lo cvabsdiff.o : cvabsdiff.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h _cvwrap.h
-cvaccum.lo cvaccum.o : cvaccum.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h _cvwrap.h
-cvadapthresh.lo cvadapthresh.o : cvadapthresh.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h _cvwrap.h
-cvaffine.lo cvaffine.o : cvaffine.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h _cvwrap.h
-cvalloc.lo cvalloc.o : cvalloc.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h _cvwrap.h
-cvapprox.lo cvapprox.o : cvapprox.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h _cvwrap.h _cvdatastructs.h
-cvarithm.lo cvarithm.o : cvarithm.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h
-cvarray.lo cvarray.o : cvarray.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h
-cvblur.lo cvblur.o : cvblur.cpp _cv.h ../include/cv.h ../include/ipl.h \
-       ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h
-cvcalccontrasthistogram.lo cvcalccontrasthistogram.o : \
-       cvcalccontrasthistogram.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h _cvwrap.h
-cvcalccovarmatrix.lo cvcalccovarmatrix.o : cvcalccovarmatrix.cpp _cv.h \
-       ../include/cv.h ../include/ipl.h ../include/iplerror.h \
-       ../include/iplmisc.h ../include/cvpixelaccess.h \
-       ../include/cvtypes.h ../include/cverror.h ../include/cvcompat.h \
-       _cvoptions.h _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h \
-       _cvarr.h _cvfuncn.h _cvmatrix.h
-cvcalccovarmatrixex.lo cvcalccovarmatrixex.o : cvcalccovarmatrixex.cpp \
-       _cv.h ../include/cv.h ../include/ipl.h ../include/iplerror.h \
-       ../include/iplmisc.h ../include/cvpixelaccess.h \
-       ../include/cvtypes.h ../include/cverror.h ../include/cvcompat.h \
-       _cvoptions.h _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h \
-       _cvarr.h _cvfuncn.h _cvmatrix.h
-cvcalceigenobjects.lo cvcalceigenobjects.o : cvcalceigenobjects.cpp \
-       _cv.h ../include/cv.h ../include/ipl.h ../include/iplerror.h \
-       ../include/iplmisc.h ../include/cvpixelaccess.h \
-       ../include/cvtypes.h ../include/cverror.h ../include/cvcompat.h \
-       _cvoptions.h _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h \
-       _cvarr.h _cvfuncn.h _cvmatrix.h
-cvcalcimagehomography.lo cvcalcimagehomography.o : \
-       cvcalcimagehomography.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h _cvdatastructs.h
-cvcalcprobdensity.lo cvcalcprobdensity.o : cvcalcprobdensity.cpp _cv.h \
-       ../include/cv.h ../include/ipl.h ../include/iplerror.h \
-       ../include/iplmisc.h ../include/cvpixelaccess.h \
-       ../include/cvtypes.h ../include/cverror.h ../include/cvcompat.h \
-       _cvoptions.h _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h \
-       _cvarr.h _cvfuncn.h _cvmatrix.h
-cvcalibinit.lo cvcalibinit.o : cvcalibinit.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h _cvwrap.h _cvgeom.h
-cvcalibration.lo cvcalibration.o : cvcalibration.cpp _cv.h \
-       ../include/cv.h ../include/ipl.h ../include/iplerror.h \
-       ../include/iplmisc.h ../include/cvpixelaccess.h \
-       ../include/cvtypes.h ../include/cverror.h ../include/cvcompat.h \
-       _cvoptions.h _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h \
-       _cvarr.h _cvfuncn.h _cvmatrix.h _cvwrap.h
-cvcamshift.lo cvcamshift.o : cvcamshift.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h _cvwrap.h
-cvcanny.lo cvcanny.o : cvcanny.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h
-cvcolor.lo cvcolor.o : cvcolor.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h
-cvcondens.lo cvcondens.o : cvcondens.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h _cvwrap.h
-cvcontourarea.lo cvcontourarea.o : cvcontourarea.cpp _cv.h \
-       ../include/cv.h ../include/ipl.h ../include/iplerror.h \
-       ../include/iplmisc.h ../include/cvpixelaccess.h \
-       ../include/cvtypes.h ../include/cverror.h ../include/cvcompat.h \
-       _cvoptions.h _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h \
-       _cvarr.h _cvfuncn.h _cvmatrix.h _cvwrap.h _cvdatastructs.h
-cvcontours.lo cvcontours.o : cvcontours.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h _cvwrap.h _cvdatastructs.h
-cvcontoursmoments.lo cvcontoursmoments.o : cvcontoursmoments.cpp _cv.h \
-       ../include/cv.h ../include/ipl.h ../include/iplerror.h \
-       ../include/iplmisc.h ../include/cvpixelaccess.h \
-       ../include/cvtypes.h ../include/cverror.h ../include/cvcompat.h \
-       _cvoptions.h _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h \
-       _cvarr.h _cvfuncn.h _cvmatrix.h _cvwrap.h _cvdatastructs.h
-cvcontourtree.lo cvcontourtree.o : cvcontourtree.cpp _cv.h \
-       ../include/cv.h ../include/ipl.h ../include/iplerror.h \
-       ../include/iplmisc.h ../include/cvpixelaccess.h \
-       ../include/cvtypes.h ../include/cverror.h ../include/cvcompat.h \
-       _cvoptions.h _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h \
-       _cvarr.h _cvfuncn.h _cvmatrix.h _cvwrap.h _cvdatastructs.h \
-       _cvgeom.h
-cvconvert.lo cvconvert.o : cvconvert.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h
-cvconvgen.lo cvconvgen.o : cvconvgen.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h
-cvconvhull.lo cvconvhull.o : cvconvhull.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h
-cvcopy.lo cvcopy.o : cvcopy.cpp _cv.h ../include/cv.h ../include/ipl.h \
-       ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h
-cvcorner.lo cvcorner.o : cvcorner.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h
-cvcornersubpix.lo cvcornersubpix.o : cvcornersubpix.cpp _cv.h \
-       ../include/cv.h ../include/ipl.h ../include/iplerror.h \
-       ../include/iplmisc.h ../include/cvpixelaccess.h \
-       ../include/cvtypes.h ../include/cverror.h ../include/cvcompat.h \
-       _cvoptions.h _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h \
-       _cvarr.h _cvfuncn.h _cvmatrix.h _cvwrap.h
-cvcorrespond.lo cvcorrespond.o : cvcorrespond.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h _cvwrap.h _cvvm.h
-cvcreatehandmask.lo cvcreatehandmask.o : cvcreatehandmask.cpp _cv.h \
-       ../include/cv.h ../include/ipl.h ../include/iplerror.h \
-       ../include/iplmisc.h ../include/cvpixelaccess.h \
-       ../include/cvtypes.h ../include/cverror.h ../include/cvcompat.h \
-       _cvoptions.h _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h \
-       _cvarr.h _cvfuncn.h _cvmatrix.h _cvwrap.h
-cvdatastructs.lo cvdatastructs.o : cvdatastructs.cpp _cv.h \
-       ../include/cv.h ../include/ipl.h ../include/iplerror.h \
-       ../include/iplmisc.h ../include/cvpixelaccess.h \
-       ../include/cvtypes.h ../include/cverror.h ../include/cvcompat.h \
-       _cvoptions.h _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h \
-       _cvarr.h _cvfuncn.h _cvmatrix.h _cvwrap.h _cvdatastructs.h
-cvdetectwr.lo cvdetectwr.o : cvdetectwr.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h _cvwrap.h
-cvdistransform.lo cvdistransform.o : cvdistransform.cpp _cv.h \
-       ../include/cv.h ../include/ipl.h ../include/iplerror.h \
-       ../include/iplmisc.h ../include/cvpixelaccess.h \
-       ../include/cvtypes.h ../include/cverror.h ../include/cvcompat.h \
-       _cvoptions.h _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h \
-       _cvarr.h _cvfuncn.h _cvmatrix.h _cvwrap.h
-cvdominants.lo cvdominants.o : cvdominants.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h _cvwrap.h
-cvdrawing.lo cvdrawing.o : cvdrawing.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h _cvwrap.h _cvdatastructs.h
-cveigendecomposite.lo cveigendecomposite.o : cveigendecomposite.cpp \
-       _cv.h ../include/cv.h ../include/ipl.h ../include/iplerror.h \
-       ../include/iplmisc.h ../include/cvpixelaccess.h \
-       ../include/cvtypes.h ../include/cverror.h ../include/cvcompat.h \
-       _cvoptions.h _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h \
-       _cvarr.h _cvfuncn.h _cvmatrix.h
-cveigenobjectswrap.lo cveigenobjectswrap.o : cveigenobjectswrap.cpp \
-       _cv.h ../include/cv.h ../include/ipl.h ../include/iplerror.h \
-       ../include/iplmisc.h ../include/cvpixelaccess.h \
-       ../include/cvtypes.h ../include/cverror.h ../include/cvcompat.h \
-       _cvoptions.h _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h \
-       _cvarr.h _cvfuncn.h _cvmatrix.h _cvwrap.h
-cveigenprojection.lo cveigenprojection.o : cveigenprojection.cpp _cv.h \
-       ../include/cv.h ../include/ipl.h ../include/iplerror.h \
-       ../include/iplmisc.h ../include/cvpixelaccess.h \
-       ../include/cvtypes.h ../include/cverror.h ../include/cvcompat.h \
-       _cvoptions.h _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h \
-       _cvarr.h _cvfuncn.h _cvmatrix.h
-cvellipsefit.lo cvellipsefit.o : cvellipsefit.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h
-cvemd.lo cvemd.o : cvemd.cpp _cv.h ../include/cv.h ../include/ipl.h \
-       ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h _cvwrap.h
-cverror.lo cverror.o : cverror.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h _cvwrap.h
-cvfeatureselect.lo cvfeatureselect.o : cvfeatureselect.cpp _cv.h \
-       ../include/cv.h ../include/ipl.h ../include/iplerror.h \
-       ../include/iplmisc.h ../include/cvpixelaccess.h \
-       ../include/cvtypes.h ../include/cverror.h ../include/cvcompat.h \
-       _cvoptions.h _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h \
-       _cvarr.h _cvfuncn.h _cvmatrix.h _cvwrap.h
-cvfilterwr.lo cvfilterwr.o : cvfilterwr.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h _cvwrap.h
-cvfindhandregion.lo cvfindhandregion.o : cvfindhandregion.cpp _cv.h \
-       ../include/cv.h ../include/ipl.h ../include/iplerror.h \
-       ../include/iplmisc.h ../include/cvpixelaccess.h \
-       ../include/cvtypes.h ../include/cverror.h ../include/cvcompat.h \
-       _cvoptions.h _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h \
-       _cvarr.h _cvfuncn.h _cvmatrix.h _cvwrap.h
-cvfindhandregiona.lo cvfindhandregiona.o : cvfindhandregiona.cpp _cv.h \
-       ../include/cv.h ../include/ipl.h ../include/iplerror.h \
-       ../include/iplmisc.h ../include/cvpixelaccess.h \
-       ../include/cvtypes.h ../include/cverror.h ../include/cvcompat.h \
-       _cvoptions.h _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h \
-       _cvarr.h _cvfuncn.h _cvmatrix.h _cvwrap.h
-cvfloodfill.lo cvfloodfill.o : cvfloodfill.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h _cvwrap.h
-cvfundam.lo cvfundam.o : cvfundam.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h _cvwrap.h _cvvm.h
-cvgeometry.lo cvgeometry.o : cvgeometry.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h _cvgeom.h
-cvgeometrywrap.lo cvgeometrywrap.o : cvgeometrywrap.cpp _cv.h \
-       ../include/cv.h ../include/ipl.h ../include/iplerror.h \
-       ../include/iplmisc.h ../include/cvpixelaccess.h \
-       ../include/cvtypes.h ../include/cverror.h ../include/cvcompat.h \
-       _cvoptions.h _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h \
-       _cvarr.h _cvfuncn.h _cvmatrix.h _cvgeom.h
-cvgesturerecognition.lo cvgesturerecognition.o : \
-       cvgesturerecognition.cpp _cv.h ../include/cv.h ../include/ipl.h \
-       ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h _cvwrap.h
-cvhistogram.lo cvhistogram.o : cvhistogram.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h _cvwrap.h
-cvhmm.lo cvhmm.o : cvhmm.cpp _cv.h ../include/cv.h ../include/ipl.h \
-       ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h
-cvhmmobs.lo cvhmmobs.o : cvhmmobs.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h
-cvhmmwrap.lo cvhmmwrap.o : cvhmmwrap.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h _cvwrap.h
-cvhough.lo cvhough.o : cvhough.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h
-cvhoughdiv.lo cvhoughdiv.o : cvhoughdiv.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h _cvlist.h
-cvhoughp.lo cvhoughp.o : cvhoughp.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h
-cvhoughwrap.lo cvhoughwrap.o : cvhoughwrap.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h _cvwrap.h
-cvimage.lo cvimage.o : cvimage.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h _cvwrap.h ../include/cv.hpp \
-       ../include/cvstorage.hpp
-cvinitconvol.lo cvinitconvol.o : cvinitconvol.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h
-cvjacobieigens.lo cvjacobieigens.o : cvjacobieigens.cpp _cv.h \
-       ../include/cv.h ../include/ipl.h ../include/iplerror.h \
-       ../include/iplmisc.h ../include/cvpixelaccess.h \
-       ../include/cvtypes.h ../include/cverror.h ../include/cvcompat.h \
-       _cvoptions.h _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h \
-       _cvarr.h _cvfuncn.h _cvmatrix.h _cvwrap.h
-cvkalman.lo cvkalman.o : cvkalman.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h _cvwrap.h
-cvlaplace.lo cvlaplace.o : cvlaplace.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h
-cvlinefit.lo cvlinefit.o : cvlinefit.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h
-cvlines.lo cvlines.o : cvlines.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h
-cvlkpyramid.lo cvlkpyramid.o : cvlkpyramid.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h _cvwrap.h
-cvlmeds.lo cvlmeds.o : cvlmeds.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h _cvwrap.h _cvvm.h
-cvlogic.lo cvlogic.o : cvlogic.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h
-cvmatchcontours.lo cvmatchcontours.o : cvmatchcontours.cpp _cv.h \
-       ../include/cv.h ../include/ipl.h ../include/iplerror.h \
-       ../include/iplmisc.h ../include/cvpixelaccess.h \
-       ../include/cvtypes.h ../include/cverror.h ../include/cvcompat.h \
-       _cvoptions.h _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h \
-       _cvarr.h _cvfuncn.h _cvmatrix.h _cvwrap.h _cvgeom.h
-cvmathfuncs.lo cvmathfuncs.o : cvmathfuncs.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h _cvwrap.h
-cvmatmul.lo cvmatmul.o : cvmatmul.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h _cvwrap.h
-cvmatrix.lo cvmatrix.o : cvmatrix.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h _cvwrap.h
-cvmatrix64d.lo cvmatrix64d.o : cvmatrix64d.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h _cvwrap.h
-cvmaxrect.lo cvmaxrect.o : cvmaxrect.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h
-cvmean.lo cvmean.o : cvmean.cpp _cv.h ../include/cv.h ../include/ipl.h \
-       ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h _cvwrap.h
-cvmeansdv.lo cvmeansdv.o : cvmeansdv.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h _cvwrap.h
-cvmineval.lo cvmineval.o : cvmineval.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h
-cvminmaxloc.lo cvminmaxloc.o : cvminmaxloc.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h _cvwrap.h
-cvmoments.lo cvmoments.o : cvmoments.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h _cvwrap.h
-cvmorph.lo cvmorph.o : cvmorph.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h
-cvmorphing.lo cvmorphing.o : cvmorphing.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h _cvwrap.h
-cvmorphwrap.lo cvmorphwrap.o : cvmorphwrap.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h _cvwrap.h
-cvmotempl.lo cvmotempl.o : cvmotempl.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h _cvwrap.h
-cvmotseg.lo cvmotseg.o : cvmotseg.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h _cvwrap.h
-cvnorm.lo cvnorm.o : cvnorm.cpp _cv.h ../include/cv.h ../include/ipl.h \
-       ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h _cvwrap.h
-cvoptflowbm.lo cvoptflowbm.o : cvoptflowbm.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h
-cvoptflowhs.lo cvoptflowhs.o : cvoptflowhs.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h
-cvoptflowlk.lo cvoptflowlk.o : cvoptflowlk.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h
-cvouttext.lo cvouttext.o : cvouttext.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h
-cvpgh.lo cvpgh.o : cvpgh.cpp _cv.h ../include/cv.h ../include/ipl.h \
-       ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h _cvwrap.h _cvdatastructs.h
-cvposit.lo cvposit.o : cvposit.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h _cvwrap.h
-cvprecomp.lo cvprecomp.o : cvprecomp.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h
-cvprecorner.lo cvprecorner.o : cvprecorner.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h
-cvprewarp.lo cvprewarp.o : cvprewarp.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h _cvwrap.h _cvvm.h
-cvprint.lo cvprint.o : cvprint.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h
-cvproject.lo cvproject.o : cvproject.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h _cvgeom.h
-cvpyramids.lo cvpyramids.o : cvpyramids.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h _cvwrap.h
-cvpyrsegmentation.lo cvpyrsegmentation.o : cvpyrsegmentation.cpp _cv.h \
-       ../include/cv.h ../include/ipl.h ../include/iplerror.h \
-       ../include/iplmisc.h ../include/cvpixelaccess.h \
-       ../include/cvtypes.h ../include/cverror.h ../include/cvcompat.h \
-       _cvoptions.h _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h \
-       _cvarr.h _cvfuncn.h _cvmatrix.h _cvwrap.h _cvdatastructs.h
-cvrand.lo cvrand.o : cvrand.cpp _cv.h ../include/cv.h ../include/ipl.h \
-       ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h
-cvrotcalipers.lo cvrotcalipers.o : cvrotcalipers.cpp _cv.h \
-       ../include/cv.h ../include/ipl.h ../include/iplerror.h \
-       ../include/iplmisc.h ../include/cvpixelaccess.h \
-       ../include/cvtypes.h ../include/cverror.h ../include/cvcompat.h \
-       _cvoptions.h _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h \
-       _cvarr.h _cvfuncn.h _cvmatrix.h _cvgeom.h
-cvsamplers.lo cvsamplers.o : cvsamplers.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h _cvwrap.h
-cvscanlines.lo cvscanlines.o : cvscanlines.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h _cvwrap.h _cvvm.h
-cvscharr.lo cvscharr.o : cvscharr.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h
-cvshapedescr.lo cvshapedescr.o : cvshapedescr.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h _cvwrap.h _cvdatastructs.h _cvgeom.h
-cvsnakes.lo cvsnakes.o : cvsnakes.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h _cvwrap.h
-cvsubdivision2d.lo cvsubdivision2d.o : cvsubdivision2d.cpp _cv.h \
-       ../include/cv.h ../include/ipl.h ../include/iplerror.h \
-       ../include/iplmisc.h ../include/cvpixelaccess.h \
-       ../include/cvtypes.h ../include/cverror.h ../include/cvcompat.h \
-       _cvoptions.h _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h \
-       _cvarr.h _cvfuncn.h _cvmatrix.h _cvgeom.h
-cvsumpixels.lo cvsumpixels.o : cvsumpixels.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h _cvwrap.h
-cvsvd.lo cvsvd.o : cvsvd.cpp _cv.h ../include/cv.h ../include/ipl.h \
-       ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h _cvwrap.h
-cvswitcher.lo cvswitcher.o : cvswitcher.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h
-cvtables.lo cvtables.o : cvtables.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h
-cvtemplmatch.lo cvtemplmatch.o : cvtemplmatch.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h
-cvthresh.lo cvthresh.o : cvthresh.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h _cvwrap.h
-cvundistort.lo cvundistort.o : cvundistort.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h
-cvutilitieswrap.lo cvutilitieswrap.o : cvutilitieswrap.cpp _cv.h \
-       ../include/cv.h ../include/ipl.h ../include/iplerror.h \
-       ../include/iplmisc.h ../include/cvpixelaccess.h \
-       ../include/cvtypes.h ../include/cverror.h ../include/cvcompat.h \
-       _cvoptions.h _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h \
-       _cvarr.h _cvfuncn.h _cvmatrix.h
-cvutils.lo cvutils.o : cvutils.cpp _cv.h ../include/cv.h \
-       ../include/ipl.h ../include/iplerror.h ../include/iplmisc.h \
-       ../include/cvpixelaccess.h ../include/cvtypes.h \
-       ../include/cverror.h ../include/cvcompat.h _cvoptions.h \
-       _cvtables.h _cverror.h _ipcv.h _optcv.h _cvutils.h _cvarr.h \
-       _cvfuncn.h _cvmatrix.h
-
-info-am:
-info: info-am
-dvi-am:
-dvi: dvi-am
-check-am: all-am
-check: check-am
-installcheck-am:
-installcheck: installcheck-am
-install-exec-am: install-libLTLIBRARIES
-install-exec: install-exec-am
-
-install-data-am: install-includeHEADERS
-install-data: install-data-am
-
-install-am: all-am
-       @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
-install: install-am
-uninstall-am: uninstall-libLTLIBRARIES uninstall-includeHEADERS
-uninstall: uninstall-am
-all-am: Makefile $(LTLIBRARIES) $(HEADERS)
-all-redirect: all-am
-install-strip:
-       $(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install
-installdirs:
-       $(mkinstalldirs)  $(DESTDIR)$(libdir) $(DESTDIR)$(includedir)
-
-
-mostlyclean-generic:
-
-clean-generic:
-
-distclean-generic:
-       -rm -f Makefile $(CONFIG_CLEAN_FILES)
-       -rm -f config.cache config.log stamp-h stamp-h[0-9]*
-
-maintainer-clean-generic:
-mostlyclean-am:  mostlyclean-libLTLIBRARIES mostlyclean-compile \
-               mostlyclean-libtool mostlyclean-tags \
-               mostlyclean-generic
-
-mostlyclean: mostlyclean-am
-
-clean-am:  clean-libLTLIBRARIES clean-compile clean-libtool clean-tags \
-               clean-generic mostlyclean-am
-
-clean: clean-am
-
-distclean-am:  distclean-libLTLIBRARIES distclean-compile \
-               distclean-libtool distclean-tags distclean-generic \
-               clean-am
-       -rm -f libtool
-
-distclean: distclean-am
-
-maintainer-clean-am:  maintainer-clean-libLTLIBRARIES \
-               maintainer-clean-compile maintainer-clean-libtool \
-               maintainer-clean-tags maintainer-clean-generic \
-               distclean-am
-       @echo "This command is intended for maintainers to use;"
-       @echo "it deletes files that may require special tools to rebuild."
-
-maintainer-clean: maintainer-clean-am
-
-.PHONY: mostlyclean-libLTLIBRARIES distclean-libLTLIBRARIES \
-clean-libLTLIBRARIES maintainer-clean-libLTLIBRARIES \
-uninstall-libLTLIBRARIES install-libLTLIBRARIES mostlyclean-compile \
-distclean-compile clean-compile maintainer-clean-compile \
-mostlyclean-libtool distclean-libtool clean-libtool \
-maintainer-clean-libtool uninstall-includeHEADERS \
-install-includeHEADERS tags mostlyclean-tags distclean-tags clean-tags \
-maintainer-clean-tags distdir info-am info dvi-am dvi check check-am \
-installcheck-am installcheck install-exec-am install-exec \
-install-data-am install-data install-am install uninstall-am uninstall \
-all-redirect all-am all installdirs mostlyclean-generic \
-distclean-generic clean-generic maintainer-clean-generic clean \
-mostlyclean distclean maintainer-clean
-
-
-# Tell versions [3.59,3.63) of GNU make to not export all variables.
-# Otherwise a system limit (for SysV at least) may be exceeded.
-.NOEXPORT:
index 8215f00eb245be492708d2784f01a6433505fbee..04b9e31d0199c92bf8cf2dddf6eb1856b6b37771 100644 (file)
 //
 //M*/
 
-#ifndef __CV_H_
-#define __CV_H_
+#ifndef _CV_INTERNAL_H_
+#define _CV_INTERNAL_H_
 
 #if _MSC_VER >= 1200
     /* disable warnings related to inline functions */
     #pragma warning( disable: 4711 4710 4514 )
 #endif
 
-typedef unsigned char uchar;
-typedef unsigned short ushort;
-typedef unsigned long ulong;
-
-#ifdef __BORLANDC__
-    #define     WIN32
-    #define     CV_DLL
-    #undef      _CV_ALWAYS_PROFILE_
-    #define     _CV_ALWAYS_NO_PROFILE_
-#endif
-
-#define CV_IMPL CV_EXTERN_C
-
-#ifndef IPCVAPI
-#define IPCVAPI(type,name,arg)                                \
-    CV_EXTERN_C type CV_STDCALL name##_f arg;                 \
-    /* function pointer */                                    \
-    typedef type (CV_STDCALL* name##_t) arg;                  \
-    extern name##_t name;
-#endif
-
-#ifndef IPCVAPI_IMPL
-#define IPCVAPI_IMPL(type,name,arg)                           \
-    /*typedef type (CV_STDCALL* name##_t) arg;*/              \
-    CV_EXTERN_C type CV_STDCALL name##_f arg;                 \
-    name##_t name = name##_f;                                 \
-    CV_EXTERN_C type CV_STDCALL name##_f arg
-#endif
-
 #include "cv.h"
-
+#include "cxmisc.h"
 #include <math.h>
 #include <assert.h>
 #include <string.h>
@@ -85,287 +56,43 @@ typedef unsigned long ulong;
 #include <limits.h>
 #include <float.h>
 
-/* get alloca declaration */
-#ifdef WIN32
-    #if defined _MSC_VER || defined __BORLANDC__
-        #include <malloc.h>
-    #endif
-#endif
-
-#ifdef __GNUC__
-    #undef alloca
-    #define alloca __builtin_alloca
-#endif
-
-#include "_cvoptions.h"
-#include "_cvtables.h"
-#include "_cverror.h"
-
-typedef enum {
-   cv1u,
-   cv8u, cv8s,
-   cv16u, cv16s, cv16sc,
-   cv32u, cv32s, cv32sc,
-   cv32f, cv32fc,
-   cv64u, cv64s, cv64sc,
-   cv64f, cv64fc
-} CvDataType;
-
-CV_EXTERN_C_FUNCPTR( void (CV_CDECL * ICVWriteNodeFunction)(void*,void*) )
-
-#define ICV_KERNEL_TYPE_MASK        (15<<16)
-#define ICV_BINARY_KERNEL           (0<<16)
-#define ICV_SEPARABLE_KERNEL        (1<<16)
-
-#define ICV_KERNEL_TYPE(flags)      ((flags) & ICV_KERNEL_TYPE_MASK)
-
-#define ICV_MAKE_SEPARABLE_KERNEL( x_type, y_type ) \
-    (ICV_SEPARABLE_KERNEL | ((x_type)&255) | (((y_type)&255) << 8))
-
-#define ICV_X_KERNEL_TYPE(flags)    ((flags) & 255)
-#define ICV_Y_KERNEL_TYPE(flags)    (((flags) >> 8) & 255)
-#define ICV_SYMMETRIC_KERNEL        1
-#define ICV_ASYMMETRIC_KERNEL       2
-
-#define ICV_1_2_1_KERNEL            (4*1+ICV_SYMMETRIC_KERNEL)
-#define ICV_m1_0_1_KERNEL           (4*2+ICV_ASYMMETRIC_KERNEL)
-#define ICV_1_m2_1_KERNEL           (4*3+ICV_SYMMETRIC_KERNEL)
-#define ICV_3_10_3_KERNEL           (4*4+ICV_SYMMETRIC_KERNEL)
-
-#define ICV_MAKE_BINARY_KERNEL( shape ) \
-    (ICV_BINARY_KERNEL | (int)(shape))
-
-#define ICV_BINARY_KERNEL_SHAPE(flags) ((CvElementShape)((flags) & 255))
-
-typedef struct CvFilterState
-{
-    /* kernel data */
-    int ker_width;
-    int ker_height;
-    int ker_x;
-    int ker_y;
-    int kerType;
-    uchar *ker0;
-    uchar *ker1;
-    double divisor;
-
-    /* image data */
-    int max_width;
-    CvDataType dataType;
-    int channels;
-    int origin;
-
-    /* cyclic buffer */
-    char *buffer;
-    int buffer_step;
-    int crows;
-    char **rows;
-    char *tbuf;
-}
-CvFilterState;
-
-#define _CvConvState CvFilterState
-#define CvMorphState CvFilterState
-
-#define  CV_COPY( dst, src, len, idx ) \
-    for( (idx) = 0; (idx) < (len); (idx)++) (dst)[idx] = (src)[idx]
-
-#define  CV_SET( dst, val, len, idx )  \
-    for( (idx) = 0; (idx) < (len); (idx)++) (dst)[idx] = (val)
-
-
-typedef struct
-{
-    uchar  b, g, r;
-}
-CvRGB8u;
-
-
-typedef struct
-{
-    uchar  b, g, r, a;
-}
-CvRGBA8u;
-
-
-typedef struct
-{
-    int  b, g, r;
-}
-CvRGB32s;
-
-
-typedef struct
-{
-    int  b, g, r, a;
-}
-CvRGBA32s;
-
-typedef struct
-{
-    float  b, g, r;
-}
-CvRGB32f;
-
-
-typedef struct
-{
-    float  b, g, r, a;
-}
-CvRGBA32f;
-
-
-#undef   CV_CALC_MAX
-#undef   CV_CALC_MIN
-
-#define  CV_CALC_MIN(a, b) (a) = CV_IMIN((a),(b))
-#define  CV_CALC_MAX(a, b) (a) = CV_IMAX((a),(b))
-
-#define CV_MORPH_ALIGN  4
-
-typedef CvStatus( CV_STDCALL* CvFilterFunc )( const void* src, int src_step,
-                                              void* dst, int dst_step,
-                                              CvSize* size, struct CvFilterState * state,
-                                              int stage );
-
-#define CvMorphFunc CvFilterFunc
-
-typedef struct CvFuncTable CvFuncTable;
-typedef struct CvBigFuncTable CvBigFuncTable;
-
-#include "_ipcv.h"
-#include "_optcv.h"
-#include "_cvutils.h"
-#include "_cvarr.h"
-#include "_cvmatrix.h"
-
-#if _MSC_VER >= 1200
-    #define CV_FORCE_INLINE  __forceinline
-#else
-    #define CV_FORCE_INLINE  CV_INLINE
-#endif
+typedef unsigned char uchar;
+typedef unsigned short ushort;
 
-#if defined _MSC_VER || defined __BORLANDC__ || defined __ICL
-    #define CV_BIG_INT(n)   n##I64
-#else
-    #define CV_BIG_INT(n)   n##LL
+#ifdef __BORLANDC__
+    #define     WIN32
+    #define     CV_DLL
+    #undef      _CV_ALWAYS_PROFILE_
+    #define     _CV_ALWAYS_NO_PROFILE_
 #endif
 
-#define  sizeof_float ((int)sizeof(float))
-#define  sizeof_short ((int)sizeof(float))
-
-#define  CV_ORIGIN_TL  0
-#define  CV_ORIGIN_BL  1
-
-#define  CV_POS_INF       0x7f800000
-#define  CV_NEG_INF       0x807fffff /* CV_TOGGLE_FLT(0xff800000) */
-#define  CV_TOGGLE_FLT(x) ((x)^((int)(x) < 0 ? 0x7fffffff : 0))
-
-#define  CV_TOGGLE_DBL(x) \
-    ((x)^((int64)(x) < 0 ? CV_BIG_INT(0x7fffffffffffffff) : 0))
-
-#define  CV_PI   3.1415926535897932384626433832795
-
-/* IEEE 754 representation of 1.f */
-#define  CV_1F          0x3f800000
-
-#define  CV_NOP(a)      (a)
-#define  CV_ADD(a, b)   ((a) + (b))
-#define  CV_SUB(a, b)   ((a) - (b))
-#define  CV_MUL(a, b)   ((a) * (b))
-#define  CV_AND(a, b)   ((a) & (b))
-#define  CV_OR(a, b)    ((a) | (b))
-#define  CV_XOR(a, b)   ((a) ^ (b))
-#define  CV_ANDN(a, b)  (~(a) & (b))
-#define  CV_ORN(a, b)   (~(a) | (b))
-#define  CV_SQR(a)      ((a) * (a))
-#define  CV_MIN(a, b)   ((a) <= (b) ? (a) : (b))
-#define  CV_MAX(a, b)   ((a) >= (b) ? (a) : (b))
-
-// (a) < (b) ? -1 : (a) > (b)
-#define  CV_CMP(a, b)   ((((a)>=(b))-1)|((a)>(b)))
-
-#define  CV_LT(a, b)    ((a) < (b))
-#define  CV_LE(a, b)    ((a) <= (b))
-#define  CV_EQ(a, b)    ((a) == (b))
-#define  CV_NE(a, b)    ((a) != (b))
-#define  CV_GT(a, b)    ((a) > (b))
-#define  CV_GE(a, b)    ((a) >= (b))
-
-#define  CV_NONZERO(a)      ((a) != 0)
-#define  CV_NONZERO_FLT(a)  (((a)+(a)) != 0)
-
-#define  CV_EMPTY
-
-#define  CV_DEFINE_MASK         \
-    float maskTab[2]; maskTab[0] = 0.f; maskTab[1] = 1.f;
-#define  CV_ANDMASK( m, x )     ((x) & (((m) == 0) - 1))
-
-// (x) * ((m) == 1 ? 1.f : (m) == 0 ? 0.f : <ERR>
-#define  CV_MULMASK( m, x )       (maskTab[(m) != 0]*(x))
-
-// (x) * ((m) == -1 ? 1.f : (m) == 0 ? 0.f : <ERR>
-#define  CV_MULMASK1( m, x )      (maskTab[(m)+1]*(x))
-
+/* helper tables */
+extern const uchar icvSaturate8u[];
+#define CV_FAST_CAST_8U(t)   (assert(-256 <= (t) || (t) <= 512), icvSaturate8u[t+256])
 
-#define CV_ZERO_OBJ(x)  memset((x), 0, sizeof(*(x)))
+// -128.f ... 255.f
+extern const float icv8x32fTab_cv[];
+#define CV_8TO32F(x)  icv8x32fTab_cv[(x)+128]
 
+// (-128.f)^2 ... (255.f)^2
+extern const float icv8x32fSqrTab[];
+#define CV_8TO32F_SQR(x)  icv8x32fSqrTab[(x)+128]
 
-#define  ICV_UN_ENTRY_C1(worktype)           \
-    worktype s0 = scalar[0]
-    
-#define  ICV_UN_ENTRY_C2(worktype)           \
-    worktype s0 = scalar[0], s1 = scalar[1]
-
-#define  ICV_UN_ENTRY_C3(worktype)           \
-    worktype s0 = scalar[0], s1 = scalar[1], s2 = scalar[2]
-
-#define  ICV_UN_ENTRY_C4(worktype)           \
-    worktype s0 = scalar[0], s1 = scalar[1], s2 = scalar[2], s3 = scalar[3]
-
-CV_INLINE void* icvAlignPtr( void* ptr, int align = 32 );
-CV_INLINE void* icvAlignPtr( void* ptr, int align )
-{
-    return (void*)( ((long)ptr + align - 1) & -align );
-}
-
-CV_INLINE int icvAlign( int size, int align );
-CV_INLINE int icvAlign( int size, int align )
+CV_INLINE  CvDataType icvDepthToDataType( int type );
+CV_INLINE  CvDataType icvDepthToDataType( int type )
 {
-    return (size + align - 1) & -align;
+    return (CvDataType)(
+            ((((int)cv8u)|((int)cv8s << 4)|((int)cv16u << 8)|
+              ((int)cv16s << 12)|((int)cv32s << 16)|((int)cv32f << 20)|
+              ((int)cv64f << 24)) >> CV_MAT_DEPTH(type)*4) & 15);
 }
 
+#define CV_HIST_DEFAULT_TYPE CV_32F
 
-#define CV_WHOLE   0
-#define CV_START   1
-#define CV_END     2
-#define CV_MIDDLE  4
-
-#ifdef IPCVAPI_DEFINED
-    #undef IPCVAPI
-    #undef IPCVAPI_DEFINED
-#endif
-
-void icvCheckImageHeader( const IplImage* image, const char* img_name );
-void icvCheckMaskImageHeader( const IplImage* image, const char* img_name );
-#define CV_CHECK_IMAGE( img ) icvCheckImageHeader( img, #img )
-#define CV_CHECK_MASK_IMAGE( img ) icvCheckMaskImageHeader( img, #img )
-
-CvTermCriteria icvCheckTermCriteria( CvTermCriteria criteria,
-                                     double default_eps, int max_iters );
-
-CV_INLINE bool icvIsRectInRect( CvRect subrect, CvRect mainrect );
-CV_INLINE bool icvIsRectInRect( CvRect subrect, CvRect mainrect )
-{
-    return  subrect.x >= mainrect.x && subrect.y >= mainrect.y &&
-            subrect.x + subrect.width <= mainrect.x + mainrect.width &&
-            subrect.y + subrect.height <= mainrect.y + mainrect.height;
-}
-
-CV_INLINE int icvGetBtPix( const IplImage* image );
-CV_INLINE int icvGetBtPix( const IplImage* image )
+CV_INLINE int icvGetImageCOI( const IplImage* image );
+CV_INLINE int icvGetImageCOI( const IplImage* image )
 {
-    return  ((image->depth & 255)>>3)*image->nChannels;
+    return image->roi ? image->roi->coi : 0;
 }
 
 CV_INLINE bool operator == (CvSize size1, CvSize size2 );
@@ -380,17 +107,19 @@ CV_INLINE bool operator != (CvSize size1, CvSize size2 )
     return size1.width != size2.width || size1.height != size2.height;
 }
 
-CV_INLINE int icvGetImageCOI( const IplImage* image );
-CV_INLINE int icvGetImageCOI( const IplImage* image )
-{
-    return image->roi ? image->roi->coi : 0;
-}
+CV_EXTERN_C_FUNCPTR( void (CV_CDECL * CvWriteNodeFunction)(void* seq,void* node) )
 
-CV_INLINE IplROI icvMakeROI( int x, int y, int width, int height, int coi = 0 );
-CV_INLINE IplROI icvMakeROI( int x, int y, int width, int height, int coi )
-{
-    IplROI roi = { coi, x, y, width, height };
-    return roi;
-}
 
-#endif /*__CV_H_*/
+#define _CvConvState CvFilterState
+#define CvMorphState CvFilterState
+
+
+#include "_cvipp.h"
+#include "_cvmatrix.h"
+#include "_cvgeom.h"
+#include "_cvimgproc.h"
+
+// default face cascade
+//extern const char* icvDefaultFaceCascade[];
+
+#endif /*_CV_INTERNAL_H_*/
index 82f959f6709715760a2acdbf04b2ce71f6d4ec54..670caeccf3579f7eedea9fd363d8c2326c304128 100644 (file)
@@ -39,8 +39,8 @@
 //
 //M*/
 
-#ifndef _IPCVGEOM_H_
-#define _IPCVGEOM_H_
+#ifndef _CV_GEOM_H_
+#define _CV_GEOM_H_
 
 /* Finds distance between two points */
 CV_INLINE  float  icvDistanceL2_32s( CvPoint pt1, CvPoint pt2 )
@@ -61,16 +61,6 @@ CV_INLINE  float  icvDistanceL2_32f( CvPoint2D32f pt1, CvPoint2D32f pt2 )
 }
 
 
-CV_INLINE int icvIsPtInCircle( CvPoint2D32f  pt,
-                               CvPoint2D32f  center,
-                               float  radius )
-{
-    pt.x -= center.x;
-    pt.y -= center.y;
-    return  pt.x*pt.x + pt.y*pt.y <= radius*radius;
-}
-
-
 int icvIsPtInCircle3( CvPoint2D32f pt, CvPoint2D32f a,
                       CvPoint2D32f b, CvPoint2D32f c );
 
@@ -83,6 +73,13 @@ CV_INLINE CvPoint2D32f icvMidPoint( CvPoint2D32f pt1, CvPoint2D32f pt2 )
     return  mid_pt;
 }
 
+CV_INLINE bool icvIsRectInRect( CvRect subrect, CvRect mainrect );
+CV_INLINE bool icvIsRectInRect( CvRect subrect, CvRect mainrect )
+{
+    return  subrect.x >= mainrect.x && subrect.y >= mainrect.y &&
+            subrect.x + subrect.width <= mainrect.x + mainrect.width &&
+            subrect.y + subrect.height <= mainrect.y + mainrect.height;
+}
 
 int  icvIntersectLines( double x1, double dx1, double y1, double dy1,
                         double x2, double dx2, double y2, double dy2,
@@ -122,12 +119,22 @@ typedef struct _CvTrianAttr
 _CvTrianAttr;
 
 
-CvStatus  icvCalcTriAttr(CvSeq *contour_h,CvPoint t2,CvPoint t1,int n1,
-                                                  CvPoint t3, int n3, double *s, double *s_c,
-                                                  double *h, double *a, double *b);
-
 CvStatus  icvMemCopy (double **buf1, double **buf2, double **buf3, int *b_max);
 
+/* curvature: 0 - 1-curvature, 1 - k-cosine curvature. */
+CvStatus  icvApproximateChainTC89( CvChain*      chain,
+                                   int header_size,
+                                   CvMemStorage* storage,
+                                   CvSeq**   contour,
+                                   int method );
+
+CvSeq* icvPointSeqFromMat( int seq_kind, const CvArr* mat,
+                           CvContour* contour_header,
+                           CvSeqBlock* block );
+
+#define CV_ADJUST_EDGE_COUNT( count, seq )  \
+    ((count) -= ((count) == (seq)->total && !CV_IS_SEQ_CLOSED(seq)))
+
 #endif /*_IPCVGEOM_H_*/
 
 /* End of file. */
diff --git a/opencv/src/cv/_cvimgproc.h b/opencv/src/cv/_cvimgproc.h
new file mode 100644 (file)
index 0000000..ba57b49
--- /dev/null
@@ -0,0 +1,234 @@
+/*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.
+//
+//
+//                        Intel License Agreement
+//                For Open Source Computer Vision Library
+//
+// Copyright (C) 2000, Intel Corporation, 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 Intel Corporation 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*/
+
+#ifndef _CV_IMG_PROC_H_
+#define _CV_IMG_PROC_H_
+
+#define ICV_KERNEL_TYPE_MASK        (15<<16)
+#define ICV_GENERIC_KERNEL          (0<<16)
+#define ICV_SEPARABLE_KERNEL        (1<<16)
+#define ICV_BINARY_KERNEL           (2<<16)
+
+#define ICV_KERNEL_TYPE(flags)      ((flags) & ICV_KERNEL_TYPE_MASK)
+
+#define ICV_MAKE_SEPARABLE_KERNEL( x_type, y_type ) \
+    (ICV_SEPARABLE_KERNEL | ((x_type)&255) | (((y_type)&255) << 8))
+
+#define ICV_X_KERNEL_TYPE(flags)    ((flags) & 255)
+#define ICV_Y_KERNEL_TYPE(flags)    (((flags) >> 8) & 255)
+#define ICV_SYMMETRIC_KERNEL        1
+#define ICV_ASYMMETRIC_KERNEL       2
+
+#define ICV_1_2_1_KERNEL            (4*1+ICV_SYMMETRIC_KERNEL)
+#define ICV_m1_0_1_KERNEL           (4*2+ICV_ASYMMETRIC_KERNEL)
+#define ICV_1_m2_1_KERNEL           (4*3+ICV_SYMMETRIC_KERNEL)
+#define ICV_3_10_3_KERNEL           (4*4+ICV_SYMMETRIC_KERNEL)
+#define ICV_DEFAULT_GAUSSIAN_KERNEL ICV_SYMMETRIC_KERNEL
+#define ICV_CUSTOM_GAUSSIAN_KERNEL  (4+ICV_SYMMETRIC_KERNEL)
+
+#define ICV_MAKE_BINARY_KERNEL( shape ) \
+    (ICV_BINARY_KERNEL | (int)(shape))
+
+#define ICV_BINARY_KERNEL_SHAPE(flags) ((flags) & 255)
+
+typedef struct CvFilterState
+{
+    /* kernel data */
+    int ker_width;
+    int ker_height;
+    int ker_x;
+    int ker_y;
+    int kerType;
+    uchar *ker0;
+    uchar *ker1;
+    double divisor;
+
+    /* image data */
+    int max_width;
+    CvDataType dataType;
+    int channels;
+    int origin;
+
+    /* cyclic buffer */
+    char *buffer;
+    int buffer_step;
+    int crows;
+    char **rows;
+    char *tbuf;
+}
+CvFilterState;
+
+#define  CV_COPY( dst, src, len, idx ) \
+    for( (idx) = 0; (idx) < (len); (idx)++) (dst)[idx] = (src)[idx]
+
+#define  CV_SET( dst, val, len, idx )  \
+    for( (idx) = 0; (idx) < (len); (idx)++) (dst)[idx] = (val)
+
+/* 
+   Finds L1 norm between two blocks.
+   !!!! function doesn't perform EMMS !!!!
+*/
+int  icvCmpBlocksL1_8u_C1( const uchar* vec1, const uchar* vec2, int len );
+
+/* 
+   Finds squared L2 norm between two blocks.
+   !!!! function don't perform EMMS (except 32f flavor function) !!!!
+*/
+int64  icvCmpBlocksL2_8u_C1( const uchar* vec1, const uchar* vec2, int len );
+double icvCmpBlocksL2_32f_C1( const float* vec1, const float* vec2, int len );
+
+
+int64  icvSumPixels_8u_C1( const uchar* vec, int len );
+double icvSumPixels_32f_C1( const float* vec, int len );
+
+/* 
+   Calculates cross correlation for two blocks.
+   !!!! function doesn't perform EMMS !!!!
+*/
+int64  icvCrossCorr_8u_C1( const uchar* vec1, const uchar* vec2, int len );
+double icvCrossCorr_32f_C1( const float* vec1, const float* vec2, int len );
+
+/* performs convolution of 2d floating-point array with 3x1, 1x3 or separable 3x3 mask */
+void icvSepConvSmall3_32f( float* src, int src_step, float* dst, int dst_step,
+            CvSize src_size, const float* kx, const float* ky, float* buffer );
+
+CvStatus CV_STDCALL icvPyrDownBorder_8u_CnR( const uchar *src, int src_step, CvSize src_size,
+                                             uchar *dst, int dst_step, CvSize dst_size, int cn );
+
+CvStatus CV_STDCALL icvPyrDownBorder_32f_CnR( const float *src, int src_step, CvSize src_size,
+                                              float *dst, int dst_step, CvSize dst_size, int cn );
+
+CvStatus CV_STDCALL icvPyrDownBorder_64f_CnR( const double *src, int src_step, CvSize src_size,
+                                              double *dst, int dst_step, CvSize dst_size, int cn );
+
+CvStatus CV_STDCALL icvFilterInitAlloc( int roiWidth, CvDataType dataType, int channels,
+                    CvSize elSize, CvPoint elAnchor, const void* elData, int elementFlags,
+                    struct CvFilterState ** morphState );
+
+CvStatus CV_STDCALL icvFilterFree( struct CvFilterState ** morphState );
+
+CvStatus CV_STDCALL icvSobelInitAlloc( int roiwidth, int depth, int kerSize,
+                                       int origin, int dx, int dy,
+                                       struct _CvConvState** state );
+
+CvStatus CV_STDCALL icvSobel_8u16s_C1R( const uchar* pSrc, int srcStep,
+                                        short* pDst, int dstStep, CvSize* roiSize,
+                                        struct _CvConvState* state, int stage );
+
+CvStatus CV_STDCALL icvSobel_32f_C1R( const float* pSrc, int srcStep,
+                                      float* pDst, int dstStep, CvSize* roiSize,
+                                      struct _CvConvState* state, int stage );
+
+CvStatus CV_STDCALL icvBlurInitAlloc( int roiWidth, int depth, int kerSize,
+                                      struct _CvConvState** state );
+
+CvStatus CV_STDCALL icvBlur_8u16s_C1R( const uchar* pSrc, int srcStep,
+                                       short* pDst, int dstStep, CvSize* roiSize,
+                                       struct _CvConvState* state, int stage );
+
+CvStatus CV_STDCALL icvBlur_32f_CnR( const float* pSrc, int srcStep,
+                                     float* pDst, int dstStep, CvSize* roiSize,
+                                     struct _CvConvState* state, int stage );
+
+#define icvBlur_32f_C1R icvBlur_32f_CnR
+
+typedef struct
+{
+    uchar  b, g, r;
+}
+CvRGB8u;
+
+
+typedef struct
+{
+    uchar  b, g, r, a;
+}
+CvRGBA8u;
+
+
+typedef struct
+{
+    int  b, g, r;
+}
+CvRGB32s;
+
+
+typedef struct
+{
+    int  b, g, r, a;
+}
+CvRGBA32s;
+
+typedef struct
+{
+    float  b, g, r;
+}
+CvRGB32f;
+
+
+typedef struct
+{
+    float  b, g, r, a;
+}
+CvRGBA32f;
+
+
+#undef   CV_CALC_MAX
+#undef   CV_CALC_MIN
+
+#define  CV_CALC_MIN(a, b) (a) = CV_IMIN((a),(b))
+#define  CV_CALC_MAX(a, b) (a) = CV_IMAX((a),(b))
+
+#define CV_MORPH_ALIGN  4
+
+typedef CvStatus( CV_STDCALL* CvFilterFunc )( const void* src, int src_step,
+                                              void* dst, int dst_step,
+                                              CvSize* size, struct CvFilterState * state,
+                                              int stage );
+
+#define CvMorphFunc CvFilterFunc
+
+#define CV_WHOLE   0
+#define CV_START   1
+#define CV_END     2
+#define CV_MIDDLE  4
+
+#endif /*_CV_INTERNAL_H_*/
diff --git a/opencv/src/cv/_cvipp.h b/opencv/src/cv/_cvipp.h
new file mode 100644 (file)
index 0000000..fefaeed
--- /dev/null
@@ -0,0 +1,472 @@
+/*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.
+//
+//
+//                        Intel License Agreement
+//                For Open Source Computer Vision Library
+//
+// Copyright (C) 2000, Intel Corporation, 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 Intel Corporation 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*/
+
+#ifndef _CV_IPP_H_
+#define _CV_IPP_H_
+
+//////////////////////////////////////// Moments ////////////////////////////////////////
+
+#define IPCV_DEF_MOMENTS( flavor, srctype )                         \
+IPCVAPI_EX( CvStatus, icvMomentsInTile_##flavor##_CnCR,             \
+"ippiMomentsGray_" #flavor "_CnCR", CV_PLUGINS1(CV_PLUGIN_OPTCV),   \
+( const srctype* img, int step, CvSize size, int cn, int coi, double *moments ))
+
+IPCV_DEF_MOMENTS( 8u, uchar )
+IPCV_DEF_MOMENTS( 16u, ushort )
+IPCV_DEF_MOMENTS( 16s, short )
+IPCV_DEF_MOMENTS( 32f, float )
+IPCV_DEF_MOMENTS( 64f, double )
+
+#define IPCV_DEF_BINARY_MOMENTS( flavor, srctype )                  \
+IPCVAPI_EX( CvStatus, icvMomentsInTileBin_##flavor##_CnCR,          \
+"ippiMomentsBinary_" #flavor "_CnCR", CV_PLUGINS1(CV_PLUGIN_OPTCV), \
+( const srctype* img, int step, CvSize size, int cn, int coi, double *moments ))
+
+IPCV_DEF_BINARY_MOMENTS( 8u, uchar )
+IPCV_DEF_BINARY_MOMENTS( 16s, ushort )
+IPCV_DEF_BINARY_MOMENTS( 32f, int )
+IPCV_DEF_BINARY_MOMENTS( 64f, int64 )
+
+#undef IPCV_DEF_MOMENTS
+#undef IPCV_DEF_BINARY_MOMENTS
+
+/****************************************************************************************\
+*                                  Background differencing                               *
+\****************************************************************************************/
+
+/////////////////////////////////// Accumulation /////////////////////////////////////////
+
+#define IPCV_ACCUM( flavor, arrtype, acctype )                                      \
+IPCVAPI_EX( CvStatus, icvAddSquare_##flavor##_C1IR,                                 \
+    "ippiAddSquare_" #flavor "_C1IR", CV_PLUGINS1(CV_PLUGIN_IPPCV),                 \
+    ( const arrtype* src, int srcstep, acctype* dst, int dststep, CvSize size ))    \
+IPCVAPI_EX( CvStatus, icvAddProduct_##flavor##_C1IR,                                \
+    "ippiAddProduct_" #flavor "_C1IR", CV_PLUGINS1(CV_PLUGIN_IPPCV),                \
+    ( const arrtype* src1, int srcstep1, const arrtype* src2, int srcstep2,         \
+      acctype* dst, int dststep, CvSize size ))                                     \
+IPCVAPI_EX( CvStatus, icvAddWeighted_##flavor##_C1IR,                               \
+    "ippiAddWeighted_" #flavor "_C1IR", CV_PLUGINS1(CV_PLUGIN_IPPCV),               \
+    ( const arrtype* src, int srcstep, acctype* dst, int dststep,                   \
+      CvSize size, acctype alpha ))                                                 \
+                                                                                    \
+IPCVAPI_EX( CvStatus, icvAdd_##flavor##_C1IMR,                                      \
+    "ippiAdd_" #flavor "_C1IMR", CV_PLUGINS1(CV_PLUGIN_IPPCV),                      \
+    ( const arrtype* src, int srcstep, const uchar* mask, int maskstep,             \
+      acctype* dst, int dststep, CvSize size ))                                     \
+IPCVAPI_EX( CvStatus, icvAddSquare_##flavor##_C1IMR,                                \
+    "ippiAddSquare_" #flavor "_C1IMR", CV_PLUGINS1(CV_PLUGIN_IPPCV),                \
+    ( const arrtype* src, int srcstep, const uchar* mask, int maskstep,             \
+      acctype* dst, int dststep, CvSize size ))                                     \
+IPCVAPI_EX( CvStatus, icvAddProduct_##flavor##_C1IMR,                               \
+    "ippiAddProduct_" #flavor "_C1IMR", CV_PLUGINS1(CV_PLUGIN_IPPCV),               \
+    ( const arrtype* src1, int srcstep1, const arrtype* src2, int srcstep2,         \
+      const uchar* mask, int maskstep, acctype* dst, int dststep, CvSize size ))    \
+IPCVAPI_EX( CvStatus, icvAddWeighted_##flavor##_C1IMR,                              \
+    "ippiAddWeighted_" #flavor "_C1IMR", CV_PLUGINS1(CV_PLUGIN_IPPCV),              \
+    ( const arrtype* src, int srcstep, const uchar* mask, int maskstep,             \
+      acctype* dst, int dststep, CvSize size, acctype alpha ))                      \
+                                                                                    \
+IPCVAPI_EX( CvStatus, icvAdd_##flavor##_C3IMR,                                      \
+    "ippiAdd_" #flavor "_C3IMR", CV_PLUGINS2(CV_PLUGIN_IPPCV,CV_PLUGIN_OPTCV),      \
+    ( const arrtype* src, int srcstep, const uchar* mask, int maskstep,             \
+      acctype* dst, int dststep, CvSize size ))                                     \
+IPCVAPI_EX( CvStatus, icvAddSquare_##flavor##_C3IMR,                                \
+    "ippiAddSquare_" #flavor "_C3IMR", CV_PLUGINS2(CV_PLUGIN_IPPCV,CV_PLUGIN_OPTCV),\
+    ( const arrtype* src, int srcstep, const uchar* mask, int maskstep,             \
+      acctype* dst, int dststep, CvSize size ))                                     \
+IPCVAPI_EX( CvStatus, icvAddProduct_##flavor##_C3IMR,                               \
+    "ippiAddProduct_" #flavor "_C3IMR", CV_PLUGINS2(CV_PLUGIN_IPPCV,CV_PLUGIN_OPTCV),\
+    ( const arrtype* src1, int srcstep1, const arrtype* src2, int srcstep2,         \
+      const uchar* mask, int maskstep, acctype* dst, int dststep, CvSize size ))    \
+IPCVAPI_EX( CvStatus, icvAddWeighted_##flavor##_C3IMR,                              \
+    "ippiAddWeighted_" #flavor "_C3IMR", CV_PLUGINS2(CV_PLUGIN_IPPCV,CV_PLUGIN_OPTCV),\
+    ( const arrtype* src, int srcstep, const uchar* mask, int maskstep,             \
+      acctype* dst, int dststep, CvSize size, acctype alpha ))
+
+IPCVAPI_EX( CvStatus, icvAdd_8u32f_C1IR,
+    "ippiAdd_8u32f_C1IR", CV_PLUGINS1(CV_PLUGIN_IPPCV),
+    ( const uchar* src, int srcstep, float* dst, int dststep, CvSize size ))
+
+IPCV_ACCUM( 8u32f, uchar, float )
+IPCV_ACCUM( 32f, float, float )
+
+#undef IPCV_ACCUM
+
+/****************************************************************************************\
+*                                         Samplers                                       *
+\****************************************************************************************/
+
+////////////////////////////////////// GetRectSubPix ////////////////////////////////////////
+
+#define IPCV_GET_RECT_SUB_PIX( flavor, cn, srctype, dsttype )       \
+IPCVAPI_EX( CvStatus, icvGetRectSubPix_##flavor##_C##cn##R,         \
+"ippiGetRectSubPix_" #flavor "_C" #cn "R", CV_PLUGINS2(CV_PLUGIN_OPTCV,CV_PLUGIN_IPPCV),\
+( const srctype* src, int src_step, CvSize src_size,                \
+  dsttype* dst, int dst_step, CvSize win_size, CvPoint2D32f center ))
+
+IPCV_GET_RECT_SUB_PIX( 8u, 1, uchar, uchar )
+IPCV_GET_RECT_SUB_PIX( 8u32f, 1, uchar, float )
+IPCV_GET_RECT_SUB_PIX( 32f, 1, float, float )
+
+IPCV_GET_RECT_SUB_PIX( 8u, 3, uchar, uchar )
+IPCV_GET_RECT_SUB_PIX( 8u32f, 3, uchar, float )
+IPCV_GET_RECT_SUB_PIX( 32f, 3, float, float )
+
+#define IPCV_GET_QUADRANGLE_SUB_PIX( flavor, cn, srctype, dsttype ) \
+IPCVAPI_EX( CvStatus, icvGetQuadrangleSubPix_##flavor##_C##cn##R,   \
+"ippiGetQuadrangeRectSubPix_" #flavor "_C" #cn "R", CV_PLUGINS2(CV_PLUGIN_OPTCV,CV_PLUGIN_IPPCV),\
+( const srctype* src, int src_step, CvSize src_size,                \
+  dsttype* dst, int dst_step, CvSize win_size,                      \
+  const float *matrix, int fillOutliers, dsttype* fillValue ))
+
+IPCV_GET_QUADRANGLE_SUB_PIX( 8u, 1, uchar, uchar )
+IPCV_GET_QUADRANGLE_SUB_PIX( 8u32f, 1, uchar, float )
+IPCV_GET_QUADRANGLE_SUB_PIX( 32f, 1, float, float )
+
+IPCV_GET_QUADRANGLE_SUB_PIX( 8u, 3, uchar, uchar )
+IPCV_GET_QUADRANGLE_SUB_PIX( 8u32f, 3, uchar, float )
+IPCV_GET_QUADRANGLE_SUB_PIX( 32f, 3, float, float )
+
+#undef IPCV_GET_RECT_SUB_PIX
+#undef IPCV_GET_QUADRANGLE_SUB_PIX
+
+
+/****************************************************************************************\
+*                                        Pyramids                                        *
+\****************************************************************************************/
+
+IPCVAPI_EX( CvStatus, icvPyrUpGetBufSize_Gauss5x5, "ippiPyrUpGetBufSize_Gauss5x5", CV_PLUGINS1(CV_PLUGIN_IPPCV),
+        ( int roiWidth, CvDataType dataType, int channels, int* bufSize))
+
+IPCVAPI_EX( CvStatus, icvPyrDownGetBufSize_Gauss5x5, "ippiPyrDownGetBufSize_Gauss5x5", CV_PLUGINS1(CV_PLUGIN_IPPCV),
+        ( int roiWidth, CvDataType dataType, int channels, int* bufSize))
+
+#define ICV_PYRAMID( name, flavor, arrtype )                    \
+IPCVAPI_EX( CvStatus, icv##name##_##flavor##_C1R,               \
+"ippi" #name "_" #flavor "_C1R", CV_PLUGINS1(CV_PLUGIN_IPPCV),  \
+( const arrtype* pSrc, int srcStep, arrtype* pDst, int dstStep, \
+  CvSize roiSize, void* pBuffer ))                              \
+IPCVAPI_EX( CvStatus, icv##name##_##flavor##_C3R,               \
+"ippi" #name "_" #flavor "_C3R", CV_PLUGINS1(CV_PLUGIN_IPPCV),  \
+( const arrtype* pSrc, int srcStep, arrtype* pDst, int dstStep, \
+  CvSize roiSize, void* pBuffer ))
+
+ICV_PYRAMID( PyrUp_Gauss5x5, 8u, uchar )
+ICV_PYRAMID( PyrUp_Gauss5x5, 32f, float )
+ICV_PYRAMID( PyrUp_Gauss5x5, 64f, double )
+
+ICV_PYRAMID( PyrDown_Gauss5x5, 8u, uchar )
+ICV_PYRAMID( PyrDown_Gauss5x5, 32f, float )
+ICV_PYRAMID( PyrDown_Gauss5x5, 64f, double )
+
+#undef ICV_PYRAMID
+
+/****************************************************************************************\
+*                                      Morphology                                        *
+\****************************************************************************************/
+
+#define IPCV_MORPH_PLUGINS 0
+//#define IPCV_MORPH_PLUGINS CV_PLUGINS1(CV_PLUGIN_IPPCV)
+
+#define IPCV_MORPHOLOGY( name )                                             \
+IPCVAPI_EX(CvStatus, icv##name##_8u_C1R,                                    \
+           "ippi" #name "_8u_C1R", IPCV_MORPH_PLUGINS,                      \
+           ( const uchar* pSrc, int srcStep, uchar* pDst, int dstStep,      \
+             CvSize* roiSize, struct CvMorphState* state, int stage ))      \
+                                                                            \
+IPCVAPI_EX(CvStatus, icv##name##_8u_C3R,                                    \
+           "ippi" #name "_8u_C3R", IPCV_MORPH_PLUGINS,                      \
+           ( const uchar* pSrc, int srcStep, uchar* pDst, int dstStep,      \
+             CvSize* roiSize, struct CvMorphState* state, int stage ))      \
+                                                                            \
+IPCVAPI_EX(CvStatus, icv##name##_8u_C4R,                                    \
+           "ippi" #name "_8u_C4R", IPCV_MORPH_PLUGINS,                      \
+           ( const uchar* pSrc, int srcStep, uchar* pDst, int dstStep,      \
+             CvSize* roiSize, struct CvMorphState* state, int stage ))      \
+                                                                            \
+IPCVAPI_EX(CvStatus, icv##name##_32f_C1R,                                   \
+           "ippi" #name "_32f_C1R", IPCV_MORPH_PLUGINS,                     \
+           ( const int* pSrc, int srcStep, int* pDst, int dstStep,          \
+             CvSize* roiSize, struct CvMorphState* state, int stage ))      \
+                                                                            \
+IPCVAPI_EX(CvStatus, icv##name##_32f_C3R,                                   \
+           "ippi" #name "_32f_C3R", IPCV_MORPH_PLUGINS,                     \
+           ( const int* pSrc, int srcStep, int* pDst, int dstStep,          \
+             CvSize* roiSize, struct CvMorphState* state, int stage ))      \
+                                                                            \
+IPCVAPI_EX(CvStatus, icv##name##_32f_C4R,                                   \
+           "ippi" #name "_32f_C4R", IPCV_MORPH_PLUGINS,                     \
+           ( const int* pSrc, int srcStep, int* pDst, int dstStep,          \
+             CvSize* roiSize, struct CvMorphState* state, int stage ))
+
+
+IPCV_MORPHOLOGY( ErodeStrip_Rect )
+IPCV_MORPHOLOGY( ErodeStrip_Cross )
+IPCV_MORPHOLOGY( ErodeStrip )
+
+IPCV_MORPHOLOGY( DilateStrip_Rect )
+IPCV_MORPHOLOGY( DilateStrip_Cross )
+IPCV_MORPHOLOGY( DilateStrip )
+
+#undef IPCV_MORPHOLOGY
+
+IPCVAPI_EX(CvStatus, icvMorphologyInitAlloc, "ippiMorphologyInitAlloc", IPCV_MORPH_PLUGINS,
+    ( int roiWidth, CvDataType dataType, int channels, CvSize elSize, CvPoint elAnchor,
+      int elShape, int* elData, struct CvMorphState** morphState ))
+
+IPCVAPI_EX( CvStatus, icvMorphologyFree, "ippiMorphologyFree", IPCV_MORPH_PLUGINS,
+    ( struct CvMorphState** morphState ))
+
+#undef IPCV_MORPH_PLUGINS
+
+/****************************************************************************************\
+*                                  Motion Template                                       *
+\****************************************************************************************/
+
+IPCVAPI_EX( CvStatus, icvUpdateMotionHistory_8u32f_C1IR,
+    "ippiUpdateMotionHistory_8u32f_C1IR", CV_PLUGINS1(CV_PLUGIN_IPPCV),
+    ( const uchar* silIm, int silStep, float* mhiIm, int mhiStep,
+      CvSize size,float  timestamp, float  mhi_duration ))
+
+/****************************************************************************************\
+*                                      Template matching                                 *
+\****************************************************************************************/
+
+#define ICV_MATCHTEMPLATE_BUFSIZE( comp_type )                  \
+IPCVAPI_EX( CvStatus, icvMatchTemplateGetBufSize_##comp_type,   \
+    "ippiMatchTemplateGetBufSize_" #comp_type, 0/*CV_PLUGINS1(CV_PLUGIN_IPPCV)*/,         \
+    ( CvSize roiSize, CvSize templSize, CvDataType dataType, int* bufferSize ))
+
+ICV_MATCHTEMPLATE_BUFSIZE( SqDiff )
+ICV_MATCHTEMPLATE_BUFSIZE( SqDiffNormed )
+ICV_MATCHTEMPLATE_BUFSIZE( Corr )
+ICV_MATCHTEMPLATE_BUFSIZE( CorrNormed )
+ICV_MATCHTEMPLATE_BUFSIZE( Coeff )
+ICV_MATCHTEMPLATE_BUFSIZE( CoeffNormed )
+
+#undef ICV_MATCHTEMPLATE_BUFSIZE
+
+#define ICV_MATCHTEMPLATE( comp_type )                          \
+IPCVAPI_EX( CvStatus, icvMatchTemplate_##comp_type##_8u32f_C1R, \
+    "ippiMatchTemplate_" #comp_type "_8u32f_C1R", 0/*CV_PLUGINS1(CV_PLUGIN_IPPCV)*/,      \
+    (const uchar* pImage, int imageStep, CvSize roiSize,        \
+    const uchar* pTemplate, int templStep, CvSize templSize,    \
+    float* pResult, int resultStep, void* pBuffer ))            \
+                                                                \
+IPCVAPI_EX( CvStatus, icvMatchTemplate_##comp_type##_32f_C1R,   \
+    "ippiMatchTemplate_" #comp_type "_32f_C1R", 0/*CV_PLUGINS1(CV_PLUGIN_IPPCV)*/,        \
+    (const float* pImage, int imageStep, CvSize roiSize,        \
+    const float* pTemplate, int templStep, CvSize templSize,    \
+    float* pResult, int resultStep, void* pBuffer ))
+
+
+ICV_MATCHTEMPLATE( SqDiff )
+ICV_MATCHTEMPLATE( SqDiffNormed )
+ICV_MATCHTEMPLATE( Corr )
+ICV_MATCHTEMPLATE( CorrNormed )
+ICV_MATCHTEMPLATE( Coeff )
+ICV_MATCHTEMPLATE( CoeffNormed )
+
+#undef ICV_MATCHTEMPLATE
+
+/****************************************************************************************/
+/*                                Distance Transform                                    */
+/****************************************************************************************/
+
+IPCVAPI_EX(CvStatus, icvDistanceTransform_3x3_8u32f_C1R,
+    "ippiDistanceTransform_3x3_8u32f_C1R", CV_PLUGINS1(CV_PLUGIN_IPPCV),
+    ( const uchar* pSrc, int srcStep, float* pDst,
+      int dstStep, CvSize roiSize, float* pMetrics ))
+
+IPCVAPI_EX(CvStatus, icvDistanceTransform_5x5_8u32f_C1R,
+    "ippiDistanceTransform_5x5_8u32f_C1R", CV_PLUGINS1(CV_PLUGIN_IPPCV),
+    ( const uchar* pSrc, int srcStep, float* pDst,
+      int dstStep, CvSize roiSize, float* pMetrics ))
+
+IPCVAPI_EX( CvStatus, icvGetDistanceTransformMask,
+    "ippiGetDistanceTransformMask", CV_PLUGINS1(CV_PLUGIN_IPPCV),
+    ( int maskType, float* pMetrics ))
+
+/****************************************************************************************\
+*                                  Pyramid segmentation                                  *
+\****************************************************************************************/
+
+IPCVAPI_EX( CvStatus,  icvUpdatePyrLinks_8u_C1, "ippiUpdatePyrLinks_8u_C1", CV_PLUGINS1(CV_PLUGIN_OPTCV),
+           ( int layer, void* layer_data, CvSize size, void* parent_layer,
+             void* writer, float threshold, int is_last_iter, void* stub,
+             CvWriteNodeFunction ))
+
+IPCVAPI_EX( CvStatus,  icvUpdatePyrLinks_8u_C3, "ippiUpdatePyrLinks_8u_C3", CV_PLUGINS1(CV_PLUGIN_OPTCV),
+           ( int layer, void* layer_data, CvSize size, void* parent_layer,
+             void* writer, float threshold, int is_last_iter, void* stub,
+             CvWriteNodeFunction ))
+
+/****************************************************************************************\
+*                                      Lens undistortion                                 *
+\****************************************************************************************/
+
+IPCVAPI_EX( CvStatus, icvUnDistort1_8u_C1R,
+    "ippiUnDistort1_8u_C1R", CV_PLUGINS1(CV_PLUGIN_OPTCV),
+    ( const uchar* srcImage, int srcStep,
+    uchar* dstImage, int dstStep,
+    CvSize size, const float* intrMatrix,
+    const float* distCoeffs, int interToggle ))
+
+IPCVAPI_EX( CvStatus, icvUnDistort1_8u_C3R,
+    "ippiUnDistort1_8u_C3R", CV_PLUGINS1(CV_PLUGIN_OPTCV),
+    ( const uchar* srcImage, int srcStep,
+    uchar* dstImage, int dstStep,
+    CvSize size, const float* intrMatrix,
+    const float* distCoeffs, int interToggle ))
+
+IPCVAPI_EX( CvStatus, icvUnDistortEx_8u_C1R,
+    "ippiUnDistortEx_8u_C1R", CV_PLUGINS1(CV_PLUGIN_OPTCV),
+    ( const uchar* srcImage, int srcStep,
+    uchar* dstImage, int dstStep,
+    CvSize size, const float* intrMatrix,
+    const float* distCoeffs, int interToggle ))
+
+IPCVAPI_EX( CvStatus, icvUnDistortEx_8u_C3R,
+    "ippiUnDistortEx_8u_C3R", CV_PLUGINS1(CV_PLUGIN_OPTCV),    
+    ( const uchar* srcImage, int srcStep,
+    uchar* dstImage, int dstStep,
+    CvSize size, const float* intrMatrix,
+    const float* distCoeffs, int interToggle ))
+
+IPCVAPI_EX( CvStatus, icvUnDistortInit,
+    "ippiUnDistortInit", CV_PLUGINS1(CV_PLUGIN_OPTCV),    
+    ( int srcStep, int* map, int mapStep, CvSize size,
+      const float* intrMatrix, const float* distCoeffs,
+      int interToggle, int pixSize ))
+
+IPCVAPI_EX( CvStatus, icvUnDistort_8u_C1R,
+    "ippiUnDistort_8u_C1R", CV_PLUGINS1(CV_PLUGIN_OPTCV),        
+    ( const uchar* srcImage, int srcStep, const int* map, int mapstep,
+      uchar* dstImage, int dstStep, CvSize size, int interToggle ))
+
+IPCVAPI_EX( CvStatus, icvUnDistort_8u_C3R,
+    "ippiUnDistort_8u_C3R", CV_PLUGINS1(CV_PLUGIN_OPTCV),        
+    ( const uchar* srcImage, int srcStep, const int* map, int mapstep,
+      uchar* dstImage, int dstStep, CvSize size, int interToggle ))
+
+/****************************************************************************************\
+*                               Thresholding functions                                   *
+\****************************************************************************************/
+
+IPCVAPI_EX(CvStatus, icvThresh_8u_C1R, "ippiThresh_8u_C1R", CV_PLUGINS1(CV_PLUGIN_OPTCV),
+           ( const uchar*  src, int  src_step, uchar*  dst, int  dst_step,
+             CvSize  roi, int  thresh, uchar max_val, int type ))
+
+IPCVAPI_EX(CvStatus, icvThresh_32f_C1R, "ippiThresh_32f_C1R", CV_PLUGINS1(CV_PLUGIN_OPTCV),
+           ( const float*  src, int  src_step, float*  dst, int  dst_step,
+             CvSize  roi, float  thresh, float max_val, int type))
+
+#if 0
+
+/****************************************************************************************\
+*                                 Geometrical transforms                                 *
+\****************************************************************************************/
+
+IPCVAPI_EX( CvStatus, icvResize_NN_8u_C1R,
+    "ippiResize_NN_8u_C1R", CV_PLUGINS1(CV_PLUGIN_OPTCV),
+    ( const uchar* src, int srcstep, CvSize srcsize,
+      uchar* dst, int dststep, CvSize dstsize, int pix_size ))
+
+#define IPCV_RESIZE_BILINEAR( flavor, cn, arrtype )                     \
+IPCVAPI_EX( CvStatus, icvResize_Bilinear_##flavor##_C##cn##R,           \
+    "ippiResize_Bilinear_" #flavor "_C" #cn "R", CV_PLUGINS1(CV_PLUGIN_OPTCV),   \
+    ( const arrtype* src, int srcstep, CvSize srcsize,                  \
+      arrtype* dst, int dststep, CvSize dstsize ))
+
+IPCV_RESIZE_BILINEAR( 8u, 1, uchar )
+IPCV_RESIZE_BILINEAR( 8u, 2, uchar )
+IPCV_RESIZE_BILINEAR( 8u, 3, uchar )
+IPCV_RESIZE_BILINEAR( 8u, 4, uchar )
+
+IPCV_RESIZE_BILINEAR( 32f, 1, float )
+IPCV_RESIZE_BILINEAR( 32f, 2, float )
+IPCV_RESIZE_BILINEAR( 32f, 3, float )
+IPCV_RESIZE_BILINEAR( 32f, 4, float )
+
+/****************************************************************************************\
+*                                 Canny Edge Detector                                    *
+\****************************************************************************************/
+
+IPCVAPI( CvStatus, icvCannyGetSize, ( CvSize roiSize, int* bufferSize ))
+
+IPCVAPI( CvStatus, icvCanny_16s8u_C1R, ( const short* pSrcDx, int srcDxStep,
+                                         const short* pSrcDy, int srcDyStep,
+                                         uchar*  pDstEdges, int dstEdgeStep, 
+                                         CvSize roiSize, float  lowThresh,
+                                         float  highThresh, void* pBuffer ))
+/****************************************************************************************\
+*                                 Blur (w/o scaling)                                     *
+\****************************************************************************************/
+
+/********************* cxcore functions ***********************/
+
+IPCVAPI_EX( CvStatus, icvCopy_8u_C1R, "ippiCopy_8u_C1R", "ippi",
+                  ( const uchar* src, int src_step,
+                    uchar* dst, int dst_step, CvSize size ))
+
+IPCVAPI_EX( CvStatus, icvbFastArctan_32f, "ippibFastArctan_32f", CV_PLUGINS1(CV_PLUGIN_IPPCV),
+                                    ( const float* y, const float* x, float* angle, int len ))
+
+#define IPCV_MULTRANS( letter, flavor, arrtype )                \
+IPCVAPI_EX( CvStatus, icvMulTransposed##letter##_##flavor,      \
+            "ippiMulTransposed_" #letter "_" #flavor, CV_PLUGINS1(CV_PLUGIN_OPTCV),  \
+            ( const arrtype* src, int srcstep,                  \
+              arrtype* dst, int dststep, CvSize size ))
+
+IPCV_MULTRANS( R, 32f, float )
+IPCV_MULTRANS( R, 64f, double )
+IPCV_MULTRANS( L, 32f, float )
+IPCV_MULTRANS( L, 64f, double )
+
+#define IPCV_CVT_TO( flavor )                                                       \
+IPCVAPI_EX( CvStatus, icvCvtTo_##flavor##_C1R, "", "", ( const void* src, int step1,\
+                      void* dst, int step, CvSize size, int param ))
+IPCV_CVT_TO( 32f )
+
+#endif
+
+#endif /*_CV_PLUGIN_H_*/
+
index 5f97597e9e5872110e2ef9fca5e5a93a32199191..154bf790f915da0d2ff7ecd5c8e2a89c162ee55c 100644 (file)
 //
 //M*/
 
-/*
-To use the list of <type>, call DECLARE_LIST and IMPLEMENT_LIST with 
-the argument <type> like this:
-struct _X{...}
-typedef struct _X X;
-DECLARE_LIST(X);
-IMPLEMENT_LIST(X);
-These macros declare and implement data structures and functions which 
-work with the list
-*/
-
+#ifndef _CV_LIST_H_
+#define _CV_LIST_H_
 
 #include <stdlib.h>
-#include <memory.h>
 #include <assert.h>
 
+#define CV_FORCE_INLINE CV_INLINE
+
 #if !defined(_LIST_INLINE)
 #define _LIST_INLINE CV_FORCE_INLINE
 #endif /*_LIST_INLINE*/
@@ -140,7 +132,7 @@ typedef struct _list _CVLIST;
     {\
         if(l->m_buf_size < l->m_size && l->m_head_free.m_pos == NULL)\
         {\
-            *(void**)l->m_buffer = icvAlloc(l->m_buf_size*sizeof(element_type) + sizeof(void*));\
+            *(void**)l->m_buffer = cvAlloc(l->m_buf_size*sizeof(element_type) + sizeof(void*));\
             l->m_buffer = *(void**)l->m_buffer;\
             *(void**)l->m_buffer = NULL;\
             element = (element_type*)((char*)l->m_buffer + sizeof(void*));\
@@ -149,7 +141,7 @@ typedef struct _list _CVLIST;
         {\
             element = (element_type*)((char*)l->m_buffer + sizeof(void*)) + l->m_size - 1;\
         }\
-    };
+    }
 
 /* This macro adds 'element' to the list of free elements*/
 #define INSERT_FREE(element_type, l, element)\
@@ -166,9 +158,9 @@ typedef struct _list _CVLIST;
 #define IMPLEMENT_LIST(type, prefix)\
 _CVLIST* prefix##create_list_##type(long size)\
 {\
-    _CVLIST* pl = (_CVLIST*)icvAlloc(sizeof(_CVLIST));\
+    _CVLIST* pl = (_CVLIST*)cvAlloc(sizeof(_CVLIST));\
     pl->m_buf_size = size > 0 ? size : default_size;\
-    pl->m_first_buffer = icvAlloc(pl->m_buf_size*sizeof(ELEMENT_##type) + sizeof(void*));\
+    pl->m_first_buffer = cvAlloc(pl->m_buf_size*sizeof(ELEMENT_##type) + sizeof(void*));\
     pl->m_buffer = pl->m_first_buffer;\
     *(void**)pl->m_buffer = NULL;\
     pl->m_size = 0;\
@@ -176,7 +168,7 @@ _CVLIST* prefix##create_list_##type(long size)\
     pl->m_tail.m_pos = NULL;\
     pl->m_head_free.m_pos = NULL;\
     return pl;\
-};\
+}\
 void prefix##destroy_list_##type(_CVLIST* l)\
 {\
     void* cur = l->m_first_buffer;\
@@ -184,19 +176,19 @@ void prefix##destroy_list_##type(_CVLIST* l)\
     while(cur)\
     {\
         next = *(void**)cur;\
-        icvFree(&cur);\
+        cvFree((void**)&cur);\
         cur = next;\
     }\
-    icvFree(&l);\
-};\
+    cvFree((void**)&l);\
+}\
 CVPOS prefix##get_head_pos_##type(_CVLIST* l)\
 {\
     return l->m_head;\
-};\
+}\
 CVPOS prefix##get_tail_pos_##type(_CVLIST* l)\
 {\
     return l->m_tail;\
-};\
+}\
 type* prefix##get_next_##type(CVPOS* pos)\
 {\
     if(pos->m_pos)\
@@ -209,7 +201,7 @@ type* prefix##get_next_##type(CVPOS* pos)\
     {\
         return NULL;\
     }\
-};\
+}\
 type* prefix##get_prev_##type(CVPOS* pos)\
 {\
     if(pos->m_pos)\
@@ -222,7 +214,7 @@ type* prefix##get_prev_##type(CVPOS* pos)\
     {\
         return NULL;\
     }\
-};\
+}\
 int prefix##is_pos_##type(CVPOS pos)\
 {\
     return !!pos.m_pos;\
@@ -233,7 +225,7 @@ void prefix##clear_list_##type(_CVLIST* l)\
     l->m_tail.m_pos = NULL;\
     l->m_size = 0;\
     l->m_head_free.m_pos = NULL;\
-};\
+}\
 CVPOS prefix##add_head_##type(_CVLIST* l, type* data)\
 {\
     ELEMENT_##type* element;\
@@ -251,7 +243,7 @@ CVPOS prefix##add_head_##type(_CVLIST* l, type* data)\
     }\
     l->m_head.m_pos = element;\
     return l->m_head;\
-};\
+}\
 CVPOS prefix##add_tail_##type(_CVLIST* l, type* data)\
 {\
     ELEMENT_##type* element;\
@@ -269,7 +261,7 @@ CVPOS prefix##add_tail_##type(_CVLIST* l, type* data)\
     }\
     l->m_tail.m_pos = element;\
     return l->m_tail;\
-};\
+}\
 void prefix##remove_head_##type(_CVLIST* l)\
 {\
     ELEMENT_##type* element = ((ELEMENT_##type*)(l->m_head.m_pos));\
@@ -280,7 +272,7 @@ void prefix##remove_head_##type(_CVLIST* l)\
     l->m_head.m_pos = element->m_next;\
     INSERT_FREE(ELEMENT_##type, l, element);\
     l->m_size--;\
-};\
+}\
 void prefix##remove_tail_##type(_CVLIST* l)\
 {\
     ELEMENT_##type* element = ((ELEMENT_##type*)(l->m_tail.m_pos));\
@@ -291,7 +283,7 @@ void prefix##remove_tail_##type(_CVLIST* l)\
     l->m_tail.m_pos = element->m_prev;\
     INSERT_FREE(ELEMENT_##type, l, element);\
     l->m_size--;\
-};\
+}\
 CVPOS prefix##insert_after_##type(_CVLIST* l, CVPOS pos, type* data)\
 {\
     ELEMENT_##type* element;\
@@ -309,7 +301,7 @@ CVPOS prefix##insert_after_##type(_CVLIST* l, CVPOS pos, type* data)\
         l->m_tail.m_pos = element;\
     newpos.m_pos = element;\
     return newpos;\
-};\
+}\
 CVPOS prefix##insert_before_##type(_CVLIST* l, CVPOS pos, type* data)\
 {\
     ELEMENT_##type* element;\
@@ -327,7 +319,7 @@ CVPOS prefix##insert_before_##type(_CVLIST* l, CVPOS pos, type* data)\
         l->m_head.m_pos = element;\
     newpos.m_pos = element;\
     return newpos;\
-};\
+}\
 void prefix##remove_at_##type(_CVLIST* l, CVPOS pos)\
 {\
     ELEMENT_##type* element = ((ELEMENT_##type*)pos.m_pos);\
@@ -349,22 +341,33 @@ void prefix##remove_at_##type(_CVLIST* l, CVPOS pos)\
     }\
     INSERT_FREE(ELEMENT_##type, l, element);\
     l->m_size--;\
-};\
+}\
 void prefix##set_##type(CVPOS pos, type* data)\
 {\
     ELEMENT_##type* element = ((ELEMENT_##type*)(pos.m_pos));\
     memcpy(&(element->m_data), data, sizeof(data));\
-};\
+}\
 type* prefix##get_##type(CVPOS pos)\
 {\
     ELEMENT_##type* element = ((ELEMENT_##type*)(pos.m_pos));\
     return &(element->m_data);\
-};\
+}\
 int prefix##get_count_##type(_CVLIST* list)\
 {\
     return list->m_size;\
-};
+}
 
 #define DECLARE_AND_IMPLEMENT_LIST(type, prefix)\
-    DECLARE_LIST(type, prefix);\
-    IMPLEMENT_LIST(type, prefix);
+    DECLARE_LIST(type, prefix)\
+    IMPLEMENT_LIST(type, prefix)
+
+typedef struct __index
+{
+    int value;
+    float rho, theta;
+}
+_index;
+
+DECLARE_LIST( _index, h_ )
+
+#endif/*_CV_LIST_H_*/
index d7c2595b99fd157ca88db02546e19efd4514ba31..dae32ec9aeda6847ce1dc4df73bf0237416c9a72 100644 (file)
@@ -39,8 +39,8 @@
 //
 //M*/
 
-#ifndef _CVMATRIX_H_
-#define _CVMATRIX_H_
+#ifndef _CV_MATRIX_H_
+#define _CV_MATRIX_H_
 
 #define icvCopyVector( src, dst, len ) memcpy( (dst), (src), (len)*sizeof((dst)[0]))
 #define icvSetZero( dst, len ) memset( (dst), 0, (len)*sizeof((dst)[0]))
 #define icvCopyMatrix_32f( src, w, h, dst ) memcpy((dst),(src),(w)*(h)*sizeof(float))
 #define icvCopyMatrix_64d( src, w, h, dst ) memcpy((dst),(src),(w)*(h)*sizeof(double))
 
-#define icvCreateVector_32f( len )  (float*)icvAlloc( (len)*sizeof(float))
-#define icvCreateVector_64d( len )  (double*)icvAlloc( (len)*sizeof(double))
-#define icvCreateMatrix_32f( w, h )  (float*)icvAlloc( (w)*(h)*sizeof(float))
-#define icvCreateMatrix_64d( w, h )  (double*)icvAlloc( (w)*(h)*sizeof(double))
+#define icvCreateVector_32f( len )  (float*)cvAlloc( (len)*sizeof(float))
+#define icvCreateVector_64d( len )  (double*)cvAlloc( (len)*sizeof(double))
+#define icvCreateMatrix_32f( w, h )  (float*)cvAlloc( (w)*(h)*sizeof(float))
+#define icvCreateMatrix_64d( w, h )  (double*)cvAlloc( (w)*(h)*sizeof(double))
 
-#define icvDeleteVector( vec )  icvFree( (void**)&(vec) )
+#define icvDeleteVector( vec )  cvFree( (void**)&(vec) )
 #define icvDeleteMatrix icvDeleteVector
 
 #define icvAddMatrix_32f( src1, src2, dst, w, h ) \
     sqrt(icvDotProduct_64d( src, src, len ))
 
 
-#define icvMulTransMatrixR_32f( src, w, h, dst )          \
-    icvMulTransposedR_32f( (src), (w)*sizeof((src)[0]),   \
-                           (dst), (w)*sizeof((src)[0]),   \
-                           cvSize((w), (h)))
-
-#define icvMulTransMatrixR_64d( src, w, h, dst )          \
-    icvMulTransposedR_64f( (src), (w)*sizeof((src)[0]),   \
-                           (dst), (w)*sizeof((src)[0]),   \
-                           cvSize((w), (h)))
-
-#define icvMulTransMatrixL_32f( src, w, h, dst )          \
-    icvMulTransposedL_32f( (src), (w)*sizeof((src)[0]),   \
-                           (dst), (h)*sizeof((src)[0]),   \
-                           cvSize((w), (h)))
-
-#define icvMulTransMatrixL_64d( src, w, h, dst )          \
-    icvMulTransposedL_64f( (src), (w)*sizeof((src)[0]),   \
-                           (dst), (h)*sizeof((src)[0]),   \
-                           cvSize((w), (h)))
-
-
 #define icvDeleteMatrix icvDeleteVector
 
+#define icvCheckVector_64f( ptr, len )
+#define icvCheckVector_32f( ptr, len )
 
 CV_INLINE double icvSum_32f( const float* src, int len )
 {
@@ -364,6 +345,67 @@ CV_INLINE void icvMulMatrix_64d( const double* src1, int w1, int h1,
 
 #define icvDotProduct_64d icvDotProduct_64f
 
-#endif/*_CVMATRIX_H_*/
+
+CV_INLINE void icvInvertMatrix_64d( double* A, int n, double* invA )
+{
+    CvMat Am = cvMat( n, n, CV_64F, A );
+    CvMat invAm = cvMat( n, n, CV_64F, invA );
+
+    cvInvert( &Am, &invAm, CV_SVD );
+}
+
+CV_INLINE void icvMulTransMatrixR_64d( double* src, int width, int height, double* dst )
+{
+    CvMat srcMat = cvMat( height, width, CV_64F, src );
+    CvMat dstMat = cvMat( width, width, CV_64F, dst );
+
+    cvMulTransposed( &srcMat, &dstMat, 1 );
+}
+
+CV_INLINE void icvMulTransMatrixL_64d( double* src, int width, int height, double* dst )
+{
+    CvMat srcMat = cvMat( height, width, CV_64F, src );
+    CvMat dstMat = cvMat( height, height, CV_64F, dst );
+
+    cvMulTransposed( &srcMat, &dstMat, 0 );
+}
+
+CV_INLINE void icvMulTransMatrixR_32f( float* src, int width, int height, float* dst )
+{
+    CvMat srcMat = cvMat( height, width, CV_32F, src );
+    CvMat dstMat = cvMat( width, width, CV_32F, dst );
+
+    cvMulTransposed( &srcMat, &dstMat, 1 );
+}
+
+CV_INLINE void icvMulTransMatrixL_32f( float* src, int width, int height, float* dst )
+{
+    CvMat srcMat = cvMat( height, width, CV_32F, src );
+    CvMat dstMat = cvMat( height, height, CV_32F, dst );
+
+    cvMulTransposed( &srcMat, &dstMat, 0 );
+}
+
+CV_INLINE void icvCvt_32f_64d( const float* src, double* dst, int len )
+{
+    int i;
+    for( i = 0; i < len; i++ )
+        dst[i] = src[i];
+}
+
+CV_INLINE void icvCvt_64d_32f( const double* src, float* dst, int len )
+{
+    int i;
+    for( i = 0; i < len; i++ )
+        dst[i] = (float)src[i];
+}
+
+CvStatus CV_STDCALL icvJacobiEigens_32f(float *A, float *V,
+                                        float *E, int n, float eps);
+
+CvStatus CV_STDCALL icvJacobiEigens_64d(double *A, double *V,
+                                        double *E, int n, double eps);
+
+#endif/*_CV_MATRIX_H_*/
 
 /* End of file. */
index 78132c61ee890eac507a7974ed796de1dcd904c0..f725b75903d8f56677f76fc0ea9a21ce76088990 100644 (file)
 
 #include "_cv.h"
 
-#define  ICV_DEF_ACC_FUNC( name, srctype, dsttype, cvtmacro )                      \
-IPCVAPI_IMPL( CvStatus,                                                            \
-name,( const srctype *pSrc, int srcStep,                                           \
-      dsttype *pSrcDst, int srcDstStep,                                            \
-      CvSize roiSize ))                                                            \
-{                                                                                  \
-    for( ; roiSize.height--; (char*&)pSrc += srcStep,                              \
-                             (char*&)pSrcDst += srcDstStep )                       \
-    {                                                                              \
-        int x;                                                                     \
-                                                                                   \
-        for( x = 0; x <= roiSize.width - 4; x += 4 )                               \
-        {                                                                          \
-            dsttype t0 = pSrcDst[x] + cvtmacro(pSrc[x]);                           \
-            dsttype t1 = pSrcDst[x + 1] + cvtmacro(pSrc[x + 1]);                   \
-                                                                                   \
-            pSrcDst[x] = (dsttype)t0;                                              \
-            pSrcDst[x + 1] = (dsttype)t1;                                          \
-                                                                                   \
-            t0 = pSrcDst[x + 2] + cvtmacro(pSrc[x + 2]);                           \
-            t1 = pSrcDst[x + 3] + cvtmacro(pSrc[x + 3]);                           \
-                                                                                   \
-            pSrcDst[x + 2] = (dsttype)t0;                                          \
-            pSrcDst[x + 3] = (dsttype)t1;                                          \
-        }                                                                          \
-                                                                                   \
-        for( ; x < roiSize.width; x++ )                                            \
-        {                                                                          \
-            dsttype t0 = pSrcDst[x] + cvtmacro(pSrc[x]);                           \
-            pSrcDst[x] = (dsttype)t0;                                              \
-        }                                                                          \
-    }                                                                              \
-                                                                                   \
-    return CV_OK;                                                                  \
+#define  ICV_DEF_ACC_FUNC_BODY( srctype, dsttype, cvtmacro )                        \
+{                                                                                   \
+    for( ; roiSize.height--; (char*&)pSrc += srcStep,                               \
+                             (char*&)pSrcDst += srcDstStep )                        \
+    {                                                                               \
+        int x;                                                                      \
+                                                                                    \
+        for( x = 0; x <= roiSize.width - 4; x += 4 )                                \
+        {                                                                           \
+            dsttype t0 = pSrcDst[x] + cvtmacro(pSrc[x]);                            \
+            dsttype t1 = pSrcDst[x + 1] + cvtmacro(pSrc[x + 1]);                    \
+                                                                                    \
+            pSrcDst[x] = (dsttype)t0;                                               \
+            pSrcDst[x + 1] = (dsttype)t1;                                           \
+                                                                                    \
+            t0 = pSrcDst[x + 2] + cvtmacro(pSrc[x + 2]);                            \
+            t1 = pSrcDst[x + 3] + cvtmacro(pSrc[x + 3]);                            \
+                                                                                    \
+            pSrcDst[x + 2] = (dsttype)t0;                                           \
+            pSrcDst[x + 3] = (dsttype)t1;                                           \
+        }                                                                           \
+                                                                                    \
+        for( ; x < roiSize.width; x++ )                                             \
+        {                                                                           \
+            dsttype t0 = pSrcDst[x] + cvtmacro(pSrc[x]);                            \
+            pSrcDst[x] = (dsttype)t0;                                               \
+        }                                                                           \
+    }                                                                               \
+                                                                                    \
+    return CV_OK;                                                                   \
 }
 
-
-#define  ICV_DEF_ACCPROD_FUNC( name, srctype, dsttype, cvtmacro )                  \
-IPCVAPI_IMPL( CvStatus,                                                            \
-name,( const srctype *pSrc1, int src1Step,                                         \
-      const srctype *pSrc2, int src2Step,                                          \
-      dsttype *pSrcDst, int srcDstStep,                                            \
-      CvSize roiSize ))                                                            \
-{                                                                                  \
-    for( ; roiSize.height--; (char*&)pSrc1 += src1Step,                            \
-                             (char*&)pSrc2 += src2Step,                            \
-                             (char*&)pSrcDst += srcDstStep )                       \
-    {                                                                              \
-        int x;                                                                     \
-                                                                                   \
-        for( x = 0; x <= roiSize.width - 4; x += 4 )                               \
-        {                                                                          \
-            dsttype t0 = pSrcDst[x] + cvtmacro(pSrc1[x])*cvtmacro(pSrc2[x]);       \
-            dsttype t1 = pSrcDst[x+1] + cvtmacro(pSrc1[x+1])*cvtmacro(pSrc2[x+1]); \
-                                                                                   \
-            pSrcDst[x] = (dsttype)t0;                                              \
-            pSrcDst[x + 1] = (dsttype)t1;                                          \
-                                                                                   \
-            t0 = pSrcDst[x + 2] + cvtmacro(pSrc1[x + 2])*cvtmacro(pSrc2[x + 2]);   \
-            t1 = pSrcDst[x + 3] + cvtmacro(pSrc1[x + 3])*cvtmacro(pSrc2[x + 3]);   \
-                                                                                   \
-            pSrcDst[x + 2] = (dsttype)t0;                                          \
-            pSrcDst[x + 3] = (dsttype)t1;                                          \
-        }                                                                          \
-                                                                                   \
-        for( ; x < roiSize.width; x++ )                                            \
-        {                                                                          \
-            dsttype t0 = pSrcDst[x] + cvtmacro(pSrc1[x])*cvtmacro(pSrc2[x]);       \
-            pSrcDst[x] = (dsttype)t0;                                              \
-        }                                                                          \
-    }                                                                              \
-                                                                                   \
-    return CV_OK;                                                                  \
+#define  ICV_DEF_ACC_FUNC( name, srctype, dsttype, cvtmacro )                       \
+IPCVAPI_IMPL( CvStatus,                                                             \
+name,( const srctype *pSrc, int srcStep,                                            \
+      dsttype *pSrcDst, int srcDstStep,                                             \
+      CvSize roiSize ), (pSrc, srcStep, pSrcDst, srcDstStep, roiSize) )             \
+ICV_DEF_ACC_FUNC_BODY( srctype, dsttype, cvtmacro )
+
+#define  ICV_DEF_ACC_FUNC_STATIC( name, srctype, dsttype, cvtmacro )                \
+static CvStatus CV_STDCALL                                                          \
+name( const srctype *pSrc, int srcStep,                                             \
+      dsttype *pSrcDst, int srcDstStep,                                             \
+      CvSize roiSize )                                                              \
+ICV_DEF_ACC_FUNC_BODY( srctype, dsttype, cvtmacro )
+
+#define  ICV_DEF_ACCPROD_FUNC( name, srctype, dsttype, cvtmacro )                   \
+IPCVAPI_IMPL( CvStatus,                                                             \
+name,( const srctype *pSrc1, int src1Step, const srctype *pSrc2, int src2Step,      \
+      dsttype *pSrcDst, int srcDstStep, CvSize roiSize ),                           \
+      (pSrc1, src1Step, pSrc2, src2Step, pSrcDst, srcDstStep, roiSize) )            \
+{                                                                                   \
+    for( ; roiSize.height--; (char*&)pSrc1 += src1Step,                             \
+                             (char*&)pSrc2 += src2Step,                             \
+                             (char*&)pSrcDst += srcDstStep )                        \
+    {                                                                               \
+        int x;                                                                      \
+                                                                                    \
+        for( x = 0; x <= roiSize.width - 4; x += 4 )                                \
+        {                                                                           \
+            dsttype t0 = pSrcDst[x] + cvtmacro(pSrc1[x])*cvtmacro(pSrc2[x]);        \
+            dsttype t1 = pSrcDst[x+1] + cvtmacro(pSrc1[x+1])*cvtmacro(pSrc2[x+1]);  \
+                                                                                    \
+            pSrcDst[x] = (dsttype)t0;                                               \
+            pSrcDst[x + 1] = (dsttype)t1;                                           \
+                                                                                    \
+            t0 = pSrcDst[x + 2] + cvtmacro(pSrc1[x + 2])*cvtmacro(pSrc2[x + 2]);    \
+            t1 = pSrcDst[x + 3] + cvtmacro(pSrc1[x + 3])*cvtmacro(pSrc2[x + 3]);    \
+                                                                                    \
+            pSrcDst[x + 2] = (dsttype)t0;                                           \
+            pSrcDst[x + 3] = (dsttype)t1;                                           \
+        }                                                                           \
+                                                                                    \
+        for( ; x < roiSize.width; x++ )                                             \
+        {                                                                           \
+            dsttype t0 = pSrcDst[x] + cvtmacro(pSrc1[x])*cvtmacro(pSrc2[x]);        \
+            pSrcDst[x] = (dsttype)t0;                                               \
+        }                                                                           \
+    }                                                                               \
+                                                                                    \
+    return CV_OK;                                                                   \
 }
 
 
-#define  ICV_DEF_ACCWEIGHT_FUNC( name, srctype, dsttype, cvtmacro )                \
-IPCVAPI_IMPL( CvStatus,                                                            \
-name,( const srctype *pSrc, int srcStep,                                           \
-      dsttype *pSrcDst, int srcDstStep,                                            \
-      CvSize roiSize, dsttype alpha ))                                             \
-{                                                                                  \
-    for( ; roiSize.height--; (char*&)pSrc += srcStep,                              \
-                             (char*&)pSrcDst += srcDstStep )                       \
-    {                                                                              \
-        int x;                                                                     \
-                                                                                   \
-        for( x = 0; x <= roiSize.width - 4; x += 4 )                               \
-        {                                                                          \
-            dsttype t0 = pSrcDst[x] + alpha*(cvtmacro(pSrc[x]) - pSrcDst[x]);      \
-            dsttype t1 = pSrcDst[x+1] + alpha*(cvtmacro(pSrc[x+1]) - pSrcDst[x+1]);\
-                                                                                   \
-            pSrcDst[x] = (dsttype)t0;                                              \
-            pSrcDst[x + 1] = (dsttype)t1;                                          \
-                                                                                   \
-            t0 = pSrcDst[x + 2] + alpha*(cvtmacro(pSrc[x + 2]) - pSrcDst[x + 2]);  \
-            t1 = pSrcDst[x + 3] + alpha*(cvtmacro(pSrc[x + 3]) - pSrcDst[x + 3]);  \
-                                                                                   \
-            pSrcDst[x + 2] = (dsttype)t0;                                          \
-            pSrcDst[x + 3] = (dsttype)t1;                                          \
-        }                                                                          \
-                                                                                   \
-        for( ; x < roiSize.width; x++ )                                            \
-        {                                                                          \
-            dsttype t0 = pSrcDst[x] + alpha*(cvtmacro(pSrc[x]) - pSrcDst[x]);      \
-            pSrcDst[x] = (dsttype)t0;                                              \
-        }                                                                          \
-    }                                                                              \
-                                                                                   \
-    return CV_OK;                                                                  \
+#define  ICV_DEF_ACCWEIGHT_FUNC( name, srctype, dsttype, cvtmacro )                 \
+IPCVAPI_IMPL( CvStatus,                                                             \
+name,( const srctype *pSrc, int srcStep, dsttype *pSrcDst, int srcDstStep,          \
+      CvSize roiSize, dsttype alpha ),                                              \
+      (pSrc, srcStep, pSrcDst, srcDstStep, roiSize, alpha) )                        \
+{                                                                                   \
+    for( ; roiSize.height--; (char*&)pSrc += srcStep,                               \
+                             (char*&)pSrcDst += srcDstStep )                        \
+    {                                                                               \
+        int x;                                                                      \
+                                                                                    \
+        for( x = 0; x <= roiSize.width - 4; x += 4 )                                \
+        {                                                                           \
+            dsttype t0 = pSrcDst[x] + alpha*(cvtmacro(pSrc[x]) - pSrcDst[x]);       \
+            dsttype t1 = pSrcDst[x+1] + alpha*(cvtmacro(pSrc[x+1]) - pSrcDst[x+1]); \
+                                                                                    \
+            pSrcDst[x] = (dsttype)t0;                                               \
+            pSrcDst[x + 1] = (dsttype)t1;                                           \
+                                                                                    \
+            t0 = pSrcDst[x + 2] + alpha*(cvtmacro(pSrc[x + 2]) - pSrcDst[x + 2]);   \
+            t1 = pSrcDst[x + 3] + alpha*(cvtmacro(pSrc[x + 3]) - pSrcDst[x + 3]);   \
+                                                                                    \
+            pSrcDst[x + 2] = (dsttype)t0;                                           \
+            pSrcDst[x + 3] = (dsttype)t1;                                           \
+        }                                                                           \
+                                                                                    \
+        for( ; x < roiSize.width; x++ )                                             \
+        {                                                                           \
+            dsttype t0 = pSrcDst[x] + alpha*(cvtmacro(pSrc[x]) - pSrcDst[x]);       \
+            pSrcDst[x] = (dsttype)t0;                                               \
+        }                                                                           \
+    }                                                                               \
+                                                                                    \
+    return CV_OK;                                                                   \
 }
 
 
@@ -233,7 +241,8 @@ IPCVAPI_IMPL( CvStatus,
 name,( const srctype *pSrc, int srcStep,                                        \
       const uchar *pMask, int maskStep,                                         \
       dsttype *pSrcDst, int srcDstStep,                                         \
-      CvSize roiSize ))                                                         \
+      CvSize roiSize ),                                                         \
+      (pSrc, srcStep, pMask, maskStep, pSrcDst, srcDstStep, roiSize) )          \
 {                                                                               \
     int x;                                                                      \
     define_mask;                                                                \
@@ -344,7 +353,9 @@ name,( const srctype *pSrc1, int src1Step,
       const srctype *pSrc2, int src2Step,                                       \
       const uchar *pMask, int maskStep,                                         \
       dsttype *pSrcDst, int srcDstStep,                                         \
-      CvSize roiSize ))                                                         \
+      CvSize roiSize ),                                                         \
+      (pSrc1, src1Step, pSrc2, src2Step, pMask, maskStep,                       \
+       pSrcDst, srcDstStep, roiSize) )                                          \
 {                                                                               \
     int x;                                                                      \
     define_mask;                                                                \
@@ -462,7 +473,8 @@ IPCVAPI_IMPL( CvStatus,                                                        \
 name,( const srctype *pSrc, int srcStep,                                       \
       const uchar *pMask, int maskStep,                                        \
       dsttype *pSrcDst, int srcDstStep,                                        \
-      CvSize roiSize, dsttype alpha ))                                         \
+      CvSize roiSize, dsttype alpha ),                                         \
+      (pSrc, srcStep, pMask, maskStep, pSrcDst, srcDstStep, roiSize, alpha) )  \
 {                                                                              \
     int x;                                                                     \
     define_mask;                                                               \
@@ -541,55 +553,36 @@ ICV_DEF_ACCWEIGHTMASK_FUNC( icvAddWeighted_##flavor##_C3IMR, 3, srctype, dsttype
                              CV_NOP, CV_MUL, CV_DEFINE_ALPHA_MASK,                     \
                              CV_PREPARE_FLT_MASK )
 
-#define ICV_DECLARE_ACC_FUNC( flavor, srctype, dsttype )                    \
-    IPCVAPI( CvStatus, icvAdd_##flavor##_C1IR, ( const srctype*, int,       \
-                                                 dsttype*, int, CvSize ))
-
-ICV_DECLARE_ACC_FUNC( 8u64f, uchar, double )
-ICV_DECLARE_ACC_FUNC( 8s64f, char, double )
-ICV_DECLARE_ACC_FUNC( 16s32f, short, float )
-ICV_DECLARE_ACC_FUNC( 16s64f, short, double )
-ICV_DECLARE_ACC_FUNC( 32f64f, float, double )
-ICV_DECLARE_ACC_FUNC( 64f, double, double )
-
-
 ICV_DEF_ACC_FUNC( icvAdd_8u32f_C1IR, uchar, float, CV_8TO32F )
-ICV_DEF_ACC_FUNC( icvAdd_8u64f_C1IR, uchar, double, CV_8TO32F )
-ICV_DEF_ACC_FUNC( icvAdd_8s32f_C1IR, char, float, CV_8TO32F )
-ICV_DEF_ACC_FUNC( icvAdd_8s64f_C1IR, char, double, CV_8TO32F )
-ICV_DEF_ACC_FUNC( icvAdd_16s32f_C1IR, short, float, CV_8TO32F )
-ICV_DEF_ACC_FUNC( icvAdd_16s64f_C1IR, short, double, CV_8TO32F )
-ICV_DEF_ACC_FUNC( icvAdd_32f_C1IR, float, float, CV_NOP )
-ICV_DEF_ACC_FUNC( icvAdd_32f64f_C1IR, float, double, CV_NOP )
-ICV_DEF_ACC_FUNC( icvAdd_64f_C1IR, double, double, CV_NOP )
+ICV_DEF_ACC_FUNC_STATIC( icvAdd_8u64f_C1IR, uchar, double, CV_8TO32F )
+ICV_DEF_ACC_FUNC_STATIC( icvAdd_16s32f_C1IR, short, float, CV_8TO32F )
+ICV_DEF_ACC_FUNC_STATIC( icvAdd_16s64f_C1IR, short, double, CV_8TO32F )
+ICV_DEF_ACC_FUNC_STATIC( icvAdd_32f64f_C1IR, float, double, CV_NOP )
 
 ICV_DEF_ACC_ALL( 8u32f, uchar, float )
-ICV_DEF_ACC_ALL( 8s32f, char, float )
 ICV_DEF_ACC_ALL_FLT( 32f, float, float )
 
-
-void  icvInitAccTable( CvFuncTable* tabfl, CvFuncTable* tabdb,
-                       CvBigFuncTable* masktab )
+static void
+icvInitAccTable( CvFuncTable* tabfl, CvFuncTable* tabdb,
+                 CvBigFuncTable* masktab )
 {
     tabfl->fn_2d[CV_8U] = (void*)icvAdd_8u32f_C1IR;
-    tabfl->fn_2d[CV_8S] = (void*)icvAdd_8s32f_C1IR;
     tabfl->fn_2d[CV_16S] = (void*)icvAdd_16s32f_C1IR;
-    tabfl->fn_2d[CV_32F] = (void*)icvAdd_32f_C1IR;
+    tabfl->fn_2d[CV_32F] = 0;
 
     tabdb->fn_2d[CV_8U] = (void*)icvAdd_8u64f_C1IR;
-    tabdb->fn_2d[CV_8S] = (void*)icvAdd_8s64f_C1IR;
     tabdb->fn_2d[CV_16S] = (void*)icvAdd_16s64f_C1IR;
     tabdb->fn_2d[CV_32F] = (void*)icvAdd_32f64f_C1IR;
-    tabdb->fn_2d[CV_64F] = (void*)icvAdd_64f_C1IR;
+    tabdb->fn_2d[CV_64F] = 0;
 
     if( masktab )
     {
         masktab->fn_2d[CV_8UC1] = (void*)icvAdd_8u32f_C1IMR;
-        masktab->fn_2d[CV_8SC1] = (void*)icvAdd_8s32f_C1IMR;
+        masktab->fn_2d[CV_8SC1] = 0;
         masktab->fn_2d[CV_32FC1] = (void*)icvAdd_32f_C1IMR;
 
         masktab->fn_2d[CV_8UC3] = (void*)icvAdd_8u32f_C3IMR;
-        masktab->fn_2d[CV_8SC3] = (void*)icvAdd_8s32f_C3IMR;
+        masktab->fn_2d[CV_8SC3] = 0;
         masktab->fn_2d[CV_32FC3] = (void*)icvAdd_32f_C3IMR;
     }
 }
@@ -599,15 +592,15 @@ void  icvInitAccTable( CvFuncTable* tabfl, CvFuncTable* tabdb,
 static  void  icvInit##FUNCNAME##Table( CvFuncTable* tab, CvBigFuncTable* masktab ) \
 {                                                                                   \
     tab->fn_2d[CV_8U] = (void*)icv##FUNCNAME##_8u32f_C1IR;                          \
-    tab->fn_2d[CV_8S] = (void*)icv##FUNCNAME##_8s32f_C1IR;                          \
+    tab->fn_2d[CV_8S] = 0;                                                          \
     tab->fn_2d[CV_32F] = (void*)icv##FUNCNAME##_32f_C1IR;                           \
                                                                                     \
     masktab->fn_2d[CV_8UC1] = (void*)icv##FUNCNAME##_8u32f_C1IMR;                   \
-    masktab->fn_2d[CV_8SC1] = (void*)icv##FUNCNAME##_8s32f_C1IMR;                   \
+    masktab->fn_2d[CV_8SC1] = 0;                                                    \
     masktab->fn_2d[CV_32FC1] = (void*)icv##FUNCNAME##_32f_C1IMR;                    \
                                                                                     \
     masktab->fn_2d[CV_8UC3] = (void*)icv##FUNCNAME##_8u32f_C3IMR;                   \
-    masktab->fn_2d[CV_8SC3] = (void*)icv##FUNCNAME##_8s32f_C3IMR;                   \
+    masktab->fn_2d[CV_8SC3] = 0;                                                    \
     masktab->fn_2d[CV_32FC3] = (void*)icv##FUNCNAME##_32f_C3IMR;                    \
 }
 
@@ -650,6 +643,12 @@ cvAcc( const void* arr, void* sumarr, const void* maskarr )
             CV_ERROR( CV_BadCOI, "" );
     }
 
+    if( CV_ARE_TYPES_EQ( mat, sum ) && !mask )
+    {
+        CV_CALL( cvAdd( mat, sum, sum, 0 ));
+        EXIT;
+    }
+
     if( !CV_ARE_CNS_EQ( mat, sum ))
         CV_ERROR( CV_StsUnmatchedFormats, "" );
 
@@ -660,7 +659,7 @@ cvAcc( const void* arr, void* sumarr, const void* maskarr )
     if( !CV_ARE_SIZES_EQ( mat, sum ))
         CV_ERROR( CV_StsUnmatchedSizes, "" );
 
-    size = icvGetMatSize( mat );
+    size = cvGetMatSize( mat );
     type = CV_MAT_TYPE( mat->type );
 
     mat_step = mat->step;
@@ -755,7 +754,7 @@ cvSquareAcc( const void* arr, void* sq_sum, const void* maskarr )
     if( !CV_ARE_SIZES_EQ( mat, sum ))
         CV_ERROR( CV_StsUnmatchedSizes, "" );
 
-    size = icvGetMatSize( mat );
+    size = cvGetMatSize( mat );
     type = CV_MAT_TYPE( mat->type );
 
     mat_step = mat->step;
@@ -854,7 +853,7 @@ cvMultiplyAcc( const void* arrA, const void* arrB,
     if( !CV_ARE_SIZES_EQ( mat1, sum ) || !CV_ARE_SIZES_EQ( mat2, sum ))
         CV_ERROR( CV_StsUnmatchedSizes, "" );
 
-    size = icvGetMatSize( mat1 );
+    size = cvGetMatSize( mat1 );
     type = CV_MAT_TYPE( mat1->type );
 
     mat1_step = mat1->step;
@@ -963,7 +962,7 @@ cvRunningAvg( const void* arrY, void* arrU,
     if( !CV_ARE_SIZES_EQ( mat, sum ))
         CV_ERROR( CV_StsUnmatchedSizes, "" );
 
-    size = icvGetMatSize( mat );
+    size = cvGetMatSize( mat );
     type = CV_MAT_TYPE( mat->type );
 
     mat_step = mat->step;
index 8d638b65de07ec97774b4addab074840eb98a60c..0b8a05977c60a951d2e11ead399c8a10b01e5b75 100644 (file)
@@ -39,8 +39,6 @@
 //
 //M*/
 #include "_cv.h"
-#include <limits.h>
-#include "_cvdatastructs.h"
 
 /****************************************************************************************\
 *                                  Chain Approximation                                   *
@@ -62,7 +60,7 @@ icvApproximateChainTC89( CvChain*               chain,
                          int                    header_size,
                          CvMemStorage*          storage, 
                          CvSeq**                contour, 
-                         CvChainApproxMethod    method )
+                         int    method )
 {
     static const int abs_diff[] = { 1, 2, 3, 4, 3, 2, 1, 0, 1, 2, 3, 4, 3, 2, 1 };
 
@@ -104,7 +102,7 @@ icvApproximateChainTC89( CvChain*               chain,
 
     if( method > CV_CHAIN_APPROX_SIMPLE && buffer_size > (int)sizeof(local_buffer))
     {
-        buffer = (char *) icvAlloc( buffer_size );
+        buffer = (char *) cvAlloc( buffer_size );
         if( !buffer )
             return CV_OUTOFMEM_ERR;
     }
@@ -230,7 +228,8 @@ icvApproximateChainTC89( CvChain*               chain,
                 temp_num = dx1 * dx2 + dy1 * dy2;
                 temp_num =
                     (float) (temp_num /
-                             sqrt( (dx1 * dx1 + dy1 * dy1) * (dx2 * dx2 + dy2 * dy2) ));
+                             sqrt( ((double)dx1 * dx1 + (double)dy1 * dy1) *
+                                   ((double)dx2 * dx2 + (double)dy2 * dy2) ));
                 temp = (float) (temp_num + 1.1);
                 sk = *((int *) &temp);
 
@@ -409,7 +408,7 @@ exit_function:
     assert( writer.seq->total > 0 );
 
     if( buffer != local_buffer )
-        icvFree( &buffer );
+        cvFree( (void**)&buffer );
     return CV_OK;
 }
 
@@ -419,7 +418,7 @@ exit_function:
 CV_IMPL CvSeq*
 cvApproxChains( CvSeq*              src_seq,
                 CvMemStorage*       storage,
-                CvChainApproxMethod method,
+                int                 method,
                 double              /*parameter*/, 
                 int                 minimal_perimeter, 
                 int                 recursive )
@@ -432,9 +431,9 @@ cvApproxChains( CvSeq*              src_seq,
     __BEGIN__;
 
     if( !src_seq || !storage )
-        CV_ERROR_FROM_STATUS( CV_NULLPTR_ERR );
+        CV_ERROR( CV_StsNullPtr, "" );
     if( method > CV_CHAIN_APPROX_TC89_KCOS || method <= 0 || minimal_perimeter < 0 )
-        CV_ERROR_FROM_STATUS( CV_BADRANGE_ERR );
+        CV_ERROR( CV_StsOutOfRange, "" );
 
     while( src_seq != 0 )
     {
@@ -456,14 +455,14 @@ cvApproxChains( CvSeq*              src_seq,
                 break;
             default:
                 assert(0);
-                CV_ERROR_FROM_STATUS( CV_BADRANGE_ERR );
+                CV_ERROR( CV_StsOutOfRange, "" );
             }
 
             assert( contour );
 
             if( contour->total > 0 )
             {
-                cvContourBoundingRect( contour, 1 );
+                cvBoundingRect( contour, 1 );
 
                 contour->v_prev = parent;
                 contour->h_prev = prev_contour;
@@ -559,14 +558,14 @@ icvApproxPolyDP( CvSeq* src_contour, int header_size,
 
     if( !is_closed )
     {
-        right_slice.startIndex = count;
+        right_slice.start_index = count;
         end_pt = *(CvPoint*)(reader.ptr);
-        start_pt = *(CvPoint*)cvGetSeqElem( src_contour, -1, 0 );
+        start_pt = *(CvPoint*)cvGetSeqElem( src_contour, -1 );
 
         if( start_pt.x != end_pt.x || start_pt.y != end_pt.y )
         {
-            slice.startIndex = 0;
-            slice.endIndex = count - 1;
+            slice.start_index = 0;
+            slice.end_index = count - 1;
             cvSeqPush( stack, &slice );
         }
         else
@@ -579,13 +578,13 @@ icvApproxPolyDP( CvSeq* src_contour, int header_size,
     if( is_closed )
     {
         /* 1. Find approximately two farthest points of the contour */
-        right_slice.startIndex = 0;
+        right_slice.start_index = 0;
 
         for( i = 0; i < init_iters; i++ )
         {
             int j;
 
-            cvSetSeqReaderPos( &reader, right_slice.startIndex, 1 );
+            cvSetSeqReaderPos( &reader, right_slice.start_index, 1 );
             CV_READ_SEQ_ELEM( start_pt, reader );   /* read the first point */
 
             if( !is_float )
@@ -605,7 +604,7 @@ icvApproxPolyDP( CvSeq* src_contour, int header_size,
                     if( dist > max_dist )
                     {
                         max_dist = dist;
-                        right_slice.startIndex = j;
+                        right_slice.start_index = j;
                     }
                 }
 
@@ -629,7 +628,7 @@ icvApproxPolyDP( CvSeq* src_contour, int header_size,
                     if( dist > max_dist )
                     {
                         max_dist = dist;
-                        right_slice.startIndex = j;
+                        right_slice.start_index = j;
                     }
                 }
 
@@ -640,13 +639,13 @@ icvApproxPolyDP( CvSeq* src_contour, int header_size,
         /* 2. initialize the stack */
         if( !le_eps )
         {
-            slice.startIndex = cvGetSeqReaderPos( &reader );
-            slice.endIndex = right_slice.startIndex += slice.startIndex;
+            slice.start_index = cvGetSeqReaderPos( &reader );
+            slice.end_index = right_slice.start_index += slice.start_index;
 
-            right_slice.startIndex -= right_slice.startIndex >= count ? count : 0;
-            right_slice.endIndex = slice.startIndex;
-            if( right_slice.endIndex < right_slice.startIndex )
-                right_slice.endIndex += count;
+            right_slice.start_index -= right_slice.start_index >= count ? count : 0;
+            right_slice.end_index = slice.start_index;
+            if( right_slice.end_index < right_slice.start_index )
+                right_slice.end_index += count;
 
             cvSeqPush( stack, &right_slice );
             cvSeqPush( stack, &slice );
@@ -662,14 +661,14 @@ icvApproxPolyDP( CvSeq* src_contour, int header_size,
     {
         cvSeqPop( stack, &slice );
 
-        assert( slice.startIndex < slice.endIndex );
+        assert( slice.start_index < slice.end_index );
 
-        if( slice.endIndex - slice.startIndex != 1 )
+        if( slice.end_index - slice.start_index != 1 )
         {
-            cvSetSeqReaderPos( &reader, slice.endIndex );
+            cvSetSeqReaderPos( &reader, slice.end_index );
             CV_READ_SEQ_ELEM( end_pt, reader );
 
-            cvSetSeqReaderPos( &reader, slice.startIndex );
+            cvSetSeqReaderPos( &reader, slice.start_index );
             CV_READ_SEQ_ELEM( start_pt, reader );
 
             if( !is_float )
@@ -680,7 +679,7 @@ icvApproxPolyDP( CvSeq* src_contour, int header_size,
 
                 assert( (dx | dy) != 0 );
 
-                for( i = slice.startIndex + 1; i < slice.endIndex; i++ )
+                for( i = slice.start_index + 1; i < slice.end_index; i++ )
                 {
                     int dist;
 
@@ -692,7 +691,7 @@ icvApproxPolyDP( CvSeq* src_contour, int header_size,
                     if( dist > max_dist )
                     {
                         max_dist = dist;
-                        right_slice.startIndex = i;
+                        right_slice.start_index = i;
                     }
                 }
 
@@ -708,7 +707,7 @@ icvApproxPolyDP( CvSeq* src_contour, int header_size,
 
                 assert( ((int&)dx | (int&)dy) != 0 );
 
-                for( i = slice.startIndex + 1; i < slice.endIndex; i++ )
+                for( i = slice.start_index + 1; i < slice.end_index; i++ )
                 {
                     float dist;
                     CvPoint2D32f ptfl;
@@ -720,7 +719,7 @@ icvApproxPolyDP( CvSeq* src_contour, int header_size,
                     if( dist > max_dist )
                     {
                         max_dist = dist;
-                        right_slice.startIndex = i;
+                        right_slice.start_index = i;
                     }
                 }
 
@@ -731,7 +730,7 @@ icvApproxPolyDP( CvSeq* src_contour, int header_size,
         {
             le_eps = 1;
             /* read starting point */
-            cvSetSeqReaderPos( &reader, slice.startIndex );
+            cvSetSeqReaderPos( &reader, slice.start_index );
             CV_READ_SEQ_ELEM( start_pt, reader );
         }
 
@@ -741,8 +740,8 @@ icvApproxPolyDP( CvSeq* src_contour, int header_size,
         }
         else
         {
-            right_slice.endIndex = slice.endIndex;
-            slice.endIndex = right_slice.startIndex;
+            right_slice.end_index = slice.end_index;
+            slice.end_index = right_slice.start_index;
             cvSeqPush( stack, &right_slice );
             cvSeqPush( stack, &slice );
         }
@@ -762,8 +761,7 @@ icvApproxPolyDP( CvSeq* src_contour, int header_size,
 
 CV_IMPL CvSeq*
 cvApproxPoly( const void*  array, int  header_size,
-              CvMemStorage*  storage,
-              CvPolyApproxMethod  method, 
+              CvMemStorage*  storage, int  method, 
               double  parameter, int parameter2 )
 {
     CvSeq* dst_seq = 0;
index 909520f267d52a91eb83879464e37178eb79a62f..eba433a99fbd374ed8d471edcc0d7d473bd2fb6f 100644 (file)
@@ -87,7 +87,7 @@ IPCVAPI_IMPL( CvStatus, icvCalcContrastHist8uC1R, (uchar ** img, int step, CvSiz
 
     j = hist->dims[0] * hist->mdims[0];
 
-    int *n = (int *) icvAlloc( (long) hist->dims[0] * sizeof( int ));
+    int *n = (int *)cvAlloc( (size_t)hist->dims[0] * sizeof( int ));
 
     if( hist->type == CV_HIST_ARRAY )
     {
@@ -157,7 +157,7 @@ IPCVAPI_IMPL( CvStatus, icvCalcContrastHist8uC1R, (uchar ** img, int step, CvSiz
         }
     }
 
-    icvFree( &n );
+    cvFree( &n );
     return CV_NO_ERR;
 }
 
@@ -202,7 +202,7 @@ IPCVAPI_IMPL( CvStatus, icvCalcContrastHistMask8uC1R, (uchar ** img, int step,
 
     j = hist->dims[0] * hist->mdims[0];
 
-    int *n = (int *) icvAlloc( (long) hist->dims[0] * sizeof( int ));
+    int *n = (int *)cvAlloc( (size_t) hist->dims[0] * sizeof( int ));
 
     if( hist->type == CV_HIST_ARRAY )
     {
@@ -285,7 +285,7 @@ IPCVAPI_IMPL( CvStatus, icvCalcContrastHistMask8uC1R, (uchar ** img, int step,
         }
     }
 
-    icvFree( &n );
+    cvFree( &n );
     return CV_NO_ERR;
 }
 
index 7872f96dda26598a0293c358cc4fa2b2f2de8051..e820dfc67997d84ebc436f7152ebecf836be44c8 100644 (file)
@@ -40,7 +40,6 @@
 //M*/
 
 #include "_cv.h"
-#include "_cvdatastructs.h"
 
 /****************************************************************************************\
 
    
 \****************************************************************************************/
 
-static CvStatus icvCalcImageHomography( float* line, CvPoint3D32f * center,
-                                        float* intrinsic,
-                                        float* homography )
+CV_IMPL void
+cvCalcImageHomography( float* line, CvPoint3D32f* _center,
+                       float* _intrinsic, float* _homography )
 {
-    float norm_xy, norm_xz, xy_sina, xy_cosa, xz_sina, xz_cosa;
-    double plane_dist;
-    float rx[3], ry[3], rz[3];
-
-/*    IppmMatr32f r_trans;       */
-    float *r_trans;
-    float *r_p;
-    float ed[3][3] = { {1.f, 0.f, 0.f}, {0.f, 1.f, 0.f}, {0.f, 0.f, 1.f} };
-    float *sub, *inv_int;
-    float t_trans[3];
-    float nx1, nx2, ny2, nz1;
-
-    assert( line != NULL );
-    if( line == NULL )
-        return CV_NULLPTR_ERR;
+    CV_FUNCNAME( "cvCalcImageHomography" );
+
+    __BEGIN__;
+
+    double norm_xy, norm_xz, xy_sina, xy_cosa, xz_sina, xz_cosa, nx1, plane_dist;
+    float _ry[3], _rz[3], _r_trans[9];
+    CvMat rx = cvMat( 1, 3, CV_32F, line );
+    CvMat ry = cvMat( 1, 3, CV_32F, _ry );
+    CvMat rz = cvMat( 1, 3, CV_32F, _rz );
+    CvMat r_trans = cvMat( 3, 3, CV_32F, _r_trans );
+    CvMat center = cvMat( 3, 1, CV_32F, _center );
+
+    float _sub[9];
+    CvMat sub = cvMat( 3, 3, CV_32F, _sub );
+    float _t_trans[3];
+    CvMat t_trans = cvMat( 3, 1, CV_32F, _t_trans );
+
+    CvMat intrinsic = cvMat( 3, 3, CV_32F, _intrinsic );
+    CvMat homography = cvMat( 3, 3, CV_32F, _homography );
+
+    if( !line || !_center || !_intrinsic || !_homography )
+        CV_ERROR( CV_StsNullPtr, "" );
 
     norm_xy = cvSqrt( line[0] * line[0] + line[1] * line[1] );
     xy_cosa = line[0] / norm_xy;
@@ -76,109 +82,39 @@ static CvStatus icvCalcImageHomography( float* line, CvPoint3D32f * center,
     xz_cosa = line[0] / norm_xz;
     xz_sina = line[2] / norm_xz;
 
-/*  rotation around y axis  */
     nx1 = -xz_sina;
-    nz1 = xz_cosa;
-
-/*  rotation around z axis  */
-    nx2 = xy_cosa * nx1;
-    ny2 = xy_sina * nx1;
-
-/*  normal of the arm plane   */
-    norm_xz = cvSqrt( nx2 * nx2 + ny2 * ny2 + nz1 * nz1 );
-    rz[0] = nx2 / norm_xz;
-    rz[1] = ny2 / norm_xz;
-    rz[2] = nz1 / norm_xz;
-
-/*  new axe  x  */
-    rx[0] = line[0];
-    rx[1] = line[1];
-    rx[2] = line[2];
-/*  new axe  y  */
-    icvCrossProduct2L_32f( &rz[0], &rx[0], &ry[0] );
-    norm_xz = cvSqrt( ry[0] * ry[0] + ry[1] * ry[1] + ry[2] * ry[2] );
-    ry[0] /= norm_xz;
-    ry[1] /= norm_xz;
-    ry[2] /= norm_xz;
-
-/*  transpone rotation matrix    */
-    r_trans = icvCreateMatrix_32f( 3, 3 );
-    r_p = (float *) r_trans;
-    r_p[0] = rx[0];
-    r_p[1] = rx[1];
-    r_p[2] = rx[2];
-    r_p[3] = ry[0];
-    r_p[4] = ry[1];
-    r_p[5] = ry[2];
-    r_p[6] = rz[0];
-    r_p[7] = rz[1];
-    r_p[8] = rz[2];
-
-/*  calculate center distanse from arm plane  */
-    plane_dist = icvDotProduct_32f( (float *) center, &rz[0], 3 );
-
-    sub = icvCreateMatrix_32f( 3, 3 );
-
-/*   calculate ed - r_trans   */
-    icvSubMatrix_32f( &ed[0][0], r_trans, sub, 3, 3 );
-
-/*   calculate (ed - r_trans)*center   */
-//    t_trans =ippmCreateVector_32f (3);
-    icvTransformVector_32f( sub, (float *) center, &t_trans[0], 3, 3 );
-
-/*  calculate (t_trans*rz)/plane_dist   matrix  */
-
-    sub[0] = t_trans[0] * rz[0];
-    sub[1] = t_trans[0] * rz[1];
-    sub[2] = t_trans[0] * rz[2];
-    sub[3] = t_trans[1] * rz[0];
-    sub[4] = t_trans[1] * rz[1];
-    sub[5] = t_trans[1] * rz[2];
-    sub[6] = t_trans[2] * rz[0];
-    sub[7] = t_trans[2] * rz[1];
-    sub[8] = t_trans[2] * rz[2];
-
-    icvScaleVector_32f( sub, sub, 3, (float) (1. / plane_dist) );
-
-/*  calculate  r_trans + (t_trans*rz)/plane_dist   matrix   */
-    icvAddMatrix_32f( r_trans, sub, sub, 3, 3 );
-
-/*   calculate  intrinsic * (r_trans + (t_trans*rz)/plane_dist)   matrix   */
-    icvMulMatrix_32f( (float *) intrinsic, 3, 3, sub, 3, 3, sub );
-
-/*   calculate  Homography matrix   */
-    inv_int = icvCreateMatrix_32f( 3, 3 );
-    icvInvertMatrix_32f( (float *) intrinsic, 3, inv_int );
-    icvMulMatrix_32f( sub, 3, 3, inv_int, 3, 3, (float *) homography );
-
-    icvDeleteMatrix( r_trans );
-    icvDeleteMatrix( inv_int );
-    icvDeleteMatrix( sub );
-
-    return CV_OK;
 
-}
+    _rz[0] = (float)(xy_cosa * nx1);
+    _rz[1] = (float)(xy_sina * nx1);
+    _rz[2] = (float)xz_cosa;
+    cvScale( &rz, &rz, 1./cvNorm(&rz,0,CV_L2) );
 
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:     cvCalcImageHomography
-//    Purpose:  calculates the cooficients of the homography matrix
-//    Context:   
-//    Parameters: 
-//      line   - pointer to the input 3D-line
-//      center - pointer to the input hand center
-//      intrinsic - intrinsic camera parameters matrix
-//      homography - result homography matrix
-//      
-//    Notes:
-//F*/
-CV_IMPL void
-cvCalcImageHomography( float *line, CvPoint3D32f * center,
-                       float* intrinsic, float* homography )
-{
-    CV_FUNCNAME( "cvCalcImageHomography" );
-    __BEGIN__;
+    /*  new axe  y  */
+    cvCrossProduct( &rz, &rx, &ry );
+    cvScale( &ry, &ry, 1./cvNorm( &ry, 0, CV_L2 ) );
+
+    /*  transpone rotation matrix    */
+    memcpy( &_r_trans[0], line, 3*sizeof(float));
+    memcpy( &_r_trans[3], _ry, 3*sizeof(float));
+    memcpy( &_r_trans[6], _rz, 3*sizeof(float));
+
+    /*  calculate center distanse from arm plane  */
+    plane_dist = cvDotProduct( &center, &rz );
 
-    IPPI_CALL( icvCalcImageHomography( line, center, intrinsic, homography ));
+    /* calculate (I - r_trans)*center */
+    cvSetIdentity( &sub );
+    cvSub( &sub, &r_trans, &sub );
+    cvMatMul( &sub, &center, &t_trans ); 
+
+    cvMatMul( &t_trans, &rz, &sub );
+    cvScaleAdd( &sub, cvRealScalar(1./plane_dist), &r_trans, &sub ); /* ? */
+
+    cvMatMul( &intrinsic, &sub, &r_trans );
+    cvInvert( &intrinsic, &sub, CV_SVD );
+    cvMatMul( &r_trans, &sub, &homography );
 
     __END__;
 }
+
+/* End of file. */
+
index d136577180bdb30d3e37f8fd38af72c3140861fb..b06fe3b60c6f6a654d7a495b72f2fb00b3067432 100644 (file)
 //
 //M*/
 #include "_cv.h"
-#include "_cvgeom.h"
-#include "string.h"
-
-#include <limits.h>
 
 typedef struct CvContourEx
 {
@@ -117,12 +113,12 @@ cvFindChessBoardCornerGuesses( const void* arr, void* thresharr,
 
     if( CV_MAT_TYPE( img->type ) != CV_8UC1 ||
         CV_MAT_TYPE( thresh->type ) != CV_8UC1 )
-        CV_ERROR( CV_BadDepth, icvUnsupportedFormat );
+        CV_ERROR( CV_BadDepth, cvUnsupportedFormat );
 
     if( !CV_ARE_SIZES_EQ( img, thresh ))
         CV_ERROR( CV_StsUnmatchedSizes, "" );
 
-    size = icvGetMatSize( img );
+    size = cvGetMatSize( img );
 
     // 
     //   Create temporary storages.
@@ -135,7 +131,7 @@ cvFindChessBoardCornerGuesses( const void* arr, void* thresharr,
     min_size = cvRound( size.width*size.height * .03 * 0.03 );
 
     // empiric threshold level 
-    mean = cvMean( img );
+    mean = cvAvg( img ).val[0];
     thresh_level = cvRound( mean - 10 );
     thresh_level = MAX( thresh_level, 10 );
 
@@ -182,15 +178,18 @@ cvFindChessBoardCornerGuesses( const void* arr, void* thresharr,
                 CvPoint pt[4];
                 int i;
                 double d1, d2, p = cvContourPerimeter(dst_contour);
+                double dx, dy;
 
                 for( i = 0; i < 4; i++ )
                     pt[i] = *(CvPoint*)cvGetSeqElem( dst_contour, i );
 
-                d1 = sqrt((pt[0].x - pt[2].x)*(pt[0].x - pt[2].x) +
-                          (pt[0].y - pt[2].y)*(pt[0].y - pt[2].y));
+                dx = pt[0].x - pt[2].x;
+                dy = pt[0].y - pt[2].y;
+                d1 = sqrt( dx*dx + dy*dy );
 
-                d2 = sqrt((pt[1].x - pt[3].x)*(pt[1].x - pt[3].x) +
-                          (pt[1].y - pt[3].y)*(pt[1].y - pt[3].y));
+                dx = pt[1].x - pt[3].x;
+                dy = pt[1].y - pt[3].y;
+                d2 = sqrt( dx*dx + dy*dy );
 
                 if( d1 >= 0.25*p && d2 >= 0.25*p )
                 {
@@ -313,11 +312,11 @@ cvFindChessBoardCornerGuesses( const void* arr, void* thresharr,
         int dx, dy, denom;
         int i, j;
 
-        indices = (int *) icvAlloc( etalon_points * sizeof( int ));
+        indices = (int *)cvAlloc( etalon_points * sizeof( int ));
 
-        iPoints = (CvPoint *) icvAlloc( etalon_points * sizeof( CvPoint ));
-        ordered = (CvPoint *) icvAlloc( etalon_points * sizeof( CvPoint ));
-        hullpoints = (CvPoint *) icvAlloc( etalon_points * sizeof( CvPoint ));
+        iPoints = (CvPoint *)cvAlloc( etalon_points * sizeof( CvPoint ));
+        ordered = (CvPoint *)cvAlloc( etalon_points * sizeof( CvPoint ));
+        hullpoints = (CvPoint *)cvAlloc( etalon_points * sizeof( CvPoint ));
 
         for( i = 0; i < etalon_points; i++ )
         {
@@ -326,7 +325,7 @@ cvFindChessBoardCornerGuesses( const void* arr, void* thresharr,
 
         numRestPoints = etalon_points;
 
-#define IPCV_L2_DIST( pt1, pt2 )  \
+        #define IPCV_L2_DIST( pt1, pt2 )  \
         (dx = (pt1).x - (pt2).x, dy = (pt1).y - (pt2).y, dx*dx + dy*dy)
 
         // Find minimal distance between image etalon points 
@@ -378,7 +377,7 @@ cvFindChessBoardCornerGuesses( const void* arr, void* thresharr,
                                          hullpoints, ind_size, (CvSeq*)&hullcontour,
                                          &hullcontour_blk );
 
-                max_level = cvRound( sqrt( min_dist ));
+                max_level = cvRound( sqrt( (double)min_dist ));
 
                 // approximate convex hull. we should get quadrangle 
                 for( level = min_approx_level; level <= max_level; level++ )
@@ -586,13 +585,12 @@ cvFindChessBoardCornerGuesses( const void* arr, void* thresharr,
     //////////////////////////////////////////////
     //////////////////////////////////////////////
     //////////////////////////////////////////////
-    __CLEANUP__;
     __END__;
 
-    icvFree( &iPoints );
-    icvFree( &indices );
-    icvFree( &ordered );
-    icvFree( &hullpoints );
+    cvFree( (void**)&iPoints );
+    cvFree( (void**)&indices );
+    cvFree( (void**)&ordered );
+    cvFree( (void**)&hullpoints );
 
     // release storages 
     cvReleaseMemStorage( &storage1 );
index 52521874a19076ef68cb8ab7b3cacb3f80dd19a8..7d4e65658302a1beca8509fd65fb376d15c984f8 100644 (file)
 
 #include <stdio.h>
 
-#define icvCvt_32f_64d  icvCvt_32f64f
-#define icvCvt_64d_32f  icvCvt_64f32f
-
-CvStatus icvFindHomography( int numPoints,
+static CvStatus icvFindHomography( int numPoints,
                             CvSize imageSize,
                             CvPoint2D64d * imagePoints,
 
                             CvPoint2D64d * objectPoints, CvMatr64d Homography );
 
-CvStatus icvInitIntrinsicParams( int numImages,
+static CvStatus icvInitIntrinsicParams( int numImages,
                                  int *numPoints,
                                  CvSize imageSize,
                                  CvPoint2D64d * imagePoints,
@@ -66,19 +63,62 @@ CvStatus icvInitIntrinsicParams( int numImages,
 
                                  CvVect64d distortion, CvMatr64d cameraMatrix );
 
-CvStatus icvNormalizeImagePoints( int numPoints,
+static CvStatus icvNormalizeImagePoints( int numPoints,
                                   CvPoint2D64d * ImagePoints,
                                   CvVect64d focalLength,
                                   CvPoint2D64d principalPoint,
                                   CvVect64d distortion, CvPoint3D64d * resImagePoints );
 
-CvStatus icvRigidMotionTransform( int numPoints,
+static CvStatus icvRigidMotionTransform( int numPoints,
                                   CvPoint3D64d * objectPoints,
                                   CvVect64d rotVect, CvVect64d transVect,
                                   CvPoint3D64d * rigidMotionTrans,/* Output points */
                                   CvMatr64d derivMotionRot, CvMatr64d derivMotionTrans );
 
-CvStatus icvSVDSym_64d( CvMatr64d LtL, CvVect64d resV, int num );
+static CvStatus icvSVDSym_64d( CvMatr64d LtL, CvVect64d resV, int num );
+
+static CvStatus CV_STDCALL icvRodrigues_64d( CvMatr64d rotMatr, CvVect64d rotVect,
+                                      CvMatr64d Jacobian, int convType );
+
+static CvStatus CV_STDCALL icvRodrigues( CvMatr32f rotMatr, CvVect32f rotVect,
+                                  CvMatr32f Jacobian, int convType );
+
+
+static CvStatus CV_STDCALL
+icvComplexMult_64d( CvMatr64d srcMatr, CvMatr64d dstMatr, int width, int height )
+{
+    CvMat src = cvMat( height, width, CV_64FC1, srcMatr );
+    CvMat dst = cvMat( width, height, CV_64FC1, dstMatr );
+
+    CvMat* at = cvCreateMat( width, height, CV_64FC1 );
+    CvMat* ata = cvCreateMat( width, width, CV_64FC1 );
+    CvMat* inv_ata = cvCreateMat( width, width, CV_64FC1 );
+
+    cvMulTransposed( &src, ata, 1 );
+    cvInvert( ata, inv_ata, CV_SVD );
+
+#if 0
+    {
+        CvMat* t = cvCreateMat( width, width, CV_64FC1 );
+        CvMat* eye = cvCreateMat( width, width, CV_64FC1 );
+        cvSetIdentity( eye );
+        cvMatMul( ata, inv_ata, t );
+        double norm = cvNorm( eye, t, CV_L1 );
+        cvReleaseMat( &t );
+        cvReleaseMat( &eye );
+    }
+#endif
+
+    cvT( &src, at );
+    cvMatMul( inv_ata, at, &dst );
+
+    cvReleaseMat( &at );
+    cvReleaseMat( &ata );
+    cvReleaseMat( &inv_ata );
+
+    return CV_OK;
+}
+
 
 /****************************************************************************************/
 /*F//////////////////////////////////////////////////////////////////////////////////////
@@ -605,12 +645,45 @@ icvInitIntrinsicParams( int numImages,
 
 /*======================================================================================*/
 
-IPCVAPI_IMPL( CvStatus, icvRodrigues_64d, (CvMatr64d rotMatr,
-                                           CvVect64d rotVect,
-                                           CvMatr64d Jacobian, CvRodriguesType convType) )
+CvStatus CV_STDCALL icvRodrigues( CvMatr32f rotMatr32f, CvVect32f rotVect32f,
+                                  CvMatr32f Jacobian32f, int convType )
 {
 
+    double rotMatr64d[3 * 3];
+    double rotVect64d[3];
+    double Jacobian64d[3 * 9];
+    CvStatus status;
+
+    if( convType == CV_RODRIGUES_V2M )
+    {
+        icvCvt_32f_64d( rotVect32f, rotVect64d, 3 );
+    }
+    else
+    {
+        icvCvt_32f_64d( rotMatr32f, rotMatr64d, 3 * 3 );
+    }
+
+    status = icvRodrigues_64d( rotMatr64d, rotVect64d, Jacobian32f ? Jacobian64d : 0, convType );
 
+    if( convType == CV_RODRIGUES_V2M )
+    {
+        icvCvt_64d_32f( rotMatr64d, rotMatr32f, 3 * 3 );
+    }
+    else
+    {
+        icvCvt_64d_32f( rotVect64d, rotVect32f, 3 );
+    }
+
+    if( Jacobian32f )
+        icvCvt_64d_32f( Jacobian64d, Jacobian32f, 3 * 9 );
+
+    return status;
+
+}
+
+CvStatus CV_STDCALL icvRodrigues_64d( CvMatr64d rotMatr, CvVect64d rotVect,
+                                      CvMatr64d Jacobian, int convType )
+{
     double      eps = DBL_EPSILON;
     double      bigeps = 10e+20*eps;
     int         t;
@@ -836,8 +909,6 @@ IPCVAPI_IMPL( CvStatus, icvRodrigues_64d, (CvMatr64d rotMatr,
             
             if( matrS[0] < bigeps )/* norm(matr) is max of singular value of matr  */
             {
-                icvMulMatrix_64d(dvar1dtheta,1,2,dthetadR,9,1,dvardR + 9 * 3);
-                        
                 icvTrace_64d(rotMatr, 3, 3, &trace);
 
                 trace       = (trace - 1.0) / 2.0;
@@ -881,12 +952,11 @@ IPCVAPI_IMPL( CvStatus, icvRodrigues_64d, (CvMatr64d rotMatr,
 
                     if( Jacobian != 0 )
                     {
-                        dthetadtr = (double)(-1 / sqrt(1 - trace * trace));
+                        dthetadtr = (double)(-1 / sqrt(1. - trace * trace));
 
                         icvScaleVector_64d(dtrdR, dthetadR, 9, dthetadtr);
                         
-
-                        dvar1dtheta[0] = (double)(-vth*cos(theta)/sin(theta));
+                        dvar1dtheta[0] = (double)(-vth/tan(theta));
                         dvar1dtheta[1] = 1;
 
                         icvSetZero_64d(dvardR,9,5);
@@ -947,9 +1017,9 @@ IPCVAPI_IMPL( CvStatus, icvRodrigues_64d, (CvMatr64d rotMatr,
                     }
                     else
                     {
-                        tmp3[0] = (double)(sqrt((rotMatr[0 * 3 + 0] + 1.0f) * 0.5f));
-                        tmp3[1] = (double)(sqrt((rotMatr[1 * 3 + 1] + 1.0f) * 0.5f));
-                        tmp3[2] = (double)(sqrt((rotMatr[2 * 3 + 2] + 1.0f) * 0.5f));
+                        tmp3[0] = (double)(sqrt((rotMatr[0 * 3 + 0] + 1.) * 0.5));
+                        tmp3[1] = (double)(sqrt((rotMatr[1 * 3 + 1] + 1.) * 0.5));
+                        tmp3[2] = (double)(sqrt((rotMatr[2 * 3 + 2] + 1.) * 0.5));
 
                         if( rotMatr[0 * 3 + 1] < 0 )
                         {
@@ -991,6 +1061,72 @@ IPCVAPI_IMPL( CvStatus, icvRodrigues_64d, (CvMatr64d rotMatr,
     return CV_NO_ERR;
 }
 
+
+CV_IMPL void
+cvRodrigues( CvMat* mat, CvMat* vec, CvMat* jacobian,
+             int convType )
+{
+    CV_FUNCNAME( "cvRodrigues" );
+
+    __BEGIN__;
+
+    if( !CV_IS_MAT( mat ) || !CV_IS_MAT( vec ))
+        CV_ERROR( CV_StsBadArg, "" );
+
+    if( !CV_ARE_DEPTHS_EQ( mat, vec ))
+        CV_ERROR( CV_StsUnmatchedFormats, "" );
+
+    if( mat->width != 3 || mat->height != 3 )
+        CV_ERROR( CV_StsBadSize, "" );
+
+    if( vec->width*vec->height*CV_MAT_CN(vec->type) != 3 )
+        CV_ERROR( CV_StsBadSize, "" );
+
+    if( !CV_IS_MAT_CONT( mat->type & vec->type ))
+        CV_ERROR( CV_BadStep, "All the input/output arrays must be conitnuous" );
+
+    if( jacobian )
+    {
+        if( !CV_IS_MAT( jacobian ))
+            CV_ERROR( CV_StsBadArg, "" );
+
+        if( !CV_ARE_TYPES_EQ( mat, jacobian ))
+            CV_ERROR( CV_StsUnmatchedFormats, "" );
+
+        if( jacobian->width != 9 || jacobian->height != 3 )
+            CV_ERROR( CV_StsBadSize, "" );
+
+        if( !CV_IS_MAT_CONT( jacobian->type ))
+            CV_ERROR( CV_BadStep, "All the input/output arrays must be conitnuous" );
+    }
+
+    if( CV_MAT_TYPE( mat->type ) == CV_64FC1 )
+    {
+        IPPI_CALL( icvRodrigues_64d( mat->data.db, vec->data.db,
+                                     jacobian ? jacobian->data.db : 0, convType ));
+    }
+    else if( CV_MAT_TYPE( mat->type ) == CV_32FC1 )
+    {
+        IPPI_CALL( icvRodrigues( mat->data.fl, vec->data.fl,
+                                 jacobian ? jacobian->data.fl : 0, convType ));
+    }
+    else
+    {
+        CV_ERROR( CV_StsUnsupportedFormat, "" );
+    }
+
+    CV_CHECK_NANS( mat );
+    CV_CHECK_NANS( vec );
+    
+#ifdef  CV_CHECK_FOR_NANS    
+    if( jacobian )
+        CV_CHECK_NANS( jacobian );
+#endif
+
+    __END__;
+}
+
+
 /*======================================================================================*/
 
 CvStatus
@@ -1135,7 +1271,7 @@ icvRigidMotionTransform( int numPoints,
 
 /*======================================================================================*/
 
-CvStatus
+static CvStatus
 icvProjectPoints( int numPoints,
                   CvPoint3D64d * objectPoints,
                   CvVect64d rotVect,
@@ -1530,7 +1666,7 @@ icvProjectPoints( int numPoints,
 #define Sgn(x)  (x<0?-1:(x>0?1:0))
 
 /*======================================================================================*/
-CvStatus
+static CvStatus
 icvFindExtrinsicCameraParams_64d( int numPoints,
                                   CvSize imageSize,
                                   CvPoint2D64d * imagePoints,
@@ -1669,7 +1805,8 @@ icvFindExtrinsicCameraParams_64d( int numPoints,
 
         icvTransposeMatrix_64d( matrV, 3, 3, R_trans );
 
-       double r_norm = sqrt(R_trans[2]*R_trans[2] + R_trans[5]*R_trans[5]);
+       double r_norm = sqrt((double)R_trans[2]*R_trans[2] +
+                            (double)R_trans[5]*R_trans[5]);
 
         if( r_norm < 1e-6 )
         {
@@ -1770,7 +1907,12 @@ icvFindExtrinsicCameraParams_64d( int numPoints,
         tmp3f2[1] = Homography[4];
         tmp3f2[2] = Homography[7];
 
-        icvCrossProduct2L_64d( tmp3f1, tmp3f2, tmp3 );
+        {
+        CvMat mf1 = cvMat( 3, 1, CV_64F, tmp3f1 );
+        CvMat mf2 = cvMat( 3, 1, CV_64F, tmp3f2 );
+        CvMat m3 = cvMat( 3, 1, CV_64F, tmp3 );
+        cvCrossProduct( &mf1, &mf2, &m3 );
+        }
 
         rotMatr[0] = Homography[0];
         rotMatr[3] = Homography[3];
@@ -1910,8 +2052,7 @@ icvFindExtrinsicCameraParams_64d( int numPoints,
         /* Copy matrix elements (reshape) */
         for( i = 0; i < 9; i++ )
         {
-            CvScalar value;
-            value = cvGetAt( matrVm, i, 11 );
+            CvScalar value = cvGetAt( matrVm, i, 11 );
             cvSetAt(matrRR,value,i%3,i/3);
         }
         double det;
@@ -2137,7 +2278,7 @@ icvFindExtrinsicCameraParams_64d( int numPoints,
 }
 
 /*======================================================================================*/
-CvStatus
+static CvStatus
 icvCalibrateCamera_64d( int numImages,
                         int *numPoints,
                         CvSize imageSize,
@@ -2553,44 +2694,6 @@ static CvStatus icvFindExtrinsicCameraParams( int numPoints,
 
 /*======================================================================================*/
 
-IPCVAPI_IMPL( CvStatus, icvRodrigues, (CvMatr32f rotMatr32f,
-                                       CvVect32f rotVect32f,
-                                       CvMatr32f Jacobian32f, CvRodriguesType convType) )
-{
-
-    double rotMatr64d[3 * 3];
-    double rotVect64d[3];
-    double Jacobian64d[3 * 9];
-    CvStatus status;
-
-    if( convType == CV_RODRIGUES_V2M )
-    {
-        icvCvt_32f_64d( rotVect32f, rotVect64d, 3 );
-    }
-    else
-    {
-        icvCvt_32f_64d( rotMatr32f, rotMatr64d, 3 * 3 );
-    }
-
-    status = icvRodrigues_64d( rotMatr64d, rotVect64d, Jacobian32f ? Jacobian64d : 0, convType );
-
-    if( convType == CV_RODRIGUES_V2M )
-    {
-        icvCvt_64d_32f( rotMatr64d, rotMatr32f, 3 * 3 );
-    }
-    else
-    {
-        icvCvt_64d_32f( rotVect64d, rotVect32f, 3 );
-    }
-
-    if( Jacobian32f )
-        icvCvt_64d_32f( Jacobian64d, Jacobian32f, 3 * 9 );
-
-    return status;
-
-}
-
-
 CV_IMPL void
 cvCalibrateCamera( int numImages,
                    int *numPoints,
@@ -2700,7 +2803,8 @@ cvFindExtrinsicCameraParams_64d( int numPoints,
 }
 /*======================================================================================*/
 
-CvStatus icvProjectPointsSimple(  int numPoints,
+static CvStatus
+icvProjectPointsSimple(  int numPoints,
                 CvPoint3D64d * objectPoints,
                 CvVect64d rotMatr,
                 CvVect64d transVect,
index d381d6559ba64a2b4d6a009be599f6d6465e57a0..f5e0109eb24cd0b932e6a95783f52711dd52032c 100644 (file)
@@ -79,7 +79,7 @@ cvMeanShift( const void* imgProb, CvRect windowIn,
     CV_CALL( mat = cvGetMat( mat, &stub ));
 
     if( CV_MAT_CN( mat->type ) > 1 )
-        CV_ERROR( CV_BadNumChannels, icvUnsupportedFormat );
+        CV_ERROR( CV_BadNumChannels, cvUnsupportedFormat );
 
     if( windowIn.height <= 0 || windowIn.width <= 0 )
         CV_ERROR( CV_StsBadArg, "Input window has non-positive sizes" );
@@ -87,11 +87,11 @@ cvMeanShift( const void* imgProb, CvRect windowIn,
     if( !icvIsRectInRect( windowIn, cvRect( 0, 0, mat->width, mat->height )))
         CV_ERROR( CV_StsBadArg, "Initial window is not inside the image ROI" );
 
-    CV_CALL( criteria = icvCheckTermCriteria( criteria, 1., 100 ));
+    CV_CALL( criteria = cvCheckTermCriteria( criteria, 1., 100 ));
 
     eps = cvRound( criteria.epsilon * criteria.epsilon );
 
-    for( i = 0; i < criteria.maxIter; i++ )
+    for( i = 0; i < criteria.max_iter; i++ )
     {
         int dx, dy;
         double inv_m00;
index 325eb54a2847a30d00487d1260045b010aa28742..80dc4d97bfa84dbbde225bf666ecf6c01c8c6c34 100644 (file)
 
 #include "_cv.h"
 
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:      ippiCanny8uC1R     
-//    Purpose:   finds edges on image using J.Canny algorithm
-//    Context:   
-//    Parameters:
-//               src - source image,
-//               srcStep - its step,
-//               dst - destination binary image with edges,
-//               dstStep - its step,
-//               roi - size of ROI,
-//               opSize - size of Sobel operator aperture, 
-//               lowThreshold, 
-//               highThreshold - tresholds for hysteresis thresholding  
-//                 
-//    Returns:   
-//    Notes: image gradient magnitude has scale factor 2^(2*opSize-1)
-//           so user must choose appropriate lowThreshold and highThreshold 
-//           i.e. if real gradient magnitude is 1, then 3x3 Sobel used in this function 
-//           will compute 8 //opSize is 2//
-//F*/
-
-IPCVAPI_IMPL( CvStatus, icvCannyGetSize, (CvSize roi, int *bufferSize) )
+static CvStatus CV_STDCALL icvCannyGetSize( CvSize roi, int *bufferSize )
 {
     if( (roi.width <= 0) && (roi.height <= 0) )
         return CV_BADSIZE_ERR;
@@ -74,12 +53,11 @@ IPCVAPI_IMPL( CvStatus, icvCannyGetSize, (CvSize roi, int *bufferSize) )
 }
 
 
-IPCVAPI_IMPL( CvStatus,
-icvCanny_16s8u_C1R, ( const short *pDX, int dxStep,
-                      const short *pDY, int dyStep,
-                      uchar *dst, int dststep,
-                      CvSize roi, float lowThreshold,
-                      float highThreshold, void *buffer ))
+static CvStatus CV_STDCALL icvCanny_16s8u_C1R( const short *pDX, int dxStep,
+                                               const short *pDY, int dyStep,
+                                               uchar *dst, int dststep,
+                                               CvSize roi, float lowThreshold,
+                                               float highThreshold, void *buffer )
 {
     static const int sec_tab[] = { 1, 3, 0, 0, 2, 2, 2, 2 };
 
@@ -128,13 +106,10 @@ icvCanny_16s8u_C1R, ( const short *pDX, int dxStep,
             int y = pDY[j];
             int s = x ^ y;
 
-            int m = (x >= 0) - 1;
-            x = (x ^ m) - m;
+            x = abs(x);
+            y = abs(y);
 
-            m = (y >= 0) - 1;
-            y = (y ^ m) - m;
-
-            m = x + y;
+            int m = x + y;
 
             /* estimating sector and magnitude */
             if( m > low )
@@ -201,9 +176,13 @@ icvCanny_16s8u_C1R, ( const short *pDX, int dxStep,
             
                 if( val )
                 {
-                    int delta = mshift[sector[j]];
-
-                    if( val >= center[delta] && val >= (center[-delta] & INT_MAX))
+                    int sec = sector[j];
+                    int delta = mshift[sec];
+                    int b = center[delta];
+                    
+                    if( val > b && val > (center[-delta] & INT_MAX) ||
+                        sec == 0 && val == b ||
+                        sec == 2 && val == b )
                     {
                         if( val > high )
                             PUSH2( dst + j, mag + j );
@@ -229,37 +208,21 @@ icvCanny_16s8u_C1R, ( const short *pDX, int dxStep,
                 *d = 255;
 
                 if( m[-1] > low && d[-1] == 0 )
-                {
                     PUSH2( d - 1, m - 1 );
-                }
-                else if( m[1] > low && d[1] == 0 )
-                {
+                if( m[1] > low && d[1] == 0 )
                     PUSH2( d + 1, m + 1 );
-                }
-                else if( m[-magstep-1] > low && d[-dststep-1] == 0 )
-                {
+                if( m[-magstep-1] > low && d[-dststep-1] == 0 )
                     PUSH2( d - dststep - 1, m - magstep - 1 );
-                }
-                else if( m[-magstep] > low && d[-dststep] == 0 )
-                {
+                if( m[-magstep] > low && d[-dststep] == 0 )
                     PUSH2( d - dststep, m - magstep );
-                }
-                else if( m[-magstep+1] > low && d[-dststep+1] == 0 )
-                {
+                if( m[-magstep+1] > low && d[-dststep+1] == 0 )
                     PUSH2( d - dststep + 1, m - magstep + 1 );
-                }
-                else if( m[magstep-1] > low && d[dststep-1] == 0 )
-                {
+                if( m[magstep-1] > low && d[dststep-1] == 0 )
                     PUSH2( d + dststep - 1, m + magstep - 1 );
-                }
-                else if( m[magstep] > low && d[dststep] == 0 )
-                {
+                if( m[magstep] > low && d[dststep] == 0 )
                     PUSH2( d + dststep, m + magstep );
-                }
-                else if( m[magstep+1] > low && d[dststep+1] == 0 )
-                {
+                if( m[magstep+1] > low && d[dststep+1] == 0 )
                     PUSH2( d + dststep + 1, m + magstep + 1 );
-                }
             }
         }
     }
@@ -286,7 +249,7 @@ cvCanny( const void* srcarr, void* dstarr,
     CvMat srcstub, *src = (CvMat*)srcarr;
     CvMat dststub, *dst = (CvMat*)dstarr;
     CvSize src_size;
-    int buf_size, origin = 0;
+    int buf_size = 0, origin = 0;
 
     CV_CALL( src = cvGetMat( src, &srcstub ));
     CV_CALL( dst = cvGetMat( dst, &dststub ));
@@ -312,7 +275,7 @@ cvCanny( const void* srcarr, void* dstarr,
     if( (aperture_size & 1) == 0 || aperture_size < 3 || aperture_size > 7 )
         CV_ERROR( CV_StsBadFlag, "" );
 
-    src_size = icvGetMatSize( src );
+    src_size = cvGetMatSize( src );
 
     dx = cvCreateMat( src_size.height, src_size.width, CV_16SC1 );
     dy = cvCreateMat( src_size.height, src_size.width, CV_16SC1 );
index 27b41fd08ca4173a1ee3695f462238e9c890bbed..6961b64a6ed831d56d3a53c6378104758eced11a 100644 (file)
@@ -45,7 +45,7 @@
 // */
 
 /********************************* COPYRIGHT NOTICE *******************************\
-  The function for RGB2Lab conversion is based on the MATLAB code
+  The function for RGB to Lab conversion is based on the MATLAB script
   RGB2Lab.m translated by Mark Ruzon from C code by Yossi Rubner, 23 September 1997.
   See the page [http://vision.stanford.edu/~ruzon/software/rgblab.html]
 \**********************************************************************************/
 
 #include "_cv.h"
 
-#define  ICV_CVT_BGR2RGB( src, dst )                        \
+#define  ICV_CVT_BGR2RGB( arrtype, src, dst )               \
 {                                                           \
-    uchar t0 = (src)[0], t1 = (src)[1], t2 = (src)[2];      \
+    arrtype t0 = (src)[0], t1 = (src)[1], t2 = (src)[2];    \
                                                             \
     (dst)[0] = t2;                                          \
     (dst)[1] = t1;                                          \
     (dst)[2] = t0;                                          \
 }
 
-#define  ICV_CVT_RGBA2BGR  ICV_CVT_BGR2RGB
+#define  ICV_CVT_BGR2RGB_8U( src, dst )   ICV_CVT_BGR2RGB( uchar, src, dst )
+#define  ICV_CVT_BGR2RGB_32F( src, dst )  ICV_CVT_BGR2RGB( float, src, dst )
 
-#define  ICV_CVT_BGR2BGRA( src, dst )                       \
+#define  ICV_CVT_RGBA2BGR_8U  ICV_CVT_BGR2RGB_8U
+#define  ICV_CVT_RGBA2BGR_32F  ICV_CVT_BGR2RGB_32F
+
+#define  ICV_CVT_BGR2BGRA( arrtype, src, dst )              \
 {                                                           \
-    uchar t0 = (src)[0], t1 = (src)[1], t2 = (src)[2];      \
+    arrtype t0 = (src)[0], t1 = (src)[1], t2 = (src)[2];    \
                                                             \
     (dst)[0] = t0;                                          \
     (dst)[1] = t1;                                          \
     (dst)[3] = 0;                                           \
 }
 
-#define  ICV_CVT_BGRA2BGR( src, dst )                       \
+#define  ICV_CVT_BGR2BGRA_8U( src, dst )   ICV_CVT_BGR2BGRA( uchar, src, dst )
+#define  ICV_CVT_BGR2BGRA_32F( src, dst )  ICV_CVT_BGR2BGRA( float, src, dst )
+
+#define  ICV_CVT_BGRA2BGR( arrtype, src, dst )              \
 {                                                           \
-    uchar t0 = (src)[0], t1 = (src)[1], t2 = (src)[2];      \
+    arrtype t0 = (src)[0], t1 = (src)[1], t2 = (src)[2];    \
                                                             \
     (dst)[0] = t0;                                          \
     (dst)[1] = t1;                                          \
     (dst)[2] = t2;                                          \
 }
 
-#define  ICV_CVT_BGR2RGBA( src, dst )                       \
+#define  ICV_CVT_BGRA2BGR_8U( src, dst )  ICV_CVT_BGRA2BGR( uchar, src, dst )
+#define  ICV_CVT_BGRA2BGR_32F( src, dst )  ICV_CVT_BGRA2BGR( float, src, dst )
+
+#define  ICV_CVT_BGR2RGBA( arrtype, src, dst )              \
 {                                                           \
-    uchar t0 = (src)[0], t1 = (src)[1], t2 = (src)[2];      \
+    arrtype t0 = (src)[0], t1 = (src)[1], t2 = (src)[2];    \
                                                             \
     (dst)[0] = t2;                                          \
     (dst)[1] = t1;                                          \
     (dst)[3] = 0;                                           \
 }
 
+#define  ICV_CVT_BGR2RGBA_8U( src, dst )  ICV_CVT_BGR2RGBA( uchar, src, dst )
+#define  ICV_CVT_BGR2RGBA_32F( src, dst )  ICV_CVT_BGR2RGBA( float, src, dst )
 
-#define  ICV_CVT_BGRA2RGBA( src, dst )                                  \
+#define  ICV_CVT_BGRA2RGBA( arrtype, src, dst )                         \
 {                                                                       \
-    uchar t0 = (src)[0], t1 = (src)[1], t2 = (src)[2], t3 = (src)[3];   \
+    arrtype t0 = (src)[0], t1 = (src)[1], t2 = (src)[2], t3 = (src)[3]; \
                                                                         \
     (dst)[0] = t2;                                                      \
     (dst)[1] = t1;                                                      \
     (dst)[3] = t3;                                                      \
 }
 
+#define  ICV_CVT_BGRA2RGBA_8U( src, dst )  ICV_CVT_BGRA2RGBA( uchar, src, dst )
+#define  ICV_CVT_BGRA2RGBA_32F( src, dst )  ICV_CVT_BGRA2RGBA( float, src, dst )
 
-#define ICV_CVT_BGR2BGR565( src, dst )                      \
-{                                                           \
-    int  t = ((src)[0] >> 3)|(((src)[1] & ~3) << 3)|        \
-             (((src)[2] & ~7) << 8);                        \
-                                                            \
-    ((ushort*)(dst))[0] = (ushort)t;                        \
-}
+/******************************** RGB: 565 <==> 888/8888 ************************/
 
-
-#define ICV_CVT_RGB2BGR565( src, dst )                      \
+#define ICV_CVT_RGB2BGR565_8U_EX( src, dst, blue_ofs )      \
 {                                                           \
-    int  t = ((src)[2] >> 3)|(((src)[1] & ~3) << 3)|        \
-             (((src)[0] & ~7) << 8);                        \
+    int  t = ((src)[blue_ofs] >> 3)|(((src)[1] & ~3) << 3)| \
+             (((src)[blue_ofs ^ 2] & ~7) << 8);             \
                                                             \
     ((ushort*)(dst))[0] = (ushort)t;                        \
 }
 
+#define ICV_CVT_BGR2BGR565_8U( src, dst )  \
+    ICV_CVT_RGB2BGR565_8U_EX( (src), (dst), 0 )
 
-#define ICV_CVT_BGRA2BGR565( src, dst )                     \
-{                                                           \
-    int  t = ((src)[0] >> 3)|(((src)[1] & ~3) << 3)|        \
-             (((src)[2] & ~7) << 8);                        \
-                                                            \
-    ((ushort*)(dst))[0] = (ushort)t;                        \
-}
+#define ICV_CVT_BGRA2BGR565_8U  ICV_CVT_BGR2BGR565_8U
+
+#define ICV_CVT_RGB2BGR565_8U( src, dst )  \
+    ICV_CVT_RGB2BGR565_8U_EX( (src), (dst), 2 )
 
+#define ICV_CVT_RGBA2BGR565_8U  ICV_CVT_RGB2BGR565_8U
 
-#define ICV_CVT_RGBA2BGR565( src, dst )                     \
+#define ICV_CVT_BGR5652RGB_8U_EX( src, dst, blue_ofs )      \
 {                                                           \
-    int  t = ((src)[2] >> 3)|(((src)[1] & ~3) << 3)|        \
-             (((src)[0] & ~7) << 8);                        \
+    unsigned t = ((ushort*)(src))[0];                       \
                                                             \
-    ((ushort*)(dst))[0] = (ushort)t;                        \
+    (dst)[blue_ofs] = (uchar)(t << 3);                      \
+    (dst)[1] = (uchar)((t >> 3) & ~3);                      \
+    (dst)[blue_ofs ^ 2] = (uchar)((t >> 8) & ~7);           \
 }
 
+#define ICV_CVT_BGR5652BGR_8U( src, dst ) \
+    ICV_CVT_BGR5652RGB_8U_EX( (src), (dst), 0 )
+
+#define ICV_CVT_BGR5652RGB_8U( src, dst ) \
+    ICV_CVT_BGR5652RGB_8U_EX( (src), (dst), 2 )
 
-#define ICV_CVT_BGR5652BGR( src, dst )                      \
+#define ICV_CVT_BGR5652RGBA_8U_EX( src, dst, blue_ofs )     \
 {                                                           \
     unsigned t = ((ushort*)(src))[0];                       \
                                                             \
-    (dst)[0] = (uchar)(t << 3);                             \
+    (dst)[blue_ofs] = (uchar)(t << 3);                      \
     (dst)[1] = (uchar)((t >> 3) & ~3);                      \
-    (dst)[2] = (uchar)((t >> 8) & ~7);                      \
+    (dst)[blue_ofs ^ 2] = (uchar)((t >> 8) & ~7);           \
+    (dst)[3] = 0;                                           \
 }
 
+#define ICV_CVT_BGR5652BGRA_8U( src, dst ) \
+    ICV_CVT_BGR5652RGBA_8U_EX( (src), (dst), 0 )
+
+#define ICV_CVT_BGR5652RGBA_8U( src, dst ) \
+    ICV_CVT_BGR5652RGBA_8U_EX( (src), (dst), 2 )
 
-#define ICV_CVT_BGR5652RGB( src, dst )                      \
+/******************************** RGB: 555 <==> 888/8888 ************************/
+
+#define ICV_CVT_RGB2BGR555_8U_EX( src, dst, blue_ofs )      \
 {                                                           \
-    unsigned t = ((ushort*)(src))[0];                       \
+    int  t = ((src)[blue_ofs] >> 3)|(((src)[1] & ~7) << 2)| \
+             (((src)[blue_ofs ^ 2] & ~7) << 7);             \
                                                             \
-    (dst)[2] = (uchar)(t << 3);                             \
-    (dst)[1] = (uchar)((t >> 3) & ~3);                      \
-    (dst)[0] = (uchar)((t >> 8) & ~7);                      \
+    ((ushort*)(dst))[0] = (ushort)t;                        \
 }
 
+#define ICV_CVT_BGR2BGR555_8U( src, dst )  \
+    ICV_CVT_RGB2BGR555_8U_EX( (src), (dst), 0 )
+
+#define ICV_CVT_BGRA2BGR555_8U  ICV_CVT_BGR2BGR555_8U
+
+#define ICV_CVT_RGB2BGR555_8U( src, dst )  \
+    ICV_CVT_RGB2BGR555_8U_EX( (src), (dst), 2 )
 
-#define ICV_CVT_BGR5652BGRA( src, dst )                     \
+#define ICV_CVT_RGBA2BGR555_8U  ICV_CVT_RGB2BGR555_8U
+
+#define ICV_CVT_BGR5552RGB_8U_EX( src, dst, blue_ofs )      \
 {                                                           \
     unsigned t = ((ushort*)(src))[0];                       \
                                                             \
-    (dst)[0] = (uchar)(t << 3);                             \
-    (dst)[1] = (uchar)((t >> 3) & ~3);                      \
-    (dst)[2] = (uchar)((t >> 8) & ~7);                      \
-    (dst)[3] = 0;                                           \
+    (dst)[blue_ofs] = (uchar)(t << 3);                      \
+    (dst)[1] = (uchar)((t >> 2) & ~7);                      \
+    (dst)[blue_ofs ^ 2] = (uchar)((t >> 7) & ~7);           \
 }
 
+#define ICV_CVT_BGR5552BGR_8U( src, dst ) \
+    ICV_CVT_BGR5552RGB_8U_EX( (src), (dst), 0 )
+
+#define ICV_CVT_BGR5552RGB_8U( src, dst ) \
+    ICV_CVT_BGR5552RGB_8U_EX( (src), (dst), 2 )
 
-#define ICV_CVT_BGR5652RGBA( src, dst )                     \
+#define ICV_CVT_BGR5552RGBA_8U_EX( src, dst, blue_ofs )     \
 {                                                           \
     unsigned t = ((ushort*)(src))[0];                       \
                                                             \
-    (dst)[2] = (uchar)(t << 3);                             \
-    (dst)[1] = (uchar)((t >> 3) & ~3);                      \
-    (dst)[0] = (uchar)((t >> 8) & ~7);                      \
+    (dst)[blue_ofs] = (uchar)(t << 3);                      \
+    (dst)[1] = (uchar)((t >> 2) & ~7);                      \
+    (dst)[blue_ofs ^ 2] = (uchar)((t >> 7) & ~7);           \
     (dst)[3] = 0;                                           \
 }
 
+#define ICV_CVT_BGR5552BGRA_8U( src, dst ) \
+    ICV_CVT_BGR5552RGBA_8U_EX( (src), (dst), 0 )
+
+#define ICV_CVT_BGR5552RGBA_8U( src, dst ) \
+    ICV_CVT_BGR5552RGBA_8U_EX( (src), (dst), 2 )
+
+/*********************************** RGB <===> Grayscale **************************/
 
 #define fix(x,n)      (int)((x)*(1 << (n)) + 0.5)
 #define descale       CV_DESCALE
 
+#define cscGr_32f  0.299f
+#define cscGg_32f  0.587f
+#define cscGb_32f  0.114f
+
 /* BGR/RGB -> Gray */
-#define shift  10
-#define cscGr  fix(0.212671,shift)
-#define cscGg  fix(0.715160,shift)
-#define cscGb  fix(0.072169,shift)
+#define csc_shift  10
+#define cscGr  fix(cscGr_32f,csc_shift) 
+#define cscGg  fix(cscGg_32f,csc_shift)
+#define cscGb  /*fix(cscGb_32f,csc_shift)*/ ((1 << csc_shift) - cscGr - cscGg)
 
-#define  ICV_CVT_BGR5652GRAY( src, dst )                        \
+#define  ICV_CVT_BGR5652GRAY_8U( src, dst )                     \
 {                                                               \
     int t = ((ushort*)(src))[0];                                \
     t = ((t << 3) & 0xf8)*cscGb + ((t >> 3) & 0xfc)*cscGg +     \
         ((t >> 8) & 0xf8)*cscGr;                                \
-    t = descale(t,shift);                                       \
-    (dst)[0] = CV_FAST_CAST_8U(t);                              \
+    t = descale(t,csc_shift);                                   \
+    (dst)[0] = (uchar)t;                                        \
 }
 
-#define  ICV_CVT_BGRA2GRAY( src, dst )                          \
+#define  ICV_CVT_BGR5552GRAY_8U( src, dst )                     \
 {                                                               \
-    int t = (src)[0]*cscGb + (src)[1]*cscGg + (src)[2]*cscGr;   \
-    t = descale(t,shift);                                       \
-    (dst)[0] = CV_FAST_CAST_8U(t);                              \
+    int t = ((ushort*)(src))[0];                                \
+    t = ((t << 3) & 0xf8)*cscGb + ((t >> 2) & 0xf8)*cscGg +     \
+        ((t >> 7) & 0xf8)*cscGr;                                \
+    t = descale(t,csc_shift);                                   \
+    (dst)[0] = (uchar)t;                                        \
 }
 
-#define  ICV_CVT_BGR2GRAY( src, dst )                           \
+#define  ICV_CVT_BGR2GRAY_8U( src, dst )                        \
 {                                                               \
     int t = (src)[0]*cscGb + (src)[1]*cscGg + (src)[2]*cscGr;   \
-    t = descale(t,shift);                                       \
-    (dst)[0] = CV_FAST_CAST_8U(t);                              \
+    t = descale(t,csc_shift);                                   \
+    (dst)[0] = (uchar)t;                                        \
 }
 
-#define  ICV_CVT_RGB2GRAY( src, dst )                           \
-{                                                               \
-    int t = (src)[0]*cscGr + (src)[1]*cscGg + (src)[2]*cscGb;   \
-    t = descale(t,shift);                                       \
-    (dst)[0] = CV_FAST_CAST_8U(t);                              \
+#define  ICV_CVT_BGR2GRAY_32F( src, dst )                                   \
+{                                                                           \
+    float t = (src)[0]*cscGb_32f + (src)[1]*cscGg_32f + (src)[2]*cscGr_32f; \
+    (dst)[0] = t;                                                           \
 }
 
-#define  ICV_CVT_RGBA2GRAY( src, dst )                          \
+#define  ICV_CVT_BGRA2GRAY_8U    ICV_CVT_BGR2GRAY_8U
+#define  ICV_CVT_BGRA2GRAY_32F    ICV_CVT_BGR2GRAY_32F
+
+#define  ICV_CVT_RGB2GRAY_8U( src, dst )                        \
 {                                                               \
     int t = (src)[0]*cscGr + (src)[1]*cscGg + (src)[2]*cscGb;   \
-    t = descale(t,shift);                                       \
-    (dst)[0] = CV_FAST_CAST_8U(t);                              \
+    t = descale(t,csc_shift);                                   \
+    (dst)[0] = (uchar)t;                                        \
+}
+
+#define  ICV_CVT_RGB2GRAY_32F( src, dst )                                   \
+{                                                                           \
+    float t = (src)[0]*cscGr_32f + (src)[1]*cscGg_32f + (src)[2]*cscGb_32f; \
+    (dst)[0] = t;                                                           \
 }
 
-#define  ICV_CVT_GRAY2BGR565( src, dst )          \
+#define  ICV_CVT_RGBA2GRAY_8U    ICV_CVT_RGB2GRAY_8U
+#define  ICV_CVT_RGBA2GRAY_32F    ICV_CVT_RGB2GRAY_32F
+
+#define  ICV_CVT_GRAY2BGR565_8U( src, dst )       \
 {                                                 \
     int t = (src)[0];                             \
     t = (t >> 3)|((t & ~3) << 3)|((t & ~7) << 8); \
     ((ushort*)(dst))[0] = (ushort)t;              \
 }
 
+#define  ICV_CVT_GRAY2BGR555_8U( src, dst )       \
+{                                                 \
+    int t = (src)[0] >> 3;                        \
+    t = t|(t << 5)|(t << 10);                     \
+                                                  \
+    ((ushort*)(dst))[0] = (ushort)t;              \
+}
 
-#define  ICV_CVT_GRAY2BGR( src, dst )       \
-{                                           \
-    uchar t = (src)[0];                     \
-    (dst)[0] = (dst)[1] = (dst)[2] = t;     \
+#define  ICV_CVT_GRAY2BGR( arrtype, src, dst )  \
+{                                               \
+    arrtype t = (src)[0];                       \
+    (dst)[0] = (dst)[1] = (dst)[2] = t;         \
 }
 
-#define  ICV_CVT_GRAY2BGRA( src, dst )      \
-{                                           \
-    uchar t = (src)[0];                     \
-    (dst)[0] = (dst)[1] = (dst)[2] = t;     \
-    (dst)[3] = 0;                           \
+#define  ICV_CVT_GRAY2BGR_8U( src, dst ) ICV_CVT_GRAY2BGR( uchar, src, dst )
+#define  ICV_CVT_GRAY2BGR_32F( src, dst ) ICV_CVT_GRAY2BGR( float, src, dst )
+
+#define  ICV_CVT_GRAY2BGRA( arrtype, src, dst ) \
+{                                               \
+    arrtype t = (src)[0];                       \
+    (dst)[0] = (dst)[1] = (dst)[2] = t;         \
+    (dst)[3] = 0;                               \
 }
 
+#define  ICV_CVT_GRAY2BGRA_8U( src, dst ) ICV_CVT_GRAY2BGRA( uchar, src, dst )
+#define  ICV_CVT_GRAY2BGRA_32F( src, dst ) ICV_CVT_GRAY2BGRA( float, src, dst )
+
 
 /* BGR/RGB -> YCrCb */
-#define yuvYr  fix(0.299,shift)
-#define yuvYg  fix(0.587,shift)
-#define yuvYb  fix(0.114,shift)
-#define yuvCr  fix(0.713,shift)
-#define yuvCb  fix(0.564,shift)
+#define yuvYr_32f cscGr_32f
+#define yuvYg_32f cscGg_32f
+#define yuvYb_32f cscGb_32f
+#define yuvCr_32f 0.713f
+#define yuvCb_32f 0.564f
+
+#define yuv_shift 10
+#define yuvYr  fix(yuvYr_32f,yuv_shift)
+#define yuvYg  fix(yuvYg_32f,yuv_shift)
+#define yuvYb  fix(yuvYb_32f,yuv_shift)
+#define yuvCr  fix(yuvCr_32f,yuv_shift)
+#define yuvCb  fix(yuvCb_32f,yuv_shift)
 
 
-#define  ICV_CVT_BGR2YCrCb_EX( src, dst, blue_idx )         \
+#define  ICV_CVT_BGR2YCrCb_EX_8U( src, dst, blue_idx )          \
+{                                                               \
+    int b = (src)[blue_idx], r = (src)[2^blue_idx], y;          \
+                                                                \
+    y = descale(b*yuvYb + (src)[1]*yuvYg + r*yuvYr,yuv_shift);  \
+    r = descale((r - y)*yuvCr + (128 << yuv_shift),yuv_shift);  \
+    b = descale((b - y)*yuvCb + (128 << yuv_shift),yuv_shift);  \
+                                                                \
+    (dst)[0] = CV_CAST_8U(y);                                   \
+    (dst)[1] = CV_CAST_8U(r);                                   \
+    (dst)[2] = CV_CAST_8U(b);                                   \
+}
+
+
+#define  ICV_CVT_BGR2YCrCb_8U( src, dst )   ICV_CVT_BGR2YCrCb_EX_8U( src, dst, 0 )
+#define  ICV_CVT_RGB2YCrCb_8U( src, dst )   ICV_CVT_BGR2YCrCb_EX_8U( src, dst, 2 )
+
+
+#define  ICV_CVT_BGR2YCrCb_EX_32F( src, dst, blue_idx )     \
 {                                                           \
-    int b = (src)[blue_idx], r = (src)[2^blue_idx], y;      \
+    float b = (src)[blue_idx], r = (src)[2^blue_idx], y;    \
                                                             \
-    y = descale(b*yuvYb + (src)[1]*yuvYg + r*yuvYr,shift);  \
-    r = descale((r - y)*yuvCr + (128 << shift),shift);      \
-    b = descale((b - y)*yuvCb + (128 << shift),shift);      \
+    y = b*yuvYb_32f + (src)[1]*yuvYg_32f + r*yuvYr_32f;     \
+    r = (r - y)*yuvCr_32f + 0.5f;                           \
+    b = (b - y)*yuvCb_32f + 0.5f;                           \
                                                             \
-    (dst)[0] = CV_FAST_CAST_8U(y);                          \
-    (dst)[1] = CV_FAST_CAST_8U(r);                          \
-    (dst)[2] = CV_FAST_CAST_8U(b);                          \
+    (dst)[0] = y;                                           \
+    (dst)[1] = r;                                           \
+    (dst)[2] = b;                                           \
 }
 
 
-#define  ICV_CVT_BGR2YCrCb( src, dst )   ICV_CVT_BGR2YCrCb_EX( src, dst, 0 )
-#define  ICV_CVT_RGB2YCrCb( src, dst )   ICV_CVT_BGR2YCrCb_EX( src, dst, 2 )
+#define  ICV_CVT_BGR2YCrCb_32F( src, dst )   ICV_CVT_BGR2YCrCb_EX_32F( src, dst, 0 )
+#define  ICV_CVT_RGB2YCrCb_32F( src, dst )   ICV_CVT_BGR2YCrCb_EX_32F( src, dst, 2 )
 
+#define  yuvRCr_32f   1.403f
+#define  yuvGCr_32f   (-0.714f)
+#define  yuvGCb_32f   (-0.344f)
+#define  yuvBCb_32f   1.773f
 
-#define  yuvRCr   fix(1.403,shift)
-#define  yuvGCr   (-fix(0.344,shift))
-#define  yuvGCb   (-fix(0.714,shift))
-#define  yuvBCb   fix(1.773,shift)
+#define  yuvRCr   fix(yuvRCr_32f,yuv_shift)
+#define  yuvGCr   (-fix(-yuvGCr_32f,yuv_shift))
+#define  yuvGCb   (-fix(-yuvGCb_32f,yuv_shift))
+#define  yuvBCb   fix(yuvBCb_32f,yuv_shift)
 
-#define  ICV_CVT_YCrCb2BGR_EX( src, dst, blue_idx )     \
+#define  ICV_CVT_YCrCb2BGR_EX_8U( src, dst, blue_idx )  \
 {                                                       \
-    int Y = (src)[0] << shift, Cr = (src)[1] - 128,     \
+    int Y = (src)[0] << yuv_shift, Cr = (src)[1] - 128, \
         Cb = (src)[2] - 128;                            \
     int b, g, r;                                        \
                                                         \
-    b = descale( Y + yuvBCb*Cb, shift );                \
-    g = descale( Y + yuvGCr*Cr + yuvGCb*Cb, shift );    \
-    r = descale( Y + yuvRCr*Cr, shift );                \
+    b = descale( Y + yuvBCb*Cb, yuv_shift );            \
+    g = descale( Y + yuvGCr*Cr + yuvGCb*Cb, yuv_shift );\
+    r = descale( Y + yuvRCr*Cr, yuv_shift );            \
                                                         \
     (dst)[blue_idx] = CV_CAST_8U(b);                    \
     (dst)[1] = CV_CAST_8U(g);                           \
     (dst)[blue_idx^2] = CV_CAST_8U(r);                  \
 }
 
-#define  ICV_CVT_YCrCb2BGR( src, dst )  ICV_CVT_YCrCb2BGR_EX( src, dst, 0 )
-#define  ICV_CVT_YCrCb2RGB( src, dst )  ICV_CVT_YCrCb2BGR_EX( src, dst, 2 )
+#define  ICV_CVT_YCrCb2BGR_8U( src, dst )  ICV_CVT_YCrCb2BGR_EX_8U( src, dst, 0 )
+#define  ICV_CVT_YCrCb2RGB_8U( src, dst )  ICV_CVT_YCrCb2BGR_EX_8U( src, dst, 2 )
+
+
+#define  ICV_CVT_YCrCb2BGR_EX_32F( src, dst, blue_idx )             \
+{                                                                   \
+    float Y = (src)[0], Cr = (src)[1] - 0.5f, Cb = (src)[2] - 0.5f; \
+    float b, g, r;                                                  \
+                                                                    \
+    b = Y + yuvBCb_32f*Cb;                                          \
+    g = Y + yuvGCr_32f*Cr + yuvGCb_32f*Cb;                          \
+    r = Y + yuvRCr_32f*Cr;                                          \
+                                                                    \
+    (dst)[blue_idx] = b;                                            \
+    (dst)[1] = g;                                                   \
+    (dst)[blue_idx^2] = r;                                          \
+}
+
+#define  ICV_CVT_YCrCb2BGR_32F( src, dst )  ICV_CVT_YCrCb2BGR_EX_32F( src, dst, 0 )
+#define  ICV_CVT_YCrCb2RGB_32F( src, dst )  ICV_CVT_YCrCb2BGR_EX_32F( src, dst, 2 )
+
 
-#define xyzXr  fix(0.412411,shift)
-#define xyzXg  fix(0.357585,shift)
-#define xyzXb  fix(0.180454,shift)
+#define xyzXr_32f  0.412411f
+#define xyzXg_32f  0.357585f
+#define xyzXb_32f  0.180454f
 
-#define xyzYr  fix(0.212649,shift)
-#define xyzYg  fix(0.715169,shift)
-#define xyzYb  fix(0.072182,shift)
+#define xyzYr_32f  0.212649f
+#define xyzYg_32f  0.715169f
+#define xyzYb_32f  0.072182f
 
-#define xyzZr  fix(0.019332,shift)
-#define xyzZg  fix(0.119195,shift)
-#define xyzZb  fix(0.950390,shift)
+#define xyzZr_32f  0.019332f
+#define xyzZg_32f  0.119195f
+#define xyzZb_32f  0.950390f
 
+#define xyz_shift 10
+#define xyzXr  fix(xyzXr_32f,xyz_shift)
+#define xyzXg  fix(xyzXg_32f,xyz_shift)
+#define xyzXb  fix(xyzXb_32f,xyz_shift)
+                            
+#define xyzYr  fix(xyzYr_32f,xyz_shift)
+#define xyzYg  fix(xyzYg_32f,xyz_shift)
+#define xyzYb  fix(xyzYb_32f,xyz_shift)
+                            
+#define xyzZr  fix(xyzZr_32f,xyz_shift)
+#define xyzZg  fix(xyzZg_32f,xyz_shift)
+#define xyzZb  fix(xyzZb_32f,xyz_shift)
 
-#define  ICV_CVT_BGR2XYZ_EX( src, dst, blue_idx )       \
+#define  ICV_CVT_BGR2XYZ_EX_8U( src, dst, blue_idx )        \
+{                                                           \
+    int b = (src)[blue_idx], g = (src)[1],                  \
+        r = (src)[2^blue_idx];                              \
+    int x, y, z;                                            \
+                                                            \
+    x = descale( b*xyzXb + g*xyzXg + r*xyzXr, xyz_shift );  \
+    y = descale( b*xyzYb + g*xyzYg + r*xyzYr, xyz_shift );  \
+    z = descale( b*xyzZb + g*xyzZg + r*xyzZr, xyz_shift );  \
+                                                            \
+    (dst)[0] = CV_FAST_CAST_8U(x);                          \
+    (dst)[1] = CV_FAST_CAST_8U(y);                          \
+    (dst)[2] = CV_FAST_CAST_8U(z);                          \
+}
+
+#define  ICV_CVT_BGR2XYZ_8U( src, dst )  ICV_CVT_BGR2XYZ_EX_8U( src, dst, 0 )
+#define  ICV_CVT_RGB2XYZ_8U( src, dst )  ICV_CVT_BGR2XYZ_EX_8U( src, dst, 2 )
+
+#define  ICV_CVT_BGR2XYZ_EX_32F( src, dst, blue_idx )   \
 {                                                       \
-    int b = (src)[blue_idx], g = (src)[1],              \
-        r = (src)[2^blue_idx];                          \
-    int x, y, z;                                        \
+    float b = (src)[blue_idx], g = (src)[1],            \
+          r = (src)[2^blue_idx];                        \
+    float x, y, z;                                      \
                                                         \
-    x = descale( b*xyzXb + g*xyzXg + r*xyzXr, shift );  \
-    y = descale( b*xyzYb + g*xyzYg + r*xyzYr, shift );  \
-    z = descale( b*xyzZb + g*xyzZg + r*xyzZr, shift );  \
+    x = b*xyzXb_32f + g*xyzXg_32f + r*xyzXr_32f;        \
+    y = b*xyzYb_32f + g*xyzYg_32f + r*xyzYr_32f;        \
+    z = b*xyzZb_32f + g*xyzZg_32f + r*xyzZr_32f;        \
                                                         \
-    (dst)[0] = CV_FAST_CAST_8U(x);                      \
-    (dst)[1] = CV_FAST_CAST_8U(y);                      \
-    (dst)[2] = CV_FAST_CAST_8U(z);                      \
+    (dst)[0] = x;                                       \
+    (dst)[1] = y;                                       \
+    (dst)[2] = z;                                       \
 }
 
-#define  ICV_CVT_BGR2XYZ( src, dst )  ICV_CVT_BGR2XYZ_EX( src, dst, 0 )
-#define  ICV_CVT_RGB2XYZ( src, dst )  ICV_CVT_BGR2XYZ_EX( src, dst, 2 )
+#define  ICV_CVT_BGR2XYZ_32F( src, dst )  ICV_CVT_BGR2XYZ_EX_32F( src, dst, 0 )
+#define  ICV_CVT_RGB2XYZ_32F( src, dst )  ICV_CVT_BGR2XYZ_EX_32F( src, dst, 2 )
+
 
-#define  xyzRx   fix(3.240479,shift)
-#define  xyzRy   (-fix(1.53715,shift))
-#define  xyzRz   (-fix(0.498535,shift))
+#define  xyzRx_32f   3.240479f
+#define  xyzRy_32f   (-1.53715f)
+#define  xyzRz_32f   (-0.498535f)
 
-#define  xyzGx   (-fix(0.969256,shift))
-#define  xyzGy   fix(1.875991,shift)
-#define  xyzGz   fix(0.041556,shift)
+#define  xyzGx_32f   (-0.969256f)
+#define  xyzGy_32f   1.875991f
+#define  xyzGz_32f   0.041556f
 
-#define  xyzBx   fix(0.055648,shift)
-#define  xyzBy   (-fix(0.204043,shift))
-#define  xyzBz   fix(1.057311,shift)
+#define  xyzBx_32f   0.055648f
+#define  xyzBy_32f   (-0.204043f)
+#define  xyzBz_32f   1.057311f
 
+#define  xyzRx      fix(xyzRx_32f,xyz_shift)
+#define  xyzRy      (-fix(-xyzRy_32f,xyz_shift))
+#define  xyzRz      (-fix(-xyzRz_32f,xyz_shift))
 
-#define  ICV_CVT_XYZ2BGR_EX( src, dst, blue_idx )       \
+#define  xyzGx      (-fix(-xyzGx_32f,xyz_shift))
+#define  xyzGy      fix(xyzGy_32f,xyz_shift)
+#define  xyzGz      fix(xyzGz_32f,xyz_shift)
+
+#define  xyzBx      fix(xyzBx_32f,xyz_shift)
+#define  xyzBy      (-fix(-xyzBy_32f,xyz_shift))
+#define  xyzBz      fix(xyzBz_32f,xyz_shift)
+
+
+#define  ICV_CVT_XYZ2BGR_EX_8U( src, dst, blue_idx )        \
+{                                                           \
+    int x = (src)[0], y = (src)[1], z = (src)[2];           \
+    int b, g, r;                                            \
+                                                            \
+    b = descale( x*xyzBx + y*xyzBy + z*xyzBz, xyz_shift );  \
+    g = descale( x*xyzGx + y*xyzGy + z*xyzGz, xyz_shift );  \
+    r = descale( x*xyzRx + y*xyzRy + z*xyzRz, xyz_shift );  \
+                                                            \
+    (dst)[blue_idx] = CV_CAST_8U(b);                        \
+    (dst)[1] = CV_CAST_8U(g);                               \
+    (dst)[blue_idx^2] = CV_CAST_8U(r);                      \
+}
+
+#define  ICV_CVT_XYZ2BGR_8U( src, dst )  ICV_CVT_XYZ2BGR_EX_8U( src, dst, 0 )
+#define  ICV_CVT_XYZ2RGB_8U( src, dst )  ICV_CVT_XYZ2BGR_EX_8U( src, dst, 2 )
+
+#define  ICV_CVT_XYZ2BGR_EX_32F( src, dst, blue_idx )   \
 {                                                       \
-    int x = (src)[0], y = (src)[1], z = (src)[2];       \
-    int b, g, r;                                        \
+    float x = (src)[0], y = (src)[1], z = (src)[2];     \
+    float b, g, r;                                      \
                                                         \
-    b = descale( x*xyzBx + y*xyzBy + z*xyzBz, shift );  \
-    g = descale( x*xyzGx + y*xyzGy + z*xyzGz, shift );  \
-    r = descale( x*xyzRx + y*xyzRy + z*xyzRz, shift );  \
+    b = x*xyzBx_32f + y*xyzBy_32f + z*xyzBz_32f;        \
+    g = x*xyzGx_32f + y*xyzGy_32f + z*xyzGz_32f;        \
+    r = x*xyzRx_32f + y*xyzRy_32f + z*xyzRz_32f;        \
                                                         \
-    (dst)[blue_idx] = CV_CAST_8U(b);                    \
-    (dst)[1] = CV_CAST_8U(g);                           \
-    (dst)[blue_idx^2] = CV_CAST_8U(r);                  \
+    (dst)[blue_idx] = b;                                \
+    (dst)[1] = g;                                       \
+    (dst)[blue_idx^2] = r;                              \
 }
 
+#define  ICV_CVT_XYZ2BGR_32F( src, dst )  ICV_CVT_XYZ2BGR_EX_32F( src, dst, 0 )
+#define  ICV_CVT_XYZ2RGB_32F( src, dst )  ICV_CVT_XYZ2BGR_EX_32F( src, dst, 2 )
 
-#define  ICV_CVT_XYZ2BGR( src, dst )  ICV_CVT_XYZ2BGR_EX( src, dst, 0 )
-#define  ICV_CVT_XYZ2RGB( src, dst )  ICV_CVT_XYZ2BGR_EX( src, dst, 2 )
 
 #undef hsv_shift
 #define hsv_shift 12
@@ -445,7 +623,7 @@ static const int div_table[] = {
 };
 
 
-#define  ICV_CVT_BGR2HSV_EX( src, dst, blue_idx )                           \
+#define  ICV_CVT_BGR2HSV_EX_8U( src, dst, blue_idx )                        \
 {                                                                           \
     int b = (src)[blue_idx], g = (src)[1], r = (src)[2^blue_idx];           \
     int h, s, v;                                                            \
@@ -473,30 +651,84 @@ static const int div_table[] = {
     (dst)[2] = (uchar)v;                                                    \
 }
 
-#define  ICV_CVT_BGR2HSV( src, dst )  ICV_CVT_BGR2HSV_EX( src, dst, 0 )
-#define  ICV_CVT_RGB2HSV( src, dst )  ICV_CVT_BGR2HSV_EX( src, dst, 2 )
+#define  ICV_CVT_BGR2HSV_8U( src, dst )  ICV_CVT_BGR2HSV_EX_8U( src, dst, 0 )
+#define  ICV_CVT_RGB2HSV_8U( src, dst )  ICV_CVT_BGR2HSV_EX_8U( src, dst, 2 )
 
-#undef lab_shift
-#define lab_shift 10
 
-#define labXr  fix(0.43391,lab_shift)
-#define labXg  fix(0.37622,lab_shift)
-#define labXb  fix(0.18986,lab_shift)
+#define  ICV_CVT_BGR2HSV_EX_32F( src, dst, blue_idx )                       \
+{                                                                           \
+    float b = (src)[blue_idx], g = (src)[1], r = (src)[2^blue_idx];         \
+    float h, s, v;                                                          \
+                                                                            \
+    float vmin, diff;                                                       \
+                                                                            \
+    v = vmin = r;                                                           \
+    if( v < g ) v = g;                                                      \
+    if( v < b ) v = b;                                                      \
+    if( vmin > g ) vmin = g;                                                \
+    if( vmin > b ) vmin = b;                                                \
+                                                                            \
+    diff = v - vmin;                                                        \
+    s = diff/(float)(fabs(v) + FLT_EPSILON);                                \
+    diff = (float)(60./(fabs(diff) + FLT_EPSILON));                         \
+    if( v == r )                                                            \
+        h = (g - b)*diff;                                                   \
+    else if( v == g )                                                       \
+        h = (b - r)*diff + 120.f;                                           \
+    else                                                                    \
+        h = (r - g)*diff + 240.f;                                           \
+                                                                            \
+    if( h < 0 ) h += 360.f;                                                 \
+                                                                            \
+    (dst)[0] = h;                                                           \
+    (dst)[1] = s;                                                           \
+    (dst)[2] = v;                                                           \
+}
+
+#define  ICV_CVT_BGR2HSV_32F( src, dst )  ICV_CVT_BGR2HSV_EX_32F( src, dst, 0 )
+#define  ICV_CVT_RGB2HSV_32F( src, dst )  ICV_CVT_BGR2HSV_EX_32F( src, dst, 2 )
 
-#define labYr  fix(0.212649,lab_shift)
-#define labYg  fix(0.715169,lab_shift)
-#define labYb  fix(0.072182,lab_shift)
+#define  labXr_32f  0.43391f
+#define  labXg_32f  0.37622f
+#define  labXb_32f  0.18986f
 
-#define labZr  fix(0.017756,lab_shift)
-#define labZg  fix(0.109478,lab_shift)
-#define labZb  fix(0.872915,lab_shift)
+#define  labYr_32f  0.212649f
+#define  labYg_32f  0.715169f
+#define  labYb_32f  0.072182f
 
-#define labT   fix(2.258279,lab_shift)
+#define  labZr_32f  0.017756f
+#define  labZg_32f  0.109478f
+#define  labZb_32f  0.872915f
 
-#define labSmallScale fix(31.27,lab_shift)
-#define labSmallShift fix(141.24138,lab_shift)
-#define labLScale fix(295.8,lab_shift)
-#define labLShift fix(41779.2,lab_shift)
+#define  labT_32f   0.008856f
+
+#undef lab_shift
+#define lab_shift 10
+#define labXr  fix(labXr_32f,lab_shift)
+#define labXg  fix(labXg_32f,lab_shift)
+#define labXb  fix(labXb_32f,lab_shift)
+                            
+#define labYr  fix(labYr_32f,lab_shift)
+#define labYg  fix(labYg_32f,lab_shift)
+#define labYb  fix(labYb_32f,lab_shift)
+                            
+#define labZr  fix(labZr_32f,lab_shift)
+#define labZg  fix(labZg_32f,lab_shift)
+#define labZb  fix(labZb_32f,lab_shift)
+
+#define labT   fix(labT_32f*255,lab_shift)
+
+#define labSmallScale_32f  7.787f
+#define labSmallShift_32f  0.13793103448275862f  /* 16/116 */
+#define labLScale_32f      116.f
+#define labLShift_32f      16.f
+#define labLScale2_32f     903.3f
+
+#define labSmallScale fix(31.27 /* labSmallScale_32f*(1<<lab_shift)/255 */,lab_shift)
+#define labSmallShift fix(141.24138 /* labSmallScale_32f*(1<<lab) */,lab_shift)
+#define labLScale fix(295.8 /* labLScale_32f*255/100 */,lab_shift)
+#define labLShift fix(41779.2 /* labLShift_32f*1024*255/100 */,lab_shift)
+#define labLScale2 fix(labLScale2_32f*0.01,lab_shift)
 
 /* 1024*(([0..511]./255)**(1./3)) */
 static ushort icvLabCubeRootTab[] = {
@@ -534,7 +766,7 @@ static ushort icvLabCubeRootTab[] = {
 1278, 1279, 1279, 1280, 1281, 1282, 1283, 1284, 1285, 1285, 1286, 1287, 1288, 1289, 1290, 1291
 };
 
-#define  ICV_CVT_BGR2Lab_EX( src, dst, blue_idx )                   \
+#define  ICV_CVT_BGR2Lab_EX_8U( src, dst, blue_idx )                \
 {                                                                   \
     int b = (src)[blue_idx], g = (src)[1],                          \
         r = (src)[2^blue_idx];                                      \
@@ -571,7 +803,7 @@ static ushort icvLabCubeRootTab[] = {
     }                                                               \
     else                                                            \
     {                                                               \
-        l = descale(y*9,lab_shift);                                 \
+        l = descale(y*labLScale2,lab_shift);                        \
         y = descale(y*labSmallScale + labSmallShift,lab_shift);     \
     }                                                               \
                                                                     \
@@ -584,11 +816,62 @@ static ushort icvLabCubeRootTab[] = {
 }
 
 
-#define  ICV_CVT_BGR2Lab( src, dst )   ICV_CVT_BGR2Lab_EX( src, dst, 0 )
-#define  ICV_CVT_RGB2Lab( src, dst )   ICV_CVT_BGR2Lab_EX( src, dst, 2 )
+#define  ICV_CVT_BGR2Lab_8U( src, dst )   ICV_CVT_BGR2Lab_EX_8U( src, dst, 0 )
+#define  ICV_CVT_RGB2Lab_8U( src, dst )   ICV_CVT_BGR2Lab_EX_8U( src, dst, 2 )
+
+#define  ICV_CVT_BGR2Lab_EX_32F( src, dst, blue_idx )               \
+{                                                                   \
+    float b = (src)[blue_idx], g = (src)[1],                        \
+        r = (src)[2^blue_idx];                                      \
+    float x, y, z;                                                  \
+    float l, a;                                                     \
+    int f;                                                          \
+                                                                    \
+    x = b*labXb_32f + g*labXg_32f + r*labXr_32f;                    \
+    y = b*labYb_32f + g*labYg_32f + r*labYr_32f;                    \
+    z = b*labZb_32f + g*labZg_32f + r*labZr_32f;                    \
+                                                                    \
+    f = x > labT_32f;                                               \
+                                                                    \
+    if( f )                                                         \
+        x = cvCbrt(x);                                              \
+    else                                                            \
+        x = x*labSmallScale_32f + labSmallShift_32f;                \
+                                                                    \
+    f = z > labT_32f;                                               \
+                                                                    \
+    if( f )                                                         \
+        z = cvCbrt(z);                                              \
+    else                                                            \
+        z = z*labSmallScale_32f + labSmallShift_32f;                \
+                                                                    \
+    f = y > labT_32f;                                               \
+                                                                    \
+    if( f )                                                         \
+    {                                                               \
+        y = cvCbrt(y);                                              \
+        l = y*labLScale_32f - labLShift_32f;                        \
+    }                                                               \
+    else                                                            \
+    {                                                               \
+        l = y*labLScale2_32f;                                       \
+        y = y*labSmallScale_32f + labSmallShift_32f;                \
+    }                                                               \
+                                                                    \
+    a = 500.f*(x - y);                                              \
+    b = 200.f*(y - z);                                              \
+                                                                    \
+    (dst)[0] = l;                                                   \
+    (dst)[1] = a;                                                   \
+    (dst)[2] = b;                                                   \
+}
+
+
+#define  ICV_CVT_BGR2Lab_32F( src, dst )   ICV_CVT_BGR2Lab_EX_32F( src, dst, 0 )
+#define  ICV_CVT_RGB2Lab_32F( src, dst )   ICV_CVT_BGR2Lab_EX_32F( src, dst, 2 )
 
 
-#define  ICV_COLORCVT_FUNC( cvt_case, flavor, arrtype, src_cn, dst_cn )         \
+#define  ICV_COLORCVT_FUNC( cvt_case, macro_suffix, flavor, arrtype, src_cn, dst_cn ) \
 static CvStatus CV_STDCALL                                                      \
 icvCvt##_##cvt_case##_##flavor( const arrtype* src, int srcstep,                \
                                 arrtype* dst, int dststep, CvSize size )        \
@@ -597,51 +880,96 @@ icvCvt##_##cvt_case##_##flavor( const arrtype* src, int srcstep,
     {                                                                           \
         int i;                                                                  \
         for( i = 0; i < size.width; i++ )                                       \
-            ICV_CVT_##cvt_case( src + i*(src_cn), dst + i*(dst_cn) );           \
+            ICV_CVT_##cvt_case##_##macro_suffix(src+i*(src_cn), dst+i*(dst_cn));\
     }                                                                           \
                                                                                 \
     return CV_OK;                                                               \
 }
 
 
-ICV_COLORCVT_FUNC( BGR2RGB, 8u_C3R, uchar, 3, 3 )
-ICV_COLORCVT_FUNC( BGR2BGRA, 8u_C3C4R, uchar, 3, 4 )
-ICV_COLORCVT_FUNC( BGRA2BGR, 8u_C4C3R, uchar, 4, 3 )
-ICV_COLORCVT_FUNC( BGR2RGBA, 8u_C3C4R, uchar, 3, 4 )
-ICV_COLORCVT_FUNC( BGRA2RGBA, 8u_C4C4R, uchar, 4, 4 )
-ICV_COLORCVT_FUNC( RGBA2BGR, 8u_C4C3R, uchar, 4, 3 )
-ICV_COLORCVT_FUNC( BGR2GRAY, 8u_C3C1R, uchar, 3, 1 )
-ICV_COLORCVT_FUNC( RGB2GRAY, 8u_C3C1R, uchar, 3, 1 )
-ICV_COLORCVT_FUNC( BGRA2GRAY, 8u_C4C1R, uchar, 4, 1 )
-ICV_COLORCVT_FUNC( RGBA2GRAY, 8u_C4C1R, uchar, 4, 1 )
-ICV_COLORCVT_FUNC( GRAY2BGR, 8u_C1C3R, uchar, 1, 3 )
-ICV_COLORCVT_FUNC( GRAY2BGRA, 8u_C1C4R, uchar, 1, 4 )
-ICV_COLORCVT_FUNC( GRAY2BGR565, 8u_C1C2R, uchar, 1, 2 )
-ICV_COLORCVT_FUNC( BGR5652GRAY, 8u_C2C1R, uchar, 2, 1 )
-ICV_COLORCVT_FUNC( BGR2BGR565, 8u_C3C2R, uchar, 3, 2 )
-ICV_COLORCVT_FUNC( RGB2BGR565, 8u_C3C2R, uchar, 3, 2 )
-ICV_COLORCVT_FUNC( BGRA2BGR565, 8u_C4C2R, uchar, 4, 2 )
-ICV_COLORCVT_FUNC( RGBA2BGR565, 8u_C4C2R, uchar, 4, 2 )
-ICV_COLORCVT_FUNC( BGR5652BGR, 8u_C2C3R, uchar, 2, 3 )
-ICV_COLORCVT_FUNC( BGR5652RGB, 8u_C2C3R, uchar, 2, 3 )
-ICV_COLORCVT_FUNC( BGR5652BGRA, 8u_C2C4R, uchar, 2, 4 )
-ICV_COLORCVT_FUNC( BGR5652RGBA, 8u_C2C4R, uchar, 2, 4 )
-
-ICV_COLORCVT_FUNC( BGR2XYZ, 8u_C3R, uchar, 3, 3 )
-ICV_COLORCVT_FUNC( RGB2XYZ, 8u_C3R, uchar, 3, 3 )
-ICV_COLORCVT_FUNC( XYZ2BGR, 8u_C3R, uchar, 3, 3 )
-ICV_COLORCVT_FUNC( XYZ2RGB, 8u_C3R, uchar, 3, 3 )
-
-ICV_COLORCVT_FUNC( BGR2YCrCb, 8u_C3R, uchar, 3, 3 )
-ICV_COLORCVT_FUNC( RGB2YCrCb, 8u_C3R, uchar, 3, 3 )
-ICV_COLORCVT_FUNC( YCrCb2BGR, 8u_C3R, uchar, 3, 3 )
-ICV_COLORCVT_FUNC( YCrCb2RGB, 8u_C3R, uchar, 3, 3 )
-
-ICV_COLORCVT_FUNC( BGR2HSV, 8u_C3R, uchar, 3, 3 )
-ICV_COLORCVT_FUNC( RGB2HSV, 8u_C3R, uchar, 3, 3 )
-
-ICV_COLORCVT_FUNC( BGR2Lab, 8u_C3R, uchar, 3, 3 )
-ICV_COLORCVT_FUNC( RGB2Lab, 8u_C3R, uchar, 3, 3 )
+/********************************* 8u ***********************************/
+
+ICV_COLORCVT_FUNC( BGR2RGB, 8U, 8u_C3R, uchar, 3, 3 )
+ICV_COLORCVT_FUNC( BGR2BGRA, 8U, 8u_C3C4R, uchar, 3, 4 )
+ICV_COLORCVT_FUNC( BGRA2BGR, 8U, 8u_C4C3R, uchar, 4, 3 )
+ICV_COLORCVT_FUNC( BGR2RGBA, 8U, 8u_C3C4R, uchar, 3, 4 )
+ICV_COLORCVT_FUNC( BGRA2RGBA, 8U, 8u_C4C4R, uchar, 4, 4 )
+ICV_COLORCVT_FUNC( RGBA2BGR, 8U, 8u_C4C3R, uchar, 4, 3 )
+ICV_COLORCVT_FUNC( BGR2GRAY, 8U, 8u_C3C1R, uchar, 3, 1 )
+ICV_COLORCVT_FUNC( RGB2GRAY, 8U, 8u_C3C1R, uchar, 3, 1 )
+ICV_COLORCVT_FUNC( BGRA2GRAY, 8U, 8u_C4C1R, uchar, 4, 1 )
+ICV_COLORCVT_FUNC( RGBA2GRAY, 8U, 8u_C4C1R, uchar, 4, 1 )
+ICV_COLORCVT_FUNC( GRAY2BGR, 8U, 8u_C1C3R, uchar, 1, 3 )
+ICV_COLORCVT_FUNC( GRAY2BGRA, 8U, 8u_C1C4R, uchar, 1, 4 )
+
+ICV_COLORCVT_FUNC( GRAY2BGR565, 8U, 8u_C1C2R, uchar, 1, 2 )
+ICV_COLORCVT_FUNC( BGR5652GRAY, 8U, 8u_C2C1R, uchar, 2, 1 )
+ICV_COLORCVT_FUNC( BGR2BGR565, 8U, 8u_C3C2R, uchar, 3, 2 )
+ICV_COLORCVT_FUNC( RGB2BGR565, 8U, 8u_C3C2R, uchar, 3, 2 )
+ICV_COLORCVT_FUNC( BGRA2BGR565, 8U, 8u_C4C2R, uchar, 4, 2 )
+ICV_COLORCVT_FUNC( RGBA2BGR565, 8U, 8u_C4C2R, uchar, 4, 2 )
+ICV_COLORCVT_FUNC( BGR5652BGR, 8U, 8u_C2C3R, uchar, 2, 3 )
+ICV_COLORCVT_FUNC( BGR5652RGB, 8U, 8u_C2C3R, uchar, 2, 3 )
+ICV_COLORCVT_FUNC( BGR5652BGRA, 8U, 8u_C2C4R, uchar, 2, 4 )
+ICV_COLORCVT_FUNC( BGR5652RGBA, 8U, 8u_C2C4R, uchar, 2, 4 )
+
+ICV_COLORCVT_FUNC( GRAY2BGR555, 8U, 8u_C1C2R, uchar, 1, 2 )
+ICV_COLORCVT_FUNC( BGR5552GRAY, 8U, 8u_C2C1R, uchar, 2, 1 )
+ICV_COLORCVT_FUNC( BGR2BGR555, 8U, 8u_C3C2R, uchar, 3, 2 )
+ICV_COLORCVT_FUNC( RGB2BGR555, 8U, 8u_C3C2R, uchar, 3, 2 )
+ICV_COLORCVT_FUNC( BGRA2BGR555, 8U, 8u_C4C2R, uchar, 4, 2 )
+ICV_COLORCVT_FUNC( RGBA2BGR555, 8U, 8u_C4C2R, uchar, 4, 2 )
+ICV_COLORCVT_FUNC( BGR5552BGR, 8U, 8u_C2C3R, uchar, 2, 3 )
+ICV_COLORCVT_FUNC( BGR5552RGB, 8U, 8u_C2C3R, uchar, 2, 3 )
+ICV_COLORCVT_FUNC( BGR5552BGRA, 8U, 8u_C2C4R, uchar, 2, 4 )
+ICV_COLORCVT_FUNC( BGR5552RGBA, 8U, 8u_C2C4R, uchar, 2, 4 )
+
+ICV_COLORCVT_FUNC( BGR2YCrCb, 8U, 8u_C3R, uchar, 3, 3 )
+ICV_COLORCVT_FUNC( RGB2YCrCb, 8U, 8u_C3R, uchar, 3, 3 )
+ICV_COLORCVT_FUNC( YCrCb2BGR, 8U, 8u_C3R, uchar, 3, 3 )
+ICV_COLORCVT_FUNC( YCrCb2RGB, 8U, 8u_C3R, uchar, 3, 3 )
+
+ICV_COLORCVT_FUNC( BGR2XYZ, 8U, 8u_C3R, uchar, 3, 3 )
+ICV_COLORCVT_FUNC( RGB2XYZ, 8U, 8u_C3R, uchar, 3, 3 )
+ICV_COLORCVT_FUNC( XYZ2BGR, 8U, 8u_C3R, uchar, 3, 3 )
+ICV_COLORCVT_FUNC( XYZ2RGB, 8U, 8u_C3R, uchar, 3, 3 )
+
+ICV_COLORCVT_FUNC( BGR2HSV, 8U, 8u_C3R, uchar, 3, 3 )
+ICV_COLORCVT_FUNC( RGB2HSV, 8U, 8u_C3R, uchar, 3, 3 )
+
+ICV_COLORCVT_FUNC( BGR2Lab, 8U, 8u_C3R, uchar, 3, 3 )
+ICV_COLORCVT_FUNC( RGB2Lab, 8U, 8u_C3R, uchar, 3, 3 )
+
+/********************************* 32f *********************************/
+
+ICV_COLORCVT_FUNC( BGR2RGB, 32F, 32f_C3R, float, 3, 3 )
+ICV_COLORCVT_FUNC( BGR2BGRA, 32F, 32f_C3C4R, float, 3, 4 )
+ICV_COLORCVT_FUNC( BGRA2BGR, 32F, 32f_C4C3R, float, 4, 3 )
+ICV_COLORCVT_FUNC( BGR2RGBA, 32F, 32f_C3C4R, float, 3, 4 )
+ICV_COLORCVT_FUNC( BGRA2RGBA, 32F, 32f_C4C4R, float, 4, 4 )
+ICV_COLORCVT_FUNC( RGBA2BGR, 32F, 32f_C4C3R, float, 4, 3 )
+ICV_COLORCVT_FUNC( BGR2GRAY, 32F, 32f_C3C1R, float, 3, 1 )
+ICV_COLORCVT_FUNC( RGB2GRAY, 32F, 32f_C3C1R, float, 3, 1 )
+ICV_COLORCVT_FUNC( BGRA2GRAY, 32F, 32f_C4C1R, float, 4, 1 )
+ICV_COLORCVT_FUNC( RGBA2GRAY, 32F, 32f_C4C1R, float, 4, 1 )
+ICV_COLORCVT_FUNC( GRAY2BGR, 32F, 32f_C1C3R, float, 1, 3 )
+ICV_COLORCVT_FUNC( GRAY2BGRA, 32F, 32f_C1C4R, float, 1, 4 )
+
+ICV_COLORCVT_FUNC( BGR2XYZ, 32F, 32f_C3R, float, 3, 3 )
+ICV_COLORCVT_FUNC( RGB2XYZ, 32F, 32f_C3R, float, 3, 3 )
+ICV_COLORCVT_FUNC( XYZ2BGR, 32F, 32f_C3R, float, 3, 3 )
+ICV_COLORCVT_FUNC( XYZ2RGB, 32F, 32f_C3R, float, 3, 3 )
+
+ICV_COLORCVT_FUNC( BGR2YCrCb, 32F, 32f_C3R, float, 3, 3 )
+ICV_COLORCVT_FUNC( RGB2YCrCb, 32F, 32f_C3R, float, 3, 3 )
+ICV_COLORCVT_FUNC( YCrCb2BGR, 32F, 32f_C3R, float, 3, 3 )
+ICV_COLORCVT_FUNC( YCrCb2RGB, 32F, 32f_C3R, float, 3, 3 )
+
+ICV_COLORCVT_FUNC( BGR2HSV, 32F, 32f_C3R, float, 3, 3 )
+ICV_COLORCVT_FUNC( RGB2HSV, 32F, 32f_C3R, float, 3, 3 )
+
+ICV_COLORCVT_FUNC( BGR2Lab, 32F, 32f_C3R, float, 3, 3 )
+ICV_COLORCVT_FUNC( RGB2Lab, 32F, 32f_C3R, float, 3, 3 )
 
 
 static CvStatus
@@ -764,68 +1092,115 @@ typedef struct CvColorCvtFuncEntry
 CvColorCvtFuncEntry;
 
 
-static void icvInitColorCvtTable( CvColorCvtFuncEntry* tab )
+static void icvInitColorCvtTable( CvColorCvtFuncEntry* tab_8u, CvColorCvtFuncEntry* tab_32f )
 {
-    #define ICV_ADD_CVT_FUNC( cvt_case, scn, dcn )                                \
-        tab[CV_##cvt_case].func = (void*)icvCvt_##cvt_case##_8u_C##scn##C##dcn##R;\
-        tab[CV_##cvt_case].src_cn = scn; tab[CV_##cvt_case].dst_cn = dcn;         \
-        tab[CV_##cvt_case].pixel_wise = 1;
-
-    #define ICV_ADD_CVT_FUNC_C3( cvt_case )                                     \
-        tab[CV_##cvt_case].func = (void*)icvCvt_##cvt_case##_8u_C3R;            \
-        tab[CV_##cvt_case].src_cn = tab[CV_##cvt_case].dst_cn = 3;              \
-        tab[CV_##cvt_case].pixel_wise = 1;
-
-    #define ICV_ADD_BAYER_FUNC( cvt_case )                                      \
-        tab[CV_##cvt_case].func = (void*)icvCvt_##cvt_case##_8u_C1C3R;          \
-        tab[CV_##cvt_case].src_cn = 1; tab[CV_##cvt_case].dst_cn = 3;           \
-        tab[CV_##cvt_case].pixel_wise = 0;
-
-
-    ICV_ADD_CVT_FUNC( BGR2BGRA, 3, 4 )
-    ICV_ADD_CVT_FUNC( BGRA2BGR, 4, 3 )
-    ICV_ADD_CVT_FUNC( BGR2RGBA, 3, 4 )
-    ICV_ADD_CVT_FUNC( BGRA2RGBA, 4, 4 )
-    ICV_ADD_CVT_FUNC( RGBA2BGR, 4, 3 )
-    ICV_ADD_CVT_FUNC( BGR5652GRAY, 2, 1 )
-    ICV_ADD_CVT_FUNC( BGR2GRAY, 3, 1 )
-    ICV_ADD_CVT_FUNC( RGB2GRAY, 3, 1 )
-    ICV_ADD_CVT_FUNC( BGRA2GRAY, 4, 1 )
-    ICV_ADD_CVT_FUNC( RGBA2GRAY, 4, 1 )
-    ICV_ADD_CVT_FUNC( GRAY2BGR565, 1, 2 )
-    ICV_ADD_CVT_FUNC( GRAY2BGR, 1, 3 )
-    ICV_ADD_CVT_FUNC( GRAY2BGRA, 1, 4 )
-    ICV_ADD_CVT_FUNC( BGR2BGR565, 3, 2 )
-    ICV_ADD_CVT_FUNC( RGB2BGR565, 3, 2 )
-    ICV_ADD_CVT_FUNC( BGRA2BGR565, 4, 2 )
-    ICV_ADD_CVT_FUNC( RGBA2BGR565, 4, 2 )
-    ICV_ADD_CVT_FUNC( BGR5652BGR, 2, 3 )
-    ICV_ADD_CVT_FUNC( BGR5652RGB, 2, 3 )
-    ICV_ADD_CVT_FUNC( BGR5652BGRA, 2, 4 )
-    ICV_ADD_CVT_FUNC( BGR5652RGBA, 2, 4 )
+    #define ICV_ADD_CVT_FUNC( cvt_case, flavor, scn, dcn )                              \
+        tab_##flavor[CV_##cvt_case].func = (void*)icvCvt_##cvt_case##_##flavor##_C##scn##C##dcn##R;\
+        tab_##flavor[CV_##cvt_case].src_cn = scn; tab_##flavor[CV_##cvt_case].dst_cn = dcn;\
+        tab_##flavor[CV_##cvt_case].pixel_wise = 1;
+
+    #define ICV_ADD_CVT_FUNC_C3( cvt_case, flavor )                                     \
+        tab_##flavor[CV_##cvt_case].func = (void*)icvCvt_##cvt_case##_##flavor##_C3R;   \
+        tab_##flavor[CV_##cvt_case].src_cn = tab_##flavor[CV_##cvt_case].dst_cn = 3;    \
+        tab_##flavor[CV_##cvt_case].pixel_wise = 1;
+
+    #define ICV_ADD_BAYER_FUNC( cvt_case, flavor )                                      \
+        tab_##flavor[CV_##cvt_case].func = (void*)icvCvt_##cvt_case##_##flavor##_C1C3R; \
+        tab_##flavor[CV_##cvt_case].src_cn = 1; tab_##flavor[CV_##cvt_case].dst_cn = 3; \
+        tab_##flavor[CV_##cvt_case].pixel_wise = 0;
+
+    /************************************ 8u **********************************/
+
+    ICV_ADD_CVT_FUNC( BGR2BGRA, 8u, 3, 4 )
+    ICV_ADD_CVT_FUNC( BGRA2BGR, 8u, 4, 3 )
+    ICV_ADD_CVT_FUNC( BGR2RGBA, 8u, 3, 4 )
+    ICV_ADD_CVT_FUNC( BGRA2RGBA, 8u, 4, 4 )
+    ICV_ADD_CVT_FUNC( RGBA2BGR, 8u, 4, 3 )
     
+    ICV_ADD_CVT_FUNC( BGR5652GRAY, 8u, 2, 1 )
+    ICV_ADD_CVT_FUNC( BGR5552GRAY, 8u, 2, 1 )
+    
+    ICV_ADD_CVT_FUNC( BGR2GRAY, 8u, 3, 1 )
+    ICV_ADD_CVT_FUNC( RGB2GRAY, 8u, 3, 1 )
+    ICV_ADD_CVT_FUNC( BGRA2GRAY, 8u, 4, 1 )
+    ICV_ADD_CVT_FUNC( RGBA2GRAY, 8u, 4, 1 )
+    
+    ICV_ADD_CVT_FUNC( GRAY2BGR565, 8u, 1, 2 )
+    ICV_ADD_CVT_FUNC( GRAY2BGR555, 8u, 1, 2 )
 
-    ICV_ADD_CVT_FUNC_C3( BGR2RGB )    
-    ICV_ADD_CVT_FUNC_C3( BGR2XYZ )
-    ICV_ADD_CVT_FUNC_C3( RGB2XYZ )
-    ICV_ADD_CVT_FUNC_C3( XYZ2BGR )
-    ICV_ADD_CVT_FUNC_C3( XYZ2RGB )
-
-    ICV_ADD_CVT_FUNC_C3( BGR2YCrCb )
-    ICV_ADD_CVT_FUNC_C3( RGB2YCrCb )
-    ICV_ADD_CVT_FUNC_C3( YCrCb2BGR )
-    ICV_ADD_CVT_FUNC_C3( YCrCb2RGB )
-
-    ICV_ADD_CVT_FUNC_C3( BGR2HSV )
-    ICV_ADD_CVT_FUNC_C3( RGB2HSV )
-
-    ICV_ADD_CVT_FUNC_C3( BGR2Lab )
-    ICV_ADD_CVT_FUNC_C3( RGB2Lab )
-
-    ICV_ADD_BAYER_FUNC( BayerBG2BGR )
-    ICV_ADD_BAYER_FUNC( BayerGB2BGR )
-    ICV_ADD_BAYER_FUNC( BayerRG2BGR )
-    ICV_ADD_BAYER_FUNC( BayerGR2BGR )
+    ICV_ADD_CVT_FUNC( GRAY2BGR, 8u, 1, 3 )
+    ICV_ADD_CVT_FUNC( GRAY2BGRA, 8u, 1, 4 )
+    
+    ICV_ADD_CVT_FUNC( BGR2BGR565, 8u, 3, 2 )
+    ICV_ADD_CVT_FUNC( RGB2BGR565, 8u, 3, 2 )
+    ICV_ADD_CVT_FUNC( BGRA2BGR565, 8u, 4, 2 )
+    ICV_ADD_CVT_FUNC( RGBA2BGR565, 8u, 4, 2 )
+    ICV_ADD_CVT_FUNC( BGR5652BGR, 8u, 2, 3 )
+    ICV_ADD_CVT_FUNC( BGR5652RGB, 8u, 2, 3 )
+    ICV_ADD_CVT_FUNC( BGR5652BGRA, 8u, 2, 4 )
+    ICV_ADD_CVT_FUNC( BGR5652RGBA, 8u, 2, 4 )
+
+    ICV_ADD_CVT_FUNC( BGR2BGR555, 8u, 3, 2 )
+    ICV_ADD_CVT_FUNC( RGB2BGR555, 8u, 3, 2 )
+    ICV_ADD_CVT_FUNC( BGRA2BGR555, 8u, 4, 2 )
+    ICV_ADD_CVT_FUNC( RGBA2BGR555, 8u, 4, 2 )
+    ICV_ADD_CVT_FUNC( BGR5552BGR, 8u, 2, 3 )
+    ICV_ADD_CVT_FUNC( BGR5552RGB, 8u, 2, 3 )
+    ICV_ADD_CVT_FUNC( BGR5552BGRA, 8u, 2, 4 )
+    ICV_ADD_CVT_FUNC( BGR5552RGBA, 8u, 2, 4 )
+    
+    ICV_ADD_BAYER_FUNC( BayerBG2BGR, 8u )
+    ICV_ADD_BAYER_FUNC( BayerGB2BGR, 8u )
+    ICV_ADD_BAYER_FUNC( BayerRG2BGR, 8u )
+    ICV_ADD_BAYER_FUNC( BayerGR2BGR, 8u )
+
+    ICV_ADD_CVT_FUNC_C3( BGR2YCrCb, 8u )
+    ICV_ADD_CVT_FUNC_C3( RGB2YCrCb, 8u )
+    ICV_ADD_CVT_FUNC_C3( YCrCb2BGR, 8u )
+    ICV_ADD_CVT_FUNC_C3( YCrCb2RGB, 8u )
+
+    ICV_ADD_CVT_FUNC_C3( BGR2RGB, 8u )
+    ICV_ADD_CVT_FUNC_C3( BGR2XYZ, 8u )
+    ICV_ADD_CVT_FUNC_C3( RGB2XYZ, 8u )
+    ICV_ADD_CVT_FUNC_C3( XYZ2BGR, 8u )
+    ICV_ADD_CVT_FUNC_C3( XYZ2RGB, 8u )
+
+    ICV_ADD_CVT_FUNC_C3( BGR2HSV, 8u )
+    ICV_ADD_CVT_FUNC_C3( RGB2HSV, 8u )
+
+    ICV_ADD_CVT_FUNC_C3( BGR2Lab, 8u )
+    ICV_ADD_CVT_FUNC_C3( RGB2Lab, 8u )
+
+    /************************************ 32f **********************************/
+
+    ICV_ADD_CVT_FUNC( BGR2BGRA, 32f, 3, 4 )
+    ICV_ADD_CVT_FUNC( BGRA2BGR, 32f, 4, 3 )
+    ICV_ADD_CVT_FUNC( BGR2RGBA, 32f, 3, 4 )
+    ICV_ADD_CVT_FUNC( BGRA2RGBA, 32f, 4, 4 )
+    ICV_ADD_CVT_FUNC( RGBA2BGR, 32f, 4, 3 )
+    ICV_ADD_CVT_FUNC( BGR2GRAY, 32f, 3, 1 )
+    ICV_ADD_CVT_FUNC( RGB2GRAY, 32f, 3, 1 )
+    ICV_ADD_CVT_FUNC( BGRA2GRAY, 32f, 4, 1 )
+    ICV_ADD_CVT_FUNC( RGBA2GRAY, 32f, 4, 1 )
+    ICV_ADD_CVT_FUNC( GRAY2BGR, 32f, 1, 3 )
+    ICV_ADD_CVT_FUNC( GRAY2BGRA, 32f, 1, 4 )
+
+    ICV_ADD_CVT_FUNC_C3( BGR2RGB, 32f )
+    ICV_ADD_CVT_FUNC_C3( BGR2XYZ, 32f )
+    ICV_ADD_CVT_FUNC_C3( RGB2XYZ, 32f )
+    ICV_ADD_CVT_FUNC_C3( XYZ2BGR, 32f )
+    ICV_ADD_CVT_FUNC_C3( XYZ2RGB, 32f )
+
+    ICV_ADD_CVT_FUNC_C3( BGR2YCrCb, 32f )
+    ICV_ADD_CVT_FUNC_C3( RGB2YCrCb, 32f )
+    ICV_ADD_CVT_FUNC_C3( YCrCb2BGR, 32f )
+    ICV_ADD_CVT_FUNC_C3( YCrCb2RGB, 32f )
+
+    ICV_ADD_CVT_FUNC_C3( BGR2HSV, 32f )
+    ICV_ADD_CVT_FUNC_C3( RGB2HSV, 32f )
+
+    ICV_ADD_CVT_FUNC_C3( BGR2Lab, 32f )
+    ICV_ADD_CVT_FUNC_C3( RGB2Lab, 32f )
 }
 
 
@@ -833,7 +1208,7 @@ static void icvInitColorCvtTable( CvColorCvtFuncEntry* tab )
 CV_IMPL void
 cvCvtColor( const CvArr* srcarr, CvArr* dstarr, int colorcvt_code )
 {
-    static CvColorCvtFuncEntry cvttab[CV_COLORCVT_MAX];
+    static CvColorCvtFuncEntry cvttab[2][CV_COLORCVT_MAX];
     static int inittab = 0;
 
     CV_FUNCNAME( "cvCvtColor" );
@@ -846,13 +1221,14 @@ cvCvtColor( const CvArr* srcarr, CvArr* dstarr, int colorcvt_code )
     CvFunc2D_2A func;
     int src_step, dst_step;
     int src_cn, dst_cn;
+    int depth, idx;
     
     CV_CALL( src = cvGetMat( srcarr, &srcstub ));
     CV_CALL( dst = cvGetMat( dstarr, &dststub ));
     
     if( !inittab )
     {
-        icvInitColorCvtTable( cvttab );
+        icvInitColorCvtTable( cvttab[0], cvttab[1] );
         inittab = 1;
     }
 
@@ -862,7 +1238,8 @@ cvCvtColor( const CvArr* srcarr, CvArr* dstarr, int colorcvt_code )
     if( !CV_ARE_DEPTHS_EQ( src, dst ))
         CV_ERROR( CV_StsUnmatchedFormats, "" );
 
-    if( CV_MAT_DEPTH( src->type ) != CV_8U )
+    depth = CV_MAT_DEPTH(src->type);
+    if( depth != CV_8U && depth != CV_32F )
         CV_ERROR( CV_StsUnsupportedFormat, "" );
 
     if( (unsigned)colorcvt_code >= CV_COLORCVT_MAX )
@@ -888,20 +1265,21 @@ cvCvtColor( const CvArr* srcarr, CvArr* dstarr, int colorcvt_code )
         break;
     }
 
-    func = (CvFunc2D_2A)cvttab[colorcvt_code].func;
+    idx = depth == CV_8U ? 0 : 1;
+    func = (CvFunc2D_2A)cvttab[idx][colorcvt_code].func;
 
     if( !func )
         CV_ERROR( CV_StsBadFlag, "" );
 
-    if( src_cn != cvttab[colorcvt_code].src_cn ||
-        dst_cn != cvttab[colorcvt_code].dst_cn )
+    if( src_cn != cvttab[idx][colorcvt_code].src_cn ||
+        dst_cn != cvttab[idx][colorcvt_code].dst_cn )
         CV_ERROR( CV_BadNumChannels, "" );
 
-    size = icvGetMatSize( src );
+    size = cvGetMatSize( src );
     src_step = src->step;
     dst_step = dst->step;
 
-    if( cvttab[colorcvt_code].pixel_wise &&
+    if( cvttab[idx][colorcvt_code].pixel_wise &&
         CV_IS_MAT_CONT( src->type & dst->type ))
     {
         size.width *= size.height;
index 7c651ac2d93c8c15b0e93c80c46199db4a233b9d..06929e7e9e2322d01b9e3e31e5c865d35ce82fe2 100644 (file)
@@ -39,7 +39,6 @@
 //
 //M*/
 #include "_cv.h"
-#include "_cvutils.h"
 
 /*F///////////////////////////////////////////////////////////////////////////////////////
 //    Name:    cvCreateConDensation
index 5a13a25dcc70e051f21ae1181ed393e297587915..158dec4f51f58b9485b6f9ecaa6e884297e8dd2b 100644 (file)
 //
 //M*/
 #include "_cv.h"
-#include <limits.h>
-#include "_cvdatastructs.h"
 
-const CvPoint icvCodeDeltas[8] =
+/* initializes 8-element array for fast access to 3x3 neighborhood of a pixel */
+#define  CV_INIT_3X3_DELTAS( deltas, step, nch )            \
+    ((deltas)[0] =  (nch),  (deltas)[1] = -(step) + (nch),  \
+     (deltas)[2] = -(step), (deltas)[3] = -(step) - (nch),  \
+     (deltas)[4] = -(nch),  (deltas)[5] =  (step) - (nch),  \
+     (deltas)[6] =  (step), (deltas)[7] =  (step) + (nch))
+
+static const CvPoint icvCodeDeltas[8] =
     { {1, 0}, {1, -1}, {0, -1}, {-1, -1}, {-1, 0}, {-1, 1}, {0, 1}, {1, 1} };
 
 CV_IMPL void
@@ -55,7 +60,7 @@ cvStartReadChainPoints( CvChain * chain, CvChainPtReader * reader )
     __BEGIN__;
 
     if( !chain || !reader )
-        CV_ERROR_FROM_STATUS( CV_NULLPTR_ERR );
+        CV_ERROR( CV_StsNullPtr, "" );
 
     if( chain->elem_size != 1 || chain->header_size < (int)sizeof(CvChain))
         CV_ERROR_FROM_STATUS( CV_BADSIZE_ERR );
@@ -88,7 +93,7 @@ cvReadChainPoint( CvChainPtReader * reader )
     __BEGIN__;
 
     if( !reader )
-        CV_ERROR_FROM_STATUS( CV_NULLPTR_ERR );
+        CV_ERROR( CV_StsNullPtr, "" );
 
     pt = reader->pt;
     
@@ -151,6 +156,7 @@ typedef struct _CvContourScanner
     char *img;                  /* current image row */
     int img_step;               /* image step */
     CvSize img_size;            /* ROI size */
+    CvPoint offset;             /* ROI offset: coordinates, added to each contour point */
     CvPoint pt;                 /* current scanner position */
     CvPoint lnbd;               /* position of the last met contour */
     int nbd;                    /* current mark val */
@@ -158,8 +164,8 @@ typedef struct _CvContourScanner
     _CvContourInfo cinfo_temp;  /* temporary var which is used in simple modes */
     _CvContourInfo frame_info;  /* information about frame */
     CvSeq frame;                /* frame itself */
-    CvChainApproxMethod approx_method1; /* approx method when tracing */
-    CvChainApproxMethod approx_method2; /* final approx method */
+    int approx_method1;         /* approx method when tracing */
+    int approx_method2;         /* final approx method */
     int mode;                   /* contour scanning mode:
                                    0 - external only
                                    1 - all the contours w/o any hierarchy
@@ -185,8 +191,8 @@ _CvContourScanner;
 */
 CV_IMPL CvContourScanner
 cvStartFindContours( void* _img, CvMemStorage* storage,
-                     int  header_size, CvContourRetrievalMode mode, 
-                     CvChainApproxMethod  method )
+                     int  header_size, int mode, 
+                     int  method, CvPoint offset )
 {
     int y;
     int step;
@@ -200,7 +206,7 @@ cvStartFindContours( void* _img, CvMemStorage* storage,
     __BEGIN__;
 
     if( !storage )
-        CV_ERROR_FROM_STATUS( CV_NULLPTR_ERR );
+        CV_ERROR( CV_StsNullPtr, "" );
 
     CV_CALL( mat = cvGetMat( mat, &stub ));
 
@@ -217,7 +223,7 @@ cvStartFindContours( void* _img, CvMemStorage* storage,
     if( header_size < (int) (method == CV_CHAIN_CODE ? sizeof( CvChain ) : sizeof( CvContour )))
         CV_ERROR_FROM_STATUS( CV_BADSIZE_ERR );
 
-    scanner = (CvContourScanner) icvAlloc( sizeof( *scanner ));
+    scanner = (CvContourScanner)cvAlloc( sizeof( *scanner ));
     if( !scanner )
         CV_ERROR_FROM_STATUS( CV_OUTOFMEM_ERR );
 
@@ -230,6 +236,7 @@ cvStartFindContours( void* _img, CvMemStorage* storage,
     scanner->img_size.width = size.width - 1;   /* exclude rightest column */
     scanner->img_size.height = size.height - 1; /* exclude bottomost row */
     scanner->mode = mode;
+    scanner->offset = offset;
     scanner->pt.x = scanner->pt.y = 1;
     scanner->lnbd.x = 0;
     scanner->lnbd.y = 1;
@@ -315,10 +322,8 @@ cvStartFindContours( void* _img, CvMemStorage* storage,
 
     __END__;
 
-    if( CV_ERR_STATUS() < 0 )
-    {
-        icvFree( (void **) &scanner );
-    }
+    if( cvGetErrStatus() < 0 )
+        cvFree( (void **)&scanner );
 
     return scanner;
 }
@@ -526,7 +531,7 @@ icvFetchContour( char                   *ptr,
                  int                    step,
                  CvPoint                pt, 
                  CvSeq*                 contour, 
-                 CvChainApproxMethod    _method )
+                 int    _method )
 {
     const char      nbd = 2;
     int             deltas[16];
@@ -624,7 +629,7 @@ icvFetchContour( char                   *ptr,
     cvEndWriteSeq( &writer );
 
     if( _method != CV_CHAIN_CODE )
-        cvContourBoundingRect( contour, 1 );
+        cvBoundingRect( contour, 1 );
 
     assert( writer.seq->total == 0 && writer.seq->first == 0 ||
             writer.seq->total > writer.seq->first->count ||
@@ -697,7 +702,7 @@ icvFetchContourEx( char*                ptr,
                    int                  step,
                    CvPoint              pt, 
                    CvSeq*               contour,
-                   CvChainApproxMethod  _method, 
+                   int  _method, 
                    int                  nbd,
                    CvRect*              _rect )
 {
@@ -846,7 +851,7 @@ cvFindNextContour( CvContourScanner scanner )
     __BEGIN__;
 
     if( !scanner )
-        CV_ERROR_FROM_STATUS( CV_NULLPTR_ERR );
+        CV_ERROR( CV_StsNullPtr, "" );
     icvEndProcessContour( scanner );
 
     /* initialize local state */
@@ -965,7 +970,9 @@ cvFindNextContour( CvContourScanner scanner )
                 if( mode <= 1 )
                 {
                     l_cinfo = &(scanner->cinfo_temp);
-                    result = icvFetchContour( img + x - is_hole, step, origin,
+                    result = icvFetchContour( img + x - is_hole, step,
+                                              cvPoint( origin.x + scanner->offset.x,
+                                                       origin.y + scanner->offset.y),
                                               seq, scanner->approx_method1 );
                     if( result < 0 )
                         goto exit_func;
@@ -974,11 +981,15 @@ cvFindNextContour( CvContourScanner scanner )
                 {
                     cvSetAdd( scanner->cinfo_set, 0, (CvSetElem **) & l_cinfo );
 
-                    result = icvFetchContourEx( img + x - is_hole, step, origin,
+                    result = icvFetchContourEx( img + x - is_hole, step,
+                                                cvPoint( origin.x + scanner->offset.x,
+                                                         origin.y + scanner->offset.y),
                                                 seq, scanner->approx_method1,
                                                 nbd, &(l_cinfo->rect) );
                     if( result < 0 )
                         goto exit_func;
+                    l_cinfo->rect.x -= scanner->offset.x;
+                    l_cinfo->rect.y -= scanner->offset.y;
 
                     l_cinfo->next = scanner->cinfo_table[nbd - 2];
                     scanner->cinfo_table[nbd - 2] = l_cinfo;
@@ -1078,7 +1089,7 @@ cvEndFindContours( CvContourScanner * _scanner )
     __BEGIN__;
 
     if( !_scanner )
-        CV_ERROR_FROM_STATUS( CV_NULLPTR_ERR );
+        CV_ERROR( CV_StsNullPtr, "" );
     scanner = *_scanner;
 
     if( scanner )
@@ -1092,7 +1103,7 @@ cvEndFindContours( CvContourScanner * _scanner )
             cvReleaseMemStorage( &(scanner->cinfo_storage) );
 
         first = scanner->frame.v_next;
-        icvFree( _scanner );
+        cvFree( (void**)_scanner );
     }
 
     __END__;
@@ -1184,7 +1195,7 @@ icvFindContoursInInterval( const CvArr* src,
             CV_ERROR( CV_StsBadArg, "Input array must be 8uC1 or 8sC1" );
         src_data = mat->data.ptr;
         img_step = mat->step;
-        img_size = icvGetMatSize( mat );
+        img_size = cvGetMatSize( mat );
     }
 
     // Create temporary sequences
@@ -1496,8 +1507,8 @@ icvFindContoursInInterval( const CvArr* src,
 CV_IMPL int
 cvFindContours( void*  img,  CvMemStorage*  storage,                
                 CvSeq**  firstContour, int  cntHeaderSize,                 
-                CvContourRetrievalMode  mode, 
-                CvChainApproxMethod  method )
+                int  mode, 
+                int  method, CvPoint offset )
 {
     CvContourScanner scanner = 0;
     CvSeq *contour = 0;
@@ -1512,13 +1523,17 @@ cvFindContours( void*  img,  CvMemStorage*  storage,
 
     if( method == CV_LINK_RUNS )
     {
+        if( offset.x != 0 || offset.y != 0 )
+            CV_ERROR( CV_StsOutOfRange,
+            "Nonzero offset is not supported in CV_LINK_RUNS yet" );
+
         CV_CALL( count = icvFindContoursInInterval( img, storage,
-                                 firstContour, cntHeaderSize ));
+                                    firstContour, cntHeaderSize ));
     }
     else
     {
         CV_CALL( scanner = cvStartFindContours( img, storage,
-                                 cntHeaderSize, mode, method ));
+                        cntHeaderSize, mode, method, offset ));
         assert( scanner );
 
         do
index 632a687e04e2bc951cbac1f982e4e2b2249d6bb5..f2b86c48b26c4bd8515423e2e5656949cf5c8f22 100644 (file)
@@ -39,8 +39,6 @@
 //
 //M*/
 #include "_cv.h"
-#include "_cvdatastructs.h"
-#include "_cvgeom.h"
 
 #define CV_MATCH_CHECK( status, cvFun )                                    \
   {                                                                        \
      goto M_END;                                                           \
   }
 
-CvStatus icvCalcTriAttr( CvSeq * contour, CvPoint t2, CvPoint t1, int n1,
-                         CvPoint t3, int n3, double *s, double *s_c,
-
-                         double *h, double *a, double *b );
+static CvStatus
+icvCalcTriAttr( const CvSeq * contour, CvPoint t2, CvPoint t1, int n1,
+                CvPoint t3, int n3, double *s, double *s_c,
+                double *h, double *a, double *b );
 
 /*F///////////////////////////////////////////////////////////////////////////////////////
 //    Name: icvCreateContourTree
@@ -66,8 +64,8 @@ CvStatus icvCalcTriAttr( CvSeq * contour, CvPoint t2, CvPoint t1, int n1,
 //      threshold - threshold for the binary tree building 
 //
 //F*/
-CvStatus
-icvCreateContourTree( CvSeq * contour, CvMemStorage * storage,
+static CvStatus
+icvCreateContourTree( const CvSeq * contour, CvMemStorage * storage,
                       CvContourTree ** tree, double threshold )
 {
     CvPoint *pt_p;              /*  pointer to previos points   */
@@ -78,6 +76,7 @@ icvCreateContourTree( CvSeq * contour, CvMemStorage * storage,
     int lpt, flag, i, j, i_tree, j_1, j_3, i_buf;
     double s, sp1, sp2, sn1, sn2, s_c, sp1_c, sp2_c, sn1_c, sn2_c, h, hp1, hp2, hn1, hn2,
         a, ap1, ap2, an1, an2, b, bp1, bp2, bn1, bn2;
+    double a_s_c, a_sp1_c;
 
     _CvTrianAttr **ptr_p, **ptr_n, **ptr1, **ptr2;      /*  pointers to pointers of triangles  */
     _CvTrianAttr *cur_adr;
@@ -113,18 +112,18 @@ icvCreateContourTree( CvSeq * contour, CvMemStorage * storage,
     ptr_p = ptr_n = ptr1 = ptr2 = NULL;
     tree_end = NULL;
 
-    pt_p = (CvPoint *) icvAlloc( lpt * sizeof( CvPoint ));
-    pt_n = (CvPoint *) icvAlloc( lpt * sizeof( CvPoint ));
+    pt_p = (CvPoint *) cvAlloc( lpt * sizeof( CvPoint ));
+    pt_n = (CvPoint *) cvAlloc( lpt * sizeof( CvPoint ));
 
-    num_p = (int *) icvAlloc( lpt * sizeof( int ));
-    num_n = (int *) icvAlloc( lpt * sizeof( int ));
+    num_p = (int *) cvAlloc( lpt * sizeof( int ));
+    num_n = (int *) cvAlloc( lpt * sizeof( int ));
 
     hearder_size = sizeof( CvContourTree );
     seq_flags = CV_SEQ_POLYGON_TREE;
     cvStartWriteSeq( seq_flags, hearder_size, sizeof( _CvTrianAttr ), storage, &writer );
 
-    ptr_p = (_CvTrianAttr **) icvAlloc( lpt * sizeof( _CvTrianAttr * ));
-    ptr_n = (_CvTrianAttr **) icvAlloc( lpt * sizeof( _CvTrianAttr * ));
+    ptr_p = (_CvTrianAttr **) cvAlloc( lpt * sizeof( _CvTrianAttr * ));
+    ptr_n = (_CvTrianAttr **) cvAlloc( lpt * sizeof( _CvTrianAttr * ));
 
     memset( ptr_p, 0, lpt * sizeof( _CvTrianAttr * ));
     memset( ptr_n, 0, lpt * sizeof( _CvTrianAttr * ));
@@ -401,8 +400,10 @@ icvCreateContourTree( CvSeq * contour, CvMemStorage * storage,
                     icvCalcTriAttr( contour, tp1, tn2, nmn2, t, nm, &sp1, &sp1_c, &hp1, &ap1,
                                     &bp1 ));
 
+    a_s_c = fabs( s_c - sn2_c );
+    a_sp1_c = fabs( sp1_c - sn1_c );
 
-    if( fabs( s_c - sn2_c ) > fabs( sp1_c - sn1_c ))
+    if( a_s_c > a_sp1_c )
 /*   form child vertexs for the root     */
     {
         tree_one.pt = t;
@@ -576,12 +577,12 @@ icvCreateContourTree( CvSeq * contour, CvMemStorage * storage,
 
   M_END:
 
-    icvFree( &ptr_n );
-    icvFree( &ptr_p );
-    icvFree( &num_n );
-    icvFree( &num_p );
-    icvFree( &pt_n );
-    icvFree( &pt_p );
+    cvFree( (void**)&ptr_n );
+    cvFree( (void**)&ptr_p );
+    cvFree( (void**)&num_n );
+    cvFree( (void**)&num_p );
+    cvFree( (void**)&pt_n );
+    cvFree( (void**)&pt_p );
 
     return status;
 }
@@ -591,9 +592,10 @@ icvCreateContourTree( CvSeq * contour, CvMemStorage * storage,
  triangle attributes calculations 
 
 \****************************************************************************************/
-CvStatus
-icvCalcTriAttr( CvSeq * contour, CvPoint t2, CvPoint t1, int n1,
-                CvPoint t3, int n3, double *s, double *s_c, double *h, double *a, double *b )
+static CvStatus
+icvCalcTriAttr( const CvSeq * contour, CvPoint t2, CvPoint t1, int n1,
+                CvPoint t3, int n3, double *s, double *s_c,
+                double *h, double *a, double *b )
 {
     double x13, y13, x12, y12, l_base, nx, ny, qq;
     double eps = 1.e-5;
@@ -644,7 +646,7 @@ icvCalcTriAttr( CvSeq * contour, CvPoint t2, CvPoint t1, int n1,
 //
 //F*/
 CV_IMPL CvContourTree*
-cvCreateContourTree( CvSeq* contour, CvMemStorage* storage, double threshold )
+cvCreateContourTree( const CvSeq* contour, CvMemStorage* storage, double threshold )
 {
     CvContourTree* tree = 0;
     
@@ -673,7 +675,7 @@ cvCreateContourTree( CvSeq* contour, CvMemStorage* storage, double threshold )
 //                 for the contour reconstracting (level or precision)
 //F*/
 CV_IMPL CvSeq*
-cvContourFromContourTree( CvContourTree*  tree,
+cvContourFromContourTree( const CvContourTree*  tree,
                           CvMemStorage*  storage,
                           CvTermCriteria  criteria )
 {
@@ -700,12 +702,12 @@ cvContourFromContourTree( CvContourTree*  tree,
     __BEGIN__;
 
     if( !tree )
-        CV_ERROR_FROM_STATUS( CV_NULLPTR_ERR );
+        CV_ERROR( CV_StsNullPtr, "" );
 
     if( !CV_IS_SEQ_POLYGON_TREE( tree ))
         CV_ERROR_FROM_STATUS( CV_BADFLAG_ERR );
 
-    criteria = icvCheckTermCriteria( criteria, 0., 100 );
+    criteria = cvCheckTermCriteria( criteria, 0., 100 );
 
     lpt = tree->total;
     ptr_buf = NULL;
@@ -724,12 +726,12 @@ cvContourFromContourTree( CvContourTree*  tree,
     seq_flags = CV_SEQ_POLYGON;
     cvStartWriteSeq( seq_flags, out_hearder_size, sizeof( CvPoint ), storage, &writer );
 
-    ptr_buf = (_CvTrianAttr **) icvAlloc( lpt * sizeof( _CvTrianAttr * ));
+    ptr_buf = (_CvTrianAttr **) cvAlloc( lpt * sizeof( _CvTrianAttr * ));
     if( ptr_buf == NULL )
         CV_ERROR_FROM_STATUS( CV_OUTOFMEM_ERR );
     if( log_iter )
     {
-        level_buf = (int *) icvAlloc( lpt * (sizeof( int )));
+        level_buf = (int *) cvAlloc( lpt * (sizeof( int )));
 
         if( level_buf == NULL )
             CV_ERROR_FROM_STATUS( CV_OUTOFMEM_ERR );
@@ -753,7 +755,7 @@ cvContourFromContourTree( CvContourTree*  tree,
         threshold = 10 * area_all;
 
     if( log_iter )
-        level = criteria.maxIter;
+        level = criteria.max_iter;
     else
         level = -1;
 
@@ -790,13 +792,13 @@ cvContourFromContourTree( CvContourTree*  tree,
     }
 
     contour = cvEndWriteSeq( &writer );
-    cvContourBoundingRect( contour, 1 );
+    cvBoundingRect( contour, 1 );
 
     __CLEANUP__;
     __END__;
 
-    icvFree( &level_buf );
-    icvFree( &ptr_buf );
+    cvFree( (void**)&level_buf );
+    cvFree( (void**)&ptr_buf );
 
     return contour;
 }
index b5223f17770eca02d0681e8cd783fd26d2388b75..1407add846d639b5e2714dfda230cb00c3953525 100644 (file)
@@ -40,7 +40,6 @@
 //M*/
 
 #include "_cv.h"
-#include "_cvdatastructs.h"
 
 static int
 icvSklansky_32s( CvPoint** array, int start, int end, int* stack, int nsign, int sign2 )
@@ -191,13 +190,10 @@ icvSklansky_32f( CvPoint2D32f** array, int start, int end, int* stack, int nsign
 typedef int (*sklansky_func)( CvPoint** points, int start, int end,
                               int* stack, int sign, int sign2 );
 
-#define cmp_pts( ptr1, ptr2 ) \
-( ptr1->x < ptr2->x  ||       \
-  ptr1->x == ptr2->x &&       \
-  ptr1->y < ptr2->y  )
-
-CV_IMPLEMENT_QSORT( icvSortPointsByPointers_32s, CvPoint *, cmp_pts );
-CV_IMPLEMENT_QSORT( icvSortPointsByPointers_32f, CvPoint2D32f *, cmp_pts );
+#define cmp_pts( pt1, pt2 )  \
+    ((pt1)->x < (pt2)->x || (pt1)->x == (pt2)->x && (pt1)->y < (pt2)->y)
+static CV_IMPLEMENT_QSORT( icvSortPointsByPointers_32s, CvPoint*, cmp_pts )
+static CV_IMPLEMENT_QSORT( icvSortPointsByPointers_32f, CvPoint2D32f*, cmp_pts )
 
 static void
 icvCalcAndWritePtIndices( CvPoint** pointer, int* stack, int start, int end,
@@ -252,6 +248,7 @@ cvConvexHull2( const CvArr* array, void* hull_storage,
     int t_count;
     int i, miny_ind = 0, maxy_ind = 0;
     int hulltype;
+    int stop_idx;
     sklansky_func sklansky;
 
     if( CV_IS_SEQ( array ))
@@ -409,6 +406,7 @@ cvConvexHull2( const CvArr* array, void* hull_storage,
             for( i = tr_count - 1; i > 0; i-- )
                 CV_WRITE_SEQ_ELEM( pointer[tr_stack[i]][0], writer );
         }
+        stop_idx = tr_count > 2 ? tr_stack[1] : tl_count > 2 ? tl_stack[tl_count - 2] : -1;
     }
 
     /* lower half */
@@ -424,6 +422,22 @@ cvConvexHull2( const CvArr* array, void* hull_storage,
             CV_SWAP( bl_count, br_count, t_count );
         }
 
+        if( stop_idx >= 0 )
+        {
+            int check_idx = bl_count > 2 ? bl_stack[1] :
+                            bl_count + br_count > 2 ? br_stack[2-bl_count] : -1;
+            if( check_idx == stop_idx || check_idx >= 0 &&
+                pointer[check_idx]->x == pointer[stop_idx]->x &&
+                pointer[check_idx]->y == pointer[stop_idx]->y )
+            {
+                /* if all the points lie on the same line, then
+                   the bottom part of the convex hull is the mirrored top part
+                   (except the exteme points).*/
+                bl_count = MIN( bl_count, 2 );
+                br_count = MIN( br_count, 2 );
+            }
+        }
+
         if( hulltype == CV_SEQ_ELTYPE_PPOINT )
         {
             for( i = 0; i < bl_count - 1; i++ )
@@ -527,7 +541,7 @@ cvConvexityDefects( const CvArr* array,
     if( CV_IS_SEQ( hull ))
     {
         int hulltype = CV_SEQ_ELTYPE( hull );
-        if( hulltype != CV_SEQ_ELTYPE_PPOINT || hulltype != CV_SEQ_ELTYPE_INDEX )
+        if( hulltype != CV_SEQ_ELTYPE_PPOINT && hulltype != CV_SEQ_ELTYPE_INDEX )
             CV_ERROR( CV_StsUnsupportedFormat,
                 "Convex hull must represented as a sequence "
                 "of indices or sequence of pointers" );
@@ -577,20 +591,20 @@ cvConvexityDefects( const CvArr* array,
 
         if( !is_index )
         {
-            CvPoint* pos = *CV_GET_SEQ_ELEM( CvPoint*, hull, 0 );
+            CvPoint* pos = *CV_SEQ_ELEM( hull, CvPoint*, 0 );
             CV_CALL( index1 = cvSeqElemIdx( ptseq, pos ));
 
-            pos = *CV_GET_SEQ_ELEM( CvPoint*, hull, 1 );
+            pos = *CV_SEQ_ELEM( hull, CvPoint*, 1 );
             CV_CALL( index2 = cvSeqElemIdx( ptseq, pos ));
 
-            pos = *CV_GET_SEQ_ELEM( CvPoint*, hull, 2 );
+            pos = *CV_SEQ_ELEM( hull, CvPoint*, 2 );
             CV_CALL( index3 = cvSeqElemIdx( ptseq, pos ));
         }
         else
         {
-            index1 = *CV_GET_SEQ_ELEM( int, hull, 0 );
-            index2 = *CV_GET_SEQ_ELEM( int, hull, 1 );
-            index3 = *CV_GET_SEQ_ELEM( int, hull, 2 );
+            index1 = *CV_SEQ_ELEM( hull, int, 0 );
+            index2 = *CV_SEQ_ELEM( hull, int, 1 );
+            index3 = *CV_SEQ_ELEM( hull, int, 2 );
         }
 
         sign += (index2 > index1) ? 1 : 0;
@@ -635,7 +649,7 @@ cvConvexityDefects( const CvArr* array,
 
         dx0 = (double)hull_next->x - (double)hull_cur->x;
         dy0 = (double)hull_next->y - (double)hull_cur->y;
-        assert( dx0 != 0 && dy0 != 0 ); 
+        assert( dx0 != 0 || dy0 != 0 ); 
         scale = 1./sqrt(dx0*dx0 + dy0*dy0);
 
         defect.start = hull_cur;
diff --git a/opencv/src/cv/cvconvolve.cpp b/opencv/src/cv/cvconvolve.cpp
new file mode 100644 (file)
index 0000000..b3c7549
--- /dev/null
@@ -0,0 +1,365 @@
+/*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.
+//
+//
+//                        Intel License Agreement
+//                For Open Source Computer Vision Library
+//
+// Copyright (C) 2000, Intel Corporation, 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 Intel Corporation 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*/
+
+#include "_cv.h"
+#include <limits.h>
+
+#define ICV_DEF_FILTER_FUNC( flavor, arrtype, worktype,                     \
+                             load_macro, cast_macro1, cast_macro2 )         \
+static CvStatus CV_STDCALL                                                  \
+icvFilter_##flavor##_CnR( arrtype* src, int srcstep,                        \
+                          arrtype* dst, int dststep, CvSize* roi,           \
+                          CvFilterState* state, int stage )                 \
+{                                                                           \
+    int width = roi->width;                                                 \
+    int src_height = roi->height;                                           \
+    int dst_height = src_height;                                            \
+    int x, y = 0, i;                                                        \
+                                                                            \
+    int ker_x = state->ker_x;                                               \
+    int ker_y = state->ker_y;                                               \
+    int ker_width = state->ker_width;                                       \
+    int ker_height = state->ker_height;                                     \
+    const float *ker_data = (const float*)state->ker0;                      \
+                                                                            \
+    int crows = state->crows;                                               \
+    arrtype **rows = (arrtype**) (state->rows);                             \
+    arrtype* tbuf = (arrtype*)(state->tbuf);                                \
+                                                                            \
+    int channels = state->channels;                                         \
+    int ker_x_n = ker_x * channels;                                         \
+    int ker_width_n = ker_width * channels;                                 \
+    int width_n = width * channels;                                         \
+                                                                            \
+    int starting_flag = 0;                                                  \
+    int width_rest = width_n & (CV_MORPH_ALIGN - 1);                        \
+    arrtype **ker_ptr, **ker = (arrtype**)cvStackAlloc(                     \
+                ker_width*ker_height*sizeof(ker[0]) );                      \
+    float* ker_coeffs0 = (float*)cvStackAlloc(                              \
+                ker_width*ker_height*sizeof(ker_coeffs0[0]) );              \
+    float* ker_coeffs = ker_coeffs0;                                        \
+                                                                            \
+    for( i = 0; i < ker_height; i++ )                                       \
+        for( x = 0; x < ker_width; x++ )                                    \
+        {                                                                   \
+            int t = ((int*)ker_data)[i*ker_width + x];                      \
+            if( t )                                                         \
+            {                                                               \
+                *(int*)ker_coeffs = t;                                      \
+                ker_coeffs++;                                               \
+            }                                                               \
+        }                                                                   \
+                                                                            \
+    /* initialize cyclic buffer when starting */                            \
+    if( stage == CV_WHOLE || stage == CV_START )                            \
+    {                                                                       \
+        for( i = 0; i < ker_height; i++ )                                   \
+        {                                                                   \
+            rows[i] = (arrtype*)(state->buffer + state->buffer_step * i);   \
+        }                                                                   \
+        crows = ker_y;                                                      \
+        if( stage != CV_WHOLE )                                             \
+            dst_height -= ker_height - ker_y - 1;                           \
+        starting_flag = 1;                                                  \
+    }                                                                       \
+                                                                            \
+    if( stage == CV_END )                                                   \
+        dst_height += ker_height - ker_y - 1;                               \
+                                                                            \
+    do                                                                      \
+    {                                                                       \
+        arrtype *tsrc, *tdst;                                               \
+        int need_copy = 0;                                                  \
+                                                                            \
+        /* fill cyclic buffer */                                            \
+        for( ; crows < ker_height; crows++ )                                \
+        {                                                                   \
+            tsrc = src;                                                     \
+            tdst = rows[crows];                                             \
+                                                                            \
+            if( src_height-- <= 0 )                                         \
+            {                                                               \
+                if( stage != CV_WHOLE && stage != CV_END )                  \
+                    break;                                                  \
+                /* duplicate last row */                                    \
+                tsrc = rows[crows - 1];                                     \
+                CV_COPY( tdst, tsrc, width_n + ker_width_n, x );            \
+                continue;                                                   \
+            }                                                               \
+                                                                            \
+            src += srcstep;                                                 \
+                                                                            \
+            CV_COPY( tdst + ker_x_n, tsrc, width_n, x );                    \
+                                                                            \
+            /* make replication borders */                                  \
+            for( i = ker_x_n - 1; i >= 0; i-- )                             \
+                tdst[i] = tdst[i + channels];                               \
+            for( i = width_n + ker_x_n; i < width_n + ker_width_n; i++ )    \
+                tdst[i] = tdst[i - channels];                               \
+        }                                                                   \
+                                                                            \
+        if( starting_flag )                                                 \
+        {                                                                   \
+            starting_flag = 0;                                              \
+            tsrc = rows[ker_y];                                             \
+                                                                            \
+            for( i = 0; i < ker_y; i++ )                                    \
+            {                                                               \
+                tdst = rows[i];                                             \
+                CV_COPY( tdst, tsrc, width_n + ker_width_n, x );            \
+            }                                                               \
+        }                                                                   \
+                                                                            \
+        /* do convolution */                                                \
+        if( crows < ker_height )                                            \
+            break;                                                          \
+                                                                            \
+        tdst = dst;                                                         \
+        if( width_rest )                                                    \
+        {                                                                   \
+            need_copy = width_n < CV_MORPH_ALIGN || y == dst_height - 1;    \
+                                                                            \
+            if( need_copy )                                                 \
+                tdst = tbuf;                                                \
+            else                                                            \
+                CV_COPY( tbuf + width_n, dst + width_n, CV_MORPH_ALIGN, x );\
+        }                                                                   \
+                                                                            \
+        ker_ptr = ker;                                                      \
+        for( i = 0; i < ker_height; i++ )                                   \
+            for( x = 0; x < ker_width; x++ )                                \
+                if( ((int*)ker_data)[i*ker_width + x] )                     \
+                    *ker_ptr++ = rows[i] + x*channels;                      \
+                                                                            \
+        if( channels == 3 )                                                 \
+        {                                                                   \
+            for( x = 0; x < width_n; x += 3 )                               \
+            {                                                               \
+                float sum0 = 0, sum1 = 0, sum2 = 0;                         \
+                worktype t0, t1, t2;                                        \
+                arrtype** kp = ker;                                         \
+                ker_coeffs = ker_coeffs0;                                   \
+                while( kp != ker_ptr )                                      \
+                {                                                           \
+                    arrtype* tp = *kp++;                                    \
+                    float f = *ker_coeffs++;                                \
+                    sum0 += load_macro(tp[x])*f;                            \
+                    sum1 += load_macro(tp[x+1])*f;                          \
+                    sum2 += load_macro(tp[x+2])*f;                          \
+                }                                                           \
+                t0 = cast_macro1(sum0);                                     \
+                t1 = cast_macro1(sum1);                                     \
+                t2 = cast_macro1(sum2);                                     \
+                tdst[x] = cast_macro2(t0);                                  \
+                tdst[x+1] = cast_macro2(t1);                                \
+                tdst[x+2] = cast_macro2(t2);                                \
+            }                                                               \
+        }                                                                   \
+        else                                                                \
+        {                                                                   \
+            for( x = 0; x < width_n; x += 4 )                               \
+            {                                                               \
+                float sum0 = 0, sum1 = 0, sum2 = 0, sum3 = 0;               \
+                worktype t0, t1;                                            \
+                arrtype** kp = ker;                                         \
+                ker_coeffs = ker_coeffs0;                                   \
+                while( kp != ker_ptr )                                      \
+                {                                                           \
+                    arrtype* tp = *kp++;                                    \
+                    float f = *ker_coeffs++;                                \
+                    sum0 += load_macro(tp[x])*f;                            \
+                    sum1 += load_macro(tp[x+1])*f;                          \
+                    sum2 += load_macro(tp[x+2])*f;                          \
+                    sum3 += load_macro(tp[x+3])*f;                          \
+                }                                                           \
+                t0 = cast_macro1(sum0);                                     \
+                t1 = cast_macro1(sum1);                                     \
+                tdst[x] = cast_macro2(t0);                                  \
+                tdst[x+1] = cast_macro2(t1);                                \
+                t0 = cast_macro1(sum2);                                     \
+                t1 = cast_macro1(sum3);                                     \
+                tdst[x+2] = cast_macro2(t0);                                \
+                tdst[x+3] = cast_macro2(t1);                                \
+            }                                                               \
+        }                                                                   \
+                                                                            \
+        if( width_rest )                                                    \
+        {                                                                   \
+            if( need_copy )                                                 \
+                CV_COPY( dst, tbuf, width_n, x );                           \
+            else                                                            \
+                CV_COPY( dst + width_n, tbuf + width_n, CV_MORPH_ALIGN, x );\
+        }                                                                   \
+                                                                            \
+        /* rotate buffer */                                                 \
+        {                                                                   \
+            arrtype *t = rows[0];                                           \
+                                                                            \
+            CV_COPY( rows, rows + 1, ker_height - 1, i );                   \
+            rows[i] = t;                                                    \
+            crows--;                                                        \
+            dst += dststep;                                                 \
+        }                                                                   \
+    }                                                                       \
+    while( ++y < dst_height );                                              \
+                                                                            \
+    roi->height = y;                                                        \
+    state->crows = crows;                                                   \
+                                                                            \
+    return CV_OK;                                                           \
+}
+
+
+ICV_DEF_FILTER_FUNC( 8u, uchar, int, CV_8TO32F, cvRound, CV_CAST_8U )
+ICV_DEF_FILTER_FUNC( 16u, ushort, int, CV_NOP, cvRound, CV_CAST_16U )
+ICV_DEF_FILTER_FUNC( 32f, float, float, CV_NOP, CV_NOP, CV_NOP )
+
+
+static void icvInitFilterTab( CvFuncTable* tab )
+{
+    tab->fn_2d[CV_8U] = (void*)icvFilter_8u_CnR;
+    tab->fn_2d[CV_16U] = (void*)icvFilter_16u_CnR;
+    tab->fn_2d[CV_32F] = (void*)icvFilter_32f_CnR;
+}
+
+
+CV_IMPL void
+cvFilter2D( const CvArr* _src, CvArr* _dst, const CvMat* _kernel, CvPoint anchor )
+{
+    static CvFuncTable filter_tab;
+    static int inittab = 0;
+    CvFilterState *state = 0;
+    float* kernel_data = 0;
+    int local_alloc = 1;
+
+    CV_FUNCNAME( "cvFilter2D" );
+
+    __BEGIN__;
+
+    CvFilterFunc func = 0;
+    int coi1 = 0, coi2 = 0;
+    CvMat srcstub, *src = (CvMat*)_src;
+    CvMat dststub, *dst = (CvMat*)_dst;
+    CvSize size;
+    int type, depth;
+    int src_step, dst_step;
+    CvMat kernel_hdr;
+    const CvMat* kernel = _kernel;
+
+    if( !inittab )
+    {
+        icvInitFilterTab( &filter_tab );
+        inittab = 1;
+    }
+
+    CV_CALL( src = cvGetMat( src, &srcstub, &coi1 ));
+    CV_CALL( dst = cvGetMat( dst, &dststub, &coi2 ));
+
+    if( coi1 != 0 || coi2 != 0 )
+        CV_ERROR( CV_BadCOI, "" );
+
+    type = CV_MAT_TYPE( src->type );
+
+    if( !CV_ARE_SIZES_EQ( src, dst ))
+        CV_ERROR( CV_StsUnmatchedSizes, "" );
+
+    if( !CV_ARE_TYPES_EQ( src, dst ))
+        CV_ERROR( CV_StsUnmatchedFormats, "" );
+
+    if( !CV_IS_MAT(kernel) ||
+        (CV_MAT_TYPE(kernel->type) != CV_32F &&
+        CV_MAT_TYPE(kernel->type) != CV_64F ))
+        CV_ERROR( CV_StsBadArg, "kernel must be single-channel floating-point matrix" );
+
+    if( anchor.x == -1 && anchor.y == -1 )
+        anchor = cvPoint(kernel->cols/2,kernel->rows/2);
+
+    if( (unsigned)anchor.x >= (unsigned)kernel->cols ||
+        (unsigned)anchor.y >= (unsigned)kernel->rows )
+        CV_ERROR( CV_StsOutOfRange, "anchor point is out of kernel" );
+
+    if( CV_MAT_TYPE(kernel->type) != CV_32F )
+    {
+        int sz = kernel->rows*kernel->cols*sizeof(kernel_data[0]);
+        if( sz < CV_MAX_LOCAL_SIZE )
+            kernel_data = (float*)cvStackAlloc( sz );
+        else
+        {
+            CV_CALL( kernel_data = (float*)cvAlloc( sz ));
+            local_alloc = 0;
+        }
+        kernel_hdr = cvMat( kernel->rows, kernel->cols, CV_32F, kernel_data );
+        cvConvertScale( kernel, &kernel_hdr, 1, 0 );
+        kernel = &kernel_hdr;
+    }
+
+    size = cvGetMatSize( src );
+    
+    depth = CV_MAT_DEPTH(type);
+    IPPI_CALL( icvFilterInitAlloc( src->cols, cv32f, CV_MAT_CN(type),
+                                   cvSize(kernel->cols, kernel->rows), anchor,
+                                   kernel->data.ptr, ICV_GENERIC_KERNEL, &state ));
+
+    if( CV_MAT_CN(type) == 2 )
+        CV_ERROR( CV_BadNumChannels, "Unsupported number of channels" );
+
+    func = (CvFilterFunc)(filter_tab.fn_2d[depth]);
+
+    if( !func )
+        CV_ERROR( CV_StsUnsupportedFormat, "" );
+
+    src_step = src->step;
+    dst_step = dst->step;
+
+    if( size.height == 1 )
+        src_step = dst_step = CV_AUTOSTEP;
+
+    IPPI_CALL( func( src->data.ptr, src_step, dst->data.ptr,
+                     dst_step, &size, state, 0 ));
+
+    __END__;
+
+    icvFilterFree( &state );
+    if( !local_alloc )
+        cvFree( (void**)&kernel_data );
+}
+
+/* End of file. */
index 3536993b97db9f7de58530482ba87d26913bf46f..a573bcf2f289fb1eb4d548bf69df0146cbd692a8 100644 (file)
@@ -41,7 +41,7 @@
 
 #include "_cv.h"
 
-CvStatus  icvCalcValues(float* Dx2Blured,
+static CvStatus  icvCalcValues(float* Dx2Blured,
                         float* Dy2Blured,
                         float* DxyBlured,
                         int width,
@@ -98,7 +98,7 @@ CvStatus  icvCalcValues(float* Dx2Blured,
             {
                 float apc = a + c;
                 float discr = apc * apc - 4 * det;
-                float Sqrt  = (float)sqrt( discr );
+                float Sqrt  = (float)sqrt( (double)discr );
                 float Inorm1,Inorm2,x1,x2,y1,y2;
 
                 l1 = (apc + Sqrt)*0.5f;
@@ -110,8 +110,8 @@ CvStatus  icvCalcValues(float* Dx2Blured,
                 y1 = b;
                 y2 = (-( a - l2 ));
 
-                Inorm1 = 1.f/(float)sqrt(x1*x1 + x2*x2);
-                Inorm2 = 1.f/(float)sqrt(y1*y1 + y2*y2);
+                Inorm1 = 1.f/(float)sqrt((double)x1*x1 + (double)x2*x2);
+                Inorm2 = 1.f/(float)sqrt((double)y1*y1 + (double)y2*y2);
                 eigenvv[ 6 * j ] = l1;
                 eigenvv[ 6 * j + 1] = l2;
                 eigenvv[ 6 * j + 2] = x1 * Inorm1;
@@ -179,8 +179,9 @@ static CvStatus  icvMulDBuffers32f( CvSize roi,
     return CV_NO_ERR;
 }
 
-IPCVAPI_IMPL(CvStatus, icvEigenValsVecsGetSize, ( int roiWidth,int apertureSize,
-                                                  int avgWindow, int* bufferSize ))
+static CvStatus CV_STDCALL
+icvEigenValsVecsGetSize( int roiWidth,int apertureSize,
+                         int avgWindow, int* bufferSize )
 {
     if((roiWidth<=0)&&(apertureSize<=3)&&(avgWindow<=3))return CV_BADSIZE_ERR;
     if(!bufferSize) return CV_NULLPTR_ERR;
@@ -204,12 +205,13 @@ IPCVAPI_IMPL(CvStatus, icvEigenValsVecsGetSize, ( int roiWidth,int apertureSize,
 //              CV_NO_ERR if all ok or error code
 //    Notes:
 //F*/
-IPCVAPI_IMPL(CvStatus, icvEigenValsVecs_8u32f_C1R, ( const unsigned char* pSrc, int srcStep,
-                                                     float* eigenvv, int eigenvvStep,
-                                                     CvSize roi, int kerSize,
-                                                     int blSize, void*  pBuffer ))
+static CvStatus CV_STDCALL
+icvEigenValsVecs_8u32f_C1R( const uchar* pSrc, int srcStep,
+                            float* eigenvv, int eigenvvStep,
+                            CvSize roi, int kerSize,
+                            int blSize, void*  pBuffer )
 {
-int RestToSobel = roi.height;
+    int RestToSobel = roi.height;
     CvSize curROI;
     int i;
     int HBuf = MAX(7,MAX(kerSize, blSize));
@@ -307,110 +309,12 @@ int RestToSobel = roi.height;
     return CV_NO_ERR;
 }
 
-IPCVAPI_IMPL(CvStatus, icvEigenValsVecs_8s32f_C1R, ( const char* pSrc, int srcStep,
-                                                  float* eigenvv, int eigenvvStep,
-                                                  CvSize roi, int kerSize,
-                                                  int blSize, void* pBuffer ))
-{
-    int RestToSobel = roi.height;
-    CvSize curROI;
-    int i;
-    int HBuf = MAX(7,MAX(kerSize, blSize));
-    /* multiplied derivatives buffers - used for bluring */
-    float* flBufXX = (float*)pBuffer;
-    float* flBufYY = flBufXX+(HBuf+1)*roi.width;
-    float* flBufXY = flBufYY+(HBuf+1)*roi.width;
-    float denom = 1;
-    
-    _CvConvState* stX;
-    _CvConvState* stY;
-    _CvConvState* stBX;
-    _CvConvState* stBY;
-    _CvConvState* stBXY;
-    /* Step of all buffers in pixels */
-    int ustep  = roi.width*sizeof(float);
-    int Temp;
-    char* src = (char*)pSrc;
-
-    
-    /* Check Bad Arguments */
-    if((src == NULL) || (eigenvv == NULL))return CV_NULLPTR_ERR;
-    if((srcStep <= 0)||(eigenvvStep <= 0))return CV_BADSIZE_ERR;
-    if((roi.width <= 0)||(roi.height <= 0 )) return CV_BADSIZE_ERR;
-    
-    for(i = 0; i < kerSize-1;i++)denom *= 2;
-    denom = denom*denom * 255*blSize*blSize;
-    denom=1.0f/denom;
-    curROI.width = roi.width;
-    icvSobelInitAlloc(roi.width,cv8u,kerSize,CV_ORIGIN_TL,1,0,&stX);
-    icvSobelInitAlloc(roi.width,cv8u,kerSize,CV_ORIGIN_TL,0,1,&stY);
-    icvBlurInitAlloc(roi.width,cv32f,kerSize,&stBX);
-    icvBlurInitAlloc(roi.width,cv32f,kerSize,&stBY);
-    icvBlurInitAlloc(roi.width,cv32f,kerSize,&stBXY);
 
-            
-    /* Main Cycle */
-    while ( RestToSobel)
-    {
-        int stage;
-        if((RestToSobel == roi.height))
-        {
-            stage = CV_START;
-            Temp = curROI.height = HBuf+kerSize/2; 
-            
-        }
-        else if(RestToSobel+kerSize/2+blSize/2<=HBuf)
-        {
-            stage = CV_END;
-            Temp = curROI.height = RestToSobel;
-        }
-        else
-        {
-            stage = CV_MIDDLE;
-            curROI.height = Temp = (RestToSobel<= HBuf)?RestToSobel-1:HBuf; 
-                             
-        }
-        RestToSobel-=Temp;
-        icvSobel_8s16s_C1R( src, srcStep, (short*)(flBufXX+roi.width),
-                          ustep, &curROI,stX, stage);
-
-        curROI.height =Temp;
-        icvSobel_8s16s_C1R( src, srcStep, (short*)(flBufYY+roi.width),
-                          ustep, &curROI,stY, stage);
-        
-        src += Temp * srcStep;
-          
-/****************************************************************************************\
-*                     Multy Buffers                                                      *
-\****************************************************************************************/
-        icvMulDBuffers(curROI,ustep,flBufXX+roi.width,flBufXY+roi.width,flBufYY+roi.width);
-        Temp = curROI.height;
-        icvBlur_32f_C1R(flBufXX+roi.width,ustep,flBufXX,ustep,&curROI,stBX,stage);
-        curROI.height =Temp;
-        icvBlur_32f_C1R(flBufXY+roi.width,ustep,flBufXY,ustep,&curROI,stBXY,stage);
-        curROI.height =Temp;
-        icvBlur_32f_C1R(flBufYY+roi.width,ustep,flBufYY,ustep,&curROI,stBY,stage);
-        
-        /* calc values */
-
-        icvCalcValues( flBufXX, flBufYY, flBufXY, roi.width,ustep,
-                     eigenvv, eigenvvStep, curROI.height,denom);
-        eigenvv += curROI.height * eigenvvStep/4;
-
-    }
-   
-    icvFilterFree(&stX);
-    icvFilterFree(&stY);
-    icvFilterFree(&stBX);
-    icvFilterFree(&stBY);
-    icvFilterFree(&stBXY);
-    return CV_NO_ERR;
-}
-
-IPCVAPI_IMPL(CvStatus, icvEigenValsVecs_32f_C1R, ( const float* pSrc, int srcStep,
-                                                   float* eigenvv, int eigenvvStep,
-                                                   CvSize roi, int kerSize,
-                                                   int blSize, void* pBuffer ))
+static CvStatus CV_STDCALL
+icvEigenValsVecs_32f_C1R( const float* pSrc, int srcStep,
+                          float* eigenvv, int eigenvvStep,
+                          CvSize roi, int kerSize,
+                          int blSize, void* pBuffer )
 {
     int RestToSobel = roi.height;
     CvSize curROI;
@@ -512,5 +416,81 @@ IPCVAPI_IMPL(CvStatus, icvEigenValsVecs_32f_C1R, ( const float* pSrc, int srcSte
 }
 
 
+#define ICV_DEF_INIT_TAB_DETECTION( FUNCNAME )              \
+static void icvInit##FUNCNAME##Table( CvFuncTable* table )  \
+{                                                           \
+    table->fn_2d[CV_8U] = (void*)icv##FUNCNAME##_8u32f_C1R; \
+    table->fn_2d[CV_8S] = 0;                                \
+    table->fn_2d[CV_32F] = (void*)icv##FUNCNAME##_32f_C1R;  \
+}
+
+
+ICV_DEF_INIT_TAB_DETECTION( EigenValsVecs )
+
+typedef CvStatus (CV_STDCALL * CvEigFunc)( const void* src, int srcstep,
+                                           void* dst, int dststep,
+                                           CvSize size, int aperture_size,
+                                           int block_size, void* buffer );
+
+CV_IMPL void
+cvCornerEigenValsAndVecs( const void* srcarr, void* eigenvarr,
+                          int block_size, int aperture_size )
+{
+    static CvFuncTable eig_tab;
+    static int inittab = 0;
+    void *buffer = 0;
+
+    CV_FUNCNAME( "cvCornerEigenValsAndVecs" );
+
+    __BEGIN__;
+
+    CvSize src_size;
+    int buf_size = 0;
+    CvEigFunc func = 0;
+
+    CvMat stub, *src = (CvMat*)srcarr;
+    CvMat eigstub, *eigenv = (CvMat*)eigenvarr;
+
+    if( !inittab )
+    {
+        icvInitEigenValsVecsTable( &eig_tab );
+        inittab = 1;
+    }
+
+    CV_CALL( src = cvGetMat( srcarr, &stub ));
+    CV_CALL( eigenv = cvGetMat( eigenv, &eigstub ));
+
+    if( CV_MAT_CN(src->type) != 1 )
+        CV_ERROR(CV_StsBadArg, "Source image has more than 1 channel");
+
+    if( CV_MAT_CN(eigenv->type)*eigenv->width != src->width*6 )
+        CV_ERROR(CV_StsBadArg, "Eigen-vals&vecs image should be 6 times "
+                               "wider than the source image");
+
+    if( src->height != eigenv->height )
+        CV_ERROR( CV_StsUnmatchedSizes, "" );
+
+    if( CV_MAT_DEPTH(eigenv->type) != CV_32F )
+        CV_ERROR( CV_BadDepth, "Eigen-vals&vecs image does not have IPL_DEPTH_32F depth" );
+
+    func = (CvEigFunc)(eig_tab.fn_2d[CV_MAT_DEPTH(src->type)]);
+    if( !func )
+        CV_ERROR( CV_StsUnsupportedFormat, "" );
+
+    src_size = cvGetMatSize( src );
+
+    IPPI_CALL( icvEigenValsVecsGetSize( src_size.width, aperture_size,
+                                        block_size, &buf_size ));
+    CV_CALL( buffer = cvAlloc( buf_size ));
+
+    IPPI_CALL( func( src->data.ptr, src->step, eigenv->data.ptr, eigenv->step,
+                     src_size, aperture_size, block_size, buffer ));
+
+    __END__;
+
+    cvFree( &buffer );
+}
+
+
 /* End of file */
 
index 5274f573f6a2e6a48af505bac22f558fcdd172d1..f1ed516a4c8b40895842da2f63094a4879db0966 100644 (file)
@@ -83,7 +83,7 @@ cvFindCornerSubPix( const void* srcarr, CvPoint2D32f* corners,
     if( win.width <= 0 || win.height <= 0 )
         CV_ERROR( CV_StsBadSize, "" );
 
-    size = icvGetMatSize( src );
+    size = cvGetMatSize( src );
 
     if( size.width < win_w + 4 || size.height < win_h + 4 )
         CV_ERROR( CV_StsBadSize, "" );
@@ -93,7 +93,7 @@ cvFindCornerSubPix( const void* srcarr, CvPoint2D32f* corners,
     {
     case CV_TERMCRIT_ITER:
         eps = 0.f;
-        max_iters = criteria.maxIter;
+        max_iters = criteria.max_iter;
         break;
     case CV_TERMCRIT_EPS:
         eps = criteria.epsilon;
@@ -101,7 +101,7 @@ cvFindCornerSubPix( const void* srcarr, CvPoint2D32f* corners,
         break;
     case CV_TERMCRIT_ITER | CV_TERMCRIT_EPS:
         eps = criteria.epsilon;
-        max_iters = criteria.maxIter;
+        max_iters = criteria.max_iter;
         break;
     default:
         assert( 0 );
index a0bbdfa1e1433f1c1b4493391243d1ea4facbc6a..7ed25c0bca25da7802658af9f8f1f318f3990c89 100644 (file)
@@ -144,9 +144,8 @@ static int icvCalcKer( char *kernel, int order, int size,
 }
 
 
-IPCVAPI_IMPL( CvStatus, icvSobelInitAlloc,(
-            int roiwidth, int datatype, int size,
-            int origin, int dx, int dy, CvFilterState** state ))
+CvStatus CV_STDCALL icvSobelInitAlloc( int roiwidth, int datatype, int size,
+                                       int origin, int dx, int dy, CvFilterState** state )
 {
     #define MAX_KERNEL_SIZE  7
     int ker[MAX_KERNEL_SIZE*2+1];
@@ -187,10 +186,13 @@ IPCVAPI_IMPL( CvStatus, icvSobelInitAlloc,(
     y_filter_type = icvCalcKer( (char*)(ker + x_size), dy, size < 0 ? size : y_size,
                                 worktype, origin != 0 );
 
-    status = icvFilterInitAlloc( roiwidth, worktype, 1, cvSize( x_size, y_size ),
-                                 cvPoint( x_size/2, y_size/2 ), ker,
-                                 ICV_MAKE_SEPARABLE_KERNEL(x_filter_type, y_filter_type),
-                                 state );
+    {
+    CvSize element_size = { x_size, y_size };
+    CvPoint element_anchor = { x_size/2, y_size/2 };
+    
+    status = icvFilterInitAlloc( roiwidth, worktype, 1, element_size, element_anchor, ker,
+                                 ICV_MAKE_SEPARABLE_KERNEL(x_filter_type, y_filter_type), state );
+    }
     if( status < 0 )
         return status;
 
@@ -200,10 +202,9 @@ IPCVAPI_IMPL( CvStatus, icvSobelInitAlloc,(
 }
 
 
-IPCVAPI_IMPL( CvStatus, icvSobel_8u16s_C1R,(
-             const uchar* pSrc, int srcStep,
-             short* dst, int dstStep, CvSize* roiSize,
-             CvFilterState* state, int stage ))
+CvStatus CV_STDCALL icvSobel_8u16s_C1R( const uchar* pSrc, int srcStep,
+                                        short* dst, int dstStep, CvSize* roiSize,
+                                        CvFilterState* state, int stage )
 {
     uchar* src = (uchar*)pSrc;
     int width = roiSize->width;
@@ -560,12 +561,11 @@ IPCVAPI_IMPL( CvStatus, icvSobel_8u16s_C1R,(
 }
 
 
-IPCVAPI_IMPL( CvStatus, icvSobel_8s16s_C1R,(
-             const char* pSrc, int srcStep,
-             short* dst, int dstStep, CvSize* roiSize,
-             CvFilterState* state, int stage ))
+CvStatus CV_STDCALL icvSobel_32f_C1R( const float* pSrc, int srcStep,
+                                      float* dst, int dstStep, CvSize* roiSize,
+                                      CvFilterState* state, int stage )
 {
-    char* src = (char*)pSrc;
+    float* src = (float*)pSrc;
     int width = roiSize->width;
     int src_height = roiSize->height;
     int dst_height = src_height;
@@ -578,13 +578,13 @@ IPCVAPI_IMPL( CvStatus, icvSobel_8s16s_C1R,(
     int ker_right = ker_width - ker_x;
 
     int crows = state->crows;
-    int **rows = (int**)(state->rows);
-    short *tbufw = (short*)(state->tbuf);
-    int *trow = 0;
+    float **rows = (float**)(state->rows);
+    float *tbufw = (float*)(state->tbuf);
+    float *trow = 0;
 
-    int* fmaskX = (int*)(state->ker0) + ker_x;
-    int* fmaskY = (int*)(state->ker1) + ker_y;
-    int fmX0 = fmaskX[0], fmY0 = fmaskY[0];
+    float* fmaskX = (float*)(state->ker0) + ker_x;
+    float* fmaskY = (float*)(state->ker1) + ker_y;
+    float fmX0 = fmaskX[0], fmY0 = fmaskY[0];
 
     int is_small_width = width < MAX( ker_x, ker_right );
     int starting_flag = 0;
@@ -600,7 +600,7 @@ IPCVAPI_IMPL( CvStatus, icvSobel_8s16s_C1R,(
     if( stage == CV_WHOLE || stage == CV_START )
     {
         for( i = 0; i < ker_height; i++ )
-            rows[i] = (int*)(state->buffer + state->buffer_step * i);
+            rows[i] = (float*)(state->buffer + state->buffer_step * i);
 
         crows = ker_y;
         if( stage != CV_WHOLE )
@@ -611,15 +611,16 @@ IPCVAPI_IMPL( CvStatus, icvSobel_8s16s_C1R,(
     if( stage == CV_END )
         dst_height += ker_height - ker_y - 1;
 
+    srcStep /= sizeof(src[0]);
     dstStep /= sizeof(dst[0]);
 
     do
     {
         int need_copy = is_small_width | (y == 0);
-        char *tsrc;
-        int   *tdst;
-        short *tdst2;
-        int   *saved_row = rows[ker_y];
+        float *tsrc;
+        float *tdst;
+        float *tdst2;
+        float *saved_row = rows[ker_y];
 
         /* fill cyclic buffer - horizontal filtering */
         for( ; crows < ker_height; crows++ )
@@ -641,7 +642,7 @@ IPCVAPI_IMPL( CvStatus, icvSobel_8s16s_C1R,(
 
             if( ker_width > 1 )
             {
-                char* tbufc = (char*)tbufw;
+                float* tbufc = (float*)tbufw;
 
                 if( need_copy )
                 {
@@ -656,7 +657,7 @@ IPCVAPI_IMPL( CvStatus, icvSobel_8s16s_C1R,(
 
                 /* make replication borders */
                 {
-                char pix = tsrc[ker_x];
+                float pix = tsrc[ker_x];
                 CV_SET( tsrc, pix, ker_x, x );
 
                 pix = tsrc[width + ker_x - 1];
@@ -676,7 +677,7 @@ IPCVAPI_IMPL( CvStatus, icvSobel_8s16s_C1R,(
                         for( i = 0; i < width; i++ )
                         {
                             int j;
-                            int t0 = tsrc[i + ker_x]*fmX0;
+                            float t0 = tsrc[i + ker_x]*fmX0;
 
                             for( j = 1; j <= ker_x; j++ )
                                 t0 += (tsrc[i+ker_x+j] - tsrc[i+ker_x-j])*fmaskX[j];
@@ -703,7 +704,7 @@ IPCVAPI_IMPL( CvStatus, icvSobel_8s16s_C1R,(
                         for( i = 0; i < width; i++ )
                         {
                             int j;
-                            int t0 = tsrc[i + ker_x]*fmX0;
+                            float t0 = tsrc[i + ker_x]*fmX0;
 
                             for( j = 1; j <= ker_x; j++ )
                                 t0 += (tsrc[i+ker_x+j] + tsrc[i+ker_x-j])*fmaskX[j];
@@ -764,29 +765,29 @@ IPCVAPI_IMPL( CvStatus, icvSobel_8s16s_C1R,(
             {
                 if( y_type == ICV_m1_0_1_KERNEL )
                 {
-                    int *trow1 = rows[origin*2], *trow2 = rows[(origin^1)*2];
+                    float *trow1 = rows[origin*2], *trow2 = rows[(origin^1)*2];
 
                     for( x = 0; x < width; x += CV_MORPH_ALIGN )
                     {
-                        int val0, val1;
+                        float val0, val1;
                         val0 = trow2[x] - trow1[x];
                         val1 = trow2[x + 1] - trow1[x + 1];
                 
-                        tdst2[x + 0] = (short)val0;
-                        tdst2[x + 1] = (short)val1;
+                        tdst2[x + 0] = (float)val0;
+                        tdst2[x + 1] = (float)val1;
                 
                         val0 = trow2[x + 2] - trow1[x + 2];
                         val1 = trow2[x + 3] - trow1[x + 3];
                 
-                        tdst2[x + 2] = (short)val0;
-                        tdst2[x + 3] = (short)val1;
+                        tdst2[x + 2] = (float)val0;
+                        tdst2[x + 3] = (float)val1;
                     }
                 }
                 else
                 {
                     for( x = 0; x < width; x += CV_MORPH_ALIGN )
                     {
-                        int val0, val1, val2, val3;
+                        float val0, val1, val2, val3;
 
                         val0 = trow[x]*fmY0;
                         val1 = trow[x + 1]*fmY0;
@@ -795,8 +796,8 @@ IPCVAPI_IMPL( CvStatus, icvSobel_8s16s_C1R,(
 
                         for( i = 1; i <= ker_y; i++ )
                         {
-                            int *trow1, *trow2;
-                            int m = fmaskY[i];
+                            float *trow1, *trow2;
+                            float m = fmaskY[i];
                             trow1 = rows[ker_y - i];
                             trow2 = rows[ker_y + i];
                             val0 += (trow2[x] - trow1[x])*m;
@@ -805,10 +806,10 @@ IPCVAPI_IMPL( CvStatus, icvSobel_8s16s_C1R,(
                             val3 += (trow2[x+3] - trow1[x+3])*m;
                         }
 
-                        tdst2[x + 0] = CV_CAST_16S(val0);
-                        tdst2[x + 1] = CV_CAST_16S(val1);
-                        tdst2[x + 2] = CV_CAST_16S(val2);
-                        tdst2[x + 3] = CV_CAST_16S(val3);
+                        tdst2[x + 0] = val0;
+                        tdst2[x + 1] = val1;
+                        tdst2[x + 2] = val2;
+                        tdst2[x + 3] = val3;
                     }
                 }
             }
@@ -816,49 +817,49 @@ IPCVAPI_IMPL( CvStatus, icvSobel_8s16s_C1R,(
             {
                 if( y_type == ICV_1_2_1_KERNEL )
                 {
-                    int *trow1 = rows[0], *trow2 = rows[2];
+                    float *trow1 = rows[0], *trow2 = rows[2];
 
                     for( x = 0; x < width; x += CV_MORPH_ALIGN )
                     {
-                        int val0, val1;
+                        float val0, val1;
                         val0 = trow[x]*2 + trow1[x] + trow2[x];
                         val1 = trow[x + 1]*2 + trow1[x+1] + trow2[x+1];
                 
-                        tdst2[x + 0] = (short)val0;
-                        tdst2[x + 1] = (short)val1;
+                        tdst2[x + 0] = (float)val0;
+                        tdst2[x + 1] = (float)val1;
                 
                         val0 = trow[x + 2]*2 + trow1[x+2] + trow2[x+2];
                         val1 = trow[x + 3]*2 + trow1[x+3] + trow2[x+3];
                 
-                        tdst2[x + 2] = (short)val0;
-                        tdst2[x + 3] = (short)val1;
+                        tdst2[x + 2] = (float)val0;
+                        tdst2[x + 3] = (float)val1;
                     }
                 }
                 else if( y_type == ICV_3_10_3_KERNEL )
                 {
-                    int *trow1 = rows[0], *trow2 = rows[2];
+                    float *trow1 = rows[0], *trow2 = rows[2];
 
                     for( x = 0; x < width; x += CV_MORPH_ALIGN )
                     {
-                        int val0, val1;
+                        float val0, val1;
                         val0 = trow[x]*10 + (trow1[x] + trow2[x])*3;
                         val1 = trow[x + 1]*10 + (trow1[x+1] + trow2[x+1])*3;
                 
-                        tdst2[x + 0] = (short)val0;
-                        tdst2[x + 1] = (short)val1;
+                        tdst2[x + 0] = (float)val0;
+                        tdst2[x + 1] = (float)val1;
                 
                         val0 = trow[x + 2]*10 + (trow1[x+2] + trow2[x+2])*3;
                         val1 = trow[x + 3]*10 + (trow1[x+3] + trow2[x+3])*3;
                 
-                        tdst2[x + 2] = (short)val0;
-                        tdst2[x + 3] = (short)val1;
+                        tdst2[x + 2] = (float)val0;
+                        tdst2[x + 3] = (float)val1;
                     }
                 }
                 else
                 {
                     for( x = 0; x < width; x += CV_MORPH_ALIGN )
                     {
-                        int val0, val1, val2, val3;
+                        float val0, val1, val2, val3;
 
                         val0 = trow[x]*fmY0;
                         val1 = trow[x + 1]*fmY0;
@@ -867,8 +868,8 @@ IPCVAPI_IMPL( CvStatus, icvSobel_8s16s_C1R,(
 
                         for( i = 1; i <= ker_y; i++ )
                         {
-                            int *trow1, *trow2;
-                            int m = fmaskY[i];
+                            float *trow1, *trow2;
+                            float m = fmaskY[i];
                             trow1 = rows[ker_y - i];
                             trow2 = rows[ker_y + i];
                             val0 += (trow2[x] + trow1[x])*m;
@@ -877,10 +878,10 @@ IPCVAPI_IMPL( CvStatus, icvSobel_8s16s_C1R,(
                             val3 += (trow2[x+3] + trow1[x+3])*m;
                         }
 
-                        tdst2[x + 0] = CV_CAST_16S(val0);
-                        tdst2[x + 1] = CV_CAST_16S(val1);
-                        tdst2[x + 2] = CV_CAST_16S(val2);
-                        tdst2[x + 3] = CV_CAST_16S(val3);
+                        tdst2[x + 0] = val0;
+                        tdst2[x + 1] = val1;
+                        tdst2[x + 2] = val2;
+                        tdst2[x + 3] = val3;
                     }
                 }
             }
@@ -896,14 +897,14 @@ IPCVAPI_IMPL( CvStatus, icvSobel_8s16s_C1R,(
         else
         {
             for( x = 0; x < width; x++ )
-                dst[x] = (short)trow[x];
+                dst[x] = (float)trow[x];
         }
 
         rows[ker_y] = saved_row;
 
         /* rotate buffer */
         {
-            int *t = rows[0];
+            float *t = rows[0];
 
             CV_COPY( rows, rows + 1, ker_height - 1, i );
             rows[i] = t;
@@ -920,12 +921,87 @@ IPCVAPI_IMPL( CvStatus, icvSobel_8s16s_C1R,(
 }
 
 
-IPCVAPI_IMPL( CvStatus, icvSobel_32f_C1R,(
-             const float* pSrc, int srcStep,
-             float* dst, int dstStep, CvSize* roiSize,
-             CvFilterState* state, int stage ))
+/****************************************************************************************\
+*                                      S C H A R R                                       *
+\****************************************************************************************/
+
+static CvStatus CV_STDCALL
+icvScharrInitAlloc( int roiwidth, int datatype, int origin,
+                    int dx, int dy, CvFilterState** state )
+{
+    return icvSobelInitAlloc( roiwidth, datatype, CV_SCHARR, origin, dx, dy, state );
+}
+
+static CvStatus CV_STDCALL
+icvScharr_8u16s_C1R( const uchar* pSrc, int srcStep,
+                     short* dst, int dstStep, CvSize* roiSize,
+                     CvFilterState* state, int stage )
 {
-    float* src = (float*)pSrc;
+    assert( state->kerType == ICV_MAKE_SEPARABLE_KERNEL( ICV_m1_0_1_KERNEL, ICV_3_10_3_KERNEL ) ||
+            state->kerType == ICV_MAKE_SEPARABLE_KERNEL( ICV_3_10_3_KERNEL, ICV_m1_0_1_KERNEL ));
+    return icvSobel_8u16s_C1R( pSrc, srcStep, dst, dstStep, roiSize, state, stage );
+}
+
+
+static CvStatus CV_STDCALL
+icvScharr_32f_C1R( const float* pSrc, int srcStep,
+                   float* dst, int dstStep, CvSize* roiSize,
+                   CvFilterState* state, int stage )
+{
+    assert( state->kerType == ICV_MAKE_SEPARABLE_KERNEL( ICV_m1_0_1_KERNEL, ICV_3_10_3_KERNEL ) ||
+            state->kerType == ICV_MAKE_SEPARABLE_KERNEL( ICV_3_10_3_KERNEL, ICV_m1_0_1_KERNEL ));
+    return icvSobel_32f_C1R( pSrc, srcStep, dst, dstStep, roiSize, state, stage );
+}
+
+/****************************************************************************************\
+*                                      L A P L A C E                                     *
+\****************************************************************************************/
+
+static CvStatus CV_STDCALL
+icvLaplaceInitAlloc( int roiwidth, int datatype,
+                     int size, CvFilterState** state )
+{
+    #define MAX_KERNEL_SIZE  7
+    int ker[MAX_KERNEL_SIZE*2+1];
+    CvDataType worktype = datatype != cv32f ? cv32s : cv32f;
+    CvStatus status;
+    int x_filter_type, y_filter_type;
+    int x_size = size;
+    
+    if( !state )
+        return CV_NULLPTR_ERR;
+
+    if( (size&1) == 0 || size < 1 || size > MAX_KERNEL_SIZE )
+        return CV_BADRANGE_ERR;
+
+    if( size == 1 )
+        x_size = 3;
+
+    x_filter_type = icvCalcKer( (char*)ker, 2, x_size, worktype, 0 );
+    y_filter_type = icvCalcKer( (char*)(ker + x_size), 0, size, worktype, 0 );
+
+    {
+    CvSize element_size = { x_size, x_size };
+    CvPoint element_anchor = { x_size/2, x_size/2 };
+
+    status = icvFilterInitAlloc( roiwidth, worktype, 2, element_size, element_anchor, ker,
+                                 ICV_MAKE_SEPARABLE_KERNEL(x_filter_type, y_filter_type), state );
+    }
+    if( status < 0 )
+        return status;
+
+    (*state)->origin = 0;
+
+    return CV_OK;
+}
+
+
+static CvStatus CV_STDCALL
+icvLaplace_8u16s_C1R( const uchar* pSrc, int srcStep,
+                      short* dst, int dstStep, CvSize* roiSize,
+                      CvFilterState* state, int stage )
+{
+    uchar* src = (uchar*)pSrc;
     int width = roiSize->width;
     int src_height = roiSize->height;
     int dst_height = src_height;
@@ -938,29 +1014,24 @@ IPCVAPI_IMPL( CvStatus, icvSobel_32f_C1R,(
     int ker_right = ker_width - ker_x;
 
     int crows = state->crows;
-    float **rows = (float**)(state->rows);
-    float *tbufw = (float*)(state->tbuf);
-    float *trow = 0;
+    int **rows = (int**)(state->rows);
+    short *tbufw = (short*)(state->tbuf);
+    int *trow = 0;
 
-    float* fmaskX = (float*)(state->ker0) + ker_x;
-    float* fmaskY = (float*)(state->ker1) + ker_y;
-    float fmX0 = fmaskX[0], fmY0 = fmaskY[0];
+    int* fmaskX = (int*)(state->ker0) + ker_x;
+    int* fmaskY = (int*)(state->ker1) + ker_y;
+    int fmX0 = fmaskX[0], fmY0 = fmaskY[0];
 
     int is_small_width = width < MAX( ker_x, ker_right );
     int starting_flag = 0;
     int width_rest = width & (CV_MORPH_ALIGN - 1);
-    int origin = state->origin;
-    int x_type = ICV_X_KERNEL_TYPE(state->kerType),
-        y_type = ICV_Y_KERNEL_TYPE(state->kerType);
-    int x_asymm = (x_type & 3) - 1, /* <0 - general kind (not used),
-                                       0-symmetric, 1-asymmetric*/
-        y_asymm = (y_type & 3) - 1; 
+    int y_type = ICV_Y_KERNEL_TYPE(state->kerType);
 
     /* initialize cyclic buffer when starting */
     if( stage == CV_WHOLE || stage == CV_START )
     {
         for( i = 0; i < ker_height; i++ )
-            rows[i] = (float*)(state->buffer + state->buffer_step * i);
+            rows[i] = (int*)(state->buffer + state->buffer_step * i);
 
         crows = ker_y;
         if( stage != CV_WHOLE )
@@ -971,16 +1042,15 @@ IPCVAPI_IMPL( CvStatus, icvSobel_32f_C1R,(
     if( stage == CV_END )
         dst_height += ker_height - ker_y - 1;
 
-    srcStep /= sizeof(src[0]);
     dstStep /= sizeof(dst[0]);
 
     do
     {
         int need_copy = is_small_width | (y == 0);
-        float *tsrc;
-        float *tdst;
-        float *tdst2;
-        float *saved_row = rows[ker_y];
+        uchar *tsrc;
+        int   *tdst;
+        short *tdst2;
+        int   *saved_row = rows[ker_y];
 
         /* fill cyclic buffer - horizontal filtering */
         for( ; crows < ker_height; crows++ )
@@ -994,15 +1064,14 @@ IPCVAPI_IMPL( CvStatus, icvSobel_32f_C1R,(
                     break;
                 /* duplicate last row */
                 trow = rows[crows - 1];
-                CV_COPY( tdst, trow, width, x );
+                CV_COPY( tdst, trow, width*2, x );
                 continue;
             }
 
             need_copy |= src_height == 1;
 
-            if( ker_width > 1 )
             {
-                float* tbufc = (float*)tbufw;
+                uchar* tbufc = (uchar*)tbufw;
 
                 if( need_copy )
                 {
@@ -1017,824 +1086,59 @@ IPCVAPI_IMPL( CvStatus, icvSobel_32f_C1R,(
 
                 /* make replication borders */
                 {
-                float pix = tsrc[ker_x];
+                uchar pix = tsrc[ker_x];
                 CV_SET( tsrc, pix, ker_x, x );
 
                 pix = tsrc[width + ker_x - 1];
                 CV_SET( tsrc + width + ker_x, pix, ker_right, x );
                 }
 
-                if( x_asymm )
+                if( ker_width == 3 )
                 {
-                    /* horizontal filter: asymmetric case */
-                    if( x_type == ICV_m1_0_1_KERNEL )
+                    if( y_type == ICV_1_2_1_KERNEL )
                     {
                         for( i = 0; i < width; i++ )
-                            tdst[i] = tsrc[i+2] - tsrc[i];
+                        {
+                            int t0 = tsrc[i] + tsrc[i+2] - tsrc[i+1]*2;
+                            int t1 = tsrc[i] + tsrc[i+2] + tsrc[i+1]*2;
+                            tdst[i] = t0;
+                            tdst[i+width] = t1;
+                        }
                     }
                     else
                     {
                         for( i = 0; i < width; i++ )
                         {
-                            int j;
-                            float t0 = tsrc[i + ker_x]*fmX0;
-
-                            for( j = 1; j <= ker_x; j++ )
-                                t0 += (tsrc[i+ker_x+j] - tsrc[i+ker_x-j])*fmaskX[j];
-
+                            int t0 = tsrc[i] + tsrc[i+2] - tsrc[i+1]*2;
+                            int t1 = tsrc[i+1];
                             tdst[i] = t0;
+                            tdst[i+width] = t1;
                         }
                     }
                 }
-                else
+                else if( ker_width == 5 )
                 {
-                    if( x_type == ICV_1_2_1_KERNEL )
-                    {
-                        for( i = 0; i < width; i++ )
-                            tdst[i] = tsrc[i+1]*2 + tsrc[i] + tsrc[i+2];
-                    }
-                    else if( x_type == ICV_3_10_3_KERNEL )
+                    for( i = 0; i < width; i++ )
                     {
-                        for( i = 0; i < width; i++ )
-                            tdst[i] = tsrc[i+1]*10 + (tsrc[i] + tsrc[i+2])*3;
+                        int t0 = tsrc[i] + tsrc[i+4] - tsrc[i+2]*2;
+                        int t1 = tsrc[i] + tsrc[i+4] + tsrc[i+2]*6 +
+                                 (tsrc[i+1] + tsrc[i+3])*4;
+                        tdst[i] = t0;
+                        tdst[i+width] = t1;
                     }
-                    else
+                }
+                else
+                {
+                    for( i = 0; i < width; i++ )
                     {
-                        /* horizontal filter: symmetric case */
-                        for( i = 0; i < width; i++ )
-                        {
-                            int j;
-                            float t0 = tsrc[i + ker_x]*fmX0;
-
-                            for( j = 1; j <= ker_x; j++ )
-                                t0 += (tsrc[i+ker_x+j] + tsrc[i+ker_x-j])*fmaskX[j];
+                        int j;
+                        int t0 = tsrc[i + ker_x]*fmX0;
+                        int t1 = tsrc[i + ker_x]*fmY0;
 
-                            tdst[i] = t0;
-                        }
-                    }
-                }
-
-                if( !need_copy )
-                {
-                    /* restore borders */
-                    CV_COPY( src - ker_x, tbufc - ker_x, ker_x, x );
-                    CV_COPY( src + width, tbufc, ker_right, x );
-                }
-            }
-            else
-            {
-                CV_COPY( tdst, tsrc + ker_x, width, x );
-            }
-
-            if( crows < ker_height )
-                src += srcStep;
-        }
-
-        if( starting_flag )
-        {
-            starting_flag = 0;
-            trow = rows[ker_y];
-
-            for( i = 0; i < ker_y; i++ )
-            {
-                tdst = rows[i];
-                CV_COPY( tdst, trow, width, x );
-            }
-        }
-
-        /* vertical convolution */
-        if( crows != ker_height )
-            break;
-
-        tdst2 = dst;
-        trow = rows[ker_y];
-
-        if( ker_height > 1 )
-        {
-            if( width_rest )
-            {
-                need_copy = width < CV_MORPH_ALIGN || y == dst_height - 1;
-
-                if( need_copy )
-                    tdst2 = tbufw;
-                else
-                    CV_COPY( tbufw + width, dst + width, CV_MORPH_ALIGN, x );
-            }
-
-            if( y_asymm )
-            {
-                if( y_type == ICV_m1_0_1_KERNEL )
-                {
-                    float *trow1 = rows[origin*2], *trow2 = rows[(origin^1)*2];
-
-                    for( x = 0; x < width; x += CV_MORPH_ALIGN )
-                    {
-                        float val0, val1;
-                        val0 = trow2[x] - trow1[x];
-                        val1 = trow2[x + 1] - trow1[x + 1];
-                
-                        tdst2[x + 0] = (float)val0;
-                        tdst2[x + 1] = (float)val1;
-                
-                        val0 = trow2[x + 2] - trow1[x + 2];
-                        val1 = trow2[x + 3] - trow1[x + 3];
-                
-                        tdst2[x + 2] = (float)val0;
-                        tdst2[x + 3] = (float)val1;
-                    }
-                }
-                else
-                {
-                    for( x = 0; x < width; x += CV_MORPH_ALIGN )
-                    {
-                        float val0, val1, val2, val3;
-
-                        val0 = trow[x]*fmY0;
-                        val1 = trow[x + 1]*fmY0;
-                        val2 = trow[x + 2]*fmY0;
-                        val3 = trow[x + 3]*fmY0;
-
-                        for( i = 1; i <= ker_y; i++ )
-                        {
-                            float *trow1, *trow2;
-                            float m = fmaskY[i];
-                            trow1 = rows[ker_y - i];
-                            trow2 = rows[ker_y + i];
-                            val0 += (trow2[x] - trow1[x])*m;
-                            val1 += (trow2[x+1] - trow1[x+1])*m;
-                            val2 += (trow2[x+2] - trow1[x+2])*m;
-                            val3 += (trow2[x+3] - trow1[x+3])*m;
-                        }
-
-                        tdst2[x + 0] = val0;
-                        tdst2[x + 1] = val1;
-                        tdst2[x + 2] = val2;
-                        tdst2[x + 3] = val3;
-                    }
-                }
-            }
-            else
-            {
-                if( y_type == ICV_1_2_1_KERNEL )
-                {
-                    float *trow1 = rows[0], *trow2 = rows[2];
-
-                    for( x = 0; x < width; x += CV_MORPH_ALIGN )
-                    {
-                        float val0, val1;
-                        val0 = trow[x]*2 + trow1[x] + trow2[x];
-                        val1 = trow[x + 1]*2 + trow1[x+1] + trow2[x+1];
-                
-                        tdst2[x + 0] = (float)val0;
-                        tdst2[x + 1] = (float)val1;
-                
-                        val0 = trow[x + 2]*2 + trow1[x+2] + trow2[x+2];
-                        val1 = trow[x + 3]*2 + trow1[x+3] + trow2[x+3];
-                
-                        tdst2[x + 2] = (float)val0;
-                        tdst2[x + 3] = (float)val1;
-                    }
-                }
-                else if( y_type == ICV_3_10_3_KERNEL )
-                {
-                    float *trow1 = rows[0], *trow2 = rows[2];
-
-                    for( x = 0; x < width; x += CV_MORPH_ALIGN )
-                    {
-                        float val0, val1;
-                        val0 = trow[x]*10 + (trow1[x] + trow2[x])*3;
-                        val1 = trow[x + 1]*10 + (trow1[x+1] + trow2[x+1])*3;
-                
-                        tdst2[x + 0] = (float)val0;
-                        tdst2[x + 1] = (float)val1;
-                
-                        val0 = trow[x + 2]*10 + (trow1[x+2] + trow2[x+2])*3;
-                        val1 = trow[x + 3]*10 + (trow1[x+3] + trow2[x+3])*3;
-                
-                        tdst2[x + 2] = (float)val0;
-                        tdst2[x + 3] = (float)val1;
-                    }
-                }
-                else
-                {
-                    for( x = 0; x < width; x += CV_MORPH_ALIGN )
-                    {
-                        float val0, val1, val2, val3;
-
-                        val0 = trow[x]*fmY0;
-                        val1 = trow[x + 1]*fmY0;
-                        val2 = trow[x + 2]*fmY0;
-                        val3 = trow[x + 3]*fmY0;
-
-                        for( i = 1; i <= ker_y; i++ )
-                        {
-                            float *trow1, *trow2;
-                            float m = fmaskY[i];
-                            trow1 = rows[ker_y - i];
-                            trow2 = rows[ker_y + i];
-                            val0 += (trow2[x] + trow1[x])*m;
-                            val1 += (trow2[x+1] + trow1[x+1])*m;
-                            val2 += (trow2[x+2] + trow1[x+2])*m;
-                            val3 += (trow2[x+3] + trow1[x+3])*m;
-                        }
-
-                        tdst2[x + 0] = val0;
-                        tdst2[x + 1] = val1;
-                        tdst2[x + 2] = val2;
-                        tdst2[x + 3] = val3;
-                    }
-                }
-            }
-
-            if( width_rest )
-            {
-                if( need_copy )
-                    CV_COPY( dst, tbufw, width, x );
-                else
-                    CV_COPY( dst + width, tbufw + width, CV_MORPH_ALIGN, x );
-            }
-        }
-        else
-        {
-            for( x = 0; x < width; x++ )
-                dst[x] = (float)trow[x];
-        }
-
-        rows[ker_y] = saved_row;
-
-        /* rotate buffer */
-        {
-            float *t = rows[0];
-
-            CV_COPY( rows, rows + 1, ker_height - 1, i );
-            rows[i] = t;
-            crows--;
-            dst += dstStep;
-        }
-    }
-    while( ++y < dst_height );
-
-    roiSize->height = y;
-    state->crows = crows;
-
-    return CV_OK;
-}
-
-
-/****************************************************************************************\
-*                                      S C H A R R                                       *
-\****************************************************************************************/
-
-IPCVAPI_IMPL( CvStatus, icvScharrInitAlloc,(
-            int roiwidth, int datatype, int origin,
-            int dx, int dy, CvFilterState** state ))
-{
-    return icvSobelInitAlloc( roiwidth, datatype, CV_SCHARR, origin, dx, dy, state );
-}
-
-IPCVAPI_IMPL( CvStatus, icvScharr_8u16s_C1R,(
-             const uchar* pSrc, int srcStep,
-             short* dst, int dstStep, CvSize* roiSize,
-             CvFilterState* state, int stage ))
-{
-    assert( state->kerType == ICV_MAKE_SEPARABLE_KERNEL( ICV_m1_0_1_KERNEL, ICV_3_10_3_KERNEL ) ||
-            state->kerType == ICV_MAKE_SEPARABLE_KERNEL( ICV_3_10_3_KERNEL, ICV_m1_0_1_KERNEL ));
-    return icvSobel_8u16s_C1R( pSrc, srcStep, dst, dstStep, roiSize, state, stage );
-}
-
-
-IPCVAPI_IMPL( CvStatus, icvScharr_8s16s_C1R,(
-             const char* pSrc, int srcStep,
-             short* dst, int dstStep, CvSize* roiSize,
-             CvFilterState* state, int stage ))
-{
-    assert( state->kerType == ICV_MAKE_SEPARABLE_KERNEL( ICV_m1_0_1_KERNEL, ICV_3_10_3_KERNEL ) ||
-            state->kerType == ICV_MAKE_SEPARABLE_KERNEL( ICV_3_10_3_KERNEL, ICV_m1_0_1_KERNEL ));
-    return icvSobel_8s16s_C1R( pSrc, srcStep, dst, dstStep, roiSize, state, stage );
-}
-
-
-IPCVAPI_IMPL( CvStatus, icvScharr_32f_C1R,(
-             const float* pSrc, int srcStep,
-             float* dst, int dstStep, CvSize* roiSize,
-             CvFilterState* state, int stage ))
-{
-    assert( state->kerType == ICV_MAKE_SEPARABLE_KERNEL( ICV_m1_0_1_KERNEL, ICV_3_10_3_KERNEL ) ||
-            state->kerType == ICV_MAKE_SEPARABLE_KERNEL( ICV_3_10_3_KERNEL, ICV_m1_0_1_KERNEL ));
-    return icvSobel_32f_C1R( pSrc, srcStep, dst, dstStep, roiSize, state, stage );
-}
-
-/****************************************************************************************\
-*                                      L A P L A C E                                     *
-\****************************************************************************************/
-
-IPCVAPI_IMPL( CvStatus, icvLaplaceInitAlloc,(
-                int roiwidth, int datatype,
-                int size, CvFilterState** state ))
-{
-    #define MAX_KERNEL_SIZE  7
-    int ker[MAX_KERNEL_SIZE*2+1];
-    CvDataType worktype = datatype != cv32f ? cv32s : cv32f;
-    CvStatus status;
-    int x_filter_type, y_filter_type;
-    int x_size = size;
-    
-    if( !state )
-        return CV_NULLPTR_ERR;
-
-    if( (size&1) == 0 || size < 1 || size > MAX_KERNEL_SIZE )
-        return CV_BADRANGE_ERR;
-
-    if( size == 1 )
-        x_size = 3;
-
-    x_filter_type = icvCalcKer( (char*)ker, 2, x_size, worktype, 0 );
-    y_filter_type = icvCalcKer( (char*)(ker + x_size), 0, size, worktype, 0 );
-
-    status = icvFilterInitAlloc( roiwidth, worktype, 2, cvSize( x_size, x_size ),
-                                 cvPoint( x_size/2, x_size/2 ), ker,
-                                 ICV_MAKE_SEPARABLE_KERNEL(x_filter_type, y_filter_type),
-                                 state );
-    if( status < 0 )
-        return status;
-
-    (*state)->origin = 0;
-
-    return CV_OK;
-}
-
-
-IPCVAPI_IMPL( CvStatus, icvLaplace_8u16s_C1R,(
-             const uchar* pSrc, int srcStep,
-             short* dst, int dstStep, CvSize* roiSize,
-             CvFilterState* state, int stage ))
-{
-    uchar* src = (uchar*)pSrc;
-    int width = roiSize->width;
-    int src_height = roiSize->height;
-    int dst_height = src_height;
-    int x, y = 0, i;
-
-    int ker_width = state->ker_width;
-    int ker_height = state->ker_height;
-    int ker_x = ker_width/2;
-    int ker_y = ker_height/2;
-    int ker_right = ker_width - ker_x;
-
-    int crows = state->crows;
-    int **rows = (int**)(state->rows);
-    short *tbufw = (short*)(state->tbuf);
-    int *trow = 0;
-
-    int* fmaskX = (int*)(state->ker0) + ker_x;
-    int* fmaskY = (int*)(state->ker1) + ker_y;
-    int fmX0 = fmaskX[0], fmY0 = fmaskY[0];
-
-    int is_small_width = width < MAX( ker_x, ker_right );
-    int starting_flag = 0;
-    int width_rest = width & (CV_MORPH_ALIGN - 1);
-    int y_type = ICV_Y_KERNEL_TYPE(state->kerType);
-
-    /* initialize cyclic buffer when starting */
-    if( stage == CV_WHOLE || stage == CV_START )
-    {
-        for( i = 0; i < ker_height; i++ )
-            rows[i] = (int*)(state->buffer + state->buffer_step * i);
-
-        crows = ker_y;
-        if( stage != CV_WHOLE )
-            dst_height -= ker_height - ker_y - 1;
-        starting_flag = 1;
-    }
-
-    if( stage == CV_END )
-        dst_height += ker_height - ker_y - 1;
-
-    dstStep /= sizeof(dst[0]);
-
-    do
-    {
-        int need_copy = is_small_width | (y == 0);
-        uchar *tsrc;
-        int   *tdst;
-        short *tdst2;
-        int   *saved_row = rows[ker_y];
-
-        /* fill cyclic buffer - horizontal filtering */
-        for( ; crows < ker_height; crows++ )
-        {
-            tsrc = src - ker_x;
-            tdst = rows[crows];
-
-            if( src_height-- <= 0 )
-            {
-                if( stage != CV_WHOLE && stage != CV_END )
-                    break;
-                /* duplicate last row */
-                trow = rows[crows - 1];
-                CV_COPY( tdst, trow, width*2, x );
-                continue;
-            }
-
-            need_copy |= src_height == 1;
-
-            {
-                uchar* tbufc = (uchar*)tbufw;
-
-                if( need_copy )
-                {
-                    tsrc = tbufc - ker_x;
-                    CV_COPY( tbufc, src, width, x );
-                }
-                else
-                {
-                    CV_COPY( tbufc - ker_x, src - ker_x, ker_x, x );
-                    CV_COPY( tbufc, src + width, ker_right, x );
-                }
-
-                /* make replication borders */
-                {
-                uchar pix = tsrc[ker_x];
-                CV_SET( tsrc, pix, ker_x, x );
-
-                pix = tsrc[width + ker_x - 1];
-                CV_SET( tsrc + width + ker_x, pix, ker_right, x );
-                }
-
-                if( ker_width == 3 )
-                {
-                    if( y_type == ICV_1_2_1_KERNEL )
-                    {
-                        for( i = 0; i < width; i++ )
-                        {
-                            int t0 = tsrc[i] + tsrc[i+2] - tsrc[i+1]*2;
-                            int t1 = tsrc[i] + tsrc[i+2] + tsrc[i+1]*2;
-                            tdst[i] = t0;
-                            tdst[i+width] = t1;
-                        }
-                    }
-                    else
-                    {
-                        for( i = 0; i < width; i++ )
-                        {
-                            int t0 = tsrc[i] + tsrc[i+2] - tsrc[i+1]*2;
-                            int t1 = tsrc[i+1];
-                            tdst[i] = t0;
-                            tdst[i+width] = t1;
-                        }
-                    }
-                }
-                else if( ker_width == 5 )
-                {
-                    for( i = 0; i < width; i++ )
-                    {
-                        int t0 = tsrc[i] + tsrc[i+4] - tsrc[i+2]*2;
-                        int t1 = tsrc[i] + tsrc[i+4] + tsrc[i+2]*6 +
-                                 (tsrc[i+1] + tsrc[i+3])*4;
-                        tdst[i] = t0;
-                        tdst[i+width] = t1;
-                    }
-                }
-                else
-                {
-                    for( i = 0; i < width; i++ )
-                    {
-                        int j;
-                        int t0 = tsrc[i + ker_x]*fmX0;
-                        int t1 = tsrc[i + ker_x]*fmY0;
-
-                        for( j = 1; j <= ker_x; j++ )
-                        {
-                            t0 += (tsrc[i+ker_x+j] + tsrc[i+ker_x-j])*fmaskX[j];
-                            t1 += (tsrc[i+ker_x+j] + tsrc[i+ker_x-j])*fmaskY[j];
-                        }
-
-                        tdst[i] = t0;
-                        tdst[i+width] = t1;
-                    }
-                }
-
-                if( !need_copy )
-                {
-                    /* restore borders */
-                    CV_COPY( src - ker_x, tbufc - ker_x, ker_x, x );
-                    CV_COPY( src + width, tbufc, ker_right, x );
-                }
-            }
-
-            if( crows < ker_height )
-                src += srcStep;
-        }
-
-        if( starting_flag )
-        {
-            starting_flag = 0;
-            trow = rows[ker_y];
-
-            for( i = 0; i < ker_y; i++ )
-            {
-                tdst = rows[i];
-                CV_COPY( tdst, trow, width*2, x );
-            }
-        }
-
-        /* vertical convolution */
-        if( crows != ker_height )
-            break;
-
-        tdst2 = dst;
-
-        if( width_rest )
-        {
-            need_copy = width < CV_MORPH_ALIGN || y == dst_height - 1;
-
-            if( need_copy )
-                tdst2 = tbufw;
-            else
-                CV_COPY( tbufw + width, dst + width, CV_MORPH_ALIGN, x );
-        }
-
-        trow = rows[ker_y];
-
-        if( ker_height == 3 )
-        {
-            int *trow1 = rows[0], *trow2 = rows[2];
-
-            if( y_type == ICV_1_2_1_KERNEL )
-            {
-                for( x = 0; x < width; x += CV_MORPH_ALIGN )
-                {
-                    int val0, val1;
-                    val0 = trow[x]*2 + trow1[x] + trow2[x] -
-                           trow[x+width]*2 + trow1[x+width] + trow2[x+width];
-                    val1 = trow[x+1]*2 + trow1[x+1] + trow2[x+1] -
-                           trow[x+1+width]*2 + trow1[x+1+width] + trow2[x+1+width];
-            
-                    tdst2[x + 0] = (short)val0;
-                    tdst2[x + 1] = (short)val1;
-            
-                    val0 = trow[x+2]*2 + trow1[x+2] + trow2[x+2] -
-                           trow[x+2+width]*2 + trow1[x+2+width] + trow2[x+2+width];
-                    val1 = trow[x+3]*2 + trow1[x+3] + trow2[x+3] -
-                           trow[x+3+width]*2 + trow1[x+3+width] + trow2[x+3+width];
-            
-                    tdst2[x + 2] = (short)val0;
-                    tdst2[x + 3] = (short)val1;
-                }
-            }
-            else
-            {
-                for( x = 0; x < width; x += CV_MORPH_ALIGN )
-                {
-                    int val0, val1;
-                    val0 = trow[x] -
-                           trow[x+width]*2 + trow1[x+width] + trow2[x+width];
-                    val1 = trow[x+1] -
-                           trow[x+1+width]*2 + trow1[x+1+width] + trow2[x+1+width];
-            
-                    tdst2[x + 0] = (short)val0;
-                    tdst2[x + 1] = (short)val1;
-            
-                    val0 = trow[x+2] -
-                           trow[x+2+width]*2 + trow1[x+2+width] + trow2[x+2+width];
-                    val1 = trow[x+3] -
-                           trow[x+3+width]*2 + trow1[x+3+width] + trow2[x+3+width];
-            
-                    tdst2[x + 2] = (short)val0;
-                    tdst2[x + 3] = (short)val1;
-                }
-            }
-        }
-        else if( ker_height == 5 )
-        {
-            int *trow0 = rows[0], *trow1 = rows[1], *trow3 = rows[3], *trow4 = rows[4];
-
-            for( x = 0; x < width; x += CV_MORPH_ALIGN )
-            {
-                int val0, val1;
-                val0 = trow0[x] + trow4[x] + (trow1[x] + trow3[x])*4 + trow[x]*6 +
-                       trow0[x+width] + trow4[x+width] - 2*trow[x+width];
-                val1 = trow0[x+1] + trow4[x+1] + (trow1[x+1] + trow3[x+1])*4 + trow[x+1]*6 +
-                       trow0[x+1+width] + trow4[x+1+width] - 2*trow[x+1+width];
-            
-                tdst2[x + 0] = (short)val0;
-                tdst2[x + 1] = (short)val1;
-            
-                val0 = trow0[x+2] + trow4[x+2] + (trow1[x+2] + trow3[x+2])*4 + trow[x+2]*6 +
-                       trow0[x+2+width] + trow4[x+2+width] - 2*trow[x+2+width];
-                val1 = trow0[x+3] + trow4[x+3] + (trow1[x+3] + trow3[x+3])*4 + trow[x+3]*6 +
-                       trow0[x+3+width] + trow4[x+3+width] - 2*trow[x+3+width];
-            
-                tdst2[x + 2] = (short)val0;
-                tdst2[x + 3] = (short)val1;
-            }
-        }
-        else
-        {
-            for( x = 0; x < width; x += CV_MORPH_ALIGN )
-            {
-                int val0, val1, val2, val3;
-
-                val0 = trow[x]*fmY0 + trow[x + width]*fmX0;
-                val1 = trow[x + 1]*fmY0 + trow[x + 1 + width]*fmX0;
-                val2 = trow[x + 2]*fmY0 + trow[x + 2 + width]*fmX0;
-                val3 = trow[x + 3]*fmY0 + trow[x + 3 + width]*fmX0;
-
-                for( i = 1; i <= ker_y; i++ )
-                {
-                    int *trow1, *trow2;
-                    int m0 = fmaskY[i], m1 = fmaskX[i];
-                    trow1 = rows[ker_y - i];
-                    trow2 = rows[ker_y + i];
-                    val0 += (trow2[x] + trow1[x])*m0 +
-                            (trow2[x+width] + trow1[x+width])*m1;
-                    val1 += (trow2[x+1] + trow1[x+1])*m0 +
-                            (trow2[x+1+width] + trow1[x+1+width])*m1;
-                    val2 += (trow2[x+2] + trow1[x+2])*m0 +
-                            (trow2[x+2+width] + trow1[x+2+width])*m1;
-                    val3 += (trow2[x+3] + trow1[x+3])*m0 +
-                            (trow2[x+3+width] + trow1[x+3+width])*m1;
-                }
-
-                tdst2[x + 0] = CV_CAST_16S(val0);
-                tdst2[x + 1] = CV_CAST_16S(val1);
-                tdst2[x + 2] = CV_CAST_16S(val2);
-                tdst2[x + 3] = CV_CAST_16S(val3);
-            }
-        }
-
-        if( width_rest )
-        {
-            if( need_copy )
-                CV_COPY( dst, tbufw, width, x );
-            else
-                CV_COPY( dst + width, tbufw + width, CV_MORPH_ALIGN, x );
-        }
-
-        rows[ker_y] = saved_row;
-
-        /* rotate buffer */
-        {
-            int *t = rows[0];
-
-            CV_COPY( rows, rows + 1, ker_height - 1, i );
-            rows[i] = t;
-            crows--;
-            dst += dstStep;
-        }
-    }
-    while( ++y < dst_height );
-
-    roiSize->height = y;
-    state->crows = crows;
-
-    return CV_OK;
-}
-
-
-IPCVAPI_IMPL( CvStatus, icvLaplace_8s16s_C1R,(
-             const char* pSrc, int srcStep,
-             short* dst, int dstStep, CvSize* roiSize,
-             CvFilterState* state, int stage ))
-{
-    char* src = (char*)pSrc;
-    int width = roiSize->width;
-    int src_height = roiSize->height;
-    int dst_height = src_height;
-    int x, y = 0, i;
-
-    int ker_width = state->ker_width;
-    int ker_height = state->ker_height;
-    int ker_x = ker_width/2;
-    int ker_y = ker_height/2;
-    int ker_right = ker_width - ker_x;
-
-    int crows = state->crows;
-    int **rows = (int**)(state->rows);
-    short *tbufw = (short*)(state->tbuf);
-    int *trow = 0;
-
-    int* fmaskX = (int*)(state->ker0) + ker_x;
-    int* fmaskY = (int*)(state->ker1) + ker_y;
-    int fmX0 = fmaskX[0], fmY0 = fmaskY[0];
-
-    int is_small_width = width < MAX( ker_x, ker_right );
-    int starting_flag = 0;
-    int width_rest = width & (CV_MORPH_ALIGN - 1);
-    int y_type = ICV_Y_KERNEL_TYPE(state->kerType);
-
-    /* initialize cyclic buffer when starting */
-    if( stage == CV_WHOLE || stage == CV_START )
-    {
-        for( i = 0; i < ker_height; i++ )
-            rows[i] = (int*)(state->buffer + state->buffer_step * i);
-
-        crows = ker_y;
-        if( stage != CV_WHOLE )
-            dst_height -= ker_height - ker_y - 1;
-        starting_flag = 1;
-    }
-
-    if( stage == CV_END )
-        dst_height += ker_height - ker_y - 1;
-
-    dstStep /= sizeof(dst[0]);
-
-    do
-    {
-        int need_copy = is_small_width | (y == 0);
-        char *tsrc;
-        int   *tdst;
-        short *tdst2;
-        int   *saved_row = rows[ker_y];
-
-        /* fill cyclic buffer - horizontal filtering */
-        for( ; crows < ker_height; crows++ )
-        {
-            tsrc = src - ker_x;
-            tdst = rows[crows];
-
-            if( src_height-- <= 0 )
-            {
-                if( stage != CV_WHOLE && stage != CV_END )
-                    break;
-                /* duplicate last row */
-                trow = rows[crows - 1];
-                CV_COPY( tdst, trow, width*2, x );
-                continue;
-            }
-
-            need_copy |= src_height == 1;
-
-            {
-                char* tbufc = (char*)tbufw;
-
-                if( need_copy )
-                {
-                    tsrc = tbufc - ker_x;
-                    CV_COPY( tbufc, src, width, x );
-                }
-                else
-                {
-                    CV_COPY( tbufc - ker_x, src - ker_x, ker_x, x );
-                    CV_COPY( tbufc, src + width, ker_right, x );
-                }
-
-                /* make replication borders */
-                {
-                char pix = tsrc[ker_x];
-                CV_SET( tsrc, pix, ker_x, x );
-
-                pix = tsrc[width + ker_x - 1];
-                CV_SET( tsrc + width + ker_x, pix, ker_right, x );
-                }
-
-                if( ker_width == 3 )
-                {
-                    if( y_type == ICV_1_2_1_KERNEL )
-                    {
-                        for( i = 0; i < width; i++ )
-                        {
-                            int t0 = tsrc[i] + tsrc[i+2] - tsrc[i+1]*2;
-                            int t1 = tsrc[i] + tsrc[i+2] + tsrc[i+1]*2;
-                            tdst[i] = t0;
-                            tdst[i+width] = t1;
-                        }
-                    }
-                    else
-                    {
-                        for( i = 0; i < width; i++ )
-                        {
-                            int t0 = tsrc[i] + tsrc[i+2] - tsrc[i+1]*2;
-                            int t1 = tsrc[i+1];
-                            tdst[i] = t0;
-                            tdst[i+width] = t1;
-                        }
-                    }
-                }
-                else if( ker_width == 5 )
-                {
-                    for( i = 0; i < width; i++ )
-                    {
-                        int t0 = tsrc[i] + tsrc[i+4] - tsrc[i+2]*2;
-                        int t1 = tsrc[i] + tsrc[i+4] + tsrc[i+2]*6 +
-                                 (tsrc[i+1] + tsrc[i+3])*4;
-                        tdst[i] = t0;
-                        tdst[i+width] = t1;
-                    }
-                }
-                else
-                {
-                    for( i = 0; i < width; i++ )
-                    {
-                        int j;
-                        int t0 = tsrc[i + ker_x]*fmX0;
-                        int t1 = tsrc[i + ker_x]*fmY0;
-
-                        for( j = 1; j <= ker_x; j++ )
-                        {
-                            t0 += (tsrc[i+ker_x+j] + tsrc[i+ker_x-j])*fmaskX[j];
-                            t1 += (tsrc[i+ker_x+j] + tsrc[i+ker_x-j])*fmaskY[j];
+                        for( j = 1; j <= ker_x; j++ )
+                        {
+                            t0 += (tsrc[i+ker_x+j] + tsrc[i+ker_x-j])*fmaskX[j];
+                            t1 += (tsrc[i+ker_x+j] + tsrc[i+ker_x-j])*fmaskY[j];
                         }
 
                         tdst[i] = t0;
@@ -2020,10 +1324,10 @@ IPCVAPI_IMPL( CvStatus, icvLaplace_8s16s_C1R,(
 }
 
 
-IPCVAPI_IMPL( CvStatus, icvLaplace_32f_C1R,(
-             const float* pSrc, int srcStep,
-             float* dst, int dstStep, CvSize* roiSize,
-             CvFilterState* state, int stage ))
+static CvStatus CV_STDCALL
+icvLaplace_32f_C1R( const float* pSrc, int srcStep,
+                    float* dst, int dstStep, CvSize* roiSize,
+                    CvFilterState* state, int stage )
 {
     float* src = (float*)pSrc;
     int width = roiSize->width;
@@ -2421,7 +1725,7 @@ void icvSepConvSmall3_32f( float*  src, int src_step,
 static  void  icvInit##FUNCNAME##Table( CvFuncTable* tab ) \
 {                                                          \
     tab->fn_2d[CV_8U] = (void*)icv##FUNCNAME##_8u16s_C1R;  \
-    tab->fn_2d[CV_8S] = (void*)icv##FUNCNAME##_8s16s_C1R;  \
+    tab->fn_2d[CV_8S] = 0;                                 \
     tab->fn_2d[CV_32F] = (void*)icv##FUNCNAME##_32f_C1R;   \
 }
 
@@ -2429,8 +1733,6 @@ ICV_DEF_INIT_DERIV_TAB( Sobel )
 ICV_DEF_INIT_DERIV_TAB( Scharr )
 ICV_DEF_INIT_DERIV_TAB( Laplace )
 
-static const CvDataType dataType[] = { cv8u, cv8s, cv16s, cv32s, cv32f, cv64f };
-
 CV_IMPL void
 cvSobel( const void* srcarr, void* dstarr, int dx, int dy, int aperture_size )
 {
@@ -2448,6 +1750,7 @@ cvSobel( const void* srcarr, void* dstarr, int dx, int dy, int aperture_size )
     CvMat dststub, *dst = (CvMat*)dstarr;
     CvFilterFunc func = 0;
     CvSize size;
+    int datatype;
 
     if( !inittab )
     {
@@ -2465,7 +1768,7 @@ cvSobel( const void* srcarr, void* dstarr, int dx, int dy, int aperture_size )
     }
 
     if( CV_MAT_CN( src->type ) != 1 || CV_MAT_CN( dst->type ) != 1 )
-        CV_ERROR( CV_BadNumChannels, icvUnsupportedFormat );
+        CV_ERROR( CV_BadNumChannels, cvUnsupportedFormat );
 
     if( CV_MAT_DEPTH( src->type ) <= CV_8S )
     {
@@ -2485,18 +1788,19 @@ cvSobel( const void* srcarr, void* dstarr, int dx, int dy, int aperture_size )
     }
 
     depth = CV_MAT_DEPTH( src->type );
+    datatype = icvDepthToDataType(depth);
 
     if( !CV_ARE_SIZES_EQ( src, dst ))
         CV_ERROR( CV_StsBadArg, "src and dst have different sizes" );
 
     if( aperture_size == CV_SCHARR )
     {
-        IPPI_CALL( icvScharrInitAlloc( src->width, (int)dataType[depth], origin, dx, dy, &state ));
+        IPPI_CALL( icvScharrInitAlloc( src->width, datatype, origin, dx, dy, &state ));
         func = (CvFilterFunc)(scharr_tab.fn_2d[depth]);
     }
     else
     {
-        IPPI_CALL( icvSobelInitAlloc( src->width, (int)dataType[depth], aperture_size,
+        IPPI_CALL( icvSobelInitAlloc( src->width, datatype, aperture_size,
                                       origin, dx, dy, &state ));
         func = (CvFilterFunc)(sobel_tab.fn_2d[depth]);
     }
@@ -2504,7 +1808,7 @@ cvSobel( const void* srcarr, void* dstarr, int dx, int dy, int aperture_size )
     if( !func )
         CV_ERROR( CV_StsUnsupportedFormat, "" );
 
-    size = icvGetMatSize(src);
+    size = cvGetMatSize(src);
     IPPI_CALL( func( src->data.ptr, src->step, dst->data.ptr,
                      dst->step, &size, state, 0 ));
 
@@ -2542,7 +1846,7 @@ cvLaplace( const void* srcarr, void* dstarr, int aperture_size )
     CV_CALL( dst = cvGetMat( dst, &dststub ));
 
     if( CV_MAT_CN( src->type ) != 1 || CV_MAT_CN( dst->type ) != 1 )
-        CV_ERROR( CV_BadNumChannels, icvUnsupportedFormat );
+        CV_ERROR( CV_BadNumChannels, cvUnsupportedFormat );
 
     if( CV_MAT_DEPTH( src->type ) <= CV_8S )
     {
@@ -2566,13 +1870,13 @@ cvLaplace( const void* srcarr, void* dstarr, int aperture_size )
     if( !CV_ARE_SIZES_EQ( src, dst ))
         CV_ERROR( CV_StsBadArg, "src and dst have different sizes" );
 
-    IPPI_CALL( icvLaplaceInitAlloc( src->width, (int)dataType[depth], aperture_size, &state ));
+    IPPI_CALL( icvLaplaceInitAlloc( src->width, icvDepthToDataType(depth), aperture_size, &state ));
     func = (CvFilterFunc)(laplace_tab.fn_2d[depth]);
 
     if( !func )
         CV_ERROR( CV_StsUnsupportedFormat, "" );
 
-    size = icvGetMatSize(src);
+    size = cvGetMatSize(src);
     IPPI_CALL( func( src->data.ptr, src->step, dst->data.ptr,
                      dst->step, &size, state, 0 ));
 
index 29c8aad8b574463fe53a02712aa96930b89e1933..e98f584420ffb7ffd880798e870684b14a6d379f 100644 (file)
@@ -40,9 +40,6 @@
 //M*/
 #include "_cv.h"
 
-#define MIN2(a, b) MIN((a),(b))
-#define CALC_MIN(a, b) if((a) > (b)) (a) = (b)
-
 #define _CV_DIST_SHIFT  18
 
 static int
@@ -57,7 +54,7 @@ _MINn( const int *values, int n )
     {
         int t = values[i];
 
-        CALC_MIN( ret, t );
+        CV_CALC_MIN( ret, t );
     }
 
     return ret;
@@ -126,14 +123,15 @@ icvCvtIntTofloat( int *idist, int step, CvSize roiSize, float scale )
 
 #define VALIDATE_INPUT(img, img_step, dist, step, roiSize)\
     if( !img || !dist ) return CV_NULLPTR_ERR;\
-    if( img_step < roiSize.width || step < roiSize.width*sizeof_float ||\
-        (step & (sizeof_float-1)) != 0 || roiSize.width < 0 || roiSize.height < 0) \
+    if( img_step < roiSize.width || step < roiSize.width*CV_SIZEOF_FLOAT ||\
+        (step & (CV_SIZEOF_FLOAT-1)) != 0 || roiSize.width < 0 || roiSize.height < 0) \
         return CV_BADSIZE_ERR;
 
 
 IPCVAPI_IMPL( CvStatus, icvDistanceTransform_3x3_8u32f_C1R,
               (const uchar * pSrc, int srcStep,
-               float *pDst, int dstStep, CvSize roiSize, float *pMetrics) )
+               float *pDst, int dstStep, CvSize roiSize, float *pMetrics),
+              (pSrc, srcStep, pDst, dstStep, roiSize, pMetrics) )
 {
     int w = roiSize.width;
     int h = roiSize.height;
@@ -147,11 +145,11 @@ IPCVAPI_IMPL( CvStatus, icvDistanceTransform_3x3_8u32f_C1R,
     if( !pSrc || !pDst || !pMetrics )
         return CV_NULLPTR_ERR;
     if( roiSize.width < 0 || roiSize.height < 0 ||
-        srcStep < roiSize.width || dstStep < roiSize.width * sizeof_float ||
-        (dstStep & (sizeof_float - 1)) != 0 )
+        srcStep < roiSize.width || dstStep < roiSize.width * CV_SIZEOF_FLOAT ||
+        (dstStep & (CV_SIZEOF_FLOAT - 1)) != 0 )
         return CV_BADSIZE_ERR;
 
-    dstStep /= sizeof_float;
+    dstStep /= CV_SIZEOF_FLOAT;
 
     mask0 = cvRound( pMetrics[0] * (1 << _CV_DIST_SHIFT) );
     mask1 = cvRound( pMetrics[1] * (1 << _CV_DIST_SHIFT) );
@@ -171,7 +169,7 @@ IPCVAPI_IMPL( CvStatus, icvDistanceTransform_3x3_8u32f_C1R,
         {
             t1 = idist[0];
             t2 = idist[-dstStep] + mask0;
-            CALC_MIN( t1, t2 );
+            CV_CALC_MIN( t1, t2 );
             idist[0] = t1;
         }
 
@@ -183,7 +181,7 @@ IPCVAPI_IMPL( CvStatus, icvDistanceTransform_3x3_8u32f_C1R,
         {
             t1 = idist[0];
             t2 = idist[dstStep] + mask0;
-            CALC_MIN( t1, t2 );
+            CV_CALC_MIN( t1, t2 );
             idist[0] = t1;
         }
 
@@ -202,7 +200,7 @@ IPCVAPI_IMPL( CvStatus, icvDistanceTransform_3x3_8u32f_C1R,
         {
             t1 = idist[ci];
             t2 = idist[ci - 1] + mask0;
-            CALC_MIN( t1, t2 );
+            CV_CALC_MIN( t1, t2 );
             idist[ci] = t1;
         }
 
@@ -215,9 +213,9 @@ IPCVAPI_IMPL( CvStatus, icvDistanceTransform_3x3_8u32f_C1R,
                 /* ci = 0 */
                 t1 = idist[0];
                 t2 = idist2[0] + mask0;
-                CALC_MIN( t1, t2 );
+                CV_CALC_MIN( t1, t2 );
                 t2 = idist2[1] + mask1;
-                CALC_MIN( t1, t2 );
+                CV_CALC_MIN( t1, t2 );
                 idist[0] = t1;
 
                 /* 0 < ci < w - 1 */
@@ -225,13 +223,13 @@ IPCVAPI_IMPL( CvStatus, icvDistanceTransform_3x3_8u32f_C1R,
                 {
                     t1 = idist[ci];
                     t2 = idist[ci - 1] + mask0;
-                    CALC_MIN( t1, t2 );
+                    CV_CALC_MIN( t1, t2 );
                     t3 = idist2[ci] + mask0;
                     t4 = idist2[ci - 1] + mask1;
-                    CALC_MIN( t3, t4 );
+                    CV_CALC_MIN( t3, t4 );
                     t2 = idist2[ci + 1] + mask1;
-                    CALC_MIN( t1, t3 );
-                    CALC_MIN( t1, t2 );
+                    CV_CALC_MIN( t1, t3 );
+                    CV_CALC_MIN( t1, t2 );
                     idist[ci] = t1;
                 }
 
@@ -239,13 +237,13 @@ IPCVAPI_IMPL( CvStatus, icvDistanceTransform_3x3_8u32f_C1R,
                 t1 = idist[ci];
 
                 t2 = idist[ci - 1] + mask0;
-                CALC_MIN( t1, t2 );
+                CV_CALC_MIN( t1, t2 );
 
                 t2 = idist2[ci - 1] + mask1;
-                CALC_MIN( t1, t2 );
+                CV_CALC_MIN( t1, t2 );
 
                 t2 = idist2[ci] + mask0;
-                CALC_MIN( t1, t2 );
+                CV_CALC_MIN( t1, t2 );
 
                 idist[ci] = t1;
             }
@@ -261,7 +259,7 @@ IPCVAPI_IMPL( CvStatus, icvDistanceTransform_3x3_8u32f_C1R,
         {
             t1 = idist[ci];
             t2 = idist[ci + 1] + mask0;
-            CALC_MIN( t1, t2 );
+            CV_CALC_MIN( t1, t2 );
             idist[ci] = t1;
         }
 
@@ -275,9 +273,9 @@ IPCVAPI_IMPL( CvStatus, icvDistanceTransform_3x3_8u32f_C1R,
                 /* ci = w - 1 */
                 t1 = idist[w - 1];
                 t2 = idist2[w - 1] + mask0;
-                CALC_MIN( t1, t2 );
+                CV_CALC_MIN( t1, t2 );
                 t2 = idist2[w - 2] + mask1;
-                CALC_MIN( t1, t2 );
+                CV_CALC_MIN( t1, t2 );
                 idist[w - 1] = t1;
 
                 /* 0 < ci < w - 1 */
@@ -285,13 +283,13 @@ IPCVAPI_IMPL( CvStatus, icvDistanceTransform_3x3_8u32f_C1R,
                 {
                     t1 = idist[ci];
                     t2 = idist[ci + 1] + mask0;
-                    CALC_MIN( t1, t2 );
+                    CV_CALC_MIN( t1, t2 );
                     t3 = idist2[ci] + mask0;
                     t4 = idist2[ci - 1] + mask1;
-                    CALC_MIN( t3, t4 );
+                    CV_CALC_MIN( t3, t4 );
                     t2 = idist2[ci + 1] + mask1;
-                    CALC_MIN( t1, t3 );
-                    CALC_MIN( t1, t2 );
+                    CV_CALC_MIN( t1, t3 );
+                    CV_CALC_MIN( t1, t2 );
                     idist[ci] = t1;
                 }
 
@@ -299,13 +297,13 @@ IPCVAPI_IMPL( CvStatus, icvDistanceTransform_3x3_8u32f_C1R,
                 t1 = idist[0];
 
                 t2 = idist[1] + mask0;
-                CALC_MIN( t1, t2 );
+                CV_CALC_MIN( t1, t2 );
 
                 t2 = idist2[0] + mask0;
-                CALC_MIN( t1, t2 );
+                CV_CALC_MIN( t1, t2 );
 
                 t2 = idist2[1] + mask1;
-                CALC_MIN( t1, t2 );
+                CV_CALC_MIN( t1, t2 );
                 idist[0] = t1;
             }
             idist += dstStep;
@@ -320,9 +318,6 @@ IPCVAPI_IMPL( CvStatus, icvDistanceTransform_3x3_8u32f_C1R,
 }
 
 
-#define _F2I(i, f) (i) = (f);
-#define _I2F(f, i) (f) = (i);
-
 #define _POINT(row, column)  (((int*)pDst)[(row)*dstStep+(column)])
 #define _ADD_POINT(row, column, m)\
     buffer[length++] = ((int*)pDst)[dstStep*(row) + (column)] + (m)
@@ -330,7 +325,8 @@ IPCVAPI_IMPL( CvStatus, icvDistanceTransform_3x3_8u32f_C1R,
 
 IPCVAPI_IMPL( CvStatus, icvDistanceTransform_5x5_8u32f_C1R,
               (const uchar * pSrc, int srcStep,
-               float *pDst, int dstStep, CvSize roiSize, float *pMetrics) )
+              float *pDst, int dstStep, CvSize roiSize, float *pMetrics),
+              (pSrc, srcStep, pDst, dstStep, roiSize, pMetrics) )
 {
     int ri;                     /* Row index */
     int ci;                     /* Column index */
@@ -348,11 +344,11 @@ IPCVAPI_IMPL( CvStatus, icvDistanceTransform_5x5_8u32f_C1R,
     if( !pSrc || !pDst || !pMetrics )
         return CV_NULLPTR_ERR;
     if( roiSize.width < 0 || roiSize.height < 0 ||
-        srcStep < roiSize.width || dstStep < roiSize.width * sizeof_float ||
-        (dstStep & (sizeof_float - 1)) != 0 )
+        srcStep < roiSize.width || dstStep < roiSize.width * CV_SIZEOF_FLOAT ||
+        (dstStep & (CV_SIZEOF_FLOAT - 1)) != 0 )
         return CV_BADSIZE_ERR;
 
-    dstStep /= sizeof_float;
+    dstStep /= CV_SIZEOF_FLOAT;
 
     mask0 = cvRound( pMetrics[0] * (1 << _CV_DIST_SHIFT) );
     mask1 = cvRound( pMetrics[1] * (1 << _CV_DIST_SHIFT) );
@@ -570,177 +566,178 @@ IPCVAPI_IMPL( CvStatus, icvDistanceTransform_5x5_8u32f_C1R,
 
     /* ri = 0, ci = 1 */
     t1 = *(int *) &_POINT( 0, 1 );
-    _F2I( t2, _POINT( 0, 0 ) + mask0 );
-    CALC_MIN( t1, t2 );
-    _I2F( _POINT( 0, 1 ), t1 );
+    t2 = _POINT( 0, 0 ) + mask0;
+    CV_CALC_MIN( t1, t2 );
+    _POINT( 0, 1 ) = t1;
 
     /* ri = 0, 1 < ci < w */
     for( ci = 2; ci < w; ci++ )
     {
         t1 = *(int *) &_POINT( 0, ci );
-        _F2I( t2, _POINT( 0, ci - 1 ) + mask0 );
-        CALC_MIN( t1, t2 );
-        _I2F( _POINT( 0, ci ), t1 );
+        t2 = _POINT( 0, ci - 1 ) + mask0;
+        CV_CALC_MIN( t1, t2 );
+        _POINT( 0, ci ) = t1;
     }
 
     /* ri = 1, ci = 0 */
     t1 = *(int *) &_POINT( 1, 0 );
-    _F2I( t2, _POINT( 0, 0 ) + mask0 );
-    CALC_MIN(t1, t2);
-       _F2I( t2, _POINT( 0, 1 ) + mask1 );
-    CALC_MIN( t1, t2 );
-    _F2I( t2, _POINT( 0, 2 ) + mask2 );
-    CALC_MIN( t1, t2 );
-    _I2F( _POINT( 1, 0 ), t1 );
+    t2 = _POINT( 0, 0 ) + mask0;
+    CV_CALC_MIN(t1, t2);
+       t2 = _POINT( 0, 1 ) + mask1;
+    CV_CALC_MIN( t1, t2 );
+    t2 = _POINT( 0, 2 ) + mask2;
+    CV_CALC_MIN( t1, t2 );
+    _POINT( 1, 0 ) = t1;
 
     /* ri = 1, ci = 1 */
     t1 = *(int *) &_POINT( 1, 1 );
-    _F2I( t2, _POINT( 0, 1 ) + mask0 );
-    CALC_MIN( t1, t2 );
-    _F2I( t2, _POINT( 0, 2 ) + mask1 );
-    CALC_MIN( t1, t2 );
-    _F2I( t2, _POINT( 0, 3 ) + mask2 );
-    CALC_MIN( t1, t2 );
-    _F2I( t2, _POINT( 0, 0 ) + mask1 );
-    CALC_MIN( t1, t2 );
-    _F2I( t2, _POINT( 1, 0 ) + mask0 );
-    CALC_MIN( t1, t2 );
-    _I2F( _POINT( 1, 1 ), t1 );
+    t2 = _POINT( 0, 1 ) + mask0;
+    CV_CALC_MIN( t1, t2 );
+    t2 = _POINT( 0, 2 ) + mask1;
+    CV_CALC_MIN( t1, t2 );
+    t2 = _POINT( 0, 3 ) + mask2;
+    CV_CALC_MIN( t1, t2 );
+    t2 = _POINT( 0, 0 ) + mask1;
+    CV_CALC_MIN( t1, t2 );
+    t2 = _POINT( 1, 0 ) + mask0;
+    CV_CALC_MIN( t1, t2 );
+    _POINT( 1, 1 ) = t1;
 
 
     /* ri = 1, 1 < ci < w - 2 */
     for( ci = 2; ci < w - 2; ci++ )
     {
         t1 = *(int *) &_POINT( 1, ci );
-        _F2I( t2, _POINT( 0, ci ) + mask0 );
-        CALC_MIN( t1, t2 );
-        _F2I( t2, _POINT( 0, ci + 1 ) + mask1 );
-        CALC_MIN( t1, t2 );
-        _F2I( t2, _POINT( 0, ci + 2 ) + mask2 );
-        CALC_MIN( t1, t2 );
-        _F2I( t2, _POINT( 0, ci - 1 ) + mask1 );
-        CALC_MIN( t1, t2 );
-        _F2I( t2, _POINT( 1, ci - 1 ) + mask0 );
-        CALC_MIN( t1, t2 );
-        _F2I( t2, _POINT( 0, ci - 2 ) + mask2 );
-        CALC_MIN( t1, t2 );
-        _I2F( _POINT( 1, ci ), t1 );
+        t2 = _POINT( 0, ci ) + mask0;
+        CV_CALC_MIN( t1, t2 );
+        t2 = _POINT( 0, ci + 1 ) + mask1;
+        CV_CALC_MIN( t1, t2 );
+        t2 = _POINT( 0, ci + 2 ) + mask2;
+        CV_CALC_MIN( t1, t2 );
+        t2 = _POINT( 0, ci - 1 ) + mask1;
+        CV_CALC_MIN( t1, t2 );
+        t2 = _POINT( 1, ci - 1 ) + mask0;
+        CV_CALC_MIN( t1, t2 );
+        t2 = _POINT( 0, ci - 2 ) + mask2;
+        CV_CALC_MIN( t1, t2 );
+        _POINT( 1, ci ) = t1;
     }
 
     /* ri = 1, ci = w - 2 */
     t1 = *(int *) &_POINT( 1, w - 2 );
-    _F2I( t2, _POINT( 0, w - 2 ) + mask0 );
-    CALC_MIN( t1, t2 );
-    _F2I( t2, _POINT( 0, w - 1 ) + mask1 );
-    CALC_MIN( t1, t2 );
-    _F2I( t2, _POINT( 0, w - 3 ) + mask1 );
-    CALC_MIN( t1, t2 );
-    _F2I( t2, _POINT( 1, w - 3 ) + mask0 );
-    CALC_MIN( t1, t2 );
-    _F2I( t2, _POINT( 0, w - 4 ) + mask2 );
-    CALC_MIN( t1, t2 );
-    _I2F( _POINT( 1, w - 2 ), t1 );
+    t2 = _POINT( 0, w - 2 ) + mask0;
+    CV_CALC_MIN( t1, t2 );
+    t2 = _POINT( 0, w - 1 ) + mask1;
+    CV_CALC_MIN( t1, t2 );
+    t2 = _POINT( 0, w - 3 ) + mask1;
+    CV_CALC_MIN( t1, t2 );
+    t2 = _POINT( 1, w - 3 ) + mask0;
+    CV_CALC_MIN( t1, t2 );
+    t2 = _POINT( 0, w - 4 ) + mask2;
+    CV_CALC_MIN( t1, t2 );
+    _POINT( 1, w - 2 ) = t1;
 
     /* ri = 1, ci = w - 1 */
     t1 = *(int *) &_POINT( 1, w - 1 );
-    _F2I( t2, _POINT( 0, w - 1 ) + mask0 );
-    CALC_MIN( t1, t2 );
-    _F2I( t2, _POINT( 0, w - 2 ) + mask1 );
-    CALC_MIN( t1, t2 );
-    _F2I( t2, _POINT( 1, w - 2 ) + mask0 );
-    CALC_MIN( t1, t2 );
-    _F2I( t2, _POINT( 0, w - 3 ) + mask2 );
-    CALC_MIN( t1, t2 );
-    _I2F( _POINT( 1, w - 1 ), t1 )
+    t2 = _POINT( 0, w - 1 ) + mask0;
+    CV_CALC_MIN( t1, t2 );
+    t2 = _POINT( 0, w - 2 ) + mask1;
+    CV_CALC_MIN( t1, t2 );
+    t2 = _POINT( 1, w - 2 ) + mask0;
+    CV_CALC_MIN( t1, t2 );
+    t2 = _POINT( 0, w - 3 ) + mask2;
+    CV_CALC_MIN( t1, t2 );
+    _POINT( 1, w - 1 ) = t1;
         /* 1 < ri < h */
         for( ri = 2; ri < h; ri++ )
     {
         /* ci = 0 */
         t1 = *(int *) &_POINT( ri, 0 );
-        _F2I( t2, _POINT( ri - 1, 0 ) + mask0 );
-        CALC_MIN( t1, t2 );
-        _F2I( t2, _POINT( ri - 1, 1 ) + mask1 );
-        CALC_MIN( t1, t2 );
-        _F2I( t2, _POINT( ri - 1, 2 ) + mask2 );
-        CALC_MIN( t1, t2 );
-        _F2I( t2, _POINT( ri - 2, 1 ) + mask2 );
-        CALC_MIN( t1, t2 );
-        _I2F( _POINT( ri, 0 ), t1 );
+        t2 = _POINT( ri - 1, 0 ) + mask0;
+        CV_CALC_MIN( t1, t2 );
+        t2 = _POINT( ri - 1, 1 ) + mask1;
+        CV_CALC_MIN( t1, t2 );
+        t2 = _POINT( ri - 1, 2 ) + mask2;
+        CV_CALC_MIN( t1, t2 );
+        t2 = _POINT( ri - 2, 1 ) + mask2;
+        CV_CALC_MIN( t1, t2 );
+        _POINT( ri, 0 ) = t1;
 
         /* ci = 1 */
         t1 = *(int *) &_POINT( ri, 1 );
-        _F2I( t2, _POINT( ri - 1, 1 ) + mask0 );
-        CALC_MIN( t1, t2 );
-        _F2I( t2, _POINT( ri - 1, 2 ) + mask1 );
-        CALC_MIN( t1, t2 );
-        _F2I( t2, _POINT( ri - 1, 3 ) + mask2 );
-        CALC_MIN( t1, t2 );
-        _F2I( t2, _POINT( ri - 2, 2 ) + mask2 );
-        CALC_MIN( t1, t2 );
-        _F2I( t2, _POINT( ri, 0 ) + mask0 );
-        CALC_MIN( t1, t2 );
-        _F2I( t2, _POINT( ri - 1, 0 ) + mask1 );
-        CALC_MIN( t1, t2 );
-        _F2I( t2, _POINT( ri - 2, 0 ) + mask2 );
-        CALC_MIN( t1, t2 );
-        _I2F( _POINT( ri, 1 ), t1 );
+        t2 = _POINT( ri - 1, 1 ) + mask0;
+        CV_CALC_MIN( t1, t2 );
+        t2 = _POINT( ri - 1, 2 ) + mask1;
+        CV_CALC_MIN( t1, t2 );
+        t2 = _POINT( ri - 1, 3 ) + mask2;
+        CV_CALC_MIN( t1, t2 );
+        t2 = _POINT( ri - 2, 2 ) + mask2;
+        CV_CALC_MIN( t1, t2 );
+        t2 = _POINT( ri, 0 ) + mask0;
+        CV_CALC_MIN( t1, t2 );
+        t2 = _POINT( ri - 1, 0 ) + mask1;
+        CV_CALC_MIN( t1, t2 );
+        t2 = _POINT( ri - 2, 0 ) + mask2;
+        CV_CALC_MIN( t1, t2 );
+        _POINT( ri, 1 ) = t1;
 
 
         /* 1 < ci < w - 2 */
         for( ci = 2; ci < w - 2; ci++ )
         {
             t1 = *(int *) &_POINT( ri, ci );
-            _F2I( t2, _POINT( ri, ci - 1 ) + mask0 );
-            CALC_MIN( t1, t2 );
-            _F2I( t2, _POINT( ri - 1, ci ) + mask0 );
-            CALC_MIN( t1, t2 );
-            _F2I( t2, _POINT( ri - 1, ci + 1 ) + mask1 );
-            CALC_MIN( t1, t2 );
-            _F2I( t2, _POINT( ri - 1, ci + 2 ) + mask2 );
-            CALC_MIN( t1, t2 );
-            _F2I( t2, _POINT( ri - 2, ci + 1 ) + mask2 );
-            CALC_MIN( t1, t2 );
-            _F2I( t2, _POINT( ri - 1, ci - 1 ) + mask1 );
-            CALC_MIN( t1, t2 );
-            _F2I( t2, _POINT( ri - 1, ci - 2 ) + mask2 );
-            CALC_MIN( t1, t2 );
-            _F2I( t2, _POINT( ri - 2, ci - 1 ) + mask2 );
-            CALC_MIN( t1, t2 );
-        _I2F( _POINT( ri, ci ), t1 )}
+            t2 = _POINT( ri, ci - 1 ) + mask0;
+            CV_CALC_MIN( t1, t2 );
+            t2 = _POINT( ri - 1, ci ) + mask0;
+            CV_CALC_MIN( t1, t2 );
+            t2 = _POINT( ri - 1, ci + 1 ) + mask1;
+            CV_CALC_MIN( t1, t2 );
+            t2 = _POINT( ri - 1, ci + 2 ) + mask2;
+            CV_CALC_MIN( t1, t2 );
+            t2 = _POINT( ri - 2, ci + 1 ) + mask2;
+            CV_CALC_MIN( t1, t2 );
+            t2 = _POINT( ri - 1, ci - 1 ) + mask1;
+            CV_CALC_MIN( t1, t2 );
+            t2 = _POINT( ri - 1, ci - 2 ) + mask2;
+            CV_CALC_MIN( t1, t2 );
+            t2 = _POINT( ri - 2, ci - 1 ) + mask2;
+            CV_CALC_MIN( t1, t2 );
+            _POINT( ri, ci ) = t1;
+        }
 
 
         /* ci = w - 2 */
         t1 = *(int *) &_POINT( ri, w - 2 );
-        _F2I( t2, _POINT( ri - 1, w - 2 ) + mask0 );
-        CALC_MIN( t1, t2 );
-        _F2I( t2, _POINT( ri - 1, w - 1 ) + mask1 );
-        CALC_MIN( t1, t2 );
-        _F2I( t2, _POINT( ri - 2, w - 1 ) + mask2 );
-        CALC_MIN( t1, t2 );
-        _F2I( t2, _POINT( ri, w - 2 ) + mask0 );
-        CALC_MIN( t1, t2 );
-        _F2I( t2, _POINT( ri - 1, w - 3 ) + mask1 );
-        CALC_MIN( t1, t2 );
-        _F2I( t2, _POINT( ri - 1, w - 4 ) + mask2 );
-        CALC_MIN( t1, t2 );
-        _F2I( t2, _POINT( ri - 2, w - 3 ) + mask2 );
-        CALC_MIN( t1, t2 );
-        _I2F( _POINT( ri, w - 2 ), t1 );
+        t2 = _POINT( ri - 1, w - 2 ) + mask0;
+        CV_CALC_MIN( t1, t2 );
+        t2 = _POINT( ri - 1, w - 1 ) + mask1;
+        CV_CALC_MIN( t1, t2 );
+        t2 = _POINT( ri - 2, w - 1 ) + mask2;
+        CV_CALC_MIN( t1, t2 );
+        t2 = _POINT( ri, w - 2 ) + mask0;
+        CV_CALC_MIN( t1, t2 );
+        t2 = _POINT( ri - 1, w - 3 ) + mask1;
+        CV_CALC_MIN( t1, t2 );
+        t2 = _POINT( ri - 1, w - 4 ) + mask2;
+        CV_CALC_MIN( t1, t2 );
+        t2 = _POINT( ri - 2, w - 3 ) + mask2;
+        CV_CALC_MIN( t1, t2 );
+        _POINT( ri, w - 2 ) = t1;
 
 
         /* ci = w - 1 */
         t1 = *(int *) &_POINT( ri, w - 1 );
-        _F2I( t2, _POINT( ri - 1, w - 1 ) + mask0 );
-        CALC_MIN( t1, t2 );
-        _F2I( t2, _POINT( ri, w - 2 ) + mask0 );
-        CALC_MIN( t1, t2 );
-        _F2I( t2, _POINT( ri - 1, w - 2 ) + mask1 );
-        CALC_MIN( t1, t2 );
-        _F2I( t2, _POINT( ri - 1, w - 3 ) + mask2 );
-        CALC_MIN( t1, t2 );
-        _F2I( t2, _POINT( ri - 2, w - 2 ) + mask2 );
-        CALC_MIN( t1, t2 );
-        _I2F( _POINT( ri, w - 1 ), t1 );
+        t2 = _POINT( ri - 1, w - 1 ) + mask0;
+        CV_CALC_MIN( t1, t2 );
+        t2 = _POINT( ri, w - 2 ) + mask0;
+        CV_CALC_MIN( t1, t2 );
+        t2 = _POINT( ri - 1, w - 2 ) + mask1;
+        CV_CALC_MIN( t1, t2 );
+        t2 = _POINT( ri - 1, w - 3 ) + mask2;
+        CV_CALC_MIN( t1, t2 );
+        t2 = _POINT( ri - 2, w - 2 ) + mask2;
+        CV_CALC_MIN( t1, t2 );
+        _POINT( ri, w - 1 ) = t1;
     }
 
 
@@ -750,88 +747,88 @@ IPCVAPI_IMPL( CvStatus, icvDistanceTransform_5x5_8u32f_C1R,
 
     /* ri = h - 1, ci = w - 2 */
     t1 = *(int *) &_POINT( h - 1, w - 2 );
-    _F2I( t2, _POINT( h - 1, w - 1 ) + mask0 );
-    CALC_MIN( t1, t2 );
-    _I2F( _POINT( h - 1, w - 2 ), t1 );
+    t2 = _POINT( h - 1, w - 1 ) + mask0;
+    CV_CALC_MIN( t1, t2 );
+    _POINT( h - 1, w - 2 ) = t1;
 
     /* ri = h - 1, w - 2 > ci >= 0 */
     for( ci = w - 3; ci >= 0; ci-- )
     {
         t1 = *(int *) &_POINT( h - 1, ci );
-        _F2I( t2, _POINT( h - 1, ci + 1 ) + mask0 );
-        CALC_MIN( t1, t2 );
-        _I2F( _POINT( h - 1, ci ), t1 );
+        t2 = _POINT( h - 1, ci + 1 ) + mask0;
+        CV_CALC_MIN( t1, t2 );
+        _POINT( h - 1, ci ) = t1;
     }
 
 
     /* ri = h - 2, ci = w - 1 */
     t1 = *(int *) &_POINT( h - 2, w - 1 );
-    _F2I( t2, _POINT( h - 1, w - 1 ) + mask0 );
-    CALC_MIN( t1, t2 );
-    _F2I( t2, _POINT( h - 1, w - 2 ) + mask1 );
-    CALC_MIN( t1, t2 );
-    _F2I( t2, _POINT( h - 1, w - 3 ) + mask2 );
-    CALC_MIN( t1, t2 );
-    _I2F( _POINT( h - 2, w - 1 ), t1 );
+    t2 = _POINT( h - 1, w - 1 ) + mask0;
+    CV_CALC_MIN( t1, t2 );
+    t2 = _POINT( h - 1, w - 2 ) + mask1;
+    CV_CALC_MIN( t1, t2 );
+    t2 = _POINT( h - 1, w - 3 ) + mask2;
+    CV_CALC_MIN( t1, t2 );
+    _POINT( h - 2, w - 1 ) = t1;
 
     /* ri = h - 2, ci = w - 2 */
     t1 = *(int *) &_POINT( h - 2, w - 2 );
-    _F2I( t2, _POINT( h - 1, w - 2 ) + mask0 );
-    CALC_MIN( t1, t2 );
-    _F2I( t2, _POINT( h - 1, w - 3 ) + mask1 );
-    CALC_MIN( t1, t2 );
-    _F2I( t2, _POINT( h - 1, w - 4 ) + mask2 );
-    CALC_MIN( t1, t2 );
-    _F2I( t2, _POINT( h - 1, w - 1 ) + mask1 );
-    CALC_MIN( t1, t2 );
-    _F2I( t2, _POINT( h - 2, w - 1 ) + mask0 );
-    CALC_MIN( t1, t2 );
-    _I2F( _POINT( h - 2, w - 2 ), t1 );
+    t2 = _POINT( h - 1, w - 2 ) + mask0;
+    CV_CALC_MIN( t1, t2 );
+    t2 = _POINT( h - 1, w - 3 ) + mask1;
+    CV_CALC_MIN( t1, t2 );
+    t2 = _POINT( h - 1, w - 4 ) + mask2;
+    CV_CALC_MIN( t1, t2 );
+    t2 = _POINT( h - 1, w - 1 ) + mask1;
+    CV_CALC_MIN( t1, t2 );
+    t2 = _POINT( h - 2, w - 1 ) + mask0;
+    CV_CALC_MIN( t1, t2 );
+    _POINT( h - 2, w - 2 ) = t1;
 
     /* ri = h - 2, w - 2 > ci > 1 */
     for( ci = w - 3; ci > 1; ci-- )
     {
         t1 = *(int *) &_POINT( h - 2, ci );
-        _F2I( t2, _POINT( h - 2, ci + 1 ) + mask0 );
-        CALC_MIN( t1, t2 );
-        _F2I( t2, _POINT( h - 1, ci ) + mask0 );
-        CALC_MIN( t1, t2 );
-        _F2I( t2, _POINT( h - 1, ci + 1 ) + mask1 );
-        CALC_MIN( t1, t2 );
-        _F2I( t2, _POINT( h - 1, ci + 2 ) + mask2 );
-        CALC_MIN( t1, t2 );
-        _F2I( t2, _POINT( h - 1, ci - 1 ) + mask1 );
-        CALC_MIN( t1, t2 );
-        _F2I( t2, _POINT( h - 1, ci - 2 ) + mask2 );
-        CALC_MIN( t1, t2 );
-        _I2F( _POINT( h - 2, ci ), t1 );
+        t2 = _POINT( h - 2, ci + 1 ) + mask0;
+        CV_CALC_MIN( t1, t2 );
+        t2 = _POINT( h - 1, ci ) + mask0;
+        CV_CALC_MIN( t1, t2 );
+        t2 = _POINT( h - 1, ci + 1 ) + mask1;
+        CV_CALC_MIN( t1, t2 );
+        t2 = _POINT( h - 1, ci + 2 ) + mask2;
+        CV_CALC_MIN( t1, t2 );
+        t2 = _POINT( h - 1, ci - 1 ) + mask1;
+        CV_CALC_MIN( t1, t2 );
+        t2 = _POINT( h - 1, ci - 2 ) + mask2;
+        CV_CALC_MIN( t1, t2 );
+        _POINT( h - 2, ci ) = t1;
     }
 
     /* ri = h - 2, ci = 1 */
     t1 = *(int *) &_POINT( h - 2, 1 );
-    _F2I( t2, _POINT( h - 2, 2 ) + mask0 );
-    CALC_MIN( t1, t2 );
-    _F2I( t2, _POINT( h - 1, 2 ) + mask1 );
-    CALC_MIN( t1, t2 );
-    _F2I( t2, _POINT( h - 1, 3 ) + mask2 );
-    CALC_MIN( t1, t2 );
-    _F2I( t2, _POINT( h - 1, 1 ) + mask0 );
-    CALC_MIN( t1, t2 );
-    _F2I( t2, _POINT( h - 1, 0 ) + mask1 );
-    CALC_MIN( t1, t2 );
-    _I2F( _POINT( h - 2, 1 ), t1 );
+    t2 = _POINT( h - 2, 2 ) + mask0;
+    CV_CALC_MIN( t1, t2 );
+    t2 = _POINT( h - 1, 2 ) + mask1;
+    CV_CALC_MIN( t1, t2 );
+    t2 = _POINT( h - 1, 3 ) + mask2;
+    CV_CALC_MIN( t1, t2 );
+    t2 = _POINT( h - 1, 1 ) + mask0;
+    CV_CALC_MIN( t1, t2 );
+    t2 = _POINT( h - 1, 0 ) + mask1;
+    CV_CALC_MIN( t1, t2 );
+    _POINT( h - 2, 1 ) = t1;
 
     /* ri = h - 2, ci = 0 */
     t1 = *(int *) &_POINT( h - 2, 0 );
-    _F2I( t2, _POINT( h - 2, 1 ) + mask0 );
-    CALC_MIN( t1, t2 );
-    _F2I( t2, _POINT( h - 1, 1 ) + mask1 );
-    CALC_MIN( t1, t2 );
-    _F2I( t2, _POINT( h - 1, 2 ) + mask2 );
-    CALC_MIN( t1, t2 );
-    _F2I( t2, _POINT( h - 1, 0 ) + mask0 );
-    CALC_MIN( t1, t2 );
-    _I2F( _POINT( h - 2, 0 ), t1 );
+    t2 = _POINT( h - 2, 1 ) + mask0;
+    CV_CALC_MIN( t1, t2 );
+    t2 = _POINT( h - 1, 1 ) + mask1;
+    CV_CALC_MIN( t1, t2 );
+    t2 = _POINT( h - 1, 2 ) + mask2;
+    CV_CALC_MIN( t1, t2 );
+    t2 = _POINT( h - 1, 0 ) + mask0;
+    CV_CALC_MIN( t1, t2 );
+    _POINT( h - 2, 0 ) = t1;
 
 
     /* h - 2 > ri >= 0 */
@@ -839,88 +836,88 @@ IPCVAPI_IMPL( CvStatus, icvDistanceTransform_5x5_8u32f_C1R,
     {
         /* ci = w - 1 */
         t1 = *(int *) &_POINT( ri, w - 1 );
-        _F2I( t2, _POINT( ri + 1, w - 1 ) + mask0 );
-        CALC_MIN( t1, t2 );
-        _F2I( t2, _POINT( ri + 1, w - 2 ) + mask1 );
-        CALC_MIN( t1, t2 );
-        _F2I( t2, _POINT( ri + 2, w - 2 ) + mask2 );
-        CALC_MIN( t1, t2 );
-        _F2I( t2, _POINT( ri + 1, w - 3 ) + mask2 );
-        CALC_MIN( t1, t2 );
-        _I2F( _POINT( ri, w - 1 ), t1 );
+        t2 = _POINT( ri + 1, w - 1 ) + mask0;
+        CV_CALC_MIN( t1, t2 );
+        t2 = _POINT( ri + 1, w - 2 ) + mask1;
+        CV_CALC_MIN( t1, t2 );
+        t2 = _POINT( ri + 2, w - 2 ) + mask2;
+        CV_CALC_MIN( t1, t2 );
+        t2 = _POINT( ri + 1, w - 3 ) + mask2;
+        CV_CALC_MIN( t1, t2 );
+        _POINT( ri, w - 1 ) = t1;
 
         /* ci = w - 2 */
         t1 = *(int *) &_POINT( ri, w - 2 );
-        _F2I( t2, _POINT( ri, w - 1 ) + mask0 );
-        CALC_MIN( t1, t2 );
-        _F2I( t2, _POINT( ri + 1, w - 1 ) + mask1 );
-        CALC_MIN( t1, t2 );
-        _F2I( t2, _POINT( ri + 2, w - 1 ) + mask2 );
-        CALC_MIN( t1, t2 );
-        _F2I( t2, _POINT( ri + 1, w - 2 ) + mask0 );
-        CALC_MIN( t1, t2 );
-        _F2I( t2, _POINT( ri + 1, w - 3 ) + mask1 );
-        CALC_MIN( t1, t2 );
-        _F2I( t2, _POINT( ri + 2, w - 3 ) + mask2 );
-        CALC_MIN( t1, t2 );
-        _F2I( t2, _POINT( ri + 1, w - 4 ) + mask2 );
-        CALC_MIN( t1, t2 );
-        _I2F( _POINT( ri, w - 2 ), t1 );
+        t2 = _POINT( ri, w - 1 ) + mask0;
+        CV_CALC_MIN( t1, t2 );
+        t2 = _POINT( ri + 1, w - 1 ) + mask1;
+        CV_CALC_MIN( t1, t2 );
+        t2 = _POINT( ri + 2, w - 1 ) + mask2;
+        CV_CALC_MIN( t1, t2 );
+        t2 = _POINT( ri + 1, w - 2 ) + mask0;
+        CV_CALC_MIN( t1, t2 );
+        t2 = _POINT( ri + 1, w - 3 ) + mask1;
+        CV_CALC_MIN( t1, t2 );
+        t2 = _POINT( ri + 2, w - 3 ) + mask2;
+        CV_CALC_MIN( t1, t2 );
+        t2 = _POINT( ri + 1, w - 4 ) + mask2;
+        CV_CALC_MIN( t1, t2 );
+        _POINT( ri, w - 2 ) = t1;
 
         /* w - 2 > ci > 1 */
         for( ci = w - 3; ci > 1; ci-- )
         {
             t1 = *(int *) &_POINT( ri, ci );
-            _F2I( t2, _POINT( ri, ci + 1 ) + mask0 );
-            CALC_MIN( t1, t2 );
-            _F2I( t2, _POINT( ri + 1, ci ) + mask0 );
-            CALC_MIN( t1, t2 );
-            _F2I( t2, _POINT( ri + 1, ci + 1 ) + mask1 );
-            CALC_MIN( t1, t2 );
-            _F2I( t2, _POINT( ri + 1, ci + 2 ) + mask2 );
-            CALC_MIN( t1, t2 );
-            _F2I( t2, _POINT( ri + 2, ci + 1 ) + mask2 );
-            CALC_MIN( t1, t2 );
-            _F2I( t2, _POINT( ri + 1, ci - 1 ) + mask1 );
-            CALC_MIN( t1, t2 );
-            _F2I( t2, _POINT( ri + 1, ci - 2 ) + mask2 );
-            CALC_MIN( t1, t2 );
-            _F2I( t2, _POINT( ri + 2, ci - 1 ) + mask2 );
-            CALC_MIN( t1, t2 );
-            _I2F( _POINT( ri, ci ), t1 );
+            t2 = _POINT( ri, ci + 1 ) + mask0;
+            CV_CALC_MIN( t1, t2 );
+            t2 = _POINT( ri + 1, ci ) + mask0;
+            CV_CALC_MIN( t1, t2 );
+            t2 = _POINT( ri + 1, ci + 1 ) + mask1;
+            CV_CALC_MIN( t1, t2 );
+            t2 = _POINT( ri + 1, ci + 2 ) + mask2;
+            CV_CALC_MIN( t1, t2 );
+            t2 = _POINT( ri + 2, ci + 1 ) + mask2;
+            CV_CALC_MIN( t1, t2 );
+            t2 = _POINT( ri + 1, ci - 1 ) + mask1;
+            CV_CALC_MIN( t1, t2 );
+            t2 = _POINT( ri + 1, ci - 2 ) + mask2;
+            CV_CALC_MIN( t1, t2 );
+            t2 = _POINT( ri + 2, ci - 1 ) + mask2;
+            CV_CALC_MIN( t1, t2 );
+            _POINT( ri, ci ) = t1;
         }
 
         /* ci = 1 */
         t1 = *(int *) &_POINT( ri, 1 );
-        _F2I( t2, _POINT( ri, 2 ) + mask0 );
-        CALC_MIN( t1, t2 );
-        _F2I( t2, _POINT( ri + 1, 1 ) + mask0 );
-        CALC_MIN( t1, t2 );
-        _F2I( t2, _POINT( ri + 1, 2 ) + mask1 );
-        CALC_MIN( t1, t2 );
-        _F2I( t2, _POINT( ri + 1, 3 ) + mask2 );
-        CALC_MIN( t1, t2 );
-        _F2I( t2, _POINT( ri + 2, 2 ) + mask2 );
-        CALC_MIN( t1, t2 );
-        _F2I( t2, _POINT( ri + 1, 0 ) + mask1 );
-        CALC_MIN( t1, t2 );
-        _F2I( t2, _POINT( ri + 2, 0 ) + mask2 );
-        CALC_MIN( t1, t2 );
-        _I2F( _POINT( ri, 1 ), t1 );
+        t2 = _POINT( ri, 2 ) + mask0;
+        CV_CALC_MIN( t1, t2 );
+        t2 = _POINT( ri + 1, 1 ) + mask0;
+        CV_CALC_MIN( t1, t2 );
+        t2 = _POINT( ri + 1, 2 ) + mask1;
+        CV_CALC_MIN( t1, t2 );
+        t2 = _POINT( ri + 1, 3 ) + mask2;
+        CV_CALC_MIN( t1, t2 );
+        t2 = _POINT( ri + 2, 2 ) + mask2;
+        CV_CALC_MIN( t1, t2 );
+        t2 = _POINT( ri + 1, 0 ) + mask1;
+        CV_CALC_MIN( t1, t2 );
+        t2 = _POINT( ri + 2, 0 ) + mask2;
+        CV_CALC_MIN( t1, t2 );
+        _POINT( ri, 1 ) = t1;
 
         /* ci = 0 */
         t1 = *(int *) &_POINT( ri, 0 );
-        _F2I( t2, _POINT( ri, 1 ) + mask0 );
-        CALC_MIN( t1, t2 );
-        _F2I( t2, _POINT( ri + 1, 0 ) + mask0 );
-        CALC_MIN( t1, t2 );
-        _F2I( t2, _POINT( ri + 1, 1 ) + mask1 );
-        CALC_MIN( t1, t2 );
-        _F2I( t2, _POINT( ri + 1, 2 ) + mask2 );
-        CALC_MIN( t1, t2 );
-        _F2I( t2, _POINT( ri + 2, 1 ) + mask2 );
-        CALC_MIN( t1, t2 );
-        _I2F( _POINT( ri, 0 ), t1 );
+        t2 = _POINT( ri, 1 ) + mask0;
+        CV_CALC_MIN( t1, t2 );
+        t2 = _POINT( ri + 1, 0 ) + mask0;
+        CV_CALC_MIN( t1, t2 );
+        t2 = _POINT( ri + 1, 1 ) + mask1;
+        CV_CALC_MIN( t1, t2 );
+        t2 = _POINT( ri + 1, 2 ) + mask2;
+        CV_CALC_MIN( t1, t2 );
+        t2 = _POINT( ri + 2, 1 ) + mask2;
+        CV_CALC_MIN( t1, t2 );
+        _POINT( ri, 0 ) = t1;
     }
 
   func_exit:
@@ -930,7 +927,7 @@ IPCVAPI_IMPL( CvStatus, icvDistanceTransform_5x5_8u32f_C1R,
 }
 
 
-IPCVAPI_IMPL( CvStatus, icvGetDistanceTransformMask, (int maskType, float *pMetrics) )
+IPCVAPI_IMPL( CvStatus, icvGetDistanceTransformMask, (int maskType, float *pMetrics), (maskType, pMetrics) )
 {
     if( !pMetrics )
         return CV_NULLPTR_ERR;
@@ -967,7 +964,7 @@ IPCVAPI_IMPL( CvStatus, icvGetDistanceTransformMask, (int maskType, float *pMetr
 /* Wrapper function for distance transform group */
 CV_IMPL void
 cvDistTransform( const void* srcarr, void* dstarr,
-                 CvDisType distType, int maskSize,
+                 int distType, int maskSize,
                  const float *mask )
 {
     CV_FUNCNAME( "cvDistTransform" );
@@ -1012,14 +1009,14 @@ cvDistTransform( const void* srcarr, void* dstarr,
         IPPI_CALL( icvDistanceTransform_3x3_8u32f_C1R
                    ( src->data.ptr, src->step,
                      dst->data.fl, dst->step,
-                     icvGetMatSize(src), _mask ));
+                     cvGetMatSize(src), _mask ));
     }
     else
     {
         IPPI_CALL( icvDistanceTransform_5x5_8u32f_C1R
                    ( src->data.ptr, src->step,
                      dst->data.fl, dst->step,
-                     icvGetMatSize(src), _mask ));
+                     cvGetMatSize(src), _mask ));
     }
 
     __END__;
index 9f2d03abc7e74f3c9b10de07f1b720dbe73c8004..28c165d7e26fb8ee7999e5abe39385d5abdf2e4d 100644 (file)
@@ -50,7 +50,7 @@ typedef struct _PointInfo
 icvPointInfo;
 
 
-CvStatus
+static CvStatus
 icvFindDominantPointsIPAN( CvSeq * contour,
                            CvMemStorage * storage,
                            CvSeq ** corners, int dmin2, int dmax2, int dneigh2, float amax )
@@ -86,10 +86,10 @@ icvFindDominantPointsIPAN( CvSeq * contour,
     if( (amax < 0) || (amax > 180) )
         return CV_BADSIZE_ERR;
 
-    sharpness = (float *) icvAlloc( n * sizeof( float ));
-    distance = (float *) icvAlloc( n * sizeof( float ));
+    sharpness = (float *) cvAlloc( n * sizeof( float ));
+    distance = (float *) cvAlloc( n * sizeof( float ));
 
-    ptInf = (icvPointInfo *) icvAlloc( n * sizeof( icvPointInfo ));
+    ptInf = (icvPointInfo *) cvAlloc( n * sizeof( icvPointInfo ));
 
 /*****************************************************************************************/
 /*                                 First pass                                            */
@@ -322,18 +322,18 @@ icvFindDominantPointsIPAN( CvSeq * contour,
 
     *corners = cvEndWriteSeq( &writer );
 
-    icvFree( &sharpness );
-    icvFree( &distance );
-    icvFree( &ptInf );
+    cvFree( (void**)&sharpness );
+    cvFree( (void**)&distance );
+    cvFree( (void**)&ptInf );
 
     return status;
 
   error:
     /* dmax is so big (more than contour diameter)
        that algorithm could become infinite cycle */
-    icvFree( &sharpness );
-    icvFree( &distance );
-    icvFree( &ptInf );
+    cvFree( (void**)&sharpness );
+    cvFree( (void**)&distance );
+    cvFree( (void**)&ptInf );
 
     return CV_BADRANGE_ERR;
 }
@@ -364,37 +364,53 @@ icvFindDominantPointsIPAN( CvSeq * contour,
 //      User must allocate out_numbers array. If it is small - function fills array 
 //      with part of points and returns  error
 //F*/
-#define CV_DOMINANT_IPAN 1
-
-CV_IMPL void
-cvFindDominantPoints( CvSeq * contour,
-                      CvMemStorage * storage, CvSeq ** corners, int method, float *parameters )
+CV_IMPL CvSeq*
+cvFindDominantPoints( CvSeq * contour, CvMemStorage * storage, int method,
+                      double parameter1, double parameter2, double parameter3, double parameter4 )
 {
+    CvSeq* corners = 0;
+
     CV_FUNCNAME( "cvFindDominantPoints" );
     __BEGIN__;
 
-    if( !contour || !parameters || !storage || !corners )
-        CV_ERROR_FROM_STATUS( CV_NULLPTR_ERR );
+    if( !contour )
+        CV_ERROR( CV_StsNullPtr, "" );
+
+    if( !storage )
+        storage = contour->storage;
+
+    if( !storage )
+        CV_ERROR( CV_StsNullPtr, "" );
 
     switch (method)
     {
     case CV_DOMINANT_IPAN:
         {
-            int dmin2 = cvRound( parameters[0] * parameters[0] );
-            int dmax2 = cvRound( parameters[1] * parameters[1] );
-            int dneigh2 = cvRound( parameters[2] * parameters[2] );
-            float amax = parameters[3];
-
-            IPPI_CALL( icvFindDominantPointsIPAN( contour, storage, corners,
-                                                  dmin2, dmax2, dneigh2, amax ));
+            int dmin = cvRound(parameter1);
+            int dmax = cvRound(parameter2);
+            int dneigh = cvRound(parameter3);
+            int amax = cvRound(parameter4);
+
+            if( amax == 0 )
+                amax = 150;
+            if( dmin == 0 )
+                dmin = 7;
+            if( dmax == 0 )
+                dmax = dmin + 2;
+            if( dneigh == 0 )
+                dneigh = dmin;
+
+            IPPI_CALL( icvFindDominantPointsIPAN( contour, storage, &corners,
+                                                  dmin*dmin, dmax*dmax, dneigh*dneigh, (float)amax ));
         }
         break;
     default:
         CV_ERROR_FROM_STATUS( CV_BADFLAG_ERR );
     }
 
-    __CLEANUP__;
     __END__;
+
+    return corners;
 }
 
 /* End of file. */
index ec27016432610d5eb48dd1e0c875b42560402273..9f9b1223db868ff606dd8fe979ba26b95aa1a0da 100644 (file)
@@ -148,7 +148,7 @@ static float icvDistC( const float *x, const float *y, void *user_param );
 CV_IMPL float
 cvCalcEMD2( const CvArr* signature_arr1,
             const CvArr* signature_arr2,
-            CvDisType dist_type,
+            int dist_type,
             CvDistanceFunction dist_func,
             const CvArr* cost_matrix,
             CvArr* flow_matrix,
@@ -156,7 +156,7 @@ cvCalcEMD2( const CvArr* signature_arr1,
             void *user_param )
 {
     char local_buffer[16384];
-    char *local_buffer_ptr = (char *)icvAlignPtr(local_buffer,16);
+    char *local_buffer_ptr = (char *)cvAlignPtr(local_buffer,16);
     CvEMDState state;
     float emd = 0;
 
@@ -196,7 +196,7 @@ cvCalcEMD2( const CvArr* signature_arr1,
     {
         CV_CALL( flow = cvGetMat( flow, &flow_stub ));
 
-        if( cost->rows != size1 || cost->cols != size2 )
+        if( flow->rows != size1 || flow->cols != size2 )
             CV_ERROR( CV_StsUnmatchedSizes,
             "The flow matrix size does not match to the signatures' sizes" );
 
@@ -235,7 +235,7 @@ cvCalcEMD2( const CvArr* signature_arr1,
         if( dims == 0 )
             CV_ERROR( CV_StsBadSize,
             "Number of dimensions can be 0 only if a user-defined metric is used" );
-        user_param = (void *) dims;
+        user_param = (void *) (size_t)dims;
         switch (dist_type)
         {
         case CV_DIST_L1:
@@ -321,7 +321,7 @@ cvCalcEMD2( const CvArr* signature_arr1,
     __END__;
 
     if( state.buffer && state.buffer != local_buffer_ptr )
-        icvFree( &(state.buffer) );
+        cvFree( (void**)&(state.buffer) );
 
     return emd;
 }
@@ -374,7 +374,7 @@ icvInitEMD( const float* signature1, int size1,
     }
     else
     {
-        buffer = (char *) icvAlloc( buffer_size );
+        buffer = (char*)cvAlloc( buffer_size );
         if( !buffer )
             return CV_OUTOFMEM_ERR;
     }
@@ -1124,7 +1124,7 @@ icvAddBasicVariable( CvEMDState * state,
 static float
 icvDistL1( const float *x, const float *y, void *user_param )
 {
-    int i, dims = (int)(long)user_param;
+    int i, dims = (int)(size_t)user_param;
     double s = 0;
 
     for( i = 0; i < dims; i++ )
@@ -1139,7 +1139,7 @@ icvDistL1( const float *x, const float *y, void *user_param )
 static float
 icvDistL2( const float *x, const float *y, void *user_param )
 {
-    int i, dims = (int)(long)user_param;
+    int i, dims = (int)(size_t)user_param;
     double s = 0;
 
     for( i = 0; i < dims; i++ )
@@ -1154,7 +1154,7 @@ icvDistL2( const float *x, const float *y, void *user_param )
 static float
 icvDistC( const float *x, const float *y, void *user_param )
 {
-    int i, dims = (int)(long)user_param;
+    int i, dims = (int)(size_t)user_param;
     double s = 0;
 
     for( i = 0; i < dims; i++ )
index 60d1de456309bc4ce8ecc26c09ce5642bcf198c4..628593a3df7b0d935c490bdf0ad65ef684470267 100644 (file)
 //
 //M*/
 #include "_cv.h"
-#include "_cvutils.h"
 
 #define  cmp_features( f1, f2 )  (*(f1) > *(f2))
 
-CV_IMPLEMENT_QSORT( icvSortFeatures, int *, cmp_features );
+static CV_IMPLEMENT_QSORT( icvSortFeatures, int *, cmp_features )
 
 void
 cvGoodFeaturesToTrack( const void* image, void* eigImage, void* tempImage,
@@ -103,11 +102,11 @@ cvGoodFeaturesToTrack( const void* image, void* eigImage, void* tempImage,
     if( CV_MAT_CN(img->type) != 1 ||
         CV_MAT_CN(eig->type) != 1 ||
         CV_MAT_CN(tmp->type) != 1 )
-        CV_ERROR( CV_BadNumChannels, icvUnsupportedFormat );
+        CV_ERROR( CV_BadNumChannels, cvUnsupportedFormat );
 
     if( CV_MAT_DEPTH(tmp->type) != CV_32F ||
         CV_MAT_DEPTH(eig->type) != CV_32F )
-        CV_ERROR( CV_BadDepth, icvUnsupportedFormat );
+        CV_ERROR( CV_BadDepth, cvUnsupportedFormat );
 
     if( !corners || !corner_count )
         CV_ERROR( CV_StsNullPtr, "" );
@@ -126,7 +125,7 @@ cvGoodFeaturesToTrack( const void* image, void* eigImage, void* tempImage,
 
     min_dist = cvRound( min_distance * min_distance );
 
-    size = icvGetMatSize( img );
+    size = cvGetMatSize( img );
     ptr_data = (int**)(tmp->data.ptr);
     eig_data = (int*)(eig->data.ptr);
     tmp_data = (int*)(tmp->data.ptr);
index 4a117e8e971e1ea957ec44ecabf5e641bab16be0..f2a623586a0ef3cd014cef1a55035b4cce7494c3 100644 (file)
@@ -81,152 +81,73 @@ CvFFillSegment;
 }
 
 
+#define ICV_EQ_C3( p1, p2 ) \
+    ((p1)[0] == (p2)[0] && (p1)[1] == (p2)[1] && (p1)[2] == (p2)[2])
+
+#define ICV_SET_C3( p, q ) \
+    ((p)[0] = (q)[0], (p)[1] = (q)[1], (p)[2] = (q)[2])
+
 /****************************************************************************************\
-*                             Simple (monochrome) Floodfill                              *
+*              Simple Floodfill (repainting single-color connected component)            *
 \****************************************************************************************/
 
 static CvStatus
-icvFloodFill_8u_C1IR( uchar* pImage, int step, CvSize roi, CvPoint seed,
+icvFloodFill_8u_CnIR( uchar* pImage, int step, CvSize roi, CvPoint seed,
                       uchar* _newVal, CvConnectedComp* region, int flags,
-                      CvFFillSegment* buffer, int buffersize )
+                      CvFFillSegment* buffer, int buffer_size, int cn )
 {
     uchar* img = pImage + step * seed.y;
     int i, L, R; 
     int area = 0;
-    int val0 = 0;
-    uchar newVal = _newVal[0];
+    int val0[] = {0,0,0};
+    uchar newVal[] = {0,0,0};
     int XMin, XMax, YMin = seed.y, YMax = seed.y;
     int _8_connectivity = (flags & 255) == 8;
-    CvFFillSegment* buffer_end = buffer + buffersize, *head = buffer, *tail = buffer;
+    CvFFillSegment* buffer_end = buffer + buffer_size, *head = buffer, *tail = buffer;
 
-    L = R = seed.x;
-    val0 = img[L];
+    L = R = XMin = XMax = seed.x;
 
-    if( val0 == newVal )
+    if( cn == 1 )
     {
-        XMin = XMax = seed.x;
-        goto exit_func;
-    }
-
-    img[L] = newVal;
+        val0[0] = img[L];
+        newVal[0] = _newVal[0];
 
-    while( ++R < roi.width && img[R] == val0 )
-        img[R] = newVal;
-
-    while( --L >= 0 && img[L] == val0 )
-        img[L] = newVal;
-
-    XMax = --R;
-    XMin = ++L;
-    ICV_PUSH( seed.y, L, R, R + 1, R, UP );
+        if( val0[0] == newVal[0] )
+            goto exit_func;
 
-    while( head != tail )
-    {
-        int k, YC, PL, PR, dir, curstep;
-        ICV_POP( YC, L, R, PL, PR, dir );
+        img[L] = newVal[0];
 
-        int data[][3] =
-        {
-            {-dir, L - _8_connectivity, R + _8_connectivity},
-            {dir, L - _8_connectivity, PL - 1},
-            {dir, PR + 1, R + _8_connectivity}
-        };
+        while( ++R < roi.width && img[R] == val0[0] )
+            img[R] = newVal[0];
 
-        if( region )
-        {
-            area += R - L + 1;
-
-            if( XMax < R ) XMax = R;
-            if( XMin > L ) XMin = L;
-            if( YMax < YC ) YMax = YC;
-            if( YMin > YC ) YMin = YC;
-        }
-
-        for( k = (unsigned)(YC - dir) >= (unsigned)roi.height; k < 3; k++ )
-        {
-            dir = data[k][0];
-            curstep = dir * step;
-            img = pImage + (YC + dir) * step;
-            int left = data[k][1];
-            int right = data[k][2];
-
-            for( i = left; i <= right; i++ )
-            {
-                if( (unsigned)i < (unsigned)roi.width && img[i] == val0 )
-                {
-                    int j = i;
-                    img[i] = newVal;
-                    while( --j >= 0 && img[j] == val0 )
-                        img[j] = newVal;
-
-                    while( ++i < roi.width && img[i] == val0 )
-                        img[i] = newVal;
-
-                    ICV_PUSH( YC + dir, j+1, i-1, L, R, -dir );
-                }
-            }
-        }
-    }
-
-exit_func:
-    if( region )
-    {
-        region->area = area;
-        region->rect.x = XMin;
-        region->rect.y = YMin;
-        region->rect.width = XMax - XMin + 1;
-        region->rect.height = YMax - YMin + 1;
-        region->value = newVal;
+        while( --L >= 0 && img[L] == val0[0] )
+            img[L] = newVal[0];
     }
-
-    return CV_NO_ERR;
-}
-
-
-#define ICV_EQ_C3( p1, p2 ) \
-    ((p1)[0] == (p2)[0] && (p1)[1] == (p2)[1] && (p1)[2] == (p2)[2])
-
-#define ICV_SET_C3( p, q ) \
-    ((p)[0] = (q)[0], (p)[1] = (q)[1], (p)[2] = (q)[2])
-
-static CvStatus
-icvFloodFill_8u_C3IR( uchar* pImage, int step, CvSize roi, CvPoint seed,
-                      uchar* _newVal, CvConnectedComp* region, int flags,
-                      CvFFillSegment* buffer, int buffersize )
-{
-    uchar* img = pImage + step * seed.y;
-    int i, L, R; 
-    int area = 0;
-    int val0[3] = { 0, 0, 0 };
-    uchar newVal[3] = { _newVal[0], _newVal[1], _newVal[2] };
-    int XMin, XMax, YMin = seed.y, YMax = seed.y;
-    int _8_connectivity = (flags & 255) == 8;
-    CvFFillSegment* buffer_end = buffer + buffersize, *head = buffer, *tail = buffer;
-
-    L = R = seed.x;
-    ICV_SET_C3( val0, img + L*3 );
-
-    if( ICV_EQ_C3( val0, newVal ))
+    else
     {
-        XMin = XMax = seed.x;
-        goto exit_func;
-    }
+        assert( cn == 3 );
+        ICV_SET_C3( val0, img + L*3 );
+        ICV_SET_C3( newVal, _newVal );
+        
+        if( ICV_EQ_C3( val0, newVal ))
+            goto exit_func;
 
-    ICV_SET_C3( img + L*3, newVal );
-    
-    while( --L >= 0 && ICV_EQ_C3( img + L*3, val0 ))
         ICV_SET_C3( img + L*3, newVal );
     
-    while( ++R < roi.width && ICV_EQ_C3( img + R*3, val0 ))
-        ICV_SET_C3( img + R*3, newVal );
+        while( --L >= 0 && ICV_EQ_C3( img + L*3, val0 ))
+            ICV_SET_C3( img + L*3, newVal );
+    
+        while( ++R < roi.width && ICV_EQ_C3( img + R*3, val0 ))
+            ICV_SET_C3( img + R*3, newVal );
+    }
 
-    XMin = ++L;
     XMax = --R;
+    XMin = ++L;
     ICV_PUSH( seed.y, L, R, R + 1, R, UP );
 
     while( head != tail )
     {
-        int k, YC, PL, PR, dir, curstep;
+        int k, YC, PL, PR, dir;
         ICV_POP( YC, L, R, PL, PR, dir );
 
         int data[][3] =
@@ -249,26 +170,42 @@ icvFloodFill_8u_C3IR( uchar* pImage, int step, CvSize roi, CvPoint seed,
         for( k = (unsigned)(YC - dir) >= (unsigned)roi.height; k < 3; k++ )
         {
             dir = data[k][0];
-            curstep = dir * step;
             img = pImage + (YC + dir) * step;
             int left = data[k][1];
             int right = data[k][2];
 
-            for( i = left; i <= right; i++ )
-            {
-                if( (unsigned)i < (unsigned)roi.width && ICV_EQ_C3( img + i*3, val0 ))
+            if( cn == 1 )
+                for( i = left; i <= right; i++ )
                 {
-                    int j = i;
-                    ICV_SET_C3( img + i*3, newVal );
-                    while( --j >= 0 && ICV_EQ_C3( img + j*3, val0 ))
-                        ICV_SET_C3( img + j*3, newVal );
+                    if( (unsigned)i < (unsigned)roi.width && img[i] == val0[0] )
+                    {
+                        int j = i;
+                        img[i] = newVal[0];
+                        while( --j >= 0 && img[j] == val0[0] )
+                            img[j] = newVal[0];
+
+                        while( ++i < roi.width && img[i] == val0[0] )
+                            img[i] = newVal[0];
 
-                    while( ++i < roi.width && ICV_EQ_C3( img + i*3, val0 ))
+                        ICV_PUSH( YC + dir, j+1, i-1, L, R, -dir );
+                    }
+                }
+            else
+                for( i = left; i <= right; i++ )
+                {
+                    if( (unsigned)i < (unsigned)roi.width && ICV_EQ_C3( img + i*3, val0 ))
+                    {
+                        int j = i;
                         ICV_SET_C3( img + i*3, newVal );
+                        while( --j >= 0 && ICV_EQ_C3( img + j*3, val0 ))
+                            ICV_SET_C3( img + j*3, newVal );
+
+                        while( ++i < roi.width && ICV_EQ_C3( img + i*3, val0 ))
+                            ICV_SET_C3( img + i*3, newVal );
 
-                    ICV_PUSH( YC + dir, j+1, i-1, L, R, -dir );
+                        ICV_PUSH( YC + dir, j+1, i-1, L, R, -dir );
+                    }
                 }
-            }
         }
     }
 
@@ -280,7 +217,7 @@ exit_func:
         region->rect.y = YMin;
         region->rect.width = XMax - XMin + 1;
         region->rect.height = YMax - YMin + 1;
-        region->value = CV_RGB( newVal[2], newVal[1], newVal[0] );
+        region->value = cvScalar(newVal[0], newVal[1], newVal[2], 0);
     }
 
     return CV_NO_ERR;
@@ -291,35 +228,54 @@ exit_func:
    are just copying and comparison on equality,
    we can do the whole op on 32-bit integers instead */
 static CvStatus
-icvFloodFill_32f_C1IR( int* pImage, int step, CvSize roi, CvPoint seed,
+icvFloodFill_32f_CnIR( int* pImage, int step, CvSize roi, CvPoint seed,
                        int* _newVal, CvConnectedComp* region, int flags,
-                       CvFFillSegment* buffer, int buffersize )
+                       CvFFillSegment* buffer, int buffer_size, int cn )
 {
     int* img = pImage + (step /= sizeof(pImage[0])) * seed.y;
     int i, L, R; 
     int area = 0;
-    int val0 = 0;
-    int newVal = _newVal[0];
+    int val0[] = {0,0,0};
+    int newVal[] = {0,0,0};
     int XMin, XMax, YMin = seed.y, YMax = seed.y;
     int _8_connectivity = (flags & 255) == 8;
-    CvFFillSegment* buffer_end = buffer + buffersize, *head = buffer, *tail = buffer;
+    CvFFillSegment* buffer_end = buffer + buffer_size, *head = buffer, *tail = buffer;
 
-    L = R = seed.x;
-    val0 = img[L];
+    L = R = XMin = XMax = seed.x;
 
-    if( val0 == newVal )
+    if( cn == 1 )
     {
-        XMin = XMax = seed.x;
-        goto exit_func;
-    }
+        val0[0] = img[L];
+        newVal[0] = _newVal[0];
+
+        if( val0[0] == newVal[0] )
+            goto exit_func;
 
-    img[L] = newVal;
+        img[L] = newVal[0];
 
-    while( ++R < roi.width && img[R] == val0 )
-        img[R] = newVal;
+        while( ++R < roi.width && img[R] == val0[0] )
+            img[R] = newVal[0];
 
-    while( --L >= 0 && img[L] == val0 )
-        img[L] = newVal;
+        while( --L >= 0 && img[L] == val0[0] )
+            img[L] = newVal[0];
+    }
+    else
+    {
+        assert( cn == 3 );
+        ICV_SET_C3( val0, img + L*3 );
+        ICV_SET_C3( newVal, _newVal );
+        
+        if( ICV_EQ_C3( val0, newVal ))
+            goto exit_func;
+
+        ICV_SET_C3( img + L*3, newVal );
+    
+        while( --L >= 0 && ICV_EQ_C3( img + L*3, val0 ))
+            ICV_SET_C3( img + L*3, newVal );
+    
+        while( ++R < roi.width && ICV_EQ_C3( img + R*3, val0 ))
+            ICV_SET_C3( img + R*3, newVal );
+    }
 
     XMax = --R;
     XMin = ++L;
@@ -327,7 +283,7 @@ icvFloodFill_32f_C1IR( int* pImage, int step, CvSize roi, CvPoint seed,
 
     while( head != tail )
     {
-        int k, YC, PL, PR, dir, curstep;
+        int k, YC, PL, PR, dir;
         ICV_POP( YC, L, R, PL, PR, dir );
 
         int data[][3] =
@@ -350,26 +306,42 @@ icvFloodFill_32f_C1IR( int* pImage, int step, CvSize roi, CvPoint seed,
         for( k = (unsigned)(YC - dir) >= (unsigned)roi.height; k < 3; k++ )
         {
             dir = data[k][0];
-            curstep = dir * step;
             img = pImage + (YC + dir) * step;
             int left = data[k][1];
             int right = data[k][2];
 
-            for( i = left; i <= right; i++ )
-            {
-                if( (unsigned)i < (unsigned)roi.width && img[i] == val0 )
+            if( cn == 1 )
+                for( i = left; i <= right; i++ )
                 {
-                    int j = i;
-                    img[i] = newVal;
-                    while( --j >= 0 && img[j] == val0 )
-                        img[j] = newVal;
+                    if( (unsigned)i < (unsigned)roi.width && img[i] == val0[0] )
+                    {
+                        int j = i;
+                        img[i] = newVal[0];
+                        while( --j >= 0 && img[j] == val0[0] )
+                            img[j] = newVal[0];
 
-                    while( ++i < roi.width && img[i] == val0 )
-                        img[i] = newVal;
+                        while( ++i < roi.width && img[i] == val0[0] )
+                            img[i] = newVal[0];
 
-                    ICV_PUSH( YC + dir, j+1, i-1, L, R, -dir );
+                        ICV_PUSH( YC + dir, j+1, i-1, L, R, -dir );
+                    }
+                }
+            else
+                for( i = left; i <= right; i++ )
+                {
+                    if( (unsigned)i < (unsigned)roi.width && ICV_EQ_C3( img + i*3, val0 ))
+                    {
+                        int j = i;
+                        ICV_SET_C3( img + i*3, newVal );
+                        while( --j >= 0 && ICV_EQ_C3( img + j*3, val0 ))
+                            ICV_SET_C3( img + j*3, newVal );
+
+                        while( ++i < roi.width && ICV_EQ_C3( img + i*3, val0 ))
+                            ICV_SET_C3( img + i*3, newVal );
+
+                        ICV_PUSH( YC + dir, j+1, i-1, L, R, -dir );
+                    }
                 }
-            }
         }
     }
 
@@ -381,7 +353,8 @@ exit_func:
         region->rect.y = YMin;
         region->rect.width = XMax - XMin + 1;
         region->rect.height = YMax - YMin + 1;
-        region->value = newVal;
+        region->value = cvScalar((float&)newVal[0],
+            (float&)newVal[1], (float&)newVal[2], 0);
     }
 
     return CV_NO_ERR;
@@ -391,36 +364,38 @@ exit_func:
 *                                   Gradient Floodfill                                   *
 \****************************************************************************************/
 
-#define DIFF_INT_C1(p1,p2) ((unsigned)((p1)[0] - (p2)[0] + d_lw)<= interval)
+#define DIFF_INT_C1(p1,p2) ((unsigned)((p1)[0] - (p2)[0] + d_lw[0]) <= interval[0])
 
 #define DIFF_INT_C3(p1,p2) ((unsigned)((p1)[0] - (p2)[0] + d_lw[0])<= interval[0] && \
                             (unsigned)((p1)[1] - (p2)[1] + d_lw[1])<= interval[1] && \
                             (unsigned)((p1)[2] - (p2)[2] + d_lw[2])<= interval[2])
 
-#define DIFF_FLT_C1(p1,p2) (fabs((p1)[0] - (p2)[0] + d_lw)<= interval)
+#define DIFF_FLT_C1(p1,p2) (fabs((p1)[0] - (p2)[0] + d_lw[0]) <= interval[0])
+
+#define DIFF_FLT_C3(p1,p2) (fabs((p1)[0] - (p2)[0] + d_lw[0]) <= interval[0] && \
+                            fabs((p1)[1] - (p2)[1] + d_lw[1]) <= interval[1] && \
+                            fabs((p1)[2] - (p2)[2] + d_lw[2]) <= interval[2])
 
 static CvStatus
-icvFloodFill_Grad_8u_C1IR( uchar* pImage, int step, uchar* pMask, int maskStep,
+icvFloodFill_Grad_8u_CnIR( uchar* pImage, int step, uchar* pMask, int maskStep,
                            CvSize /*roi*/, CvPoint seed, uchar* _newVal, uchar* _d_lw,
                            uchar* _d_up, CvConnectedComp* region, int flags,
-                           CvFFillSegment* buffer, int buffersize )
+                           CvFFillSegment* buffer, int buffer_size, int cn )
 {
-    const int cn = 1;
     uchar* img = pImage + step*seed.y;
     uchar* mask = (pMask += maskStep + 1) + maskStep*seed.y;
     int i, L, R;
     int area = 0;
-    int sum = 0, val0[1] = {0};
-    uchar newVal = _newVal[0];
-    int d_lw = _d_lw[0];
-    int d_up = _d_up[0];
-    unsigned interval = (unsigned) (d_up + d_lw);
+    int sum[] = {0,0,0}, val0[] = {0,0,0};
+    uchar newVal[] = {0,0,0};
+    int d_lw[] = {0,0,0};
+    unsigned interval[] = {0,0,0};
     int XMin, XMax, YMin = seed.y, YMax = seed.y;
     int _8_connectivity = (flags & 255) == 8;
     int fixedRange = flags & CV_FLOODFILL_FIXED_RANGE;
     int fillImage = (flags & CV_FLOODFILL_MASK_ONLY) == 0;
     uchar newMaskVal = (uchar)(flags & 0xff00 ? flags >> 8 : 1);
-    CvFFillSegment* buffer_end = buffer + buffersize, *head = buffer, *tail = buffer;
+    CvFFillSegment* buffer_end = buffer + buffer_size, *head = buffer, *tail = buffer;
 
     L = R = seed.x;
     if( mask[L] )
@@ -428,23 +403,52 @@ icvFloodFill_Grad_8u_C1IR( uchar* pImage, int step, uchar* pMask, int maskStep,
 
     mask[L] = newMaskVal;
 
-    if( fixedRange )
+    for( i = 0; i < cn; i++ )
     {
-        val0[0] = img[seed.x];
+        newVal[i] = _newVal[i];
+        d_lw[i] = _d_lw[i];
+        interval[i] = (unsigned)(_d_up[i] + _d_lw[i]);
+        if( fixedRange )
+            val0[i] = img[L*cn+i];
+    }
 
-        while( !mask[R + 1] && DIFF_INT_C1( img + (R+1)*cn, val0 ))
-            mask[++R] = newMaskVal;
+    if( cn == 1 )
+    {
+        if( fixedRange )
+        {
+            while( !mask[R + 1] && DIFF_INT_C1( img + (R+1), val0 ))
+                mask[++R] = newMaskVal;
+
+            while( !mask[L - 1] && DIFF_INT_C1( img + (L-1), val0 ))
+                mask[--L] = newMaskVal;
+        }
+        else
+        {
+            while( !mask[R + 1] && DIFF_INT_C1( img + (R+1), img + R ))
+                mask[++R] = newMaskVal;
 
-        while( !mask[L - 1] && DIFF_INT_C1( img + (L-1)*cn, val0 ))
-            mask[--L] = newMaskVal;
+            while( !mask[L - 1] && DIFF_INT_C1( img + (L-1), img + L ))
+                mask[--L] = newMaskVal;
+        }
     }
     else
     {
-        while( !mask[R + 1] && DIFF_INT_C1( img + (R+1)*cn, img + R*cn ))
-            mask[++R] = newMaskVal;
+        if( fixedRange )
+        {
+            while( !mask[R + 1] && DIFF_INT_C3( img + (R+1)*3, val0 ))
+                mask[++R] = newMaskVal;
+
+            while( !mask[L - 1] && DIFF_INT_C3( img + (L-1)*3, val0 ))
+                mask[--L] = newMaskVal;
+        }
+        else
+        {
+            while( !mask[R + 1] && DIFF_INT_C3( img + (R+1)*3, img + R*3 ))
+                mask[++R] = newMaskVal;
 
-        while( !mask[L - 1] && DIFF_INT_C1( img + (L-1)*cn, img + L*cn ))
-            mask[--L] = newMaskVal;
+            while( !mask[L - 1] && DIFF_INT_C3( img + (L-1)*3, img + L*3 ))
+                mask[--L] = newMaskVal;
+        }
     }
 
     XMax = R;
@@ -475,301 +479,186 @@ icvFloodFill_Grad_8u_C1IR( uchar* pImage, int step, uchar* pMask, int maskStep,
             if( YMin > YC ) YMin = YC;
         }
 
-        for( k = 0; k < 3; k++ )
+        if( cn == 1 )
         {
-            dir = data[k][0];
-            curstep = dir * step;
-            img = pImage + (YC + dir) * step;
-            mask = pMask + (YC + dir) * maskStep;
-            int left = data[k][1];
-            int right = data[k][2];
-
-            if( fixedRange )
+            for( k = 0; k < 3; k++ )
             {
-                for( i = left; i <= right; i++ )
-                {
-                    if( !mask[i] && DIFF_INT_C1( img + i*cn, val0 ))
+                dir = data[k][0];
+                curstep = dir * step;
+                img = pImage + (YC + dir) * step;
+                mask = pMask + (YC + dir) * maskStep;
+                int left = data[k][1];
+                int right = data[k][2];
+
+                if( fixedRange )
+                    for( i = left; i <= right; i++ )
                     {
-                        int j = i;
-                        mask[i] = newMaskVal;
-                        while( !mask[--j] && DIFF_INT_C1( img + j*cn, val0 ))
-                            mask[j] = newMaskVal;
-
-                        while( !mask[++i] && DIFF_INT_C1( img + i*cn, val0 ))
+                        if( !mask[i] && DIFF_INT_C1( img + i, val0 ))
+                        {
+                            int j = i;
                             mask[i] = newMaskVal;
+                            while( !mask[--j] && DIFF_INT_C1( img + j, val0 ))
+                                mask[j] = newMaskVal;
 
-                        ICV_PUSH( YC + dir, j+1, i-1, L, R, -dir );
+                            while( !mask[++i] && DIFF_INT_C1( img + i, val0 ))
+                                mask[i] = newMaskVal;
+
+                            ICV_PUSH( YC + dir, j+1, i-1, L, R, -dir );
+                        }
                     }
-                }
-            }
-            else if( !_8_connectivity )
-            {
-                for( i = left; i <= right; i++ )
-                {
-                    if( !mask[i] && DIFF_INT_C1( img + i*cn, img - curstep + i*cn ))
+                else if( !_8_connectivity )
+                    for( i = left; i <= right; i++ )
                     {
-                        int j = i;
-                        mask[i] = newMaskVal;
-                        while( !mask[--j] && DIFF_INT_C1( img + j*cn, img + (j+1)*cn ))
-                            mask[j] = newMaskVal;
-
-                        while( !mask[++i] &&
-                               (DIFF_INT_C1( img + i*cn, img + (i-1)*cn ) ||
-                               (DIFF_INT_C1( img + i*cn, img + i*cn - curstep) && i <= R)))
+                        if( !mask[i] && DIFF_INT_C1( img + i, img - curstep + i ))
+                        {
+                            int j = i;
                             mask[i] = newMaskVal;
+                            while( !mask[--j] && DIFF_INT_C1( img + j, img + (j+1) ))
+                                mask[j] = newMaskVal;
 
-                        ICV_PUSH( YC + dir, j+1, i-1, L, R, -dir );
+                            while( !mask[++i] &&
+                                   (DIFF_INT_C1( img + i, img + (i-1) ) ||
+                                   (DIFF_INT_C1( img + i, img + i - curstep) && i <= R)))
+                                mask[i] = newMaskVal;
+
+                            ICV_PUSH( YC + dir, j+1, i-1, L, R, -dir );
+                        }
                     }
-                }
-            }
-            else
-            {
-                for( i = left; i <= right; i++ )
-                {
-                    int idx, val[1];
-                    
-                    if( !mask[i] &&
-                        ((val[0] = img[i*cn],
-                        (unsigned)(idx = i-L-1) <= length) &&
-                        DIFF_INT_C1( val, img - curstep + (i-1)*cn ) ||
-                        (unsigned)(++idx) <= length &&
-                        DIFF_INT_C1( val, img - curstep + i*cn ) ||
-                        (unsigned)(++idx) <= length &&
-                        DIFF_INT_C1( val, img - curstep + (i+1)*cn )))
+                else
+                    for( i = left; i <= right; i++ )
                     {
-                        int j = i;
-                        mask[i] = newMaskVal;
-                        while( !mask[--j] && DIFF_INT_C1( img + j*cn, img + (j+1)*cn ))
-                            mask[j] = newMaskVal;
-
-                        while( !mask[++i] &&
-                               ((val[0] = img[i*cn],
-                               DIFF_INT_C1( val, img + (i-1)*cn )) ||
-                               ((unsigned)(idx = i-L-1) <= length &&
-                               DIFF_INT_C1( val, img - curstep + (i-1)*cn )) ||
-                               (unsigned)(++idx) <= length &&
-                               DIFF_INT_C1( val, img - curstep + i*cn ) ||
-                               (unsigned)(++idx) <= length &&
-                               DIFF_INT_C1( val, img - curstep + (i+1)*cn )))
+                        int idx, val[1];
+                
+                        if( !mask[i] &&
+                            ((val[0] = img[i],
+                            (unsigned)(idx = i-L-1) <= length) &&
+                            DIFF_INT_C1( val, img - curstep + (i-1) ) ||
+                            (unsigned)(++idx) <= length &&
+                            DIFF_INT_C1( val, img - curstep + i ) ||
+                            (unsigned)(++idx) <= length &&
+                            DIFF_INT_C1( val, img - curstep + (i+1) )))
+                        {
+                            int j = i;
                             mask[i] = newMaskVal;
-
-                        ICV_PUSH( YC + dir, j+1, i-1, L, R, -dir );
+                            while( !mask[--j] && DIFF_INT_C1( img + j, img + (j+1) ))
+                                mask[j] = newMaskVal;
+
+                            while( !mask[++i] &&
+                                   ((val[0] = img[i],
+                                   DIFF_INT_C1( val, img + (i-1) )) ||
+                                   ((unsigned)(idx = i-L-1) <= length &&
+                                   DIFF_INT_C1( val, img - curstep + (i-1) )) ||
+                                   (unsigned)(++idx) <= length &&
+                                   DIFF_INT_C1( val, img - curstep + i ) ||
+                                   (unsigned)(++idx) <= length &&
+                                   DIFF_INT_C1( val, img - curstep + (i+1) )))
+                                mask[i] = newMaskVal;
+
+                            ICV_PUSH( YC + dir, j+1, i-1, L, R, -dir );
+                        }
                     }
-                }
             }
-        }
 
-        img = pImage + YC * step;
-        if( fillImage )
-            for( i = L; i <= R; i++ )
-                img[i] = newVal;
-        else if( region )
-            for( i = L; i <= R; i++ )
-                sum += img[i];
-    }
-    
-    if( region )
-    {
-        region->area = area;
-        region->rect.x = XMin;
-        region->rect.y = YMin;
-        region->rect.width = XMax - XMin + 1;
-        region->rect.height = YMax - YMin + 1;
-    
-        if( fillImage )
-            region->value = newVal;
-        else
-            region->value = area ? ((double)sum)/area : 0;
-    }
-
-    return CV_NO_ERR;
-}
-
-
-static CvStatus
-icvFloodFill_Grad_8u_C3IR( uchar* pImage, int step, uchar* pMask, int maskStep,
-                           CvSize /*roi*/, CvPoint seed, uchar* _newVal, uchar* _d_lw,
-                           uchar* _d_up, CvConnectedComp* region, int flags,
-                           CvFFillSegment* buffer, int buffersize )
-{
-    const int cn = 3;
-    uchar* img = pImage + step*seed.y;
-    uchar* mask = (pMask += maskStep + 1) + maskStep*seed.y;
-    int i, L, R;
-    int area = 0;
-    int sum[3] = { 0, 0, 0 }, val0[3] = { 0, 0, 0 };
-    uchar newVal[3] = {_newVal[0], _newVal[1], _newVal[2]};
-    int d_lw[3] = {_d_lw[0], _d_lw[1], _d_lw[2]};
-    int d_up[3] = {_d_up[0], _d_up[1], _d_up[2]};
-    unsigned interval[3] =
-    { (unsigned) (d_up[0] + d_lw[0]),
-      (unsigned) (d_up[1] + d_lw[1]),
-      (unsigned) (d_up[2] + d_lw[2])};
-    int XMin, XMax, YMin = seed.y, YMax = seed.y;
-    int _8_connectivity = (flags & 255) == 8;
-    int fixedRange = flags & CV_FLOODFILL_FIXED_RANGE;
-    int fillImage = (flags & CV_FLOODFILL_MASK_ONLY) == 0;
-    uchar newMaskVal = (uchar)(flags & 0xff00 ? flags >> 8 : 1);
-    CvFFillSegment* buffer_end = buffer + buffersize, *head = buffer, *tail = buffer;
-
-    L = R = seed.x;
-    if( mask[L] )
-        return CV_OK;
-
-    mask[L] = newMaskVal;
-
-    if( fixedRange )
-    {
-        val0[0] = img[seed.x*cn];
-        val0[1] = img[seed.x*cn+1];
-        val0[2] = img[seed.x*cn+2];
-
-        while( DIFF_INT_C3( img + (R+1)*cn, val0 ) && !mask[R + 1] )
-            mask[++R] = newMaskVal;
-
-        while( DIFF_INT_C3( img + (L-1)*cn, val0 ) && !mask[L - 1] )
-            mask[--L] = newMaskVal;
-    }
-    else
-    {
-        while( DIFF_INT_C3( img + (R+1)*cn, img + R*cn ) && !mask[R + 1] )
-            mask[++R] = newMaskVal;
-
-        while( DIFF_INT_C3( img + (L-1)*cn, img + L*cn ) && !mask[L - 1] )
-            mask[--L] = newMaskVal;
-    }
-
-    XMax = R;
-    XMin = L;
-    ICV_PUSH( seed.y, L, R, R + 1, R, UP );
-
-    while( head != tail )
-    {
-        int k, YC, PL, PR, dir, curstep;
-        ICV_POP( YC, L, R, PL, PR, dir );
-
-        int data[][3] =
-        {
-            {-dir, L - _8_connectivity, R + _8_connectivity},
-            {dir, L - _8_connectivity, PL - 1},
-            {dir, PR + 1, R + _8_connectivity}
-        };
-
-        unsigned length = (unsigned)(R-L);
-
-        if( region )
-        {
-            area += (int)length + 1;
-
-            if( XMax < R ) XMax = R;
-            if( XMin > L ) XMin = L;
-            if( YMax < YC ) YMax = YC;
-            if( YMin > YC ) YMin = YC;
+            img = pImage + YC * step;
+            if( fillImage )
+                for( i = L; i <= R; i++ )
+                    img[i] = newVal[0];
+            else if( region )
+                for( i = L; i <= R; i++ )
+                    sum[0] += img[i];
         }
-
-        for( k = 0; k < 3; k++ )
+        else
         {
-            dir = data[k][0];
-            curstep = dir * step;
-            img = pImage + (YC + dir) * step;
-            mask = pMask + (YC + dir) * maskStep;
-            int left = data[k][1];
-            int right = data[k][2];
-
-            if( fixedRange )
+            for( k = 0; k < 3; k++ )
             {
-                for( i = left; i <= right; i++ )
-                {
-                    if( !mask[i] && DIFF_INT_C3( img + i*cn, val0 ))
+                dir = data[k][0];
+                curstep = dir * step;
+                img = pImage + (YC + dir) * step;
+                mask = pMask + (YC + dir) * maskStep;
+                int left = data[k][1];
+                int right = data[k][2];
+
+                if( fixedRange )
+                    for( i = left; i <= right; i++ )
                     {
-                        int j = i;
-                        mask[i] = newMaskVal;
-                        while( !mask[--j] && DIFF_INT_C3( img + j*cn, val0 ))
-                            mask[j] = newMaskVal;
-
-                        while( !mask[++i] && DIFF_INT_C3( img + i*cn, val0 ))
+                        if( !mask[i] && DIFF_INT_C3( img + i*3, val0 ))
+                        {
+                            int j = i;
                             mask[i] = newMaskVal;
+                            while( !mask[--j] && DIFF_INT_C3( img + j*3, val0 ))
+                                mask[j] = newMaskVal;
 
-                        ICV_PUSH( YC + dir, j+1, i-1, L, R, -dir );
+                            while( !mask[++i] && DIFF_INT_C3( img + i*3, val0 ))
+                                mask[i] = newMaskVal;
+
+                            ICV_PUSH( YC + dir, j+1, i-1, L, R, -dir );
+                        }
                     }
-                }
-            }
-            else if( !_8_connectivity )
-            {
-                for( i = left; i <= right; i++ )
-                {
-                    if( !mask[i] && DIFF_INT_C3( img + i*cn, img - curstep + i*cn ))
+                else if( !_8_connectivity )
+                    for( i = left; i <= right; i++ )
                     {
-                        int j = i;
-                        mask[i] = newMaskVal;
-                        while( !mask[--j] && DIFF_INT_C3( img + j*cn, img + (j+1)*cn ))
-                            mask[j] = newMaskVal;
-
-                        while( !mask[++i] &&
-                               (DIFF_INT_C3( img + i*cn, img + (i-1)*cn ) ||
-                               (DIFF_INT_C3( img + i*cn, img + i*cn - curstep) && i <= R)))
+                        if( !mask[i] && DIFF_INT_C3( img + i*3, img - curstep + i*3 ))
+                        {
+                            int j = i;
                             mask[i] = newMaskVal;
+                            while( !mask[--j] && DIFF_INT_C3( img + j*3, img + (j+1)*3 ))
+                                mask[j] = newMaskVal;
 
-                        ICV_PUSH( YC + dir, j+1, i-1, L, R, -dir );
+                            while( !mask[++i] &&
+                                   (DIFF_INT_C3( img + i*3, img + (i-1)*3 ) ||
+                                   (DIFF_INT_C3( img + i*3, img + i*3 - curstep) && i <= R)))
+                                mask[i] = newMaskVal;
+
+                            ICV_PUSH( YC + dir, j+1, i-1, L, R, -dir );
+                        }
                     }
-                }
-            }
-            else
-            {
-                for( i = left; i <= right; i++ )
-                {
-                    int idx, val[3];
-                    
-                    if( !mask[i] &&
-                        ((val[0] = img[i*cn],
-                          val[1] = img[i*cn+1],
-                          val[2] = img[i*cn+2],
-                        (unsigned)(idx = i-L-1) <= length) &&
-                        DIFF_INT_C3( val, img - curstep + (i-1)*cn ) ||
-                        (unsigned)(++idx) <= length &&
-                        DIFF_INT_C3( val, img - curstep + i*cn ) ||
-                        (unsigned)(++idx) <= length &&
-                        DIFF_INT_C3( val, img - curstep + (i+1)*cn )))
+                else
+                    for( i = left; i <= right; i++ )
                     {
-                        int j = i;
-                        mask[i] = newMaskVal;
-                        while( !mask[--j] && DIFF_INT_C3( img + j*cn, img + (j+1)*cn ))
-                            mask[j] = newMaskVal;
-
-                        while( !mask[++i] &&
-                               ((val[0] = img[i*cn],
-                                 val[1] = img[i*cn+1],
-                                 val[2] = img[i*cn+2],
-                               DIFF_INT_C3( &val, img + (i-1)*cn )) ||
-                               ((unsigned)(idx = i-L-1) <= length &&
-                               DIFF_INT_C3( &val, img - curstep + (i-1)*cn )) ||
-                               (unsigned)(++idx) <= length &&
-                               DIFF_INT_C3( &val, img - curstep + i*cn ) ||
-                               (unsigned)(++idx) <= length &&
-                               DIFF_INT_C3( &val, img - curstep + (i+1)*cn )))
+                        int idx, val[3];
+                
+                        if( !mask[i] &&
+                            ((ICV_SET_C3( val, img+i*3 ),
+                            (unsigned)(idx = i-L-1) <= length) &&
+                            DIFF_INT_C3( val, img - curstep + (i-1)*3 ) ||
+                            (unsigned)(++idx) <= length &&
+                            DIFF_INT_C3( val, img - curstep + i*3 ) ||
+                            (unsigned)(++idx) <= length &&
+                            DIFF_INT_C3( val, img - curstep + (i+1)*3 )))
+                        {
+                            int j = i;
                             mask[i] = newMaskVal;
-
-                        ICV_PUSH( YC + dir, j+1, i-1, L, R, -dir );
+                            while( !mask[--j] && DIFF_INT_C3( img + j*3, img + (j+1)*3 ))
+                                mask[j] = newMaskVal;
+
+                            while( !mask[++i] &&
+                                   ((ICV_SET_C3( val, img + i*3 ),
+                                   DIFF_INT_C3( val, img + (i-1)*3 )) ||
+                                   ((unsigned)(idx = i-L-1) <= length &&
+                                   DIFF_INT_C3( val, img - curstep + (i-1)*3 )) ||
+                                   (unsigned)(++idx) <= length &&
+                                   DIFF_INT_C3( val, img - curstep + i*3 ) ||
+                                   (unsigned)(++idx) <= length &&
+                                   DIFF_INT_C3( val, img - curstep + (i+1)*3 )))
+                                mask[i] = newMaskVal;
+
+                            ICV_PUSH( YC + dir, j+1, i-1, L, R, -dir );
+                        }
                     }
-                }
             }
-        }
 
-        img = pImage + YC * step;
-        if( fillImage )
-            for( i = L; i <= R; i++ )
-            {
-                img[i*3] = newVal[0];
-                img[i*3+1] = newVal[1];
-                img[i*3+2] = newVal[2];
-            }
-        else if( region )
-            for( i = L; i <= R; i++ )
-            {
-                sum[0] += img[i*3];
-                sum[1] += img[i*3+1];
-                sum[2] += img[i*3+2];
-            }
+            img = pImage + YC * step;
+            if( fillImage )
+                for( i = L; i <= R; i++ )
+                    ICV_SET_C3( img + i*3, newVal );
+            else if( region )
+                for( i = L; i <= R; i++ )
+                {
+                    sum[0] += img[i*3];
+                    sum[1] += img[i*3+1];
+                    sum[2] += img[i*3+2];
+                }
+        }
     }
     
     if( region )
@@ -781,21 +670,11 @@ icvFloodFill_Grad_8u_C3IR( uchar* pImage, int step, uchar* pMask, int maskStep,
         region->rect.height = YMax - YMin + 1;
     
         if( fillImage )
-            region->value = CV_RGB(newVal[2],newVal[1],newVal[0]);
+            region->value = cvScalar(newVal[0], newVal[1], newVal[2]);
         else
         {
-            region->value = 0;
-            if( area )
-            {
-                double inv_area = 1./area;
-                int b = cvRound(sum[0]*inv_area);
-                int g = cvRound(sum[1]*inv_area);
-                int r = cvRound(sum[2]*inv_area);
-                b = CV_CAST_8U(b);
-                g = CV_CAST_8U(g);
-                r = CV_CAST_8U(r);
-                region->value = CV_RGB( r, g, b );
-            }
+            double iarea = area ? 1./area : 0;
+            region->value = cvScalar(sum[0]*iarea, sum[1]*iarea, sum[2]*iarea);
         }
     }
 
@@ -804,27 +683,25 @@ icvFloodFill_Grad_8u_C3IR( uchar* pImage, int step, uchar* pMask, int maskStep,
 
 
 static CvStatus
-icvFloodFill_Grad_32f_C1IR( float* pImage, int step, uchar* pMask, int maskStep,
-                            CvSize /*roiSize*/, CvPoint seed, float* _newVal, float* _d_lw,
-                            float* _d_up, CvConnectedComp* region, int flags,
-                            CvFFillSegment* buffer, int buffersize )
+icvFloodFill_Grad_32f_CnIR( float* pImage, int step, uchar* pMask, int maskStep,
+                           CvSize /*roi*/, CvPoint seed, float* _newVal, float* _d_lw,
+                           float* _d_up, CvConnectedComp* region, int flags,
+                           CvFFillSegment* buffer, int buffer_size, int cn )
 {
-    const int cn = 1;
-    float* img = pImage + (step /= sizeof(pImage[0]))*seed.y;
+    float* img = pImage + (step /= sizeof(float))*seed.y;
     uchar* mask = (pMask += maskStep + 1) + maskStep*seed.y;
     int i, L, R;
     int area = 0;
-    double sum = 0;
-    float val0[1] = {0};
-    float newVal = _newVal[0];
-    float interval = 0.5f*(_d_lw[0] + _d_up[0]);
-    float d_lw = 0.5f*(_d_lw[0] - _d_up[0]);
+    double sum[] = {0,0,0}, val0[] = {0,0,0};
+    float newVal[] = {0,0,0};
+    float d_lw[] = {0,0,0};
+    float interval[] = {0,0,0};
     int XMin, XMax, YMin = seed.y, YMax = seed.y;
     int _8_connectivity = (flags & 255) == 8;
     int fixedRange = flags & CV_FLOODFILL_FIXED_RANGE;
     int fillImage = (flags & CV_FLOODFILL_MASK_ONLY) == 0;
     uchar newMaskVal = (uchar)(flags & 0xff00 ? flags >> 8 : 1);
-    CvFFillSegment* buffer_end = buffer + buffersize, *head = buffer, *tail = buffer;
+    CvFFillSegment* buffer_end = buffer + buffer_size, *head = buffer, *tail = buffer;
 
     L = R = seed.x;
     if( mask[L] )
@@ -832,23 +709,52 @@ icvFloodFill_Grad_32f_C1IR( float* pImage, int step, uchar* pMask, int maskStep,
 
     mask[L] = newMaskVal;
 
-    if( fixedRange )
+    for( i = 0; i < cn; i++ )
     {
-        val0[0] = img[seed.x];
+        newVal[i] = _newVal[i];
+        d_lw[i] = 0.5f*(_d_lw[i] - _d_up[i]);
+        interval[i] = 0.5f*(_d_lw[i] + _d_up[i]);
+        if( fixedRange )
+            val0[i] = img[L*cn+i];
+    }
+
+    if( cn == 1 )
+    {
+        if( fixedRange )
+        {
+            while( !mask[R + 1] && DIFF_FLT_C1( img + (R+1), val0 ))
+                mask[++R] = newMaskVal;
 
-        while( DIFF_FLT_C1( img + (R+1)*cn, val0 ) && !mask[R + 1] )
-            mask[++R] = newMaskVal;
+            while( !mask[L - 1] && DIFF_FLT_C1( img + (L-1), val0 ))
+                mask[--L] = newMaskVal;
+        }
+        else
+        {
+            while( !mask[R + 1] && DIFF_FLT_C1( img + (R+1), img + R ))
+                mask[++R] = newMaskVal;
 
-        while( DIFF_FLT_C1( img + (L-1)*cn, val0 ) && !mask[L - 1] )
-            mask[--L] = newMaskVal;
+            while( !mask[L - 1] && DIFF_FLT_C1( img + (L-1), img + L ))
+                mask[--L] = newMaskVal;
+        }
     }
     else
     {
-        while( DIFF_FLT_C1( img + (R+1)*cn, img + R*cn ) && !mask[R + 1] )
-            mask[++R] = newMaskVal;
+        if( fixedRange )
+        {
+            while( !mask[R + 1] && DIFF_FLT_C3( img + (R+1)*3, val0 ))
+                mask[++R] = newMaskVal;
 
-        while( DIFF_FLT_C1( img + (L-1)*cn, img + L*cn ) && !mask[L - 1] )
-            mask[--L] = newMaskVal;
+            while( !mask[L - 1] && DIFF_FLT_C3( img + (L-1)*3, val0 ))
+                mask[--L] = newMaskVal;
+        }
+        else
+        {
+            while( !mask[R + 1] && DIFF_FLT_C3( img + (R+1)*3, img + R*3 ))
+                mask[++R] = newMaskVal;
+
+            while( !mask[L - 1] && DIFF_FLT_C3( img + (L-1)*3, img + L*3 ))
+                mask[--L] = newMaskVal;
+        }
     }
 
     XMax = R;
@@ -879,98 +785,188 @@ icvFloodFill_Grad_32f_C1IR( float* pImage, int step, uchar* pMask, int maskStep,
             if( YMin > YC ) YMin = YC;
         }
 
-        for( k = 0; k < 3; k++ )
+        if( cn == 1 )
         {
-            dir = data[k][0];
-            curstep = dir * step;
-            img = pImage + (YC + dir) * step;
-            mask = pMask + (YC + dir) * maskStep;
-            int left = data[k][1];
-            int right = data[k][2];
-
-            if( fixedRange )
+            for( k = 0; k < 3; k++ )
             {
-                for( i = left; i <= right; i++ )
-                {
-                    if( !mask[i] && DIFF_FLT_C1( img + i*cn, val0 ))
+                dir = data[k][0];
+                curstep = dir * step;
+                img = pImage + (YC + dir) * step;
+                mask = pMask + (YC + dir) * maskStep;
+                int left = data[k][1];
+                int right = data[k][2];
+
+                if( fixedRange )
+                    for( i = left; i <= right; i++ )
                     {
-                        int j = i;
-                        mask[i] = newMaskVal;
-                        while( !mask[--j] && DIFF_FLT_C1( img + j*cn, val0 ))
-                            mask[j] = newMaskVal;
+                        if( !mask[i] && DIFF_FLT_C1( img + i, val0 ))
+                        {
+                            int j = i;
+                            mask[i] = newMaskVal;
+                            while( !mask[--j] && DIFF_FLT_C1( img + j, val0 ))
+                                mask[j] = newMaskVal;
 
-                        while( !mask[++i] && DIFF_FLT_C1( img + i*cn, val0 ))
+                            while( !mask[++i] && DIFF_FLT_C1( img + i, val0 ))
+                                mask[i] = newMaskVal;
+
+                            ICV_PUSH( YC + dir, j+1, i-1, L, R, -dir );
+                        }
+                    }
+                else if( !_8_connectivity )
+                    for( i = left; i <= right; i++ )
+                    {
+                        if( !mask[i] && DIFF_FLT_C1( img + i, img - curstep + i ))
+                        {
+                            int j = i;
                             mask[i] = newMaskVal;
+                            while( !mask[--j] && DIFF_FLT_C1( img + j, img + (j+1) ))
+                                mask[j] = newMaskVal;
 
-                        ICV_PUSH( YC + dir, j+1, i-1, L, R, -dir );
+                            while( !mask[++i] &&
+                                   (DIFF_FLT_C1( img + i, img + (i-1) ) ||
+                                   (DIFF_FLT_C1( img + i, img + i - curstep) && i <= R)))
+                                mask[i] = newMaskVal;
+
+                            ICV_PUSH( YC + dir, j+1, i-1, L, R, -dir );
+                        }
+                    }
+                else
+                    for( i = left; i <= right; i++ )
+                    {
+                        int idx;
+                        float val[1];
+                
+                        if( !mask[i] &&
+                            ((val[0] = img[i],
+                            (unsigned)(idx = i-L-1) <= length) &&
+                            DIFF_FLT_C1( val, img - curstep + (i-1) ) ||
+                            (unsigned)(++idx) <= length &&
+                            DIFF_FLT_C1( val, img - curstep + i ) ||
+                            (unsigned)(++idx) <= length &&
+                            DIFF_FLT_C1( val, img - curstep + (i+1) )))
+                        {
+                            int j = i;
+                            mask[i] = newMaskVal;
+                            while( !mask[--j] && DIFF_FLT_C1( img + j, img + (j+1) ))
+                                mask[j] = newMaskVal;
+
+                            while( !mask[++i] &&
+                                   ((val[0] = img[i],
+                                   DIFF_FLT_C1( val, img + (i-1) )) ||
+                                   ((unsigned)(idx = i-L-1) <= length &&
+                                   DIFF_FLT_C1( val, img - curstep + (i-1) )) ||
+                                   (unsigned)(++idx) <= length &&
+                                   DIFF_FLT_C1( val, img - curstep + i ) ||
+                                   (unsigned)(++idx) <= length &&
+                                   DIFF_FLT_C1( val, img - curstep + (i+1) )))
+                                mask[i] = newMaskVal;
+
+                            ICV_PUSH( YC + dir, j+1, i-1, L, R, -dir );
+                        }
                     }
-                }
             }
-            else if( !_8_connectivity )
+
+            img = pImage + YC * step;
+            if( fillImage )
+                for( i = L; i <= R; i++ )
+                    img[i] = newVal[0];
+            else if( region )
+                for( i = L; i <= R; i++ )
+                    sum[0] += img[i];
+        }
+        else
+        {
+            for( k = 0; k < 3; k++ )
             {
-                for( i = left; i <= right; i++ )
-                {
-                    if( !mask[i] && DIFF_FLT_C1( img + i*cn, img - curstep + i*cn ))
+                dir = data[k][0];
+                curstep = dir * step;
+                img = pImage + (YC + dir) * step;
+                mask = pMask + (YC + dir) * maskStep;
+                int left = data[k][1];
+                int right = data[k][2];
+
+                if( fixedRange )
+                    for( i = left; i <= right; i++ )
                     {
-                        int j = i;
-                        mask[i] = newMaskVal;
-                        while( !mask[--j] && DIFF_FLT_C1( img + j*cn, img + (j+1)*cn ))
-                            mask[j] = newMaskVal;
-
-                        while( !mask[++i] &&
-                               (DIFF_FLT_C1( img + i*cn, img + (i-1)*cn ) ||
-                               (DIFF_FLT_C1( img + i*cn, img + i*cn - curstep) && i <= R)))
+                        if( !mask[i] && DIFF_FLT_C3( img + i*3, val0 ))
+                        {
+                            int j = i;
                             mask[i] = newMaskVal;
+                            while( !mask[--j] && DIFF_FLT_C3( img + j*3, val0 ))
+                                mask[j] = newMaskVal;
 
-                        ICV_PUSH( YC + dir, j+1, i-1, L, R, -dir );
+                            while( !mask[++i] && DIFF_FLT_C3( img + i*3, val0 ))
+                                mask[i] = newMaskVal;
+
+                            ICV_PUSH( YC + dir, j+1, i-1, L, R, -dir );
+                        }
                     }
-                }
-            }
-            else
-            {
-                for( i = left; i <= right; i++ )
-                {
-                    int idx;
-                    float val[1];
-                    
-                    if( !mask[i] &&
-                        ((val[0] = img[i*cn],
-                        (unsigned)(idx = i-L-1) <= length) &&
-                        DIFF_FLT_C1( val, img - curstep + (i-1)*cn ) ||
-                        (unsigned)(++idx) <= length &&
-                        DIFF_FLT_C1( val, img - curstep + i*cn ) ||
-                        (unsigned)(++idx) <= length &&
-                        DIFF_FLT_C1( val, img - curstep + (i+1)*cn )))
+                else if( !_8_connectivity )
+                    for( i = left; i <= right; i++ )
                     {
-                        int j = i;
-                        mask[i] = newMaskVal;
-                        while( !mask[--j] && DIFF_FLT_C1( img + j*cn, img + (j+1)*cn ))
-                            mask[j] = newMaskVal;
-
-                        while( !mask[++i] &&
-                               ((val[0] = img[i*cn],
-                               DIFF_FLT_C1( val, img + (i-1)*cn )) ||
-                               ((unsigned)(idx = i-L-1) <= length &&
-                               DIFF_FLT_C1( val, img - curstep + (i-1)*cn )) ||
-                               (unsigned)(++idx) <= length &&
-                               DIFF_FLT_C1( val, img - curstep + i*cn ) ||
-                               (unsigned)(++idx) <= length &&
-                               DIFF_FLT_C1( val, img - curstep + (i+1)*cn )))
+                        if( !mask[i] && DIFF_FLT_C3( img + i*3, img - curstep + i*3 ))
+                        {
+                            int j = i;
                             mask[i] = newMaskVal;
+                            while( !mask[--j] && DIFF_FLT_C3( img + j*3, img + (j+1)*3 ))
+                                mask[j] = newMaskVal;
 
-                        ICV_PUSH( YC + dir, j+1, i-1, L, R, -dir );
+                            while( !mask[++i] &&
+                                   (DIFF_FLT_C3( img + i*3, img + (i-1)*3 ) ||
+                                   (DIFF_FLT_C3( img + i*3, img + i*3 - curstep) && i <= R)))
+                                mask[i] = newMaskVal;
+
+                            ICV_PUSH( YC + dir, j+1, i-1, L, R, -dir );
+                        }
+                    }
+                else
+                    for( i = left; i <= right; i++ )
+                    {
+                        int idx;
+                        float val[3];
+                
+                        if( !mask[i] &&
+                            ((ICV_SET_C3( val, img+i*3 ),
+                            (unsigned)(idx = i-L-1) <= length) &&
+                            DIFF_FLT_C3( val, img - curstep + (i-1)*3 ) ||
+                            (unsigned)(++idx) <= length &&
+                            DIFF_FLT_C3( val, img - curstep + i*3 ) ||
+                            (unsigned)(++idx) <= length &&
+                            DIFF_FLT_C3( val, img - curstep + (i+1)*3 )))
+                        {
+                            int j = i;
+                            mask[i] = newMaskVal;
+                            while( !mask[--j] && DIFF_FLT_C3( img + j*3, img + (j+1)*3 ))
+                                mask[j] = newMaskVal;
+
+                            while( !mask[++i] &&
+                                   ((ICV_SET_C3( val, img + i*3 ),
+                                   DIFF_FLT_C3( val, img + (i-1)*3 )) ||
+                                   ((unsigned)(idx = i-L-1) <= length &&
+                                   DIFF_FLT_C3( val, img - curstep + (i-1)*3 )) ||
+                                   (unsigned)(++idx) <= length &&
+                                   DIFF_FLT_C3( val, img - curstep + i*3 ) ||
+                                   (unsigned)(++idx) <= length &&
+                                   DIFF_FLT_C3( val, img - curstep + (i+1)*3 )))
+                                mask[i] = newMaskVal;
+
+                            ICV_PUSH( YC + dir, j+1, i-1, L, R, -dir );
+                        }
                     }
-                }
             }
-        }
 
-        img = pImage + YC * step;
-        if( fillImage )
-            for( i = L; i <= R; i++ )
-                img[i] = newVal;
-        else if( region )
-            for( i = L; i <= R; i++ )
-                sum += img[i];
+            img = pImage + YC * step;
+            if( fillImage )
+                for( i = L; i <= R; i++ )
+                    ICV_SET_C3( img + i*3, newVal );
+            else if( region )
+                for( i = L; i <= R; i++ )
+                {
+                    sum[0] += img[i*3];
+                    sum[1] += img[i*3+1];
+                    sum[2] += img[i*3+2];
+                }
+        }
     }
     
     if( region )
@@ -982,9 +978,12 @@ icvFloodFill_Grad_32f_C1IR( float* pImage, int step, uchar* pMask, int maskStep,
         region->rect.height = YMax - YMin + 1;
     
         if( fillImage )
-            region->value = newVal;
+            region->value = cvScalar(newVal[0], newVal[1], newVal[2]);
         else
-            region->value = area ? ((double)sum)/area : 0;
+        {
+            double iarea = area ? 1./area : 0;
+            region->value = cvScalar(sum[0]*iarea, sum[1]*iarea, sum[2]*iarea);
+        }
     }
 
     return CV_NO_ERR;
@@ -996,35 +995,32 @@ icvFloodFill_Grad_32f_C1IR( float* pImage, int step, uchar* pMask, int maskStep,
 \****************************************************************************************/
 
 typedef  CvStatus (CV_CDECL* CvFloodFillFunc)(
-                           void* img, int step, CvSize size, CvPoint seed,
-                           void* newval, CvConnectedComp* comp, int flags,
-                           void* buffer, int buffersize );
+               void* img, int step, CvSize size, CvPoint seed, void* newval,
+               CvConnectedComp* comp, int flags, void* buffer, int buffer_size, int cn );
 
 typedef  CvStatus (CV_CDECL* CvFloodFillGradFunc)(
-                           void* img, int step, uchar* mask, int maskStep, CvSize size,
-                           CvPoint seed, void* newval, void* d_lw, void* d_up,
-                           void* ccomp, int flags, void* buffer, int buffersize );
+               void* img, int step, uchar* mask, int maskStep, CvSize size,
+               CvPoint seed, void* newval, void* d_lw, void* d_up, void* ccomp,
+               int flags, void* buffer, int buffer_size, int cn );
 
 static  void  icvInitFloodFill( void** ffill_tab,
                                 void** ffillgrad_tab )
 {
-    ffill_tab[0] = (void*)icvFloodFill_8u_C1IR;
-    ffill_tab[1] = (void*)icvFloodFill_8u_C3IR;
-    ffill_tab[2] = (void*)icvFloodFill_32f_C1IR;
+    ffill_tab[0] = (void*)icvFloodFill_8u_CnIR;
+    ffill_tab[1] = (void*)icvFloodFill_32f_CnIR;
 
-    ffillgrad_tab[0] = (void*)icvFloodFill_Grad_8u_C1IR;
-    ffillgrad_tab[1] = (void*)icvFloodFill_Grad_8u_C3IR;
-    ffillgrad_tab[2] = (void*)icvFloodFill_Grad_32f_C1IR;
+    ffillgrad_tab[0] = (void*)icvFloodFill_Grad_8u_CnIR;
+    ffillgrad_tab[1] = (void*)icvFloodFill_Grad_32f_CnIR;
 }
 
 
 CV_IMPL void
 cvFloodFill( CvArr* arr, CvPoint seed_point,
-             double newVal, double lo_diff, double up_diff,
+             CvScalar newVal, CvScalar lo_diff, CvScalar up_diff,
              CvConnectedComp* comp, int flags, CvArr* maskarr )
 {
-    static void* ffill_tab[3];
-    static void* ffillgrad_tab[3];
+    static void* ffill_tab[4];
+    static void* ffillgrad_tab[4];
     static int inittab = 0;
 
     CvMat* tempMask = 0;
@@ -1033,13 +1029,12 @@ cvFloodFill( CvArr* arr, CvPoint seed_point,
 
     __BEGIN__;
 
-    int type, is_simple, idx;
-    int connectivity = flags & 255;
-    int buffersize;
-    double nv_buf, ld_buf, ud_buf;
-    CvSize size;
+    int i, type, cn, is_simple, idx;
+    int buffer_size, connectivity = flags & 255;
+    double nv_buf[4] = {0,0,0,0}, ld_buf[4] = {0,0,0,0}, ud_buf[4] = {0,0,0,0};
     CvMat stub, *img = (CvMat*)arr;
     CvMat maskstub, *mask = (CvMat*)maskarr;
+    CvSize size;
 
     if( !inittab )
     {
@@ -1049,8 +1044,10 @@ cvFloodFill( CvArr* arr, CvPoint seed_point,
 
     CV_CALL( img = cvGetMat( img, &stub ));
     type = CV_MAT_TYPE( img->type );
+    cn = CV_MAT_CN(type);
 
-    idx = type == CV_8UC1 ? 0 : type == CV_8UC3 ? 1 : type == CV_32FC1 ? 2 : -1;
+    idx = type == CV_8UC1 || type == CV_8UC3 ? 0 :
+          type == CV_32FC1 || type == CV_32FC3 ? 1 : -1;
 
     if( idx < 0 )
         CV_ERROR( CV_StsUnsupportedFormat, "" );
@@ -1060,21 +1057,24 @@ cvFloodFill( CvArr* arr, CvPoint seed_point,
     else if( connectivity != 4 && connectivity != 8 )
         CV_ERROR( CV_StsBadFlag, "Connectivity must be 4, 0(=4) or 8" );
 
-    if( type != CV_8UC3 && (lo_diff < 0 || up_diff < 0) )
-        CV_ERROR( CV_StsBadArg, "lo_diff and up_diff must be non-negative" );
+    is_simple = mask == 0 && (flags & CV_FLOODFILL_MASK_ONLY) == 0;
 
-    size = icvGetMatSize( img );
+    for( i = 0; i < cn; i++ )
+    {
+        if( lo_diff.val[i] < 0 || up_diff.val[i] < 0 )
+            CV_ERROR( CV_StsBadArg, "lo_diff and up_diff must be non-negative" );
+        is_simple &= lo_diff.val[i] == 0 && up_diff.val[i] == 0;
+    }
+
+    size = cvGetMatSize( img );
 
     if( (unsigned)seed_point.x >= (unsigned)size.width ||
         (unsigned)seed_point.y >= (unsigned)size.height )
         CV_ERROR( CV_StsOutOfRange, "Seed point is outside of image" );
 
-    is_simple = lo_diff == 0 && up_diff == 0 && mask == 0 &&
-                (flags & CV_FLOODFILL_MASK_ONLY) == 0;
-
-    icvExtractColor( newVal, type, &nv_buf );
-    buffersize = MAX( size.width, size.height )*2;
-    CV_CALL( buffer = (CvFFillSegment*)cvAlloc( buffersize*sizeof(buffer[0])));
+    cvScalarToRawData( &newVal, &nv_buf, type, 0 );
+    buffer_size = MAX( size.width, size.height )*2;
+    CV_CALL( buffer = (CvFFillSegment*)cvAlloc( buffer_size*sizeof(buffer[0])));
 
     if( is_simple )
     {
@@ -1084,7 +1084,7 @@ cvFloodFill( CvArr* arr, CvPoint seed_point,
         
         IPPI_CALL( func( img->data.ptr, img->step, size,
                          seed_point, &nv_buf, comp, flags,
-                         buffer, buffersize ));
+                         buffer, buffer_size, cn ));
     }
     else
     {
@@ -1123,12 +1123,12 @@ cvFloodFill( CvArr* arr, CvPoint seed_point,
             memset( mask_row, 1, width );
         }
 
-        icvExtractColor( lo_diff, type, &ld_buf );
-        icvExtractColor( up_diff, type, &ud_buf );
+        cvScalarToRawData( &lo_diff, &ld_buf, type, 0 );
+        cvScalarToRawData( &up_diff, &ud_buf, type, 0 );
 
         IPPI_CALL( func( img->data.ptr, img->step, mask->data.ptr, mask->step,
                          size, seed_point, &nv_buf, &ld_buf, &ud_buf,
-                         comp, flags, buffer, buffersize ));
+                         comp, flags, buffer, buffer_size, cn ));
     }
 
     __END__;
index ee15a9d5615a7a524c8fba9298aaed64eda549fe..a9bc8b79626299d7d37083e89953e5f1641adfcc 100644 (file)
 //
 //M*/
 #include "_cv.h"
-#include "_cvvm.h"
 
+/* Valery Mosyagin */
 
 /*=====================================================================================*/
 /* new version of fundamental matrix functions */
 /*=====================================================================================*/
 
-int icvComputeFundamental7Point(CvMat* points1,CvMat* points2,
+static int icvComputeFundamental7Point(CvMat* points1,CvMat* points2,
                                      CvMat* fundMatr);
 
-int icvComputeFundamental8Point(CvMat* points1,CvMat* points2,
+static int icvComputeFundamental8Point(CvMat* points1,CvMat* points2,
                                      CvMat* fundMatr);
 
 
-int icvComputeFundamentalRANSAC(   CvMat* points1,CvMat* points2,
+static int icvComputeFundamentalRANSAC(   CvMat* points1,CvMat* points2,
                                         CvMat* fundMatr,
                                         double threshold,/* threshold for good point. Distance from epipolar line */
-                                                                               double p,/* probability of good result. Usually = 0.99 */
+                                        double p,/* probability of good result. Usually = 0.99 */
                                         CvMat* status);
 
-int icvComputeFundamentalLMedS(   CvMat* points1,CvMat* points2,
+static int icvComputeFundamentalLMedS(   CvMat* points1,CvMat* points2,
                                         CvMat* fundMatr,
                                         double threshold,/* threshold for good point. Distance from epipolar line */
-                                                                               double p,/* probability of good result. Usually = 0.99 */
+                                        double p,/* probability of good result. Usually = 0.99 */
                                         CvMat* status);
 
-void icvMakeFundamentalSingular(CvMat* fundMatr);
+static void icvMakeFundamentalSingular(CvMat* fundMatr);
 
-void icvNormalizeFundPoints(   CvMat* points,
-                                                               CvMat* transfMatr);
+static void icvNormalizeFundPoints(    CvMat* points,
+                                CvMat* transfMatr);
 
-int icvSolveCubic(CvMat* coeffs,CvMat* result);
+static void icvMake2DPoints(CvMat* srcPoint,CvMat* dstPoint);
 
-void icvMake2DPoints(CvMat* srcPoint,CvMat* dstPoint);
+static void icvMake3DPoints(CvMat* srcPoint,CvMat* dstPoint);
 
-void icvMake3DPoints(CvMat* srcPoint,CvMat* dstPoint);
+static int icvCubicV( double a2, double a1, double a0, double *squares );
 
-void icvComputeCorrespondEpilines(CvMat* points,int pointImageID,CvMat* fundMatr,CvMat* corrLines);    
-
-int icvCubicV( double a2, double a1, double a0, double *squares );
+static void cvComputeCorrespondEpilines(CvMat* points,int pointImageID,CvMat* fundMatr,CvMat* corrLines);
 
 /*=====================================================================================*/
 
@@ -106,13 +104,14 @@ int icvCubicV( double a2, double a1, double a0, double *squares );
 //    Returns:
 //      number of found matrixes 
 //F*/
-int cvFindFundamentalMat(   CvMat* points1,
-                                                       CvMat* points2,
-                                                       CvMat* fundMatr,
-                                                       int    method,
-                                                       double param1,
-                                                       double param2,
-                            CvMat* status)
+CV_IMPL int
+cvFindFundamentalMat( CvMat* points1,
+                      CvMat* points2,
+                      CvMat* fundMatr,
+                      int    method,
+                      double param1,
+                      double param2,
+                      CvMat* status )
 {
     int result = -1;
 
@@ -202,20 +201,20 @@ int cvFindFundamentalMat(   CvMat* points1,
     }
 
 
-       switch( method )
-       {
-               case CV_FM_7POINT: result = icvComputeFundamental7Point(wpoints[1], wpoints[0], fundMatr);break;
+    switch( method )
+    {
+        case CV_FM_7POINT: result = icvComputeFundamental7Point(wpoints[1], wpoints[0], fundMatr);break;
 
-               case CV_FM_8POINT: result = icvComputeFundamental8Point(wpoints[1],wpoints[0], fundMatr);break;
+        case CV_FM_8POINT: result = icvComputeFundamental8Point(wpoints[1],wpoints[0], fundMatr);break;
 
-               case CV_FM_LMEDS : result = icvComputeFundamentalLMedS(   wpoints[1],wpoints[0], fundMatr,
+        case CV_FM_LMEDS : result = icvComputeFundamentalLMedS(   wpoints[1],wpoints[0], fundMatr,
                                         param1,param2,status);break;
 
-               case CV_FM_RANSAC: result = icvComputeFundamentalRANSAC(   wpoints[1],wpoints[0], fundMatr,
+        case CV_FM_RANSAC: result = icvComputeFundamentalRANSAC(   wpoints[1],wpoints[0], fundMatr,
                                         param1,param2,status);break;
 
-               //default:return -1/*ERROR*/;
-       }
+        //default:return -1/*ERROR*/;
+    }
 
     __END__;
 
@@ -228,7 +227,7 @@ int cvFindFundamentalMat(   CvMat* points1,
 /*=====================================================================================*/
 
 /* Computes 1 or 3 fundamental matrixes using 7-point algorithm */
-int icvComputeFundamental7Point(CvMat* points1, CvMat* points2, CvMat* fundMatr)
+static int icvComputeFundamental7Point(CvMat* points1, CvMat* points2, CvMat* fundMatr)
 {
 
     CvMat* squares = 0;
@@ -252,8 +251,8 @@ int icvComputeFundamental7Point(CvMat* points1, CvMat* points2, CvMat* fundMatr)
     int numPoint;
     numPoint = points1->cols;
     
-    int type;
-    type = points1->type;
+    /*int type;
+    type = points1->type;*/
     
     if( numPoint != points2->cols )
     {
@@ -335,37 +334,37 @@ int icvComputeFundamental7Point(CvMat* points1, CvMat* points2, CvMat* fundMatr)
 
     cvSVD( &matrU, &matrSS, &matrUU, &matrVV, 0/*CV_SVD_V_T*/ );/* get transposed matrix V */
 
-       double F111,F112,F113;
-       double F121,F122,F123;
-       double F131,F132,F133;
+    double F111,F112,F113;
+    double F121,F122,F123;
+    double F131,F132,F133;
 
-       double F211,F212,F213;
-       double F221,F222,F223;
-       double F231,F232,F233;
+    double F211,F212,F213;
+    double F221,F222,F223;
+    double F231,F232,F233;
 
-       F111=cvmGet(&matrVV,0,7);
+    F111=cvmGet(&matrVV,0,7);
     F112=cvmGet(&matrVV,1,7);
     F113=cvmGet(&matrVV,2,7);
-       F121=cvmGet(&matrVV,3,7);
+    F121=cvmGet(&matrVV,3,7);
     F122=cvmGet(&matrVV,4,7);
     F123=cvmGet(&matrVV,5,7);
-       F131=cvmGet(&matrVV,6,7);
+    F131=cvmGet(&matrVV,6,7);
     F132=cvmGet(&matrVV,7,7);
     F133=cvmGet(&matrVV,8,7);
     
-       F211=cvmGet(&matrVV,0,8);
+    F211=cvmGet(&matrVV,0,8);
     F212=cvmGet(&matrVV,1,8);
     F213=cvmGet(&matrVV,2,8);
-       F221=cvmGet(&matrVV,3,8);
+    F221=cvmGet(&matrVV,3,8);
     F222=cvmGet(&matrVV,4,8);
     F223=cvmGet(&matrVV,5,8);
-       F231=cvmGet(&matrVV,6,8);
+    F231=cvmGet(&matrVV,6,8);
     F232=cvmGet(&matrVV,7,8);
     F233=cvmGet(&matrVV,8,8);
 
     double a,b,c,d;
 
-       a =   F231*F112*F223 + F231*F212*F123 - F231*F212*F223 + F231*F113*F122 -
+    a =   F231*F112*F223 + F231*F212*F123 - F231*F212*F223 + F231*F113*F122 -
           F231*F113*F222 - F231*F213*F122 + F231*F213*F222 - F131*F112*F223 -
           F131*F212*F123 + F131*F212*F223 - F131*F113*F122 + F131*F113*F222 +
           F131*F213*F122 - F131*F213*F222 + F121*F212*F133 - F121*F212*F233 +
@@ -378,7 +377,7 @@ int icvComputeFundamental7Point(CvMat* points1, CvMat* points2, CvMat* fundMatr)
           F211*F123*F232 - F211*F223*F132 + F211*F223*F232 + F111*F122*F133 -
           F111*F122*F233 - F121*F112*F133 + F131*F112*F123 - F231*F112*F123;
     
-       b =   2*F231*F213*F122 - 3*F231*F213*F222 + F231*F112*F123   - 2*F231*F112*F223 -
+    b =   2*F231*F213*F122 - 3*F231*F213*F222 + F231*F112*F123   - 2*F231*F112*F223 -
           2*F231*F212*F123 + 3*F231*F212*F223 - F231*F113*F122   + 2*F231*F113*F222 +
           F131*F212*F123   - 2*F131*F212*F223 - F131*F113*F222   - F131*F213*F122   +
           2*F131*F213*F222 + F121*F113*F232   + F121*F213*F132   - 2*F121*F213*F232 -
@@ -390,14 +389,14 @@ int icvComputeFundamental7Point(CvMat* points1, CvMat* points2, CvMat* fundMatr)
           F111*F123*F232   - F111*F223*F132   + 2*F111*F223*F232 + F111*F122*F233   +
           F111*F222*F133   + F211*F122*F133;
     
-       c =   F231*F112*F223   + F231*F212*F123   - 3*F231*F212*F223 - F231*F113*F222   -
+    c =   F231*F112*F223   + F231*F212*F123   - 3*F231*F212*F223 - F231*F113*F222   -
           F231*F213*F122   + 3*F231*F213*F222 + F131*F212*F223   - F131*F213*F222   +
           F121*F213*F232   - F221*F112*F233   - F221*F212*F133   + 3*F221*F212*F233 +
           F221*F113*F232   + F221*F213*F132   - 3*F221*F213*F232 + F211*F122*F233   +
           F211*F222*F133   - 3*F211*F222*F233 - F211*F123*F232   - F211*F223*F132   +
           3*F211*F223*F232 - F121*F212*F233   + F111*F222*F233   - F111*F223*F232;
     
-       d =   F221*F213*F232 - F211*F223*F232 + F211*F222*F233 - F221*F212*F233 +
+    d =   F221*F213*F232 - F211*F223*F232 + F211*F222*F233 - F221*F212*F233 +
           F231*F212*F223 - F231*F213*F222;
 
     /* find root */
@@ -411,7 +410,7 @@ int icvComputeFundamental7Point(CvMat* points1, CvMat* points2, CvMat* fundMatr)
     cvmSet(&coeffs,0,3,d);
 
     int numCubRoots;
-    numCubRoots = icvSolveCubic(&coeffs,squares);
+    numCubRoots = cvSolveCubic(&coeffs,squares);
 
     /* take real solution */
     /* Need test all roots */
@@ -468,7 +467,7 @@ int icvComputeFundamental7Point(CvMat* points1, CvMat* points2, CvMat* fundMatr)
 
 /*=====================================================================================*/
 
-int icvComputeFundamental8Point(CvMat* points1,CvMat* points2, CvMat* fundMatr)
+static int icvComputeFundamental8Point(CvMat* points1,CvMat* points2, CvMat* fundMatr)
 {
     CvMat* wpoints[2]={0,0};
     CvMat* preFundMatr = 0;
@@ -498,8 +497,8 @@ int icvComputeFundamental8Point(CvMat* points1,CvMat* points2, CvMat* fundMatr)
     int numPoint;
     numPoint = points1->cols;
     
-    int type;
-    type = points1->type;
+    /*int type;
+    type = points1->type;*/
     
     if( numPoint != points2->cols )
     {
@@ -590,7 +589,7 @@ int icvComputeFundamental8Point(CvMat* points1,CvMat* points2, CvMat* fundMatr)
     numEig = 0;
     {
         int i;
-        for( i = 0; i < 9; i++ )
+        for( i = 0; i < 8; i++ )
         {
             if( cvmGet(matrW,i,i) < 1e-8 )
             {
@@ -671,10 +670,10 @@ int icvComputeFundamental8Point(CvMat* points1,CvMat* points2, CvMat* fundMatr)
 
 /* Computes fundamental matrix using RANSAC method */
 /*  */
-int icvComputeFundamentalRANSAC(   CvMat* points1,CvMat* points2,
+static int icvComputeFundamentalRANSAC(   CvMat* points1,CvMat* points2,
                                         CvMat* fundMatr,
                                         double threshold,/* Threshold for good points */
-                                                                               double p,/* Probability of good result. */
+                                        double p,/* Probability of good result. */
                                         CvMat* status)    
 {
     CvMat* wpoints1 = 0;
@@ -701,8 +700,8 @@ int icvComputeFundamentalRANSAC(   CvMat* points1,CvMat* points2,
     int numPoint;
     numPoint = points1->cols;
     
-    int type;
-    type = points1->type;
+    /*int type;
+    type = points1->type;*/
     
     if( numPoint != points2->cols )
     {
@@ -756,11 +755,8 @@ int icvComputeFundamentalRANSAC(   CvMat* points1,CvMat* points2,
 
     icvMake3DPoints(points1,wpoints1);
     icvMake3DPoints(points2,wpoints2);
-    
-    srand(12345);
-    
+        
     {
-        int NumSamples = 1;//just init number of samples
         int wasCount = 0;  //count of choosing samples
         int maxGoodPoints = 0;
         int numGoodPoints = 0;
@@ -770,7 +766,8 @@ int icvComputeFundamentalRANSAC(   CvMat* points1,CvMat* points2,
         bestFund = cvMat(3,3,CV_64F,bestFund_dat);
 
         /* choosen points */        
-        while( NumSamples > wasCount )
+        int NumSamples = 500;/* Initial need number of samples */
+        while( wasCount < NumSamples )
         {
             /* select samples */
             int randNumbs[7];
@@ -845,8 +842,8 @@ int icvComputeFundamentalRANSAC(   CvMat* points1,CvMat* points2,
                     {
                         /* Create corresponde lines */
                     
-                        icvComputeCorrespondEpilines(wpoints1,2,&fund7,corrLines2);
-                        icvComputeCorrespondEpilines(wpoints2,1,&fund7,corrLines1);
+                        cvComputeCorrespondEpilines(wpoints1,2,&fund7,corrLines2);
+                        cvComputeCorrespondEpilines(wpoints2,1,&fund7,corrLines1);
                         /* compute distances for points and number of good points */
                         int i;
                         numGoodPoints = 0;
@@ -877,17 +874,27 @@ int icvComputeFundamentalRANSAC(   CvMat* points1,CvMat* points2,
                     {
                         bestFlags[i] = flags[i];
                     }
-                }
-            }
+
+                    /* Recompute new number of need steps */
+
+                    /* Adaptive number of samples to count*/
+                    double ep = 1 - (double)numGoodPoints / (double)numPoint;
+                    if( ep == 1 )
+                    {
+                        ep = 0.5;//if there is not good points set ration of outliers to 50%
+                    }
             
-                       /* Adaptive number of samples to count*/
-                       double ep = 1 - (double)numGoodPoints / (double)numPoint;
-            if( ep == 1 )
-            {
-                ep = 0.5;//if there is not good points set ration of outliers to 50%
+                    double newNumSamples = log(1-p);
+                    newNumSamples /= log(1-pow(1-ep,7));
+
+                    if( newNumSamples < (double)NumSamples )
+                    {
+                        NumSamples = cvRound(newNumSamples);
+                    }
+
+                }
             }
             
-                       NumSamples = cvRound(log(1-p) / log(1-pow(1-ep,7)));
             wasCount++;
         }
 
@@ -984,7 +991,7 @@ int icvComputeFundamentalRANSAC(   CvMat* points1,CvMat* points2,
 
 /*=====================================================================================*/
 
-void icvCompPointLineDists(CvMat* points,CvMat* lines,CvMat* distances)
+static void icvCompPointLineDists(CvMat* points,CvMat* lines,CvMat* distances)
 {/* Line must be normalized */
     
     int numPoints;
@@ -1017,13 +1024,13 @@ void icvCompPointLineDists(CvMat* points,CvMat* lines,CvMat* distances)
 #define _compVals( v1, v2 )  ((v1) < (v2))
 
 /* Create function to sort vector */
-CV_IMPLEMENT_QSORT( _SortCvMatVect, double, _compVals )
+static CV_IMPLEMENT_QSORT( _SortCvMatVect, double, _compVals )
 
 /*=====================================================================================*/
-int icvComputeFundamentalLMedS(    CvMat* points1,CvMat* points2,
+static int icvComputeFundamentalLMedS(    CvMat* points1,CvMat* points2,
                                     CvMat* fundMatr,
                                     double threshold,/* Threshold for good points */
-                                                                       double p,/* Probability of good result. */
+                                    double p,/* Probability of good result. */
                                     CvMat* status)    
 {
     CvMat* wpoints1 = 0;
@@ -1055,8 +1062,8 @@ int icvComputeFundamentalLMedS(    CvMat* points1,CvMat* points2,
     int numPoint;
     numPoint = points1->cols;
     
-    int type;
-    type = points1->type;
+    /*int type;
+    type = points1->type;*/
     
     if( numPoint != points2->cols )
     {
@@ -1115,15 +1122,13 @@ int icvComputeFundamentalLMedS(    CvMat* points1,CvMat* points2,
 
     icvMake3DPoints(points1,wpoints1);
     icvMake3DPoints(points2,wpoints2);
-
-    srand(54321);
     
     {
-        int NumSamples = 1;//just init number of samples
+        int NumSamples = 500;//Maximux number of steps
         int wasCount = 0;  //count of choosing samples
 
-               double goodMean = FLT_MAX;
-               double currMean;
+        double goodMean = FLT_MAX;
+        double currMean;
 
         int numGoodPoints = 0;
 
@@ -1132,7 +1137,7 @@ int icvComputeFundamentalLMedS(    CvMat* points1,CvMat* points2,
         bestFund = cvMat(3,3,CV_64F,bestFund_dat);
 
         /* choosen points */        
-        while( NumSamples > wasCount )
+        while( wasCount < NumSamples )
         {
             /* select samples */
             int randNumbs[7];
@@ -1202,26 +1207,26 @@ int icvComputeFundamentalLMedS(    CvMat* points1,CvMat* points2,
 
                 cvGetSubArr(&fundTriple,&fund7,cvRect(0,currFund*3,3,3));
                 {
-                                   /* Compute median error for this matrix */
-                                   {
-                        icvComputeCorrespondEpilines(wpoints1,2,&fund7,corrLines2);
-                        icvComputeCorrespondEpilines(wpoints2,1,&fund7,corrLines1);
+                    /* Compute median error for this matrix */
+                    {
+                        cvComputeCorrespondEpilines(wpoints1,2,&fund7,corrLines2);
+                        cvComputeCorrespondEpilines(wpoints2,1,&fund7,corrLines1);
 
-                                           icvCompPointLineDists(wpoints1,corrLines1,dists1);
-                                           icvCompPointLineDists(wpoints2,corrLines2,dists2);
+                        icvCompPointLineDists(wpoints1,corrLines1,dists1);
+                        icvCompPointLineDists(wpoints2,corrLines2,dists2);
 
-                                           /* add distances for points (d1*d1+d2*d2) */
-                                           cvMul(dists1,dists1,distsSq1);
-                                           cvMul(dists2,dists2,distsSq2);
+                        /* add distances for points (d1*d1+d2*d2) */
+                        cvMul(dists1,dists1,distsSq1);
+                        cvMul(dists2,dists2,distsSq2);
 
-                                           cvAdd(distsSq1,distsSq2,allDists);
+                        cvAdd(distsSq1,distsSq2,allDists);
 
-                                           /* sort distances */
-                                           _SortCvMatVect(allDists->data.db,numPoint,0);
+                        /* sort distances */
+                        _SortCvMatVect(allDists->data.db,numPoint,0);
 
-                                           /* get median error */
-                                           currMean = allDists->data.db[numPoint/2];
-                                   }
+                        /* get median error */
+                        currMean = allDists->data.db[numPoint/2];
+                    }
                 }
 
                 if( currMean < goodMean )
@@ -1239,18 +1244,23 @@ int icvComputeFundamentalLMedS(    CvMat* points1,CvMat* points2,
                             numGoodPoints++;
                         }
                     }
-                }
 
-            }
 
-            /* Compute adaptive number of steps */
-                       double ep = 1 - (double)numGoodPoints / (double)numPoint;
-            if( ep == 1 )
-            {
-                ep = 0.5;//if there is not good points set ration of outliers to 50%
-            }
+                    /* Compute adaptive number of steps */
+                    double ep = 1 - (double)numGoodPoints / (double)numPoint;
+                    if( ep == 1 )
+                    {
+                        ep = 0.5;//if there is not good points set ration of outliers to 50%
+                    }
 
-                       NumSamples = cvRound(log(1-p) / log(1-pow(1-ep,7)));
+                    double newNumSamples = log(1-p);
+                    newNumSamples /= log(1-pow(1-ep,7));
+                    if( newNumSamples < (double)NumSamples )
+                    {
+                        NumSamples = cvRound(newNumSamples);
+                    }
+                }
+            }
 
             wasCount++;
         }
@@ -1266,12 +1276,12 @@ int icvComputeFundamentalLMedS(    CvMat* points1,CvMat* points2,
         }
         else
         {/* we have computed fundamental matrix */
-                   {
-                icvComputeCorrespondEpilines(wpoints1,2,&bestFund,corrLines2);
-                icvComputeCorrespondEpilines(wpoints2,1,&bestFund,corrLines1);
+            {
+                cvComputeCorrespondEpilines(wpoints1,2,&bestFund,corrLines2);
+                cvComputeCorrespondEpilines(wpoints2,1,&bestFund,corrLines1);
 
-                           icvCompPointLineDists(wpoints1,corrLines1,dists1);
-                           icvCompPointLineDists(wpoints2,corrLines2,dists2);
+                icvCompPointLineDists(wpoints1,corrLines1,dists1);
+                icvCompPointLineDists(wpoints2,corrLines2,dists2);
 
                 /* test dist for each point and set status for each point if need */
                 int i;
@@ -1301,7 +1311,7 @@ int icvComputeFundamentalLMedS(    CvMat* points1,CvMat* points2,
 
                 }
                 numGoodPoints = currPnt;
-                   }
+            }
 
             /* we have best 7-point fundamental matrix. */
             /* and best points */
@@ -1371,7 +1381,7 @@ int icvComputeFundamentalLMedS(    CvMat* points1,CvMat* points2,
 
 
 
-void icvMakeFundamentalSingular(CvMat* fundMatr)
+static void icvMakeFundamentalSingular(CvMat* fundMatr)
 {
     CV_FUNCNAME( "icvFundSingular" );
     __BEGIN__;
@@ -1429,7 +1439,7 @@ void icvMakeFundamentalSingular(CvMat* fundMatr)
 /* place centroid of points to (0,0) */
 /* set mean distance from (0,0) by sqrt(2) */
 
-void icvNormalizeFundPoints( CvMat* points, CvMat* transfMatr )
+static void icvNormalizeFundPoints( CvMat* points, CvMat* transfMatr )
 {
     CvMat* subwpointsx = 0;
     CvMat* subwpointsy = 0;
@@ -1437,16 +1447,15 @@ void icvNormalizeFundPoints( CvMat* points, CvMat* transfMatr )
     CvMat* pointsxx    = 0;
     CvMat* pointsyy    = 0;
 
-       int numPoint;
-       int type;
-       double shiftx,shifty; 
-       double meand;
-       double scale;
+    int numPoint;
+    double shiftx,shifty; 
+    double meand;
+    double scale;
 
-       CvMat tmpwpointsx;
+    CvMat tmpwpointsx;
     CvMat tmpwpointsy;
 
-       CvScalar sumx;
+    CvScalar sumx;
     CvScalar sumy;
 
     CV_FUNCNAME( "icvNormalizeFundPoints" );
@@ -1460,8 +1469,6 @@ void icvNormalizeFundPoints( CvMat* points, CvMat* transfMatr )
     }
     
     numPoint = points->cols;
-        
-    type = points->type;
     
     if( numPoint < 1 )
     {
@@ -1526,11 +1533,11 @@ void icvNormalizeFundPoints( CvMat* points, CvMat* transfMatr )
     /* in vector sqdists we have distances */
     /* compute mean value and scale */
     
-    meand = cvMean(sqdists);    
+    meand = cvAvg(sqdists).val[0];
     
     if( fabs(meand) > 1e-8  )
     {
-        scale = sqrt(2)/meand;
+        scale = 0.70710678118654752440084436210485/meand;
     }
     else
     {
@@ -1575,19 +1582,13 @@ void icvNormalizeFundPoints( CvMat* points, CvMat* transfMatr )
     cvReleaseMat(&pointsyy);
 
 }
-/*=====================================================================================*/
-// Solve cubic equation and returns number of roots
-int cvSolveCubic(CvMat* coeffs,CvMat* result)
-{
-    return icvSolveCubic(coeffs, result);
-}
 
 /*=====================================================================================*/
 // Solve cubic equation and returns number of roots
 // Also returns 0 if all values are possible
 // Test for very big coefficients
 // Input params 1x3 or 1x4
-int icvSolveCubic(CvMat* coeffs,CvMat* result)
+CV_IMPL int cvSolveCubic(CvMat* coeffs,CvMat* result)
 {/* solve a*x^3 + b+x^2 + c*x + d = 0 */
     /* coeffs a,b,c,d or b,c,d if a== 1*/
     /* test input params */
@@ -1743,7 +1744,7 @@ void cvMake2DPoints(CvMat* srcPoint,CvMat* dstPoint)
 
   Source and destiantion may be the same and in this case src must be 2D
 */
-void icvMake2DPoints(CvMat* srcPoint,CvMat* dstPoint)
+static void icvMake2DPoints(CvMat* srcPoint,CvMat* dstPoint)
 {
     CvMat* submatx = 0;
     CvMat* submaty = 0;
@@ -1842,7 +1843,7 @@ void cvMake3DPoints(CvMat* srcPoint,CvMat* dstPoint)
           
   Source and destiantion may be the same and in this case src must be 2D
 */
-void icvMake3DPoints(CvMat* srcPoint,CvMat* dstPoint)
+static void icvMake3DPoints(CvMat* srcPoint,CvMat* dstPoint)
 {
     CvMat* tmpSubmatz = 0;
 
@@ -1916,13 +1917,7 @@ void icvMake3DPoints(CvMat* srcPoint,CvMat* dstPoint)
 }
 
 /*=====================================================================================*/
-void cvComputeCorrespondEpilines(CvMat* points,int pointImageID,CvMat* fundMatr,CvMat* corrLines)
-{
-       icvComputeCorrespondEpilines(points, pointImageID, fundMatr, corrLines);
-       return;
-}
-/*=====================================================================================*/
-void icvComputeCorrespondEpilines(CvMat* points,int pointImageID,CvMat* fundMatr,CvMat* corrLines)
+static void cvComputeCorrespondEpilines(CvMat* points,int pointImageID,CvMat* fundMatr,CvMat* corrLines)
 {
 
     CvMat* wpoints = 0;
@@ -2029,7 +2024,7 @@ void icvComputeCorrespondEpilines(CvMat* points,int pointImageID,CvMat* fundMatr
 #define REAL_ZERO(x) ( (x) < 1e-8 && (x) > -1e-8)
 
 /* function return squares for cubic equation. 6 params - two for each square (Re,Im) */
-int
+static int
 icvCubicV( double a2, double a1, double a0, double *squares )
 {
     double p, q, D, c1, c2, b1, b2, ro1, ro2, fi1, fi2;
@@ -2094,23 +2089,21 @@ icvCubicV( double a2, double a1, double a0, double *squares )
 
     if( !REAL_ZERO( ro1 ))
     {
+        c1 = SIGN( ro1 ) * pow( fabs( ro1 ), 1. / 3 );
+        c1 -= SIGN( ro1 ) * p / 3. * pow( fabs( ro1 ), -1. / 3 );
 
-        c1 = SIGN( ro1 ) * pow( fabs( ro1 ), 1. / 3 ) -
-            SIGN( ro1 ) * p / 3. * pow( fabs( ro1 ), -1. / 3 );
-
-        c2 = SIGN( ro1 ) * pow( fabs( ro1 ), 1. / 3 ) +
-            SIGN( ro1 ) * p / 3. * pow( fabs( ro1 ), -1. / 3 );
+        c2 = SIGN( ro1 ) * pow( fabs( ro1 ), 1. / 3 );
+        c2 += SIGN( ro1 ) * p / 3. * pow( fabs( ro1 ), -1. / 3 );
     }                           /* if */
 
     if( !REAL_ZERO( ro2 ))
     {
+        b1 = SIGN( ro2 ) * pow( fabs( ro2 ), 1. / 3 );
+        b1 -= SIGN( ro2 ) * p / 3. * pow( fabs( ro2 ), -1. / 3 );
 
-        b1 = SIGN( ro2 ) * pow( fabs( ro2 ), 1. / 3 ) -
-            SIGN( ro2 ) * p / 3. * pow( fabs( ro2 ), -1. / 3 );
-
-        b2 = SIGN( ro2 ) * pow( fabs( ro2 ), 1. / 3 ) +
-            SIGN( ro2 ) * p / 3. * pow( fabs( ro2 ), -1. / 3 );
-    }                           /* if */
+        b2 = SIGN( ro2 ) * pow( fabs( ro2 ), 1. / 3 );
+        b2 += SIGN( ro2 ) * p / 3. * pow( fabs( ro2 ), -1. / 3 );
+    }
 
     for( i = 0; i < 6; i++ )
     {
@@ -2178,363 +2171,3 @@ icvCubicV( double a2, double a1, double a0, double *squares )
 
 /*=====================================================================================*/
 
-
-
-
-
-
-
-
-/* Obsolete functions. Just for ViewMorping */
-/*=====================================================================================*/
-
-int
-icvGaussMxN( double *A, double *B, int M, int N, double **solutions )
-{
-    int *variables;
-    int row, swapi, i, i_best = 0, j, j_best = 0, t;
-    double swapd, ratio, bigest;
-
-    if( !A || !B || !M || !N )
-        return -1;
-
-    variables = (int *) icvAlloc( (long) N * sizeof( int ));
-
-    if( variables == 0 )
-        return -1;
-
-    for( i = 0; i < N; i++ )
-    {
-        variables[i] = i;
-    }                           /* for */
-
-    /* -----  Direct way  ----- */
-
-    for( row = 0; row < M; row++ )
-    {
-
-        bigest = 0;
-
-        for( j = row; j < M; j++ )
-        {                       /* search non null element */
-            for( i = row; i < N; i++ )
-            {
-
-                if( fabs( A[j * N + i] ) > fabs( bigest ))
-                {
-                    bigest = A[j * N + i];
-                    i_best = i;
-                    j_best = j;
-                }               /* if */
-            }                   /* for */
-        }                       /* for */
-
-        if( REAL_ZERO( bigest ))
-            break;              /* if all shank elements are null */
-
-        if( j_best - row )
-        {
-
-            for( t = 0; t < N; t++ )
-            {                   /* swap a rows */
-
-                swapd = A[row * N + t];
-                A[row * N + t] = A[j_best * N + t];
-                A[j_best * N + t] = swapd;
-            }                   /* for */
-
-            swapd = B[row];
-            B[row] = B[j_best];
-            B[j_best] = swapd;
-        }                       /* if */
-
-        if( i_best - row )
-        {
-
-            for( t = 0; t < M; t++ )
-            {                   /* swap a columns  */
-
-                swapd = A[t * N + i_best];
-                A[t * N + i_best] = A[t * N + row];
-                A[t * N + row] = swapd;
-            }                   /* for */
-
-            swapi = variables[row];
-            variables[row] = variables[i_best];
-            variables[i_best] = swapi;
-        }                       /* if */
-
-        for( i = row + 1; i < M; i++ )
-        {                       /* recounting A and B */
-
-            ratio = -A[i * N + row] / A[row * N + row];
-            B[i] += B[row] * ratio;
-
-            for( j = N - 1; j >= row; j-- )
-            {
-
-                A[i * N + j] += A[row * N + j] * ratio;
-            }                   /* for */
-        }                       /* for */
-    }                           /* for */
-
-    if( row < M )
-    {                           /* if rank(A)<M */
-
-        for( j = row; j < M; j++ )
-        {
-            if( !REAL_ZERO( B[j] ))
-            {
-
-                icvFree( &variables );
-                return -1;      /* if system is antithetic */
-            }                   /* if */
-        }                       /* for */
-
-        M = row;                /* decreasing size of the task */
-    }                           /* if */
-
-    /* ----- Reverse way ----- */
-
-    if( M < N )
-    {                           /* if solution are not exclusive */
-
-        *solutions = (double *) icvAlloc( ((N - M + 1) * N) * sizeof( double ));
-
-        if( *solutions == 0 )
-        {
-            icvFree( &variables );
-            return -1;
-        }
-
-
-        for( t = M; t <= N; t++ )
-        {
-            for( j = M; j < N; j++ )
-            {
-
-                (*solutions)[(t - M) * N + variables[j]] = (double) (t == j);
-            }                   /* for */
-
-            for( i = M - 1; i >= 0; i-- )
-            {                   /* finding component of solution */
-
-                if( t < N )
-                {
-                    (*solutions)[(t - M) * N + variables[i]] = 0;
-                }
-                else
-                {
-                    (*solutions)[(t - M) * N + variables[i]] = B[i] / A[i * N + i];
-                }               /* if */
-
-                for( j = i + 1; j < N; j++ )
-                {
-
-                    (*solutions)[(t - M) * N + variables[i]] -=
-                        (*solutions)[(t - M) * N + variables[j]] * A[i * N + j] / A[i * N + i];
-                }               /* for */
-            }                   /* for */
-        }                       /* for */
-
-        icvFree( &variables );
-        return N - M;
-    }                           /* if */
-
-    *solutions = (double *) icvAlloc( (N) * sizeof( double ));
-
-    if( solutions == 0 )
-        return -1;
-
-    for( i = N - 1; i >= 0; i-- )
-    {                           /* finding exclusive solution */
-
-        (*solutions)[variables[i]] = B[i] / A[i * N + i];
-
-        for( j = i + 1; j < N; j++ )
-        {
-
-            (*solutions)[variables[i]] -=
-                (*solutions)[variables[j]] * A[i * N + j] / A[i * N + i];
-        }                       /* for */
-    }                           /* for */
-
-    icvFree( &variables );
-    return 0;
-
-}                               /* icvGaussMxN */
-
-/*=====================================================================================*/
-
-CvStatus
-icvGetCoof( double *f1, double *f2, double *a2, double *a1, double *a0 )
-{
-    double G[9], a3;
-    int i;
-
-    if( !f1 || !f2 || !a0 || !a1 || !a2 )
-        return CV_BADFACTOR_ERR;
-
-    for( i = 0; i < 9; i++ )
-    {
-
-        G[i] = f1[i] - f2[i];
-    }                           /* for */
-
-    a3 = icvDet( G );
-
-    if( REAL_ZERO( a3 ))
-        return CV_BADFACTOR_ERR;
-
-    *a2 = 0;
-    *a1 = 0;
-    *a0 = icvDet( f2 );
-
-    for( i = 0; i < 9; i++ )
-    {
-
-        *a2 += f2[i] * icvMinor( G, (int) (i % 3), (int) (i / 3) );
-        *a1 += G[i] * icvMinor( f2, (int) (i % 3), (int) (i / 3) );
-    }                           /* for */
-
-    *a0 /= a3;
-    *a1 /= a3;
-    *a2 /= a3;
-
-    return CV_NO_ERR;
-
-}                               /* icvGetCoof */
-
-
-
-/*======================================================================================*/
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    icvLMedS7
-//    Purpose:
-//      
-//      
-//    Context:
-//    Parameters:
-//     
-//      
-//      
-//     
-//      
-//    
-//     
-//    Returns:
-//      CV_NO_ERR if all Ok or error code
-//    Notes:
-//F*/
-
-CvStatus
-icvLMedS7( int *points1, int *points2, CvMatrix3 * matrix )
-{                               /* Incorrect realization */
-    CvStatus error = CV_NO_ERR;
-
-/*    int         amount; */
-    matrix = matrix;
-    points1 = points1;
-    points2 = points2;
-
-/*    error = cs_Point7( points1, points2, matrix ); */
-/*    error = icvPoint7    ( points1, points2, matrix,&amount ); */
-    return error;
-
-}                               /* icvLMedS7 */
-
-
-/*======================================================================================*/
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    icvPoint7
-//    Purpose:
-//      
-//      
-//    Context:
-//    Parameters:
-//     
-//      
-//      
-//     
-//      
-//    
-//     
-//    Returns:
-//      CV_NO_ERR if all Ok or error code
-//    Notes:
-//F*/
-
-CvStatus
-icvPoint7( int *ml, int *mr, double *F, int *amount )
-{
-    double A[63], B[7];
-    double *solutions;
-    double a2, a1, a0;
-    double squares[6];
-    int i, j;
-
-/*    int         amount; */
-/*    float*     F; */
-
-    CvStatus error = CV_BADFACTOR_ERR;
-
-/*    F = (float*)matrix->m; */
-
-    if( !ml || !mr || !F )
-        return CV_BADFACTOR_ERR;
-
-    for( i = 0; i < 7; i++ )
-    {
-        for( j = 0; j < 9; j++ )
-        {
-
-            A[i * 9 + j] = (double) ml[i * 3 + j / 3] * (double) mr[i * 3 + j % 3];
-        }                       /* for */
-        B[i] = 0;
-    }                           /* for */
-
-    *amount = 0;
-
-    if( icvGaussMxN( A, B, 7, 9, &solutions ) == 2 )
-    {
-        if( icvGetCoef( solutions, solutions + 9, &a2, &a1, &a0 ) == CV_NO_ERR )
-        {
-            icvCubic( a2, a1, a0, squares );
-
-            for( i = 0; i < 1; i++ )
-            {
-
-                if( REAL_ZERO( squares[i * 2 + 1] ))
-                {
-
-                    for( j = 0; j < 9; j++ )
-                    {
-
-                        F[*amount + j] = (float) (squares[i] * solutions[j] +
-                                                  (1 - squares[i]) * solutions[j + 9]);
-                    }           /* for */
-
-                    *amount += 9;
-
-                    error = CV_NO_ERR;
-                }               /* if */
-            }                   /* for */
-
-            icvFree( &solutions );
-            return error;
-        }
-        else
-        {
-            icvFree( &solutions );
-        }                       /* if */
-
-    }
-    else
-    {
-        icvFree( &solutions );
-    }                           /* if */
-
-    return error;
-}                               /* icvPoint7 */
-
index 336dcfe9f9190d826aaee23aded0dbaaed05c884..538a4941a8e5c1845f7ae265cce6029e9622a4ee 100644 (file)
 //
 //M*/
 #include "_cv.h"
-#include <limits.h>
-#include <float.h>
-#include "_cvgeom.h"
+
+
+CV_IMPL CvRect
+cvMaxRect( const CvRect* rect1, const CvRect* rect2 )
+{
+    if( rect1 && rect2 )
+    {
+        CvRect max_rect;
+        int a, b;
+
+        max_rect.x = a = rect1->x;
+        b = rect2->x;
+        if( max_rect.x > b )
+            max_rect.x = b;
+
+        max_rect.width = a += rect1->width;
+        b += rect2->width;
+
+        if( max_rect.width < b )
+            max_rect.width = b;
+        max_rect.width -= max_rect.x;
+
+        max_rect.y = a = rect1->y;
+        b = rect2->y;
+        if( max_rect.y > b )
+            max_rect.y = b;
+
+        max_rect.height = a += rect1->height;
+        b += rect2->height;
+
+        if( max_rect.height < b )
+            max_rect.height = b;
+        max_rect.height -= max_rect.y;
+        return max_rect;
+    }
+    else if( rect1 )
+        return *rect1;
+    else if( rect2 )
+        return *rect2;
+    else
+        return cvRect(0,0,0,0);
+}
+
+
+CV_IMPL void
+cvBoxPoints( CvBox2D box, CvPoint2D32f pt[4] )
+{
+    CV_FUNCNAME( "cvBoxPoints" );
+
+    __BEGIN__;
+    
+    float a = (float)cos(box.angle)*0.5f;
+    float b = (float)sin(box.angle)*0.5f;
+
+    if( !pt )
+        CV_ERROR( CV_StsNullPtr, "NULL vertex array pointer" );
+
+    pt[0].x = box.center.x - a*box.size.height - b*box.size.width;
+    pt[0].y = box.center.y + b*box.size.height - a*box.size.width;
+    pt[1].x = box.center.x + a*box.size.height - b*box.size.width;
+    pt[1].y = box.center.y - b*box.size.height - a*box.size.width;
+    pt[2].x = 2*box.center.x - pt[0].x;
+    pt[2].y = 2*box.center.y - pt[0].y;
+    pt[3].x = 2*box.center.x - pt[1].x;
+    pt[3].y = 2*box.center.y - pt[1].y;
+
+    __END__;
+}
+
 
 int
 icvIsPtInCircle3( CvPoint2D32f pt, CvPoint2D32f a, CvPoint2D32f b, CvPoint2D32f c )
 {
-    double val = (a.x * a.x + a.y * a.y) * cvTriangleArea( b, c, pt ) -
-        (b.x * b.x + b.y * b.y) * cvTriangleArea( a, c, pt ) +
-        (c.x * c.x + c.y * c.y) * cvTriangleArea( a, b, pt ) -
-        (pt.x * pt.x + pt.y * pt.y) * cvTriangleArea( a, b, c );
+    double val = (a.x * a.x + a.y * a.y) * cvTriangleArea( b, c, pt );
+    val -= (b.x * b.x + b.y * b.y) * cvTriangleArea( a, c, pt );
+    val += (c.x * c.x + c.y * c.y) * cvTriangleArea( a, b, pt );
+    val -= (pt.x * pt.x + pt.y * pt.y) * cvTriangleArea( a, b, c );
 
     return val > FLT_EPSILON ? 1 : val < -FLT_EPSILON ? -1 : 0;
 }
@@ -104,3 +170,6 @@ icvIntersectLines3( double *a0, double *b0, double *c0,
         point->x = point->y = FLT_MAX;
     }
 }
+
+/* End of file. */
+
diff --git a/opencv/src/cv/cvhaar.cpp b/opencv/src/cv/cvhaar.cpp
new file mode 100644 (file)
index 0000000..f61b2d9
--- /dev/null
@@ -0,0 +1,1850 @@
+/*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.
+//
+//
+//                        Intel License Agreement
+//                For Open Source Computer Vision Library
+//
+// Copyright (C) 2000, Intel Corporation, 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 Intel Corporation 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*/
+
+/* Haar features calculation */
+
+#include "_cv.h"
+#include <stdio.h>
+
+/* these settings affect the quality of detection: change with care */
+#define CV_ADJUST_FEATURES 1
+#define CV_ADJUST_WEIGHTS  0
+
+typedef int sumtype;
+typedef double sqsumtype;
+
+typedef struct CvHidHaarFeature
+{
+    struct
+    {
+        sumtype *p0, *p1, *p2, *p3;
+        float weight;
+    }
+    rect[CV_HAAR_FEATURE_MAX];
+}
+CvHidHaarFeature;
+
+
+typedef struct CvHidHaarTreeNode
+{
+    CvHidHaarFeature feature;
+    float threshold;
+    int left;
+    int right;
+}
+CvHidHaarTreeNode;
+
+
+typedef struct CvHidHaarClassifier
+{
+    int count;
+    //CvHaarFeature* orig_feature;
+    CvHidHaarTreeNode* node;
+    float* alpha;
+}
+CvHidHaarClassifier;
+
+
+typedef struct CvHidHaarStageClassifier
+{
+    int  count;
+    float threshold;
+    CvHidHaarClassifier* classifier;
+    int two_rects;
+    
+    struct CvHidHaarStageClassifier* next;
+    struct CvHidHaarStageClassifier* child;
+    struct CvHidHaarStageClassifier* parent;
+}
+CvHidHaarStageClassifier;
+
+
+struct CvHidHaarClassifierCascade
+{
+    int  count;
+    int  is_stump_based;
+    int  has_tilted_features;
+    int  is_tree;
+    double inv_window_area;
+    CvMat sum, sqsum, tilted;
+    CvHidHaarStageClassifier* stage_classifier;
+    sqsumtype *pq0, *pq1, *pq2, *pq3;
+    sumtype *p0, *p1, *p2, *p3;
+};
+
+
+static CvHaarClassifierCascade*
+icvCreateHaarClassifierCascade( int stage_count )
+{
+    CvHaarClassifierCascade* cascade = 0;
+    
+    CV_FUNCNAME( "icvCreateHaarClassifierCascade" );
+
+    __BEGIN__;
+
+    int block_size = sizeof(*cascade) + stage_count*sizeof(*cascade->stage_classifier);
+
+    if( stage_count <= 0 )
+        CV_ERROR( CV_StsOutOfRange, "Number of stages should be positive" );
+
+    CV_CALL( cascade = (CvHaarClassifierCascade*)cvAlloc( block_size ));
+    memset( cascade, 0, block_size );
+
+    cascade->stage_classifier = (CvHaarStageClassifier*)(cascade + 1);
+    cascade->flags = CV_HAAR_MAGIC_VAL;
+    cascade->count = stage_count;
+
+    __END__;
+
+    return cascade;
+}
+
+/* create more efficient internal representation of haar classifier cascade */
+static CvHidHaarClassifierCascade*
+icvCreateHidHaarClassifierCascade( CvHaarClassifierCascade* cascade )
+{
+    CvHidHaarClassifierCascade* out = 0;
+
+    CV_FUNCNAME( "icvCreateHidHaarClassifierCascade" );
+
+    __BEGIN__;
+
+    int i, j, k, l;
+    int datasize;
+    int total_classifiers = 0;
+    int total_nodes = 0;
+    char errorstr[100];
+    CvHidHaarClassifier* haar_classifier_ptr;
+    CvHidHaarTreeNode* haar_node_ptr;
+    CvSize orig_window_size;
+    int has_tilted_features = 0;
+
+    if( !CV_IS_HAAR_CLASSIFIER(cascade) )
+        CV_ERROR( !cascade ? CV_StsNullPtr : CV_StsBadArg, "Invalid classifier pointer" );
+
+    if( cascade->hid_cascade )
+        CV_ERROR( CV_StsError, "hid_cascade has been already created" );
+
+    if( !cascade->stage_classifier )
+        CV_ERROR( CV_StsNullPtr, "" );
+
+    if( cascade->count <= 0 )
+        CV_ERROR( CV_StsOutOfRange, "Negative number of cascade stages" );
+
+    orig_window_size = cascade->orig_window_size;
+    
+    /* check input structure correctness and calculate total memory size needed for
+       internal representation of the classifier cascade */
+    for( i = 0; i < cascade->count; i++ )
+    {
+        CvHaarStageClassifier* stage_classifier = cascade->stage_classifier + i;
+
+        if( !stage_classifier->classifier ||
+            stage_classifier->count <= 0 )
+        {
+            sprintf( errorstr, "header of the stage classifier #%d is invalid "
+                     "(has null pointers or non-positive classfier count)", i );
+            CV_ERROR( CV_StsError, errorstr );
+        }
+
+        total_classifiers += stage_classifier->count;
+
+        for( j = 0; j < stage_classifier->count; j++ )
+        {
+            CvHaarClassifier* classifier = stage_classifier->classifier + j;
+
+            total_nodes += classifier->count;
+            for( l = 0; l < classifier->count; l++ )
+            {
+                for( k = 0; k < CV_HAAR_FEATURE_MAX; k++ )
+                {
+                    if( classifier->haar_feature[l].rect[k].weight )
+                    {
+                        CvRect r = classifier->haar_feature[l].rect[k].r;
+                        int tilted = classifier->haar_feature[l].tilted;
+                        has_tilted_features |= tilted != 0;
+                        if( r.width < 0 || r.height < 0 || r.y < 0 ||
+                            r.x + r.width > orig_window_size.width
+                            ||
+                            (!tilted &&
+                            (r.x < 0 || r.y + r.height > orig_window_size.height))
+                            ||
+                            (tilted && (r.x - r.height < 0 ||
+                            r.y + r.width + r.height > orig_window_size.height)))
+                        {
+                            sprintf( errorstr, "rectangle #%d of the classifier #%d of "
+                                     "the stage classifier #%d is not inside "
+                                     "the reference (original) cascade window", k, j, i );
+                            CV_ERROR( CV_StsNullPtr, errorstr );
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    // this is an upper boundary for the whole hidden cascade size
+    datasize = sizeof(CvHidHaarClassifierCascade) +
+               sizeof(CvHidHaarStageClassifier)*cascade->count +
+               sizeof(CvHidHaarClassifier) * total_classifiers +
+               sizeof(CvHidHaarTreeNode) * total_nodes +
+               sizeof(void*)*(total_nodes + total_classifiers);
+
+    CV_CALL( out = (CvHidHaarClassifierCascade*)cvAlloc( datasize ));
+    memset( out, 0, sizeof(*out) );
+
+    /* init header */
+    out->count = cascade->count;
+    out->stage_classifier = (CvHidHaarStageClassifier*)(out + 1);
+    haar_classifier_ptr = (CvHidHaarClassifier*)(out->stage_classifier + cascade->count);
+    haar_node_ptr = (CvHidHaarTreeNode*)(haar_classifier_ptr + total_classifiers);
+
+    out->is_stump_based = 1;
+    out->has_tilted_features = has_tilted_features;
+    out->is_tree = 0;
+
+    /* initialize internal representation */
+    for( i = 0; i < cascade->count; i++ )
+    {
+        CvHaarStageClassifier* stage_classifier = cascade->stage_classifier + i;
+        CvHidHaarStageClassifier* hid_stage_classifier = out->stage_classifier + i;
+
+        hid_stage_classifier->count = stage_classifier->count;
+        hid_stage_classifier->threshold = stage_classifier->threshold;
+        hid_stage_classifier->classifier = haar_classifier_ptr;
+        hid_stage_classifier->two_rects = 1;
+        haar_classifier_ptr += stage_classifier->count;
+
+        hid_stage_classifier->parent = (stage_classifier->parent == -1)
+            ? NULL : out->stage_classifier + stage_classifier->parent;
+        hid_stage_classifier->next = (stage_classifier->next == -1)
+            ? NULL : out->stage_classifier + stage_classifier->next;
+        hid_stage_classifier->child = (stage_classifier->child == -1)
+            ? NULL : out->stage_classifier + stage_classifier->child;
+        
+        out->is_tree |= hid_stage_classifier->next != NULL;
+
+        for( j = 0; j < stage_classifier->count; j++ )
+        {
+            CvHaarClassifier* classifier = stage_classifier->classifier + j;
+            CvHidHaarClassifier* hid_classifier = hid_stage_classifier->classifier + j;
+            int node_count = classifier->count;
+            float* alpha_ptr = (float*)(haar_node_ptr + node_count);
+
+            hid_classifier->count = node_count;
+            hid_classifier->node = haar_node_ptr;
+            hid_classifier->alpha = alpha_ptr;
+            
+            for( l = 0; l < node_count; l++ )
+            {
+                CvHidHaarTreeNode* node = hid_classifier->node + l;
+                CvHaarFeature* feature = classifier->haar_feature + l;
+                memset( node, -1, sizeof(*node) );
+                node->threshold = classifier->threshold[l];
+                node->left = classifier->left[l];
+                node->right = classifier->right[l];
+
+                if( feature->rect[2].weight == 0 ||
+                    feature->rect[2].r.width == 0 ||
+                    feature->rect[2].r.height == 0 )
+                    memset( &(node->feature.rect[2]), 0, sizeof(node->feature.rect[2]) );
+                else
+                    hid_stage_classifier->two_rects = 0;
+            }
+
+            memcpy( alpha_ptr, classifier->alpha, (node_count+1)*sizeof(alpha_ptr[0]));
+            haar_node_ptr =
+                (CvHidHaarTreeNode*)cvAlignPtr(alpha_ptr+node_count+1, sizeof(void*));
+
+            out->is_stump_based &= node_count == 1;
+        }
+    }
+
+    cascade->hid_cascade = out;
+    assert( (char*)haar_node_ptr - (char*)out <= datasize );
+
+    __END__;
+
+    if( cvGetErrStatus() < 0 )
+        cvFree( (void**)&out );
+
+    return out;
+}
+
+
+#define sum_elem_ptr(sum,row,col)  \
+    ((sumtype*)CV_MAT_ELEM_PTR_FAST((sum),(row),(col),sizeof(sumtype)))
+
+#define sqsum_elem_ptr(sqsum,row,col)  \
+    ((sqsumtype*)CV_MAT_ELEM_PTR_FAST((sqsum),(row),(col),sizeof(sqsumtype)))
+
+#define calc_sum(rect,offset) \
+    ((rect).p0[offset] - (rect).p1[offset] - (rect).p2[offset] + (rect).p3[offset])
+
+
+CV_IMPL void
+cvSetImagesForHaarClassifierCascade( CvHaarClassifierCascade* _cascade,
+                                     const CvArr* _sum,
+                                     const CvArr* _sqsum,
+                                     const CvArr* _tilted_sum,
+                                     double scale )
+{
+    CV_FUNCNAME("cvSetImagesForHaarClassifierCascade");
+
+    __BEGIN__;
+
+    CvMat sum_stub, *sum = (CvMat*)_sum;
+    CvMat sqsum_stub, *sqsum = (CvMat*)_sqsum;
+    CvMat tilted_stub, *tilted = (CvMat*)_tilted_sum;
+    CvHidHaarClassifierCascade* cascade;
+    int coi0 = 0, coi1 = 0;
+    int i, j, k, l;
+    CvRect equ_rect;
+    double weight_scale;
+
+    if( !CV_IS_HAAR_CLASSIFIER(_cascade) )
+        CV_ERROR( !_cascade ? CV_StsNullPtr : CV_StsBadArg, "Invalid classifier pointer" );
+
+    if( scale <= 0 )
+        CV_ERROR( CV_StsOutOfRange, "Scale must be positive" );
+
+    CV_CALL( sum = cvGetMat( sum, &sum_stub, &coi0 ));
+    CV_CALL( sqsum = cvGetMat( sqsum, &sqsum_stub, &coi1 ));
+
+    if( coi0 || coi1 )
+        CV_ERROR( CV_BadCOI, "COI is not supported" );
+
+    if( !CV_ARE_SIZES_EQ( sum, sqsum ))
+        CV_ERROR( CV_StsUnmatchedSizes, "All integral images must have the same size" );
+
+    if( CV_MAT_TYPE(sqsum->type) != CV_64FC1 ||
+        CV_MAT_TYPE(sum->type) != CV_32SC1 )
+        CV_ERROR( CV_StsUnsupportedFormat,
+        "Only (32s, 64f, 32s) combination of (sum,sqsum,tilted_sum) formats is allowed" );
+
+    if( !_cascade->hid_cascade )
+        CV_CALL( icvCreateHidHaarClassifierCascade(_cascade) );
+
+    cascade = _cascade->hid_cascade;
+
+    if( cascade->has_tilted_features )
+    {
+        CV_CALL( tilted = cvGetMat( tilted, &tilted_stub, &coi1 ));
+
+        if( CV_MAT_TYPE(tilted->type) != CV_32SC1 )
+            CV_ERROR( CV_StsUnsupportedFormat,
+            "Only (32s, 64f, 32s) combination of (sum,sqsum,tilted_sum) formats is allowed" );
+
+        if( sum->step != tilted->step )
+            CV_ERROR( CV_StsUnmatchedSizes,
+            "Sum and tilted_sum must have the same stride (step, widthStep)" );
+
+        if( !CV_ARE_SIZES_EQ( sum, tilted ))
+            CV_ERROR( CV_StsUnmatchedSizes, "All integral images must have the same size" );
+        cascade->tilted = *tilted;
+    }
+    
+    _cascade->scale = scale;
+    _cascade->real_window_size.width = cvRound( _cascade->orig_window_size.width * scale );
+    _cascade->real_window_size.height = cvRound( _cascade->orig_window_size.height * scale );
+
+    cascade->sum = *sum;
+    cascade->sqsum = *sqsum;
+    
+    equ_rect.x = equ_rect.y = cvRound(scale);
+    equ_rect.width = cvRound((_cascade->orig_window_size.width-2)*scale);
+    equ_rect.height = cvRound((_cascade->orig_window_size.height-2)*scale);
+    weight_scale = 1./(equ_rect.width*equ_rect.height);
+    cascade->inv_window_area = weight_scale;
+
+    cascade->p0 = sum_elem_ptr(*sum, equ_rect.y, equ_rect.x);
+    cascade->p1 = sum_elem_ptr(*sum, equ_rect.y, equ_rect.x + equ_rect.width );
+    cascade->p2 = sum_elem_ptr(*sum, equ_rect.y + equ_rect.height, equ_rect.x );
+    cascade->p3 = sum_elem_ptr(*sum, equ_rect.y + equ_rect.height,
+                                     equ_rect.x + equ_rect.width );
+
+    cascade->pq0 = sqsum_elem_ptr(*sqsum, equ_rect.y, equ_rect.x);
+    cascade->pq1 = sqsum_elem_ptr(*sqsum, equ_rect.y, equ_rect.x + equ_rect.width );
+    cascade->pq2 = sqsum_elem_ptr(*sqsum, equ_rect.y + equ_rect.height, equ_rect.x );
+    cascade->pq3 = sqsum_elem_ptr(*sqsum, equ_rect.y + equ_rect.height,
+                                          equ_rect.x + equ_rect.width );
+
+    /* init pointers in haar features according to real window size and
+       given image pointers */
+    for( i = 0; i < _cascade->count; i++ )
+    {
+        for( j = 0; j < cascade->stage_classifier[i].count; j++ )
+        {
+            for( l = 0; l < cascade->stage_classifier[i].classifier[j].count; l++ )
+            {
+                CvHaarFeature* feature = 
+                    &_cascade->stage_classifier[i].classifier[j].haar_feature[l];
+                /* CvHidHaarClassifier* classifier =
+                    cascade->stage_classifier[i].classifier + j; */
+                CvHidHaarFeature* hidfeature = 
+                    &cascade->stage_classifier[i].classifier[j].node[l].feature;
+                double sum0 = 0, area0 = 0;
+                CvRect r[3];
+#if CV_ADJUST_FEATURES
+                int base_w = -1, base_h = -1;
+                int new_base_w = 0, new_base_h = 0;
+                int kx, ky;
+                int flagx = 0, flagy = 0;
+                int x0 = 0, y0 = 0;
+#endif
+                int nr;
+
+                /* align blocks */
+                for( k = 0; k < CV_HAAR_FEATURE_MAX; k++ )
+                {
+                    if( !hidfeature->rect[k].p0 )
+                        break;
+#if CV_ADJUST_FEATURES
+                    r[k] = feature->rect[k].r;
+                    base_w = (int)CV_IMIN( (unsigned)base_w, (unsigned)(r[k].width-1) );
+                    base_w = (int)CV_IMIN( (unsigned)base_w, (unsigned)(r[k].x - r[0].x-1) );
+                    base_h = (int)CV_IMIN( (unsigned)base_h, (unsigned)(r[k].height-1) );
+                    base_h = (int)CV_IMIN( (unsigned)base_h, (unsigned)(r[k].y - r[0].y-1) );
+#endif
+                }
+
+                base_w += 1;
+                base_h += 1;
+                nr = k;
+
+#if CV_ADJUST_FEATURES
+                kx = r[0].width / base_w;
+                ky = r[0].height / base_h;
+
+                if( kx <= 0 )
+                {
+                    flagx = 1;
+                    new_base_w = cvRound( r[0].width * scale ) / kx;
+                    x0 = cvRound( r[0].x * scale );
+                }
+
+                if( ky <= 0 )
+                {
+                    flagy = 1;
+                    new_base_h = cvRound( r[0].height * scale ) / ky;
+                    y0 = cvRound( r[0].y * scale );
+                }
+#endif
+            
+                for( k = 0; k < nr; k++ )
+                {
+                    CvRect tr;
+                    double correctionRatio;
+                
+#if CV_ADJUST_FEATURES
+                    if( flagx )
+                    {
+                        tr.x = (r[k].x - r[0].x) * new_base_w / base_w + x0;
+                        tr.width = r[k].width * new_base_w / base_w;
+                    }
+                    else
+#endif
+                    {
+                        tr.x = cvRound( r[k].x * scale );
+                        tr.width = cvRound( r[k].width * scale );
+                    }
+
+#if CV_ADJUST_FEATURES
+                    if( flagy )
+                    {
+                        tr.y = (r[k].y - r[0].y) * new_base_h / base_h + y0;
+                        tr.height = r[k].height * new_base_h / base_h;
+                    }
+                    else
+#endif
+                    {
+                        tr.y = cvRound( r[k].y * scale );
+                        tr.height = cvRound( r[k].height * scale );
+                    }
+
+#if CV_ADJUST_WEIGHTS
+                    {
+                    // RAINER START
+                    const float orig_feature_size =  (float)(feature->rect[k].r.width)*feature->rect[k].r.height; 
+                    const float orig_norm_size = (float)(cascade->orig_window_size.width)*(cascade->orig_window_size.height);
+                    const float feature_size = float(tr.width*tr.height);
+                    //const float normSize    = float(equ_rect.width*equ_rect.height);
+                    float targetRatio = orig_feature_size / origNormSize;
+                    //float isRatio = featureSize / normSize;
+                    //correctionRatio = targetRatio / isRatio / normSize;
+                    correctionRatio = targetRatio / featureSize;
+                    // RAINER END
+                    }
+#else
+                    correctionRatio = weight_scale * (!feature->tilted ? 1 : 0.5);
+#endif
+
+                    if( !feature->tilted )
+                    {
+                        hidfeature->rect[k].p0 = sum_elem_ptr(*sum, tr.y, tr.x);
+                        hidfeature->rect[k].p1 = sum_elem_ptr(*sum, tr.y, tr.x + tr.width);
+                        hidfeature->rect[k].p2 = sum_elem_ptr(*sum, tr.y + tr.height, tr.x);
+                        hidfeature->rect[k].p3 = sum_elem_ptr(*sum, tr.y + tr.height, tr.x + tr.width);
+                    }
+                    else
+                    {
+                        hidfeature->rect[k].p2 = sum_elem_ptr(*tilted, tr.y + tr.width, tr.x + tr.width);
+                        hidfeature->rect[k].p3 = sum_elem_ptr(*tilted, tr.y + tr.width + tr.height,
+                                                              tr.x + tr.width - tr.height);
+                        hidfeature->rect[k].p0 = sum_elem_ptr(*tilted, tr.y, tr.x);
+                        hidfeature->rect[k].p1 = sum_elem_ptr(*tilted, tr.y + tr.height, tr.x - tr.height);
+                    }
+
+                    hidfeature->rect[k].weight = (float)(feature->rect[k].weight * correctionRatio);
+
+                    if( k == 0 )
+                        area0 = tr.width * tr.height;
+                    else
+                        sum0 += hidfeature->rect[k].weight * tr.width * tr.height;
+                }
+
+                hidfeature->rect[0].weight = (float)(-sum0/area0);
+            } /* l */
+        } /* j */
+    }
+
+    __END__;
+}
+
+
+CV_INLINE
+double icvEvalHidHaarClassifier( CvHidHaarClassifier* classifier,
+                                 double variance_norm_factor,
+                                 size_t p_offset )
+{
+    int idx = 0;
+    do 
+    {
+        CvHidHaarTreeNode* node = classifier->node + idx;
+        double t = node->threshold * variance_norm_factor;
+
+        double sum = calc_sum(node->feature.rect[0],p_offset) * node->feature.rect[0].weight;
+        sum += calc_sum(node->feature.rect[1],p_offset) * node->feature.rect[1].weight;
+
+        if( node->feature.rect[2].p0 )
+            sum += calc_sum(node->feature.rect[2],p_offset) * node->feature.rect[2].weight;
+
+        idx = sum < t ? node->left : node->right;
+    }
+    while( idx > 0 );
+    return classifier->alpha[-idx];
+}
+
+
+CV_IMPL int
+cvRunHaarClassifierCascade( CvHaarClassifierCascade* _cascade,
+                            CvPoint pt, int start_stage )
+{
+    int result = -1;
+    CV_FUNCNAME("cvRunHaarClassifierCascade");
+
+    __BEGIN__;
+
+    int p_offset, pq_offset;
+    int i, j;
+    double mean, variance_norm_factor;
+    CvHidHaarClassifierCascade* cascade;
+
+    if( !CV_IS_HAAR_CLASSIFIER(_cascade) )
+        CV_ERROR( !_cascade ? CV_StsNullPtr : CV_StsBadArg, "Invalid cascade pointer" );
+
+    cascade = _cascade->hid_cascade;
+    if( !cascade )
+        CV_ERROR( CV_StsNullPtr, "Hidden cascade has not been created.\n"
+            "Use cvSetImagesForHaarClassifierCascade" );
+
+    if( pt.x < 0 || pt.y < 0 ||
+        pt.x + _cascade->real_window_size.width >= cascade->sum.width-2 ||
+        pt.y + _cascade->real_window_size.height >= cascade->sum.height-2 )
+        EXIT;
+
+    p_offset = pt.y * (cascade->sum.step/sizeof(sumtype)) + pt.x;
+    pq_offset = pt.y * (cascade->sqsum.step/sizeof(sqsumtype)) + pt.x;
+    mean = calc_sum(*cascade,p_offset)*cascade->inv_window_area;
+    variance_norm_factor = cascade->pq0[pq_offset] - cascade->pq1[pq_offset] -
+                           cascade->pq2[pq_offset] + cascade->pq3[pq_offset];
+    variance_norm_factor = variance_norm_factor*cascade->inv_window_area - mean*mean;
+    if( variance_norm_factor >= 0. )
+        variance_norm_factor = sqrt(variance_norm_factor);
+    else
+        variance_norm_factor = 1.;
+
+    if( cascade->is_tree )
+    {
+        CvHidHaarStageClassifier* ptr;
+        assert( start_stage == 0 );
+
+        result = 1;
+        ptr = cascade->stage_classifier;
+
+        while( ptr )
+        {
+            double stage_sum = 0;
+
+            for( j = 0; j < ptr->count; j++ )
+            {
+                stage_sum += icvEvalHidHaarClassifier( ptr->classifier + j,
+                    variance_norm_factor, p_offset );
+            }
+
+            if( stage_sum >= ptr->threshold - 0.0001 )
+            {
+                ptr = ptr->child;
+            }
+            else
+            {
+                while( ptr && ptr->next == NULL ) ptr = ptr->parent;
+                if( ptr == NULL )
+                {
+                    result = 0;
+                    EXIT;
+                }
+                ptr = ptr->next;
+            }
+        }
+    }
+    else if( cascade->is_stump_based )
+    {
+        for( i = start_stage; i < cascade->count; i++ )
+        {
+            double stage_sum = 0;
+
+            if( cascade->stage_classifier[i].two_rects )
+            {
+                for( j = 0; j < cascade->stage_classifier[i].count; j++ )
+                {
+                    CvHidHaarClassifier* classifier = cascade->stage_classifier[i].classifier + j;
+                    CvHidHaarTreeNode* node = classifier->node;
+                    double sum, t = node->threshold*variance_norm_factor, a, b;
+
+                    sum = calc_sum(node->feature.rect[0],p_offset) * node->feature.rect[0].weight;
+                    sum += calc_sum(node->feature.rect[1],p_offset) * node->feature.rect[1].weight;
+
+                    a = classifier->alpha[0];
+                    b = classifier->alpha[1];
+                    stage_sum += sum < t ? a : b;
+                }
+            }
+            else
+            {
+                for( j = 0; j < cascade->stage_classifier[i].count; j++ )
+                {
+                    CvHidHaarClassifier* classifier = cascade->stage_classifier[i].classifier + j;
+                    CvHidHaarTreeNode* node = classifier->node;
+                    double sum, t = node->threshold*variance_norm_factor, a, b;
+
+                    sum = calc_sum(node->feature.rect[0],p_offset) * node->feature.rect[0].weight;
+                    sum += calc_sum(node->feature.rect[1],p_offset) * node->feature.rect[1].weight;
+
+                    if( node->feature.rect[2].p0 )
+                        sum += calc_sum(node->feature.rect[2],p_offset) * node->feature.rect[2].weight;
+
+                    a = classifier->alpha[0];
+                    b = classifier->alpha[1];
+                    stage_sum += sum < t ? a : b;
+                }
+            }
+
+            if( stage_sum < cascade->stage_classifier[i].threshold - 0.0001 )
+            {
+                result = -i;
+                EXIT;
+            }
+        }
+    }
+    else
+    {
+        for( i = start_stage; i < cascade->count; i++ )
+        {
+            double stage_sum = 0;
+
+            for( j = 0; j < cascade->stage_classifier[i].count; j++ )
+            {
+                stage_sum += icvEvalHidHaarClassifier(
+                    cascade->stage_classifier[i].classifier + j,
+                    variance_norm_factor, p_offset );
+            }
+
+            if( stage_sum < cascade->stage_classifier[i].threshold - 0.0001 )
+            {
+                result = -i;
+                EXIT;
+            }
+        }
+    }
+
+    result = 1;
+
+    __END__;
+
+    return result;
+}
+
+
+static int is_equal( const void* _r1, const void* _r2, void* )
+{
+    const CvRect* r1 = (const CvRect*)_r1;
+    const CvRect* r2 = (const CvRect*)_r2;
+    int distance = cvRound(r1->width*0.2);
+
+    return r2->x <= r1->x + distance &&
+           r2->x >= r1->x - distance &&
+           r2->y <= r1->y + distance &&
+           r2->y >= r1->y - distance &&
+           r2->width <= cvRound( r1->width * 1.2 ) &&
+           cvRound( r2->width * 1.2 ) >= r1->width;
+}
+
+
+CV_IMPL CvSeq*
+cvHaarDetectObjects( const CvArr* _img,
+                     CvHaarClassifierCascade* cascade,
+                     CvMemStorage* storage, double scale_factor,
+                     int min_neighbors, int flags, CvSize min_size )
+{
+    int split_stage = 2;
+    CvMat stub, *img = (CvMat*)_img;
+    CvMat *temp = 0, *sum = 0, *tilted = 0, *sqsum = 0, *sumcanny = 0;
+    CvSeq* seq = 0;
+    CvSeq* seq2 = 0;
+    CvSeq* idx_seq = 0;
+    CvSeq* result_seq = 0;
+    CvMemStorage* temp_storage = 0;
+    CvAvgComp* comps = 0;
+    
+    CV_FUNCNAME( "cvHaarDetectObjects" );
+
+    __BEGIN__;
+
+    double factor;
+    int i, npass = 2, coi;
+    int do_canny_pruning = flags & CV_HAAR_DO_CANNY_PRUNING;
+
+    if( !CV_IS_HAAR_CLASSIFIER(cascade) )
+        CV_ERROR( !cascade ? CV_StsNullPtr : CV_StsBadArg, "Invalid classifier cascade" );
+
+    if( !storage )
+        CV_ERROR( CV_StsNullPtr, "Null storage pointer" );
+
+    CV_CALL( img = cvGetMat( img, &stub, &coi ));
+    if( coi )
+        CV_ERROR( CV_BadCOI, "COI is not supported" );
+
+    if( CV_MAT_DEPTH(img->type) != CV_8U )
+        CV_ERROR( CV_StsUnsupportedFormat, "Only 8-bit images are supported" );
+
+    temp = cvCreateMat( img->rows, img->cols, CV_8UC1 );
+    sum = cvCreateMat( img->rows + 1, img->cols + 1, CV_32SC1 );
+    sqsum = cvCreateMat( img->rows + 1, img->cols + 1, CV_64FC1 );
+    temp_storage = cvCreateChildMemStorage( storage );
+
+    if( !cascade->hid_cascade )
+        CV_CALL( icvCreateHidHaarClassifierCascade(cascade) );
+
+    if( cascade->hid_cascade->has_tilted_features )
+        tilted = cvCreateMat( img->rows + 1, img->cols + 1, CV_32SC1 );
+
+    seq = cvCreateSeq( 0, sizeof(CvSeq), sizeof(CvRect), temp_storage );
+    seq2 = cvCreateSeq( 0, sizeof(CvSeq), sizeof(CvAvgComp), temp_storage );
+    result_seq = cvCreateSeq( 0, sizeof(CvSeq), sizeof(CvAvgComp), storage );
+
+    if( min_neighbors == 0 )
+        seq = result_seq;
+
+    if( CV_MAT_CN(img->type) > 1 )
+    {
+        cvCvtColor( img, temp, CV_BGR2GRAY );
+        img = temp;
+    }
+    
+    cvIntegral( img, sum, sqsum, tilted );
+    
+    if( do_canny_pruning )
+    {
+        sumcanny = cvCreateMat( img->rows + 1, img->cols + 1, CV_32SC1 );
+        cvCanny( img, temp, 0, 50, 3 );
+        cvIntegral( temp, sumcanny );
+    }
+    
+    if( (unsigned)split_stage >= (unsigned)cascade->count ||
+        cascade->hid_cascade->is_tree )
+    {
+        split_stage = cascade->count;
+        npass = 1;
+    }
+
+    for( factor = 1; factor*cascade->orig_window_size.width < img->cols - 10 &&
+                     factor*cascade->orig_window_size.height < img->rows - 10;
+         factor *= scale_factor )
+    {
+        const double ystep = MAX( 2, factor );
+        CvSize win_size = { cvRound( cascade->orig_window_size.width * factor ),
+                            cvRound( cascade->orig_window_size.height * factor )};
+        CvRect equ_rect = { 0, 0, 0, 0 };
+        int *p0 = 0, *p1 = 0, *p2 = 0, *p3 = 0;
+        int *pq0 = 0, *pq1 = 0, *pq2 = 0, *pq3 = 0;
+        int pass, stage_offset = 0;
+        int stop_height = cvRound((img->rows - win_size.height - ystep) / ystep);
+
+        if( win_size.width < min_size.width || win_size.height < min_size.height )
+            continue;
+
+        cvSetImagesForHaarClassifierCascade( cascade, sum, sqsum, tilted, factor );
+        cvZero( temp );
+
+        if( do_canny_pruning )
+        {
+            equ_rect.x = cvRound(win_size.width*0.3);
+            equ_rect.y = cvRound(win_size.height*0.3);
+            equ_rect.width = cvRound(win_size.width*0.7);
+            equ_rect.height = cvRound(win_size.height*0.7);
+
+            p0 = (int*)(sumcanny->data.ptr + equ_rect.y*sumcanny->step) + equ_rect.x;
+            p1 = (int*)(sumcanny->data.ptr + equ_rect.y*sumcanny->step)
+                        + equ_rect.x + equ_rect.width;
+            p2 = (int*)(sumcanny->data.ptr + (equ_rect.y + equ_rect.height)*sumcanny->step) + equ_rect.x;
+            p3 = (int*)(sumcanny->data.ptr + (equ_rect.y + equ_rect.height)*sumcanny->step)
+                        + equ_rect.x + equ_rect.width;
+
+            pq0 = (int*)(sum->data.ptr + equ_rect.y*sum->step) + equ_rect.x;
+            pq1 = (int*)(sum->data.ptr + equ_rect.y*sum->step)
+                        + equ_rect.x + equ_rect.width;
+            pq2 = (int*)(sum->data.ptr + (equ_rect.y + equ_rect.height)*sum->step) + equ_rect.x;
+            pq3 = (int*)(sum->data.ptr + (equ_rect.y + equ_rect.height)*sum->step)
+                        + equ_rect.x + equ_rect.width;
+        }
+
+        cascade->hid_cascade->count = split_stage;
+
+        for( pass = 0; pass < npass; pass++ )
+        {
+#ifdef _OPENMP
+    #pragma omp parallel for shared(hid_cascade, stop_height, seq, ystep, temp, size, win_size, pass, npass, sum, p0, p1, p2 ,p3, pq0, pq1, pq2, pq3, stage_offset) 
+#endif // _OPENMP
+
+            for( int _iy = 0; _iy < stop_height; _iy++ )
+            {
+                int iy = cvRound(_iy*ystep);
+                int _ix, _xstep = 1;
+                int stop_width = cvRound((img->cols - win_size.width - 2*ystep) / ystep);
+                uchar* mask_row = temp->data.ptr + temp->step * iy;
+
+                for( _ix = 0; _ix < stop_width; _ix += _xstep )
+                {
+                    int ix = cvRound(_ix*ystep); // it really should be ystep
+                    
+                    if( pass == 0 )
+                    {
+                        int result;
+                        _xstep = 2;
+
+                        if( do_canny_pruning )
+                        {
+                            int offset;
+                            int s, sq;
+                        
+                            offset = iy*(sum->step/sizeof(p0[0])) + ix;
+                            s = p0[offset] - p1[offset] - p2[offset] + p3[offset];
+                            sq = pq0[offset] - pq1[offset] - pq2[offset] + pq3[offset];
+                            if( s < 100 || sq < 20 )
+                                continue;
+                        }
+
+                        result = cvRunHaarClassifierCascade( cascade, cvPoint(ix,iy), 0 );
+#ifdef _OPENMP
+#pragma omp critical
+#endif
+                        if( result > 0 )
+                        {
+                            if( pass < npass - 1 )
+                                mask_row[ix] = 1;
+                            else
+                            {
+                                CvRect rect = cvRect(ix,iy,win_size.width,win_size.height);
+                                cvSeqPush( seq, &rect );
+                            }
+                        }
+                        if( result < 0 )
+                            _xstep = 1;
+                    }
+                    else if( mask_row[ix] )
+                    {
+                        int result = cvRunHaarClassifierCascade( cascade, cvPoint(ix,iy),
+                                                                 stage_offset );
+#ifdef _OPENMP
+#pragma omp critical
+#endif
+                        if( result > 0 )
+                        {
+                            if( pass == npass - 1 )
+                            {
+                                CvRect rect = cvRect(ix,iy,win_size.width,win_size.height);
+                                cvSeqPush( seq, &rect );
+                            }
+                        }
+                        else
+                            mask_row[ix] = 0;
+                    }
+                }
+            }
+            stage_offset = cascade->hid_cascade->count;
+            cascade->hid_cascade->count = cascade->count;
+        }
+    }
+
+    if( min_neighbors != 0 )
+    {
+        // group retrieved rectangles in order to filter out noise 
+        int ncomp = cvSeqPartition( seq, 0, &idx_seq, is_equal, 0 );
+        CV_CALL( comps = (CvAvgComp*)cvAlloc( (ncomp+1)*sizeof(comps[0])));
+        memset( comps, 0, (ncomp+1)*sizeof(comps[0]));
+
+        // count number of neighbors
+        for( i = 0; i < seq->total; i++ )
+        {
+            CvRect r1 = *(CvRect*)cvGetSeqElem( seq, i );
+            int idx = *(int*)cvGetSeqElem( idx_seq, i );
+            assert( (unsigned)idx < (unsigned)ncomp );
+
+            comps[idx].neighbors++;
+             
+            comps[idx].rect.x += r1.x;
+            comps[idx].rect.y += r1.y;
+            comps[idx].rect.width += r1.width;
+            comps[idx].rect.height += r1.height;
+        }
+
+        // calculate average bounding box
+        for( i = 0; i < ncomp; i++ )
+        {
+            int n = comps[i].neighbors;
+            if( n >= min_neighbors )
+            {
+                CvAvgComp comp;
+                comp.rect.x = (comps[i].rect.x*2 + n)/(2*n);
+                comp.rect.y = (comps[i].rect.y*2 + n)/(2*n);
+                comp.rect.width = (comps[i].rect.width*2 + n)/(2*n);
+                comp.rect.height = (comps[i].rect.height*2 + n)/(2*n);
+                comp.neighbors = comps[i].neighbors;
+
+                cvSeqPush( seq2, &comp );
+            }
+        }
+
+        // filter out small face rectangles inside large face rectangles
+        for( i = 0; i < seq2->total; i++ )
+        {
+            CvAvgComp r1 = *(CvAvgComp*)cvGetSeqElem( seq2, i );
+            int j, flag = 1;
+
+            for( j = 0; j < seq2->total; j++ )
+            {
+                CvAvgComp r2 = *(CvAvgComp*)cvGetSeqElem( seq2, j );
+                int distance = cvRound( r2.rect.width * 0.2 );
+            
+                if( i != j &&
+                    r1.rect.x >= r2.rect.x - distance &&
+                    r1.rect.y >= r2.rect.y - distance &&
+                    r1.rect.x + r1.rect.width <= r2.rect.x + r2.rect.width + distance &&
+                    r1.rect.y + r1.rect.height <= r2.rect.y + r2.rect.height + distance &&
+                    (r2.neighbors > MAX( 3, r1.neighbors ) || r1.neighbors < 3) )
+                {
+                    flag = 0;
+                    break;
+                }
+            }
+
+            if( flag )
+            {
+                cvSeqPush( result_seq, &r1 );
+                /* cvSeqPush( result_seq, &r1.rect ); */
+            }
+        }
+    }
+
+    __END__;
+
+    cvReleaseMemStorage( &temp_storage );
+    cvReleaseMat( &sum );
+    cvReleaseMat( &sqsum );
+    cvReleaseMat( &tilted );
+    cvReleaseMat( &temp );
+    cvReleaseMat( &sumcanny );
+    cvFree( (void**)&comps );
+
+    return result_seq;
+}
+
+
+static CvHaarClassifierCascade*
+icvLoadCascadeCART( const char** input_cascade, int n, CvSize orig_window_size )
+{
+    int i;
+    CvHaarClassifierCascade* cascade = icvCreateHaarClassifierCascade(n);
+    cascade->orig_window_size = orig_window_size;
+
+    for( i = 0; i < n; i++ )
+    {
+        int j, count, l;
+        float threshold = 0;
+        const char* stage = input_cascade[i];
+        int dl = 0;
+
+        /* tree links */
+        int parent = -1;
+        int next = -1;
+
+        sscanf( stage, "%d%n", &count, &dl );
+        stage += dl;
+        
+        assert( count > 0 );
+        cascade->stage_classifier[i].count = count;
+        cascade->stage_classifier[i].classifier =
+            (CvHaarClassifier*)cvAlloc( count*sizeof(cascade->stage_classifier[i].classifier[0]));
+
+        for( j = 0; j < count; j++ )
+        {
+            CvHaarClassifier* classifier = cascade->stage_classifier[i].classifier + j;
+            int k, rects = 0;
+            char str[100];
+            
+            sscanf( stage, "%d%n", &classifier->count, &dl );
+            stage += dl;
+
+            classifier->haar_feature = (CvHaarFeature*) cvAlloc( 
+                classifier->count * ( sizeof( *classifier->haar_feature ) +
+                                      sizeof( *classifier->threshold ) +
+                                      sizeof( *classifier->left ) +
+                                      sizeof( *classifier->right ) ) +
+                (classifier->count + 1) * sizeof( *classifier->alpha ) );
+            classifier->threshold = (float*) (classifier->haar_feature+classifier->count);
+            classifier->left = (int*) (classifier->threshold + classifier->count);
+            classifier->right = (int*) (classifier->left + classifier->count);
+            classifier->alpha = (float*) (classifier->right + classifier->count);
+            
+            for( l = 0; l < classifier->count; l++ )
+            {
+                sscanf( stage, "%d%n", &rects, &dl );
+                stage += dl;
+
+                assert( rects >= 2 && rects <= CV_HAAR_FEATURE_MAX );
+
+                for( k = 0; k < rects; k++ )
+                {
+                    CvRect r;
+                    int band = 0;
+                    sscanf( stage, "%d%d%d%d%d%f%n",
+                            &r.x, &r.y, &r.width, &r.height, &band,
+                            &(classifier->haar_feature[l].rect[k].weight), &dl );
+                    stage += dl;
+                    classifier->haar_feature[l].rect[k].r = r;
+                }
+                sscanf( stage, "%s%n", str, &dl );
+                stage += dl;
+            
+                classifier->haar_feature[l].tilted = strncmp( str, "tilted", 6 ) == 0;
+            
+                for( k = rects; k < CV_HAAR_FEATURE_MAX; k++ )
+                {
+                    memset( classifier->haar_feature[l].rect + k, 0,
+                            sizeof(classifier->haar_feature[l].rect[k]) );
+                }
+                
+                sscanf( stage, "%f%d%d%n", &(classifier->threshold[l]), 
+                                       &(classifier->left[l]),
+                                       &(classifier->right[l]), &dl );
+                stage += dl;
+            }
+            for( l = 0; l <= classifier->count; l++ )
+            {
+                sscanf( stage, "%f%n", &(classifier->alpha[l]), &dl );
+                stage += dl;
+            }
+        }
+       
+        sscanf( stage, "%f%n", &threshold, &dl );
+        stage += dl;
+
+        cascade->stage_classifier[i].threshold = threshold;
+
+        /* load tree links */
+        if( sscanf( stage, "%d%d%n", &parent, &next, &dl ) != 2 )
+        {
+            parent = i - 1;
+            next = -1;
+        }
+        stage += dl;
+
+        cascade->stage_classifier[i].parent = parent;
+        cascade->stage_classifier[i].next = next;
+        cascade->stage_classifier[i].child = -1;
+
+        if( parent != -1 && cascade->stage_classifier[parent].child == -1 )
+        {
+            cascade->stage_classifier[parent].child = i;
+        }
+    }
+
+    return cascade;
+}
+
+#ifndef _MAX_PATH
+#define _MAX_PATH 1024
+#endif
+
+CV_IMPL CvHaarClassifierCascade*
+cvLoadHaarClassifierCascade( const char* directory, CvSize orig_window_size )
+{
+    const char** input_cascade = 0; 
+    CvHaarClassifierCascade *cascade = 0;
+
+    CV_FUNCNAME( "cvLoadHaarClassifierCascade" );
+
+    __BEGIN__;
+
+    int n;
+    char name[_MAX_PATH];
+
+    CvFileStorage* fs = NULL;
+
+    if( !directory )
+        CV_ERROR( CV_StsNullPtr, "Null path is passed" );
+
+    CV_CALL( fs = cvOpenFileStorage( directory, 0, CV_STORAGE_READ ) );
+    if( fs )
+    {
+        /* read the classifier from .[xy]ml file */
+        CV_CALL( cascade = (CvHaarClassifierCascade*)cvReadByName( fs, NULL, "cascade"));
+        CV_CALL( cvReleaseFileStorage( &fs ) );
+        EXIT;
+    }
+
+    /* read the classifier from directory */
+
+    /*if( !directory || strcmp( directory, "<default_face_cascade>" ) == 0 )
+    {
+        input_cascade = icvDefaultFaceCascade;
+        for( n = 0; input_cascade[n] != 0; n++ )
+            ;
+    }
+    else*/
+    {
+        int i, size = 0;
+        char* ptr;
+
+        for( n = 0; ; n++ )
+        {
+            sprintf( name, "%s/%d/AdaBoostCARTHaarClassifier.txt", directory, n );
+            FILE* f = fopen( name, "rb" );
+            if( !f )
+                break;
+            fseek( f, 0, SEEK_END );
+            size += ftell( f ) + 1;
+            fclose(f);
+        }
+
+        size += (n+1)*sizeof(char*);
+        CV_CALL( input_cascade = (const char**)cvAlloc( size ));
+        ptr = (char*)(input_cascade + n + 1);
+
+        for( i = 0; i < n; i++ )
+        {
+            sprintf( name, "%s/%d/AdaBoostCARTHaarClassifier.txt", directory, i );
+            FILE* f = fopen( name, "rb" );
+            if( !f )
+                CV_ERROR( CV_StsError, "" );
+            fseek( f, 0, SEEK_END );
+            size = ftell( f );
+            fseek( f, 0, SEEK_SET );
+            fread( ptr, 1, size, f );
+            fclose(f);
+            input_cascade[i] = ptr;
+            ptr += size;
+            *ptr++ = '\0';
+        }
+        input_cascade[n] = 0;
+    }
+
+    if( n == 0 )
+        CV_ERROR( CV_StsBadArg, "Invalid path" );
+
+    cascade = icvLoadCascadeCART( input_cascade, n, orig_window_size );
+
+    __END__;
+
+    if( input_cascade /*&& input_cascade != icvDefaultFaceCascade*/ )
+        cvFree( (void**)&input_cascade );
+
+    if( cvGetErrStatus() < 0 )
+        cvReleaseHaarClassifierCascade( &cascade );
+
+    return cascade;
+}
+
+
+CV_IMPL void
+cvReleaseHaarClassifierCascade( CvHaarClassifierCascade** cascade )
+{
+    if( cascade && *cascade )
+    {
+        int i;
+        int j;
+
+        for( i = 0; i < cascade[0]->count; i++ )
+        {
+            for( j = 0; j < cascade[0]->stage_classifier[i].count; j++ )
+            {
+                cvFree( (void**)
+                    &(cascade[0]->stage_classifier[i].classifier[j].haar_feature) );
+            }
+            cvFree( (void**) &(cascade[0]->stage_classifier[i].classifier) );
+        }
+        cvFree( (void**)&(cascade[0]->hid_cascade) );
+        cvFree( (void**)cascade );
+    }
+}
+
+
+/****************************************************************************************\
+*                                  Persistence functions                                 *
+\****************************************************************************************/
+
+/* field names */
+
+#define ICV_HAAR_SIZE_NAME            "size"
+#define ICV_HAAR_STAGES_NAME          "stages"
+#define ICV_HAAR_TREES_NAME             "trees"
+#define ICV_HAAR_FEATURE_NAME             "feature"
+#define ICV_HAAR_RECTS_NAME                 "rects"
+#define ICV_HAAR_TILTED_NAME                "tilted"
+#define ICV_HAAR_THRESHOLD_NAME           "threshold"
+#define ICV_HAAR_LEFT_NODE_NAME           "left_node"
+#define ICV_HAAR_LEFT_VAL_NAME            "left_val"
+#define ICV_HAAR_RIGHT_NODE_NAME          "right_node"
+#define ICV_HAAR_RIGHT_VAL_NAME           "right_val"
+#define ICV_HAAR_STAGE_THRESHOLD_NAME   "stage_threshold"
+#define ICV_HAAR_PARENT_NAME            "parent"
+#define ICV_HAAR_NEXT_NAME              "next"
+
+static int
+icvIsHaarClassifier( const void* struct_ptr )
+{
+    return CV_IS_HAAR_CLASSIFIER( struct_ptr );
+}
+
+static void*
+icvReadHaarClassifier( CvFileStorage* fs, CvFileNode* node )
+{
+    CvHaarClassifierCascade* cascade = NULL;
+
+    CV_FUNCNAME( "cvReadHaarClassifier" );
+
+    __BEGIN__;
+
+    char buf[256];
+    CvFileNode* seq_fn = NULL; /* sequence */
+    CvFileNode* fn = NULL;
+    CvFileNode* stages_fn = NULL;
+    CvSeqReader stages_reader;
+    int n;
+    int i, j, k, l;
+    int parent, next;
+
+    CV_CALL( stages_fn = cvGetFileNodeByName( fs, node, ICV_HAAR_STAGES_NAME ) );
+    if( !stages_fn || !CV_NODE_IS_SEQ( stages_fn->tag) )
+        CV_ERROR( CV_StsError, "Invalid stages node" );
+
+    n = stages_fn->data.seq->total;
+    CV_CALL( cascade = icvCreateHaarClassifierCascade(n) );
+
+    /* read size */
+    CV_CALL( seq_fn = cvGetFileNodeByName( fs, node, ICV_HAAR_SIZE_NAME ) );
+    if( !seq_fn || !CV_NODE_IS_SEQ( seq_fn->tag ) || seq_fn->data.seq->total != 2 )
+        CV_ERROR( CV_StsError, "size node is not a valid sequence." );
+    CV_CALL( fn = (CvFileNode*) cvGetSeqElem( seq_fn->data.seq, 0 ) );
+    if( !CV_NODE_IS_INT( fn->tag ) || fn->data.i <= 0 )
+        CV_ERROR( CV_StsError, "Invalid size node: width must be positive integer" );
+    cascade->orig_window_size.width = fn->data.i;
+    CV_CALL( fn = (CvFileNode*) cvGetSeqElem( seq_fn->data.seq, 1 ) );
+    if( !CV_NODE_IS_INT( fn->tag ) || fn->data.i <= 0 )
+        CV_ERROR( CV_StsError, "Invalid size node: height must be positive integer" );
+    cascade->orig_window_size.height = fn->data.i;
+
+    CV_CALL( cvStartReadSeq( stages_fn->data.seq, &stages_reader ) );
+    for( i = 0; i < n; ++i )
+    {
+        CvFileNode* stage_fn;
+        CvFileNode* trees_fn;
+        CvSeqReader trees_reader;
+
+        stage_fn = (CvFileNode*) stages_reader.ptr;
+        if( !CV_NODE_IS_MAP( stage_fn->tag ) )
+        {
+            sprintf( buf, "Invalid stage %d", i );
+            CV_ERROR( CV_StsError, buf );
+        }
+
+        CV_CALL( trees_fn = cvGetFileNodeByName( fs, stage_fn, ICV_HAAR_TREES_NAME ) );
+        if( !trees_fn || !CV_NODE_IS_SEQ( trees_fn->tag )
+            || trees_fn->data.seq->total <= 0 )
+        {
+            sprintf( buf, "Trees node is not a valid sequence. (stage %d)", i );
+            CV_ERROR( CV_StsError, buf );
+        }
+
+        CV_CALL( cascade->stage_classifier[i].classifier =
+            (CvHaarClassifier*) cvAlloc( trees_fn->data.seq->total
+                * sizeof( cascade->stage_classifier[i].classifier[0] ) ) );
+        for( j = 0; j < trees_fn->data.seq->total; ++j )
+        {
+            cascade->stage_classifier[i].classifier[j].haar_feature = NULL;
+        }
+        cascade->stage_classifier[i].count = trees_fn->data.seq->total;
+
+        CV_CALL( cvStartReadSeq( trees_fn->data.seq, &trees_reader ) );
+        for( j = 0; j < trees_fn->data.seq->total; ++j )
+        {
+            CvFileNode* tree_fn;
+            CvSeqReader tree_reader;
+            CvHaarClassifier* classifier;
+            int last_idx;
+
+            classifier = &cascade->stage_classifier[i].classifier[j];
+            tree_fn = (CvFileNode*) trees_reader.ptr;
+            if( !CV_NODE_IS_SEQ( tree_fn->tag ) || tree_fn->data.seq->total <= 0 )
+            {
+                sprintf( buf, "Tree node is not a valid sequence."
+                         " (stage %d, tree %d)", i, j );
+                CV_ERROR( CV_StsError, buf );
+            }
+
+            classifier->count = tree_fn->data.seq->total;
+            CV_CALL( classifier->haar_feature = (CvHaarFeature*) cvAlloc( 
+                classifier->count * ( sizeof( *classifier->haar_feature ) +
+                                      sizeof( *classifier->threshold ) +
+                                      sizeof( *classifier->left ) +
+                                      sizeof( *classifier->right ) ) +
+                (classifier->count + 1) * sizeof( *classifier->alpha ) ) );
+            classifier->threshold = (float*) (classifier->haar_feature+classifier->count);
+            classifier->left = (int*) (classifier->threshold + classifier->count);
+            classifier->right = (int*) (classifier->left + classifier->count);
+            classifier->alpha = (float*) (classifier->right + classifier->count);
+
+            CV_CALL( cvStartReadSeq( tree_fn->data.seq, &tree_reader ) );
+            for( k = 0, last_idx = 0; k < tree_fn->data.seq->total; ++k )
+            {
+                CvFileNode* node_fn;
+                CvFileNode* feature_fn;
+                CvFileNode* rects_fn;
+                CvSeqReader rects_reader;
+
+                node_fn = (CvFileNode*) tree_reader.ptr;
+                if( !CV_NODE_IS_MAP( node_fn->tag ) )
+                {
+                    sprintf( buf, "Tree node %d is not a valid map. (stage %d, tree %d)",
+                             k, i, j );
+                    CV_ERROR( CV_StsError, buf );
+                }
+                CV_CALL( feature_fn = cvGetFileNodeByName( fs, node_fn,
+                    ICV_HAAR_FEATURE_NAME ) );
+                if( !feature_fn || !CV_NODE_IS_MAP( feature_fn->tag ) )
+                {
+                    sprintf( buf, "Feature node is not a valid map. "
+                             "(stage %d, tree %d, node %d)", i, j, k );
+                    CV_ERROR( CV_StsError, buf );
+                }
+                CV_CALL( rects_fn = cvGetFileNodeByName( fs, feature_fn,
+                    ICV_HAAR_RECTS_NAME ) );
+                if( !rects_fn || !CV_NODE_IS_SEQ( rects_fn->tag )
+                    || rects_fn->data.seq->total < 1
+                    || rects_fn->data.seq->total > CV_HAAR_FEATURE_MAX )
+                {
+                    sprintf( buf, "Rects node is not a valid sequence. "
+                             "(stage %d, tree %d, node %d)", i, j, k );
+                    CV_ERROR( CV_StsError, buf );
+                }
+                CV_CALL( cvStartReadSeq( rects_fn->data.seq, &rects_reader ) );
+                for( l = 0; l < rects_fn->data.seq->total; ++l )
+                {
+                    CvFileNode* rect_fn;
+                    CvRect r;
+
+                    rect_fn = (CvFileNode*) rects_reader.ptr;
+                    if( !CV_NODE_IS_SEQ( rect_fn->tag ) || rect_fn->data.seq->total != 5 )
+                    {
+                        sprintf( buf, "Rect %d is not a valid sequence. "
+                                 "(stage %d, tree %d, node %d)", l, i, j, k );
+                        CV_ERROR( CV_StsError, buf );
+                    }
+                    
+                    fn = CV_SEQ_ELEM( rect_fn->data.seq, CvFileNode, 0 );
+                    if( !CV_NODE_IS_INT( fn->tag ) || fn->data.i < 0 )
+                    {
+                        sprintf( buf, "x coordinate must be non-negative integer. "
+                                 "(stage %d, tree %d, node %d, rect %d)", i, j, k, l );
+                        CV_ERROR( CV_StsError, buf );
+                    }
+                    r.x = fn->data.i;
+                    fn = CV_SEQ_ELEM( rect_fn->data.seq, CvFileNode, 1 );
+                    if( !CV_NODE_IS_INT( fn->tag ) || fn->data.i < 0 )
+                    {
+                        sprintf( buf, "y coordinate must be non-negative integer. "
+                                 "(stage %d, tree %d, node %d, rect %d)", i, j, k, l );
+                        CV_ERROR( CV_StsError, buf );
+                    }
+                    r.y = fn->data.i;
+                    fn = CV_SEQ_ELEM( rect_fn->data.seq, CvFileNode, 2 );
+                    if( !CV_NODE_IS_INT( fn->tag ) || fn->data.i <= 0
+                        || r.x + fn->data.i > cascade->orig_window_size.width )
+                    {
+                        sprintf( buf, "width must be positive integer and "
+                                 "(x + width) must not exceed window width. "
+                                 "(stage %d, tree %d, node %d, rect %d)", i, j, k, l );
+                        CV_ERROR( CV_StsError, buf );
+                    }
+                    r.width = fn->data.i;
+                    fn = CV_SEQ_ELEM( rect_fn->data.seq, CvFileNode, 3 );
+                    if( !CV_NODE_IS_INT( fn->tag ) || fn->data.i <= 0
+                        || r.y + fn->data.i > cascade->orig_window_size.height )
+                    {
+                        sprintf( buf, "height must be positive integer and "
+                                 "(y + height) must not exceed window height. "
+                                 "(stage %d, tree %d, node %d, rect %d)", i, j, k, l );
+                        CV_ERROR( CV_StsError, buf );
+                    }
+                    r.height = fn->data.i;
+                    fn = CV_SEQ_ELEM( rect_fn->data.seq, CvFileNode, 4 );
+                    if( !CV_NODE_IS_REAL( fn->tag ) )
+                    {
+                        sprintf( buf, "weight must be real number. "
+                                 "(stage %d, tree %d, node %d, rect %d)", i, j, k, l );
+                        CV_ERROR( CV_StsError, buf );
+                    }
+
+                    classifier->haar_feature[k].rect[l].weight = (float) fn->data.f;
+                    classifier->haar_feature[k].rect[l].r = r;
+
+                    CV_NEXT_SEQ_ELEM( sizeof( *rect_fn ), rects_reader );
+                } /* for each rect */
+                for( l = rects_fn->data.seq->total; l < CV_HAAR_FEATURE_MAX; ++l )
+                {
+                    classifier->haar_feature[k].rect[l].weight = 0;
+                    classifier->haar_feature[k].rect[l].r = cvRect( 0, 0, 0, 0 );
+                }
+
+                CV_CALL( fn = cvGetFileNodeByName( fs, feature_fn, ICV_HAAR_TILTED_NAME));
+                if( !fn || !CV_NODE_IS_INT( fn->tag ) )
+                {
+                    sprintf( buf, "tilted must be 0 or 1. "
+                             "(stage %d, tree %d, node %d)", i, j, k );
+                    CV_ERROR( CV_StsError, buf );
+                }
+                classifier->haar_feature[k].tilted = ( fn->data.i != 0 );
+                CV_CALL( fn = cvGetFileNodeByName( fs, node_fn, ICV_HAAR_THRESHOLD_NAME));
+                if( !fn || !CV_NODE_IS_REAL( fn->tag ) )
+                {
+                    sprintf( buf, "threshold must be real number. "
+                             "(stage %d, tree %d, node %d)", i, j, k );
+                    CV_ERROR( CV_StsError, buf );
+                }
+                classifier->threshold[k] = (float) fn->data.f;
+                CV_CALL( fn = cvGetFileNodeByName( fs, node_fn, ICV_HAAR_LEFT_NODE_NAME));
+                if( fn )
+                {
+                    if( !CV_NODE_IS_INT( fn->tag ) || fn->data.i <= k
+                        || fn->data.i >= tree_fn->data.seq->total )
+                    {
+                        sprintf( buf, "left node must be valid node number. "
+                                 "(stage %d, tree %d, node %d)", i, j, k );
+                        CV_ERROR( CV_StsError, buf );
+                    }
+                    /* left node */
+                    classifier->left[k] = fn->data.i;
+                }
+                else
+                {
+                    CV_CALL( fn = cvGetFileNodeByName( fs, node_fn,
+                        ICV_HAAR_LEFT_VAL_NAME ) );
+                    if( !fn )
+                    {
+                        sprintf( buf, "left node or left value must be specified. "
+                                 "(stage %d, tree %d, node %d)", i, j, k );
+                        CV_ERROR( CV_StsError, buf );
+                    }
+                    if( !CV_NODE_IS_REAL( fn->tag ) )
+                    {
+                        sprintf( buf, "left value must be real number. "
+                                 "(stage %d, tree %d, node %d)", i, j, k );
+                        CV_ERROR( CV_StsError, buf );
+                    }
+                    /* left value */
+                    if( last_idx >= classifier->count + 1 )
+                    {
+                        sprintf( buf, "Tree structure is broken: too many values. "
+                                 "(stage %d, tree %d, node %d)", i, j, k );
+                        CV_ERROR( CV_StsError, buf );
+                    }
+                    classifier->left[k] = -last_idx;
+                    classifier->alpha[last_idx++] = (float) fn->data.f;
+                }
+                CV_CALL( fn = cvGetFileNodeByName( fs, node_fn,ICV_HAAR_RIGHT_NODE_NAME));
+                if( fn )
+                {
+                    if( !CV_NODE_IS_INT( fn->tag ) || fn->data.i <= k
+                        || fn->data.i >= tree_fn->data.seq->total )
+                    {
+                        sprintf( buf, "right node must be valid node number. "
+                                 "(stage %d, tree %d, node %d)", i, j, k );
+                        CV_ERROR( CV_StsError, buf );
+                    }
+                    /* right node */
+                    classifier->right[k] = fn->data.i;
+                }
+                else
+                {
+                    CV_CALL( fn = cvGetFileNodeByName( fs, node_fn,
+                        ICV_HAAR_RIGHT_VAL_NAME ) );
+                    if( !fn )
+                    {
+                        sprintf( buf, "right node or right value must be specified. "
+                                 "(stage %d, tree %d, node %d)", i, j, k );
+                        CV_ERROR( CV_StsError, buf );
+                    }
+                    if( !CV_NODE_IS_REAL( fn->tag ) )
+                    {
+                        sprintf( buf, "right value must be real number. "
+                                 "(stage %d, tree %d, node %d)", i, j, k );
+                        CV_ERROR( CV_StsError, buf );
+                    }
+                    /* right value */
+                    if( last_idx >= classifier->count + 1 )
+                    {
+                        sprintf( buf, "Tree structure is broken: too many values. "
+                                 "(stage %d, tree %d, node %d)", i, j, k );
+                        CV_ERROR( CV_StsError, buf );
+                    }
+                    classifier->right[k] = -last_idx;
+                    classifier->alpha[last_idx++] = (float) fn->data.f;
+                }
+
+                CV_NEXT_SEQ_ELEM( sizeof( *node_fn ), tree_reader );
+            } /* for each node */
+            if( last_idx != classifier->count + 1 )
+            {
+                sprintf( buf, "Tree structure is broken: too few values. "
+                         "(stage %d, tree %d)", i, j );
+                CV_ERROR( CV_StsError, buf );
+            }
+
+            CV_NEXT_SEQ_ELEM( sizeof( *tree_fn ), trees_reader );
+        } /* for each tree */
+
+        CV_CALL( fn = cvGetFileNodeByName( fs, stage_fn, ICV_HAAR_STAGE_THRESHOLD_NAME));
+        if( !fn || !CV_NODE_IS_REAL( fn->tag ) )
+        {
+            sprintf( buf, "stage threshold must be real number. (stage %d)", i );
+            CV_ERROR( CV_StsError, buf );
+        }
+        cascade->stage_classifier[i].threshold = (float) fn->data.f;
+
+        parent = i - 1;
+        next = -1;
+
+        CV_CALL( fn = cvGetFileNodeByName( fs, stage_fn, ICV_HAAR_PARENT_NAME ) );
+        if( !fn || !CV_NODE_IS_INT( fn->tag )
+            || fn->data.i < -1 || fn->data.i >= cascade->stage_classifier[i].count )
+        {
+            sprintf( buf, "parent must be integer number. (stage %d)", i );
+            CV_ERROR( CV_StsError, buf );
+        }
+        parent = fn->data.i;
+        CV_CALL( fn = cvGetFileNodeByName( fs, stage_fn, ICV_HAAR_NEXT_NAME ) );
+        if( !fn || !CV_NODE_IS_INT( fn->tag )
+            || fn->data.i < -1 || fn->data.i >= cascade->stage_classifier[i].count )
+        {
+            sprintf( buf, "next must be integer number. (stage %d)", i );
+            CV_ERROR( CV_StsError, buf );
+        }
+        next = fn->data.i;
+
+        cascade->stage_classifier[i].parent = parent;
+        cascade->stage_classifier[i].next = next;
+        cascade->stage_classifier[i].child = -1;
+
+        if( parent != -1 && cascade->stage_classifier[parent].child == -1 )
+        {
+            cascade->stage_classifier[parent].child = i;
+        }
+        
+        CV_NEXT_SEQ_ELEM( sizeof( *stage_fn ), stages_reader );
+    } /* for each stage */
+
+    __END__;
+
+    if( cvGetErrStatus() < 0 )
+    {
+        cvReleaseHaarClassifierCascade( &cascade );
+        cascade = NULL;
+    }
+
+    return cascade;
+}
+
+static void
+icvWriteHaarClassifier( CvFileStorage* fs, const char* name, const void* struct_ptr,
+                        CvAttrList attributes )
+{
+    CV_FUNCNAME( "cvWriteHaarClassifier" );
+
+    __BEGIN__;
+
+    int i, j, k, l;
+    char buf[256];
+    const CvHaarClassifierCascade* cascade = (const CvHaarClassifierCascade*) struct_ptr;
+
+    /* TODO: parameters check */
+
+    CV_CALL( cvStartWriteStruct( fs, name, CV_NODE_MAP, CV_TYPE_NAME_HAAR, attributes ) );
+    
+    CV_CALL( cvStartWriteStruct( fs, ICV_HAAR_SIZE_NAME, CV_NODE_SEQ | CV_NODE_FLOW ) );
+    CV_CALL( cvWriteInt( fs, NULL, cascade->orig_window_size.width ) );
+    CV_CALL( cvWriteInt( fs, NULL, cascade->orig_window_size.height ) );
+    CV_CALL( cvEndWriteStruct( fs ) ); /* size */
+    
+    CV_CALL( cvStartWriteStruct( fs, ICV_HAAR_STAGES_NAME, CV_NODE_SEQ ) );    
+    for( i = 0; i < cascade->count; ++i )
+    {
+        CV_CALL( cvStartWriteStruct( fs, NULL, CV_NODE_MAP ) );
+        sprintf( buf, "stage %d", i );
+        CV_CALL( cvWriteComment( fs, buf, 1 ) );
+        
+        CV_CALL( cvStartWriteStruct( fs, ICV_HAAR_TREES_NAME, CV_NODE_SEQ ) );
+
+        for( j = 0; j < cascade->stage_classifier[i].count; ++j )
+        {
+            CvHaarClassifier* tree = &cascade->stage_classifier[i].classifier[j];
+
+            CV_CALL( cvStartWriteStruct( fs, NULL, CV_NODE_SEQ ) );
+            sprintf( buf, "tree %d", j );
+            CV_CALL( cvWriteComment( fs, buf, 1 ) );
+
+            for( k = 0; k < tree->count; ++k )
+            {
+                CvHaarFeature* feature = &tree->haar_feature[k];
+
+                CV_CALL( cvStartWriteStruct( fs, NULL, CV_NODE_MAP ) );
+                if( k )
+                {
+                    sprintf( buf, "node %d", k );
+                }
+                else
+                {
+                    sprintf( buf, "root node" );
+                }
+                CV_CALL( cvWriteComment( fs, buf, 1 ) );
+
+                CV_CALL( cvStartWriteStruct( fs, ICV_HAAR_FEATURE_NAME, CV_NODE_MAP ) );
+                
+                CV_CALL( cvStartWriteStruct( fs, ICV_HAAR_RECTS_NAME, CV_NODE_SEQ ) );
+                for( l = 0; l < CV_HAAR_FEATURE_MAX && feature->rect[l].weight != 0; ++l )
+                {
+                    CV_CALL( cvStartWriteStruct( fs, NULL, CV_NODE_SEQ | CV_NODE_FLOW ) );
+                    CV_CALL( cvWriteInt(  fs, NULL, feature->rect[l].r.x ) );
+                    CV_CALL( cvWriteInt(  fs, NULL, feature->rect[l].r.y ) );
+                    CV_CALL( cvWriteInt(  fs, NULL, feature->rect[l].r.width ) );
+                    CV_CALL( cvWriteInt(  fs, NULL, feature->rect[l].r.height ) );
+                    CV_CALL( cvWriteReal( fs, NULL, feature->rect[l].weight ) );
+                    CV_CALL( cvEndWriteStruct( fs ) ); /* rect */
+                }
+                CV_CALL( cvEndWriteStruct( fs ) ); /* rects */
+                CV_CALL( cvWriteInt( fs, ICV_HAAR_TILTED_NAME, feature->tilted ) );
+                CV_CALL( cvEndWriteStruct( fs ) ); /* feature */
+                
+                CV_CALL( cvWriteReal( fs, ICV_HAAR_THRESHOLD_NAME, tree->threshold[k]) );
+
+                if( tree->left[k] > 0 )
+                {
+                    CV_CALL( cvWriteInt( fs, ICV_HAAR_LEFT_NODE_NAME, tree->left[k] ) );
+                }
+                else
+                {
+                    CV_CALL( cvWriteReal( fs, ICV_HAAR_LEFT_VAL_NAME,
+                        tree->alpha[-tree->left[k]] ) );
+                }
+
+                if( tree->right[k] > 0 )
+                {
+                    CV_CALL( cvWriteInt( fs, ICV_HAAR_RIGHT_NODE_NAME, tree->right[k] ) );
+                }
+                else
+                {
+                    CV_CALL( cvWriteReal( fs, ICV_HAAR_RIGHT_VAL_NAME,
+                        tree->alpha[-tree->right[k]] ) );
+                }
+
+                CV_CALL( cvEndWriteStruct( fs ) ); /* split */
+            }
+
+            CV_CALL( cvEndWriteStruct( fs ) ); /* tree */
+        }
+
+        CV_CALL( cvEndWriteStruct( fs ) ); /* trees */
+
+        CV_CALL( cvWriteReal( fs, ICV_HAAR_STAGE_THRESHOLD_NAME,
+                              cascade->stage_classifier[i].threshold) );
+
+        CV_CALL( cvWriteInt( fs, ICV_HAAR_PARENT_NAME,
+                              cascade->stage_classifier[i].parent ) );
+        CV_CALL( cvWriteInt( fs, ICV_HAAR_NEXT_NAME,
+                              cascade->stage_classifier[i].next ) );
+
+        CV_CALL( cvEndWriteStruct( fs ) ); /* stage */
+    } /* for each stage */
+    
+    CV_CALL( cvEndWriteStruct( fs ) ); /* stages */
+    CV_CALL( cvEndWriteStruct( fs ) ); /* root */
+
+    __END__;
+}
+
+static void*
+icvCloneHaarClassifier( const void* struct_ptr )
+{
+    CvHaarClassifierCascade* cascade = NULL;
+
+    CV_FUNCNAME( "cvCloneHaarClassifier" );
+
+    __BEGIN__;
+
+    int i, j, k, n;
+    const CvHaarClassifierCascade* cascade_src =
+        (const CvHaarClassifierCascade*) struct_ptr;
+
+    n = cascade_src->count;
+    CV_CALL( cascade = icvCreateHaarClassifierCascade(n) );
+    cascade->orig_window_size = cascade_src->orig_window_size;
+
+    for( i = 0; i < n; ++i )
+    {
+        cascade->stage_classifier[i].parent = cascade_src->stage_classifier[i].parent;
+        cascade->stage_classifier[i].next = cascade_src->stage_classifier[i].next;
+        cascade->stage_classifier[i].child = cascade_src->stage_classifier[i].child;
+        cascade->stage_classifier[i].threshold = cascade_src->stage_classifier[i].threshold;
+
+        cascade->stage_classifier[i].count = 0;
+        CV_CALL( cascade->stage_classifier[i].classifier =
+            (CvHaarClassifier*) cvAlloc( cascade_src->stage_classifier[i].count
+                * sizeof( cascade->stage_classifier[i].classifier[0] ) ) );
+        
+        cascade->stage_classifier[i].count = cascade_src->stage_classifier[i].count;
+
+        for( j = 0; j < cascade->stage_classifier[i].count; ++j )
+        {
+            cascade->stage_classifier[i].classifier[j].haar_feature = NULL;
+        }
+
+        for( j = 0; j < cascade->stage_classifier[i].count; ++j )
+        {
+            const CvHaarClassifier* classifier_src = 
+                &cascade_src->stage_classifier[i].classifier[j];
+            CvHaarClassifier* classifier = 
+                &cascade->stage_classifier[i].classifier[j];
+
+            classifier->count = classifier_src->count;
+            CV_CALL( classifier->haar_feature = (CvHaarFeature*) cvAlloc( 
+                classifier->count * ( sizeof( *classifier->haar_feature ) +
+                                      sizeof( *classifier->threshold ) +
+                                      sizeof( *classifier->left ) +
+                                      sizeof( *classifier->right ) ) +
+                (classifier->count + 1) * sizeof( *classifier->alpha ) ) );
+            classifier->threshold = (float*) (classifier->haar_feature+classifier->count);
+            classifier->left = (int*) (classifier->threshold + classifier->count);
+            classifier->right = (int*) (classifier->left + classifier->count);
+            classifier->alpha = (float*) (classifier->right + classifier->count);
+            for( k = 0; k < classifier->count; ++k )
+            {
+                classifier->haar_feature[k] = classifier_src->haar_feature[k];
+                classifier->threshold[k] = classifier_src->threshold[k];
+                classifier->left[k] = classifier_src->left[k];
+                classifier->right[k] = classifier_src->right[k];
+                classifier->alpha[k] = classifier_src->alpha[k];
+            }
+            classifier->alpha[classifier->count] = 
+                classifier_src->alpha[classifier->count];
+        }
+    }
+
+    __END__;
+
+    return cascade;
+}
+
+static int
+icvRegisterHaarClassifierType()
+{
+    CV_FUNCNAME( "icvRegisterHaarClassifierType" );
+
+    __BEGIN__;
+
+    CvTypeInfo info;
+
+    info.header_size = sizeof( info );
+    info.is_instance = icvIsHaarClassifier;
+    info.release = (CvReleaseFunc) cvReleaseHaarClassifierCascade;
+    info.read = icvReadHaarClassifier;
+    info.write = icvWriteHaarClassifier;
+    info.clone = icvCloneHaarClassifier;
+    info.type_name = CV_TYPE_NAME_HAAR;
+    CV_CALL( cvRegisterType( &info ) );
+
+    __END__;
+
+    return 1;
+}
+
+static int icv_register_haar_classifier_type = icvRegisterHaarClassifierType();
+
+/* End of file. */
index d0435f65f6855782e165d548aa6cff2d1809445c..df9c7e4fe433d8f7e1402b10eba76c5bbb392080 100644 (file)
@@ -63,7 +63,7 @@ cvCreateHist( int dims, int *sizes, CvHistType type, float** ranges, int uniform
     if( type == CV_HIST_ARRAY )
     {
         CV_CALL( hist->bins = cvInitMatNDHeader( &hist->mat, dims, sizes,
-                                                  CV_HIST_DEFAULT_TYPE ));
+                                                 CV_HIST_DEFAULT_TYPE ));
         CV_CALL( cvCreateData( hist->bins ));
     }
     else if( type == CV_HIST_SPARSE )
@@ -160,6 +160,8 @@ cvReleaseHist( CvHistogram **hist )
         
         if( temp->thresh2 )
             cvFree( (void**)&temp->thresh2 );
+
+        cvFree( (void**)&temp );
     }
 
     __END__;
@@ -396,7 +398,7 @@ cvGetMinMaxHistValue( const CvHistogram* hist,
 CV_IMPL double
 cvCompareHist( const CvHistogram* hist1,
                const CvHistogram* hist2,
-               CvCompareMethod method )
+               int method )
 {
     double _result = -1;
     
@@ -492,7 +494,7 @@ cvCompareHist( const CvHistogram* hist1,
         CvSparseMatIterator iterator;
         CvSparseNode *node1, *node2;
 
-        if( mat1->total > mat2->total )
+        if( mat1->heap->active_count > mat2->heap->active_count )
         {
             CvSparseMat* t;
             CV_SWAP( mat1, mat2, t );
@@ -505,8 +507,7 @@ cvCompareHist( const CvHistogram* hist1,
                  node1 != 0; node1 = cvGetNextSparseNode( &iterator ))
             {
                 double v1 = *(float*)CV_NODE_VAL(mat1,node1);
-                uchar* node2 = icvGetNodePtr( mat2, CV_NODE_IDX(mat1,node1),
-                                              0, 0, &node1->hashval );
+                uchar* node2 = cvPtrND( mat2, CV_NODE_IDX(mat1,node1), 0, 0, &node1->hashval );
                 if( !node2 )
                     result += v1;
                 else
@@ -523,11 +524,8 @@ cvCompareHist( const CvHistogram* hist1,
                  node2 != 0; node2 = cvGetNextSparseNode( &iterator ))
             {
                 double v2 = *(float*)CV_NODE_VAL(mat2,node2);
-                if( !icvGetNodePtr( mat1, CV_NODE_IDX(mat2,node2),
-                                    0, 0, &node2->hashval ))
-                {
+                if( !cvPtrND( mat1, CV_NODE_IDX(mat2,node2), 0, 0, &node2->hashval ))
                     result += v2;
-                }
             }
             break;
         case CV_COMP_CORREL:
@@ -541,8 +539,7 @@ cvCompareHist( const CvHistogram* hist1,
                      node1 != 0; node1 = cvGetNextSparseNode( &iterator ))
                 {
                     double v1 = *(float*)CV_NODE_VAL(mat1,node1);
-                    uchar* node2 = icvGetNodePtr( mat2, CV_NODE_IDX(mat1,node1),
-                                                  0, 0, &node1->hashval );
+                    uchar* node2 = cvPtrND( mat2, CV_NODE_IDX(mat1,node1), 0, 0, &node1->hashval );
                     if( node2 )
                     {
                         double v2 = *(float*)node2;
@@ -571,8 +568,7 @@ cvCompareHist( const CvHistogram* hist1,
                      node1 != 0; node1 = cvGetNextSparseNode( &iterator ))
                 {
                     float v1 = *(float*)CV_NODE_VAL(mat1,node1);
-                    uchar* node2 = icvGetNodePtr( mat2, CV_NODE_IDX(mat1,node1),
-                                                  0, 0, &node1->hashval );
+                    uchar* node2 = cvPtrND( mat2, CV_NODE_IDX(mat1,node1), 0, 0, &node1->hashval );
                     if( node2 )
                     {
                         float v2 = *(float*)node2;
@@ -830,7 +826,7 @@ static CvStatus CV_STDCALL
 
     dims = cvGetDims( hist->bins, histsize );
 
-    tab = (int*)alloca( dims*256*sizeof(int));
+    tab = (int*)cvStackAlloc( dims*256*sizeof(int));
     status = icvCalcHistLookupTables8x( hist, 0, 256, dims,
                                         histsize, tab );
 
@@ -1034,7 +1030,7 @@ static CvStatus CV_STDCALL
                     }
                     if( i == dims )
                     {
-                        int* bin = (int*)icvGetNodePtr( mat, node_idx, 0, 1 );
+                        int* bin = (int*)cvPtrND( mat, node_idx, 0, 1 );
                         bin[0]++;
                     }
                 }
@@ -1054,7 +1050,7 @@ static CvStatus CV_STDCALL
                         }
                         if( i == dims )
                         {
-                            int* bin = (int*)icvGetNodePtr( mat, node_idx, 0, 1 );
+                            int* bin = (int*)cvPtrND( mat, node_idx, 0, 1, 0 );
                             bin[0]++;
                         }
                     }
@@ -1303,7 +1299,7 @@ static CvStatus CV_STDCALL
                         }
                         if( i == dims )
                         {
-                            int* bin = (int*)icvGetNodePtr( mat, node_idx, 0, 1 );
+                            int* bin = (int*)cvPtrND( mat, node_idx, 0, 1, 0 );
                             bin[0]++;
                         }
                     }
@@ -1331,7 +1327,7 @@ static CvStatus CV_STDCALL
                         }
                         if( i == dims )
                         {
-                            int* bin = (int*)icvGetNodePtr( mat, node_idx, 0, 1 );
+                            int* bin = (int*)cvPtrND( mat, node_idx, 0, 1, 0 );
                             bin[0]++;
                         }
                     }
@@ -1420,7 +1416,7 @@ cvCalcArrHist( CvArr** img, CvHistogram* hist,
         cont_flag &= mat->type;
     }
 
-    size = icvGetMatSize(mat0);
+    size = cvGetMatSize(mat0);
     if( CV_IS_MAT_CONT( cont_flag ))
     {
         size.width *= size.height;
@@ -1510,7 +1506,7 @@ static CvStatus CV_STDCALL
 
     dims = cvGetDims( hist->bins, histsize );
 
-    tab = (int*)alloca( dims*256*sizeof(int));
+    tab = (int*)cvStackAlloc( dims*256*sizeof(int));
     status = icvCalcHistLookupTables8x( hist, 0, 256, dims, histsize, tab );
     if( status < 0 )
         return status;
@@ -1530,7 +1526,7 @@ static CvStatus CV_STDCALL
 
         if( dims > 1 && total <= small_hist_size && CV_IS_MAT_CONT(mat->type))
         {
-            buffer = (uchar*)icvAlloc(total);
+            buffer = (uchar*)cvAlloc(total);
             if( !buffer )
                 return CV_OUTOFMEM_ERR;
             for( i = 0; i < total; i++ )
@@ -1719,7 +1715,7 @@ static CvStatus CV_STDCALL
             }
         }
 
-        icvFree( (void**)&buffer );
+        cvFree( (void**)&buffer );
     }
     else
     {
@@ -1741,7 +1737,7 @@ static CvStatus CV_STDCALL
                 }
                 if( i == dims )
                 {
-                    float* bin = (float*)icvGetNodePtr( mat, node_idx, 0, 1 );
+                    float* bin = (float*)cvPtrND( mat, node_idx, 0, 1, 0 );
                     v = cvRound(bin[0]);
                     v = CV_CAST_8U(v);
                 }
@@ -1946,7 +1942,7 @@ static CvStatus CV_STDCALL
                     }
                     if( i == dims )
                     {
-                        float* bin = (float*)icvGetNodePtr( mat, node_idx, 0, 1 );
+                        float* bin = (float*)cvPtrND( mat, node_idx, 0, 1, 0 );
                         dst[x] = bin[0];
                     }
                     else
@@ -1973,7 +1969,7 @@ static CvStatus CV_STDCALL
                     }
                     if( i == dims )
                     {
-                        float* bin = (float*)icvGetNodePtr( mat, node_idx, 0, 1 );
+                        float* bin = (float*)cvPtrND( mat, node_idx, 0, 1, 0 );
                         dst[x] = bin[0];
                     }
                     else
@@ -2048,7 +2044,7 @@ cvCalcArrBackProject( CvArr** img, CvArr* dst, const CvHistogram* hist )
         }
     }
 
-    size = icvGetMatSize(mat0);
+    size = cvGetMatSize(mat0);
     if( CV_IS_MAT_CONT( cont_flag ))
     {
         size.width *= size.height;
@@ -2081,7 +2077,7 @@ cvCalcArrBackProject( CvArr** img, CvArr* dst, const CvHistogram* hist )
 
 CV_IMPL void
 cvCalcArrBackProjectPatch( CvArr** arr, CvArr* dst, CvSize range, CvHistogram* hist,
-                           CvCompareMethod method, double norm_factor )
+                           int method, double norm_factor )
 {
     CvHistogram* model = 0;
     
@@ -2122,7 +2118,7 @@ cvCalcArrBackProjectPatch( CvArr** arr, CvArr* dst, CvSize range, CvHistogram* h
     if( CV_MAT_TYPE( dstmat->type ) != CV_32FC1 )
         CV_ERROR( CV_StsUnsupportedFormat, "Resultant image must have 32fC1 type" );
 
-    size = icvGetMatSize(dstmat);
+    size = cvGetMatSize(dstmat);
     roi.coi = 0;
 
     for( y = 0; y < size.height; y++ )
@@ -2221,9 +2217,9 @@ cvCalcProbDensity( const CvHistogram* hist, const CvHistogram* hist_mask,
     {
         CvArr* arrs[] = { hist->bins, hist_mask->bins, hist_dens->bins };
         CvMatND stubs[3];
-        CvMatNDIterator iterator;
+        CvNArrayIterator iterator;
 
-        CV_CALL( icvPrepareArrayOp( 3, arrs, 0, stubs, &iterator ));
+        CV_CALL( cvInitNArrayIterator( 3, arrs, 0, stubs, &iterator ));
 
         if( CV_MAT_TYPE(iterator.hdr[0]->type) != CV_32FC1 )
             CV_ERROR( CV_StsUnsupportedFormat, "All histograms must have 32fC1 type" );
@@ -2248,7 +2244,7 @@ cvCalcProbDensity( const CvHistogram* hist, const CvHistogram* hist_mask,
                     dstdata[i] = (float)0;
             }
         }
-        while( icvNextMatNDSlice( &iterator ));
+        while( cvNextNArraySlice( &iterator ));
     }
 
     __END__;
index 406f27fcfacbb97207ef0efcef34b78972cc7f37..267a8c4959216c55b12c9e48af2d85319614d937 100644 (file)
@@ -44,7 +44,7 @@
 
 #define halfPi ((float)(CV_PI*0.5))
 #define Pi     ((float)CV_PI)
-#define a0  -4.172325e-7f   /*(-(float)0x7)/((float)0x1000000); */
+#define a0  0 /*-4.172325e-7f*/   /*(-(float)0x7)/((float)0x1000000); */
 #define a1 1.000025f        /*((float)0x1922253)/((float)0x1000000)*2/Pi; */
 #define a2 -2.652905e-4f    /*(-(float)0x2ae6)/((float)0x1000000)*4/(Pi*Pi); */
 #define a3 -0.165624f       /*(-(float)0xa45511)/((float)0x1000000)*8/(Pi*Pi*Pi); */
 #define a6 -9.580378e-4f    /*(-(float)0x3af27)/((float)0x1000000)*64/(Pi*Pi*Pi*Pi*Pi*Pi); */
 
 #define _sin(x) ((((((a6*(x) + a5)*(x) + a4)*(x) + a3)*(x) + a2)*(x) + a1)*(x) + a0)
-
-CV_FORCE_INLINE float
-_cos( float x )
-{
-    float temp = halfPi - x;
-
-    return _sin( temp );
-}
+#define _cos(x) _sin(halfPi - (x))
 
 /****************************************************************************************\
 *                               Classical Hough Transform                                *
@@ -109,9 +102,9 @@ static  CvStatus  icvHoughLines_8uC1R( uchar* image, int step, CvSize size,
     numangle = (int) (Pi / theta);
     numrho = (int) (((width + height) * 2 + 1) / rho);
 
-    accum = (int*)icvAlloc( sizeof(accum[0]) * numangle * numrho );
-    tabSin = (float*)icvAlloc( sizeof(float) * numangle );
-    tabCos = (float*)icvAlloc( sizeof(float) * numangle );
+    accum = (int*)cvAlloc( sizeof(accum[0]) * numangle * numrho );
+    tabSin = (float*)cvAlloc( sizeof(float) * numangle );
+    tabCos = (float*)cvAlloc( sizeof(float) * numangle );
     memset( accum, 0, sizeof(accum[0]) * numangle * numrho );
 
     if( tabSin == 0 || tabCos == 0 || accum == 0 )
@@ -120,21 +113,20 @@ static  CvStatus  icvHoughLines_8uC1R( uchar* image, int step, CvSize size,
     /* May change using mirroring */
     for( ang = 0, n = 0; n < numangle; ang += theta, n++ )
     {
-        tabSin[n] = (float)sin( ang );
-        tabCos[n] = (float)cos( ang );
+        tabSin[n] = (float)(sin( ang ) * irho);
+        tabCos[n] = (float)(cos( ang ) * irho);
     }
 
-    /* May be optimized ! */
-    for( i = 0; i < width; i++ )
+    for( j = 0; j < height; j++ )
     {
-        for( j = 0; j < height; j++ )
+        for( i = 0; i < width; i++ )
         {
             /* Get (i,j) pixel from image */
             if( image[j * step + i] != 0 )
             {
                 for( n = 0; n < numangle; n++ )
                 {
-                    r = cvRound( (i * tabCos[n] + j * tabSin[n]) * irho );
+                    r = cvRound( i * tabCos[n] + j * tabSin[n] );
                     r += (numrho - 1) / 2;
                     accum[n * numrho + r]++;
                 }
@@ -164,9 +156,9 @@ static  CvStatus  icvHoughLines_8uC1R( uchar* image, int step, CvSize size,
     }
 
 func_exit:
-    icvFree( &tabSin );
-    icvFree( &tabCos );
-    icvFree( &accum );
+    cvFree( (void**)&tabSin );
+    cvFree( (void**)&tabCos );
+    cvFree( (void**)&accum );
 
     return CV_OK;
 }
@@ -176,19 +168,12 @@ func_exit:
 *                     Multi-Scale variant of Classical Hough Transform                   *
 \****************************************************************************************/
 
-typedef struct __index
-{
-    int value;
-    float rho, theta;
-}
-_index;
-
-
 #if _MSC_VER >= 1200
 #pragma warning( disable: 4714 )
 #endif
 
-DECLARE_AND_IMPLEMENT_LIST( _index, h_ );
+//DECLARE_AND_IMPLEMENT_LIST( _index, h_ );
+IMPLEMENT_LIST( _index, h_ )
 
 static  CvStatus  icvHoughLinesSDiv_8uC1R( uchar * image_src, int step, CvSize size,
                                            float rho, float theta, int threshold,
@@ -253,7 +238,7 @@ static  CvStatus  icvHoughLinesSDiv_8uC1R( uchar * image_src, int step, CvSize s
     isrho = 1 / srho;
     istheta = 1 / stheta;
 
-    rn = cvFloor( sqrt( w * w + h * h ) * irho );
+    rn = cvFloor( sqrt( (double)w * w + (double)h * h ) * irho );
     tn = cvFloor( 2 * Pi * itheta );
 
     list = h_create_list__index( linesMax < 1000 ? linesMax : 1000 );
@@ -262,18 +247,18 @@ static  CvStatus  icvHoughLinesSDiv_8uC1R( uchar * image_src, int step, CvSize s
     h_add_head__index( list, &vi );
 
     /* Precalculating sin */
-    sinTable = (float*)icvAlloc( 5 * tn * stn * sizeof( float ));
+    sinTable = (float*)cvAlloc( 5 * tn * stn * sizeof( float ));
 
     for( index = 0; index < 5 * tn * stn; index++ )
     {
-        sinTable[index] = (float)_cos( stheta * index * 0.2f );
+        sinTable[index] = (float)cos( stheta * index * 0.2f );
     }
 
     /* Allocating memory for the accumulator ad initializing it */
     if( threshold > 255 )
         goto func_exit;
 
-    caccum = (uchar*)icvAlloc( rn * tn * sizeof( caccum[0] ));
+    caccum = (uchar*)cvAlloc( rn * tn * sizeof( caccum[0] ));
     memset( caccum, 0, rn * tn * sizeof( caccum[0] ));
 
     /* Counting all feature pixels */
@@ -281,8 +266,8 @@ static  CvStatus  icvHoughLinesSDiv_8uC1R( uchar * image_src, int step, CvSize s
         for( col = 0; col < w; col++ )
             fn += _POINT( row, col ) != 0;
 
-    x = (int*)icvAlloc( fn * sizeof(x[0]));
-    y = (int*)icvAlloc( fn * sizeof(y[0]));
+    x = (int*)cvAlloc( fn * sizeof(x[0]));
+    y = (int*)cvAlloc( fn * sizeof(y[0]));
 
     /* Full Hough Transform (it's accumulator update part) */
     fi = 0;
@@ -310,8 +295,8 @@ static  CvStatus  icvHoughLinesSDiv_8uC1R( uchar * image_src, int step, CvSize s
                     xc = (float) col + 0.5f;
 
                     /* Update the accumulator */
-                    t = (float) fabs( icvFastArctan32f( yc, xc ) * d2r );
-                    r = (float) sqrt( xc * xc + yc * yc );
+                    t = (float) fabs( cvFastArctan( yc, xc ) * d2r );
+                    r = (float) sqrt( (double)xc * xc + (double)yc * yc );
                     r0 = r * irho;
                     ti0 = cvFloor( (t + Pi / 2) * itheta );
 
@@ -325,7 +310,8 @@ static  CvStatus  icvHoughLinesSDiv_8uC1R( uchar * image_src, int step, CvSize s
                          ti1 < halftn; ti1++, phi += theta_it, phi1 += scale_factor )
                     {
                         rv = r0 * _cos( phi );
-                        i = cvFloor( rv ) * tn + cvFloor( phi1 );
+                        i = cvFloor( rv ) * tn;
+                        i += cvFloor( phi1 );
                         assert( i >= 0 );
                         assert( i < rn * tn );
                         caccum[i] = (unsigned char) (caccum[i] + ((i ^ iprev) != 0));
@@ -364,7 +350,7 @@ static  CvStatus  icvHoughLinesSDiv_8uC1R( uchar * image_src, int step, CvSize s
         goto func_exit;
     }
 
-    buffer = (uchar *) icvAlloc( (srn * stn + 2) * sizeof( uchar ));
+    buffer = (uchar *) cvAlloc( (srn * stn + 2) * sizeof( uchar ));
     mcaccum = buffer + 1;
 
     count = 0;
@@ -386,8 +372,8 @@ static  CvStatus  icvHoughLinesSDiv_8uC1R( uchar * image_src, int step, CvSize s
                     xc = (float) x[index] + 0.5f;
 
                     /* Update the accumulator */
-                    t = (float) fabs( icvFastArctan32f( yc, xc ) * d2r );
-                    r = (float) sqrt( xc * xc + yc * yc ) * isrho;
+                    t = (float) fabs( cvFastArctan( yc, xc ) * d2r );
+                    r = (float) sqrt( (double)xc * xc + (double)yc * yc ) * isrho;
                     ti0 = cvFloor( (t + Pi * 0.5f) * istheta );
                     ti2 = (ti * stn - ti0) * 5;
                     r0 = (float) ri *srn;
@@ -478,11 +464,11 @@ static  CvStatus  icvHoughLinesSDiv_8uC1R( uchar * image_src, int step, CvSize s
 func_exit:
     h_destroy_list__index( list );
 
-    icvFree( &sinTable );
-    icvFree( &x );
-    icvFree( &y );
-    icvFree( &caccum );
-    icvFree( &buffer );
+    cvFree( (void**)&sinTable );
+    cvFree( (void**)&x );
+    cvFree( (void**)&y );
+    cvFree( (void**)&caccum );
+    cvFree( (void**)&buffer );
 
     return CV_OK;
 }
@@ -542,7 +528,7 @@ static  CvStatus  icvHoughLinesP_8uC1R( uchar * image_src, int step, CvSize size
     int fpn = 0;
 
     float *sinTable = 0;
-    CvRandState state;
+    CvRNG state = CvRNG(0xffffffff);
 
     if( linesMax <= 0 )
         return CV_BADSIZE_ERR;
@@ -553,19 +539,19 @@ static  CvStatus  icvHoughLinesP_8uC1R( uchar * image_src, int step, CvSize size
     irho = 1 / rho;
     itheta = 1 / theta;
 
-    rn = cvFloor( sqrt( w * w + h * h ) * irho );
+    rn = cvFloor( sqrt( (double)w * w + (double)h * h ) * irho );
     tn = cvFloor( 2 * Pi * itheta );
     halftn = cvFloor( Pi * itheta );
 
     /* Allocating memory for the accumulator ad initializing it */
     if( threshold > 255 )
     {
-        iaccum = (int *) icvAlloc( rn * tn * sizeof( int ));
+        iaccum = (int *) cvAlloc( rn * tn * sizeof( int ));
         memset( iaccum, 0, rn * tn * sizeof( int ));
     }
     else
     {
-        caccum = (uchar *) icvAlloc( rn * tn * sizeof( uchar ));
+        caccum = (uchar *) cvAlloc( rn * tn * sizeof( uchar ));
         memset( caccum, 0, rn * tn * sizeof( uchar ));
     }
 
@@ -580,17 +566,17 @@ static  CvStatus  icvHoughLinesP_8uC1R( uchar * image_src, int step, CvSize size
         }
     }
 
-    x = (int *) icvAlloc( fn * sizeof( int ));
-    y = (int *) icvAlloc( fn * sizeof( int ));
-    map = (int *) icvAlloc( w * h * sizeof( int ));
+    x = (int *) cvAlloc( fn * sizeof( int ));
+    y = (int *) cvAlloc( fn * sizeof( int ));
+    map = (int *) cvAlloc( w * h * sizeof( int ));
     memset( map, -1, w * h * sizeof( int ));
 
 #ifdef _PHOUGH_SIN_TABLE
-    sinTable = (float *) icvAlloc( tn * sizeof( float ));
+    sinTable = (float *) cvAlloc( tn * sizeof( float ));
 
     for( ti = 0; ti < tn; ti++ )
     {
-        sinTable[ti] = _sin( ti * theta );
+        sinTable[ti] = (float)sin( (double)(ti * theta) );
     }
 #endif
 
@@ -610,7 +596,6 @@ static  CvStatus  icvHoughLinesP_8uC1R( uchar * image_src, int step, CvSize size
     }
 
     /* Starting Hough Transform */
-    cvRandInit( &state, 0, 1, -1, CV_RAND_UNI );      /* Initializing random counter */
     while( fn != 0 )
     {
         int temp;
@@ -624,11 +609,12 @@ static  CvStatus  icvHoughLinesP_8uC1R( uchar * image_src, int step, CvSize size
         /* The x, y and length of a line (remember the maximum length) */
         float curx = 0, cury = 0;
         int ox, oy;             /* Rounded ax and ay */
+        int ex, ey;
 
 #define _EXCHANGE(x1, x2) temp = x1;x1 = x2;x2 = temp
 
         /* Select a pixel randomly */
-        index0 = cvRandNext(&state) % fn;
+        index0 = cvRandInt(&state) % fn;
         /* Remove the pixel from the feature points set */
         if( index0 != fn - 1 )
         {
@@ -645,8 +631,8 @@ static  CvStatus  icvHoughLinesP_8uC1R( uchar * image_src, int step, CvSize size
         xc = (float) x[fn] + 0.5f;
 
         /* Update the accumulator */
-        t = (float) fabs( icvFastArctan32f( yc, xc ) * d2r );
-        r = (float) sqrt( xc * xc + yc * yc );
+        t = (float) fabs( cvFastArctan( yc, xc ) * d2r );
+        r = (float) sqrt( (double)xc * xc + (double)yc * yc );
         ti0 = ROUNDT( t * itheta );
 
         /* ti1 = 0 */
@@ -698,6 +684,7 @@ static  CvStatus  icvHoughLinesP_8uC1R( uchar * image_src, int step, CvSize size
                 rv = r * SIN( ti1 );
                 ri1 = ROUNDR( rv * irho );
                 i = ri1 * tn + ti1 + ti0;
+                
                 caccum[i]++;
                 if( cmaccum < caccum[i] )
                 {
@@ -876,21 +863,28 @@ static  CvStatus  icvHoughLinesP_8uC1R( uchar * image_src, int step, CvSize size
         ay = msy;
         ox = cvFloor( msx );
         oy = cvFloor( msy );
-        while( (ox != cvFloor( mex ) || oy != cvFloor( mey )) && fn > 0 )
+        ex = cvFloor( mex );
+        ey = cvFloor( mey );
+
+        while( (ox != ex || oy != ey) && fn > 0 )
         {
-            image_src[oy * step + ox] = 0;
-            index0 = map[oy * w + ox];
-            if( index0 != -1 )
+            if( (unsigned)ox >= (unsigned)w || (unsigned)oy >= (unsigned)h )
+                break;
             {
-                if( index0 != fn - 1 )
+                image_src[oy * step + ox] = 0;
+                index0 = map[oy * w + ox];
+                if( index0 != -1 )
                 {
-                    /* Exchange the point with the last one */
-                    _EXCHANGE( x[index0], x[fn - 1] );
-                    _EXCHANGE( y[index0], y[fn - 1] );
-                    _EXCHANGE( map[y[index0] * w + x[index0]],
-                               map[y[fn - 1] * w + x[fn - 1]] );
+                    if( index0 != fn - 1 )
+                    {
+                        /* Exchange the point with the last one */
+                        _EXCHANGE( x[index0], x[fn - 1] );
+                        _EXCHANGE( y[index0], y[fn - 1] );
+                        _EXCHANGE( map[y[index0] * w + x[index0]],
+                                   map[y[fn - 1] * w + x[fn - 1]] );
+                    }
+                    fn--;
                 }
-                fn--;
             }
 
             ax += mdx;
@@ -913,12 +907,12 @@ static  CvStatus  icvHoughLinesP_8uC1R( uchar * image_src, int step, CvSize size
         }
     }
 func_exit:
-    icvFree( &x );
-    icvFree( &y );
-    icvFree( &map );
-    icvFree( &sinTable );
-    icvFree( &iaccum );
-    icvFree( &caccum );
+    cvFree( (void**)&x );
+    cvFree( (void**)&y );
+    cvFree( (void**)&map );
+    cvFree( (void**)&sinTable );
+    cvFree( (void**)&iaccum );
+    cvFree( (void**)&caccum );
 
     return CV_OK;
 }
@@ -943,6 +937,8 @@ cvHoughLines2( CvArr* src_image, void* lineStorage, int method,
     CvSeqBlock lines_block;
     int lineType, elemSize;
     int linesMax = INT_MAX;
+    CvSize size;
+    int iparam1, iparam2;
 
     CV_CALL( img = cvGetMat( img, &stub ));
 
@@ -992,21 +988,25 @@ cvHoughLines2( CvArr* src_image, void* lineStorage, int method,
         CV_ERROR( CV_StsBadArg, "Destination is not CvMemStorage* nor CvMat*" );
     }
 
+    size = cvGetMatSize(img);
+    iparam1 = cvRound(param1);
+    iparam2 = cvRound(param2);
+
     switch( method )
     {
     case CV_HOUGH_STANDARD:
-          IPPI_CALL( icvHoughLines_8uC1R( img->data.ptr, img->step, icvGetMatSize(img),
-                                          (float)rho, (float)theta, threshold, lines, linesMax ));
+          IPPI_CALL( icvHoughLines_8uC1R( img->data.ptr, img->step, size, (float)rho,
+                                          (float)theta, threshold, lines, linesMax ));
           break;
     case CV_HOUGH_MULTI_SCALE:
-          IPPI_CALL( icvHoughLinesSDiv_8uC1R( img->data.ptr, img->step, icvGetMatSize(img),
-                                          (float)rho, (float)theta, threshold,
-                                          cvRound(param1), cvRound(param2), lines, linesMax ));
+          IPPI_CALL( icvHoughLinesSDiv_8uC1R( img->data.ptr, img->step, size, (float)rho,
+                                              (float)theta, threshold, iparam1,
+                                              iparam2, lines, linesMax ));
           break;
     case CV_HOUGH_PROBABILISTIC:
-          IPPI_CALL( icvHoughLinesP_8uC1R( img->data.ptr, img->step, icvGetMatSize(img),
-                                          (float)rho, (float)theta, threshold,
-                                          cvRound(param1), cvRound(param2), lines, linesMax ));
+          IPPI_CALL( icvHoughLinesP_8uC1R( img->data.ptr, img->step, size, (float)rho,
+                                           (float)theta, threshold, iparam1,
+                                           iparam2, lines, linesMax ));
           break;
     default:
         CV_ERROR( CV_StsBadArg, "Unrecognized method id" );
diff --git a/opencv/src/cv/cvimgwarp.cpp b/opencv/src/cv/cvimgwarp.cpp
new file mode 100644 (file)
index 0000000..4e1a941
--- /dev/null
@@ -0,0 +1,1340 @@
+/*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.
+//
+//
+//                        Intel License Agreement
+//                For Open Source Computer Vision Library
+//
+// Copyright (C) 2000, Intel Corporation, 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 Intel Corporation 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*/
+
+/* ////////////////////////////////////////////////////////////////////
+//
+//  Geometrical transforms on images and matrices: rotation, zoom etc.
+//
+// */
+
+#include "_cv.h"
+
+/****************************************************************************************\
+*                                         Resize                                         *
+\****************************************************************************************/
+
+static CvStatus CV_STDCALL
+icvResize_NN_8u_C1R( const uchar* src, int srcstep, CvSize ssize,
+                     uchar* dst, int dststep, CvSize dsize, int pix_size )
+{
+    int* x_ofs = (int*)cvStackAlloc( dsize.width * sizeof(x_ofs[0]) );
+    int pix_size4 = pix_size / sizeof(int);
+    int x, y, t;
+
+    for( x = 0; x < dsize.width; x++ )
+    {
+        t = (ssize.width*x*2 + MIN(ssize.width, dsize.width) - 1)/(dsize.width*2);
+        t -= t >= ssize.width;
+        x_ofs[x] = t*pix_size;
+    }
+
+    for( y = 0; y < dsize.height; y++, dst += dststep )
+    {
+        const uchar* tsrc;
+        t = (ssize.height*y*2 + MIN(ssize.height, dsize.height) - 1)/(dsize.height*2);
+        t -= t >= ssize.height;
+        tsrc = src + srcstep*t;
+
+        switch( pix_size )
+        {
+        case 1:
+            for( x = 0; x <= dsize.width - 2; x += 2 )
+            {
+                uchar t0 = tsrc[x_ofs[x]];
+                uchar t1 = tsrc[x_ofs[x+1]];
+
+                dst[x] = t0;
+                dst[x+1] = t1;
+            }
+
+            for( ; x < dsize.width; x++ )
+                dst[x] = tsrc[x_ofs[x]];
+            break;
+        case 2:
+            for( x = 0; x < dsize.width; x++ )
+                *(ushort*)(dst + x*2) = *(ushort*)(tsrc + x_ofs[x]);
+            break;
+        case 3:
+            for( x = 0; x < dsize.width; x++ )
+            {
+                const uchar* _tsrc = tsrc + x_ofs[x];
+                dst[x*3] = _tsrc[0]; dst[x*3+1] = _tsrc[1]; dst[x*3+2] = _tsrc[2];
+            }
+            break;
+        case 4:
+            for( x = 0; x < dsize.width; x++ )
+                *(int*)(dst + x*4) = *(int*)(tsrc + x_ofs[x]);
+            break;
+        case 6:
+            for( x = 0; x < dsize.width; x++ )
+            {
+                const ushort* _tsrc = (const ushort*)(tsrc + x_ofs[x]);
+                ushort* _tdst = (ushort*)(dst + x*6);
+                _tdst[0] = _tsrc[0]; _tdst[1] = _tsrc[1]; _tdst[2] = _tsrc[2];
+            }
+            break;
+        default:
+            for( x = 0; x < dsize.width; x++ )
+                CV_MEMCPY_INT( dst + x*pix_size, tsrc + x_ofs[x], pix_size4 );
+        }
+    }
+
+    return CV_OK;
+}
+
+
+typedef struct CvResizeAlpha
+{
+    int idx;
+    union
+    {
+        float alpha;
+        int ialpha;
+    };
+}
+CvResizeAlpha;
+
+
+#define ICV_WARP_SHIFT          10
+#define ICV_WARP_MASK           ((1 << ICV_WARP_SHIFT) - 1)
+#define ICV_WARP_MUL_ONE_8U(x)  ((x) << ICV_WARP_SHIFT)
+#define ICV_WARP_DESCALE_8U(x)  CV_DESCALE((x), ICV_WARP_SHIFT*2)
+#define ICV_WARP_CLIP_X(x)      ((unsigned)(x) < (unsigned)ssize.width ? \
+                                (x) : (x) < 0 ? 0 : ssize.width - 1)
+#define ICV_WARP_CLIP_Y(y)      ((unsigned)(y) < (unsigned)ssize.height ? \
+                                (y) : (y) < 0 ? 0 : ssize.height - 1)
+
+
+#define  ICV_DEF_RESIZE_BILINEAR_FUNC( flavor, arrtype, worktype, alpha_field,  \
+                                       mul_one_macro, descale_macro )           \
+static CvStatus CV_STDCALL                                                      \
+icvResize_Bilinear_##flavor##_CnR( const arrtype* src, int srcstep, CvSize ssize,\
+                                   arrtype* dst, int dststep, CvSize dsize,     \
+                                   int cn, int xmax,                            \
+                                   const CvResizeAlpha* xofs,                   \
+                                   const CvResizeAlpha* yofs,                   \
+                                   worktype* buf0, worktype* buf1 )             \
+{                                                                               \
+    int prev_sy0 = -1, prev_sy1 = -1;                                           \
+    int k, dx, dy;                                                              \
+                                                                                \
+    srcstep /= sizeof(src[0]);                                                  \
+    dststep /= sizeof(dst[0]);                                                  \
+    dsize.width *= cn;                                                          \
+    xmax *= cn;                                                                 \
+                                                                                \
+    for( dy = 0; dy < dsize.height; dy++, dst += dststep )                      \
+    {                                                                           \
+        worktype fy = yofs[dy].alpha_field, *swap_t;                            \
+        int sy0 = yofs[dy].idx, sy1 = sy0 + (fy > 0 && sy0 < ssize.height-1);   \
+                                                                                \
+        if( sy0 == prev_sy0 && sy1 == prev_sy1 )                                \
+            k = 2;                                                              \
+        else if( sy0 == prev_sy1 )                                              \
+        {                                                                       \
+            CV_SWAP( buf0, buf1, swap_t );                                      \
+            k = 1;                                                              \
+        }                                                                       \
+        else                                                                    \
+            k = 0;                                                              \
+                                                                                \
+        for( ; k < 2; k++ )                                                     \
+        {                                                                       \
+            worktype* _buf = k == 0 ? buf0 : buf1;                              \
+            const arrtype* _src;                                                \
+            int sy = k == 0 ? sy0 : sy1;                                        \
+            if( k == 1 && sy1 == sy0 )                                          \
+            {                                                                   \
+                memcpy( buf1, buf0, dsize.width*sizeof(buf0[0]) );              \
+                continue;                                                       \
+            }                                                                   \
+                                                                                \
+            _src = src + sy*srcstep;                                            \
+            for( dx = 0; dx < xmax; dx++ )                                      \
+            {                                                                   \
+                int sx = xofs[dx].idx;                                          \
+                worktype fx = xofs[dx].alpha_field;                             \
+                worktype t = _src[sx];                                          \
+                _buf[dx] = mul_one_macro(t) + fx*(_src[sx+cn] - t);             \
+            }                                                                   \
+                                                                                \
+            for( ; dx < dsize.width; dx++ )                                     \
+                _buf[dx] = mul_one_macro(_src[xofs[dx].idx]);                   \
+        }                                                                       \
+                                                                                \
+        prev_sy0 = sy0;                                                         \
+        prev_sy1 = sy1;                                                         \
+                                                                                \
+        if( sy0 == sy1 )                                                        \
+            for( dx = 0; dx < dsize.width; dx++ )                               \
+                dst[dx] = (arrtype)descale_macro( mul_one_macro(buf0[dx]));     \
+        else                                                                    \
+            for( dx = 0; dx < dsize.width; dx++ )                               \
+                dst[dx] = (arrtype)descale_macro( mul_one_macro(buf0[dx]) +     \
+                                                  fy*(buf1[dx] - buf0[dx]));    \
+    }                                                                           \
+                                                                                \
+    return CV_OK;                                                               \
+}
+
+
+typedef struct CvDecimateAlpha
+{
+    int si, di;
+    float alpha;
+}
+CvDecimateAlpha;
+
+
+#define  ICV_DEF_RESIZE_AREA_FAST_FUNC( flavor, arrtype, worktype, cast_macro ) \
+static CvStatus CV_STDCALL                                                      \
+icvResize_AreaFast_##flavor##_CnR( const arrtype* src, int srcstep, CvSize ssize,\
+                              arrtype* dst, int dststep, CvSize dsize, int cn,  \
+                              const int* ofs, const int* xofs )                 \
+{                                                                               \
+    int dy, dx, k = 0;                                                          \
+    int scale_x = ssize.width/dsize.width;                                      \
+    int scale_y = ssize.height/dsize.height;                                    \
+    int area = scale_x*scale_y;                                                 \
+    float scale = 1.f/(scale_x*scale_y);                                        \
+                                                                                \
+    srcstep /= sizeof(src[0]);                                                  \
+    dststep /= sizeof(dst[0]);                                                  \
+    dsize.width *= cn;                                                          \
+                                                                                \
+    for( dy = 0; dy < dsize.height; dy++, dst += dststep )                      \
+        for( dx = 0; dx < dsize.width; dx++ )                                   \
+        {                                                                       \
+            const arrtype* _src = src + dy*scale_y*srcstep + xofs[dx];          \
+            worktype sum = 0;                                                   \
+                                                                                \
+            for( k = 0; k <= area - 4; k += 4 )                                 \
+                sum += _src[ofs[k]] + _src[ofs[k+1]] +                          \
+                       _src[ofs[k+2]] + _src[ofs[k+3]];                         \
+                                                                                \
+            for( ; k < area; k++ )                                              \
+                sum += _src[ofs[k]];                                            \
+                                                                                \
+            dst[dx] = (arrtype)cast_macro( sum*scale );                         \
+        }                                                                       \
+                                                                                \
+    return CV_OK;                                                               \
+}
+
+
+#define  ICV_DEF_RESIZE_AREA_FUNC( flavor, arrtype, load_macro, cast_macro )    \
+static CvStatus CV_STDCALL                                                      \
+icvResize_Area_##flavor##_CnR( const arrtype* src, int srcstep, CvSize ssize,   \
+                               arrtype* dst, int dststep, CvSize dsize,         \
+                               int cn, const CvDecimateAlpha* xofs,             \
+                               int xofs_count, float* buf, float* sum )         \
+{                                                                               \
+    int k, sy, dx, cur_dy = 0;                                                  \
+    float scale_y = (float)ssize.height/dsize.height;                           \
+                                                                                \
+    srcstep /= sizeof(src[0]);                                                  \
+    dststep /= sizeof(dst[0]);                                                  \
+    dsize.width *= cn;                                                          \
+                                                                                \
+    for( sy = 0; sy < ssize.height; sy++, src += srcstep )                      \
+    {                                                                           \
+        if( cn == 1 )                                                           \
+            for( k = 0; k < xofs_count; k++ )                                   \
+            {                                                                   \
+                int dxn = xofs[k].di;                                           \
+                float alpha = xofs[k].alpha;                                    \
+                buf[dxn] = buf[dxn] + load_macro(src[xofs[k].si])*alpha;        \
+            }                                                                   \
+        else if( cn == 2 )                                                      \
+            for( k = 0; k < xofs_count; k++ )                                   \
+            {                                                                   \
+                int sxn = xofs[k].si;                                           \
+                int dxn = xofs[k].di;                                           \
+                float alpha = xofs[k].alpha;                                    \
+                float t0 = buf[dxn] + load_macro(src[sxn])*alpha;               \
+                float t1 = buf[dxn+1] + load_macro(src[sxn+1])*alpha;           \
+                buf[dxn] = t0; buf[dxn+1] = t1;                                 \
+            }                                                                   \
+        else if( cn == 3 )                                                      \
+            for( k = 0; k < xofs_count; k++ )                                   \
+            {                                                                   \
+                int sxn = xofs[k].si;                                           \
+                int dxn = xofs[k].di;                                           \
+                float alpha = xofs[k].alpha;                                    \
+                float t0 = buf[dxn] + load_macro(src[sxn])*alpha;               \
+                float t1 = buf[dxn+1] + load_macro(src[sxn+1])*alpha;           \
+                float t2 = buf[dxn+2] + load_macro(src[sxn+2])*alpha;           \
+                buf[dxn] = t0; buf[dxn+1] = t1; buf[dxn+2] = t2;                \
+            }                                                                   \
+        else                                                                    \
+            for( k = 0; k < xofs_count; k++ )                                   \
+            {                                                                   \
+                int sxn = xofs[k].si;                                           \
+                int dxn = xofs[k].di;                                           \
+                float alpha = xofs[k].alpha;                                    \
+                float t0 = buf[dxn] + load_macro(src[sxn])*alpha;               \
+                float t1 = buf[dxn+1] + load_macro(src[sxn+1])*alpha;           \
+                buf[dxn] = t0; buf[dxn+1] = t1;                                 \
+                t0 = buf[dxn+2] + load_macro(src[sxn+2])*alpha;                 \
+                t1 = buf[dxn+3] + load_macro(src[sxn+3])*alpha;                 \
+                buf[dxn+2] = t0; buf[dxn+3] = t1;                               \
+            }                                                                   \
+                                                                                \
+        if( (cur_dy + 1)*scale_y <= sy + 1 || sy == ssize.height - 1 )          \
+        {                                                                       \
+            float beta = sy + 1 - (cur_dy+1)*scale_y, beta1;                    \
+            beta = MAX( beta, 0 );                                              \
+            beta1 = 1 - beta;                                                   \
+            if( fabs(beta) < 1e-3 )                                             \
+                for( dx = 0; dx < dsize.width; dx++ )                           \
+                {                                                               \
+                    dst[dx] = (arrtype)cast_macro(sum[dx] + buf[dx]);           \
+                    sum[dx] = buf[dx] = 0;                                      \
+                }                                                               \
+            else                                                                \
+                for( dx = 0; dx < dsize.width; dx++ )                           \
+                {                                                               \
+                    dst[dx] = (arrtype)cast_macro(sum[dx] + buf[dx]*beta1);     \
+                    sum[dx] = buf[dx]*beta;                                     \
+                    buf[dx] = 0;                                                \
+                }                                                               \
+            dst += dststep;                                                     \
+            cur_dy++;                                                           \
+        }                                                                       \
+        else                                                                    \
+            for( dx = 0; dx < dsize.width; dx += 2 )                            \
+            {                                                                   \
+                float t0 = sum[dx] + buf[dx];                                   \
+                float t1 = sum[dx+1] + buf[dx+1];                               \
+                sum[dx] = t0; sum[dx+1] = t1;                                   \
+                buf[dx] = buf[dx+1] = 0;                                        \
+            }                                                                   \
+    }                                                                           \
+                                                                                \
+    return CV_OK;                                                               \
+}
+
+
+#define ICV_CUBIC_TAB_SIZE   (ICV_WARP_MASK+1)
+static float icvCubicCoeffs[(ICV_CUBIC_TAB_SIZE+1)*2];
+
+static void icvInitCubicCoeffTab()
+{
+    static int inittab = 0;
+    if( !inittab )
+    {
+#if 0
+        // classical Mitchell-Netravali filter
+        const double B = 1./3;
+        const double C = 1./3;
+        const double p0 = (6 - 2*B)/6.;
+        const double p2 = (-18 + 12*B + 6*C)/6.;
+        const double p3 = (12 - 9*B - 6*C)/6.;
+        const double q0 = (8*B + 24*C)/6.;
+        const double q1 = (-12*B - 48*C)/6.;
+        const double q2 = (6*B + 30*C)/6.;
+        const double q3 = (-B - 6*C)/6.;
+
+        #define ICV_CUBIC_1(x)  (((x)*p3 + p2)*(x)*(x) + p0)
+        #define ICV_CUBIC_2(x)  ((((x)*q3 + q2)*(x) + q1)*(x) + q0)
+#else
+        // alternative "sharp" filter
+        const double A = -0.75;
+        #define ICV_CUBIC_1(x)  (((A + 2)*(x) - (A + 3))*(x)*(x) + 1)
+        #define ICV_CUBIC_2(x)  (((A*(x) - 5*A)*(x) + 8*A)*(x) - 4*A)
+#endif
+        for( int i = 0; i <= ICV_CUBIC_TAB_SIZE; i++ )
+        {
+            float x = (float)i/ICV_CUBIC_TAB_SIZE;
+            icvCubicCoeffs[i*2] = (float)ICV_CUBIC_1(x);
+            x += 1.f;
+            icvCubicCoeffs[i*2+1] = (float)ICV_CUBIC_2(x);
+        }
+
+        inittab = 1;
+    }
+}
+
+
+#define  ICV_DEF_RESIZE_BICUBIC_FUNC( flavor, arrtype, worktype, load_macro,    \
+                                      cast_macro1, cast_macro2 )                \
+static CvStatus CV_STDCALL                                                      \
+icvResize_Bicubic_##flavor##_CnR( const arrtype* src, int srcstep, CvSize ssize,\
+                                  arrtype* dst, int dststep, CvSize dsize,      \
+                                  int cn, int xmin, int xmax,                   \
+                                  const CvResizeAlpha* xofs, float** buf )      \
+{                                                                               \
+    float scale_y = (float)ssize.height/dsize.height;                           \
+    int dx, dy, sx, sy, sy2, ify;                                               \
+    int prev_sy2 = -2;                                                          \
+                                                                                \
+    xmin *= cn; xmax *= cn;                                                     \
+    dsize.width *= cn;                                                          \
+    ssize.width *= cn;                                                          \
+    srcstep /= sizeof(src[0]);                                                  \
+    dststep /= sizeof(dst[0]);                                                  \
+                                                                                \
+    for( dy = 0; dy < dsize.height; dy++, dst += dststep )                      \
+    {                                                                           \
+        float w0, w1, w2, w3;                                                   \
+        float fy, x, sum;                                                       \
+        float *row, *row0, *row1, *row2, *row3;                                 \
+        int k1, k = 4;                                                          \
+                                                                                \
+        fy = dy*scale_y;                                                        \
+        sy = cvFloor(fy);                                                       \
+        fy -= sy;                                                               \
+        ify = cvRound(fy*ICV_CUBIC_TAB_SIZE);                                   \
+        sy2 = sy + 2;                                                           \
+                                                                                \
+        if( sy2 > prev_sy2 )                                                    \
+        {                                                                       \
+            int delta = prev_sy2 - sy + 2;                                      \
+            for( k = 0; k < delta; k++ )                                        \
+                CV_SWAP( buf[k], buf[k+4-delta], row );                         \
+        }                                                                       \
+                                                                                \
+        for( sy += k - 1; k < 4; k++, sy++ )                                    \
+        {                                                                       \
+            const arrtype* _src = src + sy*srcstep;                             \
+                                                                                \
+            row = buf[k];                                                       \
+            if( sy < 0 )                                                        \
+                continue;                                                       \
+            if( sy >= ssize.height )                                            \
+            {                                                                   \
+                assert( k > 0 );                                                \
+                memcpy( row, buf[k-1], dsize.width*sizeof(row[0]) );            \
+                continue;                                                       \
+            }                                                                   \
+                                                                                \
+            for( dx = 0; dx < xmin; dx++ )                                      \
+            {                                                                   \
+                int ifx = xofs[dx].ialpha, sx0 = xofs[dx].idx;                  \
+                sx = sx0 + cn*2;                                                \
+                while( sx >= ssize.width )                                      \
+                    sx -= cn;                                                   \
+                x = load_macro(_src[sx]);                                       \
+                sum = x*icvCubicCoeffs[(ICV_CUBIC_TAB_SIZE - ifx)*2 + 1];       \
+                if( (unsigned)(sx = sx0 + cn) < (unsigned)ssize.width )         \
+                    x = load_macro(_src[sx]);                                   \
+                sum += x*icvCubicCoeffs[(ICV_CUBIC_TAB_SIZE - ifx)*2];          \
+                if( (unsigned)(sx = sx0) < (unsigned)ssize.width )              \
+                    x = load_macro(_src[sx]);                                   \
+                sum += x*icvCubicCoeffs[ifx*2];                                 \
+                if( (unsigned)(sx = sx0 - cn) < (unsigned)ssize.width )         \
+                    x = load_macro(_src[sx]);                                   \
+                row[dx] = sum + x*icvCubicCoeffs[ifx*2 + 1];                    \
+            }                                                                   \
+                                                                                \
+            for( ; dx < xmax; dx++ )                                            \
+            {                                                                   \
+                int ifx = xofs[dx].ialpha;                                      \
+                int sx0 = xofs[dx].idx;                                         \
+                row[dx] = _src[sx0 - cn]*icvCubicCoeffs[ifx*2 + 1] +            \
+                    _src[sx0]*icvCubicCoeffs[ifx*2] +                           \
+                    _src[sx0 + cn]*icvCubicCoeffs[(ICV_CUBIC_TAB_SIZE-ifx)*2] + \
+                    _src[sx0 + cn*2]*icvCubicCoeffs[(ICV_CUBIC_TAB_SIZE-ifx)*2+1];\
+            }                                                                   \
+                                                                                \
+            for( ; dx < dsize.width; dx++ )                                     \
+            {                                                                   \
+                int ifx = xofs[dx].ialpha, sx0 = xofs[dx].idx;                  \
+                x = load_macro(_src[sx0 - cn]);                                 \
+                sum = x*icvCubicCoeffs[ifx*2 + 1];                              \
+                if( (unsigned)(sx = sx0) < (unsigned)ssize.width )              \
+                    x = load_macro(_src[sx]);                                   \
+                sum += x*icvCubicCoeffs[ifx*2];                                 \
+                if( (unsigned)(sx = sx0 + cn) < (unsigned)ssize.width )         \
+                    x = load_macro(_src[sx]);                                   \
+                sum += x*icvCubicCoeffs[(ICV_CUBIC_TAB_SIZE - ifx)*2];          \
+                if( (unsigned)(sx = sx0 + cn*2) < (unsigned)ssize.width )       \
+                    x = load_macro(_src[sx]);                                   \
+                row[dx] = sum + x*icvCubicCoeffs[(ICV_CUBIC_TAB_SIZE-ifx)*2+1]; \
+            }                                                                   \
+                                                                                \
+            if( sy == 0 )                                                       \
+                for( k1 = 0; k1 < k; k1++ )                                     \
+                    memcpy( buf[k1], row, dsize.width*sizeof(row[0]));          \
+        }                                                                       \
+                                                                                \
+        prev_sy2 = sy2;                                                         \
+                                                                                \
+        row0 = buf[0]; row1 = buf[1];                                           \
+        row2 = buf[2]; row3 = buf[3];                                           \
+                                                                                \
+        w0 = icvCubicCoeffs[ify*2+1];                                           \
+        w1 = icvCubicCoeffs[ify*2];                                             \
+        w2 = icvCubicCoeffs[(ICV_CUBIC_TAB_SIZE - ify)*2];                      \
+        w3 = icvCubicCoeffs[(ICV_CUBIC_TAB_SIZE - ify)*2 + 1];                  \
+                                                                                \
+        for( dx = 0; dx < dsize.width; dx++ )                                   \
+        {                                                                       \
+            worktype val = cast_macro1( row0[dx]*w0 + row1[dx]*w1 +             \
+                                        row2[dx]*w2 + row3[dx]*w3 );            \
+            dst[dx] = cast_macro2(val);                                         \
+        }                                                                       \
+    }                                                                           \
+                                                                                \
+    return CV_OK;                                                               \
+}
+
+
+ICV_DEF_RESIZE_BILINEAR_FUNC( 8u, uchar, int, ialpha,
+                              ICV_WARP_MUL_ONE_8U, ICV_WARP_DESCALE_8U )
+ICV_DEF_RESIZE_BILINEAR_FUNC( 16u, ushort, float, alpha, CV_NOP, cvRound )
+ICV_DEF_RESIZE_BILINEAR_FUNC( 32f, float, float, alpha, CV_NOP, CV_NOP )
+
+ICV_DEF_RESIZE_BICUBIC_FUNC( 8u, uchar, int, CV_8TO32F, cvRound, CV_CAST_8U )
+ICV_DEF_RESIZE_BICUBIC_FUNC( 16u, ushort, int, CV_NOP, cvRound, CV_CAST_16U )
+ICV_DEF_RESIZE_BICUBIC_FUNC( 32f, float, float, CV_NOP, CV_NOP, CV_NOP )
+
+ICV_DEF_RESIZE_AREA_FAST_FUNC( 8u, uchar, int, cvRound )
+ICV_DEF_RESIZE_AREA_FAST_FUNC( 16u, ushort, int, cvRound )
+ICV_DEF_RESIZE_AREA_FAST_FUNC( 32f, float, float, CV_NOP )
+
+ICV_DEF_RESIZE_AREA_FUNC( 8u, uchar, CV_8TO32F, cvRound )
+ICV_DEF_RESIZE_AREA_FUNC( 16u, ushort, CV_NOP, cvRound )
+ICV_DEF_RESIZE_AREA_FUNC( 32f, float, CV_NOP, CV_NOP )
+
+
+static void icvInitResizeTab( CvFuncTable* bilin_tab,
+                              CvFuncTable* bicube_tab,
+                              CvFuncTable* areafast_tab,
+                              CvFuncTable* area_tab )
+{
+    bilin_tab->fn_2d[CV_8U] = (void*)icvResize_Bilinear_8u_CnR;
+    bilin_tab->fn_2d[CV_16U] = (void*)icvResize_Bilinear_16u_CnR;
+    bilin_tab->fn_2d[CV_32F] = (void*)icvResize_Bilinear_32f_CnR;
+
+    bicube_tab->fn_2d[CV_8U] = (void*)icvResize_Bicubic_8u_CnR;
+    bicube_tab->fn_2d[CV_16U] = (void*)icvResize_Bicubic_16u_CnR;
+    bicube_tab->fn_2d[CV_32F] = (void*)icvResize_Bicubic_32f_CnR;
+
+    areafast_tab->fn_2d[CV_8U] = (void*)icvResize_AreaFast_8u_CnR;
+    areafast_tab->fn_2d[CV_16U] = (void*)icvResize_AreaFast_16u_CnR;
+    areafast_tab->fn_2d[CV_32F] = (void*)icvResize_AreaFast_32f_CnR;
+
+    area_tab->fn_2d[CV_8U] = (void*)icvResize_Area_8u_CnR;
+    area_tab->fn_2d[CV_16U] = (void*)icvResize_Area_16u_CnR;
+    area_tab->fn_2d[CV_32F] = (void*)icvResize_Area_32f_CnR;
+}
+
+
+typedef CvStatus (CV_STDCALL * CvResizeBilinearFunc)
+                    ( const void* src, int srcstep, CvSize ssize,
+                      void* dst, int dststep, CvSize dsize,
+                      int cn, int xmax, const CvResizeAlpha* xofs,
+                      const CvResizeAlpha* yofs, float* buf0, float* buf1 );
+
+typedef CvStatus (CV_STDCALL * CvResizeBicubicFunc)
+                    ( const void* src, int srcstep, CvSize ssize,
+                      void* dst, int dststep, CvSize dsize,
+                      int cn, int xmin, int xmax,
+                      const CvResizeAlpha* xofs, float** buf );
+
+typedef CvStatus (CV_STDCALL * CvResizeAreaFastFunc)
+                    ( const void* src, int srcstep, CvSize ssize,
+                      void* dst, int dststep, CvSize dsize,
+                      int cn, const int* ofs, const int *xofs );
+
+typedef CvStatus (CV_STDCALL * CvResizeAreaFunc)
+                    ( const void* src, int srcstep, CvSize ssize,
+                      void* dst, int dststep, CvSize dsize,
+                      int cn, const CvDecimateAlpha* xofs,
+                      int xofs_count, float* buf, float* sum );
+
+
+CV_IMPL void
+cvResize( const CvArr* srcarr, CvArr* dstarr, int method )
+{
+    static CvFuncTable bilin_tab, bicube_tab, areafast_tab, area_tab;
+    static int inittab = 0;
+    void* temp_buf = 0;
+
+    CV_FUNCNAME( "cvResize" );
+
+    __BEGIN__;
+    
+    CvMat srcstub, *src = (CvMat*)srcarr;
+    CvMat dststub, *dst = (CvMat*)dstarr;
+    CvSize ssize, dsize;
+    float scale_x, scale_y;
+    int k, sx, sy, dx, dy;
+    int depth, cn;
+    
+    CV_CALL( src = cvGetMat( srcarr, &srcstub ));
+    CV_CALL( dst = cvGetMat( dstarr, &dststub ));
+    
+    if( CV_ARE_SIZES_EQ( src, dst ))
+        CV_CALL( cvCopy( src, dst ));
+
+    if( !CV_ARE_TYPES_EQ( src, dst ))
+        CV_ERROR( CV_StsUnmatchedFormats, "" );
+
+    if( !inittab )
+    {
+        icvInitResizeTab( &bilin_tab, &bicube_tab, &areafast_tab, &area_tab );
+        inittab = 1;
+    }
+
+    ssize = cvGetMatSize( src );
+    dsize = cvGetMatSize( dst );
+    depth = CV_MAT_DEPTH(src->type);
+    cn = CV_MAT_CN(src->type);
+    scale_x = (float)ssize.width/dsize.width;
+    scale_y = (float)ssize.height/dsize.height;
+
+    if( method == CV_INTER_NN )
+    {
+        IPPI_CALL( icvResize_NN_8u_C1R( src->data.ptr, src->step, ssize,
+                                        dst->data.ptr, dst->step, dsize,
+                                        CV_ELEM_SIZE(src->type)));
+    }
+    else if( method == CV_INTER_LINEAR || method == CV_INTER_AREA )
+    {
+        if( method == CV_INTER_AREA &&
+            ssize.width >= dsize.width && ssize.height >= dsize.height )
+        {
+            // "area" method for (scale_x > 1 & scale_y > 1)
+
+            int iscale_x = cvRound(scale_x);
+            int iscale_y = cvRound(scale_y);
+
+            if( scale_x == iscale_x && scale_y == iscale_y )
+            {
+                int area = iscale_x*iscale_y;
+                int srcstep = src->step / CV_ELEM_SIZE(depth);
+                int* ofs = (int*)cvStackAlloc( (area + dsize.width*cn)*sizeof(int) );
+                int* xofs = ofs + area;
+                CvResizeAreaFastFunc func = (CvResizeAreaFastFunc)areafast_tab.fn_2d[depth];
+
+                if( !func )
+                    CV_ERROR( CV_StsUnsupportedFormat, "" );
+                
+                for( sy = 0, k = 0; sy < iscale_y; sy++ )
+                    for( sx = 0; sx < iscale_x; sx++ )
+                        ofs[k++] = sy*srcstep + sx*cn;
+
+                for( dx = 0; dx < dsize.width; dx++ )
+                {
+                    sx = dx*iscale_x*cn;
+                    for( k = 0; k < cn; k++ )
+                        xofs[dx*cn + k] = sx + k;
+                }
+
+                IPPI_CALL( func( src->data.ptr, src->step, ssize, dst->data.ptr,
+                                 dst->step, dsize, cn, ofs, xofs ));
+            }
+            else
+            {
+                int buf_len = dsize.width*cn + 4, buf_size, xofs_count = 0;
+                float scale = 1.f/(scale_x*scale_y);
+                float *buf, *sum;
+                CvDecimateAlpha* xofs;
+                CvResizeAreaFunc func = (CvResizeAreaFunc)area_tab.fn_2d[depth];
+
+                if( !func )
+                    CV_ERROR( CV_StsUnsupportedFormat, "" );
+
+                buf_size = buf_len*2*sizeof(float) + ssize.width*2*sizeof(CvDecimateAlpha);
+                if( buf_size < CV_MAX_LOCAL_SIZE )
+                    buf = (float*)cvStackAlloc(buf_size);
+                else
+                    CV_CALL( temp_buf = buf = (float*)cvAlloc(buf_size));
+                sum = buf + buf_len;
+                xofs = (CvDecimateAlpha*)(sum + buf_len);
+
+                for( dx = 0, k = 0; dx < dsize.width; dx++ )
+                {
+                    float fsx1 = dx*scale_x, fsx2 = fsx1 + scale_x;
+                    int sx1 = cvCeil(fsx1), sx2 = cvFloor(fsx2);
+
+                    if( sx1 > fsx1 )
+                    {
+                        assert( k < ssize.width*2 );            
+                        xofs[k].di = dx*cn;
+                        xofs[k].si = (sx1-1)*cn;
+                        xofs[k++].alpha = (sx1 - fsx1)*scale;
+                    }
+
+                    for( sx = sx1; sx < sx2; sx++ )
+                    {
+                        assert( k < ssize.width*2 );
+                        xofs[k].di = dx*cn;
+                        xofs[k].si = sx*cn;
+                        xofs[k++].alpha = scale;
+                    }
+
+                    if( sx2 < fsx2 )
+                    {
+                        assert( k < ssize.width*2 );
+                        xofs[k].di = dx*cn;
+                        xofs[k].si = sx2*cn;
+                        xofs[k++].alpha = (fsx2 - sx2)*scale;
+                    }
+                }
+
+                xofs_count = k;
+                memset( sum, 0, buf_len*sizeof(float) );
+                memset( buf, 0, buf_len*sizeof(float) );
+
+                IPPI_CALL( func( src->data.ptr, src->step, ssize, dst->data.ptr,
+                                 dst->step, dsize, cn, xofs, xofs_count, buf, sum ));
+            }
+        }
+        else // true "area" method for the cases (scale_x > 1 & scale_y < 1) and
+             // (scale_x < 1 & scale_y > 1) is not implemented.
+             // instead, it is emulated via some variant of bilinear interpolation.
+        {
+            float inv_scale_x = (float)dsize.width/ssize.width;
+            float inv_scale_y = (float)dsize.height/ssize.height;
+            int xmax = dsize.width, width = dsize.width*cn, buf_size;
+            float *buf0, *buf1;
+            CvResizeAlpha *xofs, *yofs;
+            int area_mode = method == CV_INTER_AREA;
+            float fx, fy;
+            CvResizeBilinearFunc func = (CvResizeBilinearFunc)bilin_tab.fn_2d[depth];
+
+            if( !func )
+                CV_ERROR( CV_StsUnsupportedFormat, "" );
+
+            buf_size = width*2*sizeof(float) + (width + dsize.height)*sizeof(CvResizeAlpha);
+            if( buf_size < CV_MAX_LOCAL_SIZE )
+                buf0 = (float*)cvStackAlloc(buf_size);
+            else
+                CV_CALL( temp_buf = buf0 = (float*)cvAlloc(buf_size));
+            buf1 = buf0 + width;
+            xofs = (CvResizeAlpha*)(buf1 + width);
+            yofs = xofs + width;
+
+            for( dx = 0; dx < dsize.width; dx++ )
+            {
+                if( !area_mode )
+                {
+                    fx = (float)((dx+0.5)*scale_x - 0.5);
+                    sx = cvFloor(fx);
+                    fx -= sx;
+                }
+                else
+                {
+                    sx = cvFloor(dx*scale_x);
+                    fx = (dx+1) - (sx+1)*inv_scale_x;
+                    fx = fx <= 0 ? 0.f : fx - cvFloor(fx);
+                }
+
+                if( sx >= ssize.width-1 )
+                {
+                    fx = 0, sx = ssize.width-1;
+                    if( xmax >= dsize.width )
+                        xmax = dx;
+                }
+                else if( sx < 0 )
+                    fx = 0, sx = 0;
+
+                if( depth != CV_8U )
+                    for( k = 0, sx *= cn; k < cn; k++ )
+                        xofs[dx*cn + k].idx = sx + k, xofs[dx*cn + k].alpha = fx;
+                else
+                    for( k = 0, sx *= cn; k < cn; k++ )
+                        xofs[dx*cn + k].idx = sx + k,
+                        xofs[dx*cn + k].ialpha = CV_FLT_TO_FIX(fx, ICV_WARP_SHIFT);
+            }
+
+            for( dy = 0; dy < dsize.height; dy++ )
+            {
+                if( !area_mode )
+                {
+                    fy = (float)((dy+0.5)*scale_y - 0.5);
+                    sy = cvFloor(fy);
+                    fy -= sy;
+                    if( sy < 0 )
+                        sy = 0, fy = 0;
+                }
+                else
+                {
+                    sy = cvFloor(dy*scale_y);
+                    fy = (dy+1) - (sy+1)*inv_scale_y;
+                    fy = fy <= 0 ? 0.f : fy - cvFloor(fy);
+                }
+
+                yofs[dy].idx = sy;
+                if( depth != CV_8U )
+                    yofs[dy].alpha = fy;
+                else
+                    yofs[dy].ialpha = CV_FLT_TO_FIX(fy, ICV_WARP_SHIFT);
+            }
+
+            IPPI_CALL( func( src->data.ptr, src->step, ssize, dst->data.ptr,
+                             dst->step, dsize, cn, xmax, xofs, yofs, buf0, buf1 ));
+        }
+    }
+    else if( method == CV_INTER_CUBIC )
+    {
+        int width = dsize.width*cn, buf_size;
+        int xmin = ssize.width, xmax = -1;
+        CvResizeAlpha* xofs;
+        float* buf[4];
+        CvResizeBicubicFunc func = (CvResizeBicubicFunc)bicube_tab.fn_2d[depth];
+
+        if( !func )
+            CV_ERROR( CV_StsUnsupportedFormat, "" );
+        
+        buf_size = width*(4*sizeof(float) + sizeof(xofs[0]));
+        if( buf_size < CV_MAX_LOCAL_SIZE )
+            buf[0] = (float*)cvStackAlloc(buf_size);
+        else
+            CV_CALL( temp_buf = buf[0] = (float*)cvAlloc(buf_size));
+
+        for( k = 1; k < 4; k++ )
+            buf[k] = buf[k-1] + width;
+        xofs = (CvResizeAlpha*)(buf[3] + width);
+
+        icvInitCubicCoeffTab();
+
+        for( dx = 0; dx < dsize.width; dx++ )
+        {
+            float fx = dx*scale_x;
+            sx = cvFloor(fx);
+            fx -= sx;
+            int ifx = cvRound(fx*ICV_CUBIC_TAB_SIZE);
+            if( sx >= 0 && xmin > dx )
+                xmin = dx;
+            if( sx+2 < ssize.width )
+                xmax = dx + 1;
+        
+            // at least one of 4 points should be within the image - to
+            // be able to set other points to the same value. see the loops
+            // for( dx = 0; dx < xmin; dx++ ) ... and for( ; dx < width; dx++ ) ...
+            if( sx < -2 )
+                sx = -2;
+            else if( sx > ssize.width )
+                sx = ssize.width;
+
+            for( k = 0; k < cn; k++ )
+            {
+                xofs[dx*cn + k].idx = sx*cn + k;
+                xofs[dx*cn + k].ialpha = ifx;
+            }
+        }
+    
+        IPPI_CALL( func( src->data.ptr, src->step, ssize, dst->data.ptr,
+                         dst->step, dsize, cn, xmin, xmax, xofs, buf ));
+    }
+    else
+        CV_ERROR( CV_StsBadFlag, "Unknown/unsupported interpolation method" );
+
+    __END__;
+
+    cvFree( &temp_buf );
+}
+
+
+/****************************************************************************************\
+*                                     WarpAffine                                         *
+\****************************************************************************************/
+
+#define ICV_DEF_WARP_AFFINE_BILINEAR_FUNC( flavor, arrtype, worktype,       \
+            scale_alpha_macro, mul_one_macro, descale_macro, cast_macro )   \
+static CvStatus CV_STDCALL                                                  \
+icvWarpAffine_Bilinear_##flavor##_CnR(                                      \
+    const arrtype* src, int step, CvSize ssize,                             \
+    arrtype* dst, int dststep, CvSize dsize,                                \
+    const double* matrix, int cn,                                           \
+    const arrtype* fillval, const int* ofs )                                \
+{                                                                           \
+    int x, y, k;                                                            \
+    double  A12 = matrix[1], b1 = matrix[2];                                \
+    double  A22 = matrix[4], b2 = matrix[5];                                \
+                                                                            \
+    step /= sizeof(src[0]);                                                 \
+    dststep /= sizeof(dst[0]);                                              \
+                                                                            \
+    for( y = 0; y < dsize.height; y++, dst += dststep )                     \
+    {                                                                       \
+        int xs = CV_FLT_TO_FIX( A12*y + b1, ICV_WARP_SHIFT );               \
+        int ys = CV_FLT_TO_FIX( A22*y + b2, ICV_WARP_SHIFT );               \
+                                                                            \
+        for( x = 0; x < dsize.width; x++ )                                  \
+        {                                                                   \
+            int ixs = xs + ofs[x*2];                                        \
+            int iys = ys + ofs[x*2+1];                                      \
+            worktype a = scale_alpha_macro( ixs & ICV_WARP_MASK );          \
+            worktype b = scale_alpha_macro( iys & ICV_WARP_MASK );          \
+            worktype p0, p1;                                                \
+            ixs >>= ICV_WARP_SHIFT;                                         \
+            iys >>= ICV_WARP_SHIFT;                                         \
+                                                                            \
+            if( (unsigned)ixs < (unsigned)(ssize.width - 1) &&              \
+                (unsigned)iys < (unsigned)(ssize.height - 1) )              \
+            {                                                               \
+                const arrtype* ptr = src + step*iys + ixs*cn;               \
+                                                                            \
+                for( k = 0; k < cn; k++ )                                   \
+                {                                                           \
+                    p0 = mul_one_macro(ptr[k]) +                            \
+                        a * (ptr[k+cn] - ptr[k]);                           \
+                    p1 = mul_one_macro(ptr[k+step]) +                       \
+                        a * (ptr[k+cn+step] - ptr[k+step]);                 \
+                    p0 = descale_macro(mul_one_macro(p0) + b*(p1 - p0));    \
+                    dst[x*cn+k] = (arrtype)cast_macro(p0);                  \
+                }                                                           \
+            }                                                               \
+            else if( (unsigned)(ixs+1) < (unsigned)(ssize.width+1) &&       \
+                     (unsigned)(iys+1) < (unsigned)(ssize.height+1))        \
+            {                                                               \
+                int x0 = ICV_WARP_CLIP_X( ixs );                            \
+                int y0 = ICV_WARP_CLIP_Y( iys );                            \
+                int x1 = ICV_WARP_CLIP_X( ixs + 1 );                        \
+                int y1 = ICV_WARP_CLIP_Y( iys + 1 );                        \
+                const arrtype* ptr0, *ptr1, *ptr2, *ptr3;                   \
+                                                                            \
+                ptr0 = src + y0*step + x0*cn;                               \
+                ptr1 = src + y0*step + x1*cn;                               \
+                ptr2 = src + y1*step + x0*cn;                               \
+                ptr3 = src + y1*step + x1*cn;                               \
+                                                                            \
+                for( k = 0; k < cn; k++ )                                   \
+                {                                                           \
+                    p0 = mul_one_macro(ptr0[k]) + a * (ptr1[k] - ptr0[k]);  \
+                    p1 = mul_one_macro(ptr2[k]) + a * (ptr3[k] - ptr2[k]);  \
+                    p0 = descale_macro( mul_one_macro(p0) + b*(p1 - p0) );  \
+                    dst[x*cn+k] = (arrtype)cast_macro(p0);                  \
+                }                                                           \
+            }                                                               \
+            else if( fillval )                                              \
+                for( k = 0; k < cn; k++ )                                   \
+                    dst[x*cn+k] = fillval[k];                               \
+        }                                                                   \
+    }                                                                       \
+                                                                            \
+    return CV_OK;                                                           \
+}
+
+
+#define ICV_WARP_SCALE_ALPHA(x) ((x)*(1./(ICV_WARP_MASK+1)))
+
+ICV_DEF_WARP_AFFINE_BILINEAR_FUNC( 8u, uchar, int, CV_NOP, ICV_WARP_MUL_ONE_8U,
+                                   ICV_WARP_DESCALE_8U, CV_NOP )
+//ICV_DEF_WARP_AFFINE_BILINEAR_FUNC( 8u, uchar, double, ICV_WARP_SCALE_ALPHA, CV_NOP,
+//                                   CV_NOP, ICV_WARP_CAST_8U )
+ICV_DEF_WARP_AFFINE_BILINEAR_FUNC( 16u, ushort, double, ICV_WARP_SCALE_ALPHA, CV_NOP,
+                                   CV_NOP, cvRound )
+ICV_DEF_WARP_AFFINE_BILINEAR_FUNC( 32f, float, double, ICV_WARP_SCALE_ALPHA, CV_NOP,
+                                   CV_NOP, CV_NOP )
+
+
+typedef CvStatus (CV_STDCALL * CvWarpAffineFunc)(
+    const void* src, int srcstep, CvSize ssize,
+    void* dst, int dststep, CvSize dsize,
+    const double* matrix, int cn,
+    const void* fillval, const int* ofs );
+
+static void icvInitWarpAffineTab( CvFuncTable* bilin_tab )
+{
+    bilin_tab->fn_2d[CV_8U] = (void*)icvWarpAffine_Bilinear_8u_CnR;
+    bilin_tab->fn_2d[CV_16U] = (void*)icvWarpAffine_Bilinear_16u_CnR;
+    bilin_tab->fn_2d[CV_32F] = (void*)icvWarpAffine_Bilinear_32f_CnR;
+}
+
+
+CV_IMPL void
+cvWarpAffine( const CvArr* srcarr, CvArr* dstarr, const CvMat* matrix,
+              int flags, CvScalar fillval )
+{
+    static CvFuncTable bilin_tab;
+    static int inittab = 0;
+
+    CV_FUNCNAME( "cvWarpAffine" );
+
+    __BEGIN__;
+    
+    CvMat srcstub, *src = (CvMat*)srcarr;
+    CvMat dststub, *dst = (CvMat*)dstarr;
+    int k, depth, cn, *ofs = 0;
+    double src_matrix[6], dst_matrix[6];
+    double fillbuf[4];
+    CvMat srcAb = cvMat( 2, 3, CV_64F, src_matrix ),
+          dstAb = cvMat( 2, 3, CV_64F, dst_matrix ),
+          A, b, invA, invAb;
+    CvWarpAffineFunc func;
+    CvSize ssize, dsize;
+    
+    if( !inittab )
+    {
+        icvInitWarpAffineTab( &bilin_tab );
+        inittab = 1;
+    }
+
+    CV_CALL( src = cvGetMat( srcarr, &srcstub ));
+    CV_CALL( dst = cvGetMat( dstarr, &dststub ));
+    
+    if( !CV_ARE_TYPES_EQ( src, dst ))
+        CV_ERROR( CV_StsUnmatchedFormats, "" );
+
+    if( !CV_IS_MAT(matrix) || CV_MAT_CN(matrix->type) != 1 ||
+        CV_MAT_DEPTH(matrix->type) < CV_32F || matrix->rows != 2 || matrix->cols != 3 )
+        CV_ERROR( CV_StsBadArg,
+        "Transformation matrix should be 2x3 floating-point single-channel matrix" );
+
+    if( flags & CV_WARP_INVERSE_MAP )
+        cvConvertScale( matrix, &invAb );
+    else
+    {
+        // [R|t] -> [R^-1 | -(R^-1)*t]
+        cvConvertScale( matrix, &srcAb );
+        cvGetCols( &srcAb, &A, 0, 2 );
+        cvGetCol( &srcAb, &b, 2 );
+        cvGetCols( &dstAb, &invA, 0, 2 );
+        cvGetCol( &dstAb, &invAb, 2 );
+        cvInvert( &A, &invA, CV_SVD );
+        cvGEMM( &invA, &b, -1, 0, 0, &invAb );
+    }
+
+    depth = CV_MAT_DEPTH(src->type);
+    cn = CV_MAT_CN(src->type);
+
+    cvScalarToRawData( &fillval, fillbuf, CV_MAT_TYPE(src->type), 0 );
+    ofs = (int*)cvStackAlloc( dst->cols*2*sizeof(ofs[0]) );
+    for( k = 0; k < dst->cols; k++ )
+    {
+        ofs[2*k] = CV_FLT_TO_FIX( dst_matrix[0]*k, ICV_WARP_SHIFT );
+        ofs[2*k+1] = CV_FLT_TO_FIX( dst_matrix[3]*k, ICV_WARP_SHIFT );
+    }
+
+    ssize = cvGetMatSize(src);
+    dsize = cvGetMatSize(dst);
+
+    /*if( method == CV_INTER_LINEAR )*/
+    {
+        func = (CvWarpAffineFunc)bilin_tab.fn_2d[depth];
+        if( !func )
+            CV_ERROR( CV_StsUnsupportedFormat, "" );
+
+        IPPI_CALL( func( src->data.ptr, src->step, ssize, dst->data.ptr,
+                         dst->step, dsize, dst_matrix, cn,
+                         flags & CV_WARP_FILL_OUTLIERS ? fillbuf : 0, ofs ));
+    }
+
+    __END__;
+}
+
+
+CV_IMPL CvMat*
+cv2DRotationMatrix( CvPoint2D32f center, double angle,
+                    double scale, CvMat* matrix )
+{
+    CV_FUNCNAME( "cvGetRotationMatrix" );
+
+    __BEGIN__;
+
+    double m[2][3];
+    CvMat M = cvMat( 2, 3, CV_64FC1, m );
+    double alpha, beta;
+
+    if( !matrix )
+        CV_ERROR( CV_StsNullPtr, "" );
+
+    angle *= CV_PI/180;
+    alpha = cos(angle)*scale;
+    beta = sin(angle)*scale;
+
+    m[0][0] = alpha;
+    m[0][1] = beta;
+    m[0][2] = (1-alpha)*center.x - beta*center.y;
+    m[1][0] = -beta;
+    m[1][1] = alpha;
+    m[1][2] = beta*center.x + (1-alpha)*center.y;
+
+    cvConvert( &M, matrix );
+
+    __END__;
+
+    return matrix;
+}
+
+
+/****************************************************************************************\
+*                                    WarpPerspective                                     *
+\****************************************************************************************/
+
+#define ICV_DEF_WARP_PERSPECTIVE_BILINEAR_FUNC( flavor, arrtype, load_macro, cast_macro )\
+static CvStatus CV_STDCALL                                                  \
+icvWarpPerspective_Bilinear_##flavor##_CnR(                                 \
+    const arrtype* src, int step, CvSize ssize,                             \
+    arrtype* dst, int dststep, CvSize dsize,                                \
+    const double* matrix, int cn,                                           \
+    const arrtype* fillval )                                                \
+{                                                                           \
+    int x, y, k;                                                            \
+    float A11 = (float)matrix[0], A12 = (float)matrix[1], A13 = (float)matrix[2];\
+    float A21 = (float)matrix[3], A22 = (float)matrix[4], A23 = (float)matrix[5];\
+    float A31 = (float)matrix[6], A32 = (float)matrix[7], A33 = (float)matrix[8];\
+                                                                            \
+    step /= sizeof(src[0]);                                                 \
+    dststep /= sizeof(dst[0]);                                              \
+                                                                            \
+    for( y = 0; y < dsize.height; y++, dst += dststep )                     \
+    {                                                                       \
+        float xs0 = A12*y + A13;                                            \
+        float ys0 = A22*y + A23;                                            \
+        float ws = A32*y + A33;                                             \
+                                                                            \
+        for( x = 0; x < dsize.width; x++, xs0 += A11, ys0 += A21, ws += A31 )\
+        {                                                                   \
+            float inv_ws = 1.f/ws;                                          \
+            float xs = xs0*inv_ws;                                          \
+            float ys = ys0*inv_ws;                                          \
+            int ixs = cvFloor(xs);                                          \
+            int iys = cvFloor(ys);                                          \
+            float a = xs - ixs;                                             \
+            float b = ys - iys;                                             \
+            float p0, p1;                                                   \
+                                                                            \
+            if( (unsigned)ixs < (unsigned)(ssize.width - 1) &&              \
+                (unsigned)iys < (unsigned)(ssize.height - 1) )              \
+            {                                                               \
+                const arrtype* ptr = src + step*iys + ixs*cn;               \
+                                                                            \
+                for( k = 0; k < cn; k++ )                                   \
+                {                                                           \
+                    p0 = load_macro(ptr[k]) +                               \
+                        a * (load_macro(ptr[k+cn]) - load_macro(ptr[k]));   \
+                    p1 = load_macro(ptr[k+step]) +                          \
+                        a * (load_macro(ptr[k+cn+step]) -                   \
+                             load_macro(ptr[k+step]));                      \
+                    dst[x*cn+k] = (arrtype)cast_macro(p0 + b*(p1 - p0));    \
+                }                                                           \
+            }                                                               \
+            else if( (unsigned)(ixs+1) < (unsigned)(ssize.width+1) &&       \
+                     (unsigned)(iys+1) < (unsigned)(ssize.height+1))        \
+            {                                                               \
+                int x0 = ICV_WARP_CLIP_X( ixs );                            \
+                int y0 = ICV_WARP_CLIP_Y( iys );                            \
+                int x1 = ICV_WARP_CLIP_X( ixs + 1 );                        \
+                int y1 = ICV_WARP_CLIP_Y( iys + 1 );                        \
+                const arrtype* ptr0, *ptr1, *ptr2, *ptr3;                   \
+                                                                            \
+                ptr0 = src + y0*step + x0*cn;                               \
+                ptr1 = src + y0*step + x1*cn;                               \
+                ptr2 = src + y1*step + x0*cn;                               \
+                ptr3 = src + y1*step + x1*cn;                               \
+                                                                            \
+                for( k = 0; k < cn; k++ )                                   \
+                {                                                           \
+                    p0 = load_macro(ptr0[k]) +                              \
+                        a * (load_macro(ptr1[k]) - load_macro(ptr0[k]));    \
+                    p1 = load_macro(ptr2[k]) +                              \
+                        a * (load_macro(ptr3[k]) - load_macro(ptr2[k]));    \
+                    dst[x*cn+k] = (arrtype)cast_macro(p0 + b*(p1 - p0));    \
+                }                                                           \
+            }                                                               \
+            else if( fillval )                                              \
+                for( k = 0; k < cn; k++ )                                   \
+                    dst[x*cn+k] = fillval[k];                               \
+        }                                                                   \
+    }                                                                       \
+                                                                            \
+    return CV_OK;                                                           \
+}
+
+
+#define ICV_WARP_SCALE_ALPHA(x) ((x)*(1./(ICV_WARP_MASK+1)))
+
+ICV_DEF_WARP_PERSPECTIVE_BILINEAR_FUNC( 8u, uchar, CV_8TO32F, cvRound )
+ICV_DEF_WARP_PERSPECTIVE_BILINEAR_FUNC( 16u, ushort, CV_NOP, cvRound )
+ICV_DEF_WARP_PERSPECTIVE_BILINEAR_FUNC( 32f, float, CV_NOP, CV_NOP )
+
+typedef CvStatus (CV_STDCALL * CvWarpPerspectiveFunc)(
+    const void* src, int srcstep, CvSize ssize,
+    void* dst, int dststep, CvSize dsize,
+    const double* matrix, int cn, const void* fillval );
+
+static void icvInitWarpPerspectiveTab( CvFuncTable* bilin_tab )
+{
+    bilin_tab->fn_2d[CV_8U] = (void*)icvWarpPerspective_Bilinear_8u_CnR;
+    bilin_tab->fn_2d[CV_16U] = (void*)icvWarpPerspective_Bilinear_16u_CnR;
+    bilin_tab->fn_2d[CV_32F] = (void*)icvWarpPerspective_Bilinear_32f_CnR;
+}
+
+
+CV_IMPL void
+cvWarpPerspective( const CvArr* srcarr, CvArr* dstarr,
+                   const CvMat* matrix, int flags, CvScalar fillval )
+{
+    static CvFuncTable bilin_tab;
+    static int inittab = 0;
+
+    CV_FUNCNAME( "cvWarpPerspective" );
+
+    __BEGIN__;
+    
+    CvMat srcstub, *src = (CvMat*)srcarr;
+    CvMat dststub, *dst = (CvMat*)dstarr;
+    int depth, cn;
+    double src_matrix[9], dst_matrix[9];
+    double fillbuf[4];
+    CvMat A = cvMat( 3, 3, CV_64F, src_matrix ),
+          invA = cvMat( 3, 3, CV_64F, dst_matrix );
+    CvWarpPerspectiveFunc func;
+    CvSize ssize, dsize;
+    
+    if( !inittab )
+    {
+        icvInitWarpPerspectiveTab( &bilin_tab );
+        inittab = 1;
+    }
+
+    CV_CALL( src = cvGetMat( srcarr, &srcstub ));
+    CV_CALL( dst = cvGetMat( dstarr, &dststub ));
+    
+    if( !CV_ARE_TYPES_EQ( src, dst ))
+        CV_ERROR( CV_StsUnmatchedFormats, "" );
+
+    if( !CV_IS_MAT(matrix) || CV_MAT_CN(matrix->type) != 1 ||
+        CV_MAT_DEPTH(matrix->type) < CV_32F || matrix->rows != 3 || matrix->cols != 3 )
+        CV_ERROR( CV_StsBadArg,
+        "Transformation matrix should be 2x3 floating-point single-channel matrix" );
+
+    if( flags & CV_WARP_INVERSE_MAP )
+        cvConvertScale( matrix, &invA );
+    else
+    {
+        cvConvertScale( matrix, &A );
+        cvInvert( &A, &invA, CV_SVD );
+    }
+
+    depth = CV_MAT_DEPTH(src->type);
+    cn = CV_MAT_CN(src->type);
+    cvScalarToRawData( &fillval, fillbuf, CV_MAT_TYPE(src->type), 0 );
+
+    ssize = cvGetMatSize(src);
+    dsize = cvGetMatSize(dst);
+
+    /*if( method == CV_INTER_LINEAR )*/
+    {
+        func = (CvWarpPerspectiveFunc)bilin_tab.fn_2d[depth];
+        if( !func )
+            CV_ERROR( CV_StsUnsupportedFormat, "" );
+
+        IPPI_CALL( func( src->data.ptr, src->step, ssize, dst->data.ptr,
+                         dst->step, dsize, dst_matrix, cn,
+                         flags & CV_WARP_FILL_OUTLIERS ? fillbuf : 0 ));
+    }
+
+    __END__;
+}
+
+
+/* Calculates coefficients of perspective transformation
+ * which maps (xi,yi) to (ui,vi), (i=1,2,3,4):
+ *
+ *      c00*xi + c01*yi + c02
+ * ui = ---------------------
+ *      c20*xi + c21*yi + c22
+ *
+ *      c10*xi + c11*yi + c12
+ * vi = ---------------------
+ *      c20*xi + c21*yi + c22
+ *
+ * Coefficients are calculated by solving linear system:
+ * / x0 y0  1  0  0  0 -x0*u0 -y0*u0 \ /c00\ /u0\
+ * | x1 y1  1  0  0  0 -x1*u1 -y1*u1 | |c01| |u1|
+ * | x2 y2  1  0  0  0 -x2*u2 -y2*u2 | |c02| |u2|
+ * | x3 y3  1  0  0  0 -x3*u3 -y3*u3 |.|c10|=|u3|,
+ * |  0  0  0 x0 y0  1 -x0*v0 -y0*v0 | |c11| |v0|
+ * |  0  0  0 x1 y1  1 -x1*v1 -y1*v1 | |c12| |v1|
+ * |  0  0  0 x2 y2  1 -x2*v2 -y2*v2 | |c20| |v2|
+ * \  0  0  0 x3 y3  1 -x3*v3 -y3*v3 / \c21/ \v3/
+ *
+ * where:
+ *   cij - matrix coefficients, c22 = 1
+ */
+CV_IMPL CvMat*
+cvWarpPerspectiveQMatrix( const CvPoint2D32f* src,
+                          const CvPoint2D32f* dst,
+                          CvMat* matrix )
+{
+    CV_FUNCNAME( "cvGetPerspectiveTransformMatrix" );
+
+    __BEGIN__;
+
+    double a[8][8];
+    double b[8], x[9];
+
+    CvMat A = cvMat( 8, 8, CV_64FC1, a );
+    CvMat B = cvMat( 8, 1, CV_64FC1, b );
+    CvMat X = cvMat( 8, 1, CV_64FC1, x );
+
+    int i;
+
+    if( !src || !dst || !matrix )
+        CV_ERROR( CV_StsNullPtr, "" );
+
+    for( i = 0; i < 4; ++i )
+    {
+        a[i][0] = a[i+4][3] = src[i].x;
+        a[i][1] = a[i+4][4] = src[i].y;
+        a[i][2] = a[i+4][5] = 1;
+        a[i][3] = a[i][4] = a[i][5] =
+        a[i+4][0] = a[i+4][1] = a[i+4][2] = 0;
+        a[i][6] = -src[i].x*dst[i].x;
+        a[i][7] = -src[i].y*dst[i].x;
+        a[i+4][6] = -src[i].x*dst[i].y;
+        a[i+4][7] = -src[i].y*dst[i].y;
+        b[i] = dst[i].x;
+        b[i+4] = dst[i].y;
+    }
+
+    cvSolve( &A, &B, &X, CV_SVD );
+    x[8] = 1;
+    
+    X = cvMat( 3, 3, CV_64F, x );
+    cvConvert( &X, matrix );
+
+    __END__;
+
+    return matrix;
+}
+
+
+/* End of file. */
+
index 22a99dd44255196c37fcaca22eb3845a89ca2535..f2eb3277e1f09862e09dd6bfa44f23092634b641 100644 (file)
@@ -39,9 +39,6 @@
 //
 //M*/
 #include "_cv.h"
-#include "_cvutils.h"
-
-#include <math.h>
 
 #define _FP double
 
@@ -49,7 +46,7 @@
 #pragma warning (disable:4701)
 #endif
 
-CvStatus
+static CvStatus
 icvFitLine2D_wods( CvPoint2D32f * points, int _count, float *weights, float *line )
 {
     _FP x = 0, y = 0, x2 = 0, y2 = 0, xy = 0, w = 0;
@@ -105,7 +102,7 @@ icvFitLine2D_wods( CvPoint2D32f * points, int _count, float *weights, float *lin
     return CV_NO_ERR;
 }
 
-CvStatus
+static CvStatus
 icvFitLine3D_wods( CvPoint3D32f * points, int count, float *weights, float *line )
 {
     int i;
@@ -193,6 +190,7 @@ icvFitLine3D_wods( CvPoint3D32f * points, int count, float *weights, float *line
     det[8] = dy2 + dx2;
 
     /* Searching for a eigenvector of det corresponding to the minimal eigenvalue */
+#if 1
     ret = icvJacobiEigens_32f( det, evc, evl, 3, 0 );
     if( ret != CV_NO_ERR )
     {
@@ -200,8 +198,18 @@ icvFitLine3D_wods( CvPoint3D32f * points, int count, float *weights, float *line
     }
 
     i = evl[0] < evl[1] ? (evl[0] < evl[2] ? 0 : 2) : (evl[1] < evl[2] ? 1 : 2);
+#else
+    {
+        CvMat _det = cvMat( 3, 3, CV_32F, det );
+        CvMat _evc = cvMat( 3, 3, CV_32F, evc );
+        CvMat _evl = cvMat( 1, 3, CV_32F, evl );
+
+        cvSVD( &_det, &_evl, &_evc, 0, CV_SVD_MODIFY_A+CV_SVD_U_T );
+    }
+    i = 2;
+#endif
     v = &evc[i * 3];
-    n = (float) sqrt( v[0] * v[0] + v[1] * v[1] + v[2] * v[2] );
+    n = (float) sqrt( (double)v[0] * v[0] + (double)v[1] * v[1] + (double)v[2] * v[2] );
     line[0] = v[0] / n;
     line[1] = v[1] / n;
     line[2] = v[2] / n;
@@ -212,7 +220,7 @@ icvFitLine3D_wods( CvPoint3D32f * points, int count, float *weights, float *line
     return CV_NO_ERR;
 }
 
-void
+static void
 icvCalcDist2D( CvPoint2D32f * points, int count, float *_line, float *dist )
 {
     int j;
@@ -230,7 +238,7 @@ icvCalcDist2D( CvPoint2D32f * points, int count, float *_line, float *dist )
     }
 }
 
-void
+static void
 icvCalcDist3D( CvPoint3D32f * points, int count, float *_line, float *dist )
 {
     int j;
@@ -240,20 +248,21 @@ icvCalcDist3D( CvPoint3D32f * points, int count, float *_line, float *dist )
     for( j = 0; j < count; j++ )
     {
         float x, y, z;
+        double p1, p2, p3;
 
         x = points[j].x - px;
         y = points[j].y - py;
         z = points[j].z - pz;
 
-        dist[j] =
-            (float) sqrt( (vy * z - vz * y) * (vy * z - vz * y) +
-                          (vz * x - vx * z) * (vz * x - vx * z) + (vx * y - vy * x) * (vx * y -
-                                                                                       vy *
-                                                                                       x) );
+        p1 = vy * z - vz * y;
+        p2 = vz * x - vx * z;
+        p3 = vx * y - vy * x;
+
+        dist[j] = (float) sqrt( p1*p1 + p2*p2 + p3*p3 );
     }
 }
 
-void
+static void
 icvWeightL1( float *d, int count, float *w )
 {
     int i;
@@ -264,19 +273,19 @@ icvWeightL1( float *d, int count, float *w )
     }
 }
 
-void
+static void
 icvWeightL12( float *d, int count, float *w )
 {
     int i;
 
     for( i = 0; i < count; i++ )
     {
-        w[i] = 1.0f / (float) sqrt( 1 + (double) (d[i] * d[i] / 2) );
+        w[i] = 1.0f / (float) sqrt( 1 + (double) (d[i] * d[i] * 0.5) );
     }
 }
 
 
-void
+static void
 icvWeightHuber( float *d, int count, float *w, float _c )
 {
     int i;
@@ -292,7 +301,7 @@ icvWeightHuber( float *d, int count, float *w, float _c )
 }
 
 
-void
+static void
 icvWeightFair( float *d, int count, float *w, float _c )
 {
     int i;
@@ -304,7 +313,7 @@ icvWeightFair( float *d, int count, float *w, float _c )
     }
 }
 
-void
+static void
 icvWeightWelsch( float *d, int count, float *w, float _c )
 {
     int i;
@@ -322,7 +331,7 @@ distance specified by callbacks, fills the array of four floats with line
 parameters A, B, C, D, where (A, B) is the normalized direction vector,
 (C, D) is the point that belongs to the line. */
 
-static CvStatus  icvFitLine2D( CvPoint2D32f * points, int count, CvDisType dist,
+static CvStatus  icvFitLine2D( CvPoint2D32f * points, int count, int dist,
                                float _param, float reps, float aeps, float *line )
 {
     void (*calc_weights) (float *, int, float *) = 0;
@@ -369,8 +378,8 @@ static CvStatus  icvFitLine2D( CvPoint2D32f * points, int count, CvDisType dist,
         return CV_BADFACTOR_ERR;
     }
 
-    w = (float *) icvAlloc( count * sizeof( float ));
-    r = (float *) icvAlloc( count * sizeof( float ));
+    w = (float *) cvAlloc( count * sizeof( float ));
+    r = (float *) cvAlloc( count * sizeof( float ));
 
     for( i = 0; i < count; i++ )
         w[i] = 1.0f;
@@ -380,8 +389,8 @@ static CvStatus  icvFitLine2D( CvPoint2D32f * points, int count, CvDisType dist,
     {
         if( ret != CV_NO_ERR )
         {
-            icvFree( &w );
-            icvFree( &r );
+            cvFree( (void**)&w );
+            cvFree( (void**)&r );
             return ret;
         }
 
@@ -405,8 +414,8 @@ static CvStatus  icvFitLine2D( CvPoint2D32f * points, int count, CvDisType dist,
                     // Return...
                     memcpy( line, _line, 4 * sizeof( float ));
 
-                    icvFree( &w );
-                    icvFree( &r );
+                    cvFree( (void**)&w );
+                    cvFree( (void**)&r );
                     return CV_NO_ERR;
                 }
 
@@ -438,8 +447,8 @@ static CvStatus  icvFitLine2D( CvPoint2D32f * points, int count, CvDisType dist,
         ret = icvFitLine2D_wods( points, count, w, _line );
     }
 
-    icvFree( &w );
-    icvFree( &r );
+    cvFree( (void**)&w );
+    cvFree( (void**)&r );
     return CV_BADCONVERGENCE_ERR;
 }
 
@@ -449,7 +458,7 @@ distance specified by callbacks, fills the array of four floats with line
 parameters A, B, C, D, E, F, where (A, B, C) is the normalized direction vector, 
 (D, E, F) is the point that belongs to the line. */
 
-static CvStatus  icvFitLine3D( CvPoint3D32f * points, int count, CvDisType dist,
+static CvStatus  icvFitLine3D( CvPoint3D32f * points, int count, int dist,
                                float _param, float reps, float aeps, float *line )
 {
     void (*calc_weights) (float *, int, float *) = 0;
@@ -497,8 +506,8 @@ static CvStatus  icvFitLine3D( CvPoint3D32f * points, int count, CvDisType dist,
         return CV_BADFACTOR_ERR;
     }
 
-    w = (float *) icvAlloc( count * sizeof( float ));
-    r = (float *) icvAlloc( count * sizeof( float ));
+    w = (float *) cvAlloc( count * sizeof( float ));
+    r = (float *) cvAlloc( count * sizeof( float ));
 
     for( i = 0; i < count; i++ )
         w[i] = 1.0f;
@@ -508,8 +517,8 @@ static CvStatus  icvFitLine3D( CvPoint3D32f * points, int count, CvDisType dist,
     {
         if( ret != CV_NO_ERR )
         {
-            icvFree( &w );
-            icvFree( &r );
+            cvFree( (void**)&w );
+            cvFree( (void**)&r );
             return ret;
         }
 
@@ -543,8 +552,8 @@ static CvStatus  icvFitLine3D( CvPoint3D32f * points, int count, CvDisType dist,
                     // Return...
                     memcpy( line, _line, 6 * sizeof( float ));
 
-                    icvFree( &w );
-                    icvFree( &r );
+                    cvFree( (void**)&w );
+                    cvFree( (void**)&r );
                     return CV_NO_ERR;
                 }
 
@@ -575,14 +584,14 @@ static CvStatus  icvFitLine3D( CvPoint3D32f * points, int count, CvDisType dist,
         ret = icvFitLine3D_wods( points, count, w, _line );
     }
 
-    icvFree( &w );
-    icvFree( &r );
+    cvFree( (void**)&w );
+    cvFree( (void**)&r );
     return CV_BADCONVERGENCE_ERR;
 }
 
 
 CV_IMPL void
-cvFitLine( const CvArr* array, CvDisType dist, double param,
+cvFitLine( const CvArr* array, int dist, double param,
            double reps, double aeps, float *line )
 {
     char* buffer = 0;
@@ -605,7 +614,7 @@ cvFitLine( const CvArr* array, CvDisType dist, double param,
         if( ptseq->total == 0 )
             CV_ERROR( CV_StsBadSize, "The sequence has no points" );
         if( (type!=CV_32FC2 && type!=CV_32FC3 && type!=CV_32SC2 && type!=CV_32SC3) ||
-            icvPixSize[type] != ptseq->elem_size )
+            CV_ELEM_SIZE(type) != ptseq->elem_size )
             CV_ERROR( CV_StsUnsupportedFormat,
                 "Input sequence must consist of 2d points or 3d points" );
     }
@@ -623,7 +632,7 @@ cvFitLine( const CvArr* array, CvDisType dist, double param,
             "Input array must be 1d continuous array of 2d or 3d points" );
 
         CV_CALL( ptseq = cvMakeSeqHeaderForArray(
-            CV_SEQ_KIND_GENERIC|type, sizeof(CvContour), icvPixSize[type], mat->data.ptr,
+            CV_SEQ_KIND_GENERIC|type, sizeof(CvContour), CV_ELEM_SIZE(type), mat->data.ptr,
             mat->width + mat->height - 1, (CvSeq*)&contour_header, &block ));
     }
 
@@ -637,7 +646,7 @@ cvFitLine( const CvArr* array, CvDisType dist, double param,
     }
     else
     {
-        CV_CALL( buffer = points = (char*)cvAlloc( ptseq->total*icvPixSize[type] ));
+        CV_CALL( buffer = points = (char*)cvAlloc( ptseq->total*CV_ELEM_SIZE(type) ));
         
         if( CV_MAT_DEPTH(type) == CV_32F )
         {
index db69405a3108fa2d26a58a6ad9a9fc4f8c15c001..ace27dec4420aa97e24582841e742cccc2901d9e 100644 (file)
@@ -40,8 +40,8 @@
 //M*/
 #include "_cv.h"
 #include <float.h>
+#include <stdio.h>
 
-#if 1
 static void
 intersect( CvPoint2D32f pt, CvSize win_size, CvSize img_size,
            CvPoint * min_pt, CvPoint * max_pt )
@@ -62,10 +62,10 @@ intersect( CvPoint2D32f pt, CvSize win_size, CvSize img_size,
     max_pt->x = MIN( win_size.width, img_size.width - ipt.x );
     max_pt->y = MIN( win_size.height, img_size.height - ipt.y );
 }
-#endif
+
 
 static CvStatus
-icvInitPyramidalAlgorithm( uchar * imgA, uchar * imgB,
+icvInitPyramidalAlgorithm( const uchar * imgA, const uchar * imgB,
                            int imgStep, CvSize imgSize,
                            uchar * pyrA, uchar * pyrB,
                            int level,
@@ -100,18 +100,13 @@ icvInitPyramidalAlgorithm( uchar * imgA, uchar * imgB,
     if( level < 0 )
         return CV_BADRANGE_ERR;
 
-    /*if( imgSize.width % (1 << level) != 0 ||
-        imgSize.height % (1 << level) != 0 ||
-        (imgSize.width >> level) == 0 || (imgSize.height >> level) == 0 )
-        return CV_BADSIZE_ERR;*/
-
     switch (criteria->type)
     {
     case CV_TERMCRIT_ITER:
         criteria->epsilon = 0.f;
         break;
     case CV_TERMCRIT_EPS:
-        criteria->maxIter = max_iters;
+        criteria->max_iter = max_iters;
         break;
     case CV_TERMCRIT_ITER | CV_TERMCRIT_EPS:
         break;
@@ -135,7 +130,7 @@ icvInitPyramidalAlgorithm( uchar * imgA, uchar * imgB,
         levelSize.width = (levelSize.width + 1) >> 1;
         levelSize.height = (levelSize.height + 1) >> 1;
 
-        int tstep = icvAlign(levelSize.width,ALIGN) * sizeof( imgA[0] );
+        int tstep = cvAlign(levelSize.width,ALIGN) * sizeof( imgA[0] );
         pyrBytes += tstep * levelSize.height;
     }
 
@@ -146,7 +141,7 @@ icvInitPyramidalAlgorithm( uchar * imgA, uchar * imgB,
         (sizeof( imgI[0][0] ) * 2 + sizeof( step[0][0] ) +
          sizeof(size[0][0]) + sizeof( scale[0][0] )) * level1;
 
-    *buffer = (uchar *) icvAlloc( bufferBytes );
+    *buffer = (uchar *)cvAlloc( bufferBytes );
     if( !buffer[0] )
         return CV_OUTOFMEM_ERR;
 
@@ -156,8 +151,8 @@ icvInitPyramidalAlgorithm( uchar * imgA, uchar * imgB,
     *scale = (double *) (*step + level1);
     *size = (CvSize *)(*scale + level1);
 
-    imgI[0][0] = imgA;
-    imgJ[0][0] = imgB;
+    imgI[0][0] = (uchar*)imgA;
+    imgJ[0][0] = (uchar*)imgB;
     step[0][0] = imgStep;
     scale[0][0] = 1;
     size[0][0] = imgSize;
@@ -179,7 +174,7 @@ icvInitPyramidalAlgorithm( uchar * imgA, uchar * imgB,
             ptrB = bufPtr;
 
         icvPyrDownGetBufSize_Gauss5x5( imgSize.width, cv8u, 1, &pyr_down_buffer_size );
-        pyr_down_temp_buffer = (uchar *) icvAlloc( pyr_down_buffer_size );
+        pyr_down_temp_buffer = (uchar *) cvAlloc( pyr_down_buffer_size );
         
         levelSize = imgSize;
 
@@ -193,7 +188,7 @@ icvInitPyramidalAlgorithm( uchar * imgA, uchar * imgB,
             levelSize.height = (levelSize.height + 1) >> 1;
 
             size[0][i] = levelSize;
-            step[0][i] = icvAlign( levelSize.width, ALIGN ) * sizeof( imgA[0] );
+            step[0][i] = cvAlign( levelSize.width, ALIGN ) * sizeof( imgA[0] );
             scale[0][i] = scale[0][i - 1] * 0.5;
 
             levelBytes = step[0][i] * levelSize.height;
@@ -231,7 +226,7 @@ icvInitPyramidalAlgorithm( uchar * imgA, uchar * imgB,
     }
 
   func_exit:
-    icvFree( &pyr_down_temp_buffer );
+    cvFree( (void**)&pyr_down_temp_buffer );
 
     return CV_OK;
 }
@@ -299,13 +294,13 @@ icvInitPyramidalAlgorithm( uchar * imgA, uchar * imgB,
 //    Notes:  For calculating spatial derivatives 3x3 Sobel operator is used.
 //            The values of pixels beyond the image are determined using replication mode.
 //F*/
-static  CvStatus  icvCalcOpticalFlowPyrLK_8uC1R( uchar * imgA,
-                                                 uchar * imgB,
+static  CvStatus  icvCalcOpticalFlowPyrLK_8uC1R( const uchar * imgA,
+                                                 const uchar * imgB,
                                                  int imgStep,
                                                  CvSize imgSize,
                                                  uchar * pyrA,
                                                  uchar * pyrB,
-                                                 CvPoint2D32f * featuresA,
+                                                 const CvPoint2D32f * featuresA,
                                                  CvPoint2D32f * featuresB,
                                                  int count,
                                                  CvSize winSize,
@@ -313,7 +308,6 @@ static  CvStatus  icvCalcOpticalFlowPyrLK_8uC1R( uchar * imgA,
                                                  char *status,
                                                  float *error,
                                                  CvTermCriteria criteria, int flags )
-#if 1
 {
 #define MAX_LEVEL 10
 #define MAX_ITERS 100
@@ -371,7 +365,7 @@ static  CvStatus  icvCalcOpticalFlowPyrLK_8uC1R( uchar * imgA,
     /* buffer_size = <size for patches> + <size for pyramids> */
     bufferBytes = (srcPatchLen + patchLen * 3) * sizeof( patchI[0] );
 
-    buffer = (uchar *) icvAlloc( bufferBytes );
+    buffer = (uchar *) cvAlloc( bufferBytes );
     if( !buffer )
     {
         result = CV_OUTOFMEM_ERR;
@@ -395,8 +389,7 @@ static  CvStatus  icvCalcOpticalFlowPyrLK_8uC1R( uchar * imgA,
     {
         CvPoint2D32f v;
         CvPoint minI, maxI, minJ, maxJ;
-        int l;
-        int pt_status = 1;
+        int l, pt_status = 1;
 
         minI = maxI = minJ = maxJ = cvPoint( 0, 0 );
 
@@ -409,6 +402,9 @@ static  CvStatus  icvCalcOpticalFlowPyrLK_8uC1R( uchar * imgA,
         {
             CvPoint2D32f u;
             CvSize levelSize = size[l];
+            CvPoint prev_minJ = { -1, -1 }, prev_maxJ = { -1, -1 };
+            double Gxx = 0, Gxy = 0, Gyy = 0, D = 0;
+            float prev_mx = 0, prev_my = 0;
 
             v.x += v.x;
             v.y += v.y;
@@ -417,7 +413,7 @@ static  CvStatus  icvCalcOpticalFlowPyrLK_8uC1R( uchar * imgA,
             u.y = (float) (featuresA[i].y * scale[l]);
 
             if( icvGetRectSubPix_8u32f_C1R( imgI[l], step[l], levelSize,
-                                            patchI, srcPatchStep, srcPatchSize, u ) < 0 )
+                            patchI, srcPatchStep, srcPatchSize, u ) < 0 )
             {
                 /* point is outside the image. take the next */
                 pt_status = 0;
@@ -439,12 +435,10 @@ static  CvStatus  icvCalcOpticalFlowPyrLK_8uC1R( uchar * imgA,
 
             intersect( u, winSize, levelSize, &minI, &maxI );
 
-            for( j = 0; j < criteria.maxIter; j++ )
+            for( j = 0; j < criteria.max_iter; j++ )
             {
                 double bx = 0, by = 0;
                 float mx, my;
-                double Gxx = 0, Gxy = 0, Gyy = 0;
-                double D;
 
                 if( icvGetRectSubPix_8u32f_C1R( imgJ[l], step[l], levelSize,
                                                 patchJ, patchStep, patchSize, v ) < 0 )
@@ -462,29 +456,53 @@ static  CvStatus  icvCalcOpticalFlowPyrLK_8uC1R( uchar * imgA,
                 maxJ.x = MIN( maxJ.x, maxI.x );
                 maxJ.y = MIN( maxJ.y, maxI.y );
 
-                for( y = minJ.y; y < maxJ.y; y++ )
+                if( maxJ.x == prev_maxJ.x &&
+                    maxJ.y == prev_maxJ.y &&
+                    minJ.x == prev_minJ.x &&
+                    minJ.y == prev_minJ.y )
                 {
-                    for( x = minJ.x; x < maxJ.x; x++ )
+                    for( y = minJ.y; y < maxJ.y; y++ )
                     {
-                        int idx = y * (winSize.width * 2 + 1) + x;
-                        double t = patchI[idx] - patchJ[idx];
+                        for( x = minJ.x; x < maxJ.x; x++ )
+                        {
+                            int idx = y * (winSize.width * 2 + 1) + x;
+                            double t = patchI[idx] - patchJ[idx];
 
-                        bx += (double) (t * Ix[idx]);
-                        by += (double) (t * Iy[idx]);
-                        Gxx += Ix[idx] * Ix[idx];
-                        Gxy += Ix[idx] * Iy[idx];
-                        Gyy += Iy[idx] * Iy[idx];
+                            bx += (double) (t * Ix[idx]);
+                            by += (double) (t * Iy[idx]);
+                        }
                     }
                 }
-
-                D = Gxx * Gyy - Gxy * Gxy;
-                if( D < DBL_EPSILON )
+                else
                 {
-                    pt_status = 0;
-                    break;
-                }
+                    Gxx = Gyy = Gxy = 0;
+                    
+                    for( y = minJ.y; y < maxJ.y; y++ )
+                    {
+                        for( x = minJ.x; x < maxJ.x; x++ )
+                        {
+                            int idx = y * (winSize.width * 2 + 1) + x;
+                            double t = patchI[idx] - patchJ[idx];
+
+                            bx += (double) (t * Ix[idx]);
+                            by += (double) (t * Iy[idx]);
+                            Gxx += Ix[idx] * Ix[idx];
+                            Gxy += Ix[idx] * Iy[idx];
+                            Gyy += Iy[idx] * Iy[idx];
+                        }
+                    }
+
+                    D = Gxx * Gyy - Gxy * Gxy;
+                    if( D < DBL_EPSILON )
+                    {
+                        pt_status = 0;
+                        break;
+                    }
+                    D = 1. / D;
 
-                D = 1. / D;
+                    prev_minJ = minJ;
+                    prev_maxJ = maxJ;
+                }
 
                 mx = (float) ((Gyy * bx - Gxy * by) * D);
                 my = (float) ((Gxx * by - Gxy * bx) * D);
@@ -494,6 +512,15 @@ static  CvStatus  icvCalcOpticalFlowPyrLK_8uC1R( uchar * imgA,
 
                 if( mx * mx + my * my < criteria.epsilon )
                     break;
+
+                if( j > 0 && fabs(mx + prev_mx) < 0.01 && fabs(my + prev_my) < 0.01 )
+                {
+                    v.x -= mx*0.5f;
+                    v.y -= my*0.5f;
+                    break;
+                }
+                prev_mx = mx;
+                prev_my = my;
             }
 
             if( pt_status == 0 )
@@ -529,237 +556,14 @@ static  CvStatus  icvCalcOpticalFlowPyrLK_8uC1R( uchar * imgA,
 
   func_exit:
 
-    icvFree( &pyr_buffer );
-    icvFree( &buffer );
+    cvFree( (void**)&pyr_buffer );
+    cvFree( (void**)&buffer );
 
     return result;
 #undef MAX_LEVEL
 }
-#else
-{
-#define MAX_LEVEL 10
-#define MAX_ITERS 100
-
-    static const float kerX[] = { -1, 0, 1 }, kerY[] =
-    {
-    0.09375, 0.3125, 0.09375};  /* 3/32, 10/32, 3/32 */
-
-    uchar *pyr_buffer = 0;
-    uchar *buffer = 0;
-    int bufferBytes = 0;
-
-    uchar **imgI = 0;
-    uchar **imgJ = 0;
-    int *step = 0;
-    double *scale = 0;
-    CvSize* size = 0;
-
-    float *patchI;
-    float *patchJ;
-    float *Ix;
-    float *Iy;
-
-    int i, j, k;
-    int x, y;
-
-    CvSize patchSize = cvSize( winSize.width * 2 + 1, winSize.height * 2 + 1 );
-    int patchLen = patchSize.width * patchSize.height;
-    int patchStep = patchSize.width * sizeof( patchI[0] );
-
-    CvSize srcPatchSize = cvSize( patchSize.width + 2, patchSize.height + 2 );
-    int srcPatchLen = srcPatchSize.width * srcPatchSize.height;
-    int srcPatchStep = srcPatchSize.width * sizeof( patchI[0] );
-
-    CvStatus result = CV_OK;
-
-    /* check input arguments */
-    if( !featuresA || !featuresB )
-        return CV_NULLPTR_ERR;
-    if( winSize.width <= 1 || winSize.height <= 1 )
-        return CV_BADSIZE_ERR;
-
-    if( (flags & ~7) != 0 )
-        return CV_BADFLAG_ERR;
-    if( count <= 0 )
-        return CV_BADRANGE_ERR;
-
-    result = icvInitPyramidalAlgorithm( imgA, imgB, imgStep, imgSize,
-                                        pyrA, pyrB, level, &criteria, MAX_ITERS, flags,
-                                        &imgI, &imgJ, &step, &size, &scale, &pyr_buffer );
-
-    if( result < 0 )
-        goto func_exit;
-
-    /* buffer_size = <size for patches> + <size for pyramids> */
-    bufferBytes = (srcPatchLen + patchLen * 3) * sizeof( patchI[0] );
-
-    buffer = (uchar *) icvAlloc( bufferBytes );
-    if( !buffer )
-    {
-        result = CV_OUTOFMEM_ERR;
-        goto func_exit;
-    }
-
-    patchI = (float *) buffer;
-    patchJ = patchI + srcPatchLen;
-    Ix = patchJ + patchLen;
-    Iy = Ix + patchLen;
-
-    if( status )
-        memset( status, 1, count );
-
-    if( !(flags & CV_LKFLOW_INITIAL_GUESSES) )
-    {
-        memcpy( featuresB, featuresA, count * sizeof( featuresA[0] ));
-    }
-
-    /* find flow for each given point */
-    for( i = 0; i < count; i++ )
-    {
-        CvPoint2D32f v;
-        double t;
-
-        //CvPoint minI, maxI, minJ, maxJ;
-        int l;
-        int pt_status = 1;
-
-        //minI = maxI = minJ = maxJ = cvPoint(0,0);
-
-        v.x = (float) (featuresB[i].x * scale[level] * 0.5);
-        v.y = (float) (featuresB[i].y * scale[level] * 0.5);
-
-        /* do processing from top pyramid level (smallest image)
-           to the bottom (original image) */
-        for( l = level; l >= 0; l-- )
-        {
-            CvPoint2D32f u;
-            CvSize levelSize = size[l];
-            double Gxx, Gxy, Gyy, D;
-
-            Gxx = Gxy = Gyy = 0;
-
-            v.x += v.x;
-            v.y += v.y;
-
-            u.x = (float) (featuresA[i].x * scale[l]);
-            u.y = (float) (featuresA[i].y * scale[l]);
-
-            if( icvGetRectSubPix_8u32f_C1R( imgI[l], step[l], levelSize,
-                                             patchI, srcPatchStep, srcPatchSize, u ) < 0 )
-            {
-                /* point is outside the image. take the next */
-                pt_status = 0;
-                break;
-            }
-
-            /* calc Ix */
-            icvSepConvSmall3_32f( patchI, srcPatchStep, Ix, patchStep,
-                                  srcPatchSize, kerX, kerY, patchJ );
-
-            /* calc Iy */
-            icvSepConvSmall3_32f( patchI, srcPatchStep, Iy, patchStep,
-                                  srcPatchSize, kerY, kerX, patchJ );
-
-            /* repack patchI (remove borders) */
-            for( k = 0; k < patchSize.height; k++ )
-                memcpy( patchI + k * patchSize.width,
-                        patchI + (k + 1) * srcPatchSize.width + 1, patchStep );
-
-            for( y = 0, k = 0; y < patchSize.height; y++ )
-            {
-                for( x = 0; x < patchSize.width; x++, k++ )
-                {
-                    Gxx += Ix[k] * Ix[k];
-                    Gxy += Ix[k] * Iy[k];
-                    Gyy += Iy[k] * Iy[k];
-                }
-            }
-
-            D = Gxx * Gyy - Gxy * Gxy;
-            if( D < DBL_EPSILON )
-            {
-                pt_status = 0;
-                break;
-            }
-
-            D = 1. / D;
-
-            t = Gxx * D;
-            Gxx = Gyy * D;
-            Gyy = t;
-            Gxy *= -D;
-
-            //intersect( u, winSize, levelSize, &minI, &maxI );
-
-            for( j = 0; j < criteria.maxIter; j++ )
-            {
-                double bx = 0, by = 0;
-                float mx, my;
-
-                if( icvGetRectSubPix_8u32f_C1R( imgJ[l], step[l], levelSize,
-                                                 patchJ, patchStep, patchSize, v ) < 0 )
-                {
-                    /* point is outside image. take the next */
-                    pt_status = 0;
-                    break;
-                }
-
-                for( k = 0; k < patchLen; k++ )
-                {
-                    double t = patchI[k] - patchJ[k];
-
-                    bx += (double) (t * Ix[k]);
-                    by += (double) (t * Iy[k]);
-                }
-
-                mx = (float) (Gxx * bx + Gxy * by);
-                my = (float) (Gxy * bx + Gyy * by);
-
-                v.x += mx;
-                v.y += my;
-
-                if( mx * mx + my * my < criteria.epsilon )
-                    break;
-            }
-
-            if( pt_status == 0 )
-                break;
-        }
-
-        if( pt_status )
-        {
-            featuresB[i] = v;
-
-            if( error )
-            {
-                /* calc error */
-                double err = 0;
-
-                for( k = 0; k < patchLen; k++ )
-                {
-                    double t = patchI[k] - patchJ[k];
-
-                    err += t * t;
-                }
-                error[i] = (float) sqrt( err );
-            }
-        }
-
-        if( status )
-            status[i] = (char) pt_status;
-    }
-
-  func_exit:
-
-    icvFree( &pyr_buffer );
-    icvFree( &buffer );
-
-    return result;
-#undef MAX_LEVEL
-}
-#endif
-
 
+#if 0
 /* Affine tracking algorithm */
 static  CvStatus  icvCalcAffineFlowPyrLK_8uC1R( uchar * imgA, uchar * imgB,
                                                 int imgStep, CvSize imgSize,
@@ -829,7 +633,7 @@ static  CvStatus  icvCalcAffineFlowPyrLK_8uC1R( uchar * imgA, uchar * imgB,
 
         (36 * 2 + 6) * sizeof( double );
 
-    buffer = (uchar *) icvAlloc( bufferBytes );
+    buffer = (uchar *) cvAlloc( bufferBytes );
     if( !buffer )
     {
         result = CV_OUTOFMEM_ERR;
@@ -983,7 +787,7 @@ static  CvStatus  icvCalcAffineFlowPyrLK_8uC1R( uchar * imgA, uchar * imgB,
             }
             else
             {
-                for( j = 0; j < criteria.maxIter; j++ )
+                for( j = 0; j < criteria.max_iter; j++ )
                 {
                     double b[6], eta[6];
                     double t0, t1, s = 0;
@@ -1088,24 +892,24 @@ static  CvStatus  icvCalcAffineFlowPyrLK_8uC1R( uchar * imgA, uchar * imgB,
 
   func_exit:
 
-    icvFree( &pyr_buffer );
-    icvFree( &buffer );
+    cvFree( (void**)&pyr_buffer );
+    cvFree( (void**)&buffer );
 
     return result;
 #undef MAX_LEVEL
 }
-
+#endif
 
 static int icvMinimalPyramidSize( CvSize img_size )
 {
-    return icvAlign(img_size.width,8) * img_size.height / 3;
+    return cvAlign(img_size.width,8) * img_size.height / 3;
 }
 
 
 CV_IMPL void
 cvCalcOpticalFlowPyrLK( const void* arrA, const void* arrB,
                         void* pyrarrA, void* pyrarrB,
-                        CvPoint2D32f * featuresA,
+                        const CvPoint2D32f * featuresA,
                         CvPoint2D32f * featuresB,
                         int count, CvSize winSize, int level,
                         char *status, float *error,
@@ -1136,7 +940,7 @@ cvCalcOpticalFlowPyrLK( const void* arrA, const void* arrB,
     if( imgA->step != imgB->step )
         CV_ERROR( CV_StsUnmatchedSizes, "imgA and imgB must have equal steps" );
 
-    img_size = icvGetMatSize( imgA );
+    img_size = cvGetMatSize( imgA );
 
     if( pyrA )
     {
@@ -1174,7 +978,7 @@ cvCalcOpticalFlowPyrLK( const void* arrA, const void* arrB,
     __END__;
 }
 
-
+#if 0
 CV_IMPL void
 cvCalcAffineFlowPyrLK( const void* arrA, const void* arrB,
                        void* pyrarrA, void* pyrarrB,
@@ -1213,7 +1017,7 @@ cvCalcAffineFlowPyrLK( const void* arrA, const void* arrB,
     if( !matrices )
         CV_ERROR( CV_StsNullPtr, "" );
 
-    img_size = icvGetMatSize( imgA );
+    img_size = cvGetMatSize( imgA );
 
     if( pyrA )
     {
@@ -1250,7 +1054,7 @@ cvCalcAffineFlowPyrLK( const void* arrA, const void* arrB,
 
     __END__;
 }
-
+#endif
 
 
 /* End of file. */
index fdacf52e88df4cdf0bbf6c2c570c4ea1330dd85e..f0edf9a2533101d33793f27eabd29b52370a93f9 100644 (file)
@@ -39,7 +39,6 @@
 //
 //M*/
 #include "_cv.h"
-#include "_cvgeom.h"
 
 /*F///////////////////////////////////////////////////////////////////////////////////////
 //    Name: cvMatchContours
@@ -56,8 +55,8 @@
 //
 //F*/
 CV_IMPL  double
-cvMatchContours( const void* contour1, const void* contour2,
-                 CvContoursMatchMethod method, double /*parameter*/ )
+cvMatchShapes( const void* contour1, const void* contour2,
+               int method, double /*parameter*/ )
 {
     CvMoments moments;
     CvHuMoments huMoments;
@@ -72,7 +71,7 @@ cvMatchContours( const void* contour1, const void* contour2,
     __BEGIN__;
 
     if( !contour1 || !contour2 )
-        CV_ERROR_FROM_STATUS( CV_NULLPTR_ERR );
+        CV_ERROR( CV_StsNullPtr, "" );
 
 /*   first moments calculation */
     CV_CALL( cvMoments( contour1, &moments ));
@@ -221,15 +220,14 @@ cvMatchContours( const void* contour1, const void* contour2,
 //      result - output calculated measure 
 //F*/
 CV_IMPL  double
-cvMatchContourTrees( CvContourTree* tree1, CvContourTree* tree2,
-                     CvContourTreesMatchMethod method, 
-                                        double threshold )
+cvMatchContourTrees( const CvContourTree* tree1, const CvContourTree* tree2,
+                     int method, double threshold )
 {
     _CvTrianAttr **ptr_p1, **ptr_p2;    /*pointers to the pointer's buffer */
     _CvTrianAttr **ptr_n1, **ptr_n2;    /*pointers to the pointer's buffer */
     _CvTrianAttr **ptr11, **ptr12, **ptr21, **ptr22;
 
-    static int lpt1, lpt2, lpt, flag, flag_n, i, j, ibuf, ibuf1;
+    int lpt1, lpt2, lpt, flag, flag_n, i, j, ibuf, ibuf1;
     double match_v, d12, area1, area2, r11, r12, r21, r22, w1, w2;
     double eps = 1.e-5;
     char s1, s2;
@@ -241,35 +239,27 @@ cvMatchContourTrees( CvContourTree* tree1, CvContourTree* tree2,
     __BEGIN__;
 
     if( !tree1 || !tree2 )
-        CV_ERROR_FROM_STATUS( CV_NULLPTR_ERR );
+        CV_ERROR( CV_StsNullPtr, "" );
 
     if( method != CV_CONTOUR_TREES_MATCH_I1 )
-        CV_ERROR_FROM_STATUS( CV_BADCOEF_ERR );
+        CV_ERROR( CV_StsBadArg, "Unknown/unsupported comparison method" );
 
     if( !CV_IS_SEQ_POLYGON_TREE( tree1 ))
-        CV_ERROR_FROM_STATUS( CV_BADFLAG_ERR );
+        CV_ERROR( CV_StsBadArg, "The first argument is not a valid contour tree" );
 
     if( !CV_IS_SEQ_POLYGON_TREE( tree2 ))
-        CV_ERROR_FROM_STATUS( CV_BADFLAG_ERR );
+        CV_ERROR( CV_StsBadArg, "The second argument is not a valid contour tree" );
 
     lpt1 = tree1->total;
     lpt2 = tree2->total;
     lpt = lpt1 > lpt2 ? lpt1 : lpt2;
 
     ptr_p1 = ptr_n1 = ptr_p2 = ptr_n2 = NULL;
-    ptr_p1 = (_CvTrianAttr **) icvAlloc( lpt * sizeof( _CvTrianAttr * ));
-    if( ptr_p1 == NULL )
-        return CV_OUTOFMEM_ERR;
-    ptr_p2 = (_CvTrianAttr **) icvAlloc( lpt * sizeof( _CvTrianAttr * ));
-    if( ptr_p2 == NULL )
-        return CV_OUTOFMEM_ERR;
-
-    ptr_n1 = (_CvTrianAttr **) icvAlloc( lpt * sizeof( _CvTrianAttr * ));
-    if( ptr_n1 == NULL )
-        return CV_OUTOFMEM_ERR;
-    ptr_n2 = (_CvTrianAttr **) icvAlloc( lpt * sizeof( _CvTrianAttr * ));
-    if( ptr_n2 == NULL )
-        return CV_OUTOFMEM_ERR;
+    CV_CALL( ptr_p1 = (_CvTrianAttr **) cvAlloc( lpt * sizeof( _CvTrianAttr * )));
+    CV_CALL( ptr_p2 = (_CvTrianAttr **) cvAlloc( lpt * sizeof( _CvTrianAttr * )));
+
+    CV_CALL( ptr_n1 = (_CvTrianAttr **) cvAlloc( lpt * sizeof( _CvTrianAttr * )));
+    CV_CALL( ptr_n2 = (_CvTrianAttr **) cvAlloc( lpt * sizeof( _CvTrianAttr * )));
 
     cvStartReadSeq( (CvSeq *) tree1, &reader1, 0 );
     cvStartReadSeq( (CvSeq *) tree2, &reader2, 0 );
@@ -289,7 +279,7 @@ cvMatchContourTrees( CvContourTree* tree1, CvContourTree* tree2,
     area2 = tree_2.area;
 
     if( area1 < eps || area2 < eps || lpt < 4 )
-        CV_ERROR_FROM_STATUS( CV_BADSIZE_ERR );
+        CV_ERROR( CV_StsBadSize, "" );
 
     r11 = r12 = r21 = r22 = w1 = w2 = d12 = 0;
     flag = 0;
@@ -347,10 +337,18 @@ cvMatchContourTrees( CvContourTree* tree1, CvContourTree* tree2,
                 {
                 case 1:
                     {
+                        double t0, t1;
                         if( s1 != s2 )
-                            d12 = fabs( r11 * w1 + r21 * w2 ) + fabs( r12 * w1 + r22 * w2 );
+                        {
+                            t0 = fabs( r11 * w1 + r21 * w2 );
+                            t1 = fabs( r12 * w1 + r22 * w2 );
+                        }
                         else
-                            d12 = fabs( r11 * w1 - r21 * w2 ) + fabs( r12 * w1 - r22 * w2 );
+                        {
+                            t0 = fabs( r11 * w1 - r21 * w2 );
+                            t1 = fabs( r12 * w1 - r22 * w2 );
+                        }
+                        d12 = t0 + t1;
                         break;
                     }
                 }
@@ -388,10 +386,10 @@ cvMatchContourTrees( CvContourTree* tree1, CvContourTree* tree2,
 
     __END__;
 
-    icvFree( &ptr_n2 );
-    icvFree( &ptr_n1 );
-    icvFree( &ptr_p2 );
-    icvFree( &ptr_p1 );
+    cvFree( (void**)&ptr_n2 );
+    cvFree( (void**)&ptr_n1 );
+    cvFree( (void**)&ptr_p2 );
+    cvFree( (void**)&ptr_p1 );
 
     return result;
 }
index 6e19fdec786fcefa8487b3d260749c572c00b89a..0118cb4a0e65da5f7668f25beea31f1c1ae286a6 100644 (file)
@@ -39,7 +39,6 @@
 //
 //M*/
 #include "_cv.h"
-#include "_cvdatastructs.h"
 
 /* The function calculates center of gravity and central second order moments */
 static void
@@ -253,7 +252,8 @@ icvAccumulateMoments( double *tiles, CvSize size, CvSize tile_size, CvMoments *
 
 #define ICV_DEF_CALC_MOMENTS_IN_TILE( __op__, name, flavor, srctype, temptype, momtype ) \
 IPCVAPI_IMPL( CvStatus, icv##name##_##flavor##_CnCR,                                     \
-( const srctype* img, int step, CvSize size, int cn, int coi, double *moments ))         \
+( const srctype* img, int step, CvSize size, int cn, int coi, double *moments ),         \
+  (img, step, size, cn, coi, moments) )                                                  \
 {                                                                                        \
     int x, y, sx_init = (size.width & -4) * (size.width & -4), sy = 0;                   \
     momtype mom[10];                                                                     \
@@ -261,7 +261,8 @@ IPCVAPI_IMPL( CvStatus, icv##name##_##flavor##_CnCR,
     assert( img && size.width && (size.width | size.height) >= 0 );                      \
     memset( mom, 0, 10 * sizeof( mom[0] ));                                              \
                                                                                          \
-    img += coi - 1;                                                                      \
+    if( coi )                                                                            \
+        img += coi - 1;                                                                  \
                                                                                          \
     for( y = 0; y < size.height; sy += 2 * y + 1, y++, (char*&)img += step )             \
     {                                                                                    \
@@ -332,7 +333,7 @@ IPCVAPI_IMPL( CvStatus, icv##name##_##flavor##_CnCR,
 
 
 ICV_DEF_CALC_MOMENTS_IN_TILE( CV_NOP, MomentsInTile, 8u, uchar, int, int )
-ICV_DEF_CALC_MOMENTS_IN_TILE( CV_NOP, MomentsInTile, 8s, char, int, int )
+ICV_DEF_CALC_MOMENTS_IN_TILE( CV_NOP, MomentsInTile, 16u, ushort, int, int64 )
 ICV_DEF_CALC_MOMENTS_IN_TILE( CV_NOP, MomentsInTile, 16s, short, int, int64 )
 ICV_DEF_CALC_MOMENTS_IN_TILE( CV_NOP, MomentsInTile, 32f, float, double, double )
 ICV_DEF_CALC_MOMENTS_IN_TILE( CV_NOP, MomentsInTile, 64f, double, double, double )
@@ -342,8 +343,10 @@ ICV_DEF_CALC_MOMENTS_IN_TILE( CV_NONZERO, MomentsInTileBin, 16s, ushort, int, in
 ICV_DEF_CALC_MOMENTS_IN_TILE( CV_NONZERO_FLT, MomentsInTileBin, 32f, int, int, int )
 ICV_DEF_CALC_MOMENTS_IN_TILE( CV_NONZERO_FLT, MomentsInTileBin, 64f, int64, double, double )
 
+#define icvMomentsInTile_8s_CnCR  0
 #define icvMomentsInTile_32s_CnCR  0
 #define icvMomentsInTileBin_8s_CnCR   icvMomentsInTileBin_8u_CnCR
+#define icvMomentsInTileBin_16u_CnCR   icvMomentsInTileBin_16s_CnCR
 #define icvMomentsInTileBin_32s_CnCR  0
 
 CV_DEF_INIT_FUNC_TAB_2D( MomentsInTile, CnCR )
@@ -412,8 +415,8 @@ cvMoments( const void* array, CvMoments* moments, int binary )
     type = CV_MAT_TYPE( mat->type );
     depth = CV_MAT_DEPTH( type );
     cn = CV_MAT_CN( type );
-    pix_size = icvPixSize[type];
-    size = icvGetMatSize( mat );
+    pix_size = CV_ELEM_SIZE(type);
+    size = cvGetMatSize( mat );
 
     if( cn > 1 && coi == 0 )
         CV_ERROR( CV_StsBadArg, "Invalid image type" );
@@ -426,7 +429,7 @@ cvMoments( const void* array, CvMoments* moments, int binary )
     func = (CvFunc2DnC_1A1P)(!binary ? mom_tab.fn_2d[depth] : mombin_tab.fn_2d[depth]);
 
     if( !func )
-        CV_ERROR( CV_StsBadArg, icvUnsupportedFormat );
+        CV_ERROR( CV_StsBadArg, cvUnsupportedFormat );
 
     if( depth >= CV_32S && !binary )
         tile_size = size;
index 917e3719a871209d7f484674d4b96e991d55de89..ce6a417d513bc1e7bdbdec6ed3e61eeed2547d71 100644 (file)
 IPCVAPI_IMPL( CvStatus,
     icvMorphologyInitAlloc, ( int roiWidth, CvDataType dataType, int channels,
                               CvSize elSize, CvPoint elAnchor,
-                              CvElementShape elShape, int* elData,
-                              struct CvMorphState** morphState ))
+                              int elShape, int* elData,
+                              struct CvMorphState** morphState ),
+                              (roiWidth, dataType, channels, elSize, elAnchor,
+                              elShape, elData, morphState) )
 {
     CvStatus status;
     
@@ -60,13 +62,13 @@ IPCVAPI_IMPL( CvStatus,
             int i, r = elSize.height / 2, c = elSize.width / 2;
             double inv_r2 = 1. / (((double) (r)) * (r));
 
-            elData = (int*)alloca( elSize.width * elSize.height * sizeof(elData[0]));
+            elData = (int*)cvStackAlloc( elSize.width * elSize.height * sizeof(elData[0]));
             memset( elData, 0, elSize.width*elSize.height*sizeof(elData[0]));
 
             for( i = 0; i < r; i++ )
             {
                 int y = r - i;
-                int dx = cvRound( c * sqrt( (r * r - y * y) * inv_r2 ));
+                int dx = cvRound( c * sqrt( ((double)r * r - y * y) * inv_r2 ));
                 int x1 = c - dx;
                 int x2 = c + dx;
 
@@ -105,2238 +107,716 @@ IPCVAPI_IMPL( CvStatus,
 }
 
 
-IPCVAPI_IMPL( CvStatus, icvMorphologyFree, (CvMorphState ** morphState) )
+IPCVAPI_IMPL( CvStatus, icvMorphologyFree, (CvMorphState ** morphState), (morphState) )
 {
     return icvFilterFree( morphState );
 }
 
 
-static CvStatus
-icvErodeRC_8u( uchar * src, int srcStep,
-               uchar * dst, int dstStep, CvSize * roiSize, CvMorphState * state, int stage )
-{
-    int width = roiSize->width;
-    int src_height = roiSize->height;
-    int dst_height = src_height;
-    int x, y = 0, i;
-
-    int ker_x = state->ker_x;
-    int ker_y = state->ker_y;
-    int ker_width = state->ker_width;
-    int ker_height = state->ker_height;
-    int ker_right = ker_width - ker_x - ((width & 1) == 0);
-
-    int crows = state->crows;
-    uchar **rows = (uchar **) (state->rows);
-    uchar *tbuf = (uchar *) (state->tbuf);
-
-    int channels = state->channels;
-    int ker_x_n = ker_x * channels;
-    int ker_width_n = ker_width * channels;
-    int ker_right_n = ker_right * channels;
-    int width_n = width * channels;
-
-    int is_small_width = width < MAX( ker_x, ker_right );
-    int starting_flag = 0;
-    int width_rest = width_n & (CV_MORPH_ALIGN - 1);
-
-    int is_cross = ICV_BINARY_KERNEL_SHAPE(state->kerType) == CV_SHAPE_CROSS;
-
-    /* initialize cyclic buffer when starting */
-    if( stage == CV_WHOLE || stage == CV_START )
-    {
-        for( i = 0; i < ker_height; i++ )
-        {
-            rows[i] = (uchar *) (state->buffer + state->buffer_step * i);
-        }
-        crows = ker_y;
-        if( stage != CV_WHOLE )
-            dst_height -= ker_height - ker_y - 1;
-        starting_flag = 1;
-    }
-
-    if( stage == CV_END )
-        dst_height += ker_height - ker_y - 1;
-
-    do
-    {
-        int need_copy = is_small_width | (y == 0);
-        uchar *tsrc, *tdst;
-        uchar *saved_row = rows[ker_y];
-
-        /* fill cyclic buffer - horizontal filtering */
-        for( ; crows < ker_height + is_cross; crows++ )
-        {
-            if( crows < ker_height )
-            {
-                tsrc = src - ker_x_n;
-                tdst = rows[crows];
-
-                if( src_height-- <= 0 )
-                {
-                    if( stage != CV_WHOLE && stage != CV_END )
-                        break;
-                    /* duplicate last row */
-                    tsrc = rows[crows - 1];
-                    CV_COPY( tdst, tsrc, width_n, x );
-                    continue;
-                }
-
-                need_copy |= src_height == 1;
-            }
-            else
-            {
-                /* convolve center line for cross-shaped element */
-                tsrc = rows[ker_y] - ker_x_n;
-                tdst = tbuf;
-
-                need_copy = 0;
-            }
-
-            if( ker_width > 1 && (!is_cross || crows == ker_height) )
-            {
-                if( need_copy )
-                {
-                    tsrc = tbuf - ker_x_n;
-                    CV_COPY( tbuf, src, width_n, x );
-                }
-                else if( !is_cross )
-                {
-                    CV_COPY( tbuf - ker_x_n, src - ker_x_n, ker_x_n, x );
-                    CV_COPY( tbuf, src + width_n, ker_right_n, x );
-                }
-
-                if( channels == 1 )
-                {
-                    /* make replication borders */
-                    uchar pix = tsrc[ker_x];
-
-                    CV_SET( tsrc, pix, ker_x, x );
-
-                    pix = tsrc[width + ker_x - 1];
-                    CV_SET( tsrc + width + ker_x, pix, ker_right, x );
-
-                    /* horizontal convolution loop */
-                    for( i = 0; i < width_n; i += 2 )
-                    {
-                        int j;
-                        int t, t0 = tsrc[i + 1];
-
-                        for( j = 2; j < ker_width_n; j++ )
-                        {
-                            int t1 = tsrc[i + j];
-
-                            CV_CALC_MIN( t0, t1 );
-                        }
-
-                        t = tsrc[i];
-                        CV_CALC_MIN( t, t0 );
-                        tdst[i] = (uchar) t;
-
-                        t = tsrc[i + j];
-                        CV_CALC_MIN( t, t0 );
-                        tdst[i + 1] = (uchar) t;
-                    }
-                }
-                else if( channels == 3 )
-                {
-                    /* make replication borders */
-                    CvRGB8u pix = ((CvRGB8u *) tsrc)[ker_x];
-
-                    CV_SET( (CvRGB8u *) tsrc, pix, ker_x, x );
-
-                    pix = ((CvRGB8u *) tsrc)[width + ker_x - 1];
-                    CV_SET( (CvRGB8u *) tsrc + width + ker_x, pix, ker_right, x );
-
-                    /* horizontal convolution loop */
-                    for( i = 0; i < width_n; i++ )
-                    {
-                        int j;
-                        int t0 = tsrc[i];
-
-                        for( j = 3; j < ker_width_n; j += 3 )
-                        {
-                            int t1 = tsrc[i + j];
-
-                            CV_CALC_MIN( t0, t1 );
-                        }
-
-                        tdst[i] = (uchar) t0;
-                    }
-                }
-                else            /* channels == 4 */
-                {
-                    /* make replication borders */
-                    CvRGBA8u pix = ((CvRGBA8u *) tsrc)[ker_x];
-
-                    CV_SET( (CvRGBA8u *) tsrc, pix, ker_x, x );
-
-                    pix = ((CvRGBA8u *) tsrc)[width + ker_x - 1];
-                    CV_SET( (CvRGBA8u *) tsrc + width + ker_x, pix, ker_right, x );
-
-                    /* horizontal convolution loop */
-                    for( i = 0; i < width_n; i++ )
-                    {
-                        int j;
-                        int t0 = tsrc[i];
-
-                        for( j = 4; j < ker_width_n; j += 4 )
-                        {
-                            int t1 = tsrc[i + j];
-
-                            CV_CALC_MIN( t0, t1 );
-                        }
-
-                        tdst[i] = (uchar) t0;
-                    }
-                }
-
-                if( !need_copy && !is_cross )
-                {
-                    /* restore borders */
-                    CV_COPY( src - ker_x_n, tbuf - ker_x_n, ker_x_n, x );
-                    CV_COPY( src + width_n, tbuf, ker_right_n, x );
-                }
-            }
-            else
-            {
-                CV_COPY( tdst, tsrc + ker_x_n, width_n, x );
-            }
-
-            src += crows < ker_height ? srcStep : 0;
-        }
-
-        if( starting_flag )
-        {
-            starting_flag = 0;
-            tsrc = rows[ker_y];
-
-            for( i = 0; i < ker_y; i++ )
-            {
-                tdst = rows[i];
-                CV_COPY( tdst, tsrc, width_n, x );
-            }
-        }
-
-        /* vertical convolution */
-        if( crows != ker_height )
-        {
-            if( crows < ker_height )
-                break;
-            /* else it is cross-shaped element: change central line */
-            rows[ker_y] = tbuf;
-            crows--;
-        }
-
-        tdst = dst;
-
-        if( width_rest )
-        {
-            need_copy = width_n < CV_MORPH_ALIGN || y == dst_height - 1;
-
-            if( need_copy )
-                tdst = tbuf;
-            else
-                CV_COPY( tbuf + width_n, dst + width_n, CV_MORPH_ALIGN, x );
-        }
-
-        for( x = 0; x < width_n; x += 4 )
-        {
-            int val0, val1, val2, val3;
-
-            tsrc = rows[0];
-
-            val0 = tsrc[x];
-            val1 = tsrc[x + 1];
-            val2 = tsrc[x + 2];
-            val3 = tsrc[x + 3];
-
-            for( i = 1; i < ker_height; i++ )
-            {
-                int s;
-
-                tsrc = rows[i];
-
-                s = tsrc[x + 0];
-                CV_CALC_MIN( val0, s );
-                s = tsrc[x + 1];
-                CV_CALC_MIN( val1, s );
-                s = tsrc[x + 2];
-                CV_CALC_MIN( val2, s );
-                s = tsrc[x + 3];
-                CV_CALC_MIN( val3, s );
-            }
-
-            tdst[x + 0] = (uchar) val0;
-            tdst[x + 1] = (uchar) val1;
-            tdst[x + 2] = (uchar) val2;
-            tdst[x + 3] = (uchar) val3;
-        }
-
-        if( width_rest )
-        {
-            if( need_copy )
-                CV_COPY( dst, tbuf, width_n, x );
-            else
-                CV_COPY( dst + width_n, tbuf + width_n, CV_MORPH_ALIGN, x );
-        }
-
-        rows[ker_y] = saved_row;
-
-        /* rotate buffer */
-        {
-            uchar *t = rows[0];
-
-            CV_COPY( rows, rows + 1, ker_height - 1, i );
-            rows[i] = t;
-            crows--;
-            dst += dstStep;
-        }
-    }
-    while( ++y < dst_height );
-
-    roiSize->height = y;
-    state->crows = crows;
-
-    return CV_OK;
-}
-
-
-static CvStatus
-icvErodeArb_8u( uchar * src, int srcStep,
-                uchar * dst, int dstStep, CvSize * roiSize, CvMorphState * state, int stage )
-{
-#define INIT_VAL 255
-    int width = roiSize->width;
-    int src_height = roiSize->height;
-    int dst_height = src_height;
-    int x, y = 0, i;
-
-    int ker_x = state->ker_x;
-    int ker_y = state->ker_y;
-    int ker_width = state->ker_width;
-    int ker_height = state->ker_height;
-    int ker_right = ker_width - ker_x - ((width & 1) == 0);
-    uchar *ker_data = state->ker1 + ker_width;
-
-    int crows = state->crows;
-    uchar **rows = (uchar **) (state->rows);
-    uchar *tbuf = (uchar *) (state->tbuf);
-
-    int channels = state->channels;
-    int ker_x_n = ker_x * channels;
-    int ker_width_n = ker_width * channels;
-    int width_n = width * channels;
-
-    int starting_flag = 0;
-    int width_rest = width_n & (CV_MORPH_ALIGN - 1);
-
-    /* initialize cyclic buffer when starting */
-    if( stage == CV_WHOLE || stage == CV_START )
-    {
-        for( i = 0; i < ker_height; i++ )
-        {
-            rows[i] = (uchar *) (state->buffer + state->buffer_step * i);
-        }
-        crows = ker_y;
-        if( stage != CV_WHOLE )
-            dst_height -= ker_height - ker_y - 1;
-        starting_flag = 1;
-    }
-
-    if( stage == CV_END )
-        dst_height += ker_height - ker_y - 1;
-
-    do
-    {
-        uchar *tsrc, *tdst;
-        int need_copy = 0;
-
-        /* fill cyclic buffer - horizontal filtering */
-        for( ; crows < ker_height; crows++ )
-        {
-            tsrc = src;
-            tdst = rows[crows];
-
-            if( src_height-- <= 0 )
-            {
-                if( stage != CV_WHOLE && stage != CV_END )
-                    break;
-                /* duplicate last row */
-                tsrc = rows[crows - 1];
-                CV_COPY( tdst, tsrc, width_n + ker_width_n, x );
-                continue;
-            }
-
-            src += srcStep;
-
-            CV_COPY( tdst + ker_x_n, tsrc, width_n, x );
-
-            /* make replication borders */
-            if( channels == 1 )
-            {
-                uchar pix = tdst[ker_x];
-
-                CV_SET( tdst, pix, ker_x, x );
-
-                pix = tdst[width + ker_x - 1];
-                CV_SET( tdst + width + ker_x, pix, ker_right, x );
-            }
-            else if( channels == 3 )
-            {
-                CvRGB8u pix = ((CvRGB8u *) tdst)[ker_x];
-
-                CV_SET( (CvRGB8u *) tdst, pix, ker_x, x );
-
-                pix = ((CvRGB8u *) tdst)[width + ker_x - 1];
-                CV_SET( (CvRGB8u *) tdst + width + ker_x, pix, ker_right, x );
-            }
-            else                /* channels == 4 */
-            {
-                /* make replication borders */
-                CvRGBA8u pix = ((CvRGBA8u *) tdst)[ker_x];
-
-                CV_SET( (CvRGBA8u *) tdst, pix, ker_x, x );
-
-                pix = ((CvRGBA8u *) tdst)[width + ker_x - 1];
-                CV_SET( (CvRGBA8u *) tdst + width + ker_x, pix, ker_right, x );
-            }
-        }
-
-        if( starting_flag )
-        {
-            starting_flag = 0;
-            tsrc = rows[ker_y];
-
-            for( i = 0; i < ker_y; i++ )
-            {
-                tdst = rows[i];
-                CV_COPY( tdst, tsrc, width_n + ker_width_n, x );
-            }
-        }
-
-        /* vertical convolution */
-        if( crows < ker_height )
-            break;
-
-        tdst = dst;
-        if( width_rest )
-        {
-            need_copy = width_n < CV_MORPH_ALIGN || y == dst_height - 1;
-
-            if( need_copy )
-                tdst = tbuf;
-            else
-                CV_COPY( tbuf + width_n, dst + width_n, CV_MORPH_ALIGN, x );
-        }
-
-        if( channels == 1 )
-        {
-            for( x = 0; x < width_n; x += 4 )
-            {
-                int val0 = INIT_VAL, val1 = INIT_VAL, val2 = INIT_VAL, val3 = INIT_VAL;
-
-                uchar *ker = ker_data;
-
-                for( i = 0; i < ker_height; i++, ker += ker_width )
-                {
-                    int j = -ker_width;
-
-                    tsrc = rows[i] + x - j;
-                    do
-                    {
-                        int m = ker[j];
-                        int t = tsrc[j] | m;
-
-                        CV_CALC_MIN( val0, t );
-                        t = tsrc[j + 1] | m;
-                        CV_CALC_MIN( val1, t );
-                        t = tsrc[j + 2] | m;
-                        CV_CALC_MIN( val2, t );
-                        t = tsrc[j + 3] | m;
-                        CV_CALC_MIN( val3, t );
-                    }
-                    while( ++j < 0 );
-                }
-
-                tdst[x] = (uchar) val0;
-                tdst[x + 1] = (uchar) val1;
-                tdst[x + 2] = (uchar) val2;
-                tdst[x + 3] = (uchar) val3;
-            }
-        }
-        else if( channels == 3 )
-        {
-            for( x = 0; x < width_n; x += 3 )
-            {
-                int val0 = INIT_VAL, val1 = INIT_VAL, val2 = INIT_VAL;
-
-                uchar *ker = ker_data;
-
-                for( i = 0; i < ker_height; i++, ker += ker_width )
-                {
-                    int j = -ker_width;
-
-                    tsrc = rows[i] + x - j * 3;
-                    for( ; j < 0; j++ )
-                    {
-                        int m = ker[j];
-                        int t = tsrc[j * 3] | m;
-
-                        CV_CALC_MIN( val0, t );
-                        t = tsrc[j * 3 + 1] | m;
-                        CV_CALC_MIN( val1, t );
-                        t = tsrc[j * 3 + 2] | m;
-                        CV_CALC_MIN( val2, t );
-                    }
-                }
-
-                tdst[x] = (uchar) val0;
-                tdst[x + 1] = (uchar) val1;
-                tdst[x + 2] = (uchar) val2;
-            }
-        }
-        else
-        {
-            for( x = 0; x < width_n; x += 4 )
-            {
-                int val0 = INIT_VAL, val1 = INIT_VAL, val2 = INIT_VAL, val3 = INIT_VAL;
-
-                uchar *ker = ker_data;
-
-                for( i = 0; i < ker_height; i++, ker += ker_width )
-                {
-                    int j = -ker_width;
-
-                    tsrc = rows[i] + x - j * 4;
-                    for( ; j < 0; j++ )
-                    {
-                        int m = ker[j];
-                        int t = tsrc[j * 4] | m;
-
-                        CV_CALC_MIN( val0, t );
-                        t = tsrc[j * 4 + 1] | m;
-                        CV_CALC_MIN( val1, t );
-                        t = tsrc[j * 4 + 2] | m;
-                        CV_CALC_MIN( val2, t );
-                        t = tsrc[j * 4 + 3] | m;
-                        CV_CALC_MIN( val3, t );
-                    }
-                }
-
-                tdst[x] = (uchar) val0;
-                tdst[x + 1] = (uchar) val1;
-                tdst[x + 2] = (uchar) val2;
-                tdst[x + 3] = (uchar) val3;
-            }
-        }
-
-        if( width_rest )
-        {
-            if( need_copy )
-                CV_COPY( dst, tbuf, width_n, x );
-            else
-                CV_COPY( dst + width_n, tbuf + width_n, CV_MORPH_ALIGN, x );
-        }
-
-        /* rotate buffer */
-        {
-            uchar *t = rows[0];
-
-            CV_COPY( rows, rows + 1, ker_height - 1, i );
-            rows[i] = t;
-            crows--;
-            dst += dstStep;
-        }
-    }
-    while( ++y < dst_height );
-
-    roiSize->height = y;
-    state->crows = crows;
-
-    return CV_OK;
-#undef INIT_VAL
-}
-
-
-static CvStatus
-icvErodeRC_32f( float *src, int srcStep,
-                float *dst, int dstStep, CvSize * roiSize, CvMorphState * state, int stage )
-{
-    int width = roiSize->width;
-    int src_height = roiSize->height;
-    int dst_height = src_height;
-    int x, y = 0, i;
-
-    int ker_x = state->ker_x;
-    int ker_y = state->ker_y;
-    int ker_width = state->ker_width;
-    int ker_height = state->ker_height;
-    int ker_right = ker_width - ker_x - ((width & 1) == 0);
-
-    int crows = state->crows;
-    int **rows = (int **) (state->rows);
-    int *tbuf = (int *) (state->tbuf);
-    int *tbuf2 = (int *) (state->tbuf + state->buffer_step);
-
-    int channels = state->channels;
-    int ker_x_n = ker_x * channels;
-    int ker_width_n = ker_width * channels;
-    int width_n = width * channels;
-
-    int starting_flag = 0;
-    int width_rest = width_n & (CV_MORPH_ALIGN - 1);
-
-    int is_cross = ICV_BINARY_KERNEL_SHAPE(state->kerType) == CV_SHAPE_CROSS;
-
-    /* initialize cyclic buffer when starting */
-    if( stage == CV_WHOLE || stage == CV_START )
-    {
-        for( i = 0; i < ker_height; i++ )
-        {
-            rows[i] = (int *) (state->buffer + state->buffer_step * i);
-        }
-        crows = ker_y;
-        if( stage != CV_WHOLE )
-            dst_height -= ker_height - ker_y - 1;
-        starting_flag = 1;
-    }
-
-    if( stage == CV_END )
-        dst_height += ker_height - ker_y - 1;
-
-    srcStep /= sizeof_float;
-    dstStep /= sizeof_float;
-
-    do
-    {
-        int need_copy = 0;
-        int *tsrc, *tdst;
-        int *saved_row = rows[ker_y];
-
-        /* fill cyclic buffer - horizontal filtering */
-        for( ; crows < ker_height + is_cross; crows++ )
-        {
-            if( crows < ker_height )
-            {
-                tsrc = (int *) src;
-                tdst = rows[crows];
-
-                if( src_height-- <= 0 )
-                {
-                    if( stage != CV_WHOLE && stage != CV_END )
-                        break;
-                    /* duplicate last row */
-                    tsrc = rows[crows - 1];
-                    CV_COPY( tdst, tsrc, width_n, x );
-                    continue;
-                }
-
-                for( x = 0; x < width_n; x++ )
-                {
-                    int t = tsrc[x];
-
-                    tbuf2[x] = CV_TOGGLE_FLT( t );
-                }
-                tsrc = tbuf2 - ker_x_n;
-            }
-            else
-            {
-                /* convolve center line for cross-shaped element */
-                tsrc = rows[ker_y] - ker_x_n;
-                tdst = tbuf;
-            }
-
-            if( ker_width > 1 && (!is_cross || crows == ker_height) )
-            {
-                if( channels == 1 )
-                {
-                    /* make replication borders */
-                    int pix = tsrc[ker_x];
-
-                    CV_SET( tsrc, pix, ker_x, x );
-
-                    pix = tsrc[width + ker_x - 1];
-                    CV_SET( tsrc + width + ker_x, pix, ker_right, x );
-
-                    /* horizontal convolution loop */
-                    for( i = 0; i < width_n; i += 2 )
-                    {
-                        int j;
-                        int t, t0 = tsrc[i + 1];
-
-                        for( j = 2; j < ker_width_n; j++ )
-                        {
-                            int t1 = tsrc[i + j];
-
-                            CV_CALC_MIN( t0, t1 );
-                        }
-
-                        t = tsrc[i];
-                        CV_CALC_MIN( t, t0 );
-                        tdst[i] = (int) t;
-
-                        t = tsrc[i + j];
-                        CV_CALC_MIN( t, t0 );
-                        tdst[i + 1] = (int) t;
-                    }
-                }
-                else if( channels == 3 )
-                {
-                    /* make replication borders */
-                    CvRGB32s pix = ((CvRGB32s *) tsrc)[ker_x];
-
-                    CV_SET( (CvRGB32s *) tsrc, pix, ker_x, x );
-
-                    pix = ((CvRGB32s *) tsrc)[width + ker_x - 1];
-                    CV_SET( (CvRGB32s *) tsrc + width + ker_x, pix, ker_right, x );
-
-                    /* horizontal convolution loop */
-                    for( i = 0; i < width_n; i++ )
-                    {
-                        int j;
-                        int t0 = tsrc[i];
-
-                        for( j = 3; j < ker_width_n; j += 3 )
-                        {
-                            int t1 = tsrc[i + j];
-
-                            CV_CALC_MIN( t0, t1 );
-                        }
-
-                        tdst[i] = (int) t0;
-                    }
-                }
-                else            /* channels == 4 */
-                {
-                    /* make replication borders */
-                    CvRGBA32s pix = ((CvRGBA32s *) tsrc)[ker_x];
-
-                    CV_SET( (CvRGBA32s *) tsrc, pix, ker_x, x );
-
-                    pix = ((CvRGBA32s *) tsrc)[width + ker_x - 1];
-                    CV_SET( (CvRGBA32s *) tsrc + width + ker_x, pix, ker_right, x );
-
-                    /* horizontal convolution loop */
-                    for( i = 0; i < width_n; i++ )
-                    {
-                        int j;
-                        int t0 = tsrc[i];
-
-                        for( j = 4; j < ker_width_n; j += 4 )
-                        {
-                            int t1 = tsrc[i + j];
-
-                            CV_CALC_MIN( t0, t1 );
-                        }
-
-                        tdst[i] = (int) t0;
-                    }
-                }
-            }
-            else
-            {
-                CV_COPY( tdst, tsrc + ker_x_n, width_n, x );
-            }
-
-            if( crows < ker_height )
-                src += srcStep;
-        }
-
-        if( starting_flag )
-        {
-            starting_flag = 0;
-            tsrc = rows[ker_y];
-
-            for( i = 0; i < ker_y; i++ )
-            {
-                tdst = rows[i];
-                CV_COPY( tdst, tsrc, width_n, x );
-            }
-        }
-
-        /* vertical convolution */
-        if( crows != ker_height )
-        {
-            if( crows < ker_height )
-                break;
-            /* else it is cross-shaped element: change central line */
-            rows[ker_y] = tbuf;
-            crows--;
-        }
-
-        tdst = (int *) dst;
-
-        if( width_rest )
-        {
-            need_copy = width_n < CV_MORPH_ALIGN || y == dst_height - 1;
-
-            if( need_copy )
-                tdst = tbuf;
-            else
-                CV_COPY( tbuf + width_n, tdst + width_n, CV_MORPH_ALIGN, x );
-        }
-
-        for( x = 0; x < width_n; x += 4 )
-        {
-            int val0, val1, val2, val3;
-
-            tsrc = rows[0];
-
-            val0 = tsrc[x];
-            val1 = tsrc[x + 1];
-            val2 = tsrc[x + 2];
-            val3 = tsrc[x + 3];
-
-            for( i = 1; i < ker_height; i++ )
-            {
-                int s;
-
-                tsrc = rows[i];
-
-                s = tsrc[x + 0];
-                CV_CALC_MIN( val0, s );
-                s = tsrc[x + 1];
-                CV_CALC_MIN( val1, s );
-                s = tsrc[x + 2];
-                CV_CALC_MIN( val2, s );
-                s = tsrc[x + 3];
-                CV_CALC_MIN( val3, s );
-            }
-            tdst[x + 0] = CV_TOGGLE_FLT( val0 );
-            tdst[x + 1] = CV_TOGGLE_FLT( val1 );
-            tdst[x + 2] = CV_TOGGLE_FLT( val2 );
-            tdst[x + 3] = CV_TOGGLE_FLT( val3 );
-        }
-
-        if( width_rest )
-        {
-            if( need_copy )
-                CV_COPY( (int *) dst, tbuf, width_n, x );
-            else
-                CV_COPY( tdst + width_n, tbuf + width_n, CV_MORPH_ALIGN, x );
-        }
-
-        rows[ker_y] = saved_row;
-
-        /* rotate buffer */
-        {
-            int *t = rows[0];
-
-            CV_COPY( rows, rows + 1, ker_height - 1, i );
-            rows[i] = t;
-            crows--;
-            dst += dstStep;
-        }
-    }
-    while( ++y < dst_height );
-
-    roiSize->height = y;
-    state->crows = crows;
-
-    return CV_OK;
-}
-
-
-static CvStatus
-icvErodeArb_32f( float *src, int srcStep,
-                 float *dst, int dstStep, CvSize * roiSize, CvMorphState * state, int stage )
-{
-#define INIT_VAL  INT_MAX
-    int width = roiSize->width;
-    int src_height = roiSize->height;
-    int dst_height = src_height;
-    int x, y = 0, i;
-
-    int ker_x = state->ker_x;
-    int ker_y = state->ker_y;
-    int ker_width = state->ker_width;
-    int ker_height = state->ker_height;
-    int ker_right = ker_width - ker_x - ((width & 1) == 0);
-    char *ker_data = (char *) (state->ker1 + ker_width);
-
-    int crows = state->crows;
-    int **rows = (int **) (state->rows);
-    int *tbuf = (int *) (state->tbuf);
-
-    int channels = state->channels;
-    int ker_x_n = ker_x * channels;
-    int ker_width_n = ker_width * channels;
-    int width_n = width * channels;
-
-    int starting_flag = 0;
-    int width_rest = width_n & (CV_MORPH_ALIGN - 1);
-
-    /* initialize cyclic buffer when starting */
-    if( stage == CV_WHOLE || stage == CV_START )
-    {
-        for( i = 0; i < ker_height; i++ )
-        {
-            rows[i] = (int *) (state->buffer + state->buffer_step * i);
-        }
-        crows = ker_y;
-        if( stage != CV_WHOLE )
-            dst_height -= ker_height - ker_y - 1;
-        starting_flag = 1;
-    }
-
-    if( stage == CV_END )
-        dst_height += ker_height - ker_y - 1;
-
-    srcStep /= sizeof_float;
-    dstStep /= sizeof_float;
-
-    do
-    {
-        int *tsrc, *tdst;
-        int need_copy = 0;
-
-        /* fill cyclic buffer - horizontal filtering */
-        for( ; crows < ker_height; crows++ )
-        {
-            tsrc = (int *) src;
-            tdst = rows[crows];
-
-            if( src_height-- <= 0 )
-            {
-                if( stage != CV_WHOLE && stage != CV_END )
-                    break;
-                /* duplicate last row */
-                tsrc = rows[crows - 1];
-                CV_COPY( tdst, tsrc, width_n + ker_width_n, x );
-                continue;
-            }
-
-            src += srcStep;
-
-            for( x = 0; x < width_n; x++ )
-            {
-                int t = tsrc[x];
-
-                tdst[ker_x_n + x] = (int) CV_TOGGLE_FLT( t );
-            }
-
-            /* make replication borders */
-            if( channels == 1 )
-            {
-                int pix = tdst[ker_x];
-
-                CV_SET( tdst, pix, ker_x, x );
-
-                pix = tdst[width + ker_x - 1];
-                CV_SET( tdst + width + ker_x, pix, ker_right, x );
-            }
-            else if( channels == 3 )
-            {
-                CvRGB32s pix = ((CvRGB32s *) tdst)[ker_x];
-
-                CV_SET( (CvRGB32s *) tdst, pix, ker_x, x );
-
-                pix = ((CvRGB32s *) tdst)[width + ker_x - 1];
-                CV_SET( (CvRGB32s *) tdst + width + ker_x, pix, ker_right, x );
-            }
-            else                /* channels == 4 */
-            {
-                /* make replication borders */
-                CvRGBA32s pix = ((CvRGBA32s *) tdst)[ker_x];
-
-                CV_SET( (CvRGBA32s *) tdst, pix, ker_x, x );
-
-                pix = ((CvRGBA32s *) tdst)[width + ker_x - 1];
-                CV_SET( (CvRGBA32s *) tdst + width + ker_x, pix, ker_right, x );
-            }
-        }
-
-        if( starting_flag )
-        {
-            starting_flag = 0;
-            tsrc = rows[ker_y];
-
-            for( i = 0; i < ker_y; i++ )
-            {
-                tdst = rows[i];
-                CV_COPY( tdst, tsrc, width_n + ker_width_n, x );
-            }
-        }
-
-        /* vertical convolution */
-        if( crows < ker_height )
-            break;
-
-        tdst = (int *) dst;
-        if( width_rest )
-        {
-            need_copy = width_n < CV_MORPH_ALIGN || y == dst_height - 1;
-
-            if( need_copy )
-                tdst = tbuf;
-            else
-                CV_COPY( tbuf + width_n, (int *) (dst + width_n), CV_MORPH_ALIGN, x );
-        }
-
-        if( channels == 1 )
-        {
-            for( x = 0; x < width_n; x += 4 )
-            {
-                int val0 = INIT_VAL, val1 = INIT_VAL, val2 = INIT_VAL, val3 = INIT_VAL;
-
-                char *ker = ker_data;
-
-                for( i = 0; i < ker_height; i++, ker += ker_width )
-                {
-                    int j = -ker_width;
-
-                    tsrc = rows[i] + x - j;
-                    do
-                    {
-                        int m = ker[j];
-
-                        if( !m )
-                        {
-                            int t = tsrc[j];
-
-                            CV_CALC_MIN( val0, t );
-                            t = tsrc[j + 1];
-                            CV_CALC_MIN( val1, t );
-                            t = tsrc[j + 2];
-                            CV_CALC_MIN( val2, t );
-                            t = tsrc[j + 3];
-                            CV_CALC_MIN( val3, t );
-                        }
-                    }
-                    while( ++j < 0 );
-                }
-
-                tdst[x] = (int) CV_TOGGLE_FLT( val0 );
-                tdst[x + 1] = (int) CV_TOGGLE_FLT( val1 );
-                tdst[x + 2] = (int) CV_TOGGLE_FLT( val2 );
-                tdst[x + 3] = (int) CV_TOGGLE_FLT( val3 );
-            }
-        }
-        else if( channels == 3 )
-        {
-            for( x = 0; x < width_n; x += 3 )
-            {
-                int val0 = INIT_VAL, val1 = INIT_VAL, val2 = INIT_VAL;
-
-                char *ker = ker_data;
-
-                for( i = 0; i < ker_height; i++, ker += ker_width )
-                {
-                    int j = -ker_width;
-
-                    tsrc = rows[i] + x - j * 3;
-                    for( ; j < 0; j++ )
-                    {
-                        int m = ker[j];
-
-                        if( !m )
-                        {
-                            int t = tsrc[j * 3];
-
-                            CV_CALC_MIN( val0, t );
-                            t = tsrc[j * 3 + 1];
-                            CV_CALC_MIN( val1, t );
-                            t = tsrc[j * 3 + 2];
-                            CV_CALC_MIN( val2, t );
-                        }
-                    }
-                }
-
-                tdst[x] = (int) CV_TOGGLE_FLT( val0 );
-                tdst[x + 1] = (int) CV_TOGGLE_FLT( val1 );
-                tdst[x + 2] = (int) CV_TOGGLE_FLT( val2 );
-            }
-        }
-        else
-        {
-            for( x = 0; x < width_n; x += 4 )
-            {
-                int val0 = INIT_VAL, val1 = INIT_VAL, val2 = INIT_VAL, val3 = INIT_VAL;
-
-                char *ker = ker_data;
-
-                for( i = 0; i < ker_height; i++, ker += ker_width )
-                {
-                    int j = -ker_width;
-
-                    tsrc = rows[i] + x - j * 4;
-                    for( ; j < 0; j++ )
-                    {
-                        int m = ker[j];
-
-                        if( !m )
-                        {
-                            int t = tsrc[j * 4];
-
-                            CV_CALC_MIN( val0, t );
-                            t = tsrc[j * 4 + 1];
-                            CV_CALC_MIN( val1, t );
-                            t = tsrc[j * 4 + 2];
-                            CV_CALC_MIN( val2, t );
-                            t = tsrc[j * 4 + 3];
-                            CV_CALC_MIN( val3, t );
-                        }
-                    }
-                }
-
-                tdst[x] = (int) CV_TOGGLE_FLT( val0 );
-                tdst[x + 1] = (int) CV_TOGGLE_FLT( val1 );
-                tdst[x + 2] = (int) CV_TOGGLE_FLT( val2 );
-                tdst[x + 3] = (int) CV_TOGGLE_FLT( val3 );
-            }
-        }
-
-        if( width_rest )
-        {
-            if( need_copy )
-                CV_COPY( (int *) dst, tbuf, width_n, x );
-            else
-                CV_COPY( (int *) (dst + width_n), tbuf + width_n, CV_MORPH_ALIGN, x );
-        }
-
-        /* rotate buffer */
-        {
-            int *t = rows[0];
-
-            CV_COPY( rows, rows + 1, ker_height - 1, i );
-            rows[i] = t;
-            crows--;
-            dst += dstStep;
-        }
-    }
-    while( ++y < dst_height );
-
-    roiSize->height = y;
-    state->crows = crows;
-
-    return CV_OK;
-#undef INIT_VAL
-}
-
-
-static CvStatus
-icvDilateArb_32f( float *src, int srcStep,
-                  float *dst, int dstStep, CvSize * roiSize, CvMorphState * state, int stage )
-{
-#define INIT_VAL  INT_MIN
-    int width = roiSize->width;
-    int src_height = roiSize->height;
-    int dst_height = src_height;
-    int x, y = 0, i;
-
-    int ker_x = state->ker_x;
-    int ker_y = state->ker_y;
-    int ker_width = state->ker_width;
-    int ker_height = state->ker_height;
-    int ker_right = ker_width - ker_x - ((width & 1) == 0);
-    char *ker_data = (char *) (state->ker0 + ker_width);
-
-    int crows = state->crows;
-    int **rows = (int **) (state->rows);
-    int *tbuf = (int *) (state->tbuf);
-
-    int channels = state->channels;
-    int ker_x_n = ker_x * channels;
-    int ker_width_n = ker_width * channels;
-    int width_n = width * channels;
-
-    int starting_flag = 0;
-    int width_rest = width_n & (CV_MORPH_ALIGN - 1);
-
-    /* initialize cyclic buffer when starting */
-    if( stage == CV_WHOLE || stage == CV_START )
-    {
-        for( i = 0; i < ker_height; i++ )
-        {
-            rows[i] = (int *) (state->buffer + state->buffer_step * i);
-        }
-        crows = ker_y;
-        if( stage != CV_WHOLE )
-            dst_height -= ker_height - ker_y - 1;
-        starting_flag = 1;
-    }
-
-    if( stage == CV_END )
-        dst_height += ker_height - ker_y - 1;
-
-    srcStep /= sizeof_float;
-    dstStep /= sizeof_float;
-
-    do
-    {
-        int *tsrc, *tdst;
-        int need_copy = 0;
-
-        /* fill cyclic buffer - horizontal filtering */
-        for( ; crows < ker_height; crows++ )
-        {
-            tsrc = (int *) src;
-            tdst = rows[crows];
-
-            if( src_height-- <= 0 )
-            {
-                if( stage != CV_WHOLE && stage != CV_END )
-                    break;
-                /* duplicate last row */
-                tsrc = rows[crows - 1];
-                CV_COPY( tdst, tsrc, width_n + ker_width_n, x );
-                continue;
-            }
-
-            src += srcStep;
-
-            for( x = 0; x < width_n; x++ )
-            {
-                int t = tsrc[x];
-
-                tdst[ker_x_n + x] = (int) CV_TOGGLE_FLT( t );
-            }
-
-            /* make replication borders */
-            if( channels == 1 )
-            {
-                int pix = tdst[ker_x];
-
-                CV_SET( tdst, pix, ker_x, x );
-
-                pix = tdst[width + ker_x - 1];
-                CV_SET( tdst + width + ker_x, pix, ker_right, x );
-            }
-            else if( channels == 3 )
-            {
-                CvRGB32s pix = ((CvRGB32s *) tdst)[ker_x];
-
-                CV_SET( (CvRGB32s *) tdst, pix, ker_x, x );
-
-                pix = ((CvRGB32s *) tdst)[width + ker_x - 1];
-                CV_SET( (CvRGB32s *) tdst + width + ker_x, pix, ker_right, x );
-            }
-            else                /* channels == 4 */
-            {
-                /* make replication borders */
-                CvRGBA32s pix = ((CvRGBA32s *) tdst)[ker_x];
-
-                CV_SET( (CvRGBA32s *) tdst, pix, ker_x, x );
-
-                pix = ((CvRGBA32s *) tdst)[width + ker_x - 1];
-                CV_SET( (CvRGBA32s *) tdst + width + ker_x, pix, ker_right, x );
-            }
-        }
-
-        if( starting_flag )
-        {
-            starting_flag = 0;
-            tsrc = rows[ker_y];
-
-            for( i = 0; i < ker_y; i++ )
-            {
-                tdst = rows[i];
-                CV_COPY( tdst, tsrc, width_n + ker_width_n, x );
-            }
-        }
-
-        /* vertical convolution */
-        if( crows < ker_height )
-            break;
-
-        tdst = (int *) dst;
-        if( width_rest )
-        {
-            need_copy = width_n < CV_MORPH_ALIGN || y == dst_height - 1;
-
-            if( need_copy )
-                tdst = tbuf;
-            else
-                CV_COPY( tbuf + width_n, (int *) (dst + width_n), CV_MORPH_ALIGN, x );
-        }
-
-        if( channels == 1 )
-        {
-            for( x = 0; x < width_n; x += 4 )
-            {
-                int val0 = INIT_VAL, val1 = INIT_VAL, val2 = INIT_VAL, val3 = INIT_VAL;
-
-                char *ker = ker_data;
-
-                for( i = 0; i < ker_height; i++, ker += ker_width )
-                {
-                    int j = -ker_width;
-
-                    tsrc = rows[i] + x - j;
-                    do
-                    {
-                        int m = ker[j];
-
-                        if( m )
-                        {
-                            int t = tsrc[j];
-
-                            CV_CALC_MAX( val0, t );
-                            t = tsrc[j + 1];
-                            CV_CALC_MAX( val1, t );
-                            t = tsrc[j + 2];
-                            CV_CALC_MAX( val2, t );
-                            t = tsrc[j + 3];
-                            CV_CALC_MAX( val3, t );
-                        }
-                    }
-                    while( ++j < 0 );
-                }
-
-                tdst[x] = (int) CV_TOGGLE_FLT( val0 );
-                tdst[x + 1] = (int) CV_TOGGLE_FLT( val1 );
-                tdst[x + 2] = (int) CV_TOGGLE_FLT( val2 );
-                tdst[x + 3] = (int) CV_TOGGLE_FLT( val3 );
-            }
-        }
-        else if( channels == 3 )
-        {
-            for( x = 0; x < width_n; x += 3 )
-            {
-                int val0 = INIT_VAL, val1 = INIT_VAL, val2 = INIT_VAL;
-
-                char *ker = ker_data;
-
-                for( i = 0; i < ker_height; i++, ker += ker_width )
-                {
-                    int j = -ker_width;
-
-                    tsrc = rows[i] + x - j * 3;
-                    for( ; j < 0; j++ )
-                    {
-                        int m = ker[j];
-
-                        if( m )
-                        {
-                            int t = tsrc[j * 3];
-
-                            CV_CALC_MAX( val0, t );
-                            t = tsrc[j * 3 + 1];
-                            CV_CALC_MAX( val1, t );
-                            t = tsrc[j * 3 + 2];
-                            CV_CALC_MAX( val2, t );
-                        }
-                    }
-                }
-
-                tdst[x] = (int) CV_TOGGLE_FLT( val0 );
-                tdst[x + 1] = (int) CV_TOGGLE_FLT( val1 );
-                tdst[x + 2] = (int) CV_TOGGLE_FLT( val2 );
-            }
-        }
-        else
-        {
-            for( x = 0; x < width_n; x += 4 )
-            {
-                int val0 = INIT_VAL, val1 = INIT_VAL, val2 = INIT_VAL, val3 = INIT_VAL;
-
-                char *ker = ker_data;
-
-                for( i = 0; i < ker_height; i++, ker += ker_width )
-                {
-                    int j = -ker_width;
-
-                    tsrc = rows[i] + x - j * 4;
-                    for( ; j < 0; j++ )
-                    {
-                        int m = ker[j];
-
-                        if( m )
-                        {
-                            int t = tsrc[j * 4];
-
-                            CV_CALC_MAX( val0, t );
-                            t = tsrc[j * 4 + 1];
-                            CV_CALC_MAX( val1, t );
-                            t = tsrc[j * 4 + 2];
-                            CV_CALC_MAX( val2, t );
-                            t = tsrc[j * 4 + 3];
-                            CV_CALC_MAX( val3, t );
-                        }
-                    }
-                }
-
-                tdst[x] = (int) CV_TOGGLE_FLT( val0 );
-                tdst[x + 1] = (int) CV_TOGGLE_FLT( val1 );
-                tdst[x + 2] = (int) CV_TOGGLE_FLT( val2 );
-                tdst[x + 3] = (int) CV_TOGGLE_FLT( val3 );
-            }
-        }
-
-        if( width_rest )
-        {
-            if( need_copy )
-                CV_COPY( (int *) dst, tbuf, width_n, x );
-            else
-                CV_COPY( (int *) (dst + width_n), tbuf + width_n, CV_MORPH_ALIGN, x );
-        }
-
-        /* rotate buffer */
-        {
-            int *t = rows[0];
-
-            CV_COPY( rows, rows + 1, ker_height - 1, i );
-            rows[i] = t;
-            crows--;
-            dst += dstStep;
-        }
-    }
-    while( ++y < dst_height );
-
-    roiSize->height = y;
-    state->crows = crows;
+/****************************************************************************************\
+*         Erode/Dilate with rectangular or cross-shaped element for integer types        *
+\****************************************************************************************/
 
-    return CV_OK;
-#undef INIT_VAL
+#define ICV_DEF_MORPH_RECT_INT_FUNC( name, flavor, arrtype,                 \
+                                     update_extr_macro )                    \
+static CvStatus CV_STDCALL                                                  \
+icv##name##RC_##flavor( arrtype* src, int srcstep,                          \
+                        arrtype* dst, int dststep,                          \
+                        CvSize* roi, CvMorphState* state, int stage )       \
+{                                                                           \
+    int width = roi->width;                                                 \
+    int src_height = roi->height;                                           \
+    int dst_height = src_height;                                            \
+    int x, y = 0, i;                                                        \
+                                                                            \
+    int ker_x = state->ker_x;                                               \
+    int ker_y = state->ker_y;                                               \
+    int ker_width = state->ker_width;                                       \
+    int ker_height = state->ker_height;                                     \
+    int ker_right = ker_width - ker_x;                                      \
+                                                                            \
+    int crows = state->crows;                                               \
+    arrtype** rows = (arrtype**)(state->rows);                              \
+    arrtype* tbuf = (arrtype*)(state->tbuf);                                \
+                                                                            \
+    int channels = state->channels;                                         \
+    int ker_x_n = ker_x * channels;                                         \
+    int ker_width_n = ker_width * channels;                                 \
+    int ker_right_n = ker_right * channels;                                 \
+    int width_n = width * channels;                                         \
+                                                                            \
+    int is_small_width = width < MAX( ker_x, ker_right );                   \
+    int starting_flag = 0;                                                  \
+    int width_rest = width_n & (CV_MORPH_ALIGN - 1);                        \
+                                                                            \
+    int is_cross = ICV_BINARY_KERNEL_SHAPE(state->kerType)==CV_SHAPE_CROSS; \
+                                                                            \
+    /* initialize cyclic buffer when starting */                            \
+    if( stage == CV_WHOLE || stage == CV_START )                            \
+    {                                                                       \
+        for( i = 0; i < ker_height; i++ )                                   \
+            rows[i] = (arrtype*)(state->buffer + state->buffer_step * i);   \
+                                                                            \
+        crows = ker_y;                                                      \
+        if( stage != CV_WHOLE )                                             \
+            dst_height -= ker_height - ker_y - 1;                           \
+        starting_flag = 1;                                                  \
+    }                                                                       \
+                                                                            \
+    if( stage == CV_END )                                                   \
+        dst_height += ker_height - ker_y - 1;                               \
+                                                                            \
+    do                                                                      \
+    {                                                                       \
+        int need_copy = is_small_width | (y == 0);                          \
+        arrtype *tsrc, *tdst;                                               \
+        arrtype *saved_row = rows[ker_y];                                   \
+                                                                            \
+        /* fill cyclic buffer - horizontal filtering */                     \
+        for( ; crows < ker_height + is_cross; crows++ )                     \
+        {                                                                   \
+            if( crows < ker_height )                                        \
+            {                                                               \
+                tsrc = src - ker_x_n;                                       \
+                tdst = rows[crows];                                         \
+                                                                            \
+                if( src_height-- <= 0 )                                     \
+                {                                                           \
+                    if( stage != CV_WHOLE && stage != CV_END )              \
+                        break;                                              \
+                    /* duplicate last row */                                \
+                    tsrc = rows[crows - 1];                                 \
+                    CV_COPY( tdst, tsrc, width_n, x );                      \
+                    continue;                                               \
+                }                                                           \
+                                                                            \
+                need_copy |= src_height == 1;                               \
+            }                                                               \
+            else                                                            \
+            {                                                               \
+                /* convolve center line for cross-shaped element */         \
+                tsrc = rows[ker_y] - ker_x_n;                               \
+                tdst = tbuf;                                                \
+                                                                            \
+                need_copy = 0;                                              \
+            }                                                               \
+                                                                            \
+            if( ker_width > 1 && (!is_cross || crows == ker_height) )       \
+            {                                                               \
+                if( need_copy )                                             \
+                {                                                           \
+                    tsrc = tbuf - ker_x_n;                                  \
+                    CV_COPY( tbuf, src, width_n, x );                       \
+                }                                                           \
+                else if( !is_cross )                                        \
+                {                                                           \
+                    CV_COPY( tbuf - ker_x_n, src - ker_x_n, ker_x_n, x );   \
+                    CV_COPY( tbuf, src + width_n, ker_right_n, x );         \
+                }                                                           \
+                                                                            \
+                /* make replication borders */                              \
+                for( i = ker_x_n - 1; i >= 0; i-- )                         \
+                    tsrc[i] = tsrc[i + channels];                           \
+                for( i = width_n + ker_x_n; i < width_n + ker_width_n; i++ )\
+                    tsrc[i] = tsrc[i - channels];                           \
+                                                                            \
+                /* row processing */                                        \
+                if( channels == 1 )                                         \
+                    for( i = 0; i < width_n; i += 2 )                       \
+                    {                                                       \
+                        int j;                                              \
+                        int t, t0 = tsrc[i + 1];                            \
+                                                                            \
+                        for( j = 2; j < ker_width_n; j++ )                  \
+                        {                                                   \
+                            int t1 = tsrc[i + j];                           \
+                            update_extr_macro( t0, t1 );                    \
+                        }                                                   \
+                                                                            \
+                        t = tsrc[i];                                        \
+                        update_extr_macro( t, t0 );                         \
+                        tdst[i] = (arrtype) t;                              \
+                                                                            \
+                        t = tsrc[i + j];                                    \
+                        update_extr_macro( t, t0 );                         \
+                        tdst[i + 1] = (arrtype) t;                          \
+                    }                                                       \
+                else                                                        \
+                    for( i = 0; i < width_n; i++ )                          \
+                    {                                                       \
+                        int j;                                              \
+                        int t0 = tsrc[i];                                   \
+                                                                            \
+                        for( j = channels; j < ker_width_n; j += channels ) \
+                        {                                                   \
+                            int t1 = tsrc[i + j];                           \
+                            update_extr_macro( t0, t1 );                    \
+                        }                                                   \
+                                                                            \
+                        tdst[i] = (arrtype)t0;                              \
+                    }                                                       \
+                                                                            \
+                if( !need_copy && !is_cross )                               \
+                {                                                           \
+                    /* restore borders */                                   \
+                    CV_COPY( src - ker_x_n, tbuf - ker_x_n, ker_x_n, x );   \
+                    CV_COPY( src + width_n, tbuf, ker_right_n, x );         \
+                }                                                           \
+            }                                                               \
+            else                                                            \
+                CV_COPY( tdst, tsrc + ker_x_n, width_n, x );                \
+                                                                            \
+            src += crows < ker_height ? srcstep : 0;                        \
+        }                                                                   \
+                                                                            \
+        if( starting_flag )                                                 \
+        {                                                                   \
+            starting_flag = 0;                                              \
+            tsrc = rows[ker_y];                                             \
+                                                                            \
+            for( i = 0; i < ker_y; i++ )                                    \
+            {                                                               \
+                tdst = rows[i];                                             \
+                CV_COPY( tdst, tsrc, width_n, x );                          \
+            }                                                               \
+        }                                                                   \
+                                                                            \
+        /* vertical convolution */                                          \
+        if( crows != ker_height )                                           \
+        {                                                                   \
+            if( crows < ker_height )                                        \
+                break;                                                      \
+            /* else it is cross-shaped element: change central line */      \
+            rows[ker_y] = tbuf;                                             \
+            crows--;                                                        \
+        }                                                                   \
+                                                                            \
+        tdst = dst;                                                         \
+                                                                            \
+        if( width_rest )                                                    \
+        {                                                                   \
+            need_copy = width_n < CV_MORPH_ALIGN || y == dst_height - 1;    \
+                                                                            \
+            if( need_copy )                                                 \
+                tdst = tbuf;                                                \
+            else                                                            \
+                CV_COPY( tbuf + width_n, dst + width_n, CV_MORPH_ALIGN, x );\
+        }                                                                   \
+                                                                            \
+        for( x = 0; x < width_n; x += 4 )                                   \
+        {                                                                   \
+            int val0, val1, val2, val3;                                     \
+                                                                            \
+            tsrc = rows[0];                                                 \
+                                                                            \
+            val0 = tsrc[x];                                                 \
+            val1 = tsrc[x + 1];                                             \
+            val2 = tsrc[x + 2];                                             \
+            val3 = tsrc[x + 3];                                             \
+                                                                            \
+            for( i = 1; i < ker_height; i++ )                               \
+            {                                                               \
+                tsrc = rows[i];                                             \
+                int s = tsrc[x + 0];                                        \
+                update_extr_macro( val0, s );                               \
+                s = tsrc[x + 1];                                            \
+                update_extr_macro( val1, s );                               \
+                s = tsrc[x + 2];                                            \
+                update_extr_macro( val2, s );                               \
+                s = tsrc[x + 3];                                            \
+                update_extr_macro( val3, s );                               \
+            }                                                               \
+                                                                            \
+            tdst[x + 0] = (arrtype)val0;                                    \
+            tdst[x + 1] = (arrtype)val1;                                    \
+            tdst[x + 2] = (arrtype)val2;                                    \
+            tdst[x + 3] = (arrtype)val3;                                    \
+        }                                                                   \
+                                                                            \
+        if( width_rest )                                                    \
+        {                                                                   \
+            if( need_copy )                                                 \
+                CV_COPY( dst, tbuf, width_n, x );                           \
+            else                                                            \
+                CV_COPY( dst + width_n, tbuf + width_n, CV_MORPH_ALIGN, x );\
+        }                                                                   \
+                                                                            \
+        rows[ker_y] = saved_row;                                            \
+                                                                            \
+        /* rotate buffer */                                                 \
+        {                                                                   \
+            arrtype *t = rows[0];                                           \
+                                                                            \
+            CV_COPY( rows, rows + 1, ker_height - 1, i );                   \
+            rows[i] = t;                                                    \
+            crows--;                                                        \
+            dst += dststep;                                                 \
+        }                                                                   \
+    }                                                                       \
+    while( ++y < dst_height );                                              \
+                                                                            \
+    roi->height = y;                                                        \
+    state->crows = crows;                                                   \
+                                                                            \
+    return CV_OK;                                                           \
 }
 
 
+/****************************************************************************************\
+*         Erode/Dilate with rectangular or cross-shaped element for 32f type             *
+\****************************************************************************************/
 
-static CvStatus
-icvDilateRC_8u( uchar * src, int srcStep,
-                uchar * dst, int dstStep, CvSize * roiSize, CvMorphState * state, int stage )
-{
-    int width = roiSize->width;
-    int src_height = roiSize->height;
-    int dst_height = src_height;
-    int x, y = 0, i;
-
-    int ker_x = state->ker_x;
-    int ker_y = state->ker_y;
-    int ker_width = state->ker_width;
-    int ker_height = state->ker_height;
-    int ker_right = ker_width - ker_x - ((width & 1) == 0);
-
-    int crows = state->crows;
-    uchar **rows = (uchar **) (state->rows);
-    uchar *tbuf = (uchar *) (state->tbuf);
-
-    int channels = state->channels;
-    int ker_x_n = ker_x * channels;
-    int ker_width_n = ker_width * channels;
-    int ker_right_n = ker_right * channels;
-    int width_n = width * channels;
-
-    int is_small_width = width < MAX( ker_x, ker_right );
-    int starting_flag = 0;
-    int width_rest = width_n & (CV_MORPH_ALIGN - 1);
-
-    int is_cross = ICV_BINARY_KERNEL_SHAPE(state->kerType) == CV_SHAPE_CROSS;
-
-    /* initialize cyclic buffer when starting */
-    if( stage == CV_WHOLE || stage == CV_START )
-    {
-        for( i = 0; i < ker_height; i++ )
-        {
-            rows[i] = (uchar *) (state->buffer + state->buffer_step * i);
-        }
-        crows = ker_y;
-        if( stage != CV_WHOLE )
-            dst_height -= ker_height - ker_y - 1;
-        starting_flag = 1;
-    }
-
-    if( stage == CV_END )
-        dst_height += ker_height - ker_y - 1;
-
-    do
-    {
-        int need_copy = is_small_width | (y == 0);
-        uchar *tsrc, *tdst;
-        uchar *saved_row = rows[ker_y];
-
-        /* fill cyclic buffer - horizontal filtering */
-        for( ; crows < ker_height + is_cross; crows++ )
-        {
-            if( crows < ker_height )
-            {
-                tsrc = src - ker_x_n;
-                tdst = rows[crows];
-
-                if( src_height-- <= 0 )
-                {
-                    if( stage != CV_WHOLE && stage != CV_END )
-                        break;
-                    /* duplicate last row */
-                    tsrc = rows[crows - 1];
-                    CV_COPY( tdst, tsrc, width_n, x );
-                    continue;
-                }
-
-                need_copy |= src_height == 1;
-            }
-            else
-            {
-                /* convolve center line for cross-shaped element */
-                tsrc = rows[ker_y] - ker_x_n;
-                tdst = tbuf;
-
-                need_copy = 0;
-            }
-
-            if( ker_width > 1 && (!is_cross || crows == ker_height) )
-            {
-                if( need_copy )
-                {
-                    tsrc = tbuf - ker_x_n;
-                    CV_COPY( tbuf, src, width_n, x );
-                }
-                else if( !is_cross )
-                {
-                    CV_COPY( tbuf - ker_x_n, src - ker_x_n, ker_x_n, x );
-                    CV_COPY( tbuf, src + width_n, ker_right_n, x );
-                }
-
-                if( channels == 1 )
-                {
-                    /* make replication borders */
-                    uchar pix = tsrc[ker_x];
-
-                    CV_SET( tsrc, pix, ker_x, x );
-
-                    pix = tsrc[width + ker_x - 1];
-                    CV_SET( tsrc + width + ker_x, pix, ker_right, x );
-
-                    /* horizontal convolution loop */
-                    for( i = 0; i < width_n; i += 2 )
-                    {
-                        int j;
-                        int t, t0 = tsrc[i + 1];
-
-                        for( j = 2; j < ker_width_n; j++ )
-                        {
-                            int t1 = tsrc[i + j];
-
-                            CV_CALC_MAX( t0, t1 );
-                        }
-
-                        t = tsrc[i];
-                        CV_CALC_MAX( t, t0 );
-                        tdst[i] = (uchar) t;
-
-                        t = tsrc[i + j];
-                        CV_CALC_MAX( t, t0 );
-                        tdst[i + 1] = (uchar) t;
-                    }
-                }
-                else if( channels == 3 )
-                {
-                    /* make replication borders */
-                    CvRGB8u pix = ((CvRGB8u *) tsrc)[ker_x];
-
-                    CV_SET( (CvRGB8u *) tsrc, pix, ker_x, x );
-
-                    pix = ((CvRGB8u *) tsrc)[width + ker_x - 1];
-                    CV_SET( (CvRGB8u *) tsrc + width + ker_x, pix, ker_right, x );
-
-                    /* horizontal convolution loop */
-                    for( i = 0; i < width_n; i++ )
-                    {
-                        int j;
-                        int t0 = tsrc[i];
-
-                        for( j = 3; j < ker_width_n; j += 3 )
-                        {
-                            int t1 = tsrc[i + j];
-
-                            CV_CALC_MAX( t0, t1 );
-                        }
-
-                        tdst[i] = (uchar) t0;
-                    }
-                }
-                else            /* channels == 4 */
-                {
-                    /* make replication borders */
-                    CvRGBA8u pix = ((CvRGBA8u *) tsrc)[ker_x];
-
-                    CV_SET( (CvRGBA8u *) tsrc, pix, ker_x, x );
-
-                    pix = ((CvRGBA8u *) tsrc)[width + ker_x - 1];
-                    CV_SET( (CvRGBA8u *) tsrc + width + ker_x, pix, ker_right, x );
-
-                    /* horizontal convolution loop */
-                    for( i = 0; i < width_n; i++ )
-                    {
-                        int j;
-                        int t0 = tsrc[i];
-
-                        for( j = 4; j < ker_width_n; j += 4 )
-                        {
-                            int t1 = tsrc[i + j];
-
-                            CV_CALC_MAX( t0, t1 );
-                        }
-
-                        tdst[i] = (uchar) t0;
-                    }
-                }
-
-                if( !need_copy && !is_cross )
-                {
-                    /* restore borders */
-                    CV_COPY( src - ker_x_n, tbuf - ker_x_n, ker_x_n, x );
-                    CV_COPY( src + width_n, tbuf, ker_right_n, x );
-                }
-            }
-            else
-            {
-                CV_COPY( tdst, tsrc + ker_x_n, width_n, x );
-            }
-
-            if( crows < ker_height )
-                src += srcStep;
-        }
-
-        if( starting_flag )
-        {
-            starting_flag = 0;
-            tsrc = rows[ker_y];
-
-            for( i = 0; i < ker_y; i++ )
-            {
-                tdst = rows[i];
-                CV_COPY( tdst, tsrc, width_n, x );
-            }
-        }
-
-        /* vertical convolution */
-        if( crows != ker_height )
-        {
-            if( crows < ker_height )
-                break;
-            /* else it is cross-shaped element: change central line */
-            rows[ker_y] = tbuf;
-            crows--;
-        }
-
-        tdst = dst;
-
-        if( width_rest )
-        {
-            need_copy = width_n < CV_MORPH_ALIGN || y == dst_height - 1;
-
-            if( need_copy )
-                tdst = tbuf;
-            else
-                CV_COPY( tbuf + width_n, dst + width_n, CV_MORPH_ALIGN, x );
-        }
-
-        for( x = 0; x < width_n; x += 4 )
-        {
-            int val0, val1, val2, val3;
-
-            tsrc = rows[0];
-
-            val0 = tsrc[x];
-            val1 = tsrc[x + 1];
-            val2 = tsrc[x + 2];
-            val3 = tsrc[x + 3];
-
-            for( i = 1; i < ker_height; i++ )
-            {
-                int s;
-
-                tsrc = rows[i];
-
-                s = tsrc[x + 0];
-                CV_CALC_MAX( val0, s );
-                s = tsrc[x + 1];
-                CV_CALC_MAX( val1, s );
-                s = tsrc[x + 2];
-                CV_CALC_MAX( val2, s );
-                s = tsrc[x + 3];
-                CV_CALC_MAX( val3, s );
-            }
-
-            tdst[x + 0] = (uchar) val0;
-            tdst[x + 1] = (uchar) val1;
-            tdst[x + 2] = (uchar) val2;
-            tdst[x + 3] = (uchar) val3;
-        }
-
-        if( width_rest )
-        {
-            if( need_copy )
-                CV_COPY( dst, tbuf, width_n, x );
-            else
-                CV_COPY( dst + width_n, tbuf + width_n, CV_MORPH_ALIGN, x );
-        }
-
-        rows[ker_y] = saved_row;
-
-        /* rotate buffer */
-        {
-            uchar *t = rows[0];
-
-            CV_COPY( rows, rows + 1, ker_height - 1, i );
-            rows[i] = t;
-            crows--;
-            dst += dstStep;
-        }
-    }
-    while( ++y < dst_height );
-
-    roiSize->height = y;
-    state->crows = crows;
-
-    return CV_OK;
+#define ICV_DEF_MORPH_RECT_FLT_FUNC( name, flavor, arrtype,                 \
+                                     update_extr_macro )                    \
+static CvStatus                                                             \
+icv##name##RC_##flavor( arrtype* src, int srcstep,                          \
+                        arrtype* dst, int dststep,                          \
+                        CvSize* roi, CvMorphState* state, int stage )       \
+{                                                                           \
+    int width = roi->width;                                                 \
+    int src_height = roi->height;                                           \
+    int dst_height = src_height;                                            \
+    int x, y = 0, i;                                                        \
+                                                                            \
+    int ker_x = state->ker_x;                                               \
+    int ker_y = state->ker_y;                                               \
+    int ker_width = state->ker_width;                                       \
+    int ker_height = state->ker_height;                                     \
+                                                                            \
+    int crows = state->crows;                                               \
+    int **rows = (int**)(state->rows);                                      \
+    int *tbuf = (int*)(state->tbuf);                                        \
+    int *tbuf2 = (int*)(state->tbuf + state->buffer_step);                  \
+                                                                            \
+    int channels = state->channels;                                         \
+    int ker_x_n = ker_x * channels;                                         \
+    int ker_width_n = ker_width * channels;                                 \
+    int width_n = width * channels;                                         \
+                                                                            \
+    int starting_flag = 0;                                                  \
+    int width_rest = width_n & (CV_MORPH_ALIGN - 1);                        \
+                                                                            \
+    int is_cross = ICV_BINARY_KERNEL_SHAPE(state->kerType)==CV_SHAPE_CROSS; \
+                                                                            \
+    /* initialize cyclic buffer when starting */                            \
+    if( stage == CV_WHOLE || stage == CV_START )                            \
+    {                                                                       \
+        for( i = 0; i < ker_height; i++ )                                   \
+        {                                                                   \
+            rows[i] = (int *) (state->buffer + state->buffer_step * i);     \
+        }                                                                   \
+        crows = ker_y;                                                      \
+        if( stage != CV_WHOLE )                                             \
+            dst_height -= ker_height - ker_y - 1;                           \
+        starting_flag = 1;                                                  \
+    }                                                                       \
+                                                                            \
+    if( stage == CV_END )                                                   \
+        dst_height += ker_height - ker_y - 1;                               \
+                                                                            \
+    srcstep /= sizeof(src[0]);                                              \
+    dststep /= sizeof(dst[0]);                                              \
+                                                                            \
+    do                                                                      \
+    {                                                                       \
+        int need_copy = 0;                                                  \
+        int *tsrc, *tdst;                                                   \
+        int *saved_row = rows[ker_y];                                       \
+                                                                            \
+        /* fill cyclic buffer - horizontal filtering */                     \
+        for( ; crows < ker_height + is_cross; crows++ )                     \
+        {                                                                   \
+            if( crows < ker_height )                                        \
+            {                                                               \
+                tsrc = (int *) src;                                         \
+                tdst = rows[crows];                                         \
+                                                                            \
+                if( src_height-- <= 0 )                                     \
+                {                                                           \
+                    if( stage != CV_WHOLE && stage != CV_END )              \
+                        break;                                              \
+                    /* duplicate last row */                                \
+                    tsrc = rows[crows - 1];                                 \
+                    CV_COPY( tdst, tsrc, width_n, x );                      \
+                    continue;                                               \
+                }                                                           \
+                                                                            \
+                for( x = 0; x < width_n; x++ )                              \
+                {                                                           \
+                    int t = tsrc[x];                                        \
+                                                                            \
+                    tbuf2[x] = CV_TOGGLE_FLT( t );                          \
+                }                                                           \
+                tsrc = tbuf2 - ker_x_n;                                     \
+            }                                                               \
+            else                                                            \
+            {                                                               \
+                /* convolve center line for cross-shaped element */         \
+                tsrc = rows[ker_y] - ker_x_n;                               \
+                tdst = tbuf;                                                \
+            }                                                               \
+                                                                            \
+            if( ker_width > 1 && (!is_cross || crows == ker_height) )       \
+            {                                                               \
+                /* make replication borders */                              \
+                for( i = ker_x_n - 1; i >= 0; i-- )                         \
+                    tsrc[i] = tsrc[i + channels];                           \
+                for( i = width_n + ker_x_n; i < width_n + ker_width_n; i++ )\
+                    tsrc[i] = tsrc[i - channels];                           \
+                                                                            \
+                /* row processing */                                        \
+                if( channels == 1 )                                         \
+                    for( i = 0; i < width_n; i += 2 )                       \
+                    {                                                       \
+                        int j;                                              \
+                        int t, t0 = tsrc[i + 1];                            \
+                                                                            \
+                        for( j = 2; j < ker_width_n; j++ )                  \
+                        {                                                   \
+                            int t1 = tsrc[i + j];                           \
+                            update_extr_macro( t0, t1 );                    \
+                        }                                                   \
+                                                                            \
+                        t = tsrc[i];                                        \
+                        update_extr_macro( t, t0 );                         \
+                        tdst[i] = (int) t;                                  \
+                                                                            \
+                        t = tsrc[i + j];                                    \
+                        update_extr_macro( t, t0 );                         \
+                        tdst[i + 1] = (int) t;                              \
+                    }                                                       \
+                else                                                        \
+                    for( i = 0; i < width_n; i++ )                          \
+                    {                                                       \
+                        int j;                                              \
+                        int t0 = tsrc[i];                                   \
+                                                                            \
+                        for( j = channels; j < ker_width_n; j += channels ) \
+                        {                                                   \
+                            int t1 = tsrc[i + j];                           \
+                            update_extr_macro( t0, t1 );                    \
+                        }                                                   \
+                                                                            \
+                        tdst[i] = (int) t0;                                 \
+                    }                                                       \
+            }                                                               \
+            else                                                            \
+                CV_COPY( tdst, tsrc + ker_x_n, width_n, x );                \
+                                                                            \
+            if( crows < ker_height )                                        \
+                src += srcstep;                                             \
+        }                                                                   \
+                                                                            \
+        if( starting_flag )                                                 \
+        {                                                                   \
+            starting_flag = 0;                                              \
+            tsrc = rows[ker_y];                                             \
+                                                                            \
+            for( i = 0; i < ker_y; i++ )                                    \
+            {                                                               \
+                tdst = rows[i];                                             \
+                CV_COPY( tdst, tsrc, width_n, x );                          \
+            }                                                               \
+        }                                                                   \
+                                                                            \
+        /* vertical convolution */                                          \
+        if( crows != ker_height )                                           \
+        {                                                                   \
+            if( crows < ker_height )                                        \
+                break;                                                      \
+            /* else it is cross-shaped element: change central line */      \
+            rows[ker_y] = tbuf;                                             \
+            crows--;                                                        \
+        }                                                                   \
+                                                                            \
+        tdst = (int *) dst;                                                 \
+                                                                            \
+        if( width_rest )                                                    \
+        {                                                                   \
+            need_copy = width_n < CV_MORPH_ALIGN || y == dst_height - 1;    \
+                                                                            \
+            if( need_copy )                                                 \
+                tdst = tbuf;                                                \
+            else                                                            \
+                CV_COPY(tbuf + width_n, tdst + width_n, CV_MORPH_ALIGN, x); \
+        }                                                                   \
+                                                                            \
+        for( x = 0; x < width_n; x += 4 )                                   \
+        {                                                                   \
+            int val0, val1, val2, val3;                                     \
+                                                                            \
+            tsrc = rows[0];                                                 \
+                                                                            \
+            val0 = tsrc[x];                                                 \
+            val1 = tsrc[x + 1];                                             \
+            val2 = tsrc[x + 2];                                             \
+            val3 = tsrc[x + 3];                                             \
+                                                                            \
+            for( i = 1; i < ker_height; i++ )                               \
+            {                                                               \
+                tsrc = rows[i];                                             \
+                int s = tsrc[x + 0];                                        \
+                update_extr_macro( val0, s );                               \
+                s = tsrc[x + 1];                                            \
+                update_extr_macro( val1, s );                               \
+                s = tsrc[x + 2];                                            \
+                update_extr_macro( val2, s );                               \
+                s = tsrc[x + 3];                                            \
+                update_extr_macro( val3, s );                               \
+            }                                                               \
+            tdst[x + 0] = CV_TOGGLE_FLT( val0 );                            \
+            tdst[x + 1] = CV_TOGGLE_FLT( val1 );                            \
+            tdst[x + 2] = CV_TOGGLE_FLT( val2 );                            \
+            tdst[x + 3] = CV_TOGGLE_FLT( val3 );                            \
+        }                                                                   \
+                                                                            \
+        if( width_rest )                                                    \
+        {                                                                   \
+            if( need_copy )                                                 \
+                CV_COPY( (int *) dst, tbuf, width_n, x );                   \
+            else                                                            \
+                CV_COPY(tdst + width_n, tbuf + width_n, CV_MORPH_ALIGN, x); \
+        }                                                                   \
+                                                                            \
+        rows[ker_y] = saved_row;                                            \
+                                                                            \
+        /* rotate buffer */                                                 \
+        {                                                                   \
+            int *t = rows[0];                                               \
+                                                                            \
+            CV_COPY( rows, rows + 1, ker_height - 1, i );                   \
+            rows[i] = t;                                                    \
+            crows--;                                                        \
+            dst += dststep;                                                 \
+        }                                                                   \
+    }                                                                       \
+    while( ++y < dst_height );                                              \
+                                                                            \
+    roi->height = y;                                                        \
+    state->crows = crows;                                                   \
+                                                                            \
+    return CV_OK;                                                           \
 }
 
 
-static CvStatus
-icvDilateArb_8u( uchar * src, int srcStep,
-                 uchar * dst, int dstStep, CvSize * roiSize, CvMorphState * state, int stage )
-{
-#define INIT_VAL 0
-    int width = roiSize->width;
-    int src_height = roiSize->height;
-    int dst_height = src_height;
-    int x, y = 0, i;
-
-    int ker_x = state->ker_x;
-    int ker_y = state->ker_y;
-    int ker_width = state->ker_width;
-    int ker_height = state->ker_height;
-    int ker_right = ker_width - ker_x - ((width & 1) == 0);
-    uchar *ker_data = state->ker0 + ker_width;
-
-    int crows = state->crows;
-    uchar **rows = (uchar **) (state->rows);
-    uchar *tbuf = (uchar *) (state->tbuf);
-
-    int channels = state->channels;
-    int ker_x_n = ker_x * channels;
-    int ker_width_n = ker_width * channels;
-    int width_n = width * channels;
-
-    int starting_flag = 0;
-    int width_rest = width_n & (CV_MORPH_ALIGN - 1);
-
-    /* initialize cyclic buffer when starting */
-    if( stage == CV_WHOLE || stage == CV_START )
-    {
-        for( i = 0; i < ker_height; i++ )
-        {
-            rows[i] = (uchar *) (state->buffer + state->buffer_step * i);
-        }
-        crows = ker_y;
-        if( stage != CV_WHOLE )
-            dst_height -= ker_height - ker_y - 1;
-        starting_flag = 1;
-    }
-
-    if( stage == CV_END )
-        dst_height += ker_height - ker_y - 1;
-
-    do
-    {
-        uchar *tsrc, *tdst;
-        int need_copy = 0;
-
-        /* fill cyclic buffer - horizontal filtering */
-        for( ; crows < ker_height; crows++ )
-        {
-            tsrc = src;
-            tdst = rows[crows];
-
-            if( src_height-- <= 0 )
-            {
-                if( stage != CV_WHOLE && stage != CV_END )
-                    break;
-                /* duplicate last row */
-                tsrc = rows[crows - 1];
-                CV_COPY( tdst, tsrc, width_n + ker_width_n, x );
-                continue;
-            }
-
-            src += srcStep;
-
-            CV_COPY( tdst + ker_x_n, tsrc, width_n, x );
-
-            /* make replication borders */
-            if( channels == 1 )
-            {
-                uchar pix = tdst[ker_x];
-
-                CV_SET( tdst, pix, ker_x, x );
-
-                pix = tdst[width + ker_x - 1];
-                CV_SET( tdst + width + ker_x, pix, ker_right, x );
-            }
-            else if( channels == 3 )
-            {
-                CvRGB8u pix = ((CvRGB8u *) tdst)[ker_x];
-
-                CV_SET( (CvRGB8u *) tdst, pix, ker_x, x );
-
-                pix = ((CvRGB8u *) tdst)[width + ker_x - 1];
-                CV_SET( (CvRGB8u *) tdst + width + ker_x, pix, ker_right, x );
-            }
-            else                /* channels == 4 */
-            {
-                /* make replication borders */
-                CvRGBA8u pix = ((CvRGBA8u *) tdst)[ker_x];
-
-                CV_SET( (CvRGBA8u *) tdst, pix, ker_x, x );
-
-                pix = ((CvRGBA8u *) tdst)[width + ker_x - 1];
-                CV_SET( (CvRGBA8u *) tdst + width + ker_x, pix, ker_right, x );
-            }
-        }
-
-        if( starting_flag )
-        {
-            starting_flag = 0;
-            tsrc = rows[ker_y];
-
-            for( i = 0; i < ker_y; i++ )
-            {
-                tdst = rows[i];
-                CV_COPY( tdst, tsrc, width_n + ker_width_n, x );
-            }
-        }
-
-        /* vertical convolution */
-        if( crows < ker_height )
-            break;
-
-        tdst = dst;
-        if( width_rest )
-        {
-            need_copy = width_n < CV_MORPH_ALIGN || y == dst_height - 1;
-
-            if( need_copy )
-                tdst = tbuf;
-            else
-                CV_COPY( tbuf + width_n, dst + width_n, CV_MORPH_ALIGN, x );
-        }
-
-        if( channels == 1 )
-        {
-            for( x = 0; x < width_n; x += 4 )
-            {
-                int val0 = INIT_VAL, val1 = INIT_VAL, val2 = INIT_VAL, val3 = INIT_VAL;
-
-                uchar *ker = ker_data;
-
-                for( i = 0; i < ker_height; i++, ker += ker_width )
-                {
-                    int j = -ker_width;
-
-                    tsrc = rows[i] + x - j;
-                    do
-                    {
-                        int m = ker[j];
-                        int t = tsrc[j] & m;
-
-                        CV_CALC_MAX( val0, t );
-                        t = tsrc[j + 1] & m;
-                        CV_CALC_MAX( val1, t );
-                        t = tsrc[j + 2] & m;
-                        CV_CALC_MAX( val2, t );
-                        t = tsrc[j + 3] & m;
-                        CV_CALC_MAX( val3, t );
-                    }
-                    while( ++j < 0 );
-                }
-
-                tdst[x] = (uchar) val0;
-                tdst[x + 1] = (uchar) val1;
-                tdst[x + 2] = (uchar) val2;
-                tdst[x + 3] = (uchar) val3;
-            }
-        }
-        else if( channels == 3 )
-        {
-            for( x = 0; x < width_n; x += 3 )
-            {
-                int val0 = INIT_VAL, val1 = INIT_VAL, val2 = INIT_VAL;
-
-                uchar *ker = ker_data;
-
-                for( i = 0; i < ker_height; i++, ker += ker_width )
-                {
-                    int j = -ker_width;
-
-                    tsrc = rows[i] + x - j * 3;
-                    for( ; j < 0; j++ )
-                    {
-                        int m = ker[j];
-                        int t = tsrc[j * 3] & m;
-
-                        CV_CALC_MAX( val0, t );
-                        t = tsrc[j * 3 + 1] & m;
-                        CV_CALC_MAX( val1, t );
-                        t = tsrc[j * 3 + 2] & m;
-                        CV_CALC_MAX( val2, t );
-                    }
-                }
-
-                tdst[x] = (uchar) val0;
-                tdst[x + 1] = (uchar) val1;
-                tdst[x + 2] = (uchar) val2;
-            }
-        }
-        else
-        {
-            for( x = 0; x < width_n; x += 4 )
-            {
-                int val0 = INIT_VAL, val1 = INIT_VAL, val2 = INIT_VAL, val3 = INIT_VAL;
-
-                uchar *ker = ker_data;
-
-                for( i = 0; i < ker_height; i++, ker += ker_width )
-                {
-                    int j = -ker_width;
-
-                    tsrc = rows[i] + x - j * 4;
-                    for( ; j < 0; j++ )
-                    {
-                        int m = ker[j];
-                        int t = tsrc[j * 4] & m;
-
-                        CV_CALC_MAX( val0, t );
-                        t = tsrc[j * 4 + 1] & m;
-                        CV_CALC_MAX( val1, t );
-                        t = tsrc[j * 4 + 2] & m;
-                        CV_CALC_MAX( val2, t );
-                        t = tsrc[j * 4 + 3] & m;
-                        CV_CALC_MAX( val3, t );
-                    }
-                }
-
-                tdst[x] = (uchar) val0;
-                tdst[x + 1] = (uchar) val1;
-                tdst[x + 2] = (uchar) val2;
-                tdst[x + 3] = (uchar) val3;
-            }
-        }
-
-        if( width_rest )
-        {
-            if( need_copy )
-                CV_COPY( dst, tbuf, width_n, x );
-            else
-                CV_COPY( dst + width_n, tbuf + width_n, CV_MORPH_ALIGN, x );
-        }
-
-        /* rotate buffer */
-        {
-            uchar *t = rows[0];
-
-            CV_COPY( rows, rows + 1, ker_height - 1, i );
-            rows[i] = t;
-            crows--;
-            dst += dstStep;
-        }
-    }
-    while( ++y < dst_height );
-
-    roiSize->height = y;
-    state->crows = crows;
+/****************************************************************************************\
+*         Erode/Dilate with arbitrary element and arbitrary type                         *
+\****************************************************************************************/
 
-    return CV_OK;
-#undef INIT_VAL
+#define ICV_DEF_MORPH_ARB_FUNC( name, flavor, arrtype, init_val,            \
+                                update_extr_macro, toggle_macro )           \
+static CvStatus                                                             \
+icv##name##Arb_##flavor( arrtype* src, int srcstep,                         \
+                         arrtype* dst, int dststep,                         \
+                         CvSize* roi, CvMorphState* state, int stage )      \
+{                                                                           \
+    const int INIT_VAL = init_val;                                          \
+    int width = roi->width;                                                 \
+    int src_height = roi->height;                                           \
+    int dst_height = src_height;                                            \
+    int x, y = 0, i;                                                        \
+                                                                            \
+    int ker_x = state->ker_x;                                               \
+    int ker_y = state->ker_y;                                               \
+    int ker_width = state->ker_width;                                       \
+    int ker_height = state->ker_height;                                     \
+    uchar *ker_data = state->ker0;                                          \
+                                                                            \
+    int crows = state->crows;                                               \
+    arrtype **rows = (arrtype **) (state->rows);                            \
+    arrtype *tbuf = (arrtype *) (state->tbuf);                              \
+                                                                            \
+    int channels = state->channels;                                         \
+    int ker_x_n = ker_x * channels;                                         \
+    int ker_width_n = ker_width * channels;                                 \
+    int width_n = width * channels;                                         \
+                                                                            \
+    int starting_flag = 0;                                                  \
+    int width_rest = width_n & (CV_MORPH_ALIGN - 1);                        \
+    arrtype **ker_ptr, **ker = (arrtype**)cvStackAlloc(                     \
+        ker_width*ker_height*sizeof(ker[0]) );                              \
+                                                                            \
+    srcstep /= sizeof(src[0]);                                              \
+    dststep /= sizeof(dst[0]);                                              \
+                                                                            \
+    /* initialize cyclic buffer when starting */                            \
+    if( stage == CV_WHOLE || stage == CV_START )                            \
+    {                                                                       \
+        for( i = 0; i < ker_height; i++ )                                   \
+            rows[i] = (arrtype *) (state->buffer + state->buffer_step * i); \
+        crows = ker_y;                                                      \
+        if( stage != CV_WHOLE )                                             \
+            dst_height -= ker_height - ker_y - 1;                           \
+        starting_flag = 1;                                                  \
+    }                                                                       \
+                                                                            \
+    if( stage == CV_END )                                                   \
+        dst_height += ker_height - ker_y - 1;                               \
+                                                                            \
+    do                                                                      \
+    {                                                                       \
+        arrtype *tsrc, *tdst;                                               \
+        int need_copy = 0;                                                  \
+                                                                            \
+        /* fill cyclic buffer - horizontal filtering */                     \
+        for( ; crows < ker_height; crows++ )                                \
+        {                                                                   \
+            tsrc = src;                                                     \
+            tdst = rows[crows];                                             \
+                                                                            \
+            if( src_height-- <= 0 )                                         \
+            {                                                               \
+                if( stage != CV_WHOLE && stage != CV_END )                  \
+                    break;                                                  \
+                /* duplicate last row */                                    \
+                tsrc = rows[crows - 1];                                     \
+                CV_COPY( tdst, tsrc, width_n + ker_width_n, x );            \
+                continue;                                                   \
+            }                                                               \
+                                                                            \
+            src += srcstep;                                                 \
+            for( x = 0; x < width_n; x++ )                                  \
+            {                                                               \
+                arrtype t = tsrc[x];                                        \
+                tdst[ker_x_n + x] = toggle_macro(t);                        \
+            }                                                               \
+                                                                            \
+            /* make replication borders */                                  \
+            for( i = ker_x_n - 1; i >= 0; i-- )                             \
+                tdst[i] = tdst[i + channels];                               \
+            for( i = width_n + ker_x_n; i < width_n + ker_width_n; i++ )    \
+                tdst[i] = tdst[i - channels];                               \
+        }                                                                   \
+                                                                            \
+        if( starting_flag )                                                 \
+        {                                                                   \
+            starting_flag = 0;                                              \
+            tsrc = rows[ker_y];                                             \
+                                                                            \
+            for( i = 0; i < ker_y; i++ )                                    \
+            {                                                               \
+                tdst = rows[i];                                             \
+                CV_COPY( tdst, tsrc, width_n + ker_width_n, x );            \
+            }                                                               \
+        }                                                                   \
+                                                                            \
+        if( crows < ker_height )                                            \
+            break;                                                          \
+                                                                            \
+        tdst = dst;                                                         \
+        if( width_rest )                                                    \
+        {                                                                   \
+            need_copy = width_n < CV_MORPH_ALIGN || y == dst_height - 1;    \
+                                                                            \
+            if( need_copy )                                                 \
+                tdst = tbuf;                                                \
+            else                                                            \
+                CV_COPY( tbuf + width_n, dst + width_n, CV_MORPH_ALIGN, x );\
+        }                                                                   \
+                                                                            \
+        ker_ptr = ker;                                                      \
+        for( i = 0; i < ker_height; i++ )                                   \
+            for( x = 0; x < ker_width; x++ )                                \
+            {                                                               \
+                if( ker_data[i*ker_width + x] )                             \
+                    *ker_ptr++ = rows[i] + x*channels;                      \
+            }                                                               \
+                                                                            \
+        if( channels == 3 )                                                 \
+            for( x = 0; x < width_n; x += 3 )                               \
+            {                                                               \
+                int val0 = INIT_VAL, val1 = INIT_VAL, val2 = INIT_VAL;      \
+                arrtype** kp = ker;                                         \
+                while( kp != ker_ptr )                                      \
+                {                                                           \
+                    arrtype* tp = *kp++;                                    \
+                    int t = tp[x];                                          \
+                    update_extr_macro( val0, t );                           \
+                    t = tp[x+1];                                            \
+                    update_extr_macro( val1, t );                           \
+                    t = tp[x+2];                                            \
+                    update_extr_macro( val2, t );                           \
+                }                                                           \
+                tdst[x] = (arrtype)toggle_macro(val0);                      \
+                tdst[x + 1] = (arrtype)toggle_macro(val1);                  \
+                tdst[x + 2] = (arrtype)toggle_macro(val2);                  \
+            }                                                               \
+        else                                                                \
+            /* channels == 1 or channels == 4 */                            \
+            for( x = 0; x < width_n; x += 4 )                               \
+            {                                                               \
+                int val0 = INIT_VAL, val1 = INIT_VAL,                       \
+                    val2 = INIT_VAL, val3 = INIT_VAL;                       \
+                arrtype** kp = ker;                                         \
+                while( kp != ker_ptr )                                      \
+                {                                                           \
+                    arrtype* tp = *kp++;                                    \
+                    int t = tp[x];                                          \
+                    update_extr_macro( val0, t );                           \
+                    t = tp[x+1];                                            \
+                    update_extr_macro( val1, t );                           \
+                    t = tp[x+2];                                            \
+                    update_extr_macro( val2, t );                           \
+                    t = tp[x+3];                                            \
+                    update_extr_macro( val3, t );                           \
+                }                                                           \
+                                                                            \
+                tdst[x] = (arrtype)toggle_macro(val0);                      \
+                tdst[x + 1] = (arrtype)toggle_macro(val1);                  \
+                tdst[x + 2] = (arrtype)toggle_macro(val2);                  \
+                tdst[x + 3] = (arrtype)toggle_macro(val3);                  \
+            }                                                               \
+                                                                            \
+        if( width_rest )                                                    \
+        {                                                                   \
+            if( need_copy )                                                 \
+                CV_COPY( dst, tbuf, width_n, x );                           \
+            else                                                            \
+                CV_COPY( dst + width_n, tbuf + width_n, CV_MORPH_ALIGN, x );\
+        }                                                                   \
+                                                                            \
+        /* rotate buffer */                                                 \
+        {                                                                   \
+            arrtype *t = rows[0];                                           \
+                                                                            \
+            CV_COPY( rows, rows + 1, ker_height - 1, i );                   \
+            rows[i] = t;                                                    \
+            crows--;                                                        \
+            dst += dststep;                                                 \
+        }                                                                   \
+    }                                                                       \
+    while( ++y < dst_height );                                              \
+                                                                            \
+    roi->height = y;                                                        \
+    state->crows = crows;                                                   \
+                                                                            \
+    return CV_OK;                                                           \
 }
 
 
+ICV_DEF_MORPH_RECT_INT_FUNC( Erode, 8u, uchar, CV_CALC_MIN )
+ICV_DEF_MORPH_RECT_INT_FUNC( Dilate, 8u, uchar, CV_CALC_MAX )
+ICV_DEF_MORPH_RECT_FLT_FUNC( Erode, 32f, int, CV_CALC_MIN )
+ICV_DEF_MORPH_RECT_FLT_FUNC( Dilate, 32f, int, CV_CALC_MAX )
 
-static CvStatus
-icvDilateRC_32f( float *src, int srcStep,
-                 float *dst, int dstStep, CvSize * roiSize, CvMorphState * state, int stage )
-{
-    int width = roiSize->width;
-    int src_height = roiSize->height;
-    int dst_height = src_height;
-    int x, y = 0, i;
-
-    int ker_x = state->ker_x;
-    int ker_y = state->ker_y;
-    int ker_width = state->ker_width;
-    int ker_height = state->ker_height;
-    int ker_right = ker_width - ker_x - ((width & 1) == 0);
-
-    int crows = state->crows;
-    int **rows = (int **) (state->rows);
-    int *tbuf = (int *) (state->tbuf);
-    int *tbuf2 = (int *) (state->tbuf + state->buffer_step);
-
-    int channels = state->channels;
-    int ker_x_n = ker_x * channels;
-    int ker_width_n = ker_width * channels;
-    int width_n = width * channels;
-
-    int starting_flag = 0;
-    int width_rest = width_n & (CV_MORPH_ALIGN - 1);
-
-    int is_cross = ICV_BINARY_KERNEL_SHAPE(state->kerType) == CV_SHAPE_CROSS;
-
-    /* initialize cyclic buffer when starting */
-    if( stage == CV_WHOLE || stage == CV_START )
-    {
-        for( i = 0; i < ker_height; i++ )
-        {
-            rows[i] = (int *) (state->buffer + state->buffer_step * i);
-        }
-        crows = ker_y;
-        if( stage != CV_WHOLE )
-            dst_height -= ker_height - ker_y - 1;
-        starting_flag = 1;
-    }
-
-    if( stage == CV_END )
-        dst_height += ker_height - ker_y - 1;
-
-    srcStep /= sizeof_float;
-    dstStep /= sizeof_float;
-
-    do
-    {
-        int need_copy = 0;
-        int *tsrc, *tdst;
-        int *saved_row = rows[ker_y];
-
-        /* fill cyclic buffer - horizontal filtering */
-        for( ; crows < ker_height + is_cross; crows++ )
-        {
-            if( crows < ker_height )
-            {
-                tsrc = (int *) src;
-                tdst = rows[crows];
-
-                if( src_height-- <= 0 )
-                {
-                    if( stage != CV_WHOLE && stage != CV_END )
-                        break;
-                    /* duplicate last row */
-                    tsrc = rows[crows - 1];
-                    CV_COPY( tdst, tsrc, width_n, x );
-                    continue;
-                }
-
-                for( x = 0; x < width_n; x++ )
-                {
-                    int t = tsrc[x];
-
-                    tbuf2[x] = CV_TOGGLE_FLT( t );
-                }
-
-                tsrc = tbuf2 - ker_x_n;
-            }
-            else
-            {
-                /* convolve center line for cross-shaped element */
-                tsrc = rows[ker_y] - ker_x_n;
-                tdst = tbuf;
-            }
-
-            if( ker_width > 1 && (!is_cross || crows == ker_height) )
-            {
-                if( channels == 1 )
-                {
-                    /* make replication borders */
-                    int pix = tsrc[ker_x];
-
-                    CV_SET( tsrc, pix, ker_x, x );
-
-                    pix = tsrc[width + ker_x - 1];
-                    CV_SET( tsrc + width + ker_x, pix, ker_right, x );
-
-                    /* horizontal convolution loop */
-                    for( i = 0; i < width_n; i += 2 )
-                    {
-                        int j;
-                        int t, t0 = tsrc[i + 1];
-
-                        for( j = 2; j < ker_width_n; j++ )
-                        {
-                            int t1 = tsrc[i + j];
-
-                            CV_CALC_MAX( t0, t1 );
-                        }
-
-                        t = tsrc[i];
-                        CV_CALC_MAX( t, t0 );
-                        tdst[i] = (int) t;
-
-                        t = tsrc[i + j];
-                        CV_CALC_MAX( t, t0 );
-                        tdst[i + 1] = (int) t;
-                    }
-                }
-                else if( channels == 3 )
-                {
-                    /* make replication borders */
-                    CvRGB32s pix = ((CvRGB32s *) tsrc)[ker_x];
-
-                    CV_SET( (CvRGB32s *) tsrc, pix, ker_x, x );
-
-                    pix = ((CvRGB32s *) tsrc)[width + ker_x - 1];
-                    CV_SET( (CvRGB32s *) tsrc + width + ker_x, pix, ker_right, x );
-
-                    /* horizontal convolution loop */
-                    for( i = 0; i < width_n; i++ )
-                    {
-                        int j;
-                        int t0 = tsrc[i];
-
-                        for( j = 3; j < ker_width_n; j += 3 )
-                        {
-                            int t1 = tsrc[i + j];
-
-                            CV_CALC_MAX( t0, t1 );
-                        }
-
-                        tdst[i] = (int) t0;
-                    }
-                }
-                else            /* channels == 4 */
-                {
-                    /* make replication borders */
-                    CvRGBA32s pix = ((CvRGBA32s *) tsrc)[ker_x];
-
-                    CV_SET( (CvRGBA32s *) tsrc, pix, ker_x, x );
-
-                    pix = ((CvRGBA32s *) tsrc)[width + ker_x - 1];
-                    CV_SET( (CvRGBA32s *) tsrc + width + ker_x, pix, ker_right, x );
-
-                    /* horizontal convolution loop */
-                    for( i = 0; i < width_n; i++ )
-                    {
-                        int j;
-                        int t0 = tsrc[i];
-
-                        for( j = 4; j < ker_width_n; j += 4 )
-                        {
-                            int t1 = tsrc[i + j];
-
-                            CV_CALC_MAX( t0, t1 );
-                        }
-
-                        tdst[i] = (int) t0;
-                    }
-                }
-            }
-            else
-            {
-                CV_COPY( tdst, tsrc + ker_x_n, width_n, x );
-            }
-
-            if( crows < ker_height )
-                src += srcStep;
-        }
-
-        if( starting_flag )
-        {
-            starting_flag = 0;
-            tsrc = rows[ker_y];
-
-            for( i = 0; i < ker_y; i++ )
-            {
-                tdst = rows[i];
-                CV_COPY( tdst, tsrc, width_n, x );
-            }
-        }
-
-        /* vertical convolution */
-        if( crows != ker_height )
-        {
-            if( crows < ker_height )
-                break;
-            /* else it is cross-shaped element: change central line */
-            rows[ker_y] = tbuf;
-            crows--;
-        }
-
-        tdst = (int *) dst;
-
-        if( width_rest )
-        {
-            need_copy = width_n < CV_MORPH_ALIGN || y == dst_height - 1;
-
-            if( need_copy )
-                tdst = tbuf;
-            else
-                CV_COPY( tbuf + width_n, tdst + width_n, CV_MORPH_ALIGN, x );
-        }
-
-        for( x = 0; x < width_n; x += 4 )
-        {
-            int val0, val1, val2, val3;
-
-            tsrc = rows[0];
-
-            val0 = tsrc[x];
-            val1 = tsrc[x + 1];
-            val2 = tsrc[x + 2];
-            val3 = tsrc[x + 3];
-
-            for( i = 1; i < ker_height; i++ )
-            {
-                int s;
-
-                tsrc = rows[i];
-
-                s = tsrc[x + 0];
-                CV_CALC_MAX( val0, s );
-                s = tsrc[x + 1];
-                CV_CALC_MAX( val1, s );
-                s = tsrc[x + 2];
-                CV_CALC_MAX( val2, s );
-                s = tsrc[x + 3];
-                CV_CALC_MAX( val3, s );
-            }
-            tdst[x + 0] = CV_TOGGLE_FLT( val0 );
-            tdst[x + 1] = CV_TOGGLE_FLT( val1 );
-            tdst[x + 2] = CV_TOGGLE_FLT( val2 );
-            tdst[x + 3] = CV_TOGGLE_FLT( val3 );
-        }
-
-        if( width_rest )
-        {
-            if( need_copy )
-                CV_COPY( (int *) dst, tbuf, width_n, x );
-            else
-                CV_COPY( tdst + width_n, tbuf + width_n, CV_MORPH_ALIGN, x );
-        }
-
-        rows[ker_y] = saved_row;
-
-        /* rotate buffer */
-        {
-            int *t = rows[0];
-
-            CV_COPY( rows, rows + 1, ker_height - 1, i );
-            rows[i] = t;
-            crows--;
-            dst += dstStep;
-        }
-    }
-    while( ++y < dst_height );
-
-    roiSize->height = y;
-    state->crows = crows;
-
-    return CV_OK;
-}
-
-
+ICV_DEF_MORPH_ARB_FUNC( Erode, 8u, uchar, 255, CV_CALC_MIN, CV_NOP )
+ICV_DEF_MORPH_ARB_FUNC( Dilate, 8u, uchar, 0, CV_CALC_MAX, CV_NOP )
+ICV_DEF_MORPH_ARB_FUNC( Erode, 32f, int, INT_MAX, CV_CALC_MIN, CV_TOGGLE_FLT )
+ICV_DEF_MORPH_ARB_FUNC( Dilate, 32f, int, INT_MIN, CV_CALC_MAX, CV_TOGGLE_FLT )
 
 static CvStatus
-icvCheckMorphArgs( const void *pSrc, int srcStep,
-                   void *pDst, int dstStep,
-                   CvSize * roiSize,
+icvCheckMorphArgs( const void *pSrc, int srcstep,
+                   void *pDst, int dststep,
+                   CvSize * roi,
                    CvMorphState * state,
-                   int stage, CvElementShape shape, CvDataType dataType, int channels )
+                   int stage, int shape, CvDataType dataType, int channels )
 {
     int bt_pix = channels * (dataType != cv32f ? 1 : 4);
 
-    if( !pSrc || !pDst || !state || !roiSize )
+    if( !pSrc || !pDst || !state || !roi )
         return CV_NULLPTR_ERR;
 
-    if( roiSize->width <= 0 || roiSize->width > state->max_width || roiSize->height < 0 )
+    if( roi->width <= 0 || roi->width > state->max_width || roi->height < 0 )
         return CV_BADSIZE_ERR;
 
     if( state->dataType != dataType || state->channels != channels )
@@ -2345,40 +825,40 @@ icvCheckMorphArgs( const void *pSrc, int srcStep,
     if( ICV_BINARY_KERNEL_SHAPE(state->kerType) != shape )
         return CV_UNMATCHED_FORMATS_ERR;
 
-    if( roiSize->width * bt_pix > srcStep || roiSize->width * bt_pix > dstStep )
+    if( roi->width * bt_pix > srcstep || roi->width * bt_pix > dststep )
         return CV_BADSIZE_ERR;
 
     if( stage != CV_WHOLE && stage != CV_MIDDLE && stage != CV_START && stage != CV_END )
         return CV_BADRANGE_ERR;
 
-    if( state->crows == 0 && stage > CV_START || roiSize->height == 0 && stage != CV_END )
+    if( state->crows == 0 && stage > CV_START || roi->height == 0 && stage != CV_END )
     {
-        roiSize->height = 0;
+        roi->height = 0;
         return ( CvStatus ) 1;
     }
 
     return CV_OK;
 }
 
-
 /****************************************************************************************\
                               Internal IPP-like functions
 \****************************************************************************************/
 
 #define ICV_DEF_MORPH_FUNC( extname, intname, flavor, cn, arrtype, shape )          \
 IPCVAPI_IMPL( CvStatus,                                                             \
-icv##extname##_##flavor##_C##cn##R,( const arrtype* pSrc, int srcStep,              \
-                                     arrtype* pDst, int dstStep,                    \
-                                     CvSize* roiSize,                               \
-                                     CvMorphState * state, int stage ))             \
+icv##extname##_##flavor##_C##cn##R,( const arrtype* pSrc, int srcstep,              \
+                                     arrtype* pDst, int dststep,                    \
+                                     CvSize* roi,                                   \
+                                     CvMorphState * state, int stage ),             \
+                                     (pSrc, srcstep, pDst, dststep, roi, state, stage) )\
 {                                                                                   \
-    CvStatus status = icvCheckMorphArgs( pSrc, srcStep, pDst, dstStep, roiSize,     \
+    CvStatus status = icvCheckMorphArgs( pSrc, srcstep, pDst, dststep, roi,         \
                                          state, stage, shape, cv##flavor, cn );     \
                                                                                     \
     if( status == CV_OK )                                                           \
     {                                                                               \
-        status = icv##intname##_##flavor( (arrtype*)pSrc, srcStep, pDst, dstStep,   \
-                                          roiSize, state, stage );                  \
+        status = icv##intname##_##flavor( (arrtype*)pSrc, srcstep, pDst, dststep,   \
+                                          roi, state, stage );                      \
     }                                                                               \
                                                                                     \
     return status >= 0 ? CV_OK : status;                                            \
@@ -2397,17 +877,17 @@ ICV_DEF_MORPH_FUNC( ErodeStrip, ErodeArb, 8u, 1, uchar, CV_SHAPE_CUSTOM )
 ICV_DEF_MORPH_FUNC( ErodeStrip, ErodeArb, 8u, 3, uchar, CV_SHAPE_CUSTOM )
 ICV_DEF_MORPH_FUNC( ErodeStrip, ErodeArb, 8u, 4, uchar, CV_SHAPE_CUSTOM )
 
-ICV_DEF_MORPH_FUNC( ErodeStrip_Rect, ErodeRC, 32f, 1, float, CV_SHAPE_RECT )
-ICV_DEF_MORPH_FUNC( ErodeStrip_Rect, ErodeRC, 32f, 3, float, CV_SHAPE_RECT )
-ICV_DEF_MORPH_FUNC( ErodeStrip_Rect, ErodeRC, 32f, 4, float, CV_SHAPE_RECT )
+ICV_DEF_MORPH_FUNC( ErodeStrip_Rect, ErodeRC, 32f, 1, int, CV_SHAPE_RECT )
+ICV_DEF_MORPH_FUNC( ErodeStrip_Rect, ErodeRC, 32f, 3, int, CV_SHAPE_RECT )
+ICV_DEF_MORPH_FUNC( ErodeStrip_Rect, ErodeRC, 32f, 4, int, CV_SHAPE_RECT )
 
-ICV_DEF_MORPH_FUNC( ErodeStrip_Cross, ErodeRC, 32f, 1, float, CV_SHAPE_CROSS )
-ICV_DEF_MORPH_FUNC( ErodeStrip_Cross, ErodeRC, 32f, 3, float, CV_SHAPE_CROSS )
-ICV_DEF_MORPH_FUNC( ErodeStrip_Cross, ErodeRC, 32f, 4, float, CV_SHAPE_CROSS )
+ICV_DEF_MORPH_FUNC( ErodeStrip_Cross, ErodeRC, 32f, 1, int, CV_SHAPE_CROSS )
+ICV_DEF_MORPH_FUNC( ErodeStrip_Cross, ErodeRC, 32f, 3, int, CV_SHAPE_CROSS )
+ICV_DEF_MORPH_FUNC( ErodeStrip_Cross, ErodeRC, 32f, 4, int, CV_SHAPE_CROSS )
 
-ICV_DEF_MORPH_FUNC( ErodeStrip, ErodeArb, 32f, 1, float, CV_SHAPE_CUSTOM )
-ICV_DEF_MORPH_FUNC( ErodeStrip, ErodeArb, 32f, 3, float, CV_SHAPE_CUSTOM )
-ICV_DEF_MORPH_FUNC( ErodeStrip, ErodeArb, 32f, 4, float, CV_SHAPE_CUSTOM )
+ICV_DEF_MORPH_FUNC( ErodeStrip, ErodeArb, 32f, 1, int, CV_SHAPE_CUSTOM )
+ICV_DEF_MORPH_FUNC( ErodeStrip, ErodeArb, 32f, 3, int, CV_SHAPE_CUSTOM )
+ICV_DEF_MORPH_FUNC( ErodeStrip, ErodeArb, 32f, 4, int, CV_SHAPE_CUSTOM )
 
 ICV_DEF_MORPH_FUNC( DilateStrip_Rect, DilateRC, 8u, 1, uchar, CV_SHAPE_RECT )
 ICV_DEF_MORPH_FUNC( DilateStrip_Rect, DilateRC, 8u, 3, uchar, CV_SHAPE_RECT )
@@ -2421,17 +901,17 @@ ICV_DEF_MORPH_FUNC( DilateStrip, DilateArb, 8u, 1, uchar, CV_SHAPE_CUSTOM )
 ICV_DEF_MORPH_FUNC( DilateStrip, DilateArb, 8u, 3, uchar, CV_SHAPE_CUSTOM )
 ICV_DEF_MORPH_FUNC( DilateStrip, DilateArb, 8u, 4, uchar, CV_SHAPE_CUSTOM )
 
-ICV_DEF_MORPH_FUNC( DilateStrip_Rect, DilateRC, 32f, 1, float, CV_SHAPE_RECT )
-ICV_DEF_MORPH_FUNC( DilateStrip_Rect, DilateRC, 32f, 3, float, CV_SHAPE_RECT )
-ICV_DEF_MORPH_FUNC( DilateStrip_Rect, DilateRC, 32f, 4, float, CV_SHAPE_RECT )
+ICV_DEF_MORPH_FUNC( DilateStrip_Rect, DilateRC, 32f, 1, int, CV_SHAPE_RECT )
+ICV_DEF_MORPH_FUNC( DilateStrip_Rect, DilateRC, 32f, 3, int, CV_SHAPE_RECT )
+ICV_DEF_MORPH_FUNC( DilateStrip_Rect, DilateRC, 32f, 4, int, CV_SHAPE_RECT )
 
-ICV_DEF_MORPH_FUNC( DilateStrip_Cross, DilateRC, 32f, 1, float, CV_SHAPE_CROSS )
-ICV_DEF_MORPH_FUNC( DilateStrip_Cross, DilateRC, 32f, 3, float, CV_SHAPE_CROSS )
-ICV_DEF_MORPH_FUNC( DilateStrip_Cross, DilateRC, 32f, 4, float, CV_SHAPE_CROSS )
+ICV_DEF_MORPH_FUNC( DilateStrip_Cross, DilateRC, 32f, 1, int, CV_SHAPE_CROSS )
+ICV_DEF_MORPH_FUNC( DilateStrip_Cross, DilateRC, 32f, 3, int, CV_SHAPE_CROSS )
+ICV_DEF_MORPH_FUNC( DilateStrip_Cross, DilateRC, 32f, 4, int, CV_SHAPE_CROSS )
 
-ICV_DEF_MORPH_FUNC( DilateStrip, DilateArb, 32f, 1, float, CV_SHAPE_CUSTOM )
-ICV_DEF_MORPH_FUNC( DilateStrip, DilateArb, 32f, 3, float, CV_SHAPE_CUSTOM )
-ICV_DEF_MORPH_FUNC( DilateStrip, DilateArb, 32f, 4, float, CV_SHAPE_CUSTOM )
+ICV_DEF_MORPH_FUNC( DilateStrip, DilateArb, 32f, 1, int, CV_SHAPE_CUSTOM )
+ICV_DEF_MORPH_FUNC( DilateStrip, DilateArb, 32f, 3, int, CV_SHAPE_CUSTOM )
+ICV_DEF_MORPH_FUNC( DilateStrip, DilateArb, 32f, 4, int, CV_SHAPE_CUSTOM )
 
 
 
@@ -2441,7 +921,7 @@ ICV_DEF_MORPH_FUNC( DilateStrip, DilateArb, 32f, 4, float, CV_SHAPE_CUSTOM )
 CV_IMPL IplConvKernel *
 cvCreateStructuringElementEx( int cols, int rows,
                               int anchorX, int anchorY,
-                              CvElementShape shape, int *values )
+                              int shape, int *values )
 {
     IplConvKernel *element = 0;
     int i, size = rows * cols;
@@ -2459,8 +939,8 @@ cvCreateStructuringElementEx( int cols, int rows,
         (unsigned) anchorX >= (unsigned) cols || (unsigned) anchorY >= (unsigned) rows )
         CV_ERROR_FROM_STATUS( CV_BADSIZE_ERR );
 
-    element_size = icvAlign(element_size,32);
-    element = (IplConvKernel *) icvAlloc( element_size );
+    element_size = cvAlign(element_size,32);
+    element = (IplConvKernel *)cvAlloc( element_size );
     if( !element )
         CV_ERROR_FROM_STATUS( CV_OUTOFMEM_ERR );
 
@@ -2499,7 +979,7 @@ cvCreateStructuringElementEx( int cols, int rows,
             for( i = 0; i < r; i++ )
             {
                 int y = r - i;
-                int dx = cvRound( c * sqrt( (r * r - y * y) * inv_r2 ));
+                int dx = cvRound( c * sqrt( ((double)r * r - y * y) * inv_r2 ));
                 int x1 = c - dx;
                 int x2 = c + dx;
 
@@ -2520,7 +1000,7 @@ cvCreateStructuringElementEx( int cols, int rows,
         }
         break;
     default:
-        icvFree( &element );
+        cvFree( (void**)&element );
         CV_ERROR_FROM_STATUS( CV_BADFLAG_ERR );
     }
 
@@ -2539,7 +1019,7 @@ cvReleaseStructuringElement( IplConvKernel ** element )
 
     if( !element )
         CV_ERROR_FROM_STATUS( CV_NULLPTR_ERR );
-    icvFree( element );
+    cvFree( (void**)element );
 
     __END__;
 }
@@ -2605,19 +1085,19 @@ icvMorphOp( const void* srcarr, void* dstarr, IplConvKernel* element,
     static CvBigFuncTable morph_tab[6];
     static int inittab = 0;
     CvMorphState *state = 0;
+    CvMat* temp = 0;
 
     CV_FUNCNAME( "icvMorphOp" );
 
     __BEGIN__;
 
     CvMorphFunc func = 0;
-    CvElementShape shape;
+    int shape;
     int i, coi1 = 0, coi2 = 0;
     CvMat srcstub, *src = (CvMat*)srcarr;
     CvMat dststub, *dst = (CvMat*)dstarr;
     CvSize size;
     int type;
-    int src_step, dst_step;
 
     if( !inittab )
     {
@@ -2626,6 +1106,9 @@ icvMorphOp( const void* srcarr, void* dstarr, IplConvKernel* element,
         inittab = 1;
     }
 
+    if( iterations <= 0 )
+        CV_CALL( cvCopy( src, dst ));
+
     CV_CALL( src = cvGetMat( src, &srcstub, &coi1 ));
     
     if( src != &srcstub )
@@ -2635,9 +1118,7 @@ icvMorphOp( const void* srcarr, void* dstarr, IplConvKernel* element,
     }
 
     if( dstarr == srcarr )
-    {
         dst = src;
-    }
     else
     {
         CV_CALL( dst = cvGetMat( dst, &dststub, &coi2 ));
@@ -2662,21 +1143,25 @@ icvMorphOp( const void* srcarr, void* dstarr, IplConvKernel* element,
 
     if( element )
     {
+        CvSize element_size = { element->nCols, element->nRows };
+        CvPoint element_anchor = { element->anchorX, element->anchorY };
         IPPI_CALL(
             icvMorphologyInitAlloc( src->width, CV_MAT_DEPTH(type) == CV_8U ? cv8u : cv32f,
-                                 CV_MAT_CN(type), cvSize( element->nCols, element->nRows),
-                                 cvPoint( element->anchorX, element->anchorY ),
-                                 (CvElementShape) (element->nShiftR), element->values,
+                                 CV_MAT_CN(type), element_size, element_anchor,
+                                 (int) (element->nShiftR), element->values,
                                  &state ));
-        shape = (CvElementShape) (element->nShiftR);
+        shape = (int)(element->nShiftR);
         shape = shape < CV_SHAPE_ELLIPSE ? shape : CV_SHAPE_CUSTOM;
     }
     else
     {
+        CvSize element_size = { 1+iterations*2, 1+iterations*2 };
+        CvPoint element_anchor = { iterations, iterations };
         IPPI_CALL(
             icvMorphologyInitAlloc( src->width, CV_MAT_DEPTH(type) == CV_8U ? cv8u : cv32f,
-                                  CV_MAT_CN(type), cvSize( 3, 3 ), cvPoint( 1, 1 ),
+                                  CV_MAT_CN(type), element_size, element_anchor,
                                   CV_SHAPE_RECT, 0, &state ));
+        iterations = 1;
         shape = CV_SHAPE_RECT;
     }
 
@@ -2686,16 +1171,14 @@ icvMorphOp( const void* srcarr, void* dstarr, IplConvKernel* element,
     if( !func )
         CV_ERROR( CV_StsUnsupportedFormat, "" );
 
-    size = icvGetMatSize( src );
-
-    src_step = src->step;
-    dst_step = dst->step;
-
-    if( src_step == 0 )
-        src_step = dst_step = size.width * icvPixSize[type];
+    size = cvGetMatSize( src );
 
     for( i = 0; i < iterations; i++ )
     {
+        int src_step = src->step, dst_step = dst->step;
+        if( src_step == 0 )
+            src_step = dst_step = size.width * CV_ELEM_SIZE(type);
+
         IPPI_CALL( func( src->data.ptr, src_step, dst->data.ptr,
                          dst_step, &size, state, 0 ));
         src = dst;
@@ -2703,6 +1186,7 @@ icvMorphOp( const void* srcarr, void* dstarr, IplConvKernel* element,
 
     __END__;
 
+    cvReleaseMat( &temp );
     icvMorphologyFree( &state );
 }
 
@@ -2724,7 +1208,7 @@ cvDilate( const void* src, void* dst, IplConvKernel* element, int iterations )
 
 CV_IMPL void
 cvMorphologyEx( const void* src, void* dst,
-                void* temp, IplConvKernel* element, CvMorphOp op, int iterations )
+                void* temp, IplConvKernel* element, int op, int iterations )
 {
     CV_FUNCNAME( "cvMorhologyEx" );
 
@@ -2753,12 +1237,18 @@ cvMorphologyEx( const void* src, void* dst,
         CV_CALL( cvSub( dst, temp, dst ));
         break;
     case CV_MOP_TOPHAT:
-        CV_CALL( cvErode( src, src != dst ? dst : temp, element, iterations ));
-        CV_CALL( cvSub( src, src != dst ? dst : temp, dst ));
+        if( src != dst )
+            temp = dst;
+        CV_CALL( cvErode( src, temp, element, iterations ));
+        CV_CALL( cvDilate( temp, temp, element, iterations ));
+        CV_CALL( cvSub( src, temp, dst ));
         break;
     case CV_MOP_BLACKHAT:
-        CV_CALL( cvDilate( src, src != dst ? dst : temp, element, iterations ));
-        CV_CALL( cvSub( src != dst ? dst : temp, src, dst ));
+        if( src != dst )
+            temp = dst;
+        CV_CALL( cvDilate( src, temp, element, iterations ));
+        CV_CALL( cvErode( temp, temp, element, iterations ));
+        CV_CALL( cvSub( temp, src, dst ));
         break;
     default:
         CV_ERROR( CV_StsBadArg, "unknown morphological operation" );
index d3a7476597c672eea329e046b349f3bc651bc053..a7d7a7a87f67b66027d0e287a3cd7851e94cda8a 100644 (file)
 //           CV_BADFACTOR_ERR - mhi_duration is non positive
 //    Notes:
 //F*/
-IPCVAPI_IMPL( CvStatus, icvUpdateMotionHistory_8u32f_C1IR, (const uchar * silIm,
-                                                            int silStep,
-                                                            float *mhiIm,
-                                                            int mhiStep,
-                                                            CvSize size,
-                                                            float timestamp,
-                                                            float mhi_duration) )
+IPCVAPI_IMPL( CvStatus, icvUpdateMotionHistory_8u32f_C1IR,
+    (const uchar * silIm, int silStep, float *mhiIm, int mhiStep,
+     CvSize size, float timestamp, float mhi_duration),
+     (silIm, silStep, mhiIm, mhiStep, size, timestamp, mhi_duration) )
 {
     int y;
     int delbound;
@@ -80,8 +77,8 @@ IPCVAPI_IMPL( CvStatus, icvUpdateMotionHistory_8u32f_C1IR, (const uchar * silIm,
         return CV_NULLPTR_ERR;
 
     if( size.height <= 0 || size.width <= 0 ||
-        silStep < size.width || mhiStep < size.width * sizeof_float ||
-        (mhiStep & (sizeof_float - 1)) != 0 )
+        silStep < size.width || mhiStep < size.width * CV_SIZEOF_FLOAT ||
+        (mhiStep & (CV_SIZEOF_FLOAT - 1)) != 0 )
         return CV_BADSIZE_ERR;
 
     if( mhi_duration < 0 )
@@ -90,7 +87,7 @@ IPCVAPI_IMPL( CvStatus, icvUpdateMotionHistory_8u32f_C1IR, (const uchar * silIm,
     mhi_duration = timestamp - mhi_duration;
     delbound = CV_TOGGLE_FLT( (*(int *) &mhi_duration) );
 
-    mhiStep /= sizeof_float;
+    mhiStep /= CV_SIZEOF_FLOAT;
 
     if( mhiStep == size.width && silStep == size.width )
     {
@@ -193,22 +190,24 @@ icvCalcMotionGradient32fC1R( float *mhi, int mhiStep,
     if( ((mhiStep | orientStep) & 3) != 0 )
         return CV_BADSIZE_ERR;
 
-    tempStep = icvAlign(roi.width,2) * sizeof( float );
+    tempStep = cvAlign(roi.width,2) * sizeof( float );
 
     tempSize = tempStep * roi.height;
 
-    drvX_min = (float *) icvAlloc( tempSize );
-    drvY_max = (float *) icvAlloc( tempSize );
+    drvX_min = (float *) cvAlloc( tempSize );
+    drvY_max = (float *) cvAlloc( tempSize );
     if( !drvX_min || !drvY_max )
     {
         result = CV_OUTOFMEM_ERR;
         goto func_exit;
     }
 
-    icvMorphologyInitAlloc( roi.width, cv32f, 1,
-                             cvSize( apertureSize, apertureSize ),
-                             cvPoint( apertureSize / 2, apertureSize / 2 ),
-                             CV_SHAPE_RECT, 0, &morph_filter );
+    {
+    CvSize element_size = { apertureSize, apertureSize };
+    CvPoint element_anchor = { apertureSize/2, apertureSize/2 };
+    icvMorphologyInitAlloc( roi.width, cv32f, 1, element_size, element_anchor,
+                            CV_SHAPE_RECT, 0, &morph_filter );
+    }
 
     /* calc Dx and Dy */
     icvSobelInitAlloc( roi.width, cv32f, apertureSize, origin, 1, 0, &pX );
@@ -228,7 +227,7 @@ icvCalcMotionGradient32fC1R( float *mhi, int mhiStep,
     for( y = 0; y < roi.height; y++, drvX_min += tempStep / sizeof( float ),
          drvY_max += tempStep / sizeof( float ), orient += orientStep / sizeof( float ))
     {
-        icvbFastArctan_32f( drvY_max, drvX_min, orient, roi.width );
+        cvbFastArctan( drvY_max, drvX_min, orient, roi.width );
 
         /* make orientation zero where the gradient is very small */
         for( x = 0; x < roi.width; x++ )
@@ -244,12 +243,12 @@ icvCalcMotionGradient32fC1R( float *mhi, int mhiStep,
     drvY_max -= tempSize / sizeof( float );
     orient -= (orientStep / sizeof( float )) * roi.height;
 
-    result = icvErodeStrip_Rect_32f_C1R( mhi, mhiStep, drvX_min, tempStep,
-                                          &roi, morph_filter, 0 );
+    result = icvErodeStrip_Rect_32f_C1R( (int*)mhi, mhiStep, (int*)drvX_min, tempStep,
+                                         &roi, morph_filter, 0 );
     if( result < 0 )
         goto func_exit;
 
-    result = icvDilateStrip_Rect_32f_C1R( mhi, mhiStep, drvY_max, tempStep,
+    result = icvDilateStrip_Rect_32f_C1R( (int*)mhi, mhiStep, (int*)drvY_max, tempStep,
                                            &roi, morph_filter, 0 );
     if( result < 0 )
         goto func_exit;
@@ -292,8 +291,8 @@ icvCalcMotionGradient32fC1R( float *mhi, int mhiStep,
   func_exit:
 
     icvMorphologyFree( &morph_filter );
-    icvFree( &drvX_min );
-    icvFree( &drvY_max );
+    cvFree( (void**)&drvX_min );
+    cvFree( (void**)&drvY_max );
 
     return result;
 }
@@ -486,7 +485,7 @@ cvUpdateMotionHistory( const void* silhouette, void* mhimg,
     if( !CV_ARE_SIZES_EQ( mhi, silh ))
         CV_ERROR( CV_StsUnmatchedSizes, "" );
 
-    size = icvGetMatSize( mhi );
+    size = cvGetMatSize( mhi );
 
     mhi_step = mhi->step;
     silh_step = silh->step;
@@ -549,7 +548,7 @@ cvCalcMotionGradient( const void* mhiimg, void* maskimg,
         CV_SWAP( minTDelta, maxTDelta, t );
     }
 
-    size = icvGetMatSize( mhi );
+    size = cvGetMatSize( mhi );
 
     IPPI_CALL( icvCalcMotionGradient32fC1R( mhi->data.fl, mhi->step,
                                             (uchar*)(mask->data.ptr), mask->step,
@@ -594,7 +593,7 @@ cvCalcGlobalOrientation( const void* orientation, const void* maskimg, const voi
     if( !CV_ARE_SIZES_EQ( mhi, mask ) || !CV_ARE_SIZES_EQ( orient, mhi ))
         CV_ERROR( CV_StsUnmatchedSizes, "" );
 
-    size = icvGetMatSize( mhi );
+    size = cvGetMatSize( mhi );
 
     mhi_step = mhi->step;
     mask_step = mask->step;
@@ -675,8 +674,10 @@ cvSegmentMotion( const CvArr* mhiimg, CvArr* segmask, CvMemStorage* storage,
             {
                 CvConnectedComp comp;
                 int x1, y1;
+                CvScalar _seg_thresh = cvRealScalar(seg_thresh);
+                CvPoint seed = cvPoint(x,y);
 
-                CV_CALL( cvFloodFill( mhi, cvPoint( x, y ), 0, seg_thresh, seg_thresh,
+                CV_CALL( cvFloodFill( mhi, seed, cvRealScalar(0), _seg_thresh, _seg_thresh,
                                       &comp, CV_FLOODFILL_MASK_ONLY + 2*256 + 4, mask8u ));
 
                 for( y1 = 0; y1 < comp.rect.height; y1++ )
index cbca6617e29a691d251c937df86b40dc00543746..47a1417f94d303d8d8e638175d0a1e244c53eed1 100644 (file)
 
 #include "_cv.h"
 
-IPCVAPI( CvStatus , icvCalcOpticalFlowBM_8u32fR,( uchar* imgA, uchar* imgB,
-                                                  int  imgStep, CvSize imgSize,
-                                                  CvSize blockSize, CvSize shiftSize,
-                                                  CvSize maxRange,
-                                                  int usePrevious,
-                                                  float*   velocityX,
-                                                  float*   velocityY,
-                                                  int      velStep ))
+
+static CvStatus CV_STDCALL
+icvCopyBM_8u_C1R( const uchar* src, int src_step,
+                  uchar* dst, int dst_step, CvSize size )
+{
+    for( ; size.height--; src += src_step, dst += dst_step )
+        memcpy( dst, src, size.width );
+    return CV_OK;
+}
 
 
 /*F///////////////////////////////////////////////////////////////////////////////////////
@@ -73,16 +74,13 @@ IPCVAPI( CvStatus , icvCalcOpticalFlowBM_8u32fR,( uchar* imgA, uchar* imgB,
 #define SMALL_DIFF 2
 #define BIG_DIFF 128
 
-IPCVAPI_IMPL( CvStatus, icvCalcOpticalFlowBM_8u32fR, (uchar * imgA,
-                                                      uchar * imgB,
-                                                      int imgStep,
-                                                      CvSize imgSize,
-                                                      CvSize blockSize,
-                                                      CvSize shiftSize,
-                                                      CvSize maxRange,
-                                                      int usePrev,
-                                                      float *velocityX,
-                                                      float *velocityY, int velStep) )
+static CvStatus CV_STDCALL
+icvCalcOpticalFlowBM_8u32fR( uchar * imgA, uchar * imgB,
+                             int imgStep, CvSize imgSize,
+                             CvSize blockSize, CvSize shiftSize,
+                             CvSize maxRange, int usePrev,
+                             float *velocityX, float *velocityY,
+                             int velStep )
 {
     const float back = 1.f / (float) (1 << 16);
 
@@ -121,8 +119,8 @@ IPCVAPI_IMPL( CvStatus, icvCalcOpticalFlowBM_8u32fR, (uchar * imgA,
     uchar *blockB = 0;
     uchar *blockZ = 0;
     int blSize = blockSize.width * blockSize.height;
-    int bufferSize = icvAlign(blSize + 9,16);
-    int cmpSize = icvAlign(blSize,4);
+    int bufferSize = cvAlign(blSize + 9,16);
+    int cmpSize = cvAlign(blSize,4);
     int patch_ofs = blSize & -8;
     int64 patch_mask = (((int64) 1) << (blSize - patch_ofs * 8)) - 1;
 
@@ -140,7 +138,7 @@ IPCVAPI_IMPL( CvStatus, icvCalcOpticalFlowBM_8u32fR, (uchar * imgA,
 /****************************************************************************************\
 *   Allocate buffers                                                                     *
 \****************************************************************************************/
-    blockA = (uchar *) icvAlloc( bufferSize * 3 );
+    blockA = (uchar *) cvAlloc( bufferSize * 3 );
     if( !blockA )
         return CV_OUTOFMEM_ERR;
 
@@ -149,11 +147,11 @@ IPCVAPI_IMPL( CvStatus, icvCalcOpticalFlowBM_8u32fR, (uchar * imgA,
 
     memset( blockZ, 0, bufferSize );
 
-    ss = (CvPoint *) icvAlloc( (2 * maxRange.width + 1) * (2 * maxRange.height + 1) *
+    ss = (CvPoint *) cvAlloc( (2 * maxRange.width + 1) * (2 * maxRange.height + 1) *
                                sizeof( CvPoint ));
     if( !ss )
     {
-        icvFree( &blockA );
+        cvFree( (void**)&blockA );
         return CV_OUTOFMEM_ERR;
     }
 
@@ -366,10 +364,10 @@ IPCVAPI_IMPL( CvStatus, icvCalcOpticalFlowBM_8u32fR, (uchar * imgA,
 
             if( main_flag )
             {
-                icvCopy_8u_C1R( imgA + X1, imgStep, blockA,
-                                CurSize.width, CurSize );
-                icvCopy_8u_C1R( imgB + (Y1 + offY)*imgStep + (X1 + offX),
-                                imgStep, blockB, CurSize.width, CurSize );
+                icvCopyBM_8u_C1R( imgA + X1, imgStep, blockA,
+                                  CurSize.width, CurSize );
+                icvCopyBM_8u_C1R( imgB + (Y1 + offY)*imgStep + (X1 + offX),
+                                  imgStep, blockB, CurSize.width, CurSize );
 
                 *((int64 *) (blockA + patch_ofs)) &= patch_mask;
                 *((int64 *) (blockB + patch_ofs)) &= patch_mask;
@@ -379,9 +377,9 @@ IPCVAPI_IMPL( CvStatus, icvCalcOpticalFlowBM_8u32fR, (uchar * imgA,
                 memset( blockA, 0, bufferSize );
                 memset( blockB, 0, bufferSize );
 
-                icvCopy_8u_C1R( imgA + X1, imgStep, blockA, blockSize.width, CurSize );
-                icvCopy_8u_C1R( imgB + (Y1 + offY) * imgStep + (X1 + offX), imgStep,
-                                blockB, blockSize.width, CurSize );
+                icvCopyBM_8u_C1R( imgA + X1, imgStep, blockA, blockSize.width, CurSize );
+                icvCopyBM_8u_C1R( imgB + (Y1 + offY) * imgStep + (X1 + offX), imgStep,
+                                  blockB, blockSize.width, CurSize );
             }
 
             if( !main_flag )
@@ -438,16 +436,16 @@ IPCVAPI_IMPL( CvStatus, icvCalcOpticalFlowBM_8u32fR, (uchar * imgA,
 
                     if( main_flag )
                     {
-                        icvCopy_8u_C1R( imgB + Y2 * imgStep + X2,
-                                        imgStep, blockB, CurSize.width, CurSize );
+                        icvCopyBM_8u_C1R( imgB + Y2 * imgStep + X2,
+                                          imgStep, blockB, CurSize.width, CurSize );
 
                         *((int64 *) (blockB + patch_ofs)) &= patch_mask;
                     }
                     else
                     {
                         memset( blockB, 0, bufferSize );
-                        icvCopy_8u_C1R( imgB + Y1 * imgStep + X1, imgStep,
-                                        blockB, blockSize.width, CurSize );
+                        icvCopyBM_8u_C1R( imgB + Y1 * imgStep + X1, imgStep,
+                                          blockB, blockSize.width, CurSize );
                     }
 
                     tmpDist = icvCmpBlocksL1_8u_C1( blockA, blockB, cmpSize );
@@ -534,8 +532,8 @@ IPCVAPI_IMPL( CvStatus, icvCalcOpticalFlowBM_8u32fR, (uchar * imgA,
         }
     }
 
-    icvFree( &ss );
-    icvFree( &blockA );
+    cvFree( (void**)&ss );
+    cvFree( (void**)&blockA );
     
     return CV_OK;
 }                               /*cvCalcOpticalFlowBM_8u */
@@ -594,7 +592,7 @@ cvCalcOpticalFlowBM( const void* srcarrA, const void* srcarrB,
         CV_ERROR( CV_BadStep, "two source or two destination images have different steps" );
 
     IPPI_CALL( icvCalcOpticalFlowBM_8u32fR( (uchar*)srcA->data.ptr, (uchar*)srcB->data.ptr,
-                                            srcA->step, icvGetMatSize( srcA ), blockSize,
+                                            srcA->step, cvGetMatSize( srcA ), blockSize,
                                             shiftSize, maxRange, usePrevious,
                                             velx->data.fl, vely->data.fl, velx->step ));
     __END__;
index 46b5f514521d248d9438357469e2f48604b42615..825565df6a6cd21c417335b8c0b34f9b49af461b 100644 (file)
@@ -53,19 +53,6 @@ typedef struct
 }
 icvDerProductEx;
 
-
-IPCVAPI( CvStatus , icvCalcOpticalFlowHS_8u32fR,( uchar*  imgA,
-                                                  uchar*  imgB,
-                                                  int     imgStep,
-                                                  CvSize imgSize,
-                                                  int     usePrevious,
-                                                  float*  velocityX,
-                                                  float*  velocityY,
-                                                  int     velStep,
-                                                  float   lambda,
-                                                  CvTermCriteria criteria ))
-
-
 /*F///////////////////////////////////////////////////////////////////////////////////////
 //    Name: icvCalcOpticalFlowHS_8u32fR (Horn & Schunck method )
 //    Purpose: calculate Optical flow for 2 images using Horn & Schunck algorithm
@@ -95,15 +82,17 @@ IPCVAPI( CvStatus , icvCalcOpticalFlowHS_8u32fR,( uchar*  imgA,
 //
 //
 //F*/
-IPCVAPI_IMPL( CvStatus, icvCalcOpticalFlowHS_8u32fR, (uchar * imgA,
-                                                      uchar * imgB,
-                                                      int imgStep,
-                                                      CvSize imgSize,
-                                                      int usePrevious,
-                                                      float *velocityX,
-                                                      float *velocityY,
-                                                      int velStep,
-                                                      float lambda, CvTermCriteria criteria) )
+static CvStatus CV_STDCALL
+icvCalcOpticalFlowHS_8u32fR( uchar*  imgA,
+                             uchar*  imgB,
+                             int     imgStep,
+                             CvSize imgSize,
+                             int     usePrevious,
+                             float*  velocityX,
+                             float*  velocityY,
+                             int     velStep,
+                             float   lambda,
+                             CvTermCriteria criteria )
 {
     /* Loops indexes */
     int i, j, k, address;
@@ -166,20 +155,20 @@ IPCVAPI_IMPL( CvStatus, icvCalcOpticalFlowHS_8u32fR, (uchar * imgA,
     /****************************************************************************************/
     for( k = 0; k < 2; k++ )
     {
-        MemX[k] = (float *) icvAlloc( (imgSize.height) * sizeof( float ));
+        MemX[k] = (float *) cvAlloc( (imgSize.height) * sizeof( float ));
 
         if( MemX[k] == NULL )
             NoMem = 1;
-        MemY[k] = (float *) icvAlloc( (imgSize.width) * sizeof( float ));
+        MemY[k] = (float *) cvAlloc( (imgSize.width) * sizeof( float ));
 
         if( MemY[k] == NULL )
             NoMem = 1;
 
-        VelBufX[k] = (float *) icvAlloc( imageWidth * sizeof( float ));
+        VelBufX[k] = (float *) cvAlloc( imageWidth * sizeof( float ));
 
         if( VelBufX[k] == NULL )
             NoMem = 1;
-        VelBufY[k] = (float *) icvAlloc( imageWidth * sizeof( float ));
+        VelBufY[k] = (float *) cvAlloc( imageWidth * sizeof( float ));
 
         if( VelBufY[k] == NULL )
             NoMem = 1;
@@ -187,7 +176,7 @@ IPCVAPI_IMPL( CvStatus, icvCalcOpticalFlowHS_8u32fR, (uchar * imgA,
 
     BufferSize = imageHeight * imageWidth;
 
-    II = (icvDerProductEx *) icvAlloc( BufferSize * sizeof( icvDerProductEx ));
+    II = (icvDerProductEx *) cvAlloc( BufferSize * sizeof( icvDerProductEx ));
     if( (II == NULL) )
         NoMem = 1;
 
@@ -196,19 +185,19 @@ IPCVAPI_IMPL( CvStatus, icvCalcOpticalFlowHS_8u32fR, (uchar * imgA,
         for( k = 0; k < 2; k++ )
         {
             if( MemX[k] )
-                icvFree( (void **) &MemX[k] );
+                cvFree( (void **) &MemX[k] );
 
             if( MemY[k] )
-                icvFree( (void **) &MemY[k] );
+                cvFree( (void **) &MemY[k] );
 
             if( VelBufX[k] )
-                icvFree( (void **) &VelBufX[k] );
+                cvFree( (void **) &VelBufX[k] );
 
             if( VelBufY[k] )
-                icvFree( (void **) &VelBufY[k] );
+                cvFree( (void **) &VelBufY[k] );
         }
         if( II )
-            icvFree( (void **) &II );
+            cvFree( (void **) &II );
         return CV_OUTOFMEM_ERR;
     }
 /****************************************************************************************\
@@ -467,7 +456,7 @@ IPCVAPI_IMPL( CvStatus, icvCalcOpticalFlowHS_8u32fR, (uchar * imgA,
         memcpy( &velocityY[imageWidth * (imageHeight - 1)],
                 VelBufY[(imageHeight - 1) & 1], imageWidth * sizeof( float ));
 
-        if( (criteria.type & CV_TERMCRIT_ITER) && (iter == criteria.maxIter) )
+        if( (criteria.type & CV_TERMCRIT_ITER) && (iter == criteria.max_iter) )
             Stop = 1;
         if( (criteria.type & CV_TERMCRIT_EPS) && (Eps < criteria.epsilon) )
             Stop = 1;
@@ -475,12 +464,12 @@ IPCVAPI_IMPL( CvStatus, icvCalcOpticalFlowHS_8u32fR, (uchar * imgA,
     /* Free memory */
     for( k = 0; k < 2; k++ )
     {
-        icvFree( (void **) &MemX[k] );
-        icvFree( (void **) &MemY[k] );
-        icvFree( (void **) &VelBufX[k] );
-        icvFree( (void **) &VelBufY[k] );
+        cvFree( (void **) &MemX[k] );
+        cvFree( (void **) &MemY[k] );
+        cvFree( (void **) &VelBufX[k] );
+        cvFree( (void **) &VelBufY[k] );
     }
-    icvFree( (void **) &II );
+    cvFree( (void **) &II );
 
     return CV_OK;
 } /*icvCalcOpticalFlowHS_8u32fR*/
@@ -537,7 +526,7 @@ cvCalcOpticalFlowHS( const void* srcarrA, const void* srcarrB, int usePrevious,
         CV_ERROR( CV_BadStep, "source and destination images have different step" );
 
     IPPI_CALL( icvCalcOpticalFlowHS_8u32fR( (uchar*)srcA->data.ptr, (uchar*)srcB->data.ptr,
-                                            srcA->step, icvGetMatSize( srcA ), usePrevious,
+                                            srcA->step, cvGetMatSize( srcA ), usePrevious,
                                             velx->data.fl, vely->data.fl,
                                             velx->step, (float)lambda, criteria ));
     __END__;
index 315eae6804f10e1db6dd0162e33edb995fb438e7..497d772f0a20cd70ea5a8804bfb3406077c7cd2b 100644 (file)
@@ -51,17 +51,6 @@ typedef struct
 icvDerProduct;
 
 
-IPCVAPI( CvStatus , icvCalcOpticalFlowLK_8u32fR,( uchar*   imgA,
-                                                    uchar*   imgB,
-                                                    int      imgStep,
-                                                    CvSize imgSize,
-                                                    CvSize winSize,
-                                                    float*   velocityX,
-                                                    float*   velocityY,
-                                                    int      velStep  ))
-
-
-
 #define CONV( A, B, C)  ((float)( A +  (B<<1)  + C ))
 /*F///////////////////////////////////////////////////////////////////////////////////////
 //    Name: icvCalcOpticalFlowLK_8u32fR ( Lucas & Kanade method )
@@ -90,13 +79,14 @@ IPCVAPI( CvStatus , icvCalcOpticalFlowLK_8u32fR,( uchar*   imgA,
 //
 //
 //F*/
-IPCVAPI_IMPL( CvStatus, icvCalcOpticalFlowLK_8u32fR, (uchar * imgA,
-                                                      uchar * imgB,
-                                                      int imgStep,
-                                                      CvSize imgSize,
-                                                      CvSize winSize,
-                                                      float *velocityX,
-                                                      float *velocityY, int velStep) )
+static CvStatus CV_STDCALL
+icvCalcOpticalFlowLK_8u32fR( uchar * imgA,
+                             uchar * imgB,
+                             int imgStep,
+                             CvSize imgSize,
+                             CvSize winSize,
+                             float *velocityX,
+                             float *velocityY, int velStep )
 {
     /* Loops indexes */
     int i, j, k;
@@ -212,11 +202,11 @@ IPCVAPI_IMPL( CvStatus, icvCalcOpticalFlowLK_8u32fR, (uchar * imgA,
     /****************************************************************************************/
     for( k = 0; k < 2; k++ )
     {
-        MemX[k] = (float *) icvAlloc( (imgSize.height) * sizeof( float ));
+        MemX[k] = (float *) cvAlloc( (imgSize.height) * sizeof( float ));
 
         if( MemX[k] == NULL )
             NoMem = 1;
-        MemY[k] = (float *) icvAlloc( (imgSize.width) * sizeof( float ));
+        MemY[k] = (float *) cvAlloc( (imgSize.width) * sizeof( float ));
 
         if( MemY[k] == NULL )
             NoMem = 1;
@@ -224,8 +214,8 @@ IPCVAPI_IMPL( CvStatus, icvCalcOpticalFlowLK_8u32fR, (uchar * imgA,
 
     BufferSize = BufferHeight * BufferWidth;
 
-    II = (icvDerProduct *) icvAlloc( BufferSize * sizeof( icvDerProduct ));
-    WII = (icvDerProduct *) icvAlloc( BufferSize * sizeof( icvDerProduct ));
+    II = (icvDerProduct *) cvAlloc( BufferSize * sizeof( icvDerProduct ));
+    WII = (icvDerProduct *) cvAlloc( BufferSize * sizeof( icvDerProduct ));
 
 
     if( (II == NULL) || (WII == NULL) )
@@ -236,15 +226,15 @@ IPCVAPI_IMPL( CvStatus, icvCalcOpticalFlowLK_8u32fR, (uchar * imgA,
         for( k = 0; k < 2; k++ )
         {
             if( MemX[k] )
-                icvFree( (void **) &MemX[k] );
+                cvFree( (void **) &MemX[k] );
 
             if( MemY[k] )
-                icvFree( (void **) &MemY[k] );
+                cvFree( (void **) &MemY[k] );
         }
         if( II )
-            icvFree( (void **) &II );
+            cvFree( (void **) &II );
         if( WII )
-            icvFree( (void **) &WII );
+            cvFree( (void **) &WII );
 
         return CV_OUTOFMEM_ERR;
     }
@@ -554,11 +544,11 @@ IPCVAPI_IMPL( CvStatus, icvCalcOpticalFlowLK_8u32fR, (uchar * imgA,
     /* Free memory */
     for( k = 0; k < 2; k++ )
     {
-        icvFree( (void **) &MemX[k] );
-        icvFree( (void **) &MemY[k] );
+        cvFree( (void **) &MemX[k] );
+        cvFree( (void **) &MemY[k] );
     }
-    icvFree( (void **) &II );
-    icvFree( (void **) &WII );
+    cvFree( (void **) &II );
+    cvFree( (void **) &WII );
 
     return CV_OK;
 } /*icvCalcOpticalFlowLK_8u32fR*/
@@ -614,7 +604,7 @@ cvCalcOpticalFlowLK( const void* srcarrA, const void* srcarrB, CvSize winSize,
         CV_ERROR( CV_BadStep, "source and destination images have different step" );
 
     IPPI_CALL( icvCalcOpticalFlowLK_8u32fR( (uchar*)srcA->data.ptr, (uchar*)srcB->data.ptr,
-                                            srcA->step, icvGetMatSize( srcA ), winSize,
+                                            srcA->step, cvGetMatSize( srcA ), winSize,
                                             velx->data.fl, vely->data.fl, velx->step ));
 
     __END__;
index 2304712e1a1a190b4dae2fa3b472a28ec7015862..ed1d1dbef552266cf16bd6adb1df170c166ccd6a 100644 (file)
@@ -39,8 +39,6 @@
 //
 //M*/
 #include "_cv.h"
-#include "_cvdatastructs.h"
-#include <float.h>
 
 #define _CV_ACOS_TABLE_SIZE  513
 
@@ -148,11 +146,11 @@ static const float icv_acos_table[_CV_ACOS_TABLE_SIZE] = {
 //      CV_OK or error code
 //    Notes:
 //F*/
-CvStatus
+static CvStatus
 icvCalcPGH( const CvSeq * contour, float *pgh, int angle_dim, int dist_dim )
 {
     char local_buffer[(1 << 14) + 32];
-    float *local_buffer_ptr = (float *)icvAlignPtr(local_buffer,32);
+    float *local_buffer_ptr = (float *)cvAlignPtr(local_buffer,32);
     float *buffer = local_buffer_ptr;
     double angle_scale = (angle_dim - 0.51) / icv_acos_table[0];
     double dist_scale = DBL_EPSILON;
@@ -180,7 +178,7 @@ icvCalcPGH( const CvSeq * contour, float *pgh, int angle_dim, int dist_dim )
 
     if( buffer_size > (int)sizeof(local_buffer) - 32 )
     {
-        buffer = (float *) icvAlloc( buffer_size );
+        buffer = (float *) cvAlloc( buffer_size );
         if( !buffer )
             return CV_OUTOFMEM_ERR;
     }
@@ -201,7 +199,7 @@ icvCalcPGH( const CvSeq * contour, float *pgh, int angle_dim, int dist_dim )
         buffer[i] = (float) (dx * dx + dy * dy);
     }
 
-    icvbInvSqrt_32f( buffer, buffer, i );
+    cvbInvSqrt( buffer, buffer, i );
 
     /* 
        do 2 passes. 
@@ -328,7 +326,7 @@ icvCalcPGH( const CvSeq * contour, float *pgh, int angle_dim, int dist_dim )
     }
 
     if( buffer != local_buffer_ptr )
-        icvFree( &buffer );
+        cvFree( (void**)&buffer );
 
     return CV_OK;
 }
index 94da776e4db7617f757457bb8d43c14b6fa30255..d1f8da74dada4f32bcf927a8fce20640ec94e164 100644 (file)
@@ -49,7 +49,7 @@ struct CvPOSITObject
     float* img_vecs;
 };
 
-void icvPseudoInverse3D( float *a, float *b, int n, int method );
+static void icvPseudoInverse3D( float *a, float *b, int n, int method );
 
 static  CvStatus  icvCreatePOSITObject( CvPoint3D32f *points,
                                         int numPoints,
@@ -78,8 +78,8 @@ static  CvStatus  icvCreatePOSITObject( CvPoint3D32f *points,
         return CV_NULLPTR_ERR;
 
     /* memory allocation */
-    pObject = (CvPOSITObject *) icvAlloc( sizeof( CvPOSITObject ) +
-                                          inv_matr_size + obj_vec_size + img_vec_size );
+    pObject = (CvPOSITObject *) cvAlloc( sizeof( CvPOSITObject ) +
+                                         inv_matr_size + obj_vec_size + img_vec_size );
 
     if( !pObject )
         return CV_OUTOFMEM_ERR;
@@ -140,7 +140,7 @@ static  CvStatus  icvPOSIT( CvPOSITObject *pObject, CvPoint2D32f *imagePoints,
         return CV_BADFLAG_ERR;
     if( (criteria.type & CV_TERMCRIT_EPS) && criteria.epsilon < 0 )
         return CV_BADFACTOR_ERR;
-    if( (criteria.type & CV_TERMCRIT_ITER) && criteria.maxIter <= 0 )
+    if( (criteria.type & CV_TERMCRIT_ITER) && criteria.max_iter <= 0 )
         return CV_BADFACTOR_ERR;
 
     while( !converged )
@@ -231,7 +231,7 @@ static  CvStatus  icvPOSIT( CvPOSITObject *pObject, CvPoint2D32f *imagePoints,
 
         count++;
         converged = ((criteria.type & CV_TERMCRIT_EPS) && (diff < criteria.epsilon));
-        converged |= ((criteria.type & CV_TERMCRIT_ITER) && (count == criteria.maxIter));
+        converged |= ((criteria.type & CV_TERMCRIT_ITER) && (count == criteria.max_iter));
     }
     invScale = 1 / scale;
     translation[0] = imagePoints[0].x * invScale;
@@ -244,7 +244,7 @@ static  CvStatus  icvPOSIT( CvPOSITObject *pObject, CvPoint2D32f *imagePoints,
 
 static  CvStatus  icvReleasePOSITObject( CvPOSITObject ** ppObject )
 {
-    icvFree( ppObject );
+    cvFree( (void**)ppObject );
     return CV_NO_ERR;
 }
 
index 35119d5727913c61f0a7632fdf5c26a6192faf86..10935fce5747f3a56202347dd767fce86fb24dda 100644 (file)
@@ -215,7 +215,6 @@ icvPyrDownG5x5_##flavor( const type* src, int srcstep, type* dst, int dststep,
 
 
 ICV_DEF_PYR_DOWN_FUNC( 8u, uchar, int, PD_SCALE_INT )
-ICV_DEF_PYR_DOWN_FUNC( 8s, char, int, PD_SCALE_INT )
 ICV_DEF_PYR_DOWN_FUNC( 32f, float, float, PD_SCALE_FLT )
 ICV_DEF_PYR_DOWN_FUNC( 64f, double, double, PD_SCALE_FLT )
 
@@ -425,7 +424,6 @@ icvPyrUpG5x5_##flavor( const type* src, int srcstep, type* dst, int dststep,
 
 
 ICV_DEF_PYR_UP_FUNC( 8u, uchar, int, PU_SCALE_INT )
-ICV_DEF_PYR_UP_FUNC( 8s, char, int, PU_SCALE_INT )
 ICV_DEF_PYR_UP_FUNC( 32f, float, float, PU_SCALE_FLT )
 ICV_DEF_PYR_UP_FUNC( 64f, double, double, PU_SCALE_FLT )
 
@@ -438,16 +436,15 @@ ICV_DEF_PYR_UP_FUNC( 64f, double, double, PU_SCALE_FLT )
 #define ICV_DEF_PYR_FUNC( name, flavor, cn, arrtype )               \
 IPCVAPI_IMPL( CvStatus, name##_Gauss5x5_##flavor##_C##cn##R,        \
 ( const arrtype* pSrc, int srcStep, arrtype* pDst, int dstStep,     \
-  CvSize roiSize, void* pBuffer ))                                  \
+  CvSize roiSize, void* pBuffer ),                                  \
+  (pSrc, srcStep, pDst, dstStep, roiSize, pBuffer ) )               \
 {                                                                   \
     return name##G5x5_##flavor( pSrc, srcStep, pDst, dstStep,       \
-                                    roiSize, pBuffer, cn );         \
+                                roiSize, pBuffer, cn );             \
 }
 
 ICV_DEF_PYR_FUNC( icvPyrUp, 8u, 1, uchar )
 ICV_DEF_PYR_FUNC( icvPyrUp, 8u, 3, uchar )
-ICV_DEF_PYR_FUNC( icvPyrUp, 8s, 1, char )
-ICV_DEF_PYR_FUNC( icvPyrUp, 8s, 3, char )
 ICV_DEF_PYR_FUNC( icvPyrUp, 32f, 1, float )
 ICV_DEF_PYR_FUNC( icvPyrUp, 32f, 3, float )
 ICV_DEF_PYR_FUNC( icvPyrUp, 64f, 1, double )
@@ -455,8 +452,6 @@ ICV_DEF_PYR_FUNC( icvPyrUp, 64f, 3, double )
 
 ICV_DEF_PYR_FUNC( icvPyrDown, 8u, 1, uchar )
 ICV_DEF_PYR_FUNC( icvPyrDown, 8u, 3, uchar )
-ICV_DEF_PYR_FUNC( icvPyrDown, 8s, 1, char )
-ICV_DEF_PYR_FUNC( icvPyrDown, 8s, 3, char )
 ICV_DEF_PYR_FUNC( icvPyrDown, 32f, 1, float )
 ICV_DEF_PYR_FUNC( icvPyrDown, 32f, 3, float )
 ICV_DEF_PYR_FUNC( icvPyrDown, 64f, 1, double )
@@ -464,7 +459,8 @@ ICV_DEF_PYR_FUNC( icvPyrDown, 64f, 3, double )
 
 
 IPCVAPI_IMPL( CvStatus, icvPyrUpGetBufSize_Gauss5x5, (int roiWidth, CvDataType dataType,
-                                                      int channels, int *bufSize) )
+                                                      int channels, int *bufSize),
+                                                      (roiWidth, dataType, channels, bufSize) )
 {
     int bufStep;
 
@@ -500,7 +496,8 @@ IPCVAPI_IMPL( CvStatus, icvPyrUpGetBufSize_Gauss5x5, (int roiWidth, CvDataType d
 
 
 IPCVAPI_IMPL( CvStatus, icvPyrDownGetBufSize_Gauss5x5, ( int roiWidth, CvDataType dataType,
-                                                         int channels, int *bufSize) )
+                                                         int channels, int *bufSize),
+                                                         (roiWidth, dataType, channels, bufSize) )
 {
     int bufStep;
 
@@ -534,319 +531,420 @@ IPCVAPI_IMPL( CvStatus, icvPyrDownGetBufSize_Gauss5x5, ( int roiWidth, CvDataTyp
     return CV_OK;
 }
 
-
-
 /****************************************************************************************\
                         Downsampled image border completion
 \****************************************************************************************/
 
-#define ICV_DEF_PYR_BORDER_FUNC( flavor, arrtype, worktype, _pd_scale_ )                \
-IPCVAPI_IMPL( CvStatus,                                                                 \
-icvPyrDownBorder_##flavor##_CnR, ( const arrtype *src, int src_step, CvSize src_size,   \
-                            arrtype *dst, int dst_step, CvSize dst_size, int channels ))\
-{                                                                                       \
-    worktype local_buffer[1 << 10];                                                     \
-    worktype *buf = local_buffer, *buf0;                                                \
-    const arrtype* src2;                                                                \
-    arrtype* dst2;                                                                      \
-    int buf_size;                                                                       \
-    int i, j;                                                                           \
-    int W = src_size.width, H = src_size.height;                                        \
-    int Wd = dst_size.width, Hd = dst_size.height;                                      \
-    int Wd_, Hd_;                                                                       \
-    int bufW;                                                                           \
-    int cols, rows; /* columns and rows to modify */                                    \
-                                                                                        \
-    buf_size = MAX(src_size.width,src_size.height) * sizeof(buf[0]) * 2 * channels;     \
-    if( buf_size > (int)sizeof(local_buffer))                                           \
-    {                                                                                   \
-        buf = (worktype*) icvAlloc( buf_size );                                         \
-        if( !buf )                                                                      \
-            return CV_OUTOFMEM_ERR;                                                     \
-    }                                                                                   \
-                                                                                        \
-    buf0 = buf;                                                                         \
-                                                                                        \
-    src_step /= sizeof(src[0]);                                                         \
-    dst_step /= sizeof(dst[0]);                                                         \
-                                                                                        \
-    cols = (W & 1) + (Wd*2 > W);                                                        \
-    rows = (H & 1) + (Hd*2 > H);                                                        \
-                                                                                        \
-    src2 = src + (H-1)*src_step;                                                        \
-    dst2 = dst + (Hd - rows)*dst_step;                                                  \
-    src += (W - 1)*channels;                                                            \
-    dst += (Wd - cols)*channels;                                                        \
-                                                                                        \
-    /* part of row(column) from 1 to Wd_(Hd_) is processed using PD_FILTER macro */     \
-    Wd_ = Wd - 1 + (cols == 1 && (W & 1) != 0);                                         \
-    Hd_ = Hd - 1 + (rows == 1 && (H & 1) != 0);                                         \
-                                                                                        \
-    bufW = channels * cols;                                                             \
-                                                                                        \
-    /******************* STAGE 1. ******************/                                   \
-                                                                                        \
-    /* do horizontal convolution of the 1-2 right columns and write results to buffer */\
-    if( cols > 0 )                                                                      \
-    {                                                                                   \
-        switch( W )                                                                     \
-        {                                                                               \
-        case 1:                                                                         \
-        case 2:                                                                         \
-            assert( Wd == 1 );                                                          \
-            for( i = 0; i < H; i++, src += src_step, buf += channels )                  \
-                for( j = 0; j < channels; j++ )                                         \
-                    buf[j] = PD_SINGULAR( src[j-channels*(W-1)], src[j] );              \
-            break;                                                                      \
-        case 3:                                                                         \
-            if( Wd == 1 )                                                               \
-                for( i = 0; i < H; i++, src += src_step, buf += channels )              \
-                    for( j = 0; j < channels; j++ )                                     \
-                        buf[j] = PD_LT( src[j-channels*2], src[j-channels], src[j] );   \
-            else                                                                        \
-                for( i = 0; i < H; i++, src += src_step, buf += channels*2 )            \
-                    for( j = 0; j < channels; j++ )                                     \
-                    {                                                                   \
-                        buf[j] = PD_LT( src[j-channels*2], src[j-channels], src[j] );   \
-                        buf[j+channels]=PD_LT(src[j],src[j-channels],src[j-channels*2]);\
-                    }                                                                   \
-            break;                                                                      \
-        default:                                                                        \
-            if( !(W & 1) )                                                              \
-                for( i = 0; i < H; i++, src += src_step, buf += channels )              \
-                    for( j = 0; j < channels; j++ )                                     \
-                        buf[j] = PD_LT( src[j], src[j-channels], src[j-channels*2] );   \
-            else if( cols == 1 )                                                        \
-                for( i = 0; i < H; i++, src += src_step, buf += channels )              \
-                    for( j = 0; j < channels; j++ )                                     \
-                        buf[j] = PD_FILTER( src[j-channels*4], src[j-channels*3],       \
-                                            src[j-channels*2], src[j-channels], src[j]);\
-            else                                                                        \
-                for( i = 0; i < H; i++, src += src_step, buf += channels*2 )            \
-                    for( j = 0; j < channels; j++ )                                     \
-                    {                                                                   \
-                        buf[j] = PD_FILTER( src[j-channels*4], src[j-channels*3],       \
-                                            src[j-channels*2], src[j-channels], src[j]);\
-                        buf[j+channels] = PD_LT( src[j], src[j-channels], src[j-channels*2] );  \
-                    }                                                                   \
-        }                                                                               \
-                                                                                        \
-        buf = buf0;                                                                     \
-    }                                                                                   \
-                                                                                        \
-    src = src2;                                                                         \
-                                                                                        \
-    /******************* STAGE 2. ******************/                                   \
-                                                                                        \
-    /* do vertical convolution of the pre-processed right columns, */                   \
-    /* stored in buffer, and write results to the destination */                        \
-    /* do vertical convolution of the 1-2 bottom rows */                                \
-    /* and write results to the buffer */                                               \
-    switch( H )                                                                         \
-    {                                                                                   \
-    case 1:                                                                             \
-    case 2:                                                                             \
-        if( cols > 0 )                                                                  \
-        {                                                                               \
-            assert( Hd == 1 );                                                          \
-            for( j = 0; j < bufW; j++ )                                                 \
-                dst[j] = (arrtype)_pd_scale_( PD_SINGULAR( buf[j], buf[j+(H-1)*bufW] ));\
-        }                                                                               \
-                                                                                        \
-        if( rows > 0 )                                                                  \
-        {                                                                               \
-            for( j = 0; j < W*channels; j++ )                                           \
-                buf[j] = PD_SINGULAR( src[j-src_step], src[j] );                        \
-        }                                                                               \
-        break;                                                                          \
-                                                                                        \
-    case 3:                                                                             \
-                                                                                        \
-        if( cols > 0 )                                                                  \
-        {                                                                               \
-            for( j = 0; j < bufW; j++ )                                                 \
-                dst[j]= (arrtype)_pd_scale_(PD_LT( buf[j], buf[j+bufW], buf[j+bufW*2]));\
-            if( Hd == 2 )                                                               \
-            {                                                                           \
-                dst += dst_step;                                                        \
-                for( j = 0; j < bufW; j++ )                                             \
-                    dst[j] = (arrtype)_pd_scale_(PD_LT( buf[j+bufW*2], buf[j+bufW], buf[j]));\
-            }                                                                           \
-        }                                                                               \
-                                                                                        \
-        if( Hd == 1 )                                                                   \
-            for( j = 0; j < W*channels; j++ )                                           \
-                buf[j] = PD_LT( src[j-src_step*2], src[j - src_step], src[j] );         \
-        else                                                                            \
-            for( j = 0; j < W*channels; j++ )                                           \
-            {                                                                           \
-                buf[j] = PD_LT( src[j-src_step*2], src[j - src_step], src[j] );         \
-                buf[j+W*channels] = PD_LT( src[j],src[j-src_step],src[j-src_step*2] );  \
-            }                                                                           \
-        break;                                                                          \
-                                                                                        \
-    default:                                                                            \
-                                                                                        \
-        if( cols > 0 )                                                                  \
-        {                                                                               \
-            /* top of the right border */                                               \
-            for( j = 0; j < bufW; j++ )                                                 \
-                dst[j]=(arrtype)_pd_scale_( PD_LT( buf[j], buf[j+bufW], buf[j+bufW*2]));\
-                                                                                        \
-            /* middle part of the right border */                                       \
-            buf += bufW*2;                                                              \
-            dst += dst_step;                                                            \
-            for( i = 1; i < Hd_; i++, dst += dst_step, buf += bufW*2 )                  \
-            {                                                                           \
-                for( j = 0; j < bufW; j++ )                                             \
-                    dst[j] = (arrtype)_pd_scale_( PD_FILTER( buf[j - bufW*2], buf[j - bufW],\
-                                                  buf[j], buf[j + bufW], buf[j + bufW*2] ));\
-            }                                                                           \
-                                                                                        \
-            /* bottom of the right border */                                            \
-            if( !(H & 1) )                                                              \
-                for( j = 0; j < bufW; j++ )                                             \
-                    dst[j] = (arrtype)_pd_scale_( PD_RB( buf[j-bufW*2], buf[j-bufW],    \
-                                                         buf[j], buf[j+bufW] ));        \
-            else if( rows > 1 )                                                         \
-                for( j = 0; j < bufW; j++ )                                             \
-                    dst[j]=(arrtype)_pd_scale_(PD_LT( buf[j-bufW*2], buf[j-bufW], buf[j]));\
-                                                                                        \
-            buf = buf0;                                                                 \
-        }                                                                               \
-                                                                                        \
-        if( rows > 0 )                                                                  \
-        {                                                                               \
-            if( !(H & 1) )                                                              \
-                for( j = 0; j < W*channels; j++ )                                       \
-                    buf[j] = PD_LT( src[j], src[j-src_step], src[j-src_step*2] );       \
-            else if( cols == 1 )                                                        \
-                for( j = 0; j < W*channels; j++ )                                       \
-                    buf[j] = PD_FILTER( src[j-src_step*4], src[j-src_step*3],           \
-                                        src[j-src_step*2], src[j-src_step], src[j] );   \
-            else                                                                        \
-                for( j = 0; j < W*channels; j++ )                                       \
-                {                                                                       \
-                    buf[j] = PD_FILTER( src[j-src_step*4], src[j-src_step*3],           \
-                                        src[j-src_step*2], src[j-src_step], src[j] );   \
-                    buf[j+W*channels] = PD_LT( src[j], src[j-src_step], src[j-src_step*2] );\
-                }                                                                       \
-        }                                                                               \
-    }                                                                                   \
-                                                                                        \
-                                                                                        \
-    /******************* STAGE 3. ******************/                                   \
-                                                                                        \
-    /* do horizontal convolution of the pre-processed bottom rows,*/                    \
-    /* stored in buffer, and write results to the destination */                        \
-    if( rows > 0 )                                                                      \
-    {                                                                                   \
-        dst = dst2;                                                                     \
-                                                                                        \
-        switch( W )                                                                     \
-        {                                                                               \
-        case 1:                                                                         \
-        case 2:                                                                         \
-            assert( Wd == 1 );                                                          \
-            for( ; rows--; dst += dst_step, buf += W*channels )                         \
-                for( j = 0; j < channels; j++ )                                         \
-                    dst[j] = (arrtype)_pd_scale_( PD_SINGULAR( buf[j],                  \
-                                                  buf[j+(W-1)*channels] ));             \
-            break;                                                                      \
-                                                                                        \
-        case 3:                                                                         \
-            if( Wd == 1 )                                                               \
-                for( ; rows--; dst += dst_step, buf += W*channels )                     \
-                    for( j = 0; j < channels; j++ )                                     \
-                        dst[j] = (arrtype)_pd_scale_( PD_LT(                            \
-                            buf[j], buf[j+channels], buf[j+channels*2] ));              \
-            else                                                                        \
-                for( ; rows--; dst += dst_step, buf += W*channels )                     \
-                    for( j = 0; j < channels; j++ )                                     \
-                    {                                                                   \
-                        dst[j] = (arrtype)_pd_scale_( PD_LT(                            \
-                            buf[j], buf[j+channels], buf[j+channels*2] ));              \
-                        dst[j + channels] = (arrtype)_pd_scale_( PD_LT(                 \
-                            buf[j+channels*2], buf[j+channels], buf[j] ));              \
-                    }                                                                   \
-            break;                                                                      \
-                                                                                        \
-        default:                                                                        \
-                                                                                        \
-            for( ; rows--; dst += dst_step, buf += W*channels )                         \
-            {                                                                           \
-                /* left part of the bottom row */                                       \
-                for( j = 0; j < channels; j++ )                                         \
-                    dst[j] = (arrtype)_pd_scale_( PD_LT( buf[j], buf[j+channels],       \
-                                                         buf[j+channels*2] ));          \
-                                                                                        \
-                /* middle part of the bottom row */                                     \
-                for( i = channels; i < Wd_*channels; i += channels )                    \
-                {                                                                       \
-                    for( j = 0; j < channels; j++ )                                     \
-                        dst[i+j] = (arrtype)_pd_scale_( PD_FILTER(                      \
-                                 buf[i*2+j-channels*2], buf[i*2+j-channels], buf[i*2+j],\
-                                 buf[i*2+j+channels], buf[i*2+j+channels*2] ));         \
-                }                                                                       \
-                                                                                        \
-                /* bottom of the right border */                                        \
-                if( !(W & 1) )                                                          \
-                    for( j = 0; j < channels; j++ )                                     \
-                        dst[i+j] = (arrtype)_pd_scale_( PD_RB( buf[i*2+j-channels*2],   \
-                                buf[i*2+j-channels], buf[i*2+j], buf[i*2+j+channels] ));\
-                else if( cols > 1 )                                                     \
-                    for( j = 0; j < channels; j++ )                                     \
-                        dst[i+j] = (arrtype)_pd_scale_( PD_LT( buf[i*2+j-channels*2],   \
-                                                    buf[i*2+j-channels], buf[i*2+j] )); \
-            }                                                                           \
-        }                                                                               \
-    }                                                                                   \
-                                                                                        \
-    if( buf0 != local_buffer )                                                          \
-        icvFree( &buf0 );                                                               \
-                                                                                        \
-    return CV_OK;                                                                       \
+#define ICV_DEF_PYR_BORDER_FUNC( flavor, arrtype, worktype, _pd_scale_ )                            \
+CvStatus CV_STDCALL                                                                                 \
+icvPyrDownBorder_##flavor##_CnR( const arrtype *src, int src_step, CvSize src_size,                 \
+                          arrtype *dst, int dst_step, CvSize dst_size, int channels )               \
+{                                                                                                   \
+    int local_alloc = 0;                                                                            \
+    worktype *buf = 0, *buf0 = 0;                                                                   \
+    const arrtype* src2;                                                                            \
+    arrtype* dst2;                                                                                  \
+    int buf_size;                                                                                   \
+    int i, j;                                                                                       \
+    int W = src_size.width, H = src_size.height;                                                    \
+    int Wd = dst_size.width, Hd = dst_size.height;                                                  \
+    int Wd_, Hd_;                                                                                   \
+    int Wn = W*channels;                                                                            \
+    int bufW;                                                                                       \
+    int cols, rows; /* columns and rows to modify */                                                \
+                                                                                                    \
+    assert( channels == 1 || channels == 3 );                                                       \
+                                                                                                    \
+    buf_size = MAX(src_size.width,src_size.height) * sizeof(buf[0]) * 2 * channels;                 \
+    if( buf_size > (1 << 14) )                                                                      \
+    {                                                                                               \
+        buf = (worktype*)cvAlloc( buf_size );                                                       \
+        if( !buf )                                                                                  \
+            return CV_OUTOFMEM_ERR;                                                                 \
+    }                                                                                               \
+    else                                                                                            \
+    {                                                                                               \
+        buf = (worktype*)cvAlignPtr(alloca( buf_size+8 ), 8);                                       \
+        local_alloc = 1;                                                                            \
+    }                                                                                               \
+                                                                                                    \
+    buf0 = buf;                                                                                     \
+                                                                                                    \
+    src_step /= sizeof(src[0]);                                                                     \
+    dst_step /= sizeof(dst[0]);                                                                     \
+                                                                                                    \
+    cols = (W & 1) + (Wd*2 > W);                                                                    \
+    rows = (H & 1) + (Hd*2 > H);                                                                    \
+                                                                                                    \
+    src2 = src + (H-1)*src_step;                                                                    \
+    dst2 = dst + (Hd - rows)*dst_step;                                                              \
+    src += (W - 1)*channels;                                                                        \
+    dst += (Wd - cols)*channels;                                                                    \
+                                                                                                    \
+    /* part of row(column) from 1 to Wd_(Hd_) is processed using PD_FILTER macro */                 \
+    Wd_ = Wd - 1 + (cols == 1 && (W & 1) != 0);                                                     \
+    Hd_ = Hd - 1 + (rows == 1 && (H & 1) != 0);                                                     \
+                                                                                                    \
+    bufW = channels * cols;                                                                         \
+                                                                                                    \
+    /******************* STAGE 1. ******************/                                               \
+                                                                                                    \
+    /* do horizontal convolution of the 1-2 right columns and write results to buffer */            \
+    if( cols > 0 )                                                                                  \
+    {                                                                                               \
+        if( W <= 2 )                                                                                \
+        {                                                                                           \
+            assert( Wd == 1 );                                                                      \
+            for( i = 0; i < H; i++, src += src_step, buf += channels )                              \
+            {                                                                                       \
+                if( channels == 1 )                                                                 \
+                    buf[0] = PD_SINGULAR( src[1-Wn], src[0] );                                      \
+                else                                                                                \
+                {                                                                                   \
+                    buf[0] = PD_SINGULAR( src[3-Wn], src[0] );                                      \
+                    buf[1] = PD_SINGULAR( src[4-Wn], src[1] );                                      \
+                    buf[2] = PD_SINGULAR( src[5-Wn], src[2] );                                      \
+                }                                                                                   \
+            }                                                                                       \
+        }                                                                                           \
+        else if( W == 3 && Wd == 1 || W > 3 && !(Wd & 1) )                                          \
+        {                                                                                           \
+            for( i = 0; i < H; i++, src += src_step, buf += channels )                              \
+            {                                                                                       \
+                if( channels == 1 )                                                                 \
+                    buf[0] = PD_LT( src[-2], src[-1], src[0] );                                     \
+                else                                                                                \
+                {                                                                                   \
+                    buf[0] = PD_LT( src[-6], src[-3], src[0] );                                     \
+                    buf[1] = PD_LT( src[-5], src[-2], src[1] );                                     \
+                    buf[2] = PD_LT( src[-4], src[-1], src[2] );                                     \
+                }                                                                                   \
+            }                                                                                       \
+        }                                                                                           \
+        else if( W == 3 )                                                                           \
+        {                                                                                           \
+            for( i = 0; i < H; i++, src += src_step, buf += channels*2 )                            \
+            {                                                                                       \
+                if( channels == 1 )                                                                 \
+                {                                                                                   \
+                    buf[0] = PD_LT( src[-2], src[-1], src[0] );                                     \
+                    buf[1] = PD_LT( src[0], src[-1], src[-2] );                                     \
+                }                                                                                   \
+                else                                                                                \
+                {                                                                                   \
+                    buf[0] = PD_LT( src[-6], src[-3], src[0] );                                     \
+                    buf[1] = PD_LT( src[-5], src[-2], src[1] );                                     \
+                    buf[2] = PD_LT( src[-4], src[-1], src[2] );                                     \
+                    buf[3] = PD_LT( src[0], src[-3], src[-6] );                                     \
+                    buf[4] = PD_LT( src[1], src[-2], src[-5] );                                     \
+                    buf[5] = PD_LT( src[2], src[-1], src[-4] );                                     \
+                }                                                                                   \
+            }                                                                                       \
+        }                                                                                           \
+        else if( cols == 1 )                                                                        \
+        {                                                                                           \
+            for( i = 0; i < H; i++, src += src_step, buf += channels )                              \
+            {                                                                                       \
+                if( channels == 1 )                                                                 \
+                    buf[0] = PD_FILTER( src[-4], src[-3], src[-2], src[-1], src[0]);                \
+                else                                                                                \
+                {                                                                                   \
+                    buf[0] = PD_FILTER( src[-12], src[-9], src[-6], src[-3], src[0]);               \
+                    buf[1] = PD_FILTER( src[-11], src[-8], src[-5], src[-2], src[1]);               \
+                    buf[2] = PD_FILTER( src[-10], src[-7], src[-4], src[-1], src[2]);               \
+                }                                                                                   \
+            }                                                                                       \
+        }                                                                                           \
+        else                                                                                        \
+        {                                                                                           \
+            for( i = 0; i < H; i++, src += src_step, buf += channels*2 )                            \
+            {                                                                                       \
+                if( channels == 1 )                                                                 \
+                {                                                                                   \
+                    buf[0] = PD_FILTER( src[-4], src[-3], src[-2], src[-1], src[0] );               \
+                    buf[1] = PD_LT( src[0], src[-1], src[-2] );                                     \
+                }                                                                                   \
+                else                                                                                \
+                {                                                                                   \
+                    buf[0] = PD_FILTER( src[-12], src[-9], src[-6], src[-3], src[0] );              \
+                    buf[1] = PD_FILTER( src[-11], src[-8], src[-5], src[-2], src[1] );              \
+                    buf[2] = PD_FILTER( src[-10], src[-7], src[-4], src[-1], src[2] );              \
+                    buf[3] = PD_LT( src[0], src[-3], src[-6] );                                     \
+                    buf[4] = PD_LT( src[1], src[-2], src[-5] );                                     \
+                    buf[5] = PD_LT( src[2], src[-1], src[-4] );                                     \
+                }                                                                                   \
+            }                                                                                       \
+        }                                                                                           \
+        buf = buf0;                                                                                 \
+    }                                                                                               \
+                                                                                                    \
+    src = src2;                                                                                     \
+                                                                                                    \
+    /******************* STAGE 2. ******************/                                               \
+                                                                                                    \
+    /* do vertical convolution of the pre-processed right columns, */                               \
+    /* stored in buffer, and write results to the destination */                                    \
+    /* do vertical convolution of the 1-2 bottom rows */                                            \
+    /* and write results to the buffer */                                                           \
+    if( H <= 2 )                                                                                    \
+    {                                                                                               \
+        if( cols > 0 )                                                                              \
+        {                                                                                           \
+            assert( Hd == 1 );                                                                      \
+            for( j = 0; j < bufW; j++ )                                                             \
+                dst[j] = (arrtype)_pd_scale_( PD_SINGULAR( buf[j], buf[j+(H-1)*bufW] ));            \
+        }                                                                                           \
+                                                                                                    \
+        if( rows > 0 )                                                                              \
+        {                                                                                           \
+            for( j = 0; j < Wn; j++ )                                                               \
+                buf[j] = PD_SINGULAR( src[j-src_step], src[j] );                                    \
+        }                                                                                           \
+    }                                                                                               \
+    else if( H == 3 )                                                                               \
+    {                                                                                               \
+        if( cols > 0 )                                                                              \
+        {                                                                                           \
+            for( j = 0; j < bufW; j++ )                                                             \
+            {                                                                                       \
+                dst[j]= (arrtype)_pd_scale_(PD_LT( buf[j], buf[j+bufW], buf[j+bufW*2]));            \
+            }                                                                                       \
+            if( Hd == 2 )                                                                           \
+            {                                                                                       \
+                dst += dst_step;                                                                    \
+                for( j = 0; j < bufW; j++ )                                                         \
+                    dst[j] = (arrtype)_pd_scale_(PD_LT( buf[j+bufW*2], buf[j+bufW], buf[j]));       \
+            }                                                                                       \
+        }                                                                                           \
+                                                                                                    \
+        if( Hd == 1 )                                                                               \
+        {                                                                                           \
+            for( j = 0; j < Wn; j++ )                                                               \
+                buf[j] = PD_LT( src[j-src_step*2], src[j - src_step], src[j] );                     \
+        }                                                                                           \
+        else                                                                                        \
+        {                                                                                           \
+            for( j = 0; j < Wn; j++ )                                                               \
+            {                                                                                       \
+                buf[j] = PD_LT( src[j-src_step*2], src[j - src_step], src[j] );                     \
+                buf[j+Wn] = PD_LT( src[j],src[j-src_step],src[j-src_step*2] );                      \
+            }                                                                                       \
+        }                                                                                           \
+    }                                                                                               \
+    else                                                                                            \
+    {                                                                                               \
+        if( cols > 0 )                                                                              \
+        {                                                                                           \
+            /* top of the right border */                                                           \
+            for( j = 0; j < bufW; j++ )                                                             \
+                dst[j]=(arrtype)_pd_scale_( PD_LT( buf[j], buf[j+bufW], buf[j+bufW*2]));            \
+                                                                                                    \
+            /* middle part of the right border */                                                   \
+            buf += bufW*2;                                                                          \
+            dst += dst_step;                                                                        \
+            for( i = 1; i < Hd_; i++, dst += dst_step, buf += bufW*2 )                              \
+            {                                                                                       \
+                for( j = 0; j < bufW; j++ )                                                         \
+                    dst[j] = (arrtype)_pd_scale_( PD_FILTER( buf[j - bufW*2], buf[j - bufW],        \
+                                                  buf[j], buf[j + bufW], buf[j + bufW*2] ));        \
+            }                                                                                       \
+                                                                                                    \
+            /* bottom of the right border */                                                        \
+            if( !(H & 1) )                                                                          \
+            {                                                                                       \
+                for( j = 0; j < bufW; j++ )                                                         \
+                    dst[j] = (arrtype)_pd_scale_( PD_RB( buf[j-bufW*2], buf[j-bufW],                \
+                                                         buf[j], buf[j+bufW] ));                    \
+            }                                                                                       \
+            else if( rows > 1 )                                                                     \
+            {                                                                                       \
+                for( j = 0; j < bufW; j++ )                                                         \
+                    dst[j]=(arrtype)_pd_scale_(PD_LT( buf[j-bufW*2], buf[j-bufW], buf[j]));         \
+            }                                                                                       \
+                                                                                                    \
+            buf = buf0;                                                                             \
+        }                                                                                           \
+                                                                                                    \
+        if( rows > 0 )                                                                              \
+        {                                                                                           \
+            if( !(H & 1) )                                                                          \
+            {                                                                                       \
+                for( j = 0; j < Wn; j++ )                                                           \
+                    buf[j] = PD_LT( src[j], src[j-src_step], src[j-src_step*2] );                   \
+            }                                                                                       \
+            else if( cols == 1 )                                                                    \
+            {                                                                                       \
+                for( j = 0; j < Wn; j++ )                                                           \
+                    buf[j] = PD_FILTER( src[j-src_step*4], src[j-src_step*3],                       \
+                                        src[j-src_step*2], src[j-src_step], src[j] );               \
+            }                                                                                       \
+            else                                                                                    \
+            {                                                                                       \
+                for( j = 0; j < Wn; j++ )                                                           \
+                {                                                                                   \
+                    buf[j] = PD_FILTER( src[j-src_step*4], src[j-src_step*3],                       \
+                                        src[j-src_step*2], src[j-src_step], src[j] );               \
+                    buf[j+Wn] = PD_LT( src[j], src[j-src_step], src[j-src_step*2] );                \
+                }                                                                                   \
+            }                                                                                       \
+        }                                                                                           \
+    }                                                                                               \
+                                                                                                    \
+                                                                                                    \
+    /******************* STAGE 3. ******************/                                               \
+                                                                                                    \
+    /* do horizontal convolution of the pre-processed bottom rows,*/                                \
+    /* stored in buffer, and write results to the destination */                                    \
+    if( rows > 0 )                                                                                  \
+    {                                                                                               \
+        dst = dst2;                                                                                 \
+                                                                                                    \
+        if( W <= 2 )                                                                                \
+        {                                                                                           \
+            assert( Wd == 1 );                                                                      \
+            for( ; rows--; dst += dst_step, buf += Wn )                                             \
+            {                                                                                       \
+                if( channels == 1 )                                                                 \
+                    dst[0] = (arrtype)_pd_scale_( PD_SINGULAR( buf[0], buf[Wn-1] ));                \
+                else                                                                                \
+                {                                                                                   \
+                    dst[0] = (arrtype)_pd_scale_( PD_SINGULAR( buf[0], buf[Wn-3] ));                \
+                    dst[1] = (arrtype)_pd_scale_( PD_SINGULAR( buf[1], buf[Wn-2] ));                \
+                    dst[2] = (arrtype)_pd_scale_( PD_SINGULAR( buf[2], buf[Wn-1] ));                \
+                }                                                                                   \
+            }                                                                                       \
+        }                                                                                           \
+        else if( W == 3 )                                                                           \
+        {                                                                                           \
+            if( Wd == 1 )                                                                           \
+            {                                                                                       \
+                for( ; rows--; dst += dst_step, buf += Wn )                                         \
+                {                                                                                   \
+                    if( channels == 1 )                                                             \
+                        dst[0] = (arrtype)_pd_scale_( PD_LT(buf[0], buf[1], buf[2] ));              \
+                    else                                                                            \
+                    {                                                                               \
+                        dst[0] = (arrtype)_pd_scale_( PD_LT(buf[0], buf[3], buf[6] ));              \
+                        dst[1] = (arrtype)_pd_scale_( PD_LT(buf[1], buf[4], buf[7] ));              \
+                        dst[2] = (arrtype)_pd_scale_( PD_LT(buf[2], buf[5], buf[8] ));              \
+                    }                                                                               \
+                }                                                                                   \
+            }                                                                                       \
+            else                                                                                    \
+            {                                                                                       \
+                for( ; rows--; dst += dst_step, buf += Wn )                                         \
+                {                                                                                   \
+                    if( channels == 1 )                                                             \
+                    {                                                                               \
+                        dst[0] = (arrtype)_pd_scale_( PD_LT(buf[0], buf[1], buf[2] ));              \
+                        dst[1] = (arrtype)_pd_scale_( PD_LT(buf[2], buf[1], buf[0] ));              \
+                    }                                                                               \
+                    else                                                                            \
+                    {                                                                               \
+                        dst[0] = (arrtype)_pd_scale_( PD_LT(buf[0], buf[3], buf[6] ));              \
+                        dst[1] = (arrtype)_pd_scale_( PD_LT(buf[1], buf[4], buf[7] ));              \
+                        dst[2] = (arrtype)_pd_scale_( PD_LT(buf[2], buf[5], buf[8] ));              \
+                        dst[3] = (arrtype)_pd_scale_( PD_LT(buf[6], buf[3], buf[0] ));              \
+                        dst[4] = (arrtype)_pd_scale_( PD_LT(buf[7], buf[4], buf[1] ));              \
+                        dst[5] = (arrtype)_pd_scale_( PD_LT(buf[8], buf[5], buf[2] ));              \
+                    }                                                                               \
+                }                                                                                   \
+            }                                                                                       \
+        }                                                                                           \
+        else                                                                                        \
+        {                                                                                           \
+            for( ; rows--; dst += dst_step, buf += Wn )                                             \
+            {                                                                                       \
+                if( channels == 1 )                                                                 \
+                {                                                                                   \
+                    /* left part of the bottom row */                                               \
+                    dst[0] = (arrtype)_pd_scale_( PD_LT( buf[0], buf[1], buf[2] ));                 \
+                                                                                                    \
+                    /* middle part of the bottom row */                                             \
+                    for( i = 1; i < Wd_; i++ )                                                      \
+                    {                                                                               \
+                        dst[i] = (arrtype)_pd_scale_( PD_FILTER(buf[i*2-2], buf[i*2-1],             \
+                                                    buf[i*2],buf[i*2+1], buf[i*2+2] ));             \
+                    }                                                                               \
+                                                                                                    \
+                    /* right part of the bottom row */                                              \
+                    if( !(W & 1) )                                                                  \
+                        dst[i] = (arrtype)_pd_scale_( PD_RB( buf[i*2-2],buf[i*2-1],                 \
+                                                    buf[i*2], buf[i*2+1] ));                        \
+                    else if( cols > 1 )                                                             \
+                        dst[i] = (arrtype)_pd_scale_( PD_LT( buf[i*2-2], buf[i*2-1], buf[i*2] ));   \
+                }                                                                                   \
+                else                                                                                \
+                {                                                                                   \
+                    /* left part of the bottom row */                                               \
+                    dst[0] = (arrtype)_pd_scale_( PD_LT( buf[0], buf[3], buf[6] ));                 \
+                    dst[1] = (arrtype)_pd_scale_( PD_LT( buf[1], buf[4], buf[7] ));                 \
+                    dst[2] = (arrtype)_pd_scale_( PD_LT( buf[2], buf[5], buf[8] ));                 \
+                                                                                                    \
+                    /* middle part of the bottom row */                                             \
+                    for( i = 3; i < Wd_*3; i++ )                                                    \
+                    {                                                                               \
+                        dst[i] = (arrtype)_pd_scale_( PD_FILTER(buf[i*2-6], buf[i*2-3],             \
+                                                        buf[i*2],buf[i*2+3], buf[i*2+6] ));         \
+                    }                                                                               \
+                                                                                                    \
+                    /* right part of the bottom row */                                              \
+                    if( !(W & 1) )                                                                  \
+                    {                                                                               \
+                        dst[i] = (arrtype)_pd_scale_( PD_RB( buf[i*2-6],buf[i*2-3],                 \
+                                                    buf[i*2], buf[i*2+3] ));                        \
+                        dst[i+1] = (arrtype)_pd_scale_( PD_RB( buf[i*2-5],buf[i*2-2],               \
+                                                    buf[i*2+1], buf[i*2+4] ));                      \
+                        dst[i+2] = (arrtype)_pd_scale_( PD_RB( buf[i*2-4],buf[i*2-1],               \
+                                                    buf[i*2+2], buf[i*2+5] ));                      \
+                    }                                                                               \
+                    else if( cols > 1 )                                                             \
+                    {                                                                               \
+                        dst[i] = (arrtype)_pd_scale_( PD_LT( buf[i*2-6], buf[i*2-3], buf[i*2] ));   \
+                        dst[i+1] = (arrtype)_pd_scale_( PD_LT( buf[i*2-5], buf[i*2-2], buf[i*2+1]));\
+                        dst[i+2] = (arrtype)_pd_scale_( PD_LT( buf[i*2-4], buf[i*2-1], buf[i*2+2]));\
+                    }                                                                               \
+                }                                                                                   \
+            }                                                                                       \
+        }                                                                                           \
+    }                                                                                               \
+                                                                                                    \
+    if( !local_alloc )                                                                              \
+        cvFree( (void**)&buf0 );                                                                    \
+                                                                                                    \
+    return CV_OK;                                                                                   \
 }
 
-ICV_DEF_PYR_BORDER_FUNC( 8u, uchar, int, PD_SCALE_INT )
-ICV_DEF_PYR_BORDER_FUNC( 8s, char, int, PD_SCALE_INT )
-ICV_DEF_PYR_BORDER_FUNC( 32f, float, float, PD_SCALE_FLT )
-ICV_DEF_PYR_BORDER_FUNC( 64f, double, double, PD_SCALE_FLT )
-
-
-#define ICV_DEF_INIT_PYR_TABLE( FUNCNAME, FLAG )                    \
-static void icvInit##FUNCNAME##FLAG##Table( CvBigFuncTable* tab )   \
+#define ICV_DEF_INIT_PYR_TABLE( FUNCNAME )                          \
+static void icvInit##FUNCNAME##RTable( CvBigFuncTable* tab )        \
 {                                                                   \
-    tab->fn_2d[CV_8UC1] = (void*)icv##FUNCNAME##_8u_C1##FLAG;       \
-    tab->fn_2d[CV_8UC3] = (void*)icv##FUNCNAME##_8u_C3##FLAG;       \
-    tab->fn_2d[CV_8SC1] = (void*)icv##FUNCNAME##_8s_C1##FLAG;       \
-    tab->fn_2d[CV_8SC3] = (void*)icv##FUNCNAME##_8s_C3##FLAG;       \
-    tab->fn_2d[CV_32FC1] = (void*)icv##FUNCNAME##_32f_C1##FLAG;     \
-    tab->fn_2d[CV_32FC3] = (void*)icv##FUNCNAME##_32f_C3##FLAG;     \
-    tab->fn_2d[CV_64FC1] = (void*)icv##FUNCNAME##_64f_C1##FLAG;     \
-    tab->fn_2d[CV_64FC3] = (void*)icv##FUNCNAME##_64f_C3##FLAG;     \
+    tab->fn_2d[CV_8UC1] = (void*)icv##FUNCNAME##_8u_C1R;            \
+    tab->fn_2d[CV_8UC3] = (void*)icv##FUNCNAME##_8u_C3R;            \
+    tab->fn_2d[CV_8SC1] = 0;                                        \
+    tab->fn_2d[CV_8SC3] = 0;                                        \
+    tab->fn_2d[CV_32FC1] = (void*)icv##FUNCNAME##_32f_C1R;          \
+    tab->fn_2d[CV_32FC3] = (void*)icv##FUNCNAME##_32f_C3R;          \
+    tab->fn_2d[CV_64FC1] = (void*)icv##FUNCNAME##_64f_C1R;          \
+    tab->fn_2d[CV_64FC3] = (void*)icv##FUNCNAME##_64f_C3R;          \
 }
 
-#define ICV_DEF_INIT_PYR_BORDER_TABLE( FUNCNAME, FLAG )             \
-static void icvInit##FUNCNAME##FLAG##Table( CvFuncTable* tab )      \
+#define ICV_DEF_INIT_PYR_BORDER_TABLE( FUNCNAME )                   \
+static void icvInit##FUNCNAME##RTable( CvFuncTable* tab )           \
 {                                                                   \
-    tab->fn_2d[CV_8U] = (void*)icv##FUNCNAME##_8u_Cn##FLAG;         \
-    tab->fn_2d[CV_8S] = (void*)icv##FUNCNAME##_8s_Cn##FLAG;         \
-    tab->fn_2d[CV_32F] = (void*)icv##FUNCNAME##_32f_Cn##FLAG;       \
-    tab->fn_2d[CV_64F] = (void*)icv##FUNCNAME##_64f_Cn##FLAG;       \
+    tab->fn_2d[CV_8U] = (void*)icv##FUNCNAME##_8u_CnR;              \
+    tab->fn_2d[CV_8S] = 0;                                          \
+    tab->fn_2d[CV_32F] = (void*)icv##FUNCNAME##_32f_CnR;            \
+    tab->fn_2d[CV_64F] = (void*)icv##FUNCNAME##_64f_CnR;            \
 }
 
 
-ICV_DEF_INIT_PYR_TABLE( PyrUp_Gauss5x5, R )
-ICV_DEF_INIT_PYR_TABLE( PyrDown_Gauss5x5, R )
-
-ICV_DEF_INIT_PYR_BORDER_TABLE( PyrDownBorder, R )
+ICV_DEF_INIT_PYR_TABLE( PyrUp_Gauss5x5 )
+ICV_DEF_INIT_PYR_TABLE( PyrDown_Gauss5x5 )
+ICV_DEF_INIT_PYR_BORDER_TABLE( PyrDownBorder )
 
 typedef CvStatus (CV_STDCALL * CvPyrDownBorderFunc)( const void* src, int srcstep,
-                                                     CvSize srcsize,
-                                                     void* dst, int dststep,
-                                                     CvSize dstsize,
-                                                     int channels );
+                                                     CvSize srcsize, void* dst,
+                                                     int dststep, CvSize dstsize, int cn );
 
 /****************************************************************************************\
 *                                 External functions                                     *
@@ -901,12 +999,16 @@ cvPyrUp( const void* srcarr, void* dstarr, int _filter )
     if( !func )
         CV_ERROR( CV_StsUnsupportedFormat, "" );
 
-    IPPI_CALL( icvPyrUpGetBufSize_Gauss5x5( src->width, icvDepthToDataType(type),
-                                            CV_MAT_CN( type ), &buffer_size ));
+    if( icvPyrUpGetBufSize_Gauss5x5( src->width, icvDepthToDataType(type),
+                                     CV_MAT_CN( type ), &buffer_size ) < 0 )
+    {
+        icvPyrUpGetBufSize_Gauss5x5_f( src->width, icvDepthToDataType(type),
+                                       CV_MAT_CN( type ), &buffer_size );
+    }
 
     if( buffer_size <= CV_MAX_LOCAL_SIZE )
     {
-        buffer = alloca( buffer_size );
+        buffer = cvStackAlloc( buffer_size );
         local_alloc = 1;
     }
     else
@@ -915,7 +1017,7 @@ cvPyrUp( const void* srcarr, void* dstarr, int _filter )
     }
 
     IPPI_CALL( func( src->data.ptr, src->step, dst->data.ptr, dst->step,
-                     icvGetMatSize(src), buffer ));
+                     cvGetMatSize(src), buffer ));
     __END__;
 
     if( buffer && !local_alloc )
@@ -965,8 +1067,8 @@ cvPyrDown( const void* srcarr, void* dstarr, int _filter )
     if( !CV_ARE_TYPES_EQ( src, dst ))
         CV_ERROR( CV_StsUnmatchedFormats, "" );
 
-    src_size = icvGetMatSize(src);
-    dst_size = icvGetMatSize(dst);
+    src_size = cvGetMatSize(src);
+    dst_size = cvGetMatSize(dst);
     src_size2.width = src_size.width & -2;
     src_size2.height = src_size.height & -2;
 
@@ -984,12 +1086,16 @@ cvPyrDown( const void* srcarr, void* dstarr, int _filter )
     if( !func )
         CV_ERROR( CV_StsUnsupportedFormat, "" );
 
-    IPPI_CALL( icvPyrDownGetBufSize_Gauss5x5( src_size2.width, icvDepthToDataType(type),
-                                              CV_MAT_CN( type ), &buffer_size ));
+    if( icvPyrDownGetBufSize_Gauss5x5( src_size2.width, icvDepthToDataType(type),
+                                       CV_MAT_CN( type ), &buffer_size ) < 0 )
+    {
+        icvPyrDownGetBufSize_Gauss5x5_f( src_size2.width, icvDepthToDataType(type),
+                                         CV_MAT_CN( type ), &buffer_size );
+    }
     
     if( buffer_size <= CV_MAX_LOCAL_SIZE )
     {
-        buffer = alloca( buffer_size );
+        buffer = cvStackAlloc( buffer_size );
         local_alloc = 1;
     }
     else
@@ -1008,7 +1114,7 @@ cvPyrDown( const void* srcarr, void* dstarr, int _filter )
             CV_ERROR( CV_StsUnsupportedFormat, "" );
 
         IPPI_CALL( border_func( src->data.ptr, src->step, src_size,
-                                dst->data.ptr, dst->step, dst_size, CV_MAT_CN(type)));
+                                dst->data.ptr, dst->step, dst_size, CV_MAT_CN(type) ));
     }
 
     __END__;
@@ -1018,4 +1124,14 @@ cvPyrDown( const void* srcarr, void* dstarr, int _filter )
 }
 
 
+/* MSVC .NET 2003 spends a long time building this, thus, as the code
+   is not performance-critical, we turn off the optimization here */
+#if _MSC_VER > 1300 && !defined __ICL
+#pragma optimize("", off)
+#endif
+
+ICV_DEF_PYR_BORDER_FUNC( 8u, uchar, int, PD_SCALE_INT )
+ICV_DEF_PYR_BORDER_FUNC( 32f, float, float, PD_SCALE_FLT )
+ICV_DEF_PYR_BORDER_FUNC( 64f, double, double, PD_SCALE_FLT )
+
 /* End of file. */
index add95fbf1cdcb1744a62699529103dc93c621f5e..0ad5dc9e68445a9b8f25f580a39f51bbe636f582 100644 (file)
@@ -39,7 +39,6 @@
 //
 //M*/
 #include "_cv.h"
-#include "_cvdatastructs.h"
 
 typedef struct _CvRGBf
 {   float blue;
@@ -94,18 +93,18 @@ typedef struct _CvListNode
 _CvListNode;
 
 
-CvStatus  icvSegmentClusterC1( CvSeq* cmp_seq, CvSeq* res_seq,
+static CvStatus  icvSegmentClusterC1( CvSeq* cmp_seq, CvSeq* res_seq,
                                  double threshold,
                                  _CvPyramid* first_level_end,
                                  CvSize first_level_size );
 
-CvStatus  icvSegmentClusterC3( CvSeq* cmp_seq, CvSeq* res_seq,
+static CvStatus  icvSegmentClusterC3( CvSeq* cmp_seq, CvSeq* res_seq,
                                  double threshold,
                                  _CvPyramidC3* first_level_end,
                                  CvSize first_level_size );
 
-void icvMaxRoi( _CvRect16u *max_rect, _CvRect16u* cur_rect );
-void icvMaxRoi1( _CvRect16u *max_rect, int x, int y );
+static void icvMaxRoi( _CvRect16u *max_rect, _CvRect16u* cur_rect );
+static void icvMaxRoi1( _CvRect16u *max_rect, int x, int y );
 
 
 #define _CV_CHECK( icvFun )                                             \
@@ -121,7 +120,6 @@ void icvMaxRoi1( _CvRect16u *max_rect, int x, int y );
                                        (float)fabs((a).green - (b).green),  \
                                        (float)fabs((a).blue - (b).blue))*/
 
-CV_INLINE float icvRGBDist_Max( const _CvRGBf& a, const _CvRGBf& b );
 CV_INLINE float icvRGBDist_Max( const _CvRGBf& a, const _CvRGBf& b )
 {
     float tr = (float)fabs(a.red - b.red);
@@ -131,12 +129,13 @@ CV_INLINE float icvRGBDist_Max( const _CvRGBf& a, const _CvRGBf& b )
     return _CV_MAX3( tr, tg, tb );
 }
 
-CV_INLINE float icvRGBDist_Sum( const _CvRGBf& a, const _CvRGBf& b );
 CV_INLINE float icvRGBDist_Sum( const _CvRGBf& a, const _CvRGBf& b )
 {
-    return (float)(fabs(a.red - b.red) +
-                   fabs(a.green - b.green) +
-                   fabs(a.blue - b.blue));
+    float tr = (float)fabs(a.red - b.red);
+    float tg = (float)fabs(a.green - b.green);
+    float tb = (float)fabs(a.blue - b.blue);
+    
+    return (tr + tg + tb);
 }
 
 #if 1
@@ -166,7 +165,7 @@ icvWritePyrNode( void *elem, void *writer )
 }
 
 
-CvStatus
+static CvStatus
 icvPyrSegmentation8uC1R( uchar * src_image, int src_step,
                          uchar * dst_image, int dst_step,
                          CvSize roi, CvFilter filter,
@@ -241,7 +240,7 @@ icvPyrSegmentation8uC1R( uchar * src_image, int src_step,
     }
 
     /* allocate buffer */
-    buffer = (char *) icvAlloc( buffer_size );
+    buffer = (char *) cvAlloc( buffer_size );
     if( !buffer )
     {
         status = CV_OUTOFMEM_ERR;
@@ -253,8 +252,14 @@ icvPyrSegmentation8uC1R( uchar * src_image, int src_step,
     /* initialization pyramid-linking properties down up to level */
     step = roi.width * sizeof( float );
 
-    _CV_CHECK( icvCvtTo_32f_C1R( src_image, src_step, pyramida,
-                                 step, roi, CV_8UC1 ));
+    {
+        CvMat _src;
+        CvMat _pyramida;
+        cvInitMatHeader( &_src, roi.height, roi.width, CV_8UC1, src_image, src_step );
+        cvInitMatHeader( &_pyramida, roi.height, roi.width, CV_32FC1, pyramida, step );
+        cvConvert( &_src, &_pyramida );
+        /*_CV_CHECK( icvCvtTo_32f_C1R( src_image, src_step, pyramida, step, roi, CV_8UC1 ));*/
+    }
     p_base = (_CvPyramidBase *) (buffer + step * roi.height);
     pyram[0] = (_CvPyramid *) p_base;
 
@@ -273,7 +278,7 @@ icvPyrSegmentation8uC1R( uchar * src_image, int src_step,
 
     icvPyrDownGetBufSize_Gauss5x5( size.width, cv32f, 1, &buff_size );
     assert( buff_size > 0 );
-    buff = icvAlloc( buff_size );
+    buff = cvAlloc( buff_size );
     assert( buff );
 
     /* calculate initial pyramid */
@@ -301,7 +306,7 @@ icvPyrSegmentation8uC1R( uchar * src_image, int src_step,
         }
     }
 
-    icvFree( &buff );
+    cvFree( &buff );
 
     cvStartAppendToSeq( cmp_seq, &writer );
 
@@ -565,7 +570,7 @@ icvPyrSegmentation8uC1R( uchar * src_image, int src_step,
     }
   M_END:
 
-    icvFree( &buffer );
+    cvFree( (void**)&buffer );
     cvReleaseMemStorage( &temp_storage );
 
     if( status == CV_OK )
@@ -579,7 +584,7 @@ icvPyrSegmentation8uC1R( uchar * src_image, int src_step,
 /****************************************************************************************\
     color!!!  image segmentation by pyramid-linking   
 \****************************************************************************************/
-CvStatus
+static CvStatus
 icvPyrSegmentation8uC3R( uchar * src_image, int src_step,
                          uchar * dst_image, int dst_step,
                          CvSize roi, CvFilter filter,
@@ -658,7 +663,7 @@ icvPyrSegmentation8uC3R( uchar * src_image, int src_step,
     }
 
     /* allocate buffer */
-    buffer = (char *) icvAlloc( buffer_size );
+    buffer = (char *) cvAlloc( buffer_size );
     if( !buffer )
     {
         status = CV_OUTOFMEM_ERR;
@@ -670,8 +675,16 @@ icvPyrSegmentation8uC3R( uchar * src_image, int src_step,
     /* initialization pyramid-linking properties down up to level */
     step = roi.width * sizeof( _CvRGBf );
 
-    _CV_CHECK( icvCvtTo_32f_C1R( src_image, src_step, pyramida, step,
-                                 cvSize( roi.width * 3, roi.height ), CV_8UC1 ));
+    {
+        CvMat _src;
+        CvMat _pyramida;
+        cvInitMatHeader( &_src, roi.height, roi.width, CV_8UC3, src_image, src_step );
+        cvInitMatHeader( &_pyramida, roi.height, roi.width, CV_32FC3, pyramida, step );
+        cvConvert( &_src, &_pyramida );
+        /*_CV_CHECK( icvCvtTo_32f_C1R( src_image, src_step, pyramida, step,
+                                 cvSize( roi.width * 3, roi.height ), CV_8UC1 ));*/
+    }
+
     p_base = (_CvPyramidBaseC3 *) (buffer + step * roi.height);
     pyram[0] = (_CvPyramidC3 *) p_base;
 
@@ -690,7 +703,7 @@ icvPyrSegmentation8uC3R( uchar * src_image, int src_step,
 
     icvPyrDownGetBufSize_Gauss5x5( size.width, cv32f, 3, &buff_size );
     assert( buff_size > 0 );
-    buff = icvAlloc( buff_size );
+    buff = cvAlloc( buff_size );
     assert( buff );
 
     /* calculate initial pyramid */
@@ -718,7 +731,7 @@ icvPyrSegmentation8uC3R( uchar * src_image, int src_step,
         }
     }
 
-    icvFree( &buff );
+    cvFree( &buff );
 
     cvStartAppendToSeq( cmp_seq, &writer );
 
@@ -995,7 +1008,7 @@ icvPyrSegmentation8uC3R( uchar * src_image, int src_step,
 
   M_END:
 
-    icvFree( &buffer );
+    cvFree( (void**)&buffer );
     cvReleaseMemStorage( &temp_storage );
 
     if( status == CV_OK )
@@ -1005,15 +1018,10 @@ icvPyrSegmentation8uC3R( uchar * src_image, int src_step,
 }
 
 
-IPCVAPI_IMPL( CvStatus, icvUpdatePyrLinks_8u_C1, (int layer,
-                                                  void *layer_data,
-                                                  CvSize size,
-                                                  void *parent_layer,
-                                                  void *_writer,
-                                                  float threshold,
-                                                  int is_last_iter,
-                                                  void *_stub,
-                                                  ICVWriteNodeFunction ))
+IPCVAPI_IMPL( CvStatus, icvUpdatePyrLinks_8u_C1,
+    (int layer, void *layer_data, CvSize size, void *parent_layer,
+     void *_writer, float threshold, int is_last_iter, void *_stub, CvWriteNodeFunction /*func*/),
+     (layer, layer_data, size, parent_layer, _writer, threshold, is_last_iter, _stub, icvWritePyrNode) )
 {
     int i, j;
     _CvListNode cmp_node;
@@ -1194,15 +1202,10 @@ IPCVAPI_IMPL( CvStatus, icvUpdatePyrLinks_8u_C1, (int layer,
 }
 
 
-IPCVAPI_IMPL( CvStatus, icvUpdatePyrLinks_8u_C3, (int layer,
-                                                  void *layer_data,
-                                                  CvSize size,
-                                                  void *parent_layer,
-                                                  void *_writer,
-                                                  float threshold,
-                                                  int is_last_iter,
-                                                  void *_stub,
-                                                  ICVWriteNodeFunction ))
+IPCVAPI_IMPL( CvStatus, icvUpdatePyrLinks_8u_C3,
+    (int layer, void *layer_data, CvSize size, void *parent_layer,
+     void *_writer, float threshold, int is_last_iter, void *_stub, CvWriteNodeFunction /*func*/),
+     (layer, layer_data, size, parent_layer, _writer, threshold, is_last_iter, _stub, icvWritePyrNode) )
 {
     int i, j;
     _CvListNode cmp_node;
@@ -1433,7 +1436,7 @@ icvSegmentClusterC1( CvSeq * cmp_seq, CvSeq * res_seq,
 
             c = cvRound( cmp->c );
             *(int *) &(cmp->c) = c;
-            comp.value = (float) c;
+            comp.value = cvRealScalar(c);
             comp.area = cmp->a;
             comp.rect.x = cmp->rect.x1;
             comp.rect.y = cmp->rect.y1;
@@ -1536,7 +1539,7 @@ icvSegmentClusterC1( CvSeq * cmp_seq, CvSeq * res_seq,
                 node = node->next;
             }
 
-            comp.value = (float) c;
+            comp.value = cvRealScalar(c);
             comp.area = temp_cmp.a;
             comp.rect.x = temp_cmp.rect.x1;
             comp.rect.y = temp_cmp.rect.y1;
@@ -1612,8 +1615,7 @@ icvSegmentClusterC3( CvSeq * cmp_seq, CvSeq * res_seq,
             ((int *) &(cmp->c))[0] = c_blue;
             ((int *) &(cmp->c))[1] = c_green;
             ((int *) &(cmp->c))[2] = c_red;
-            comp.value = (float) ((uchar) c_blue +
-                                  ((uchar) c_green << 8) + ((uchar) c_red << 16));
+            comp.value = cvScalar( c_blue, c_green, c_red );
             comp.area = cmp->a;
             comp.rect.x = cmp->rect.x1;
             comp.rect.y = cmp->rect.y1;
@@ -1726,8 +1728,7 @@ icvSegmentClusterC3( CvSeq * cmp_seq, CvSeq * res_seq,
                 node = node->next;
             }
 
-            comp.value = (float) ((uchar) c_blue +
-                                  ((uchar) c_green << 8) + ((uchar) c_red << 16));
+            comp.value = cvScalar( c_blue, c_green, c_red );
             comp.area = temp_cmp.a;
             comp.rect.x = temp_cmp.rect.x1;
             comp.rect.y = temp_cmp.rect.y1;
@@ -1834,17 +1835,14 @@ cvPyrSegmentation( IplImage * src,
 
     __BEGIN__;
 
-    CV_CALL( CV_CHECK_IMAGE( src ));
-    CV_CALL( CV_CHECK_IMAGE( dst ));
-
     if( src->depth != IPL_DEPTH_8U )
-        CV_ERROR( CV_BadDepth, icvUnsupportedFormat );
+        CV_ERROR( CV_BadDepth, cvUnsupportedFormat );
 
     if( src->depth != dst->depth || src->nChannels != dst->nChannels )
         CV_ERROR( CV_StsBadArg, "src and dst have different formats" );
 
-    cvGetImageRawData( src, &src_data, &src_step, &src_size );
-    cvGetImageRawData( dst, &dst_data, &dst_step, &dst_size );
+    cvGetRawData( src, &src_data, &src_step, &src_size );
+    cvGetRawData( dst, &dst_data, &dst_step, &dst_size );
 
     if( src_size != dst_size )
         CV_ERROR( CV_StsBadArg, "src and dst have different ROIs" );
@@ -1866,9 +1864,8 @@ cvPyrSegmentation( IplImage * src,
                                             comp, storage, level, thresh1, thresh2 ));
         break;
     default:
-        CV_ERROR( CV_BadNumChannels, icvUnsupportedFormat );
+        CV_ERROR( CV_BadNumChannels, cvUnsupportedFormat );
     }
-    __CLEANUP__;
     __END__;
 }
 
index 77119b7b1fac802a5cfb56ce704f3ca968fb2ebc..365fd6b9e7b30d7677bc9252bde8c7d8349e79f6 100644 (file)
@@ -39,7 +39,6 @@
 //
 //M*/
 #include "_cv.h"
-#include "_cvdatastructs.h"
 
 typedef struct
 {
@@ -97,8 +96,8 @@ icvRotatingCalipers( CvPoint2D32f* points, int n, int mode, float* out )
     float max_dist = 0;
     char buffer[32];
     int i, k;
-    CvPoint2D32f* vect = (CvPoint2D32f*)icvAlloc( n * sizeof(vect[0]) );
-    float* inv_vect_length = (float*)icvAlloc( n * sizeof(inv_vect_length[0]) );
+    CvPoint2D32f* vect = (CvPoint2D32f*)cvAlloc( n * sizeof(vect[0]) );
+    float* inv_vect_length = (float*)cvAlloc( n * sizeof(inv_vect_length[0]) );
     int left = 0, bottom = 0, right = 0, top = 0;
     int seq[4] = { -1, -1, -1, -1 };
 
@@ -106,7 +105,7 @@ icvRotatingCalipers( CvPoint2D32f* points, int n, int mode, float* out )
        (a,b) (-b,a) (-a,-b) (b, -a)     
      */
     /* this is a first base bector (a,b) initialized by (1,0) */
-    float orientation;
+    float orientation = 0;
     float base_a;
     float base_b = 0;
 
@@ -139,19 +138,29 @@ icvRotatingCalipers( CvPoint2D32f* points, int n, int mode, float* out )
         pt0 = pt;
     }
 
-    icvbInvSqrt_32f( inv_vect_length, inv_vect_length, n );
+    cvbInvSqrt( inv_vect_length, inv_vect_length, n );
 
     /* find convex hull orientation */
     {
-        float ax = vect[0].x;
-        float ay = vect[0].y;
-        float bx = vect[1].x;
-        float by = vect[1].y;
+        double ax = vect[n-1].x;
+        double ay = vect[n-1].y;
+        
+        for( i = 0; i < n; i++ )
+        {
+            double bx = vect[i].x;
+            double by = vect[i].y;
 
-        float convexity = ax * by - ay * bx;
+            double convexity = ax * by - ay * bx;
 
-        assert( convexity != 0 );
-        orientation = (convexity > 0) ? 1.f : (-1.f);
+            if( convexity != 0 )
+            {
+                orientation = (convexity > 0) ? 1.f : (-1.f);
+                break;
+            }
+            ax = bx;
+            ay = by;
+        }
+        assert( orientation != 0 );
     }
     base_a = orientation;
 
@@ -168,7 +177,7 @@ icvRotatingCalipers( CvPoint2D32f* points, int n, int mode, float* out )
     for( k = 0; k < n; k++ )
     {
         /* sinus of minimal angle */
-        float sinus;
+        /*float sinus;*/
 
         /* compute cosine of angle between calipers side and polygon edge */
         /* dp - dot product */
@@ -191,21 +200,38 @@ icvRotatingCalipers( CvPoint2D32f* points, int n, int mode, float* out )
         cosalpha = dp3 * inv_vect_length[seq[3]];
         maxcos = (cosalpha > maxcos) ? (main_element = 3, cosalpha) : maxcos;
 
-        sinus = orientation * cvSqrt( 1 - maxcos * maxcos );
-
-        /* rotate calipers */
+        /*rotate calipers*/
         {
-            float x = base_a;
-            float y = base_b;
-
-            base_a = maxcos * x - sinus * y;
-            base_b = sinus * x + maxcos * y;
-        }
-
+            //get next base
+            int pindex = seq[main_element];
+            float lead_x = vect[pindex].x*inv_vect_length[pindex];
+            float lead_y = vect[pindex].y*inv_vect_length[pindex];
+            switch( main_element )
+            {
+            case 0:
+                base_a = lead_x;
+                base_b = lead_y;
+                break;
+            case 1:
+                base_a = lead_y; 
+                base_b = -lead_x;
+                break;
+            case 2:
+                base_a = -lead_x;
+                base_b = -lead_y;
+                break;
+            case 3:
+                base_a = -lead_y;
+                base_b = lead_x;
+                break;
+            default: assert(0);
+            }
+        }                        
         /* change base point of main edge */
         seq[main_element] += 1;
         seq[main_element] = (seq[main_element] == n) ? 0 : seq[main_element];
 
+        
         switch (mode)
         {
         case CV_CALIPERS_MAXHEIGHT:
@@ -308,8 +334,8 @@ icvRotatingCalipers( CvPoint2D32f* points, int n, int mode, float* out )
         break;
     }
 
-    icvFree( (void**)&vect );
-    icvFree( (void**)&inv_vect_length );
+    cvFree( (void**)&vect );
+    cvFree( (void**)&inv_vect_length );
 }
 
 
index dbe9670df85f91ae35143d6ff410c03773aac7d9..abf9329aea23058ea16b26d51a3e0a2dda0dde93 100644 (file)
 // the use of this software, even if advised of the possibility of such damage.
 //
 //M*/
+
 #include "_cv.h"
-#include "_cvutils.h"
 
 /* 
    Initializes line iterator.
    Returns number of points on the line or negative number if error.
 */
-int
-icvInitLineIterator( const CvMat* mat, CvPoint pt1, CvPoint pt2,
-                     CvLineIterator* iterator, int connectivity,
-                     int left_to_right )
+CV_IMPL int
+cvInitLineIterator( const void* img, CvPoint pt1, CvPoint pt2,
+                    CvLineIterator* iterator, int connectivity )
 {
+    int count = -1;
+    
+    CV_FUNCNAME( "cvInitLineIterator" );
+
+    __BEGIN__;
+
+    CvMat stub, *mat = (CvMat*)img;
     int dx, dy, s;
     int bt_pix, bt_pix0, step;
 
+    CV_CALL( mat = cvGetMat( mat, &stub ));
+
+    if( !iterator )
+        CV_ERROR( CV_StsNullPtr, "" );
+
+    if( connectivity != 8 && connectivity != 4 )
+        CV_ERROR( CV_StsBadArg, "" );
+
+    if( (unsigned)pt1.x >= (unsigned)(mat->width) ||
+        (unsigned)pt2.x >= (unsigned)(mat->width) ||
+        (unsigned)pt1.y >= (unsigned)(mat->height) ||
+        (unsigned)pt2.y >= (unsigned)(mat->height) )
+        CV_ERROR( CV_StsBadPoint, "" );
+
     assert( connectivity == 4 || connectivity == 8 );
 
-    bt_pix0 = bt_pix = icvPixSize[CV_MAT_TYPE(mat->type)];
+    bt_pix0 = bt_pix = CV_ELEM_SIZE(mat->type);
     step = mat->step;
 
     dx = pt2.x - pt1.x;
     dy = pt2.y - pt1.y;
     s = dx < 0 ? -1 : 0;
 
-    if( left_to_right )
-    {
-        dx = (dx ^ s) - s;
-        dy = (dy ^ s) - s;
-        pt1.x ^= (pt1.x ^ pt2.x) & s;
-        pt1.y ^= (pt1.y ^ pt2.y) & s;
-    }
-    else
-    {
-        dx = (dx ^ s) - s;
-        bt_pix = (bt_pix ^ s) - s;
-    }
+    dx = (dx ^ s) - s;
+    bt_pix = (bt_pix ^ s) - s;
 
     iterator->ptr = (uchar*)(mat->data.ptr + pt1.y * step + pt1.x * bt_pix0);
 
@@ -101,7 +111,7 @@ icvInitLineIterator( const CvMat* mat, CvPoint pt1, CvPoint pt2,
         iterator->minus_delta = -(dy + dy);
         iterator->plus_step = step;
         iterator->minus_step = bt_pix;
-        s = dx + 1;
+        count = dx + 1;
     }
     else /* connectivity == 4 */
     {
@@ -112,45 +122,9 @@ icvInitLineIterator( const CvMat* mat, CvPoint pt1, CvPoint pt2,
         iterator->minus_delta = -(dy + dy);
         iterator->plus_step = step - bt_pix;
         iterator->minus_step = bt_pix;
-        s = dx + dy + 1;
+        count = dx + dy + 1;
     }
 
-    return s;
-}
-
-
-/* 
-   Initializes line iterator.
-   Returns number of points on the line or negative number if error.
-*/
-CV_IMPL int
-cvInitLineIterator( const void* img, CvPoint pt1, CvPoint pt2,
-                    CvLineIterator* iterator, int connectivity )
-{
-    int count = -1;
-    
-    CV_FUNCNAME( "cvInitLineIterator" );
-
-    __BEGIN__;
-
-    CvMat stub, *mat = (CvMat*)img;
-
-    CV_CALL( mat = cvGetMat( mat, &stub ));
-
-    if( !iterator )
-        CV_ERROR( CV_StsNullPtr, "" );
-
-    if( connectivity != 8 && connectivity != 4 )
-        CV_ERROR( CV_StsBadArg, "" );
-
-    if( (unsigned)pt1.x >= (unsigned)(mat->width) ||
-        (unsigned)pt2.x >= (unsigned)(mat->width) ||
-        (unsigned)pt1.y >= (unsigned)(mat->height) ||
-        (unsigned)pt2.y >= (unsigned)(mat->height) )
-        CV_ERROR( CV_StsBadPoint, "" );
-
-    count = icvInitLineIterator( mat, pt1, pt2, iterator, connectivity );
-
     __END__;
 
     return count;
@@ -161,79 +135,19 @@ cvInitLineIterator( const void* img, CvPoint pt1, CvPoint pt2,
 *                                   line samplers                                      *
 \**************************************************************************************/
 
-////////////////////////////////////////////////////////////////////////////////////////
-
-#define  ICV_DEF_SAMPLE_LINE( flavor, arrtype, pix_size )                  \
-IPCVAPI_IMPL( CvStatus, icvSampleLine_##flavor,                            \
-( CvLineIterator* iterator, arrtype* buffer, int count ))                  \
-{                                                                          \
-    for( int i = 0; i < count; i++ )                                       \
-    {                                                                      \
-        memcpy( buffer, iterator->ptr, pix_size );                         \
-        buffer += pix_size;                                                \
-        CV_NEXT_LINE_POINT( *iterator );                                   \
-    }                                                                      \
-                                                                           \
-    return CV_OK;                                                          \
-}
-
-
-ICV_DEF_SAMPLE_LINE( 8u_C1R, uchar, 1 )
-ICV_DEF_SAMPLE_LINE( 8u_C2R, uchar, 2 )
-ICV_DEF_SAMPLE_LINE( 8u_C3R, uchar, 3 )
-ICV_DEF_SAMPLE_LINE( 32f_C1R, float, 4 )
-ICV_DEF_SAMPLE_LINE( 32f_C2R, float, 8 )
-ICV_DEF_SAMPLE_LINE( 32f_C3R, float, 12 )
-
-#define icvSampleLine_16u_C2R   icvSampleLine_32f_C1R
-#define icvSampleLine_16u_C3R   0
-#define icvSampleLine_32s_C2R   icvSampleLine_32f_C2R
-#define icvSampleLine_32s_C3R   icvSampleLine_32f_C3R
-#define icvSampleLine_64s_C2R   0
-#define icvSampleLine_64s_C3R   0
-#define icvSampleLine_64s_C4R   0
-
-
-static CvStatus  icvSampleLine( CvLineIterator* iterator, void* buffer,
-                                int count, int pix_size )
-{
-    for( int i = 0; i < count; i++ )
-    {
-        memcpy( buffer, iterator->ptr, pix_size );
-        (char*&)buffer += pix_size;
-        CV_NEXT_LINE_POINT( *iterator );
-    }
-
-    return CV_OK;
-}
-
-
-CV_DEF_INIT_PIXSIZE_TAB_2D( SampleLine, R )
-
-typedef  CvStatus (*CvLineFunc)( CvLineIterator* iterator, void* buffer, int count );
-
 CV_IMPL int
 cvSampleLine( const void* img, CvPoint pt1, CvPoint pt2,
               void* buffer, int connectivity )
 {
-    static  CvBtFuncTable  sl_tab;
-    static  int inittab = 1;
     int count = -1;
     
     CV_FUNCNAME( "cvSampleLine" );
 
     __BEGIN__;
     
-    int coi = 0, pix_size;
+    int i, coi = 0, pix_size;
     CvMat stub, *mat = (CvMat*)img;
     CvLineIterator iterator;
-    CvLineFunc func = 0;
-
-    if( !inittab )
-    {
-        icvInitSampleLineRTable( &sl_tab );
-        inittab = 1;
-    }
 
     CV_CALL( mat = cvGetMat( mat, &stub, &coi ));
 
@@ -245,16 +159,12 @@ cvSampleLine( const void* img, CvPoint pt1, CvPoint pt2,
 
     CV_CALL( count = cvInitLineIterator( mat, pt1, pt2, &iterator, connectivity ));
 
-    pix_size = icvPixSize[CV_MAT_TYPE(mat->type)];
-    func = (CvLineFunc)sl_tab.fn_2d[pix_size];
-
-    if( func )
-    {
-        IPPI_CALL( func( &iterator, buffer, count ));
-    }
-    else
+    pix_size = CV_ELEM_SIZE(mat->type);
+    for( i = 0; i < count; i++ )
     {
-        icvSampleLine( &iterator, buffer, count, pix_size );
+        CV_MEMCPY_AUTO( buffer, iterator.ptr, pix_size );
+        (char*&)buffer += pix_size;
+        CV_NEXT_LINE_POINT( iterator );
     }
 
     __END__;
@@ -322,23 +232,31 @@ icvAdjustRect( const void* srcptr, int src_step, int pix_size,
 
 
 #define  ICV_DEF_GET_RECT_SUB_PIX_FUNC( flavor, srctype, dsttype, worktype, \
-                                        cast_macro, scale_macro, mul_macro )\
+                                        cast_macro, scale_macro, cast_macro2 )\
 IPCVAPI_IMPL( CvStatus, icvGetRectSubPix_##flavor##_C1R,                    \
 ( const srctype* src, int src_step, CvSize src_size,                        \
-  dsttype* dst, int dst_step, CvSize win_size, CvPoint2D32f center ))       \
+  dsttype* dst, int dst_step, CvSize win_size, CvPoint2D32f center ),       \
+  (src, src_step, src_size, dst, dst_step, win_size, center) )              \
 {                                                                           \
     CvPoint ip;                                                             \
-    worktype a, b;                                                          \
+    worktype  a11, a12, a21, a22, b1, b2;                                   \
+    float a, b;                                                             \
     int i, j;                                                               \
                                                                             \
-    center.x -= (win_size.width - 1)*0.5f;                                  \
-    center.y -= (win_size.height - 1)*0.5f;                                 \
+    center.x -= (win_size.width-1)*0.5f;                                    \
+    center.y -= (win_size.height-1)*0.5f;                                   \
                                                                             \
     ip.x = cvFloor( center.x );                                             \
     ip.y = cvFloor( center.y );                                             \
                                                                             \
-    a = scale_macro( center.x - ip.x );                                     \
-    b = scale_macro( center.y - ip.y );                                     \
+    a = center.x - ip.x;                                                    \
+    b = center.y - ip.y;                                                    \
+    a11 = scale_macro((1.f-a)*(1.f-b));                                     \
+    a12 = scale_macro(a*(1.f-b));                                           \
+    a21 = scale_macro((1.f-a)*b);                                           \
+    a22 = scale_macro(a*b);                                                 \
+    b1 = scale_macro(1.f - b);                                              \
+    b2 = scale_macro(b);                                                    \
                                                                             \
     src_step /= sizeof( src[0] );                                           \
                                                                             \
@@ -351,15 +269,29 @@ IPCVAPI_IMPL( CvStatus, icvGetRectSubPix_##flavor##_C1R,                    \
         for( i = 0; i < win_size.height; i++, src += src_step,              \
                                               (char*&)dst += dst_step )     \
         {                                                                   \
-            for( j = 0; j < win_size.width; j++ )                           \
+            for( j = 0; j <= win_size.width - 2; j += 2 )                   \
             {                                                               \
-                worktype s0 = cast_macro(src[j]);                           \
-                worktype s1 = cast_macro(src[j + src_step]);                \
+                worktype s0 = cast_macro(src[j])*a11 +                      \
+                              cast_macro(src[j+1])*a12 +                    \
+                              cast_macro(src[j+src_step])*a21 +             \
+                              cast_macro(src[j+src_step+1])*a22;            \
+                worktype s1 = cast_macro(src[j+1])*a11 +                    \
+                              cast_macro(src[j+2])*a12 +                    \
+                              cast_macro(src[j+src_step+1])*a21 +           \
+                              cast_macro(src[j+src_step+2])*a22;            \
+                                                                            \
+                dst[j] = (dsttype)cast_macro2(s0);                          \
+                dst[j+1] = (dsttype)cast_macro2(s1);                        \
+            }                                                               \
                                                                             \
-                s0 += mul_macro( a, (cast_macro(src[j + 1]) - s0));         \
-                s1 += mul_macro( a, (cast_macro(src[j+src_step+1]) - s1));  \
+            for( ; j < win_size.width; j++ )                                \
+            {                                                               \
+                worktype s0 = cast_macro(src[j])*a11 +                      \
+                              cast_macro(src[j+1])*a12 +                    \
+                              cast_macro(src[j+src_step])*a21 +             \
+                              cast_macro(src[j+src_step+1])*a22;            \
                                                                             \
-                dst[j] = (dsttype)(s0 + mul_macro( b, (s1 - s0)));          \
+                dst[j] = (dsttype)cast_macro2(s0);                          \
             }                                                               \
         }                                                                   \
     }                                                                       \
@@ -379,29 +311,28 @@ IPCVAPI_IMPL( CvStatus, icvGetRectSubPix_##flavor##_C1R,                    \
                                                                             \
             for( j = 0; j < r.x; j++ )                                      \
             {                                                               \
-                worktype s0 = cast_macro(src[r.x]);                         \
-                worktype s1 = cast_macro(src2[r.x]);                        \
+                worktype s0 = cast_macro(src[r.x])*b1 +                     \
+                              cast_macro(src2[r.x])*b2;                     \
                                                                             \
-                dst[j] = (dsttype)(s0 + mul_macro( b, (s1 - s0)));          \
+                dst[j] = (dsttype)cast_macro2(s0);                          \
             }                                                               \
                                                                             \
             for( ; j < r.width; j++ )                                       \
             {                                                               \
-                worktype s0 = cast_macro(src[j]);                           \
-                worktype s1 = cast_macro(src2[j]);                          \
+                worktype s0 = cast_macro(src[j])*a11 +                      \
+                              cast_macro(src[j+1])*a12 +                    \
+                              cast_macro(src2[j])*a21 +                     \
+                              cast_macro(src2[j+1])*a22;                    \
                                                                             \
-                s0 += mul_macro( a, (cast_macro(src[j + 1]) - s0));         \
-                s1 += mul_macro( a, (cast_macro(src2[j + 1]) - s1));        \
-                                                                            \
-                dst[j] = (dsttype)(s0 + mul_macro( b, (s1 - s0)));          \
+                dst[j] = (dsttype)cast_macro2(s0);                          \
             }                                                               \
                                                                             \
             for( ; j < win_size.width; j++ )                                \
             {                                                               \
-                worktype s0 = cast_macro(src[r.width]);                     \
-                worktype s1 = cast_macro(src2[r.width]);                    \
+                worktype s0 = cast_macro(src[r.width])*b1 +                 \
+                              cast_macro(src2[r.width])*b2;                 \
                                                                             \
-                dst[j] = (dsttype)(s0 + mul_macro( b, (s1 - s0)));          \
+                dst[j] = (dsttype)cast_macro2(s0);                          \
             }                                                               \
                                                                             \
             if( i < r.height )                                              \
@@ -417,14 +348,15 @@ IPCVAPI_IMPL( CvStatus, icvGetRectSubPix_##flavor##_C1R,                    \
                                         cast_macro, scale_macro, mul_macro )\
 IPCVAPI_IMPL( CvStatus, icvGetRectSubPix_##flavor##_C3R,                    \
 ( const srctype* src, int src_step, CvSize src_size,                        \
-  dsttype* dst, int dst_step, CvSize win_size, CvPoint2D32f center ))       \
+  dsttype* dst, int dst_step, CvSize win_size, CvPoint2D32f center ),       \
+  (src, src_step, src_size, dst, dst_step, win_size, center) )              \
 {                                                                           \
     CvPoint ip;                                                             \
     worktype a, b;                                                          \
     int i, j;                                                               \
                                                                             \
-    center.x -= (win_size.width - 1)*0.5f;                                  \
-    center.y -= (win_size.height - 1)*0.5f;                                 \
+    center.x -= (win_size.width-1)*0.5f;                                    \
+    center.y -= (win_size.height-1)*0.5f;                                   \
                                                                             \
     ip.x = cvFloor( center.x );                                             \
     ip.y = cvFloor( center.y );                                             \
@@ -542,11 +474,11 @@ IPCVAPI_IMPL( CvStatus, icvGetRectSubPix_##flavor##_C3R,                    \
 #define ICV_SHIFT             16
 #define ICV_SCALE(x)          cvRound((x)*(1 << ICV_SHIFT))
 #define ICV_MUL_SCALE(x,y)    (((x)*(y) + (1 << (ICV_SHIFT-1))) >> ICV_SHIFT)
+#define ICV_DESCALE(x)        (((x)+(1 << (ICV_SHIFT-1))) >> ICV_SHIFT)
 
-
-ICV_DEF_GET_RECT_SUB_PIX_FUNC( 8u, uchar, uchar, int, CV_NOP, ICV_SCALE, ICV_MUL_SCALE )
-ICV_DEF_GET_RECT_SUB_PIX_FUNC( 32f, float, float, float, CV_NOP, CV_NOP, CV_MUL )
-ICV_DEF_GET_RECT_SUB_PIX_FUNC( 8u32f, uchar, float, float, CV_8TO32F, CV_NOP, CV_MUL )
+ICV_DEF_GET_RECT_SUB_PIX_FUNC( 8u, uchar, uchar, int, CV_NOP, ICV_SCALE, ICV_DESCALE )
+ICV_DEF_GET_RECT_SUB_PIX_FUNC( 32f, float, float, float, CV_NOP, CV_NOP, CV_NOP )
+ICV_DEF_GET_RECT_SUB_PIX_FUNC( 8u32f, uchar, float, float, CV_8TO32F, CV_NOP, CV_NOP )
 
 ICV_DEF_GET_RECT_SUB_PIX_FUNC_C3( 8u, uchar, uchar, int, CV_NOP, ICV_SCALE, ICV_MUL_SCALE )
 ICV_DEF_GET_RECT_SUB_PIX_FUNC_C3( 32f, float, float, float, CV_NOP, CV_NOP, CV_MUL )
@@ -604,8 +536,8 @@ cvGetRectSubPix( const void* srcarr, void* dstarr, CvPoint2D32f center )
     if( (cn != 1 && cn != 3) || !CV_ARE_CNS_EQ( src, dst ))
         CV_ERROR( CV_StsUnsupportedFormat, "" );
 
-    src_size = icvGetMatSize( src );
-    dst_size = icvGetMatSize( dst );
+    src_size = cvGetMatSize( src );
+    dst_size = cvGetMatSize( dst );
 
     if( dst_size.width > src_size.width || dst_size.height > src_size.height )
         CV_ERROR( CV_StsBadSize, "destination ROI must be smaller than source ROI" );
@@ -634,7 +566,7 @@ cvGetRectSubPix( const void* srcarr, void* dstarr, CvPoint2D32f center )
 
 #define GET_X(X,Y)  ((X)*A11 + (Y)*A12 + b1)
 #define GET_Y(X,Y)  ((X)*A21 + (Y)*A22 + b2)
-#define PTR_AT(X,Y) (src + (Y)*srcStep + (X))
+#define PTR_AT(X,Y) (src + (Y)*src_step + (X))
 
 #define CLIP_X(x) (unsigned)(x) < (unsigned)src_size.width ?  \
                   (x) : (x) < 0 ? 0 : src_size.width - 1
@@ -646,24 +578,26 @@ cvGetRectSubPix( const void* srcarr, void* dstarr, CvPoint2D32f center )
 #define ICV_DEF_GET_QUADRANGLE_SUB_PIX_FUNC( flavor, srctype, dsttype,      \
                                              worktype, cast_macro, cvt )    \
 IPCVAPI_IMPL( CvStatus, icvGetQuadrangleSubPix_##flavor##_C1R,              \
-              ( const srctype * src, int srcStep, CvSize src_size,          \
-                dsttype *dst, int dstStep, CvSize win_size,                 \
+              ( const srctype * src, int src_step, CvSize src_size,         \
+                dsttype *dst, int dst_step, CvSize win_size,                \
                 const float *matrix, int fill_outliers,                     \
-                dsttype* fillval ))                                         \
+                dsttype* fillval ),                                         \
+                (src, src_step, src_size, dst, dst_step, win_size,          \
+                matrix, fill_outliers, fillval) )                           \
 {                                                                           \
     int x, y, x0, y0, x1, y1;                                               \
-    float  A11 = matrix[0], A12 = matrix[1], b1 = matrix[2];                \
-    float  A21 = matrix[3], A22 = matrix[4], b2 = matrix[5];                \
+    float  A11 = matrix[0], A12 = matrix[1], b1 = matrix[2] - 0.5f;         \
+    float  A21 = matrix[3], A22 = matrix[4], b2 = matrix[5] - 0.5f;         \
     dsttype fv = *fillval;                                                  \
     int left = -(win_size.width >> 1), right = win_size.width + left - 1;   \
     int top = -(win_size.height >> 1), bottom = win_size.height + top - 1;  \
                                                                             \
-    srcStep /= sizeof(srctype);                                             \
-    dstStep /= sizeof(dsttype);                                             \
+    src_step /= sizeof(srctype);                                            \
+    dst_step /= sizeof(dsttype);                                            \
                                                                             \
     dst -= left;                                                            \
                                                                             \
-    for( y = top; y <= bottom; y++, dst += dstStep )                        \
+    for( y = top; y <= bottom; y++, dst += dst_step )                       \
     {                                                                       \
         float xs = GET_X( left, y );                                        \
         float ys = GET_Y( left, y );                                        \
@@ -691,8 +625,8 @@ IPCVAPI_IMPL( CvStatus, icvGetQuadrangleSubPix_##flavor##_C1R,              \
                 ys += A21;                                                  \
                                                                             \
                 p0 = cvt(ptr[0]) + a * (cvt(ptr[1]) - cvt(ptr[0]));         \
-                p1 = cvt(ptr[srcStep]) + a * (cvt(ptr[srcStep + 1]) -       \
-                                              cvt(ptr[srcStep]));           \
+                p1 = cvt(ptr[src_step]) + a * (cvt(ptr[src_step + 1]) -     \
+                                              cvt(ptr[src_step]));          \
                 dst[x] = cast_macro(p0 + b * (p1 - p0));                    \
             }                                                               \
         }                                                                   \
@@ -718,8 +652,8 @@ IPCVAPI_IMPL( CvStatus, icvGetQuadrangleSubPix_##flavor##_C1R,              \
                     const srctype *ptr = PTR_AT( ixs, iys );                \
                                                                             \
                     p0 = cvt(ptr[0]) + a * (cvt(ptr[1]) - cvt(ptr[0]));     \
-                    p1 = cvt(ptr[srcStep]) + a * (cvt(ptr[srcStep + 1]) -   \
-                                                  cvt(ptr[srcStep]));       \
+                    p1 = cvt(ptr[src_step]) + a * (cvt(ptr[src_step + 1]) - \
+                                                  cvt(ptr[src_step]));      \
                                                                             \
                     dst[x] = cast_macro(p0 + b * (p1 - p0));                \
                 }                                                           \
@@ -756,25 +690,27 @@ IPCVAPI_IMPL( CvStatus, icvGetQuadrangleSubPix_##flavor##_C1R,              \
 
 
 #define ICV_DEF_GET_QUADRANGLE_SUB_PIX_FUNC_C3( flavor, srctype, dsttype,   \
-                                             worktype, cast_macro, cvt )    \
+                                                worktype, cast_macro, cvt ) \
 IPCVAPI_IMPL( CvStatus, icvGetQuadrangleSubPix_##flavor##_C3R,              \
-              ( const srctype * src, int srcStep, CvSize src_size,          \
-                dsttype *dst, int dstStep, CvSize win_size,                 \
+              ( const srctype * src, int src_step, CvSize src_size,         \
+                dsttype *dst, int dst_step, CvSize win_size,                \
                 const float *matrix, int fill_outliers,                     \
-                dsttype* fillval ))                                         \
+                dsttype* fillval ),                                         \
+                (src, src_step, src_size, dst, dst_step, win_size,          \
+                matrix, fill_outliers, fillval) )                           \
 {                                                                           \
     int x, y, x0, y0, x1, y1;                                               \
-    float  A11 = matrix[0], A12 = matrix[1], b1 = matrix[2];                \
-    float  A21 = matrix[3], A22 = matrix[4], b2 = matrix[5];                \
+    float  A11 = matrix[0], A12 = matrix[1], b1 = matrix[2] - 0.5f;         \
+    float  A21 = matrix[3], A22 = matrix[4], b2 = matrix[5] - 0.5f;         \
     int left = -(win_size.width >> 1), right = win_size.width + left - 1;   \
     int top = -(win_size.height >> 1), bottom = win_size.height + top - 1;  \
                                                                             \
-    srcStep /= sizeof(srctype);                                             \
-    dstStep /= sizeof(dsttype);                                             \
+    src_step /= sizeof(srctype);                                            \
+    dst_step /= sizeof(dsttype);                                            \
                                                                             \
     dst -= left*3;                                                          \
                                                                             \
-    for( y = top; y <= bottom; y++, dst += dstStep )                        \
+    for( y = top; y <= bottom; y++, dst += dst_step )                       \
     {                                                                       \
         float xs = GET_X( left, y );                                        \
         float ys = GET_Y( left, y );                                        \
@@ -802,18 +738,18 @@ IPCVAPI_IMPL( CvStatus, icvGetQuadrangleSubPix_##flavor##_C3R,              \
                 ys += A21;                                                  \
                                                                             \
                 p0 = cvt(ptr[0]) + a * (cvt(ptr[3]) - cvt(ptr[0]));         \
-                p1 = cvt(ptr[srcStep]) + a * (cvt(ptr[srcStep + 3]) -       \
-                                              cvt(ptr[srcStep]));           \
+                p1 = cvt(ptr[src_step]) + a * (cvt(ptr[src_step + 3]) -     \
+                                              cvt(ptr[src_step]));          \
                 dst[x*3] = cast_macro(p0 + b * (p1 - p0));                  \
                                                                             \
                 p0 = cvt(ptr[1]) + a * (cvt(ptr[4]) - cvt(ptr[1]));         \
-                p1 = cvt(ptr[srcStep+1]) + a * (cvt(ptr[srcStep + 4]) -     \
-                                                cvt(ptr[srcStep + 1]));     \
+                p1 = cvt(ptr[src_step+1]) + a * (cvt(ptr[src_step + 4]) -   \
+                                                cvt(ptr[src_step + 1]));    \
                 dst[x*3+1] = cast_macro(p0 + b * (p1 - p0));                \
                                                                             \
                 p0 = cvt(ptr[2]) + a * (cvt(ptr[5]) - cvt(ptr[2]));         \
-                p1 = cvt(ptr[srcStep+2]) + a * (cvt(ptr[srcStep + 5]) -     \
-                                                cvt(ptr[srcStep + 2]));     \
+                p1 = cvt(ptr[src_step+2]) + a * (cvt(ptr[src_step + 5]) -   \
+                                                cvt(ptr[src_step + 2]));    \
                 dst[x*3+2] = cast_macro(p0 + b * (p1 - p0));                \
             }                                                               \
         }                                                                   \
@@ -839,18 +775,18 @@ IPCVAPI_IMPL( CvStatus, icvGetQuadrangleSubPix_##flavor##_C3R,              \
                     const srctype *ptr = PTR_AT( ixs*3, iys );              \
                                                                             \
                     p0 = cvt(ptr[0]) + a * (cvt(ptr[3]) - cvt(ptr[0]));     \
-                    p1 = cvt(ptr[srcStep]) + a * (cvt(ptr[srcStep + 3]) -   \
-                                                         cvt(ptr[srcStep]));\
+                    p1 = cvt(ptr[src_step]) + a * (cvt(ptr[src_step + 3]) - \
+                                                   cvt(ptr[src_step]));     \
                     dst[x*3] = cast_macro(p0 + b * (p1 - p0));              \
                                                                             \
                     p0 = cvt(ptr[1]) + a * (cvt(ptr[4]) - cvt(ptr[1]));     \
-                    p1 = cvt(ptr[srcStep+1]) + a * (cvt(ptr[srcStep + 4]) - \
-                                                    cvt(ptr[srcStep + 1])); \
+                    p1 = cvt(ptr[src_step+1]) + a * (cvt(ptr[src_step + 4])-\
+                                                    cvt(ptr[src_step + 1]));\
                     dst[x*3+1] = cast_macro(p0 + b * (p1 - p0));            \
                                                                             \
                     p0 = cvt(ptr[2]) + a * (cvt(ptr[5]) - cvt(ptr[2]));     \
-                    p1 = cvt(ptr[srcStep+2]) + a * (cvt(ptr[srcStep + 5]) - \
-                                                    cvt(ptr[srcStep + 2])); \
+                    p1 = cvt(ptr[src_step+2]) + a * (cvt(ptr[src_step + 5])-\
+                                                    cvt(ptr[src_step + 2]));\
                     dst[x*3+2] = cast_macro(p0 + b * (p1 - p0));            \
                 }                                                           \
                 else if( !fill_outliers )                                   \
@@ -929,7 +865,7 @@ typedef CvStatus (CV_STDCALL *CvGetQuadrangleSubPixFunc)(
 
 CV_IMPL void
 cvGetQuadrangleSubPix( const void* srcarr, void* dstarr,
-                       const void* matrix, int fillOutliers,
+                       const CvMat* mat, int fillOutliers,
                        CvScalar fillValue )
 {
     static  CvFuncTable  gq_tab[2];
@@ -940,7 +876,6 @@ cvGetQuadrangleSubPix( const void* srcarr, void* dstarr,
 
     CvMat srcstub, *src = (CvMat*)srcarr;
     CvMat dststub, *dst = (CvMat*)dstarr;
-    CvMat matstub, *mat = (CvMat*)matrix;
     CvSize src_size, dst_size;
     CvGetQuadrangleSubPixFunc func;
     double buf[12];
@@ -960,15 +895,15 @@ cvGetQuadrangleSubPix( const void* srcarr, void* dstarr,
         CV_CALL( dst = cvGetMat( dst, &dststub ));
 
     if( !CV_IS_MAT(mat))
-        CV_CALL( mat = cvGetMat( mat, &matstub ));
+        CV_ERROR( CV_StsBadArg, "map matrix is not valid" );
 
     cn = CV_MAT_CN( src->type );
 
     if( (cn != 1 && cn != 3) || !CV_ARE_CNS_EQ( src, dst ))
         CV_ERROR( CV_StsUnsupportedFormat, "" );
 
-    src_size = icvGetMatSize( src );
-    dst_size = icvGetMatSize( dst );
+    src_size = cvGetMatSize( src );
+    dst_size = cvGetMatSize( dst );
 
     /*if( dst_size.width > src_size.width || dst_size.height > src_size.height )
         CV_ERROR( CV_StsBadSize, "destination ROI must not be larger than source ROI" );*/
index 3c6cf6c491f724cac2bf9566a73f5334e6161c99..42ff51ac094bc1c4af5e8282abe777b920016113 100644 (file)
@@ -39,8 +39,6 @@
 //
 //M*/
 #include "_cv.h"
-#include "_cvdatastructs.h"
-#include "_cvgeom.h"
 
 /* calculates length of a curve (e.g. contour perimeter) */
 CV_IMPL  double
@@ -54,7 +52,8 @@ cvArcLength( const void *array, CvSlice slice, int is_closed )
 
     int i, j = 0, count;
     const int N = 16;
-    float buffer[N];
+    float buf[N];
+    CvMat buffer = cvMat( 1, N, CV_32F, buf ); 
     CvSeqReader reader;
     CvContour contour_header;
     CvSeq* contour = 0;
@@ -78,17 +77,17 @@ cvArcLength( const void *array, CvSlice slice, int is_closed )
 
     if( contour->total > 1 )
     {
-        CvPoint pt1, pt2;
         int is_float = CV_SEQ_ELTYPE( contour ) == CV_32FC2;
         
         cvStartReadSeq( contour, &reader, 0 );
-        cvSetSeqReaderPos( &reader, slice.startIndex );
-        count = icvSliceLength( slice, contour );
+        cvSetSeqReaderPos( &reader, slice.start_index );
+        count = cvSliceLength( slice, contour );
 
         count -= !is_closed && count == contour->total;
 
         /* scroll the reader by 1 point */
-        CV_READ_EDGE( pt1, pt2, reader );
+        reader.prev_elem = reader.ptr;
+        CV_NEXT_SEQ_ELEM( sizeof(CvPoint), reader );
 
         for( i = 0; i < count; i++ )
         {
@@ -114,12 +113,13 @@ cvArcLength( const void *array, CvSlice slice, int is_closed )
             reader.prev_elem = reader.ptr;
             CV_NEXT_SEQ_ELEM( contour->elem_size, reader );
 
-            buffer[j] = dx * dx + dy * dy;
+            buffer.data.fl[j] = dx * dx + dy * dy;
             if( ++j == N || i == count - 1 )
             {
-                icvbSqrt_32f( buffer, buffer, j );
+                buffer.cols = j;
+                cvPow( &buffer, &buffer, 0.5 );
                 for( ; j > 0; j-- )
-                    perimeter += buffer[j-1];
+                    perimeter += buffer.data.fl[j-1];
             }
         }
     }
@@ -163,8 +163,15 @@ icvFindCircle( CvPoint2D32f pt0, CvPoint2D32f pt1,
 }
 
 
+CV_INLINE double icvIsPtInCircle( CvPoint2D32f pt, CvPoint2D32f center, float radius )
+{
+    double dx = pt.x - center.x;
+    double dy = pt.y - center.y;
+    return (double)radius*radius - dx*dx - dy*dy;
+}
 
-int
+
+static int
 icvFindEnslosingCicle4pts_32f( CvPoint2D32f * pts, CvPoint2D32f * _center, float *_radius )
 {
     int shuffles[4][4] = { {0, 1, 2, 3}, {0, 1, 3, 2}, {2, 3, 0, 1}, {2, 3, 1, 0} };
@@ -207,14 +214,14 @@ icvFindEnslosingCicle4pts_32f( CvPoint2D32f * pts, CvPoint2D32f * _center, float
     }
 
     center = icvMidPoint( pts[idxs[0]], pts[idxs[1]] );
-    radius = (float) (icvDistanceL2_32f( pts[idxs[0]], center ) * (1 + 0.03));
+    radius = (float)(icvDistanceL2_32f( pts[idxs[0]], center )*1.03);
     if( radius < 1.f )
         radius = 1.f;
 
-    if( icvIsPtInCircle( pts[idxs[2]], center, radius ) &&
-        icvIsPtInCircle( pts[idxs[3]], center, radius ))
+    if( icvIsPtInCircle( pts[idxs[2]], center, radius ) >= 0 &&
+        icvIsPtInCircle( pts[idxs[3]], center, radius ) >= 0 )
     {
-        k = 2;
+        k = 2; //rand()%2+2;
     }
     else
     {
@@ -228,7 +235,7 @@ icvFindEnslosingCicle4pts_32f( CvPoint2D32f * pts, CvPoint2D32f * _center, float
                 if( radius < 2.f )
                     radius = 2.f;
 
-                if( icvIsPtInCircle( pts[shuffles[i][3]], center, radius ) &&
+                if( icvIsPtInCircle( pts[shuffles[i][3]], center, radius ) >= 0 &&
                     min_radius > radius )
                 {
                     min_radius = radius;
@@ -254,25 +261,25 @@ icvFindEnslosingCicle4pts_32f( CvPoint2D32f * pts, CvPoint2D32f * _center, float
 
     /* reorder output points */
     for( i = 0; i < 4; i++ )
-    {
         res_pts[i] = pts[idxs[i]];
-    }
 
     for( i = 0; i < 4; i++ )
     {
         pts[i] = res_pts[i];
+        assert( icvIsPtInCircle( pts[i], center, radius ) >= 0 );
     }
 
     return k;
 }
 
 
-CV_IMPL void
+CV_IMPL int
 cvMinEnclosingCircle( const void* array, CvPoint2D32f * _center, float *_radius )
 {
-    const int max_iters = 20;
+    const int max_iters = 100;
     CvPoint2D32f center = { 0, 0 };
     float radius = 0;
+    int result = 0;
 
     if( _center )
         _center->x = _center->y = 0.f;
@@ -371,6 +378,8 @@ cvMinEnclosingCircle( const void* array, CvPoint2D32f * _center, float *_radius
 
     for( k = 0; k < max_iters; k++ )
     {
+        double min_delta = 0, delta;
+        
         icvFindEnslosingCicle4pts_32f( pts, &center, &radius );
         cvStartReadSeq( sequence, &reader, 0 );
 
@@ -389,13 +398,16 @@ cvMinEnclosingCircle( const void* array, CvPoint2D32f * _center, float *_radius
             }
             CV_NEXT_SEQ_ELEM( sequence->elem_size, reader );
 
-            if( !icvIsPtInCircle( ptfl, center, radius ))
+            delta = icvIsPtInCircle( ptfl, center, radius );
+            if( delta < min_delta )
             {
                 pts[3] = ptfl;
-                break;
+                min_delta = delta;
+                //break;
             }
         }
-        if( i == count )
+        result = min_delta >= 0;
+        if( result )
             break;
     }
 
@@ -403,6 +415,8 @@ cvMinEnclosingCircle( const void* array, CvPoint2D32f * _center, float *_radius
 
     *_center = center;
     *_radius = radius;
+
+    return result;
 }
 
 
@@ -480,7 +494,7 @@ icvMemCopy( double **buf1, double **buf2, double **buf3, int *b_max )
     if( *buf2 == NULL )
     {
         *b_max = 2 * (*b_max);
-        *buf2 = (double *) icvAlloc( (*b_max) * sizeof( double ));
+        *buf2 = (double *)cvAlloc( (*b_max) * sizeof( double ));
 
         if( *buf2 == NULL )
             return CV_OUTOFMEM_ERR;
@@ -488,13 +502,13 @@ icvMemCopy( double **buf1, double **buf2, double **buf3, int *b_max )
         memcpy( *buf2, *buf3, bb * sizeof( double ));
 
         *buf3 = *buf2;
-        icvFree( &(*buf1) );
+        cvFree( (void**)buf1 );
         *buf1 = NULL;
     }
     else
     {
         *b_max = 2 * (*b_max);
-        *buf1 = (double *) icvAlloc( (*b_max) * sizeof( double ));
+        *buf1 = (double *) cvAlloc( (*b_max) * sizeof( double ));
 
         if( *buf1 == NULL )
             return CV_OUTOFMEM_ERR;
@@ -502,7 +516,7 @@ icvMemCopy( double **buf1, double **buf2, double **buf3, int *b_max )
         memcpy( *buf1, *buf3, bb * sizeof( double ));
 
         *buf3 = *buf1;
-        icvFree( &(*buf2) );
+        cvFree( (void**)buf2 );
         *buf2 = NULL;
     }
     return CV_OK;
@@ -532,7 +546,7 @@ static CvStatus icvContourSecArea( CvSeq * contour, CvSlice slice, double *area
     if( !CV_IS_SEQ_POLYGON( contour ))
         return CV_BADFLAG_ERR;
 
-    lpt = icvSliceLength( slice, contour );
+    lpt = cvSliceLength( slice, contour );
     /*if( n2 >= n1 )
         lpt = n2 - n1 + 1;
     else
@@ -544,7 +558,7 @@ static CvStatus icvContourSecArea( CvSeq * contour, CvSlice slice, double *area
         sk1 = 0;
         flag = 0;
         dxy = 0;
-        p_are1 = (double *) icvAlloc( p_max * sizeof( double ));
+        p_are1 = (double *) cvAlloc( p_max * sizeof( double ));
 
         if( p_are1 == NULL )
             return CV_OUTOFMEM_ERR;
@@ -553,16 +567,16 @@ static CvStatus icvContourSecArea( CvSeq * contour, CvSlice slice, double *area
         p_are2 = NULL;
 
         cvStartReadSeq( contour, &reader, 0 );
-        cvSetSeqReaderPos( &reader, slice.startIndex );
+        cvSetSeqReaderPos( &reader, slice.start_index );
         CV_READ_SEQ_ELEM( pt_s, reader );
         p_ind = 0;
-        cvSetSeqReaderPos( &reader, slice.endIndex );
+        cvSetSeqReaderPos( &reader, slice.end_index );
         CV_READ_SEQ_ELEM( pt_e, reader );
 
 /*    normal coefficients    */
         nx = pt_s.y - pt_e.y;
         ny = pt_e.x - pt_s.x;
-        cvSetSeqReaderPos( &reader, slice.startIndex );
+        cvSetSeqReaderPos( &reader, slice.start_index );
 
         while( lpt-- > 0 )
         {
@@ -667,9 +681,9 @@ static CvStatus icvContourSecArea( CvSeq * contour, CvSlice slice, double *area
             (*area) += fabs( p_are[i] );
 
         if( p_are1 != NULL )
-            icvFree( &p_are1 );
+            cvFree( (void**)&p_are1 );
         else if( p_are2 != NULL )
-            icvFree( &p_are2 );
+            cvFree( (void**)&p_are2 );
 
         return CV_OK;
     }
@@ -704,7 +718,7 @@ cvContourArea( const void *array, CvSlice slice )
             CV_SEQ_KIND_CURVE, array, &contour_header, &block ));
     }
 
-    if( icvSliceLength( slice, contour ) == contour->total )
+    if( cvSliceLength( slice, contour ) == contour->total )
     {
         IPPI_CALL( icvContourArea( contour, &area ));
     }
@@ -812,8 +826,7 @@ static CvStatus icvFitEllipse_32f( CvSeq* points, CvBox2D* box )
     }
 
     /* compute S */
-    status1 = icvMulTransMatrixR_32f( D, 6, n, S );
-    assert( status1 == CV_OK );
+    icvMulTransMatrixR_32f( D, 6, n, S );
 
     /* fill matrix C */
     icvSetZero_32f( C, 6, 6 );
@@ -827,24 +840,16 @@ static CvStatus icvFitEllipse_32f( CvSeq* points, CvBox2D* box )
 
     //avoid troubles with small negative values
     for( i = 0; i < 6; i++ )
-       eigenvalues[i] = (float)fabs( eigenvalues[i] ); 
-
-    /* compute sqrt of every eigenvalue; they all must be positive */
-    status1 = icvbSqrt_32f( eigenvalues, eigenvalues, 6 );
-    assert( status1 == CV_OK );
+        eigenvalues[i] = (float)fabs(eigenvalues[i]);
 
-    /* compute inverse of Q */
-    status1 = icvbInvSqrt_32f( eigenvalues, eigenvalues, 6 );
-    assert( status1 == CV_OK );
+    cvbSqrt( eigenvalues, eigenvalues, 6 );
+    cvbInvSqrt( eigenvalues, eigenvalues, 6 );
 
     for( i = 0; i < 6; i++ )
-    {
         icvScaleVector_32f( &INVEIGV[i * 6], &INVEIGV[i * 6], 6, eigenvalues[i] );
-    }
 
     // INVQ = transp(INVEIGV) * INVEIGV
-    status1 = icvMulTransMatrixR_32f( INVEIGV, 6, 6, INVQ );
-    assert( status1 == CV_OK );
+    icvMulTransMatrixR_32f( INVEIGV, 6, 6, INVQ );
     
     /* create matrix INVQ*C*INVQ */
     icvMulMatrix_32f( INVQ, 6, 6, C, 6, 6, TMP1 );
@@ -963,7 +968,7 @@ static CvStatus icvFitEllipse_32f( CvSeq* points, CvBox2D* box )
     }
 
     /* calc angle */
-    box->angle = icvFastArctan32f( INVEIGV[3], INVEIGV[2] );
+    box->angle = cvFastArctan( INVEIGV[3], INVEIGV[2] );
 
 error:
 
@@ -1014,7 +1019,7 @@ cvFitEllipse2( const CvArr* array )
 
 /* Calculates bounding rectagnle of a point set or retrieves already calculated */
 CV_IMPL  CvRect
-cvBoundingRect( const void* array, int update )
+cvBoundingRect( CvArr* array, int update )
 {
     CvSeqReader reader;
     CvRect  rect = { 0, 0, 0, 0 };
index c0d1f2321258950e1cafb2a31da947f26006b4b5..8a97dc7a7ce2c44d4bb01582e9e8b3353e06a9e2 100644 (file)
                                     Initialization
 \****************************************************************************************/
 
-IPCVAPI_IMPL( CvStatus, icvFilterInitAlloc, (
+CvStatus CV_STDCALL icvFilterInitAlloc(
              int roiWidth, CvDataType dataType, int channels,
              CvSize elSize, CvPoint elAnchor,
              const void* elData, int elementType,
-             struct CvFilterState ** filterState ))
+             struct CvFilterState ** filterState )
 {
     CvFilterState *state = 0;
-    const int align = sizeof(long);
+    const int align = sizeof(size_t);
     int ker_size = 0;
     int buffer_step = 0;
     int buffer_size;
     int bt_pix, bt_pix_n;
-    int aligned_hdr_size = icvAlign((int)sizeof(*state),align);
+    int aligned_hdr_size = cvAlign((int)sizeof(*state),align);
     int temp_lines = dataType == cv8u ? 1 : 2;
     int binaryElement = ICV_KERNEL_TYPE(elementType) == ICV_BINARY_KERNEL;
     int separableElement = ICV_KERNEL_TYPE(elementType) == ICV_SEPARABLE_KERNEL;
@@ -88,14 +88,14 @@ IPCVAPI_IMPL( CvStatus, icvFilterInitAlloc, (
                    separableElement ? (elSize.width + elSize.height)*bt_pix :
                                       elSize.width * elSize.height * bt_pix;
 
-    buffer_step = icvAlign((roiWidth + elSize.width+1 + CV_MORPH_ALIGN*4)*bt_pix_n, align);
+    buffer_step = cvAlign((roiWidth + elSize.width+1 + CV_MORPH_ALIGN*4)*bt_pix_n, align);
 
     buffer_size = (elSize.height + temp_lines) * (buffer_step + sizeof(void*)) +
                   ker_size + aligned_hdr_size + elSize.width * bt_pix_n;
 
-    buffer_size = icvAlign(buffer_size + align, align);
+    buffer_size = cvAlign(buffer_size + align, align);
 
-    state = (CvFilterState*)icvAlloc( buffer_size );
+    state = (CvFilterState*)cvAlloc( buffer_size );
     if( !state )
         return CV_OUTOFMEM_ERR;
 
@@ -114,7 +114,7 @@ IPCVAPI_IMPL( CvStatus, icvFilterInitAlloc, (
     state->dataType = dataType;
     state->channels = channels;
     state->origin = 0;
-    ptr += icvAlign( aligned_hdr_size + elAnchor.x * bt_pix_n, CV_MORPH_ALIGN * bt_pix );
+    ptr += cvAlign( aligned_hdr_size + elAnchor.x * bt_pix_n, CV_MORPH_ALIGN * bt_pix );
 
     state->buffer = ptr;
     ptr += buffer_step * elSize.height;
@@ -135,14 +135,12 @@ IPCVAPI_IMPL( CvStatus, icvFilterInitAlloc, (
         if( binaryElement )
         {
             int i, mask_size = elSize.width * elSize.height;
-            state->ker1 = (uchar*)(ptr + (ker_size >> 1));
+            state->ker1 = 0;
 
             for( i = 0; i < mask_size; i++ )
             {
                 int t = ((int*)elData)[i] ? -1 : 0;
-
                 state->ker0[i] = (uchar)t;
-                state->ker1[i] = (uchar)~t;
             }
         }
         else
@@ -157,11 +155,11 @@ IPCVAPI_IMPL( CvStatus, icvFilterInitAlloc, (
 }
 
 
-IPCVAPI_IMPL( CvStatus, icvFilterFree, (CvFilterState ** filterState) )
+CvStatus CV_STDCALL icvFilterFree( CvFilterState ** filterState )
 {
     if( !filterState )
         return CV_NULLPTR_ERR;
-    icvFree( (void **) filterState );
+    cvFree( (void **) filterState );
     return CV_OK;
 }
 
@@ -170,7 +168,7 @@ IPCVAPI_IMPL( CvStatus, icvFilterFree, (CvFilterState ** filterState) )
 
 static CvStatus
 icvSmoothInitAlloc( int roiWidth, CvDataType /*dataType*/, int channels,
-                    CvSize elSize, int smoothtype,
+                    CvSize elSize, int smoothtype, double sigma,
                     struct CvFilterState** filterState )
 {
     static const float small_gaussian_tab[][SMALL_GAUSSIAN_SIZE] = 
@@ -190,30 +188,31 @@ icvSmoothInitAlloc( int roiWidth, CvDataType /*dataType*/, int channels,
         int i, n = elSize.width, m = elSize.height;
         float* dataY;
                 
-        dataX = (float*)alloca( (elSize.width + elSize.height)*sizeof(dataX[0]));
+        dataX = (float*)cvStackAlloc( (elSize.width + elSize.height)*sizeof(dataX[0]));
         dataY = dataX + elSize.width;
 
-        if( n <= SMALL_GAUSSIAN_SIZE )
+        if( n <= SMALL_GAUSSIAN_SIZE && sigma <= 0 )
         {
             assert( n%2 == 1 );
             memcpy( dataX, small_gaussian_tab[n>>1], n*sizeof(dataX[0]));
         }
         else
         {
-            double sigmaX = (n/2 - 1)*0.3 + 0.8;
-            double scaleX = 0.39894228040143267793994605993438/sigmaX;
+            double sigmaX = sigma > 0 ? sigma : (n/2 - 1)*0.3 + 0.8;
+            //double scaleX = 0.39894228040143267793994605993438/sigmaX;
             double scale2X = -0.5/(sigmaX*sigmaX);
-            double sumX;
-            sumX = dataX[n/2] = (float)scaleX;
+            double sumX = 1.;
+            sumX = dataX[n/2] = 1.f;
         
-            for( i = 1; i < (n+1)/2; i++ )
+            for( i = 1; i <= n/2; i++ )
             {
-                dataX[n/2+i] = dataX[n/2-i] = (float)(exp(scale2X*i*i)*scaleX);
+                dataX[n/2+i] = dataX[n/2-i] = (float)exp(scale2X*i*i);
                 sumX += dataX[n/2+i]*2;
             }
 
-            // adjust endpoints to make sum = 1
-            dataX[0] = dataX[n-1] = (float)(dataX[0] + (1 - sumX)*0.5);
+            sumX = 1./sumX;
+            for( i = 0; i <= n/2; i++ )
+                dataX[n/2+i] = dataX[n/2-i] = (float)(dataX[n/2+i]*sumX);
         }
 
         if( m == n )
@@ -227,7 +226,7 @@ icvSmoothInitAlloc( int roiWidth, CvDataType /*dataType*/, int channels,
         }
         else
         {
-            double sigmaY = (m/2 - 1)*0.3 + 0.8;
+            double sigmaY = sigma > 0 ? sigma : (m/2 - 1)*0.3 + 0.8;
             double scaleY = 0.39894228040143267793994605993438/sigmaY;
             double scale2Y = -0.5/(sigmaY*sigmaY);
             double sumY;
@@ -249,7 +248,6 @@ icvSmoothInitAlloc( int roiWidth, CvDataType /*dataType*/, int channels,
 
     status = icvFilterInitAlloc( roiWidth, cv32f, channels, elSize,
                                  elAnchor, dataX, ICV_SEPARABLE_KERNEL, filterState );
-
     if( status < 0 )
         return status;
 
@@ -258,7 +256,11 @@ icvSmoothInitAlloc( int roiWidth, CvDataType /*dataType*/, int channels,
         if( smoothtype == CV_BLUR )
             (*filterState)->divisor = elSize.width * elSize.height;
         else if( smoothtype == CV_GAUSSIAN )
+        {
             (*filterState)->divisor = (double)(1 << elSize.width) * (1 << elSize.height);
+            (*filterState)->kerType = ((*filterState)->kerType & ~255) |
+                (sigma > 0 ? ICV_CUSTOM_GAUSSIAN_KERNEL : ICV_DEFAULT_GAUSSIAN_KERNEL);
+        }
     }
 
     return filterState != 0 ? CV_OK : CV_NOTDEFINED_ERR;
@@ -276,15 +278,10 @@ icvSmoothFree( CvFilterState ** filterState )
                                       Simple Blur
 \****************************************************************************************/
 
-IPCVAPI( CvStatus,
-     icvBlur_8u_CnR, ( uchar* src, int srcStep,
-                       uchar* dst, int dstStep, CvSize * roiSize,
-                       CvFilterState* state, int stage ));
-
-IPCVAPI_IMPL( CvStatus,
-     icvBlur_8u_CnR, ( uchar* src, int srcStep,
-                       uchar* dst, int dstStep, CvSize * roiSize,
-                       CvFilterState* state, int stage ))
+static CvStatus CV_STDCALL
+icvBlur_8u_CnR( uchar* src, int srcStep,
+                uchar* dst, int dstStep, CvSize * roiSize,
+                CvFilterState* state, int stage )
 {
     int width = roiSize->width;
     int src_height = roiSize->height;
@@ -313,7 +310,7 @@ IPCVAPI_IMPL( CvStatus,
     int starting_flag = 0;
     int width_rest = width_n & (CV_MORPH_ALIGN - 1);
     int divisor = cvRound(state->divisor);
-    CvFastDiv fastdiv = icvFastDiv( divisor );
+    double inv_divisor = divisor ? 1./divisor : 0.;
 
     /* initialize cyclic buffer when starting */
     if( stage == CV_WHOLE || stage == CV_START )
@@ -369,17 +366,16 @@ IPCVAPI_IMPL( CvStatus,
                     CV_COPY( tbuf, src + width_n, ker_right_n, x );
                 }
 
+                /* make replication borders */
+                for( i = ker_x_n - 1; i >= 0; i-- )
+                    tsrc[i] = tsrc[i + channels];
+                for( i = width_n + ker_x_n; i < width_n + ker_width_n; i++ )
+                    tsrc[i] = tsrc[i - channels];
+
                 if( channels == 1 )
                 {
-                    /* make replication borders */
-                    uchar pix = tsrc[ker_x];
                     int t0 = 0;
 
-                    CV_SET( tsrc, pix, ker_x, x );
-
-                    pix = tsrc[width + ker_x - 1];
-                    CV_SET( tsrc + width + ker_x, pix, ker_right, x );
-
                     for( i = 0; i < ker_width_n - 1; i++ )
                         t0 += tsrc[i];
 
@@ -393,15 +389,8 @@ IPCVAPI_IMPL( CvStatus,
                 }
                 else if( channels == 3 )
                 {
-                    /* make replication borders */
-                    CvRGB8u pix = ((CvRGB8u *)tsrc)[ker_x];
                     int t0 = 0, t1 = 0, t2 = 0;
 
-                    CV_SET( (CvRGB8u *) tsrc, pix, ker_x, x );
-
-                    pix = ((CvRGB8u *) tsrc)[width + ker_x - 1];
-                    CV_SET( (CvRGB8u *) tsrc + width + ker_x, pix, ker_right, x );
-
                     for( i = 0; i < ker_width_n - 3; i += 3 )
                     {
                         t0 += tsrc[i];
@@ -425,15 +414,8 @@ IPCVAPI_IMPL( CvStatus,
                 }
                 else            /* channels == 4 */
                 {
-                    /* make replication borders */
-                    CvRGBA8u pix = ((CvRGBA8u *) tsrc)[ker_x];
                     int t0 = 0, t1 = 0, t2 = 0, t3 = 0;
-
-                    CV_SET( (CvRGBA8u *) tsrc, pix, ker_x, x );
-
-                    pix = ((CvRGBA8u *) tsrc)[width + ker_x - 1];
-                    CV_SET( (CvRGBA8u *) tsrc + width + ker_x, pix, ker_right, x );
-
+                    
                     for( i = 0; i < ker_width_n - 4; i += 4 )
                     {
                         t0 += tsrc[i];
@@ -522,8 +504,8 @@ IPCVAPI_IMPL( CvStatus,
             val0 += trow2[x];
             val1 += trow2[x+1];
 
-            t0 = CV_FAST_UDIV(val0, fastdiv);
-            t1 = CV_FAST_UDIV(val1, fastdiv);
+            t0 = cvRound(val0*inv_divisor);
+            t1 = cvRound(val1*inv_divisor);
 
             tdst2[x] = (uchar)t0;
             tdst2[x+1] = (uchar)t1;
@@ -537,8 +519,8 @@ IPCVAPI_IMPL( CvStatus,
             val0 += trow2[x+2];
             val1 += trow2[x+3];
 
-            t0 = CV_FAST_UDIV(val0, fastdiv);
-            t1 = CV_FAST_UDIV(val1, fastdiv);
+            t0 = cvRound(val0*inv_divisor);
+            t1 = cvRound(val1*inv_divisor);
 
             tdst2[x+2] = (uchar)t0;
             tdst2[x+3] = (uchar)t1;
@@ -576,15 +558,10 @@ IPCVAPI_IMPL( CvStatus,
 }
 
 
-IPCVAPI( CvStatus,
-     icvBlur_8u16s_C1R, ( const uchar* src, int srcStep,
-                          short* dst, int dstStep, CvSize * roiSize,
-                          CvFilterState* state, int stage ));
-
-IPCVAPI_IMPL( CvStatus,
-     icvBlur_8u16s_C1R, ( const uchar* pSrc, int srcStep,
-                          short* dst, int dstStep, CvSize * roiSize,
-                          CvFilterState* state, int stage ))
+CvStatus CV_STDCALL
+icvBlur_8u16s_C1R( const uchar* pSrc, int srcStep,
+                   short* dst, int dstStep, CvSize * roiSize,
+                   CvFilterState* state, int stage )
 {
     uchar* src = (uchar*)pSrc;
     int width = roiSize->width;
@@ -804,243 +781,10 @@ IPCVAPI_IMPL( CvStatus,
 }
 
 
-IPCVAPI( CvStatus,
-     icvBlur_8s16s_C1R, ( const char* src, int srcStep,
-                          short* dst, int dstStep, CvSize * roiSize,
-                          CvFilterState* state, int stage ));
-
-IPCVAPI_IMPL( CvStatus,
-     icvBlur_8s16s_C1R, ( const char* pSrc, int srcStep,
-                          short* dst, int dstStep, CvSize * roiSize,
-                          CvFilterState* state, int stage ))
-{
-    char* src = (char*)pSrc;
-    int width = roiSize->width;
-    int src_height = roiSize->height;
-    int dst_height = src_height;
-    int x, y = 0, i;
-
-    int ker_x = state->ker_x;
-    int ker_y = state->ker_y;
-    int ker_width = state->ker_width;
-    int ker_height = state->ker_height;
-    int ker_right = ker_width - ker_x;
-
-    int crows = state->crows;
-    int **rows = (int**)(state->rows);
-    short *tbufw = (short*)(state->tbuf);
-    int   *sumbuf = (int*)((char*)state->tbuf + state->buffer_step);
-    int *trow, *trow2;
-
-    int channels = state->channels;
-    int ker_x_n = ker_x * channels;
-    int ker_width_n = ker_width * channels;
-    int ker_right_n = ker_right * channels;
-    int width_n = width * channels;
-
-    int is_small_width = width < MAX( ker_x, ker_right );
-    int starting_flag = 0;
-    int width_rest = width_n & (CV_MORPH_ALIGN - 1);
-
-    /* initialize cyclic buffer when starting */
-    if( stage == CV_WHOLE || stage == CV_START )
-    {
-        for( i = 0; i < ker_height; i++ )
-            rows[i] = (int*)(state->buffer + state->buffer_step * i);
-
-        crows = ker_y;
-        if( stage != CV_WHOLE )
-            dst_height -= ker_height - ker_y - 1;
-        starting_flag = 1;
-    }
-
-    if( stage == CV_END )
-        dst_height += ker_height - ker_y - 1;
-
-    dstStep /= sizeof(dst[0]);
-
-    do
-    {
-        int need_copy = is_small_width | (y == 0);
-        char *tsrc;
-        int *tdst;
-        short *tdst2;
-        int *saved_row = rows[ker_y];
-
-        /* fill cyclic buffer - horizontal filtering */
-        for( ; crows < ker_height; crows++ )
-        {
-            tsrc = src - ker_x_n;
-            tdst = rows[crows];
-
-            if( src_height-- <= 0 )
-            {
-                if( stage != CV_WHOLE && stage != CV_END )
-                    break;
-                /* duplicate last row */
-                trow = rows[crows - 1];
-                CV_COPY( tdst, trow, width_n, x );
-                continue;
-            }
-
-            need_copy |= src_height == 1;
-
-            if( ker_width > 1 )
-            {
-                char* tbuf = (char*)tbufw;
-
-                if( need_copy )
-                {
-                    tsrc = tbuf - ker_x_n;
-                    CV_COPY( tbuf, src, width_n, x );
-                }
-                else
-                {
-                    CV_COPY( tbuf - ker_x_n, src - ker_x_n, ker_x_n, x );
-                    CV_COPY( tbuf, src + width_n, ker_right_n, x );
-                }
-
-                {
-                    /* make replication borders */
-                    char pix = tsrc[ker_x];
-                    int t0 = 0;
-
-                    CV_SET( tsrc, pix, ker_x, x );
-
-                    pix = tsrc[width + ker_x - 1];
-                    CV_SET( tsrc + width + ker_x, pix, ker_right, x );
-
-                    for( i = 0; i < ker_width_n - 1; i++ )
-                        t0 += tsrc[i];
-
-                    /* horizontal blurring */
-                    for( i = ker_width_n; i < width_n + ker_width_n; i++ )
-                    {
-                        t0 += tsrc[i-1];
-                        tdst[i-ker_width_n] = t0;
-                        t0 -= tsrc[i - ker_width_n];
-                    }
-                }
-
-                if( !need_copy )
-                {
-                    /* restore borders */
-                    CV_COPY( src - ker_x_n, tbuf - ker_x_n, ker_x_n, x );
-                    CV_COPY( src + width_n, tbuf, ker_right_n, x );
-                }
-            }
-            else
-            {
-                CV_COPY( tdst, tsrc + ker_x_n, width_n, x );
-            }
-
-            if( crows < ker_height )
-                src += srcStep;
-        }
-
-        if( starting_flag )
-        {
-            starting_flag = 0;
-
-            for( x = 0; x < width_n; x++ )
-            {
-                int t = rows[ker_y][x];
-                for( i = 0; i < ker_y; i++ ) // copy border
-                    rows[i][x] = t;
-
-                t *= ker_y;
-                for( i = ker_y; i < ker_height - 1; i++ ) // accumulate initial sum
-                    t += rows[i][x];
-                sumbuf[x] = t;
-            }
-        }
-
-        /* vertical convolution */
-        if( crows != ker_height )
-            break;
-
-        tdst2 = dst;
-
-        if( width_rest )
-        {
-            need_copy = width_n < CV_MORPH_ALIGN || y == dst_height - 1;
-
-            if( need_copy )
-                tdst2 = tbufw;
-            else
-                CV_COPY( tbufw + width_n, dst + width_n, CV_MORPH_ALIGN, x );
-        }
-
-        trow = rows[0];
-        trow2 = rows[ker_height-1];
-
-        for( x = 0; x < width_n; x += CV_MORPH_ALIGN )
-        {
-            int val0, val1;
-
-            val0 = sumbuf[x];
-            val1 = sumbuf[x+1];
-            
-            val0 += trow2[x];
-            val1 += trow2[x+1];
-
-            tdst2[x] = (short)val0;
-            tdst2[x+1] = (short)val1;
-
-            sumbuf[x] = val0 - trow[x];
-            sumbuf[x+1] = val1 - trow[x+1];
-
-            val0 = sumbuf[x+2];
-            val1 = sumbuf[x+3];
-            
-            val0 += trow2[x+2];
-            val1 += trow2[x+3];
-
-            tdst2[x+2] = (short)val0;
-            tdst2[x+3] = (short)val1;
-
-            sumbuf[x+2] = val0 - trow[x+2];
-            sumbuf[x+3] = val1 - trow[x+3];
-        }
-
-        if( width_rest )
-        {
-            if( need_copy )
-                CV_COPY( dst, tbufw, width_n, x );
-            else
-                CV_COPY( dst + width_n, tbufw + width_n, CV_MORPH_ALIGN, x );
-        }
-
-        rows[ker_y] = saved_row;
-
-        /* rotate buffer */
-        {
-            int *t = rows[0];
-
-            CV_COPY( rows, rows + 1, ker_height - 1, i );
-            rows[i] = t;
-            crows--;
-            dst += dstStep;
-        }
-    }
-    while( ++y < dst_height );
-
-    roiSize->height = y;
-    state->crows = crows;
-
-    return CV_OK;
-}
-
-
-IPCVAPI( CvStatus,
-     icvBlur_32f_CnR, ( const float* src, int srcStep,
-                        float* dst, int dstStep, CvSize * roiSize,
-                        CvFilterState* state, int stage ));
-
-IPCVAPI_IMPL( CvStatus,
-     icvBlur_32f_CnR, ( const float* pSrc, int srcStep,
-                        float* dst, int dstStep, CvSize * roiSize,
-                        CvFilterState* state, int stage ))
+CvStatus CV_STDCALL
+icvBlur_32f_CnR( const float* pSrc, int srcStep,
+                 float* dst, int dstStep, CvSize * roiSize,
+                 CvFilterState* state, int stage )
 {
     float* src = (float*)pSrc;
     int width = roiSize->width;
@@ -1129,21 +873,19 @@ IPCVAPI_IMPL( CvStatus,
                     CV_COPY( tbuf, src + width_n, ker_right_n, x );
                 }
 
+                /* make replication borders */
+                for( i = ker_x_n - 1; i >= 0; i-- )
+                    tsrc[i] = tsrc[i + channels];
+                for( i = width_n + ker_x_n; i < width_n + ker_width_n; i++ )
+                    tsrc[i] = tsrc[i - channels];
+
+                /* horizontal blurring */
                 if( channels == 1 )
                 {
-                    /* make replication borders */
-                    float pix = tsrc[ker_x];
                     float t0 = 0;
-
-                    CV_SET( tsrc, pix, ker_x, x );
-
-                    pix = tsrc[width + ker_x - 1];
-                    CV_SET( tsrc + width + ker_x, pix, ker_right, x );
-
                     for( i = 0; i < ker_width_n - 1; i++ )
                         t0 += tsrc[i];
 
-                    /* horizontal blurring */
                     for( i = ker_width_n; i < width_n + ker_width_n; i++ )
                     {
                         t0 += tsrc[i-1];
@@ -1153,15 +895,7 @@ IPCVAPI_IMPL( CvStatus,
                 }
                 else if( channels == 3 )
                 {
-                    /* make replication borders */
-                    CvRGB32f pix = ((CvRGB32f *)tsrc)[ker_x];
                     float t0 = 0, t1 = 0, t2 = 0;
-
-                    CV_SET( (CvRGB32f *) tsrc, pix, ker_x, x );
-
-                    pix = ((CvRGB32f *) tsrc)[width + ker_x - 1];
-                    CV_SET( (CvRGB32f *) tsrc + width + ker_x, pix, ker_right, x );
-
                     for( i = 0; i < ker_width_n - 3; i += 3 )
                     {
                         t0 += tsrc[i];
@@ -1169,7 +903,6 @@ IPCVAPI_IMPL( CvStatus,
                         t2 += tsrc[i+2];
                     }
 
-                    /* horizontal blurring */
                     for( i = ker_width_n; i < width_n + ker_width_n; i += 3 )
                     {
                         t0 += tsrc[i-3];
@@ -1185,15 +918,7 @@ IPCVAPI_IMPL( CvStatus,
                 }
                 else            /* channels == 4 */
                 {
-                    /* make replication borders */
-                    CvRGBA32f pix = ((CvRGBA32f *) tsrc)[ker_x];
                     float t0 = 0, t1 = 0, t2 = 0, t3 = 0;
-
-                    CV_SET( (CvRGBA32f *) tsrc, pix, ker_x, x );
-
-                    pix = ((CvRGBA32f *) tsrc)[width + ker_x - 1];
-                    CV_SET( (CvRGBA32f *) tsrc + width + ker_x, pix, ker_right, x );
-
                     for( i = 0; i < ker_width_n - 4; i += 4 )
                     {
                         t0 += tsrc[i];
@@ -1370,12 +1095,12 @@ IPCVAPI_IMPL( CvStatus,
 }
 
 
-IPCVAPI_IMPL( CvStatus, icvBlurInitAlloc,(
+CvStatus CV_STDCALL icvBlurInitAlloc(
     int roiWidth, int depth, int size,
-    struct CvFilterState** filterState ))
+    struct CvFilterState** filterState )
 {
     return icvSmoothInitAlloc( roiWidth, (CvDataType)depth, 1, cvSize(size,size),
-                               CV_BLUR_NO_SCALE, filterState );
+                               CV_BLUR_NO_SCALE, 0, filterState );
 }
 
 
@@ -1383,16 +1108,10 @@ IPCVAPI_IMPL( CvStatus, icvBlurInitAlloc,(
                                     Gaussian Blur
 \****************************************************************************************/
 
-
-IPCVAPI( CvStatus,
-     icvGaussianBlur_small_8u_CnR, ( uchar* src, int srcStep,
-                                     uchar* dst, int dstStep, CvSize * roiSize,
-                                     CvFilterState* state, int stage ));
-
-IPCVAPI_IMPL( CvStatus,
-     icvGaussianBlur_small_8u_CnR, ( uchar* src, int srcStep,
-                                     uchar* dst, int dstStep, CvSize * roiSize,
-                                     CvFilterState* state, int stage ))
+static CvStatus CV_STDCALL
+icvGaussianBlur_small_8u_CnR( uchar* src, int srcStep,
+                              uchar* dst, int dstStep, CvSize * roiSize,
+                              CvFilterState* state, int stage )
 {
     int width = roiSize->width;
     int src_height = roiSize->height;
@@ -1413,6 +1132,7 @@ IPCVAPI_IMPL( CvStatus,
     int channels = state->channels;
     int ker_x_n = ker_x * channels;
     int ker_right_n = ker_right * channels;
+    int ker_width_n = ker_width * channels;
     int width_n = width * channels;
 
     int is_small_width = width < MAX( ker_x, ker_right );
@@ -1478,15 +1198,14 @@ IPCVAPI_IMPL( CvStatus,
                     CV_COPY( tbuf, src + width_n, ker_right_n, x );
                 }
 
+                /* make replication borders */
+                for( i = ker_x_n - 1; i >= 0; i-- )
+                    tsrc[i] = tsrc[i + channels];
+                for( i = width_n + ker_x_n; i < width_n + ker_width_n; i++ )
+                    tsrc[i] = tsrc[i - channels];
+
                 if( channels == 1 )
                 {
-                    /* make replication borders */
-                    uchar pix = tsrc[ker_x];
-                    CV_SET( tsrc, pix, ker_x, x );
-
-                    pix = tsrc[width + ker_x - 1];
-                    CV_SET( tsrc + width + ker_x, pix, ker_right, x );
-
                     /* horizontal blurring */
                     if( ker_width == 3 )
                     {
@@ -1508,13 +1227,6 @@ IPCVAPI_IMPL( CvStatus,
                 }
                 else if( channels == 3 )
                 {
-                    /* make replication borders */
-                    CvRGB8u pix = ((CvRGB8u *)tsrc)[ker_x];
-                    CV_SET( (CvRGB8u *) tsrc, pix, ker_x, x );
-
-                    pix = ((CvRGB8u *) tsrc)[width + ker_x - 1];
-                    CV_SET( (CvRGB8u *) tsrc + width + ker_x, pix, ker_right, x );
-
                     /* horizontal blurring */
                     if( ker_width == 3 )
                     {
@@ -1565,13 +1277,6 @@ IPCVAPI_IMPL( CvStatus,
                 }
                 else   /* channels == 4 */
                 {
-                    /* make replication borders */
-                    CvRGBA8u pix = ((CvRGBA8u *) tsrc)[ker_x];
-                    CV_SET( (CvRGBA8u *) tsrc, pix, ker_x, x );
-
-                    pix = ((CvRGBA8u *) tsrc)[width + ker_x - 1];
-                    CV_SET( (CvRGBA8u *) tsrc + width + ker_x, pix, ker_right, x );
-
                     /* horizontal blurring */
                     if( ker_width == 3 )
                     {
@@ -1767,17 +1472,14 @@ IPCVAPI_IMPL( CvStatus,
 }
 
 
-IPCVAPI( CvStatus,
-     icvGaussianBlur_8u_CnR, ( uchar* src, int srcStep,
-                               uchar* dst, int dstStep, CvSize * roiSize,
-                               CvFilterState* state, int stage ));
-IPCVAPI_IMPL( CvStatus,
-     icvGaussianBlur_8u_CnR, ( uchar* src, int srcStep,
-                               uchar* dst, int dstStep, CvSize * roiSize,
-                               CvFilterState* state, int stage ))
+static CvStatus CV_STDCALL
+icvGaussianBlur_8u_CnR( uchar* src, int srcStep,
+                        uchar* dst, int dstStep, CvSize * roiSize,
+                        CvFilterState* state, int stage )
 {
     if( state->ker_width <= SMALL_GAUSSIAN_SIZE &&
-        state->ker_height <= SMALL_GAUSSIAN_SIZE )
+        state->ker_height <= SMALL_GAUSSIAN_SIZE &&
+        ICV_X_KERNEL_TYPE(state->kerType) == ICV_DEFAULT_GAUSSIAN_KERNEL )
     {
         return icvGaussianBlur_small_8u_CnR( src, srcStep, dst, dstStep,
                                              roiSize, state, stage );
@@ -1804,6 +1506,7 @@ IPCVAPI_IMPL( CvStatus,
         int ker_x_n = ker_x * channels;
         int ker_right_n = ker_right * channels;
         int width_n = width * channels;
+        int ker_width_n = ker_width * channels;
     
         float* fmaskX = (float*)(state->ker0) + ker_x;
         float* fmaskY = (float*)(state->ker1) + ker_y;
@@ -1867,16 +1570,15 @@ IPCVAPI_IMPL( CvStatus,
                         CV_COPY( tbuf, src + width_n, ker_right_n, x );
                     }
 
+                    /* make replication borders */
+                    for( i = ker_x_n - 1; i >= 0; i-- )
+                        tsrc[i] = tsrc[i + channels];
+                    for( i = width_n + ker_x_n; i < width_n + ker_width_n; i++ )
+                        tsrc[i] = tsrc[i - channels];
+
+                    /* horizontal blurring */
                     if( channels == 1 )
                     {
-                        /* make replication borders */
-                        uchar pix = tsrc[ker_x];
-                        CV_SET( tsrc, pix, ker_x, x );
-
-                        pix = tsrc[width + ker_x - 1];
-                        CV_SET( tsrc + width + ker_x, pix, ker_right, x );
-
-                        /* horizontal blurring */
                         for( i = 0; i < width_n; i++ )
                         {
                             int j;
@@ -1891,64 +1593,32 @@ IPCVAPI_IMPL( CvStatus,
                     }
                     else if( channels == 3 )
                     {
-                        /* make replication borders */
-                        CvRGB8u pix = ((CvRGB8u *)tsrc)[ker_x];
-                        CV_SET( (CvRGB8u *) tsrc, pix, ker_x, x );
-
-                        pix = ((CvRGB8u *) tsrc)[width + ker_x - 1];
-                        CV_SET( (CvRGB8u *) tsrc + width + ker_x, pix, ker_right, x );
-
-                        /* horizontal blurring */
-                        if( ker_width == 3 )
+                        for( i = 0; i < width_n; i += 3 )
                         {
-                            for( i = 0; i < width_n; i += 3 )
-                            {
-                                double t0 = (tsrc[i + 3]*2 + tsrc[i] + tsrc[i+6])*0.25;
-                                double t1 = (tsrc[i + 4]*2 + tsrc[i+1] + tsrc[i+7])*0.25;
-                                double t2 = (tsrc[i + 5]*2 + tsrc[i+2] + tsrc[i+8])*0.25;
+                            int j;
+                            double t0 = CV_8TO32F(tsrc[i + ker_x_n])*fmX0;
+                            double t1 = CV_8TO32F(tsrc[i + ker_x_n + 1])*fmX0;
+                            double t2 = CV_8TO32F(tsrc[i + ker_x_n + 2])*fmX0;
 
-                                tdst[i] = (float)t0;
-                                tdst[i+1] = (float)t1;
-                                tdst[i+2] = (float)t2;
-                            }
-                        }
-                        else
-                        {
-                            for( i = 0; i < width_n; i += 3 )
+                            for( j = 1; j <= ker_x; j++ )
                             {
-                                int j;
-                                double t0 = CV_8TO32F(tsrc[i + ker_x_n])*fmX0;
-                                double t1 = CV_8TO32F(tsrc[i + ker_x_n + 1])*fmX0;
-                                double t2 = CV_8TO32F(tsrc[i + ker_x_n + 2])*fmX0;
-
-                                for( j = 1; j <= ker_x; j++ )
-                                {
-                                    int j3 = j*3;
-                                    double m = fmaskX[j];
-                                    t0 += (CV_8TO32F(tsrc[i+ker_x_n+j3]) +
-                                           CV_8TO32F(tsrc[i+ker_x_n-j3]))*m;
-                                    t1 += (CV_8TO32F(tsrc[i+ker_x_n+j3+1]) +
-                                           CV_8TO32F(tsrc[i+ker_x_n-j3+1]))*m;
-                                    t2 += (CV_8TO32F(tsrc[i+ker_x_n+j3+2]) +
-                                           CV_8TO32F(tsrc[i+ker_x_n-j3+2]))*m;
-                                }
-
-                                tdst[i] = (float)t0;
-                                tdst[i+1] = (float)t1;
-                                tdst[i+2] = (float)t2;
+                                int j3 = j*3;
+                                double m = fmaskX[j];
+                                t0 += (CV_8TO32F(tsrc[i+ker_x_n+j3]) +
+                                       CV_8TO32F(tsrc[i+ker_x_n-j3]))*m;
+                                t1 += (CV_8TO32F(tsrc[i+ker_x_n+j3+1]) +
+                                       CV_8TO32F(tsrc[i+ker_x_n-j3+1]))*m;
+                                t2 += (CV_8TO32F(tsrc[i+ker_x_n+j3+2]) +
+                                       CV_8TO32F(tsrc[i+ker_x_n-j3+2]))*m;
                             }
+
+                            tdst[i] = (float)t0;
+                            tdst[i+1] = (float)t1;
+                            tdst[i+2] = (float)t2;
                         }
                     }
                     else    /* channels == 4 */
                     {
-                        /* make replication borders */
-                        CvRGBA8u pix = ((CvRGBA8u *) tsrc)[ker_x];
-                        CV_SET( (CvRGBA8u *) tsrc, pix, ker_x, x );
-
-                        pix = ((CvRGBA8u *) tsrc)[width + ker_x - 1];
-                        CV_SET( (CvRGBA8u *) tsrc + width + ker_x, pix, ker_right, x );
-
-                        /* horizontal blurring */
                         for( i = 0; i < width_n; i += 4 )
                         {
                             int j;
@@ -2081,14 +1751,10 @@ IPCVAPI_IMPL( CvStatus,
 }
 
 
-IPCVAPI( CvStatus,
-     icvGaussianBlur_32f_CnR, ( float* src, int srcStep,
-                                float* dst, int dstStep, CvSize * roiSize,
-                                CvFilterState* state, int stage ));
-IPCVAPI_IMPL( CvStatus,
-     icvGaussianBlur_32f_CnR, ( float* src, int srcStep,
-                                float* dst, int dstStep, CvSize * roiSize,
-                                CvFilterState* state, int stage ))
+static CvStatus CV_STDCALL
+icvGaussianBlur_32f_CnR( float* src, int srcStep,
+                         float* dst, int dstStep, CvSize * roiSize,
+                         CvFilterState* state, int stage )
 {
     int width = roiSize->width;
     int src_height = roiSize->height;
@@ -2110,6 +1776,7 @@ IPCVAPI_IMPL( CvStatus,
     int ker_x_n = ker_x * channels;
     int ker_right_n = ker_right * channels;
     int width_n = width * channels;
+    int ker_width_n = ker_width * channels;
 
     float* fmaskX = (float*)(state->ker0) + ker_x;
     float* fmaskY = (float*)(state->ker1) + ker_y;
@@ -2176,16 +1843,15 @@ IPCVAPI_IMPL( CvStatus,
                     CV_COPY( tbuf, src + width_n, ker_right_n, x );
                 }
 
+                /* make replication borders */
+                for( i = ker_x_n - 1; i >= 0; i-- )
+                    tsrc[i] = tsrc[i + channels];
+                for( i = width_n + ker_x_n; i < width_n + ker_width_n; i++ )
+                    tsrc[i] = tsrc[i - channels];
+
+                /* horizontal blurring */
                 if( channels == 1 )
                 {
-                    /* make replication borders */
-                    float pix = tsrc[ker_x];
-                    CV_SET( tsrc, pix, ker_x, x );
-
-                    pix = tsrc[width + ker_x - 1];
-                    CV_SET( tsrc + width + ker_x, pix, ker_right, x );
-
-                    /* horizontal blurring */
                     for( i = 0; i < width_n; i++ )
                     {
                         int j;
@@ -2200,64 +1866,32 @@ IPCVAPI_IMPL( CvStatus,
                 }
                 else if( channels == 3 )
                 {
-                    /* make replication borders */
-                    CvRGB32f pix = ((CvRGB32f *)tsrc)[ker_x];
-                    CV_SET( (CvRGB32f *) tsrc, pix, ker_x, x );
-
-                    pix = ((CvRGB32f *) tsrc)[width + ker_x - 1];
-                    CV_SET( (CvRGB32f *) tsrc + width + ker_x, pix, ker_right, x );
-
-                    /* horizontal blurring */
-                    if( ker_width == 3 )
+                    for( i = 0; i < width_n; i += 3 )
                     {
-                        for( i = 0; i < width_n; i += 3 )
-                        {
-                            double t0 = (tsrc[i + 3]*2 + tsrc[i] + tsrc[i+6])*0.25;
-                            double t1 = (tsrc[i + 4]*2 + tsrc[i+1] + tsrc[i+7])*0.25;
-                            double t2 = (tsrc[i + 5]*2 + tsrc[i+2] + tsrc[i+8])*0.25;
+                        int j;
+                        double t0 = (tsrc[i + ker_x_n])*fmX0;
+                        double t1 = (tsrc[i + ker_x_n + 1])*fmX0;
+                        double t2 = (tsrc[i + ker_x_n + 2])*fmX0;
 
-                            tdst[i] = (float)t0;
-                            tdst[i+1] = (float)t1;
-                            tdst[i+2] = (float)t2;
-                        }
-                    }
-                    else
-                    {
-                        for( i = 0; i < width_n; i += 3 )
+                        for( j = 1; j <= ker_x; j++ )
                         {
-                            int j;
-                            double t0 = (tsrc[i + ker_x_n])*fmX0;
-                            double t1 = (tsrc[i + ker_x_n + 1])*fmX0;
-                            double t2 = (tsrc[i + ker_x_n + 2])*fmX0;
-
-                            for( j = 1; j <= ker_x; j++ )
-                            {
-                                int j3 = j*3;
-                                double m = fmaskX[j];
-                                t0 += ((tsrc[i+ker_x_n+j3]) +
-                                       (tsrc[i+ker_x_n-j3]))*m;
-                                t1 += ((tsrc[i+ker_x_n+j3+1]) +
-                                       (tsrc[i+ker_x_n-j3+1]))*m;
-                                t2 += ((tsrc[i+ker_x_n+j3+2]) +
-                                       (tsrc[i+ker_x_n-j3+2]))*m;
-                            }
-
-                            tdst[i] = (float)t0;
-                            tdst[i+1] = (float)t1;
-                            tdst[i+2] = (float)t2;
+                            int j3 = j*3;
+                            double m = fmaskX[j];
+                            t0 += ((tsrc[i+ker_x_n+j3]) +
+                                   (tsrc[i+ker_x_n-j3]))*m;
+                            t1 += ((tsrc[i+ker_x_n+j3+1]) +
+                                   (tsrc[i+ker_x_n-j3+1]))*m;
+                            t2 += ((tsrc[i+ker_x_n+j3+2]) +
+                                   (tsrc[i+ker_x_n-j3+2]))*m;
                         }
+
+                        tdst[i] = (float)t0;
+                        tdst[i+1] = (float)t1;
+                        tdst[i+2] = (float)t2;
                     }
                 }
                 else    /* channels == 4 */
                 {
-                    /* make replication borders */
-                    CvRGBA32f pix = ((CvRGBA32f *) tsrc)[ker_x];
-                    CV_SET( (CvRGBA32f *) tsrc, pix, ker_x, x );
-
-                    pix = ((CvRGBA32f *) tsrc)[width + ker_x - 1];
-                    CV_SET( (CvRGBA32f *) tsrc + width + ker_x, pix, ker_right, x );
-
-                    /* horizontal blurring */
                     for( i = 0; i < width_n; i += 4 )
                     {
                         int j;
@@ -2393,17 +2027,11 @@ IPCVAPI_IMPL( CvStatus,
                                       Median Filter
 \****************************************************************************************/
 
-IPCVAPI( CvStatus,
-     icvMedianBlur_8u_CnR, ( uchar* src, int srcStep,
-                             uchar* dst, int dstStep,
-                             CvSize* roiSize,
-                             int* param, int /*stub */ ));
-
-IPCVAPI_IMPL( CvStatus,
-     icvMedianBlur_8u_CnR, ( uchar* src, int srcStep,
-                             uchar* dst, int dstStep,
-                             CvSize* roiSize,
-                             int* param, int /*stub */ ))
+static CvStatus CV_STDCALL
+icvMedianBlur_8u_CnR( uchar* src, int srcStep,
+                      uchar* dst, int dstStep,
+                      CvSize* roiSize,
+                      int* param, int /*stub */ )
 {
     const int small_thresh = 3;
     #define N  16
@@ -2643,15 +2271,10 @@ IPCVAPI_IMPL( CvStatus,
                                    Bilateral Filtering
 \****************************************************************************************/
 
-IPCVAPI( CvStatus,
-     icvBilateralFiltering_8u_CnR, ( uchar* src, int srcStep,
-                                     uchar* dst, int dstStep,
-                                     CvSize* roiSize, int* param, int /*stub */ ));
-
-IPCVAPI_IMPL( CvStatus,
-     icvBilateralFiltering_8u_CnR, ( uchar* src, int srcStep,
-                                     uchar* dst, int dstStep,
-                                     CvSize* roiSize, int* param, int /*stub*/ ))
+static CvStatus CV_STDCALL
+icvBilateralFiltering_8u_CnR( uchar* src, int srcStep,
+                              uchar* dst, int dstStep,
+                              CvSize* roiSize, int* param, int /*stub*/ )
 {
     CvSize size = *roiSize;
     
@@ -2886,7 +2509,6 @@ static void icvInitSmoothTab( CvFuncTable* blur_no_scale_tab,
                               CvFuncTable* median_tab, CvFuncTable* bilateral_tab )
 {
     blur_no_scale_tab->fn_2d[CV_8U] = (void*)icvBlur_8u16s_C1R;
-    blur_no_scale_tab->fn_2d[CV_8S] = (void*)icvBlur_8s16s_C1R;
     blur_no_scale_tab->fn_2d[CV_32F] = (void*)icvBlur_32f_CnR;
     
     blur_tab->fn_2d[CV_8U] = (void*)icvBlur_8u_CnR;
@@ -2902,8 +2524,8 @@ static void icvInitSmoothTab( CvFuncTable* blur_no_scale_tab,
 
  
 CV_IMPL void
-cvSmooth( const void* srcarr, void* dstarr,
-          int smoothtype, int param1, int param2 )
+cvSmooth( const void* srcarr, void* dstarr, int smoothtype,
+          int param1, int param2, double param3 )
 {
     static CvFuncTable smooth_tab[5];
     static int inittab = 0;
@@ -2934,23 +2556,22 @@ cvSmooth( const void* srcarr, void* dstarr,
     CV_CALL( src = cvGetMat( src, &srcstub, &coi1 ));
     CV_CALL( dst = cvGetMat( dst, &dststub, &coi2 ));
 
+    if( coi1 != 0 || coi2 != 0 )
+        CV_ERROR( CV_BadCOI, "" );
+
     type = CV_MAT_TYPE( src->type );
     dsttype = CV_MAT_TYPE( dst->type );
 
     if( !((smoothtype > 0 && CV_ARE_SIZES_EQ( src, dst )) ||
           (smoothtype == 0 &&
           (type == CV_8UC1 && dsttype == CV_16SC1 ||
-           type == CV_8SC1 && dsttype == CV_16SC1 ||
            type == CV_32FC1 && dsttype == CV_32FC1 ))))
         CV_ERROR( CV_StsUnmatchedFormats, "" );
 
     if( !CV_ARE_SIZES_EQ( src, dst ))
         CV_ERROR( CV_StsUnmatchedSizes, "" );
 
-    if( coi1 != 0 || coi2 != 0 )
-        CV_ERROR( CV_BadCOI, "" );
-
-    size = icvGetMatSize( src );
+    size = cvGetMatSize( src );
     
     depth = CV_MAT_DEPTH(type);
     nonlin_param[0] = CV_MAT_CN(type);
@@ -2963,9 +2584,6 @@ cvSmooth( const void* srcarr, void* dstarr,
         CV_ERROR( CV_StsBadArg,
         "Inplace operation is not supported for that type of smoothing" );
 
-    if( smoothtype < CV_BILATERAL && (param1 < 1 || (param1 & 1) == 0) )
-        CV_ERROR( CV_StsOutOfRange, "Bad aperture size (should be >=1 and odd)" );
-
     if( smoothtype == CV_BILATERAL )
     {
         if( param1 < 0 || param2 < 0 )
@@ -2974,6 +2592,18 @@ cvSmooth( const void* srcarr, void* dstarr,
         param1 += param1 == 0;
         param2 += param2 == 0;
     }
+    else /* simple blurring, gaussian, median */
+    {
+        // automatic detection of kernel size from sigma
+        if( smoothtype == CV_GAUSSIAN && param1 == 0 && param3 > 0 )
+            param1 = cvRound(param3*(depth == CV_8U ? 3 : 4)*2 + 1)|1;
+        
+        if( param2 == 0 )
+            param2 = param1;
+        if( param1 < 1 || (param1 & 1) == 0 || param2 < 1 || (param2 & 1) == 0 )
+            CV_ERROR( CV_StsOutOfRange,
+                "One of aperture dimensions is incorrect (should be >=1 and odd)" );
+    }
 
     if( smoothtype <= CV_GAUSSIAN )
     {
@@ -2981,7 +2611,7 @@ cvSmooth( const void* srcarr, void* dstarr,
                                        CV_MAT_CN(type),
                                        cvSize( param1, size.height == 1 ? 1 :
                                                smoothtype <= CV_GAUSSIAN ? param2 : param1),
-                                       smoothtype, &state ));
+                                       smoothtype, param3 /* custom sigma */, &state ));
         ptr = state;
     }
 
index 58bac6f103aff1cdd7da267de8b208b6a4a8a5c5..dd5cf9f487afc1f5b2139f3fd358ef33f3fdc062 100644 (file)
 #define _CV_SNAKE_IMAGE 1
 #define _CV_SNAKE_GRAD  2
 
-/* internal function */
-CvStatus icvSnake8uC1R( unsigned char *src,
-                        int srcStep,
-                        CvSize roi,
-                        CvPoint * pt,
-
-                        int length,
-                        float *alpha,
-                        float *beta,
-                        float *gamma,
-                        CvCoeffType coeffUsage,
-                        CvSize win, CvTermCriteria criteria, int scheme );
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:      icvSnakeImage8uC1R     
-//    Purpose:   
-//    Context:   
-//    Parameters:
-//               src - source image,
-//               srcStep - its step in bytes,
-//               roi - size of ROI,
-//               points - pointer to snake points array
-//               length - size of points array, 
-//               alpha - pointer to coefficient of continuity energy, 
-//               beta - pointer to coefficient of curvature energy,  
-//               gamma - pointer to coefficient of image energy,  
-//               coeffUsage - if CV_VALUE - alpha, beta, gamma point to single value
-//                            if CV_MATAY - point to arrays
-//               criteria - termination criteria.
-//    Returns:   
-//F*/
-IPCVAPI_IMPL( CvStatus, icvSnakeImage8uC1R, (unsigned char *src,
-                                             int srcStep,
-                                             CvSize roi,
-                                             CvPoint * points,
-                                             int length,
-                                             float *alpha,
-                                             float *beta,
-                                             float *gamma,
-                                             CvCoeffType coeffUsage,
-                                             CvSize win, CvTermCriteria criteria) )
-{
-    return icvSnake8uC1R( src, srcStep, roi, points, length,
-                          alpha, beta, gamma, coeffUsage, win, criteria, _CV_SNAKE_IMAGE );
-
-}
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:      icvSnakeImageGrad8uC1R     
-//    Purpose:   
-//    Context:   
-//    Parameters:
-//               src - source image,
-//               srcStep - its step in bytes,
-//               roi - size of ROI,
-//               points - pointer to snake points array
-//               length - size of points array, 
-//               alpha - pointer to coefficient of continuity energy, 
-//               beta - pointer to coefficient of curvature energy,  
-//               gamma - pointer to coefficient of image energy,  
-//               coeffUsage - if CV_VALUE - alpha, beta, gamma point to single value
-//                            if CV_MATAY - point to arrays
-//               criteria - termination criteria.
-//    Returns:   
-//F*/
-IPCVAPI_IMPL( CvStatus, icvSnakeImageGrad8uC1R, (unsigned char *src,
-                                                 int srcStep,
-                                                 CvSize roi,
-                                                 CvPoint * points,
-                                                 int length,
-                                                 float *alpha,
-                                                 float *beta,
-                                                 float *gamma,
-                                                 CvCoeffType coeffUsage,
-                                                 CvSize win, CvTermCriteria criteria) )
-{
-    return icvSnake8uC1R( src, srcStep, roi, points, length,
-                          alpha, beta, gamma, coeffUsage, win, criteria, _CV_SNAKE_GRAD );
-}
 
 /*F///////////////////////////////////////////////////////////////////////////////////////
 //    Name:      icvSnake8uC1R     
@@ -146,7 +67,7 @@ IPCVAPI_IMPL( CvStatus, icvSnakeImageGrad8uC1R, (unsigned char *src,
 //    Returns:   
 //F*/
 
-CvStatus
+static CvStatus
 icvSnake8uC1R( unsigned char *src,
                int srcStep,
                CvSize roi,
@@ -155,7 +76,7 @@ icvSnake8uC1R( unsigned char *src,
                float *alpha,
                float *beta,
                float *gamma,
-               CvCoeffType coeffUsage, CvSize win, CvTermCriteria criteria, int scheme )
+               int coeffUsage, CvSize win, CvTermCriteria criteria, int scheme )
 {
     int i, j, k;
     int neighbors = win.height * win.width;
@@ -219,26 +140,26 @@ icvSnake8uC1R( unsigned char *src,
 
     if( scheme == _CV_SNAKE_GRAD )
     {
-        dx = (short *) icvAlloc( 10 * 10 * sizeof( short ));
-        dy = (short *) icvAlloc( 10 * 10 * sizeof( short ));
+        dx = (short *) cvAlloc( 10 * 10 * sizeof( short ));
+        dy = (short *) cvAlloc( 10 * 10 * sizeof( short ));
 
-        gradient = (float *) icvAlloc( roi.height * roi.width * sizeof( float ));
+        gradient = (float *) cvAlloc( roi.height * roi.width * sizeof( float ));
 
         if( !gradient )
             return CV_OUTOFMEM_ERR;
-        map = (uchar *) icvAlloc( map_width * map_height );
+        map = (uchar *) cvAlloc( map_width * map_height );
         if( !map )
         {
-            icvFree( &gradient );
+            cvFree( (void**)&gradient );
             return CV_OUTOFMEM_ERR;
         }
         /* clear map - no gradient computed */
         memset( (void *) map, 0, map_width * map_height );
     }
-    Econt = (float *) icvAlloc( neighbors * sizeof( float ));
-    Ecurv = (float *) icvAlloc( neighbors * sizeof( float ));
-    Eimg = (float *) icvAlloc( neighbors * sizeof( float ));
-    E = (float *) icvAlloc( neighbors * sizeof( float ));
+    Econt = (float *) cvAlloc( neighbors * sizeof( float ));
+    Ecurv = (float *) cvAlloc( neighbors * sizeof( float ));
+    Eimg = (float *) cvAlloc( neighbors * sizeof( float ));
+    E = (float *) cvAlloc( neighbors * sizeof( float ));
 
     while( !converged )
     {
@@ -472,23 +393,23 @@ icvSnake8uC1R( unsigned char *src,
             }
         }
         converged = (moved == 0);
-        if( (criteria.type & CV_TERMCRIT_ITER) && (iteration >= criteria.maxIter) )
+        if( (criteria.type & CV_TERMCRIT_ITER) && (iteration >= criteria.max_iter) )
             converged = 1;
         if( (criteria.type & CV_TERMCRIT_EPS) && (moved <= criteria.epsilon) )
             converged = 1;
     }
 
-    icvFree( &Econt );
-    icvFree( &Ecurv );
-    icvFree( &Eimg );
-    icvFree( &E );
+    cvFree( (void**)&Econt );
+    cvFree( (void**)&Ecurv );
+    cvFree( (void**)&Eimg );
+    cvFree( (void**)&E );
 
     if( scheme == _CV_SNAKE_GRAD )
     {
-        icvFree( &gradient );
-        icvFree( &map );
-        icvFree( &dx );
-        icvFree( &dy );
+        cvFree( (void**)&gradient );
+        cvFree( (void**)&map );
+        cvFree( (void**)&dx );
+        cvFree( (void**)&dy );
     }
     return CV_OK;
 }
@@ -498,7 +419,7 @@ CV_IMPL void
 cvSnakeImage( const IplImage* src, CvPoint* points,
               int length, float *alpha,
               float *beta, float *gamma,
-              CvCoeffType coeffUsage, CvSize win,
+              int coeffUsage, CvSize win,
               CvTermCriteria criteria, int calcGradient )
 {
 
@@ -514,22 +435,13 @@ cvSnakeImage( const IplImage* src, CvPoint* points,
         CV_ERROR( CV_BadNumChannels, "input image has more than one channel" );
 
     if( src->depth != IPL_DEPTH_8U )
-        CV_ERROR( CV_BadDepth, icvUnsupportedFormat );
+        CV_ERROR( CV_BadDepth, cvUnsupportedFormat );
 
+    cvGetRawData( src, &data, &step, &size );
 
-    cvGetImageRawData( src, &data, &step, &size );
-
-    if( calcGradient )
-    {
-        IPPI_CALL( icvSnakeImageGrad8uC1R( data, step, size, points, length,
-                              alpha, beta, gamma, coeffUsage, win, criteria ));
-    }
-    else
-    {
-        IPPI_CALL( icvSnakeImage8uC1R( data, step, size, points, length, alpha, beta,
-                                       gamma, coeffUsage, win, criteria ));
-    }
-    __CLEANUP__;
+    IPPI_CALL( icvSnake8uC1R( data, step, size, points, length,
+                              alpha, beta, gamma, coeffUsage, win, criteria,
+                              calcGradient ? _CV_SNAKE_GRAD : _CV_SNAKE_IMAGE ));
     __END__;
 }
 
index 1002a9944a50c8bbf6c63488f807db26bf6f7626..50ec3c16046c9d9cd8f298d6c57a3f45e2debd2d 100644 (file)
@@ -39,9 +39,6 @@
 //
 //M*/
 #include "_cv.h"
-#include <float.h>
-#include <stdlib.h>
-#include "_cvgeom.h"
 
 #if _MSC_VER >= 1200
 #pragma warning (disable:4710)  // function '...' not inlined
@@ -58,7 +55,7 @@ cvCreateSubdiv2D( int subdiv_type, int header_size,
     __BEGIN__;
 
     if( !storage )
-        CV_ERROR_FROM_STATUS( CV_NULLPTR_ERR );
+        CV_ERROR( CV_StsNullPtr, "" );
 
     if( header_size < (int)sizeof( *subdiv ) ||
         quadedge_size < (int)sizeof( CvQuadEdge2D ) ||
@@ -79,7 +76,7 @@ cvCreateSubdiv2D( int subdiv_type, int header_size,
 *                                    Quad Edge  algebra                                  *
 \****************************************************************************************/
 
-CV_IMPL CvSubdiv2DEdge
+static CvSubdiv2DEdge
 cvSubdiv2DMakeEdge( CvSubdiv2D * subdiv )
 {
     CvQuadEdge2D *edge = 0;
@@ -90,7 +87,7 @@ cvSubdiv2DMakeEdge( CvSubdiv2D * subdiv )
     __BEGIN__;
 
     if( !subdiv )
-        CV_ERROR_FROM_STATUS( CV_NULLPTR_ERR );
+        CV_ERROR( CV_StsNullPtr, "" );
 
     edge = (CvQuadEdge2D*)cvSetNew( (CvSet*)subdiv->edges );
     CV_CHECK();
@@ -112,7 +109,7 @@ cvSubdiv2DMakeEdge( CvSubdiv2D * subdiv )
 }
 
 
-CV_IMPL CvSubdiv2DPoint *
+static CvSubdiv2DPoint *
 cvSubdiv2DAddPoint( CvSubdiv2D * subdiv, CvPoint2D32f pt, int is_virtual )
 {
     CvSubdiv2DPoint *subdiv_point = 0;
@@ -130,7 +127,7 @@ cvSubdiv2DAddPoint( CvSubdiv2D * subdiv, CvPoint2D32f pt, int is_virtual )
 }
 
 
-CV_IMPL void
+static void
 cvSubdiv2DSplice( CvSubdiv2DEdge edgeA, CvSubdiv2DEdge edgeB )
 {
     CvSubdiv2DEdge *a_next = &CV_SUBDIV2D_NEXT_EDGE( edgeA );
@@ -146,7 +143,7 @@ cvSubdiv2DSplice( CvSubdiv2DEdge edgeA, CvSubdiv2DEdge edgeB )
 }
 
 
-CV_IMPL void
+static void
 cvSubdiv2DSetEdgePoints( CvSubdiv2DEdge edge,
                          CvSubdiv2DPoint * org_pt, CvSubdiv2DPoint * dst_pt )
 {
@@ -157,7 +154,7 @@ cvSubdiv2DSetEdgePoints( CvSubdiv2DEdge edge,
     __BEGIN__;
 
     if( !quadedge )
-        CV_ERROR_FROM_STATUS( CV_NULLPTR_ERR );
+        CV_ERROR( CV_StsNullPtr, "" );
 
     quadedge->pt[edge & 3] = org_pt;
     quadedge->pt[(edge + 2) & 3] = dst_pt;
@@ -167,7 +164,7 @@ cvSubdiv2DSetEdgePoints( CvSubdiv2DEdge edge,
 }
 
 
-CV_IMPL void
+static void
 cvSubdiv2DDeleteEdge( CvSubdiv2D * subdiv, CvSubdiv2DEdge edge )
 {
     CvQuadEdge2D *quadedge = (CvQuadEdge2D *) (edge & ~3);
@@ -177,7 +174,7 @@ cvSubdiv2DDeleteEdge( CvSubdiv2D * subdiv, CvSubdiv2DEdge edge )
     __BEGIN__;
 
     if( !subdiv || !quadedge )
-        CV_ERROR_FROM_STATUS( CV_NULLPTR_ERR );
+        CV_ERROR( CV_StsNullPtr, "" );
 
     cvSubdiv2DSplice( edge, cvSubdiv2DGetEdge( edge, CV_PREV_AROUND_ORG ));
 
@@ -194,7 +191,7 @@ cvSubdiv2DDeleteEdge( CvSubdiv2D * subdiv, CvSubdiv2DEdge edge )
 }
 
 
-CV_IMPL CvSubdiv2DEdge
+static CvSubdiv2DEdge
 cvSubdiv2DConnectEdges( CvSubdiv2D * subdiv, CvSubdiv2DEdge edgeA, CvSubdiv2DEdge edgeB )
 {
     CvSubdiv2DEdge new_edge = 0;
@@ -203,16 +200,19 @@ cvSubdiv2DConnectEdges( CvSubdiv2D * subdiv, CvSubdiv2DEdge edgeA, CvSubdiv2DEdg
 
     __BEGIN__;
 
+    CvSubdiv2DPoint *orgB, *dstA;
+
     if( !subdiv )
-        CV_ERROR_FROM_STATUS( CV_NULLPTR_ERR );
+        CV_ERROR( CV_StsNullPtr, "" );
 
     new_edge = cvSubdiv2DMakeEdge( subdiv );
 
     cvSubdiv2DSplice( new_edge, cvSubdiv2DGetEdge( edgeA, CV_NEXT_AROUND_LEFT ));
     cvSubdiv2DSplice( cvSubdiv2DSymEdge( new_edge ), edgeB );
 
-    cvSubdiv2DSetEdgePoints( new_edge, cvSubdiv2DEdgeDst( edgeA ), cvSubdiv2DEdgeOrg( edgeB ));
-
+    dstA = cvSubdiv2DEdgeDst( edgeA );
+    orgB = cvSubdiv2DEdgeOrg( edgeB );
+    cvSubdiv2DSetEdgePoints( new_edge, dstA, orgB );
     
     __END__;
 
@@ -220,16 +220,20 @@ cvSubdiv2DConnectEdges( CvSubdiv2D * subdiv, CvSubdiv2DEdge edgeA, CvSubdiv2DEdg
 }
 
 
-CV_IMPL void
+static void
 cvSubdiv2DSwapEdges( CvSubdiv2DEdge edge )
 {
     CvSubdiv2DEdge sym_edge = cvSubdiv2DSymEdge( edge );
     CvSubdiv2DEdge a = cvSubdiv2DGetEdge( edge, CV_PREV_AROUND_ORG );
     CvSubdiv2DEdge b = cvSubdiv2DGetEdge( sym_edge, CV_PREV_AROUND_ORG );
+    CvSubdiv2DPoint *dstB, *dstA;
 
     cvSubdiv2DSplice( edge, a );
     cvSubdiv2DSplice( sym_edge, b );
-    cvSubdiv2DSetEdgePoints( edge, cvSubdiv2DEdgeDst( a ), cvSubdiv2DEdgeDst( b ));
+
+    dstA = cvSubdiv2DEdgeDst( a );
+    dstB = cvSubdiv2DEdgeDst( b );
+    cvSubdiv2DSetEdgePoints( edge, dstA, dstB );
 
     cvSubdiv2DSplice( edge, cvSubdiv2DGetEdge( a, CV_NEXT_AROUND_LEFT ));
     cvSubdiv2DSplice( sym_edge, cvSubdiv2DGetEdge( b, CV_NEXT_AROUND_LEFT ));
@@ -239,8 +243,8 @@ cvSubdiv2DSwapEdges( CvSubdiv2DEdge edge )
 static int
 icvIsRightOf( CvPoint2D32f& pt, CvSubdiv2DEdge edge )
 {
-    float cw_area = (float)cvTriangleArea( pt, cvSubdiv2DEdgeDst( edge )->pt,
-                                           cvSubdiv2DEdgeOrg( edge )->pt );
+    CvSubdiv2DPoint *org = cvSubdiv2DEdgeOrg(edge), *dst = cvSubdiv2DEdgeDst(edge);
+    float cw_area = (float)cvTriangleArea( pt, dst->pt, org->pt );
     int iarea = (int&)cw_area;
 
     return (iarea > 0)*2 - (iarea + iarea != 0);
@@ -263,7 +267,7 @@ cvSubdiv2DLocate( CvSubdiv2D * subdiv, CvPoint2D32f pt,
     __BEGIN__;
 
     if( !subdiv )
-        CV_ERROR_FROM_STATUS( CV_NULLPTR_ERR );
+        CV_ERROR( CV_StsNullPtr, "" );
 
     if( !CV_IS_SUBDIV2D(subdiv) )
         CV_ERROR_FROM_STATUS( CV_BADFLAG_ERR );
@@ -350,9 +354,12 @@ cvSubdiv2DLocate( CvSubdiv2D * subdiv, CvPoint2D32f pt,
         CvPoint2D32f org_pt = cvSubdiv2DEdgeOrg( edge )->pt;
         CvPoint2D32f dst_pt = cvSubdiv2DEdgeDst( edge )->pt;
 
-        t1 = fabs( pt.x - org_pt.x ) + fabs( pt.y - org_pt.y );
-        t2 = fabs( pt.x - dst_pt.x ) + fabs( pt.y - dst_pt.y );
-        t3 = fabs( org_pt.x - dst_pt.x ) + fabs( org_pt.y - dst_pt.y );
+        t1 = fabs( pt.x - org_pt.x );
+        t1 += fabs( pt.y - org_pt.y );
+        t2 = fabs( pt.x - dst_pt.x );
+        t2 += fabs( pt.y - dst_pt.y );
+        t3 = fabs( org_pt.x - dst_pt.x );
+        t3 += fabs( org_pt.y - dst_pt.y );
 
         if( t1 < FLT_EPSILON )
         {
@@ -404,7 +411,7 @@ cvSubdivDelaunay2DInsert( CvSubdiv2D * subdiv, CvPoint2D32f pt )
     __BEGIN__;
 
     if( !subdiv )
-        CV_ERROR_FROM_STATUS( CV_NULLPTR_ERR );
+        CV_ERROR( CV_StsNullPtr, "" );
 
     if( !CV_IS_SUBDIV2D(subdiv) )
         CV_ERROR_FROM_STATUS( CV_BADFLAG_ERR );
@@ -513,7 +520,7 @@ cvInitSubdivDelaunay2D( CvSubdiv2D * subdiv, CvRect rect )
     __BEGIN__;
 
     if( !subdiv )
-        CV_ERROR_FROM_STATUS( CV_NULLPTR_ERR );
+        CV_ERROR( CV_StsNullPtr, "" );
 
     cvClearSet( (CvSet *) (subdiv->edges) );
     cvClearSet( (CvSet *) subdiv );
@@ -564,7 +571,7 @@ cvClearSubdivVoronoi2D( CvSubdiv2D * subdiv )
     __BEGIN__;
 
     if( !subdiv )
-        CV_ERROR_FROM_STATUS( CV_NULLPTR_ERR );
+        CV_ERROR( CV_StsNullPtr, "" );
 
     /* clear pointers to voronoi points */
     total = subdiv->edges->total;
@@ -616,7 +623,7 @@ cvCalcSubdivVoronoi2D( CvSubdiv2D * subdiv )
     __BEGIN__;
 
     if( !subdiv )
-        CV_ERROR_FROM_STATUS( CV_NULLPTR_ERR );
+        CV_ERROR( CV_StsNullPtr, "" );
 
     /* check if it is already calculated */
     if( subdiv->is_geometry_valid )
@@ -725,10 +732,10 @@ cvFindNearestPoint2D( CvSubdiv2D* subdiv, CvPoint2D32f pt )
     __BEGIN__;
 
     if( !subdiv )
-        CV_ERROR_FROM_STATUS( CV_NULLPTR_ERR );
+        CV_ERROR( CV_StsNullPtr, "" );
 
     if( !CV_IS_SUBDIV2D( subdiv ))
-        CV_ERROR_FROM_STATUS( CV_NULLPTR_ERR );
+        CV_ERROR( CV_StsNullPtr, "" );
 
     if( !subdiv->is_geometry_valid )
         cvCalcSubdivVoronoi2D( subdiv );
index 5944aa77310d8cd47bf37dae6f67ed4bfeb80c26..1e507790cb5faf2896e19e2a80918c88a1edca1f 100644 (file)
 
 #include "_cv.h"
 
-/****************************************************************************************\
-*                             Find sum of pixels in the ROI                              *
-\****************************************************************************************/
-
-
-#define ICV_DEF_SUM_1D_CASE_COI( __op__, src, len, sum, cn )                \
-{                                                                           \
-    int i;                                                                  \
-                                                                            \
-    for( i = 0; i <= (len) - 4*(cn); i += 4*(cn) )                          \
-        (sum)[0] += __op__((src)[i]) + __op__((src)[i+(cn)]) +              \
-                    __op__((src)[i+(cn)*2]) + __op__((src)[i+(cn)*3]);      \
-                                                                            \
-    for( ; i < (len); i += (cn) )                                           \
-        (sum)[0] += __op__((src)[i]);                                       \
-}                                                                           \
-
-
-#define ICV_DEF_SUM_1D_CASE_C1( __op__, src, len, sum ) \
-    ICV_DEF_SUM_1D_CASE_COI( __op__, src, len, sum, 1 )
-
-
-#define ICV_DEF_SUM_1D_CASE_C2( __op__, src, len, sum )                     \
-{                                                                           \
-    int i;                                                                  \
-                                                                            \
-    for( i = 0; i <= (len) - 8; i += 8 )                                    \
-    {                                                                       \
-        (sum)[0] += __op__((src)[i]) + __op__((src)[i+2]) +                 \
-                    __op__((src)[i+4]) + __op__((src)[i+6]);                \
-        (sum)[1] += __op__((src)[i+1]) + __op__((src)[i+3]) +               \
-                    __op__((src)[i+5]) + __op__((src)[i+7]);                \
-    }                                                                       \
-                                                                            \
-    for( ; i < (len); i += 2 )                                              \
-    {                                                                       \
-        (sum)[0] += __op__((src)[i]);                                       \
-        (sum)[1] += __op__((src)[i+1]);                                     \
-    }                                                                       \
-}                                                                           \
-
-
-#define ICV_DEF_SUM_1D_CASE_C3( __op__, src, len, sum )                     \
-{                                                                           \
-    int i;                                                                  \
-                                                                            \
-    for( i = 0; i <= (len) - 12; i += 12 )                                  \
-    {                                                                       \
-        (sum)[0] += __op__((src)[i]) + __op__((src)[i+3]) +                 \
-                    __op__((src)[i+6]) + __op__((src)[i+9]);                \
-        (sum)[1] += __op__((src)[i+1]) + __op__((src)[i+4]) +               \
-                    __op__((src)[i+7]) + __op__((src)[i+10]);               \
-        (sum)[2] += __op__((src)[i+2]) + __op__((src)[i+5]) +               \
-                    __op__((src)[i+8]) + __op__((src)[i+11]);               \
-    }                                                                       \
-                                                                            \
-    for( ; i < (len); i += 3 )                                              \
-    {                                                                       \
-        (sum)[0] += __op__((src)[i]);                                       \
-        (sum)[1] += __op__((src)[i+1]);                                     \
-        (sum)[2] += __op__((src)[i+2]);                                     \
-    }                                                                       \
-}
-
-
-#define ICV_DEF_SUM_1D_CASE_C4( __op__, src, len, sum )                     \
-{                                                                           \
-    int i;                                                                  \
-                                                                            \
-    for( i = 0; i <= (len) - 16; i += 16 )                                  \
-    {                                                                       \
-        (sum)[0] += __op__((src)[i]) + __op__((src)[i+4]) +                 \
-                    __op__((src)[i+8]) + __op__((src)[i+12]);               \
-        (sum)[1] += __op__((src)[i+1]) + __op__((src)[i+5]) +               \
-                    __op__((src)[i+9]) + __op__((src)[i+13]);               \
-        (sum)[2] += __op__((src)[i+2]) + __op__((src)[i+6]) +               \
-                    __op__((src)[i+10]) + __op__((src)[i+14]);              \
-        (sum)[3] += __op__((src)[i+3]) + __op__((src)[i+7]) +               \
-                    __op__((src)[i+11]) + __op__((src)[i+15]);              \
-    }                                                                       \
-                                                                            \
-    for( ; i < (len); i += 4 )                                              \
-    {                                                                       \
-        (sum)[0] += __op__((src)[i]);                                       \
-        (sum)[1] += __op__((src)[i+1]);                                     \
-        (sum)[2] += __op__((src)[i+2]);                                     \
-        (sum)[3] += __op__((src)[i+3]);                                     \
-    }                                                                       \
-}
-
-
-#define CV_SUM_ENTRY_C1( sumtype ) \
-    sumtype temp[1] = { 0 };
-
-#define CV_SUM_ENTRY_C2( sumtype ) \
-    sumtype temp[2] = { 0, 0 };
-
-#define CV_SUM_ENTRY_C3( sumtype ) \
-    sumtype temp[3] = { 0, 0, 0 };
-
-#define CV_SUM_ENTRY_C4( sumtype ) \
-    sumtype temp[4] = { 0, 0, 0, 0 };
-
-#define CV_SUM_EXIT_C1(sumtype_final) \
-    sum[0] = (sumtype_final)temp[0]
-
-#define CV_SUM_EXIT_C2(sumtype_final) \
-    CV_SUM_EXIT_C1(sumtype_final), sum[1] = (sumtype_final)temp[1]
-
-#define CV_SUM_EXIT_C3(sumtype_final) \
-    CV_SUM_EXIT_C2(sumtype_final), sum[2] = (sumtype_final)temp[2]
-
-#define CV_SUM_EXIT_C4(sumtype_final) \
-    CV_SUM_EXIT_C3(sumtype_final), sum[3] = (sumtype_final)temp[3]
-
-
-#define ICV_DEF_SUM_FUNC_2D( __op__, _entry_, _exit_, name, flavor,         \
-                             cn, srctype, sumtype, sumtype_final )          \
-IPCVAPI_IMPL(CvStatus, icv##name##_##flavor##_C##cn##R,( const srctype* src,\
-                                    int step, CvSize size, sumtype_final* sum ))\
-{                                                                           \
-    _entry_( sumtype );                                                     \
-    size.width *= cn;                                                       \
-                                                                            \
-    for( int y = 0; y < size.height; y++, (char*&)src += step )             \
-    {                                                                       \
-        ICV_DEF_SUM_1D_CASE_C##cn( __op__, src, size.width, temp );         \
-    }                                                                       \
-                                                                            \
-    _exit_(sumtype_final);                                                  \
-                                                                            \
-    return CV_OK;                                                           \
-}
-
-
-#define ICV_DEF_SUM_0D_CASE_C1( __op__, src, sum )                          \
-{                                                                           \
-    (sum)[0] += __op__((src)[0]);                                           \
-}                                                                           \
-
-
-#define ICV_DEF_SUM_0D_CASE_C2( __op__, src, sum )                          \
-{                                                                           \
-    (sum)[0] += __op__((src)[0]);                                           \
-    (sum)[1] += __op__((src)[1]);                                           \
-}                                                                           \
-
-
-#define ICV_DEF_SUM_FUNC_2D_EX( __op__, _entry_, _exit_, name, flavor,      \
-                                cn, srctype, sumtype, sumtype_final )       \
-IPCVAPI_IMPL(CvStatus, icv##name##_##flavor##_C##cn##R,( const srctype* src,\
-                                    int step, CvSize size, sumtype_final* sum )) \
-{                                                                           \
-    _entry_( sumtype );                                                     \
-                                                                            \
-    if( size.width == 1 )                                                   \
-    {                                                                       \
-        for( int y = 0; y < size.height; y++, (char*&)src += step )         \
-        {                                                                   \
-            ICV_DEF_SUM_0D_CASE_C##cn( __op__, src, temp );                 \
-        }                                                                   \
-    }                                                                       \
-    else                                                                    \
-    {                                                                       \
-        size.width *= cn;                                                   \
-                                                                            \
-        for( int y = 0; y < size.height; y++, (char*&)src += step )         \
-        {                                                                   \
-            ICV_DEF_SUM_1D_CASE_C##cn( __op__, src, size.width, temp );     \
-        }                                                                   \
-    }                                                                       \
-                                                                            \
-    _exit_(sumtype_final);                                                  \
-                                                                            \
-    return CV_OK;                                                           \
-}
-
-
-
-#define ICV_DEF_SUM_FUNC_2D_COI( __op__, name, flavor, srctype,             \
-                                 sumtype, sumtype_final )                   \
-IPCVAPI_IMPL(CvStatus, icv##name##_##flavor##_CnCR, ( const srctype* src,   \
-                    int step, CvSize size, int cn, int coi, sumtype_final* sum )) \
-{                                                                           \
-    CV_SUM_ENTRY_C1( sumtype );                                             \
-                                                                            \
-    size.width *= cn;                                                       \
-    src += coi - 1;                                                         \
-                                                                            \
-    for( int y = 0; y < size.height; y++, (char*&)src += step )             \
-    {                                                                       \
-        ICV_DEF_SUM_1D_CASE_COI( __op__, src, size.width, temp, cn );       \
-    }                                                                       \
-                                                                            \
-    CV_SUM_EXIT_C1(sumtype_final);                                          \
-                                                                            \
-    return CV_OK;                                                           \
-}
-
-
-#define ICV_DEF_SUM_ALL( __op__, name, flavor, srctype, sumtype, sumtype_final )\
-    ICV_DEF_SUM_FUNC_2D( __op__, CV_SUM_ENTRY_C1, CV_SUM_EXIT_C1,               \
-                         name, flavor, 1, srctype, sumtype, sumtype_final )     \
-    ICV_DEF_SUM_FUNC_2D( __op__, CV_SUM_ENTRY_C2, CV_SUM_EXIT_C2,               \
-                         name, flavor, 2, srctype, sumtype, sumtype_final )     \
-    ICV_DEF_SUM_FUNC_2D( __op__, CV_SUM_ENTRY_C3, CV_SUM_EXIT_C3,               \
-                         name, flavor, 3, srctype, sumtype, sumtype_final )     \
-    ICV_DEF_SUM_FUNC_2D( __op__, CV_SUM_ENTRY_C4, CV_SUM_EXIT_C4,               \
-                         name, flavor, 4, srctype, sumtype, sumtype_final )     \
-    ICV_DEF_SUM_FUNC_2D_COI( __op__, name, flavor, srctype, sumtype, sumtype_final )
-
-
-ICV_DEF_SUM_ALL( CV_NOP, Sum, 8u, uchar, int64, double )
-ICV_DEF_SUM_ALL( CV_NOP, Sum, 8s, char, int64, double )
-ICV_DEF_SUM_ALL( CV_NOP, Sum, 16s, short, int64, double )
-ICV_DEF_SUM_ALL( CV_CAST_64S, Sum, 32s, int, int64, double )
-ICV_DEF_SUM_ALL( CV_NOP, Sum, 32f, float, double, double )
-ICV_DEF_SUM_ALL( CV_NOP, Sum, 64f, double, double, double )
-
-CV_DEF_INIT_BIG_FUNC_TAB( Sum, R )
-CV_DEF_INIT_FUNC_TAB_2D( Sum, CnCR )
-
-CV_IMPL CvScalar
-cvSum( const CvArr* arr )
-{
-    static CvBigFuncTable sum_tab;
-    static CvFuncTable sumcoi_tab;
-    static int inittab = 0;
-
-    CvScalar sum = {{ 0, 0, 0, 0 }};
-
-    CV_FUNCNAME("cvSum");
-
-    __BEGIN__;
-
-    int type, coi = 0;
-    int mat_step;
-    CvSize size;
-    CvMat stub, *mat = (CvMat*)arr;
-
-    if( !inittab )
-    {
-        icvInitSumRTable( &sum_tab );
-        icvInitSumCnCRTable( &sumcoi_tab );
-        inittab = 1;
-    }
-
-    if( !CV_IS_MAT(mat) )
-    {
-        if( CV_IS_MATND(mat) )
-        {
-            CvMatND stub;
-            CvMatNDIterator iterator;
-            CvFunc2D_1A1P func;
-
-            CV_CALL( icvPrepareArrayOp( 1, (void**)&mat, 0, &stub, &iterator ));
-
-            type = CV_MAT_TYPE(iterator.hdr[0]->type);
-            func = (CvFunc2D_1A1P)(sum_tab.fn_2d[type]);
-            if( !func )
-                CV_ERROR( CV_StsUnsupportedFormat, "" );
-       
-            do
-            {
-                CvScalar temp = {{ 0, 0, 0, 0 }};
-                IPPI_CALL( func( iterator.ptr[0], CV_STUB_STEP,
-                                 iterator.size, temp.val ));
-                sum.val[0] += temp.val[0];
-                sum.val[1] += temp.val[1];
-                sum.val[2] += temp.val[2];
-                sum.val[3] += temp.val[3];
-            }
-            while( icvNextMatNDSlice( &iterator ));
-            EXIT;
-        }
-        else
-            CV_CALL( mat = cvGetMat( mat, &stub, &coi ));
-    }
-
-    type = CV_MAT_TYPE(mat->type);
-    size = icvGetMatSize( mat );
-
-    mat_step = mat->step;
-
-    if( CV_IS_MAT_CONT( mat->type ))
-    {
-        size.width *= size.height;
-        
-        if( size.width <= CV_MAX_INLINE_MAT_OP_SIZE )
-        {
-            if( type == CV_32FC1 )
-            {
-                float* data = mat->data.fl;
-
-                do
-                {
-                    sum.val[0] += data[size.width - 1];
-                }
-                while( --size.width );
-
-                EXIT;
-            }
-
-            if( type == CV_64FC1 )
-            {
-                double* data = mat->data.db;
-
-                do
-                {
-                    sum.val[0] += data[size.width - 1];
-                }
-                while( --size.width );
-
-                EXIT;
-            }
-        }
-        size.height = 1;
-        mat_step = CV_STUB_STEP;
-    }
-
-    if( CV_MAT_CN(type) == 1 || coi == 0 )
-    {
-        CvFunc2D_1A1P func = (CvFunc2D_1A1P)(sum_tab.fn_2d[type]);
-
-        if( !func )
-            CV_ERROR( CV_StsBadArg, icvUnsupportedFormat );
-
-        IPPI_CALL( func( mat->data.ptr, mat_step, size, sum.val ));
-    }
-    else
-    {
-        CvFunc2DnC_1A1P func = (CvFunc2DnC_1A1P)(sumcoi_tab.fn_2d[CV_MAT_DEPTH(type)]);
-
-        if( !func )
-            CV_ERROR( CV_StsBadArg, icvUnsupportedFormat );
-
-        IPPI_CALL( func( mat->data.ptr, mat_step, size,
-                         CV_MAT_CN(type), coi, sum.val ));
-    }
-
-    __END__;
-
-    return  sum;
-}
-
-
-#define ICV_DEF_SUM_C1( __op__, name, flavor, srctype, sumtype )        \
-    ICV_DEF_SUM_FUNC_2D( __op__, CV_SUM_ENTRY_C1, CV_SUM_EXIT_C1,       \
-                         name, flavor, 1, srctype, sumtype, int )       \
-    ICV_DEF_SUM_FUNC_2D_COI( __op__, name, flavor, srctype, sumtype, int )
-
-ICV_DEF_SUM_C1( CV_NONZERO, CountNonZero, 8u, uchar, int )
-ICV_DEF_SUM_C1( CV_NONZERO, CountNonZero, 16s, ushort, int )
-ICV_DEF_SUM_C1( CV_NONZERO, CountNonZero, 32s, int, int )
-ICV_DEF_SUM_C1( CV_NONZERO_FLT, CountNonZero, 32f, int, int )
-ICV_DEF_SUM_C1( CV_NONZERO_FLT, CountNonZero, 64f, int64, int )
-
-#define icvCountNonZero_8s_C1R icvCountNonZero_8u_C1R
-#define icvCountNonZero_8s_CnCR icvCountNonZero_8u_CnCR
-
-CV_DEF_INIT_FUNC_TAB_2D( CountNonZero, C1R )
-CV_DEF_INIT_FUNC_TAB_2D( CountNonZero, CnCR )
-
-
-CV_IMPL int
-cvCountNonZero( const CvArr* img )
-{
-    static CvFuncTable nz_tab;
-    static CvFuncTable nzcoi_tab;
-    static int inittab = 0;
-
-    int count = 0;
-
-    CV_FUNCNAME("cvCountNonZero");
-
-    __BEGIN__;
-
-    int type, coi = 0;
-    int mat_step;
-    CvSize size;
-    CvMat stub, *mat = (CvMat*)img;
-
-    if( !inittab )
-    {
-        icvInitCountNonZeroC1RTable( &nz_tab );
-        icvInitCountNonZeroCnCRTable( &nzcoi_tab );
-        inittab = 1;
-    }
-
-    if( !CV_IS_MAT(mat) )
-    {
-        if( CV_IS_MATND(mat) )
-        {
-            CvMatND stub;
-            CvMatNDIterator iterator;
-            CvFunc2D_1A1P func;
-
-            CV_CALL( icvPrepareArrayOp( 1, (void**)&mat, 0, &stub, &iterator ));
-
-            type = CV_MAT_TYPE(iterator.hdr[0]->type);
-
-            if( CV_MAT_CN(type) != 1 )
-                CV_ERROR( CV_BadNumChannels,
-                    "Only single-channel array are supported here" );
-
-            func = (CvFunc2D_1A1P)(nz_tab.fn_2d[CV_MAT_DEPTH(type)]);
-            if( !func )
-                CV_ERROR( CV_StsUnsupportedFormat, "" );
-       
-            do
-            {
-                int temp;
-                IPPI_CALL( func( iterator.ptr[0], CV_STUB_STEP,
-                                 iterator.size, &temp ));
-                count += temp;
-            }
-            while( icvNextMatNDSlice( &iterator ));
-            EXIT;
-        }
-        else
-            CV_CALL( mat = cvGetMat( mat, &stub, &coi ));
-    }
-
-    type = CV_MAT_TYPE(mat->type);
-    size = icvGetMatSize( mat );
-
-    mat_step = mat->step;
-
-    if( CV_IS_MAT_CONT( mat->type ))
-    {
-        size.width *= size.height;
-        size.height = 1;
-        mat_step = CV_STUB_STEP;
-    }
-
-    if( CV_MAT_CN(type) == 1 || coi == 0 )
-    {
-        CvFunc2D_1A1P func = (CvFunc2D_1A1P)(nz_tab.fn_2d[CV_MAT_DEPTH(type)]);
-
-        if( CV_MAT_CN(type) != 1 )
-            CV_ERROR( CV_BadNumChannels,
-            "The function can handle only a single channel at a time (use COI)");
-
-        if( !func )
-            CV_ERROR( CV_StsBadArg, icvUnsupportedFormat );
-
-        IPPI_CALL( func( mat->data.ptr, mat_step, size, &count ));
-    }
-    else
-    {
-        CvFunc2DnC_1A1P func = (CvFunc2DnC_1A1P)(nzcoi_tab.fn_2d[CV_MAT_DEPTH(type)]);
-
-        if( !func )
-            CV_ERROR( CV_StsBadArg, icvUnsupportedFormat );
-
-        IPPI_CALL( func( mat->data.ptr, mat_step, size, CV_MAT_CN(type), coi, &count ));
-    }
-
-    __END__;
-
-    return  count;
-}
-
-
 #define ICV_DEF_INTEGRAL_OP( flavor, arrtype, sumtype, sqsumtype, worktype,     \
                              cast_macro, cast_sqr_macro )                       \
-IPCVAPI( CvStatus,                                                              \
-    icvIntegralImage_##flavor##_C1R,( const arrtype* src, int srcstep,          \
-                                    sumtype* sum, int sumstep,                  \
-                                    sqsumtype* sqsum, int sqsumstep,            \
-                                    sumtype* tilted, int tiltedstep,            \
-                                    CvSize size ))                              \
-                                                                                \
-IPCVAPI_IMPL( CvStatus,                                                         \
-    icvIntegralImage_##flavor##_C1R,( const arrtype* src, int srcstep,          \
-                                    sumtype* sum, int sumstep,                  \
-                                    sqsumtype* sqsum, int sqsumstep,            \
-                                    sumtype* tilted, int tiltedstep,            \
-                                    CvSize size ))                              \
+static CvStatus CV_STDCALL                                                      \
+icvIntegralImage_##flavor##_C1R( const arrtype* src, int srcstep,               \
+                                 sumtype* sum, int sumstep,                     \
+                                 sqsumtype* sqsum, int sqsumstep,               \
+                                 sumtype* tilted, int tiltedstep,               \
+                                 CvSize size )                                  \
 {                                                                               \
     int x, y;                                                                   \
     sumtype s;                                                                  \
@@ -616,7 +145,7 @@ IPCVAPI_IMPL( CvStatus,
             return CV_NULLPTR_ERR;                                              \
         }                                                                       \
                                                                                 \
-        buf = (sumtype*)alloca( (size.width + 1 )* sizeof(buf[0]));             \
+        buf = (sumtype*)cvStackAlloc( (size.width + 1 )* sizeof(buf[0]));       \
         sum[-1] = tilted[-1] = 0;                                               \
         sqsum[-1] = 0;                                                          \
                                                                                 \
@@ -792,7 +321,7 @@ cvIntegral( const CvArr* image, CvArr* sumImage,
     IPPI_CALL( func( src->data.ptr, src->step, sum->data.ptr, sum->step,
                      sqsum ? sqsum->data.ptr : 0, sqsum ? sqsum->step : 0,
                      tilted ? tilted->data.ptr : 0, tilted ? tilted->step : 0,
-                     icvGetMatSize( src )));
+                     cvGetMatSize( src )));
 
 
     __END__;
index 4884ff056201a9e2715a27554390e3454fd1df10..611248d00d745950a95d9b0f08876452b3142163 100644 (file)
 //
 //M*/
 
-
 /****************************************************************************************/
-/*                This part of code is used to generate DLL function body               */
+/*                         Dynamic detection and loading of IPP modules                 */
 /****************************************************************************************/
 
-/* get all the function prototypes as in static library */
 #include "_cv.h"
 
-#if _MSC_VER >= 1200
-#pragma warning( disable: 4115 )        /* type definition in () */
-#pragma warning( disable: 4100 )        /* unreferenced formal paramter */
-#endif
-
-#ifdef WIN32
-#include <windows.h>
-#else
-#include <dlfcn.h>
-#include <string.h>
-#endif
-
-#include <stdio.h>
-#include <ctype.h>
-
-
-typedef const char* CvProcessorType;
-
-#define CV_PROC_GENERIC    ""
-#define CV_PROC_IA32_PII   "m6"
-#define CV_PROC_IA32_PIII  "a6"
-#define CV_PROC_IA32_P4    "w7"
-
-/*
-   determine processor type
-*/
-static CvProcessorType
-icvGetProcessorType( void )
-{
-    CvProcessorType proc_type = CV_PROC_GENERIC;
-
-#ifdef  WIN32
-
-    SYSTEM_INFO sys;
-    GetSystemInfo( &sys );
-
-    if( sys.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL &&
-        sys.dwProcessorType == PROCESSOR_INTEL_PENTIUM )
-    {
-        static const char cpuid_code[] =
-            "\x53\x56\x57\xb8\x01\x00\x00\x00\x0f\xa2\x5f\x5e\x5b\xc3";
-        typedef int64 (CV_CDECL * func_ptr)(void);
-        func_ptr cpuid = (func_ptr)(void*)cpuid_code;
-
-        int version = 0, features = 0, family = 0;
-        int id = 0;
-
-        int64 val = cpuid();
-        version = (int)val;
-        features = (int)(val >> 32);
-
-        #define ICV_CPUID_M6     ((1<<15)|(1<<23)|6)  /* cmov + mmx */
-        #define ICV_CPUID_A6     ((1<<25)|ICV_CPUID_M6) /* <all above> + xmm */
-        #define ICV_CPUID_W7     ((1<<26)|ICV_CPUID_A6|(1<<3)|1) /* <all above> + emm */
-
-        family = (version >> 8) & 15;
-        if( family >= 6 && (features & (ICV_CPUID_M6 & ~6)) != 0 ) /* Pentium II or higher */
-        {
-            id = (features & ICV_CPUID_W7 & -256) | family;
-        }
-
-        switch( id )
-        {
-        case ICV_CPUID_W7:
-            proc_type = CV_PROC_IA32_P4;
-            break;
-        case ICV_CPUID_A6:
-            proc_type = CV_PROC_IA32_PIII;
-            break;
-        case ICV_CPUID_M6:
-            proc_type = CV_PROC_IA32_PII;
-            break;
-        }
-    }
-
-#else
-    char buffer[1000] = "";
-
-    //reading /proc/cpuinfo file (proc file system must be supported)
-    FILE *file = fopen( "/proc/cpuinfo", "r" );
-
-    memset( buffer, 0, sizeof(buffer));
-
-    if( file && fread( buffer, 1, 1000, file ))
-    {
-        if( strstr( buffer, "mmx" ) && strstr( buffer, "cmov" ))
-        {
-            proc_type = CV_PROC_IA32_PII;
-
-            if( strstr( buffer, "xmm" ) || strstr( buffer, "sse" ))
-            {
-                proc_type = CV_PROC_IA32_PIII;
-
-                if( strstr( buffer, "emm" ))
-                    proc_type = CV_PROC_IA32_P4;
-            }
-        }
-    }
-#endif
-
-    return proc_type;
-}
-
-
-static CvProcessorType
-icvPreviousProcessor( const char* proc_type )
-{
-    char signature[100];
-    int i;
-
-    if( strlen( proc_type ) >= sizeof(signature))
-        return CV_PROC_GENERIC;
-
-    for( i = 0; proc_type[i]; i++ )
-        signature[i] = (char)tolower( proc_type[i] );
-
-    signature[i++] = '\0';
-
-    if( !strcmp( signature, CV_PROC_IA32_P4 ))
-        proc_type = CV_PROC_IA32_PIII;
-    else if( !strcmp( signature, CV_PROC_IA32_PIII ))
-        proc_type = CV_PROC_IA32_PII;
-    else
-        proc_type = CV_PROC_GENERIC;
-
-    return proc_type;
-}
-
-
-#define __CV_DEFINE_USER_LIST__
-
-/****************************************************************************************/
-/*              Implement all dll functions via static library calls                    */
-/****************************************************************************************/
-
 /****************************************************************************************/
 /*                               Make functions descriptions                            */
 /****************************************************************************************/
 
-typedef void (CV_CDECL * ipp_func_addr) (void);
-
-#undef IPCVAPI
-#define GETAPI(addr,name) { (ipp_func_addr*)&addr, #name, 0 },
-#define IPCVAPI(type,name,arg) GETAPI( name, name )
-
-struct func_desc
-{
-    ipp_func_addr *addr;
-    const char *name;
-    int loaded;
-};
-
-static func_desc ipp_func_desc[] =
-{
-#undef __IPCV_H_
-#include "_ipcv.h"
-#undef __IPCV_H_
-    {0, 0}
-};
-
-
-#undef __IPCV_H_
-#undef IPCVAPI
-#define IPCVAPI(type,name,arg)                          \
-    *(ipp_func_desc[i].addr) = (ipp_func_addr)name##_f; \
-    ipp_func_desc[i].loaded = 0;                        \
-    i++;
-
-// set all the primitive function pointers to OpenCV code.
-static void icvResetPointers()
-{
-    int i = 0;
-#include "_ipcv.h"
-}
-
-/*
-   determine processor type, load appropriate dll and
-   initialize all function pointers
-*/
-#ifdef WIN32
-#define DLL_PREFIX ""
-#define DLL_SUFFIX ".dll"
-#else
-#define DLL_PREFIX "lib"
-#define DLL_SUFFIX ".so"
-#define LoadLibrary(name) dlopen(name, RTLD_LAZY)
-#define FreeLibrary(name) dlclose(name)
-#define GetProcAddress dlsym
-typedef void* HMODULE;
-#endif
-
-#if 0 /*def _DEBUG*/
-#define DLL_DEBUG_FLAG "d"
-#else
-#define DLL_DEBUG_FLAG ""
-#endif
-
-//#define VERBOSE_LOADING
-
-#ifdef VERBOSE_LOADING
-#define ICV_PRINTF(args)  printf args
-#else
-#define ICV_PRINTF(args)
-#endif
+#undef IPCVAPI_EX
+#define IPCVAPI_EX(type,func_name,names,modules,arg) \
+    { &(void*&)func_name##_p, (void*)(size_t)-1, names, modules, 0 },
 
-typedef struct CvModuleInfo
+static CvPluginFuncInfo cv_ipp_tab[] =
 {
-    const char* basename;
-    HMODULE handle;
-    char name[100];
-}
-CvModuleInfo;
-
-static CvModuleInfo modules[] =
-{
-    {"ippcv", 0, "" },
-    {"optcv", 0, "" },
-    { 0, 0, "" }
+#undef _CV_IPP_H_
+#include "_cvipp.h"
+#undef _CV_IPP_H_
+    {0, 0, 0, 0, 0}
 };
 
-static const char* prefices[] = { "ippi", "ippcv", 0 };
-
-CV_IMPL int
-cvLoadPrimitives( const char* processor_type )
-{
-    int i, loaded_modules = 0, loaded_functions = 0;
-    CvProcessorType proc_type = CvProcessorType(processor_type);
-    
-    icvResetPointers();
-
-    if( !proc_type || strcmp(proc_type, CV_PROC_GENERIC) != 0 )
-        proc_type = icvGetProcessorType();
-
-    // try to load optimized dlls
-    for( i = 0; modules[i].basename; i++ )
-    {
-        CvProcessorType proc = proc_type;
-
-        // unload previously loaded optimized modules
-        if( modules[i].handle )
-        {
-            FreeLibrary( modules[i].handle );
-            modules[i].handle = 0;
-        }
-        
-        while( strcmp( proc, CV_PROC_GENERIC ) != 0 )
-        {
-            sprintf( modules[i].name, DLL_PREFIX "%s%s" DLL_DEBUG_FLAG DLL_SUFFIX,
-                     modules[i].basename, (const char*)proc );
-            
-            modules[i].handle = LoadLibrary( modules[i].name );
-            if( modules[i].handle != 0 )
-            {
-                ICV_PRINTF(("%s loaded\n", modules[i].name )); 
-                loaded_modules++;
-                break;
-            }
-            
-            proc = icvPreviousProcessor( proc );
-        }
-    }
-
-    if( loaded_modules > 0 )
-    {
-        for( i = 0; ipp_func_desc[i].name != 0; i++ )
-        {
-        #if _MSC_VER >= 1200
-            #pragma warning( disable: 4054 4055 )   /* converting pointers to code<->data */
-        #endif
-            char name[100];
-            uchar* addr = 0;
-            int j = 0, k = 0;
-
-            if( ipp_func_desc[i].loaded )
-                continue;
-
-            for( j = 0; prefices[j] != 0; j++ )
-            {
-                strcpy( name, prefices[j] );
-                strcat( name, ipp_func_desc[i].name + 3 );
-
-                for( k = 0; modules[k].basename != 0; k++ )
-                    if( modules[k].handle )
-                    {
-                        addr = (uchar*)GetProcAddress( modules[k].handle, name );
-                        if( addr )
-                            break;
-                    }
-
-                if( addr )
-                    break;
-            }
-
-            if( addr )
-            {
-            #ifdef WIN32            
-                while( *addr == 0xE9 )
-                    addr += 5 + *((int*)(addr + 1));
-            #endif
-                *ipp_func_desc[i].addr = (ipp_func_addr)addr;
-                ipp_func_desc[i].loaded = k+1; // store incremented index of the module
-                                               // that contain the loaded function
-                loaded_functions++;
-                ICV_PRINTF(("%s:  \t%s\n", ipp_func_desc[i].name, modules[k].name ));
-            }
-
-            #if _MSC_VER >= 1200
-                #pragma warning( default: 4054 4055 )
-            #endif
-        }
-    }
-    
-#ifdef VERBOSE_LOADING
-    {
-    int not_loaded = 0;
-    ICV_PRINTF(("\nTotal loaded: %d\n\n", loaded_functions ));
-    printf( "***************************************************\nNot loaded ...\n\n" );
-    for( i = 0; ipp_func_desc[i].name != 0; i++ )
-        if( !ipp_func_desc[i].loaded )
-        {
-            ICV_PRINTF(( "%s\n", ipp_func_desc[i].name ));
-            not_loaded++;
-        }
-
-    ICV_PRINTF(("\nTotal: %d\n", not_loaded ));
-    }
-#endif
-
-    return loaded_functions;
-}
-
-
-static int loaded_functions = cvLoadPrimitives();
-
-
-void
-cvGetLibraryInfo( const char **_version, int *_loaded, const char **_dll_name )
-{
-    static const char* version = __DATE__;
-    static char loaded_modules[1000] = "";
-
-    if( _version )
-        *_version = version;
-    
-    if( _loaded )
-        *_loaded = loaded_functions;
-    
-    if( _dll_name )
-    {
-        int i;
-        static int init_loaded_modules = 0;
-        
-        if( !init_loaded_modules )
-        {
-            init_loaded_modules = 1;
-            for( i = 0; modules[i].basename; i++ )
-                if( modules[i].handle != 0 )
-                {
-                    sprintf( loaded_modules + strlen(loaded_modules),
-                             ", %s", modules[i].name );
-                }
-        }
-
-        *_dll_name = strlen(loaded_modules) == 0 ? "none" :
-                     (const char*)(loaded_modules + 2); // skip ", "
-    }
-}
-
-
-CV_IMPL int
-cvFillInternalFuncsTable(void* tbl)
-{
-    int loaded = 0;
-
-    func_desc* table = (func_desc*)tbl;
-    assert(table);
-
-    for( int i = 0; table[i].name; i++ )
-    {
-        int j;
-        for( j = 0;
-             ipp_func_desc[j].name && strcmp( ipp_func_desc[j].name, table[i].name );
-             j++ );
-        if( ipp_func_desc[j].name )
-        {
-            *table[i].addr = *ipp_func_desc[j].addr;
-            table[i].loaded = 1;
-            loaded++;
-        }
-    }
-
-    return loaded;
-}
-
+static CvModuleInfo cv_module = { 0, "cv", "beta 4.0", cv_ipp_tab };
+static int loaded_functions = cvRegisterModule( &cv_module );
 
 /* End of file. */
index d035df754fe5da654283f6af6b6477e046ea8928..1c28927082384426f9c635e785990d25285b5523 100644 (file)
@@ -6,31 +6,7 @@
 
 #include "_cv.h"
 
-const char icvDepthToType[] =
-{
-    -1, -1, CV_8U, CV_8S, -1, CV_16S, -1, -1,
-    CV_32F, CV_32S, -1, -1, -1, -1, -1, -1, CV_64F, -1
-};
-
-const int icvTypeToDepth[] =
-{
-    IPL_DEPTH_8U, IPL_DEPTH_8S, IPL_DEPTH_16S,
-    IPL_DEPTH_32S, IPL_DEPTH_32F, IPL_DEPTH_64F
-};
-
-const int icvPixSize[] =
-{
-    sizeof(uchar)*1, sizeof(char)*1, sizeof(short)*1, sizeof(int)*1,
-    sizeof(float)*1, sizeof(double)*1, 0, 0,
-    sizeof(uchar)*2, sizeof(char)*2, sizeof(short)*2, sizeof(int)*2,
-    sizeof(float)*2, sizeof(double)*2, 0, 0,
-    sizeof(uchar)*3, sizeof(char)*3, sizeof(short)*3, sizeof(int)*3,
-    sizeof(float)*3, sizeof(double)*3, 0, 0,
-    sizeof(uchar)*4, sizeof(char)*4, sizeof(short)*4, sizeof(int)*4,
-    sizeof(float)*4, sizeof(double)*4, 0, 0
-};
-
-const float icv8x32fTab[] =
+const float icv8x32fTab_cv[] =
 {
     -128.f, -127.f, -126.f, -125.f, -124.f, -123.f, -122.f, -121.f,
     -120.f, -119.f, -118.f, -117.f, -116.f, -115.f, -114.f, -113.f,
@@ -82,7 +58,6 @@ const float icv8x32fTab[] =
      248.f,  249.f,  250.f,  251.f,  252.f,  253.f,  254.f,  255.f
 };
 
-
 const float icv8x32fSqrTab[] =
 {
  16384.f,  16129.f,  15876.f,  15625.f,  15376.f,  15129.f,  14884.f,  14641.f,
@@ -135,7 +110,6 @@ const float icv8x32fSqrTab[] =
  61504.f,  62001.f,  62500.f,  63001.f,  63504.f,  64009.f,  64516.f,  65025.f
 };
 
-
 const uchar icvSaturate8u[] = 
 {
       0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
@@ -189,41 +163,4 @@ const uchar icvSaturate8u[] =
     255
 };
 
-
-const char icvSaturate8s[] = 
-{
--128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
--128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
--128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
--128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
--128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
--128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
--128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
--128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
--128, -127, -126, -125, -124, -123, -122, -121, -120, -119, -118, -117, -116, -115, -114, -113,
--112, -111, -110, -109, -108, -107, -106, -105, -104, -103, -102, -101, -100,  -99,  -98,  -97,
- -96,  -95,  -94,  -93,  -92,  -91,  -90,  -89,  -88,  -87,  -86,  -85,  -84,  -83,  -82,  -81,
- -80,  -79,  -78,  -77,  -76,  -75,  -74,  -73,  -72,  -71,  -70,  -69,  -68,  -67,  -66,  -65,
- -64,  -63,  -62,  -61,  -60,  -59,  -58,  -57,  -56,  -55,  -54,  -53,  -52,  -51,  -50,  -49,
- -48,  -47,  -46,  -45,  -44,  -43,  -42,  -41,  -40,  -39,  -38,  -37,  -36,  -35,  -34,  -33,
- -32,  -31,  -30,  -29,  -28,  -27,  -26,  -25,  -24,  -23,  -22,  -21,  -20,  -19,  -18,  -17,
- -16,  -15,  -14,  -13,  -12,  -11,  -10,   -9,   -8,   -7,   -6,   -5,   -4,   -3,   -2,   -1,
-   0,    1,    2,    3,    4,    5,    6,    7,    8,    9,   10,   11,   12,   13,   14,   15,
-  16,   17,   18,   19,   20,   21,   22,   23,   24,   25,   26,   27,   28,   29,   30,   31,
-  32,   33,   34,   35,   36,   37,   38,   39,   40,   41,   42,   43,   44,   45,   46,   47,
-  48,   49,   50,   51,   52,   53,   54,   55,   56,   57,   58,   59,   60,   61,   62,   63,
-  64,   65,   66,   67,   68,   69,   70,   71,   72,   73,   74,   75,   76,   77,   78,   79,
-  80,   81,   82,   83,   84,   85,   86,   87,   88,   89,   90,   91,   92,   93,   94,   95,
-  96,   97,   98,   99,  100,  101,  102,  103,  104,  105,  106,  107,  108,  109,  110,  111,
- 112,  113,  114,  115,  116,  117,  118,  119,  120,  121,  122,  123,  124,  125,  126,  127,
- 127,  127,  127,  127,  127,  127,  127,  127,  127,  127,  127,  127,  127,  127,  127,  127,
- 127,  127,  127,  127,  127,  127,  127,  127,  127,  127,  127,  127,  127,  127,  127,  127,
- 127,  127,  127,  127,  127,  127,  127,  127,  127,  127,  127,  127,  127,  127,  127,  127,
- 127,  127,  127,  127,  127,  127,  127,  127,  127,  127,  127,  127,  127,  127,  127,  127,
- 127,  127,  127,  127,  127,  127,  127,  127,  127,  127,  127,  127,  127,  127,  127,  127,
- 127,  127,  127,  127,  127,  127,  127,  127,  127,  127,  127,  127,  127,  127,  127,  127,
- 127,  127,  127,  127,  127,  127,  127,  127,  127,  127,  127,  127,  127,  127,  127,  127,
- 127,  127,  127,  127,  127,  127,  127,  127,  127,  127,  127,  127,  127,  127,  127,  127,
-};
-
 /* End of file. */
index d5e99236e14f56f1f7262f9ebe7fc33a765a2f0b..45bb6f6b688a6a0272cb4bc19030f4e51bacffdc 100644 (file)
@@ -50,9 +50,9 @@ icvCalculateBufferSizes( CvSize roiSize, CvSize templSize,
                          int *sumBufSize, int *sqsumBufSize,
                          int *resNumBufSize, int *resDenomBufSize )
 {
-    int depth = dataType == cv32f ? sizeof_float : 1;
+    int depth = dataType == cv32f ? CV_SIZEOF_FLOAT : 1;
 
-#define align(size) icvAlign((int)(size) + 16, 32)
+#define align(size) cvAlign((int)(size) + 16, 32)
 
     *imgBufSize = align( (templSize.width * roiSize.height + roiSize.width) * depth );
     *templBufSize = align( templSize.width * templSize.height * depth );
@@ -99,11 +99,11 @@ icvMatchTemplateEntry( const void *pImage, int imageStep,
 
     if( templStep < templSize.width * depth ||
         imageStep < roiSize.width * depth ||
-        resultStep < (roiSize.width - templSize.width + 1) * sizeof_float )
+        resultStep < (roiSize.width - templSize.width + 1) * CV_SIZEOF_FLOAT )
         return CV_BADSIZE_ERR;
 
     if( (templStep & (depth - 1)) != 0 ||
-        (imageStep & (depth - 1)) != 0 || (resultStep & (sizeof_float - 1)) != 0 )
+        (imageStep & (depth - 1)) != 0 || (resultStep & (CV_SIZEOF_FLOAT - 1)) != 0 )
         return CV_BADSIZE_ERR;
 
     icvCalculateBufferSizes( roiSize, templSize, dataType,
@@ -164,7 +164,9 @@ icvMatchTemplateEntry( const void *pImage, int imageStep,
 IPCVAPI_IMPL( CvStatus, icvMatchTemplate_SqDiff_8u32f_C1R,
               (const uchar * pImage, int imageStep, CvSize roiSize,
                const uchar * pTemplate, int templStep, CvSize templSize,
-               float *pResult, int resultStep, void *pBuffer) )
+               float *pResult, int resultStep, void *pBuffer),
+               (pImage, imageStep, roiSize, pTemplate, templStep, templSize,
+                pResult, resultStep, pBuffer) )
 {
     uchar *imgBuf = 0;
     uchar *templBuf = 0;
@@ -184,7 +186,7 @@ IPCVAPI_IMPL( CvStatus, icvMatchTemplate_SqDiff_8u32f_C1R,
     if( result != CV_OK )
         return result;
 
-    resultStep /= sizeof_float;
+    resultStep /= CV_SIZEOF_FLOAT;
 
     /* main loop - through x coordinate of the result */
     for( x = 0; x < resultSize.width; x++ )
@@ -227,7 +229,9 @@ IPCVAPI_IMPL( CvStatus, icvMatchTemplate_SqDiff_8u32f_C1R,
 IPCVAPI_IMPL( CvStatus, icvMatchTemplate_SqDiffNormed_8u32f_C1R,
               (const uchar * pImage, int imageStep, CvSize roiSize,
                const uchar * pTemplate, int templStep, CvSize templSize,
-               float *pResult, int resultStep, void *pBuffer) )
+               float *pResult, int resultStep, void *pBuffer),
+               (pImage, imageStep, roiSize, pTemplate, templStep, templSize,
+                pResult, resultStep, pBuffer) )
 {
     uchar *imgBuf = 0;
     uchar *templBuf = 0;
@@ -252,7 +256,7 @@ IPCVAPI_IMPL( CvStatus, icvMatchTemplate_SqDiffNormed_8u32f_C1R,
     if( result != CV_OK )
         return result;
 
-    resultStep /= sizeof_float;
+    resultStep /= CV_SIZEOF_FLOAT;
 
     /* calc common statistics for template and image */
     {
@@ -260,7 +264,7 @@ IPCVAPI_IMPL( CvStatus, icvMatchTemplate_SqDiffNormed_8u32f_C1R,
         int64 templSqsum = icvCrossCorr_8u_C1( templBuf, templBuf, winLen );
 
         templCoeff = (double) templSqsum;
-        templCoeff = icvInvSqrt64d( fabs( templCoeff ) + FLT_EPSILON );
+        templCoeff = 1./sqrt( fabs( templCoeff ) + FLT_EPSILON );
 
         for( y = 0; y < roiSize.height; y++, rowPtr += templSize.width )
         {
@@ -316,7 +320,7 @@ IPCVAPI_IMPL( CvStatus, icvMatchTemplate_SqDiffNormed_8u32f_C1R,
         for( y = 0; y < resultSize.height; y++ )
         {
             double res = ((double) resNum[y]) * templCoeff *
-                icvInvSqrt64d( fabs( (double) resDenom[y] ) + FLT_EPSILON );
+                1./sqrt( fabs( (double) resDenom[y] ) + FLT_EPSILON );
 
             pResult[x + y * resultStep] = (float) res;
         }
@@ -330,7 +334,9 @@ IPCVAPI_IMPL( CvStatus, icvMatchTemplate_SqDiffNormed_8u32f_C1R,
 IPCVAPI_IMPL( CvStatus, icvMatchTemplate_Corr_8u32f_C1R,
               (const uchar * pImage, int imageStep, CvSize roiSize,
                const uchar * pTemplate, int templStep, CvSize templSize,
-               float *pResult, int resultStep, void *pBuffer) )
+               float *pResult, int resultStep, void *pBuffer),
+               (pImage, imageStep, roiSize, pTemplate, templStep, templSize,
+                pResult, resultStep, pBuffer) )
 {
     uchar *imgBuf = 0;
     uchar *templBuf = 0;
@@ -350,7 +356,7 @@ IPCVAPI_IMPL( CvStatus, icvMatchTemplate_Corr_8u32f_C1R,
     if( result != CV_OK )
         return result;
 
-    resultStep /= sizeof_float;
+    resultStep /= CV_SIZEOF_FLOAT;
 
     /* main loop - through x coordinate of the result */
     for( x = 0; x < resultSize.width; x++ )
@@ -394,7 +400,9 @@ IPCVAPI_IMPL( CvStatus, icvMatchTemplate_Corr_8u32f_C1R,
 IPCVAPI_IMPL( CvStatus, icvMatchTemplate_CorrNormed_8u32f_C1R,
               (const uchar * pImage, int imageStep, CvSize roiSize,
                const uchar * pTemplate, int templStep, CvSize templSize,
-               float *pResult, int resultStep, void *pBuffer) )
+               float *pResult, int resultStep, void *pBuffer),
+               (pImage, imageStep, roiSize, pTemplate, templStep, templSize,
+                pResult, resultStep, pBuffer) )
 {
     uchar *imgBuf = 0;
     uchar *templBuf = 0;
@@ -419,7 +427,7 @@ IPCVAPI_IMPL( CvStatus, icvMatchTemplate_CorrNormed_8u32f_C1R,
     if( result != CV_OK )
         return result;
 
-    resultStep /= sizeof_float;
+    resultStep /= CV_SIZEOF_FLOAT;
 
     /* calc common statistics for template and image */
     {
@@ -428,7 +436,7 @@ IPCVAPI_IMPL( CvStatus, icvMatchTemplate_CorrNormed_8u32f_C1R,
 
 
         templCoeff = (double) templSqsum;
-        templCoeff = icvInvSqrt64d( fabs( templCoeff ) + FLT_EPSILON );
+        templCoeff = 1./sqrt( fabs( templCoeff ) + FLT_EPSILON );
 
         for( y = 0; y < roiSize.height; y++, rowPtr += templSize.width )
         {
@@ -485,7 +493,7 @@ IPCVAPI_IMPL( CvStatus, icvMatchTemplate_CorrNormed_8u32f_C1R,
         for( y = 0; y < resultSize.height; y++ )
         {
             double res = ((double) resNum[y]) * templCoeff *
-                icvInvSqrt64d( fabs( (double) resDenom[y] ) + FLT_EPSILON );
+                1./sqrt( fabs( (double) resDenom[y] ) + FLT_EPSILON );
 
             pResult[x + y * resultStep] = (float) res;
         }
@@ -500,7 +508,9 @@ IPCVAPI_IMPL( CvStatus, icvMatchTemplate_CorrNormed_8u32f_C1R,
 IPCVAPI_IMPL( CvStatus, icvMatchTemplate_Coeff_8u32f_C1R,
               (const uchar * pImage, int imageStep, CvSize roiSize,
                const uchar * pTemplate, int templStep, CvSize templSize,
-               float *pResult, int resultStep, void *pBuffer) )
+               float *pResult, int resultStep, void *pBuffer),
+               (pImage, imageStep, roiSize, pTemplate, templStep, templSize,
+                pResult, resultStep, pBuffer) )
 {
     uchar *imgBuf = 0;
     uchar *templBuf = 0;
@@ -525,7 +535,7 @@ IPCVAPI_IMPL( CvStatus, icvMatchTemplate_Coeff_8u32f_C1R,
     if( result != CV_OK )
         return result;
 
-    resultStep /= sizeof_float;
+    resultStep /= CV_SIZEOF_FLOAT;
 
     /* calc common statistics for template and image */
     {
@@ -602,7 +612,9 @@ IPCVAPI_IMPL( CvStatus, icvMatchTemplate_Coeff_8u32f_C1R,
 IPCVAPI_IMPL( CvStatus, icvMatchTemplate_CoeffNormed_8u32f_C1R,
               (const uchar * pImage, int imageStep, CvSize roiSize,
                const uchar * pTemplate, int templStep, CvSize templSize,
-               float *pResult, int resultStep, void *pBuffer) )
+               float *pResult, int resultStep, void *pBuffer),
+               (pImage, imageStep, roiSize, pTemplate, templStep, templSize,
+                pResult, resultStep, pBuffer) )
 {
     uchar *imgBuf = 0;
     uchar *templBuf = 0;
@@ -631,7 +643,7 @@ IPCVAPI_IMPL( CvStatus, icvMatchTemplate_CoeffNormed_8u32f_C1R,
     if( result != CV_OK )
         return result;
 
-    resultStep /= sizeof_float;
+    resultStep /= CV_SIZEOF_FLOAT;
 
     /* calc common statistics for template and image */
     {
@@ -642,7 +654,7 @@ IPCVAPI_IMPL( CvStatus, icvMatchTemplate_CoeffNormed_8u32f_C1R,
 
 
         templCoeff = (double) templSqsum - ((double) templSum) * templSum * winCoeff;
-        templCoeff = icvInvSqrt64d( fabs( templCoeff ) + FLT_EPSILON );
+        templCoeff = 1./sqrt( fabs( templCoeff ) + FLT_EPSILON );
 
         for( y = 0; y < roiSize.height; y++, rowPtr += templSize.width )
         {
@@ -710,7 +722,7 @@ IPCVAPI_IMPL( CvStatus, icvMatchTemplate_CoeffNormed_8u32f_C1R,
             double res = ((double) resNum[y]) - wsum * templSum;
             double nrm_s = ((double) resDenom[y + resultSize.height]) - wsum * sum;
 
-            res *= templCoeff * icvInvSqrt64d( fabs( nrm_s ) + FLT_EPSILON );
+            res *= templCoeff / sqrt( fabs( nrm_s ) + FLT_EPSILON );
             pResult[x + y * resultStep] = (float) res;
         }
     }
@@ -718,575 +730,6 @@ IPCVAPI_IMPL( CvStatus, icvMatchTemplate_CoeffNormed_8u32f_C1R,
     return CV_OK;
 }
 
-
-/****************************************************************************************\
-*                                      8s flavor                                         *
-\****************************************************************************************/
-
-/* --------------------------------------- SqDiff ------------------------------------- */
-
-IPCVAPI_IMPL( CvStatus, icvMatchTemplate_SqDiff_8s32f_C1R,
-              (const char *pImage, int imageStep, CvSize roiSize,
-               const char *pTemplate, int templStep, CvSize templSize,
-               float *pResult, int resultStep, void *pBuffer) )
-{
-    char *imgBuf = 0;
-    char *templBuf = 0;
-    int64 *resNum = 0;
-    int winLen = templSize.width * templSize.height;
-    CvSize resultSize = cvSize( roiSize.width - templSize.width + 1,
-                                roiSize.height - templSize.height + 1 );
-    int x, y;
-
-    CvStatus result = icvMatchTemplateEntry( pImage, imageStep, roiSize,
-                                             pTemplate, templStep, templSize,
-                                             pResult, resultStep, pBuffer,
-                                             cv8s, 0, 0,
-                                             (void **) &imgBuf, (void **) &templBuf,
-                                             0, 0, (void **) &resNum, 0 );
-
-    if( result != CV_OK )
-        return result;
-
-    resultStep /= sizeof_float;
-
-    /* main loop - through x coordinate of the result */
-    for( x = 0; x < resultSize.width; x++ )
-    {
-        char *imgPtr = imgBuf + x;
-
-        /* update sums and image band buffer */
-        if( x > 0 )
-        {
-            const char *src = pImage + x + templSize.width - 1;
-            char *dst = imgPtr - 1;
-
-            dst += templSize.width;
-
-            for( y = 0; y < roiSize.height; y++, src += imageStep, dst += templSize.width )
-            {
-                dst[0] = src[0];
-            }
-        }
-
-        for( y = 0; y < resultSize.height; y++, imgPtr += templSize.width )
-        {
-            int64 res = icvCmpBlocksL2_8s_C1( imgPtr, templBuf, winLen );
-
-            resNum[y] = res;
-        }
-
-
-
-        for( y = 0; y < resultSize.height; y++ )
-        {
-            pResult[x + y * resultStep] = (float) resNum[y];
-        }
-    }
-
-    return CV_OK;
-}
-
-
-/* ----------------------------------- SqDiffNormed ----------------------------------- */
-
-IPCVAPI_IMPL( CvStatus, icvMatchTemplate_SqDiffNormed_8s32f_C1R,
-              (const char *pImage, int imageStep, CvSize roiSize,
-               const char *pTemplate, int templStep, CvSize templSize,
-               float *pResult, int resultStep, void *pBuffer) )
-{
-    char *imgBuf = 0;
-    char *templBuf = 0;
-    int64 *sqsumBuf = 0;
-    int64 *resNum = 0;
-    int64 *resDenom = 0;
-    double templCoeff = 0;
-
-    int winLen = templSize.width * templSize.height;
-    CvSize resultSize = cvSize( roiSize.width - templSize.width + 1,
-                                roiSize.height - templSize.height + 1 );
-    int x, y;
-
-    CvStatus result = icvMatchTemplateEntry( pImage, imageStep, roiSize,
-                                             pTemplate, templStep, templSize,
-                                             pResult, resultStep, pBuffer,
-                                             cv8s, 0, 1,
-                                             (void **) &imgBuf, (void **) &templBuf,
-                                             0, (void **) &sqsumBuf,
-                                             (void **) &resNum, (void **) &resDenom );
-
-    if( result != CV_OK )
-        return result;
-
-    resultStep /= sizeof_float;
-
-    /* calc common statistics for template and image */
-    {
-        const char *rowPtr = (const char *) imgBuf;
-        int64 templSqsum = icvCrossCorr_8s_C1( templBuf, templBuf, winLen );
-
-
-        templCoeff = (double) templSqsum;
-        templCoeff = icvInvSqrt64d( fabs( templCoeff ) + FLT_EPSILON );
-
-        for( y = 0; y < roiSize.height; y++, rowPtr += templSize.width )
-        {
-            sqsumBuf[y] = icvCrossCorr_8s_C1( rowPtr, rowPtr, templSize.width );
-        }
-
-    }
-
-    /* main loop - through x coordinate of the result */
-    for( x = 0; x < resultSize.width; x++ )
-    {
-        int64 sqsum = 0;
-        char *img_ptr = imgBuf + x;
-
-        /* update sums and image band buffer */
-        if( x > 0 )
-        {
-            const char *src = pImage + x + templSize.width - 1;
-            char *dst = img_ptr - 1;
-            int out_val = dst[0];
-
-            dst += templSize.width;
-
-            for( y = 0; y < roiSize.height; y++, src += imageStep, dst += templSize.width )
-            {
-                int in_val = src[0];
-
-                sqsumBuf[y] += (in_val - out_val) * (in_val + out_val);
-                out_val = dst[0];
-                dst[0] = (char) in_val;
-            }
-        }
-
-        for( y = 0; y < templSize.height; y++ )
-        {
-            sqsum += sqsumBuf[y];
-        }
-
-        for( y = 0; y < resultSize.height; y++, img_ptr += templSize.width )
-        {
-            int64 res = icvCmpBlocksL2_8s_C1( img_ptr, templBuf, winLen );
-
-            if( y > 0 )
-            {
-                sqsum -= sqsumBuf[y - 1];
-                sqsum += sqsumBuf[y + templSize.height - 1];
-            }
-            resNum[y] = res;
-            resDenom[y] = sqsum;
-        }
-
-
-
-        for( y = 0; y < resultSize.height; y++ )
-        {
-            double res = ((double) resNum[y]) * templCoeff *
-                icvInvSqrt64d( fabs( (double) resDenom[y] ) + FLT_EPSILON );
-
-            pResult[x + y * resultStep] = (float) res;
-        }
-    }
-
-    return CV_OK;
-}
-
-/* -------------------------------------- Corr ---------------------------------------- */
-
-IPCVAPI_IMPL( CvStatus, icvMatchTemplate_Corr_8s32f_C1R,
-              (const char *pImage, int imageStep, CvSize roiSize,
-               const char *pTemplate, int templStep, CvSize templSize,
-               float *pResult, int resultStep, void *pBuffer) )
-{
-    char *imgBuf = 0;
-    char *templBuf = 0;
-    int64 *resNum = 0;
-    int winLen = templSize.width * templSize.height;
-    CvSize resultSize = cvSize( roiSize.width - templSize.width + 1,
-                                roiSize.height - templSize.height + 1 );
-    int x, y;
-
-    CvStatus result = icvMatchTemplateEntry( pImage, imageStep, roiSize,
-                                             pTemplate, templStep, templSize,
-                                             pResult, resultStep, pBuffer,
-                                             cv8s, 0, 0,
-                                             (void **) &imgBuf, (void **) &templBuf,
-                                             0, 0, (void **) &resNum, 0 );
-
-    if( result != CV_OK )
-        return result;
-
-    resultStep /= sizeof_float;
-
-    /* main loop - through x coordinate of the result */
-    for( x = 0; x < resultSize.width; x++ )
-    {
-        char *imgPtr = imgBuf + x;
-
-        /* update sums and image band buffer */
-        if( x > 0 )
-        {
-            const char *src = pImage + x + templSize.width - 1;
-            char *dst = imgPtr - 1;
-
-            dst += templSize.width;
-
-            for( y = 0; y < roiSize.height; y++, src += imageStep, dst += templSize.width )
-            {
-                dst[0] = src[0];
-            }
-        }
-
-        for( y = 0; y < resultSize.height; y++, imgPtr += templSize.width )
-        {
-            int64 res = icvCrossCorr_8s_C1( imgPtr, templBuf, winLen );
-
-            resNum[y] = res;
-        }
-
-
-
-        for( y = 0; y < resultSize.height; y++ )
-        {
-            pResult[x + y * resultStep] = (float) resNum[y];
-        }
-    }
-
-    return CV_OK;
-}
-
-/* ------------------------------------ CorrNormed ------------------------------------ */
-
-IPCVAPI_IMPL( CvStatus, icvMatchTemplate_CorrNormed_8s32f_C1R,
-              (const char *pImage, int imageStep, CvSize roiSize,
-               const char *pTemplate, int templStep, CvSize templSize,
-               float *pResult, int resultStep, void *pBuffer) )
-{
-    char *imgBuf = 0;
-    char *templBuf = 0;
-    int64 *sqsumBuf = 0;
-    int64 *resNum = 0;
-    int64 *resDenom = 0;
-    double templCoeff = 0;
-
-    int winLen = templSize.width * templSize.height;
-    CvSize resultSize = cvSize( roiSize.width - templSize.width + 1,
-                                roiSize.height - templSize.height + 1 );
-    int x, y;
-
-    CvStatus result = icvMatchTemplateEntry( pImage, imageStep, roiSize,
-                                             pTemplate, templStep, templSize,
-                                             pResult, resultStep, pBuffer,
-                                             cv8s, 0, 1,
-                                             (void **) &imgBuf, (void **) &templBuf,
-                                             0, (void **) &sqsumBuf,
-                                             (void **) &resNum, (void **) &resDenom );
-
-    if( result != CV_OK )
-        return result;
-
-    resultStep /= sizeof_float;
-
-    /* calc common statistics for template and image */
-    {
-        const char *rowPtr = (const char *) imgBuf;
-        int64 templSqsum = icvCrossCorr_8s_C1( templBuf, templBuf, winLen );
-
-
-        templCoeff = (double) templSqsum;
-        templCoeff = icvInvSqrt64d( fabs( templCoeff ) + FLT_EPSILON );
-
-        for( y = 0; y < roiSize.height; y++, rowPtr += templSize.width )
-        {
-            sqsumBuf[y] = icvCrossCorr_8s_C1( rowPtr, rowPtr, templSize.width );
-        }
-
-    }
-
-    /* main loop - through x coordinate of the result */
-    for( x = 0; x < resultSize.width; x++ )
-    {
-        int64 sqsum = 0;
-        char *imgPtr = imgBuf + x;
-
-        /* update sums and image band buffer */
-        if( x > 0 )
-        {
-            const char *src = pImage + x + templSize.width - 1;
-            char *dst = imgPtr - 1;
-            int out_val = dst[0];
-
-            dst += templSize.width;
-
-            for( y = 0; y < roiSize.height; y++, src += imageStep, dst += templSize.width )
-            {
-                int in_val = src[0];
-
-                sqsumBuf[y] += (in_val - out_val) * (in_val + out_val);
-                out_val = dst[0];
-                dst[0] = (char) in_val;
-            }
-        }
-
-        for( y = 0; y < templSize.height; y++ )
-        {
-            sqsum += sqsumBuf[y];
-        }
-
-        for( y = 0; y < resultSize.height; y++, imgPtr += templSize.width )
-        {
-            int64 res = icvCrossCorr_8s_C1( imgPtr, templBuf, winLen );
-
-            if( y > 0 )
-            {
-                sqsum -= sqsumBuf[y - 1];
-                sqsum += sqsumBuf[y + templSize.height - 1];
-            }
-            resNum[y] = res;
-            resDenom[y] = sqsum;
-        }
-
-
-
-        for( y = 0; y < resultSize.height; y++ )
-        {
-            double res = ((double) resNum[y]) * templCoeff *
-                icvInvSqrt64d( fabs( (double) resDenom[y] ) + FLT_EPSILON );
-
-            pResult[x + y * resultStep] = (float) res;
-        }
-    }
-
-    return CV_OK;
-}
-
-
-/* -------------------------------------- Coeff --------------------------------------- */
-
-IPCVAPI_IMPL( CvStatus, icvMatchTemplate_Coeff_8s32f_C1R,
-              (const char *pImage, int imageStep, CvSize roiSize,
-               const char *pTemplate, int templStep, CvSize templSize,
-               float *pResult, int resultStep, void *pBuffer) )
-{
-    char *imgBuf = 0;
-    char *templBuf = 0;
-    int64 *resNum = 0;
-    int64 *resDenom = 0;
-    int64 *sumBuf = 0;
-    int winLen = templSize.width * templSize.height;
-    CvSize resultSize = cvSize( roiSize.width - templSize.width + 1,
-                                roiSize.height - templSize.height + 1 );
-    int64 templSum = 0;
-    double winCoeff = 1. / (winLen + DBL_EPSILON);
-    int x, y;
-
-    CvStatus result = icvMatchTemplateEntry( pImage, imageStep, roiSize,
-                                             pTemplate, templStep, templSize,
-                                             pResult, resultStep, pBuffer,
-                                             cv8s, 1, 0,
-                                             (void **) &imgBuf, (void **) &templBuf,
-                                             (void **) &sumBuf, 0,
-                                             (void **) &resNum, (void **) &resDenom );
-
-    if( result != CV_OK )
-        return result;
-
-    resultStep /= sizeof_float;
-
-    /* calc common statistics for template and image */
-    {
-        const char *rowPtr = (const char *) imgBuf;
-
-        templSum = icvSumPixels_8s_C1( templBuf, winLen );
-
-        for( y = 0; y < roiSize.height; y++, rowPtr += templSize.width )
-        {
-            sumBuf[y] = icvSumPixels_8s_C1( rowPtr, templSize.width );
-        }
-
-    }
-
-    /* main loop - through x coordinate of the result */
-    for( x = 0; x < resultSize.width; x++ )
-    {
-        char *imgPtr = imgBuf + x;
-        int64 sum = 0;
-
-        /* update sums and image band buffer */
-        if( x > 0 )
-        {
-            const char *src = pImage + x + templSize.width - 1;
-            char *dst = imgPtr - 1;
-            int out_val = dst[0];
-
-            dst += templSize.width;
-
-            for( y = 0; y < roiSize.height; y++, src += imageStep, dst += templSize.width )
-            {
-                int in_val = src[0];
-
-                sumBuf[y] += in_val - out_val;
-                out_val = dst[0];
-                dst[0] = (char) in_val;
-            }
-        }
-
-        for( y = 0; y < templSize.height; y++ )
-        {
-            sum += sumBuf[y];
-        }
-
-        for( y = 0; y < resultSize.height; y++, imgPtr += templSize.width )
-        {
-            int64 res = icvCrossCorr_8s_C1( imgPtr, templBuf, winLen );
-
-            if( y > 0 )
-            {
-                sum -= sumBuf[y - 1];
-                sum += sumBuf[y + templSize.height - 1];
-            }
-            resNum[y] = res;
-            resDenom[y] = sum;
-        }
-
-
-
-        for( y = 0; y < resultSize.height; y++ )
-        {
-            double res = ((double) resNum[y]) - winCoeff * templSum * ((double) resDenom[y]);
-
-            pResult[x + y * resultStep] = (float) res;
-        }
-    }
-
-    return CV_OK;
-}
-
-
-/* ------------------------------------ CoeffNormed ----------------------------------- */
-
-IPCVAPI_IMPL( CvStatus, icvMatchTemplate_CoeffNormed_8s32f_C1R,
-              (const char *pImage, int imageStep, CvSize roiSize,
-               const char *pTemplate, int templStep, CvSize templSize,
-               float *pResult, int resultStep, void *pBuffer) )
-{
-    char *imgBuf = 0;
-    char *templBuf = 0;
-    int64 *sumBuf = 0;
-    int64 *sqsumBuf = 0;
-    int64 *resNum = 0;
-    int64 *resDenom = 0;
-    int64 templSum = 0;
-    double templCoeff = 0;
-
-    int winLen = templSize.width * templSize.height;
-    double winCoeff = 1. / (winLen + DBL_EPSILON);
-
-    CvSize resultSize = cvSize( roiSize.width - templSize.width + 1,
-                                roiSize.height - templSize.height + 1 );
-    int x, y;
-
-    CvStatus result = icvMatchTemplateEntry( pImage, imageStep, roiSize,
-                                             pTemplate, templStep, templSize,
-                                             pResult, resultStep, pBuffer,
-                                             cv8s, 1, 1,
-                                             (void **) &imgBuf, (void **) &templBuf,
-                                             (void **) &sumBuf, (void **) &sqsumBuf,
-                                             (void **) &resNum, (void **) &resDenom );
-
-    if( result != CV_OK )
-        return result;
-
-    resultStep /= sizeof_float;
-
-    /* calc common statistics for template and image */
-    {
-        const char *rowPtr = (const char *) imgBuf;
-        int64 templSqsum = icvCrossCorr_8s_C1( templBuf, templBuf, winLen );
-
-        templSum = icvSumPixels_8s_C1( templBuf, winLen );
-
-
-        templCoeff = (double) templSqsum - ((double) templSum) * templSum * winCoeff;
-        templCoeff = icvInvSqrt64d( fabs( templCoeff ) + FLT_EPSILON );
-
-        for( y = 0; y < roiSize.height; y++, rowPtr += templSize.width )
-        {
-            sumBuf[y] = icvSumPixels_8s_C1( rowPtr, templSize.width );
-            sqsumBuf[y] = icvCrossCorr_8s_C1( rowPtr, rowPtr, templSize.width );
-        }
-
-    }
-
-    /* main loop - through x coordinate of the result */
-    for( x = 0; x < resultSize.width; x++ )
-    {
-        int64 sum = 0;
-        int64 sqsum = 0;
-        char *imgPtr = imgBuf + x;
-
-        /* update sums and image band buffer */
-        if( x > 0 )
-        {
-            const char *src = pImage + x + templSize.width - 1;
-            char *dst = imgPtr - 1;
-            int out_val = dst[0];
-
-            dst += templSize.width;
-
-            for( y = 0; y < roiSize.height; y++, src += imageStep, dst += templSize.width )
-            {
-                int in_val = src[0];
-
-                sumBuf[y] += in_val - out_val;
-                sqsumBuf[y] += (in_val - out_val) * (in_val + out_val);
-                out_val = dst[0];
-                dst[0] = (char) in_val;
-            }
-        }
-
-        for( y = 0; y < templSize.height; y++ )
-        {
-            sum += sumBuf[y];
-            sqsum += sqsumBuf[y];
-        }
-
-        for( y = 0; y < resultSize.height; y++, imgPtr += templSize.width )
-        {
-            int64 res = icvCrossCorr_8s_C1( imgPtr, templBuf, winLen );
-
-            if( y > 0 )
-            {
-                sum -= sumBuf[y - 1];
-                sum += sumBuf[y + templSize.height - 1];
-                sqsum -= sqsumBuf[y - 1];
-                sqsum += sqsumBuf[y + templSize.height - 1];
-            }
-            resNum[y] = res;
-            resDenom[y] = sum;
-            resDenom[y + resultSize.height] = sqsum;
-        }
-
-
-
-        for( y = 0; y < resultSize.height; y++ )
-        {
-            double sum = ((double) resDenom[y]);
-            double wsum = winCoeff * sum;
-            double res = ((double) resNum[y]) - wsum * templSum;
-            double nrm_s = ((double) resDenom[y + resultSize.height]) - wsum * sum;
-
-            res *= templCoeff * icvInvSqrt64d( fabs( nrm_s ) + FLT_EPSILON );
-            pResult[x + y * resultStep] = (float) res;
-        }
-    }
-
-    return CV_OK;
-}
-
-
 /****************************************************************************************\
 *                                      32f flavor                                        *
 \****************************************************************************************/
@@ -1296,7 +739,9 @@ IPCVAPI_IMPL( CvStatus, icvMatchTemplate_CoeffNormed_8s32f_C1R,
 IPCVAPI_IMPL( CvStatus, icvMatchTemplate_SqDiff_32f_C1R,
               (const float *pImage, int imageStep, CvSize roiSize,
                const float *pTemplate, int templStep, CvSize templSize,
-               float *pResult, int resultStep, void *pBuffer) )
+               float *pResult, int resultStep, void *pBuffer),
+               (pImage, imageStep, roiSize, pTemplate, templStep, templSize,
+                pResult, resultStep, pBuffer) )
 {
     float *imgBuf = 0;
     float *templBuf = 0;
@@ -1316,9 +761,9 @@ IPCVAPI_IMPL( CvStatus, icvMatchTemplate_SqDiff_32f_C1R,
     if( result != CV_OK )
         return result;
 
-    imageStep /= sizeof_float;
-    templStep /= sizeof_float;
-    resultStep /= sizeof_float;
+    imageStep /= CV_SIZEOF_FLOAT;
+    templStep /= CV_SIZEOF_FLOAT;
+    resultStep /= CV_SIZEOF_FLOAT;
 
     /* main loop - through x coordinate of the result */
     for( x = 0; x < resultSize.width; x++ )
@@ -1361,7 +806,9 @@ IPCVAPI_IMPL( CvStatus, icvMatchTemplate_SqDiff_32f_C1R,
 IPCVAPI_IMPL( CvStatus, icvMatchTemplate_SqDiffNormed_32f_C1R,
               (const float *pImage, int imageStep, CvSize roiSize,
                const float *pTemplate, int templStep, CvSize templSize,
-               float *pResult, int resultStep, void *pBuffer) )
+               float *pResult, int resultStep, void *pBuffer),
+               (pImage, imageStep, roiSize, pTemplate, templStep, templSize,
+                pResult, resultStep, pBuffer) )
 {
     float *imgBuf = 0;
     float *templBuf = 0;
@@ -1386,9 +833,9 @@ IPCVAPI_IMPL( CvStatus, icvMatchTemplate_SqDiffNormed_32f_C1R,
     if( result != CV_OK )
         return result;
 
-    imageStep /= sizeof_float;
-    templStep /= sizeof_float;
-    resultStep /= sizeof_float;
+    imageStep /= CV_SIZEOF_FLOAT;
+    templStep /= CV_SIZEOF_FLOAT;
+    resultStep /= CV_SIZEOF_FLOAT;
 
     /* calc common statistics for template and image */
     {
@@ -1397,7 +844,7 @@ IPCVAPI_IMPL( CvStatus, icvMatchTemplate_SqDiffNormed_32f_C1R,
 
 
         templCoeff = (double) templSqsum;
-        templCoeff = icvInvSqrt64d( fabs( templCoeff ) + FLT_EPSILON );
+        templCoeff = 1./sqrt( fabs( templCoeff ) + FLT_EPSILON );
 
         for( y = 0; y < roiSize.height; y++, rowPtr += templSize.width )
         {
@@ -1452,7 +899,7 @@ IPCVAPI_IMPL( CvStatus, icvMatchTemplate_SqDiffNormed_32f_C1R,
         for( y = 0; y < resultSize.height; y++ )
         {
             double res = ((double) resNum[y]) * templCoeff *
-                icvInvSqrt64d( fabs( (double) resDenom[y] ) + FLT_EPSILON );
+                1./sqrt( fabs( (double) resDenom[y] ) + FLT_EPSILON );
 
             pResult[x + y * resultStep] = (float) res;
         }
@@ -1466,7 +913,9 @@ IPCVAPI_IMPL( CvStatus, icvMatchTemplate_SqDiffNormed_32f_C1R,
 IPCVAPI_IMPL( CvStatus, icvMatchTemplate_Corr_32f_C1R,
               (const float *pImage, int imageStep, CvSize roiSize,
                const float *pTemplate, int templStep, CvSize templSize,
-               float *pResult, int resultStep, void *pBuffer) )
+               float *pResult, int resultStep, void *pBuffer),
+               (pImage, imageStep, roiSize, pTemplate, templStep, templSize,
+                pResult, resultStep, pBuffer) )
 {
     float *imgBuf = 0;
     float *templBuf = 0;
@@ -1486,9 +935,9 @@ IPCVAPI_IMPL( CvStatus, icvMatchTemplate_Corr_32f_C1R,
     if( result != CV_OK )
         return result;
 
-    imageStep /= sizeof_float;
-    templStep /= sizeof_float;
-    resultStep /= sizeof_float;
+    imageStep /= CV_SIZEOF_FLOAT;
+    templStep /= CV_SIZEOF_FLOAT;
+    resultStep /= CV_SIZEOF_FLOAT;
 
     /* main loop - through x coordinate of the result */
     for( x = 0; x < resultSize.width; x++ )
@@ -1530,7 +979,9 @@ IPCVAPI_IMPL( CvStatus, icvMatchTemplate_Corr_32f_C1R,
 IPCVAPI_IMPL( CvStatus, icvMatchTemplate_CorrNormed_32f_C1R,
               (const float *pImage, int imageStep, CvSize roiSize,
                const float *pTemplate, int templStep, CvSize templSize,
-               float *pResult, int resultStep, void *pBuffer) )
+               float *pResult, int resultStep, void *pBuffer),
+               (pImage, imageStep, roiSize, pTemplate, templStep, templSize,
+                pResult, resultStep, pBuffer) )
 {
     float *imgBuf = 0;
     float *templBuf = 0;
@@ -1555,9 +1006,9 @@ IPCVAPI_IMPL( CvStatus, icvMatchTemplate_CorrNormed_32f_C1R,
     if( result != CV_OK )
         return result;
 
-    imageStep /= sizeof_float;
-    templStep /= sizeof_float;
-    resultStep /= sizeof_float;
+    imageStep /= CV_SIZEOF_FLOAT;
+    templStep /= CV_SIZEOF_FLOAT;
+    resultStep /= CV_SIZEOF_FLOAT;
 
     /* calc common statistics for template and image */
     {
@@ -1566,7 +1017,7 @@ IPCVAPI_IMPL( CvStatus, icvMatchTemplate_CorrNormed_32f_C1R,
 
 
         templCoeff = (double) templSqsum;
-        templCoeff = icvInvSqrt64d( fabs( templCoeff ) + FLT_EPSILON );
+        templCoeff = 1./sqrt( fabs( templCoeff ) + FLT_EPSILON );
 
         for( y = 0; y < roiSize.height; y++, rowPtr += templSize.width )
         {
@@ -1621,7 +1072,7 @@ IPCVAPI_IMPL( CvStatus, icvMatchTemplate_CorrNormed_32f_C1R,
         for( y = 0; y < resultSize.height; y++ )
         {
             double res = ((double) resNum[y]) * templCoeff *
-                icvInvSqrt64d( fabs( (double) resDenom[y] ) + FLT_EPSILON );
+                1./sqrt( fabs( (double) resDenom[y] ) + FLT_EPSILON );
 
             pResult[x + y * resultStep] = (float) res;
         }
@@ -1636,7 +1087,9 @@ IPCVAPI_IMPL( CvStatus, icvMatchTemplate_CorrNormed_32f_C1R,
 IPCVAPI_IMPL( CvStatus, icvMatchTemplate_Coeff_32f_C1R,
               (const float *pImage, int imageStep, CvSize roiSize,
                const float *pTemplate, int templStep, CvSize templSize,
-               float *pResult, int resultStep, void *pBuffer) )
+               float *pResult, int resultStep, void *pBuffer),
+               (pImage, imageStep, roiSize, pTemplate, templStep, templSize,
+                pResult, resultStep, pBuffer) )
 {
     float *imgBuf = 0;
     float *templBuf = 0;
@@ -1661,9 +1114,9 @@ IPCVAPI_IMPL( CvStatus, icvMatchTemplate_Coeff_32f_C1R,
     if( result != CV_OK )
         return result;
 
-    imageStep /= sizeof_float;
-    templStep /= sizeof_float;
-    resultStep /= sizeof_float;
+    imageStep /= CV_SIZEOF_FLOAT;
+    templStep /= CV_SIZEOF_FLOAT;
+    resultStep /= CV_SIZEOF_FLOAT;
 
     /* calc common statistics for template and image */
     {
@@ -1737,7 +1190,9 @@ IPCVAPI_IMPL( CvStatus, icvMatchTemplate_Coeff_32f_C1R,
 IPCVAPI_IMPL( CvStatus, icvMatchTemplate_CoeffNormed_32f_C1R,
               (const float *pImage, int imageStep, CvSize roiSize,
                const float *pTemplate, int templStep, CvSize templSize,
-               float *pResult, int resultStep, void *pBuffer) )
+               float *pResult, int resultStep, void *pBuffer),
+               (pImage, imageStep, roiSize, pTemplate, templStep, templSize,
+                pResult, resultStep, pBuffer) )
 {
     float *imgBuf = 0;
     float *templBuf = 0;
@@ -1766,9 +1221,9 @@ IPCVAPI_IMPL( CvStatus, icvMatchTemplate_CoeffNormed_32f_C1R,
     if( result != CV_OK )
         return result;
 
-    imageStep /= sizeof_float;
-    templStep /= sizeof_float;
-    resultStep /= sizeof_float;
+    imageStep /= CV_SIZEOF_FLOAT;
+    templStep /= CV_SIZEOF_FLOAT;
+    resultStep /= CV_SIZEOF_FLOAT;
 
     /* calc common statistics for template and image */
     {
@@ -1778,7 +1233,7 @@ IPCVAPI_IMPL( CvStatus, icvMatchTemplate_CoeffNormed_32f_C1R,
 
         templSum = icvSumPixels_32f_C1( templBuf, winLen );
         templCoeff = (double) templSqsum - ((double) templSum) * templSum * winCoeff;
-        templCoeff = icvInvSqrt64d( fabs( templCoeff ) + FLT_EPSILON );
+        templCoeff = 1./sqrt( fabs( templCoeff ) + FLT_EPSILON );
 
         for( y = 0; y < roiSize.height; y++, rowPtr += templSize.width )
         {
@@ -1844,7 +1299,7 @@ IPCVAPI_IMPL( CvStatus, icvMatchTemplate_CoeffNormed_32f_C1R,
             double res = ((double) resNum[y]) - wsum * templSum;
             double nrm_s = ((double) resDenom[y + resultSize.height]) - wsum * sum;
 
-            res *= templCoeff * icvInvSqrt64d( fabs( nrm_s ) + FLT_EPSILON );
+            res *= templCoeff / sqrt( fabs( nrm_s ) + FLT_EPSILON );
             pResult[x + y * resultStep] = (float) res;
         }
     }
@@ -1873,7 +1328,7 @@ icvMatchTemplateGetBufSize( CvSize roiSize, CvSize templSize,
         roiSize.width < templSize.width || roiSize.height < templSize.height )
         return CV_BADSIZE_ERR;
 
-    if( dataType != cv8u && dataType != cv8s && dataType != cv32f )
+    if( dataType != cv8u && dataType != cv32f )
         return CV_BADDEPTH_ERR;
 
     icvCalculateBufferSizes( roiSize, templSize, dataType,
@@ -1888,46 +1343,49 @@ icvMatchTemplateGetBufSize( CvSize roiSize, CvSize templSize,
 }
 
 
-IPCVAPI_IMPL( CvStatus, icvMatchTemplateGetBufSize_SqDiff, (CvSize roiSize, CvSize templSize,
-                                                            CvDataType dataType,
-                                                            int *bufferSize) )
+IPCVAPI_IMPL( CvStatus, icvMatchTemplateGetBufSize_SqDiff,
+             (CvSize roiSize, CvSize templSize, CvDataType dataType, int *bufferSize),
+             (roiSize, templSize, dataType, bufferSize) )
 {
     return icvMatchTemplateGetBufSize( roiSize, templSize, dataType, bufferSize, 0, 0 );
 }
 
 
 IPCVAPI_IMPL( CvStatus, icvMatchTemplateGetBufSize_SqDiffNormed,
-              (CvSize roiSize, CvSize templSize, CvDataType dataType, int *bufferSize) )
+              (CvSize roiSize, CvSize templSize, CvDataType dataType, int *bufferSize),
+              (roiSize, templSize, dataType, bufferSize) )
 {
     return icvMatchTemplateGetBufSize( roiSize, templSize, dataType, bufferSize, 0, 1 );
 }
 
 
-IPCVAPI_IMPL( CvStatus, icvMatchTemplateGetBufSize_Corr, (CvSize roiSize, CvSize templSize,
-                                                          CvDataType dataType,
-                                                          int *bufferSize) )
+IPCVAPI_IMPL( CvStatus, icvMatchTemplateGetBufSize_Corr,
+             (CvSize roiSize, CvSize templSize, CvDataType dataType, int *bufferSize),
+             (roiSize, templSize, dataType, bufferSize) )
 {
     return icvMatchTemplateGetBufSize( roiSize, templSize, dataType, bufferSize, 0, 0 );
 }
 
 
 IPCVAPI_IMPL( CvStatus, icvMatchTemplateGetBufSize_CorrNormed,
-              (CvSize roiSize, CvSize templSize, CvDataType dataType, int *bufferSize) )
+              (CvSize roiSize, CvSize templSize, CvDataType dataType, int *bufferSize),
+             (roiSize, templSize, dataType, bufferSize) )
 {
     return icvMatchTemplateGetBufSize( roiSize, templSize, dataType, bufferSize, 0, 1 );
 }
 
 
-IPCVAPI_IMPL( CvStatus, icvMatchTemplateGetBufSize_Coeff, (CvSize roiSize, CvSize templSize,
-                                                           CvDataType dataType,
-                                                           int *bufferSize) )
+IPCVAPI_IMPL( CvStatus, icvMatchTemplateGetBufSize_Coeff,
+             (CvSize roiSize, CvSize templSize, CvDataType dataType, int *bufferSize),
+             (roiSize, templSize, dataType, bufferSize) )
 {
     return icvMatchTemplateGetBufSize( roiSize, templSize, dataType, bufferSize, 1, 0 );
 }
 
 
 IPCVAPI_IMPL( CvStatus, icvMatchTemplateGetBufSize_CoeffNormed,
-              (CvSize roiSize, CvSize templSize, CvDataType dataType, int *bufferSize) )
+              (CvSize roiSize, CvSize templSize, CvDataType dataType, int *bufferSize),
+              (roiSize, templSize, dataType, bufferSize) )
 {
     return icvMatchTemplateGetBufSize( roiSize, templSize, dataType, bufferSize, 1, 1 );
 }
@@ -1965,12 +1423,12 @@ static  void  icvInitMatchTemplTable( void** bufSizeTab, void** funcTab )
     funcTab[4]  = (void*)icvMatchTemplate_Coeff_8u32f_C1R;
     funcTab[5]  = (void*)icvMatchTemplate_CoeffNormed_8u32f_C1R;
 
-    funcTab[6]  = (void*)icvMatchTemplate_SqDiff_8s32f_C1R;
-    funcTab[7]  = (void*)icvMatchTemplate_SqDiffNormed_8s32f_C1R;
-    funcTab[8]  = (void*)icvMatchTemplate_Corr_8s32f_C1R;
-    funcTab[9]  = (void*)icvMatchTemplate_CorrNormed_8s32f_C1R;
-    funcTab[10] = (void*)icvMatchTemplate_Coeff_8s32f_C1R;
-    funcTab[11] = (void*)icvMatchTemplate_CoeffNormed_8s32f_C1R;
+    funcTab[6]  = 0;
+    funcTab[7]  = 0;
+    funcTab[8]  = 0;
+    funcTab[9]  = 0;
+    funcTab[10] = 0;
+    funcTab[11] = 0;
 
     funcTab[12] = (void*)icvMatchTemplate_SqDiff_32f_C1R;
     funcTab[13] = (void*)icvMatchTemplate_SqDiffNormed_32f_C1R;
@@ -1982,8 +1440,7 @@ static  void  icvInitMatchTemplTable( void** bufSizeTab, void** funcTab )
 
 
 CV_IMPL void
-cvMatchTemplate( const void* arr, const void* templarr, void* resultarr,
-                 CvTemplMatchMethod method )
+cvMatchTemplate( const void* arr, const void* templarr, void* resultarr, int method )
 {
     static void* bufSizeFuncs[6];
     static void* funcs[18];
@@ -2021,7 +1478,6 @@ cvMatchTemplate( const void* arr, const void* templarr, void* resultarr,
 
     if( CV_MAT_CN( img->type ) != 1 ||
         CV_MAT_DEPTH( img->type ) != CV_8U &&
-        CV_MAT_DEPTH( img->type ) != CV_8S &&
         CV_MAT_DEPTH( img->type ) != CV_32F )
         CV_ERROR( CV_StsUnsupportedFormat, "" );
 
@@ -2044,25 +1500,21 @@ cvMatchTemplate( const void* arr, const void* templarr, void* resultarr,
         dataType = cv8u;
         dataOffset = 0;
         break;
-    case CV_8S:
-        dataType = cv8s;
-        dataOffset = 1;
-        break;
     case CV_32F:
         dataType = cv32f;
         dataOffset = 2;
         break;
     default:
-        CV_ERROR( CV_StsBadArg, icvUnsupportedFormat );
+        CV_ERROR( CV_StsBadArg, cvUnsupportedFormat );
     }
 
-    imgSize = icvGetMatSize( img );
-    templSize = icvGetMatSize( templ );
+    imgSize = cvGetMatSize( img );
+    templSize = cvGetMatSize( templ );
 
     bufSizeFunc = (CvMatchBufSizeFunc)(bufSizeFuncs[imethod]);
     IPPI_CALL( bufSizeFunc( imgSize, templSize, dataType, &bufferSize ));
 
-    CV_CALL( buffer = icvAlloc( bufferSize ));
+    CV_CALL( buffer = cvAlloc( bufferSize ));
 
     func = (CvMatchTemplFunc)(funcs[imethod + dataOffset * 6]);
 
@@ -2074,13 +1526,13 @@ cvMatchTemplate( const void* arr, const void* templarr, void* resultarr,
     result_step = result->step;
 
     if( img_step == 0 )
-        img_step = img->width*icvPixSize[CV_MAT_TYPE(img->type)];
+        img_step = img->width*CV_ELEM_SIZE(img->type);
 
     if( templ_step == 0 )
-        templ_step = templ->width*icvPixSize[CV_MAT_TYPE(templ->type)];
+        templ_step = templ->width*CV_ELEM_SIZE(templ->type);
 
     if( result_step == 0 )
-        result_step = result->width*icvPixSize[CV_MAT_TYPE(result->type)];
+        result_step = result->width*CV_ELEM_SIZE(result->type);
 
     IPPI_CALL(  func( img->data.ptr, img_step, imgSize,
                       templ->data.ptr, templ_step, templSize,
index be76812b522468f7ed3e41405b7a12faadda8451..3658a309b0b61484b21cc88ef151af9bf4e52184 100644 (file)
 
 #include "_cv.h"
 
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    icvThreshold8uC1R
-//    Purpose: Thresholding the source array
-//    Context:
-//    Parameters:
-//      Src     - source array
-//      roi     - size of picture in elements
-//      srcStep - length of string
-//      Thresh  - threshold parameter
-//      Type    - thresholding type, must be one of
-//                  CV_THRESH_BINARY       - val = (val > Thresh ? MAX    : 0)
-//                  CV_THRESH_BINARY_INV   - val = (val > Thresh ? 0      : MAX)
-//                  CV_THRESH_TRUNC        - val = (val > Thresh ? Thresh : val)
-//                  CV_THRESH_TOZERO       - val = (val > Thresh ? val    : 0)
-//                  CV_THRESH_TOZERO_INV   - val = (val > Thresh ? 0      : val)
-//    Returns:
-//    Notes:
-//      The MAX constant for uchar is 255, for char is 127
-//F*/
-IPCVAPI_IMPL( CvStatus, icvThresh_8u_C1R, (const uchar * src,
-                                           int src_step,
-                                           uchar * dst,
-                                           int dst_step,
-                                           CvSize roi,
-                                           int thresh, uchar maxval, CvThreshType type) )
+IPCVAPI_IMPL( CvStatus, icvThresh_8u_C1R,
+    (const uchar * src, int src_step, uchar * dst, int dst_step,
+     CvSize roi, int thresh, uchar maxval, int type),
+    (src, src_step, dst, dst_step, roi, thresh, maxval, type) )
 {
     /* Some variables */
     int i, j;
@@ -134,125 +113,10 @@ IPCVAPI_IMPL( CvStatus, icvThresh_8u_C1R, (const uchar * src,
 }
 
 
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    icvThreshold8sC1R
-//    Purpose: Thresholding the source array
-//    Context:
-//    Parameters:
-//      Src     - source array
-//      roi     - size of picture in elements
-//      srcStep - length of string
-//      Thresh  - threshold parameter
-//      Type    - thresholding type, must be one of
-//                  CV_THRESH_BINARY       - val = (val > Thresh ? MAX    : 0)
-//                  CV_THRESH_BINARY_INV   - val = (val > Thresh ? 0      : MAX)
-//                  CV_THRESH_TRUNC        - val = (val > Thresh ? Thresh : val)
-//                  CV_THRESH_TOZERO       - val = (val > Thresh ? val    : 0)
-//                  CV_THRESH_TOZERO_INV   - val = (val > Thresh ? 0      : val)
-//    Returns:
-//    Notes:
-//      The MAX constant for uchar is 255, for char is 127
-//F*/
-IPCVAPI_IMPL( CvStatus, icvThresh_8s_C1R, (const char *src,
-                                           int src_step,
-                                           char *dst,
-                                           int dst_step,
-                                           CvSize roi,
-                                           int thresh, char maxval, CvThreshType type) )
-{
-    /* Some variables */
-    int i, j;
-
-    /* Check for bad arguments */
-    if( !src || !dst )
-        return CV_NULLPTR_ERR;
-    if( thresh < -128 || thresh > 127 )
-        return CV_BADFACTOR_ERR;
-    if( roi.width <= 0 || roi.height <= 0 )
-        return CV_BADSIZE_ERR;
-    if( roi.width > src_step )
-        return CV_BADSIZE_ERR;
-    if( roi.width > dst_step )
-        return CV_BADSIZE_ERR;
-
-    if( roi.width == src_step && roi.width == dst_step )
-    {
-        roi.width *= roi.height;
-        roi.height = 1;
-    }
-
-    /* Calculating */
-    switch (type)
-    {
-    case CV_THRESH_BINARY:
-        for( i = 0; i < roi.height; i++, src += src_step, dst += dst_step )
-            for( j = 0; j < roi.width; j++ )
-                dst[j] = (char) (((thresh - src[j]) >> 8) & maxval);
-        break;
-    case CV_THRESH_BINARY_INV:
-        for( i = 0; i < roi.height; i++, src += src_step, dst += dst_step )
-            for( j = 0; j < roi.width; j++ )
-                dst[j] = (char) (((src[j] - thresh - 1) >> 8) & maxval);
-        break;
-    case CV_THRESH_TRUNC:
-        for( i = 0; i < roi.height; i++, src += src_step, dst += dst_step )
-            for( j = 0; j < roi.width; j++ )
-            {
-                int temp = src[j] - thresh;
-
-                dst[j] = (char) ((temp & (temp >> 31)) + thresh);
-            }
-        break;
-    case CV_THRESH_TOZERO:
-        for( i = 0; i < roi.height; i++, src += src_step, dst += dst_step )
-            for( j = 0; j < roi.width; j++ )
-            {
-                int temp = src[j];
-
-                dst[j] = (char) (((thresh - temp) >> 31) & temp);
-            }
-        break;
-    case CV_THRESH_TOZERO_INV:
-        for( i = 0; i < roi.height; i++, src += src_step, dst += dst_step )
-            for( j = 0; j < roi.width; j++ )
-            {
-                int temp = src[j];
-
-                dst[j] = (char) (((temp - thresh - 1) >> 31) & temp);
-            }
-        break;
-    default:
-        return CV_BADFLAG_ERR;
-    }
-    return CV_NO_ERR;
-}
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    icvThreshold32fC1R
-//    Purpose: Thresholding the source array
-//    Context:
-//    Parameters:
-//      Src     - source array
-//      roi     - size of picture in elements
-//      srcStep - length of string
-//      Thresh  - threshold parameter
-//      Type    - thresholding type, must be one of
-//                  CV_THRESH_BINARY       - val = (val > Thresh ? MAX    : 0)
-//                  CV_THRESH_BINARY_INV   - val = (val > Thresh ? 0      : MAX)
-//                  CV_THRESH_TRUNC        - val = (val > Thresh ? Thresh : val)
-//                  CV_THRESH_TOZERO       - val = (val > Thresh ? val    : 0)
-//                  CV_THRESH_TOZERO_INV   - val = (val > Thresh ? 0      : val)
-//    Returns:
-//    Notes:
-//      The MAX constant for uchar is 255, for char is 127
-//F*/
-IPCVAPI_IMPL( CvStatus, icvThresh_32f_C1R, (const float *src,
-                                            int src_step,
-                                            float *dst,
-                                            int dst_step,
-                                            CvSize roi,
-                                            float thresh, float maxval, CvThreshType type) )
+IPCVAPI_IMPL( CvStatus, icvThresh_32f_C1R,
+    (const float *src, int src_step, float *dst, int dst_step,
+    CvSize roi, float thresh, float maxval, int type),
+    (src, src_step, dst, dst_step, roi, thresh, maxval, type))
 {
     /* Some variables */
     int i, j;
@@ -268,15 +132,15 @@ IPCVAPI_IMPL( CvStatus, icvThresh_32f_C1R, (const float *src,
         return CV_NULLPTR_ERR;
     if( roi.width < 0 || roi.height < 0 )
         return CV_BADSIZE_ERR;
-    if( roi.width * sizeof_float > src_step )
+    if( roi.width * CV_SIZEOF_FLOAT > src_step )
         return CV_BADSIZE_ERR;
-    if( roi.width * sizeof_float > dst_step )
+    if( roi.width * CV_SIZEOF_FLOAT > dst_step )
         return CV_BADSIZE_ERR;
-    if( (src_step & (sizeof_float - 1)) != 0 || (dst_step & (sizeof_float - 1)) != 0 )
+    if( (src_step & (CV_SIZEOF_FLOAT - 1)) != 0 || (dst_step & (CV_SIZEOF_FLOAT - 1)) != 0 )
         return CV_BADSIZE_ERR;
 
-    src_step /= sizeof_float;
-    dst_step /= sizeof_float;
+    src_step /= CV_SIZEOF_FLOAT;
+    dst_step /= CV_SIZEOF_FLOAT;
 
     if( roi.width == src_step && roi.width == dst_step )
     {
@@ -358,7 +222,7 @@ IPCVAPI_IMPL( CvStatus, icvThresh_32f_C1R, (const float *src,
 
 
 CV_IMPL void
-cvThreshold( const void* srcarr, void* dstarr, double thresh, double maxval, CvThreshType type )
+cvThreshold( const void* srcarr, void* dstarr, double thresh, double maxval, int type )
 {
     CV_FUNCNAME( "cvThreshold" );
 
@@ -406,7 +270,7 @@ cvThreshold( const void* srcarr, void* dstarr, double thresh, double maxval, CvT
     if( !CV_ARE_SIZES_EQ( src, dst ) )
         CV_ERROR( CV_StsUnmatchedSizes, "" );
 
-    roi = icvGetMatSize( src );
+    roi = cvGetMatSize( src );
     roi.width *= CV_MAT_CN(src->type);
     if( CV_IS_MAT_CONT( src->type & dst->type ))
     {
@@ -428,19 +292,13 @@ cvThreshold( const void* srcarr, void* dstarr, double thresh, double maxval, CvT
                                      (uchar*)dst->data.ptr, dst_step, roi,
                                      cvRound(thresh), CV_CAST_8U(ival), type ));
         break;
-    case CV_8S:
-        ival = cvRound(maxval);
-        IPPI_CALL( icvThresh_8s_C1R( (char*)src->data.ptr, src_step,
-                                     (char*)dst->data.ptr, dst_step, roi,
-                                     cvRound(thresh), CV_CAST_8S(ival), type ));
-        break;
     case CV_32F:
         IPPI_CALL( icvThresh_32f_C1R( src->data.fl, src_step,
                                       dst->data.fl, dst_step, roi,
                                       (float)thresh, (float)maxval, type ));
         break;
     default:
-        CV_ERROR( CV_BadDepth, icvUnsupportedFormat );
+        CV_ERROR( CV_BadDepth, cvUnsupportedFormat );
     }
 
     __END__;
index 945cda0cb5263fb87d77e5a523387d5b97d4cd7e..2e7e1c3e9c6426b6a11752e1c15b59826d4071ae 100644 (file)
@@ -52,7 +52,7 @@ typedef struct CvUnDistortData
 CvUnDistortData;
 
 /*F//////////////////////////////////////////////////////////////////////////////////////
-//    Names: icvUnDistortInit_8uC1R, icvUnDistortInit_8uC3R, 
+//    Names: icvUnDistortInit_8uC1R, icvUnDistortInit_8uC3R,
 //    Purpose: The functions calculate arrays of distorted points indices and
 //             interpolation coefficients for cvUnDistort function
 //    Context:
@@ -72,11 +72,10 @@ CvUnDistortData;
 //F*/
 /*______________________________________________________________________________________*/
 
-IPCVAPI_IMPL( CvStatus, icvUnDistortInit, ( int srcStep, int* data,
-                                            int mapStep, CvSize size,
-                                            const float *intrMatrix,
-                                            const float *distCoeffs,
-                                            int interToggle, int pixSize ))
+IPCVAPI_IMPL( CvStatus, icvUnDistortInit,
+    ( int srcStep, int* data, int mapStep, CvSize size, const float *intrMatrix,
+      const float *distCoeffs, int interToggle, int pixSize ),
+      (srcStep, data, mapStep, size, intrMatrix, distCoeffs, interToggle, pixSize) )
 {
     const float a1 = 1.f / intrMatrix[0], b1 = 1.f / intrMatrix[4],
         u0 = intrMatrix[2], v0 = intrMatrix[5],
@@ -96,7 +95,7 @@ IPCVAPI_IMPL( CvStatus, icvUnDistortInit, ( int srcStep, int* data,
         {
             float dv = v - v0;
             float y = b1 * dv;
-            float y1 = p1 / y;
+            float y1 = p1 / (y?y:0.1f);
             float y2 = y * y;
             float y3 = 2.f * p1 * y;
 
@@ -104,7 +103,7 @@ IPCVAPI_IMPL( CvStatus, icvUnDistortInit, ( int srcStep, int* data,
             {
                 float du = u - u0;
                 float x = a1 * du;
-                float x1 = p2 / x;
+                float x1 = p2 / (x?x:0.1f);
                 float x2 = x * x;
                 float x3 = p22 * x;
                 float r2 = x2 + y2;
@@ -132,7 +131,7 @@ IPCVAPI_IMPL( CvStatus, icvUnDistortInit, ( int srcStep, int* data,
         {
             float dv = v - v0;
             float y = b1 * dv;
-            float y1 = p1 / y;
+            float y1 = p1 / (y?y:0.1f);
             float y2 = y * y;
             float y3 = 2.f * p1 * y;
 
@@ -140,7 +139,7 @@ IPCVAPI_IMPL( CvStatus, icvUnDistortInit, ( int srcStep, int* data,
             {
                 float du = u - u0;
                 float x = a1 * du;
-                float x1 = p2 / x;
+                float x1 = p2 / (x?x:0.1f);
                 float x2 = x * x;
                 float x3 = p22 * x;
                 float r2 = x2 + y2;
@@ -226,10 +225,10 @@ IPCVAPI_IMPL( CvStatus, icvUnDistortInit, ( int srcStep, int* data,
 //F*/
 /*______________________________________________________________________________________*/
 
-IPCVAPI_IMPL( CvStatus, icvUnDistort_8u_C1R, ( const uchar* src, int srcStep,
-                                               const int* data, int mapStep,
-                                               uchar* dst, int dstStep,
-                                               CvSize size, int interToggle ))
+IPCVAPI_IMPL( CvStatus, icvUnDistort_8u_C1R,
+    ( const uchar* src, int srcStep, const int* data, int mapStep,
+      uchar* dst, int dstStep, CvSize size, int interToggle ),
+      (src, srcStep, data, mapStep, dst, dstStep, size, interToggle) )
 {
     int u, v;
     uchar buf;
@@ -296,14 +295,14 @@ IPCVAPI_IMPL( CvStatus, icvUnDistort_8u_C1R, ( const uchar* src, int srcStep,
     t1 = (src_ptr)[2];                  \
     (dst_ptr)[1] = t0;                  \
     (dst_ptr)[2] = t1
-   
+
 
 /*_____________________________ 3-CHANNEL IMAGES _______________________________*/
 
-IPCVAPI_IMPL( CvStatus, icvUnDistort_8u_C3R, ( const uchar* src, int srcStep,
-                                               const int* data, int mapStep,
-                                               uchar* dst, int dstStep,
-                                               CvSize size, int interToggle ))
+IPCVAPI_IMPL( CvStatus, icvUnDistort_8u_C3R,
+    ( const uchar* src, int srcStep, const int* data, int mapStep,
+      uchar* dst, int dstStep, CvSize size, int interToggle ),
+      (src, srcStep, data, mapStep, dst, dstStep, size, interToggle) )
 {
     int u, v;
     uchar buf[3];
@@ -404,11 +403,10 @@ IPCVAPI_IMPL( CvStatus, icvUnDistort_8u_C3R, ( const uchar* src, int srcStep,
 #define S2 11
 #define FM (float)0x400000
 
-IPCVAPI_IMPL( CvStatus, icvUnDistort1_8u_C1R, ( const uchar* src, int srcStep,
-                                                uchar* dst, int dstStep, CvSize size,
-                                                const float *intrMatrix,
-                                                const float *distCoeffs,
-                                                int interToggle ))
+IPCVAPI_IMPL( CvStatus, icvUnDistort1_8u_C1R,
+    ( const uchar* src, int srcStep, uchar* dst, int dstStep, CvSize size,
+      const float *intrMatrix, const float *distCoeffs, int interToggle ),
+      (src, srcStep, dst, dstStep, size, intrMatrix, distCoeffs, interToggle) )
 {
     const float fm = FM;
     const float a1 = 1.f / intrMatrix[0], b1 = 1.f / intrMatrix[4],
@@ -423,15 +421,15 @@ IPCVAPI_IMPL( CvStatus, icvUnDistort1_8u_C1R, ( const uchar* src, int srcStep,
     if( !src || !dst || !intrMatrix || !distCoeffs )
         return CV_NULLPTR_ERR;
 
-    x2 = (float *) icvAlloc( sizeof( float ) * size.width );
+    x2 = (float *) cvAlloc( sizeof( float ) * size.width );
 
     if( x2 == NULL )
         return CV_OUTOFMEM_ERR;
-    du = (float *) icvAlloc( sizeof( float ) * size.width );
+    du = (float *) cvAlloc( sizeof( float ) * size.width );
 
     if( du == NULL )
     {
-        icvFree( (void **) &x2 );
+        cvFree( (void **) &x2 );
         return CV_OUTOFMEM_ERR;
     }
 
@@ -519,17 +517,16 @@ IPCVAPI_IMPL( CvStatus, icvUnDistort1_8u_C1R, ( const uchar* src, int srcStep,
 
     memcpy( (void*)src, buf, 1 );
 
-    icvFree( (void **) &x2 );
-    icvFree( (void **) &du );
+    cvFree( (void **) &x2 );
+    cvFree( (void **) &du );
     return CV_NO_ERR;
 }
 /*______________________________________________________ 3-CHANNEL IMAGES ______________*/
 
-IPCVAPI_IMPL( CvStatus, icvUnDistort1_8u_C3R, ( const uchar* src, int srcStep,
-                                                uchar* dst, int dstStep, CvSize size,
-                                                const float *intrMatrix,
-                                                const float *distCoeffs,
-                                                int interToggle ))
+IPCVAPI_IMPL( CvStatus, icvUnDistort1_8u_C3R,
+    ( const uchar* src, int srcStep, uchar* dst, int dstStep, CvSize size,
+      const float *intrMatrix, const float *distCoeffs, int interToggle ),
+      (src, srcStep, dst, dstStep, size, intrMatrix, distCoeffs, interToggle) )
 {
     const float fm = FM;
     const float a1 = 1.f / intrMatrix[0], b1 = 1.f / intrMatrix[4],
@@ -545,15 +542,15 @@ IPCVAPI_IMPL( CvStatus, icvUnDistort1_8u_C3R, ( const uchar* src, int srcStep,
     if( !src || !dst || !intrMatrix || !distCoeffs )
         return CV_NULLPTR_ERR;
 
-    x2 = (float *) icvAlloc( sizeof( float ) * size.width );
+    x2 = (float *) cvAlloc( sizeof( float ) * size.width );
 
     if( x2 == NULL )
         return CV_OUTOFMEM_ERR;
-    du = (float *) icvAlloc( sizeof( float ) * size.width );
+    du = (float *) cvAlloc( sizeof( float ) * size.width );
 
     if( du == NULL )
     {
-        icvFree( (void **) &x2 );
+        cvFree( (void **) &x2 );
         return CV_OUTOFMEM_ERR;
     }
 
@@ -753,8 +750,8 @@ IPCVAPI_IMPL( CvStatus, icvUnDistort1_8u_C3R, ( const uchar* src, int srcStep,
 
     memcpy( (void*)src, buf, 1 );
 
-    icvFree( (void **) &x2 );
-    icvFree( (void **) &du );
+    cvFree( (void **) &x2 );
+    cvFree( (void **) &du );
     return CV_NO_ERR;
 }
 
@@ -781,11 +778,10 @@ IPCVAPI_IMPL( CvStatus, icvUnDistort1_8u_C3R, ( const uchar* src, int srcStep,
 //F*/
 /*______________________________________________________________________________________*/
 
-IPCVAPI_IMPL( CvStatus, icvUnDistortEx_8u_C1R, ( const uchar* src, int srcStep,
-                                                 uchar* dst, int dstStep, CvSize size,
-                                                 const float *intrMatrix,
-                                                 const float *distCoeffs,
-                                                 int interToggle ))
+IPCVAPI_IMPL( CvStatus, icvUnDistortEx_8u_C1R,
+    ( const uchar* src, int srcStep, uchar* dst, int dstStep, CvSize size,
+      const float *intrMatrix, const float *distCoeffs, int interToggle ),
+      (src, srcStep, dst, dstStep, size, intrMatrix, distCoeffs, interToggle) )
 {
     const float fm = FM;
     const float a1 = 1.f / intrMatrix[0], b1 = 1.f / intrMatrix[4],
@@ -806,21 +802,21 @@ IPCVAPI_IMPL( CvStatus, icvUnDistortEx_8u_C1R, ( const uchar* src, int srcStep,
     /*if ( !p1 && !p2 ) return icvUnDistort1_8uC1R ( src, dst, step, size,
        intrMatrix, distCoeffs, interToggle ); */
 
-    x1 = (float *) icvAlloc( sizeof( float ) * size.width );
-    x2 = (float *) icvAlloc( sizeof( float ) * size.width );
-    x3 = (float *) icvAlloc( sizeof( float ) * size.width );
-    du = (float *) icvAlloc( sizeof( float ) * size.width );
+    x1 = (float *) cvAlloc( sizeof( float ) * size.width );
+    x2 = (float *) cvAlloc( sizeof( float ) * size.width );
+    x3 = (float *) cvAlloc( sizeof( float ) * size.width );
+    du = (float *) cvAlloc( sizeof( float ) * size.width );
 
     if( x1 == NULL || x2 == NULL || x3 == NULL || du == NULL )
     {
         if( x1 )
-            icvFree( (void **) &x1 );
+            cvFree( (void **) &x1 );
         if( x2 )
-            icvFree( (void **) &x2 );
+            cvFree( (void **) &x2 );
         if( x3 )
-            icvFree( (void **) &x3 );
+            cvFree( (void **) &x3 );
         if( du )
-            icvFree( (void **) &du );
+            cvFree( (void **) &du );
         return CV_OUTOFMEM_ERR;
     }
 
@@ -834,7 +830,7 @@ IPCVAPI_IMPL( CvStatus, icvUnDistortEx_8u_C1R, ( const uchar* src, int srcStep,
             float w = u - u0;
             float x = a1 * w;
 
-            x1[u] = p2 / x;
+            x1[u] = p2 / (x?x:0.1f);
             x2[u] = x * x;
             x3[u] = 2.f * p2 * x;
             du[u] = w;
@@ -844,7 +840,7 @@ IPCVAPI_IMPL( CvStatus, icvUnDistortEx_8u_C1R, ( const uchar* src, int srcStep,
         {
             float dv = v - v0;
             float y = b1 * dv;
-            float y1 = p1 / y;
+            float y1 = p1 / (y?y:0.1f);
             float y2 = y * y;
             float y3 = 2.f * p1 * y;
 
@@ -872,7 +868,7 @@ IPCVAPI_IMPL( CvStatus, icvUnDistortEx_8u_C1R, ( const uchar* src, int srcStep,
             float w = u - u0;
             float x = a1 * w;
 
-            x1[u] = p2 / x;
+            x1[u] = p2 / (x?x:0.1f);
             x2[u] = x * x;
             x3[u] = 2.f * p2 * x;
             du[u] = fm * w;
@@ -882,7 +878,7 @@ IPCVAPI_IMPL( CvStatus, icvUnDistortEx_8u_C1R, ( const uchar* src, int srcStep,
         {
             float dv = v - v0;
             float y = b1 * dv;
-            float y1 = p1 / y;
+            float y1 = p1 / (y?y:0.1f);
             float y2 = y * y;
             float y3 = 2.f * p1 * y;
 
@@ -926,19 +922,18 @@ IPCVAPI_IMPL( CvStatus, icvUnDistortEx_8u_C1R, ( const uchar* src, int srcStep,
 
     memcpy( (void*)src, buf, 1 );
 
-    icvFree( (void **) &x1 );
-    icvFree( (void **) &x2 );
-    icvFree( (void **) &x3 );
-    icvFree( (void **) &du );
+    cvFree( (void **) &x1 );
+    cvFree( (void **) &x2 );
+    cvFree( (void **) &x3 );
+    cvFree( (void **) &du );
     return CV_NO_ERR;
 }
 /*______________________________________________________ 3-CHANNEL IMAGES ______________*/
 
-IPCVAPI_IMPL( CvStatus, icvUnDistortEx_8u_C3R, ( const uchar* src, int srcStep,
-                                                 uchar* dst, int dstStep, CvSize size,
-                                                 const float *intrMatrix,
-                                                 const float *distCoeffs,
-                                                 int interToggle ))
+IPCVAPI_IMPL( CvStatus, icvUnDistortEx_8u_C3R,
+    ( const uchar* src, int srcStep, uchar* dst, int dstStep, CvSize size,
+      const float *intrMatrix, const float *distCoeffs, int interToggle ),
+     (src, srcStep, dst, dstStep, size, intrMatrix, distCoeffs, interToggle) )
 {
     const float fm = FM;
     const float a1 = 1.f / intrMatrix[0], b1 = 1.f / intrMatrix[4],
@@ -960,27 +955,27 @@ IPCVAPI_IMPL( CvStatus, icvUnDistortEx_8u_C3R, ( const uchar* src, int srcStep,
     /*if ( !p1 && !p2 ) return icvUnDistort1_8uC3R ( src, dst, srcStep, size,
        intrMatrix, distCoeffs, interToggle ); */
 
-    x1 = (float *) icvAlloc( sizeof( float ) * size.width );
-    x2 = (float *) icvAlloc( sizeof( float ) * size.width );
-    x3 = (float *) icvAlloc( sizeof( float ) * size.width );
-    du = (float *) icvAlloc( sizeof( float ) * size.width );
+    x1 = (float *) cvAlloc( sizeof( float ) * size.width );
+    x2 = (float *) cvAlloc( sizeof( float ) * size.width );
+    x3 = (float *) cvAlloc( sizeof( float ) * size.width );
+    du = (float *) cvAlloc( sizeof( float ) * size.width );
 
     if( x1 == NULL || x2 == NULL || x3 == NULL || du == NULL )
     {
         if( x1 )
-            icvFree( (void **) &x1 );
+            cvFree( (void **) &x1 );
         if( x2 )
-            icvFree( (void **) &x2 );
+            cvFree( (void **) &x2 );
         if( x3 )
-            icvFree( (void **) &x3 );
+            cvFree( (void **) &x3 );
         if( du )
-            icvFree( (void **) &du );
+            cvFree( (void **) &du );
         return CV_OUTOFMEM_ERR;
     }
 
     memcpy( buf, src, 3 );
     memset( (void*)src, 0, 3 );
-    
+
     if( !interToggle )
     {
         for( u = 0; u < size.width; u++ )
@@ -988,7 +983,7 @@ IPCVAPI_IMPL( CvStatus, icvUnDistortEx_8u_C3R, ( const uchar* src, int srcStep,
             float w = u - u0;
             float x = a1 * w;
 
-            x1[u] = p2 / x;
+            x1[u] = p2 / (x?x:0.1f);
             x2[u] = x * x;
             x3[u] = 2.f * p2 * x;
             du[u] = w;
@@ -998,7 +993,7 @@ IPCVAPI_IMPL( CvStatus, icvUnDistortEx_8u_C3R, ( const uchar* src, int srcStep,
         {
             float dv = v - v0;
             float y = b1 * dv;
-            float y1 = p1 / y;
+            float y1 = p1 / (y?y:0.1f);
             float y2 = y * y;
             float y3 = 2.f * p1 * y;
 
@@ -1058,7 +1053,7 @@ IPCVAPI_IMPL( CvStatus, icvUnDistortEx_8u_C3R, ( const uchar* src, int srcStep,
             float w = u - u0;
             float x = a1 * w;
 
-            x1[u] = p2 / x;
+            x1[u] = p2 / (x?x:0.1f);
             x2[u] = x * x;
             x3[u] = 2.f * p2 * x;
             du[u] = fm * w;
@@ -1068,7 +1063,7 @@ IPCVAPI_IMPL( CvStatus, icvUnDistortEx_8u_C3R, ( const uchar* src, int srcStep,
         {
             float dv = v - v0;
             float y = b1 * dv;
-            float y1 = p1 / y;
+            float y1 = p1 / (y?y:0.1f);
             float y2 = y * y;
             float y3 = 2.f * p1 * y;
 
@@ -1196,10 +1191,10 @@ IPCVAPI_IMPL( CvStatus, icvUnDistortEx_8u_C3R, ( const uchar* src, int srcStep,
 
     memcpy( (void*)src, buf, 3 );
 
-    icvFree( (void **) &x1 );
-    icvFree( (void **) &x2 );
-    icvFree( (void **) &x3 );
-    icvFree( (void **) &du );
+    cvFree( (void **) &x1 );
+    cvFree( (void **) &x2 );
+    cvFree( (void **) &x3 );
+    cvFree( (void **) &du );
     return CV_NO_ERR;
 }
 /*______________________________________________________________________________________*/
@@ -1235,7 +1230,7 @@ cvUnDistortOnce( const void* srcImage, void* dstImage,
 {
     static void* undist_tab[4];
     static int inittab = 0;
-    
+
     CV_FUNCNAME( "cvUnDistortOnce" );
 
     __BEGIN__;
@@ -1274,7 +1269,7 @@ cvUnDistortOnce( const void* srcImage, void* dstImage,
     if( !intrMatrix || !distCoeffs )
         CV_ERROR( CV_StsNullPtr, "" );
 
-    size = icvGetMatSize( src );
+    size = cvGetMatSize( src );
 
     func = (CvUnDistortOnceFunc)
         (undist_tab[(CV_MAT_CN(src->type)-1)+(distCoeffs[2] != 0 || distCoeffs[3] != 0)]);
@@ -1284,7 +1279,7 @@ cvUnDistortOnce( const void* srcImage, void* dstImage,
 
     IPPI_CALL( func( src->data.ptr, src->step, dst->data.ptr, dst->step, size,
                      intrMatrix, distCoeffs, interpolate ));
-  
+
     __END__;
 }
 
@@ -1337,11 +1332,11 @@ cvUnDistortInit( const void* srcImage, void* undistMap,
         !interpolate && src->width > map->width )
         CV_ERROR( CV_StsUnmatchedSizes, "" );
 
-    size = icvGetMatSize( src );
+    size = cvGetMatSize( src );
 
     IPPI_CALL( icvUnDistortInit( src->step, (int*)map->data.ptr, map->step,
                                  size, intrMatrix, distCoeffs,
-                                 interpolate, icvPixSize[CV_MAT_TYPE(src->type)]));
+                                 interpolate, CV_ELEM_SIZE(src->type)));
 
     __END__;
 }
@@ -1402,7 +1397,7 @@ cvUnDistort( const void* srcImage, void* dstImage,
     if( !CV_ARE_SIZES_EQ( src, dst ))
         CV_ERROR( CV_StsUnmatchedSizes, "" );
 
-    size = icvGetMatSize( src );
+    size = cvGetMatSize( src );
 
     if( CV_MAT_TYPE( src->type ) == CV_8UC1 )
     {
@@ -1414,7 +1409,7 @@ cvUnDistort( const void* srcImage, void* dstImage,
     else if( CV_MAT_TYPE( src->type ) == CV_8UC3 )
     {
         IPPI_CALL( icvUnDistort_8u_C3R( src->data.ptr, src->step,
-                                        (int*)map->data.ptr, map->step, 
+                                        (int*)map->data.ptr, map->step,
                                         dst->data.ptr, dst->step,
                                         size, interpolate ));
     }
@@ -1487,7 +1482,7 @@ cvConvertMap( const CvArr* srcImage, const CvArr* flUndistMap,
         CV_ERROR( CV_StsUnmatchedSizes, "" );
 
     flmapdata = (CvPoint2D32f*)flmap->data.ptr;
-    pixSize = icvPixSize[CV_MAT_TYPE(src->type)];
+    pixSize = CV_ELEM_SIZE(src->type);
     srcStep = src->step;
 
     if( !interpolate )
index 7d05cb99ac72e5fc3ff701d87e1b81c352bbecfd..ad89e0e4d603e90ae4befb3418ca04dae92bdd07 100644 (file)
 
 #include "_cv.h"
 
-
-CV_IMPL CvRect
-cvMaxRect( const CvRect* rect1, const CvRect* rect2 )
+CvSeq* icvPointSeqFromMat( int seq_kind, const CvArr* arr,
+                           CvContour* contour_header, CvSeqBlock* block )
 {
-    if( rect1 && rect2 )
-    {
-        CvRect max_rect;
-        int a, b;
-
-        max_rect.x = a = rect1->x;
-        b = rect2->x;
-        if( max_rect.x > b )
-            max_rect.x = b;
-
-        max_rect.width = a += rect1->width;
-        b += rect2->width;
-
-        if( max_rect.width < b )
-            max_rect.width = b;
-        max_rect.width -= max_rect.x;
-
-        max_rect.y = a = rect1->y;
-        b = rect2->y;
-        if( max_rect.y > b )
-            max_rect.y = b;
-
-        max_rect.height = a += rect1->height;
-        b += rect2->height;
-
-        if( max_rect.height < b )
-            max_rect.height = b;
-        max_rect.height -= max_rect.y;
-        return max_rect;
-    }
-    else if( rect1 )
-        return *rect1;
-    else if( rect2 )
-        return *rect2;
-    else
-        return cvRect(0,0,0,0);
-}
+    CvSeq* contour = 0;
 
+    CV_FUNCNAME( "icvPointSeqFromMat" );
 
-CV_IMPL void
-cvBoxPoints( CvBox2D box, CvPoint2D32f pt[4] )
-{
-    CV_FUNCNAME( "cvBoxPoints" );
+    assert( arr != 0 && contour_header != 0 && block != 0 );
 
     __BEGIN__;
     
-    float a = (float)cos(box.angle)*0.5f;
-    float b = (float)sin(box.angle)*0.5f;
+    int eltype;
+    CvMat* mat = (CvMat*)arr;
+    
+    if( !CV_IS_MAT( mat ))
+        CV_ERROR( CV_StsBadArg, "Input array is not a valid matrix" ); 
+
+    eltype = CV_MAT_TYPE( mat->type );
+    if( eltype != CV_32SC2 && eltype != CV_32FC2 )
+        CV_ERROR( CV_StsUnsupportedFormat,
+        "The matrix can not be converted to point sequence because of "
+        "inappropriate element type" );
 
-    if( !pt )
-        CV_ERROR( CV_StsNullPtr, "NULL vertex array pointer" );
+    if( mat->width != 1 && mat->height != 1 || !CV_IS_MAT_CONT(mat->type))
+        CV_ERROR( CV_StsBadArg,
+        "The matrix converted to point sequence must be "
+        "1-dimensional and continuous" );
 
-    pt[0].x = box.center.x - a*box.size.height - b*box.size.width;
-    pt[0].y = box.center.y + b*box.size.height - a*box.size.width;
-    pt[1].x = box.center.x + a*box.size.height - b*box.size.width;
-    pt[1].y = box.center.y - b*box.size.height - a*box.size.width;
-    pt[2].x = 2*box.center.x - pt[0].x;
-    pt[2].y = 2*box.center.y - pt[0].y;
-    pt[3].x = 2*box.center.x - pt[1].x;
-    pt[3].y = 2*box.center.y - pt[1].y;
+    CV_CALL( cvMakeSeqHeaderForArray(
+            (seq_kind & (CV_SEQ_KIND_MASK|CV_SEQ_FLAG_CLOSED)) | eltype,
+            sizeof(CvContour), CV_ELEM_SIZE(eltype), mat->data.ptr,
+            mat->width*mat->height, (CvSeq*)contour_header, block ));
+
+    contour = (CvSeq*)contour_header;
 
     __END__;
+
+    return contour;
+}
+
+
+/*F///////////////////////////////////////////////////////////////////////////////////////
+//    Names:      icvJacobiEigens_32f, icvJacobiEigens_64d
+//    Purpose:    Eigenvalues & eigenvectors calculation of a symmetric matrix:
+//                A Vi  =  Ei Vi
+//    Context:   
+//    Parameters: A(n, n) - source symmetric matrix (n - rows & columns number),
+//                V(n, n) - matrix of its eigenvectors 
+//                          (i-th row is an eigenvector Vi),
+//                E(n)    - vector of its eigenvalues
+//                          (i-th element is an eigenvalue Ei),
+//                eps     - accuracy of diagonalization.
+//               
+//    Returns:
+//    CV_NO_ERROR or error code     
+//    Notes:
+//        1. The functions destroy source matrix A, so if you need it further, you
+//           have to copy it before the processing.
+//        2. Eigenvalies and eigenvectors are sorted in Ei absolute value descending.
+//        3. Calculation time depends on eps value. If the time isn't very important,
+//           we recommend to set eps = 0.
+//F*/
+
+/*=========================== Single precision function ================================*/
+
+CvStatus CV_STDCALL icvJacobiEigens_32f(float *A, float *V, float *E, int n, float eps)
+{
+    int i, j, k, ind;
+    float *AA = A, *VV = V;
+    double Amax, anorm = 0, ax;
+
+    if( A == NULL || V == NULL || E == NULL )
+        return CV_NULLPTR_ERR;
+    if( n <= 0 )
+        return CV_BADSIZE_ERR;
+    if( eps < 1.0e-7f )
+        eps = 1.0e-7f;
+
+    /*-------- Prepare --------*/
+    for( i = 0; i < n; i++, VV += n, AA += n )
+    {
+        for( j = 0; j < i; j++ )
+        {
+            double Am = AA[j];
+
+            anorm += Am * Am;
+        }
+        for( j = 0; j < n; j++ )
+            VV[j] = 0.f;
+        VV[i] = 1.f;
+    }
+
+    anorm = sqrt( anorm + anorm );
+    ax = anorm * eps / n;
+    Amax = anorm;
+
+    while( Amax > ax )
+    {
+        Amax /= n;
+        do                      /* while (ind) */
+        {
+            int p, q;
+            float *V1 = V, *A1 = A;
+
+            ind = 0;
+            for( p = 0; p < n - 1; p++, A1 += n, V1 += n )
+            {
+                float *A2 = A + n * (p + 1), *V2 = V + n * (p + 1);
+
+                for( q = p + 1; q < n; q++, A2 += n, V2 += n )
+                {
+                    double x, y, c, s, c2, s2, a;
+                    float *A3, Apq = A1[q], App, Aqq, Aip, Aiq, Vpi, Vqi;
+
+                    if( fabs( Apq ) < Amax )
+                        continue;
+
+                    ind = 1;
+
+                    /*---- Calculation of rotation angle's sine & cosine ----*/
+                    App = A1[p];
+                    Aqq = A2[q];
+                    y = 5.0e-1 * (App - Aqq);
+                    x = -Apq / sqrt( (double)Apq * Apq + (double)y * y );
+                    if( y < 0.0 )
+                        x = -x;
+                    s = x / sqrt( 2.0 * (1.0 + sqrt( 1.0 - (double)x * x )));
+                    s2 = s * s;
+                    c = sqrt( 1.0 - s2 );
+                    c2 = c * c;
+                    a = 2.0 * Apq * c * s;
+
+                    /*---- Apq annulation ----*/
+                    A3 = A;
+                    for( i = 0; i < p; i++, A3 += n )
+                    {
+                        Aip = A3[p];
+                        Aiq = A3[q];
+                        Vpi = V1[i];
+                        Vqi = V2[i];
+                        A3[p] = (float) (Aip * c - Aiq * s);
+                        A3[q] = (float) (Aiq * c + Aip * s);
+                        V1[i] = (float) (Vpi * c - Vqi * s);
+                        V2[i] = (float) (Vqi * c + Vpi * s);
+                    }
+                    for( ; i < q; i++, A3 += n )
+                    {
+                        Aip = A1[i];
+                        Aiq = A3[q];
+                        Vpi = V1[i];
+                        Vqi = V2[i];
+                        A1[i] = (float) (Aip * c - Aiq * s);
+                        A3[q] = (float) (Aiq * c + Aip * s);
+                        V1[i] = (float) (Vpi * c - Vqi * s);
+                        V2[i] = (float) (Vqi * c + Vpi * s);
+                    }
+                    for( ; i < n; i++ )
+                    {
+                        Aip = A1[i];
+                        Aiq = A2[i];
+                        Vpi = V1[i];
+                        Vqi = V2[i];
+                        A1[i] = (float) (Aip * c - Aiq * s);
+                        A2[i] = (float) (Aiq * c + Aip * s);
+                        V1[i] = (float) (Vpi * c - Vqi * s);
+                        V2[i] = (float) (Vqi * c + Vpi * s);
+                    }
+                    A1[p] = (float) (App * c2 + Aqq * s2 - a);
+                    A2[q] = (float) (App * s2 + Aqq * c2 + a);
+                    A1[q] = A2[p] = 0.0f;
+                }               /*q */
+            }                   /*p */
+        }
+        while( ind );
+        Amax /= n;
+    }                           /* while ( Amax > ax ) */
+
+    for( i = 0, k = 0; i < n; i++, k += n + 1 )
+        E[i] = A[k];
+    /*printf(" M = %d\n", M); */
+
+    /* -------- ordering -------- */
+    for( i = 0; i < n; i++ )
+    {
+        int m = i;
+        float Em = (float) fabs( E[i] );
+
+        for( j = i + 1; j < n; j++ )
+        {
+            float Ej = (float) fabs( E[j] );
+
+            m = (Em < Ej) ? j : m;
+            Em = (Em < Ej) ? Ej : Em;
+        }
+        if( m != i )
+        {
+            int l;
+            float b = E[i];
+
+            E[i] = E[m];
+            E[m] = b;
+            for( j = 0, k = i * n, l = m * n; j < n; j++, k++, l++ )
+            {
+                b = V[k];
+                V[k] = V[l];
+                V[l] = b;
+            }
+        }
+    }
+
+    return CV_NO_ERR;
+}
+
+/*=========================== Double precision function ================================*/
+
+CvStatus CV_STDCALL icvJacobiEigens_64d(double *A, double *V, double *E, int n, double eps)
+{
+    int i, j, k, p, q, ind;
+    double *A1 = A, *V1 = V, *A2 = A, *V2 = V;
+    double Amax = 0.0, anorm = 0.0, ax;
+
+    if( A == NULL || V == NULL || E == NULL )
+        return CV_NULLPTR_ERR;
+    if( n <= 0 )
+        return CV_BADSIZE_ERR;
+    if( eps < 1.0e-15 )
+        eps = 1.0e-15;
+
+    /*-------- Prepare --------*/
+    for( i = 0; i < n; i++, V1 += n, A1 += n )
+    {
+        for( j = 0; j < i; j++ )
+        {
+            double Am = A1[j];
+
+            anorm += Am * Am;
+        }
+        for( j = 0; j < n; j++ )
+            V1[j] = 0.0;
+        V1[i] = 1.0;
+    }
+
+    anorm = sqrt( anorm + anorm );
+    ax = anorm * eps / n;
+    Amax = anorm;
+
+    while( Amax > ax )
+    {
+        Amax /= n;
+        do                      /* while (ind) */
+        {
+            ind = 0;
+            A1 = A;
+            V1 = V;
+            for( p = 0; p < n - 1; p++, A1 += n, V1 += n )
+            {
+                A2 = A + n * (p + 1);
+                V2 = V + n * (p + 1);
+                for( q = p + 1; q < n; q++, A2 += n, V2 += n )
+                {
+                    double x, y, c, s, c2, s2, a;
+                    double *A3, Apq, App, Aqq, App2, Aqq2, Aip, Aiq, Vpi, Vqi;
+
+                    if( fabs( A1[q] ) < Amax )
+                        continue;
+                    Apq = A1[q];
+
+                    ind = 1;
+
+                    /*---- Calculation of rotation angle's sine & cosine ----*/
+                    App = A1[p];
+                    Aqq = A2[q];
+                    y = 5.0e-1 * (App - Aqq);
+                    x = -Apq / sqrt( Apq * Apq + (double)y * y );
+                    if( y < 0.0 )
+                        x = -x;
+                    s = x / sqrt( 2.0 * (1.0 + sqrt( 1.0 - (double)x * x )));
+                    s2 = s * s;
+                    c = sqrt( 1.0 - s2 );
+                    c2 = c * c;
+                    a = 2.0 * Apq * c * s;
+
+                    /*---- Apq annulation ----*/
+                    A3 = A;
+                    for( i = 0; i < p; i++, A3 += n )
+                    {
+                        Aip = A3[p];
+                        Aiq = A3[q];
+                        Vpi = V1[i];
+                        Vqi = V2[i];
+                        A3[p] = Aip * c - Aiq * s;
+                        A3[q] = Aiq * c + Aip * s;
+                        V1[i] = Vpi * c - Vqi * s;
+                        V2[i] = Vqi * c + Vpi * s;
+                    }
+                    for( ; i < q; i++, A3 += n )
+                    {
+                        Aip = A1[i];
+                        Aiq = A3[q];
+                        Vpi = V1[i];
+                        Vqi = V2[i];
+                        A1[i] = Aip * c - Aiq * s;
+                        A3[q] = Aiq * c + Aip * s;
+                        V1[i] = Vpi * c - Vqi * s;
+                        V2[i] = Vqi * c + Vpi * s;
+                    }
+                    for( ; i < n; i++ )
+                    {
+                        Aip = A1[i];
+                        Aiq = A2[i];
+                        Vpi = V1[i];
+                        Vqi = V2[i];
+                        A1[i] = Aip * c - Aiq * s;
+                        A2[i] = Aiq * c + Aip * s;
+                        V1[i] = Vpi * c - Vqi * s;
+                        V2[i] = Vqi * c + Vpi * s;
+                    }
+                    App2 = App * c2 + Aqq * s2 - a;
+                    Aqq2 = App * s2 + Aqq * c2 + a;
+                    A1[p] = App2;
+                    A2[q] = Aqq2;
+                    A1[q] = A2[p] = 0.0;
+                }               /*q */
+            }                   /*p */
+        }
+        while( ind );
+    }                           /* while ( Amax > ax ) */
+
+    for( i = 0, k = 0; i < n; i++, k += n + 1 )
+        E[i] = A[k];
+
+    /* -------- ordering -------- */
+    for( i = 0; i < n; i++ )
+    {
+        int m = i;
+        double Em = fabs( E[i] );
+
+        for( j = i + 1; j < n; j++ )
+        {
+            double Ej = fabs( E[j] );
+
+            m = (Em < Ej) ? j : m;
+            Em = (Em < Ej) ? Ej : Em;
+        }
+        if( m != i )
+        {
+            int l;
+            double b = E[i];
+
+            E[i] = E[m];
+            E[m] = b;
+            for( j = 0, k = i * n, l = m * n; j < n; j++, k++, l++ )
+            {
+                b = V[k];
+                V[k] = V[l];
+                V[l] = b;
+            }
+        }
+    }
+
+    return CV_NO_ERR;
+}
+
+
+/* 
+   Finds L1 norm between two blocks.
+*/
+int
+icvCmpBlocksL1_8u_C1( const uchar * vec1, const uchar * vec2, int len )
+{
+    int i, sum = 0;
+
+    for( i = 0; i <= len - 4; i += 4 )
+    {
+        int t0 = abs(vec1[i] - vec2[i]);
+        int t1 = abs(vec1[i + 1] - vec2[i + 1]);
+        int t2 = abs(vec1[i + 2] - vec2[i + 2]);
+        int t3 = abs(vec1[i + 3] - vec2[i + 3]);
+
+        sum += t0 + t1 + t2 + t3;
+    }
+
+    for( ; i < len; i++ )
+    {
+        int t0 = abs(vec1[i] - vec2[i]);
+        sum += t0;
+    }
+
+    return sum;
+}
+
+
+int64
+icvCmpBlocksL2_8u_C1( const uchar * vec1, const uchar * vec2, int len )
+{
+    int i, s = 0;
+    int64 sum = 0;
+
+    for( i = 0; i <= len - 4; i += 4 )
+    {
+        int v = vec1[i] - vec2[i];
+        int e = v * v;
+
+        v = vec1[i + 1] - vec2[i + 1];
+        e += v * v;
+        v = vec1[i + 2] - vec2[i + 2];
+        e += v * v;
+        v = vec1[i + 3] - vec2[i + 3];
+        e += v * v;
+        sum += e;
+    }
+
+    for( ; i < len; i++ )
+    {
+        int v = vec1[i] - vec2[i];
+
+        s += v * v;
+    }
+
+    return sum + s;
+}
+
+
+double
+icvCmpBlocksL2_32f_C1( const float *vec1, const float *vec2, int len )
+{
+    double sum = 0;
+    int i;
+
+    for( i = 0; i <= len - 4; i += 4 )
+    {
+        double v0 = vec1[i] - vec2[i];
+        double v1 = vec1[i + 1] - vec2[i + 1];
+        double v2 = vec1[i + 2] - vec2[i + 2];
+        double v3 = vec1[i + 3] - vec2[i + 3];
+
+        sum += v0 * v0 + v1 * v1 + v2 * v2 + v3 * v3;
+    }
+    for( ; i < len; i++ )
+    {
+        double v = vec1[i] - vec2[i];
+
+        sum += v * v;
+    }
+    return sum;
+}
+
+
+/* 
+   Calculates cross correlation for two blocks.
+*/
+int64
+icvCrossCorr_8u_C1( const uchar * vec1, const uchar * vec2, int len )
+{
+    int i, s = 0;
+    int64 sum = 0;
+
+    for( i = 0; i <= len - 4; i += 4 )
+    {
+        int e = vec1[i] * vec2[i];
+        int v = vec1[i + 1] * vec2[i + 1];
+
+        e += v;
+        v = vec1[i + 2] * vec2[i + 2];
+        e += v;
+        v = vec1[i + 3] * vec2[i + 3];
+        e += v;
+        sum += e;
+    }
+
+    for( ; i < len; i++ )
+    {
+        s += vec1[i] * vec2[i];
+    }
+
+    return sum + s;
+}
+
+double
+icvCrossCorr_32f_C1( const float *vec1, const float *vec2, int len )
+{
+    double sum = 0;
+    int i;
+
+    for( i = 0; i <= len - 4; i += 4 )
+    {
+        double v0 = vec1[i] * vec2[i];
+        double v1 = vec1[i + 1] * vec2[i + 1];
+        double v2 = vec1[i + 2] * vec2[i + 2];
+        double v3 = vec1[i + 3] * vec2[i + 3];
+
+        sum += v0 + v1 + v2 + v3;
+    }
+    for( ; i < len; i++ )
+    {
+        double v = vec1[i] * vec2[i];
+
+        sum += v;
+    }
+    return sum;
+}
+
+
+/* 
+   Calculates cross correlation for two blocks.
+*/
+int64
+icvSumPixels_8u_C1( const uchar * vec, int len )
+{
+    int i, s = 0;
+    int64 sum = 0;
+
+    for( i = 0; i <= len - 4; i += 4 )
+    {
+        sum += vec[i] + vec[i + 1] + vec[i + 2] + vec[i + 3];
+    }
+
+    for( ; i < len; i++ )
+    {
+        s += vec[i];
+    }
+
+    return sum + s;
 }
 
+double
+icvSumPixels_32f_C1( const float *vec, int len )
+{
+    double sum = 0;
+    int i;
+
+    for( i = 0; i <= len - 4; i += 4 )
+    {
+        sum += vec[i] + vec[i + 1] + vec[i + 2] + vec[i + 3];
+    }
+
+    for( ; i < len; i++ )
+    {
+        sum += vec[i];
+    }
+    return sum;
+}
 
 /* End of file. */