#include #include using namespace std; namespace icl { // {{{ constructor / destructor ImgBase::ImgBase(depth d, const ImgParams ¶ms):m_oParams(params),m_eDepth(d) { // {{{ open FUNCTION_LOG("ImgBase(" << getWidth() << "," << getHeight() << "," << translateFormat(getFormat()) << ", "<< translateDepth(getDepth()) << "," << getChannels() << ") this:" << this); } // }}} ImgBase::~ImgBase(){ // {{{ open FUNCTION_LOG(""); } // }}} // }}} // {{{ utility functions void ImgBase::print(const string sTitle) const{ // {{{ open FUNCTION_LOG(sTitle); printf( " -----------------------------------------\n" "| image: %s\n" "| timestamp: %s\n" "| width: %d, height: %d, channels: %d\n",sTitle.c_str(), this->getTime().toString().c_str(), getSize().width,getSize().height,getChannels()); printf( "| depth: %s format: %s\n",translateDepth(getDepth()).c_str(), translateFormat(getFormat()).c_str()); printf( "| ROI: x: %d, y: %d, w: %d, h: %d \n", getROI().x, getROI().y,getROI().width, getROI().height); switch (m_eDepth){ #define ICL_INSTANTIATE_DEPTH(D) case depth##D: \ for(int i=0;i()->getMin(i)),(double)(asImg()->getMax(i))); \ } \ break; ICL_INSTANTIATE_ALL_DEPTHS; default: ICL_INVALID_DEPTH; break; #undef ICL_INSTANTIATE_DEPTH } printf(" -----------------------------------------\n"); } // }}} // }}} // {{{ convert(depth) ImgBase *ImgBase::convert(depth d) const{ FUNCTION_LOG(""); switch(d){ #define ICL_INSTANTIATE_DEPTH(D) case depth##D: return this->convert((Img*)0); break; ICL_INSTANTIATE_ALL_DEPTHS; #undef ICL_INSTANTIATE_DEPTH default: ICL_INVALID_FORMAT; break; } } // }}} // {{{ convert(ImgBase *poDst) ImgBase *ImgBase::convert(ImgBase *poDst) const{ FUNCTION_LOG(""); if(!poDst) return deepCopy(); switch(poDst->getDepth()){ #define ICL_INSTANTIATE_DEPTH(D) case depth##D: return this->convert(poDst->asImg()); break; ICL_INSTANTIATE_ALL_DEPTHS; #undef ICL_INSTANTIATE_DEPTH default: ICL_INVALID_FORMAT; break; } } // }}} // {{{ convert(Img*) template Img *ImgBase::convert(Img *poDst) const{ FUNCTION_LOG("ptr:"<(getParams()); else poDst->setParams(getParams()); poDst->setTime(getTime()); #define ICL_INSTANTIATE_DEPTH(D) \ case depth##D: for(int c=getChannels()-1;c>=0;--c){ \ icl::convert(asImg()->getData(c), \ asImg()->getData(c)+getDim(),poDst->getData(c)); \ } break; switch(getDepth()){ ICL_INSTANTIATE_ALL_DEPTHS; } #undef ICL_INSTANTIATE_DEPTH return poDst; } // }}} // {{{ convertROI(depth) ImgBase *ImgBase::convertROI(depth d) const{ FUNCTION_LOG(""); switch(d){ #define ICL_INSTANTIATE_DEPTH(D) case depth##D: return this->convertROI((Img*)0); break; ICL_INSTANTIATE_ALL_DEPTHS; #undef ICL_INSTANTIATE_DEPTH default: ICL_INVALID_FORMAT; break; } } // }}} // {{{ convertROI(ImgBase *) ImgBase *ImgBase::convertROI(ImgBase *poDst) const{ FUNCTION_LOG(""); if(!poDst) return deepCopy(); switch(poDst->getDepth()){ #define ICL_INSTANTIATE_DEPTH(D) case depth##D: return this->convertROI(poDst->asImg()); break; ICL_INSTANTIATE_ALL_DEPTHS; #undef ICL_INSTANTIATE_DEPTH default: ICL_INVALID_FORMAT; break; } } // }}} // {{{ convertROI(Img*) template Img *ImgBase::convertROI(Img *poDst) const{ /// new using src and dst ROI FUNCTION_LOG("ptr:"<(getROISize(),getChannels(),getFormat()); }else{ ICLASSERT( poDst->getROISize() == getROISize() ); poDst->setChannels(getChannels()); poDst->setFormat(getFormat()); } poDst->setTime(getTime()); #define ICL_INSTANTIATE_DEPTH(D) \ case depth##D: \ for(int c=getChannels()-1;c>=0;--c){ \ convertChannelROI(asImg(),c,getROIOffset(),getROISize(), \ poDst,c,poDst->getROIOffset(),poDst->getROISize()); \ } \ break; switch(getDepth()){ ICL_INSTANTIATE_ALL_DEPTHS; } #undef ICL_INSTANTIATE_DEPTH return poDst; } // }}} // {{{ setFormat void ImgBase::setFormat(format fmt){ FUNCTION_LOG(""); int newcc = getChannelsOfFormat(fmt); if(fmt != formatMatrix && newcc != getChannels()){ setChannels(newcc); } m_oParams.setFormat(fmt); } // }}} // {{{ clear void ImgBase::clear(int iChannel, icl64f val, bool bROIOnly){ FUNCTION_LOG(""); switch(getDepth()){ #define ICL_INSTANTIATE_DEPTH(D) \ case depth##D: \ asImg()->clear(iChannel, \ clipped_cast(val), \ bROIOnly); break; ICL_INSTANTIATE_ALL_DEPTHS; #undef ICL_INSTANTIATE_DEPTH } } // }}} // {{{ normalizeXXX void ImgBase::normalizeAllChannels(const Range &dstRange){ FUNCTION_LOG(""); switch(getDepth()){ #define ICL_INSTANTIATE_DEPTH(D) \ case depth##D: asImg()->normalizeAllChannels( \ dstRange.castTo()); break; ICL_INSTANTIATE_ALL_DEPTHS; #undef ICL_INSTANTIATE_DEPTH } } void ImgBase::normalizeChannel(int iChannel,const Range &srcRange,const Range &dstRange){ FUNCTION_LOG(""); switch(getDepth()){ #define ICL_INSTANTIATE_DEPTH(D) \ case depth##D: asImg()->normalizeChannel(iChannel, \ srcRange.castTo(), \ dstRange.castTo()); break; ICL_INSTANTIATE_ALL_DEPTHS; #undef ICL_INSTANTIATE_DEPTH } } void ImgBase::normalizeChannel(int iChannel,const Range &dstRange){ FUNCTION_LOG(""); switch(getDepth()){ #define ICL_INSTANTIATE_DEPTH(D) \ case depth##D: asImg()->normalizeChannel(iChannel, \ dstRange.castTo()); break; ICL_INSTANTIATE_ALL_DEPTHS; #undef ICL_INSTANTIATE_DEPTH } } void ImgBase::normalizeImg(const Range &srcRange,const Range &dstRange){ FUNCTION_LOG(""); switch(getDepth()){ #define ICL_INSTANTIATE_DEPTH(D) \ case depth##D: asImg()->normalizeImg( \ srcRange.castTo(), \ dstRange.castTo()); break; ICL_INSTANTIATE_ALL_DEPTHS; #undef ICL_INSTANTIATE_DEPTH } } void ImgBase::normalizeImg(const Range &dstRange){ FUNCTION_LOG(""); switch(getDepth()){ #define ICL_INSTANTIATE_DEPTH(D) \ case depth##D: asImg()->normalizeImg( \ dstRange.castTo()); break; ICL_INSTANTIATE_ALL_DEPTHS; #undef ICL_INSTANTIATE_DEPTH } } // }}} // {{{ getMin,getMax, getMinMax icl64f ImgBase::getMax(int iChannel, Point *coords) const{ FUNCTION_LOG(""); switch(getDepth()){ #define ICL_INSTANTIATE_DEPTH(D) case depth##D: return asImg()->getMax(iChannel,coords); ICL_INSTANTIATE_ALL_DEPTHS; #undef ICL_INSTANTIATE_DEPTH } return 0; } /// Returns min pixel value of channel iChannel within ROI /** @param iChannel Index of channel **/ icl64f ImgBase::getMin(int iChannel, Point *coords) const{ FUNCTION_LOG(""); switch(getDepth()){ #define ICL_INSTANTIATE_DEPTH(D) case depth##D: return asImg()->getMin(iChannel,coords); ICL_INSTANTIATE_ALL_DEPTHS; #undef ICL_INSTANTIATE_DEPTH } return 0; } /// return maximal pixel value over all channels (restricted to ROI) icl64f ImgBase::getMin() const{ FUNCTION_LOG(""); switch(getDepth()){ #define ICL_INSTANTIATE_DEPTH(D) case depth##D: return asImg()->getMin(); ICL_INSTANTIATE_ALL_DEPTHS; #undef ICL_INSTANTIATE_DEPTH } return 0; } /// return minimal pixel value over all channels (restricted to ROI) icl64f ImgBase::getMax() const{ FUNCTION_LOG(""); switch(getDepth()){ #define ICL_INSTANTIATE_DEPTH(D) case depth##D: return asImg()->getMax(); ICL_INSTANTIATE_ALL_DEPTHS; #undef ICL_INSTANTIATE_DEPTH } return 0; } /// Returns min and max pixel values of channel iChannel within ROI /** @param rtMin reference to store the min value @param rtMax reference to store the max value @param iChannel Index of channel **/ const Range ImgBase::getMinMax(int iChannel, Point *minCoords, Point *maxCoords) const{ FUNCTION_LOG(""); switch(getDepth()){ #define ICL_INSTANTIATE_DEPTH(D) case depth##D: return asImg()->getMinMax(iChannel,minCoords,maxCoords).castTo(); ICL_INSTANTIATE_ALL_DEPTHS; #undef ICL_INSTANTIATE_DEPTH } return Range(); } /// return minimal and maximal pixel values over all channels (restricted to ROI) const Range ImgBase::getMinMax() const{ FUNCTION_LOG(""); switch(getDepth()){ #define ICL_INSTANTIATE_DEPTH(D) case depth##D: return asImg()->getMinMax().castTo(); ICL_INSTANTIATE_ALL_DEPTHS; #undef ICL_INSTANTIATE_DEPTH } return Range(); } // }}} // {{{ setParams void ImgBase::setParams(const ImgParams ¶ms){ FUNCTION_LOG(""); setChannels(params.getChannels()); setSize(params.getSize()); setFormat(params.getFormat()); setROI(params.getROI()); } // }}} std::ostream &operator<<(std::ostream &s, const ImgBase &image){ return s << "Img<" << image.getDepth() << ">(Size("<