1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-2002 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
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. *
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. *
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. *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
37 \*---------------------------------------------------------------------------*/
45 #include "OSGConfig.h"
46 #include "OSGImageBase.h"
48 #include "OSGReal16.h"
52 /*! \brief Image class. See \ref PageSystemImage
54 \ingroup GrpSystemImageObj
55 \ingroup GrpLibOSGSystem
59 class OSG_SYSTEM_DLLMAPPING Image
: public ImageBase
63 /*========================== PUBLIC =================================*/
67 typedef ImageBase Inherited
;
73 OSG_I_PF
= GL_INTENSITY
,
74 OSG_L_PF
= GL_LUMINANCE
,
75 OSG_LA_PF
= GL_LUMINANCE_ALPHA
,
81 OSG_RGBA_PF
= GL_RGBA
,
85 #elif defined(GL_BGR_EXT)
86 OSG_BGR_PF
= GL_BGR_EXT
,
93 OSG_BGRA_PF
= GL_BGRA
,
94 #elif defined(GL_BGRA_EXT)
95 OSG_BGRA_PF
= GL_BGRA_EXT
,
100 #if defined(GL_COMPRESSED_RGB_S3TC_DXT1_EXT)
101 OSG_RGB_DXT1
= GL_COMPRESSED_RGB_S3TC_DXT1_EXT
,
107 #if defined(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT)
108 OSG_RGBA_DXT1
= GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
,
114 #if defined(GL_COMPRESSED_RGBA_S3TC_DXT3_EXT)
115 OSG_RGBA_DXT3
= GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
,
121 #if defined(GL_COMPRESSED_RGBA_S3TC_DXT5_EXT)
122 OSG_RGBA_DXT5
= GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
,
127 OSG_DEPTH_PF
= GL_DEPTH_COMPONENT
,
129 /*** GL_EXT_packed_depth_stencil ***/
130 #if defined(GL_DEPTH_STENCIL)
131 OSG_DEPTH_STENCIL_PF
= GL_DEPTH_STENCIL
,
132 #elif defined(GL_DEPTH_STENCIL_EXT)
133 OSG_DEPTH_STENCIL_PF
= GL_DEPTH_STENCIL_EXT
,
134 #elif defined(GL_DEPTH_STENCIL_NV)
135 OSG_DEPTH_STENCIL_PF
= GL_DEPTH_STENCIL_NV
,
137 OSG_DEPTH_STENCIL_PF
= 0,
140 OSG_ALPHA_INTEGER_PF
= GL_ALPHA_INTEGER_EXT
,
141 OSG_RGB_INTEGER_PF
= GL_RGB_INTEGER_EXT
,
142 OSG_RGBA_INTEGER_PF
= GL_RGBA_INTEGER_EXT
,
143 OSG_BGR_INTEGER_PF
= GL_BGR_INTEGER_EXT
,
144 OSG_BGRA_INTEGER_PF
= GL_BGRA_INTEGER_EXT
,
145 OSG_LUMINANCE_INTEGER_PF
= GL_LUMINANCE_INTEGER_EXT
,
146 OSG_LUMINANCE_ALPHA_INTEGER_PF
= GL_LUMINANCE_ALPHA_INTEGER_EXT
153 OSG_INVALID_IMAGEDATATYPE
= GL_NONE
,
154 OSG_UINT8_IMAGEDATA
= GL_UNSIGNED_BYTE
,
155 OSG_UINT16_IMAGEDATA
= GL_UNSIGNED_SHORT
,
156 OSG_UINT32_IMAGEDATA
= GL_UNSIGNED_INT
,
157 OSG_FLOAT16_IMAGEDATA
= GL_HALF_FLOAT_NV
,
158 OSG_FLOAT32_IMAGEDATA
= GL_FLOAT
,
159 OSG_INT16_IMAGEDATA
= GL_SHORT
,
160 OSG_INT32_IMAGEDATA
= GL_INT
,
162 /*** GL_EXT_packed_depth_stencil ***/
163 #if defined(GL_UNSIGNED_INT_24_8_EXT)
164 OSG_UINT24_8_IMAGEDATA
= GL_UNSIGNED_INT_24_8_EXT
165 #elif defined(GL_UNSIGNED_INT_24_8_NV)
166 OSG_UINT24_8_IMAGEDATA
= GL_UNSIGNED_INT_24_8_NV
168 OSG_UINT24_8_IMAGEDATA
= GL_NONE
174 OSG_RESUNIT_INVALID
= 0,
175 OSG_RESUNIT_NONE
= 1,
179 /*---------------------------------------------------------------------*/
183 virtual void changed(ConstFieldMaskArg whichField
,
188 /*---------------------------------------------------------------------*/
192 virtual void dump( UInt32 uiIndent
= 0,
193 const BitVector bvFlags
= 0) const;
196 /*---------------------------------------------------------------------*/
197 /*! \name Set Object Data */
200 bool set ( UInt32 pixelFormat
,
204 Int32 mipmapCount
= 1,
205 Int32 frameCount
= 1,
206 Time frameDelay
= 0.0,
207 const UInt8
*data
= 0,
208 Int32 type
= OSG_UINT8_IMAGEDATA
,
209 bool allocMem
= true,
210 Int32 sidecount
= 1 );
211 bool set ( Image
*image
);
212 bool setData (const UInt8
*data
= 0 );
213 void clearData ( void );
214 bool setSubData ( Int32 offX
,
221 bool flipDepthFrameData( void );
225 /*---------------------------------------------------------------------*/
226 /*! \name Add Value */
229 bool addValue(const Char8
*value
);
232 /*---------------------------------------------------------------------*/
233 /*! \name Reformate */
236 bool reformat(const PixelFormat pixelFormat
,
237 Image
*destination
= NULL
,
238 Int32 iCompressionFlags
= 0);
241 /*---------------------------------------------------------------------*/
242 /*! \name Convert dataType */
245 void swapDataEndian (void );
246 bool convertDataTypeTo(Int32 destDataType
= OSG_UINT8_IMAGEDATA
);
249 /*---------------------------------------------------------------------*/
253 bool scale (Int32 width
,
256 Image
*destination
= NULL
);
257 bool scaleNextPower2(Image
*destination
= NULL
);
260 /*---------------------------------------------------------------------*/
264 bool mirror (bool horizontal
,
266 bool flipDepth
= false,
267 Image
*destination
= NULL
);
270 /*---------------------------------------------------------------------*/
271 /*! \name SubImage */
274 bool subImage(Int32 offX
,
280 Image
*destination
= NULL
);
283 /*---------------------------------------------------------------------*/
287 bool slice(Int32 offX
= -1,
290 Image
*destination
= NULL
);
293 /*---------------------------------------------------------------------*/
297 bool createMipmap(Int32 level
= -1,
298 Image
*destination
= NULL
);
300 bool removeMipmap(void );
303 /*---------------------------------------------------------------------*/
304 /*! \name Read/Write */
307 bool write(const Char8
*fileName
);
308 bool read (const Char8
*fileName
);
311 /*---------------------------------------------------------------------*/
312 /*! \name Storage/Restore */
315 UInt64
store (const Char8
*mimeType
,
318 UInt64
restore(const UInt8
*mem
,
322 /*---------------------------------------------------------------------*/
323 /*! \name Comparison/Assign */
326 Image
&operator = (const Image
&image
);
327 bool operator < (const Image
&image
);
328 bool operator == (const Image
&image
);
329 bool operator != (const Image
&image
);
332 /*---------------------------------------------------------------------*/
333 /*! \name Get Methods */
336 bool isValid (void) const;
337 bool hasAlphaChannel (void);
338 bool isAlphaBinary (void);
339 bool hasColorChannel (void);
340 bool hasCompressedData(void);
341 UInt8
getComponents (void) const;
343 bool calcIsAlphaBinary(void);
345 SizeT
getHash (bool force
= false) const;
348 /*---------------------------------------------------------------------*/
352 unsigned long getSize(bool withMipmap
= true,
353 bool withFrames
= true,
354 bool withSides
= true) const;
357 /*---------------------------------------------------------------------*/
358 /*! \name Get Methods */
361 const UInt8
*getData (UInt32 mipmapNum
= 0,
363 UInt32 sidecount
= 0) const;
364 UInt8
*editData (UInt32 mipmapNum
= 0,
366 UInt32 sidecount
= 0);
368 const UInt8
*getDataFast (UInt32 mipmapNum
= 0,
370 UInt32 sidecount
= 0);
371 UInt8
*editDataFast (UInt32 mipmapNum
= 0,
373 UInt32 sidecount
= 0);
375 const UInt8
*getDataByTime (Time time
,
376 UInt32 mipmapNum
= 1) const;
377 UInt8
*editDataByTime(Time time
,
378 UInt32 mipmapNum
= 1);
381 /*---------------------------------------------------------------------*/
382 /*! \name Calculate */
385 void calcMipmapGeometry (UInt32 mipmapNum
,
388 UInt32
&depth
) const;
389 UInt32
calcMipmapLevelCount(void ) const;
390 UInt32
calcFrameNum (Time time
,
391 bool loop
= true) const;
394 /*---------------------------------------------------------------------*/
395 /*! \name Clear Image */
398 virtual void clear (UChar8 pixelValue
= 0 );
399 virtual void clearFloat(Real32 pixelValue
= 0.0 );
400 virtual void clearHalf (Real16 pixelValue
= Real16( 0.0 ));
403 /*---------------------------------------------------------------------*/
404 /*! \name attachment handling */
407 bool hasAttachment ( void ) const;
408 UInt32
attachmentCount ( void ) const;
409 void setAttachmentField (const std::string
&key
,
410 const std::string
&data
);
411 const std::string
*findAttachmentField(const std::string
&key
) const;
414 /*---------------------------------------------------------------------*/
415 /*! \name Calculate Mipmap Size */
418 UInt32
calcMipmapLevelSize(UInt32 mipmapNum
,
422 UInt32
calcMipmapLevelSize(UInt32 mipmapNum
) const;
424 UInt32
calcMipmapSumSize (UInt32 mipmapNum
,
428 UInt32
calcMipmapSumSize (UInt32 mipmapNum
) const;
431 /*---------------------------------------------------------------------*/
432 /*! \name Don't know yet */
436 void imageContentChanged(Int32 minX
= -1, Int32 maxX
= -1,
437 Int32 minY
= -1, Int32 maxY
= -1,
438 Int32 minZ
= -1, Int32 maxZ
= -1 );
442 /*========================= PROTECTED ===============================*/
446 std::vector
<Int32
> _mipmapOffset
;
448 mutable bool _hashValid
;
450 /*---------------------------------------------------------------------*/
451 /*! \name static element */
454 static UInt32 _formatDic
[][2];
455 static Int32 _typeDic
[][2];
458 /*---------------------------------------------------------------------*/
459 /*! \name Constructors */
463 Image(const Image
&source
);
466 /*---------------------------------------------------------------------*/
467 /*! \name Destructors */
470 virtual ~Image(void);
473 /*---------------------------------------------------------------------*/
477 static void initMethod(InitPhase ePhase
);
480 /*========================== PRIVATE ================================*/
484 /*---------------------------------------------------------------------*/
485 /*! \name Image Data */
488 bool createData (const UInt8
*data
,
489 bool allocMem
= true );
490 bool scaleData (const UInt8
*srcData
,
499 void calcMipmapOffsets( void );
500 void calcHash ( void ) const;
502 bool mirrorData (const UInt8
*srcData
,
509 bool flipDepth
= false);
512 /*---------------------------------------------------------------------*/
514 friend class FieldContainer
;
515 friend class ImageBase
;
518 typedef Image
*ImageP
;
522 #include "OSGImageBase.inl"
523 #include "OSGImage.inl"
525 #endif /* _OSGIMAGE_H_ */