PageRenderTime 162ms CodeModel.GetById 57ms app.highlight 49ms RepoModel.GetById 51ms app.codeStats 0ms

/Source/System/Image/WS/OSGImage.h

https://github.com/msteners/OpenSGDevMaster_Toolbox
C++ Header | 490 lines | 242 code | 90 blank | 158 comment | 2 complexity | 8bb9f3bad01d7623e0138d9ff473ee48 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 _OSGIMAGE_H_
 40#define _OSGIMAGE_H_
 41#ifdef __sgi
 42#pragma once
 43#endif
 44
 45#include "OSGConfig.h"
 46#include "OSGImageBase.h"
 47#include "OSGGLEXT.h"
 48#include "OSGReal16.h"
 49
 50OSG_BEGIN_NAMESPACE
 51
 52/*! \brief Image class. See \ref PageSystemImage
 53           for a description.
 54*/
 55
 56class OSG_SYSTEM_DLLMAPPING Image : public ImageBase
 57{
 58  private:
 59
 60    /*==========================  PUBLIC  =================================*/
 61
 62  public:
 63
 64    typedef ImageBase                           Inherited;
 65
 66    enum PixelFormat 
 67    {   
 68        OSG_INVALID_PF = 0,
 69        OSG_A_PF       = GL_ALPHA,
 70        OSG_I_PF       = GL_INTENSITY,
 71        OSG_L_PF       = GL_LUMINANCE,
 72        OSG_LA_PF      = GL_LUMINANCE_ALPHA,
 73/*** BGR ***/
 74#if defined(GL_BGR)
 75        OSG_BGR_PF     = GL_BGR,
 76#elif defined(GL_BGR_EXT)
 77        OSG_BGR_PF     = GL_BGR_EXT,
 78#else
 79        OSG_BGR_PF     = 0,
 80#endif
 81        
 82/*** BGRA ***/
 83#if defined(GL_BGRA)
 84        OSG_BGRA_PF    = GL_BGRA,
 85#elif defined(GL_BGRA_EXT)
 86        OSG_BGRA_PF    = GL_BGRA_EXT,
 87#else
 88        OSG_BGRA_PF    = 0,
 89#endif
 90/*** RGB_DXT1 ***/
 91#if defined(GL_COMPRESSED_RGB_S3TC_DXT1_EXT)
 92        OSG_RGB_DXT1   = GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
 93#else
 94        OSG_RGB_DXT1   = 0,
 95#endif
 96        
 97/*** RGBA_DXT1 ***/
 98#if defined(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT)
 99        OSG_RGBA_DXT1  = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
100#else
101        OSG_RGBA_DXT1  = 0,
102#endif
103        
104/*** RGBA_DXT3 ***/
105#if defined(GL_COMPRESSED_RGBA_S3TC_DXT3_EXT)
106        OSG_RGBA_DXT3  = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT,
107#else
108        OSG_RGBA_DXT3  = 0,
109#endif
110        
111/*** RGBA_DXT5 ***/
112#if defined(GL_COMPRESSED_RGBA_S3TC_DXT5_EXT)
113        OSG_RGBA_DXT5  = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT,
114#else
115        OSG_RGBA_DXT5  = 0,
116#endif
117
118        OSG_RGB_PF     = GL_RGB,
119        OSG_RGBA_PF    = GL_RGBA,
120						 
121        OSG_ALPHA_INTEGER_PF           = GL_ALPHA_INTEGER_EXT,
122        OSG_RGB_INTEGER_PF             = GL_RGB_INTEGER_EXT,
123        OSG_RGBA_INTEGER_PF            = GL_RGBA_INTEGER_EXT,
124        OSG_BGR_INTEGER_PF             = GL_BGR_INTEGER_EXT,
125        OSG_BGRA_INTEGER_PF            = GL_BGRA_INTEGER_EXT,
126        OSG_LUMINANCE_INTEGER_PF       = GL_LUMINANCE_INTEGER_EXT,
127        OSG_LUMINANCE_ALPHA_INTEGER_PF = GL_LUMINANCE_ALPHA_INTEGER_EXT
128    };
129
130    enum Type 
131    {
132        OSG_INVALID_IMAGEDATATYPE  = GL_NONE,
133        OSG_UINT8_IMAGEDATA        = GL_UNSIGNED_BYTE,
134        OSG_UINT16_IMAGEDATA       = GL_UNSIGNED_SHORT,
135        OSG_UINT32_IMAGEDATA       = GL_UNSIGNED_INT,
136        OSG_FLOAT16_IMAGEDATA      = GL_HALF_FLOAT_NV,
137        OSG_FLOAT32_IMAGEDATA      = GL_FLOAT,
138        OSG_INT16_IMAGEDATA        = GL_SHORT,
139        OSG_INT32_IMAGEDATA        = GL_INT
140    };
141
142    enum ResUnit 
143    {
144        OSG_RESUNIT_INVALID       = 0,
145        OSG_RESUNIT_NONE          = 1,
146        OSG_RESUNIT_INCH          = 2
147    };
148
149    /*---------------------------------------------------------------------*/
150    /*! \name                      Sync                                    */
151    /*! \{                                                                 */
152
153    virtual void changed(ConstFieldMaskArg whichField,
154                         UInt32            origin,
155                         BitVector         details);
156
157    /*! \}                                                                 */
158    /*---------------------------------------------------------------------*/
159    /*! \name                     Output                                   */
160    /*! \{                                                                 */
161
162    virtual void dump(      UInt32     uiIndent = 0,
163                      const BitVector  bvFlags  = 0) const;
164
165    /*! \}                                                                 */
166    /*---------------------------------------------------------------------*/
167    /*! \name                   Set Object Data                            */
168    /*! \{                                                                 */
169
170    bool set               (      UInt32    pixelFormat,
171                                  Int32     width,
172                                  Int32     height      = 1,
173                                  Int32     depth       = 1,
174                                  Int32     mipmapCount = 1,
175                                  Int32     frameCount  = 1,
176                                  Time      frameDelay  = 0.0,
177                            const UInt8    *data        = 0,
178                                  Int32     type        = OSG_UINT8_IMAGEDATA,
179                                  bool      allocMem    = true,
180                                  Int32     sidecount   = 1                  );
181    bool set               (      Image   *image                            );
182    bool setData           (const UInt8    *data = 0                         );
183    void clearData         (      void                                       );
184    bool setSubData        (      Int32     offX, 
185                                  Int32     offY, 
186                                  Int32     offZ,
187                                  Int32     srcW, 
188                                  Int32     srcH, 
189                                  Int32     srcD,
190                            const UInt8    *data                             );
191    bool flipDepthFrameData(      void                                       );
192
193
194    /*! \}                                                                 */
195    /*---------------------------------------------------------------------*/
196    /*! \name                     Add Value                                */
197    /*! \{                                                                 */
198
199    bool addValue(const Char8 *value);
200
201    /*! \}                                                                 */
202    /*---------------------------------------------------------------------*/
203    /*! \name                     Reformate                                */
204    /*! \{                                                                 */
205
206    bool reformat(const PixelFormat  pixelFormat,
207                        Image       *destination       = NULL,
208                        Int32        iCompressionFlags = 0);
209
210    /*! \}                                                                 */
211    /*---------------------------------------------------------------------*/
212    /*! \name                    Convert dataType                          */
213    /*! \{                                                                 */
214
215    void swapDataEndian   (void                                    );
216    bool convertDataTypeTo(Int32 destDataType = OSG_UINT8_IMAGEDATA);
217
218    /*! \}                                                                 */
219    /*---------------------------------------------------------------------*/
220    /*! \name                       Scale                                  */
221    /*! \{                                                                 */
222
223    bool scale          (Int32  width, 
224                         Int32  height      = 1,
225                         Int32  depth       = 1,
226                         Image *destination = NULL);
227    bool scaleNextPower2(Image *destination = NULL);
228
229    /*! \}                                                                 */
230    /*---------------------------------------------------------------------*/
231    /*! \name                      Mirror                                  */
232    /*! \{                                                                 */
233
234    bool mirror         (bool   horizontal,
235                         bool   vertical,
236                         bool   flipDepth   = false,
237                         Image *destination = NULL  );
238
239    /*! \}                                                                 */
240    /*---------------------------------------------------------------------*/
241    /*! \name                      SubImage                                */
242    /*! \{                                                                 */
243
244    bool subImage(Int32  offX, 
245                  Int32  offY, 
246                  Int32  offZ,
247                  Int32  destW, 
248                  Int32  destH, 
249                  Int32  destD,
250                  Image *destination = NULL);
251
252    /*! \}                                                                 */
253    /*---------------------------------------------------------------------*/
254    /*! \name                      Slice                                   */
255    /*! \{                                                                 */
256
257    bool slice(Int32  offX = -1, 
258               Int32  offY = -1, 
259               Int32  offZ = -1,
260               Image *destination = NULL);
261
262    /*! \}                                                                 */
263    /*---------------------------------------------------------------------*/
264    /*! \name                      Mipmap                                  */
265    /*! \{                                                                 */
266
267    bool createMipmap(Int32  level       = -1, 
268                      Image *destination = NULL);
269
270    bool removeMipmap(void                     );
271
272    /*! \}                                                                 */
273    /*---------------------------------------------------------------------*/
274    /*! \name                   Read/Write                                 */
275    /*! \{                                                                 */
276
277    bool write(const Char8 *fileName);
278    bool read (const Char8 *fileName);
279
280    /*! \}                                                                 */
281    /*---------------------------------------------------------------------*/
282    /*! \name                 Storage/Restore                              */
283    /*! \{                                                                 */
284
285    UInt64 store  (const Char8 *mimeType, 
286                         UInt8 *mem, 
287                         Int32  memSize = -1);
288    UInt64 restore(const UInt8 *mem, 
289                         Int32  memSize = -1);
290
291    /*! \}                                                                 */
292    /*---------------------------------------------------------------------*/
293    /*! \name               Comparison/Assign                              */
294    /*! \{                                                                 */
295
296    Image &operator =  (const Image &image);
297    bool   operator <  (const Image &image);
298    bool   operator == (const Image &image);
299    bool   operator != (const Image &image);
300
301    /*! \}                                                                 */
302    /*---------------------------------------------------------------------*/
303    /*! \name                    Get  Methods                              */
304    /*! \{                                                                 */
305
306    bool   isValid          (void) const;
307    bool   hasAlphaChannel  (void);
308    bool   isAlphaBinary    (void);
309    bool   hasColorChannel  (void);
310    bool   hasCompressedData(void);
311    UInt8  getComponents    (void) const;
312    
313    bool   calcIsAlphaBinary(void);
314
315    /*! \}                                                                 */
316    /*---------------------------------------------------------------------*/
317    /*! \name                      Size                                    */
318    /*! \{                                                                 */
319
320    unsigned long getSize(bool withMipmap = true,
321                          bool withFrames = true,
322                          bool withSides  = true) const;
323
324    /*! \}                                                                 */
325    /*---------------------------------------------------------------------*/
326    /*! \name                   Get Methods                                */
327    /*! \{                                                                 */
328
329    const UInt8 *getData       (UInt32 mipmapNum = 0,
330                                UInt32 frameNum  = 0,
331                                UInt32 sidecount = 0) const;
332          UInt8 *editData      (UInt32 mipmapNum = 0,
333                                UInt32 frameNum  = 0,
334                                UInt32 sidecount = 0);
335
336    const UInt8 *getDataFast   (UInt32 mipmapNum = 0,
337                                UInt32 frameNum  = 0,
338                                UInt32 sidecount = 0) const;
339          UInt8 *editDataFast  (UInt32 mipmapNum = 0,
340                                UInt32 frameNum  = 0,
341                                UInt32 sidecount = 0);
342
343    const UInt8 *getDataByTime (Time   time, 
344                                UInt32 mipmapNum = 1) const;
345          UInt8 *editDataByTime(Time   time, 
346                                UInt32 mipmapNum = 1);
347
348    /*! \}                                                                 */
349    /*---------------------------------------------------------------------*/
350    /*! \name                      Calculate                               */
351    /*! \{                                                                 */
352
353    void   calcMipmapGeometry  (UInt32 mipmapNum,
354                                UInt32 &width,
355                                UInt32 &height,
356                                UInt32 &depth     ) const;
357    UInt32 calcMipmapLevelCount(void              ) const;
358    UInt32 calcFrameNum        (Time    time, 
359                                bool    loop = true) const;
360
361    /*! \}                                                                 */
362    /*---------------------------------------------------------------------*/
363    /*! \name                   Clear Image                                */
364    /*! \{                                                                 */
365
366    virtual void clear     (UChar8 pixelValue = 0            );
367    virtual void clearFloat(Real32 pixelValue = 0.0          );
368    virtual void clearHalf (Real16 pixelValue = Real16( 0.0 ));
369
370    /*! \}                                                                 */
371    /*---------------------------------------------------------------------*/
372    /*! \name               attachment handling                            */
373    /*! \{                                                                 */
374
375    bool               hasAttachment      (      void             ) const;
376    UInt32             attachmentCount    (      void             ) const;
377    void               setAttachmentField (const std::string &key,
378                                           const std::string &data);
379    const std::string *findAttachmentField(const std::string &key ) const;
380
381    /*! \}                                                                 */
382    /*---------------------------------------------------------------------*/
383    /*! \name               Calculate Mipmap Size                          */
384    /*! \{                                                                 */
385
386    UInt32 calcMipmapLevelSize(UInt32 mipmapNum,
387                               UInt32 w, 
388                               UInt32 h, 
389                               UInt32 d        ) const;
390    UInt32 calcMipmapLevelSize(UInt32 mipmapNum) const;
391
392    UInt32 calcMipmapSumSize  (UInt32 mipmapNum,
393                               UInt32 w, 
394                               UInt32 h, 
395                               UInt32 d        ) const;
396    UInt32 calcMipmapSumSize  (UInt32 mipmapNum) const;
397
398    /*! \}                                                                 */
399    /*---------------------------------------------------------------------*/
400    /*! \name                        Don't know yet                        */
401    /*! \{                                                                 */
402
403#if 0
404    void imageContentChanged(Int32 minX = -1, Int32 maxX = -1,
405                             Int32 minY = -1, Int32 maxY = -1,
406                             Int32 minZ = -1, Int32 maxZ = -1 );
407#endif    
408
409    /*! \}                                                                 */
410    /*=========================  PROTECTED  ===============================*/
411
412  protected:
413
414    std::vector<Int32> _mipmapOffset;
415
416    /*---------------------------------------------------------------------*/
417    /*! \name                  static element                              */
418    /*! \{                                                                 */
419
420    static UInt32 _formatDic[][2];
421    static Int32  _typeDic  [][2];
422
423    /*! \}                                                                 */
424    /*---------------------------------------------------------------------*/
425    /*! \name                  Constructors                                */
426    /*! \{                                                                 */
427
428    Image(void);
429    Image(const Image &source);
430
431    /*! \}                                                                 */
432    /*---------------------------------------------------------------------*/
433    /*! \name                   Destructors                                */
434    /*! \{                                                                 */
435
436    virtual ~Image(void);
437
438    /*! \}                                                                 */
439    /*---------------------------------------------------------------------*/
440    /*! \name                       Init                                   */
441    /*! \{                                                                 */
442
443    static void initMethod(InitPhase ePhase);
444
445    /*! \}                                                                 */
446    /*==========================  PRIVATE  ================================*/
447
448  private:
449
450    /*---------------------------------------------------------------------*/
451    /*! \name                   Image Data                                 */
452    /*! \{                                                                 */
453
454    bool createData       (const UInt8 *data, 
455                                 bool   allocMem = true  );
456    bool scaleData        (const UInt8 *srcData,
457                                 Int32  srcW, 
458                                 Int32  srcH, 
459                                 Int32  srcD,
460                                 UInt8 *destData,
461                                 Int32  destW, 
462                                 Int32  destH, 
463                                 Int32  destD            );
464
465    void calcMipmapOffsets(      void                    );
466
467    bool mirrorData       (const UInt8 *srcData,
468                                 UInt8 *destData,
469                                 Int32  width,
470                                 Int32  height,
471                                 Int32  depth,
472                                 bool   horizontal,
473                                 bool   vertical,
474                                 bool   flipDepth = false);
475
476    /*! \}                                                                 */
477    /*---------------------------------------------------------------------*/
478
479    friend class FieldContainer;
480    friend class ImageBase;
481};
482
483typedef Image *ImageP;
484
485OSG_END_NAMESPACE
486
487#include "OSGImageBase.inl"
488#include "OSGImage.inl"
489
490#endif /* _OSGIMAGE_H_ */