Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

OgreImage.h

Go to the documentation of this file.
00001 /*
00002 -----------------------------------------------------------------------------
00003 This source file is part of OGRE
00004     (Object-oriented Graphics Rendering Engine)
00005 For the latest info, see http://www.ogre3d.org/
00006 
00007 Copyright © 2000-2002 The OGRE Team
00008 Also see acknowledgements in Readme.html
00009 
00010 This program is free software; you can redistribute it and/or modify it under
00011 the terms of the GNU Lesser General Public License as published by the Free Software
00012 Foundation; either version 2 of the License, or (at your option) any later
00013 version.
00014 
00015 This program is distributed in the hope that it will be useful, but WITHOUT
00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
00018 
00019 You should have received a copy of the GNU Lesser General Public License along with
00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
00022 http://www.gnu.org/copyleft/lesser.txt.
00023 -----------------------------------------------------------------------------
00024 */
00025 #ifndef _Image_H__
00026 #define _Image_H__
00027 
00028 #include "OgrePrerequisites.h"
00029 
00030 #include "OgreCommon.h"
00031 
00032 namespace Ogre {
00033 
00034     enum ImageFlags
00035     {
00036         IF_COMPRESSED = 0x00000001,
00037         IF_CUBEMAP    = 0x00000002,
00038         IF_3D_TEXTURE = 0x00000004
00039     };
00051     class _OgreExport Image
00052     {
00053     public:
00056         struct Rect
00057         {
00058             long left, top, right, bottom;
00059 
00060             Rect()
00061             {
00062             }
00063             Rect( long l, long t, long r, long b )
00064             {
00065                 left = l;
00066                 top = t;   
00067                 right = r;
00068                 bottom = b;                
00069             }
00070             Rect& operator = ( const Rect& other )
00071             {
00072                 left = other.left;
00073                 top = other.top;
00074                 right = other.right;
00075                 bottom = other.bottom;       
00076 
00077                 return *this;
00078             }
00079         };
00080 
00081     public:
00084         Image();
00087         Image( const Image &img );
00088 
00091         virtual ~Image();
00092 
00095         Image & operator = ( const Image & img );
00096 
00116         Image & flipAroundY();
00117 
00132         Image & flipAroundX();
00133 
00144         static uchar PF2PS( PixelFormat format )
00145         {
00146             return getNumElemBytes( format );
00147         }
00148 
00157         inline static uchar getNumElemBytes( PixelFormat format )
00158         {
00159             switch( format )
00160             {
00161             case PF_UNKNOWN:
00162                 return 0;
00163             case PF_L8:
00164             case PF_A8:
00165             case PF_A4L4:
00166             case PF_L4A4:
00167                 return 1;
00168             case PF_R5G6B5:
00169             case PF_B5G6R5:
00170             case PF_A4R4G4B4:
00171             case PF_B4G4R4A4:
00172                 return 2;
00173             case PF_R8G8B8:
00174             case PF_B8G8R8:
00175                 return 3;
00176             case PF_A8R8G8B8:
00177             case PF_B8G8R8A8:
00178             case PF_A2R10G10B10:
00179             case PF_B10G10R10A2:
00180                 return 4;
00181             default:
00182                 return 0xff;
00183             }
00184         }
00185 
00196         static uchar PF2BPP( PixelFormat format )
00197         {
00198             return getNumElemBits( format );
00199         }
00200 
00209         inline static uchar getNumElemBits( PixelFormat format )
00210         {
00211             switch( format )
00212             {
00213             case PF_UNKNOWN:
00214                 return 0;
00215             case PF_L8:
00216             case PF_A8:
00217             case PF_A4L4:
00218             case PF_L4A4:
00219             case PF_DXT1:
00220                 return 8;
00221             case PF_R5G6B5:
00222             case PF_B5G6R5:
00223             case PF_A4R4G4B4:
00224             case PF_B4G4R4A4:
00225             case PF_DXT2:
00226             case PF_DXT3:
00227             case PF_DXT4:
00228             case PF_DXT5:
00229                 return 16;
00230             case PF_R8G8B8:
00231             case PF_B8G8R8:
00232                 return 24;
00233             case PF_A8R8G8B8:
00234             case PF_B8G8R8A8:
00235             case PF_A2R10G10B10:
00236             case PF_B10G10R10A2:
00237                 return 32;
00238             default:
00239                 return 0xff;
00240             }
00241         }
00242 
00255         inline static bool convReqsFlip( PixelFormat srcformat, PixelFormat destformat )
00256         {
00257             /* We increment the flag when the format is little endian. Then we check
00258                if the flag modulo 2 is zero. It it is, then we either haven't incremented
00259                at all (both formats big endian) or we have incremented twice (both formats
00260                little endian), so we need no flipping is needed. Otherwise, flipping is 
00261                required. */
00262             uchar flag = 0;
00263 
00264             switch( srcformat )
00265             {
00266             case PF_A4L4:
00267             case PF_R5G6B5:
00268             case PF_A4R4G4B4:
00269             case PF_R8G8B8:
00270             case PF_A8R8G8B8:
00271             case PF_A2R10G10B10:
00272                 flag++;
00273                 break;
00274 
00275             default:
00276                 break;
00277             }
00278 
00279             switch( destformat )
00280             {
00281             case PF_A4L4:
00282             case PF_R5G6B5:
00283             case PF_A4R4G4B4:
00284             case PF_R8G8B8:
00285             case PF_A8R8G8B8:
00286             case PF_A2R10G10B10:
00287                 flag++;
00288                 break;
00289 
00290             default:
00291                 break;
00292             }
00293 
00294             if( flag % 2 )
00295                 return true;
00296             return false;
00297         }
00298 
00317         Image& loadDynamicImage( uchar* pData, ushort uWidth, 
00318                                  ushort uHeight, PixelFormat eFormat );
00319 
00322         Image & loadRawData( 
00323             const DataChunk &pData, 
00324             ushort uWidth, ushort uHeight, 
00325             PixelFormat eFormat );
00326 
00339         Image & load( const String& strFileName );
00340 
00360         Image & load( const DataChunk& chunk, const String& type );
00361 
00364         uchar* getData(void);
00365 
00368         const uchar * getData() const;       
00369 
00372         size_t getSize() const;
00373 
00376         unsigned short getNumMipmaps() const;
00377 
00380         bool hasFlag(const ImageFlags imgFlag);
00381 
00384         ushort getWidth(void) const;
00385 
00388         ushort getHeight(void) const;
00389 
00392         ushort getDepth(void) const;
00393 
00396         ushort getRowSpan(void) const;
00397 
00400         PixelFormat getFormat() const;
00401 
00404         uchar getBPP() const;
00405 
00408         bool getHasAlpha() const;
00409 
00415         static void applyGamma( uchar *buffer, Real gamma, size_t size, uchar bpp );
00416 
00417         static bool formatHasAlpha(PixelFormat format);
00418 
00419     private:
00420         // The width of the image in pixels
00421         ushort m_uWidth;
00422         // The height of the image in pixels
00423         ushort m_uHeight;
00424         // The depth of the image
00425         ushort m_uDepth;
00426         // The size of the image buffer
00427         uint m_uSize;
00428         // The number of mipmaps the image contains
00429         ushort m_uNumMipmaps;
00430         // Image specific flags.
00431         int m_uFlags;
00432 
00433         // The pixel format of the image
00434         PixelFormat m_eFormat;
00435 
00436         // The number of bytes per pixel
00437         uchar m_ucPixelSize;
00438         uchar* m_pBuffer;
00439 
00440         // A bool to determine if we delete the buffer or the calling app does
00441         bool m_bAutoDelete;
00442     };
00443 
00444 } // namespace
00445 
00446 #endif

Copyright © 2002-2003 by The OGRE Team
Last modified Fri May 14 23:22:18 2004