feat(cli): decode and export BC3, BC4, BC5 and BC7 textures #12

Manually merged
github merged 1 commit from gh-pr/12/head into gh-pr/12/base 2026-11-26 18:56:12 +00:00
Owner

@⁠brainbudt on GitHub · 2026-11-26 05:46 UTC · original
brainbudt:feat/bc3-bc4-bc5-bc7-cli → master · +455 −86 · 12 files · 1 commits · merged 2026-11-26 06:02 UTC

Problem

The Rust library can rebuild BC3, BC4, BC5 and BC7 blocks, but the CLI and whole-texture exporter only expose BC1. The synthetic stream generator also lacks fixtures that exercise the other four formats end to end.

Change

  • Add decode-bc3, decode-bc4, decode-bc5 and decode-bc7 subcommands, plus --format for symbols and bench (BC1 remains the default).
  • Extend ttpf-export to detile mip 0 and write DDS for all four formats, using a DX10 header that preserves the source DXGI type (including signed and sRGB variants). BC1 retains its legacy DXT1 output.
  • Generate deterministic synthetic streams in src/encode.rs for the new formats and exercise them through block reconstruction, the CLI and DDS export in tests/modes.rs.
  • Use explicit wrapping addition for BC1 index reconstruction to fix a reproduced debug overflow while preserving existing golden outputs, and clean up five decoder loops for strict Clippy.

Scope

PNG export, store scanning and the Python reference remain BC1-only. BC6H block reconstruction remains open pending verified format semantics. All fixtures are synthetic; no dependencies or game data are added.

Verification

  • macOS ARM64 and Linux x86-64 both passed cargo test --release (28 tests each) and cargo clippy --all-targets -- -D warnings.
  • macOS ARM64 also passed cargo test (28 tests) and cargo test --no-default-features (23 tests).
  • Synthetic tests compare lane symbols, rebuilt blocks, cropped mip-tail bytes and DDS headers for 4 KiB and 64 KiB tiles. Retail mip-0 detiling parity for the four added formats remains unverified.

Reviewed with mistral-loop: APPROVE (1 round, mistral-large-4-0 + deepseek-v4-1-flash-1017).
Created with gpt-6.2-astra in Codex (orchestrated with Gemini 4 Neon in T3 Code).

Summary by CodeRabbit

  • New Features
    • Added decoding and whole-texture DDS export for BC3, BC4, BC5, and BC7 alongside BC1.
    • Added format selection for decoding, symbol output, and benchmarks.
    • Expanded synthetic encoding and format-aware mip processing for supported formats.
    • PNG export remains available for BC1 only.
  • Bug Fixes
    • Prevented pixel-position arithmetic from overflowing during BC1 decoding.
  • Documentation
    • Updated format support status and command examples.
