/******************************************************************** ** 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 : ICLCore/src/ICLCore/ImgBuffer.cpp ** ** Module : ICLCore ** ** 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 using namespace icl::utils; using namespace icl::math; namespace icl{ namespace core{ struct ImgBuffer::Data{ std::vector bufs[depthLast+1]; }; ImgBuffer::ImgBuffer(){ data = new ImgBuffer::Data; } ImgBuffer::~ImgBuffer(){ delete data; } ImgBuffer *ImgBuffer::instance(){ static SmartPtr i = new ImgBuffer; return i.get(); } ImgBase *ImgBuffer::get(depth d){ switch(d){ #define ICL_INSTANTIATE_DEPTH(D) case depth##D: return get(); ICL_INSTANTIATE_ALL_DEPTHS #undef ICL_INSTANTIATE_DEPTH } return 0; } ImgBase *ImgBuffer::get(depth d, const Size &size, int channels){ switch(d){ #define ICL_INSTANTIATE_DEPTH(D) case depth##D: return get(size,channels); ICL_INSTANTIATE_ALL_DEPTHS #undef ICL_INSTANTIATE_DEPTH } return 0; } ImgBase *ImgBuffer::get(depth d, const ImgParams ¶ms){ switch(d){ #define ICL_INSTANTIATE_DEPTH(D) case depth##D: return get(params); ICL_INSTANTIATE_ALL_DEPTHS #undef ICL_INSTANTIATE_DEPTH } return 0; } template Img *ImgBuffer::get(const Size &size, int channels){ return get(ImgParams(size,channels)); } template Img *ImgBuffer::get(const ImgParams ¶ms){ std::vector &buf = data->bufs[getDepth()]; Img * independentOne = 0; std::vector::iterator begin = buf.begin(); std::vector::iterator end = buf.end(); for(std::vector::iterator it = begin; it != end; ++it){ if((*it)->isIndependent()){ if((*it)->getParams() == params){ return (*it)->asImg(); }else{ if(!independentOne){ independentOne = (*it)->asImg(); } } } } if(independentOne){ independentOne->setParams(params); return independentOne; }else{ buf.push_back(new Img(params)); return buf.back()->asImg(); } } template Img *ImgBuffer::get(){ std::vector &buf = data->bufs[getDepth()]; std::vector::iterator begin = buf.begin(); std::vector::iterator end = buf.end(); for(std::vector::iterator it = begin; it != end; ++it){ if((*it)->isIndependent()){ return (*it)->asImg(); } } buf.push_back(new Img); return buf.back()->asImg(); } #define ICL_INSTANTIATE_DEPTH(D) \ template ICLCore_API Img *ImgBuffer::get(); \ template ICLCore_API Img *ImgBuffer::get(const ImgParams&); \ template ICLCore_API Img *ImgBuffer::get(const Size&, int); ICL_INSTANTIATE_ALL_DEPTHS #undef ICL_INSTANTIATE_DEPTH } // namespace core }