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_SYSTEM_DLLMAPPING Image : public ImageBase
00057 {
00058   private:
00059 
00060     /*==========================  PUBLIC  =================================*/
00061 
00062   public:
00063 
00064     typedef ImageBase                           Inherited;
00065 
00066     enum PixelFormat 
00067     {   
00068         OSG_INVALID_PF = 0,
00069         OSG_A_PF       = GL_ALPHA,
00070         OSG_I_PF       = GL_INTENSITY,
00071         OSG_L_PF       = GL_LUMINANCE,
00072         OSG_LA_PF      = GL_LUMINANCE_ALPHA,
00073 /*** BGR ***/
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 /*** BGRA ***/
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 /*** 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         OSG_ALPHA_INTEGER_PF           = GL_ALPHA_INTEGER_EXT,
00122         OSG_RGB_INTEGER_PF             = GL_RGB_INTEGER_EXT,
00123         OSG_RGBA_INTEGER_PF            = GL_RGBA_INTEGER_EXT,
00124         OSG_BGR_INTEGER_PF             = GL_BGR_INTEGER_EXT,
00125         OSG_BGRA_INTEGER_PF            = GL_BGRA_INTEGER_EXT,
00126         OSG_LUMINANCE_INTEGER_PF       = GL_LUMINANCE_INTEGER_EXT,
00127         OSG_LUMINANCE_ALPHA_INTEGER_PF = GL_LUMINANCE_ALPHA_INTEGER_EXT
00128     };
00129 
00130     enum Type 
00131     {
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     {
00144         OSG_RESUNIT_INVALID       = 0,
00145         OSG_RESUNIT_NONE          = 1,
00146         OSG_RESUNIT_INCH          = 2
00147     };
00148 
00149     /*---------------------------------------------------------------------*/
00153     virtual void changed(ConstFieldMaskArg whichField,
00154                          UInt32            origin,
00155                          BitVector         details);
00156 
00158     /*---------------------------------------------------------------------*/
00162     virtual void dump(      UInt32     uiIndent = 0,
00163                       const BitVector  bvFlags  = 0) const;
00164 
00166     /*---------------------------------------------------------------------*/
00170     bool set               (      UInt32    pixelFormat,
00171                                   Int32     width,
00172                                   Int32     height      = 1,
00173                                   Int32     depth       = 1,
00174                                   Int32     mipmapCount = 1,
00175                                   Int32     frameCount  = 1,
00176                                   Time      frameDelay  = 0.0,
00177                             const UInt8    *data        = 0,
00178                                   Int32     type        = OSG_UINT8_IMAGEDATA,
00179                                   bool      allocMem    = true,
00180                                   Int32     sidecount   = 1                  );
00181     bool set               (      ImagePtr  image                            );
00182     bool setData           (const UInt8    *data = 0                         );
00183     void clearData         (      void                                       );
00184     bool setSubData        (      Int32     offX, 
00185                                   Int32     offY, 
00186                                   Int32     offZ,
00187                                   Int32     srcW, 
00188                                   Int32     srcH, 
00189                                   Int32     srcD,
00190                             const UInt8    *data                             );
00191     bool flipDepthFrameData(      void                                       );
00192 
00193 
00195     /*---------------------------------------------------------------------*/
00199     bool addValue(const Char8 *value);
00200 
00202     /*---------------------------------------------------------------------*/
00206     bool reformat(const PixelFormat pixelFormat,
00207                         ImagePtr    destination = NullFC);
00208 
00210     /*---------------------------------------------------------------------*/
00214     void swapDataEndian   (void                                    );
00215     bool convertDataTypeTo(Int32 destDataType = OSG_UINT8_IMAGEDATA);
00216 
00218     /*---------------------------------------------------------------------*/
00222     bool scale          (Int32    width, 
00223                          Int32    height      = 1,
00224                          Int32    depth       = 1,
00225                          ImagePtr destination = NullFC );
00226     bool scaleNextPower2(ImagePtr destination = NullFC );
00227 
00229     /*---------------------------------------------------------------------*/
00233     bool subImage(Int32    offX, 
00234                   Int32    offY, 
00235                   Int32    offZ,
00236                   Int32    destW, 
00237                   Int32    destH, 
00238                   Int32    destD,
00239                   ImagePtr destination = NullFC);
00240 
00242     /*---------------------------------------------------------------------*/
00246     bool slice(Int32    offX = -1, 
00247                Int32    offY = -1, 
00248                Int32    offZ = -1,
00249                ImagePtr destination = NullFC);
00250 
00252     /*---------------------------------------------------------------------*/
00256     bool createMipmap(Int32    level       = -1, 
00257                       ImagePtr destination = NullFC);
00258 
00260     /*---------------------------------------------------------------------*/
00264     bool write(const Char8 *fileName);
00265     bool read (const Char8 *fileName);
00266 
00268     /*---------------------------------------------------------------------*/
00272     UInt64 store  (const Char8 *mimeType, 
00273                          UInt8 *mem, 
00274                          Int32  memSize = -1);
00275     UInt64 restore(const UInt8 *mem, 
00276                          Int32  memSize = -1);
00277 
00279     /*---------------------------------------------------------------------*/
00283     Image &operator =  (const Image &image);
00284     bool   operator <  (const Image &image);
00285     bool   operator == (const Image &image);
00286     bool   operator != (const Image &image);
00287 
00289     /*---------------------------------------------------------------------*/
00293     bool   isValid          (void) const;
00294     bool   hasAlphaChannel  (void);
00295     bool   isAlphaBinary    (void);
00296     bool   hasColorChannel  (void);
00297     bool   hasCompressedData(void);
00298     UInt8  getComponents    (void) const;
00299     
00300     bool   calcIsAlphaBinary(void);
00301 
00303     /*---------------------------------------------------------------------*/
00307     unsigned long getSize(bool withMipmap = true,
00308                           bool withFrames = true,
00309                           bool withSides  = true) const;
00310 
00312     /*---------------------------------------------------------------------*/
00316 #ifdef OSG_1_GET_COMPAT
00317           UInt8 *getData       (UInt32 mipmapNum = 0,
00318                                 UInt32 frameNum  = 0,
00319                                 UInt32 sidecount = 0);
00320 #endif
00321     const UInt8 *getData       (UInt32 mipmapNum = 0,
00322                                 UInt32 frameNum  = 0,
00323                                 UInt32 sidecount = 0) const;
00324           UInt8 *editData      (UInt32 mipmapNum = 0,
00325                                 UInt32 frameNum  = 0,
00326                                 UInt32 sidecount = 0);
00327     const UInt8 *getDataByTime (Time   time, 
00328                                 UInt32 mipmapNum = 1) const;
00329           UInt8 *editDataByTime(Time   time, 
00330                                 UInt32 mipmapNum = 1);
00331 
00333     /*---------------------------------------------------------------------*/
00337     void   calcMipmapGeometry  (UInt32 mipmapNum,
00338                                 UInt32 &width,
00339                                 UInt32 &height,
00340                                 UInt32 &depth     ) const;
00341     UInt32 calcMipmapLevelCount(void              ) const;
00342     UInt32 calcFrameNum        (Time    time, 
00343                                 bool    loop = true) const;
00344 
00346     /*---------------------------------------------------------------------*/
00350     virtual void clear     (UChar8 pixelValue = 0            );
00351     virtual void clearFloat(Real32 pixelValue = 0.0          );
00352     virtual void clearHalf (Real16 pixelValue = Real16( 0.0 ));
00353 
00355     /*---------------------------------------------------------------------*/
00359     bool               hasAttachment      (      void             ) const;
00360     UInt32             attachmentCount    (      void             ) const;
00361     void               setAttachmentField (const std::string &key,
00362                                            const std::string &data);
00363     const std::string *findAttachmentField(const std::string &key ) const;
00364 
00366     /*---------------------------------------------------------------------*/
00370     UInt32 calcMipmapLevelSize(UInt32 mipmapNum,
00371                                UInt32 w, 
00372                                UInt32 h, 
00373                                UInt32 d        ) const;
00374     UInt32 calcMipmapLevelSize(UInt32 mipmapNum) const;
00375 
00376     UInt32 calcMipmapSumSize  (UInt32 mipmapNum,
00377                                UInt32 w, 
00378                                UInt32 h, 
00379                                UInt32 d        ) const;
00380     UInt32 calcMipmapSumSize  (UInt32 mipmapNum) const;
00381 
00383     /*---------------------------------------------------------------------*/
00387     void addParent(
00388               FieldContainerPtrConst &parent, 
00389         const UInt16                  uiStoredInFieldId = InvalidParentEPos);
00390 
00391     void subParent(FieldContainerPtrConst &parent);
00392 
00394     /*=========================  PROTECTED  ===============================*/
00395 
00396   protected:
00397 
00398     /*---------------------------------------------------------------------*/
00402     static Int32 _formatDic[][2];
00403     static Int32 _typeDic  [][2];
00404 
00406     /*---------------------------------------------------------------------*/
00410     Image(void);
00411     Image(const Image &source);
00412 
00414     /*---------------------------------------------------------------------*/
00418     virtual ~Image(void);
00419 
00421     /*---------------------------------------------------------------------*/
00425     static void initMethod(InitPhase ePhase);
00426 
00428     /*==========================  PRIVATE  ================================*/
00429 
00430   private:
00431 
00432     /*---------------------------------------------------------------------*/
00436     bool createData(const UInt8 *data, 
00437                           bool   allocMem = true);
00438     bool scaleData (      UInt8 *srcData,
00439                           Int32  srcW, 
00440                           Int32  srcH, 
00441                           Int32  srcD,
00442                           UInt8 *destData,
00443                           Int32  destW, 
00444                           Int32  destH, 
00445                           Int32  destD          );
00446 
00448     /*---------------------------------------------------------------------*/
00449 
00450     friend class FieldContainer;
00451     friend class ImageBase;
00452 };
00453 
00454 typedef Image *ImageP;
00455 
00456 OSG_END_NAMESPACE
00457 
00458 #include "OSGImageBase.inl"
00459 #include "OSGImage.inl"
00460 
00461 #endif /* _OSGIMAGE_H_ */