dds_png: decode R9G9B9E5 shared exponent previews #2218

Closed
github-bot wants to merge 0 commits from github-bot/gh-2218 into main AGit
Owner

@⁠ZroIsHere on GitHub · 2026-11-26 06:40 UTC · original
ZroIsHere:fix/dds-png-r9g9b9e5 → main · +35 −4 · 2 files · 1 commits · closed without merging

Summary

Add DDS preview decoding for DXGI R9G9B9E5_SHAREDEXP (format 67). Expand each 9-bit channel mantissa using the shared 5-bit biased exponent, clamp RGB to [0, 1], round to 8-bit values, and emit opaque alpha.

Validate row pitch and truncated payloads. Update the tex_export.py help text to include this PNG preview format.

Validation

  • git diff --check
  • Python AST parse
  • Tests not run.
**@⁠ZroIsHere** on GitHub · 2026-11-26 06:40 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2218) `ZroIsHere:fix/dds-png-r9g9b9e5` → `main` · +35 −4 · 2 files · 1 commits · closed without merging ## Summary Add DDS preview decoding for DXGI R9G9B9E5_SHAREDEXP (format 67). Expand each 9-bit channel mantissa using the shared 5-bit biased exponent, clamp RGB to [0, 1], round to 8-bit values, and emit opaque alpha. Validate row pitch and truncated payloads. Update the `tex_export.py` help text to include this PNG preview format. ## Validation - `git diff --check` - Python AST parse - Tests not run.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:22:38 +00:00
Author
Owner

@⁠ecox982745 on GitHub · 2026-11-26 07:17 UTC · original

The standalone DDS preview decodes format 67 correctly at d36c961c3e58. The advertised tex_export.py --png path still skips the texture. I tested both commands on Windows with synthetic data and Python 3.13.18, on the CPU.

Check Result
dds_png.py input.dds output.png All 16,384 RGBA pixels matched an independent integer reference. The 512 × 32 fixture exercises every 9-bit mantissa at every shared exponent in each channel, with different channel orderings and 16 padding bytes between rows. Removing the final payload byte produced a truncation error. Parent a73a57e1339b rejected format 67.
tex_headers.py on a synthetic archive Zero textures indexed. The format-name lookup in tools/tex_headers.py (line 818) omits 67.
tex_export.py index.json carve out --png with the same descriptor supplied in the index Exit 0, one unsupported format, no DDS or PNG. The guard at tools/tex_export.py:119 checks a table derived from tex_headers.FMT_INFO, which also omits 67.

I tried two entries locally in tools/tex_headers.py, adding 67: "R9G9B9E5_SHAREDEXP" to DXGI and 67: (4, 1) to FMT_INFO. With the same synthetic 4 KiB tile equation and input, the indexer found one texture and the exporter wrote both files. The DDS payload matched the original packed words byte for byte, and every exported PNG pixel matched the reference. A regression test from indexing through PNG would cover both lookups.

The four existing DDS/export test files passed at the unchanged PR head (250 tests passed, 174 subtests passed, one Windows symlink test skipped).

**@⁠ecox982745** on GitHub · 2026-11-26 07:17 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2218#issuecomment-7185289935) The standalone DDS preview decodes format 67 correctly at `d36c961c3e58`. The advertised `tex_export.py --png` path still skips the texture. I tested both commands on Windows with synthetic data and Python 3.13.18, on the CPU. | Check | Result | | --- | --- | | `dds_png.py input.dds output.png` | All 16,384 RGBA pixels matched an independent integer reference. The 512 × 32 fixture exercises every 9-bit mantissa at every shared exponent in each channel, with different channel orderings and 16 padding bytes between rows. Removing the final payload byte produced a truncation error. Parent `a73a57e1339b` rejected format 67. | | `tex_headers.py` on a synthetic archive | Zero textures indexed. The format-name lookup in `tools/tex_headers.py` (line 818) omits 67. | | `tex_export.py index.json carve out --png` with the same descriptor supplied in the index | Exit 0, one `unsupported format`, no DDS or PNG. The guard at `tools/tex_export.py:119` checks a table derived from `tex_headers.FMT_INFO`, which also omits 67. | I tried two entries locally in `tools/tex_headers.py`, adding `67: "R9G9B9E5_SHAREDEXP"` to `DXGI` and `67: (4, 1)` to `FMT_INFO`. With the same synthetic 4 KiB tile equation and input, the indexer found one texture and the exporter wrote both files. The DDS payload matched the original packed words byte for byte, and every exported PNG pixel matched the reference. A regression test from indexing through PNG would cover both lookups. The four existing DDS/export test files passed at the unchanged PR head (250 tests passed, 174 subtests passed, one Windows symlink test skipped).
Author
Owner

