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 (c) 2000-2006 Torus Knot Software Ltd 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 You may alternatively use this source under the terms of a specific version of 00025 the OGRE Unrestricted License provided you have obtained such a license from 00026 Torus Knot Software Ltd. 00027 ----------------------------------------------------------------------------- 00028 */ 00029 #ifndef _PixelFormat_H__ 00030 #define _PixelFormat_H__ 00031 00032 #include "OgrePrerequisites.h" 00033 #include "OgreCommon.h" 00034 00035 namespace Ogre { 00037 enum PixelFormat 00038 { 00040 PF_UNKNOWN = 0, 00042 PF_L8 = 1, 00043 PF_BYTE_L = PF_L8, 00045 PF_L16 = 2, 00046 PF_SHORT_L = PF_L16, 00048 PF_A8 = 3, 00049 PF_BYTE_A = PF_A8, 00051 PF_A4L4 = 4, 00053 PF_BYTE_LA = 5, 00055 PF_R5G6B5 = 6, 00057 PF_B5G6R5 = 7, 00059 PF_R3G3B2 = 31, 00061 PF_A4R4G4B4 = 8, 00063 PF_A1R5G5B5 = 9, 00065 PF_R8G8B8 = 10, 00067 PF_B8G8R8 = 11, 00069 PF_A8R8G8B8 = 12, 00071 PF_A8B8G8R8 = 13, 00073 PF_B8G8R8A8 = 14, 00075 PF_R8G8B8A8 = 28, 00078 PF_X8R8G8B8 = 26, 00081 PF_X8B8G8R8 = 27, 00082 #if OGRE_ENDIAN == OGRE_ENDIAN_BIG 00083 00084 PF_BYTE_RGB = PF_R8G8B8, 00086 PF_BYTE_BGR = PF_B8G8R8, 00088 PF_BYTE_BGRA = PF_B8G8R8A8, 00090 PF_BYTE_RGBA = PF_R8G8B8A8, 00091 #else 00092 00093 PF_BYTE_RGB = PF_B8G8R8, 00095 PF_BYTE_BGR = PF_R8G8B8, 00097 PF_BYTE_BGRA = PF_A8R8G8B8, 00099 PF_BYTE_RGBA = PF_A8B8G8R8, 00100 #endif 00101 00102 PF_A2R10G10B10 = 15, 00104 PF_A2B10G10R10 = 16, 00106 PF_DXT1 = 17, 00108 PF_DXT2 = 18, 00110 PF_DXT3 = 19, 00112 PF_DXT4 = 20, 00114 PF_DXT5 = 21, 00115 // 16-bit pixel format, 16 bits (float) for red 00116 PF_FLOAT16_R = 32, 00117 // 48-bit pixel format, 16 bits (float) for red, 16 bits (float) for green, 16 bits (float) for blue 00118 PF_FLOAT16_RGB = 22, 00119 // 64-bit pixel format, 16 bits (float) for red, 16 bits (float) for green, 16 bits (float) for blue, 16 bits (float) for alpha 00120 PF_FLOAT16_RGBA = 23, 00121 // 16-bit pixel format, 16 bits (float) for red 00122 PF_FLOAT32_R = 33, 00123 // 96-bit pixel format, 32 bits (float) for red, 32 bits (float) for green, 32 bits (float) for blue 00124 PF_FLOAT32_RGB = 24, 00125 // 128-bit pixel format, 32 bits (float) for red, 32 bits (float) for green, 32 bits (float) for blue, 32 bits (float) for alpha 00126 PF_FLOAT32_RGBA = 25, 00127 // 32-bit, 2-channel s10e5 floating point pixel format, 16-bit green, 16-bit red 00128 PF_FLOAT16_GR = 35, 00129 // 64-bit, 2-channel floating point pixel format, 32-bit green, 32-bit red 00130 PF_FLOAT32_GR = 36, 00131 // Depth texture format 00132 PF_DEPTH = 29, 00133 // 64-bit pixel format, 16 bits for red, green, blue and alpha 00134 PF_SHORT_RGBA = 30, 00135 // 32-bit pixel format, 16-bit green, 16-bit red 00136 PF_SHORT_GR = 34, 00137 // 48-bit pixel format, 16 bits for red, green and blue 00138 PF_SHORT_RGB = 37, 00139 // Number of pixel formats currently defined 00140 PF_COUNT = 38 00141 }; 00142 00146 enum PixelFormatFlags { 00147 // This format has an alpha channel 00148 PFF_HASALPHA = 0x00000001, 00149 // This format is compressed. This invalidates the values in elemBytes, 00150 // elemBits and the bit counts as these might not be fixed in a compressed format. 00151 PFF_COMPRESSED = 0x00000002, 00152 // This is a floating point format 00153 PFF_FLOAT = 0x00000004, 00154 // This is a depth format (for depth textures) 00155 PFF_DEPTH = 0x00000008, 00156 // Format is in native endian. Generally true for the 16, 24 and 32 bits 00157 // formats which can be represented as machine integers. 00158 PFF_NATIVEENDIAN = 0x00000010, 00159 // This is an intensity format instead of a RGB one. The luminance 00160 // replaces R,G and B. (but not A) 00161 PFF_LUMINANCE = 0x00000020 00162 }; 00163 00165 enum PixelComponentType 00166 { 00167 PCT_BYTE = 0, 00168 PCT_SHORT = 1, 00169 PCT_FLOAT16 = 2, 00170 PCT_FLOAT32 = 3, 00171 PCT_COUNT = 4 00172 }; 00173 00179 class _OgreExport PixelBox: public Box { 00180 public: 00182 PixelBox() {} 00190 PixelBox(const Box &extents, PixelFormat pixelFormat, void *pixelData=0): 00191 Box(extents), data(pixelData), format(pixelFormat) 00192 { 00193 setConsecutive(); 00194 } 00204 PixelBox(size_t width, size_t height, size_t depth, PixelFormat pixelFormat, void *pixelData=0): 00205 Box(0, 0, 0, width, height, depth), 00206 data(pixelData), format(pixelFormat) 00207 { 00208 setConsecutive(); 00209 } 00210 00212 void *data; 00214 PixelFormat format; 00219 size_t rowPitch; 00225 size_t slicePitch; 00226 00230 void setConsecutive() 00231 { 00232 rowPitch = getWidth(); 00233 slicePitch = getWidth()*getHeight(); 00234 } 00239 size_t getRowSkip() const { return rowPitch - getWidth(); } 00244 size_t getSliceSkip() const { return slicePitch - (getHeight() * rowPitch); } 00245 00249 bool isConsecutive() const 00250 { 00251 return rowPitch == getWidth() && slicePitch == getWidth()*getHeight(); 00252 } 00256 size_t getConsecutiveSize() const; 00265 PixelBox getSubVolume(const Box &def) const; 00266 }; 00267 00268 00272 class _OgreExport PixelUtil { 00273 public: 00280 static size_t getNumElemBytes( PixelFormat format ); 00281 00288 static size_t getNumElemBits( PixelFormat format ); 00289 00307 static size_t getMemorySize(size_t width, size_t height, size_t depth, PixelFormat format); 00308 00316 static unsigned int getFlags( PixelFormat format ); 00317 00319 static bool hasAlpha(PixelFormat format); 00321 static bool isFloatingPoint(PixelFormat format); 00323 static bool isCompressed(PixelFormat format); 00325 static bool isDepth(PixelFormat format); 00327 static bool isNativeEndian(PixelFormat format); 00329 static bool isLuminance(PixelFormat format); 00330 00343 static bool isValidExtent(size_t width, size_t height, size_t depth, PixelFormat format); 00344 00348 static void getBitDepths(PixelFormat format, int rgba[4]); 00349 00353 static void getBitMasks(PixelFormat format, uint32 rgba[4]); 00354 00357 static String getFormatName(PixelFormat srcformat); 00358 00366 static bool isAccessible(PixelFormat srcformat); 00367 00372 static PixelComponentType getComponentType(PixelFormat fmt); 00373 00377 static size_t getComponentCount(PixelFormat fmt); 00378 00386 static PixelFormat getFormatFromName(const String& name, bool accessibleOnly = false, bool caseSensitive = false); 00387 00395 static String getBNFExpressionOfPixelFormats(bool accessibleOnly = false); 00396 00406 static PixelFormat getFormatForBitDepths(PixelFormat fmt, ushort integerBits, ushort floatBits); 00407 00413 static void packColour(const ColourValue &colour, const PixelFormat pf, void* dest); 00419 static void packColour(const uint8 r, const uint8 g, const uint8 b, const uint8 a, const PixelFormat pf, void* dest); 00427 static void packColour(const float r, const float g, const float b, const float a, const PixelFormat pf, void* dest); 00428 00434 static void unpackColour(ColourValue *colour, PixelFormat pf, const void* src); 00443 static void unpackColour(uint8 *r, uint8 *g, uint8 *b, uint8 *a, PixelFormat pf, const void* src); 00449 static void unpackColour(float *r, float *g, float *b, float *a, PixelFormat pf, const void* src); 00450 00459 static void bulkPixelConversion(void *src, PixelFormat srcFormat, void *dest, PixelFormat dstFormat, unsigned int count); 00460 00468 static void bulkPixelConversion(const PixelBox &src, const PixelBox &dst); 00469 }; 00470 00471 } 00472 00473 #endif
Copyright © 2000-2005 by The OGRE Team
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Sep 30 10:50:57 2007