encodeBc1 function
Encodes image as BC1 (vkFormat.bc1RgbaUNormBlock): one 8-byte block
per 4×4 tile, two RGB565 endpoints and sixteen 2-bit palette picks.
Always four-color mode. BC1 also has a three-color-plus-transparent
mode, signalled by writing the first endpoint as the numerically smaller
of the two — this encoder never does, because nothing here ever wants a
transparent pixel out of a colour block (alpha, when a texture has it,
is BC3's separate half). _orderEndpoints enforces this by swapping and,
on a tie, nudging one channel by one step — see its own doc comment for
why a tie is not a curiosity to leave alone.
Endpoints from a principal-axis fit, not a bounding box — see
blockEndpoints, which every block encoder here shares.
Implementation
Uint8List encodeBc1(Rgba8Image image) {
requireWholeBlocks(image, 'encodeBc1');
final blocksX = image.width ~/ 4;
final blocksY = image.height ~/ 4;
final out = Uint8List(blocksX * blocksY * 8);
var offset = 0;
for (var by = 0; by < blocksY; by++) {
for (var bx = 0; bx < blocksX; bx++) {
final block = encodeBc1Block(readBlock(image, bx, by));
out.setRange(offset, offset + 8, block);
offset += 8;
}
}
return out;
}