@⁠real-rusher on GitHub · 2026-11-26 10:12 UTC · original

Verified on main a73a57e1 (Ubuntu 24.04 x86-64, Python 3.13, no GPU). Merges cleanly into main, compileall clean.

The PR adds no test, so I checked the decoder with a synthetic 2x2 DX10 DDS (DXGI 67) built by hand: texels (R, G, B mantissa, exponent) = (256, 128, 0, 16), (511, 64, 1, 15), (300, 0, 0, 20) and all zero. tools/dds_png.py writes RGB 255/128/0, 255/32/0, 255/0/0 and 0/0/0 with alpha 255, which matches mantissa * 2^(e - 24) clamped to [0, 1] and rounded half up. main refuses the same file with "Unsupported DXGI format: 67".

Notes for review:

  • A unit test that fails on main would make this mergeable by the CONTRIBUTING.md checklist; the 2x2 case above could be one.
  • It conflicts with #2157 and #2158 (tools/dds_png.py, tools/tex_export.py), which add formats to the same tables, so whichever lands later needs a rebase.

AI-assisted: yes (Claude Code)

**@⁠real-rusher** on GitHub · 2026-11-26 10:12 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2218#issuecomment-7189047932) Verified on main a73a57e1 (Ubuntu 24.04 x86-64, Python 3.13, no GPU). Merges cleanly into main, compileall clean. The PR adds no test, so I checked the decoder with a synthetic 2x2 DX10 DDS (DXGI 67) built by hand: texels (R, G, B mantissa, exponent) = (256, 128, 0, 16), (511, 64, 1, 15), (300, 0, 0, 20) and all zero. tools/dds_png.py writes RGB 255/128/0, 255/32/0, 255/0/0 and 0/0/0 with alpha 255, which matches mantissa * 2^(e - 24) clamped to [0, 1] and rounded half up. main refuses the same file with "Unsupported DXGI format: 67". Notes for review: - A unit test that fails on main would make this mergeable by the CONTRIBUTING.md checklist; the 2x2 case above could be one. - It conflicts with #2157 and #2158 (tools/dds_png.py, tools/tex_export.py), which add formats to the same tables, so whichever lands later needs a rebase. AI-assisted: yes (Claude Code)
github-bot closed this pull request 2026-11-26 17:59:42 +00:00
Author
Owner

@⁠aslan2142 on GitHub · 2026-11-26 18:28 UTC · original

Merged through the integration PR #2394 (DDS preview formats batch), as head d36c961c3, with a merge commit, so your commits stay yours.

Added on top:

  • The tex_export.py --png fix ecox982745 found: tools/tex_headers.py now lists DXGI 67 in DXGI and FMT_INFO. The indexer keeps such textures, and the export reaches your decoder.
  • Tests:
    • a 2x2 decoder test with padded rows and truncation, using real-rusher's texels plus a saturating and a zero-exponent case;
    • an index -> DDS -> PNG test in test_tex_export.py.

Thanks @⁠ZroIsHere, and thanks to ecox982745 and real-rusher for the checks.

AI-assisted (Claude Code, Claude Opus 5.5 and Claude Fable 5.2)

**@⁠aslan2142** on GitHub · 2026-11-26 18:28 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2218#issuecomment-7200512529) Merged through the integration PR #2394 (DDS preview formats batch), as head `d36c961c3`, with a merge commit, so your commits stay yours. Added on top: - **The `tex_export.py --png` fix** ecox982745 found: `tools/tex_headers.py` now lists DXGI 67 in `DXGI` and `FMT_INFO`. The indexer keeps such textures, and the export reaches your decoder. - **Tests:** - a 2x2 decoder test with padded rows and truncation, using real-rusher's texels plus a saturating and a zero-exponent case; - an index -> DDS -> PNG test in `test_tex_export.py`. Thanks @⁠ZroIsHere, and thanks to ecox982745 and real-rusher for the checks. AI-assisted (Claude Code, Claude Opus 5.5 and Claude Fable 5.2)

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.