提交 9ee87bd0 编写于 作者: I Ilya Lavrenov

added parallel version of CvtColorLoop - main inner function of cvtColor

上级 c6e74119
...@@ -156,24 +156,44 @@ template<> struct ColorChannel<float> ...@@ -156,24 +156,44 @@ template<> struct ColorChannel<float>
///////////////////////////// Top-level template function //////////////////////////////// ///////////////////////////// Top-level template function ////////////////////////////////
template<class Cvt> void CvtColorLoop(const Mat& srcmat, Mat& dstmat, const Cvt& cvt) template <typename Cvt>
class CvtColorLoop_Invoker :
public ParallelLoopBody
{ {
typedef typename Cvt::channel_type _Tp; typedef typename Cvt::channel_type _Tp;
Size sz = srcmat.size(); public:
const uchar* src = srcmat.data;
uchar* dst = dstmat.data; CvtColorLoop_Invoker(const Mat& _src, Mat& _dst, const Cvt& _cvt) :
size_t srcstep = srcmat.step, dststep = dstmat.step; ParallelLoopBody(), src(_src), dst(_dst), cvt(_cvt)
if( srcmat.isContinuous() && dstmat.isContinuous() )
{ {
sz.width *= sz.height;
sz.height = 1;
} }
virtual void operator()(const Range& range) const
{
int i = range.start;
const uchar* yS = src.data + src.step * i;
uchar* yD = dst.data + dst.step * i;
for( ; sz.height--; src += srcstep, dst += dststep ) for ( ; i < range.end; ++i, yS += src.step, yD += dst.step )
cvt((const _Tp*)src, (_Tp*)dst, sz.width); cvt((const _Tp*)yS, (_Tp*)yD, src.cols);
} }
private:
const Mat src;
Mat dst;
const Cvt cvt;
CvtColorLoop_Invoker(const CvtColorLoop_Invoker&);
const CvtColorLoop_Invoker& operator= (const CvtColorLoop_Invoker&);
};
template <typename Cvt>
void CvtColorLoop(const Mat& src, Mat& dst, const Cvt& cvt)
{
Range range(0, src.rows);
CvtColorLoop_Invoker<Cvt> invoker(src, dst, cvt);
parallel_for_(range, invoker);
}
////////////////// Various 3/4-channel to 3/4-channel RGB transformations ///////////////// ////////////////// Various 3/4-channel to 3/4-channel RGB transformations /////////////////
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册