Skip to content

ritmo-tools pixel: read the grid on the subject, and never call an upscale 1x art - #226

Merged
SandroMaglione merged 2 commits into
mainfrom
tools/pixel-grid-subject
Nov 11, 2026
Merged

SandroMaglione merged 2 commits into
mainfrom
tools/pixel-grid-subject

Conversation

@SandroMaglione

Copy link
Copy Markdown
Member

Two fixes to pixel check / pixel fix grid detection, found by scoring the fixer on xprite-pixelate's benchmark (MIT) and pixel-bench v1 (MIT), through checkImage, the path the CLI runs.

What changes

  1. The grid is read on the subject (detectGrid in grid.ts). It finds the box holding the subject: its visible pixels, or, on an opaque picture whose border is one color, the pixels away from that color. It keeps a 4 px margin, so the outline stays where the edge profiles see it. It detects there, then shifts the offsets back onto the whole picture. Output size and recipes are unchanged.
  2. An upscale is not pixel art at its own size (isNative in report.ts). If under 5% of neighbouring pixels change color and the picture has more than 32 colors, it is judged as a fix. A grid that can't be found now reports needs-person instead of clean at full size. The color limit keeps flat parallax layers counted as 1× art.

Evidence (exact size)

main this PR
AI suite (1746 cases + 98 sparse-on-white cases I added) 65.0% 76.0%
Small sprite on a clear canvas 24.0% 99.0%
Small sprite on an off-white canvas 25.5% 95.9%
pixel-bench v1 (7651 cases) 38.2% 40.1%
v1: wrong size but trusted (fixable/clean) 4168 2889
AI suite: upscales wrongly called 1× art 200 4

Rows for this PR use the crop as measured before the 4 px margin was added. On a 722-case sample, the margin moved exact sizes by under a point.

Real 1× art: 165 of 178 corpus images were left alone before and 170 after. 280 shipped PNGs from Still Time, Landkeep and Spirit Call give identical verdicts. The crop measured alone won 211 AI cases and lost 15.

Known limits

  • Cells under about 5 px are still not detected well. Clean 2–3× upscales stay the main gap on pixel-bench v1 (xprite 87%). Few-colour ones are still reported clean.
  • Drift (cells that grow across the picture) is not addressed here. A prototype of cuts that walk cell to cell did well on AI pictures but needs a full-suite run first.
  • The gate's thresholds (5%, 32 colors) were set on this corpus. When the gate is wrong, the result is needs-person, never a bad fix.

Tests

  • New tests: a sprite on a much larger clear canvas, on an off-white canvas, and a drifting upscale whose grid is not found. All three fail on main.
  • A flat few-color picture stays 1× art (guards the color limit).
  • pnpm run check passes. No public TypeScript API changed, so no website build.

🤖 Generated with Claude Code

SandroMaglione and others added 2 commits November 11, 2026 16:39
…scale 1x art

detectGrid now finds the cell size on the picture's subject (its visible
pixels, or the pixels away from a uniform border color, with a 4 px margin)
and places the grid back on the whole picture. An empty canvas around a
small sprite made every cell size look clean.

isNative no longer takes a smooth picture with many colors (an upscale
whose grid was not found) as pixel art at its own size, so check reports
needs-person instead of clean at the picture's full size.

Measured with xprite-pixelate's benchmark and pixel-bench v1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@SandroMaglione
SandroMaglione merged commit 4b3e3a5 into main Nov 11, 2026
5 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.

1 participant