Loading...
Searching...
No Matches
Ogre::PixelUtil Class Reference
Core » Image

Some utility functions for packing and unpacking pixel data. More...

`#include <OgrePixelFormat.h>`

## Static Public Member Functions

static void | bulkPixelConversion (const PixelBox &src, const PixelBox &dst)
| Convert pixels from one format to another.
static void | bulkPixelConversion (void *src, PixelFormat srcFormat, void *dst, PixelFormat dstFormat, unsigned int count)
| Convert consecutive pixels from one format to another.
static void | bulkPixelVerticalFlip (const PixelBox &box)
| Flips pixels inplace in vertical direction.
static void | getBitDepths (PixelFormat format, int rgba[4])
| Gives the number of bits (RGBA) for a format.
static void | getBitMasks (PixelFormat format, uint64 rgba[4])
| Gives the masks for the R, G, B and A component.
static void | getBitShifts (PixelFormat format, unsigned char rgba[4])
| Gives the bit shifts for R, G, B and A component.
static uint8 | getComponentCount (PixelFormat fmt)
| Returns the component count for a certain pixel format.
static PixelComponentType | getComponentType (PixelFormat fmt)
| Returns the component type for a certain pixel 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 according with given bit depths.
static PixelFormat | getFormatFromName (const String &name, bool accessibleOnly=false, bool caseSensitive=false)
| Gets the format from given name.
static const String & | getFormatName (PixelFormat srcformat)
| Gets the name of an image 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 memory layout.
static uint8 | getNumElemBits (PixelFormat format)
| Returns the size in bits of an element of the given pixel format.
static uint8 | getNumElemBytes (PixelFormat format)
| Returns the size in bytes 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 bool | isAccessible (PixelFormat srcformat)
| Returns whether the format can be packed or unpacked with the packColour() and unpackColour() functions.
static bool | isCompressed (PixelFormat format)
| Shortcut method to determine if the format is compressed.
static bool | isDepth (PixelFormat format)
| Shortcut method to determine if the format is a depth format.
static bool | isFloatingPoint (PixelFormat format)
| Shortcut method to determine if the format is floating point.
static bool | isInteger (PixelFormat format)
| Shortcut method to determine if the format is integer.
static bool | isLuminance (PixelFormat format)
| Shortcut method to determine if the format is a luminance format.
static bool | isNativeEndian (PixelFormat format)
| Shortcut method to determine if the format is in native endian format.
static void | packColour (const ColourValue &colour, const PixelFormat pf, void *dest)
| Pack a colour value to memory.
static void | packColour (const float r, const float g, const float b, const float a, const PixelFormat pf, void *dest)
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
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 | unpackColour (ColourValue &colour, PixelFormat pf, const void *src)
| Unpack a colour value from memory.
static void | unpackColour (ColourValue *colour, PixelFormat pf, const void *src)
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
static void | unpackColour (float *r, float *g, float *b, float *a, PixelFormat pf, const void *src)
| Unpack a colour value from memory.
static void | unpackColour (uint8 *r, uint8 *g, uint8 *b, uint8 *a, PixelFormat pf, const void *src)
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

## Detailed Description

Some utility functions for packing and unpacking pixel data.

## Member Function Documentation

## getNumElemBytes()

uint8 Ogre::PixelUtil::getNumElemBytes | ( | PixelFormat | format | ) |

static

Returns the size in bytes of an element of the given pixel format.

Returns
  The size in bytes of an element. See Remarks.

Passing PF_UNKNOWN will result in returning a size of 0 bytes.

Referenced by Python.Numpy::view().

## getNumElemBits()

uint8 Ogre::PixelUtil::getNumElemBits | ( | PixelFormat | format | ) |

static

Returns the size in bits of an element of the given pixel format.

Returns
  The size in bits of an element. See Remarks.

Passing PF_UNKNOWN will result in returning a size of 0 bits.

## getMemorySize()

size_t Ogre::PixelUtil::getMemorySize | ( | uint32 | width,
|  | uint32 | height,
|  | uint32 | depth,
|  | PixelFormat | format )

static

Returns the size in memory of a region with the given extents and pixel format with consecutive memory layout.

Parameters

  width | The width of the area
  height | The height of the area
  depth | The depth of the area
  format | The format of the area

Returns
  The size in bytes

In case that the format is non-compressed, this simply returns width * height * depth * PixelUtil::getNumElemBytes(format). In the compressed case, this does serious magic.

## getFlags()

unsigned int Ogre::PixelUtil::getFlags | ( | PixelFormat | format | ) |

static

