#include #include #include #include #include using namespace std; using namespace icl::ioutils; namespace icl{ 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 = ioutils::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