OGRE: OgrePixelFormat.h Source File - OGRE Documentation

# 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-2006 Torus Knot Software Ltd
    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 You may alternatively use this source under the terms of a specific version of
    00025 the OGRE Unrestricted License provided you have obtained such a license from
    00026 Torus Knot Software Ltd.
    00027 -----------------------------------------------------------------------------
    00028 */
    00029 #ifndef _PixelFormat_H__
    00030 #define _PixelFormat_H__
    00031
    00032 #include "OgrePrerequisites.h"
    00033 #include "OgreCommon.h"
    00034
    00035 namespace Ogre {
    00037     enum PixelFormat
    00038     {
    00040         PF_UNKNOWN = 0,
    00042         PF_L8 = 1,
    00043         PF_BYTE_L = PF_L8,
    00045         PF_L16 = 2,
    00046         PF_SHORT_L = PF_L16,
    00048         PF_A8 = 3,
    00049         PF_BYTE_A = PF_A8,
    00051         PF_A4L4 = 4,
    00053         PF_BYTE_LA = 5,
    00055         PF_R5G6B5 = 6,
    00057         PF_B5G6R5 = 7,
    00059         PF_R3G3B2 = 31,
    00061         PF_A4R4G4B4 = 8,
    00063         PF_A1R5G5B5 = 9,
    00065         PF_R8G8B8 = 10,
    00067         PF_B8G8R8 = 11,
    00069         PF_A8R8G8B8 = 12,
    00071         PF_A8B8G8R8 = 13,
    00073         PF_B8G8R8A8 = 14,
    00075         PF_R8G8B8A8 = 28,
    00078         PF_X8R8G8B8 = 26,
    00081         PF_X8B8G8R8 = 27,
    00082 #if OGRE_ENDIAN == OGRE_ENDIAN_BIG
    00084         PF_BYTE_RGB = PF_R8G8B8,
    00086         PF_BYTE_BGR = PF_B8G8R8,
    00088         PF_BYTE_BGRA = PF_B8G8R8A8,
    00090         PF_BYTE_RGBA = PF_R8G8B8A8,
    00091 #else
    00093         PF_BYTE_RGB = PF_B8G8R8,
    00095         PF_BYTE_BGR = PF_R8G8B8,
    00097         PF_BYTE_BGRA = PF_A8R8G8B8,
    00099         PF_BYTE_RGBA = PF_A8B8G8R8,
    00100 #endif
    00102         PF_A2R10G10B10 = 15,
    00104         PF_A2B10G10R10 = 16,
    00106         PF_DXT1 = 17,
    00108         PF_DXT2 = 18,
    00110         PF_DXT3 = 19,
    00112         PF_DXT4 = 20,
    00114         PF_DXT5 = 21,
    00115         // 16-bit pixel format, 16 bits (float) for red
    00116         PF_FLOAT16_R = 32,
    00117         // 48-bit pixel format, 16 bits (float) for red, 16 bits (float) for green, 16 bits (float) for blue
    00118         PF_FLOAT16_RGB = 22,
    00119         // 64-bit pixel format, 16 bits (float) for red, 16 bits (float) for green, 16 bits (float) for blue, 16 bits (float) for alpha
    00120         PF_FLOAT16_RGBA = 23,
    00121         // 16-bit pixel format, 16 bits (float) for red
    00122         PF_FLOAT32_R = 33,
    00123        // 96-bit pixel format, 32 bits (float) for red, 32 bits (float) for green, 32 bits (float) for blue
    00124         PF_FLOAT32_RGB = 24,
    00125         // 128-bit pixel format, 32 bits (float) for red, 32 bits (float) for green, 32 bits (float) for blue, 32 bits (float) for alpha
    00126         PF_FLOAT32_RGBA = 25,
    00127         // 32-bit, 2-channel s10e5 floating point pixel format, 16-bit green, 16-bit red
    00128         PF_FLOAT16_GR = 35,
    00129         // 64-bit, 2-channel floating point pixel format, 32-bit green, 32-bit red
    00130         PF_FLOAT32_GR = 36,
    00131         // Depth texture format
    00132         PF_DEPTH = 29,
    00133         // 64-bit pixel format, 16 bits for red, green, blue and alpha
    00134         PF_SHORT_RGBA = 30,
    00135         // 32-bit pixel format, 16-bit green, 16-bit red
    00136         PF_SHORT_GR = 34,
    00137         // 48-bit pixel format, 16 bits for red, green and blue
    00138         PF_SHORT_RGB = 37,
    00139         // Number of pixel formats currently defined
    00140         PF_COUNT = 38
    00141     };
    00142     typedef std::vector<PixelFormat> PixelFormatList;
    00143
    00147     enum PixelFormatFlags {
    00148         // This format has an alpha channel
    00149         PFF_HASALPHA        = 0x00000001,
    00150         // This format is compressed. This invalidates the values in elemBytes,
    00151         // elemBits and the bit counts as these might not be fixed in a compressed format.
    00152         PFF_COMPRESSED    = 0x00000002,
    00153         // This is a floating point format
    00154         PFF_FLOAT           = 0x00000004,
    00155         // This is a depth format (for depth textures)
    00156         PFF_DEPTH           = 0x00000008,
    00157         // Format is in native endian. Generally true for the 16, 24 and 32 bits
    00158         // formats which can be represented as machine integers.
    00159         PFF_NATIVEENDIAN    = 0x00000010,
    00160         // This is an intensity format instead of a RGB one. The luminance
    00161         // replaces R,G and B. (but not A)
    00162         PFF_LUMINANCE       = 0x00000020
    00163     };
    00164
    00166     enum PixelComponentType
    00167     {
    00168         PCT_BYTE = 0,
    00169         PCT_SHORT = 1,
    00170         PCT_FLOAT16 = 2,
    00171         PCT_FLOAT32 = 3,
    00172         PCT_COUNT = 4
    00173     };
    00174
    00180     class _OgreExport PixelBox: public Box {
    00181     public:
    00183         PixelBox() {}
    00191         PixelBox(const Box &extents, PixelFormat pixelFormat, void *pixelData=0):
    00192             Box(extents), data(pixelData), format(pixelFormat)
    00193         {
    00194             setConsecutive();
    00195         }
    00205         PixelBox(size_t width, size_t height, size_t depth, PixelFormat pixelFormat, void *pixelData=0):
    00206             Box(0, 0, 0, width, height, depth),
    00207             data(pixelData), format(pixelFormat)
    00208         {
    00209             setConsecutive();
    00210         }
    00211
    00213         void *data;
    00215         PixelFormat format;
    00220         size_t rowPitch;
    00226         size_t slicePitch;
    00227
    00231         void setConsecutive()
    00232         {
    00233             rowPitch = getWidth();
    00234             slicePitch = getWidth()*getHeight();
    00235         }
    00240         size_t getRowSkip() const { return rowPitch - getWidth(); }
    00245         size_t getSliceSkip() const { return slicePitch - (getHeight() * rowPitch); }
    00246
    00250         bool isConsecutive() const
    00251         {
    00252             return rowPitch == getWidth() && slicePitch == getWidth()*getHeight();
    00253         }
    00257         size_t getConsecutiveSize() const;
    00266         PixelBox getSubVolume(const Box &def) const;
    00267     };
    00268
    00269
    00273     class _OgreExport PixelUtil {
    00274     public:
    00281         static size_t getNumElemBytes( PixelFormat format );
    00282
    00289         static size_t getNumElemBits( PixelFormat format );
    00290
    00308         static size_t getMemorySize(size_t width, size_t height, size_t depth, PixelFormat format);
    00309
    00317         static unsigned int getFlags( PixelFormat format );
    00318
    00320         static bool hasAlpha(PixelFormat format);
    00322         static bool isFloatingPoint(PixelFormat format);
    00324         static bool isCompressed(PixelFormat format);
    00326         static bool isDepth(PixelFormat format);
    00328         static bool isNativeEndian(PixelFormat format);
    00330         static bool isLuminance(PixelFormat format);
    00331
    00344         static bool isValidExtent(size_t width, size_t height, size_t depth, PixelFormat format);
    00345
    00349         static void getBitDepths(PixelFormat format, int rgba[4]);
    00350
    00354         static void getBitMasks(PixelFormat format, uint32 rgba[4]);
    00355
    00358         static String getFormatName(PixelFormat srcformat);
    00359
    00367         static bool isAccessible(PixelFormat srcformat);
    00368
    00373         static PixelComponentType getComponentType(PixelFormat fmt);
    00374
    00378         static size_t getComponentCount(PixelFormat fmt);
    00379
    00387         static PixelFormat getFormatFromName(const String& name, bool accessibleOnly = false, bool caseSensitive = false);
    00388
    00396         static String getBNFExpressionOfPixelFormats(bool accessibleOnly = false);
    00397
    00407         static PixelFormat getFormatForBitDepths(PixelFormat fmt, ushort integerBits, ushort floatBits);
    00408
    00414         static void packColour(const ColourValue &colour, const PixelFormat pf,  void* dest);
    00420         static void packColour(const uint8 r, const uint8 g, const uint8 b, const uint8 a, const PixelFormat pf,  void* dest);
    00428         static void packColour(const float r, const float g, const float b, const float a, const PixelFormat pf,  void* dest);
    00429
    00435         static void unpackColour(ColourValue *colour, PixelFormat pf,  const void* src);
    00444         static void unpackColour(uint8 *r, uint8 *g, uint8 *b, uint8 *a, PixelFormat pf,  const void* src);
    00450         static void unpackColour(float *r, float *g, float *b, float *a, PixelFormat pf,  const void* src);
    00451
    00460         static void bulkPixelConversion(void *src, PixelFormat srcFormat, void *dest, PixelFormat dstFormat, unsigned int count);
    00461
    00469         static void bulkPixelConversion(const PixelBox &src, const PixelBox &dst);
    00470     };
    00471
    00472 }
    00473
    00474 #endif

Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Jul 26 11:32:19 2009