All optimized function tables wrapped to getters to change its

initialization time.
This commit is contained in:
Alexander Smorkalov 2013-08-15 00:01:40 -07:00
parent 7b95bb20f7
commit a3dd13450c
4 changed files with 387 additions and 270 deletions

View File

@ -1131,6 +1131,8 @@ static void binary_op(InputArray _src1, InputArray _src2, OutputArray _dst,
}
}
static BinaryFunc* getMaxTab()
{
static BinaryFunc maxTab[] =
{
(BinaryFunc)GET_OPTIMIZED(max8u), (BinaryFunc)GET_OPTIMIZED(max8s),
@ -1140,6 +1142,11 @@ static BinaryFunc maxTab[] =
0
};
return maxTab;
}
static BinaryFunc* getMinTab()
{
static BinaryFunc minTab[] =
{
(BinaryFunc)GET_OPTIMIZED(min8u), (BinaryFunc)GET_OPTIMIZED(min8s),
@ -1149,6 +1156,9 @@ static BinaryFunc minTab[] =
0
};
return minTab;
}
}
void cv::bitwise_and(InputArray a, InputArray b, OutputArray c, InputArray mask)
@ -1177,36 +1187,36 @@ void cv::bitwise_not(InputArray a, OutputArray c, InputArray mask)
void cv::max( InputArray src1, InputArray src2, OutputArray dst )
{
binary_op(src1, src2, dst, noArray(), maxTab, false );
binary_op(src1, src2, dst, noArray(), getMaxTab(), false );
}
void cv::min( InputArray src1, InputArray src2, OutputArray dst )
{
binary_op(src1, src2, dst, noArray(), minTab, false );
binary_op(src1, src2, dst, noArray(), getMinTab(), false );
}
void cv::max(const Mat& src1, const Mat& src2, Mat& dst)
{
OutputArray _dst(dst);
binary_op(src1, src2, _dst, noArray(), maxTab, false );
binary_op(src1, src2, _dst, noArray(), getMaxTab(), false );
}
void cv::min(const Mat& src1, const Mat& src2, Mat& dst)
{
OutputArray _dst(dst);
binary_op(src1, src2, _dst, noArray(), minTab, false );
binary_op(src1, src2, _dst, noArray(), getMinTab(), false );
}
void cv::max(const Mat& src1, double src2, Mat& dst)
{
OutputArray _dst(dst);
binary_op(src1, src2, _dst, noArray(), maxTab, false );
binary_op(src1, src2, _dst, noArray(), getMaxTab(), false );
}
void cv::min(const Mat& src1, double src2, Mat& dst)
{
OutputArray _dst(dst);
binary_op(src1, src2, _dst, noArray(), minTab, false );
binary_op(src1, src2, _dst, noArray(), getMinTab(), false );
}
/****************************************************************************************\
@ -1493,6 +1503,8 @@ static void arithm_op(InputArray _src1, InputArray _src2, OutputArray _dst,
}
}
static BinaryFunc* getAddTab()
{
static BinaryFunc addTab[] =
{
(BinaryFunc)GET_OPTIMIZED(add8u), (BinaryFunc)GET_OPTIMIZED(add8s),
@ -1502,6 +1514,11 @@ static BinaryFunc addTab[] =
0
};
return addTab;
}
static BinaryFunc* getSubTab()
{
static BinaryFunc subTab[] =
{
(BinaryFunc)GET_OPTIMIZED(sub8u), (BinaryFunc)GET_OPTIMIZED(sub8s),
@ -1511,7 +1528,12 @@ static BinaryFunc subTab[] =
0
};
static BinaryFunc absdiffTab[] =
return subTab;
}
static BinaryFunc* getAbsDiffTab()
{
static BinaryFunc absDiffTab[] =
{
(BinaryFunc)GET_OPTIMIZED(absdiff8u), (BinaryFunc)GET_OPTIMIZED(absdiff8s),
(BinaryFunc)GET_OPTIMIZED(absdiff16u), (BinaryFunc)GET_OPTIMIZED(absdiff16s),
@ -1520,12 +1542,15 @@ static BinaryFunc absdiffTab[] =
0
};
return absDiffTab;
}
}
void cv::add( InputArray src1, InputArray src2, OutputArray dst,
InputArray mask, int dtype )
{
arithm_op(src1, src2, dst, mask, dtype, addTab );
arithm_op(src1, src2, dst, mask, dtype, getAddTab() );
}
void cv::subtract( InputArray src1, InputArray src2, OutputArray dst,
@ -1560,12 +1585,12 @@ void cv::subtract( InputArray src1, InputArray src2, OutputArray dst,
}
}
#endif
arithm_op(src1, src2, dst, mask, dtype, subTab );
arithm_op(src1, src2, dst, mask, dtype, getSubTab() );
}
void cv::absdiff( InputArray src1, InputArray src2, OutputArray dst )
{
arithm_op(src1, src2, dst, noArray(), -1, absdiffTab);
arithm_op(src1, src2, dst, noArray(), -1, getAbsDiffTab());
}
/****************************************************************************************\
@ -1855,6 +1880,8 @@ static void recip64f( const double* src1, size_t step1, const double* src2, size
}
static BinaryFunc* getMulTab()
{
static BinaryFunc mulTab[] =
{
(BinaryFunc)mul8u, (BinaryFunc)mul8s, (BinaryFunc)mul16u,
@ -1862,6 +1889,11 @@ static BinaryFunc mulTab[] =
(BinaryFunc)mul64f, 0
};
return mulTab;
}
static BinaryFunc* getDivTab()
{
static BinaryFunc divTab[] =
{
(BinaryFunc)div8u, (BinaryFunc)div8s, (BinaryFunc)div16u,
@ -1869,6 +1901,11 @@ static BinaryFunc divTab[] =
(BinaryFunc)div64f, 0
};
return divTab;
}
static BinaryFunc* getRecipTab()
{
static BinaryFunc recipTab[] =
{
(BinaryFunc)recip8u, (BinaryFunc)recip8s, (BinaryFunc)recip16u,
@ -1876,25 +1913,27 @@ static BinaryFunc recipTab[] =
(BinaryFunc)recip64f, 0
};
return recipTab;
}
}
void cv::multiply(InputArray src1, InputArray src2,
OutputArray dst, double scale, int dtype)
{
arithm_op(src1, src2, dst, noArray(), dtype, mulTab, true, &scale);
arithm_op(src1, src2, dst, noArray(), dtype, getMulTab(), true, &scale);
}
void cv::divide(InputArray src1, InputArray src2,
OutputArray dst, double scale, int dtype)
{
arithm_op(src1, src2, dst, noArray(), dtype, divTab, true, &scale);
arithm_op(src1, src2, dst, noArray(), dtype, getDivTab(), true, &scale);
}
void cv::divide(double scale, InputArray src2,
OutputArray dst, int dtype)
{
arithm_op(src2, src2, dst, noArray(), dtype, recipTab, true, &scale);
arithm_op(src2, src2, dst, noArray(), dtype, getRecipTab(), true, &scale);
}
/****************************************************************************************\
@ -2037,6 +2076,8 @@ static void addWeighted64f( const double* src1, size_t step1, const double* src2
addWeighted_<double, double>(src1, step1, src2, step2, dst, step, sz, scalars);
}
static BinaryFunc* getAddWeightedTab()
{
static BinaryFunc addWeightedTab[] =
{
(BinaryFunc)GET_OPTIMIZED(addWeighted8u), (BinaryFunc)GET_OPTIMIZED(addWeighted8s), (BinaryFunc)GET_OPTIMIZED(addWeighted16u),
@ -2044,13 +2085,16 @@ static BinaryFunc addWeightedTab[] =
(BinaryFunc)addWeighted64f, 0
};
return addWeightedTab;
}
}
void cv::addWeighted( InputArray src1, double alpha, InputArray src2,
double beta, double gamma, OutputArray dst, int dtype )
{
double scalars[] = {alpha, beta, gamma};
arithm_op(src1, src2, dst, noArray(), dtype, addWeightedTab, true, scalars);
arithm_op(src1, src2, dst, noArray(), dtype, getAddWeightedTab(), true, scalars);
}
@ -2310,6 +2354,8 @@ static void cmp64f(const double* src1, size_t step1, const double* src2, size_t
cmp_(src1, step1, src2, step2, dst, step, size, *(int*)_cmpop);
}
static BinaryFunc getCmpFunc(int depth)
{
static BinaryFunc cmpTab[] =
{
(BinaryFunc)GET_OPTIMIZED(cmp8u), (BinaryFunc)GET_OPTIMIZED(cmp8s),
@ -2319,6 +2365,8 @@ static BinaryFunc cmpTab[] =
0
};
return cmpTab[depth];
}
static double getMinVal(int depth)
{
@ -2348,7 +2396,7 @@ void cv::compare(InputArray _src1, InputArray _src2, OutputArray _dst, int op)
_dst.create(src1.size(), CV_8UC(cn));
Mat dst = _dst.getMat();
Size sz = getContinuousSize(src1, src2, dst, src1.channels());
cmpTab[src1.depth()](src1.data, src1.step, src2.data, src2.step, dst.data, dst.step, sz, &op);
getCmpFunc(src1.depth())(src1.data, src1.step, src2.data, src2.step, dst.data, dst.step, sz, &op);
return;
}
@ -2380,7 +2428,7 @@ void cv::compare(InputArray _src1, InputArray _src2, OutputArray _dst, int op)
size_t esz = src1.elemSize();
size_t blocksize0 = (size_t)(BLOCK_SIZE + esz-1)/esz;
BinaryFunc func = cmpTab[depth1];
BinaryFunc func = getCmpFunc(depth1);
if( !haveScalar )
{
@ -2557,6 +2605,8 @@ static void inRangeReduce(const uchar* src, uchar* dst, size_t len, int cn)
typedef void (*InRangeFunc)( const uchar* src1, size_t step1, const uchar* src2, size_t step2,
const uchar* src3, size_t step3, uchar* dst, size_t step, Size sz );
static InRangeFunc getInRangeFunc(int depth)
{
static InRangeFunc inRangeTab[] =
{
(InRangeFunc)GET_OPTIMIZED(inRange8u), (InRangeFunc)GET_OPTIMIZED(inRange8s), (InRangeFunc)GET_OPTIMIZED(inRange16u),
@ -2564,6 +2614,9 @@ static InRangeFunc inRangeTab[] =
(InRangeFunc)inRange64f, 0
};
return inRangeTab[depth];
}
}
void cv::inRange(InputArray _src, InputArray _lowerb,
@ -2601,7 +2654,7 @@ void cv::inRange(InputArray _src, InputArray _lowerb,
_dst.create(src.dims, src.size, CV_8U);
Mat dst = _dst.getMat();
InRangeFunc func = inRangeTab[depth];
InRangeFunc func = getInRangeFunc(depth);
const Mat* arrays_sc[] = { &src, &dst, 0 };
const Mat* arrays_nosc[] = { &src, &dst, &lb, &ub, 0 };

View File

@ -194,18 +194,28 @@ static void merge64s(const int64** src, int64* dst, int len, int cn )
typedef void (*SplitFunc)(const uchar* src, uchar** dst, int len, int cn);
typedef void (*MergeFunc)(const uchar** src, uchar* dst, int len, int cn);
static SplitFunc getSplitFunc(int depth)
{
static SplitFunc splitTab[] =
{
(SplitFunc)GET_OPTIMIZED(split8u), (SplitFunc)GET_OPTIMIZED(split8u), (SplitFunc)GET_OPTIMIZED(split16u), (SplitFunc)GET_OPTIMIZED(split16u),
(SplitFunc)GET_OPTIMIZED(split32s), (SplitFunc)GET_OPTIMIZED(split32s), (SplitFunc)GET_OPTIMIZED(split64s), 0
};
return splitTab[depth];
}
static MergeFunc getMergeFunc(int depth)
{
static MergeFunc mergeTab[] =
{
(MergeFunc)GET_OPTIMIZED(merge8u), (MergeFunc)GET_OPTIMIZED(merge8u), (MergeFunc)GET_OPTIMIZED(merge16u), (MergeFunc)GET_OPTIMIZED(merge16u),
(MergeFunc)GET_OPTIMIZED(merge32s), (MergeFunc)GET_OPTIMIZED(merge32s), (MergeFunc)GET_OPTIMIZED(merge64s), 0
};
return mergeTab[depth];
}
}
void cv::split(const Mat& src, Mat* mv)
@ -217,7 +227,7 @@ void cv::split(const Mat& src, Mat* mv)
return;
}
SplitFunc func = splitTab[depth];
SplitFunc func = getSplitFunc(depth);
CV_Assert( func != 0 );
int esz = (int)src.elemSize(), esz1 = (int)src.elemSize1();
@ -328,7 +338,7 @@ void cv::merge(const Mat* mv, size_t n, OutputArray _dst)
NAryMatIterator it(arrays, ptrs, cn+1);
int total = (int)it.size, blocksize = cn <= 4 ? total : std::min(total, blocksize0);
MergeFunc func = mergeTab[depth];
MergeFunc func = getMergeFunc(depth);
for( i = 0; i < it.nplanes; i++, ++it )
{
@ -429,6 +439,8 @@ static void mixChannels64s( const int64** src, const int* sdelta,
typedef void (*MixChannelsFunc)( const uchar** src, const int* sdelta,
uchar** dst, const int* ddelta, int len, int npairs );
static MixChannelsFunc getMixchFunc(int depth)
{
static MixChannelsFunc mixchTab[] =
{
(MixChannelsFunc)mixChannels8u, (MixChannelsFunc)mixChannels8u, (MixChannelsFunc)mixChannels16u,
@ -436,6 +448,9 @@ static MixChannelsFunc mixchTab[] =
(MixChannelsFunc)mixChannels64s, 0
};
return mixchTab[depth];
}
}
void cv::mixChannels( const Mat* src, size_t nsrcs, Mat* dst, size_t ndsts, const int* fromTo, size_t npairs )
@ -489,7 +504,7 @@ void cv::mixChannels( const Mat* src, size_t nsrcs, Mat* dst, size_t ndsts, cons
NAryMatIterator it(arrays, ptrs, (int)(nsrcs + ndsts));
int total = (int)it.size, blocksize = std::min(total, (int)((BLOCK_SIZE + esz1-1)/esz1));
MixChannelsFunc func = mixchTab[depth];
MixChannelsFunc func = getMixchFunc(depth);
for( i = 0; i < it.nplanes; i++, ++it )
{
@ -941,6 +956,8 @@ DEF_CVT_FUNC(32s64f, int, double);
DEF_CVT_FUNC(32f64f, float, double);
DEF_CPY_FUNC(64s, int64);
static BinaryFunc getCvtScaleAbsFunc(int depth)
{
static BinaryFunc cvtScaleAbsTab[] =
{
(BinaryFunc)cvtScaleAbs8u, (BinaryFunc)cvtScaleAbs8s8u, (BinaryFunc)cvtScaleAbs16u8u,
@ -948,48 +965,11 @@ static BinaryFunc cvtScaleAbsTab[] =
(BinaryFunc)cvtScaleAbs64f8u, 0
};
static BinaryFunc cvtScaleTab[][8] =
{
{
(BinaryFunc)GET_OPTIMIZED(cvtScale8u), (BinaryFunc)GET_OPTIMIZED(cvtScale8s8u), (BinaryFunc)GET_OPTIMIZED(cvtScale16u8u),
(BinaryFunc)GET_OPTIMIZED(cvtScale16s8u), (BinaryFunc)GET_OPTIMIZED(cvtScale32s8u), (BinaryFunc)GET_OPTIMIZED(cvtScale32f8u),
(BinaryFunc)cvtScale64f8u, 0
},
{
(BinaryFunc)GET_OPTIMIZED(cvtScale8u8s), (BinaryFunc)GET_OPTIMIZED(cvtScale8s), (BinaryFunc)GET_OPTIMIZED(cvtScale16u8s),
(BinaryFunc)GET_OPTIMIZED(cvtScale16s8s), (BinaryFunc)GET_OPTIMIZED(cvtScale32s8s), (BinaryFunc)GET_OPTIMIZED(cvtScale32f8s),
(BinaryFunc)cvtScale64f8s, 0
},
{
(BinaryFunc)GET_OPTIMIZED(cvtScale8u16u), (BinaryFunc)GET_OPTIMIZED(cvtScale8s16u), (BinaryFunc)GET_OPTIMIZED(cvtScale16u),
(BinaryFunc)GET_OPTIMIZED(cvtScale16s16u), (BinaryFunc)GET_OPTIMIZED(cvtScale32s16u), (BinaryFunc)GET_OPTIMIZED(cvtScale32f16u),
(BinaryFunc)cvtScale64f16u, 0
},
{
(BinaryFunc)GET_OPTIMIZED(cvtScale8u16s), (BinaryFunc)GET_OPTIMIZED(cvtScale8s16s), (BinaryFunc)GET_OPTIMIZED(cvtScale16u16s),
(BinaryFunc)GET_OPTIMIZED(cvtScale16s), (BinaryFunc)GET_OPTIMIZED(cvtScale32s16s), (BinaryFunc)GET_OPTIMIZED(cvtScale32f16s),
(BinaryFunc)cvtScale64f16s, 0
},
{
(BinaryFunc)GET_OPTIMIZED(cvtScale8u32s), (BinaryFunc)GET_OPTIMIZED(cvtScale8s32s), (BinaryFunc)GET_OPTIMIZED(cvtScale16u32s),
(BinaryFunc)GET_OPTIMIZED(cvtScale16s32s), (BinaryFunc)GET_OPTIMIZED(cvtScale32s), (BinaryFunc)GET_OPTIMIZED(cvtScale32f32s),
(BinaryFunc)cvtScale64f32s, 0
},
{
(BinaryFunc)GET_OPTIMIZED(cvtScale8u32f), (BinaryFunc)GET_OPTIMIZED(cvtScale8s32f), (BinaryFunc)GET_OPTIMIZED(cvtScale16u32f),
(BinaryFunc)GET_OPTIMIZED(cvtScale16s32f), (BinaryFunc)GET_OPTIMIZED(cvtScale32s32f), (BinaryFunc)GET_OPTIMIZED(cvtScale32f),
(BinaryFunc)cvtScale64f32f, 0
},
{
(BinaryFunc)cvtScale8u64f, (BinaryFunc)cvtScale8s64f, (BinaryFunc)cvtScale16u64f,
(BinaryFunc)cvtScale16s64f, (BinaryFunc)cvtScale32s64f, (BinaryFunc)cvtScale32f64f,
(BinaryFunc)cvtScale64f, 0
},
{
0, 0, 0, 0, 0, 0, 0, 0
return cvtScaleAbsTab[depth];
}
};
BinaryFunc getConvertFunc(int sdepth, int ddepth)
{
static BinaryFunc cvtTab[][8] =
{
{
@ -1032,13 +1012,53 @@ static BinaryFunc cvtTab[][8] =
}
};
BinaryFunc getConvertFunc(int sdepth, int ddepth)
{
return cvtTab[CV_MAT_DEPTH(ddepth)][CV_MAT_DEPTH(sdepth)];
}
BinaryFunc getConvertScaleFunc(int sdepth, int ddepth)
{
static BinaryFunc cvtScaleTab[][8] =
{
{
(BinaryFunc)GET_OPTIMIZED(cvtScale8u), (BinaryFunc)GET_OPTIMIZED(cvtScale8s8u), (BinaryFunc)GET_OPTIMIZED(cvtScale16u8u),
(BinaryFunc)GET_OPTIMIZED(cvtScale16s8u), (BinaryFunc)GET_OPTIMIZED(cvtScale32s8u), (BinaryFunc)GET_OPTIMIZED(cvtScale32f8u),
(BinaryFunc)cvtScale64f8u, 0
},
{
(BinaryFunc)GET_OPTIMIZED(cvtScale8u8s), (BinaryFunc)GET_OPTIMIZED(cvtScale8s), (BinaryFunc)GET_OPTIMIZED(cvtScale16u8s),
(BinaryFunc)GET_OPTIMIZED(cvtScale16s8s), (BinaryFunc)GET_OPTIMIZED(cvtScale32s8s), (BinaryFunc)GET_OPTIMIZED(cvtScale32f8s),
(BinaryFunc)cvtScale64f8s, 0
},
{
(BinaryFunc)GET_OPTIMIZED(cvtScale8u16u), (BinaryFunc)GET_OPTIMIZED(cvtScale8s16u), (BinaryFunc)GET_OPTIMIZED(cvtScale16u),
(BinaryFunc)GET_OPTIMIZED(cvtScale16s16u), (BinaryFunc)GET_OPTIMIZED(cvtScale32s16u), (BinaryFunc)GET_OPTIMIZED(cvtScale32f16u),
(BinaryFunc)cvtScale64f16u, 0
},
{
(BinaryFunc)GET_OPTIMIZED(cvtScale8u16s), (BinaryFunc)GET_OPTIMIZED(cvtScale8s16s), (BinaryFunc)GET_OPTIMIZED(cvtScale16u16s),
(BinaryFunc)GET_OPTIMIZED(cvtScale16s), (BinaryFunc)GET_OPTIMIZED(cvtScale32s16s), (BinaryFunc)GET_OPTIMIZED(cvtScale32f16s),
(BinaryFunc)cvtScale64f16s, 0
},
{
(BinaryFunc)GET_OPTIMIZED(cvtScale8u32s), (BinaryFunc)GET_OPTIMIZED(cvtScale8s32s), (BinaryFunc)GET_OPTIMIZED(cvtScale16u32s),
(BinaryFunc)GET_OPTIMIZED(cvtScale16s32s), (BinaryFunc)GET_OPTIMIZED(cvtScale32s), (BinaryFunc)GET_OPTIMIZED(cvtScale32f32s),
(BinaryFunc)cvtScale64f32s, 0
},
{
(BinaryFunc)GET_OPTIMIZED(cvtScale8u32f), (BinaryFunc)GET_OPTIMIZED(cvtScale8s32f), (BinaryFunc)GET_OPTIMIZED(cvtScale16u32f),
(BinaryFunc)GET_OPTIMIZED(cvtScale16s32f), (BinaryFunc)GET_OPTIMIZED(cvtScale32s32f), (BinaryFunc)GET_OPTIMIZED(cvtScale32f),
(BinaryFunc)cvtScale64f32f, 0
},
{
(BinaryFunc)cvtScale8u64f, (BinaryFunc)cvtScale8s64f, (BinaryFunc)cvtScale16u64f,
(BinaryFunc)cvtScale16s64f, (BinaryFunc)cvtScale32s64f, (BinaryFunc)cvtScale32f64f,
(BinaryFunc)cvtScale64f, 0
},
{
0, 0, 0, 0, 0, 0, 0, 0
}
};
return cvtScaleTab[CV_MAT_DEPTH(ddepth)][CV_MAT_DEPTH(sdepth)];
}
@ -1051,7 +1071,7 @@ void cv::convertScaleAbs( InputArray _src, OutputArray _dst, double alpha, doubl
double scale[] = {alpha, beta};
_dst.create( src.dims, src.size, CV_8UC(cn) );
Mat dst = _dst.getMat();
BinaryFunc func = cvtScaleAbsTab[src.depth()];
BinaryFunc func = getCvtScaleAbsFunc(src.depth());
CV_Assert( func != 0 );
if( src.dims <= 2 )

View File

@ -1725,6 +1725,8 @@ diagtransform_64f(const double* src, double* dst, const double* m, int len, int
typedef void (*TransformFunc)( const uchar* src, uchar* dst, const uchar* m, int, int, int );
static TransformFunc getTransformFunc(int depth)
{
static TransformFunc transformTab[] =
{
(TransformFunc)transform_8u, (TransformFunc)transform_8s, (TransformFunc)transform_16u,
@ -1732,6 +1734,11 @@ static TransformFunc transformTab[] =
(TransformFunc)transform_64f, 0
};
return transformTab[depth];
}
static TransformFunc getDiagTransformFunc(int depth)
{
static TransformFunc diagTransformTab[] =
{
(TransformFunc)diagtransform_8u, (TransformFunc)diagtransform_8s, (TransformFunc)diagtransform_16u,
@ -1739,6 +1746,9 @@ static TransformFunc diagTransformTab[] =
(TransformFunc)diagtransform_64f, 0
};
return diagTransformTab[depth];
}
}
void cv::transform( InputArray _src, OutputArray _dst, InputArray _mtx )
@ -1800,7 +1810,7 @@ void cv::transform( InputArray _src, OutputArray _dst, InputArray _mtx )
}
}
TransformFunc func = isDiag ? diagTransformTab[depth] : transformTab[depth];
TransformFunc func = isDiag ? getDiagTransformFunc(depth): getTransformFunc(depth);
CV_Assert( func != 0 );
const Mat* arrays[] = {&src, &dst, 0};
@ -2766,6 +2776,8 @@ static double dotProd_64f(const double* src1, const double* src2, int len)
typedef double (*DotProdFunc)(const uchar* src1, const uchar* src2, int len);
static DotProdFunc getDotProdFunc(int depth)
{
static DotProdFunc dotProdTab[] =
{
(DotProdFunc)GET_OPTIMIZED(dotProd_8u), (DotProdFunc)GET_OPTIMIZED(dotProd_8s),
@ -2774,11 +2786,14 @@ static DotProdFunc dotProdTab[] =
(DotProdFunc)dotProd_64f, 0
};
return dotProdTab[depth];
}
double Mat::dot(InputArray _mat) const
{
Mat mat = _mat.getMat();
int cn = channels();
DotProdFunc func = dotProdTab[depth()];
DotProdFunc func = getDotProdFunc(depth());
CV_Assert( mat.type() == type() && mat.size == size && func != 0 );
if( isContinuous() && mat.isContinuous() )

View File

@ -199,6 +199,8 @@ static int sum64f( const double* src, const uchar* mask, double* dst, int len, i
typedef int (*SumFunc)(const uchar*, const uchar* mask, uchar*, int, int);
static SumFunc getSumFunc(int depth)
{
static SumFunc sumTab[] =
{
(SumFunc)GET_OPTIMIZED(sum8u), (SumFunc)sum8s,
@ -208,6 +210,9 @@ static SumFunc sumTab[] =
0
};
return sumTab[depth];
}
template<typename T>
static int countNonZero_(const T* src, int len )
{
@ -271,6 +276,8 @@ static int countNonZero64f( const double* src, int len )
typedef int (*CountNonZeroFunc)(const uchar*, int);
static CountNonZeroFunc getCountNonZeroTab(int depth)
{
static CountNonZeroFunc countNonZeroTab[] =
{
(CountNonZeroFunc)GET_OPTIMIZED(countNonZero8u), (CountNonZeroFunc)GET_OPTIMIZED(countNonZero8u),
@ -279,6 +286,8 @@ static CountNonZeroFunc countNonZeroTab[] =
(CountNonZeroFunc)GET_OPTIMIZED(countNonZero64f), 0
};
return countNonZeroTab[depth];
}
template<typename T, typename ST, typename SQT>
static int sumsqr_(const T* src0, const uchar* mask, ST* sum, SQT* sqsum, int len, int cn )
@ -427,12 +436,17 @@ static int sqsum64f( const double* src, const uchar* mask, double* sum, double*
typedef int (*SumSqrFunc)(const uchar*, const uchar* mask, uchar*, uchar*, int, int);
static SumSqrFunc getSumSqrTab(int depth)
{
static SumSqrFunc sumSqrTab[] =
{
(SumSqrFunc)GET_OPTIMIZED(sqsum8u), (SumSqrFunc)sqsum8s, (SumSqrFunc)sqsum16u, (SumSqrFunc)sqsum16s,
(SumSqrFunc)sqsum32s, (SumSqrFunc)GET_OPTIMIZED(sqsum32f), (SumSqrFunc)sqsum64f, 0
};
return sumSqrTab[depth];
}
}
cv::Scalar cv::sum( InputArray _src )
@ -478,7 +492,7 @@ cv::Scalar cv::sum( InputArray _src )
}
#endif
SumFunc func = sumTab[depth];
SumFunc func = getSumFunc(depth);
CV_Assert( cn <= 4 && func != 0 );
@ -530,7 +544,7 @@ cv::Scalar cv::sum( InputArray _src )
int cv::countNonZero( InputArray _src )
{
Mat src = _src.getMat();
CountNonZeroFunc func = countNonZeroTab[src.depth()];
CountNonZeroFunc func = getCountNonZeroTab(src.depth());
CV_Assert( src.channels() == 1 && func != 0 );
@ -626,7 +640,7 @@ cv::Scalar cv::mean( InputArray _src, InputArray _mask )
}
#endif
SumFunc func = sumTab[depth];
SumFunc func = getSumFunc(depth);
CV_Assert( cn <= 4 && func != 0 );
@ -685,7 +699,7 @@ void cv::meanStdDev( InputArray _src, OutputArray _mean, OutputArray _sdv, Input
CV_Assert( mask.empty() || mask.type() == CV_8U );
int k, cn = src.channels(), depth = src.depth();
SumSqrFunc func = sumSqrTab[depth];
SumSqrFunc func = getSumSqrTab(depth);
CV_Assert( func != 0 );
@ -859,6 +873,8 @@ static void minMaxIdx_64f(const double* src, const uchar* mask, double* minval,
typedef void (*MinMaxIdxFunc)(const uchar*, const uchar*, int*, int*, size_t*, size_t*, int, size_t);
static MinMaxIdxFunc getMinmaxTab(int depth)
{
static MinMaxIdxFunc minmaxTab[] =
{
(MinMaxIdxFunc)GET_OPTIMIZED(minMaxIdx_8u), (MinMaxIdxFunc)GET_OPTIMIZED(minMaxIdx_8s),
@ -868,6 +884,9 @@ static MinMaxIdxFunc minmaxTab[] =
0
};
return minmaxTab[depth];
}
static void ofs2idx(const Mat& a, size_t ofs, int* idx)
{
int i, d = a.dims;
@ -899,7 +918,7 @@ void cv::minMaxIdx(InputArray _src, double* minVal,
CV_Assert( (cn == 1 && (mask.empty() || mask.type() == CV_8U)) ||
(cn >= 1 && mask.empty() && !minIdx && !maxIdx) );
MinMaxIdxFunc func = minmaxTab[depth];
MinMaxIdxFunc func = getMinmaxTab(depth);
CV_Assert( func != 0 );
const Mat* arrays[] = {&src, &mask, 0};
@ -1362,6 +1381,8 @@ CV_DEF_NORM_ALL(64f, double, double, double, double)
typedef int (*NormFunc)(const uchar*, const uchar*, uchar*, int, int);
typedef int (*NormDiffFunc)(const uchar*, const uchar*, const uchar*, uchar*, int, int);
static NormFunc getNormFunc(int normType, int depth)
{
static NormFunc normTab[3][8] =
{
{
@ -1378,6 +1399,11 @@ static NormFunc normTab[3][8] =
}
};
return normTab[normType][depth];
}
static NormDiffFunc getNormDiffFunc(int normType, int depth)
{
static NormDiffFunc normDiffTab[3][8] =
{
{
@ -1400,6 +1426,9 @@ static NormDiffFunc normDiffTab[3][8] =
}
};
return normDiffTab[normType][depth];
}
}
double cv::norm( InputArray _src, int normType, InputArray _mask )
@ -1482,7 +1511,7 @@ double cv::norm( InputArray _src, int normType, InputArray _mask )
return result;
}
NormFunc func = normTab[normType >> 1][depth];
NormFunc func = getNormFunc(normType >> 1, depth);
CV_Assert( func != 0 );
const Mat* arrays[] = {&src, &mask, 0};
@ -1623,7 +1652,7 @@ double cv::norm( InputArray _src1, InputArray _src2, int normType, InputArray _m
return result;
}
NormDiffFunc func = normDiffTab[normType >> 1][depth];
NormDiffFunc func = getNormDiffFunc(normType >> 1, depth);
CV_Assert( func != 0 );
const Mat* arrays[] = {&src1, &src2, &mask, 0};