class PixelData

A buffer describing a volume (3D), image (2D) or line (1D) of pixels in memory.

Pixels are stored as a succession of "depth" slices, each containing "height" rows of "width" pixels.

Public

Constructors

PixelData

PixelData() = default

PixelData

PixelData(const PixelVolume &extents, PixelFormat pixelFormat)

Constructs a new object with an internal buffer capable of holding "extents" volume of pixels, where each pixel is of the specified pixel format.

Extent offsets are also stored, but are not used internally.

PixelData

PixelData(u32 width, u32 height, u32 depth, PixelFormat pixelFormat)

Constructs a new object with an internal buffer capable of holding volume of pixels described by provided width, height and depth, where each pixel is of the specified pixel format.

PixelData

PixelData(const PixelData &copy)

Methods

GetRowPitch

u32 GetRowPitch() const

Returns the number of bytes that offsets one row from another.

This can be exact number of bytes required to hold "width" pixel, but doesn't have to be as some buffers require padding.

GetSlicePitch

u32 GetSlicePitch() const

Returns the number of bytes that offsets one depth slice from another.

This can be exact number of bytes required to hold "width * height" pixels, but doesn't have to be as some buffers require padding.

SetRowPitch

void SetRowPitch(u32 rowPitch)

Sets the pitch (in bytes) that determines offset between rows of the pixel buffer.

Call this before allocating the buffer.

SetSlicePitch

void SetSlicePitch(u32 slicePitch)

Sets the pitch (in bytes) that determines offset between depth slices of the pixel buffer.

Call this before allocating the buffer.

GetRowSkip

u32 GetRowSkip() const

Returns the number of extra bytes in a row (non-zero only if rows are not consecutive (row pitch is larger than the number of bytes required to hold "width" pixels)).

GetSliceSkip

u32 GetSliceSkip() const

Returns the number of extra bytes in a depth slice (non-zero only if slices aren't consecutive (slice pitch is larger than the number of bytes required to hold "width * height").

GetFormat

PixelFormat GetFormat() const

Returns the pixel format used by the internal buffer for storing the pixels.

GetWidth

u32 GetWidth() const

Returns width of the buffer in pixels.

GetHeight

u32 GetHeight() const

Returns height of the buffer in pixels.

GetDepth

u32 GetDepth() const

Returns depth of the buffer in pixels.

GetLeft

u32 GetLeft() const

Returns left-most start of the pixel volume.

This value is not used internally in any way. It is just passed through from the constructor.

GetRight

u32 GetRight() const

Returns right-most end of the pixel volume.

This value is not used internally in any way. It is just passed through from the constructor.

GetTop

u32 GetTop() const

Returns top-most start of the pixel volume.

This value is not used internally in any way. It is just passed through from the constructor.

GetBottom

u32 GetBottom() const

Returns bottom-most end of the pixel volume.

This value is not used internally in any way. It is just passed through from the constructor.

GetFront

u32 GetFront() const

Returns front-most start of the pixel volume.

This value is not used internally in any way. It is just passed through from the constructor.

GetBack

u32 GetBack() const

Returns back-most end of the pixel volume.

This value is not used internally in any way. It is just passed through from the constructor.

GetExtents

PixelVolume GetExtents() const

Returns extents of the pixel volume this object is capable of holding.

IsConsecutive

bool IsConsecutive() const

Return whether this buffer is laid out consecutive in memory (meaning the pitches are equal to the dimensions).

GetConsecutiveSize

u32 GetConsecutiveSize() const

Return the size (in bytes) this image would take if it was laid out consecutive in memory.

GetSize

u32 GetSize() const

Return the size (in bytes) of the buffer this image requires.

GetSubVolume

PixelData GetSubVolume(const PixelVolume &volume) const

Returns pixel data containing a sub-volume of this object.

Returned data will not have its own buffer, but will instead point to this one. It is up to the caller to ensure this object outlives any sub-volume objects.

SampleColorAt

Color SampleColorAt(const Vector2 &coords, TextureFilter filter = TF_BILINEAR) const

Samples a color at the specified coordinates using a specific filter.

coords
Coordinates to sample the color at. They start at top left corner (0, 0), and are in range [0, 1].
filter
Filtering mode to use when sampling the color.

Returns: Sampled color.

GetColorAt

Color GetColorAt(u32 x, u32 y, u32 z = 0) const

Returns pixel color at the specified coordinates.

SetColorAt

void SetColorAt(const Color &color, u32 x, u32 y, u32 z = 0)

Sets the pixel color at the specified coordinates.

GetColors

Vector<Color> GetColors() const

Converts all the internal data into an array of colors.

Array is mapped as such: arrayIdx = x + y * width + z * width * height.

SetColors

void SetColors(const Vector<Color> &colors)

Initializes the internal buffer with the provided set of colors.

The array should be of width * height * depth size and mapped as such: arrayIdx = x + y * width + z * width * height.

SetColors

void SetColors(Color *colors, u32 elementCount)

Initializes the internal buffer with the provided set of colors.

The array should be of width * height * depth size and mapped as such: arrayIdx = x + y * width + z * width * height.

SetColors

void SetColors(const Color &color)

Initializes all the pixels with a single color.

GetDepthAt

float GetDepthAt(u32 x, u32 y, u32 z = 0) const

Interprets pixel data as depth information as retrieved from the GPU's depth buffer.

Converts the device specific depth value to range [0, 1] and returns it.

GetDepths

Vector<float> GetDepths() const

Converts all the internal data into an array of floats as if each individual pixel is retrieved with getDepthAt().

Array is mapped as such: arrayIdx = x + y * width + z * width * height.

staticCreate

static SPtr<PixelData> Create(const PixelVolume &extents, PixelFormat pixelFormat)

Constructs a new object with an internal buffer capable of holding "extents" volume of pixels, where each pixel is of the specified pixel format.

Extent offsets are also stored, but are not used internally.

staticCreate

static SPtr<PixelData> Create(u32 width, u32 height, u32 depth, PixelFormat pixelFormat)

Constructs a new object with an internal buffer capable of holding volume of pixels described by provided width, height and depth, where each pixel is of the specified pixel format.

staticGetRttiStatic

static RTTIType *GetRttiStatic()

GetRtti

RTTIType *GetRtti() const override

Returns an interface you can use to access class' Run Time Type Information.

Operators

operator=

PixelData &operator=(const PixelData &rhs)

Private

Methods

GetInternalBufferSize

u32 GetInternalBufferSize() const override

Returns the needed size of the internal buffer, in bytes.

Fields

mExtents

PixelVolume mExtents

mFormat

PixelFormat mFormat

mRowPitch

u32 mRowPitch

mSlicePitch

u32 mSlicePitch