BinaryFunc is defined in core.hpp as
typedef void (*BinaryFunc)(const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, Size sz, void*); and BinaryFunc getConvertFunc(int sdepth, int ddepth) returns a template
template<typename T, typename DT> static void cvt_( const T* src, size_t sstep, DT* dst, size_t dstep, Size size ) What is the point of having cvt_ as template if it's always typecasted as BinaryFunc? In case of cvt8u32f for example, getConvertFunc should return cvt_<short, float>. But because it is typecasted, wouldn't it return cvt_<uchar, uchar>?
Also, I tried to replicate the code in convert.cpp in the following manner :
template<typename TS, typename TD> static void test_(TS src, TD dst) { dst = (TD)(src * dst); cout << src << " " << dst << " " << __func__ << endl; } #define GET_NAME(suffix, stype, dtype) \ void test_##suffix(stype src, dtype dst) \ {\ test_(src, dst); \ } GET_NAME(32f32s, float, int) GET_NAME(32f64f, float, double) int main(int argc, char **argv) { typedef void (*func)(int, int); func f1 = (func)(&test_32f32s); func f2 = (func)(&test_32f64f); f1(2.4f, 1); return 0; } I get src = 0 in test_. Why is this happening?
if the function pointer is defined as
typedef void (*func)(float, int); I get the desired result for f1.
Edit 1: If I call test_32f32s(2.4f, 1) then as well I get the desired result. But I tried to replicate the BinaryFunc syntax which isn't working.
Edit 2: Using a void* in typedef works somehow. Here's the code
template<typename TS, typename TD> static void test_(TS *src, TD *dst) { *dst = (TD)(*(TS*)src * *(TD*)dst); cout << *src << " " << *dst << " " << __func__ << endl; } #define GET_NAME(suffix, stype, dtype) \ void test_##suffix(stype *src, dtype *dst) \ {\ test_(src, dst); \ } GET_NAME(32f16s, float, int) GET_NAME(32f64f, float, double) typedef void (*func)(void*, void*); func getFunc(int type) { func fns[] = {(func)(test_32f16s), (func)(test_32f64f)}; return fns[type]; } int main(int argc, char **argv) { float tmpf = 10.0f; float *f = &tmpf; int tmpi = 2; int *i = &tmpi; double tmpd = 5.0; double *d = &tmpd; cout << *f << " " << *i << " " << *d << endl; func fnf = getFunc(0); fnf(f, i); func fnd = getFunc(1); fnd(f, d); } This is just to understand the style of coding used here.
template<typename T, typename DT> static void cvt_( const T* src, size_t sstep, DT* dst, size_t dstep, Size size )Where do you see this returning a template? The return type isvoid. Maybe the formatting (which I don't like) is throwing you off.invalid conversion from ‘void (*)(float, int)’ to ‘func {aka void (*)(int, int)}. But how are the function ptrs in convert.cpp typecasted?