Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

OSGImage.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 _OSGIMAGE_H_
00040 #define _OSGIMAGE_H_
00041 #ifdef __sgi
00042 #pragma once
00043 #endif
00044 
00045 #include <OSGConfig.h>
00046 #include <OSGImageBase.h>
00047 #include <OSGGLEXT.h>
00048 #include <OSGReal16.h>
00049 
00050 OSG_BEGIN_NAMESPACE
00051 
00056 class OSG_SYSTEMLIB_DLLMAPPING Image : public ImageBase
00057 {
00058   private:
00059 
00060     typedef ImageBase Inherited;
00061 
00062     /*==========================  PUBLIC  =================================*/
00063   public:
00064 
00065     enum PixelFormat {   OSG_INVALID_PF = 0,
00066 
00067                          OSG_I_PF       = GL_INTENSITY,
00068 
00069                          OSG_L_PF       = GL_LUMINANCE,
00070                          OSG_LA_PF      = GL_LUMINANCE_ALPHA,
00071 
00072 /*** BGR ***/
00073 #if defined(GL_BGR)
00074                          OSG_BGR_PF     = GL_BGR,
00075 #elif defined(GL_BGR_EXT)
00076                          OSG_BGR_PF     = GL_BGR_EXT,
00077 #else
00078                          OSG_BGR_PF     = 0,
00079 #endif
00080 
00081 /*** BGRA ***/
00082 #if defined(GL_BGRA)
00083                          OSG_BGRA_PF    = GL_BGRA,
00084 #elif defined(GL_BGRA_EXT)
00085                          OSG_BGRA_PF    = GL_BGRA_EXT,
00086 #else
00087                          OSG_BGRA_PF    = 0,
00088 #endif
00089 
00090 /*** RGB_DXT1 ***/
00091 #if defined(GL_COMPRESSED_RGB_S3TC_DXT1_EXT)
00092                          OSG_RGB_DXT1   = GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
00093 #else
00094                          OSG_RGB_DXT1   = 0,
00095 #endif
00096 
00097 /*** RGBA_DXT1 ***/
00098 #if defined(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT)
00099                          OSG_RGBA_DXT1  = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
00100 #else
00101                          OSG_RGBA_DXT1   = 0,
00102 #endif
00103 
00104 /*** RGBA_DXT3 ***/
00105 #if defined(GL_COMPRESSED_RGBA_S3TC_DXT3_EXT)
00106                          OSG_RGBA_DXT3  = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT,
00107 #else
00108                          OSG_RGBA_DXT3   = 0,
00109 #endif
00110 
00111 /*** RGBA_DXT5 ***/
00112 #if defined(GL_COMPRESSED_RGBA_S3TC_DXT5_EXT)
00113                          OSG_RGBA_DXT5  = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT,
00114 #else
00115                          OSG_RGBA_DXT5   = 0,
00116 #endif
00117 
00118                          OSG_RGB_PF     = GL_RGB,
00119                          OSG_RGBA_PF    = GL_RGBA
00120     };
00121 
00122     enum Type {
00123                          OSG_INVALID_IMAGEDATATYPE  = GL_NONE,
00124                          OSG_UINT8_IMAGEDATA        = GL_UNSIGNED_BYTE,
00125                          OSG_UINT16_IMAGEDATA       = GL_UNSIGNED_SHORT,
00126                          OSG_UINT32_IMAGEDATA       = GL_UNSIGNED_INT,
00127                          OSG_FLOAT16_IMAGEDATA      = GL_HALF_FLOAT_NV,
00128                          OSG_FLOAT32_IMAGEDATA      = GL_FLOAT
00129     };
00130 
00131     /*---------------------------------------------------------------------*/
00135     virtual void changed(BitVector  whichField,
00136                          UInt32     origin    );
00137 
00139     /*---------------------------------------------------------------------*/
00143     virtual void dump(      UInt32     uiIndent = 0,
00144                       const BitVector  bvFlags  = 0) const;
00145 
00147     /*---------------------------------------------------------------------*/
00151     bool set                (      UInt32      pixelFormat,
00152                                    Int32       width,
00153                                    Int32       height = 1,
00154                                    Int32       depth = 1,
00155                                    Int32       mipmapCount = 1,
00156                                    Int32       frameCount = 1,
00157                                    Time        frameDelay = 0.0,
00158                                    const UInt8       *data = 0,
00159                                    Int32 type = OSG_UINT8_IMAGEDATA,
00160                                    bool        allocMem = true, 
00161                                    Int32       sideCount = 1);
00162 
00163     bool set                (      ImagePtr   image            );
00164     bool setData            (const UInt8     *data = 0         );
00165     void clearData          (void                              );
00166     bool setSubData ( Int32 offX, Int32 offY, Int32 offZ,
00167                       Int32 srcW, Int32 srcH, Int32 srcD,
00168                       const UInt8 *data );
00169     bool flipDepthFrameData (void                              );
00170 
00171 
00173     /*---------------------------------------------------------------------*/
00177     bool addValue (const char *value);
00178 
00180     /*---------------------------------------------------------------------*/
00184     bool reformat ( const PixelFormat pixelFormat,
00185                     ImagePtr destination = NullFC);
00186 
00188     /*---------------------------------------------------------------------*/
00192     void swapDataEndian(void);
00193     bool convertDataTypeTo ( Int32 destDataType = OSG_UINT8_IMAGEDATA );
00194 
00196     /*---------------------------------------------------------------------*/
00200     bool scale          ( Int32 width, Int32 height = 1,
00201                           Int32 depth = 1,
00202                           ImagePtr destination = NullFC );
00203     bool scaleNextPower2( ImagePtr destination = NullFC );
00204 
00206     /*---------------------------------------------------------------------*/
00210     bool subImage ( Int32 offX, Int32 offY, Int32 offZ,
00211                     Int32 destW, Int32 destH, Int32 destD,
00212                     ImagePtr destination = NullFC);
00213 
00215     /*---------------------------------------------------------------------*/
00219     bool slice ( Int32 offX = -1, Int32 offY = -1, Int32 offZ = -1,
00220                  ImagePtr destination = NullFC);
00221 
00223     /*---------------------------------------------------------------------*/
00227     bool createMipmap ( Int32 level = -1, ImagePtr destination = NullFC);
00228 
00230     /*---------------------------------------------------------------------*/
00234     bool write (const Char8 *fileName);
00235     bool read  (const Char8 *fileName);
00236 
00238     /*---------------------------------------------------------------------*/
00242     UInt64 store   (const Char8 *mimeType, UInt8* mem, Int32 memSize = -1);
00243     UInt64 restore (const UInt8* mem, Int32 memSize = -1);
00244 
00246     /*---------------------------------------------------------------------*/
00250     Image &operator =  (const Image &image);
00251     bool   operator <  (const Image &image);
00252     bool   operator == (const Image &image);
00253     bool   operator != (const Image &image);
00254 
00256     /*---------------------------------------------------------------------*/
00260     inline bool   isValid           (void) const;
00261            bool   hasAlphaChannel   (void);
00262            bool   hasColorChannel   (void);
00263            bool   hasCompressedData (void);
00264            UInt8  getComponents     (void) const;
00265 
00267     /*---------------------------------------------------------------------*/
00271     inline unsigned long getSize ( bool withMipmap = true,
00272                                    bool withFrames = true,
00273                                    bool withSides  = true ) const;
00274 
00276     /*---------------------------------------------------------------------*/
00280     inline const UInt8 *getData ( UInt32 mipmapNum = 0,
00281                                   UInt32 frameNum = 0,
00282                                   UInt32 sideNum = 0 ) const;
00283     inline       UInt8 *getData ( UInt32 mipmapNum = 0,
00284                                   UInt32 frameNum = 0,
00285                                   UInt32 sideNum = 0 );
00286 
00287     UInt8 *getDataByTime(Time time, UInt32 mipmapNum = 1);
00288 
00290     /*---------------------------------------------------------------------*/
00294     void   calcMipmapGeometry   ( UInt32 mipmapNum,
00295                                   UInt32 &width,
00296                                   UInt32 &height,
00297                                   UInt32 &depth       ) const;
00298 
00299     UInt32 calcMipmapLevelCount ( void                       ) const;
00300     UInt32 calcFrameNum         ( Time time, bool loop = true) const;
00301 
00303     /*---------------------------------------------------------------------*/
00307     virtual void clear (UChar8 pixelValue = 0);
00308     virtual void clearFloat (Real32 pixelValue = 0.0);
00309     virtual void clearHalf (Real16 pixelValue = Real16( 0.0 ));
00310 
00312     /*---------------------------------------------------------------------*/
00316     bool   hasAttachment   (void) const;
00317     UInt32 attachmentCount (void) const;
00318     void   setAttachmentField ( const std::string &key,
00319                                 const std::string &data);
00320     const std::string * findAttachmentField ( const std::string &key) const;
00321 
00323     /*---------------------------------------------------------------------*/
00327     UInt32 calcMipmapLevelSize( UInt32 mipmapNum,
00328                                      UInt32 w, UInt32 h, UInt32 d) const;
00329     UInt32 calcMipmapLevelSize( UInt32 mipmapNum                 ) const;
00330 
00331     UInt32 calcMipmapSumSize  ( UInt32 mipmapNum,
00332                                      UInt32 w, UInt32 h, UInt32 d) const;
00333     UInt32 calcMipmapSumSize  ( UInt32 mipmapNum                 ) const;
00334 
00336     /*=========================  PROTECTED  ===============================*/
00337   protected:
00338 
00339     /*---------------------------------------------------------------------*/
00343     static Int32 _formatDic[][2];
00344     static Int32 _typeDic[][2];
00345 
00347     /*---------------------------------------------------------------------*/
00351     Image(void);
00352     Image(const Image &source);
00353 
00355     /*---------------------------------------------------------------------*/
00359     virtual ~Image(void);
00360 
00363     /*==========================  PRIVATE  ================================*/
00364   private:
00365     /*---------------------------------------------------------------------*/
00369     bool createData ( const UInt8 *data, bool allocMem = true );
00370     bool scaleData  ( UInt8* srcData,
00371                       Int32 srcW, Int32 srcH, Int32 srcD,
00372                       UInt8* destData,
00373                       Int32 destW, Int32 destH, Int32 destD );
00374 
00377     friend class FieldContainer;
00378     friend class ImageBase;
00379 
00380     static void initMethod(void);
00381 };
00382 
00383 typedef Image *ImageP;
00384 
00385 OSG_END_NAMESPACE
00386 
00387 #include <OSGImageBase.inl>
00388 #include <OSGImage.inl>
00389 
00390 #define OSGIMAGE_HEADER_CVSID "@(#)$Id: $"
00391 
00392 #endif /* _OSGIMAGE_H_ */

Generated on Thu Aug 25 04:06:01 2005 for OpenSG by  doxygen 1.4.3