Returns the property flags for this pixel format.

Returns
  A bitfield combination of PFF_HASALPHA, PFF_ISCOMPRESSED, PFF_FLOAT, PFF_DEPTH, PFF_NATIVEENDIAN, PFF_LUMINANCE

This replaces the separate functions for formatHasAlpha, formatIsFloat, ...

## hasAlpha()

bool Ogre::PixelUtil::hasAlpha | ( | PixelFormat | format | ) |

static

Shortcut method to determine if the format has an alpha component.

## isFloatingPoint()

bool Ogre::PixelUtil::isFloatingPoint | ( | PixelFormat | format | ) |

static

Shortcut method to determine if the format is floating point.

## isInteger()

bool Ogre::PixelUtil::isInteger | ( | PixelFormat | format | ) |

static

Shortcut method to determine if the format is integer.

## isCompressed()

bool Ogre::PixelUtil::isCompressed | ( | PixelFormat | format | ) |

static

Shortcut method to determine if the format is compressed.

## isDepth()

bool Ogre::PixelUtil::isDepth | ( | PixelFormat | format | ) |

static

Shortcut method to determine if the format is a depth format.

## isNativeEndian()

bool Ogre::PixelUtil::isNativeEndian | ( | PixelFormat | format | ) |

static

Shortcut method to determine if the format is in native endian format.

## isLuminance()

bool Ogre::PixelUtil::isLuminance | ( | PixelFormat | format | ) |

static

Shortcut method to determine if the format is a luminance format.

## getBitDepths()

void Ogre::PixelUtil::getBitDepths | ( | PixelFormat | format,
|  | int | rgba[4] )

static

Gives the number of bits (RGBA) for a format.

See remarks.

Remarks
  For non-colour formats (dxt, depth) this returns [0,0,0,0].

## getBitMasks()

void Ogre::PixelUtil::getBitMasks | ( | PixelFormat | format,
|  | uint64 | rgba[4] )

static

Gives the masks for the R, G, B and A component.

Note
  Only valid for native endian formats

## getBitShifts()

void Ogre::PixelUtil::getBitShifts | ( | PixelFormat | format,
|  | unsigned char | rgba[4] )

static

Gives the bit shifts for R, G, B and A component.

Note
  Only valid for native endian formats

## getFormatName()

const String & Ogre::PixelUtil::getFormatName | ( | PixelFormat | srcformat | ) |

static

Gets the name of an image format.

Referenced by Ogre::to_string().

## isAccessible()

bool Ogre::PixelUtil::isAccessible | ( | PixelFormat | srcformat | ) |

static

Returns whether the format can be packed or unpacked with the packColour() and unpackColour() functions.

This is generally not true for compressed formats as they are special. It can only be true for formats with a fixed element size.

## getComponentType()

PixelComponentType Ogre::PixelUtil::getComponentType | ( | PixelFormat | fmt | ) |

static

Returns the component type for a certain pixel format.

Returns PCT_BYTE in case there is no clear component type like with compressed formats. This is one of PCT_BYTE, PCT_SHORT, PCT_FLOAT16, PCT_FLOAT32.

## getComponentCount()

uint8 Ogre::PixelUtil::getComponentCount | ( | PixelFormat | fmt | ) |

static

Returns the component count for a certain pixel format.

Returns 3(no alpha) or 4 (has alpha) in case there is no clear component type like with compressed formats.

## getFormatFromName()

PixelFormat Ogre::PixelUtil::getFormatFromName | ( | const String & | name,
|  | bool | accessibleOnly = false,
|  | bool | caseSensitive = false )

static

Gets the format from given name.

Parameters

  name | The string of format name
  accessibleOnly | If true, non-accessible format will treat as invalid format, otherwise, all supported format are valid.
  caseSensitive | Should be set true if string match should use case sensitivity.

Returns
  The format match the format name, or PF_UNKNOWN if is invalid name.

## getFormatForBitDepths()

PixelFormat Ogre::PixelUtil::getFormatForBitDepths | ( | PixelFormat | fmt,
|  | ushort | integerBits,
|  | ushort | floatBits )

static

Returns the similar format but according with given bit depths.

Parameters

  fmt | The original format.
  integerBits | Preferred bit depth (pixel bits) for integer pixel format. Available values: 0, 16 and 32, where 0 (the default) means as it is.
  floatBits | Preferred bit depth (channel bits) for float pixel format. Available values: 0, 16 and 32, where 0 (the default) means as it is.

Returns
  The format that similar original format with bit depth according with preferred bit depth, or original format if no conversion occurring.

