From 78662ac085e7190103d7ff131ccaf114274c9238 Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Wed, 9 Apr 2025 17:37:15 +0300 Subject: [PATCH] Transfer IPP polarToCart to HAL. --- 3rdparty/ipphal/CMakeLists.txt | 1 + 3rdparty/ipphal/include/ipp_hal_core.hpp | 8 +++ 3rdparty/ipphal/src/cart_polar_ipp.cpp | 28 ++++++++++ modules/core/src/mathfuncs.cpp | 69 ------------------------ 4 files changed, 37 insertions(+), 69 deletions(-) create mode 100644 3rdparty/ipphal/src/cart_polar_ipp.cpp diff --git a/3rdparty/ipphal/CMakeLists.txt b/3rdparty/ipphal/CMakeLists.txt index 5e69b0511e..376bf7d386 100644 --- a/3rdparty/ipphal/CMakeLists.txt +++ b/3rdparty/ipphal/CMakeLists.txt @@ -11,6 +11,7 @@ add_library(ipphal STATIC "${CMAKE_CURRENT_SOURCE_DIR}/src/mean_ipp.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/minmax_ipp.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/norm_ipp.cpp" + "${CMAKE_CURRENT_SOURCE_DIR}/src/cart_polar_ipp.cpp" ) if(HAVE_IPP_ICV) diff --git a/3rdparty/ipphal/include/ipp_hal_core.hpp b/3rdparty/ipphal/include/ipp_hal_core.hpp index 441a8bb207..ac2ac868f0 100644 --- a/3rdparty/ipphal/include/ipp_hal_core.hpp +++ b/3rdparty/ipphal/include/ipp_hal_core.hpp @@ -34,4 +34,12 @@ int ipp_hal_normDiff(const uchar* src1, size_t src1_step, const uchar* src2, siz #endif +int ipp_hal_polarToCart32f(const float* mag, const float* angle, float* x, float* y, int len, bool angleInDegrees); +int ipp_hal_polarToCart64f(const double* mag, const double* angle, double* x, double* y, int len, bool angleInDegrees); + +#undef cv_hal_polarToCart32f +#define cv_hal_polarToCart32f ipp_hal_polarToCart32f +#undef cv_hal_polarToCart64f +#define cv_hal_polarToCart64f ipp_hal_polarToCart64f + #endif diff --git a/3rdparty/ipphal/src/cart_polar_ipp.cpp b/3rdparty/ipphal/src/cart_polar_ipp.cpp new file mode 100644 index 0000000000..39f4d4a53a --- /dev/null +++ b/3rdparty/ipphal/src/cart_polar_ipp.cpp @@ -0,0 +1,28 @@ +#include "ipp_hal_core.hpp" + +#include +#include + +int ipp_hal_polarToCart32f(const float* mag, const float* angle, float* x, float* y, int len, bool angleInDegrees) +{ + const bool isInPlace = (x == mag) || (x == angle) || (y == mag) || (y == angle); + if (isInPlace || angleInDegrees) + return CV_HAL_ERROR_NOT_IMPLEMENTED; + + if (CV_INSTRUMENT_FUN_IPP(ippsPolarToCart_32f, mag, angle, x, y, len) < 0) + return CV_HAL_ERROR_NOT_IMPLEMENTED; + + return CV_HAL_ERROR_OK; +} + +int ipp_hal_polarToCart64f(const double* mag, const double* angle, double* x, double* y, int len, bool angleInDegrees) +{ + const bool isInPlace = (x == mag) || (x == angle) || (y == mag) || (y == angle); + if (isInPlace || angleInDegrees) + return CV_HAL_ERROR_NOT_IMPLEMENTED; + + if (CV_INSTRUMENT_FUN_IPP(ippsPolarToCart_64f, mag, angle, x, y, len) < 0) + return CV_HAL_ERROR_NOT_IMPLEMENTED; + + return CV_HAL_ERROR_OK; +} diff --git a/modules/core/src/mathfuncs.cpp b/modules/core/src/mathfuncs.cpp index 0403b75452..0604d2c33f 100644 --- a/modules/core/src/mathfuncs.cpp +++ b/modules/core/src/mathfuncs.cpp @@ -378,65 +378,6 @@ static bool ocl_polarToCart( InputArray _mag, InputArray _angle, #endif -#ifdef HAVE_IPP -static bool ipp_polarToCart(Mat &mag, Mat &angle, Mat &x, Mat &y) -{ - CV_INSTRUMENT_REGION_IPP(); - - int depth = angle.depth(); - if(depth != CV_32F && depth != CV_64F) - return false; - - if(angle.dims <= 2) - { - int len = (int)(angle.cols*angle.channels()); - - if(depth == CV_32F) - { - for (int h = 0; h < angle.rows; h++) - { - if(CV_INSTRUMENT_FUN_IPP(ippsPolarToCart_32f, (const float*)mag.ptr(h), (const float*)angle.ptr(h), (float*)x.ptr(h), (float*)y.ptr(h), len) < 0) - return false; - } - } - else - { - for (int h = 0; h < angle.rows; h++) - { - if(CV_INSTRUMENT_FUN_IPP(ippsPolarToCart_64f, (const double*)mag.ptr(h), (const double*)angle.ptr(h), (double*)x.ptr(h), (double*)y.ptr(h), len) < 0) - return false; - } - } - return true; - } - else - { - const Mat *arrays[] = {&mag, &angle, &x, &y, NULL}; - uchar *ptrs[4] = {NULL}; - NAryMatIterator it(arrays, ptrs); - int len = (int)(it.size*angle.channels()); - - if(depth == CV_32F) - { - for (size_t i = 0; i < it.nplanes; i++, ++it) - { - if(CV_INSTRUMENT_FUN_IPP(ippsPolarToCart_32f, (const float*)ptrs[0], (const float*)ptrs[1], (float*)ptrs[2], (float*)ptrs[3], len) < 0) - return false; - } - } - else - { - for (size_t i = 0; i < it.nplanes; i++, ++it) - { - if(CV_INSTRUMENT_FUN_IPP(ippsPolarToCart_64f, (const double*)ptrs[0], (const double*)ptrs[1], (double*)ptrs[2], (double*)ptrs[3], len) < 0) - return false; - } - } - return true; - } -} -#endif - void polarToCart( InputArray src1, InputArray src2, OutputArray dst1, OutputArray dst2, bool angleInDegrees ) { @@ -444,14 +385,6 @@ void polarToCart( InputArray src1, InputArray src2, CV_Assert(dst1.getObj() != dst2.getObj()); -#ifdef HAVE_IPP - const bool isInPlace = - (src1.getObj() == dst1.getObj()) || - (src1.getObj() == dst2.getObj()) || - (src2.getObj() == dst1.getObj()) || - (src2.getObj() == dst2.getObj()); -#endif - int type = src2.type(), depth = CV_MAT_DEPTH(type), cn = CV_MAT_CN(type); CV_Assert((depth == CV_32F || depth == CV_64F) && (src1.empty() || src1.type() == type)); @@ -464,8 +397,6 @@ void polarToCart( InputArray src1, InputArray src2, dst2.create( Angle.dims, Angle.size, type ); Mat X = dst1.getMat(), Y = dst2.getMat(); - CV_IPP_RUN(!angleInDegrees && !isInPlace, ipp_polarToCart(Mag, Angle, X, Y)); - const Mat* arrays[] = {&Mag, &Angle, &X, &Y, 0}; uchar* ptrs[4] = {}; NAryMatIterator it(arrays, ptrs);