#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 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->beginROI(c); for(const ImgIterator itSrc1 = src1->beginROI(c),itSrc2 = src2->beginROI(c), itEnd = src1->endROI(c); itSrc1 != itEnd; ++itSrc1, ++itSrc2, ++itDst){ *itDst = PixelFunc::apply(*itSrc1,*itSrc2); } } } }; // }}} #ifdef HAVE_IPP 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()); } } // }}} #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(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(and,And); CREATE_IPP_FUNCTIONS_FOR_OP(or,Or); CREATE_IPP_FUNCTIONS_FOR_OP(xor,Xor); #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_INT_DEPTHS; #undef ICL_INSTANTIATE_DEPTH default: ICL_INVALID_DEPTH; } } // }}} } // end of anonymous namespace void BinaryLogicalOp::apply(const ImgBase *poSrc1,const ImgBase *poSrc2, ImgBase **ppoDst){ // {{{ open ICLASSERT_RETURN( poSrc1 ); ICLASSERT_RETURN( poSrc2 ); ICLASSERT_RETURN( ppoDst ); ICLASSERT_RETURN( poSrc1 != *ppoDst && poSrc2 != *ppoDst ); if(!BinaryOp::check(poSrc1,poSrc2)){ ERROR_LOG("souce images are incompatible (aborting)"); return; } if(!BinaryOp::prepare(ppoDst,poSrc1)){ ERROR_LOG("unable to prepare destination image (aborting)"); return; } switch(m_eOpType){ case andOp: apply_op(poSrc1,poSrc2,*ppoDst); break; case orOp: apply_op(poSrc1,poSrc2,*ppoDst); break; case xorOp: apply_op(poSrc1,poSrc2,*ppoDst); break; } } // }}} }