From 747ffc57be7d8b548836c8dfe49f569689d31251 Mon Sep 17 00:00:00 2001 From: Vincent Rabaud Date: Wed, 23 Sep 2026 09:44:20 +0200 Subject: [PATCH] Merge pull request #30040 from vrabaud:function_ptr Fix function pointer signature mismatches - #30040 Contrib PR: https://github.com/opencv/opencv_contrib/pull/4224 Calling a function through a function pointer with a mismatched signature is undefined behavior in C/C++ and causes Clang Control Flow Integrity to trap with `SIGILL` (`ud1`) at indirect call sites. This is a follow-up on https://github.com/opencv/opencv/pull/28939 ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work - [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [ ] The feature is well documented and sample code can be built with the project CMake --- cmake/OpenCVCompilerOptions.cmake | 6 + modules/core/src/arithm.cpp | 108 ++--------- modules/core/src/batch_distance.cpp | 121 +++++-------- modules/core/src/dxt.cpp | 161 +++++++++-------- modules/core/src/has_non_zero.simd.hpp | 31 ++-- modules/core/src/lut.cpp | 69 +++---- modules/core/src/mathfuncs.cpp | 50 +----- modules/core/src/matmul.dispatch.cpp | 38 ++-- modules/core/src/matmul.simd.hpp | 114 +++++++----- modules/core/src/matrix_operations.cpp | 56 +++--- modules/core/src/mean.simd.hpp | 17 +- modules/core/src/merge.dispatch.cpp | 24 ++- modules/core/src/minmax.dispatch.cpp | 2 +- modules/core/src/minmax.simd.hpp | 35 ++-- modules/core/src/norm.simd.hpp | 168 ++++++++++-------- modules/core/src/precomp.hpp | 6 +- modules/core/src/rand.cpp | 99 +++++------ modules/core/src/split.dispatch.cpp | 24 ++- modules/core/src/sum.simd.hpp | 30 ++-- modules/geometry/src/moments.cpp | 12 +- modules/highgui/src/window_gtk.cpp | 8 + .../imgcodecs/src/grfmt_jpeg2000_openjpeg.cpp | 21 ++- modules/imgcodecs/src/grfmt_png.cpp | 12 +- modules/imgcodecs/src/grfmt_png.hpp | 6 +- modules/imgproc/src/accum.cpp | 142 ++++++++++----- modules/imgproc/src/histogram.cpp | 13 +- modules/imgproc/src/warp_kernels.simd.hpp | 46 ++--- modules/python/src2/cv2.cpp | 8 + 28 files changed, 744 insertions(+), 683 deletions(-) diff --git a/cmake/OpenCVCompilerOptions.cmake b/cmake/OpenCVCompilerOptions.cmake index a89dbc4c4c..2a73fdb3b2 100644 --- a/cmake/OpenCVCompilerOptions.cmake +++ b/cmake/OpenCVCompilerOptions.cmake @@ -517,6 +517,12 @@ macro(ocv_add_modules_compiler_options) if(OPENCV_ENABLE_MEMORY_SANITIZER) add_definitions(-DOPENCV_ENABLE_MEMORY_SANITIZER=1) endif() + if(CV_GCC OR CV_CLANG OR CV_ICX) + ocv_check_flag_support(CXX "-Wcast-function-type-strict" _varname_cxx "") + if(${_varname_cxx}) + add_compile_options(-Wcast-function-type-strict) + endif() + endif() endmacro() # adjust -Wl,-rpath-link diff --git a/modules/core/src/arithm.cpp b/modules/core/src/arithm.cpp index 90e687d2a9..a32c4094f9 100644 --- a/modules/core/src/arithm.cpp +++ b/modules/core/src/arithm.cpp @@ -1459,10 +1459,13 @@ struct InRange_SIMD #endif template -static void inRange_(const T* src1, size_t step1, const T* src2, size_t step2, - const T* src3, size_t step3, uchar* dst, size_t step, +static void inRange_(const void* _src1, size_t step1, const void* _src2, size_t step2, + const void* _src3, size_t step3, uchar* dst, size_t step, Size size) { + const T* src1 = (const T*)_src1; + const T* src2 = (const T*)_src2; + const T* src3 = (const T*)_src3; step1 /= sizeof(src1[0]); step2 /= sizeof(src2[0]); step3 /= sizeof(src3[0]); @@ -1489,79 +1492,6 @@ static void inRange_(const T* src1, size_t step1, const T* src2, size_t step2, } } - -static void inRange8u(const uchar* src1, size_t step1, const uchar* src2, size_t step2, - const uchar* src3, size_t step3, uchar* dst, size_t step, Size size) -{ - inRange_(src1, step1, src2, step2, src3, step3, dst, step, size); -} - -static void inRange8s(const schar* src1, size_t step1, const schar* src2, size_t step2, - const schar* src3, size_t step3, uchar* dst, size_t step, Size size) -{ - inRange_(src1, step1, src2, step2, src3, step3, dst, step, size); -} - -static void inRange16u(const ushort* src1, size_t step1, const ushort* src2, size_t step2, - const ushort* src3, size_t step3, uchar* dst, size_t step, Size size) -{ - inRange_(src1, step1, src2, step2, src3, step3, dst, step, size); -} - -static void inRange16s(const short* src1, size_t step1, const short* src2, size_t step2, - const short* src3, size_t step3, uchar* dst, size_t step, Size size) -{ - inRange_(src1, step1, src2, step2, src3, step3, dst, step, size); -} - -static void inRange32u(const unsigned* src1, size_t step1, const unsigned* src2, size_t step2, - const unsigned* src3, size_t step3, uchar* dst, size_t step, Size size) -{ - inRange_(src1, step1, src2, step2, src3, step3, dst, step, size); -} - -static void inRange32s(const int* src1, size_t step1, const int* src2, size_t step2, - const int* src3, size_t step3, uchar* dst, size_t step, Size size) -{ - inRange_(src1, step1, src2, step2, src3, step3, dst, step, size); -} - -static void inRange64u(const uint64* src1, size_t step1, const uint64* src2, size_t step2, - const uint64* src3, size_t step3, uchar* dst, size_t step, Size size) -{ - inRange_(src1, step1, src2, step2, src3, step3, dst, step, size); -} - -static void inRange64s(const int64* src1, size_t step1, const int64* src2, size_t step2, - const int64* src3, size_t step3, uchar* dst, size_t step, Size size) -{ - inRange_(src1, step1, src2, step2, src3, step3, dst, step, size); -} - -static void inRange32f(const float* src1, size_t step1, const float* src2, size_t step2, - const float* src3, size_t step3, uchar* dst, size_t step, Size size) -{ - inRange_(src1, step1, src2, step2, src3, step3, dst, step, size); -} - -static void inRange64f(const double* src1, size_t step1, const double* src2, size_t step2, - const double* src3, size_t step3, uchar* dst, size_t step, Size size) -{ - inRange_(src1, step1, src2, step2, src3, step3, dst, step, size); -} - -static void inRange16f(const hfloat* src1, size_t step1, const hfloat* src2, size_t step2, - const hfloat* src3, size_t step3, uchar* dst, size_t step, Size size) -{ - inRange_(src1, step1, src2, step2, src3, step3, dst, step, size); -} - -static void inRange16bf(const bfloat* src1, size_t step1, const bfloat* src2, size_t step2, - const bfloat* src3, size_t step3, uchar* dst, size_t step, Size size) -{ - inRange_(src1, step1, src2, step2, src3, step3, dst, step, size); -} - static void inRangeReduce(const uchar* src, uchar* dst, size_t len, int cn) { int k = cn % 4 ? cn % 4 : 4; @@ -1586,26 +1516,26 @@ 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 ); +typedef void (*InRangeFunc)( const void* src1, size_t step1, const void* src2, size_t step2, + const void* src3, size_t step3, uchar* dst, size_t step, Size sz ); static InRangeFunc getInRangeFunc(int depth) { static InRangeFunc inRangeTab[CV_DEPTH_MAX] = { - (InRangeFunc)GET_OPTIMIZED(inRange8u), - (InRangeFunc)GET_OPTIMIZED(inRange8s), - (InRangeFunc)GET_OPTIMIZED(inRange16u), - (InRangeFunc)GET_OPTIMIZED(inRange16s), - (InRangeFunc)GET_OPTIMIZED(inRange32s), - (InRangeFunc)GET_OPTIMIZED(inRange32f), - (InRangeFunc)GET_OPTIMIZED(inRange64f), - (InRangeFunc)inRange16f, - (InRangeFunc)inRange16bf, + inRange_, + inRange_, + inRange_, + inRange_, + inRange_, + inRange_, + inRange_, + inRange_, + inRange_, 0, - (InRangeFunc)GET_OPTIMIZED(inRange64u), - (InRangeFunc)GET_OPTIMIZED(inRange64s), - (InRangeFunc)GET_OPTIMIZED(inRange32u), + inRange_, + inRange_, + inRange_, 0, }; diff --git a/modules/core/src/batch_distance.cpp b/modules/core/src/batch_distance.cpp index 4210c672b9..7b9e5b3e70 100644 --- a/modules/core/src/batch_distance.cpp +++ b/modules/core/src/batch_distance.cpp @@ -11,9 +11,12 @@ namespace cv { template -void batchDistL1_(const _Tp* src1, const _Tp* src2, size_t step2, - int nvecs, int len, _Rt* dist, const uchar* mask) +static void batchDistL1_(const void* _src1, const void* _src2, size_t step2, + int nvecs, int len, void* _dist, const uchar* mask) { + const _Tp* src1 = (const _Tp*)_src1; + const _Tp* src2 = (const _Tp*)_src2; + _Rt* dist = (_Rt*)_dist; step2 /= sizeof(src2[0]); if( !mask ) { @@ -29,9 +32,12 @@ void batchDistL1_(const _Tp* src1, const _Tp* src2, size_t step2, } template -void batchDistL2Sqr_(const _Tp* src1, const _Tp* src2, size_t step2, - int nvecs, int len, _Rt* dist, const uchar* mask) +static void batchDistL2Sqr_(const void* _src1, const void* _src2, size_t step2, + int nvecs, int len, void* _dist, const uchar* mask) { + const _Tp* src1 = (const _Tp*)_src1; + const _Tp* src2 = (const _Tp*)_src2; + _Rt* dist = (_Rt*)_dist; step2 /= sizeof(src2[0]); if( !mask ) { @@ -47,9 +53,12 @@ void batchDistL2Sqr_(const _Tp* src1, const _Tp* src2, size_t step2, } template<> -void batchDistL2Sqr_(const float* src1, const float* src2, size_t step2, - int nvecs, int len, float* dist, const uchar* mask) +void batchDistL2Sqr_(const void* _src1, const void* _src2, size_t step2, + int nvecs, int len, void* _dist, const uchar* mask) { + const float* src1 = (const float*)_src1; + const float* src2 = (const float*)_src2; + float* dist = (float*)_dist; step2 /= sizeof(src2[0]); if( !mask ) { @@ -65,9 +74,12 @@ void batchDistL2Sqr_(const float* src1, const float* src2, size_t step2, } template -void batchDistL2_(const _Tp* src1, const _Tp* src2, size_t step2, - int nvecs, int len, _Rt* dist, const uchar* mask) +static void batchDistL2_(const void* _src1, const void* _src2, size_t step2, + int nvecs, int len, void* _dist, const uchar* mask) { + const _Tp* src1 = (const _Tp*)_src1; + const _Tp* src2 = (const _Tp*)_src2; + _Rt* dist = (_Rt*)_dist; step2 /= sizeof(src2[0]); if( !mask ) { @@ -83,9 +95,12 @@ void batchDistL2_(const _Tp* src1, const _Tp* src2, size_t step2, } template<> -void batchDistL2_(const float* src1, const float* src2, size_t step2, - int nvecs, int len, float* dist, const uchar* mask) +void batchDistL2_(const void* _src1, const void* _src2, size_t step2, + int nvecs, int len, void* _dist, const uchar* mask) { + const float* src1 = (const float*)_src1; + const float* src2 = (const float*)_src2; + float* dist = (float*)_dist; step2 /= sizeof(src2[0]); if( !mask ) { @@ -100,9 +115,12 @@ void batchDistL2_(const float* src1, const float* src2, size_t step2, } } -static void batchDistHamming(const uchar* src1, const uchar* src2, size_t step2, - int nvecs, int len, int* dist, const uchar* mask) +static void batchDistHamming(const void* _src1, const void* _src2, size_t step2, + int nvecs, int len, void* _dist, const uchar* mask) { + const uchar* src1 = (const uchar*)_src1; + const uchar* src2 = (const uchar*)_src2; + int* dist = (int*)_dist; step2 /= sizeof(src2[0]); if( !mask ) { @@ -122,9 +140,12 @@ static void batchDistHamming(const uchar* src1, const uchar* src2, size_t step2, } } -static void batchDistHamming2(const uchar* src1, const uchar* src2, size_t step2, - int nvecs, int len, int* dist, const uchar* mask) +static void batchDistHamming2(const void* _src1, const void* _src2, size_t step2, + int nvecs, int len, void* _dist, const uchar* mask) { + const uchar* src1 = (const uchar*)_src1; + const uchar* src2 = (const uchar*)_src2; + int* dist = (int*)_dist; step2 /= sizeof(src2[0]); if( !mask ) { @@ -144,56 +165,8 @@ static void batchDistHamming2(const uchar* src1, const uchar* src2, size_t step2 } } -static void batchDistL1_8u32s(const uchar* src1, const uchar* src2, size_t step2, - int nvecs, int len, int* dist, const uchar* mask) -{ - batchDistL1_(src1, src2, step2, nvecs, len, dist, mask); -} - -static void batchDistL1_8u32f(const uchar* src1, const uchar* src2, size_t step2, - int nvecs, int len, float* dist, const uchar* mask) -{ - batchDistL1_(src1, src2, step2, nvecs, len, dist, mask); -} - -static void batchDistL2Sqr_8u32s(const uchar* src1, const uchar* src2, size_t step2, - int nvecs, int len, int* dist, const uchar* mask) -{ - batchDistL2Sqr_(src1, src2, step2, nvecs, len, dist, mask); -} - -static void batchDistL2Sqr_8u32f(const uchar* src1, const uchar* src2, size_t step2, - int nvecs, int len, float* dist, const uchar* mask) -{ - batchDistL2Sqr_(src1, src2, step2, nvecs, len, dist, mask); -} - -static void batchDistL2_8u32f(const uchar* src1, const uchar* src2, size_t step2, - int nvecs, int len, float* dist, const uchar* mask) -{ - batchDistL2_(src1, src2, step2, nvecs, len, dist, mask); -} - -static void batchDistL1_32f(const float* src1, const float* src2, size_t step2, - int nvecs, int len, float* dist, const uchar* mask) -{ - batchDistL1_(src1, src2, step2, nvecs, len, dist, mask); -} - -static void batchDistL2Sqr_32f(const float* src1, const float* src2, size_t step2, - int nvecs, int len, float* dist, const uchar* mask) -{ - batchDistL2Sqr_(src1, src2, step2, nvecs, len, dist, mask); -} - -static void batchDistL2_32f(const float* src1, const float* src2, size_t step2, - int nvecs, int len, float* dist, const uchar* mask) -{ - batchDistL2_(src1, src2, step2, nvecs, len, dist, mask); -} - -typedef void (*BatchDistFunc)(const uchar* src1, const uchar* src2, size_t step2, - int nvecs, int len, uchar* dist, const uchar* mask); +typedef void (*BatchDistFunc)(const void* src1, const void* src2, size_t step2, + int nvecs, int len, void* dist, const uchar* mask); struct BatchDistInvoker : public ParallelLoopBody @@ -352,28 +325,28 @@ void cv::batchDistance( InputArray _src1, InputArray _src2, if( type == CV_8U ) { if( normType == NORM_L1 && dtype == CV_32S ) - func = (BatchDistFunc)batchDistL1_8u32s; + func = batchDistL1_; else if( normType == NORM_L1 && dtype == CV_32F ) - func = (BatchDistFunc)batchDistL1_8u32f; + func = batchDistL1_; else if( normType == NORM_L2SQR && dtype == CV_32S ) - func = (BatchDistFunc)batchDistL2Sqr_8u32s; + func = batchDistL2Sqr_; else if( normType == NORM_L2SQR && dtype == CV_32F ) - func = (BatchDistFunc)batchDistL2Sqr_8u32f; + func = batchDistL2Sqr_; else if( normType == NORM_L2 && dtype == CV_32F ) - func = (BatchDistFunc)batchDistL2_8u32f; + func = batchDistL2_; else if( normType == NORM_HAMMING && dtype == CV_32S ) - func = (BatchDistFunc)batchDistHamming; + func = batchDistHamming; else if( normType == NORM_HAMMING2 && dtype == CV_32S ) - func = (BatchDistFunc)batchDistHamming2; + func = batchDistHamming2; } else if( type == CV_32F && dtype == CV_32F ) { if( normType == NORM_L1 ) - func = (BatchDistFunc)batchDistL1_32f; + func = batchDistL1_; else if( normType == NORM_L2SQR ) - func = (BatchDistFunc)batchDistL2Sqr_32f; + func = batchDistL2Sqr_; else if( normType == NORM_L2 ) - func = (BatchDistFunc)batchDistL2_32f; + func = batchDistL2_; } if( func == 0 ) diff --git a/modules/core/src/dxt.cpp b/modules/core/src/dxt.cpp index 9d95f5d901..5fff474e4d 100644 --- a/modules/core/src/dxt.cpp +++ b/modules/core/src/dxt.cpp @@ -1691,35 +1691,10 @@ ExpandCCS( uchar* _ptr, int n, int elem_size ) } } -static void DFT_32f(const OcvDftOptions & c, const Complexf* src, Complexf* dst) +template +static void dftWrap(const OcvDftOptions & c, const void* src, void* dst) { - DFT(c, src, dst); -} - -static void DFT_64f(const OcvDftOptions & c, const Complexd* src, Complexd* dst) -{ - DFT(c, src, dst); -} - - -static void RealDFT_32f(const OcvDftOptions & c, const float* src, float* dst) -{ - RealDFT(c, src, dst); -} - -static void RealDFT_64f(const OcvDftOptions & c, const double* src, double* dst) -{ - RealDFT(c, src, dst); -} - -static void CCSIDFT_32f(const OcvDftOptions & c, const float* src, float* dst) -{ - CCSIDFT(c, src, dst); -} - -static void CCSIDFT_64f(const OcvDftOptions & c, const double* src, double* dst) -{ - CCSIDFT(c, src, dst); + fn(c, (const T*)src, (T*)dst); } } @@ -1727,6 +1702,12 @@ static void CCSIDFT_64f(const OcvDftOptions & c, const double* src, double* dst) #ifdef USE_IPP_DFT typedef IppStatus (CV_STDCALL* IppDFTGetSizeFunc)(int, int, IppHintAlgorithm, int*, int*, int*); typedef IppStatus (CV_STDCALL* IppDFTInitFunc)(int, int, IppHintAlgorithm, void*, uchar*); + +template +static IppStatus CV_STDCALL ippDFTInitWrap(int n, int flags, IppHintAlgorithm hint, void* spec, Ipp8u* initbuf) +{ + return init_fn(n, flags, hint, (SpecType*)spec, initbuf); +} #endif namespace cv @@ -3278,12 +3259,12 @@ public: if( depth == CV_32F ) { getSizeFunc = ippsDFTGetSize_R_32f; - initFunc = (IppDFTInitFunc)ippsDFTInit_R_32f; + initFunc = ippDFTInitWrap; } else { getSizeFunc = ippsDFTGetSize_R_64f; - initFunc = (IppDFTInitFunc)ippsDFTInit_R_64f; + initFunc = ippDFTInitWrap; } } else @@ -3291,12 +3272,12 @@ public: if( depth == CV_32F ) { getSizeFunc = ippsDFTGetSize_C_32fc; - initFunc = (IppDFTInitFunc)ippsDFTInit_C_32fc; + initFunc = ippDFTInitWrap; } else { getSizeFunc = ippsDFTGetSize_C_64fc; - initFunc = (IppDFTInitFunc)ippsDFTInit_C_64fc; + initFunc = ippDFTInitWrap; } } if( getSizeFunc(opt.n, ipp_norm_flag, ippAlgHintNone, &specsize, &initsize, &worksize) >= 0 ) @@ -3351,12 +3332,12 @@ public: { static DFTFunc dft_tbl[6] = { - (DFTFunc)DFT_32f, - (DFTFunc)RealDFT_32f, - (DFTFunc)CCSIDFT_32f, - (DFTFunc)DFT_64f, - (DFTFunc)RealDFT_64f, - (DFTFunc)CCSIDFT_64f + dftWrap>, + dftWrap>, + dftWrap>, + dftWrap>, + dftWrap>, + dftWrap> }; int idx = 0; if (stage == 0) @@ -4145,28 +4126,11 @@ DCTInit( int n, int elem_size, void* _wave, int inv ) typedef void (*DCTFunc)(const OcvDftOptions & c, const void* src, size_t src_step, void* dft_src, void* dft_dst, void* dst, size_t dst_step, const void* dct_wave); -static void DCT_32f(const OcvDftOptions & c, const float* src, size_t src_step, float* dft_src, float* dft_dst, - float* dst, size_t dst_step, const Complexf* dct_wave) +template*)> +static void dctWrap(const OcvDftOptions & c, const void* src, size_t src_step, void* dft_src, void* dft_dst, + void* dst, size_t dst_step, const void* dct_wave) { - DCT(c, src, src_step, dft_src, dft_dst, dst, dst_step, dct_wave); -} - -static void IDCT_32f(const OcvDftOptions & c, const float* src, size_t src_step, float* dft_src, float* dft_dst, - float* dst, size_t dst_step, const Complexf* dct_wave) -{ - IDCT(c, src, src_step, dft_src, dft_dst, dst, dst_step, dct_wave); -} - -static void DCT_64f(const OcvDftOptions & c, const double* src, size_t src_step, double* dft_src, double* dft_dst, - double* dst, size_t dst_step, const Complexd* dct_wave) -{ - DCT(c, src, src_step, dft_src, dft_dst, dst, dst_step, dct_wave); -} - -static void IDCT_64f(const OcvDftOptions & c, const double* src, size_t src_step, double* dft_src, double* dft_dst, - double* dst, size_t dst_step, const Complexd* dct_wave) -{ - IDCT(c, src, src_step, dft_src, dft_dst, dst, dst_step, dct_wave); + fn(c, (const T*)src, src_step, (T*)dft_src, (T*)dft_dst, (T*)dst, dst_step, (const Complex*)dct_wave); } } @@ -4179,11 +4143,54 @@ namespace cv typedef IppStatus (CV_STDCALL * ippiDCTFunc)(const Ipp32f* pSrc, int srcStep, Ipp32f* pDst, int dstStep, const void* pDCTSpec, Ipp8u* pBuffer); typedef IppStatus (CV_STDCALL * ippiDCTInit)(void* pDCTSpec, IppiSize roiSize, Ipp8u* pMemInit ); typedef IppStatus (CV_STDCALL * ippiDCTGetSize)(IppiSize roiSize, int* pSizeSpec, int* pSizeInit, int* pSizeBuf); + +template +static IppStatus CV_STDCALL ippiDCTWrap(const Ipp32f* pSrc, int srcStep, Ipp32f* pDst, int dstStep, const void* pDCTSpec, Ipp8u* pBuffer) +{ + return fn(pSrc, srcStep, pDst, dstStep, (const SpecType*)pDCTSpec, pBuffer); +} + +template +static IppStatus CV_STDCALL ippiDCTInitWrap(void* pDCTSpec, IppiSize roiSize, Ipp8u* pMemInit) +{ + return fn((SpecType*)pDCTSpec, roiSize, pMemInit); +} + +template +static IppStatus CV_STDCALL ippiDCTGetSizeWrap(IppiSize roiSize, int* pSizeSpec, int* pSizeInit, int* pSizeBuf) +{ + return fn(roiSize, pSizeSpec, pSizeInit, pSizeBuf); +} + #elif IPP_VERSION_X100 >= 700 typedef IppStatus (CV_STDCALL * ippiDCTFunc)(const Ipp32f*, int, Ipp32f*, int, const void*, Ipp8u*); typedef IppStatus (CV_STDCALL * ippiDCTInitAlloc)(void**, IppiSize, IppHintAlgorithm); typedef IppStatus (CV_STDCALL * ippiDCTFree)(void* pDCTSpec); typedef IppStatus (CV_STDCALL * ippiDCTGetBufSize)(const void*, int*); + +template +static IppStatus CV_STDCALL ippiDCTWrap(const Ipp32f* pSrc, int srcStep, Ipp32f* pDst, int dstStep, const void* pDCTSpec, Ipp8u* pBuffer) +{ + return fn(pSrc, srcStep, pDst, dstStep, (const SpecType*)pDCTSpec, pBuffer); +} + +template +static IppStatus CV_STDCALL ippiDCTInitAllocWrap(void** pDCTSpec, IppiSize roiSize, IppHintAlgorithm hint) +{ + return fn((SpecType**)pDCTSpec, roiSize, hint); +} + +template +static IppStatus CV_STDCALL ippiDCTFreeWrap(void* pDCTSpec) +{ + return fn((SpecType*)pDCTSpec); +} + +template +static IppStatus CV_STDCALL ippiDCTGetBufSizeWrap(const void* pDCTSpec, int* pSize) +{ + return fn((const SpecType*)pDCTSpec, pSize); +} #endif class DctIPPLoop_Invoker : public ParallelLoopBody @@ -4220,9 +4227,9 @@ public: ippFree(pInitBuf); \ return; - ippiDCTFunc ippiDCT_32f_C1R = inv ? (ippiDCTFunc)ippiDCTInv_32f_C1R : (ippiDCTFunc)ippiDCTFwd_32f_C1R; - ippiDCTInit ippDctInit = inv ? (ippiDCTInit)ippiDCTInvInit_32f : (ippiDCTInit)ippiDCTFwdInit_32f; - ippiDCTGetSize ippDctGetSize = inv ? (ippiDCTGetSize)ippiDCTInvGetSize_32f : (ippiDCTGetSize)ippiDCTFwdGetSize_32f; + ippiDCTFunc ippiDCT_32f_C1R = inv ? ippiDCTWrap : ippiDCTWrap; + ippiDCTInit ippDctInit = inv ? ippiDCTInitWrap : ippiDCTInitWrap; + ippiDCTGetSize ippDctGetSize = inv ? ippiDCTGetSizeWrap : ippiDCTGetSizeWrap; if(ippDctGetSize(srcRoiSize, &specSize, &initSize, &bufferSize) < 0) { @@ -4276,10 +4283,10 @@ public: CV_SUPPRESS_DEPRECATED_START - ippiDCTFunc ippDctFun = inv ? (ippiDCTFunc)ippiDCTInv_32f_C1R : (ippiDCTFunc)ippiDCTFwd_32f_C1R; - ippiDCTInitAlloc ippInitAlloc = inv ? (ippiDCTInitAlloc)ippiDCTInvInitAlloc_32f : (ippiDCTInitAlloc)ippiDCTFwdInitAlloc_32f; - ippiDCTFree ippFree = inv ? (ippiDCTFree)ippiDCTInvFree_32f : (ippiDCTFree)ippiDCTFwdFree_32f; - ippiDCTGetBufSize ippGetBufSize = inv ? (ippiDCTGetBufSize)ippiDCTInvGetBufSize_32f : (ippiDCTGetBufSize)ippiDCTFwdGetBufSize_32f; + ippiDCTFunc ippDctFun = inv ? ippiDCTWrap : ippiDCTWrap; + ippiDCTInitAlloc ippInitAlloc = inv ? ippiDCTInitAllocWrap : ippiDCTInitAllocWrap; + ippiDCTFree ippFree = inv ? ippiDCTFreeWrap : ippiDCTFreeWrap; + ippiDCTGetBufSize ippGetBufSize = inv ? ippiDCTGetBufSizeWrap : ippiDCTGetBufSizeWrap; if (ippInitAlloc(&pDCTSpec, srcRoiSize, ippAlgHintNone)>=0 && ippGetBufSize(pDCTSpec, &bufSize)>=0) { @@ -4352,9 +4359,9 @@ static bool ippi_DCT_32f(const uchar * src, size_t src_step, uchar * dst, size_t if(pInitBuf) \ ippFree(pInitBuf); \ - ippiDCTFunc ippiDCT_32f_C1R = inv ? (ippiDCTFunc)ippiDCTInv_32f_C1R : (ippiDCTFunc)ippiDCTFwd_32f_C1R; - ippiDCTInit ippDctInit = inv ? (ippiDCTInit)ippiDCTInvInit_32f : (ippiDCTInit)ippiDCTFwdInit_32f; - ippiDCTGetSize ippDctGetSize = inv ? (ippiDCTGetSize)ippiDCTInvGetSize_32f : (ippiDCTGetSize)ippiDCTFwdGetSize_32f; + ippiDCTFunc ippiDCT_32f_C1R = inv ? ippiDCTWrap : ippiDCTWrap; + ippiDCTInit ippDctInit = inv ? ippiDCTInitWrap : ippiDCTInitWrap; + ippiDCTGetSize ippDctGetSize = inv ? ippiDCTGetSizeWrap : ippiDCTGetSizeWrap; if(ippDctGetSize(srcRoiSize, &specSize, &initSize, &bufferSize) < 0) return false; @@ -4402,10 +4409,10 @@ static bool ippi_DCT_32f(const uchar * src, size_t src_step, uchar * dst, size_t CV_SUPPRESS_DEPRECATED_START - ippiDCTFunc ippDctFun = inv ? (ippiDCTFunc)ippiDCTInv_32f_C1R : (ippiDCTFunc)ippiDCTFwd_32f_C1R; - ippiDCTInitAlloc ippInitAlloc = inv ? (ippiDCTInitAlloc)ippiDCTInvInitAlloc_32f : (ippiDCTInitAlloc)ippiDCTFwdInitAlloc_32f; - ippiDCTFree ippFree = inv ? (ippiDCTFree)ippiDCTInvFree_32f : (ippiDCTFree)ippiDCTFwdFree_32f; - ippiDCTGetBufSize ippGetBufSize = inv ? (ippiDCTGetBufSize)ippiDCTInvGetBufSize_32f : (ippiDCTGetBufSize)ippiDCTFwdGetBufSize_32f; + ippiDCTFunc ippDctFun = inv ? ippiDCTWrap : ippiDCTWrap; + ippiDCTInitAlloc ippInitAlloc = inv ? ippiDCTInitAllocWrap : ippiDCTInitAllocWrap; + ippiDCTFree ippFree = inv ? ippiDCTFreeWrap : ippiDCTFreeWrap; + ippiDCTGetBufSize ippGetBufSize = inv ? ippiDCTGetBufSizeWrap : ippiDCTGetBufSizeWrap; status = ippStsErr; @@ -4463,10 +4470,10 @@ public: isContinuous = (flags & CV_HAL_DFT_IS_CONTINUOUS) != 0; static DCTFunc dct_tbl[4] = { - (DCTFunc)DCT_32f, - (DCTFunc)IDCT_32f, - (DCTFunc)DCT_64f, - (DCTFunc)IDCT_64f + dctWrap>, + dctWrap>, + dctWrap>, + dctWrap> }; dct_func = dct_tbl[(int)isInverse + (depth == CV_64F)*2]; opt.nf = 0; diff --git a/modules/core/src/has_non_zero.simd.hpp b/modules/core/src/has_non_zero.simd.hpp index a08c1816dd..13b582fa97 100644 --- a/modules/core/src/has_non_zero.simd.hpp +++ b/modules/core/src/has_non_zero.simd.hpp @@ -6,7 +6,7 @@ namespace cv { -typedef bool (*HasNonZeroFunc)(const uchar*, size_t); +typedef bool (*HasNonZeroFunc)(const void*, size_t); CV_CPU_OPTIMIZATION_NAMESPACE_BEGIN @@ -23,8 +23,9 @@ HasNonZeroFunc getHasNonZeroFunc(int depth); #undef DEFINE_HASNONZERO_FUNC #define DEFINE_HASNONZERO_FUNC(funcname, suffix, T, VT, cmp_op, scalar_nz_op) \ -static bool funcname( const T* src, size_t len ) \ +static bool funcname( const void* _src, size_t len ) \ { \ + const T* src = (const T*)_src; \ size_t i = 0; \ SIMD_ONLY( \ const int vlanes = VTraits::vlanes(); \ @@ -96,19 +97,19 @@ HasNonZeroFunc getHasNonZeroFunc(int depth) { static HasNonZeroFunc hasNonZeroTab[CV_DEPTH_MAX] = { - (HasNonZeroFunc)GET_OPTIMIZED(hasNonZero8u), - (HasNonZeroFunc)GET_OPTIMIZED(hasNonZero8u), - (HasNonZeroFunc)GET_OPTIMIZED(hasNonZero16u), - (HasNonZeroFunc)GET_OPTIMIZED(hasNonZero16u), - (HasNonZeroFunc)GET_OPTIMIZED(hasNonZero32s), - (HasNonZeroFunc)GET_OPTIMIZED(hasNonZero32f), - (HasNonZeroFunc)GET_OPTIMIZED(hasNonZero64f), - (HasNonZeroFunc)GET_OPTIMIZED(hasNonZero16f), - (HasNonZeroFunc)GET_OPTIMIZED(hasNonZero16f), - (HasNonZeroFunc)GET_OPTIMIZED(hasNonZero8u), - (HasNonZeroFunc)GET_OPTIMIZED(hasNonZero64s), - (HasNonZeroFunc)GET_OPTIMIZED(hasNonZero64s), - (HasNonZeroFunc)GET_OPTIMIZED(hasNonZero32s), + hasNonZero8u, + hasNonZero8u, + hasNonZero16u, + hasNonZero16u, + hasNonZero32s, + hasNonZero32f, + hasNonZero64f, + hasNonZero16f, + hasNonZero16f, + hasNonZero8u, + hasNonZero64s, + hasNonZero64s, + hasNonZero32s, 0 }; diff --git a/modules/core/src/lut.cpp b/modules/core/src/lut.cpp index 80a8d20b01..a5f5df3f54 100644 --- a/modules/core/src/lut.cpp +++ b/modules/core/src/lut.cpp @@ -22,8 +22,11 @@ namespace cv { template static void -LUT_( const Ti* src, const T* lut, T* dst, const int len, const int cn, const int lutcn ) +LUT_( const void* _src, const void* _lut, void* _dst, int len, int cn, int lutcn ) { + const Ti* src = (const Ti*)_src; + const T* lut = (const T*)_lut; + T* dst = (T*)_dst; if( lutcn == 1 ) { for( int i = 0; i < len*cn; i++ ) @@ -37,7 +40,13 @@ LUT_( const Ti* src, const T* lut, T* dst, const int len, const int cn, const in } } -typedef void (*LUTFunc)( const uchar* src, const uchar* lut, uchar* dst, int len, int cn, int lutcn ); +template +static void lutDispatchWrap( const void* src, const void* lut, void* dst, int len, int cn, int lutcn ) +{ + fn((const uchar*)src, (const T*)lut, (T*)dst, len, cn, lutcn); +} + +typedef void (*LUTFunc)( const void* src, const void* lut, void* dst, int len, int cn, int lutcn ); static LUTFunc getLUTFunc(const int srcDepth, const int dstDepth) { @@ -46,40 +55,40 @@ static LUTFunc getLUTFunc(const int srcDepth, const int dstDepth) { switch(dstDepth) { - case CV_8U: ret = (LUTFunc)LUT8u_dispatch; break; - case CV_8S: ret = (LUTFunc)LUT_; break; - case CV_16U: ret = (LUTFunc)LUT16u_dispatch; break; - case CV_16S: ret = (LUTFunc)LUT_; break; - case CV_32S: ret = (LUTFunc)LUT_; break; - case CV_32F: ret = (LUTFunc)LUT_; break; // float - case CV_64F: ret = (LUTFunc)LUT_; break; // double - case CV_16F: ret = (LUTFunc)LUT_; break; // hfloat - case CV_16BF: ret = (LUTFunc)LUT_; break; // bfloat - case CV_Bool: ret = (LUTFunc)LUT_; break; // bool - case CV_64U: ret = (LUTFunc)LUT_; break; - case CV_64S: ret = (LUTFunc)LUT_; break; - case CV_32U: ret = (LUTFunc)LUT_; break; - default: ret = nullptr; break; + case CV_8U: ret = lutDispatchWrap; break; + case CV_8S: ret = LUT_; break; + case CV_16U: ret = lutDispatchWrap; break; + case CV_16S: ret = LUT_; break; + case CV_32S: ret = LUT_; break; + case CV_32F: ret = LUT_; break; // float + case CV_64F: ret = LUT_; break; // double + case CV_16F: ret = LUT_; break; // hfloat + case CV_16BF: ret = LUT_; break; // bfloat + case CV_Bool: ret = LUT_; break; // bool + case CV_64U: ret = LUT_; break; + case CV_64S: ret = LUT_; break; + case CV_32U: ret = LUT_; break; + default: ret = nullptr; break; } } else if((srcDepth == CV_16U) || (srcDepth == CV_16S)) { switch(dstDepth) { - case CV_8U: ret = (LUTFunc)LUT_; break; - case CV_8S: ret = (LUTFunc)LUT_; break; - case CV_16U: ret = (LUTFunc)LUT_; break; - case CV_16S: ret = (LUTFunc)LUT_; break; - case CV_32S: ret = (LUTFunc)LUT_; break; - case CV_32F: ret = (LUTFunc)LUT_; break; // float - case CV_64F: ret = (LUTFunc)LUT_; break; // double - case CV_16F: ret = (LUTFunc)LUT_; break; // hfloat - case CV_16BF: ret = (LUTFunc)LUT_; break; // bfloat - case CV_Bool: ret = (LUTFunc)LUT_; break; // bool - case CV_64U: ret = (LUTFunc)LUT_; break; - case CV_64S: ret = (LUTFunc)LUT_; break; - case CV_32U: ret = (LUTFunc)LUT_; break; - default: ret = nullptr; break; + case CV_8U: ret = LUT_; break; + case CV_8S: ret = LUT_; break; + case CV_16U: ret = LUT_; break; + case CV_16S: ret = LUT_; break; + case CV_32S: ret = LUT_; break; + case CV_32F: ret = LUT_; break; // float + case CV_64F: ret = LUT_; break; // double + case CV_16F: ret = LUT_; break; // hfloat + case CV_16BF: ret = LUT_; break; // bfloat + case CV_Bool: ret = LUT_; break; // bool + case CV_64U: ret = LUT_; break; + case CV_64S: ret = LUT_; break; + case CV_32U: ret = LUT_; break; + default: ret = nullptr; break; } } diff --git a/modules/core/src/mathfuncs.cpp b/modules/core/src/mathfuncs.cpp index 1b3ed9dae4..6bb5330e5f 100644 --- a/modules/core/src/mathfuncs.cpp +++ b/modules/core/src/mathfuncs.cpp @@ -812,8 +812,10 @@ struct iPow_SIMD template static void -iPow_i( const T* src, T* dst, int len, int power ) +iPow_i( const void* _src, void* _dst, int len, int power ) { + const T* src = (const T*)_src; + T* dst = (T*)_dst; if( power < 0 ) { T tab[5] = @@ -852,8 +854,10 @@ iPow_i( const T* src, T* dst, int len, int power ) template static void -iPow_f( const T* src, T* dst, int len, int power0 ) +iPow_f( const void* _src, void* _dst, int len, int power0 ) { + const T* src = (const T*)_src; + T* dst = (T*)_dst; iPow_SIMD vop; int i = vop(src, dst, len, power0); int power = std::abs(power0); @@ -878,48 +882,12 @@ iPow_f( const T* src, T* dst, int len, int power0 ) } } -static void iPow8u(const uchar* src, uchar* dst, int len, int power) -{ - iPow_i(src, dst, len, power); -} - -static void iPow8s(const schar* src, schar* dst, int len, int power) -{ - iPow_i(src, dst, len, power); -} - -static void iPow16u(const ushort* src, ushort* dst, int len, int power) -{ - iPow_i(src, dst, len, power); -} - -static void iPow16s(const short* src, short* dst, int len, int power) -{ - iPow_i(src, dst, len, power); -} - -static void iPow32s(const int* src, int* dst, int len, int power) -{ - iPow_i(src, dst, len, power); -} - -static void iPow32f(const float* src, float* dst, int len, int power) -{ - iPow_f(src, dst, len, power); -} - -static void iPow64f(const double* src, double* dst, int len, int power) -{ - iPow_f(src, dst, len, power); -} - - -typedef void (*IPowFunc)( const uchar* src, uchar* dst, int len, int power ); +typedef void (*IPowFunc)( const void* src, void* dst, int len, int power ); static IPowFunc ipowTab[CV_DEPTH_MAX] = { - (IPowFunc)iPow8u, (IPowFunc)iPow8s, (IPowFunc)iPow16u, (IPowFunc)iPow16s, - (IPowFunc)iPow32s, (IPowFunc)iPow32f, (IPowFunc)iPow64f, 0 + iPow_i, iPow_i, iPow_i, iPow_i, + iPow_i, iPow_f, iPow_f, 0 }; #ifdef HAVE_OPENCL diff --git a/modules/core/src/matmul.dispatch.cpp b/modules/core/src/matmul.dispatch.cpp index 9fb6e3696f..d1c10ea484 100644 --- a/modules/core/src/matmul.dispatch.cpp +++ b/modules/core/src/matmul.dispatch.cpp @@ -930,59 +930,59 @@ void mulTransposed(InputArray _src, OutputArray _dst, bool ata, * Dot Product * \****************************************************************************************/ -static double dotProd_8u(const uchar* src1, const uchar* src2, int len) +static double dotProd_8u(const void* src1, const void* src2, int len) { CV_INSTRUMENT_REGION(); - CV_CPU_DISPATCH(dotProd_8u, (src1, src2, len), + CV_CPU_DISPATCH(dotProd_8u, ((const uchar*)src1, (const uchar*)src2, len), CV_CPU_DISPATCH_MODES_ALL); } -static double dotProd_8s(const schar* src1, const schar* src2, int len) +static double dotProd_8s(const void* src1, const void* src2, int len) { CV_INSTRUMENT_REGION(); - CV_CPU_DISPATCH(dotProd_8s, (src1, src2, len), + CV_CPU_DISPATCH(dotProd_8s, ((const schar*)src1, (const schar*)src2, len), CV_CPU_DISPATCH_MODES_ALL); } -static double dotProd_16u(const ushort* src1, const ushort* src2, int len) +static double dotProd_16u(const void* src1, const void* src2, int len) { CV_INSTRUMENT_REGION(); - CV_CPU_DISPATCH(dotProd_16u, (src1, src2, len), + CV_CPU_DISPATCH(dotProd_16u, ((const ushort*)src1, (const ushort*)src2, len), CV_CPU_DISPATCH_MODES_ALL); } -static double dotProd_16s(const short* src1, const short* src2, int len) +static double dotProd_16s(const void* src1, const void* src2, int len) { CV_INSTRUMENT_REGION(); - CV_CPU_DISPATCH(dotProd_16s, (src1, src2, len), + CV_CPU_DISPATCH(dotProd_16s, ((const short*)src1, (const short*)src2, len), CV_CPU_DISPATCH_MODES_ALL); } -static double dotProd_32s(const int* src1, const int* src2, int len) +static double dotProd_32s(const void* src1, const void* src2, int len) { CV_INSTRUMENT_REGION(); - CV_CPU_DISPATCH(dotProd_32s, (src1, src2, len), + CV_CPU_DISPATCH(dotProd_32s, ((const int*)src1, (const int*)src2, len), CV_CPU_DISPATCH_MODES_ALL); } -static double dotProd_32f(const float* src1, const float* src2, int len) +static double dotProd_32f(const void* src1, const void* src2, int len) { CV_INSTRUMENT_REGION(); - CV_CPU_DISPATCH(dotProd_32f, (src1, src2, len), + CV_CPU_DISPATCH(dotProd_32f, ((const float*)src1, (const float*)src2, len), CV_CPU_DISPATCH_MODES_ALL); } -static double dotProd_64f(const double* src1, const double* src2, int len) +static double dotProd_64f(const void* src1, const void* src2, int len) { CV_INSTRUMENT_REGION(); - CV_CPU_DISPATCH(dotProd_64f, (src1, src2, len), + CV_CPU_DISPATCH(dotProd_64f, ((const double*)src1, (const double*)src2, len), CV_CPU_DISPATCH_MODES_ALL); } -typedef double (*DotProdFunc)(const uchar* src1, const uchar* src2, int len); +typedef double (*DotProdFunc)(const void* src1, const void* src2, int len); static DotProdFunc getDotProdFunc(int depth) { static DotProdFunc dotProdTab[CV_DEPTH_MAX] = { - (DotProdFunc)GET_OPTIMIZED(dotProd_8u), (DotProdFunc)GET_OPTIMIZED(dotProd_8s), - (DotProdFunc)dotProd_16u, (DotProdFunc)dotProd_16s, - (DotProdFunc)dotProd_32s, (DotProdFunc)GET_OPTIMIZED(dotProd_32f), - (DotProdFunc)dotProd_64f, 0 + dotProd_8u, dotProd_8s, + dotProd_16u, dotProd_16s, + dotProd_32s, dotProd_32f, + dotProd_64f, 0 }; return dotProdTab[depth]; diff --git a/modules/core/src/matmul.simd.hpp b/modules/core/src/matmul.simd.hpp index 6f2ac4c25d..1c146a4a06 100644 --- a/modules/core/src/matmul.simd.hpp +++ b/modules/core/src/matmul.simd.hpp @@ -75,8 +75,8 @@ namespace cv { // forward declarations -typedef void (*TransformFunc)(const uchar* src, uchar* dst, const uchar* m, int len, int scn, int dcn); -typedef void (*ScaleAddFunc)(const uchar* src1, const uchar* src2, uchar* dst, int len, const void* alpha); +typedef void (*TransformFunc)(const void* src, void* dst, const void* m, int len, int scn, int dcn); +typedef void (*ScaleAddFunc)(const void* src1, const void* src2, void* dst, int len, const void* alpha); typedef void (*MulTransposedFunc)(const Mat& src, const/*preallocated*/ Mat& dst, const Mat& delta, double scale); typedef double (*MahalanobisImplFunc)(const Mat& v1, const Mat& v2, const Mat& icovar, double *diff_buffer /*[len]*/, int len /*=v1.total()*/); @@ -1136,6 +1136,31 @@ typedef void (*GEMMStoreFunc)( const void* src1, size_t step1, const void* src2, size_t step2, void* dst, size_t dststep, Size dstsize, double alpha, double beta, int flags ); +template +static void gemmSingleMulWrap( const void* src1, size_t step1, + const void* src2, size_t step2, const void* src3, size_t step3, + void* dst, size_t dststep, Size srcsize, Size dstsize, + double alpha, double beta, int flags ) +{ + fn((const T*)src1, step1, (const T*)src2, step2, (const T*)src3, step3, (T*)dst, dststep, srcsize, dstsize, alpha, beta, flags); +} + +template +static void gemmBlockMulWrap( const void* src1, size_t step1, + const void* src2, size_t step2, void* dst, size_t dststep, + Size srcsize, Size dstsize, int flags ) +{ + fn((const T*)src1, step1, (const T*)src2, step2, (WT*)dst, dststep, srcsize, dstsize, flags); +} + +template +static void gemmStoreWrap( const void* src1, size_t step1, + const void* src2, size_t step2, void* dst, size_t dststep, + Size dstsize, double alpha, double beta, int flags ) +{ + fn((const T*)src1, step1, (const WT*)src2, step2, (T*)dst, dststep, dstsize, alpha, beta, flags); +} + static void GEMMSingleMul_32f( const float* a_data, size_t a_step, const float* b_data, size_t b_step, const float* c_data, size_t c_step, @@ -1560,28 +1585,28 @@ static void gemmImpl( Mat A, Mat B, double alpha, if( type == CV_32FC1 ) { - singleMulFunc = (GEMMSingleMulFunc)GEMMSingleMul_32f; - blockMulFunc = (GEMMBlockMulFunc)GEMMBlockMul_32f; - storeFunc = (GEMMStoreFunc)GEMMStore_32f; + singleMulFunc = gemmSingleMulWrap; + blockMulFunc = gemmBlockMulWrap; + storeFunc = gemmStoreWrap; } else if( type == CV_64FC1 ) { - singleMulFunc = (GEMMSingleMulFunc)GEMMSingleMul_64f; - blockMulFunc = (GEMMBlockMulFunc)GEMMBlockMul_64f; - storeFunc = (GEMMStoreFunc)GEMMStore_64f; + singleMulFunc = gemmSingleMulWrap; + blockMulFunc = gemmBlockMulWrap; + storeFunc = gemmStoreWrap; } else if( type == CV_32FC2 ) { - singleMulFunc = (GEMMSingleMulFunc)GEMMSingleMul_32fc; - blockMulFunc = (GEMMBlockMulFunc)GEMMBlockMul_32fc; - storeFunc = (GEMMStoreFunc)GEMMStore_32fc; + singleMulFunc = gemmSingleMulWrap; + blockMulFunc = gemmBlockMulWrap; + storeFunc = gemmStoreWrap; } else { CV_Assert( type == CV_64FC2 ); - singleMulFunc = (GEMMSingleMulFunc)GEMMSingleMul_64fc; - blockMulFunc = (GEMMBlockMulFunc)GEMMBlockMul_64fc; - storeFunc = (GEMMStoreFunc)GEMMStore_64fc; + singleMulFunc = gemmSingleMulWrap; + blockMulFunc = gemmBlockMulWrap; + storeFunc = gemmStoreWrap; } if( (d_size.width == 1 || len == 1) && !(flags & GEMM_2_T) && B.isContinuous() ) @@ -2844,13 +2869,19 @@ diagtransform_64f(const double* src, double* dst, const double* m, int len, int } +template +static void transformWrap(const void* src, void* dst, const void* m, int len, int scn, int dcn) +{ + fn((const T*)src, (T*)dst, (const WT*)m, len, scn, dcn); +} + TransformFunc getTransformFunc(int depth) { static TransformFunc transformTab[CV_DEPTH_MAX] = { - (TransformFunc)transform_8u, (TransformFunc)transform_8s, (TransformFunc)transform_16u, - (TransformFunc)transform_16s, (TransformFunc)transform_32s, (TransformFunc)transform_32f, - (TransformFunc)transform_64f, 0 + transformWrap, transformWrap, transformWrap, + transformWrap, transformWrap, transformWrap, + transformWrap, 0 }; return transformTab[depth]; @@ -2860,9 +2891,9 @@ TransformFunc getDiagTransformFunc(int depth) { static TransformFunc diagTransformTab[CV_DEPTH_MAX] = { - (TransformFunc)diagtransform_8u, (TransformFunc)diagtransform_8s, (TransformFunc)diagtransform_16u, - (TransformFunc)diagtransform_16s, (TransformFunc)diagtransform_32s, (TransformFunc)diagtransform_32f, - (TransformFunc)diagtransform_64f, 0 + transformWrap, transformWrap, transformWrap, + transformWrap, transformWrap, transformWrap, + transformWrap, 0 }; return diagTransformTab[depth]; @@ -2875,8 +2906,11 @@ TransformFunc getDiagTransformFunc(int depth) \****************************************************************************************/ template static void -perspectiveTransform_( const T* src, T* dst, const double* m, int len, int scn, int dcn ) +perspectiveTransform_( const void* _src, void* _dst, const void* _m_ptr, int len, int scn, int dcn ) { + const T* src = (const T*)_src; + T* dst = (T*)_dst; + const double* m = (const double*)_m_ptr; const double eps = FLT_EPSILON; int i; @@ -2959,24 +2993,12 @@ perspectiveTransform_( const T* src, T* dst, const double* m, int len, int scn, } } -static void -perspectiveTransform_32f(const float* src, float* dst, const double* m, int len, int scn, int dcn) -{ - perspectiveTransform_(src, dst, m, len, scn, dcn); -} - -static void -perspectiveTransform_64f(const double* src, double* dst, const double* m, int len, int scn, int dcn) -{ - perspectiveTransform_(src, dst, m, len, scn, dcn); -} - TransformFunc getPerspectiveTransform(int depth) { if (depth == CV_32F) - return (TransformFunc)perspectiveTransform_32f; + return perspectiveTransform_; if (depth == CV_64F) - return (TransformFunc)perspectiveTransform_64f; + return perspectiveTransform_; CV_Assert(0 && "Not supported"); } @@ -2986,10 +3008,13 @@ TransformFunc getPerspectiveTransform(int depth) * ScaleAdd * \****************************************************************************************/ -static void scaleAdd_32f(const float* src1, const float* src2, float* dst, - int len, float* _alpha) +static void scaleAdd_32f(const void* _src1, const void* _src2, void* _dst, + int len, const void* _alpha) { - float alpha = *_alpha; + const float* src1 = (const float*)_src1; + const float* src2 = (const float*)_src2; + float* dst = (float*)_dst; + float alpha = *(const float*)_alpha; int i = 0; #if (CV_SIMD || CV_SIMD_SCALABLE) v_float32 v_alpha = vx_setall_f32(alpha); @@ -3003,10 +3028,13 @@ static void scaleAdd_32f(const float* src1, const float* src2, float* dst, } -static void scaleAdd_64f(const double* src1, const double* src2, double* dst, - int len, double* _alpha) +static void scaleAdd_64f(const void* _src1, const void* _src2, void* _dst, + int len, const void* _alpha) { - double alpha = *_alpha; + const double* src1 = (const double*)_src1; + const double* src2 = (const double*)_src2; + double* dst = (double*)_dst; + double alpha = *(const double*)_alpha; int i = 0; #if (CV_SIMD_64F || CV_SIMD_SCALABLE_64F) v_float64 a2 = vx_setall_f64(alpha); @@ -3022,9 +3050,9 @@ static void scaleAdd_64f(const double* src1, const double* src2, double* dst, ScaleAddFunc getScaleAddFunc(int depth) { if (depth == CV_32F) - return (ScaleAddFunc)scaleAdd_32f; + return scaleAdd_32f; if (depth == CV_64F) - return (ScaleAddFunc)scaleAdd_64f; + return scaleAdd_64f; CV_Assert(0 && "Not supported"); } diff --git a/modules/core/src/matrix_operations.cpp b/modules/core/src/matrix_operations.cpp index c7935f28e7..dae9682193 100644 --- a/modules/core/src/matrix_operations.cpp +++ b/modules/core/src/matrix_operations.cpp @@ -1041,23 +1041,29 @@ template static void sort_( const Mat& src, Mat& dst, int flags ) #if defined(HAVE_IPP) && !IPP_DISABLE_SORT typedef IppStatus (CV_STDCALL *IppSortFunc)(void *pSrcDst, int len, Ipp8u *pBuffer); +template +static IppStatus CV_STDCALL ippSortWrap(void* pSrcDst, int len, Ipp8u* pBuffer) +{ + return fn((T*)pSrcDst, len, pBuffer); +} + static IppSortFunc getSortFunc(int depth, bool sortDescending) { if (!sortDescending) - return depth == CV_8U ? (IppSortFunc)ippsSortRadixAscend_8u_I : - depth == CV_16U ? (IppSortFunc)ippsSortRadixAscend_16u_I : - depth == CV_16S ? (IppSortFunc)ippsSortRadixAscend_16s_I : - depth == CV_32S ? (IppSortFunc)ippsSortRadixAscend_32s_I : - depth == CV_32F ? (IppSortFunc)ippsSortRadixAscend_32f_I : - depth == CV_64F ? (IppSortFunc)ippsSortRadixAscend_64f_I : + return depth == CV_8U ? ippSortWrap : + depth == CV_16U ? ippSortWrap : + depth == CV_16S ? ippSortWrap : + depth == CV_32S ? ippSortWrap : + depth == CV_32F ? ippSortWrap : + depth == CV_64F ? ippSortWrap : 0; else - return depth == CV_8U ? (IppSortFunc)ippsSortRadixDescend_8u_I : - depth == CV_16U ? (IppSortFunc)ippsSortRadixDescend_16u_I : - depth == CV_16S ? (IppSortFunc)ippsSortRadixDescend_16s_I : - depth == CV_32S ? (IppSortFunc)ippsSortRadixDescend_32s_I : - depth == CV_32F ? (IppSortFunc)ippsSortRadixDescend_32f_I : - depth == CV_64F ? (IppSortFunc)ippsSortRadixDescend_64f_I : + return depth == CV_8U ? ippSortWrap : + depth == CV_16U ? ippSortWrap : + depth == CV_16S ? ippSortWrap : + depth == CV_32S ? ippSortWrap : + depth == CV_32F ? ippSortWrap : + depth == CV_64F ? ippSortWrap : 0; } @@ -1199,21 +1205,27 @@ template static void sortIdx_( const Mat& src, Mat& dst, int flags ) #if defined(HAVE_IPP) && !IPP_DISABLE_SORT typedef IppStatus (CV_STDCALL *IppSortIndexFunc)(const void* pSrc, Ipp32s srcStrideBytes, Ipp32s *pDstIndx, int len, Ipp8u *pBuffer); +template +static IppStatus CV_STDCALL ippSortIndexWrap(const void* pSrc, Ipp32s srcStrideBytes, Ipp32s *pDstIndx, int len, Ipp8u *pBuffer) +{ + return fn((const T*)pSrc, srcStrideBytes, pDstIndx, len, pBuffer); +} + static IppSortIndexFunc getSortIndexFunc(int depth, bool sortDescending) { if (!sortDescending) - return depth == CV_8U ? (IppSortIndexFunc)ippsSortRadixIndexAscend_8u : - depth == CV_16U ? (IppSortIndexFunc)ippsSortRadixIndexAscend_16u : - depth == CV_16S ? (IppSortIndexFunc)ippsSortRadixIndexAscend_16s : - depth == CV_32S ? (IppSortIndexFunc)ippsSortRadixIndexAscend_32s : - depth == CV_32F ? (IppSortIndexFunc)ippsSortRadixIndexAscend_32f : + return depth == CV_8U ? ippSortIndexWrap : + depth == CV_16U ? ippSortIndexWrap : + depth == CV_16S ? ippSortIndexWrap : + depth == CV_32S ? ippSortIndexWrap : + depth == CV_32F ? ippSortIndexWrap : 0; else - return depth == CV_8U ? (IppSortIndexFunc)ippsSortRadixIndexDescend_8u : - depth == CV_16U ? (IppSortIndexFunc)ippsSortRadixIndexDescend_16u : - depth == CV_16S ? (IppSortIndexFunc)ippsSortRadixIndexDescend_16s : - depth == CV_32S ? (IppSortIndexFunc)ippsSortRadixIndexDescend_32s : - depth == CV_32F ? (IppSortIndexFunc)ippsSortRadixIndexDescend_32f : + return depth == CV_8U ? ippSortIndexWrap : + depth == CV_16U ? ippSortIndexWrap : + depth == CV_16S ? ippSortIndexWrap : + depth == CV_32S ? ippSortIndexWrap : + depth == CV_32F ? ippSortIndexWrap : 0; } diff --git a/modules/core/src/mean.simd.hpp b/modules/core/src/mean.simd.hpp index f030eed976..96764c2437 100644 --- a/modules/core/src/mean.simd.hpp +++ b/modules/core/src/mean.simd.hpp @@ -12,6 +12,12 @@ typedef int (*SumSqrFunc)(const uchar*, const uchar* mask, uchar*, uchar*, int, CV_CPU_OPTIMIZATION_NAMESPACE_BEGIN +template +static int sumSqrWrap(const uchar* src, const uchar* mask, uchar* sum, uchar* sqsum, int len, int cn) +{ + return fn((const T*)src, mask, (ST*)sum, (SQT*)sqsum, len, cn); +} + SumSqrFunc getSumSqrFunc(int depth); #ifndef CV_CPU_OPTIMIZATION_DECLARATIONS_ONLY @@ -621,10 +627,13 @@ SumSqrFunc getSumSqrFunc(int depth) CV_INSTRUMENT_REGION(); static SumSqrFunc sumSqrTab[CV_DEPTH_MAX] = { - (SumSqrFunc)GET_OPTIMIZED(sqsum8u), (SumSqrFunc)sqsum8s, (SumSqrFunc)sqsum16u, (SumSqrFunc)sqsum16s, - (SumSqrFunc)sqsum32s, (SumSqrFunc)GET_OPTIMIZED(sqsum32f), (SumSqrFunc)sqsum64f, - (SumSqrFunc)sqsum16f, (SumSqrFunc)sqsum16bf, 0, - (SumSqrFunc)sqsum64u, (SumSqrFunc)sqsum64s, (SumSqrFunc)sqsum32u, 0 + sumSqrWrap, sumSqrWrap, + sumSqrWrap, sumSqrWrap, + sumSqrWrap, sumSqrWrap, + sumSqrWrap, + sumSqrWrap, sumSqrWrap, 0, + sumSqrWrap, sumSqrWrap, + sumSqrWrap, 0 }; return sumSqrTab[depth]; diff --git a/modules/core/src/merge.dispatch.cpp b/modules/core/src/merge.dispatch.cpp index 668026ee00..3f59c4f0b7 100644 --- a/modules/core/src/merge.dispatch.cpp +++ b/modules/core/src/merge.dispatch.cpp @@ -46,19 +46,25 @@ void merge64s(const int64** src, int64* dst, int len, int cn ) } // namespace cv::hal:: -typedef void (*MergeFunc)(const uchar** src, uchar* dst, int len, int cn); +typedef void (*MergeFunc)(const void** src, void* dst, int len, int cn); + +template +static void mergeWrap(const void** src, void* dst, int len, int cn) +{ + fn((const T**)src, (T*)dst, len, cn); +} static MergeFunc getMergeFunc(int depth) { static MergeFunc mergeTab[CV_DEPTH_MAX] = { - (MergeFunc)GET_OPTIMIZED(cv::hal::merge8u), (MergeFunc)GET_OPTIMIZED(cv::hal::merge8u), - (MergeFunc)GET_OPTIMIZED(cv::hal::merge16u), (MergeFunc)GET_OPTIMIZED(cv::hal::merge16u), - (MergeFunc)GET_OPTIMIZED(cv::hal::merge32s), (MergeFunc)GET_OPTIMIZED(cv::hal::merge32s), - (MergeFunc)GET_OPTIMIZED(cv::hal::merge64s), (MergeFunc)GET_OPTIMIZED(cv::hal::merge16u), - (MergeFunc)GET_OPTIMIZED(cv::hal::merge16u), (MergeFunc)GET_OPTIMIZED(cv::hal::merge8u), - (MergeFunc)GET_OPTIMIZED(cv::hal::merge64s), (MergeFunc)GET_OPTIMIZED(cv::hal::merge64s), - (MergeFunc)GET_OPTIMIZED(cv::hal::merge32s), 0, 0, 0, + mergeWrap, mergeWrap, + mergeWrap, mergeWrap, + mergeWrap, mergeWrap, + mergeWrap, mergeWrap, + mergeWrap, mergeWrap, + mergeWrap, mergeWrap, + mergeWrap, 0, 0, 0, }; return mergeTab[depth]; @@ -187,7 +193,7 @@ void merge(const Mat* mv, size_t n, OutputArray _dst) for( size_t j = 0; j < total; j += blocksize ) { size_t bsz = std::min(total - j, blocksize); - func( (const uchar**)&ptrs[1], ptrs[0], (int)bsz, cn ); + func( (const void**)&ptrs[1], ptrs[0], (int)bsz, cn ); if( j + blocksize < total ) { diff --git a/modules/core/src/minmax.dispatch.cpp b/modules/core/src/minmax.dispatch.cpp index dd335454cd..b411850973 100644 --- a/modules/core/src/minmax.dispatch.cpp +++ b/modules/core/src/minmax.dispatch.cpp @@ -54,7 +54,7 @@ void getMinMaxRes(const Mat & db, double * minVal, double * maxVal, { uint index_max = std::numeric_limits::max(); T minval = std::numeric_limits::max(); - T maxval = std::numeric_limits::min() > 0 ? -std::numeric_limits::max() : std::numeric_limits::min(), maxval2 = maxval; + T maxval = std::numeric_limits::min() > 0 ? (T)-std::numeric_limits::max() : std::numeric_limits::min(), maxval2 = maxval; uint minloc = index_max, maxloc = index_max; size_t index = 0; diff --git a/modules/core/src/minmax.simd.hpp b/modules/core/src/minmax.simd.hpp index 57c7935a0e..d61a86f749 100644 --- a/modules/core/src/minmax.simd.hpp +++ b/modules/core/src/minmax.simd.hpp @@ -13,6 +13,15 @@ typedef void (*MinMaxIdxFunc)(const uchar* data, const uchar* mask, CV_CPU_OPTIMIZATION_NAMESPACE_BEGIN +template +static void minMaxIdxWrap(const uchar* data, const uchar* mask, + void* minval, void* maxval, + size_t* minidx, size_t* maxidx, + int len, size_t startidx) +{ + fn((const T*)data, mask, (WT*)minval, (WT*)maxval, minidx, maxidx, len, startidx); +} + MinMaxIdxFunc getMinMaxIdxFunc(int depth); #ifndef CV_CPU_OPTIMIZATION_DECLARATIONS_ONLY @@ -369,19 +378,19 @@ MinMaxIdxFunc getMinMaxIdxFunc(int depth) { static MinMaxIdxFunc minMaxIdxTab[CV_DEPTH_MAX] = { - (MinMaxIdxFunc)GET_OPTIMIZED(minMaxIdx8u), - (MinMaxIdxFunc)GET_OPTIMIZED(minMaxIdx8s), - (MinMaxIdxFunc)GET_OPTIMIZED(minMaxIdx16u), - (MinMaxIdxFunc)GET_OPTIMIZED(minMaxIdx16s), - (MinMaxIdxFunc)GET_OPTIMIZED(minMaxIdx32s), - (MinMaxIdxFunc)GET_OPTIMIZED(minMaxIdx32f), - (MinMaxIdxFunc)GET_OPTIMIZED(minMaxIdx64f), - (MinMaxIdxFunc)GET_OPTIMIZED(minMaxIdx16f), - (MinMaxIdxFunc)GET_OPTIMIZED(minMaxIdx16bf), - (MinMaxIdxFunc)GET_OPTIMIZED(minMaxIdx8u), - (MinMaxIdxFunc)GET_OPTIMIZED(minMaxIdx64u), - (MinMaxIdxFunc)GET_OPTIMIZED(minMaxIdx64s), - (MinMaxIdxFunc)GET_OPTIMIZED(minMaxIdx32u), + minMaxIdxWrap, + minMaxIdxWrap, + minMaxIdxWrap, + minMaxIdxWrap, + minMaxIdxWrap, + minMaxIdxWrap, + minMaxIdxWrap, + minMaxIdxWrap, + minMaxIdxWrap, + minMaxIdxWrap, + minMaxIdxWrap, + minMaxIdxWrap, + minMaxIdxWrap, 0 }; diff --git a/modules/core/src/norm.simd.hpp b/modules/core/src/norm.simd.hpp index eaa07eee32..44dfc5fe27 100644 --- a/modules/core/src/norm.simd.hpp +++ b/modules/core/src/norm.simd.hpp @@ -15,6 +15,18 @@ using NormDiffFunc = int (*)(const uchar*, const uchar*, const uchar*, uchar*, i CV_CPU_OPTIMIZATION_NAMESPACE_BEGIN +template +static int normWrap(const uchar* src1, const uchar* src2, uchar* res, int len, int cn) +{ + return fn((const T*)src1, src2, (RT*)res, len, cn); +} + +template +static int normDiffWrap(const uchar* src1, const uchar* src2, const uchar* src3, uchar* res, int len, int cn) +{ + return fn((const T*)src1, (const T*)src2, src3, (RT*)res, len, cn); +} + NormFunc getNormFunc(int normType, int depth); NormDiffFunc getNormDiffFunc(int normType, int depth); @@ -2319,51 +2331,51 @@ NormFunc getNormFunc(int normType, int depth) static NormFunc normTab[3][CV_DEPTH_MAX] = { { - (NormFunc)GET_OPTIMIZED(normInf_8u), - (NormFunc)GET_OPTIMIZED(normInf_8s), - (NormFunc)GET_OPTIMIZED(normInf_16u), - (NormFunc)GET_OPTIMIZED(normInf_16s), - (NormFunc)GET_OPTIMIZED(normInf_32s), - (NormFunc)GET_OPTIMIZED(normInf_32f), - (NormFunc)normInf_64f, - (NormFunc)GET_OPTIMIZED(normInf_16f), - (NormFunc)GET_OPTIMIZED(normInf_16bf), - (NormFunc)normInf_Bool, - (NormFunc)GET_OPTIMIZED(normInf_64u), - (NormFunc)GET_OPTIMIZED(normInf_64s), - (NormFunc)GET_OPTIMIZED(normInf_32u), + normWrap, + normWrap, + normWrap, + normWrap, + normWrap, + normWrap, + normWrap, + normWrap, + normWrap, + normWrap, + normWrap, + normWrap, + normWrap, 0 }, { - (NormFunc)GET_OPTIMIZED(normL1_8u), - (NormFunc)GET_OPTIMIZED(normL1_8s), - (NormFunc)GET_OPTIMIZED(normL1_16u), - (NormFunc)GET_OPTIMIZED(normL1_16s), - (NormFunc)GET_OPTIMIZED(normL1_32s), - (NormFunc)GET_OPTIMIZED(normL1_32f), - (NormFunc)normL1_64f, - (NormFunc)GET_OPTIMIZED(normL1_16f), - (NormFunc)GET_OPTIMIZED(normL1_16bf), - (NormFunc)normL1_Bool, - (NormFunc)GET_OPTIMIZED(normL1_64u), - (NormFunc)GET_OPTIMIZED(normL1_64s), - (NormFunc)GET_OPTIMIZED(normL1_32u), + normWrap, + normWrap, + normWrap, + normWrap, + normWrap, + normWrap, + normWrap, + normWrap, + normWrap, + normWrap, + normWrap, + normWrap, + normWrap, 0 }, { - (NormFunc)GET_OPTIMIZED(normL2_8u), - (NormFunc)GET_OPTIMIZED(normL2_8s), - (NormFunc)GET_OPTIMIZED(normL2_16u), - (NormFunc)GET_OPTIMIZED(normL2_16s), - (NormFunc)GET_OPTIMIZED(normL2_32s), - (NormFunc)GET_OPTIMIZED(normL2_32f), - (NormFunc)normL2_64f, - (NormFunc)GET_OPTIMIZED(normL2_16f), - (NormFunc)GET_OPTIMIZED(normL2_16bf), - (NormFunc)normL2_Bool, - (NormFunc)GET_OPTIMIZED(normL2_64u), - (NormFunc)GET_OPTIMIZED(normL2_64s), - (NormFunc)GET_OPTIMIZED(normL2_32u), + normWrap, + normWrap, + normWrap, + normWrap, + normWrap, + normWrap, + normWrap, + normWrap, + normWrap, + normWrap, + normWrap, + normWrap, + normWrap, 0 } }; @@ -2378,51 +2390,51 @@ NormDiffFunc getNormDiffFunc(int normType, int depth) static NormDiffFunc normDiffTab[3][CV_DEPTH_MAX] = { { - (NormDiffFunc)GET_OPTIMIZED(normDiffInf_8u), - (NormDiffFunc)normDiffInf_8s, - (NormDiffFunc)normDiffInf_16u, - (NormDiffFunc)normDiffInf_16s, - (NormDiffFunc)normDiffInf_32s, - (NormDiffFunc)GET_OPTIMIZED(normDiffInf_32f), - (NormDiffFunc)normDiffInf_64f, - (NormDiffFunc)normDiffInf_16f, - (NormDiffFunc)normDiffInf_16bf, - (NormDiffFunc)normDiffInf_Bool, - (NormDiffFunc)normDiffInf_64u, - (NormDiffFunc)normDiffInf_64s, - (NormDiffFunc)normDiffInf_32u, + normDiffWrap, + normDiffWrap, + normDiffWrap, + normDiffWrap, + normDiffWrap, + normDiffWrap, + normDiffWrap, + normDiffWrap, + normDiffWrap, + normDiffWrap, + normDiffWrap, + normDiffWrap, + normDiffWrap, 0 }, { - (NormDiffFunc)GET_OPTIMIZED(normDiffL1_8u), - (NormDiffFunc)normDiffL1_8s, - (NormDiffFunc)normDiffL1_16u, - (NormDiffFunc)normDiffL1_16s, - (NormDiffFunc)normDiffL1_32s, - (NormDiffFunc)GET_OPTIMIZED(normDiffL1_32f), - (NormDiffFunc)normDiffL1_64f, - (NormDiffFunc)normDiffL1_16f, - (NormDiffFunc)normDiffL1_16bf, - (NormDiffFunc)normDiffL1_Bool, - (NormDiffFunc)normDiffL1_64u, - (NormDiffFunc)normDiffL1_64s, - (NormDiffFunc)normDiffL1_32u, + normDiffWrap, + normDiffWrap, + normDiffWrap, + normDiffWrap, + normDiffWrap, + normDiffWrap, + normDiffWrap, + normDiffWrap, + normDiffWrap, + normDiffWrap, + normDiffWrap, + normDiffWrap, + normDiffWrap, 0 }, { - (NormDiffFunc)GET_OPTIMIZED(normDiffL2_8u), - (NormDiffFunc)normDiffL2_8s, - (NormDiffFunc)normDiffL2_16u, - (NormDiffFunc)normDiffL2_16s, - (NormDiffFunc)normDiffL2_32s, - (NormDiffFunc)GET_OPTIMIZED(normDiffL2_32f), - (NormDiffFunc)normDiffL2_64f, - (NormDiffFunc)normDiffL2_16f, - (NormDiffFunc)normDiffL2_16bf, - (NormDiffFunc)normDiffL2_Bool, - (NormDiffFunc)normDiffL2_64u, - (NormDiffFunc)normDiffL2_64s, - (NormDiffFunc)normDiffL2_32u, + normDiffWrap, + normDiffWrap, + normDiffWrap, + normDiffWrap, + normDiffWrap, + normDiffWrap, + normDiffWrap, + normDiffWrap, + normDiffWrap, + normDiffWrap, + normDiffWrap, + normDiffWrap, + normDiffWrap, 0 }, }; diff --git a/modules/core/src/precomp.hpp b/modules/core/src/precomp.hpp index f377d0f45e..c4adaacdbc 100644 --- a/modules/core/src/precomp.hpp +++ b/modules/core/src/precomp.hpp @@ -256,9 +256,9 @@ typedef void (*BinaryFunc)(const uchar* src1, size_t step1, uchar* dst, size_t step, Size sz, void*); -typedef void (*BinaryFuncC)(const uchar* src1, size_t step1, - const uchar* src2, size_t step2, - uchar* dst, size_t step, int width, int height, +typedef void (*BinaryFuncC)(const void* src1, size_t step1, + const void* src2, size_t step2, + void* dst, size_t step, int width, int height, void*); // Exported so the new element-wise expression engine can reuse the already-optimized, diff --git a/modules/core/src/rand.cpp b/modules/core/src/rand.cpp index 69e4a0ba69..ac15c29b42 100644 --- a/modules/core/src/rand.cpp +++ b/modules/core/src/rand.cpp @@ -213,24 +213,17 @@ randi_( uint64_t* arr, int len, int cn, uint64* state, const DivStruct* p ) *state = temp; } -#define DEF_RANDI_FUNC(suffix, type) \ -static void randBits_##suffix(type* arr, int len, int cn, uint64* state, \ - const Vec2l* p, void*, int flags) \ -{ randBits_(arr, len, cn, state, p, flags); } \ -\ -static void randi_##suffix(type* arr, int len, int cn, uint64* state, \ - const DivStruct* p, void*, int) \ -{ randi_(arr, len, cn, state, p); } +template +static void randBitsWrap(void* arr, int len, int cn, uint64* state, const void* p, void*, int flags) +{ + randBits_((T*)arr, len, cn, state, (const Vec2l*)p, flags); +} -DEF_RANDI_FUNC(8u, uchar) -DEF_RANDI_FUNC(8b, bool) -DEF_RANDI_FUNC(8s, schar) -DEF_RANDI_FUNC(16u, ushort) -DEF_RANDI_FUNC(16s, short) -DEF_RANDI_FUNC(32u, unsigned) -DEF_RANDI_FUNC(32s, int) -DEF_RANDI_FUNC(64u, uint64_t) -DEF_RANDI_FUNC(64s, int64_t) +template +static void randiWrap(void* arr, int len, int cn, uint64* state, const void* p, void*, int) +{ + randi_((T*)arr, len, cn, state, (const DivStruct*)p); +} // Narrow an f32 buffer into one of the 1-byte FP8 destinations. static inline void cvt32fToFP8(const float* src, void* dst, int len, int depth) @@ -240,8 +233,10 @@ static inline void cvt32fToFP8(const float* src, void* dst, int len, int depth) } static inline bool isFP8Depth(int d) { return d >= CV_8F_E4M3FN && d <= CV_8F_E4M3FNUZ; } -static void randf_16_or_32f( void* dst, int len_, int cn, uint64* state, const Vec2f* p, float* fbuf, int flags ) +static void randf_16_or_32f( void* dst, int len_, int cn, uint64* state, const void* _p, void* _fbuf, int flags ) { + const Vec2f* p = (const Vec2f*)_p; + float* fbuf = (float*)_fbuf; int depth = CV_MAT_DEPTH(flags); uint64 temp = *state; int k = 0, len = len_*cn; @@ -264,8 +259,10 @@ static void randf_16_or_32f( void* dst, int len_, int cn, uint64* state, const V } static void -randf_64f( double* arr, int len_, int cn, uint64* state, const Vec2d* p, void*, int ) +randf_64f( void* _arr, int len_, int cn, uint64* state, const void* _p, void*, int ) { + double* arr = (double*)_arr; + const Vec2d* p = (const Vec2d*)_p; uint64 temp = *state; int k = 0, len = len_*cn; cn--; @@ -280,24 +277,24 @@ randf_64f( double* arr, int len_, int cn, uint64* state, const Vec2d* p, void*, hal::addRNGBias64f(arr, &p[0][0], len_, cn+1); } -typedef void (*RandFunc)(uchar* arr, int len, int cn, uint64* state, +typedef void (*RandFunc)(void* arr, int len, int cn, uint64* state, const void* p, void* tempbuf, int flags); static RandFunc randTab[CV_DEPTH_MAX][CV_DEPTH_MAX] = { { - (RandFunc)randi_8u, (RandFunc)randi_8s, (RandFunc)randi_16u, - (RandFunc)randi_16s, (RandFunc)randi_32s, (RandFunc)randf_16_or_32f, - (RandFunc)randf_64f, (RandFunc)randf_16_or_32f, (RandFunc)randf_16_or_32f, - (RandFunc)randi_8b, (RandFunc)randi_64u, (RandFunc)randi_64s, - (RandFunc)randi_32u, - (RandFunc)randf_16_or_32f, (RandFunc)randf_16_or_32f // CV_8F_E4M3FN, E4M3FNUZ + randiWrap, randiWrap, randiWrap, + randiWrap, randiWrap, randf_16_or_32f, + randf_64f, randf_16_or_32f, randf_16_or_32f, + randiWrap, randiWrap, randiWrap, + randiWrap, + randf_16_or_32f, randf_16_or_32f // CV_8F_E4M3FN, E4M3FNUZ }, { - (RandFunc)randBits_8u, (RandFunc)randBits_8s, (RandFunc)randBits_16u, - (RandFunc)randBits_16s, (RandFunc)randBits_32s, 0, 0, 0, 0, - (RandFunc)randBits_8b, (RandFunc)randBits_64u, (RandFunc)randBits_64s, - (RandFunc)randBits_32u, 0, 0, 0 + randBitsWrap, randBitsWrap, randBitsWrap, + randBitsWrap, randBitsWrap, 0, 0, 0, 0, + randBitsWrap, randBitsWrap, randBitsWrap, + randBitsWrap, 0, 0, 0 } }; @@ -390,9 +387,12 @@ double RNG::gaussian(double sigma) } template static void -randnScale_(float* src, T* dst, int len, int cn, - const PT* mean, const PT* stddev, int flags ) +randnScale_(float* src, void* _dst, int len, int cn, + const void* _mean, const void* _stddev, int flags ) { + T* dst = (T*)_dst; + const PT* mean = (const PT*)_mean; + const PT* stddev = (const PT*)_stddev; bool stdmtx = (flags & RNG_FLAG_STDMTX) != 0; int i, j, k; if( !stdmtx || cn == 1 ) @@ -431,9 +431,12 @@ randnScale_(float* src, T* dst, int len, int cn, // special version for 16f, 16bf and 32f static void -randnScale_16_or_32f(float* fbuf, float* dst, int len, int cn, - const float* mean, const float* stddev, int flags) +randnScale_16_or_32f(float* fbuf, void* _dst, int len, int cn, + const void* _mean, const void* _stddev, int flags) { + float* dst = (float*)_dst; + const float* mean = (const float*)_mean; + const float* stddev = (const float*)_stddev; bool stdmtx = (flags & RNG_FLAG_STDMTX) != 0; int depth = CV_MAT_DEPTH(flags); float* arr = depth == CV_16F || depth == CV_16BF || isFP8Depth(depth) ? fbuf : dst; @@ -498,33 +501,17 @@ randnScale_16_or_32f(float* fbuf, float* dst, int len, int cn, cvt32fToFP8(fbuf, dst, len, depth); } -#define DEF_RANDNSCALE_FUNC(suffix, T, PT) \ -static void randnScale_##suffix( float* src, T* dst, int len, int cn, \ - const PT* mean, const PT* stddev, int flags ) \ -{ randnScale_(src, dst, len, cn, mean, stddev, flags); } - -DEF_RANDNSCALE_FUNC(8u, uchar, float) -DEF_RANDNSCALE_FUNC(8b, bool, float) -DEF_RANDNSCALE_FUNC(8s, schar, float) -DEF_RANDNSCALE_FUNC(16u, ushort, float) -DEF_RANDNSCALE_FUNC(16s, short, float) -DEF_RANDNSCALE_FUNC(32u, unsigned, float) -DEF_RANDNSCALE_FUNC(32s, int, float) -DEF_RANDNSCALE_FUNC(64u, uint64_t, double) -DEF_RANDNSCALE_FUNC(64s, int64_t, double) -DEF_RANDNSCALE_FUNC(64f, double, double) - typedef void (*RandnScaleFunc)(float* src, void* dst, int len, int cn, const void* mean, const void* stddev, int flags); static RandnScaleFunc randnScaleTab[CV_DEPTH_MAX] = { - (RandnScaleFunc)randnScale_8u, (RandnScaleFunc)randnScale_8s, (RandnScaleFunc)randnScale_16u, - (RandnScaleFunc)randnScale_16s, (RandnScaleFunc)randnScale_32s, (RandnScaleFunc)randnScale_16_or_32f, - (RandnScaleFunc)randnScale_64f, (RandnScaleFunc)randnScale_16_or_32f, (RandnScaleFunc)randnScale_16_or_32f, - (RandnScaleFunc)randnScale_8b, (RandnScaleFunc)randnScale_64u, (RandnScaleFunc)randnScale_64s, - (RandnScaleFunc)randnScale_32u, - (RandnScaleFunc)randnScale_16_or_32f, (RandnScaleFunc)randnScale_16_or_32f // CV_8F_E4M3FN, E4M3FNUZ + randnScale_, randnScale_, randnScale_, + randnScale_, randnScale_, randnScale_16_or_32f, + randnScale_, randnScale_16_or_32f, randnScale_16_or_32f, + randnScale_, randnScale_, randnScale_, + randnScale_, + randnScale_16_or_32f, randnScale_16_or_32f // CV_8F_E4M3FN, E4M3FNUZ }; void RNG::fill( InputOutputArray _mat, int disttype, diff --git a/modules/core/src/split.dispatch.cpp b/modules/core/src/split.dispatch.cpp index f10bcba7e0..7a750d5856 100644 --- a/modules/core/src/split.dispatch.cpp +++ b/modules/core/src/split.dispatch.cpp @@ -49,19 +49,25 @@ void split64s(const int64* src, int64** dst, int len, int cn ) * split & merge * \****************************************************************************************/ -typedef void (*SplitFunc)(const uchar* src, uchar** dst, int len, int cn); +typedef void (*SplitFunc)(const void* src, void** dst, int len, int cn); + +template +static void splitWrap(const void* src, void** dst, int len, int cn) +{ + fn((const T*)src, (T**)dst, len, cn); +} static SplitFunc getSplitFunc(int depth) { static SplitFunc splitTab[CV_DEPTH_MAX] = { - (SplitFunc)GET_OPTIMIZED(cv::hal::split8u), (SplitFunc)GET_OPTIMIZED(cv::hal::split8u), - (SplitFunc)GET_OPTIMIZED(cv::hal::split16u), (SplitFunc)GET_OPTIMIZED(cv::hal::split16u), - (SplitFunc)GET_OPTIMIZED(cv::hal::split32s), (SplitFunc)GET_OPTIMIZED(cv::hal::split32s), - (SplitFunc)GET_OPTIMIZED(cv::hal::split64s), (SplitFunc)GET_OPTIMIZED(cv::hal::split16u), - (SplitFunc)GET_OPTIMIZED(cv::hal::split16u), (SplitFunc)GET_OPTIMIZED(cv::hal::split8u), - (SplitFunc)GET_OPTIMIZED(cv::hal::split64s), (SplitFunc)GET_OPTIMIZED(cv::hal::split64s), - (SplitFunc)GET_OPTIMIZED(cv::hal::split32s), 0, 0, 0 + splitWrap, splitWrap, + splitWrap, splitWrap, + splitWrap, splitWrap, + splitWrap, splitWrap, + splitWrap, splitWrap, + splitWrap, splitWrap, + splitWrap, 0, 0, 0 }; return splitTab[depth]; @@ -161,7 +167,7 @@ void split(const Mat& src, Mat* mv) for( size_t j = 0; j < total; j += blocksize ) { size_t bsz = std::min(total - j, blocksize); - func( ptrs[0], &ptrs[1], (int)bsz, cn ); + func( ptrs[0], (void**)&ptrs[1], (int)bsz, cn ); if( j + blocksize < total ) { diff --git a/modules/core/src/sum.simd.hpp b/modules/core/src/sum.simd.hpp index 65a768ce2f..387210bd1d 100644 --- a/modules/core/src/sum.simd.hpp +++ b/modules/core/src/sum.simd.hpp @@ -9,6 +9,12 @@ namespace cv { CV_CPU_OPTIMIZATION_NAMESPACE_BEGIN +template +static int sumWrap(const uchar* src, const uchar* mask, uchar* sum, int len, int cn) +{ + return fn((const T*)src, mask, (ST*)sum, len, cn); +} + SumFunc getSumFunc(int depth); #ifndef CV_CPU_OPTIMIZATION_DECLARATIONS_ONLY @@ -384,19 +390,19 @@ SumFunc getSumFunc(int depth) { static SumFunc sumTab[CV_DEPTH_MAX] = { - (SumFunc)GET_OPTIMIZED(sum8u), - (SumFunc)sum8s, - (SumFunc)sum16u, - (SumFunc)sum16s, - (SumFunc)sum32s, - (SumFunc)GET_OPTIMIZED(sum32f), - (SumFunc)sum64f, - (SumFunc)sum16f, - (SumFunc)sum16bf, + sumWrap, + sumWrap, + sumWrap, + sumWrap, + sumWrap, + sumWrap, + sumWrap, + sumWrap, + sumWrap, 0, - (SumFunc)sum64u, - (SumFunc)sum64s, - (SumFunc)sum32u, + sumWrap, + sumWrap, + sumWrap, 0 }; diff --git a/modules/geometry/src/moments.cpp b/modules/geometry/src/moments.cpp index b683f7ebcf..56aa068457 100644 --- a/modules/geometry/src/moments.cpp +++ b/modules/geometry/src/moments.cpp @@ -486,6 +486,12 @@ static bool ocl_moments( InputArray _src, Moments& m, bool binary) #ifdef HAVE_IPP typedef IppStatus (CV_STDCALL * ippiMoments)(const void* pSrc, int srcStep, IppiSize roiSize, IppiMomentState_64f* pCtx); +template +static IppStatus CV_STDCALL ippiMomentsWrap(const void* pSrc, int srcStep, IppiSize roiSize, IppiMomentState_64f* pCtx) +{ + return fn((const T*)pSrc, srcStep, roiSize, pCtx); +} + static bool ipp_moments(Mat &src, Moments &m ) { #if IPP_VERSION_X100 >= 900 @@ -506,9 +512,9 @@ static bool ipp_moments(Mat &src, Moments &m ) int stateSize = 0; ippiMoments ippiMoments64f = - (type == CV_8UC1)?(ippiMoments)ippiMoments64f_8u_C1R: - (type == CV_16UC1)?(ippiMoments)ippiMoments64f_16u_C1R: - (type == CV_32FC1)?(ippiMoments)ippiMoments64f_32f_C1R: + (type == CV_8UC1)?ippiMomentsWrap: + (type == CV_16UC1)?ippiMomentsWrap: + (type == CV_32FC1)?ippiMomentsWrap: NULL; if(!ippiMoments64f) return false; diff --git a/modules/highgui/src/window_gtk.cpp b/modules/highgui/src/window_gtk.cpp index 301013c542..ff599bb202 100644 --- a/modules/highgui/src/window_gtk.cpp +++ b/modules/highgui/src/window_gtk.cpp @@ -42,6 +42,14 @@ #include "precomp.hpp" #include "backend.hpp" +#if defined(__clang__) +#pragma clang diagnostic ignored "-Wunknown-warning-option" +#pragma clang diagnostic ignored "-Wcast-function-type-strict" +#elif defined(__GNUC__) +#pragma GCC diagnostic ignored "-Wpragmas" +#pragma GCC diagnostic ignored "-Wcast-function-type-strict" +#endif + #if defined (HAVE_GTK) #include diff --git a/modules/imgcodecs/src/grfmt_jpeg2000_openjpeg.cpp b/modules/imgcodecs/src/grfmt_jpeg2000_openjpeg.cpp index 047a522eca..54ab95c785 100644 --- a/modules/imgcodecs/src/grfmt_jpeg2000_openjpeg.cpp +++ b/modules/imgcodecs/src/grfmt_jpeg2000_openjpeg.cpp @@ -446,8 +446,9 @@ bool decodeSYCCData(const opj_image_t& inImg, cv::Mat& outImg, uint8_t shift, bo return false; } -OPJ_SIZE_T opjReadFromBuffer(void* dist, OPJ_SIZE_T count, detail::OpjMemoryBuffer* buffer) +OPJ_SIZE_T opjReadFromBuffer(void* dist, OPJ_SIZE_T count, void* userData) { + detail::OpjMemoryBuffer* buffer = static_cast(userData); const OPJ_SIZE_T bytesToRead = std::min(buffer->availableBytes(), count); if (bytesToRead > 0) { @@ -461,21 +462,23 @@ OPJ_SIZE_T opjReadFromBuffer(void* dist, OPJ_SIZE_T count, detail::OpjMemoryBuff } } -OPJ_SIZE_T opjSkipFromBuffer(OPJ_SIZE_T count, detail::OpjMemoryBuffer* buffer) { - const OPJ_SIZE_T bytesToSkip = std::min(buffer->availableBytes(), count); +OPJ_OFF_T opjSkipFromBuffer(OPJ_OFF_T count, void* userData) { + detail::OpjMemoryBuffer* buffer = static_cast(userData); + const OPJ_SIZE_T bytesToSkip = std::min(buffer->availableBytes(), static_cast(count)); if (bytesToSkip > 0) { buffer->pos += bytesToSkip; - return bytesToSkip; + return static_cast(bytesToSkip); } else { - return static_cast(-1); + return static_cast(-1); } } -OPJ_BOOL opjSeekFromBuffer(OPJ_OFF_T count, detail::OpjMemoryBuffer* buffer) +OPJ_BOOL opjSeekFromBuffer(OPJ_OFF_T count, void* userData) { + detail::OpjMemoryBuffer* buffer = static_cast(userData); // Count should stay positive to prevent unsigned overflow CV_DbgAssert(count > 0); // To provide proper comparison between OPJ_OFF_T and OPJ_SIZE_T, both should be @@ -494,9 +497,9 @@ detail::StreamPtr opjCreateBufferInputStream(detail::OpjMemoryBuffer* buf) opj_stream_set_user_data(stream.get(), static_cast(buf), nullptr); opj_stream_set_user_data_length(stream.get(), buf->length); - opj_stream_set_read_function(stream.get(), (opj_stream_read_fn)(opjReadFromBuffer)); - opj_stream_set_skip_function(stream.get(), (opj_stream_skip_fn)(opjSkipFromBuffer)); - opj_stream_set_seek_function(stream.get(), (opj_stream_seek_fn)(opjSeekFromBuffer)); + opj_stream_set_read_function(stream.get(), opjReadFromBuffer); + opj_stream_set_skip_function(stream.get(), opjSkipFromBuffer); + opj_stream_set_seek_function(stream.get(), opjSeekFromBuffer); } return stream; } diff --git a/modules/imgcodecs/src/grfmt_png.cpp b/modules/imgcodecs/src/grfmt_png.cpp index cdaa553733..b212b341bf 100644 --- a/modules/imgcodecs/src/grfmt_png.cpp +++ b/modules/imgcodecs/src/grfmt_png.cpp @@ -234,9 +234,8 @@ ImageDecoder PngDecoder::newDecoder() const return makePtr(); } -void PngDecoder::readDataFromBuf( void* _png_ptr, unsigned char* dst, size_t size ) +void PngDecoder::readDataFromBuf( png_structp png_ptr, png_bytep dst, png_size_t size ) { - png_structp png_ptr = (png_structp)_png_ptr; PngDecoder* decoder = (PngDecoder*)(png_get_io_ptr(png_ptr)); CV_Assert( decoder ); const Mat& buf = decoder->m_buf; @@ -270,7 +269,7 @@ bool PngDecoder::readHeader() uint32_t id = 0; if( !m_buf.empty() ) - png_set_read_fn(m_png_ptr, this, (png_rw_ptr)readDataFromBuf ); + png_set_read_fn(m_png_ptr, this, readDataFromBuf ); else { m_f = fopen(m_filename.c_str(), "rb"); @@ -977,11 +976,10 @@ ImageEncoder PngEncoder::newEncoder() const return makePtr(); } -void PngEncoder::writeDataToBuf(void* _png_ptr, unsigned char* src, size_t size) +void PngEncoder::writeDataToBuf(png_structp png_ptr, png_bytep src, png_size_t size) { if( size == 0 ) return; - png_structp png_ptr = (png_structp)_png_ptr; PngEncoder* encoder = (PngEncoder*)(png_get_io_ptr(png_ptr)); CV_Assert( encoder && encoder->m_buf ); size_t cursz = encoder->m_buf->size(); @@ -989,7 +987,7 @@ void PngEncoder::writeDataToBuf(void* _png_ptr, unsigned char* src, size_t size) memcpy( &(*encoder->m_buf)[cursz], src, size ); } -void PngEncoder::flushBuf(void*) +void PngEncoder::flushBuf(png_structp) { } @@ -1020,7 +1018,7 @@ bool PngEncoder::write( const Mat& img, const std::vector& params ) if( m_buf ) { png_set_write_fn(png_ptr, this, - (png_rw_ptr)writeDataToBuf, (png_flush_ptr)flushBuf); + writeDataToBuf, flushBuf); } else { diff --git a/modules/imgcodecs/src/grfmt_png.hpp b/modules/imgcodecs/src/grfmt_png.hpp index c43c966dd1..53636f3add 100644 --- a/modules/imgcodecs/src/grfmt_png.hpp +++ b/modules/imgcodecs/src/grfmt_png.hpp @@ -131,7 +131,7 @@ public: ImageDecoder newDecoder() const CV_OVERRIDE; private: - static void readDataFromBuf(void* png_ptr, uchar* dst, size_t size); + static void readDataFromBuf(png_structp png_ptr, png_bytep dst, png_size_t size); static void info_fn(png_structp png_ptr, png_infop info_ptr); static void row_fn(png_structp png_ptr, png_bytep new_row, png_uint_32 row_num, int pass); CV_NODISCARD_STD bool processing_start(void* frame_ptr, const Mat& img); @@ -188,8 +188,8 @@ public: ImageEncoder newEncoder() const CV_OVERRIDE; protected: - static void writeDataToBuf(void* png_ptr, unsigned char* src, size_t size); - static void flushBuf(void* png_ptr); + static void writeDataToBuf(png_structp png_ptr, png_bytep src, png_size_t size); + static void flushBuf(png_structp png_ptr); /** * @brief Writes data to an output destination, either a file stream or an in-memory buffer. * diff --git a/modules/imgproc/src/accum.cpp b/modules/imgproc/src/accum.cpp index b17aa47a5b..aa8227b678 100644 --- a/modules/imgproc/src/accum.cpp +++ b/modules/imgproc/src/accum.cpp @@ -51,40 +51,96 @@ namespace cv { -typedef void(*AccFunc)(const uchar*, uchar*, const uchar*, int, int); -typedef void(*AccProdFunc)(const uchar*, const uchar*, uchar*, const uchar*, int, int); -typedef void(*AccWFunc)(const uchar*, uchar*, const uchar*, int, int, double); +#ifdef HAVE_IPP +template +static IppStatus CV_STDCALL ippiAddWrap(const void* pSrc, int srcStep, Ipp32f* pSrcDst, int srcdstStep, IppiSize roiSize) +{ + return fn((const T*)pSrc, srcStep, pSrcDst, srcdstStep, roiSize); +} + +template +static IppStatus CV_STDCALL ippiAddMaskWrap(const void* pSrc, int srcStep, const Ipp8u* pMask, int maskStep, Ipp32f* pSrcDst, int srcDstStep, IppiSize roiSize) +{ + return fn((const T*)pSrc, srcStep, pMask, maskStep, pSrcDst, srcDstStep, roiSize); +} + +template +static IppStatus CV_STDCALL ippiAddProductWrap(const void* pSrc1, int src1Step, const void* pSrc2, int src2Step, Ipp32f* pSrcDst, int srcdstStep, IppiSize roiSize) +{ + return fn((const T*)pSrc1, src1Step, (const T*)pSrc2, src2Step, pSrcDst, srcdstStep, roiSize); +} + +template +static IppStatus CV_STDCALL ippiAddProductMaskWrap(const void* pSrc1, int src1Step, const void* pSrc2, int src2Step, const Ipp8u* pMask, int maskStep, Ipp32f* pSrcDst, int srcDstStep, IppiSize roiSize) +{ + return fn((const T*)pSrc1, src1Step, (const T*)pSrc2, src2Step, pMask, maskStep, pSrcDst, srcDstStep, roiSize); +} + +template +static IppStatus CV_STDCALL ippiAddWeightedWrap(const void* pSrc, int srcStep, Ipp32f* pSrcDst, int srcdstStep, IppiSize roiSize, Ipp32f alpha) +{ + return fn((const T*)pSrc, srcStep, pSrcDst, srcdstStep, roiSize, alpha); +} + +template +static IppStatus CV_STDCALL ippiAddWeightedMaskWrap(const void* pSrc, int srcStep, const Ipp8u* pMask, int maskStep, Ipp32f* pSrcDst, int srcDstStep, IppiSize roiSize, Ipp32f alpha) +{ + return fn((const T*)pSrc, srcStep, pMask, maskStep, pSrcDst, srcDstStep, roiSize, alpha); +} +#endif + +typedef void(*AccFunc)(const void*, void*, const uchar*, int, int); +typedef void(*AccProdFunc)(const void*, const void*, void*, const uchar*, int, int); +typedef void(*AccWFunc)(const void*, void*, const uchar*, int, int, double); + +template +static void accWrap(const void* src, void* dst, const uchar* mask, int len, int cn) +{ + fn((const ST*)src, (DT*)dst, mask, len, cn); +} + +template +static void accProdWrap(const void* src1, const void* src2, void* dst, const uchar* mask, int len, int cn) +{ + fn((const ST*)src1, (const ST*)src2, (DT*)dst, mask, len, cn); +} + +template +static void accWWrap(const void* src, void* dst, const uchar* mask, int len, int cn, double alpha) +{ + fn((const ST*)src, (DT*)dst, mask, len, cn, alpha); +} static AccFunc accTab[CV_DEPTH_MAX] = { - (AccFunc)acc_8u32f, (AccFunc)acc_8u64f, - (AccFunc)acc_16u32f, (AccFunc)acc_16u64f, - (AccFunc)acc_32f, (AccFunc)acc_32f64f, - (AccFunc)acc_64f + accWrap, accWrap, + accWrap, accWrap, + accWrap, accWrap, + accWrap }; static AccFunc accSqrTab[CV_DEPTH_MAX] = { - (AccFunc)accSqr_8u32f, (AccFunc)accSqr_8u64f, - (AccFunc)accSqr_16u32f, (AccFunc)accSqr_16u64f, - (AccFunc)accSqr_32f, (AccFunc)accSqr_32f64f, - (AccFunc)accSqr_64f + accWrap, accWrap, + accWrap, accWrap, + accWrap, accWrap, + accWrap }; static AccProdFunc accProdTab[CV_DEPTH_MAX] = { - (AccProdFunc)accProd_8u32f, (AccProdFunc)accProd_8u64f, - (AccProdFunc)accProd_16u32f, (AccProdFunc)accProd_16u64f, - (AccProdFunc)accProd_32f, (AccProdFunc)accProd_32f64f, - (AccProdFunc)accProd_64f + accProdWrap, accProdWrap, + accProdWrap, accProdWrap, + accProdWrap, accProdWrap, + accProdWrap }; static AccWFunc accWTab[CV_DEPTH_MAX] = { - (AccWFunc)accW_8u32f, (AccWFunc)accW_8u64f, - (AccWFunc)accW_16u32f, (AccWFunc)accW_16u64f, - (AccWFunc)accW_32f, (AccWFunc)accW_32f64f, - (AccWFunc)accW_64f + accWWrap, accWWrap, + accWWrap, accWWrap, + accWWrap, accWWrap, + accWWrap }; inline int getAccTabIdx(int sdepth, int ddepth) @@ -187,16 +243,16 @@ static bool ipp_accumulate(InputArray _src, InputOutputArray _dst, InputArray _m if (mask.empty()) { CV_SUPPRESS_DEPRECATED_START - ippiAdd_I = sdepth == CV_8U && ddepth == CV_32F ? (IppiAdd)ippiAdd_8u32f_C1IR : - sdepth == CV_16U && ddepth == CV_32F ? (IppiAdd)ippiAdd_16u32f_C1IR : - sdepth == CV_32F && ddepth == CV_32F ? (IppiAdd)ippiAdd_32f_C1IR : 0; + ippiAdd_I = sdepth == CV_8U && ddepth == CV_32F ? ippiAddWrap : + sdepth == CV_16U && ddepth == CV_32F ? ippiAddWrap : + sdepth == CV_32F && ddepth == CV_32F ? ippiAddWrap : 0; CV_SUPPRESS_DEPRECATED_END } else if (scn == 1) { - ippiAdd_IM = sdepth == CV_8U && ddepth == CV_32F ? (IppiAddMask)ippiAdd_8u32f_C1IMR : - sdepth == CV_16U && ddepth == CV_32F ? (IppiAddMask)ippiAdd_16u32f_C1IMR : - sdepth == CV_32F && ddepth == CV_32F ? (IppiAddMask)ippiAdd_32f_C1IMR : 0; + ippiAdd_IM = sdepth == CV_8U && ddepth == CV_32F ? ippiAddMaskWrap : + sdepth == CV_16U && ddepth == CV_32F ? ippiAddMaskWrap : + sdepth == CV_32F && ddepth == CV_32F ? ippiAddMaskWrap : 0; } if (ippiAdd_I || ippiAdd_IM) @@ -284,15 +340,15 @@ static bool ipp_accumulate_square(InputArray _src, InputOutputArray _dst, InputA if (mask.empty()) { - ippiAddSquare_I = sdepth == CV_8U && ddepth == CV_32F ? (ippiAddSquare)ippiAddSquare_8u32f_C1IR : - sdepth == CV_16U && ddepth == CV_32F ? (ippiAddSquare)ippiAddSquare_16u32f_C1IR : - sdepth == CV_32F && ddepth == CV_32F ? (ippiAddSquare)ippiAddSquare_32f_C1IR : 0; + ippiAddSquare_I = sdepth == CV_8U && ddepth == CV_32F ? ippiAddWrap : + sdepth == CV_16U && ddepth == CV_32F ? ippiAddWrap : + sdepth == CV_32F && ddepth == CV_32F ? ippiAddWrap : 0; } else if (scn == 1) { - ippiAddSquare_IM = sdepth == CV_8U && ddepth == CV_32F ? (ippiAddSquareMask)ippiAddSquare_8u32f_C1IMR : - sdepth == CV_16U && ddepth == CV_32F ? (ippiAddSquareMask)ippiAddSquare_16u32f_C1IMR : - sdepth == CV_32F && ddepth == CV_32F ? (ippiAddSquareMask)ippiAddSquare_32f_C1IMR : 0; + ippiAddSquare_IM = sdepth == CV_8U && ddepth == CV_32F ? ippiAddMaskWrap : + sdepth == CV_16U && ddepth == CV_32F ? ippiAddMaskWrap : + sdepth == CV_32F && ddepth == CV_32F ? ippiAddMaskWrap : 0; } if (ippiAddSquare_I || ippiAddSquare_IM) @@ -381,15 +437,15 @@ static bool ipp_accumulate_product(InputArray _src1, InputArray _src2, if (mask.empty()) { - ippiAddProduct_I = sdepth == CV_8U && ddepth == CV_32F ? (ippiAddProduct)ippiAddProduct_8u32f_C1IR : - sdepth == CV_16U && ddepth == CV_32F ? (ippiAddProduct)ippiAddProduct_16u32f_C1IR : - sdepth == CV_32F && ddepth == CV_32F ? (ippiAddProduct)ippiAddProduct_32f_C1IR : 0; + ippiAddProduct_I = sdepth == CV_8U && ddepth == CV_32F ? ippiAddProductWrap : + sdepth == CV_16U && ddepth == CV_32F ? ippiAddProductWrap : + sdepth == CV_32F && ddepth == CV_32F ? ippiAddProductWrap : 0; } else if (scn == 1) { - ippiAddProduct_IM = sdepth == CV_8U && ddepth == CV_32F ? (ippiAddProductMask)ippiAddProduct_8u32f_C1IMR : - sdepth == CV_16U && ddepth == CV_32F ? (ippiAddProductMask)ippiAddProduct_16u32f_C1IMR : - sdepth == CV_32F && ddepth == CV_32F ? (ippiAddProductMask)ippiAddProduct_32f_C1IMR : 0; + ippiAddProduct_IM = sdepth == CV_8U && ddepth == CV_32F ? ippiAddProductMaskWrap : + sdepth == CV_16U && ddepth == CV_32F ? ippiAddProductMaskWrap : + sdepth == CV_32F && ddepth == CV_32F ? ippiAddProductMaskWrap : 0; } if (ippiAddProduct_I || ippiAddProduct_IM) @@ -485,15 +541,15 @@ static bool ipp_accumulate_weighted( InputArray _src, InputOutputArray _dst, if (mask.empty()) { - ippiAddWeighted_I = sdepth == CV_8U && ddepth == CV_32F ? (ippiAddWeighted)ippiAddWeighted_8u32f_C1IR : - sdepth == CV_16U && ddepth == CV_32F ? (ippiAddWeighted)ippiAddWeighted_16u32f_C1IR : - sdepth == CV_32F && ddepth == CV_32F ? (ippiAddWeighted)ippiAddWeighted_32f_C1IR : 0; + ippiAddWeighted_I = sdepth == CV_8U && ddepth == CV_32F ? ippiAddWeightedWrap : + sdepth == CV_16U && ddepth == CV_32F ? ippiAddWeightedWrap : + sdepth == CV_32F && ddepth == CV_32F ? ippiAddWeightedWrap : 0; } else if (scn == 1) { - ippiAddWeighted_IM = sdepth == CV_8U && ddepth == CV_32F ? (ippiAddWeightedMask)ippiAddWeighted_8u32f_C1IMR : - sdepth == CV_16U && ddepth == CV_32F ? (ippiAddWeightedMask)ippiAddWeighted_16u32f_C1IMR : - sdepth == CV_32F && ddepth == CV_32F ? (ippiAddWeightedMask)ippiAddWeighted_32f_C1IMR : 0; + ippiAddWeighted_IM = sdepth == CV_8U && ddepth == CV_32F ? ippiAddWeightedMaskWrap : + sdepth == CV_16U && ddepth == CV_32F ? ippiAddWeightedMaskWrap : + sdepth == CV_32F && ddepth == CV_32F ? ippiAddWeightedMaskWrap : 0; } if (ippiAddWeighted_I || ippiAddWeighted_IM) diff --git a/modules/imgproc/src/histogram.cpp b/modules/imgproc/src/histogram.cpp index 0d2f260518..6e95715eda 100644 --- a/modules/imgproc/src/histogram.cpp +++ b/modules/imgproc/src/histogram.cpp @@ -691,12 +691,19 @@ calcHist_8u( std::vector& _ptrs, const std::vector& _deltas, typedef IppStatus(CV_STDCALL * IppiHistogram_C1)(const void* pSrc, int srcStep, IppiSize roiSize, Ipp32u* pHist, const IppiHistogramSpec* pSpec, Ipp8u* pBuffer); +template +static IppStatus CV_STDCALL ippiHistogram_C1_Wrap(const void* pSrc, int srcStep, + IppiSize roiSize, Ipp32u* pHist, const IppiHistogramSpec* pSpec, Ipp8u* pBuffer) +{ + return fn((const T*)pSrc, srcStep, roiSize, pHist, pSpec, pBuffer); +} + static IppiHistogram_C1 getIppiHistogramFunction_C1(int type) { IppiHistogram_C1 ippFunction = - (type == CV_8UC1) ? (IppiHistogram_C1)ippiHistogram_8u_C1R : - (type == CV_16UC1) ? (IppiHistogram_C1)ippiHistogram_16u_C1R : - (type == CV_32FC1) ? (IppiHistogram_C1)ippiHistogram_32f_C1R : + (type == CV_8UC1) ? ippiHistogram_C1_Wrap : + (type == CV_16UC1) ? ippiHistogram_C1_Wrap : + (type == CV_32FC1) ? ippiHistogram_C1_Wrap : NULL; return ippFunction; diff --git a/modules/imgproc/src/warp_kernels.simd.hpp b/modules/imgproc/src/warp_kernels.simd.hpp index f01c984f9f..c35c0f6482 100644 --- a/modules/imgproc/src/warp_kernels.simd.hpp +++ b/modules/imgproc/src/warp_kernels.simd.hpp @@ -8623,67 +8623,73 @@ bicubic64fC4(const float* srcx, const float* srcy, int len, } +template +static void bicubicWarpWrap(const float* x, const float* y, int len, const void* src, size_t srcstep, Size srcsize, void* dst, const float* coeffs, int flags, const void* fillval) +{ + fn(x, y, len, src, srcstep, srcsize, (T*)dst, coeffs, flags, (T*)fillval); +} + ImgWarpFunc getBicubicWarpFunc_(int type) { if (type == CV_8UC1) { - return (ImgWarpFunc)bicubic8uC1; + return bicubicWarpWrap; } if (type == CV_8UC2) { - return (ImgWarpFunc)bicubic8uC2; + return bicubicWarpWrap; } if (type == CV_8UC3) { - return (ImgWarpFunc)bicubic8uC3; + return bicubicWarpWrap; } if (type == CV_8UC4) { - return (ImgWarpFunc)bicubic8uC4; + return bicubicWarpWrap; } if (type == CV_16UC1) { - return (ImgWarpFunc)bicubic16uC1; + return bicubicWarpWrap; } if (type == CV_16UC2) { - return (ImgWarpFunc)bicubic16uC2; + return bicubicWarpWrap; } if (type == CV_16UC3) { - return (ImgWarpFunc)bicubic16uC3; + return bicubicWarpWrap; } if (type == CV_16UC4) { - return (ImgWarpFunc)bicubic16uC4; + return bicubicWarpWrap; } if (type == CV_16SC1) { - return (ImgWarpFunc)bicubic16sC1; + return bicubicWarpWrap; } if (type == CV_16SC2) { - return (ImgWarpFunc)bicubic16sC2; + return bicubicWarpWrap; } if (type == CV_16SC3) { - return (ImgWarpFunc)bicubic16sC3; + return bicubicWarpWrap; } if (type == CV_16SC4) { - return (ImgWarpFunc)bicubic16sC4; + return bicubicWarpWrap; } if (type == CV_32FC1) { - return (ImgWarpFunc)bicubic32fC1; + return bicubicWarpWrap; } if (type == CV_32FC2) { - return (ImgWarpFunc)bicubic32fC2; + return bicubicWarpWrap; } if (type == CV_32FC3) { - return (ImgWarpFunc)bicubic32fC3; + return bicubicWarpWrap; } if (type == CV_32FC4) { - return (ImgWarpFunc)bicubic32fC4; + return bicubicWarpWrap; } if (type == CV_64FC1) { - return (ImgWarpFunc)bicubic64fC1; + return bicubicWarpWrap; } if (type == CV_64FC2) { - return (ImgWarpFunc)bicubic64fC2; + return bicubicWarpWrap; } if (type == CV_64FC3) { - return (ImgWarpFunc)bicubic64fC3; + return bicubicWarpWrap; } if (type == CV_64FC4) { - return (ImgWarpFunc)bicubic64fC4; + return bicubicWarpWrap; } return (ImgWarpFunc)nullptr; } diff --git a/modules/python/src2/cv2.cpp b/modules/python/src2/cv2.cpp index 129b961698..8dcf25eb99 100644 --- a/modules/python/src2/cv2.cpp +++ b/modules/python/src2/cv2.cpp @@ -2,6 +2,14 @@ // https://numpy.org/doc/1.17/reference/c-api.array.html#importing-the-api #define PY_ARRAY_UNIQUE_SYMBOL opencv_ARRAY_API +#if defined(__clang__) +#pragma clang diagnostic ignored "-Wunknown-warning-option" +#pragma clang diagnostic ignored "-Wcast-function-type-strict" +#elif defined(__GNUC__) +#pragma GCC diagnostic ignored "-Wpragmas" +#pragma GCC diagnostic ignored "-Wcast-function-type-strict" +#endif + #include "cv2.hpp" #include "opencv2/opencv_modules.hpp"