00001 /* 00002 ----------------------------------------------------------------------------- 00003 This source file is part of OGRE 00004 (Object-oriented Graphics Rendering Engine) 00005 For the latest info, see http://ogre.sourceforge.net/ 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 "OgreString.h" 00031 #include "OgreCommon.h" 00032 #include "OgreDataChunk.h" 00033 00034 namespace Ogre { 00035 00047 class _OgreExport Image 00048 { 00049 public: 00052 struct Rect 00053 { 00054 long left, top, right, bottom; 00055 00056 Rect() 00057 { 00058 } 00059 Rect( long l, long t, long r, long b ) 00060 { 00061 left = l; 00062 top = t; 00063 right = r; 00064 bottom = b; 00065 } 00066 Rect& operator = ( const Rect& other ) 00067 { 00068 left = other.left; 00069 top = other.top; 00070 right = other.right; 00071 bottom = other.bottom; 00072 00073 return *this; 00074 } 00075 }; 00076 00077 public: 00080 Image(); 00083 Image( const Image &img ); 00084 00087 virtual ~Image(); 00088 00091 Image & operator = ( const Image & img ); 00092 00112 Image & flipAroundY(); 00113 00128 Image & flipAroundX(); 00129 00140 static uchar PF2PS( PixelFormat format ) 00141 { 00142 return getNumElemBytes( format ); 00143 } 00144 00153 inline static uchar getNumElemBytes( PixelFormat format ) 00154 { 00155 switch( format ) 00156 { 00157 case PF_UNKNOWN: 00158 return 0; 00159 case PF_L8: 00160 case PF_A8: 00161 case PF_A4L4: 00162 case PF_L4A4: 00163 return 1; 00164 case PF_R5G6B5: 00165 case PF_B5G6R5: 00166 case PF_A4R4G4B4: 00167 case PF_B4G4R4A4: 00168 return 2; 00169 case PF_R8G8B8: 00170 case PF_B8R8G8: 00171 return 3; 00172 case PF_A8R8G8B8: 00173 case PF_B8G8R8A8: 00174 case PF_A2R10G10B10: 00175 case PF_B10G10R10A2: 00176 return 4; 00177 default: 00178 return 0xff; 00179 } 00180 } 00181 00192 static uchar PF2BPP( PixelFormat format ) 00193 { 00194 return getNumElemBits( format ); 00195 } 00196 00205 inline static uchar getNumElemBits( PixelFormat format ) 00206 { 00207 switch( format ) 00208 { 00209 case PF_UNKNOWN: 00210 return 0; 00211 case PF_L8: 00212 case PF_A8: 00213 case PF_A4L4: 00214 case PF_L4A4: 00215 return 8; 00216 case PF_R5G6B5: 00217 case PF_B5G6R5: 00218 case PF_A4R4G4B4: 00219 case PF_B4G4R4A4: 00220 return 16; 00221 case PF_R8G8B8: 00222 case PF_B8R8G8: 00223 return 24; 00224 case PF_A8R8G8B8: 00225 case PF_B8G8R8A8: 00226 case PF_A2R10G10B10: 00227 case PF_B10G10R10A2: 00228 return 32; 00229 default: 00230 return 0xff; 00231 } 00232 } 00233 00246 inline static bool convReqsFlip( PixelFormat srcformat, PixelFormat destformat ) 00247 { 00248 /* We increment the flag when the format is little endian. Then we check 00249 if the flag modulo 2 is zero. It it is, then we either haven't incremented 00250 at all (both formats big endian) or we have incremented twice (both formats 00251 little endian), so we need no flipping is needed. Otherwise, flipping is 00252 required. */ 00253 uchar flag = 0; 00254 00255 switch( srcformat ) 00256 { 00257 case PF_A4L4: 00258 case PF_R5G6B5: 00259 case PF_A4R4G4B4: 00260 case PF_R8G8B8: 00261 case PF_A8R8G8B8: 00262 case PF_A2R10G10B10: 00263 flag++; 00264 break; 00265 00266 default: 00267 break; 00268 } 00269 00270 switch( destformat ) 00271 { 00272 case PF_A4L4: 00273 case PF_R5G6B5: 00274 case PF_A4R4G4B4: 00275 case PF_R8G8B8: 00276 case PF_A8R8G8B8: 00277 case PF_A2R10G10B10: 00278 flag++; 00279 break; 00280 00281 default: 00282 break; 00283 } 00284 00285 if( flag % 2 ) 00286 return true; 00287 return false; 00288 } 00289 00292 Image & loadRawData( 00293 const DataChunk &pData, 00294 ushort uWidth, ushort uHeight, 00295 PixelFormat eFormat ); 00296 00309 Image & load( const String& strFileName ); 00310 00330 Image & load( const DataChunk& chunk, const String& type ); 00331 00334 uchar* getData(void); 00335 00338 const uchar * getData() const; 00339 00342 size_t getSize() const; 00343 00346 ushort getWidth(void) const; 00347 00350 ushort getHeight(void) const; 00351 00354 ushort getRowSpan(void) const; 00355 00358 PixelFormat getFormat() const; 00359 00362 uchar getBPP() const; 00363 00366 bool getHasAlpha() const; 00367 00373 static void applyGamma( uchar *byffer, Real gamma, uint size, uchar bpp ); 00374 00375 private: 00376 // The width of the image in pixels 00377 ushort m_uWidth; 00378 // The height of the image in pixels 00379 ushort m_uHeight; 00380 00381 // The pixel format of the image 00382 PixelFormat m_eFormat; 00383 00384 // The number of bytes per pixel 00385 uchar m_ucPixelSize; 00386 uchar* m_pBuffer; 00387 }; 00388 00389 } // namespace 00390 00391 #endif
Copyright © 2002 by The OGRE Team