Skip to content

Generate clean 2D game sprites & animation atlases — component-row pipeline: state rows, alpha cleanup, frame extraction, runtime atlases. Codex/Claude skill.

docs(chroma): the border rule is looser than the interior rule; CHANGELOG Unreleased (v2.1.2)

Soohong Kim659d98daa563
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a283cf5..cbd1c25 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,11 @@
All notable public changes to `sprite-gen` are recorded here. Versions track the `version:` field in `SKILL.md` and `pyproject.toml`.
+## Unreleased (v2.1.2)
+
+- The flat-border colour that decides the painted key no longer has to balance its keyed channels. Grok paints `#FF00FF` as (216, 46, 147) / (225, 52, 155) / (236, 59, 161) — blue/red ≈ 0.68, under the 0.8 balance the interior family rule (`is_key_family`) demands — so `detect_background_key_rgb` fell back to the declared key and, at ~120 from pure magenta, the whole background survived (2026-09-11 rev3 objects). A border is already background evidence: the new border rule `is_border_key_candidate` (keyed channels lit, unkeyed channels dark and under 35 % of the brightest keyed one — a superset of `is_key_family`) is the one function `detect_background_key_rgb`, `cutout --key auto`, `video-canvas --key` and the `video-frames` residual/subject split classify the border with. The interior rule is unchanged; hot pink (250, 77, 150) and purple (213, 112, 246) inside the subject still survive.
+- The painted key's erase ball is bounded by the background it came from: it erases the pixels that carry the key's hue signature plus whatever inside the ball is 8-connected to them (the antialiased rim), not an isolated look-alike patch inside the subject — hot pink sits 46 from Grok's magenta and would otherwise have been cut out. The declared key's ball stays position-blind. The 96 radius is unchanged.
+
## v2.1.1 - Chroma keying follows the painted background
- Chroma keying measures the key distance from the background colour the generator actually painted (detected from the flat borders, `detect_background_key_rgb`) as well as from the pure key, in `cutout`, `extract`, `slice-sheet` and `video-frames`. Image models paint `#00FF00` as (8, 162, 24) and darker; that colour sat on the 96 radius from pure green and keyed half-and-half pixel by pixel. The radius is unchanged. Reports carry `chroma_key_painted`. Documented cost: key-family dark subject colours are erased on darker painted backgrounds — choose the key away from the subject's hues.
diff --git a/docs/chroma-alpha.md b/docs/chroma-alpha.md
index 00e8058..228b5c1 100644
--- a/docs/chroma-alpha.md
+++ b/docs/chroma-alpha.md
@@ -46,6 +46,8 @@ The close-up crops below show the edge detail behind the full-body comparisons.
- Blue subjects → avoid cyan/blue keys; magenta or green.
- Both pink *and* green in one subject → pick the key farther from the larger/more important material, verify both survive after extraction, and prefer `--chroma-key auto` (distance-scored).
+**The border and the interior answer different questions** (2026-09-12). `detect_background_key_rgb` classifies the border samples with `is_border_key_candidate` — keyed channels lit, unkeyed channels dark (< 64) and under 35 % of the brightest keyed channel, no balance between the keyed channels — because a flat border is already background evidence: Grok paints `#FF00FF` as (216, 46, 147), blue/red 0.68, which the interior rule `is_key_family` (balance ≥ 0.8) rejected, so the detector fell back to the declared key and the whole background survived. The interior rule keeps the balance so hot pink (250, 77, 150) and purple (213, 112, 246) inside the subject stay byte-identical; they fail the border rule too, on the lit green channel. The painted key's erase ball only reaches pixels that carry the signature or are 8-connected to them through the ball (the antialiased rim) — an isolated look-alike patch inside the subject is not erased. `cutout --key auto`, `video-canvas --key` and the `video-frames` residual split use the same border function.
+
## `--chroma-key auto`
When unsure, let `--chroma-key auto` sample the base. It excludes the detected flat opaque chroma background from subject scoring, then scores candidates by distance from the remaining subject pixels. `auto` refuses a key whose nearest subject pixel falls inside the erase radius when a safer candidate exists, records candidate `score`, `min_subject_distance`, `clears_erase_radius`, and `background` metadata in the request, and warns (stderr) when no candidate clears the subject — so a small but critical feature (eyes, a gem, an ear lamp) under 1% of the pixels is not silently deleted. Only force a key when you know the subject hue is safely far from it. Verify after extraction that the dominant subject color survived — a black-where-it-should-be-colored frame means the key was adjacent to the subject.
diff --git a/docs/video-pipeline.md b/docs/video-pipeline.md
index d06f556..aceb886 100644
--- a/docs/video-pipeline.md
+++ b/docs/video-pipeline.md
@@ -82,6 +82,27 @@ a (8, 162, 24) green sat at distance 96.38 from pure green while (7, 163, 24) sa
leftover background as a clipped subject. The report records `chroma_key_painted` per
frame.
+**The border is classified by a looser rule than the interior** (2026-09-12). The
+detector's "hue family" test used to be `extract.is_key_family`, the interior rule, whose
+two-channel balance (the dimmer keyed channel ≥ 0.8 of the brighter) exists to keep hot
+pink (250, 77, 150) and purple (213, 112, 246) alive *inside* the subject. Grok paints
+`#FF00FF` as (216, 46, 147) / (225, 52, 155) — blue/red ≈ 0.68 — so that rule said "not
+the key" for a colour that filled the whole border, the detector fell back to the declared
+key, and at ~120 from pure magenta the entire background survived. A flat border is
+already evidence of *background*, so the border rule `extract.is_border_key_candidate`
+drops the balance and keeps the hue signature: every keyed channel lit (≥ 64), every
+unkeyed channel dark (< 64) and under 35 % of the brightest keyed channel. It is a
+superset of the interior rule (family ∪ signature), so nothing the old detector found is
+lost, and hot pink / purple fail it on a different axis (their green channel is lit). One
+function classifies the border everywhere — `detect_background_key_rgb`, `cutout --key
+auto`, `video-canvas --key` and the edge-contact split below. The interior rule is
+untouched. And because the painted colour's authority is border evidence, its erase ball
+is bounded by the background it came from: it erases the signature pixels plus whatever
+inside the ball is 8-connected to them (the antialiased rim, whose blend with a lit
+subject colour lifts the unkeyed channel over the bar), never an isolated look-alike patch
+inside the subject — hot pink sits 46 from Grok's magenta. The declared key's ball stays a
+colour ball, position-blind.
+
Two consequences worth knowing. Dark outline halo (the antialiased blend between subject
and a dark-painted key) is now erased with the background — on the three 2026-09-11
walk clips that was outline pixels only (0 newly opaque, interior holes ≤ 7 px per