## packColour() [1/3]

void Ogre::PixelUtil::packColour | ( | const ColourValue & | colour,
|  | const PixelFormat | pf,
|  | void * | dest )

inline static

Pack a colour value to memory.

Parameters

  colour | The colour
  pf | Pixelformat in which to write the colour
  dest | Destination memory location

References Ogre::ColourValue::a, Ogre::ColourValue::b, Ogre::ColourValue::g, packColour(), and Ogre::ColourValue::r.

Referenced by packColour().

## packColour() [2/3]

void Ogre::PixelUtil::packColour | ( | const uint8 | r,
|  | const uint8 | g,
|  | const uint8 | b,
|  | const uint8 | a,
|  | const PixelFormat | pf,
|  | void * | dest )

static

Pack a colour value to memory.

Parameters

  r,g,b,a | The four colour components, range 0.0f to 1.0f (an exception to this case exists for floating point pixel formats, which don't clamp to 0.0f..1.0f)
  pf | Pixelformat in which to write the colour
  dest | Destination memory location

## packColour() [3/3]

void Ogre::PixelUtil::packColour | ( | const float | r,
|  | const float | g,
|  | const float | b,
|  | const float | a,
|  | const PixelFormat | pf,
|  | void * | dest )

static

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

## unpackColour() [1/4]

void Ogre::PixelUtil::unpackColour | ( | ColourValue & | colour,
|  | PixelFormat | pf,
|  | const void * | src )

inline static

Unpack a colour value from memory.

Parameters

  colour | The colour is returned here
  pf | Pixelformat in which to read the colour
  src | Source memory location

References Ogre::ColourValue::a, Ogre::ColourValue::b, Ogre::ColourValue::g, Ogre::ColourValue::r, and unpackColour().

Referenced by unpackColour(), and unpackColour().

## unpackColour() [2/4]

void Ogre::PixelUtil::unpackColour | ( | ColourValue * | colour,
|  | PixelFormat | pf,
|  | const void * | src )

inline static

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

References Ogre::ColourValue::a, Ogre::ColourValue::b, Ogre::ColourValue::g, Ogre::ColourValue::r, and unpackColour().

## unpackColour() [3/4]

void Ogre::PixelUtil::unpackColour | ( | float * | r,
|  | float * | g,
|  | float * | b,
|  | float * | a,
|  | PixelFormat | pf,
|  | const void * | src )

static

Unpack a colour value from memory.

Parameters

  r,g,b,a | The four colour channels are returned here
  pf | Pixelformat in which to read the colour
  src | Source memory location

## unpackColour() [4/4]

void Ogre::PixelUtil::unpackColour | ( | uint8 * | r,
|  | uint8 * | g,
|  | uint8 * | b,
|  | uint8 * | a,
|  | PixelFormat | pf,
|  | const void * | src )

static

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Note
  This function returns the colour components in 8 bit precision, this will lose precision when coming from PF_A2R10G10B10 or floating point formats.

## bulkPixelConversion() [1/2]

void Ogre::PixelUtil::bulkPixelConversion | ( | void * | src,
|  | PixelFormat | srcFormat,
|  | void * | dst,
|  | PixelFormat | dstFormat,
|  | unsigned int | count )

inline static

Convert consecutive pixels from one format to another.

No dithering or filtering is being done. Converting from RGB to luminance takes the R channel. In case the source and destination format match, just a copy is done.

Parameters

  src | Pointer to source region
  srcFormat | Pixel format of source region
  dst | Pointer to destination region
  dstFormat | Pixel format of destination region
  count | The number of pixels to convert

References bulkPixelConversion().

Referenced by bulkPixelConversion().

## bulkPixelConversion() [2/2]

void Ogre::PixelUtil::bulkPixelConversion | ( | const PixelBox & | src,
|  | const PixelBox & | dst )

static

Convert pixels from one format to another.

No dithering or filtering is being done. Converting from RGB to luminance takes the R channel.

Parameters

  src | PixelBox containing the source pixels, pitches and format
  dst | PixelBox containing the destination pixels, pitches and format

Remarks
  The source and destination boxes must have the same dimensions. In case the source and destination format match, a plain copy is done.

## bulkPixelVerticalFlip()

void Ogre::PixelUtil::bulkPixelVerticalFlip | ( | const PixelBox & | box | ) |

static

Flips pixels inplace in vertical direction.

Parameters

  box | PixelBox containing pixels, pitches and format

Remarks
  Non consecutive pixel boxes are supported.

The documentation for this class was generated from the following file:

- OgrePixelFormat.h