Image

View source

Represents image data as a render-core asset value.

Examples

import { Image } from '@wimaengine/render-core'

const image = Image.default()
console.log(image.dimensions.x, image.dimensions.y) // 1 1

Constructor


constructor(buffer: Uint8ClampedArray<ArrayBufferLike>, dimensions: Vector2)

View source

Creates an image value from raw bytes and dimensions.

The supplied buffer and dimensions are stored directly without copying or validation.

Parameters

NameDescriptionDefault
buffer

Raw image bytes to store.

—
dimensions

Image width and height to store.

—

Properties


raw: Uint8ClampedArray<ArrayBufferLike>

View source

Raw bytes associated with the image.

The value stores these bytes in a clamped 8-bit typed array.

dimensions: Vector2

View source

Image width and height.

The dimensions are represented by a Vector2.

Methods


staticdefault(): Image

View source

Creates a default one-by-one image value.

Each call creates a new image with a new Uint8ClampedArray containing [1, 0, 1, 1] and a new Vector2 with x and y set to 1. Image.deserialize uses this value when out is omitted.

Returns

A new default image value.

staticserialize(value: Image): ImageSerial

View source

Serializes an image value to a plain object.

raw is copied to a regular number array with Array.from, and dimensions is converted with Vector2.serialize. The image value is not mutated.

Parameters

NameDescriptionDefault
value

Image value to serialize.

—

Returns

The serialized image data.

staticdeserialize(value: ImageSerial, out?: Image): Image

View source

Deserializes a plain object into an image value.

raw is replaced with a new Uint8ClampedArray created from the serial array. dimensions is passed to Vector2.deserialize with the output image’s existing dimensions object, so that object is updated and reused. When out is omitted, a new value from Image.default is populated. The output image value is returned.

Parameters

NameDescriptionDefault
value

Serialized image data to restore.

—
out?

Image value to populate and return.

...

Returns

The populated output image value.

staticvalidateSerial(value: unknown): value is ImageSerial

View source

Checks whether a value has the serialized image structure.

The value must be an object with raw and dimensions properties. raw must be an array, and dimensions must pass Vector2.validateSerial. The elements of raw are not inspected; this method does not construct an Image or validate image bytes.

Parameters

NameDescriptionDefault
value

Value to check.

—

Returns

Whether the value has the required structure.