#ifndef __RV_MTX_H_INCLUDED_
#define __RV_MTX_H_INCLUDED_


 
#include <rvb\rvtypes.h>
#include <rvb\mpm.h>

   


#define MTX_API  WINAPI


 
//constructor and destroyer
extern "C" RvMatrix MTX_API rvCreateMatrixEx(int elemType,  int rows, int cols, void* pDataBuffer  , UINT nSize , int pitch=-1);
//MTX_API RvMatrix rvCreateMatrix(int elemType, RvSize size );
extern "C" RvMatrix MTX_API rvCreateMatrix(int elemType,  int rows, int cols );


extern "C" void   MTX_API   rvDestroyMatrix( RvMatrix  matrix );
extern "C" RvMatrix MTX_API rvCloneMatrix( const RvMatrix  matrix, RvMatrix dest=NULL);

extern "C" BOOL MTX_API  rvInitializeMatrix(RvMatrix  matrix, int elemType, int rows, int cols,  void* pDataBuffer , UINT nSize, int pitch=-1);
extern "C" void MTX_API  rvFinalizeMatrix(RvMatrix  matrix);

extern "C" void MTX_API rvMallocMatrixHeap(RvMatrix  matrix, RvMemSize size);
 extern "C" void MTX_API rvFreeMatrixHeap(RvMatrix  matrix);
 


extern "C" BOOL MTX_API  rvmAttachBufferEx( RvMatrix matrix, const RvMatrix  other );
extern "C" BOOL MTX_API  rvmAttachBuffer( RvMatrix matrix,   void* data, UINT size );
extern "C" void MTX_API  rvmDetachBuffer( RvMatrix matrix );

extern "C" int MTX_API   rvmGetType( const RvMatrix matrix );


//sub matrix
extern "C" RvMatrix MTX_API rvmGetSub( const RvMatrix matrix,  RvMatrix submat ,  RvRect rect);

#define RV_GET_SUB_MTX(mtx, rect) rvmGetSub(mtx, NULL, rect)

extern "C" RvMatrix MTX_API rvmGetRow( const RvMatrix matrix,  int row,  RvMatrix submat=NULL);
extern "C" RvMatrix MTX_API rvmGetRows( const RvMatrix matrix, int start, int end, int delta=1, RvMatrix submat=NULL  );

extern "C" RvMatrix MTX_API  rvmGetCol(const RvMatrix matrix,  int col,  RvMatrix submat=NULL );
extern "C" RvMatrix MTX_API  rvmGetCols(const RvMatrix matrix, int start, int end, int delta=1, RvMatrix submat=NULL );
extern "C" RvMatrix  MTX_API rvmGetDiag(const RvMatrix matrix, int offset=0, RvMatrix submat=NULL  );

extern "C" UINT MTX_API       rvmGetSize( const RvMatrix matrix);
extern "C" RvSize MTX_API     rvmGetDims( const RvMatrix matrix);
extern "C" void*   MTX_API    rvmGetPtr( const RvMatrix matrix );

//element
extern "C" RvScalar MTX_API rvmGet ( const RvMatrix matrix, int idx0, int idx1=-1, int idx2=-1, int idx3=-1 );
extern "C" double MTX_API   rvmGet2( const RvMatrix matrix, int row, int col );
extern "C" double MTX_API   rvmGet3( const RvMatrix matrix, int x, int y );

extern "C" void  MTX_API    rvmSet(const RvMatrix matrix, int x, int y, double val);
extern "C" void   MTX_API   rvmSet2(const RvMatrix matrix, int idx0, int idx1, int idx2, int idx3, RvScalar value);
extern "C" void  MTX_API    rvmSet3(const RvMatrix matrix, int row, int col, double val );

//fast value-setting
extern "C" void    MTX_API  rvmCopy( const RvMatrix  src, RvMatrix dest, const RvMatrix mask=NULL );
extern "C" void  MTX_API    rvmFlood( RvMatrix matrix, RvScalar value,  const RvMatrix mask=NULL );
extern "C" void  MTX_API    rvmZero( RvMatrix matrix );
extern "C" void MTX_API     rvmIdent( RvMatrix matrix, RvScalar value  );
extern "C" void   MTX_API   rvmRange( RvMatrix matrix, double start, double end );

//transpose
extern "C" BOOL   MTX_API    rvmReshapeEx(  RvMatrix matrix, int elemType, int rows, int cols );
extern "C" BOOL  MTX_API     rvmReshape(  RvMatrix matrix, int rows, int cols );

extern "C" void  MTX_API     rvmRepeat( const RvMatrix src, RvMatrix dest );
extern "C" void  MTX_API     rvmFlip( const RvMatrix src, int dir=RV_DIR_BOTH  );
extern "C" RvMatrix MTX_API  rvmSplit( const RvMatrix src, RvMatrix dst0, RvMatrix dst1,   RvMatrix dst2, RvMatrix dst3 );
extern "C" RvMatrix MTX_API  rvmMerge( const RvMatrix src0, const RvMatrix src1,  const RvMatrix src2, const RvMatrix src3, RvMatrix dest );
extern "C" RvMatrix MTX_API  rvmMix( const RvMatrix* src, int src_count, RvMatrix* dest, int dst_count, const int* from_to, int pair_count );
//MTX_API void     rvmRandShuffle( RvMatrix mat, RvRNG* rng, double iter_factor=1 );

