Class Astc4x4TileCodec
- Namespace
- LansMap.Core.TileCodecs.Astc4x4
Disk-format codec for ASTC 4x4 GPU blocks already stored in a cache blob: no image decode, extract the mip levels an upload needs.
public sealed class Astc4x4TileCodec : ITileBlockCodec, ITileCodec
- Inheritance
-
objectAstc4x4TileCodec
- Implements
Properties
Format
The TileCacheBlob.Format tag this codec recognizes.
public TileCacheBlob.Format Format { get; }
Property Value
Id
Stable lowercase identifier for this codec, for example "bc1", "etc2", or "astc4x4".
public string Id { get; }
Property Value
Remarks
Serialized scenes carry this string. Do not localize it, and do not change the spelling once shipped. One id is one GPU block format including its parameters: a family such as ASTC ships as separate ids ("astc4x4", "astc6x6"), never a bare "astc".
RequiresDecode
True when the payload is still compressed (PNG/JPEG) and needs an image decode; false when it is already GPU-ready blocks.
public bool RequiresDecode { get; }
Property Value
Methods
DecodeLevel(byte[], int, int, int, byte[], int)
Decodes one already-extracted mip level's raw blocks back to RGBA8888.
public void DecodeLevel(byte[] blocks, int offset, int width, int height, byte[] outRgba, int outOffset)
Parameters
blocksbyte[]Level bytes, LevelBlockBytes(int, int) readable from
offset.offsetintStart of this level in
blocks, in bytes.widthintLevel width in texels.
heightintLevel height in texels.
outRgbabyte[]Destination, widthheight4 RGBA8888 bytes row-major from
outOffset.outOffsetintStart write index in
outRgba, in bytes.
Remarks
Cache migration only needs the base level; the rest of a stored chain is discarded and rebuilt by the new codec's WritePayload(int, int, byte[], byte[], byte[], int). The default throws NotSupportedException so a codec that has not overridden this still compiles and simply skips local migration.
LevelBlockBytes(int, int)
Byte count of one mip level as raw blocks, block-rounded.
public int LevelBlockBytes(int widthTexels, int heightTexels)
Parameters
Returns
- int
Size in bytes of each TryBuildMips(byte[], int, int, int, int, byte[][]) buffer for this level. A tail smaller than one block still costs one whole block.
RequiredPayloadBytes(int, int)
Byte count of one whole disk payload (header plus every mip of a full chain) for a base level of the given dimensions.
public int RequiredPayloadBytes(int width, int height)
Parameters
Returns
- int
Payload size in bytes.
TryBuildMips(byte[], int, int, int, int, byte[][])
Extracts requiredLevels mip levels from a
GPU-ready disk payload into caller-owned buffers.
public bool TryBuildMips(byte[] payload, int offset, int length, int tileSizePx, int requiredLevels, byte[][] mips)
Parameters
payloadbyte[]Disk payload bytes, not copied.
offsetintStart of this tile's payload in
payload, in bytes.lengthintReadable byte count from
offset.tileSizePxintExpected base-level edge length in texels.
requiredLevelsintMip levels to copy, 1 or more.
mipsbyte[][]Caller-owned buffers, one per level; each entry must already hold that level's block-byte count.
Returns
- bool
True when the payload parsed and the levels were copied; false (never throws) on a corrupt or foreign-written entry.
Remarks
Only meaningful when RequiresDecode is false. The
buffers in mips are reused across calls: size
them before calling, do not allocate here.
WritePayload(int, int, byte[], byte[], byte[], int)
Encodes base-level RGBA8888 into a full mip-chain disk payload.
public int WritePayload(int width, int height, byte[] rgba, byte[] scratchRgba, byte[] outPayload, int outOffset)
Parameters
widthintBase-level width in texels.
heightintBase-level height in texels.
rgbabyte[]Base-level widthheight4 RGBA8888 bytes; a working buffer, not preserved.
scratchRgbabyte[]Caller-owned scratch of at least widthheight4 bytes; a working buffer, not preserved.
outPayloadbyte[]Caller-owned destination, at least RequiredPayloadBytes(int, int) bytes from
outOffset.outOffsetintStart 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.