PageRenderTime 327ms CodeModel.GetById 110ms app.highlight 94ms RepoModel.GetById 118ms app.codeStats 0ms

/Source/System/Image/ES/OSGImage.h

https://github.com/msteners/OpenSGDevMaster_Toolbox
C++ Header | 436 lines | 208 code | 78 blank | 150 comment | 3 complexity | 3a543e3ab2fc39a908d24bf24b91f534 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#if !defined(OSG_EMBEDDED) || OSG_GL_ES_VERSION > 100
 71        OSG_I_PF       = GL_INTENSITY,
 72#endif
 73		OSG_L_PF       = GL_LUMINANCE,
 74        OSG_LA_PF      = GL_LUMINANCE_ALPHA,
 75/*** BGR ***/
 76#if defined(GL_BGR)
 77        OSG_BGR_PF     = GL_BGR,
 78#elif defined(GL_BGR_EXT)
 79        OSG_BGR_PF     = GL_BGR_EXT,
 80#else
 81        OSG_BGR_PF     = 0,
 82#endif
 83        
 84/*** BGRA ***/
 85#if defined(GL_BGRA)
 86        OSG_BGRA_PF    = GL_BGRA,
 87#elif defined(GL_BGRA_EXT)
 88        OSG_BGRA_PF    = GL_BGRA_EXT,
 89#else
 90        OSG_BGRA_PF    = 0,
 91#endif
 92/*** RGB_DXT1 ***/
 93#if defined(GL_COMPRESSED_RGB_S3TC_DXT1_EXT)
 94        OSG_RGB_DXT1   = GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
 95#else
 96        OSG_RGB_DXT1   = 0,
 97#endif
 98        
 99/*** RGBA_DXT1 ***/
