# 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-2005 The OGRE Team
    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 */
    00025 #ifndef _PixelFormat_H__
    00026 #define _PixelFormat_H__
    00027
    00028 #include "OgrePrerequisites.h"
    00029 #include "OgreCommon.h"
    00030
    00031 namespace Ogre {
    00033     enum PixelFormat
    00034     {
    00036         PF_UNKNOWN = 0,
    00038         PF_L8 = 1,
    00039         PF_BYTE_L = PF_L8,
    00041         PF_L16 = 2,
    00042         PF_SHORT_L = PF_L16,
    00044         PF_A8 = 3,
    00045         PF_BYTE_A = PF_A8,
    00047         PF_A4L4 = 4,
    00049         PF_BYTE_LA = 5,
    00051         PF_R5G6B5 = 6,
    00053         PF_B5G6R5 = 7,
    00055         PF_R3G3B2 = 31,
    00057         PF_A4R4G4B4 = 8,
    00059         PF_A1R5G5B5 = 9,
    00061         PF_R8G8B8 = 10,
    00063         PF_B8G8R8 = 11,
    00065         PF_A8R8G8B8 = 12,
    00067         PF_A8B8G8R8 = 13,
    00069         PF_B8G8R8A8 = 14,
    00071         PF_R8G8B8A8 = 28,
    00074         PF_X8R8G8B8 = 26,
    00077         PF_X8B8G8R8 = 27,
    00078 #if OGRE_ENDIAN == OGRE_ENDIAN_BIG
    00079
    00080         PF_BYTE_RGB = PF_R8G8B8,
    00082         PF_BYTE_BGR = PF_B8G8R8,
    00084         PF_BYTE_BGRA = PF_B8G8R8A8,
    00086         PF_BYTE_RGBA = PF_R8G8B8A8,
    00087 #else
    00088
    00089         PF_BYTE_RGB = PF_B8G8R8,
    00091         PF_BYTE_BGR = PF_R8G8B8,
    00093         PF_BYTE_BGRA = PF_A8R8G8B8,
    00095         PF_BYTE_RGBA = PF_A8B8G8R8,
    00096 #endif
    00097
    00098         PF_A2R10G10B10 = 15,
    00100         PF_A2B10G10R10 = 16,
    00102         PF_DXT1 = 17,
    00104         PF_DXT2 = 18,
    00106         PF_DXT3 = 19,
    00108         PF_DXT4 = 20,
    00110         PF_DXT5 = 21,
    00111         // 16-bit pixel format, 16 bits (float) for red
    00112         PF_FLOAT16_R = 32,
    00113         // 48-bit pixel format, 16 bits (float) for red, 16 bits (float) for green, 16 bits (float) for blue
    00114         PF_FLOAT16_RGB = 22,
    00115         // 64-bit pixel format, 16 bits (float) for red, 16 bits (float) for green, 16 bits (float) for blue, 16 bits (float) for alpha
    00116         PF_FLOAT16_RGBA = 23,
    00117         // 16-bit pixel format, 16 bits (float) for red
    00118         PF_FLOAT32_R = 33,
    00119        // 96-bit pixel format, 32 bits (float) for red, 32 bits (float) for green, 32 bits (float) for blue
    00120         PF_FLOAT32_RGB = 24,
    00121         // 128-bit pixel format, 32 bits (float) for red, 32 bits (float) for green, 32 bits (float) for blue, 32 bits (float) for alpha
    00122         PF_FLOAT32_RGBA = 25,
    00123         // Depth texture format
    00124         PF_DEPTH = 29,
    00125         // 64-bit pixel format, 16 bits for red, green, blue and alpha
    00126         PF_SHORT_RGBA = 30,
    00127         // Number of pixel formats currently defined
    00128         PF_COUNT = 34
    00129     };
    00130
    00134     enum PixelFormatFlags {
    00135         // This format has an alpha channel
    00136         PFF_HASALPHA        = 0x00000001,
    00137         // This format is compressed. This invalidates the values in elemBytes,
    00138         // elemBits and the bit counts as these might not be fixed in a compressed format.
    00139         PFF_COMPRESSED    = 0x00000002,
    00140         // This is a floating point format
    00141         PFF_FLOAT           = 0x00000004,
    00142         // This is a depth format (for depth textures)
    00143         PFF_DEPTH           = 0x00000008,
    00144         // Format is in native endian. Generally true for the 16, 24 and 32 bits
    00145         // formats which can be represented as machine integers.
    00146         PFF_NATIVEENDIAN    = 0x00000010,
    00147         // This is an intensity format instead of a RGB one. The luminance
    00148         // replaces R,G and B. (but not A)
    00149         PFF_LUMINANCE       = 0x00000020
    00150     };
    00156     class _OgreExport PixelBox: public Box {
    00157     public:
    00159         PixelBox() {}
    00167         PixelBox(const Box &extents, PixelFormat pixelFormat, void *pixelData=0):
    00168             Box(extents), data(pixelData), format(pixelFormat)
    00169         {
    00170             setConsecutive();
    00171         }
    00181         PixelBox(size_t width, size_t height, size_t depth, PixelFormat pixelFormat, void *pixelData=0):
    00182             Box(0, 0, 0, width, height, depth),
    00183             data(pixelData), format(pixelFormat)
    00184         {
    00185             setConsecutive();
    00186         }
    00187
    00189         void *data;
    00191         PixelFormat format;
    00196         size_t rowPitch;
    00202         size_t slicePitch;
    00203
    00207         void setConsecutive()
    00208         {
    00209             rowPitch = getWidth();
    00210             slicePitch = getWidth()*getHeight();
    00211         }
    00216         size_t getRowSkip() const { return rowPitch - getWidth(); }
    00221         size_t getSliceSkip() const { return slicePitch - (getHeight() * rowPitch); }
    00222
    00226         bool isConsecutive() const
    00227         {
    00228             return rowPitch == getWidth() && slicePitch == getWidth()*getHeight();
    00229         }
    00233         size_t getConsecutiveSize() const;
    00242         PixelBox getSubVolume(const Box &def) const;
    00243     };
    00244
    00245
    00249     class _OgreExport PixelUtil {
    00250     public:
    00257         static size_t getNumElemBytes( PixelFormat format );
    00258
    00265         static size_t getNumElemBits( PixelFormat format );
    00266
    00284         static size_t getMemorySize(size_t width, size_t height, size_t depth, PixelFormat format);
    00285
    00293         static unsigned int getFlags( PixelFormat format );
    00294
    00296         static bool hasAlpha(PixelFormat format);
    00298         static bool isFloatingPoint(PixelFormat format);
    00300         static bool isCompressed(PixelFormat format);
    00302         static bool isDepth(PixelFormat format);
    00304         static bool isNativeEndian(PixelFormat format);
    00306         static bool isLuminance(PixelFormat format);
    00307
    00320         static bool isValidExtent(size_t width, size_t height, size_t depth, PixelFormat format);
    00321
    00325         static void getBitDepths(PixelFormat format, int rgba[4]);
    00326
    00330         static void getBitMasks(PixelFormat format, uint32 rgba[4]);
    00331
    00334         static String getFormatName(PixelFormat srcformat);
    00335
    00343         static bool isAccessible(PixelFormat srcformat);
    00344
    00350         static void packColour(const ColourValue &colour, const PixelFormat pf,  const void* dest);
    00356         static void packColour(const uint8 r, const uint8 g, const uint8 b, const uint8 a, const PixelFormat pf,  const void* dest);
    00364         static void packColour(const float r, const float g, const float b, const float a, const PixelFormat pf,  const void* dest);
    00365
    00371         static void unpackColour(ColourValue *colour, PixelFormat pf,  const void* src);
    00380         static void unpackColour(uint8 *r, uint8 *g, uint8 *b, uint8 *a, PixelFormat pf,  const void* src);
    00386         static void unpackColour(float *r, float *g, float *b, float *a, PixelFormat pf,  const void* src);
    00387
    00396         static void bulkPixelConversion(void *src, PixelFormat srcFormat, void *dest, PixelFormat dstFormat, unsigned int count);
    00397
    00405         static void bulkPixelConversion(const PixelBox &src, const PixelBox &dst);
    00406     };
    00407
    00408 };
    00409
    00410 #endif

Copyright © 2000-2005 by The OGRE Team
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Feb 12 12:59:50 2006