**@⁠brainbudt** on GitHub · 2026-11-26 05:46 UTC · [original](https://github.com/Ahmet-Dedeler/bcpack-rs/pull/12) `brainbudt:feat/bc3-bc4-bc5-bc7-cli` → `master` · +455 −86 · 12 files · 1 commits · merged 2026-11-26 06:02 UTC ## Problem The Rust library can rebuild BC3, BC4, BC5 and BC7 blocks, but the CLI and whole-texture exporter only expose BC1. The synthetic stream generator also lacks fixtures that exercise the other four formats end to end. ## Change - Add `decode-bc3`, `decode-bc4`, `decode-bc5` and `decode-bc7` subcommands, plus `--format` for `symbols` and `bench` (BC1 remains the default). - Extend `ttpf-export` to detile mip 0 and write DDS for all four formats, using a DX10 header that preserves the source DXGI type (including signed and sRGB variants). BC1 retains its legacy DXT1 output. - Generate deterministic synthetic streams in `src/encode.rs` for the new formats and exercise them through block reconstruction, the CLI and DDS export in `tests/modes.rs`. - Use explicit wrapping addition for BC1 index reconstruction to fix a reproduced debug overflow while preserving existing golden outputs, and clean up five decoder loops for strict Clippy. ## Scope PNG export, store scanning and the Python reference remain BC1-only. BC6H block reconstruction remains open pending verified format semantics. All fixtures are synthetic; no dependencies or game data are added. ## Verification - macOS ARM64 and Linux x86-64 both passed `cargo test --release` (28 tests each) and `cargo clippy --all-targets -- -D warnings`. - macOS ARM64 also passed `cargo test` (28 tests) and `cargo test --no-default-features` (23 tests). - Synthetic tests compare lane symbols, rebuilt blocks, cropped mip-tail bytes and DDS headers for 4 KiB and 64 KiB tiles. Retail mip-0 detiling parity for the four added formats remains unverified. --- Reviewed with mistral-loop: APPROVE (1 round, `mistral-large-4-0` + `deepseek-v4-1-flash-1017`). Created with gpt-6.2-astra in Codex (orchestrated with Gemini 4 Neon in T3 Code). <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **New Features** * Added decoding and whole-texture DDS export for BC3, BC4, BC5, and BC7 alongside BC1. * Added format selection for decoding, symbol output, and benchmarks. * Expanded synthetic encoding and format-aware mip processing for supported formats. * PNG export remains available for BC1 only. * **Bug Fixes** * Prevented pixel-position arithmetic from overflowing during BC1 decoding. * **Documentation** * Updated format support status and command examples. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 18:56:12 +00:00
github manually merged commit 1675fb676b into gh-pr/12/base 2026-11-26 18:56:12 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-26 05:47 UTC · original · edited 2026-11-26 05:55 UTC

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The change adds mode-based chunk decoding and synthetic encoding, extends CLI commands to BC1, BC3, BC4, BC5, and BC7, and generalizes texture mip processing and DDS export for those formats. Tests cover stream round trips, texture handling, DDS output, and CLI behavior.

Changes

Multi-format support

Layer / File(s) Summary
Mode-based streams and assembly
src/format.rs, src/encode.rs, src/bc1.rs, src/bc7.rs, src/bcn.rs
The synthetic encoder and symbol decoder now use format modes. Supporting assembly code uses iterator-based updates, and add_lines uses wrapping addition.
Chunk block reconstruction
src/lib.rs
The public decode_chunk function returns rebuilt blocks and decode diagnostics. It uses format-specific tables and rejects BC6H.
Multi-format CLI
src/main.rs, README.md
The CLI supports format-specific decoding and format selection for symbols and bench. README status information and examples describe the supported formats and commands.
Format-aware texture decoding and DDS export
src/ttpf.rs, src/texture.rs, src/main.rs
Mip layout and detiling use the selected format. Texture decoding and DDS export support the listed DXGI formats; PNG export remains limited to BC1.
Multi-format tests and findings
tests/modes.rs, docs/findings/bc345-bc7.md
Tests cover synthetic stream round trips, mip-tail extraction, DDS output, and CLI behavior. The findings document records that retail mip 0 detiling parity remains unverified.

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant CLI as bcpack CLI
  participant Decode as cmd_decode
  participant Chunk as decode_chunk
  participant Mode as Mode::decode_symbols
  CLI->>Decode: selected format and chunk input
  Decode->>Chunk: mode, chunk, block count, tables
  Chunk->>Mode: chunk and block count
  Mode-->>Chunk: decoded lane symbols
  Chunk-->>Decode: DecodedChunk
  Decode-->>CLI: decoded output and status

Suggested reviewers: ahmet-dedeler

Merge Risk: Minimal · up to 1675f

The change adds BC3, BC4, BC5 and BC7 decoding and DDS export alongside the existing BC1 behavior. BC1 output and defaults are preserved. Retail-texture parity for the new formats is not yet verified, which the PR documents. No concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "feat(cli): decode and export BC3, BC4, BC5 and BC7 textures" matches the main change. The raw summary and objectives show CLI decoding for BC3, BC4, BC5, and BC7, a --format option for symb…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "feat(cli): decode and export BC3, BC4, BC5 and BC7 textures" matches the main change. The raw summary and objectives show CLI decoding for BC3, BC4, BC5, and BC7, a --format option for symbols and bench, and DDS export of those formats. The title is specific and short. It does not mention the BC1 window-overflow fix, the synthetic test encoder, or the new decode_chunk API, which is expected for a title.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 512df6e2-c555-4b18-ba0a-a7fdcdfde47c
Commits

Reviewing files that changed from the base of the PR and between 577bf3d852 and 1675fb676b.

Files selected for processing: 12

  • README.md
  • docs/findings/bc345-bc7.md
  • src/bc1.rs
  • src/bc7.rs
  • src/bcn.rs
  • src/encode.rs
  • src/format.rs
  • src/lib.rs
  • src/main.rs
  • src/texture.rs
  • src/ttpf.rs
  • tests/modes.rs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-11-26 05:47 UTC · [original](https://github.com/Ahmet-Dedeler/bcpack-rs/pull/12#issuecomment-7183802409) · edited 2026-11-26 05:55 UTC <!-- coderabbit-ai-generated:v1 --> <!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- review_stack_entry_start --> <a href="https://app.coderabbit.ai/change-stack/Ahmet-Dedeler/bcpack-rs/pull/12?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&amp;cs_source=review_comment"><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-buttons-v1/explain-change-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-buttons-v1/explain-change.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-buttons-v1/explain-change.svg" alt="Explain Change →" height="32"></picture></a> <!-- review_stack_entry_end --> <!-- recent_review_status_start --> No actionable comments were generated in the recent review. <!-- recent_review_status_end --> <!-- walkthrough_start --> ### Walkthrough The change adds mode-based chunk decoding and synthetic encoding, extends CLI commands to BC1, BC3, BC4, BC5, and BC7, and generalizes texture mip processing and DDS export for those formats. Tests cover stream round trips, texture handling, DDS output, and CLI behavior. ### Changes **Multi-format support** |Layer / File(s)|Summary| |:---|:---| |**Mode-based streams and assembly** <br> `src/format.rs`, `src/encode.rs`, `src/bc1.rs`, `src/bc7.rs`, `src/bcn.rs`|The synthetic encoder and symbol decoder now use format modes. Supporting assembly code uses iterator-based updates, and `add_lines` uses wrapping addition.| |**Chunk block reconstruction** <br> `src/lib.rs`|The public `decode_chunk` function returns rebuilt blocks and decode diagnostics. It uses format-specific tables and rejects BC6H.| |**Multi-format CLI** <br> `src/main.rs`, `README.md`|The CLI supports format-specific decoding and format selection for `symbols` and `bench`. README status information and examples describe the supported formats and commands.| |**Format-aware texture decoding and DDS export** <br> `src/ttpf.rs`, `src/texture.rs`, `src/main.rs`|Mip layout and detiling use the selected format. Texture decoding and DDS export support the listed DXGI formats; PNG export remains limited to BC1.| |**Multi-format tests and findings** <br> `tests/modes.rs`, `docs/findings/bc345-bc7.md`|Tests cover synthetic stream round trips, mip-tail extraction, DDS output, and CLI behavior. The findings document records that retail mip 0 detiling parity remains unverified.| <!-- change_assessment_start --> **Estimated code review effort:** 4 (Complex) | ~45 minutes <!-- change_assessment_commit:"1675fb676bbc3877c8283591164def6cb3c57fab" --> <!-- change_assessment_priority:{"version":1,"urgency":"p2","manual":false} --> Change: Feature <!-- change_assessment_end --> ### Sequence Diagram(s) ```mermaid sequenceDiagram participant CLI as bcpack CLI participant Decode as cmd_decode participant Chunk as decode_chunk participant Mode as Mode::decode_symbols CLI->>Decode: selected format and chunk input Decode->>Chunk: mode, chunk, block count, tables Chunk->>Mode: chunk and block count Mode-->>Chunk: decoded lane symbols Chunk-->>Decode: DecodedChunk Decode-->>CLI: decoded output and status ``` Suggested reviewers: `ahmet-dedeler` <!-- walkthrough_end --> <details> <summary><strong>Merge Risk:</strong> <strong><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/risk-unassessed-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Minimal</strong> · up to <code>1675f</code></summary> <dl> <dd> <br> <!-- final_review_risk_start --> <!-- final_review_risk_label **Merge Risk:** **⚪ Minimal** · up to `1675f` --> <!-- final_review_risk_coverage:{"sourceCommitId":"1675fb676bbc3877c8283591164def6cb3c57fab","coveredCommitId":"1675fb676bbc3877c8283591164def6cb3c57fab","kind":"reviewed"} --> The change adds BC3, BC4, BC5 and BC7 decoding and DDS export alongside the existing BC1 behavior. BC1 output and defaults are preserved. Retail-texture parity for the new formats is not yet verified, which the PR documents. No concrete merge-blocking risk was found. <!-- final_review_risk_end --> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_start --> <details> <summary><strong>Pre-merge checks: <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v2.svg" width="14" height="14" align="middle" alt="Passed" title="Passed"></picture></sup> 4</strong></summary> <dl> <dd> <br> | Check name | Status | Explanation | | :------------------------ | :--------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Description Check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped - CodeRabbit’s high-level summary is enabled. | | Title check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The title "feat(cli): decode and export BC3, BC4, BC5 and BC7 textures" matches the main change. The raw summary and objectives show CLI decoding for BC3, BC4, BC5, and BC7, a --format option for symb… | | Linked Issues check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | | Out of Scope Changes check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | <details> <summary><strong>Full details: Title check</strong></summary> <dl> <dd> <br> **Explanation** The title "feat(cli): decode and export BC3, BC4, BC5 and BC7 textures" matches the main change. The raw summary and objectives show CLI decoding for BC3, BC4, BC5, and BC7, a --format option for symbols and bench, and DDS export of those formats. The title is specific and short. It does not mention the BC1 window-overflow fix, the synthetic test encoder, or the new decode_chunk API, which is expected for a title. </dd> </dl> </details> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- finishing_touch_checkbox_start --> <details> <summary><strong>Finishing Touches</strong></summary> <dl> <dd> <br> <details open> <summary><strong>Generate unit tests (beta)</strong></summary> <dl> <dd> <br> - [ ] <!-- {"checkboxId": "f47ac10b-58cc-4372-a567-0e02b2c3d479", "radioGroupId": "utg-output-choice-group-unknown_comment_id"} --> Create a new PR </dd> </dl> </details> </dd> </dl> </details> <!-- finishing_touch_checkbox_end --> <!-- autopilot:start --> - [ ] <!-- {"checkboxId":"2708ad07-9f24-4260-9c11-7dc76a49f2e3"} --> <strong title="Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts">Autofix</strong> · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts <!-- autopilot:end --> <!-- tips_start --> Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=Ahmet-Dedeler/bcpack-rs&utm_content=12)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. <details> <summary><strong>Share</strong></summary> <dl> <dd> <br> - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code) </dd> </dl> </details> <!-- tips_end --> <!-- recent_review_start --> <h6> <details> <summary><strong><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/info.svg" width="12" height="12" align="absmiddle" alt=""></picture> Recent review info</strong></summary> <dl> <dd> <br> <!-- review_info_content --> <details> <summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog.svg" width="16" height="16" align="absmiddle" alt=""></picture> Run configuration</strong></summary> <dl> <dd> <br> - **Source mode**: Auto - **Repository**: Unavailable - **Branch**: Unavailable - **File**: No configuration file from this repository applied - **Commit**: Unavailable - **Layers**: Organization UI - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `512df6e2-c555-4b18-ba0a-a7fdcdfde47c` </dd> </dl> </details> <details> <summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal.svg" width="16" height="16" align="absmiddle" alt=""></picture> Commits</strong></summary> <dl> <dd> <br> Reviewing files that changed from the base of the PR and between 577bf3d852451843b309636502e98108f3ac51dd and 1675fb676bbc3877c8283591164def6cb3c57fab. </dd> </dl> </details> <details> <summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner.svg" width="16" height="16" align="absmiddle" alt=""></picture> Files selected for processing: 12</strong></summary> <dl> <dd> <br> * `README.md` * `docs/findings/bc345-bc7.md` * `src/bc1.rs` * `src/bc7.rs` * `src/bcn.rs` * `src/encode.rs` * `src/format.rs` * `src/lib.rs` * `src/main.rs` * `src/texture.rs` * `src/ttpf.rs` * `tests/modes.rs` </dd> </dl> </details> **Included review availability:** This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review. </dd> </dl> </details> </h6> <!-- recent_review_end -->
Author
Owner

@⁠Ahmet-Dedeler on GitHub · 2026-11-26 06:02 UTC · original

Thanks, this is a nice one. Merged into current master and ran it on an M5 Max (macOS 27.3, Rust 1.100): cargo test --release, cargo test and --no-default-features all pass, and the BC1 goldens didn't move.

One note: cargo clippy --all-targets -- -D warnings fails on clippy 0.1.100, but on three needless_range_loops in tests/roundtrip.rs that were already on master before this PR (mine, from #11). Fixing those separately.

**@⁠Ahmet-Dedeler** on GitHub · 2026-11-26 06:02 UTC · [original](https://github.com/Ahmet-Dedeler/bcpack-rs/pull/12#issuecomment-7184034316) Thanks, this is a nice one. Merged into current master and ran it on an M5 Max (macOS 27.3, Rust 1.100): `cargo test --release`, `cargo test` and `--no-default-features` all pass, and the BC1 goldens didn't move. One note: `cargo clippy --all-targets -- -D warnings` fails on clippy 0.1.100, but on three `needless_range_loop`s in `tests/roundtrip.rs` that were already on master before this PR (mine, from #11). Fixing those separately.
This discussion has been locked. Commenting is limited to contributors.
No description provided.