Content-Length: 928166 | pFad | http://github.com/opencv/opencv/commit/d19dd94deefcc7ef700a6a872231cab3efc5dfc0

52 Moved IPP remap to HAL · opencv/opencv@d19dd94 · GitHub
Skip to content

Commit d19dd94

Browse files
committed
Moved IPP remap to HAL
1 parent c48dad1 commit d19dd94

File tree

4 files changed

+143
-156
lines changed

4 files changed

+143
-156
lines changed

hal/ipp/include/ipp_hal_imgproc.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,13 @@ int ipp_hal_warpPerspective(int src_type, const uchar *src_data, size_t src_step
2424
#define cv_hal_warpPerspective ipp_hal_warpPerspective
2525
#endif
2626

27+
28+
int ipp_hal_remap32f(int src_type, const uchar *src_data, size_t src_step, int src_width, int src_height,
29+
uchar *dst_data, size_t dst_step, int dst_width, int dst_height,
30+
float* mapx, size_t mapx_step, float* mapy, size_t mapy_step,
31+
int interpolation, int border_type, const double border_value[4]);
32+
#undef cv_hal_remap32f
33+
#define cv_hal_remap32f ipp_hal_remap32f
34+
35+
2736
#endif //__IPP_HAL_IMGPROC_HPP__

hal/ipp/src/precomp_ipp.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@
1111
#include "iw++/iw.hpp"
1212
#endif
1313

14+
static inline IppiSize ippiSize(size_t width, size_t height)
15+
{
16+
IppiSize size = { (int)width, (int)height };
17+
return size;
18+
}
19+
20+
static inline IppiSize ippiSize(const cv::Size & _size)
21+
{
22+
IppiSize size = { _size.width, _size.height };
23+
return size;
24+
}
25+
1426
static inline IppDataType ippiGetDataType(int depth)
1527
{
1628
depth = CV_MAT_DEPTH(depth);

hal/ipp/src/warp_ipp.cpp

Lines changed: 122 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,21 +133,22 @@ int ipp_hal_warpAffine(int src_type, const uchar *src_data, size_t src_step, int
133133
return CV_HAL_ERROR_OK;
134134
}
135135
#endif
136+
#endif
136137

137138
typedef IppStatus (CV_STDCALL* ippiSetFunc)(const void*, void *, int, IppiSize);
138139

139140
template <int channels, typename Type>
140-
bool IPPSetSimple(cv::Scalar value, void *dataPointer, int step, IppiSize &size, ippiSetFunc func)
141+
bool IPPSetSimple(const double value[4], void *dataPointer, int step, IppiSize &size, ippiSetFunc func)
141142
{
142143
//CV_INSTRUMENT_REGION_IPP();
143144

144145
Type values[channels];
145146
for( int i = 0; i < channels; i++ )
146147
values[i] = cv::saturate_cast<Type>(value[i]);
147-
return func(values, dataPointer, step, size) >= 0;
148+
return CV_INSTRUMENT_FUN_IPP(func, values, dataPointer, step, size) >= 0;
148149
}
149150

150-
static bool IPPSet(const cv::Scalar &value, void *dataPointer, int step, IppiSize &size, int channels, int depth)
151+
static bool IPPSet(const double value[4], void *dataPointer, int step, IppiSize &size, int channels, int depth)
151152
{
152153
//CV_INSTRUMENT_REGION_IPP();
153154

@@ -248,7 +249,7 @@ class IPPWarpPerspectiveInvoker :
248249
{
249250
IppiSize setSize = {dst.cols, range.end - range.start};
250251
void *dataPointer = dst.ptr(range.start);
251-
if( !IPPSet( cv::Scalar(borderValue[0], borderValue[1], borderValue[2], borderValue[3]), dataPointer, (int)dst.step[0], setSize, cnn, src.depth() ) )
252+
if( !IPPSet( borderValue, dataPointer, (int)dst.step[0], setSize, cnn, src.depth() ) )
252253
{
253254
*ok = false;
254255
return;
@@ -364,4 +365,120 @@ int ipp_hal_warpPerspective(int src_type, const uchar *src_data, size_t src_step
364365
return CV_HAL_ERROR_OK;
365366
}
366367
#endif
367-
#endif
368+
369+
typedef IppStatus(CV_STDCALL *ippiRemap)(const void *pSrc, IppiSize srcSize, int srcStep, IppiRect srcRoi,
370+
const Ipp32f *pxMap, int xMapStep, const Ipp32f *pyMap, int yMapStep,
371+
void *pDst, int dstStep, IppiSize dstRoiSize, int interpolation);
372+
373+
class IPPRemapInvoker : public cv::ParallelLoopBody
374+
{
375+
public:
376+
IPPRemapInvoker(int _src_type, const uchar *_src_data, size_t _src_step, int _src_width, int _src_height,
377+
uchar *_dst_data, size_t _dst_step, int _dst_width, float *_mapx, size_t _mapx_step, float *_mapy,
378+
size_t _mapy_step, ippiRemap _ippFunc, int _ippInterpolation, int _borderType, const double _borderValue[4], bool *_ok) :
379+
ParallelLoopBody(),
380+
src_type(_src_type), src(_src_data), src_step(_src_step), src_width(_src_width), src_height(_src_height),
381+
dst(_dst_data), dst_step(_dst_step), dst_width(_dst_width), mapx(_mapx), mapx_step(_mapx_step), mapy(_mapy),
382+
mapy_step(_mapy_step), ippFunc(_ippFunc), ippInterpolation(_ippInterpolation), borderType(_borderType), ok(_ok)
383+
{
384+
memcpy(this->borderValue, _borderValue, sizeof(this->borderValue));
385+
*ok = true;
386+
}
387+
388+
virtual void operator()(const cv::Range &range) const
389+
{
390+
IppiRect srcRoiRect = {0, 0, src_width, src_height};
391+
uchar *dst_roi_data = dst + range.start * dst_step;
392+
IppiSize dstRoiSize = ippiSize(dst_width, range.size());
393+
int depth = CV_MAT_DEPTH(src_type), cn = CV_MAT_CN(src_type);
394+
395+
if (borderType == cv::BORDER_CONSTANT &&
396+
!IPPSet(borderValue, dst_roi_data, (int)dst_step, dstRoiSize, cn, depth))
397+
{
398+
*ok = false;
399+
return;
400+
}
401+
402+
if (CV_INSTRUMENT_FUN_IPP(ippFunc, src, {src_width, src_height}, (int)src_step, srcRoiRect,
403+
mapx, (int)mapx_step, mapy, (int)mapy_step,
404+
dst_roi_data, (int)dst_step, dstRoiSize, ippInterpolation) < 0)
405+
*ok = false;
406+
else
407+
{
408+
CV_IMPL_ADD(CV_IMPL_IPP | CV_IMPL_MT);
409+
}
410+
}
411+
412+
private:
413+
int src_type;
414+
const uchar *src;
415+
size_t src_step;
416+
int src_width, src_height;
417+
uchar *dst;
418+
size_t dst_step;
419+
int dst_width;
420+
float *mapx;
421+
size_t mapx_step;
422+
float *mapy;
423+
size_t mapy_step;
424+
ippiRemap ippFunc;
425+
int ippInterpolation, borderType;
426+
double borderValue[4];
427+
bool *ok;
428+
};
429+
430+
int ipp_hal_remap32f(int src_type, const uchar *src_data, size_t src_step, int src_width, int src_height,
431+
uchar *dst_data, size_t dst_step, int dst_width, int dst_height,
432+
float *mapx, size_t mapx_step, float *mapy, size_t mapy_step,
433+
int interpolation, int border_type, const double border_value[4])
434+
{
435+
if ((interpolation == cv::INTER_LINEAR || interpolation == cv::INTER_CUBIC || interpolation == cv::INTER_NEAREST) &&
436+
(border_type == cv::BORDER_CONSTANT || border_type == cv::BORDER_TRANSPARENT))
437+
{
438+
int ippInterpolation =
439+
interpolation == cv::INTER_NEAREST ? IPPI_INTER_NN : interpolation == cv::INTER_LINEAR ? IPPI_INTER_LINEAR
440+
: IPPI_INTER_CUBIC;
441+
442+
/* C1 C2 C3 C4 */
443+
char impl[CV_DEPTH_MAX][4][3]={{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, //8U
444+
{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, //8S
445+
{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, //16U
446+
{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, //16S
447+
{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, //32S
448+
{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, //32F
449+
{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}}; //64F
450+
451+
if (impl[CV_TYPE(src_type)][CV_MAT_CN(src_type) - 1][interpolation] == 0)
452+
{
453+
return CV_HAL_ERROR_NOT_IMPLEMENTED;
454+
}
455+
456+
ippiRemap ippFunc =
457+
src_type == CV_8UC1 ? (ippiRemap)ippiRemap_8u_C1R : src_type == CV_8UC3 ? (ippiRemap)ippiRemap_8u_C3R
458+
: src_type == CV_8UC4 ? (ippiRemap)ippiRemap_8u_C4R
459+
: src_type == CV_16UC1 ? (ippiRemap)ippiRemap_16u_C1R
460+
: src_type == CV_16UC3 ? (ippiRemap)ippiRemap_16u_C3R
461+
: src_type == CV_16UC4 ? (ippiRemap)ippiRemap_16u_C4R
462+
: src_type == CV_32FC1 ? (ippiRemap)ippiRemap_32f_C1R
463+
: src_type == CV_32FC3 ? (ippiRemap)ippiRemap_32f_C3R
464+
: src_type == CV_32FC4 ? (ippiRemap)ippiRemap_32f_C4R
465+
: 0;
466+
467+
if (ippFunc)
468+
{
469+
bool ok;
470+
471+
IPPRemapInvoker invoker(src_type, src_data, src_step, src_width, src_height, dst_data, dst_step, dst_width,
472+
mapx, mapx_step, mapy, mapy_step, ippFunc, ippInterpolation, border_type, border_value, &ok);
473+
cv::Range range(0, dst_height);
474+
cv::parallel_for_(range, invoker, dst_width * dst_height / (double)(1 << 16));
475+
476+
if (ok)
477+
{
478+
CV_IMPL_ADD(CV_IMPL_IPP | CV_IMPL_MT);
479+
return CV_HAL_ERROR_OK;
480+
}
481+
}
482+
}
483+
return CV_HAL_ERROR_NOT_IMPLEMENTED;
484+
}

modules/imgproc/src/imgwarp.cpp

Lines changed: 0 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -60,66 +60,6 @@ using namespace cv;
6060
namespace cv
6161
{
6262

63-
#if defined (HAVE_IPP) && (!IPP_DISABLE_REMAP)
64-
typedef IppStatus (CV_STDCALL* ippiSetFunc)(const void*, void *, int, IppiSize);
65-
66-
template <int channels, typename Type>
67-
bool IPPSetSimple(cv::Scalar value, void *dataPointer, int step, IppiSize &size, ippiSetFunc func)
68-
{
69-
CV_INSTRUMENT_REGION_IPP();
70-
71-
Type values[channels];
72-
for( int i = 0; i < channels; i++ )
73-
values[i] = saturate_cast<Type>(value[i]);
74-
return func(values, dataPointer, step, size) >= 0;
75-
}
76-
77-
static bool IPPSet(const cv::Scalar &value, void *dataPointer, int step, IppiSize &size, int channels, int depth)
78-
{
79-
CV_INSTRUMENT_REGION_IPP();
80-
81-
if( channels == 1 )
82-
{
83-
switch( depth )
84-
{
85-
case CV_8U:
86-
return CV_INSTRUMENT_FUN_IPP(ippiSet_8u_C1R, saturate_cast<Ipp8u>(value[0]), (Ipp8u *)dataPointer, step, size) >= 0;
87-
case CV_16U:
88-
return CV_INSTRUMENT_FUN_IPP(ippiSet_16u_C1R, saturate_cast<Ipp16u>(value[0]), (Ipp16u *)dataPointer, step, size) >= 0;
89-
case CV_32F:
90-
return CV_INSTRUMENT_FUN_IPP(ippiSet_32f_C1R, saturate_cast<Ipp32f>(value[0]), (Ipp32f *)dataPointer, step, size) >= 0;
91-
}
92-
}
93-
else
94-
{
95-
if( channels == 3 )
96-
{
97-
switch( depth )
98-
{
99-
case CV_8U:
100-
return IPPSetSimple<3, Ipp8u>(value, dataPointer, step, size, (ippiSetFunc)ippiSet_8u_C3R);
101-
case CV_16U:
102-
return IPPSetSimple<3, Ipp16u>(value, dataPointer, step, size, (ippiSetFunc)ippiSet_16u_C3R);
103-
case CV_32F:
104-
return IPPSetSimple<3, Ipp32f>(value, dataPointer, step, size, (ippiSetFunc)ippiSet_32f_C3R);
105-
}
106-
}
107-
else if( channels == 4 )
108-
{
109-
switch( depth )
110-
{
111-
case CV_8U:
112-
return IPPSetSimple<4, Ipp8u>(value, dataPointer, step, size, (ippiSetFunc)ippiSet_8u_C4R);
113-
case CV_16U:
114-
return IPPSetSimple<4, Ipp16u>(value, dataPointer, step, size, (ippiSetFunc)ippiSet_16u_C4R);
115-
case CV_32F:
116-
return IPPSetSimple<4, Ipp32f>(value, dataPointer, step, size, (ippiSetFunc)ippiSet_32f_C4R);
117-
}
118-
}
119-
}
120-
return false;
121-
}
122-
#endif
12363

12464
/************** interpolation formulas and tables ***************/
12565

@@ -1572,57 +1512,7 @@ static bool ocl_logPolar(InputArray _src, OutputArray _dst,
15721512

15731513
#endif
15741514

1575-
#if defined HAVE_IPP && !IPP_DISABLE_REMAP
1576-
1577-
typedef IppStatus (CV_STDCALL * ippiRemap)(const void * pSrc, IppiSize srcSize, int srcStep, IppiRect srcRoi,
1578-
const Ipp32f* pxMap, int xMapStep, const Ipp32f* pyMap, int yMapStep,
1579-
void * pDst, int dstStep, IppiSize dstRoiSize, int interpolation);
1580-
1581-
class IPPRemapInvoker :
1582-
public ParallelLoopBody
1583-
{
1584-
public:
1585-
IPPRemapInvoker(Mat & _src, Mat & _dst, Mat & _xmap, Mat & _ymap, ippiRemap _ippFunc,
1586-
int _ippInterpolation, int _borderType, const Scalar & _borderValue, bool * _ok) :
1587-
ParallelLoopBody(), src(_src), dst(_dst), map1(_xmap), map2(_ymap), ippFunc(_ippFunc),
1588-
ippInterpolation(_ippInterpolation), borderType(_borderType), borderValue(_borderValue), ok(_ok)
1589-
{
1590-
*ok = true;
1591-
}
1592-
1593-
virtual void operator() (const Range & range) const
1594-
{
1595-
IppiRect srcRoiRect = { 0, 0, src.cols, src.rows };
1596-
Mat dstRoi = dst.rowRange(range);
1597-
IppiSize dstRoiSize = ippiSize(dstRoi.size());
1598-
int type = dst.type(), depth = CV_MAT_DEPTH(type), cn = CV_MAT_CN(type);
1599-
1600-
if (borderType == BORDER_CONSTANT &&
1601-
!IPPSet(borderValue, dstRoi.ptr(), (int)dstRoi.step, dstRoiSize, cn, depth))
1602-
{
1603-
*ok = false;
1604-
return;
1605-
}
1606-
1607-
if (CV_INSTRUMENT_FUN_IPP(ippFunc, src.ptr(), ippiSize(src.size()), (int)src.step, srcRoiRect,
1608-
map1.ptr<Ipp32f>(), (int)map1.step, map2.ptr<Ipp32f>(), (int)map2.step,
1609-
dstRoi.ptr(), (int)dstRoi.step, dstRoiSize, ippInterpolation) < 0)
1610-
*ok = false;
1611-
else
1612-
{
1613-
CV_IMPL_ADD(CV_IMPL_IPP|CV_IMPL_MT);
1614-
}
1615-
}
1616-
1617-
private:
1618-
Mat & src, & dst, & map1, & map2;
1619-
ippiRemap ippFunc;
1620-
int ippInterpolation, borderType;
1621-
Scalar borderValue;
1622-
bool * ok;
1623-
};
16241515

1625-
#endif
16261516

16271517
}
16281518

@@ -1737,47 +1627,6 @@ void cv::remap( InputArray _src, OutputArray _dst,
17371627

17381628
int type = src.type(), depth = CV_MAT_DEPTH(type);
17391629

1740-
#if defined HAVE_IPP && !IPP_DISABLE_REMAP
1741-
CV_IPP_CHECK()
1742-
{
1743-
if ((interpolation == INTER_LINEAR || interpolation == INTER_CUBIC || interpolation == INTER_NEAREST) &&
1744-
map1.type() == CV_32FC1 && map2.type() == CV_32FC1 &&
1745-
(borderType == BORDER_CONSTANT || borderType == BORDER_TRANSPARENT))
1746-
{
1747-
int ippInterpolation =
1748-
interpolation == INTER_NEAREST ? IPPI_INTER_NN :
1749-
interpolation == INTER_LINEAR ? IPPI_INTER_LINEAR : IPPI_INTER_CUBIC;
1750-
1751-
ippiRemap ippFunc =
1752-
type == CV_8UC1 ? (ippiRemap)ippiRemap_8u_C1R :
1753-
type == CV_8UC3 ? (ippiRemap)ippiRemap_8u_C3R :
1754-
type == CV_8UC4 ? (ippiRemap)ippiRemap_8u_C4R :
1755-
type == CV_16UC1 ? (ippiRemap)ippiRemap_16u_C1R :
1756-
type == CV_16UC3 ? (ippiRemap)ippiRemap_16u_C3R :
1757-
type == CV_16UC4 ? (ippiRemap)ippiRemap_16u_C4R :
1758-
type == CV_32FC1 ? (ippiRemap)ippiRemap_32f_C1R :
1759-
type == CV_32FC3 ? (ippiRemap)ippiRemap_32f_C3R :
1760-
type == CV_32FC4 ? (ippiRemap)ippiRemap_32f_C4R : 0;
1761-
1762-
if (ippFunc)
1763-
{
1764-
bool ok;
1765-
IPPRemapInvoker invoker(src, dst, map1, map2, ippFunc, ippInterpolation,
1766-
borderType, borderValue, &ok);
1767-
Range range(0, dst.rows);
1768-
parallel_for_(range, invoker, dst.total() / (double)(1 << 16));
1769-
1770-
if (ok)
1771-
{
1772-
CV_IMPL_ADD(CV_IMPL_IPP|CV_IMPL_MT);
1773-
return;
1774-
}
1775-
setIppErrorStatus();
1776-
}
1777-
}
1778-
}
1779-
#endif
1780-
17811630
RemapNNFunc nnfunc = 0;
17821631
RemapFunc ifunc = 0;
17831632
const void* ctab = 0;

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/opencv/opencv/commit/d19dd94deefcc7ef700a6a872231cab3efc5dfc0

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy