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-2013 Torus Knot Software Ltd 00008 00009 Permission is hereby granted, free of charge, to any person obtaining a copy 00010 of this software and associated documentation files (the "Software"), to deal 00011 in the Software without restriction, including without limitation the rights 00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00013 copies of the Software, and to permit persons to whom the Software is 00014 furnished to do so, subject to the following conditions: 00015 00016 The above copyright notice and this permission notice shall be included in 00017 all copies or substantial portions of the Software. 00018 00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00025 THE SOFTWARE. 00026 ----------------------------------------------------------------------------- 00027 */ 00028 #ifndef _PixelFormat_H__ 00029 #define _PixelFormat_H__ 00030 00031 #include "OgrePrerequisites.h" 00032 #include "OgreCommon.h" 00033 #include "OgreHeaderPrefix.h" 00034 00035 namespace Ogre { 00043 enum PixelFormat 00044 { 00046 PF_UNKNOWN = 0, 00048 PF_L8 = 1, 00049 PF_BYTE_L = PF_L8, 00051 PF_L16 = 2, 00052 PF_SHORT_L = PF_L16, 00054 PF_A8 = 3, 00055 PF_BYTE_A = PF_A8, 00057 PF_A4L4 = 4, 00059 PF_BYTE_LA = 5, 00061 PF_R5G6B5 = 6, 00063 PF_B5G6R5 = 7, 00065 PF_R3G3B2 = 31, 00067 PF_A4R4G4B4 = 8, 00069 PF_A1R5G5B5 = 9, 00071 PF_R8G8B8 = 10, 00073 PF_B8G8R8 = 11, 00075 PF_A8R8G8B8 = 12, 00077 PF_A8B8G8R8 = 13, 00079 PF_B8G8R8A8 = 14, 00081 PF_R8G8B8A8 = 28, 00084 PF_X8R8G8B8 = 26, 00087 PF_X8B8G8R8 = 27, 00088 #if OGRE_ENDIAN == OGRE_ENDIAN_BIG 00089 00090 PF_BYTE_RGB = PF_R8G8B8, 00092 PF_BYTE_BGR = PF_B8G8R8, 00094 PF_BYTE_BGRA = PF_B8G8R8A8, 00096 PF_BYTE_RGBA = PF_R8G8B8A8, 00097 #else 00098 00099 PF_BYTE_RGB = PF_B8G8R8, 00101 PF_BYTE_BGR = PF_R8G8B8, 00103 PF_BYTE_BGRA = PF_A8R8G8B8, 00105 PF_BYTE_RGBA = PF_A8B8G8R8, 00106 #endif 00107 00108 PF_A2R10G10B10 = 15, 00110 PF_A2B10G10R10 = 16, 00112 PF_DXT1 = 17, 00114 PF_DXT2 = 18, 00116 PF_DXT3 = 19, 00118 PF_DXT4 = 20, 00120 PF_DXT5 = 21, 00122 PF_FLOAT16_R = 32, 00124 PF_FLOAT16_RGB = 22, 00126 PF_FLOAT16_RGBA = 23, 00127 // 32-bit pixel format, 32 bits (float) for red 00128 PF_FLOAT32_R = 33, 00130 PF_FLOAT32_RGB = 24, 00132 PF_FLOAT32_RGBA = 25, 00134 PF_FLOAT16_GR = 35, 00136 PF_FLOAT32_GR = 36, 00138 PF_DEPTH = 29, 00140 PF_SHORT_RGBA = 30, 00142 PF_SHORT_GR = 34, 00144 PF_SHORT_RGB = 37, 00146 PF_PVRTC_RGB2 = 38, 00148 PF_PVRTC_RGBA2 = 39, 00150 PF_PVRTC_RGB4 = 40, 00152 PF_PVRTC_RGBA4 = 41, 00154 PF_PVRTC2_2BPP = 42, 00156 PF_PVRTC2_4BPP = 43, 00158 PF_R11G11B10_FLOAT = 44, 00160 PF_R8_UINT = 45, 00162 PF_R8G8_UINT = 46, 00164 PF_R8G8B8_UINT = 47, 00166 PF_R8G8B8A8_UINT = 48, 00168 PF_R16_UINT = 49, 00170 PF_R16G16_UINT = 50, 00172 PF_R16G16B16_UINT = 51, 00174 PF_R16G16B16A16_UINT = 52, 00176 PF_R32_UINT = 53, 00178 PF_R32G32_UINT = 54, 00180 PF_R32G32B32_UINT = 55, 00182 PF_R32G32B32A32_UINT = 56, 00184 PF_R8_SINT = 57, 00186 PF_R8G8_SINT = 58, 00188 PF_R8G8B8_SINT = 59, 00190 PF_R8G8B8A8_SINT = 60, 00192 PF_R16_SINT = 61, 00194 PF_R16G16_SINT = 62, 00196 PF_R16G16B16_SINT = 63, 00198 PF_R16G16B16A16_SINT = 64, 00200 PF_R32_SINT = 65, 00202 PF_R32G32_SINT = 66, 00204 PF_R32G32B32_SINT = 67, 00206 PF_R32G32B32A32_SINT = 68, 00208 PF_R9G9B9E5_SHAREDEXP = 69, 00210 PF_BC4_UNORM = 70, 00212 PF_BC4_SNORM = 71, 00214 PF_BC5_UNORM = 72, 00216 PF_BC5_SNORM = 73, 00218 PF_BC6H_UF16 = 74, 00220 PF_BC6H_SF16 = 75, 00222 PF_BC7_UNORM = 76, 00224 PF_BC7_UNORM_SRGB = 77, 00226 PF_R8 = 78, 00228 PF_RG8 = 79, 00230 PF_R8_SNORM = 80, 00232 PF_R8G8_SNORM = 81, 00234 PF_R8G8B8_SNORM = 82, 00236 PF_R8G8B8A8_SNORM = 83, 00238 PF_R16_SNORM = 84, 00240 PF_R16G16_SNORM = 85, 00242 PF_R16G16B16_SNORM = 86, 00244 PF_R16G16B16A16_SNORM = 87, 00246 PF_ETC1_RGB8 = 88, 00248 PF_ETC2_RGB8 = 89, 00250 PF_ETC2_RGBA8 = 90, 00252 PF_ETC2_RGB8A1 = 91, 00254 PF_ATC_RGB = 92, 00256 PF_ATC_RGBA_EXPLICIT_ALPHA = 93, 00258 PF_ATC_RGBA_INTERPOLATED_ALPHA = 94, 00259 // Number of pixel formats currently defined 00260 PF_COUNT = 95 00261 }; 00262 typedef vector<PixelFormat>::type PixelFormatList; 00263 00267 enum PixelFormatFlags { 00269 PFF_HASALPHA = 0x00000001, 00272 PFF_COMPRESSED = 0x00000002, 00274 PFF_FLOAT = 0x00000004, 00276 PFF_DEPTH = 0x00000008, 00279 PFF_NATIVEENDIAN = 0x00000010, 00282 PFF_LUMINANCE = 0x00000020, 00284 PFF_INTEGER = 0x00000040 00285 }; 00286 00288 enum PixelComponentType 00289 { 00290 PCT_BYTE = 0, 00291 PCT_SHORT = 1, 00292 PCT_FLOAT16 = 2, 00293 PCT_FLOAT32 = 3, 00294 PCT_SINT = 4, 00295 PCT_UINT = 5, 00296 PCT_COUNT = 6 00297 }; 00298 00304 class _OgreExport PixelBox: public Box, public ImageAlloc { 00305 public: 00307 PixelBox() {} 00308 ~PixelBox() {} 00316 PixelBox(const Box &extents, PixelFormat pixelFormat, void *pixelData=0): 00317 Box(extents), data(pixelData), format(pixelFormat) 00318 { 00319 setConsecutive(); 00320 } 00330 PixelBox(uint32 width, uint32 height, uint32 depth, PixelFormat pixelFormat, void *pixelData=0): 00331 Box(0, 0, 0, width, height, depth), 00332 data(pixelData), format(pixelFormat) 00333 { 00334 setConsecutive(); 00335 } 00336 00338 void *data; 00340 PixelFormat format; 00345 size_t rowPitch; 00351 size_t slicePitch; 00352 00356 void setConsecutive() 00357 { 00358 rowPitch = getWidth(); 00359 slicePitch = getWidth()*getHeight(); 00360 } 00365 size_t getRowSkip() const { return rowPitch - getWidth(); } 00370 size_t getSliceSkip() const { return slicePitch - (getHeight() * rowPitch); } 00371 00375 bool isConsecutive() const 00376 { 00377 return rowPitch == getWidth() && slicePitch == getWidth()*getHeight(); 00378 } 00382 size_t getConsecutiveSize() const; 00391 PixelBox getSubVolume(const Box &def) const; 00392 00396 void* getTopLeftFrontPixelPtr() const; 00397 00403 ColourValue getColourAt(size_t x, size_t y, size_t z); 00404 00410 void setColourAt(ColourValue const &cv, size_t x, size_t y, size_t z); 00411 }; 00412 00413 00417 class _OgreExport PixelUtil { 00418 public: 00425 static size_t getNumElemBytes( PixelFormat format ); 00426 00433 static size_t getNumElemBits( PixelFormat format ); 00434 00452 static size_t getMemorySize(uint32 width, uint32 height, uint32 depth, PixelFormat format); 00453 00461 static unsigned int getFlags( PixelFormat format ); 00462 00464 static bool hasAlpha(PixelFormat format); 00466 static bool isFloatingPoint(PixelFormat format); 00468 static bool isInteger(PixelFormat format); 00470 static bool isCompressed(PixelFormat format); 00472 static bool isDepth(PixelFormat format); 00474 static bool isNativeEndian(PixelFormat format); 00476 static bool isLuminance(PixelFormat format); 00477 00490 static bool isValidExtent(size_t width, size_t height, size_t depth, PixelFormat format); 00491 00495 static void getBitDepths(PixelFormat format, int rgba[4]); 00496 00500 static void getBitMasks(PixelFormat format, uint64 rgba[4]); 00501 00505 static void getBitShifts(PixelFormat format, unsigned char rgba[4]); 00506 00509 static String getFormatName(PixelFormat srcformat); 00510 00518 static bool isAccessible(PixelFormat srcformat); 00519 00524 static PixelComponentType getComponentType(PixelFormat fmt); 00525 00529 static size_t getComponentCount(PixelFormat fmt); 00530 00538 static PixelFormat getFormatFromName(const String& name, bool accessibleOnly = false, bool caseSensitive = false); 00539 00547 static String getBNFExpressionOfPixelFormats(bool accessibleOnly = false); 00548 00558 static PixelFormat getFormatForBitDepths(PixelFormat fmt, ushort integerBits, ushort floatBits); 00559 00565 static void packColour(const ColourValue &colour, const PixelFormat pf, void* dest); 00573 static void packColour(const uint8 r, const uint8 g, const uint8 b, const uint8 a, const PixelFormat pf, void* dest); 00581 static void packColour(const float r, const float g, const float b, const float a, const PixelFormat pf, void* dest); 00582 00588 static void unpackColour(ColourValue *colour, PixelFormat pf, const void* src); 00600 static void unpackColour(uint8 *r, uint8 *g, uint8 *b, uint8 *a, PixelFormat pf, const void* src); 00609 static void unpackColour(float *r, float *g, float *b, float *a, PixelFormat pf, const void* src); 00610 00619 static void bulkPixelConversion(void *src, PixelFormat srcFormat, void *dst, PixelFormat dstFormat, unsigned int count); 00620 00628 static void bulkPixelConversion(const PixelBox &src, const PixelBox &dst); 00629 00634 static void bulkPixelVerticalFlip(const PixelBox &box); 00635 }; 00639 } 00640 00641 #include "OgreHeaderSuffix.h" 00642 00643 #endif
Copyright © 2012 Torus Knot Software Ltd

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Mon Jul 27 2020 13:40:44