100#if defined(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT)
101        OSG_RGBA_DXT1  = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
102#else
103        OSG_RGBA_DXT1  = 0,
104#endif
105        
106/*** RGBA_DXT3 ***/
107#if defined(GL_COMPRESSED_RGBA_S3TC_DXT3_EXT)
108        OSG_RGBA_DXT3  = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT,
109#else
110        OSG_RGBA_DXT3  = 0,
111#endif
112        
113/*** RGBA_DXT5 ***/
114#if defined(GL_COMPRESSED_RGBA_S3TC_DXT5_EXT)
115        OSG_RGBA_DXT5  = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT,
116#else
117        OSG_RGBA_DXT5  = 0,
118#endif
119
120        OSG_RGB_PF     = GL_RGB,
121        OSG_RGBA_PF    = GL_RGBA
122    };
123
124    enum Type 
125    {
126        OSG_INVALID_IMAGEDATATYPE  = GL_FALSE,
127        OSG_UINT8_IMAGEDATA        = GL_UNSIGNED_BYTE,
128#if defined(GL_UNSIGNED_SHORT)
129        OSG_UINT16_IMAGEDATA       = GL_UNSIGNED_SHORT,
130#endif
131#if defined(GL_UNSIGNED_INT)
132        OSG_UINT32_IMAGEDATA       = GL_UNSIGNED_INT,
133#endif
134#if !defined(OSG_EMBEDDED)
135		OSG_FLOAT16_IMAGEDATA      = GL_HALF_FLOAT_NV,
136#endif
137		OSG_FLOAT32_IMAGEDATA      = GL_FLOAT
138    };
139
140    /*---------------------------------------------------------------------*/
141    /*! \name                      Sync                                    */
142    /*! \{                                                                 */
143
144    virtual void changed(ConstFieldMaskArg whichField,
145                         UInt32            origin,
146                         BitVector         details);
147
148    /*! \}                                                                 */
149    /*---------------------------------------------------------------------*/
150    /*! \name                     Output                                   */
151    /*! \{                                                                 */
152
153    virtual void dump(      UInt32     uiIndent = 0,
154                      const BitVector  bvFlags  = 0) const;
155
156    /*! \}                                                                 */
157    /*---------------------------------------------------------------------*/
158    /*! \name                   Set Object Data                            */
159    /*! \{                                                                 */
160
161    bool set               (      UInt32    pixelFormat,
162                                  Int32     width,
163                                  Int32     height      = 1,
164                                  Int32     depth       = 1,
165                                  Int32     mipmapCount = 1,
166                                  Int32     frameCount  = 1,
167                                  Time      frameDelay  = 0.0,
168                            const UInt8    *data        = 0,
169                                  Int32     type        = OSG_UINT8_IMAGEDATA,
170                                  bool      allocMem    = true,
171                                  Int32     sidecount   = 1                  );
172    bool set               (      ImagePtr  image                            );
173    bool setData           (const UInt8    *data = 0                         );
174    void clearData         (      void                                       );
175    bool setSubData        (      Int32     offX, 
176                                  Int32     offY, 
177                                  Int32     offZ,
178                                  Int32     srcW, 
179                                  Int32     srcH, 
180                                  Int32     srcD,
181                            const UInt8    *data                             );
182    bool flipDepthFrameData(      void                                       );
183
184
185    /*! \}                                                                 */
186    /*---------------------------------------------------------------------*/
187    /*! \name                     Add Value                                */
188    /*! \{                                                                 */
189
190    bool addValue(const Char8 *value);
191
192    /*! \}                                                                 */
193    /*---------------------------------------------------------------------*/
194    /*! \name                     Reformate                                */
195    /*! \{                                                                 */
196
197    bool reformat(const PixelFormat pixelFormat,
198                        ImagePtr    destination = NullFC);
199
200    /*! \}                                                                 */
201    /*---------------------------------------------------------------------*/
202    /*! \name                    Convert dataType                          */
203    /*! \{                                                                 */
204
205    void swapDataEndian   (void                                    );
206    bool convertDataTypeTo(Int32 destDataType = OSG_UINT8_IMAGEDATA);
207
208    /*! \}                                                                 */
209    /*---------------------------------------------------------------------*/
210    /*! \name                       Scale                                  */
211    /*! \{                                                                 */
212
213    bool scale          (Int32    width, 
214                         Int32    height      = 1,
215                         Int32    depth       = 1,
216                         ImagePtr destination = NullFC );
217    bool scaleNextPower2(ImagePtr destination = NullFC );
218
219    /*! \}                                                                 */
220    /*---------------------------------------------------------------------*/
221    /*! \name                      SubImage                                */
222    /*! \{                                                                 */
223
224    bool subImage(Int32    offX, 
225                  Int32    offY, 
226                  Int32    offZ,
227                  Int32    destW, 
228                  Int32    destH, 
229                  Int32    destD,
230                  ImagePtr destination = NullFC);
231
232    /*! \}                                                                 */
233    /*---------------------------------------------------------------------*/
234    /*! \name                      Slice                                   */
235    /*! \{                                                                 */
236
237    bool slice(Int32    offX = -1, 
238               Int32    offY = -1, 
239               Int32    offZ = -1,
240               ImagePtr destination = NullFC);
241
242    /*! \}                                                                 */
243    /*---------------------------------------------------------------------*/
244    /*! \name                      Mipmap                                  */
245    /*! \{                                                                 */
246
247    bool createMipmap(Int32    level       = -1, 
248                      ImagePtr destination = NullFC);
249
250    /*! \}                                                                 */
251    /*---------------------------------------------------------------------*/
252    /*! \name                   Read/Write                                 */
253    /*! \{                                                                 */
254
255    bool write(const Char8 *fileName);
256    bool read (const Char8 *fileName);
257
258    /*! \}                                                                 */
259    /*---------------------------------------------------------------------*/
260    /*! \name                 Storage/Restore                              */
261    /*! \{                                                                 */
262
263    UInt64 store  (const Char8 *mimeType, 
264                         UInt8 *mem, 
265                         Int32  memSize = -1);
266    UInt64 restore(const UInt8 *mem, 
267                         Int32  memSize = -1);
268
269    /*! \}                                                                 */
270    /*---------------------------------------------------------------------*/
271    /*! \name               Comparison/Assign                              */
272    /*! \{                                                                 */
273
274    Image &operator =  (const Image &image);
275    bool   operator <  (const Image &image);
276    bool   operator == (const Image &image);
277    bool   operator != (const Image &image);
278
279    /*! \}                                                                 */
280    /*---------------------------------------------------------------------*/
281    /*! \name                    Get  Methods                              */
282    /*! \{                                                                 */
283
284    bool   isValid          (void) const;
285    bool   hasAlphaChannel  (void);
286    bool   isAlphaBinary    (void);
287    bool   hasColorChannel  (void);
288    bool   hasCompressedData(void);
289    UInt8  getComponents    (void) const;
290    
291    bool   calcIsAlphaBinary(void);
292
293    /*! \}                                                                 */
294    /*---------------------------------------------------------------------*/
295    /*! \name                      Size                                    */
296    /*! \{                                                                 */
297
298    unsigned long getSize(bool withMipmap = true,
299                          bool withFrames = true,
300                          bool withSides  = true) const;
301
302    /*! \}                                                                 */
303    /*---------------------------------------------------------------------*/
304    /*! \name                   Get Methods                                */
305    /*! \{                                                                 */
306
307    const UInt8 *getData       (UInt32 mipmapNum = 0,
308                                UInt32 frameNum  = 0,
309                                UInt32 sidecount = 0) const;
310          UInt8 *editData      (UInt32 mipmapNum = 0,
311                                UInt32 frameNum  = 0,
312                                UInt32 sidecount = 0);
313    const UInt8 *getDataByTime (Time   time, 
314                                UInt32 mipmapNum = 1) const;
315          UInt8 *editDataByTime(Time   time, 
316                                UInt32 mipmapNum = 1);
317
318    /*! \}                                                                 */
319    /*---------------------------------------------------------------------*/
320    /*! \name                      Calculate                               */
321    /*! \{                                                                 */
322
323    void   calcMipmapGeometry  (UInt32 mipmapNum,
324                                UInt32 &width,
325                                UInt32 &height,
326                                UInt32 &depth     ) const;
327    UInt32 calcMipmapLevelCount(void              ) const;
328    UInt32 calcFrameNum        (Time    time, 
329                                bool    loop = true) const;
330
331    /*! \}                                                                 */
332    /*---------------------------------------------------------------------*/
333    /*! \name                   Clear Image                                */
334    /*! \{                                                                 */
335
336    virtual void clear     (UChar8 pixelValue = 0            );
337    virtual void clearFloat(Real32 pixelValue = 0.0          );
338    virtual void clearHalf (Real16 pixelValue = Real16( 0.0 ));
339
340    /*! \}                                                                 */
341    /*---------------------------------------------------------------------*/
342    /*! \name               attachment handling                            */
343    /*! \{                                                                 */
344
345    bool               hasAttachment      (      void             ) const;
346    UInt32             attachmentCount    (      void             ) const;
347    void               setAttachmentField (const std::string &key,
348                                           const std::string &data);
349    const std::string *findAttachmentField(const std::string &key ) const;
350
351    /*! \}                                                                 */
352    /*---------------------------------------------------------------------*/
353    /*! \name               Calculate Mipmap Size                          */
354    /*! \{                                                                 */
355
356    UInt32 calcMipmapLevelSize(UInt32 mipmapNum,
357                               UInt32 w, 
358                               UInt32 h, 
359                               UInt32 d        ) const;
360    UInt32 calcMipmapLevelSize(UInt32 mipmapNum) const;
361
362    UInt32 calcMipmapSumSize  (UInt32 mipmapNum,
363                               UInt32 w, 
364                               UInt32 h, 
365                               UInt32 d        ) const;
366    UInt32 calcMipmapSumSize  (UInt32 mipmapNum) const;
367
368    /*! \}                                                                 */
369    /*=========================  PROTECTED  ===============================*/
370
371  protected:
372
373    /*---------------------------------------------------------------------*/
374    /*! \name                  static element                              */
375    /*! \{                                                                 */
376
377    static Int32 _formatDic[][2];
378    static Int32 _typeDic  [][2];
379
380    /*! \}                                                                 */
381    /*---------------------------------------------------------------------*/
382    /*! \name                  Constructors                                */
383    /*! \{                                                                 */
384
385    Image(void);
386    Image(const Image &source);
387
388    /*! \}                                                                 */
389    /*---------------------------------------------------------------------*/
390    /*! \name                   Destructors                                */
391    /*! \{                                                                 */
392
393    virtual ~Image(void);
394
395    /*! \}                                                                 */
396    /*---------------------------------------------------------------------*/
397    /*! \name                       Init                                   */
398    /*! \{                                                                 */
399
400    static void initMethod(InitPhase ePhase);
401
402    /*! \}                                                                 */
403    /*==========================  PRIVATE  ================================*/
404
405  private:
406
407    /*---------------------------------------------------------------------*/
408    /*! \name                   Image Data                                 */
409    /*! \{                                                                 */
410
411    bool createData(const UInt8 *data, 
412                          bool   allocMem = true);
413    bool scaleData (      UInt8 *srcData,
414                          Int32  srcW, 
415                          Int32  srcH, 
416                          Int32  srcD,
417                          UInt8 *destData,
418                          Int32  destW, 
419                          Int32  destH, 
420                          Int32  destD          );
421
422    /*! \}                                                                 */
423    /*---------------------------------------------------------------------*/
424
425    friend class FieldContainer;
426    friend class ImageBase;
427};
428
429typedef Image *ImageP;
430
431OSG_END_NAMESPACE
432
433#include "OSGImageBase.inl"
434#include "OSGImage.inl"
435
436#endif /* _OSGIMAGE_H_ */