PageRenderTime 326ms CodeModel.GetById 202ms app.highlight 61ms RepoModel.GetById 59ms app.codeStats 1ms

/Source/System/Image/OSGImageFileType.h

https://github.com/msteners/OpenSGDevMaster_Toolbox
C++ Header | 390 lines | 136 code | 100 blank | 154 comment | 0 complexity | 42cbf3b3a37875cfe246aac6bc79fabf MD5 | raw file
  1/*---------------------------------------------------------------------------*\
  2 *                                OpenSG                                     *
  3 *                                                                           *
  4 *                                                                           *
  5 *             Copyright (C) 2000-2002 by the OpenSG Forum                   *
  6 *                                                                           *
  7 *                            www.opensg.org                                 *
  8 *                                                                           *
  9 *   contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de          *
 10 *                                                                           *
 11\*---------------------------------------------------------------------------*/
 12/*---------------------------------------------------------------------------*\
 13 *                                License                                    *
 14 *                                                                           *
 15 * This library is free software; you can redistribute it and/or modify it   *
 16 * under the terms of the GNU Library General Public License as published    *
 17 * by the Free Software Foundation, version 2.                               *
 18 *                                                                           *
 19 * This library is distributed in the hope that it will be useful, but       *
 20 * WITHOUT ANY WARRANTY; without even the implied warranty of                *
 21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
 22 * Library General Public License for more details.                          *
 23 *                                                                           *
 24 * You should have received a copy of the GNU Library General Public         *
 25 * License along with this library; if not, write to the Free Software       *
 26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 *
 27 *                                                                           *
 28\*---------------------------------------------------------------------------*/
 29/*---------------------------------------------------------------------------*\
 30 *                                Changes                                    *
 31 *                                                                           *
 32 *                                                                           *
 33 *                                                                           *
 34 *                                                                           *
 35 *                                                                           *
 36 *                                                                           *
 37\*---------------------------------------------------------------------------*/
 38
 39#ifndef _OSGIMAGEFILETYPE_H_
 40#define _OSGIMAGEFILETYPE_H_
 41
 42#include <list>
 43
 44#include "OSGIOFileTypeBase.h"
 45#include "OSGImage.h"
 46#include "OSGGeoReferenceAttachment.h"
 47
 48#include "boost/shared_ptr.hpp"
 49
 50OSG_BEGIN_NAMESPACE
 51
 52class ImageFileType;
 53
 54
 55class OSG_SYSTEM_DLLMAPPING ImageBlockAccessor
 56{
 57    /*==========================  PUBLIC  =================================*/
 58    
 59  public:
 60
 61    /*---------------------------------------------------------------------*/
 62    /*! \name                   Destructor                                 */
 63    /*! \{                                                                 */
 64
 65    virtual ~ImageBlockAccessor(void);
 66
 67    /*! \}                                                                 */
 68    /*---------------------------------------------------------------------*/
 69    /*! \name                   Read/Write                                 */
 70    /*! \{                                                                 */
 71
 72    virtual bool isOpen(void) = 0;
 73
 74    /*! \}                                                                 */
 75    /*---------------------------------------------------------------------*/
 76    /*! \name                   Read/Write                                 */
 77    /*! \{                                                                 */
 78
 79    Vec2i              getSize       (void);
 80    
 81    Image::Type        getType       (void);
 82    Image::PixelFormat getFormat     (void);
 83
 84    Real64             getNoDataValue(void);
 85
 86    /*! \}                                                                 */
 87    /*---------------------------------------------------------------------*/
 88    /*! \name                   Read/Write                                 */
 89    /*! \{                                                                 */
 90
 91    GeoReferenceAttachment *getGeoRef(void);
 92
 93    /*! \}                                                                 */
 94    /*---------------------------------------------------------------------*/
 95    /*! \name                   Read/Write                                 */
 96    /*! \{                                                                 */
 97
 98    virtual bool readBlockA16(Vec2i   vSampleOrigin,
 99                              Int32   iTextureSize,
100                              UInt16 *pTarget,
101                              Int32   iTargetSizeBytes) = 0;
102
103    virtual bool readBlockA16(Vec2i   vSampleOrigin,
104                              Int32   iTextureSize,
105                              Int16  *pTarget,
106                              Int32   iTargetSizeBytes) = 0;
107
108    /*! \}                                                                 */
109    /*=========================  PROTECTED  ===============================*/
110
111  protected:
112
113    GeoReferenceAttachmentUnrecPtr _pGeoRef;
114    Vec2i                          _vSize;
115    Image::Type                    _eImgType;
116    Image::PixelFormat             _eImgFormat;
117    Real64                         _fNoDataValue;
118
119    /*---------------------------------------------------------------------*/
120    /*! \name                Default Constructor                           */
121    /*! \{                                                                 */
122
123    ImageBlockAccessor(void);
124
125    /*! \}                                                                 */
126    /*==========================  PRIVATE  ================================*/
127
128  private:
129};
130
131typedef boost::shared_ptr<ImageBlockAccessor> ImageBlockAccessorPtr;
132
133class OSG_SYSTEM_DLLMAPPING BlockAccessWrapper : public ImageBlockAccessor
134{
135    /*==========================  PUBLIC  =================================*/
136    
137  public:
138
139    typedef ImageBlockAccessor Inherited;
140
141    /*---------------------------------------------------------------------*/
142    /*! \name                   Destructor                                 */
143    /*! \{                                                                 */
144
145    virtual ~BlockAccessWrapper(void);
146
147    /*! \}                                                                 */
148    /*---------------------------------------------------------------------*/
149    /*! \name                   Read/Write                                 */
150    /*! \{                                                                 */
151
152    virtual bool isOpen(void);
153
154    /*! \}                                                                 */
155    /*---------------------------------------------------------------------*/
156    /*! \name                   Read/Write                                 */
157    /*! \{                                                                 */
158
159    /*! \}                                                                 */
160    /*---------------------------------------------------------------------*/
161    /*! \name                   Read/Write                                 */
162    /*! \{                                                                 */
163
164    /*! \}                                                                 */
165    /*---------------------------------------------------------------------*/
166    /*! \name                   Read/Write                                 */
167    /*! \{                                                                 */
168
169    virtual bool readBlockA16(Vec2i   vSampleOrigin,
170                              Int32   iTextureSize,
171                              UInt16 *pTarget,
172                              Int32   iTargetSizeBytes);
173
174    virtual bool readBlockA16(Vec2i   vSampleOrigin,
175                              Int32   iTextureSize,
176                              Int16  *pTarget,
177                              Int32   iTargetSizeBytes);
178
179    /*! \}                                                                 */
180    /*=========================  PROTECTED  ===============================*/
181
182  protected:
183
184    ImageUnrecPtr _pImage;
185
186    /*---------------------------------------------------------------------*/
187    /*! \name                Default Constructor                           */
188    /*! \{                                                                 */
189
190    BlockAccessWrapper(void);
191
192    /*! \}                                                                 */
193    /*---------------------------------------------------------------------*/
194    /*! \name                   Read/Write                                 */
195    /*! \{                                                                 */
196
197    void open(const Char8 *szFilename);
198
199    /*! \}                                                                 */
200    /*==========================  PRIVATE  ================================*/
201
202  private:
203
204    friend class ImageFileType;
205};
206
207typedef boost::shared_ptr<BlockAccessWrapper> BlockAccessWrapperPtr;
208
209/*! \brief Abstract Base ImageFileType. Defines the Interface for
210all concrete ImageFileTypes. See \ref PageSystemImage for detailed description.
211*/
212
213class OSG_SYSTEM_DLLMAPPING ImageFileType : public IOFileTypeBase
214{
215    /*==========================  PUBLIC  =================================*/   
216  public:
217    /*---------------------------------------------------------------------*/
218    /*! \name Public Types                                                 */
219    /*! \{                                                                 */
220    
221    typedef IOFileTypeBase Inherited;
222    typedef ImageFileType  Self;
223    
224    /*! \}                                                                 */
225    /*---------------------------------------------------------------------*/
226    /*! \name                     Flags                                    */
227    /*! \{                                                                 */
228  
229    enum
230    {
231        OSG_READ_SUPPORTED  = 1,
232        OSG_WRITE_SUPPORTED = 2
233    };
234    
235    /*! \}                                                                 */
236    /*---------------------------------------------------------------------*/
237    /*! \name                   Destructor                                 */
238    /*! \{                                                                 */
239
240    virtual ~ImageFileType(void);
241    
242    /*! \}                                                                 */
243    /*---------------------------------------------------------------------*/
244    /*! \name                    Get  Methods                              */
245    /*! \{                                                                 */
246    
247    const      Char8             *getMimeType  (void) const;
248
249    const std::list<std::string> &getSuffixList(void) const;
250    
251    /*! \}                                                                 */
252    /*---------------------------------------------------------------------*/
253    /*! \name                   Read/Write                                 */
254    /*! \{                                                                 */
255
256    virtual bool read          (      Image            *pImage, 
257                                const Char8            *fileName   ) ;
258
259    virtual bool write         (      Image const      *pImage, 
260                                const Char8            *fileName   ) ;
261
262    virtual bool read          (      Image            *pImage, 
263                                      std::istream     &is, 
264                                const std::string      &mimetype);
265
266    virtual bool write         (      Image const      *pImage, 
267                                      std::ostream     &os, 
268                                const std::string      &mimetype);
269
270    virtual bool validateHeader(const Char8            *fileName, 
271                                      bool             &implemented);
272
273    /*! \}                                                                 */
274    /*---------------------------------------------------------------------*/
275    /*! \name                   Read/Write                                 */
276    /*! \{                                                                 */
277
278    virtual ImageBlockAccessorPtr open(const Char8 *fileName);
279
280    /*! \}                                                                 */
281    /*---------------------------------------------------------------------*/
282    /*! \name                        Type                                  */
283    /*! \{                                                                 */
284
285    virtual std::string determineMimetypeFromStream(std::istream &is);
286
287    /*! \}                                                                 */
288    /*---------------------------------------------------------------------*/
289    /*! \name              static store/restore                            */
290    /*! \{                                                                 */
291
292    static UInt64 restore(      Image            *pImage, 
293                          const UChar8           *buffer,
294                                Int32             memSize = -1);
295
296    static UInt64 store  (      Image const      *pImage,
297                          const Char8            *mimeType,
298                                UChar8           *buffer, 
299                                Int32             memSize = -1);
300
301    /*! \}                                                                 */
302    /*---------------------------------------------------------------------*/
303    /*! \name                  Raw Store/Restore                           */
304    /*! \{                                                                 */
305
306    virtual UInt64 restoreData(      Image            *pImage, 
307                               const UChar8           *buffer,
308                                     Int32             memSize = -1);
309
310    virtual UInt64 storeData  (      Image const      *pImage, 
311                                     UChar8           *buffer,
312                                     Int32             memSize = -1);
313
314    /*! \}                                                                 */
315    /*---------------------------------------------------------------------*/
316    /*! \name                   store/restore                              */
317    /*! \{                                                                 */
318
319           UInt64 store         (Image const      *pImage, 
320                                 UChar8           *buffer,
321                                 Int32             memSize = -1);
322    
323    virtual UInt64 maxBufferSize(Image const      *pImage      );
324
325    /*! \}                                                                 */
326    /*---------------------------------------------------------------------*/
327    /*! \name                       dump                                   */
328    /*! \{                                                                 */
329
330    void dump(void);
331
332    /*! \}                                                                 */
333    /*=========================  PROTECTED  ===============================*/
334
335  protected:
336
337    /*---------------------------------------------------------------------*/
338    /*! \name                   MTD Header                                 */
339    /*! \{                                                                 */
340
341    struct OSG_SYSTEM_DLLMAPPING Head
342    {
343        Char8          suffix[8];
344        
345        unsigned short pixelFormat;
346        unsigned short width;
347        unsigned short height;
348        unsigned short depth;
349        unsigned short mipmapCount;
350        unsigned short frameCount;
351        unsigned short frameDelay;
352        unsigned short sideCount;
353        unsigned short dataType;
354        unsigned short _reserved3;
355        unsigned short _reserved4;
356        unsigned short attachmentSize;
357
358        bool netToHost(void);
359        bool hostToNet(void);
360    };
361
362    /*! \}                                                                 */
363    /*---------------------------------------------------------------------*/
364    /*! \name                Default Constructor                           */
365    /*! \{                                                                 */
366
367    ImageFileType(const Char8  *mimeType,
368                  const Char8  *suffixArray[], 
369                        UInt16  suffixByteCount,
370                        UInt32  flags = OSG_READ_SUPPORTED);
371
372    /*! \}                                                                 */
373    /*==========================  PRIVATE  ================================*/
374
375  private:
376    /* prohibit default function (move to 'public' if needed) */
377          ImageFileType            (const ImageFileType &obj);
378    const ImageFileType &operator =(const ImageFileType &obj);
379
380
381    std::list<std::string> _suffixList;
382
383    std::string            _mimeType;
384};
385
386typedef ImageFileType *ImageFileTypeP;
387
388OSG_END_NAMESPACE
389
390#endif // _OSGIMAGEFILETYPE_H_