Fawkes API  Fawkes Development Version
filetype.h
00001 
00002 /***************************************************************************
00003  *  filetype.h - little utility to decide on filetype, this FireVision
00004  *               version can also detect FvRaw images.
00005  *
00006  *  Generated: Tue Feb 23 13:49:38 2005
00007  *  Copyright  2005-2007  Tim Niemueller [www.niemueller.de]
00008  *
00009  ****************************************************************************/
00010 
00011 /*  This program is free software; you can redistribute it and/or modify
00012  *  it under the terms of the GNU General Public License as published by
00013  *  the Free Software Foundation; either version 2 of the License, or
00014  *  (at your option) any later version. A runtime exception applies to
00015  *  this software (see LICENSE.GPL_WRE file mentioned below for details).
00016  *
00017  *  This program is distributed in the hope that it will be useful,
00018  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020  *  GNU Library General Public License for more details.
00021  *
00022  *  Read the full text in the LICENSE.GPL_WRE file in the doc directory.
00023  */
00024 
00025 #ifndef __FIREVISION_FVUTILS_FILETYPE_H_
00026 #define __FIREVISION_FVUTILS_FILETYPE_H_
00027 
00028 #include <core/exception.h>
00029 #include <utils/system/filetype.h>
00030 #include <fvutils/readers/fvraw.h>
00031 #include <fvutils/colormap/cmfile.h>
00032 #include <string>
00033 
00034 namespace firevision {
00035 #if 0 /* just to make Emacs auto-indent happy */
00036 }
00037 #endif
00038 
00039 inline std::string
00040 fv_filetype_file(const char *filename)
00041 {
00042   std::string rv;
00043 
00044   try {
00045     rv = fawkes::filetype_file(filename);
00046   } catch (fawkes::Exception &e) {
00047     // Some error occured, most likely libmagic was not available at compile
00048     // time, assume data to make our own checks, we just cannot detect JPG
00049     // and PNG in this case.
00050     rv = "data";
00051   }
00052 
00053   if ( rv == "data" ) {
00054     if ( FvRawReader::is_FvRaw(filename) ) {
00055       rv = "FvRaw";
00056     } else if ( ColormapFile::is_colormap_file(filename) ) {
00057       rv = "FvColormap";
00058     }
00059   }
00060 
00061   return rv;
00062 }
00063 
00064 } // end namespace firevision
00065 
00066 
00067 #endif