Table of Contents

Class TileAstc4x4Payload

On-disk ASTC 4x4 mip-chain payload: base dimensions, level count, then every mip level's blocks concatenated, level 0 first.

public static class TileAstc4x4Payload
Inheritance
object
TileAstc4x4Payload

Fields

HeaderSize

Header size in bytes: width(4) + height(4) + levelCount(4), little-endian.

public const int HeaderSize = 12

Field Value

int

Methods

LevelOffset(int, int, int)

Byte offset of a mip level's blocks, relative to blocksOffset from TryReadHeader(byte[], int, int, out int, out int, out int, out int).

public static int LevelOffset(int width, int height, int level)

Parameters

width int

Base-level width in texels.

height int

Base-level height in texels.

level int

Mip index, 0 is the base.

Returns

int

Offset in bytes from the start of the block region.

RequiredPayloadBytes(int, int)

Byte count of a full payload for a base level of the given dimensions.

public static int RequiredPayloadBytes(int width, int height)

Parameters

width int

Base-level width in texels.

height int

Base-level height in texels.

Returns

int

Header plus every mip's block bytes.

TryReadHeader(byte[], int, int, out int, out int, out int, out int)

Parses the 12-byte header without reading the block bytes.

public static bool TryReadHeader(byte[] payload, int offset, int length, out int width, out int height, out int levelCount, out int blocksOffset)

Parameters

payload byte[]

Disk payload bytes, not copied.

offset int

Start of this payload in payload, in bytes.

length int

Readable byte count from offset.

width int

Base-level width in texels, or 0 on failure.

height int

Base-level height in texels, or 0 on failure.

levelCount int

Stored mip count, or 0 on failure.

blocksOffset int

Byte index of level 0's blocks.

Returns

bool

True when the header parsed and levelCount is within the chain this size can hold; false on a short, null, or hostile header. Never throws.

Write(int, int, byte[], byte[], byte[], int)

Encodes a full ASTC 4x4 mip chain into a disk payload.

public static int Write(int width, int height, byte[] rgba, byte[] scratchRgba, byte[] outPayload, int outOffset)

Parameters

width int

Base-level width in texels, a multiple of 4.

height int

Base-level height in texels, a multiple of 4.

rgba byte[]

Base-level widthheight4 RGBA8888 bytes; a working buffer, not preserved.

scratchRgba byte[]

Caller-owned scratch of at least widthheight4 bytes; a working buffer, not preserved.

outPayload byte[]

Caller-owned destination, at least RequiredPayloadBytes(int, int) bytes from outOffset.

outOffset int

Start write index in outPayload, in bytes.

Returns

int

Bytes written, equal to RequiredPayloadBytes(int, int).

Remarks

rgba and scratchRgba are ping-pong working buffers. After return, neither holds the original level-0 pixels. Pass a copy if you still need them.