#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->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()); } } // }}} #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 **poDst){ // {{{ open printf("in apply \n"); ICLASSERT_RETURN( poSrc1 ); ICLASSERT_RETURN( poSrc2 ); if(!BinaryOp::check(poSrc1,poSrc2) || !BinaryOp::prepare(poDst,poSrc1)){ return; } switch(m_eOpType){ case andOp: apply_op(poSrc1,poSrc2,*poDst); break; case orOp: apply_op(poSrc1,poSrc2,*poDst); break; case xorOp: apply_op(poSrc1,poSrc2,*poDst); break; } } // }}} }