Table of Contents

Class Bc1Encoder

Encodes RGBA8888 into BC1 blocks (8 bytes per 4x4 texels, 4 bpp) with a fast range-fit, no iterative refinement.

public static class Bc1Encoder
Inheritance
object
Bc1Encoder

Remarks

Every block is forced into four-color (opaque) mode. BC1's three-color plus transparent mode exists for alpha, which tiles never carry.

Fields

BlockBytes

BC1 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 BC1 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 BC1 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. A level below 4x4 is legal in BC1 and still costs one whole block. Missing texels clamp from the level's own edge.

RequiredBlockBufferBytes(int, int)

Byte count of a tightly packed BC1 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.