Class TileBc1Payload
- Namespace
- LansMap.Core.TileCodecs.Bc1
On-disk BC1 mip-chain payload: base dimensions, level count, then every mip level's blocks concatenated, level 0 first.
public static class TileBc1Payload
- Inheritance
-
objectTileBc1Payload
Fields
HeaderSize
Header size in bytes: width(4) + height(4) + levelCount(4), little-endian.
public const int HeaderSize = 12
Field Value
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
widthintBase-level width in texels.
heightintBase-level height in texels.
levelintMip 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
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
payloadbyte[]Disk payload bytes, not copied.
offsetintStart of this payload in
payload, in bytes.lengthintReadable byte count from
offset.widthintBase-level width in texels, or 0 on failure.
heightintBase-level height in texels, or 0 on failure.
levelCountintStored mip count, or 0 on failure.
blocksOffsetintByte index of level 0's blocks.
Returns
- bool
True when the header parsed and
levelCountis 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 BC1 mip chain into a disk payload.
public static int Write(int width, int height, byte[] rgba, byte[] scratchRgba, byte[] outPayload, int outOffset)
Parameters
widthintBase-level width in texels, a multiple of 4.
heightintBase-level height in texels, a multiple of 4.
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.