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-2012 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,
    00153         PF_R8 = 42,
    00155         PF_RG8 = 43,
    00156         // Number of pixel formats currently defined
    00157         PF_COUNT = 44
    00158     };
    00159     typedef vector<PixelFormat>::type PixelFormatList;
    00160
    00164     enum PixelFormatFlags {
    00165         // This format has an alpha channel
    00166         PFF_HASALPHA        = 0x00000001,
    00167         // This format is compressed. This invalidates the values in elemBytes,
    00168         // elemBits and the bit counts as these might not be fixed in a compressed format.
    00169         PFF_COMPRESSED    = 0x00000002,
    00170         // This is a floating point format
    00171         PFF_FLOAT           = 0x00000004,
    00172         // This is a depth format (for depth textures)
    00173         PFF_DEPTH           = 0x00000008,
    00174         // Format is in native endian. Generally true for the 16, 24 and 32 bits
    00175         // formats which can be represented as machine integers.
    00176         PFF_NATIVEENDIAN    = 0x00000010,
    00177         // This is an intensity format instead of a RGB one. The luminance
    00178         // replaces R,G and B. (but not A)
    00179         PFF_LUMINANCE       = 0x00000020
    00180     };
    00181
    00183     enum PixelComponentType
    00184     {
    00185         PCT_BYTE = 0,
    00186         PCT_SHORT = 1,
    00187         PCT_FLOAT16 = 2,
    00188         PCT_FLOAT32 = 3,
    00189         PCT_COUNT = 4
    00190     };
    00191
    00197     class _OgreExport PixelBox: public Box, public ImageAlloc {
    00198     public:
    00200         PixelBox() {}
    00201         ~PixelBox() {}
    00209         PixelBox(const Box &extents, PixelFormat pixelFormat, void *pixelData=0):
    00210             Box(extents), data(pixelData), format(pixelFormat)
    00211         {
    00212             setConsecutive();
    00213         }
    00223         PixelBox(size_t width, size_t height, size_t depth, PixelFormat pixelFormat, void *pixelData=0):
    00224             Box(0, 0, 0, width, height, depth),
    00225             data(pixelData), format(pixelFormat)
    00226         {
    00227             setConsecutive();
    00228         }
    00229
    00231         void *data;
    00233         PixelFormat format;
    00238         size_t rowPitch;
    00244         size_t slicePitch;
    00245
    00249         void setConsecutive()
    00250         {
    00251             rowPitch = getWidth();
    00252             slicePitch = getWidth()*getHeight();
    00253         }
    00258         size_t getRowSkip() const { return rowPitch - getWidth(); }
    00263         size_t getSliceSkip() const { return slicePitch - (getHeight() * rowPitch); }
    00264
    00268         bool isConsecutive() const
    00269         {
    00270             return rowPitch == getWidth() && slicePitch == getWidth()*getHeight();
    00271         }
    00275         size_t getConsecutiveSize() const;
    00284         PixelBox getSubVolume(const Box &def) const;
    00285
    00291         ColourValue getColourAt(size_t x, size_t y, size_t z);
    00292
    00298         void setColourAt(ColourValue const &cv, size_t x, size_t y, size_t z);
    00299     };
    00300
    00301
    00305     class _OgreExport PixelUtil {
    00306     public:
    00313         static size_t getNumElemBytes( PixelFormat format );
    00314
    00321         static size_t getNumElemBits( PixelFormat format );
    00322
    00340         static size_t getMemorySize(size_t width, size_t height, size_t depth, PixelFormat format);
    00341
    00349         static unsigned int getFlags( PixelFormat format );
    00350
    00352         static bool hasAlpha(PixelFormat format);
    00354         static bool isFloatingPoint(PixelFormat format);
    00356         static bool isCompressed(PixelFormat format);
    00358         static bool isDepth(PixelFormat format);
    00360         static bool isNativeEndian(PixelFormat format);
    00362         static bool isLuminance(PixelFormat format);
    00363
    00376         static bool isValidExtent(size_t width, size_t height, size_t depth, PixelFormat format);
    00377
    00381         static void getBitDepths(PixelFormat format, int rgba[4]);
    00382
    00386         static void getBitMasks(PixelFormat format, uint32 rgba[4]);
    00387
    00391         static void getBitShifts(PixelFormat format, unsigned char rgba[4]);
    00392
    00395         static String getFormatName(PixelFormat srcformat);
    00396
    00404         static bool isAccessible(PixelFormat srcformat);
    00405
    00410         static PixelComponentType getComponentType(PixelFormat fmt);
    00411
    00415         static size_t getComponentCount(PixelFormat fmt);
    00416
    00424         static PixelFormat getFormatFromName(const String& name, bool accessibleOnly = false, bool caseSensitive = false);
    00425
    00433         static String getBNFExpressionOfPixelFormats(bool accessibleOnly = false);
    00434
    00444         static PixelFormat getFormatForBitDepths(PixelFormat fmt, ushort integerBits, ushort floatBits);
    00445
    00451         static void packColour(const ColourValue &colour, const PixelFormat pf,  void* dest);
    00457         static void packColour(const uint8 r, const uint8 g, const uint8 b, const uint8 a, const PixelFormat pf,  void* dest);
    00465         static void packColour(const float r, const float g, const float b, const float a, const PixelFormat pf,  void* dest);
    00466
    00472         static void unpackColour(ColourValue *colour, PixelFormat pf,  const void* src);
    00481         static void unpackColour(uint8 *r, uint8 *g, uint8 *b, uint8 *a, PixelFormat pf,  const void* src);
    00487         static void unpackColour(float *r, float *g, float *b, float *a, PixelFormat pf,  const void* src);
    00488
    00497         static void bulkPixelConversion(void *src, PixelFormat srcFormat, void *dest, PixelFormat dstFormat, unsigned int count);
    00498
    00506         static void bulkPixelConversion(const PixelBox &src, const PixelBox &dst);
    00507     };
    00511 }
    00512
    00513 #endif

Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Sun Sep 2 2012 07:27:22