OSGImageFileHandler.h

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002  *                                OpenSG                                     *
00003  *                                                                           *
00004  *                                                                           *
00005  *             Copyright (C) 2000-2002 by the OpenSG Forum                   *
00006  *                                                                           *
00007  *                            www.opensg.org                                 *
00008  *                                                                           *
00009  *   contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de          *
00010  *                                                                           *
00011 \*---------------------------------------------------------------------------*/
00012 /*---------------------------------------------------------------------------*\
00013  *                                License                                    *
00014  *                                                                           *
00015  * This library is free software; you can redistribute it and/or modify it   *
00016  * under the terms of the GNU Library General Public License as published    *
00017  * by the Free Software Foundation, version 2.                               *
00018  *                                                                           *
00019  * This library is distributed in the hope that it will be useful, but       *
00020  * WITHOUT ANY WARRANTY; without even the implied warranty of                *
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
00022  * Library General Public License for more details.                          *
00023  *                                                                           *
00024  * You should have received a copy of the GNU Library General Public         *
00025  * License along with this library; if not, write to the Free Software       *
00026  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 *
00027  *                                                                           *
00028 \*---------------------------------------------------------------------------*/
00029 /*---------------------------------------------------------------------------*\
00030  *                                Changes                                    *
00031  *                                                                           *
00032  *                                                                           *
00033  *                                                                           *
00034  *                                                                           *
00035  *                                                                           *
00036  *                                                                           *
00037 \*---------------------------------------------------------------------------*/
00038 
00039 #ifndef _OSGIMAGEFILEHANDLER_H_
00040 #define _OSGIMAGEFILEHANDLER_H_
00041 
00042 #ifdef  __sgi
00043 #pragma  once
00044 #endif
00045 
00046 #include <list>
00047 #include <map>
00048 
00049 #include "OSGSystemDef.h"
00050 #include "OSGIDStringLink.h"
00051 #include "OSGImageFileType.h"
00052 #include "OSGSingletonHolder.h"
00053 
00054 
00055 OSG_BEGIN_NAMESPACE
00056 
00057 class PathHandler;
00058 
00063 class OSG_SYSTEM_DLLMAPPING ImageFileHandlerBase 
00064 {
00065 
00066     friend class ImageFileType;
00067 
00068     /*==========================  PUBLIC  =================================*/
00069 
00070   public:
00071 
00072     typedef ImagePtr (*ReadCB) (const Char8 *fileName, const Char8 *mimeType);
00073 
00074     /*---------------------------------------------------------------------*/
00078     virtual ImagePtr read (const Char8            *fileName, 
00079                            const Char8            *mimeType = 0);
00080 
00081     virtual bool     read (      ImagePtrArg       pImage,
00082                            const Char8            *fileName, 
00083                            const Char8            *mimeType = 0);
00084 
00085     virtual bool     write(      ImageConstPtrArg  pImage,
00086                            const Char8            *fileName, 
00087                            const Char8            *mimeType = 0);
00088 
00089 
00090     virtual ImagePtr read (      std::istream     &is,
00091                            const std::string      &mimeType    );
00092 
00093     virtual bool     read (      ImagePtrArg       pImage,
00094                                  std::istream     &is,
00095                            const std::string      &mimeType    );
00096 
00097     virtual bool     write(      ImageConstPtrArg  pImage,
00098                                  std::ostream     &os,
00099                            const std::string      &mimeType    );
00100 
00101     
00103     /*---------------------------------------------------------------------*/
00107     void   setReadCB(ReadCB pCB);
00108     ReadCB getReadCB(void      );
00109 
00111     /*---------------------------------------------------------------------*/
00115     virtual PathHandler *getPathHandler(void                     );
00116     virtual void         setPathHandler(PathHandler *pPathHandler);
00117     
00119     /*---------------------------------------------------------------------*/
00123     virtual       bool          setOptions(const Char8 *suffix, 
00124                                            const Char8 *options);
00125     virtual const Char8        *getOptions(const Char8 *suffix);
00126 
00128     /*---------------------------------------------------------------------*/
00132     virtual UInt64  restore(      ImagePtrArg       pImage,
00133                             const UChar8           *buffer, 
00134                                   Int32             memSize = -1);
00135 
00136     virtual UInt64  store  (      ImageConstPtrArg  pImage, 
00137                             const Char8            *mimeType,
00138                                   UChar8           *buffer, 
00139                                   Int32             memSize = -1);
00140 
00141     virtual UChar8 *store  (      ImageConstPtrArg  pImage, 
00142                                   UInt64           &memSize,
00143                             const Char8            *mimeType = 0);
00144 
00146     /*---------------------------------------------------------------------*/
00150     ImageFileType *getFileType   (const Char8 *mimeType,
00151                                   const Char8 *fileName       = 0,
00152                                         bool   validateHeader = false);
00153 
00154     ImageFileType *getDefaultType(void);
00155 
00156 
00158     /*---------------------------------------------------------------------*/
00162     std::string    determineMimetypeFromName  (const std::string  &fileName);
00163 
00164     std::string    determineMimetypeFromStream(      std::istream &is      );
00165 
00166     std::string    determineMimetypeFromSuffix(const std::string  &suffix  );
00167 
00169     /*---------------------------------------------------------------------*/
00173     virtual int getSuffixList(
00174         std::list<const Char8*> &suffixList,
00175              UInt32              flags = (ImageFileType::OSG_READ_SUPPORTED |
00176                                           ImageFileType::OSG_WRITE_SUPPORTED));
00177 
00179     /*---------------------------------------------------------------------*/
00183     void dump(void);
00184 
00186     /*---------------------------------------------------------------------*/
00192     /*=========================  PROTECTED  ===============================*/
00193 
00194   protected:
00195     
00196     typedef std::map<std::string, ImageFileType *> TypeMap;
00197 
00198     ReadCB       _pReadCallback;
00199 
00200     PathHandler *_pPathHandler;
00201 
00202     TypeMap      _suffixTypeMap;
00203     TypeMap      _mimeTypeMap;
00204 
00205     static const std::string _fileNameKey;
00206     static const std::string _fullFilePathKey;
00207 
00208            bool addImageFileType (ImageFileType &fileType);
00209 
00210     static void normalizeMimetype(std::string   &mimetype);
00211 
00212     static void normalizeSuffix  (std::string   &suffix  );
00213 
00214     /*==========================  PRIVATE  ================================*/
00215 
00216   private:
00217 
00218     template <class SingletonT>
00219     friend class SingletonHolder;
00220 
00221     /*---------------------------------------------------------------------*/
00225     ImageFileHandlerBase(void);
00226 
00228     /*---------------------------------------------------------------------*/
00232           ImageFileHandlerBase            (const ImageFileHandlerBase &obj);
00233     const ImageFileHandlerBase &operator =(const ImageFileHandlerBase &obj);
00234 
00236     /*---------------------------------------------------------------------*/
00240     virtual ~ImageFileHandlerBase(void);
00241 
00243 };
00244 
00245 #if defined(WIN32)
00246 #    if !defined(OSG_COMPILE_IMAGEFILEHANDLER)
00247 OSG_SYSTEM_EXPIMP_TMPL 
00248 template class OSG_SYSTEM_DLLMAPPING SingletonHolder<ImageFileHandlerBase>;
00249 #    endif
00250 #endif
00251 
00252 typedef SingletonHolder<ImageFileHandlerBase> ImageFileHandler;
00253 
00254 typedef ImageFileHandler *ImageFileHandlerP;
00255 
00256 OSG_END_NAMESPACE
00257 
00258 #endif // _OSGIMAGEFILEHANDLER_H_