Table of Contents

Class Etc2Encoder

Encodes RGBA8888 into ETC2 RGB blocks (8 bytes per 4x4 texels, 4 bpp) using ETC1 individual mode only.

public static class Etc2Encoder
Inheritance
object
Etc2Encoder

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

int

BlockPixels

Texels along one edge of a block, 4.

public const int BlockPixels = 4

Field Value

int

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

pixels int

Axis 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

rgba byte[]

widthheight4 RGBA8888 bytes, row-major.

width int

Width in texels, a positive multiple of 4.

height int

Height in texels, a positive multiple of 4.

outBlocks byte[]

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

outOffset int

Start 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

rgba byte[]

widthheight4 RGBA8888 bytes, row-major.

width int

Width in texels, greater than 0.

height int

Height in texels, greater than 0.

outBlocks byte[]

Caller-owned destination, at least BlockBytes from outOffset.

outOffset int

Start 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

width int

Width in texels.

height int

Height in texels.

Returns

int

Size in bytes, block-rounded.