/******************************************************************** ** 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/UnaryLogicalOp.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 PixelFuncNoVal{ static inline T apply(const T t){ return t; } }; template struct PixelFuncNoVal{ static inline T apply(const T t){ return ~t; } }; template struct LoopFuncNoVal{ static inline void apply(const Img *src, Img *dst ){ for(int c=src->getChannels()-1; c >= 0; --c) { ImgIterator itDst = dst->beginROI(c); for(const ImgIterator itSrc = src->beginROI(c),itSrcEnd=src->endROI(c) ; itSrc!=itSrcEnd; ++itSrc, ++itDst){ *itDst = PixelFuncNoVal::apply(*itSrc); } } } }; template struct PixelFuncWithVal{ static inline T apply(const T t, T val){ return t &val; } }; template struct PixelFuncWithVal{ static inline T apply(const T t, T val){ return t & val; } }; template struct PixelFuncWithVal{ static inline T apply(const T t, T val){ return t | val; } }; template struct PixelFuncWithVal{ static inline T apply(const T t, T val){ return t ^ val; } }; template struct LoopFuncWithVal{ static inline void apply(const Img *src, Img *dst, T val ){ for(int c=src->getChannels()-1; c >= 0; --c) { ImgIterator itDst = dst->beginROI(c); for(const ImgIterator itSrc = src->beginROI(c),itSrcEnd = src->endROI(c) ; itSrc!=itSrcEnd; ++itSrc, ++itDst){ *itDst = PixelFuncWithVal::apply(*itSrc,val); } } } }; #ifdef ICL_HAVE_IPP // IPP function specializations for "no val": template inline void ipp_call_no_val(const Img *src, Img *dst){ // {{{ open for (int c=src->getChannels()-1; c >= 0; --c) { func (src->getROIData (c), src->getLineStep(), dst->getROIData (c), dst->getLineStep(), dst->getROISize()); } } #define CREATE_IPP_FUNCTIONS_FOR_OP(OP,IPPOP) \ template<> struct LoopFuncNoVal{ \ static inline void apply(const Img *src, Img *dst ){ ipp_call_no_val(src, dst); } \ } CREATE_IPP_FUNCTIONS_FOR_OP(not,Not); #undef CREATE_IPP_FUNCTIONS_FOR_OP /*** IPP function specializations for "with val": addOp=0, subOp=1, divOp=2, mulOp=3, ***/ template inline void ipp_call_with_val(const Img *src, Img *dst, T val){ for (int c=src->getChannels()-1; c >= 0; --c) { func (src->getROIData (c), src->getLineStep(),val, dst->getROIData (c), dst->getLineStep(), dst->getROISize()); } } #define CREATE_IPP_FUNCTIONS_FOR_OP(OP,IPPOP) \ template<> struct LoopFuncWithVal{ \ static inline void apply(const Img *src, Img *dst, icl8u val ){ \ ipp_call_with_val(src, dst,val); \ } \ }; \ template<> struct LoopFuncWithVal{ \ static inline void apply(const Img *src, Img *dst, icl32s val ){ \ ipp_call_with_val(src, dst,val); \ } \ } CREATE_IPP_FUNCTIONS_FOR_OP(and,AndC); CREATE_IPP_FUNCTIONS_FOR_OP(or,OrC); CREATE_IPP_FUNCTIONS_FOR_OP(xor,XorC); //fallback f16s TODO #undef CREATE_IPP_FUNCTIONS_FOR_OP #endif template void apply_unary_logical_op_no_val(const ImgBase *src, ImgBase *dst){ switch(src->getDepth()){ #define ICL_INSTANTIATE_DEPTH(D) case depth##D: LoopFuncNoVal::apply(src->asImg(),dst->asImg()); break; ICL_INSTANTIATE_ALL_INT_DEPTHS; #undef ICL_INSTANTIATE_DEPTH default: ICL_INVALID_DEPTH; } } template void apply_unary_logical_op_with_val(const ImgBase *src, ImgBase *dst, icl32s val){ switch(src->getDepth()){ #define ICL_INSTANTIATE_DEPTH(D) \ case depth##D: LoopFuncWithVal::apply(src->asImg(), \ dst->asImg(), clipped_cast(val)); break; ICL_INSTANTIATE_ALL_INT_DEPTHS; #undef ICL_INSTANTIATE_DEPTH default: ICL_INVALID_DEPTH; } } } // end of anonymous namespace void UnaryLogicalOp::apply(const ImgBase *poSrc, ImgBase **poDst){ ICLASSERT_RETURN( poSrc ); if(!UnaryOp::prepare(poDst,poSrc)) return; switch(m_eOpType){ case andOp: apply_unary_logical_op_with_val(poSrc,*poDst,m_dValue); break; case orOp: apply_unary_logical_op_with_val(poSrc,*poDst,m_dValue); break; case xorOp: apply_unary_logical_op_with_val(poSrc,*poDst,m_dValue); break; case notOp: apply_unary_logical_op_no_val(poSrc,*poDst); break; } } } // namespace filter }