00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
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
00063 public:
00064
00065 enum PixelFormat { OSG_INVALID_PF = 0,
00066
00067 OSG_A_PF = GL_ALPHA,
00068 OSG_I_PF = GL_INTENSITY,
00069
00070 OSG_L_PF = GL_LUMINANCE,
00071 OSG_LA_PF = GL_LUMINANCE_ALPHA,
00072
00073
00074 #if defined(GL_BGR)
00075 OSG_BGR_PF = GL_BGR,
00076 #elif defined(GL_BGR_EXT)
00077 OSG_BGR_PF = GL_BGR_EXT,
00078 #else
00079 OSG_BGR_PF = 0,
00080 #endif
00081
00082
00083 #if defined(GL_BGRA)
00084 OSG_BGRA_PF = GL_BGRA,
00085 #elif defined(GL_BGRA_EXT)
00086 OSG_BGRA_PF = GL_BGRA_EXT,
00087 #else
00088 OSG_BGRA_PF = 0,
00089 #endif
00090
00091
00092 #if defined(GL_COMPRESSED_RGB_S3TC_DXT1_EXT)
00093 OSG_RGB_DXT1 = GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
00094 #else
00095 OSG_RGB_DXT1 = 0,
00096 #endif
00097
00098
00099 #if defined(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT)
00100 OSG_RGBA_DXT1 = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
00101 #else
00102 OSG_RGBA_DXT1 = 0,
00103 #endif
00104
00105
00106 #if defined(GL_COMPRESSED_RGBA_S3TC_DXT3_EXT)
00107 OSG_RGBA_DXT3 = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT,
00108 #else
00109 OSG_RGBA_DXT3 = 0,
00110 #endif
00111
00112
00113 #if defined(GL_COMPRESSED_RGBA_S3TC_DXT5_EXT)
00114 OSG_RGBA_DXT5 = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT,
00115 #else
00116 OSG_RGBA_DXT5 = 0,
00117 #endif
00118
00119 OSG_RGB_PF = GL_RGB,
00120 OSG_RGBA_PF = GL_RGBA,
00121
00122 OSG_ALPHA_INTEGER_PF = GL_ALPHA_INTEGER_EXT,
00123 OSG_RGB_INTEGER_PF = GL_RGB_INTEGER_EXT,
00124 OSG_RGBA_INTEGER_PF = GL_RGBA_INTEGER_EXT,
00125 OSG_BGR_INTEGER_PF = GL_BGR_INTEGER_EXT,
00126 OSG_BGRA_INTEGER_PF = GL_BGRA_INTEGER_EXT,
00127 OSG_LUMINANCE_INTEGER_PF = GL_LUMINANCE_INTEGER_EXT,
00128 OSG_LUMINANCE_ALPHA_INTEGER_PF = GL_LUMINANCE_ALPHA_INTEGER_EXT
00129 };
00130
00131 enum Type {
00132 OSG_INVALID_IMAGEDATATYPE = GL_NONE,
00133 OSG_UINT8_IMAGEDATA = GL_UNSIGNED_BYTE,
00134 OSG_UINT16_IMAGEDATA = GL_UNSIGNED_SHORT,
00135 OSG_UINT32_IMAGEDATA = GL_UNSIGNED_INT,
00136 OSG_FLOAT16_IMAGEDATA = GL_HALF_FLOAT_NV,
00137 OSG_FLOAT32_IMAGEDATA = GL_FLOAT,
00138 OSG_INT16_IMAGEDATA = GL_SHORT,
00139 OSG_INT32_IMAGEDATA = GL_INT
00140 };
00141
00142 enum ResUnit {
00143 OSG_RESUNIT_INVALID = 0,
00144 OSG_RESUNIT_NONE = 1,
00145 OSG_RESUNIT_INCH = 2
00146 };
00147
00148
00152 virtual void changed(BitVector whichField,
00153 UInt32 origin );
00154
00156
00160 virtual void dump( UInt32 uiIndent = 0,
00161 const BitVector bvFlags = 0) const;
00162
00164
00168 bool set ( UInt32 pixelFormat,
00169 Int32 width,
00170 Int32 height = 1,
00171 Int32 depth = 1,
00172 Int32 mipmapCount = 1,
00173 Int32 frameCount = 1,
00174 Time frameDelay = 0.0,
00175 const UInt8 *data = 0,
00176 Int32 type = OSG_UINT8_IMAGEDATA,
00177 bool allocMem = true,
00178 Int32 sideCount = 1);
00179
00180 bool set ( ImagePtr image );
00181 bool setData (const UInt8 *data = 0 );
00182 void clearData (void );
00183 bool setSubData ( Int32 offX, Int32 offY, Int32 offZ,
00184 Int32 srcW, Int32 srcH, Int32 srcD,
00185 const UInt8 *data );
00186 bool flipDepthFrameData (void );
00187
00188
00190
00194 bool addValue (const char *value);
00195
00197
00201 bool reformat ( const PixelFormat pixelFormat,
00202 ImagePtr destination = NullFC);
00203
00205
00209 void swapDataEndian(void);
00210 bool convertDataTypeTo ( Int32 destDataType = OSG_UINT8_IMAGEDATA );
00211
00213
00217 bool scale ( Int32 width, Int32 height = 1,
00218 Int32 depth = 1,
00219 ImagePtr destination = NullFC );
00220 bool scaleNextPower2( ImagePtr destination = NullFC );
00221
00223
00227 bool subImage ( Int32 offX, Int32 offY, Int32 offZ,
00228 Int32 destW, Int32 destH, Int32 destD,
00229 ImagePtr destination = NullFC);
00230
00232
00236 bool slice ( Int32 offX = -1, Int32 offY = -1, Int32 offZ = -1,
00237 ImagePtr destination = NullFC);
00238
00240
00244 bool createMipmap ( Int32 level = -1, ImagePtr destination = NullFC);
00245
00247
00251 bool write (const Char8 *fileName);
00252 bool read (const Char8 *fileName);
00253
00255
00259 UInt64 store (const Char8 *mimeType, UInt8* mem, Int32 memSize = -1);
00260 UInt64 restore (const UInt8* mem, Int32 memSize = -1);
00261
00263
00267 Image &operator = (const Image &image);
00268 bool operator < (const Image &image);
00269 bool operator == (const Image &image);
00270 bool operator != (const Image &image);
00271
00273
00277 inline bool isValid (void) const;
00278 bool hasAlphaChannel (void);
00279 bool isAlphaBinary (void);
00280 bool hasColorChannel (void);
00281 bool hasCompressedData (void);
00282 UInt8 getComponents (void) const;
00283
00284 bool calcIsAlphaBinary (void);
00285
00287
00291 inline unsigned long getSize ( bool withMipmap = true,
00292 bool withFrames = true,
00293 bool withSides = true ) const;
00294
00296
00300 inline const UInt8 *getData ( UInt32 mipmapNum = 0,
00301 UInt32 frameNum = 0,
00302 UInt32 sideNum = 0 ) const;
00303 inline UInt8 *getData ( UInt32 mipmapNum = 0,
00304 UInt32 frameNum = 0,
00305 UInt32 sideNum = 0 );
00306
00307 UInt8 *getDataByTime(Time time, UInt32 mipmapNum = 1);
00308
00310
00314 void calcMipmapGeometry ( UInt32 mipmapNum,
00315 UInt32 &width,
00316 UInt32 &height,
00317 UInt32 &depth ) const;
00318
00319 UInt32 calcMipmapLevelCount ( void ) const;
00320 UInt32 calcFrameNum ( Time time, bool loop = true) const;
00321
00323
00327 virtual void clear (UChar8 pixelValue = 0);
00328 virtual void clearFloat (Real32 pixelValue = 0.0);
00329 virtual void clearHalf (Real16 pixelValue = Real16( 0.0 ));
00330
00332
00336 bool hasAttachment (void) const;
00337 UInt32 attachmentCount (void) const;
00338 void setAttachmentField ( const std::string &key,
00339 const std::string &data);
00340 const std::string * findAttachmentField ( const std::string &key) const;
00341
00343
00347 UInt32 calcMipmapLevelSize( UInt32 mipmapNum,
00348 UInt32 w, UInt32 h, UInt32 d) const;
00349 UInt32 calcMipmapLevelSize( UInt32 mipmapNum ) const;
00350
00351 UInt32 calcMipmapSumSize ( UInt32 mipmapNum,
00352 UInt32 w, UInt32 h, UInt32 d) const;
00353 UInt32 calcMipmapSumSize ( UInt32 mipmapNum ) const;
00354
00356
00357 protected:
00358
00359
00363 static Int32 _formatDic[][2];
00364 static Int32 _typeDic[][2];
00365
00367
00371 Image(void);
00372 Image(const Image &source);
00373
00375
00379 virtual ~Image(void);
00380
00383 #if defined(OSG_FIXED_MFIELDSYNC)
00384 virtual void onDestroyAspect(UInt32 uiId, UInt32 uiAspect);
00385 #endif
00386
00387
00388 private:
00389
00393 bool createData ( const UInt8 *data, bool allocMem = true );
00394 bool scaleData ( UInt8* srcData,
00395 Int32 srcW, Int32 srcH, Int32 srcD,
00396 UInt8* destData,
00397 Int32 destW, Int32 destH, Int32 destD );
00398
00401 friend class FieldContainer;
00402 friend class ImageBase;
00403
00404 static void initMethod(void);
00405 };
00406
00407 typedef Image *ImageP;
00408
00409 OSG_END_NAMESPACE
00410
00411 #include <OSGImageBase.inl>
00412 #include <OSGImage.inl>
00413
00414 #define OSGIMAGE_HEADER_CVSID "@(#)$Id: $"
00415
00416 #endif