diff --git a/modules/imgproc/src/color.cpp b/modules/imgproc/src/color.cpp index 0dc95d17e02ef46f8c6d9b176e2d6bf37447aa81..25cdbeac336a4826db2a8dc28099609aaacfb847 100644 --- a/modules/imgproc/src/color.cpp +++ b/modules/imgproc/src/color.cpp @@ -156,24 +156,44 @@ template<> struct ColorChannel ///////////////////////////// Top-level template function //////////////////////////////// -template void CvtColorLoop(const Mat& srcmat, Mat& dstmat, const Cvt& cvt) +template +class CvtColorLoop_Invoker : + public ParallelLoopBody { typedef typename Cvt::channel_type _Tp; - Size sz = srcmat.size(); - const uchar* src = srcmat.data; - uchar* dst = dstmat.data; - size_t srcstep = srcmat.step, dststep = dstmat.step; - - if( srcmat.isContinuous() && dstmat.isContinuous() ) +public: + + CvtColorLoop_Invoker(const Mat& _src, Mat& _dst, const Cvt& _cvt) : + ParallelLoopBody(), src(_src), dst(_dst), cvt(_cvt) { - 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 ) - cvt((const _Tp*)src, (_Tp*)dst, sz.width); -} + for ( ; i < range.end; ++i, yS += src.step, yD += dst.step ) + 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 +void CvtColorLoop(const Mat& src, Mat& dst, const Cvt& cvt) +{ + Range range(0, src.rows); + CvtColorLoop_Invoker invoker(src, dst, cvt); + parallel_for_(range, invoker); +} ////////////////// Various 3/4-channel to 3/4-channel RGB transformations /////////////////