00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #ifndef OSGIMAGEFILEHANDLER_CLASS_DECLARATION
00040 #define OSGIMAGEFILEHANDLER_CLASS_DECLARATION
00041 #ifdef __sgi
00042 #pragma once
00043 #endif
00044
00045 #include <list>
00046 #include <map>
00047
00048 #include <OSGSystemDef.h>
00049 #include <OSGBaseTypes.h>
00050 #include <OSGIDStringLink.h>
00051 #include <OSGImageFileType.h>
00052 #include <iosfwd>
00053
00054
00055 OSG_BEGIN_NAMESPACE
00056
00057 class PathHandler;
00058
00063 class OSG_SYSTEMLIB_DLLMAPPING ImageFileHandler {
00064
00065 friend class ImageFileType;
00066
00067
00068 public:
00069
00073 virtual ~ImageFileHandler (void);
00074
00076
00080 virtual ImagePtr read ( const char *fileName, const char *mimeType = 0);
00081
00082 virtual bool read ( ImagePtr &image,
00083 const char *fileName, const char *mimeType = 0);
00084
00085 virtual bool write ( const ImagePtr &image,
00086 const char *fileName, const char *mimeType = 0);
00087
00088 virtual ImagePtr read ( std::istream &is, const std::string &mimeType);
00089
00090 virtual bool read ( ImagePtr &image,
00091 std::istream &is, const std::string &mimeType);
00092
00093 virtual bool write ( const ImagePtr &image,
00094 std::ostream &os, const std::string &mimeType);
00095
00097
00101 typedef ImagePtr (*readcbfp) (const char *fileName, const char *mimeType);
00102 void setReadCB(readcbfp fp);
00103 readcbfp getReadCB(void);
00104
00106
00110 virtual PathHandler* getPathHandler(void );
00111 virtual void setPathHandler(PathHandler *pPathHandler);
00112
00114
00118 virtual bool setOptions(const Char8 *suffix, const Char8 *options);
00119 virtual const Char8 *getOptions(const Char8 *suffix);
00120
00122
00126 virtual UInt64 restore ( ImagePtr &image,
00127 const UChar8 *buffer, Int32 memSize = -1 );
00128
00129 virtual UInt64 store ( const ImagePtr &image, const char *mimeType,
00130 UChar8 *buffer, Int32 memSize = -1 );
00131
00132 virtual UChar8* store ( const ImagePtr &image, UInt64 &memSize,
00133 const char *mimeType = 0);
00135
00139 ImageFileType * getFileType ( const char *mimeType,
00140 const char *fileName = 0,
00141 bool validateHeader = false);
00142
00143 ImageFileType * getDefaultType (void);
00144
00145 virtual int getSuffixList(std::list<const Char8*> & suffixList,
00146 UInt32 flags = ImageFileType::OSG_READ_SUPPORTED |
00147 ImageFileType::OSG_WRITE_SUPPORTED);
00148
00149 std::string determineMimetypeFromName(const std::string &fileName);
00150
00151 std::string determineMimetypeFromSuffix(const std::string &suffix);
00152
00153 std::string determineMimetypeFromStream(std::istream &is);
00154
00156
00160 void dump (void);
00161
00163
00167 static ImageFileHandler & the (void);
00168
00171
00172 protected:
00173
00174
00175 private:
00176
00177 static ImageFileHandler *_the;
00178
00179 std::map<std::string, ImageFileType *> _suffixTypeMap;
00180
00181 typedef std::map<std::string, ImageFileType*> TypeMap;
00182
00183 TypeMap _typeMap;
00184
00185 static bool addImageFileType (ImageFileType &fileType);
00186
00187 static void normalizeMimetype(std::string &mimetype);
00188
00189 static void normalizeSuffix(std::string &suffix);
00190
00191 PathHandler* _pPathHandler;
00192 readcbfp _readFP;
00193
00194 static const std::string _fileNameKey;
00195
00196 static const std::string _fullFilePathKey;
00197
00198
00202 ImageFileHandler (void);
00203
00205
00209 ImageFileHandler(const ImageFileHandler &obj);
00210
00212
00216 const ImageFileHandler & operator= (const ImageFileHandler &obj);
00217
00219 };
00220
00221 typedef ImageFileHandler* ImageFileHandlerP;
00222
00223 OSG_END_NAMESPACE
00224
00225 #endif // OSGIMAGEFILEHANDLER_CLASS_DECLARATION