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
    00250        inline static bool PFHasAlpha(PixelFormat format)
    00251        {
    00252             switch(format) {
    00253                 case PF_A8:
    00254                 case PF_A4L4:
    00255                 case PF_L4A4:
    00256                 case PF_A4R4G4B4:
    00257                 case PF_B4G4R4A4:
    00258                 case PF_A8R8G8B8:
    00259                 case PF_B8G8R8A8:
    00260                 case PF_A2R10G10B10:
    00261                 case PF_B10G10R10A2:
    00262                     return true;
    00263                 default:
    00264                     return false;
    00265             }
    00266         }
    00267
    00280         inline static bool convReqsFlip( PixelFormat srcformat, PixelFormat destformat )
    00281         {
    00282             /* We increment the flag when the format is little endian. Then we check
    00283                if the flag modulo 2 is zero. It it is, then we either haven't incremented
    00284                at all (both formats big endian) or we have incremented twice (both formats
    00285                little endian), so we need no flipping is needed. Otherwise, flipping is
    00286                required. */
    00287             uchar flag = 0;
    00288
    00289             switch( srcformat )
    00290             {
    00291             case PF_A4L4:
    00292             case PF_R5G6B5:
    00293             case PF_A4R4G4B4:
    00294             case PF_R8G8B8:
    00295             case PF_A8R8G8B8:
    00296             case PF_A2R10G10B10:
    00297                 flag++;
    00298                 break;
    00299
    00300             default:
    00301                 break;
    00302             }
    00303
    00304             switch( destformat )
    00305             {
    00306             case PF_A4L4:
    00307             case PF_R5G6B5:
    00308             case PF_A4R4G4B4:
    00309             case PF_R8G8B8:
    00310             case PF_A8R8G8B8:
    00311             case PF_A2R10G10B10:
    00312                 flag++;
    00313                 break;
    00314
    00315             default:
    00316                 break;
    00317             }
    00318
    00319             if( flag % 2 )
    00320                 return true;
    00321             return false;
    00322         }
    00323
    00342         Image& loadDynamicImage( uchar* pData, ushort uWidth,
    00343                                  ushort uHeight, PixelFormat eFormat );
    00344
    00347         Image & loadRawData(
    00348             const DataChunk &pData,
    00349             ushort uWidth, ushort uHeight,
    00350             PixelFormat eFormat );
    00351
    00364         Image & load( const String& strFileName );
    00365
    00385         Image & load( const DataChunk& chunk, const String& type );
    00386
    00388         void save(const String& filename);
    00389
    00392         uchar* getData(void);
    00393
    00396         const uchar * getData() const;
    00397
    00400         size_t getSize() const;
    00401
    00404         unsigned short getNumMipmaps() const;
    00405
    00408         bool hasFlag(const ImageFlags imgFlag) const;
    00409
    00412         ushort getWidth(void) const;
    00413
    00416         ushort getHeight(void) const;
    00417
    00420         ushort getDepth(void) const;
    00421
    00424         ushort getRowSpan(void) const;
    00425
    00428         PixelFormat getFormat() const;
    00429
    00432         uchar getBPP() const;
    00433
    00436         bool getHasAlpha() const;
    00437
    00443         static void applyGamma( uchar *buffer, Real gamma, size_t size, uchar bpp );
    00444
    00445         static bool formatHasAlpha(PixelFormat format);
    00446
    00447         enum Filter
    00448         {
    00449             FILTER_NEAREST,
    00450             FILTER_LINEAR,
    00451             FILTER_BILINEAR,
    00452             FILTER_BOX,
    00453             FILTER_TRIANGLE,
    00454             FILTER_BICUBIC
    00455         };
    00457         void resize(ushort width, ushort height, Filter filter = FILTER_BILINEAR);
    00458
    00459
    00460     private:
    00461         // The width of the image in pixels
    00462         ushort m_uWidth;
    00463         // The height of the image in pixels
    00464         ushort m_uHeight;
    00465         // The depth of the image
    00466         ushort m_uDepth;
    00467         // The size of the image buffer
    00468         uint m_uSize;
    00469         // The number of mipmaps the image contains
    00470         ushort m_uNumMipmaps;
    00471         // Image specific flags.
    00472         int m_uFlags;
    00473
    00474         // The pixel format of the image
    00475         PixelFormat m_eFormat;
    00476
    00477         // The number of bytes per pixel
    00478         uchar m_ucPixelSize;
    00479         uchar* m_pBuffer;
    00480
    00481         // A bool to determine if we delete the buffer or the calling app does
    00482         bool m_bAutoDelete;
    00483     };
    00484
    00485 } // namespace
    00486
    00487 #endif

Copyright © 2002-2003 by The OGRE Team
Last modified Sun Nov 28 19:48:30 2004