[PR #2325] calibrated_texture: crop NPOT mips to the DDS grid (CALIBRATED-TEXTURE-NPOT-DDS) #2329

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

📋 Pull Request Information

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

Base: main ← Head: fix/calibrated-texture-npot-dds


📝 Commits (1)

  • a80bb68 calibrated_texture: crop NPOT mips to the DDS grid (CALIBRATED-TEXTURE-NPOT-DDS)

📊 Changes

2 files changed (+57 additions, -2 deletions)

View changed files

📝 tests/test_calibrated_texture_extra.py (+44 -0)
📝 tools/calibrated_texture.py (+13 -2)

📄 Description

Claimed in the coordination issue as: CALIBRATED-TEXTURE-NPOT-DDS (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7193838373)

What and why

tools/calibrated_texture.py LocalDecoder.dds (the --calibration export) wrote every block of a mip's stored grid under a standard DDS header. For NPOT chains the stored grid can be wider or taller than the DDS mip, which is the case ttpf_mips._visible_rows exists for in the regular export:

  • Compact chains. 17x13 BC1 stores its 8x6 mip 1 as 3x2 blocks; DDS holds 2x2. The payload was 208 bytes instead of 192, and a reader took blocks (0,0) (1,0) (2,0) (0,1) as mip 1. ASSET-568 moved this branch to the stored grid to get the offsets right and dropped the crop; its test checks compact_dds_layout's return values, not the payload.
  • Mode-1 arrays. This branch kept the DDS grid, but addresses() takes its tile pitch from the grid it is given. A 513x520 BC7 array stores mip 1 as 65x65 blocks (two 64-block tiles per row) where DDS holds 64x65, so rows 64 and on were read from the wrong tile (128 blocks differ per export).

Each mip is now read on its stored grid, which also sets the tile pitch, and cropped to the DDS rows and columns. Aligned textures are unchanged (the crop is skipped when the grids match). For both cases above the export is now byte-identical to ttpf_mips.texture_dds.

Tested

Windows 11, Python 3.14.7, synthetic pools only (numpy is not installed here, so the test runs on the file's own numpy stand-in; CI's numpy job runs it with numpy):

  • python -I tests/test_calibrated_texture_extra.py: the new TestLocalDecoder.test_dds_npot_mips_are_cropped_to_the_dds_grid writes a 17x13 BC1 chain and a 2-slice 513x520 BC7 mode-1 array whose every block holds its own (slice, mip, x, y) and compares the export with the DDS rows of each mip. On main both cases fail (208 != 192; block 20866 is (0, 1, 64, 0) instead of (0, 1, 0, 64)); with the fix both pass. 30 of 31 tests pass; test_export_file_replacement_failure_cleans_temporary_file fails on main as well (claimed in #1608, open #2101).
  • tests/test_calibrated_texture.py (skips without numpy), tests/test_ttpf_mips.py (93), tests/test_ttpf_assets.py (31), tests/test_tool_startup.py OK.
  • python -m compileall; scripts/check_no_game_data.py on both files.

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

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/2325 **Author:** [@syfyra](https://github.com/syfyra) **Created:** 11/26/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/calibrated-texture-npot-dds` --- ### 📝 Commits (1) - [`a80bb68`](https://github.com/ubiquitarianism/leonida/commit/a80bb68f75918ca3faf711b7da78030157ece700) calibrated_texture: crop NPOT mips to the DDS grid (CALIBRATED-TEXTURE-NPOT-DDS) ### 📊 Changes **2 files changed** (+57 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_calibrated_texture_extra.py` (+44 -0) 📝 `tools/calibrated_texture.py` (+13 -2) </details> ### 📄 Description Claimed in the coordination issue as: CALIBRATED-TEXTURE-NPOT-DDS (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7193838373) ### What and why `tools/calibrated_texture.py` `LocalDecoder.dds` (the `--calibration` export) wrote every block of a mip's stored grid under a standard DDS header. For NPOT chains the stored grid can be wider or taller than the DDS mip, which is the case `ttpf_mips._visible_rows` exists for in the regular export: - **Compact chains.** 17x13 BC1 stores its 8x6 mip 1 as 3x2 blocks; DDS holds 2x2. The payload was 208 bytes instead of 192, and a reader took blocks (0,0) (1,0) (2,0) (0,1) as mip 1. ASSET-568 moved this branch to the stored grid to get the offsets right and dropped the crop; its test checks `compact_dds_layout`'s return values, not the payload. - **Mode-1 arrays.** This branch kept the DDS grid, but `addresses()` takes its tile pitch from the grid it is given. A 513x520 BC7 array stores mip 1 as 65x65 blocks (two 64-block tiles per row) where DDS holds 64x65, so rows 64 and on were read from the wrong tile (128 blocks differ per export). Each mip is now read on its stored grid, which also sets the tile pitch, and cropped to the DDS rows and columns. Aligned textures are unchanged (the crop is skipped when the grids match). For both cases above the export is now byte-identical to `ttpf_mips.texture_dds`. ### Tested Windows 11, Python 3.14.7, synthetic pools only (numpy is not installed here, so the test runs on the file's own numpy stand-in; CI's numpy job runs it with numpy): - `python -I tests/test_calibrated_texture_extra.py`: the new `TestLocalDecoder.test_dds_npot_mips_are_cropped_to_the_dds_grid` writes a 17x13 BC1 chain and a 2-slice 513x520 BC7 mode-1 array whose every block holds its own (slice, mip, x, y) and compares the export with the DDS rows of each mip. On `main` both cases fail (`208 != 192`; block 20866 is (0, 1, 64, 0) instead of (0, 1, 0, 64)); with the fix both pass. 30 of 31 tests pass; `test_export_file_replacement_failure_cleans_temporary_file` fails on `main` as well (claimed in #1608, open #2101). - `tests/test_calibrated_texture.py` (skips without numpy), `tests/test_ttpf_mips.py` (93), `tests/test_ttpf_assets.py` (31), `tests/test_tool_startup.py` OK. - `python -m compileall`; `scripts/check_no_game_data.py` on both files. GPUs tested: n/a (CPU-only tool) 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#2329
No description provided.