/******************************************************************** ** 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 : ICLIO/src/ICLIO/FileGrabberPluginPNM.cpp ** ** Module : ICLIO ** ** Authors: Christof Elbrechter, Michael Goetting ** ** ** ** ** ** 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 #include using namespace std; using namespace icl::utils; using namespace icl::core; namespace icl{ namespace io{ static int ti(const std::string &t) { return parse(t); } static std::vector vec3(int a, int b, int c){ int abc[] = {a,b,c}; return std::vector(abc,abc+3); } void FileGrabberPluginPNM::grab(File &file, ImgBase **dest){ ICLASSERT_RETURN(dest); file.open(File::readBinary); string nextLine; bool bIsICL = file.getSuffix() == ".icl" || file.getSuffix() == ".icl.gz"; ////////////////////////////////////////////////////////////////////// /// READ HEADER INFORMATION FROM THE FILE /////////////////////////// ////////////////////////////////////////////////////////////////////// FileGrabberPlugin::HeaderInfo oInfo; oInfo.imageFormat = formatGray; oInfo.imageDepth = depth8u; oInfo.channelCount = 0; oInfo.imageCount = 1; if(!bIsICL){ string l = file.readLine(); if(l.length() < 2 || l[0] != 'P') throw InvalidFileFormatException(); switch (l[1]) { case '6': oInfo.imageFormat = formatRGB; break; case '5': oInfo.imageFormat = formatGray; break; default: throw InvalidFileFormatException(); } } oInfo.channelCount = getChannelsOfFormat(oInfo.imageFormat); // {{{ Read special header info do { nextLine = skipWhitespaces(file.readLine()); vector ts = tok(nextLine," "); if(ts.size() < 3) continue; string sKey = ts[1]; if (sKey == "NumFeatures" || sKey == "NumImages") { oInfo.imageCount = parse(ts[2]); if(!oInfo.imageCount) throw InvalidFileFormatException(); oInfo.channelCount *= oInfo.imageCount; } else if (sKey == "ROI") { oInfo.roi = Rect(ti(ts[2]),ti(ts[3]),ti(ts[4]),ti(ts[5])); continue; } else if (sKey == "ImageDepth") { if (!bIsICL) continue; // ignore image depth for all formats but ICL oInfo.imageDepth = parse( ts[2] ); continue; } else if (sKey == "Format") { oInfo.imageFormat = parse(ts[2]); } else if (sKey == "TimeStamp") { oInfo.time = parse