# OgrePixelFormat.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 (c) 2000-2009 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
    00034 namespace Ogre {
    00042     enum PixelFormat
    00043     {
    00045         PF_UNKNOWN = 0,
    00047         PF_L8 = 1,
    00048         PF_BYTE_L = PF_L8,
    00050         PF_L16 = 2,
    00051         PF_SHORT_L = PF_L16,
    00053         PF_A8 = 3,
    00054         PF_BYTE_A = PF_A8,
    00056         PF_A4L4 = 4,
    00058         PF_BYTE_LA = 5,
    00060         PF_R5G6B5 = 6,
    00062         PF_B5G6R5 = 7,
    00064         PF_R3G3B2 = 31,
    00066         PF_A4R4G4B4 = 8,
    00068         PF_A1R5G5B5 = 9,
    00070         PF_R8G8B8 = 10,
    00072         PF_B8G8R8 = 11,
    00074         PF_A8R8G8B8 = 12,
    00076         PF_A8B8G8R8 = 13,
    00078         PF_B8G8R8A8 = 14,
    00080         PF_R8G8B8A8 = 28,
    00083         PF_X8R8G8B8 = 26,
    00086         PF_X8B8G8R8 = 27,
    00087 #if OGRE_ENDIAN == OGRE_ENDIAN_BIG
    00088
    00089         PF_BYTE_RGB = PF_R8G8B8,
    00091         PF_BYTE_BGR = PF_B8G8R8,
    00093         PF_BYTE_BGRA = PF_B8G8R8A8,
    00095         PF_BYTE_RGBA = PF_R8G8B8A8,
    00096 #else
    00097
    00098         PF_BYTE_RGB = PF_B8G8R8,
    00100         PF_BYTE_BGR = PF_R8G8B8,
    00102         PF_BYTE_BGRA = PF_A8R8G8B8,
    00104         PF_BYTE_RGBA = PF_A8B8G8R8,
    00105 #endif
    00106
    00107         PF_A2R10G10B10 = 15,
    00109         PF_A2B10G10R10 = 16,
    00111         PF_DXT1 = 17,
    00113         PF_DXT2 = 18,
    00115         PF_DXT3 = 19,
    00117         PF_DXT4 = 20,
    00119         PF_DXT5 = 21,
    00120         // 16-bit pixel format, 16 bits (float) for red
    00121         PF_FLOAT16_R = 32,
    00122         // 48-bit pixel format, 16 bits (float) for red, 16 bits (float) for green, 16 bits (float) for blue
    00123         PF_FLOAT16_RGB = 22,
    00124         // 64-bit pixel format, 16 bits (float) for red, 16 bits (float) for green, 16 bits (float) for blue, 16 bits (float) for alpha
    00125         PF_FLOAT16_RGBA = 23,
    00126         // 32-bit pixel format, 32 bits (float) for red
    00127         PF_FLOAT32_R = 33,
    00128         // 96-bit pixel format, 32 bits (float) for red, 32 bits (float) for green, 32 bits (float) for blue
    00129         PF_FLOAT32_RGB = 24,
    00130         // 128-bit pixel format, 32 bits (float) for red, 32 bits (float) for green, 32 bits (float) for blue, 32 bits (float) for alpha
    00131         PF_FLOAT32_RGBA = 25,
    00132         // 32-bit, 2-channel s10e5 floating point pixel format, 16-bit green, 16-bit red
    00133         PF_FLOAT16_GR = 35,
    00134         // 64-bit, 2-channel floating point pixel format, 32-bit green, 32-bit red
    00135         PF_FLOAT32_GR = 36,
    00136         // Depth texture format
    00137         PF_DEPTH = 29,
    00138         // 64-bit pixel format, 16 bits for red, green, blue and alpha
    00139         PF_SHORT_RGBA = 30,
    00140         // 32-bit pixel format, 16-bit green, 16-bit red
    00141         PF_SHORT_GR = 34,
    00142         // 48-bit pixel format, 16 bits for red, green and blue
    00143         PF_SHORT_RGB = 37,
    00145         PF_PVRTC_RGB2 = 38,
    00147         PF_PVRTC_RGBA2 = 39,
    00149         PF_PVRTC_RGB4 = 40,
    00151         PF_PVRTC_RGBA4 = 41,
    00152         // Number of pixel formats currently defined
    00153         PF_COUNT = 42
    00154     };
    00155     typedef vector<PixelFormat>::type PixelFormatList;
    00156
    00160     enum PixelFormatFlags {
    00161         // This format has an alpha channel
    00162         PFF_HASALPHA        = 0x00000001,
    00163         // This format is compressed. This invalidates the values in elemBytes,
    00164         // elemBits and the bit counts as these might not be fixed in a compressed format.
    00165         PFF_COMPRESSED    = 0x00000002,
    00166         // This is a floating point format
    00167         PFF_FLOAT           = 0x00000004,
    00168         // This is a depth format (for depth textures)
    00169         PFF_DEPTH           = 0x00000008,
    00170         // Format is in native endian. Generally true for the 16, 24 and 32 bits
    00171         // formats which can be represented as machine integers.
    00172         PFF_NATIVEENDIAN    = 0x00000010,
    00173         // This is an intensity format instead of a RGB one. The luminance
    00174         // replaces R,G and B. (but not A)
    00175         PFF_LUMINANCE       = 0x00000020
    00176     };
    00177
    00179     enum PixelComponentType
    00180     {
    00181         PCT_BYTE = 0,
    00182         PCT_SHORT = 1,
    00183         PCT_FLOAT16 = 2,
    00184         PCT_FLOAT32 = 3,
    00185         PCT_COUNT = 4
    00186     };
    00187
    00193     class _OgreExport PixelBox: public Box, public ImageAlloc {
    00194     public:
    00196         PixelBox() {}
    00197         ~PixelBox() {}
    00205         PixelBox(const Box &extents, PixelFormat pixelFormat, void *pixelData=0):
    00206             Box(extents), data(pixelData), format(pixelFormat)
    00207         {
    00208             setConsecutive();
    00209         }
    00219         PixelBox(size_t width, size_t height, size_t depth, PixelFormat pixelFormat, void *pixelData=0):
    00220             Box(0, 0, 0, width, height, depth),
    00221             data(pixelData), format(pixelFormat)
    00222         {
    00223             setConsecutive();
    00224         }
    00225
    00227         void *data;
    00229         PixelFormat format;
    00234         size_t rowPitch;
    00240         size_t slicePitch;
    00241
    00245         void setConsecutive()
    00246         {
    00247             rowPitch = getWidth();
    00248             slicePitch = getWidth()*getHeight();
    00249         }
    00254         size_t getRowSkip() const { return rowPitch - getWidth(); }
    00259         size_t getSliceSkip() const { return slicePitch - (getHeight() * rowPitch); }
    00260
    00264         bool isConsecutive() const
    00265         {
    00266             return rowPitch == getWidth() && slicePitch == getWidth()*getHeight();
    00267         }
    00271         size_t getConsecutiveSize() const;
    00280         PixelBox getSubVolume(const Box &def) const;
    00281
    00287         ColourValue getColourAt(size_t x, size_t y, size_t z);
    00288
    00294         void setColourAt(ColourValue const &cv, size_t x, size_t y, size_t z);
    00295     };
    00296
    00297
    00301     class _OgreExport PixelUtil {
    00302     public:
    00309         static size_t getNumElemBytes( PixelFormat format );
    00310
    00317         static size_t getNumElemBits( PixelFormat format );
    00318
    00336         static size_t getMemorySize(size_t width, size_t height, size_t depth, PixelFormat format);
    00337
    00345         static unsigned int getFlags( PixelFormat format );
    00346
    00348         static bool hasAlpha(PixelFormat format);
    00350         static bool isFloatingPoint(PixelFormat format);
    00352         static bool isCompressed(PixelFormat format);
    00354         static bool isDepth(PixelFormat format);
    00356         static bool isNativeEndian(PixelFormat format);
    00358         static bool isLuminance(PixelFormat format);
    00359
    00372         static bool isValidExtent(size_t width, size_t height, size_t depth, PixelFormat format);
    00373
    00377         static void getBitDepths(PixelFormat format, int rgba[4]);
    00378
    00382         static void getBitMasks(PixelFormat format, uint32 rgba[4]);
    00383
    00387         static void getBitShifts(PixelFormat format, unsigned char rgba[4]);
    00388
    00391         static String getFormatName(PixelFormat srcformat);
    00392
    00400         static bool isAccessible(PixelFormat srcformat);
    00401
    00406         static PixelComponentType getComponentType(PixelFormat fmt);
    00407
    00411         static size_t getComponentCount(PixelFormat fmt);
    00412
    00420         static PixelFormat getFormatFromName(const String& name, bool accessibleOnly = false, bool caseSensitive = false);
    00421
    00429         static String getBNFExpressionOfPixelFormats(bool accessibleOnly = false);
    00430
    00440         static PixelFormat getFormatForBitDepths(PixelFormat fmt, ushort integerBits, ushort floatBits);
    00441
    00447         static void packColour(const ColourValue &colour, const PixelFormat pf,  void* dest);
    00453         static void packColour(const uint8 r, const uint8 g, const uint8 b, const uint8 a, const PixelFormat pf,  void* dest);
    00461         static void packColour(const float r, const float g, const float b, const float a, const PixelFormat pf,  void* dest);
    00462
    00468         static void unpackColour(ColourValue *colour, PixelFormat pf,  const void* src);
    00477         static void unpackColour(uint8 *r, uint8 *g, uint8 *b, uint8 *a, PixelFormat pf,  const void* src);
    00483         static void unpackColour(float *r, float *g, float *b, float *a, PixelFormat pf,  const void* src);
    00484
    00493         static void bulkPixelConversion(void *src, PixelFormat srcFormat, void *dest, PixelFormat dstFormat, unsigned int count);
    00494
    00502         static void bulkPixelConversion(const PixelBox &src, const PixelBox &dst);
    00503     };
    00507 }
    00508
    00509 #endif

Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Sun May 8 2011 20:28:08