Skip to Content
⚠ Under Construction
ReferenceC++ APIImage

endstone::Image

Represents an RGBA image.

Types:

NameDescription
Type

Functions:

NameDescription
ImageCreate an empty image (all pixels transparent black).
getColorGet the color of a pixel.
getDataGets the raw pixel buffer (row-major, H x W x D).
getDepthGet the image depth.
getHeightGet the image height.
getWidthGet the image width.
setColorSet the color of a pixel.

Functions:

NameDescription
fromArrayCreates an image from the pixel data in a byte array.
fromBufferCreates an image from the pixel data in a byte buffer.

Type

enum Type { Invalid = 0, Grayscale = 1, RGB = 3, RGBA = 4 };

Image

Image(const Type type, const int width, const int height)

Create an empty image (all pixels transparent black).

Parameters:

  • type Image type
  • width Image width in pixels
  • height Image height in pixels

getColor

Color getColor(const int x, const int y) const

Get the color of a pixel.

Parameters:

  • x X coordinate (0 ≤ x < width)
  • y Y coordinate (0 ≤ y < height)

Returns:

Color at (x, y)

getData

std::string_view getData() const

Gets the raw pixel buffer (row-major, H x W x D).

Returns:

The underlying image data buffer

getDepth

int getDepth() const

Get the image depth.

Returns:

Image depth

getHeight

int getHeight() const

Get the image height.

Returns:

Image height in pixels

getWidth

int getWidth() const

Get the image width.

Returns:

Image width in pixels

setColor

void setColor(const int x, const int y, const Color color)

Set the color of a pixel.

Parameters:

  • x X coordinate (0 ≤ x < width)
  • y Y coordinate (0 ≤ y < height)
  • color New color for the pixel

fromArray

static Result<Image> fromArray(Type type, const int width, const int height, const std::vector<unsigned char> &array)

Creates an image from the pixel data in a byte array.

Parameters:

  • type Image type
  • width Image width in pixels
  • height Image height in pixels
  • array

Returns:

The image on success, or an error on failure.

fromBuffer

static Result<Image> fromBuffer(Type type, const int width, const int height, std::string_view buffer)

Creates an image from the pixel data in a byte buffer.

Parameters:

  • type Image type
  • width Image width in pixels
  • height Image height in pixels
  • buffer

Returns:

The image on success, or an error on failure.

Last updated on