fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / Image / OSGImage.h
blob3074d1082451652eaa4d4d32a53dab13b3ece2cc
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 \*---------------------------------------------------------------------------*/
39 #ifndef _OSGIMAGE_H_
40 #define _OSGIMAGE_H_
41 #ifdef __sgi
42 #pragma once
43 #endif
45 #include "OSGConfig.h"
46 #include "OSGImageBase.h"
47 #include "OSGGLEXT.h"
48 #include "OSGReal16.h"
50 OSG_BEGIN_NAMESPACE
52 /*! \brief Image class. See \ref PageSystemImage
53 for a description.
54 \ingroup GrpSystemImageObj
55 \ingroup GrpLibOSGSystem
56 \includebasedoc
59 class OSG_SYSTEM_DLLMAPPING Image : public ImageBase
61 private:
63 /*========================== PUBLIC =================================*/
65 public:
67 typedef ImageBase Inherited;
69 enum PixelFormat
71 OSG_INVALID_PF = 0,
72 OSG_A_PF = GL_ALPHA,
73 OSG_I_PF = GL_INTENSITY,
74 OSG_L_PF = GL_LUMINANCE,
75 OSG_LA_PF = GL_LUMINANCE_ALPHA,
77 OSG_R_PF = GL_RED,
78 OSG_RG_PF = GL_RG,
80 OSG_RGB_PF = GL_RGB,
81 OSG_RGBA_PF = GL_RGBA,
82 /*** BGR ***/
83 #if defined(GL_BGR)
84 OSG_BGR_PF = GL_BGR,
85 #elif defined(GL_BGR_EXT)
86 OSG_BGR_PF = GL_BGR_EXT,
87 #else
88 OSG_BGR_PF = 0,
89 #endif
91 /*** BGRA ***/
92 #if defined(GL_BGRA)
93 OSG_BGRA_PF = GL_BGRA,
94 #elif defined(GL_BGRA_EXT)
95 OSG_BGRA_PF = GL_BGRA_EXT,
96 #else
97 OSG_BGRA_PF = 0,
98 #endif
99 /*** RGB_DXT1 ***/
100 #if defined(GL_COMPRESSED_RGB_S3TC_DXT1_EXT)
101 OSG_RGB_DXT1 = GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
102 #else
103 OSG_RGB_DXT1 = 0,
104 #endif
106 /*** RGBA_DXT1 ***/
107 #if defined(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT)
108 OSG_RGBA_DXT1 = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
109 #else
110 OSG_RGBA_DXT1 = 0,
111 #endif
113 /*** RGBA_DXT3 ***/
114 #if defined(GL_COMPRESSED_RGBA_S3TC_DXT3_EXT)
115 OSG_RGBA_DXT3 = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT,
116 #else
117 OSG_RGBA_DXT3 = 0,
118 #endif
120 /*** RGBA_DXT5 ***/
121 #if defined(GL_COMPRESSED_RGBA_S3TC_DXT5_EXT)
122 OSG_RGBA_DXT5 = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT,
123 #else
124 OSG_RGBA_DXT5 = 0,
125 #endif
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,
136 #else
137 OSG_DEPTH_STENCIL_PF = 0,
138 #endif
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
151 enum Type
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
167 #else
168 OSG_UINT24_8_IMAGEDATA = GL_NONE
169 #endif
172 enum ResUnit
174 OSG_RESUNIT_INVALID = 0,
175 OSG_RESUNIT_NONE = 1,
176 OSG_RESUNIT_INCH = 2
179 /*---------------------------------------------------------------------*/
180 /*! \name Sync */
181 /*! \{ */
183 virtual void changed(ConstFieldMaskArg whichField,
184 UInt32 origin,
185 BitVector details);
187 /*! \} */
188 /*---------------------------------------------------------------------*/
189 /*! \name Output */
190 /*! \{ */
192 virtual void dump( UInt32 uiIndent = 0,
193 const BitVector bvFlags = 0) const;
195 /*! \} */
196 /*---------------------------------------------------------------------*/
197 /*! \name Set Object Data */
198 /*! \{ */
200 bool set ( UInt32 pixelFormat,
201 Int32 width,
202 Int32 height = 1,
203 Int32 depth = 1,
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,
215 Int32 offY,
216 Int32 offZ,
217 Int32 srcW,
218 Int32 srcH,
219 Int32 srcD,
220 const UInt8 *data );
221 bool flipDepthFrameData( void );
224 /*! \} */
225 /*---------------------------------------------------------------------*/
226 /*! \name Add Value */
227 /*! \{ */
229 bool addValue(const Char8 *value);
231 /*! \} */
232 /*---------------------------------------------------------------------*/
233 /*! \name Reformate */
234 /*! \{ */
236 bool reformat(const PixelFormat pixelFormat,
237 Image *destination = NULL,
238 Int32 iCompressionFlags = 0);
240 /*! \} */
241 /*---------------------------------------------------------------------*/
242 /*! \name Convert dataType */
243 /*! \{ */
245 void swapDataEndian (void );
246 bool convertDataTypeTo(Int32 destDataType = OSG_UINT8_IMAGEDATA);
248 /*! \} */
249 /*---------------------------------------------------------------------*/
250 /*! \name Scale */
251 /*! \{ */
253 bool scale (Int32 width,
254 Int32 height = 1,
255 Int32 depth = 1,
256 Image *destination = NULL);
257 bool scaleNextPower2(Image *destination = NULL);
259 /*! \} */
260 /*---------------------------------------------------------------------*/
261 /*! \name Mirror */
262 /*! \{ */
264 bool mirror (bool horizontal,
265 bool vertical,
266 bool flipDepth = false,
267 Image *destination = NULL );
269 /*! \} */
270 /*---------------------------------------------------------------------*/
271 /*! \name SubImage */
272 /*! \{ */
274 bool subImage(Int32 offX,
275 Int32 offY,
276 Int32 offZ,
277 Int32 destW,
278 Int32 destH,
279 Int32 destD,
280 Image *destination = NULL);
282 /*! \} */
283 /*---------------------------------------------------------------------*/
284 /*! \name Slice */
285 /*! \{ */
287 bool slice(Int32 offX = -1,
288 Int32 offY = -1,
289 Int32 offZ = -1,
290 Image *destination = NULL);
292 /*! \} */
293 /*---------------------------------------------------------------------*/
294 /*! \name Mipmap */
295 /*! \{ */
297 bool createMipmap(Int32 level = -1,
298 Image *destination = NULL);
300 bool removeMipmap(void );
302 /*! \} */
303 /*---------------------------------------------------------------------*/
304 /*! \name Read/Write */
305 /*! \{ */
307 bool write(const Char8 *fileName);
308 bool read (const Char8 *fileName);
310 /*! \} */
311 /*---------------------------------------------------------------------*/
312 /*! \name Storage/Restore */
313 /*! \{ */
315 UInt64 store (const Char8 *mimeType,
316 UInt8 *mem,
317 Int32 memSize = -1);
318 UInt64 restore(const UInt8 *mem,
319 Int32 memSize = -1);
321 /*! \} */
322 /*---------------------------------------------------------------------*/
323 /*! \name Comparison/Assign */
324 /*! \{ */
326 Image &operator = (const Image &image);
327 bool operator < (const Image &image);
328 bool operator == (const Image &image);
329 bool operator != (const Image &image);
331 /*! \} */
332 /*---------------------------------------------------------------------*/
333 /*! \name Get Methods */
334 /*! \{ */
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;
347 /*! \} */
348 /*---------------------------------------------------------------------*/
349 /*! \name Size */
350 /*! \{ */
352 unsigned long getSize(bool withMipmap = true,
353 bool withFrames = true,
354 bool withSides = true) const;
356 /*! \} */
357 /*---------------------------------------------------------------------*/
358 /*! \name Get Methods */
359 /*! \{ */
361 const UInt8 *getData (UInt32 mipmapNum = 0,
362 UInt32 frameNum = 0,
363 UInt32 sidecount = 0) const;
364 UInt8 *editData (UInt32 mipmapNum = 0,
365 UInt32 frameNum = 0,
366 UInt32 sidecount = 0);
368 const UInt8 *getDataFast (UInt32 mipmapNum = 0,
369 UInt32 frameNum = 0,
370 UInt32 sidecount = 0);
371 UInt8 *editDataFast (UInt32 mipmapNum = 0,
372 UInt32 frameNum = 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);
380 /*! \} */
381 /*---------------------------------------------------------------------*/
382 /*! \name Calculate */
383 /*! \{ */
385 void calcMipmapGeometry (UInt32 mipmapNum,
386 UInt32 &width,
387 UInt32 &height,
388 UInt32 &depth ) const;
389 UInt32 calcMipmapLevelCount(void ) const;
390 UInt32 calcFrameNum (Time time,
391 bool loop = true) const;
393 /*! \} */
394 /*---------------------------------------------------------------------*/
395 /*! \name Clear Image */
396 /*! \{ */
398 virtual void clear (UChar8 pixelValue = 0 );
399 virtual void clearFloat(Real32 pixelValue = 0.0 );
400 virtual void clearHalf (Real16 pixelValue = Real16( 0.0 ));
402 /*! \} */
403 /*---------------------------------------------------------------------*/
404 /*! \name attachment handling */
405 /*! \{ */
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;
413 /*! \} */
414 /*---------------------------------------------------------------------*/
415 /*! \name Calculate Mipmap Size */
416 /*! \{ */
418 UInt32 calcMipmapLevelSize(UInt32 mipmapNum,
419 UInt32 w,
420 UInt32 h,
421 UInt32 d ) const;
422 UInt32 calcMipmapLevelSize(UInt32 mipmapNum) const;
424 UInt32 calcMipmapSumSize (UInt32 mipmapNum,
425 UInt32 w,
426 UInt32 h,
427 UInt32 d ) const;
428 UInt32 calcMipmapSumSize (UInt32 mipmapNum) const;
430 /*! \} */
431 /*---------------------------------------------------------------------*/
432 /*! \name Don't know yet */
433 /*! \{ */
435 #if 0
436 void imageContentChanged(Int32 minX = -1, Int32 maxX = -1,
437 Int32 minY = -1, Int32 maxY = -1,
438 Int32 minZ = -1, Int32 maxZ = -1 );
439 #endif
441 /*! \} */
442 /*========================= PROTECTED ===============================*/
444 protected:
446 std::vector<Int32> _mipmapOffset;
447 mutable SizeT _hash;
448 mutable bool _hashValid;
450 /*---------------------------------------------------------------------*/
451 /*! \name static element */
452 /*! \{ */
454 static UInt32 _formatDic[][2];
455 static Int32 _typeDic [][2];
457 /*! \} */
458 /*---------------------------------------------------------------------*/
459 /*! \name Constructors */
460 /*! \{ */
462 Image(void);
463 Image(const Image &source);
465 /*! \} */
466 /*---------------------------------------------------------------------*/
467 /*! \name Destructors */
468 /*! \{ */
470 virtual ~Image(void);
472 /*! \} */
473 /*---------------------------------------------------------------------*/
474 /*! \name Init */
475 /*! \{ */
477 static void initMethod(InitPhase ePhase);
479 /*! \} */
480 /*========================== PRIVATE ================================*/
482 private:
484 /*---------------------------------------------------------------------*/
485 /*! \name Image Data */
486 /*! \{ */
488 bool createData (const UInt8 *data,
489 bool allocMem = true );
490 bool scaleData (const UInt8 *srcData,
491 Int32 srcW,
492 Int32 srcH,
493 Int32 srcD,
494 UInt8 *destData,
495 Int32 destW,
496 Int32 destH,
497 Int32 destD );
499 void calcMipmapOffsets( void );
500 void calcHash ( void ) const;
502 bool mirrorData (const UInt8 *srcData,
503 UInt8 *destData,
504 Int32 width,
505 Int32 height,
506 Int32 depth,
507 bool horizontal,
508 bool vertical,
509 bool flipDepth = false);
511 /*! \} */
512 /*---------------------------------------------------------------------*/
514 friend class FieldContainer;
515 friend class ImageBase;
518 typedef Image *ImageP;
520 OSG_END_NAMESPACE
522 #include "OSGImageBase.inl"
523 #include "OSGImage.inl"
525 #endif /* _OSGIMAGE_H_ */