OGRE  1.9.0
OgrePixelFormat.h
Go to the documentation of this file.
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4 (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2014 Torus Knot Software Ltd
8
9Permission is hereby granted, free of charge, to any person obtaining a copy
10of this software and associated documentation files (the "Software"), to deal
11in the Software without restriction, including without limitation the rights
12to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13copies of the Software, and to permit persons to whom the Software is
14furnished to do so, subject to the following conditions:
15
16The above copyright notice and this permission notice shall be included in
17all copies or substantial portions of the Software.
18
19THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25THE 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
35namespace Ogre {
44 {
48 PF_L8 = 1,
51 PF_L16 = 2,
54 PF_A8 = 3,
88#if OGRE_ENDIAN == OGRE_ENDIAN_BIG
97#else
106#endif
127 // 32-bit pixel format, 32 bits (float) for red
226 PF_R8 = 78,
228 PF_RG8 = 79,
259 // Number of pixel formats currently defined
260 PF_COUNT = 95
261 };
263
269 PFF_HASALPHA = 0x00000001,
272 PFF_COMPRESSED = 0x00000002,
274 PFF_FLOAT = 0x00000004,
276 PFF_DEPTH = 0x00000008,
279 PFF_NATIVEENDIAN = 0x00000010,
282 PFF_LUMINANCE = 0x00000020,
284 PFF_INTEGER = 0x00000040
285 };
286
298
304 class _OgreExport PixelBox: public Box, public ImageAlloc {
305 public:
316 PixelBox(const Box &extents, PixelFormat pixelFormat, void *pixelData=0):
317 Box(extents), data(pixelData), format(pixelFormat)
318 {
319 setConsecutive();
320 }
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
338 void *data;
345 size_t rowPitch;
352
357 {
358 rowPitch = getWidth();
359 slicePitch = getWidth()*getHeight();
360 }
365 size_t getRowSkip() const { return rowPitch - getWidth(); }
370 size_t getSliceSkip() const { return slicePitch - (getHeight() * rowPitch); }
371
375 bool isConsecutive() const
376 {
377 return rowPitch == getWidth() && slicePitch == getWidth()*getHeight();
378 }
382 size_t getConsecutiveSize() const;
391 PixelBox getSubVolume(const Box &def) const;
392
397
403 ColourValue getColourAt(size_t x, size_t y, size_t z);
404
410 void setColourAt(ColourValue const &cv, size_t x, size_t y, size_t z);
411 };
412
413
418 public:
425 static size_t getNumElemBytes( PixelFormat format );
426
433 static size_t getNumElemBits( PixelFormat format );
434
452 static size_t getMemorySize(uint32 width, uint32 height, uint32 depth, PixelFormat format);
453
461 static unsigned int getFlags( PixelFormat format );
462
464 static bool hasAlpha(PixelFormat format);
466 static bool isFloatingPoint(PixelFormat format);
468 static bool isInteger(PixelFormat format);
470 static bool isCompressed(PixelFormat format);
472 static bool isDepth(PixelFormat format);
474 static bool isNativeEndian(PixelFormat format);
476 static bool isLuminance(PixelFormat format);
477
490 static bool isValidExtent(size_t width, size_t height, size_t depth, PixelFormat format);
491
495 static void getBitDepths(PixelFormat format, int rgba[4]);
496
500 static void getBitMasks(PixelFormat format, uint64 rgba[4]);
501
505 static void getBitShifts(PixelFormat format, unsigned char rgba[4]);
506
510
518 static bool isAccessible(PixelFormat srcformat);
519
525
529 static size_t getComponentCount(PixelFormat fmt);
530
538 static PixelFormat getFormatFromName(const String& name, bool accessibleOnly = false, bool caseSensitive = false);
539
547 static String getBNFExpressionOfPixelFormats(bool accessibleOnly = false);
548
558 static PixelFormat getFormatForBitDepths(PixelFormat fmt, ushort integerBits, ushort floatBits);
559
565 static void packColour(const ColourValue &colour, const PixelFormat pf, void* dest);
573 static void packColour(const uint8 r, const uint8 g, const uint8 b, const uint8 a, const PixelFormat pf, void* dest);
581 static void packColour(const float r, const float g, const float b, const float a, const PixelFormat pf, void* dest);
582
588 static void unpackColour(ColourValue *colour, PixelFormat pf, const void* src);
600 static void unpackColour(uint8 *r, uint8 *g, uint8 *b, uint8 *a, PixelFormat pf, const void* src);
609 static void unpackColour(float *r, float *g, float *b, float *a, PixelFormat pf, const void* src);
610
619 static void bulkPixelConversion(void *src, PixelFormat srcFormat, void *dst, PixelFormat dstFormat, unsigned int count);
620
628 static void bulkPixelConversion(const PixelBox &src, const PixelBox &dst);
629
634 static void bulkPixelVerticalFlip(const PixelBox &box);
635 };
639}
640
641#include "OgreHeaderSuffix.h"
642
643#endif
#define _OgreExport
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
Class representing colour.
A primitive describing a volume (3D), image (2D) or line (1D) of pixels in memory.
size_t getSliceSkip() const
Get the number of elements between one past the right bottom pixel of one slice and the left top pixe...
PixelBox()
Parameter constructor for setting the members manually.
size_t getRowSkip() const
Get the number of elements between one past the rightmost pixel of one row and the leftmost pixel of ...
PixelBox getSubVolume(const Box &def) const
Return a subvolume of this PixelBox.
void * getTopLeftFrontPixelPtr() const
Return a data pointer pointing to top left front pixel of the pixel box.
PixelBox(const Box &extents, PixelFormat pixelFormat, void *pixelData=0)
Constructor providing extents in the form of a Box object.
size_t slicePitch
Number of elements between the top left pixel of one (depth) slice and the top left pixel of the next...
void setConsecutive()
Set the rowPitch and slicePitch so that the buffer is laid out consecutive in memory.
PixelBox(uint32 width, uint32 height, uint32 depth, PixelFormat pixelFormat, void *pixelData=0)
Constructor providing width, height and depth.
PixelFormat format
The pixel format.
size_t rowPitch
Number of elements between the leftmost pixel of one row and the left pixel of the next.
size_t getConsecutiveSize() const
Return the size (in bytes) this image would take if it was laid out consecutive in memory.
bool isConsecutive() const
Return whether this buffer is laid out consecutive in memory (ie the pitches are equal to the dimensi...
void * data
The data pointer.
void setColourAt(ColourValue const &cv, size_t x, size_t y, size_t z)
Set colour value at a certain location in the PixelBox.
ColourValue getColourAt(size_t x, size_t y, size_t z)
Get colour value from a certain location in the PixelBox.
Some utility functions for packing and unpacking pixel data.
static void bulkPixelConversion(void *src, PixelFormat srcFormat, void *dst, PixelFormat dstFormat, unsigned int count)
Convert consecutive pixels from one format to another.
static bool isInteger(PixelFormat format)
Shortcut method to determine if the format is integer.
static size_t getNumElemBits(PixelFormat format)
Returns the size in bits of an element of the given pixel format.
static bool hasAlpha(PixelFormat format)
Shortcut method to determine if the format has an alpha component.
static size_t getNumElemBytes(PixelFormat format)
Returns the size in bytes of an element of the given pixel format.
static void packColour(const float r, const float g, const float b, const float a, const PixelFormat pf, void *dest)
Pack a colour value to memory.
static bool isAccessible(PixelFormat srcformat)
Returns whether the format can be packed or unpacked with the packColour() and unpackColour() functio...
static String getBNFExpressionOfPixelFormats(bool accessibleOnly=false)
Gets the BNF expression of the pixel-formats.
static void bulkPixelVerticalFlip(const PixelBox &box)
Flips pixels inplace in vertical direction.
static bool isFloatingPoint(PixelFormat format)
Shortcut method to determine if the format is floating point.
static bool isDepth(PixelFormat format)
Shortcut method to determine if the format is a depth format.
static PixelFormat getFormatFromName(const String &name, bool accessibleOnly=false, bool caseSensitive=false)
Gets the format from given name.
static void unpackColour(uint8 *r, uint8 *g, uint8 *b, uint8 *a, PixelFormat pf, const void *src)
Unpack a colour value from memory.
static void packColour(const ColourValue &colour, const PixelFormat pf, void *dest)
Pack a colour value to memory.
static bool isLuminance(PixelFormat format)
Shortcut method to determine if the format is a luminance format.
static size_t getMemorySize(uint32 width, uint32 height, uint32 depth, PixelFormat format)
Returns the size in memory of a region with the given extents and pixel format with consecutive memor...
static PixelComponentType getComponentType(PixelFormat fmt)
Returns the component type for a certain pixel format.
static void getBitDepths(PixelFormat format, int rgba[4])
Gives the number of bits (RGBA) for a format.
static void unpackColour(ColourValue *colour, PixelFormat pf, const void *src)
Unpack a colour value from memory.
static void bulkPixelConversion(const PixelBox &src, const PixelBox &dst)
Convert pixels from one format to another.
static void getBitMasks(PixelFormat format, uint64 rgba[4])
Gives the masks for the R, G, B and A component.
static bool isNativeEndian(PixelFormat format)
Shortcut method to determine if the format is in native endian format.
static bool isCompressed(PixelFormat format)
Shortcut method to determine if the format is compressed.
static bool isValidExtent(size_t width, size_t height, size_t depth, PixelFormat format)
Return whether a certain image extent is valid for this image format.
static unsigned int getFlags(PixelFormat format)
Returns the property flags for this pixel format.
static PixelFormat getFormatForBitDepths(PixelFormat fmt, ushort integerBits, ushort floatBits)
Returns the similar format but acoording with given bit depths.
static void unpackColour(float *r, float *g, float *b, float *a, PixelFormat pf, const void *src)
Unpack a colour value from memory.
static size_t getComponentCount(PixelFormat fmt)
Returns the component count for a certain pixel format.
static String getFormatName(PixelFormat srcformat)
Gets the name of an image format.
static void packColour(const uint8 r, const uint8 g, const uint8 b, const uint8 a, const PixelFormat pf, void *dest)
Pack a colour value to memory.
static void getBitShifts(PixelFormat format, unsigned char rgba[4])
Gives the bit shifts for R, G, B and A component.
vector< PixelFormat >::type PixelFormatList
PixelFormatFlags
Flags defining some on/off properties of pixel formats.
PixelFormat
The pixel format used for images, textures, and render surfaces.
PixelComponentType
Pixel component format.
@ PFF_LUMINANCE
This is an intensity format instead of a RGB one.
@ PFF_NATIVEENDIAN
Format is in native endian.
@ PFF_FLOAT
This is a floating point format.
@ PFF_DEPTH
This is a depth format (for depth textures)
@ PFF_HASALPHA
This format has an alpha channel.
@ PFF_INTEGER
This is an integer format.
@ PFF_COMPRESSED
This format is compressed.
@ PF_R3G3B2
8-bit pixel format, 2 bits blue, 3 bits green, 3 bits red.
@ PF_ATC_RGBA_INTERPOLATED_ALPHA
ATC (AMD_compressed_ATC_texture)
@ PF_SHORT_RGBA
64-bit pixel format, 16 bits for red, green, blue and alpha
@ PF_A8R8G8B8
32-bit pixel format, 8 bits for alpha, red, green and blue.
@ PF_R16G16_SINT
32-bit pixel format, 16 bits red (signed int), 16 bits blue (signed int).
@ PF_FLOAT32_GR
64-bit, 2-channel floating point pixel format, 32-bit green, 32-bit red
@ PF_A2R10G10B10
32-bit pixel format, 2 bits for alpha, 10 bits for red, green and blue.
@ PF_PVRTC_RGB4
PVRTC (PowerVR) RGB 4 bpp.
@ PF_R32G32B32_UINT
96-bit pixel format, 32 bits red (unsigned int), 32 bits blue (unsigned int), 32 bits green (unsigned...
@ PF_FLOAT32_RGBA
128-bit pixel format, 32 bits (float) for red, 32 bits (float) for green, 32 bits (float) for blue,...
@ PF_X8R8G8B8
32-bit pixel format, 8 bits for red, 8 bits for green, 8 bits for blue like PF_A8R8G8B8,...
@ PF_R16G16B16_SINT
48-bit pixel format, 16 bits red (signed int), 16 bits blue (signed int), 16 bits green (signed int).
@ PF_ETC2_RGB8A1
ETC2 (Ericsson Texture Compression)
@ PF_R8G8B8_SNORM
24-bit pixel format, 8 bits red (signed normalised int), 8 bits blue (signed normalised int),...
@ PF_BC7_UNORM
DDS (DirectDraw Surface) BC7 format (unsigned normalised)
@ PF_R32_SINT
32-bit pixel format, 32 bits red (signed int).
@ PF_X8B8G8R8
32-bit pixel format, 8 bits for blue, 8 bits for green, 8 bits for red like PF_A8B8G8R8,...
@ PF_R8G8B8
24-bit pixel format, 8 bits for red, green and blue.
@ PF_R16G16B16_UINT
48-bit pixel format, 16 bits red (unsigned int), 16 bits blue (unsigned int), 16 bits green (unsigned...
@ PF_L8
8-bit pixel format, all bits luminance.
@ PF_A2B10G10R10
32-bit pixel format, 10 bits for blue, green and red, 2 bits for alpha.
@ PF_R32G32B32A32_UINT
128-bit pixel format, 32 bits red (unsigned int), 32 bits blue (unsigned int), 32 bits green (unsigne...
@ PF_R16G16B16A16_UINT
64-bit pixel format, 16 bits red (unsigned int), 16 bits blue (unsigned int), 16 bits green (unsigned...
@ PF_R16_SINT
16-bit pixel format, 16 bits red (signed int).
@ PF_R8G8B8A8_SNORM
32-bit pixel format, 8 bits red (signed normalised int), 8 bits blue (signed normalised int),...
@ PF_R11G11B10_FLOAT
32-bit pixel format, 11 bits (float) for red, 11 bits (float) for green, 10 bits (float) for blue
@ PF_R16G16_SNORM
32-bit pixel format, 16 bits red (signed normalised int), 16 bits blue (signed normalised int).
@ PF_DXT1
DDS (DirectDraw Surface) DXT1 format.
@ PF_ATC_RGB
ATC (AMD_compressed_ATC_texture)
@ PF_ETC1_RGB8
ETC1 (Ericsson Texture Compression)
@ PF_ETC2_RGBA8
ETC2 (Ericsson Texture Compression)
@ PF_R8G8B8A8_UINT
32-bit pixel format, 8 bits red (unsigned int), 8 bits blue (unsigned int), 8 bits green (unsigned in...
@ PF_PVRTC_RGBA2
PVRTC (PowerVR) RGBA 2 bpp.
@ PF_BC6H_UF16
DDS (DirectDraw Surface) BC6H format (unsigned 16 bit float)
@ PF_BYTE_BGR
3 byte pixel format, 1 byte for blue, 1 byte for green, 1 byte for red
@ PF_R8G8B8_UINT
24-bit pixel format, 8 bits red (unsigned int), 8 bits blue (unsigned int), 8 bits green (unsigned in...
@ PF_B8G8R8
24-bit pixel format, 8 bits for blue, green and red.
@ PF_R8G8_UINT
16-bit pixel format, 8 bits red (unsigned int), 8 bits blue (unsigned int).
@ PF_A4L4
8-bit pixel format, 4 bits alpha, 4 bits luminance.
@ PF_BC6H_SF16
DDS (DirectDraw Surface) BC6H format (signed 16 bit float)
@ PF_A8
8-bit pixel format, all bits alpha.
@ PF_SHORT_RGB
48-bit pixel format, 16 bits for red, green and blue
@ PF_R8G8_SNORM
16-bit pixel format, 8 bits red (signed normalised int), 8 bits blue (signed normalised int).
@ PF_R8G8B8A8
32-bit pixel format, 8 bits for red, green, blue and alpha.
@ PF_R32G32B32_SINT
96-bit pixel format, 32 bits red (signed int), 32 bits blue (signed int), 32 bits green (signed int).
@ PF_A4R4G4B4
16-bit pixel format, 4 bits for alpha, red, green and blue.
@ PF_SHORT_GR
32-bit pixel format, 16-bit green, 16-bit red
@ PF_BYTE_BGRA
4 byte pixel format, 1 byte for blue, 1 byte for green, 1 byte for red and one byte for alpha
@ PF_BC5_UNORM
DDS (DirectDraw Surface) BC5 format (unsigned normalised)
@ PF_R16_SNORM
16-bit pixel format, 16 bits red (signed normalised int).
@ PF_ETC2_RGB8
ETC2 (Ericsson Texture Compression)
@ PF_FLOAT32_RGB
96-bit pixel format, 32 bits (float) for red, 32 bits (float) for green, 32 bits (float) for blue
@ PF_R5G6B5
16-bit pixel format, 5 bits red, 6 bits green, 5 bits blue.
@ PF_DXT3
DDS (DirectDraw Surface) DXT3 format.
@ PF_DXT4
DDS (DirectDraw Surface) DXT4 format.
@ PF_BC7_UNORM_SRGB
DDS (DirectDraw Surface) BC7 format (unsigned normalised sRGB)
@ PF_R16G16B16A16_SNORM
64-bit pixel format, 16 bits red (signed normalised int), 16 bits blue (signed normalised int),...
@ PF_A1R5G5B5
16-bit pixel format, 5 bits for blue, green, red and 1 for alpha.
@ PF_BC5_SNORM
DDS (DirectDraw Surface) BC5 format (signed normalised)
@ PF_PVRTC_RGBA4
PVRTC (PowerVR) RGBA 4 bpp.
@ PF_DXT5
DDS (DirectDraw Surface) DXT5 format.
@ PF_BYTE_RGB
3 byte pixel format, 1 byte for red, 1 byte for green, 1 byte for blue
@ PF_R16G16B16_SNORM
48-bit pixel format, 16 bits red (signed normalised int), 16 bits blue (signed normalised int),...
@ PF_UNKNOWN
Unknown pixel format.
@ PF_R32G32_UINT
64-bit pixel format, 32 bits red (unsigned int), 32 bits blue (unsigned int).
@ PF_R8G8B8A8_SINT
32-bit pixel format, 8 bits red (signed int), 8 bits blue (signed int), 8 bits green (signed int),...
@ PF_R16_UINT
16-bit pixel format, 16 bits red (unsigned int).
@ PF_DEPTH
Depth texture format.
@ PF_BC4_UNORM
DDS (DirectDraw Surface) BC4 format (unsigned normalised)
@ PF_R8_SINT
8-bit pixel format, 8 bits red (signed int).
@ PF_L16
16-bit pixel format, all bits luminance.
@ PF_ATC_RGBA_EXPLICIT_ALPHA
ATC (AMD_compressed_ATC_texture)
@ PF_FLOAT16_R
16-bit pixel format, 16 bits (float) for red
@ PF_R32G32B32A32_SINT
128-bit pixel format, 32 bits red (signed int), 32 bits blue (signed int), 32 bits green (signed int)...
@ PF_FLOAT16_RGB
48-bit pixel format, 16 bits (float) for red, 16 bits (float) for green, 16 bits (float) for blue
@ PF_DXT2
DDS (DirectDraw Surface) DXT2 format.
@ PF_R32G32_SINT
64-bit pixel format, 32 bits red (signed int), 32 bits blue (signed int).
@ PF_B8G8R8A8
32-bit pixel format, 8 bits for blue, green, red and alpha.
@ PF_A8B8G8R8
32-bit pixel format, 8 bits for blue, green, red and alpha.
@ PF_R32_UINT
32-bit pixel format, 32 bits red (unsigned int).
@ PF_BYTE_LA
2 byte pixel format, 1 byte luminance, 1 byte alpha
@ PF_FLOAT16_GR
32-bit, 2-channel s10e5 floating point pixel format, 16-bit green, 16-bit red
@ PF_R8
8-bit pixel format, all bits red.
@ PF_PVRTC2_2BPP
PVRTC (PowerVR) Version 2, 2 bpp.
@ PF_R16G16_UINT
32-bit pixel format, 16 bits red (unsigned int), 16 bits blue (unsigned int).
@ PF_PVRTC2_4BPP
PVRTC (PowerVR) Version 2, 4 bpp.
@ PF_PVRTC_RGB2
PVRTC (PowerVR) RGB 2 bpp.
@ PF_BC4_SNORM
DDS (DirectDraw Surface) BC4 format (signed normalised)
@ PF_R8G8_SINT
16-bit pixel format, 8 bits red (signed int), 8 bits blue (signed int).
@ PF_BYTE_RGBA
4 byte pixel format, 1 byte for red, 1 byte for green, 1 byte for blue, and one byte for alpha
@ PF_R16G16B16A16_SINT
64-bit pixel format, 16 bits red (signed int), 16 bits blue (signed int), 16 bits green (signed int),...
@ PF_R8_UINT
8-bit pixel format, 8 bits red (unsigned int).
@ PF_R9G9B9E5_SHAREDEXP
32-bit pixel format, 9 bits for blue, green, red plus a 5 bit exponent.
@ PF_R8_SNORM
8-bit pixel format, 8 bits red (signed normalised int).
@ PF_FLOAT16_RGBA
64-bit pixel format, 16 bits (float) for red, 16 bits (float) for green, 16 bits (float) for blue,...
@ PF_RG8
16-bit pixel format, 8 bits red, 8 bits green.
@ PF_R8G8B8_SINT
24-bit pixel format, 8 bits red (signed int), 8 bits blue (signed int), 8 bits green (signed int).
@ PF_B5G6R5
16-bit pixel format, 5 bits red, 6 bits green, 5 bits blue.
@ PCT_FLOAT16
Short per component (16 bit fixed 0.0..1.0))
@ PCT_FLOAT32
16 bit float per component
@ PCT_SINT
32 bit float per component
@ PCT_SHORT
Byte per component (8 bit fixed 0.0..1.0)
@ PCT_UINT
Signed integer per component.
@ PCT_COUNT
Unsigned integer per component.
unsigned char uint8
unsigned long long uint64
unsigned int uint32
_StringBase String
unsigned short ushort
Structure used to define a box in a 3-D integer space.
Definition OgreCommon.h:660
std::vector< T, A > type