/* ImgBase.cpp Written by: Michael Götting (2006) University of Bielefeld AG Neuroinformatik mgoettin@techfak.uni-bielefeld.de */ #include #include using namespace std; namespace icl { // {{{ constructor / destructor ImgBase::ImgBase(depth d, const ImgParams ¶ms): m_oParams(params),m_eDepth(d) { FUNCTION_LOG("ImgBase(" << getWidth() << "," << getHeight() << "," << translateFormat(getFormat()) << ", "<< translateDepth(getDepth()) << "," << getChannels() << ") this:" << this); } ImgBase::~ImgBase() { FUNCTION_LOG(""); } // }}} // {{{ utillity functions ImgBase* ImgBase::shallowCopy(ImgBase** ppoDst) const { FUNCTION_LOG(""); ImgBase* poDst = ppoDst ? *ppoDst : 0; // create image with zero channels if (!poDst) poDst = imgNew(getDepth(),getSize(),0,getROI()); else ensureDepth (&poDst, getDepth ()); switch (getDepth()){ case depth8u: *poDst->asImg() = *this->asImg(); break; case depth16s: *poDst->asImg() = *this->asImg(); break; case depth32s: *poDst->asImg() = *this->asImg(); break; case depth32f: *poDst->asImg() = *this->asImg(); break; case depth64f: *poDst->asImg() = *this->asImg(); break; default: ICL_INVALID_DEPTH; break; } if (ppoDst) *ppoDst = poDst; poDst->setTime(this->getTime()); return poDst; } ImgBase* ImgBase::shallowCopy(const std::vector& vChannels, ImgBase** ppoDst) const { FUNCTION_LOG(""); ImgBase* poDst = ppoDst ? *ppoDst : 0; // create image with zero channels if (!poDst) poDst = imgNew(getDepth(),getSize(),0,getROI()); else { poDst->setChannels (0); ensureDepth (&poDst, getDepth ()); poDst->setSize(getSize()); poDst->setROI (getROI()); } switch (getDepth()){ case depth8u: poDst->asImg()->append (this->asImg(), vChannels); break; case depth16s: poDst->asImg()->append (this->asImg(), vChannels); break; case depth32s: poDst->asImg()->append (this->asImg(), vChannels); break; case depth32f: poDst->asImg()->append (this->asImg(), vChannels); break; case depth64f: poDst->asImg()->append (this->asImg(), vChannels); break; default: ICL_INVALID_DEPTH; break; } if (ppoDst) *ppoDst = poDst; poDst->setTime(this->getTime()); return poDst; } void ImgBase::print(const string sTitle) const { 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){ case depth8u: for(int i=0;i()->getMin(i),asImg()->getMax(i)); } break; case depth16s: for(int i=0;i()->getMin(i),asImg()->getMax(i)); } break; case depth32s: for(int i=0;i()->getMin(i),asImg()->getMax(i)); } break; case depth32f: for(int i=0;i()->getMin(i),asImg()->getMax(i)); } break; case depth64f: for(int i=0;i()->getMin(i),asImg()->getMax(i)); } break; default: ICL_INVALID_DEPTH; break; } printf(" -----------------------------------------\n"); } // }}} // {{{ convertTo - template template Img *ImgBase::convertTo( Img* poDst) const { FUNCTION_LOG(""); if(!poDst) poDst = new Img(getParams()); else poDst->setParams(getParams()); poDst->setTime(this->getTime()); switch (getDepth()){ case depth8u: for(int c=0;c(asImg(),c,poDst,c); break; case depth16s: for(int c=0;c(asImg(),c,poDst,c); break; case depth32s: for(int c=0;c(asImg(),c,poDst,c); break; case depth32f: for(int c=0;c(asImg(),c,poDst,c); break; case depth64f: for(int c=0;c(asImg(),c,poDst,c); break; default: ICL_INVALID_FORMAT; break; } return poDst; } template Img* ImgBase::convertTo(Img*) const; template Img* ImgBase::convertTo(Img*) const; template Img* ImgBase::convertTo(Img*) const; template Img* ImgBase::convertTo(Img*) const; template Img* ImgBase::convertTo(Img*) const; // }}} // {{{ setFormat void ImgBase::setFormat(format fmt){ FUNCTION_LOG(""); int newcc = getChannelsOfFormat(fmt); if(fmt != formatMatrix && newcc != getChannels()){ setChannels(newcc); } m_oParams.setFormat(fmt); } // }}} // {{{ setParams void ImgBase::setParams(const ImgParams ¶ms){ FUNCTION_LOG(""); setChannels(params.getChannels()); setSize(params.getSize()); setFormat(params.getFormat()); setROI(params.getROI()); } // }}} } //namespace icl