/* * libopenraw - ordiag.cpp * * Copyright (C) 2007 Hubert Figuiere * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include #include #include #include using OpenRaw::RawFile; using OpenRaw::Thumbnail; /** * Dump on RawFile. (functor) */ class OrDiag { public: /** constructor * @param out the output stream */ OrDiag(std::ostream & out) : m_out(out) { } std::string dataTypeToString(Thumbnail::DataType t) { switch(t) { case OR_DATA_TYPE_NONE: return "None"; break; case OR_DATA_TYPE_PIXMAP_8RGB: return "8bits per channel RGB pixmap"; break; case OR_DATA_TYPE_JPEG: return "JPEG data"; break; case OR_DATA_TYPE_TIFF: return "TIFF container"; break; case OR_DATA_TYPE_PNG: return "PNG container"; break; case OR_DATA_TYPE_UNKNOWN: return "Unknown type"; break; default: break; } return "Invalid"; } /** return a string for the raw file type */ std::string typeToString(RawFile::Type t) { switch(t) { case OR_RAWFILE_TYPE_UNKNOWN: break; case OR_RAWFILE_TYPE_CR2: return "Canon CR2"; break; case OR_RAWFILE_TYPE_CRW: return "Canon CRW"; break; case OR_RAWFILE_TYPE_NEF: return "Nikon NEF"; break; case OR_RAWFILE_TYPE_MRW: return "Minolta MRW"; break; case OR_RAWFILE_TYPE_ARW: return "Sony ARW"; break; case OR_RAWFILE_TYPE_DNG: return "Adobe DNG"; break; case OR_RAWFILE_TYPE_ORF: return "Olympus ORF"; break; case OR_RAWFILE_TYPE_PEF: return "Pentax PEF"; break; default: break; } return "Unknown"; } /** dump the previews of the raw file to mout */ void dumpPreviews(RawFile * rf) { const std::vector & previews = rf->listThumbnailSizes(); m_out << boost::format("\tNumber of previews: %1%\n") % previews.size(); m_out << "\tAvailable previews:\n"; for(std::vector::const_iterator iter = previews.begin(); iter != previews.end(); iter++) { m_out << boost::format("\t\tSize %1%\n") % *iter; Thumbnail thumb; ::or_error err = rf->getThumbnail(*iter, thumb); if (err != OR_ERROR_NONE) { m_out << boost::format("\t\t\tError getting thumbnail %1%\n") % err; } else { m_out << boost::format("\t\t\tFormat %1%\n") % dataTypeToString(thumb.dataType()); } } } void operator()(const std::string &s) { m_out << boost::format("Dumping %1%\n") % s; RawFile * rf = RawFile::newRawFile(s.c_str()); if (rf == NULL) { m_out << "unrecognized file\n"; } else { m_out << boost::format("\tType = %1% (%2%)\n") % rf->type() % typeToString(rf->type()); dumpPreviews(rf); } } private: std::ostream & m_out; }; void print_help() { std::cerr << "ordiag [-v] [-h] [-d 0-9] [files...]\n"; std::cerr << "Print libopenraw diagnostics\n"; std::cerr << "\t-h: show this help\n"; std::cerr << "\t-v: show version\n"; std::cerr << "\t-d level: set debug / verbosity to level\n"; std::cerr << "\tfiles: the files to diagnose\n"; } void print_version() { std::cerr << "ordiag version 0.0 - (c) 2007 Hubert Figuiere\n"; } int main(int argc, char **argv) { int done = 0; int dbl = 0; std::vector files; OpenRaw::init(); int o; while((o = getopt(argc, argv, "hvd")) != -1) { switch (o) { case 'h': print_help(); done = 1; break; case 'v': print_version(); done = 1; break; case 'd': dbl++; break; case '?': break; default: break; } } if (done) { return 0; } for ( ; optind < argc; optind++) { files.push_back(argv[optind]); } if (files.empty()) { std::cerr << "missing file name.\n"; if (dbl) { print_version(); } print_help(); return 1; } if (dbl >=2) { or_debug_set_level(DEBUG2); } // do the business. for_each(files.begin(), files.end(), OrDiag(std::cout)); return 0; }