dds_png: pick the BC4/BC5 SNORM ramp from the stored endpoints (DDS-PNG-SNORM-MODE) #2084

Open
github-bot wants to merge 1 commit from github-bot/gh-2084 into main AGit
Owner

@⁠syfyra on GitHub · 2026-11-25 19:50 UTC · original
syfyra:fix/dds-png-bc4-snorm-mode → main · +24 −8 · 2 files · 1 commits · open

Claimed in the coordination issue as: DDS-PNG-SNORM-MODE (#1608)

What and why

tools/dds_png.py _bc_interp_lut_snorm clamped a -128 endpoint to -127 before choosing between the eight- and six-value ramps. D3D's BC4_SNORM rule compares the stored int8 endpoints (red_0 > red_1) and reads -128 as -127 only once it becomes a value; DirectXTex and Pillow decode it the same way.

So the endpoint pair 0x81, 0x80 (-127 > -128) is an eight-value block whose entries are all -1.0. The clamp made the two endpoints equal, the six-value ramp was taken, and index 7 decoded to its constant +1.0: 255 instead of 0 in the PNG, for BC4_SNORM and both channels of BC5_SNORM (DXGI 81/84 and the BC4S/BC5S FourCCs). The ramp is now chosen from the stored values and only the values are clamped. Of the 65,536 endpoint pairs this changes the ramp of exactly that one.

Tested

Windows 11, Python 3.14.7, synthetic blocks only:

  • python -I tests/test_dds_png.py: the new Bc4Tests.test_snorm_ramp_is_chosen_by_the_raw_endpoints (BC4S and BC5S, both endpoint orders) fails on main with 255 != 0 and passes with the fix; 101 tests OK.
  • Every BC5_SNORM red endpoint pair (65,536) x all 8 indices, decoded by dds_png and by Pillow 12.3: on main one mismatch (0x81, 0x80, index 7: 255 vs 0); with the fix the largest difference is 1 (rounding).
  • Also pass: test_dds_png_dx10, test_dds_subresources, test_gallery, test_world_build, test_batch_glb; python -m compileall; scripts/check_no_game_data.py on both files. Not run: tests/test_tex_export.py (pytest and numpy).

GPUs tested: n/a (CPU-only decoder)

AI-assisted: yes (Claude Code, Claude Opus 5.5)

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator change)

🤖 Generated with Claude Code

**@⁠syfyra** on GitHub · 2026-11-25 19:50 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2084) `syfyra:fix/dds-png-bc4-snorm-mode` → `main` · +24 −8 · 2 files · 1 commits · open Claimed in the coordination issue as: DDS-PNG-SNORM-MODE (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) ### What and why `tools/dds_png.py` `_bc_interp_lut_snorm` clamped a -128 endpoint to -127 *before* choosing between the eight- and six-value ramps. D3D's BC4_SNORM rule compares the stored int8 endpoints (`red_0 > red_1`) and reads -128 as -127 only once it becomes a value; DirectXTex and Pillow decode it the same way. So the endpoint pair `0x81, 0x80` (-127 > -128) is an eight-value block whose entries are all -1.0. The clamp made the two endpoints equal, the six-value ramp was taken, and index 7 decoded to its constant +1.0: 255 instead of 0 in the PNG, for BC4_SNORM and both channels of BC5_SNORM (DXGI 81/84 and the `BC4S`/`BC5S` FourCCs). The ramp is now chosen from the stored values and only the values are clamped. Of the 65,536 endpoint pairs this changes the ramp of exactly that one. ### Tested Windows 11, Python 3.14.7, synthetic blocks only: - `python -I tests/test_dds_png.py`: the new `Bc4Tests.test_snorm_ramp_is_chosen_by_the_raw_endpoints` (BC4S and BC5S, both endpoint orders) fails on `main` with `255 != 0` and passes with the fix; 101 tests OK. - Every BC5_SNORM red endpoint pair (65,536) x all 8 indices, decoded by `dds_png` and by Pillow 12.3: on `main` one mismatch (`0x81, 0x80`, index 7: 255 vs 0); with the fix the largest difference is 1 (rounding). - Also pass: `test_dds_png_dx10`, `test_dds_subresources`, `test_gallery`, `test_world_build`, `test_batch_glb`; `python -m compileall`; `scripts/check_no_game_data.py` on both files. Not run: `tests/test_tex_export.py` (pytest and numpy). GPUs tested: n/a (CPU-only decoder) AI-assisted: yes (Claude Code, Claude Opus 5.5) ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a: no translator change) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
_bc_interp_lut_snorm clamped a -128 endpoint to -127 before the red_0 > red_1
test. D3D's BC4_SNORM rule compares the stored int8 endpoints and reads -128
as -127 only as a value (DirectXTex and Pillow decode it that way), so the
pair 0x81, 0x80 (-127 > -128) is an eight-value block with every entry -1.0.
The clamp made the endpoints equal, took the six-value ramp, and index 7
decoded to +1.0 (255) instead of 0. It is the only one of the 65,536 pairs
whose ramp changes.

Tested: new test_snorm_ramp_is_chosen_by_the_raw_endpoints (BC4S and BC5S,
fails before the fix); all 65,536 BC5_SNORM endpoint pairs x 8 indices match
Pillow 12.3 within 1 (one 255-off mismatch before).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:17:16 +00:00
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2084/head:github-bot/gh-2084'
git switch 'github-bot/gh-2084'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2084'
git switch 'github-bot/gh-2084'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2084'
git switch 'github-bot/gh-2084'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2084'
git switch 'main'
git merge --squash 'github-bot/gh-2084'
git switch 'main'
git merge --ff-only 'github-bot/gh-2084'
git switch 'main'
git merge 'github-bot/gh-2084'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.