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

Merged
syfyra merged 1 commit from upstream-pr/2084 into main 2026-11-28 10:47:13 +00:00
syfyra commented 2026-11-25 19:50:23 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by syfyra on 2026-11-25T19:50:23Z.


Claimed in the coordination issue as: DDS-PNG-SNORM-MODE (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7172770290)

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

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5498090446 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2084). Originally posted by [syfyra](https://github.com/syfyra) on 2026-11-25T19:50:23Z. --- Claimed in the coordination issue as: DDS-PNG-SNORM-MODE (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7172770290) ### 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)
sodove commented 2026-11-28 10:12:20 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by sodove on 2026-11-28T10:12:20Z.


#2084 | head 9797ec66a1afc092aa64ce4304860af1f18185c7 | python3 -I tests/test_dds_png.py -v | red: 101 run, 2 failures | green: 101 passed | Red → green

The signed BC4/BC5 endpoint cases failed their decoded-value assertions on main.

Pinned main 33db04a7010e81c40a7a6a15624525aa0c4a3a58, merged into this PR head. Ubuntu 26.04.1 (WSL2), Python 3.14.4. Full suite: not run. AI-assisted: OpenAI Codex. Batch claim.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7237742733 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2084#issuecomment-7237742733). Originally posted by [sodove](https://github.com/sodove) on 2026-11-28T10:12:20Z. --- #2084 | head `9797ec66a1afc092aa64ce4304860af1f18185c7` | `python3 -I tests/test_dds_png.py -v` | red: 101 run, 2 failures | green: 101 passed | **Red → green** The signed BC4/BC5 endpoint cases failed their decoded-value assertions on main. Pinned main `33db04a7010e81c40a7a6a15624525aa0c4a3a58`, merged into this PR head. Ubuntu 26.04.1 (WSL2), Python 3.14.4. Full suite: not run. AI-assisted: OpenAI Codex. [Batch claim](https://github.com/ProjectLeonida/mandy/issues/1608#issuecomment-7237628300).
DadaCap commented 2026-11-28 10:47:15 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by DadaCap on 2026-11-28T10:47:15Z.


Merged, thank you @syfyra!

What it does: dds_png: pick the BC4/BC5 SNORM ramp from the stored endpoints (DDS-PNG-SNORM-MODE)

How it was checked: sodove tested this PR at head 9797ec66a on main 33db04a70: the PR's own test fails on main and passes with this PR merged in (his result is linked from the batch summary in #1608). We then re-ran the same test locally on Windows 11 and got the same verdict: on main, red (2 failures); with the PR, green (101 OK).

CI: the red jobs on this PR fail the same way on main, or on the older main it was built on (the cs_dpp_cmp.asm translator fixture, since fixed on main, and the Windows runner's Visual Studio setup), so none comes from this change.

Merged one by one with 20 other PRs of the same reviewed batch, pinned to the tested head.

AI-assisted (Claude Code, Claude Opus 5.5), posted for the maintainers.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7238121720 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2084#issuecomment-7238121720). Originally posted by [DadaCap](https://github.com/DadaCap) on 2026-11-28T10:47:15Z. --- Merged, thank you @syfyra! **What it does:** dds_png: pick the BC4/BC5 SNORM ramp from the stored endpoints (DDS-PNG-SNORM-MODE) **How it was checked:** sodove tested this PR at head `9797ec66a` on main `33db04a70`: the PR's own test fails on main and passes with this PR merged in (his result is linked from the batch summary in #1608). We then re-ran the same test locally on Windows 11 and got the same verdict: on main, red (2 failures); with the PR, green (101 OK). **CI:** the red jobs on this PR fail the same way on main, or on the older main it was built on (the `cs_dpp_cmp.asm` translator fixture, since fixed on main, and the Windows runner's Visual Studio setup), so none comes from this change. Merged one by one with 20 other PRs of the same reviewed batch, pinned to the tested head. AI-assisted (Claude Code, Claude Opus 5.5), posted for the maintainers.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!2084
No description provided.