Skip to content

Fix garbled .BIN renders: derive width from SAUCE FileType, infer height from data#2

Merged
grymmjack merged 2 commits into
mainfrom
claude/garbled-33-n1-bin-uxzkh5
Jun 30, 2026
Merged

Fix garbled .BIN renders: derive width from SAUCE FileType, infer height from data#2
grymmjack merged 2 commits into
mainfrom
claude/garbled-33-n1-bin-uxzkh5

Conversation

@grymmjack

@grymmjack grymmjack commented Jun 30, 2026

Copy link
Copy Markdown
Owner

Problem

1995/33-pic95/33-N1.BIN rendered garbled — recognizable text sheared diagonally across the canvas. Classic wrong-canvas-dimension symptom. While fixing it I audited the whole text-mode dimension path and found a second latent bug of the same class.

Fix 1 — BIN width (the reported bug)

Header-less .BIN files are SAUCE DataType 5 (BinaryText), which encodes the canvas width as FileType × 2 (there's no header width field). Sauce::char_width() only handled DataType 1 (Character art, width in TInfo1), so it returned None for any .BIN and bin.rs fell back to its 160-column default.

For this piece the real width is 500 columns (FileType 250 → 500). Rendered at 160 wide, each 500-cell source row wraps across ~3.1 canvas rows → the diagonal shear. Verified by the data: 37,500 cells ÷ 500 = exactly 75 rows (matching the SAUCE line count, TInfo2 = 75); ÷ 160 = a fractional 234.375.

Added a BinaryText branch to char_width() (DataType 1 → TInfo1 unchanged; DataType 5 → FileType × 2). This matches ansilove, which is what 16colo.rs renders with.

Fix 2 — BIN height (found during the audit)

bin.rs trusted SAUCE TInfo2 for the row count. A raw .BIN is an uncompressed (char, attr) stream, so its height is authoritative from the byte count, and ansilove computes rows = bytes/2/width, ignoring TInfo2 for BIN. A stale or garbage TInfo2 would otherwise pad the canvas with blank rows or clip the art — the same wrong-dimension trap as the width default. Now inferred from the data, which also matches every other binary decoder here (IDF / ADF / Tundra all infer height from the data).

Audit notes (no change needed)

  • XBin carries its own width/height in the header — correct.
  • Tundra uses char_width() (DataType 1, FileType 8) → now also benefits from the consolidated logic; height from max_row. Correct.
  • IDF width = x1 + 1 from header; height inferred. Correct.
  • ADF fixed 80-wide; height inferred. Correct.

Tests

  • binarytext_width_comes_from_filetype_times_two (sauce.rs): FileType 250 → width 500.
  • binarytext_filetype_sets_width_and_height_is_inferred (bin.rs): end-to-end — FileType → width × 2, height inferred, a bogus TInfo2 = 99 ignored.

Full suite green (164 passed, 11 ignored network/trash); clippy clean.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Cdcq8oRES3RSyL1nyhwoeF

claude added 2 commits June 30, 2026 15:58
Header-less .BIN files (SAUCE DataType 5, BinaryText) carry their canvas
width as FileType × 2, not in TInfo1. char_width() only handled
Character-type art (DataType 1), so every non-160-wide .BIN fell back to
the 160-column default and sheared diagonally (e.g. 1995/33-pic95/33-N1.BIN
is 500 columns: FileType 250 → 500, 37500 cells / 500 = exactly 75 rows,
matching its SAUCE line count).

Add a BinaryText branch to char_width() and a regression test.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Cdcq8oRES3RSyL1nyhwoeF
A raw .BIN is an uncompressed (char, attr) stream, so its row count is
authoritative from the byte count — and ansilove (what 16colo.rs renders
with) computes rows = bytes/2/width, ignoring TInfo2 for BIN. Trusting a
stale or garbage TInfo2 could pad the canvas with blank rows or clip the
art, the same wrong-dimension trap as the width default just fixed. This
also matches every other binary decoder here (IDF/ADF/Tundra all infer
height from the data).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Cdcq8oRES3RSyL1nyhwoeF
@grymmjack grymmjack changed the title Fix sheared .BIN render by deriving width from SAUCE FileType Fix garbled .BIN renders: derive width from SAUCE FileType, infer height from data Jun 30, 2026
@grymmjack grymmjack marked this pull request as ready for review June 30, 2026 18:51
@grymmjack grymmjack merged commit 0091135 into main Jun 30, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants