/******************************************************************** ** Image Component Library (ICL) ** ** ** ** Copyright (C) 2006-2013 CITEC, University of Bielefeld ** ** Neuroinformatics Group ** ** Website: www.iclcv.org and ** ** http://opensource.cit-ec.de/projects/icl ** ** ** ** File : ICLFilter/src/ICLFilter/BinaryLogicalOp.cpp ** ** Module : ICLFilter ** ** Authors: Christof Elbrechter ** ** ** ** ** ** GNU LESSER GENERAL PUBLIC LICENSE ** ** This file may be used under the terms of the GNU Lesser General ** ** Public License version 3.0 as published by the ** ** ** ** Free Software Foundation and appearing in the file LICENSE.LGPL ** ** included in the packaging of this file. Please review the ** ** following information to ensure the license requirements will ** ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt ** ** ** ** The development of this software was supported by the ** ** Excellence Cluster EXC 277 Cognitive Interaction Technology. ** ** The Excellence Cluster EXC 277 is a grant of the Deutsche ** ** Forschungsgemeinschaft (DFG) in the context of the German ** ** Excellence Initiative. ** ** ** ********************************************************************/ #include #include #include using namespace icl::utils; using namespace icl::core; namespace icl { namespace filter{ 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 ICL_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; } } // }}} } // namespace filter }