[148] | 1 | /* |
---|
| 2 | ----------------------------------------------------------------------------- |
---|
| 3 | This source file is part of OGRE |
---|
| 4 | (Object-oriented Graphics Rendering Engine) |
---|
| 5 | For the latest info, see http://www.ogre3d.org/ |
---|
| 6 | |
---|
| 7 | Copyright (c) 2000-2013 Torus Knot Software Ltd |
---|
| 8 | |
---|
| 9 | Permission is hereby granted, free of charge, to any person obtaining a copy |
---|
| 10 | of this software and associated documentation files (the "Software"), to deal |
---|
| 11 | in the Software without restriction, including without limitation the rights |
---|
| 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
---|
| 13 | copies of the Software, and to permit persons to whom the Software is |
---|
| 14 | furnished to do so, subject to the following conditions: |
---|
| 15 | |
---|
| 16 | The above copyright notice and this permission notice shall be included in |
---|
| 17 | all copies or substantial portions of the Software. |
---|
| 18 | |
---|
| 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
| 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
| 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
---|
| 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
---|
| 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
---|
| 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
---|
| 25 | THE SOFTWARE. |
---|
| 26 | ----------------------------------------------------------------------------- |
---|
| 27 | */ |
---|
| 28 | #ifndef _PixelFormat_H__ |
---|
| 29 | #define _PixelFormat_H__ |
---|
| 30 | |
---|
| 31 | #include "OgrePrerequisites.h" |
---|
| 32 | #include "OgreCommon.h" |
---|
| 33 | #include "OgreHeaderPrefix.h" |
---|
| 34 | |
---|
| 35 | namespace Ogre { |
---|
| 36 | /** \addtogroup Core |
---|
| 37 | * @{ |
---|
| 38 | */ |
---|
| 39 | /** \addtogroup Image |
---|
| 40 | * @{ |
---|
| 41 | */ |
---|
| 42 | /** The pixel format used for images, textures, and render surfaces */ |
---|
| 43 | enum PixelFormat |
---|
| 44 | { |
---|
| 45 | /// Unknown pixel format. |
---|
| 46 | PF_UNKNOWN = 0, |
---|
| 47 | /// 8-bit pixel format, all bits luminance. |
---|
| 48 | PF_L8 = 1, |
---|
| 49 | PF_BYTE_L = PF_L8, |
---|
| 50 | /// 16-bit pixel format, all bits luminance. |
---|
| 51 | PF_L16 = 2, |
---|
| 52 | PF_SHORT_L = PF_L16, |
---|
| 53 | /// 8-bit pixel format, all bits alpha. |
---|
| 54 | PF_A8 = 3, |
---|
| 55 | PF_BYTE_A = PF_A8, |
---|
| 56 | /// 8-bit pixel format, 4 bits alpha, 4 bits luminance. |
---|
| 57 | PF_A4L4 = 4, |
---|
| 58 | /// 2 byte pixel format, 1 byte luminance, 1 byte alpha |
---|
| 59 | PF_BYTE_LA = 5, |
---|
| 60 | /// 16-bit pixel format, 5 bits red, 6 bits green, 5 bits blue. |
---|
| 61 | PF_R5G6B5 = 6, |
---|
| 62 | /// 16-bit pixel format, 5 bits red, 6 bits green, 5 bits blue. |
---|
| 63 | PF_B5G6R5 = 7, |
---|
| 64 | /// 8-bit pixel format, 2 bits blue, 3 bits green, 3 bits red. |
---|
| 65 | PF_R3G3B2 = 31, |
---|
| 66 | /// 16-bit pixel format, 4 bits for alpha, red, green and blue. |
---|
| 67 | PF_A4R4G4B4 = 8, |
---|
| 68 | /// 16-bit pixel format, 5 bits for blue, green, red and 1 for alpha. |
---|
| 69 | PF_A1R5G5B5 = 9, |
---|
| 70 | /// 24-bit pixel format, 8 bits for red, green and blue. |
---|
| 71 | PF_R8G8B8 = 10, |
---|
| 72 | /// 24-bit pixel format, 8 bits for blue, green and red. |
---|
| 73 | PF_B8G8R8 = 11, |
---|
| 74 | /// 32-bit pixel format, 8 bits for alpha, red, green and blue. |
---|
| 75 | PF_A8R8G8B8 = 12, |
---|
| 76 | /// 32-bit pixel format, 8 bits for blue, green, red and alpha. |
---|
| 77 | PF_A8B8G8R8 = 13, |
---|
| 78 | /// 32-bit pixel format, 8 bits for blue, green, red and alpha. |
---|
| 79 | PF_B8G8R8A8 = 14, |
---|
| 80 | /// 32-bit pixel format, 8 bits for red, green, blue and alpha. |
---|
| 81 | PF_R8G8B8A8 = 28, |
---|
| 82 | /// 32-bit pixel format, 8 bits for red, 8 bits for green, 8 bits for blue |
---|
| 83 | /// like PF_A8R8G8B8, but alpha will get discarded |
---|
| 84 | PF_X8R8G8B8 = 26, |
---|
| 85 | /// 32-bit pixel format, 8 bits for blue, 8 bits for green, 8 bits for red |
---|
| 86 | /// like PF_A8B8G8R8, but alpha will get discarded |
---|
| 87 | PF_X8B8G8R8 = 27, |
---|
| 88 | #if OGRE_ENDIAN == OGRE_ENDIAN_BIG |
---|
| 89 | /// 3 byte pixel format, 1 byte for red, 1 byte for green, 1 byte for blue |
---|
| 90 | PF_BYTE_RGB = PF_R8G8B8, |
---|
| 91 | /// 3 byte pixel format, 1 byte for blue, 1 byte for green, 1 byte for red |
---|
| 92 | PF_BYTE_BGR = PF_B8G8R8, |
---|
| 93 | /// 4 byte pixel format, 1 byte for blue, 1 byte for green, 1 byte for red and one byte for alpha |
---|
| 94 | PF_BYTE_BGRA = PF_B8G8R8A8, |
---|
| 95 | /// 4 byte pixel format, 1 byte for red, 1 byte for green, 1 byte for blue, and one byte for alpha |
---|
| 96 | PF_BYTE_RGBA = PF_R8G8B8A8, |
---|
| 97 | #else |
---|
| 98 | /// 3 byte pixel format, 1 byte for red, 1 byte for green, 1 byte for blue |
---|
| 99 | PF_BYTE_RGB = PF_B8G8R8, |
---|
| 100 | /// 3 byte pixel format, 1 byte for blue, 1 byte for green, 1 byte for red |
---|
| 101 | PF_BYTE_BGR = PF_R8G8B8, |
---|
| 102 | /// 4 byte pixel format, 1 byte for blue, 1 byte for green, 1 byte for red and one byte for alpha |
---|
| 103 | PF_BYTE_BGRA = PF_A8R8G8B8, |
---|
| 104 | /// 4 byte pixel format, 1 byte for red, 1 byte for green, 1 byte for blue, and one byte for alpha |
---|
| 105 | PF_BYTE_RGBA = PF_A8B8G8R8, |
---|
| 106 | #endif |
---|
| 107 | /// 32-bit pixel format, 2 bits for alpha, 10 bits for red, green and blue. |
---|
| 108 | PF_A2R10G10B10 = 15, |
---|
| 109 | /// 32-bit pixel format, 10 bits for blue, green and red, 2 bits for alpha. |
---|
| 110 | PF_A2B10G10R10 = 16, |
---|
| 111 | /// DDS (DirectDraw Surface) DXT1 format |
---|
| 112 | PF_DXT1 = 17, |
---|
| 113 | /// DDS (DirectDraw Surface) DXT2 format |
---|
| 114 | PF_DXT2 = 18, |
---|
| 115 | /// DDS (DirectDraw Surface) DXT3 format |
---|
| 116 | PF_DXT3 = 19, |
---|
| 117 | /// DDS (DirectDraw Surface) DXT4 format |
---|
| 118 | PF_DXT4 = 20, |
---|
| 119 | /// DDS (DirectDraw Surface) DXT5 format |
---|
| 120 | PF_DXT5 = 21, |
---|
| 121 | /// 16-bit pixel format, 16 bits (float) for red |
---|
| 122 | PF_FLOAT16_R = 32, |
---|
| 123 | /// 48-bit pixel format, 16 bits (float) for red, 16 bits (float) for green, 16 bits (float) for blue |
---|
| 124 | PF_FLOAT16_RGB = 22, |
---|
| 125 | /// 64-bit pixel format, 16 bits (float) for red, 16 bits (float) for green, 16 bits (float) for blue, 16 bits (float) for alpha |
---|
| 126 | PF_FLOAT16_RGBA = 23, |
---|
| 127 | // 32-bit pixel format, 32 bits (float) for red |
---|
| 128 | PF_FLOAT32_R = 33, |
---|
| 129 | /// 96-bit pixel format, 32 bits (float) for red, 32 bits (float) for green, 32 bits (float) for blue |
---|
| 130 | PF_FLOAT32_RGB = 24, |
---|
| 131 | /// 128-bit pixel format, 32 bits (float) for red, 32 bits (float) for green, 32 bits (float) for blue, 32 bits (float) for alpha |
---|
| 132 | PF_FLOAT32_RGBA = 25, |
---|
| 133 | /// 32-bit, 2-channel s10e5 floating point pixel format, 16-bit green, 16-bit red |
---|
| 134 | PF_FLOAT16_GR = 35, |
---|
| 135 | /// 64-bit, 2-channel floating point pixel format, 32-bit green, 32-bit red |
---|
| 136 | PF_FLOAT32_GR = 36, |
---|
| 137 | /// Depth texture format |
---|
| 138 | PF_DEPTH = 29, |
---|
| 139 | /// 64-bit pixel format, 16 bits for red, green, blue and alpha |
---|
| 140 | PF_SHORT_RGBA = 30, |
---|
| 141 | /// 32-bit pixel format, 16-bit green, 16-bit red |
---|
| 142 | PF_SHORT_GR = 34, |
---|
| 143 | /// 48-bit pixel format, 16 bits for red, green and blue |
---|
| 144 | PF_SHORT_RGB = 37, |
---|
| 145 | /// PVRTC (PowerVR) RGB 2 bpp |
---|
| 146 | PF_PVRTC_RGB2 = 38, |
---|
| 147 | /// PVRTC (PowerVR) RGBA 2 bpp |
---|
| 148 | PF_PVRTC_RGBA2 = 39, |
---|
| 149 | /// PVRTC (PowerVR) RGB 4 bpp |
---|
| 150 | PF_PVRTC_RGB4 = 40, |
---|
| 151 | /// PVRTC (PowerVR) RGBA 4 bpp |
---|
| 152 | PF_PVRTC_RGBA4 = 41, |
---|
| 153 | /// PVRTC (PowerVR) Version 2, 2 bpp |
---|
| 154 | PF_PVRTC2_2BPP = 42, |
---|
| 155 | /// PVRTC (PowerVR) Version 2, 4 bpp |
---|
| 156 | PF_PVRTC2_4BPP = 43, |
---|
| 157 | /// 32-bit pixel format, 11 bits (float) for red, 11 bits (float) for green, 10 bits (float) for blue |
---|
| 158 | PF_R11G11B10_FLOAT = 44, |
---|
| 159 | /// 8-bit pixel format, 8 bits red (unsigned int). |
---|
| 160 | PF_R8_UINT = 45, |
---|
| 161 | /// 16-bit pixel format, 8 bits red (unsigned int), 8 bits blue (unsigned int). |
---|
| 162 | PF_R8G8_UINT = 46, |
---|
| 163 | /// 24-bit pixel format, 8 bits red (unsigned int), 8 bits blue (unsigned int), 8 bits green (unsigned int). |
---|
| 164 | PF_R8G8B8_UINT = 47, |
---|
| 165 | /// 32-bit pixel format, 8 bits red (unsigned int), 8 bits blue (unsigned int), 8 bits green (unsigned int), 8 bits alpha (unsigned int). |
---|
| 166 | PF_R8G8B8A8_UINT = 48, |
---|
| 167 | /// 16-bit pixel format, 16 bits red (unsigned int). |
---|
| 168 | PF_R16_UINT = 49, |
---|
| 169 | /// 32-bit pixel format, 16 bits red (unsigned int), 16 bits blue (unsigned int). |
---|
| 170 | PF_R16G16_UINT = 50, |
---|
| 171 | /// 48-bit pixel format, 16 bits red (unsigned int), 16 bits blue (unsigned int), 16 bits green (unsigned int). |
---|
| 172 | PF_R16G16B16_UINT = 51, |
---|
| 173 | /// 64-bit pixel format, 16 bits red (unsigned int), 16 bits blue (unsigned int), 16 bits green (unsigned int), 16 bits alpha (unsigned int). |
---|
| 174 | PF_R16G16B16A16_UINT = 52, |
---|
| 175 | /// 32-bit pixel format, 32 bits red (unsigned int). |
---|
| 176 | PF_R32_UINT = 53, |
---|
| 177 | /// 64-bit pixel format, 32 bits red (unsigned int), 32 bits blue (unsigned int). |
---|
| 178 | PF_R32G32_UINT = 54, |
---|
| 179 | /// 96-bit pixel format, 32 bits red (unsigned int), 32 bits blue (unsigned int), 32 bits green (unsigned int). |
---|
| 180 | PF_R32G32B32_UINT = 55, |
---|
| 181 | /// 128-bit pixel format, 32 bits red (unsigned int), 32 bits blue (unsigned int), 32 bits green (unsigned int), 32 bits alpha (unsigned int). |
---|
| 182 | PF_R32G32B32A32_UINT = 56, |
---|
| 183 | /// 8-bit pixel format, 8 bits red (signed int). |
---|
| 184 | PF_R8_SINT = 57, |
---|
| 185 | /// 16-bit pixel format, 8 bits red (signed int), 8 bits blue (signed int). |
---|
| 186 | PF_R8G8_SINT = 58, |
---|
| 187 | /// 24-bit pixel format, 8 bits red (signed int), 8 bits blue (signed int), 8 bits green (signed int). |
---|
| 188 | PF_R8G8B8_SINT = 59, |
---|
| 189 | /// 32-bit pixel format, 8 bits red (signed int), 8 bits blue (signed int), 8 bits green (signed int), 8 bits alpha (signed int). |
---|
| 190 | PF_R8G8B8A8_SINT = 60, |
---|
| 191 | /// 16-bit pixel format, 16 bits red (signed int). |
---|
| 192 | PF_R16_SINT = 61, |
---|
| 193 | /// 32-bit pixel format, 16 bits red (signed int), 16 bits blue (signed int). |
---|
| 194 | PF_R16G16_SINT = 62, |
---|
| 195 | /// 48-bit pixel format, 16 bits red (signed int), 16 bits blue (signed int), 16 bits green (signed int). |
---|
| 196 | PF_R16G16B16_SINT = 63, |
---|
| 197 | /// 64-bit pixel format, 16 bits red (signed int), 16 bits blue (signed int), 16 bits green (signed int), 16 bits alpha (signed int). |
---|
| 198 | PF_R16G16B16A16_SINT = 64, |
---|
| 199 | /// 32-bit pixel format, 32 bits red (signed int). |
---|
| 200 | PF_R32_SINT = 65, |
---|
| 201 | /// 64-bit pixel format, 32 bits red (signed int), 32 bits blue (signed int). |
---|
| 202 | PF_R32G32_SINT = 66, |
---|
| 203 | /// 96-bit pixel format, 32 bits red (signed int), 32 bits blue (signed int), 32 bits green (signed int). |
---|
| 204 | PF_R32G32B32_SINT = 67, |
---|
| 205 | /// 128-bit pixel format, 32 bits red (signed int), 32 bits blue (signed int), 32 bits green (signed int), 32 bits alpha (signed int). |
---|
| 206 | PF_R32G32B32A32_SINT = 68, |
---|
| 207 | /// 32-bit pixel format, 9 bits for blue, green, red plus a 5 bit exponent. |
---|
| 208 | PF_R9G9B9E5_SHAREDEXP = 69, |
---|
| 209 | /// DDS (DirectDraw Surface) BC4 format (unsigned normalised) |
---|
| 210 | PF_BC4_UNORM = 70, |
---|
| 211 | /// DDS (DirectDraw Surface) BC4 format (signed normalised) |
---|
| 212 | PF_BC4_SNORM = 71, |
---|
| 213 | /// DDS (DirectDraw Surface) BC5 format (unsigned normalised) |
---|
| 214 | PF_BC5_UNORM = 72, |
---|
| 215 | /// DDS (DirectDraw Surface) BC5 format (signed normalised) |
---|
| 216 | PF_BC5_SNORM = 73, |
---|
| 217 | /// DDS (DirectDraw Surface) BC6H format (unsigned 16 bit float) |
---|
| 218 | PF_BC6H_UF16 = 74, |
---|
| 219 | /// DDS (DirectDraw Surface) BC6H format (signed 16 bit float) |
---|
| 220 | PF_BC6H_SF16 = 75, |
---|
| 221 | /// DDS (DirectDraw Surface) BC7 format (unsigned normalised) |
---|
| 222 | PF_BC7_UNORM = 76, |
---|
| 223 | /// DDS (DirectDraw Surface) BC7 format (unsigned normalised sRGB) |
---|
| 224 | PF_BC7_UNORM_SRGB = 77, |
---|
| 225 | /// 8-bit pixel format, all bits red. |
---|
| 226 | PF_R8 = 78, |
---|
| 227 | /// 16-bit pixel format, 8 bits red, 8 bits green. |
---|
| 228 | PF_RG8 = 79, |
---|
| 229 | /// 8-bit pixel format, 8 bits red (signed normalised int). |
---|
| 230 | PF_R8_SNORM = 80, |
---|
| 231 | /// 16-bit pixel format, 8 bits red (signed normalised int), 8 bits blue (signed normalised int). |
---|
| 232 | PF_R8G8_SNORM = 81, |
---|
| 233 | /// 24-bit pixel format, 8 bits red (signed normalised int), 8 bits blue (signed normalised int), 8 bits green (signed normalised int). |
---|
| 234 | PF_R8G8B8_SNORM = 82, |
---|
| 235 | /// 32-bit pixel format, 8 bits red (signed normalised int), 8 bits blue (signed normalised int), 8 bits green (signed normalised int), 8 bits alpha (signed normalised int). |
---|
| 236 | PF_R8G8B8A8_SNORM = 83, |
---|
| 237 | /// 16-bit pixel format, 16 bits red (signed normalised int). |
---|
| 238 | PF_R16_SNORM = 84, |
---|
| 239 | /// 32-bit pixel format, 16 bits red (signed normalised int), 16 bits blue (signed normalised int). |
---|
| 240 | PF_R16G16_SNORM = 85, |
---|
| 241 | /// 48-bit pixel format, 16 bits red (signed normalised int), 16 bits blue (signed normalised int), 16 bits green (signed normalised int). |
---|
| 242 | PF_R16G16B16_SNORM = 86, |
---|
| 243 | /// 64-bit pixel format, 16 bits red (signed normalised int), 16 bits blue (signed normalised int), 16 bits green (signed normalised int), 16 bits alpha (signed normalised int). |
---|
| 244 | PF_R16G16B16A16_SNORM = 87, |
---|
| 245 | /// ETC1 (Ericsson Texture Compression) |
---|
| 246 | PF_ETC1_RGB8 = 88, |
---|
| 247 | /// ETC2 (Ericsson Texture Compression) |
---|
| 248 | PF_ETC2_RGB8 = 89, |
---|
| 249 | /// ETC2 (Ericsson Texture Compression) |
---|
| 250 | PF_ETC2_RGBA8 = 90, |
---|
| 251 | /// ETC2 (Ericsson Texture Compression) |
---|
| 252 | PF_ETC2_RGB8A1 = 91, |
---|
| 253 | /// ATC (AMD_compressed_ATC_texture) |
---|
| 254 | PF_ATC_RGB = 92, |
---|
| 255 | /// ATC (AMD_compressed_ATC_texture) |
---|
| 256 | PF_ATC_RGBA_EXPLICIT_ALPHA = 93, |
---|
| 257 | /// ATC (AMD_compressed_ATC_texture) |
---|
| 258 | PF_ATC_RGBA_INTERPOLATED_ALPHA = 94, |
---|
| 259 | // Number of pixel formats currently defined |
---|
| 260 | PF_COUNT = 95 |
---|
| 261 | }; |
---|
| 262 | typedef vector<PixelFormat>::type PixelFormatList; |
---|
| 263 | |
---|
| 264 | /** |
---|
| 265 | * Flags defining some on/off properties of pixel formats |
---|
| 266 | */ |
---|
| 267 | enum PixelFormatFlags { |
---|
| 268 | /// This format has an alpha channel |
---|
| 269 | PFF_HASALPHA = 0x00000001, |
---|
| 270 | /** This format is compressed. This invalidates the values in elemBytes, |
---|
| 271 | elemBits and the bit counts as these might not be fixed in a compressed format. */ |
---|
| 272 | PFF_COMPRESSED = 0x00000002, |
---|
| 273 | /// This is a floating point format |
---|
| 274 | PFF_FLOAT = 0x00000004, |
---|
| 275 | /// This is a depth format (for depth textures) |
---|
| 276 | PFF_DEPTH = 0x00000008, |
---|
| 277 | /** Format is in native endian. Generally true for the 16, 24 and 32 bits |
---|
| 278 | formats which can be represented as machine integers. */ |
---|
| 279 | PFF_NATIVEENDIAN = 0x00000010, |
---|
| 280 | /** This is an intensity format instead of a RGB one. The luminance |
---|
| 281 | replaces R,G and B. (but not A) */ |
---|
| 282 | PFF_LUMINANCE = 0x00000020, |
---|
| 283 | /// This is an integer format |
---|
| 284 | PFF_INTEGER = 0x00000040 |
---|
| 285 | }; |
---|
| 286 | |
---|
| 287 | /** Pixel component format */ |
---|
| 288 | enum PixelComponentType |
---|
| 289 | { |
---|
| 290 | PCT_BYTE = 0, /// Byte per component (8 bit fixed 0.0..1.0) |
---|
| 291 | PCT_SHORT = 1, /// Short per component (16 bit fixed 0.0..1.0)) |
---|
| 292 | PCT_FLOAT16 = 2, /// 16 bit float per component |
---|
| 293 | PCT_FLOAT32 = 3, /// 32 bit float per component |
---|
| 294 | PCT_SINT = 4, /// Signed integer per component |
---|
| 295 | PCT_UINT = 5, /// Unsigned integer per component |
---|
| 296 | PCT_COUNT = 6 /// Number of pixel types |
---|
| 297 | }; |
---|
| 298 | |
---|
| 299 | /** A primitive describing a volume (3D), image (2D) or line (1D) of pixels in memory. |
---|
| 300 | In case of a rectangle, depth must be 1. |
---|
| 301 | Pixels are stored as a succession of "depth" slices, each containing "height" rows of |
---|
| 302 | "width" pixels. |
---|
| 303 | */ |
---|
| 304 | class _OgreExport PixelBox: public Box, public ImageAlloc { |
---|
| 305 | public: |
---|
| 306 | /// Parameter constructor for setting the members manually |
---|
| 307 | PixelBox() {} |
---|
| 308 | ~PixelBox() {} |
---|
| 309 | /** Constructor providing extents in the form of a Box object. This constructor |
---|
| 310 | assumes the pixel data is laid out consecutively in memory. (this |
---|
| 311 | means row after row, slice after slice, with no space in between) |
---|
| 312 | @param extents Extents of the region defined by data |
---|
| 313 | @param pixelFormat Format of this buffer |
---|
| 314 | @param pixelData Pointer to the actual data |
---|
| 315 | */ |
---|
| 316 | PixelBox(const Box &extents, PixelFormat pixelFormat, void *pixelData=0): |
---|
| 317 | Box(extents), data(pixelData), format(pixelFormat) |
---|
| 318 | { |
---|
| 319 | setConsecutive(); |
---|
| 320 | } |
---|
| 321 | /** Constructor providing width, height and depth. This constructor |
---|
| 322 | assumes the pixel data is laid out consecutively in memory. (this |
---|
| 323 | means row after row, slice after slice, with no space in between) |
---|
| 324 | @param width Width of the region |
---|
| 325 | @param height Height of the region |
---|
| 326 | @param depth Depth of the region |
---|
| 327 | @param pixelFormat Format of this buffer |
---|
| 328 | @param pixelData Pointer to the actual data |
---|
| 329 | */ |
---|
| 330 | PixelBox(uint32 width, uint32 height, uint32 depth, PixelFormat pixelFormat, void *pixelData=0): |
---|
| 331 | Box(0, 0, 0, width, height, depth), |
---|
| 332 | data(pixelData), format(pixelFormat) |
---|
| 333 | { |
---|
| 334 | setConsecutive(); |
---|
| 335 | } |
---|
| 336 | |
---|
| 337 | /// The data pointer |
---|
| 338 | void *data; |
---|
| 339 | /// The pixel format |
---|
| 340 | PixelFormat format; |
---|
| 341 | /** Number of elements between the leftmost pixel of one row and the left |
---|
| 342 | pixel of the next. This value must always be equal to getWidth() (consecutive) |
---|
| 343 | for compressed formats. |
---|
| 344 | */ |
---|
| 345 | size_t rowPitch; |
---|
| 346 | /** Number of elements between the top left pixel of one (depth) slice and |
---|
| 347 | the top left pixel of the next. This can be a negative value. Must be a multiple of |
---|
| 348 | rowPitch. This value must always be equal to getWidth()*getHeight() (consecutive) |
---|
| 349 | for compressed formats. |
---|
| 350 | */ |
---|
| 351 | size_t slicePitch; |
---|
| 352 | |
---|
| 353 | /** Set the rowPitch and slicePitch so that the buffer is laid out consecutive |
---|
| 354 | in memory. |
---|
| 355 | */ |
---|
| 356 | void setConsecutive() |
---|
| 357 | { |
---|
| 358 | rowPitch = getWidth(); |
---|
| 359 | slicePitch = getWidth()*getHeight(); |
---|
| 360 | } |
---|
| 361 | /** Get the number of elements between one past the rightmost pixel of |
---|
| 362 | one row and the leftmost pixel of the next row. (IE this is zero if rows |
---|
| 363 | are consecutive). |
---|
| 364 | */ |
---|
| 365 | size_t getRowSkip() const { return rowPitch - getWidth(); } |
---|
| 366 | /** Get the number of elements between one past the right bottom pixel of |
---|
| 367 | one slice and the left top pixel of the next slice. (IE this is zero if slices |
---|
| 368 | are consecutive). |
---|
| 369 | */ |
---|
| 370 | size_t getSliceSkip() const { return slicePitch - (getHeight() * rowPitch); } |
---|
| 371 | |
---|
| 372 | /** Return whether this buffer is laid out consecutive in memory (ie the pitches |
---|
| 373 | are equal to the dimensions) |
---|
| 374 | */ |
---|
| 375 | bool isConsecutive() const |
---|
| 376 | { |
---|
| 377 | return rowPitch == getWidth() && slicePitch == getWidth()*getHeight(); |
---|
| 378 | } |
---|
| 379 | /** Return the size (in bytes) this image would take if it was |
---|
| 380 | laid out consecutive in memory |
---|
| 381 | */ |
---|
| 382 | size_t getConsecutiveSize() const; |
---|
| 383 | /** Return a subvolume of this PixelBox. |
---|
| 384 | @param def Defines the bounds of the subregion to return |
---|
| 385 | @return A pixel box describing the region and the data in it |
---|
| 386 | @remarks This function does not copy any data, it just returns |
---|
| 387 | a PixelBox object with a data pointer pointing somewhere inside |
---|
| 388 | the data of object. |
---|
| 389 | @throws Exception(ERR_INVALIDPARAMS) if def is not fully contained |
---|
| 390 | */ |
---|
| 391 | PixelBox getSubVolume(const Box &def) const; |
---|
| 392 | |
---|
| 393 | /** Return a data pointer pointing to top left front pixel of the pixel box. |
---|
| 394 | @remarks Non consecutive pixel boxes are supported. |
---|
| 395 | */ |
---|
| 396 | void* getTopLeftFrontPixelPtr() const; |
---|
| 397 | |
---|
| 398 | /** |
---|
| 399 | * Get colour value from a certain location in the PixelBox. The z coordinate |
---|
| 400 | * is only valid for cubemaps and volume textures. This uses the first (largest) |
---|
| 401 | * mipmap. |
---|
| 402 | */ |
---|
| 403 | ColourValue getColourAt(size_t x, size_t y, size_t z); |
---|
| 404 | |
---|
| 405 | /** |
---|
| 406 | * Set colour value at a certain location in the PixelBox. The z coordinate |
---|
| 407 | * is only valid for cubemaps and volume textures. This uses the first (largest) |
---|
| 408 | * mipmap. |
---|
| 409 | */ |
---|
| 410 | void setColourAt(ColourValue const &cv, size_t x, size_t y, size_t z); |
---|
| 411 | }; |
---|
| 412 | |
---|
| 413 | |
---|
| 414 | /** |
---|
| 415 | * Some utility functions for packing and unpacking pixel data |
---|
| 416 | */ |
---|
| 417 | class _OgreExport PixelUtil { |
---|
| 418 | public: |
---|
| 419 | /** Returns the size in bytes of an element of the given pixel format. |
---|
| 420 | @return |
---|
| 421 | The size in bytes of an element. See Remarks. |
---|
| 422 | @remarks |
---|
| 423 | Passing PF_UNKNOWN will result in returning a size of 0 bytes. |
---|
| 424 | */ |
---|
| 425 | static size_t getNumElemBytes( PixelFormat format ); |
---|
| 426 | |
---|
| 427 | /** Returns the size in bits of an element of the given pixel format. |
---|
| 428 | @return |
---|
| 429 | The size in bits of an element. See Remarks. |
---|
| 430 | @remarks |
---|
| 431 | Passing PF_UNKNOWN will result in returning a size of 0 bits. |
---|
| 432 | */ |
---|
| 433 | static size_t getNumElemBits( PixelFormat format ); |
---|
| 434 | |
---|
| 435 | /** Returns the size in memory of a region with the given extents and pixel |
---|
| 436 | format with consecutive memory layout. |
---|
| 437 | @param width |
---|
| 438 | The width of the area |
---|
| 439 | @param height |
---|
| 440 | The height of the area |
---|
| 441 | @param depth |
---|
| 442 | The depth of the area |
---|
| 443 | @param format |
---|
| 444 | The format of the area |
---|
| 445 | @return |
---|
| 446 | The size in bytes |
---|
| 447 | @remarks |
---|
| 448 | In case that the format is non-compressed, this simply returns |
---|
| 449 | width*height*depth*PixelUtil::getNumElemBytes(format). In the compressed |
---|
| 450 | case, this does serious magic. |
---|
| 451 | */ |
---|
| 452 | static size_t getMemorySize(uint32 width, uint32 height, uint32 depth, PixelFormat format); |
---|
| 453 | |
---|
| 454 | /** Returns the property flags for this pixel format |
---|
| 455 | @return |
---|
| 456 | A bitfield combination of PFF_HASALPHA, PFF_ISCOMPRESSED, |
---|
| 457 | PFF_FLOAT, PFF_DEPTH, PFF_NATIVEENDIAN, PFF_LUMINANCE |
---|
| 458 | @remarks |
---|
| 459 | This replaces the separate functions for formatHasAlpha, formatIsFloat, ... |
---|
| 460 | */ |
---|
| 461 | static unsigned int getFlags( PixelFormat format ); |
---|
| 462 | |
---|
| 463 | /** Shortcut method to determine if the format has an alpha component */ |
---|
| 464 | static bool hasAlpha(PixelFormat format); |
---|
| 465 | /** Shortcut method to determine if the format is floating point */ |
---|
| 466 | static bool isFloatingPoint(PixelFormat format); |
---|
| 467 | /** Shortcut method to determine if the format is integer */ |
---|
| 468 | static bool isInteger(PixelFormat format); |
---|
| 469 | /** Shortcut method to determine if the format is compressed */ |
---|
| 470 | static bool isCompressed(PixelFormat format); |
---|
| 471 | /** Shortcut method to determine if the format is a depth format. */ |
---|
| 472 | static bool isDepth(PixelFormat format); |
---|
| 473 | /** Shortcut method to determine if the format is in native endian format. */ |
---|
| 474 | static bool isNativeEndian(PixelFormat format); |
---|
| 475 | /** Shortcut method to determine if the format is a luminance format. */ |
---|
| 476 | static bool isLuminance(PixelFormat format); |
---|
| 477 | |
---|
| 478 | /** Return whether a certain image extent is valid for this image format. |
---|
| 479 | @param width |
---|
| 480 | The width of the area |
---|
| 481 | @param height |
---|
| 482 | The height of the area |
---|
| 483 | @param depth |
---|
| 484 | The depth of the area |
---|
| 485 | @param format |
---|
| 486 | The format of the area |
---|
| 487 | @remarks For non-compressed formats, this is always true. For DXT formats, |
---|
| 488 | only sizes with a width and height multiple of 4 and depth 1 are allowed. |
---|
| 489 | */ |
---|
| 490 | static bool isValidExtent(size_t width, size_t height, size_t depth, PixelFormat format); |
---|
| 491 | |
---|
| 492 | /** Gives the number of bits (RGBA) for a format. See remarks. |
---|
| 493 | @remarks For non-colour formats (dxt, depth) this returns [0,0,0,0]. |
---|
| 494 | */ |
---|
| 495 | static void getBitDepths(PixelFormat format, int rgba[4]); |
---|
| 496 | |
---|
| 497 | /** Gives the masks for the R, G, B and A component |
---|
| 498 | @note Only valid for native endian formats |
---|
| 499 | */ |
---|
| 500 | static void getBitMasks(PixelFormat format, uint64 rgba[4]); |
---|
| 501 | |
---|
| 502 | /** Gives the bit shifts for R, G, B and A component |
---|
| 503 | @note Only valid for native endian formats |
---|
| 504 | */ |
---|
| 505 | static void getBitShifts(PixelFormat format, unsigned char rgba[4]); |
---|
| 506 | |
---|
| 507 | /** Gets the name of an image format |
---|
| 508 | */ |
---|
| 509 | static String getFormatName(PixelFormat srcformat); |
---|
| 510 | |
---|
| 511 | /** Returns whether the format can be packed or unpacked with the packColour() |
---|
| 512 | and unpackColour() functions. This is generally not true for compressed and |
---|
| 513 | depth formats as they are special. It can only be true for formats with a |
---|
| 514 | fixed element size. |
---|
| 515 | @return |
---|
| 516 | true if yes, otherwise false |
---|
| 517 | */ |
---|
| 518 | static bool isAccessible(PixelFormat srcformat); |
---|
| 519 | |
---|
| 520 | /** Returns the component type for a certain pixel format. Returns PCT_BYTE |
---|
| 521 | in case there is no clear component type like with compressed formats. |
---|
| 522 | This is one of PCT_BYTE, PCT_SHORT, PCT_FLOAT16, PCT_FLOAT32. |
---|
| 523 | */ |
---|
| 524 | static PixelComponentType getComponentType(PixelFormat fmt); |
---|
| 525 | |
---|
| 526 | /** Returns the component count for a certain pixel format. Returns 3(no alpha) or |
---|
| 527 | 4 (has alpha) in case there is no clear component type like with compressed formats. |
---|
| 528 | */ |
---|
| 529 | static size_t getComponentCount(PixelFormat fmt); |
---|
| 530 | |
---|
| 531 | /** Gets the format from given name. |
---|
| 532 | @param name The string of format name |
---|
| 533 | @param accessibleOnly If true, non-accessible format will treat as invalid format, |
---|
| 534 | otherwise, all supported format are valid. |
---|
| 535 | @param caseSensitive Should be set true if string match should use case sensitivity. |
---|
| 536 | @return The format match the format name, or PF_UNKNOWN if is invalid name. |
---|
| 537 | */ |
---|
| 538 | static PixelFormat getFormatFromName(const String& name, bool accessibleOnly = false, bool caseSensitive = false); |
---|
| 539 | |
---|
| 540 | /** Gets the BNF expression of the pixel-formats. |
---|
| 541 | @note The string returned by this function is intended to be used as a BNF expression |
---|
| 542 | to work with Compiler2Pass. |
---|
| 543 | @param accessibleOnly If true, only accessible pixel format will take into account, otherwise all |
---|
| 544 | pixel formats list in PixelFormat enumeration will being returned. |
---|
| 545 | @return A string contains the BNF expression. |
---|
| 546 | */ |
---|
| 547 | static String getBNFExpressionOfPixelFormats(bool accessibleOnly = false); |
---|
| 548 | |
---|
| 549 | /** Returns the similar format but acoording with given bit depths. |
---|
| 550 | @param fmt The original foamt. |
---|
| 551 | @param integerBits Preferred bit depth (pixel bits) for integer pixel format. |
---|
| 552 | Available values: 0, 16 and 32, where 0 (the default) means as it is. |
---|
| 553 | @param floatBits Preferred bit depth (channel bits) for float pixel format. |
---|
| 554 | Available values: 0, 16 and 32, where 0 (the default) means as it is. |
---|
| 555 | @return The format that similar original format with bit depth according |
---|
| 556 | with preferred bit depth, or original format if no conversion occurring. |
---|
| 557 | */ |
---|
| 558 | static PixelFormat getFormatForBitDepths(PixelFormat fmt, ushort integerBits, ushort floatBits); |
---|
| 559 | |
---|
| 560 | /** Pack a colour value to memory |
---|
| 561 | @param colour The colour |
---|
| 562 | @param pf Pixelformat in which to write the colour |
---|
| 563 | @param dest Destination memory location |
---|
| 564 | */ |
---|
| 565 | static void packColour(const ColourValue &colour, const PixelFormat pf, void* dest); |
---|
| 566 | /** Pack a colour value to memory |
---|
| 567 | @param r,g,b,a The four colour components, range 0.0f to 1.0f |
---|
| 568 | (an exception to this case exists for floating point pixel |
---|
| 569 | formats, which don't clamp to 0.0f..1.0f) |
---|
| 570 | @param pf Pixelformat in which to write the colour |
---|
| 571 | @param dest Destination memory location |
---|
| 572 | */ |
---|
| 573 | static void packColour(const uint8 r, const uint8 g, const uint8 b, const uint8 a, const PixelFormat pf, void* dest); |
---|
| 574 | /** Pack a colour value to memory |
---|
| 575 | @param r,g,b,a The four colour components, range 0.0f to 1.0f |
---|
| 576 | (an exception to this case exists for floating point pixel |
---|
| 577 | formats, which don't clamp to 0.0f..1.0f) |
---|
| 578 | @param pf Pixelformat in which to write the colour |
---|
| 579 | @param dest Destination memory location |
---|
| 580 | */ |
---|
| 581 | static void packColour(const float r, const float g, const float b, const float a, const PixelFormat pf, void* dest); |
---|
| 582 | |
---|
| 583 | /** Unpack a colour value from memory |
---|
| 584 | @param colour The colour is returned here |
---|
| 585 | @param pf Pixelformat in which to read the colour |
---|
| 586 | @param src Source memory location |
---|
| 587 | */ |
---|
| 588 | static void unpackColour(ColourValue *colour, PixelFormat pf, const void* src); |
---|
| 589 | /** Unpack a colour value from memory |
---|
| 590 | @param r The red channel is returned here (as byte) |
---|
| 591 | @param g The blue channel is returned here (as byte) |
---|
| 592 | @param b The green channel is returned here (as byte) |
---|
| 593 | @param a The alpha channel is returned here (as byte) |
---|
| 594 | @param pf Pixelformat in which to read the colour |
---|
| 595 | @param src Source memory location |
---|
| 596 | @remarks This function returns the colour components in 8 bit precision, |
---|
| 597 | this will lose precision when coming from PF_A2R10G10B10 or floating |
---|
| 598 | point formats. |
---|
| 599 | */ |
---|
| 600 | static void unpackColour(uint8 *r, uint8 *g, uint8 *b, uint8 *a, PixelFormat pf, const void* src); |
---|
| 601 | /** Unpack a colour value from memory |
---|
| 602 | @param r The red channel is returned here (as float) |
---|
| 603 | @param g The blue channel is returned here (as float) |
---|
| 604 | @param b The green channel is returned here (as float) |
---|
| 605 | @param a The alpha channel is returned here (as float) |
---|
| 606 | @param pf Pixelformat in which to read the colour |
---|
| 607 | @param src Source memory location |
---|
| 608 | */ |
---|
| 609 | static void unpackColour(float *r, float *g, float *b, float *a, PixelFormat pf, const void* src); |
---|
| 610 | |
---|
| 611 | /** Convert consecutive pixels from one format to another. No dithering or filtering is being done. |
---|
| 612 | Converting from RGB to luminance takes the R channel. In case the source and destination format match, |
---|
| 613 | just a copy is done. |
---|
| 614 | @param src Pointer to source region |
---|
| 615 | @param srcFormat Pixel format of source region |
---|
| 616 | @param dst Pointer to destination region |
---|
| 617 | @param dstFormat Pixel format of destination region |
---|
| 618 | */ |
---|
| 619 | static void bulkPixelConversion(void *src, PixelFormat srcFormat, void *dst, PixelFormat dstFormat, unsigned int count); |
---|
| 620 | |
---|
| 621 | /** Convert pixels from one format to another. No dithering or filtering is being done. Converting |
---|
| 622 | from RGB to luminance takes the R channel. |
---|
| 623 | @param src PixelBox containing the source pixels, pitches and format |
---|
| 624 | @param dst PixelBox containing the destination pixels, pitches and format |
---|
| 625 | @remarks The source and destination boxes must have the same |
---|
| 626 | dimensions. In case the source and destination format match, a plain copy is done. |
---|
| 627 | */ |
---|
| 628 | static void bulkPixelConversion(const PixelBox &src, const PixelBox &dst); |
---|
| 629 | |
---|
| 630 | /** Flips pixels inplace in vertical direction. |
---|
| 631 | @param box PixelBox containing pixels, pitches and format |
---|
| 632 | @remarks Non consecutive pixel boxes are supported. |
---|
| 633 | */ |
---|
| 634 | static void bulkPixelVerticalFlip(const PixelBox &box); |
---|
| 635 | }; |
---|
| 636 | /** @} */ |
---|
| 637 | /** @} */ |
---|
| 638 | |
---|
| 639 | } |
---|
| 640 | |
---|
| 641 | #include "OgreHeaderSuffix.h" |
---|
| 642 | |
---|
| 643 | #endif |
---|