OGRE  1.8
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgrePixelFormat.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4  (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2013 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE 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 
35 namespace Ogre {
44  {
48  PF_L8 = 1,
51  PF_L16 = 2,
54  PF_A8 = 3,
57  PF_A4L4 = 4,
61  PF_R5G6B5 = 6,
63  PF_B5G6R5 = 7,
65  PF_R3G3B2 = 31,
71  PF_R8G8B8 = 10,
73  PF_B8G8R8 = 11,
88 #if OGRE_ENDIAN == OGRE_ENDIAN_BIG
97 #else
101  PF_BYTE_BGR = PF_R8G8B8,
103  PF_BYTE_BGRA = PF_A8R8G8B8,
105  PF_BYTE_RGBA = PF_A8B8G8R8,
106 #endif
107  PF_A2R10G10B10 = 15,
112  PF_DXT1 = 17,
114  PF_DXT2 = 18,
116  PF_DXT3 = 19,
118  PF_DXT4 = 20,
120  PF_DXT5 = 21,
121  // 16-bit pixel format, 16 bits (float) for red
123  // 48-bit pixel format, 16 bits (float) for red, 16 bits (float) for green, 16 bits (float) for blue
125  // 64-bit pixel format, 16 bits (float) for red, 16 bits (float) for green, 16 bits (float) for blue, 16 bits (float) for alpha
127  // 32-bit pixel format, 32 bits (float) for red
129  // 96-bit pixel format, 32 bits (float) for red, 32 bits (float) for green, 32 bits (float) for blue
131  // 128-bit pixel format, 32 bits (float) for red, 32 bits (float) for green, 32 bits (float) for blue, 32 bits (float) for alpha
133  // 32-bit, 2-channel s10e5 floating point pixel format, 16-bit green, 16-bit red
135  // 64-bit, 2-channel floating point pixel format, 32-bit green, 32-bit red
137  // Depth texture format
138  PF_DEPTH = 29,
139  // 64-bit pixel format, 16 bits for red, green, blue and alpha
141  // 32-bit pixel format, 16-bit green, 16-bit red
143  // 48-bit pixel format, 16 bits for red, green and blue
154  PF_R8 = 42,
156  PF_RG8 = 43,
157  // Number of pixel formats currently defined
158  PF_COUNT = 44
159  };
161 
166  // This format has an alpha channel
167  PFF_HASALPHA = 0x00000001,
168  // This format is compressed. This invalidates the values in elemBytes,
169  // elemBits and the bit counts as these might not be fixed in a compressed format.
170  PFF_COMPRESSED = 0x00000002,
171  // This is a floating point format
172  PFF_FLOAT = 0x00000004,
173  // This is a depth format (for depth textures)
174  PFF_DEPTH = 0x00000008,
175  // Format is in native endian. Generally true for the 16, 24 and 32 bits
176  // formats which can be represented as machine integers.
177  PFF_NATIVEENDIAN = 0x00000010,
178  // This is an intensity format instead of a RGB one. The luminance
179  // replaces R,G and B. (but not A)
180  PFF_LUMINANCE = 0x00000020
181  };
182 
185  {
186  PCT_BYTE = 0,
187  PCT_SHORT = 1,
191  };
192 
198  class _OgreExport PixelBox: public Box, public ImageAlloc {
199  public:
201  PixelBox() {}
210  PixelBox(const Box &extents, PixelFormat pixelFormat, void *pixelData=0):
211  Box(extents), data(pixelData), format(pixelFormat)
212  {
213  setConsecutive();
214  }
224  PixelBox(size_t width, size_t height, size_t depth, PixelFormat pixelFormat, void *pixelData=0):
225  Box(0, 0, 0, width, height, depth),
226  data(pixelData), format(pixelFormat)
227  {
228  setConsecutive();
229  }
230 
232  void *data;
239  size_t rowPitch;
245  size_t slicePitch;
246 
251  {
252  rowPitch = getWidth();
253  slicePitch = getWidth()*getHeight();
254  }
259  size_t getRowSkip() const { return rowPitch - getWidth(); }
264  size_t getSliceSkip() const { return slicePitch - (getHeight() * rowPitch); }
265 
269  bool isConsecutive() const
270  {
271  return rowPitch == getWidth() && slicePitch == getWidth()*getHeight();
272  }
276  size_t getConsecutiveSize() const;
285  PixelBox getSubVolume(const Box &def) const;
286 
292  ColourValue getColourAt(size_t x, size_t y, size_t z);
293 
299  void setColourAt(ColourValue const &cv, size_t x, size_t y, size_t z);
300  };
301 
302 
307  public:
314  static size_t getNumElemBytes( PixelFormat format );
315 
322  static size_t getNumElemBits( PixelFormat format );
323 
341  static size_t getMemorySize(size_t width, size_t height, size_t depth, PixelFormat format);
342 
350  static unsigned int getFlags( PixelFormat format );
351 
353  static bool hasAlpha(PixelFormat format);
355  static bool isFloatingPoint(PixelFormat format);
357  static bool isCompressed(PixelFormat format);
359  static bool isDepth(PixelFormat format);
361  static bool isNativeEndian(PixelFormat format);
363  static bool isLuminance(PixelFormat format);
364 
377  static bool isValidExtent(size_t width, size_t height, size_t depth, PixelFormat format);
378 
382  static void getBitDepths(PixelFormat format, int rgba[4]);
383 
387  static void getBitMasks(PixelFormat format, uint32 rgba[4]);
388 
392  static void getBitShifts(PixelFormat format, unsigned char rgba[4]);
393 
396  static String getFormatName(PixelFormat srcformat);
397 
405  static bool isAccessible(PixelFormat srcformat);
406 
411  static PixelComponentType getComponentType(PixelFormat fmt);
412 
416  static size_t getComponentCount(PixelFormat fmt);
417 
425  static PixelFormat getFormatFromName(const String& name, bool accessibleOnly = false, bool caseSensitive = false);
426 
434  static String getBNFExpressionOfPixelFormats(bool accessibleOnly = false);
435 
445  static PixelFormat getFormatForBitDepths(PixelFormat fmt, ushort integerBits, ushort floatBits);
446 
452  static void packColour(const ColourValue &colour, const PixelFormat pf, void* dest);
458  static void packColour(const uint8 r, const uint8 g, const uint8 b, const uint8 a, const PixelFormat pf, void* dest);
466  static void packColour(const float r, const float g, const float b, const float a, const PixelFormat pf, void* dest);
467 
473  static void unpackColour(ColourValue *colour, PixelFormat pf, const void* src);
482  static void unpackColour(uint8 *r, uint8 *g, uint8 *b, uint8 *a, PixelFormat pf, const void* src);
488  static void unpackColour(float *r, float *g, float *b, float *a, PixelFormat pf, const void* src);
489 
498  static void bulkPixelConversion(void *src, PixelFormat srcFormat, void *dest, PixelFormat dstFormat, unsigned int count);
499 
507  static void bulkPixelConversion(const PixelBox &src, const PixelBox &dst);
508  };
512 }
513 
514 #include "OgreHeaderSuffix.h"
515 
516 #endif
unsigned char uint8
Definition: OgrePlatform.h:272
16-bit pixel format, 5 bits red, 6 bits green, 5 bits blue.
Short per component (16 bit fixed 0.0..1.0))
unsigned int uint32
Definition: OgrePlatform.h:270
#define _OgreExport
Definition: OgrePlatform.h:233
8-bit pixel format, 4 bits alpha, 4 bits luminance.
size_t rowPitch
Number of elements between the leftmost pixel of one row and the left pixel of the next...
32-bit pixel format, 8 bits for alpha, red, green and blue.
16-bit pixel format, 8 bits red, 8 bits green.
Class representing colour.
DDS (DirectDraw Surface) DXT5 format.
size_t getSliceSkip() const
Get the number of elements between one past the right bottom pixel of one slice and the left top pixe...
PixelFormatFlags
Flags defining some on/off properties of pixel formats.
3 byte pixel format, 1 byte for blue, 1 byte for green, 1 byte for red
PVRTC (PowerVR) RGBA 4 bpp.
32-bit pixel format, 8 bits for blue, green, red and alpha.
void * data
The data pointer.
PVRTC (PowerVR) RGBA 2 bpp.
Byte per component (8 bit fixed 0.0..1.0)
Some utility functions for packing and unpacking pixel data.
Unknown pixel format.
32-bit pixel format, 8 bits for red, green, blue and alpha.
DDS (DirectDraw Surface) DXT3 format.
PixelFormat format
The pixel format.
PixelComponentType
Pixel component format.
4 byte pixel format, 1 byte for red, 1 byte for green, 1 byte for blue, and one byte for alpha ...
16 bit float per component
24-bit pixel format, 8 bits for blue, green and red.
DDS (DirectDraw Surface) DXT1 format.
Structure used to define a box in a 3-D integer space.
Definition: OgreCommon.h:662
3 byte pixel format, 1 byte for red, 1 byte for green, 1 byte for blue
PVRTC (PowerVR) RGB 2 bpp.
32-bit pixel format, 10 bits for blue, green and red, 2 bits for alpha.
32-bit pixel format, 8 bits for blue, green, red and alpha.
DDS (DirectDraw Surface) DXT2 format.
8-bit pixel format, all bits luminance.
16-bit pixel format, 5 bits red, 6 bits green, 5 bits blue.
PixelFormat
The pixel format used for images, textures, and render surfaces.
32-bit pixel format, 8 bits for red, 8 bits for green, 8 bits for blue like PF_A8R8G8B8, but alpha will get discarded
PixelBox()
Parameter constructor for setting the members manually.
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
16-bit pixel format, 4 bits for alpha, red, green and blue.
size_t slicePitch
Number of elements between the top left pixel of one (depth) slice and the top left pixel of the next...
16-bit pixel format, 5 bits for blue, green, red and 1 for alpha.
PixelBox(size_t width, size_t height, size_t depth, PixelFormat pixelFormat, void *pixelData=0)
Constructor providing width, height and depth.
4 byte pixel format, 1 byte for blue, 1 byte for green, 1 byte for red and one byte for alpha ...
vector< PixelFormat >::type PixelFormatList
unsigned short ushort
32-bit pixel format, 2 bits for alpha, 10 bits for red, green and blue.
DDS (DirectDraw Surface) DXT4 format.
8-bit pixel format, all bits alpha.
24-bit pixel format, 8 bits for red, green and blue.
8-bit pixel format, all bits red.
bool isConsecutive() const
Return whether this buffer is laid out consecutive in memory (ie the pitches are equal to the dimensi...
32 bit float per component
16-bit pixel format, all bits luminance.
_StringBase String
PixelBox(const Box &extents, PixelFormat pixelFormat, void *pixelData=0)
Constructor providing extents in the form of a Box object.
void setConsecutive()
Set the rowPitch and slicePitch so that the buffer is laid out consecutive in memory.
32-bit pixel format, 8 bits for blue, 8 bits for green, 8 bits for red like PF_A8B8G8R8, but alpha will get discarded
A primitive describing a volume (3D), image (2D) or line (1D) of pixels in memory.
8-bit pixel format, 2 bits blue, 3 bits green, 3 bits red.
size_t getRowSkip() const
Get the number of elements between one past the rightmost pixel of one row and the leftmost pixel of ...
2 byte pixel format, 1 byte luminance, 1 byte alpha
PVRTC (PowerVR) RGB 4 bpp.