added ippisFlip to cv::sort

This commit is contained in:
Ilya Lavrenov 2014-04-15 14:58:11 +04:00
parent 26e8c6216f
commit 1f6b719776
2 changed files with 58 additions and 14 deletions

View File

@ -9,7 +9,7 @@ using std::tr1::make_tuple;
using std::tr1::get;
#define TYPICAL_MAT_SIZES_SORT TYPICAL_MAT_SIZES
#define TYPICAL_MAT_TYPES_SORT CV_8SC1, CV_16UC1, CV_32FC1
#define TYPICAL_MAT_TYPES_SORT CV_8UC1, CV_16UC1, CV_32FC1
#define SORT_TYPES SORT_EVERY_ROW | SORT_ASCENDING, SORT_EVERY_ROW | SORT_DESCENDING
#define TYPICAL_MATS_SORT testing::Combine( testing::Values(TYPICAL_MAT_SIZES_SORT), testing::Values(TYPICAL_MAT_TYPES_SORT), testing::Values(SORT_TYPES) )
@ -48,5 +48,5 @@ PERF_TEST_P(sortIdxFixture, sorIdx, TYPICAL_MATS_SORT)
TEST_CYCLE() cv::sortIdx(a, b, flags);
SANITY_CHECK(b);
SANITY_CHECK_NOTHING();
}

View File

@ -3468,8 +3468,10 @@ namespace cv
{
#if IPP_VERSION_X100 > 0 && !defined HAVE_IPP_ICV_ONLY
#define USE_IPP_SORT
typedef IppStatus (CV_STDCALL *IppSortFunc)(void *, int);
typedef IppSortFunc IppFlipFunc;
static IppSortFunc getSortFunc(int depth, bool sortDescending)
{
@ -3489,6 +3491,18 @@ static IppSortFunc getSortFunc(int depth, bool sortDescending)
depth == CV_64F ? (IppSortFunc)ippsSortDescend_64f_I : 0;
}
static IppFlipFunc getFlipFunc(int depth)
{
CV_SUPPRESS_DEPRECATED_START
return
depth == CV_8U || depth == CV_8S ? (IppFlipFunc)ippsFlip_8u_I :
depth == CV_16U || depth == CV_16S ? (IppFlipFunc)ippsFlip_16u_I :
depth == CV_32S || depth == CV_32F ? (IppFlipFunc)ippsFlip_32f_I :
depth == CV_64F ? (IppFlipFunc)ippsFlip_64f_I : 0;
CV_SUPPRESS_DEPRECATED_END
}
#endif
template<typename T> static void sort_( const Mat& src, Mat& dst, int flags )
@ -3509,8 +3523,10 @@ template<typename T> static void sort_( const Mat& src, Mat& dst, int flags )
}
bptr = (T*)buf;
#if IPP_VERSION_X100 > 0 && !defined HAVE_IPP_ICV_ONLY
IppSortFunc ippFunc = getSortFunc(src.depth(), sortDescending);
#ifdef USE_IPP_SORT
int depth = src.depth();
IppSortFunc ippSortFunc = getSortFunc(depth, sortDescending);
IppFlipFunc ippFlipFunc = getFlipFunc(depth);
#endif
for( i = 0; i < n; i++ )
@ -3532,14 +3548,27 @@ template<typename T> static void sort_( const Mat& src, Mat& dst, int flags )
ptr[j] = ((const T*)(src.data + src.step*j))[i];
}
#if IPP_VERSION_X100 > 0 && !defined HAVE_IPP_ICV_ONLY
if (!ippFunc || ippFunc(ptr, len) < 0)
#ifdef USE_IPP_SORT
if (!ippSortFunc || ippSortFunc(ptr, len) < 0)
#endif
{
#ifdef USE_IPP_SORT
setIppErrorStatus();
#endif
std::sort( ptr, ptr + len );
if( sortDescending )
for( j = 0; j < len/2; j++ )
std::swap(ptr[j], ptr[len-1-j]);
{
#ifdef USE_IPP_SORT
if (!ippFlipFunc || ippFlipFunc(ptr, len) < 0)
#endif
{
#ifdef USE_IPP_SORT
setIppErrorStatus();
#endif
for( j = 0; j < len/2; j++ )
std::swap(ptr[j], ptr[len-1-j]);
}
}
}
if( !sortRows )
@ -3556,7 +3585,7 @@ public:
const _Tp* arr;
};
#if IPP_VERSION_X100 > 0 && !defined HAVE_IPP_ICV_ONLY
#ifdef USE_IPP_SORT
typedef IppStatus (CV_STDCALL *IppSortIndexFunc)(void *, int *, int);
@ -3603,8 +3632,10 @@ template<typename T> static void sortIdx_( const Mat& src, Mat& dst, int flags )
bptr = (T*)buf;
_iptr = (int*)ibuf;
#if IPP_VERSION_X100 > 0 && !defined HAVE_IPP_ICV_ONLY
IppSortIndexFunc ippFunc = getSortIndexFunc(src.depth(), sortDescending);
#ifdef USE_IPP_SORT
int depth = src.depth();
IppSortIndexFunc ippFunc = getSortIndexFunc(depth, sortDescending);
IppFlipFunc ippFlipFunc = getFlipFunc(depth);
#endif
for( i = 0; i < n; i++ )
@ -3625,14 +3656,27 @@ template<typename T> static void sortIdx_( const Mat& src, Mat& dst, int flags )
for( j = 0; j < len; j++ )
iptr[j] = j;
#if IPP_VERSION_X100 > 0 && !defined HAVE_IPP_ICV_ONLY
#ifdef USE_IPP_SORT
if (sortRows || !ippFunc || ippFunc(ptr, iptr, len) < 0)
#endif
{
#ifdef USE_IPP_SORT
setIppErrorStatus();
#endif
std::sort( iptr, iptr + len, LessThanIdx<T>(ptr) );
if( sortDescending )
for( j = 0; j < len/2; j++ )
std::swap(iptr[j], iptr[len-1-j]);
{
#ifdef USE_IPP_SORT
if (!ippFlipFunc || ippFlipFunc(iptr, len) < 0)
#endif
{
#ifdef USE_IPP_SORT
setIppErrorStatus();
#endif
for( j = 0; j < len/2; j++ )
std::swap(iptr[j], iptr[len-1-j]);
}
}
}
if( !sortRows )