extern "C" void MTX_API     rvmLut( const RvMatrix src,  const RvMatrix lut, RvMatrix dest=NULL, const RvMatrix mask=NULL);
extern "C" void  MTX_API    rvmLinear( const RvMatrix src, RvMatrix dest, double scale=1, double shift=0 , const RvMatrix mask=NULL);
extern "C" void  MTX_API    rvmLinearAbs( const RvMatrix src, RvMatrix dest, double scale=1, double shift=0 , const RvMatrix mask=NULL);

//element 
extern "C" RvMatrix MTX_API rvmAdd( const RvMatrix src1, const RvMatrix src2, RvMatrix dest, const RvMatrix mask=NULL );
extern "C" RvMatrix MTX_API rvmAddS( const RvMatrix src, RvScalar value, RvMatrix dest, const RvMatrix mask=NULL );
extern "C" RvMatrix MTX_API rvmAddW( const RvMatrix src1, double alpha, const RvMatrix src2, double beta, double gamma, RvMatrix dest );
extern "C" RvMatrix MTX_API rvmSub( const RvMatrix src1, const RvMatrix src2, RvMatrix dest, const RvMatrix mask=NULL );
extern "C" RvMatrix MTX_API rvmSubS( const RvMatrix src, RvScalar value, RvMatrix dest, const RvMatrix mask=NULL );
extern "C" RvMatrix MTX_API rvmSubRS( const RvMatrix src, RvScalar value, RvMatrix dest, const RvMatrix mask=NULL );
extern "C" RvMatrix MTX_API rvmMul( const RvMatrix src1, const RvMatrix src2, RvMatrix dest, double scale=1 );
extern "C" RvMatrix MTX_API rvmDiv( const RvMatrix src1, const RvMatrix src2, RvMatrix dest, double scale=1 );
extern "C" RvMatrix MTX_API rvmAnd( const RvMatrix src1, const RvMatrix src2, RvMatrix dest, const RvMatrix mask=NULL);
extern "C" RvMatrix MTX_API rvmAndS( const RvMatrix src, RvScalar value, RvMatrix dest, const RvMatrix mask=NULL );
extern "C" RvMatrix MTX_API rvmOr( const RvMatrix src1, const RvMatrix src2, RvMatrix dest, const RvMatrix mask=NULL );
extern "C" RvMatrix MTX_API rvmOrS( const RvMatrix src, RvScalar value, RvMatrix dest, const RvMatrix mask=NULL );
extern "C" RvMatrix MTX_API rvmXor( const RvMatrix src1, const RvMatrix src2, RvMatrix dest, const RvMatrix mask=NULL );
extern "C" RvMatrix MTX_API rvmXorS( const RvMatrix src, RvScalar value, RvMatrix dest, const RvMatrix mask=NULL );
extern "C" RvMatrix MTX_API rvmNot( const RvMatrix src, RvMatrix dest, const RvMatrix mask=NULL );

extern "C" RvMatrix MTX_API rvmCmp( const RvMatrix src1, const RvMatrix src2, RvMatrix dest, int cmp_op , const RvMatrix mask=NULL );
extern "C" RvMatrix MTX_API rvmCmpS( const RvMatrix src, double value, RvMatrix dest, int cmp_op, const RvMatrix mask=NULL );

extern "C" RvMatrix MTX_API rvmIsRanged( const RvMatrix src, const RvMatrix lower, const RvMatrix upper, RvMatrix dest, const RvMatrix mask=NULL );
extern "C" RvMatrix MTX_API rvmInRangeS( const RvMatrix src, RvScalar lower, RvScalar upper, RvMatrix dest, const RvMatrix mask=NULL );
extern "C" RvMatrix MTX_API rvmMax( const RvMatrix src1, const RvMatrix src2, RvMatrix dest , const RvMatrix mask=NULL);
extern "C" RvMatrix MTX_API rvmMaxS( const RvMatrix src, double value, RvMatrix dest, const RvMatrix mask=NULL );
extern "C" RvMatrix MTX_API rvmMin( const RvMatrix src1, const RvMatrix src2, RvMatrix dest, const RvMatrix mask=NULL );
extern "C" RvMatrix MTX_API rvmMinS( const RvMatrix src, double value, RvMatrix dest, const RvMatrix mask=NULL );
extern "C" RvMatrix MTX_API rvmAbsDiff( const RvMatrix src1, const RvMatrix src2, RvMatrix dest , const RvMatrix mask=NULL);
extern "C" RvMatrix MTX_API rvmAbsDiffS( const RvMatrix src, RvMatrix dest, RvScalar value, const RvMatrix mask=NULL );



#endif
 