Fix BC1 transparency and BC2/BC3 preview palettes #35

Manually merged
github merged 1 commit from gh-pr/35/head into gh-pr/35/base 2026-11-26 20:04:41 +00:00
Owner

@⁠ifBars on GitHub · 2026-11-23 04:21 UTC · original
ifBars:fix/preview-bc1-bc2-bc3 → master · +227 −3 · 1 files · 1 commits · merged 2026-11-23 04:34 UTC

BC1's three-colour mode uses index 3 for transparent black. to_rgba called the opaque decoder, so those pixels got alpha 255. BC2 and BC3 had a related palette problem: their colour decoder switched to three colours when c0 <= c1, although both formats always use four colours. Microsoft's BC1 reference and BC2/BC3 reference describe the rules.

This selects decode_bc1a for BC1 and repairs only the affected BC2/BC3 RGB values after decoding. Alpha interpolation and output packing stay the same. The six synthetic tests cover transparency, ascending and equal palettes, both BC3 alpha modes, and BC2/BC3 images clipped at the right and bottom edges. The initial reproduction failed for BC1, BC2 and BC3; all six final regression tests pass with the fix.

Validated on Windows x64: 109 core tests pass, one ignored (--no-default-features), and the CLI check passes. The final six colour tests also pass after expanding the edge-coverage case. Full release builds/tests run in CI.

AI-assisted with Codex and DeepSeek. No game data is included.

**@⁠ifBars** on GitHub · 2026-11-23 04:21 UTC · [original](https://github.com/holdmysocks/SixNG/pull/35) `ifBars:fix/preview-bc1-bc2-bc3` → `master` · +227 −3 · 1 files · 1 commits · merged 2026-11-23 04:34 UTC BC1's three-colour mode uses index 3 for transparent black. `to_rgba` called the opaque decoder, so those pixels got alpha 255. BC2 and BC3 had a related palette problem: their colour decoder switched to three colours when `c0 <= c1`, although both formats always use four colours. Microsoft's [BC1 reference](https://learn.microsoft.com/en-us/windows/uwp/graphics-concepts/opaque-and-1-bit-alpha-textures) and [BC2/BC3 reference](https://learn.microsoft.com/en-us/windows/uwp/graphics-concepts/textures-with-alpha-channels) describe the rules. This selects `decode_bc1a` for BC1 and repairs only the affected BC2/BC3 RGB values after decoding. Alpha interpolation and output packing stay the same. The six synthetic tests cover transparency, ascending and equal palettes, both BC3 alpha modes, and BC2/BC3 images clipped at the right and bottom edges. The initial reproduction failed for BC1, BC2 and BC3; all six final regression tests pass with the fix. Validated on Windows x64: 109 core tests pass, one ignored (`--no-default-features`), and the CLI check passes. The final six colour tests also pass after expanding the edge-coverage case. Full release builds/tests run in CI. AI-assisted with Codex and DeepSeek. No game data is included.
texture2ddecoder 0.1.2 decodes BC1 through the opaque entry point, so the
three-colour index 3 came out opaque instead of transparent. It also decodes
the BC2/BC3 colour half with the BC1 block decoder, which switches to three
colours when c0 <= c1; BC2 and BC3 always use four colours.

BC1 now uses decode_bc1a. BC2/BC3 keep texture2ddecoder's alpha and repair
only the index-2 and index-3 RGB of blocks with c0 <= c1, preserving alpha
and the existing 0xAARRGGBB output.

The block tests cover transparent BC1, ascending and equal BC2/BC3 palettes,
both BC3 alpha modes, and clipped edges. Core tests: 109 passed, 1 ignored.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 20:04:39 +00:00
github manually merged commit 2037771b0f into gh-pr/35/base 2026-11-26 20:04:41 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.