OpenSGDevMaster_Toolbox /Source/System/Image/OSGImageFileType.h

Language C/C++ Header Lines 391
MD5 Hash 42cbf3b3a37875cfe246aac6bc79fabf
Repository https://github.com/msteners/OpenSGDevMaster_Toolbox.git View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
/*---------------------------------------------------------------------------*\
 *                                OpenSG                                     *
 *                                                                           *
 *                                                                           *
 *             Copyright (C) 2000-2002 by the OpenSG Forum                   *
 *                                                                           *
 *                            www.opensg.org                                 *
 *                                                                           *
 *   contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de          *
 *                                                                           *
\*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*\
 *                                License                                    *
 *                                                                           *
 * This library is free software; you can redistribute it and/or modify it   *
 * under the terms of the GNU Library General Public License as published    *
 * by the Free Software Foundation, version 2.                               *
 *                                                                           *
 * 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         *
 * Library General Public License for more details.                          *
 *                                                                           *
 * You should have received a copy of the GNU Library General Public         *
 * License along with this library; if not, write to the Free Software       *
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 *
 *                                                                           *
\*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*\
 *                                Changes                                    *
 *                                                                           *
 *                                                                           *
 *                                                                           *
 *                                                                           *
 *                                                                           *
 *                                                                           *
\*---------------------------------------------------------------------------*/

#ifndef _OSGIMAGEFILETYPE_H_
#define _OSGIMAGEFILETYPE_H_

#include <list>

#include "OSGIOFileTypeBase.h"
#include "OSGImage.h"
#include "OSGGeoReferenceAttachment.h"

#include "boost/shared_ptr.hpp"

OSG_BEGIN_NAMESPACE

class ImageFileType;


class OSG_SYSTEM_DLLMAPPING ImageBlockAccessor
{
    /*==========================  PUBLIC  =================================*/
    
  public:

    /*---------------------------------------------------------------------*/
    /*! \name                   Destructor                                 */
    /*! \{                                                                 */

    virtual ~ImageBlockAccessor(void);

    /*! \}                                                                 */
    /*---------------------------------------------------------------------*/
    /*! \name                   Read/Write                                 */
    /*! \{                                                                 */

    virtual bool isOpen(void) = 0;

    /*! \}                                                                 */
    /*---------------------------------------------------------------------*/
    /*! \name                   Read/Write                                 */
    /*! \{                                                                 */

    Vec2i              getSize       (void);
    
    Image::Type        getType       (void);
    Image::PixelFormat getFormat     (void);

    Real64             getNoDataValue(void);

    /*! \}                                                                 */
    /*---------------------------------------------------------------------*/
    /*! \name                   Read/Write                                 */
    /*! \{                                                                 */

    GeoReferenceAttachment *getGeoRef(void);

    /*! \}                                                                 */
    /*---------------------------------------------------------------------*/
    /*! \name                   Read/Write                                 */
    /*! \{                                                                 */

    virtual bool readBlockA16(Vec2i   vSampleOrigin,
                              Int32   iTextureSize,
                              UInt16 *pTarget,
                              Int32   iTargetSizeBytes) = 0;

    virtual bool readBlockA16(Vec2i   vSampleOrigin,
                              Int32   iTextureSize,
                              Int16  *pTarget,
                              Int32   iTargetSizeBytes) = 0;

    /*! \}                                                                 */
    /*=========================  PROTECTED  ===============================*/

  protected:

    GeoReferenceAttachmentUnrecPtr _pGeoRef;
    Vec2i                          _vSize;
    Image::Type                    _eImgType;
    Image::PixelFormat             _eImgFormat;
    Real64                         _fNoDataValue;

    /*---------------------------------------------------------------------*/
    /*! \name                Default Constructor                           */
    /*! \{                                                                 */

    ImageBlockAccessor(void);

    /*! \}                                                                 */
    /*==========================  PRIVATE  ================================*/

  private:
};

typedef boost::shared_ptr<ImageBlockAccessor> ImageBlockAccessorPtr;

class OSG_SYSTEM_DLLMAPPING BlockAccessWrapper : public ImageBlockAccessor
{
    /*==========================  PUBLIC  =================================*/
    
  public:

    typedef ImageBlockAccessor Inherited;

    /*---------------------------------------------------------------------*/
    /*! \name                   Destructor                                 */
    /*! \{                                                                 */

    virtual ~BlockAccessWrapper(void);

    /*! \}                                                                 */
    /*---------------------------------------------------------------------*/
    /*! \name                   Read/Write                                 */
    /*! \{                                                                 */

    virtual bool isOpen(void);

    /*! \}                                                                 */
    /*---------------------------------------------------------------------*/
    /*! \name                   Read/Write                                 */
    /*! \{                                                                 */

    /*! \}                                                                 */
    /*---------------------------------------------------------------------*/
    /*! \name                   Read/Write                                 */
    /*! \{                                                                 */

    /*! \}                                                                 */
    /*---------------------------------------------------------------------*/
    /*! \name                   Read/Write                                 */
    /*! \{                                                                 */

    virtual bool readBlockA16(Vec2i   vSampleOrigin,
                              Int32   iTextureSize,
                              UInt16 *pTarget,
                              Int32   iTargetSizeBytes);

    virtual bool readBlockA16(Vec2i   vSampleOrigin,
                              Int32   iTextureSize,
                              Int16  *pTarget,
                              Int32   iTargetSizeBytes);

    /*! \}                                                                 */
    /*=========================  PROTECTED  ===============================*/

  protected:

    ImageUnrecPtr _pImage;

    /*---------------------------------------------------------------------*/
    /*! \name                Default Constructor                           */
    /*! \{                                                                 */

    BlockAccessWrapper(void);

