Class Etc2Encoder
- Namespace
- LansMap.Core.TileCodecs.Etc2
Encodes RGBA8888 into ETC2 RGB blocks (8 bytes per 4x4 texels, 4 bpp) using ETC1 individual mode only.
public static class Etc2Encoder
- Inheritance
-
objectEtc2Encoder
Remarks
ETC2 keeps ETC1 bit-for-bit compatible, so a correct individual-mode encoder is a correct (if not feature-complete) ETC2 RGB encoder. T, H, planar, and differential modes are not emitted. Pixel indices are column-major (k = y + x*4), an ETC1 spec quirk. Exact flat mid-tones do not round-trip; exact black and white do, because modifiers clamp.
Fields
BlockBytes
ETC2 RGB block size, 8 bytes.
public const int BlockBytes = 8
Field Value
BlockPixels
Texels along one edge of a block, 4.
public const int BlockPixels = 4
Field Value
Methods
BlockSpan(int)
Blocks along one axis, rounding a tail smaller than 4 texels up to one block.
public static int BlockSpan(int pixels)
Parameters
pixelsintAxis length in texels.
Returns
- int
Block count along that axis.
Encode(byte[], int, int, byte[], int)
Encodes a whole mip level whose edges are positive multiples of 4 into ETC2 individual-mode blocks.
public static void Encode(byte[] rgba, int width, int height, byte[] outBlocks, int outOffset)
Parameters
rgbabyte[]widthheight4 RGBA8888 bytes, row-major.
widthintWidth in texels, a positive multiple of 4.
heightintHeight in texels, a positive multiple of 4.
outBlocksbyte[]Caller-owned destination, at least RequiredBlockBufferBytes(int, int) bytes from
outOffset.outOffsetintStart write index in
outBlocks, in bytes.
Remarks
A level smaller than 4x4 on either axis must use EncodeSubBlockLevel(byte[], int, int, byte[], int) instead.
EncodeSubBlockLevel(byte[], int, int, byte[], int)
Encodes a mip tail smaller than one full block into exactly one ETC2 block, edge-clamped.
public static void EncodeSubBlockLevel(byte[] rgba, int width, int height, byte[] outBlocks, int outOffset)
Parameters
rgbabyte[]widthheight4 RGBA8888 bytes, row-major.
widthintWidth in texels, greater than 0.
heightintHeight in texels, greater than 0.
outBlocksbyte[]Caller-owned destination, at least BlockBytes from
outOffset.outOffsetintStart write index in
outBlocks, in bytes.
Remarks
Only for a level smaller than 4x4 on at least one axis. Missing texels clamp from the level's own edge, so a uniform tail stays uniform rather than smearing adjacent memory.
RequiredBlockBufferBytes(int, int)
Byte count of a tightly packed ETC2 block grid for the given texel size.
public static int RequiredBlockBufferBytes(int width, int height)
Parameters
Returns
- int
Size in bytes, block-rounded.