Fix garbled .BIN renders: derive width from SAUCE FileType, infer height from data#2
Merged
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
1995/33-pic95/33-N1.BINrendered 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
.BINfiles are SAUCE DataType 5 (BinaryText), which encodes the canvas width asFileType × 2(there's no header width field).Sauce::char_width()only handled DataType 1 (Character art, width in TInfo1), so it returnedNonefor any.BINandbin.rsfell 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.rstrusted SAUCE TInfo2 for the row count. A raw.BINis an uncompressed(char, attr)stream, so its height is authoritative from the byte count, and ansilove computesrows = 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)
char_width()(DataType 1, FileType 8) → now also benefits from the consolidated logic; height frommax_row. Correct.x1 + 1from header; 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