    /*! \}                                                                 */
    /*---------------------------------------------------------------------*/
    /*! \name                   Read/Write                                 */
    /*! \{                                                                 */

    void open(const Char8 *szFilename);

    /*! \}                                                                 */
    /*==========================  PRIVATE  ================================*/

  private:

    friend class ImageFileType;
};

typedef boost::shared_ptr<BlockAccessWrapper> BlockAccessWrapperPtr;

/*! \brief Abstract Base ImageFileType. Defines the Interface for
all concrete ImageFileTypes. See \ref PageSystemImage for detailed description.
*/

class OSG_SYSTEM_DLLMAPPING ImageFileType : public IOFileTypeBase
{
    /*==========================  PUBLIC  =================================*/   
  public:
    /*---------------------------------------------------------------------*/
    /*! \name Public Types                                                 */
    /*! \{                                                                 */
    
    typedef IOFileTypeBase Inherited;
    typedef ImageFileType  Self;
    
    /*! \}                                                                 */
    /*---------------------------------------------------------------------*/
    /*! \name                     Flags                                    */
    /*! \{                                                                 */
  
    enum
    {
        OSG_READ_SUPPORTED  = 1,
        OSG_WRITE_SUPPORTED = 2
    };
    
    /*! \}                                                                 */
    /*---------------------------------------------------------------------*/
    /*! \name                   Destructor                                 */
    /*! \{                                                                 */

    virtual ~ImageFileType(void);
    
    /*! \}                                                                 */
    /*---------------------------------------------------------------------*/
    /*! \name                    Get  Methods                              */
    /*! \{                                                                 */
    
    const      Char8             *getMimeType  (void) const;

    const std::list<std::string> &getSuffixList(void) const;
    
    /*! \}                                                                 */
    /*---------------------------------------------------------------------*/
    /*! \name                   Read/Write                                 */
    /*! \{                                                                 */

    virtual bool read          (      Image            *pImage, 
                                const Char8            *fileName   ) ;

    virtual bool write         (      Image const      *pImage, 
                                const Char8            *fileName   ) ;

    virtual bool read          (      Image            *pImage, 
                                      std::istream     &is, 
                                const std::string      &mimetype);

    virtual bool write         (      Image const      *pImage, 
                                      std::ostream     &os, 
                                const std::string      &mimetype);

    virtual bool validateHeader(const Char8            *fileName, 
                                      bool             &implemented);

    /*! \}                                                                 */
    /*---------------------------------------------------------------------*/
    /*! \name                   Read/Write                                 */
    /*! \{                                                                 */

    virtual ImageBlockAccessorPtr open(const Char8 *fileName);

    /*! \}                                                                 */
    /*---------------------------------------------------------------------*/
    /*! \name                        Type                                  */
    /*! \{                                                                 */

    virtual std::string determineMimetypeFromStream(std::istream &is);

    /*! \}                                                                 */
    /*---------------------------------------------------------------------*/
    /*! \name              static store/restore                            */
    /*! \{                                                                 */

    static UInt64 restore(      Image            *pImage, 
                          const UChar8           *buffer,
                                Int32             memSize = -1);

    static UInt64 store  (      Image const      *pImage,
                          const Char8            *mimeType,
                                UChar8           *buffer, 
                                Int32             memSize = -1);

    /*! \}                                                                 */
    /*---------------------------------------------------------------------*/
    /*! \name                  Raw Store/Restore                           */
    /*! \{                                                                 */

    virtual UInt64 restoreData(      Image            *pImage, 
                               const UChar8           *buffer,
                                     Int32             memSize = -1);

    virtual UInt64 storeData  (      Image const      *pImage, 
                                     UChar8           *buffer,
                                     Int32             memSize = -1);

    /*! \}                                                                 */
    /*---------------------------------------------------------------------*/
    /*! \name                   store/restore                              */
    /*! \{                                                                 */

           UInt64 store         (Image const      *pImage, 
                                 UChar8           *buffer,
                                 Int32             memSize = -1);
    
    virtual UInt64 maxBufferSize(Image const      *pImage      );

    /*! \}                                                                 */
    /*---------------------------------------------------------------------*/
    /*! \name                       dump                                   */
    /*! \{                                                                 */

    void dump(void);

    /*! \}                                                                 */
    /*=========================  PROTECTED  ===============================*/

  protected:

    /*---------------------------------------------------------------------*/
    /*! \name                   MTD Header                                 */
    /*! \{                                                                 */

    struct OSG_SYSTEM_DLLMAPPING Head
    {
        Char8          suffix[8];
        
        unsigned short pixelFormat;
        unsigned short width;
        unsigned short height;
        unsigned short depth;
        unsigned short mipmapCount;
        unsigned short frameCount;
        unsigned short frameDelay;
        unsigned short sideCount;
        unsigned short dataType;
        unsigned short _reserved3;
        unsigned short _reserved4;
        unsigned short attachmentSize;

        bool netToHost(void);
        bool hostToNet(void);
    };

    /*! \}                                                                 */
    /*---------------------------------------------------------------------*/
    /*! \name                Default Constructor                           */
    /*! \{                                                                 */

    ImageFileType(const Char8  *mimeType,
                  const Char8  *suffixArray[], 
                        UInt16  suffixByteCount,
                        UInt32  flags = OSG_READ_SUPPORTED);

    /*! \}                                                                 */
    /*==========================  PRIVATE  ================================*/

  private:
    /* prohibit default function (move to 'public' if needed) */
          ImageFileType            (const ImageFileType &obj);
    const ImageFileType &operator =(const ImageFileType &obj);


    std::list<std::string> _suffixList;

    std::string            _mimeType;
};

typedef ImageFileType *ImageFileTypeP;

OSG_END_NAMESPACE

#endif // _OSGIMAGEFILETYPE_H_
Back to Top