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

Open
opened 2026-11-26 21:20:00 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/2084
Author: @syfyra
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: fix/dds-png-bc4-snorm-mode


📝 Commits (1)

  • 9797ec6 dds_png: pick the BC4/BC5 SNORM ramp from the stored endpoints (DDS-PNG-SNORM-MODE)

📊 Changes

2 files changed (+24 additions, -8 deletions)

View changed files

📝 tests/test_dds_png.py (+15 -0)
📝 tools/dds_png.py (+9 -8)

📄 Description

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


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/2084 **Author:** [@syfyra](https://github.com/syfyra) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/dds-png-bc4-snorm-mode` --- ### 📝 Commits (1) - [`9797ec6`](https://github.com/ubiquitarianism/leonida/commit/9797ec66a1afc092aa64ce4304860af1f18185c7) dds_png: pick the BC4/BC5 SNORM ramp from the stored endpoints (DDS-PNG-SNORM-MODE) ### 📊 Changes **2 files changed** (+24 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_dds_png.py` (+15 -0) 📝 `tools/dds_png.py` (+9 -8) </details> ### 📄 Description 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) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#2090
No description provided.