#include #include #include namespace icl { namespace{ template struct PixelFunc{ static inline T apply(const T t1, const T t2){ return t1+t2; } }; template struct PixelFunc{ static inline T apply(const T t1, const T t2){ return t1+t2; } }; template struct PixelFunc{ static inline T apply(const T t1, const T t2){ return t1-t2; } }; template struct PixelFunc{ static inline T apply(const T t1, const T t2){ return t1*t2; } }; template struct PixelFunc{ static inline T apply(const T t1, const T t2){ return t1/t2; } }; template struct LoopFunc{ // {{{ open static inline void apply(const Img *src1, const Img *src2, Img *dst ){ for(int c=src1->getChannels()-1; c >= 0; --c) { ImgIterator itDst = dst->getROIIterator(c); for(ConstImgIterator itSrc1 = src1->getROIIterator(c),itSrc2 = src2->getROIIterator(c) ; itSrc1.inRegion(); ++itSrc1, ++itSrc2, ++itDst){ *itDst = PixelFunc::apply(*itSrc1,*itSrc2); } } } }; // }}} #ifdef WITH_IPP_OPTIMIZATION template inline void ipp_call(const Img *src1,const Img *src2, Img *dst){ // {{{ open for (int c=src1->getChannels()-1; c >= 0; --c) { func (src1->getROIData (c), src1->getLineStep(), src2->getROIData (c), src2->getLineStep(), dst->getROIData (c), dst->getLineStep(), dst->getROISize()); } } // }}} template inline void ipp_call_sfs(const Img *src1,const Img *src2, Img *dst){ // {{{ open for (int c=src1->getChannels()-1; c >= 0; --c) { func (src1->getROIData (c), src1->getLineStep(), src2->getROIData (c), src2->getLineStep(), dst->getROIData (c), dst->getLineStep(), dst->getROISize(), 0); } } // }}} #define CREATE_IPP_FUNCTIONS_FOR_OP(OP,IPPOP) \ template<> struct LoopFunc{ \ static inline void apply(const Img *src1,const Img *src2, Img *dst ){ \ ipp_call_sfs(src2,src1,dst); \ } \ }; \ template<> struct LoopFunc{ \ static inline void apply(const Img *src1,const Img *src2, Img *dst ){ \ ipp_call_sfs(src2,src1, dst); \ } \ }; \ template<> struct LoopFunc{ \ static inline void apply(const Img *src1,const Img *src2, Img *dst ){ \ ipp_call(src2,src1, dst); \ } \ } CREATE_IPP_FUNCTIONS_FOR_OP(add,Add); CREATE_IPP_FUNCTIONS_FOR_OP(sub,Sub); CREATE_IPP_FUNCTIONS_FOR_OP(mul,Mul); CREATE_IPP_FUNCTIONS_FOR_OP(div,Div); #undef CREATE_IPP_FUNCTIONS_FOR_OP #endif template void apply_op(const ImgBase *src1,const ImgBase *src2, ImgBase *dst){ // {{{ open switch(src1->getDepth()){ #define ICL_INSTANTIATE_DEPTH(D) case depth##D: LoopFunc::apply(src1->asImg(),src2->asImg(), dst->asImg()); break; ICL_INSTANTIATE_ALL_DEPTHS; #undef ICL_INSTANTIATE_DEPTH } } // }}} } // end of anonymous namespace void BinaryArithmeticalOp::apply(const ImgBase *poSrc1,const ImgBase *poSrc2, ImgBase **poDst){ // {{{ open ICLASSERT_RETURN( poSrc1 ); ICLASSERT_RETURN( poSrc2 ); if(!BinaryOp::check(poSrc1,poSrc2) || !BinaryOp::prepare(poDst,poSrc1)){ return; } switch(m_eOpType){ case addOp: apply_op(poSrc1,poSrc2,*poDst); break; case mulOp: apply_op(poSrc1,poSrc2,*poDst); break; case divOp: apply_op(poSrc1,poSrc2,*poDst); break; case subOp: apply_op(poSrc1,poSrc2,*poDst); break; } } // }}} }