Skip to content

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

fix(video-loop): a walk's or run's seam is read between its drawings, as its steps are — the seam gate on source frames and on the cells that play, the body anchor's ramp rule, and motion-auto's seam_gate read one reading, the step gate's drawings, so a walk held on twos or threes whose wrap falls between two drawings is no longer refused for the hold

Soohong Kim0c5bf05eaf61
diff --git a/CHANGELOG.md b/CHANGELOG.md
index efab66b..c599f7d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -311,6 +311,13 @@ To get the 2.45.3 frames back, pass:
- **Fix: Windows run dir lock handling.** Every command that writes a run dir (for example `extract`, `compose-atlas`, `export-pngs`, `unpack-atlas`) takes a single-writer lock: the entry `.sprite-gen.lock` inside the run dir. Before this fix, on Windows only, when that name held a link pointing at a file that does not exist, the writer followed the link and made the lock file at the link's target, outside the run dir, and that file was left behind when the writer released the lock; also on Windows only, a folder at that name, a link to a folder, or a link whose target is written with forward slashes ended the command with a bare `OSError` (`EACCES` or `EINVAL`) instead of the named refusal. Now on Windows a link or a folder at that name is refused by name, the same as on macOS and Linux (`run dir lock ... is not a lock file (a link or a folder)`), and nothing is followed, made or removed, while macOS and Linux behave exactly as before. The test is `tests/spec/test_run_dir_lock.py`.
+**Upgrading from 3.0.0: A held walk or run whose wrap fell between two drawings, refused before, may now pass.** A walk drawn a frame each gives the same loop files byte for byte. Reports record `seam_read` (`read`, `drawings`, `hold`) on every walk or run whose seam ratio gates the cut, and `seam_after_anchor` gains the same three fields when cells are read again, with `strip.json` and the failure line of the seam gate unchanged.
+
+- **Behavior change: Walk and run loops gated by their seam ratio now measure the seam between drawings.** For any walk or run whose cut is gated by the seam ratio (neither pinned nor played once), the seam is read between drawings using each drawing's first frame (`loop.seam_drawings`, built on `repair.flow_drawings`), matching the reading used by the step gate. This applies in three places: the seam gate itself, both on source frames (`seam_measurement: source-frames`) and rendered cells (`rendered-cells`); the body anchor ramp rule, reading the wrap and every step between the cells' drawings; and candidate evaluation under `--anchor motion-auto` (`loop.seam_on_cells` through `loop.wrap_on_cells`) when selecting two-step cuts or testing overlapped wrap attempts. Loops showing fewer than three drawings continue to be read on every frame (`seam_read.read: cells`).
+- **Report: Reports record whether the seam gate read frames or drawings.** On every walk or run whose seam ratio gates the cut, `seam_read` records `read` (`cells` or `drawings`), `drawings`, and `hold`. When `--anchor body` ramps cells and triggers a re-read, `seam_after_anchor` records those same three fields for the cells that play, and its `largest_step_into` names the first frame of a drawing. Strip sidecar `strip.json` does not change.
+- **Known limits: Measuring between drawings allows cuts from a third of the stride short to a sixth long on twos, and from a third short to a quarter long on threes, to pass.** On synthetic 24-frame stride walks standing in place, cuts of 16 to 28 frames on twos (ratio 1.02 to 1.67; 30 refused at 2.06) and 16 to 30 frames on threes (0.95 to 1.48) pass the seam gate, whereas drawn on ones cuts of 16 to 22, 28, and 30 are refused (2.38 to 4.07). A shifted final drawing passes up to 2 px on twos (1.66; 3 px refused) and up to 4 px on threes (1.73; 6 px refused). Under `--anchor body` sliding 0.2 px a frame, cuts of 16 to 28 frames pass on twos and 16 to 30 on threes, tolerating shifts of 2 px on twos and 6 px on threes. The step gate already passed these cuts (largest step 1.26 to 1.86), while the earlier frame-by-frame seam gate refused them all. For full synthetic limits and ramp discretization behavior, see `docs/loop-review.md` section "The body anchor and the seam gate".
+- **Tests:** `tests/video/test_held_walk_seam.py`: a held walk cut between its drawings passes the seam gate on twos and threes; a walk drawn a frame each is read on every frame and its ratio is the frames' own; a held walk whose last drawing is moved 10 px is refused between its drawings; a held sliding walk passes on the drawings the ramp plays, and a jump the ramp moves into a held walk is refused as the source frames refuse it; a held walk motion-auto cuts passes on its cells between their drawings (a side walk on twos, a side walker on threes); motion-auto's seam gate reads a held cut between its drawings, and a last drawing with a band of its body gone is over the limit. `tests/video/test_walk_steps.py`: the walker on threes with a tail on its own beat records its tried two-step cut within the seam gate between drawings, declined as out of phase; the search's cut stands as before.
+
## v3.0.0 - Remove rig layer composition
**Upgrading from 2.46.0: `sprite-gen compose-layers` and its other launch forms are removed, and rig layer declarations are no longer read.** `compose-atlas` no longer writes a manifest `rig` block or `animation.rows.<state>.track` for a run that declared a rig. Runs that never declared `rig`, `layers` or a state `track` get the same manifest as before. Existing run files and `layers/` folders stay on disk.
diff --git a/docs/loop-review.md b/docs/loop-review.md
index dd9a416..a86c3c0 100644
--- a/docs/loop-review.md
+++ b/docs/loop-review.md
@@ -53,7 +53,9 @@ limit; otherwise source refusal stands. Passing cuts, `--seam-max 1000` included
not read again, keeping identical bytes.
Only where read again, `seam_after_anchor` records `source_seam_ratio`, `seam_ratio`,
-`largest_step_ratio`, and `largest_step_into` (pass or fail). The ramp closes the wrap
+`largest_step_ratio`, and `largest_step_into` (pass or fail). It also records `read`,
+`drawings`, and `hold` for the cells read again, and its `largest_step_into` is the
+first frame of a drawing. The ramp closes the wrap
of a cut whose frames at the wrap jump sideways and moves the jump a few frames into the
loop; read at the wrap alone, every such cut of the test walk passed (one or two frames
moved 2 to 10 px); a window of steps beside the wrap misses a jump one frame longer than
@@ -66,7 +68,67 @@ does not close. Repaired frames check the wrap alone, a walk whose ordinary step
uneven can read a step over the limit on the cells that play and is refused as before,
and `--anchor feet` reads source frames.
-After this rule, the step gate reads cells between drawings for every walk or run loop that plays round. A known limit on walks held on twos or threes was measured on synthetic side walks sliding 0.1 px a frame, cut one stride by hand with `--anchor body` without repair from six starts each. The seam gate reads frames, not drawings: a cut whose wrap falls between drawings reads wrap 2.13 to 4.87 times the mean step on filmed frames and fails, though between drawings it closes (wrap 0.90 to 1.60). The body anchor rule also reads frame by frame, refusing all cuts on those held walks even where the ramp closed the wrap (cell wrap 0.00 to 1.77), because largest frame steps are 2.48 to 3.43 while cells between drawings step at most 1.32 to 1.70. Those cuts stay refused; reading seam gate and anchor rules between drawings is left to later work. Unheld walks of the same probe were unaffected.
+For any walk or run whose seam ratio gates the cut (neither pinned nor played once), the
+seam is read between the loop's drawings rather than frame by frame, using each drawing's
+first frame (`loop.seam_drawings`, built on `repair.flow_drawings`), the same reading the
+step gate uses. This applies in three places: the seam gate itself, both on
+source frames (`seam_measurement: source-frames`) and on rendered cells (`rendered-cells`:
+`--anchor motion` or `motion-auto`, a frame made by repair, or the body anchor rule); the
+body anchor's ramp rule on the cells that play, reading both the wrap and every step
+between the cells' drawings; and `--anchor motion-auto`'s candidate seam gate before a cut
+is taken (`loop.seam_on_cells` through `loop.wrap_on_cells`), which chooses among two-step
+cuts from foot crossings and judges overlapped wrap attempts. A loop showing fewer than
+three drawings is read on every frame (`seam_read.read: cells`), as the step gate skips
+such loops. A walk drawn a frame each (hold 1) has every frame a drawing, giving the same
+values, the same failure line, and the same loop files byte for byte. Reports record
+`seam_read` (`read`, `drawings`, `hold`) on every walk or run whose seam ratio gates the
+cut; `seam_after_anchor` gains the same three fields for cells read again, and its
+`largest_step_into` is the first frame of a drawing. Strip sidecar `strip.json` and the
+failure line of the seam gate do not change.
+
+On synthetic test frames of a 24-frame stride side walk standing in place, cut one stride
+from a drawing's first frame, the wrap reads 1.02 on twos and 0.95 on threes between drawings
+and passes, where frame-by-frame readings were 2.13 and 3.14 (refused before). When sliding
+0.3 px a frame and cut by hand with `--anchor body`, source frames still read 3.25 (twos)
+and 2.38 (threes) between drawings, but after the ramp moves the wrap back, the cells that
+play read wrap 1.02 and 0.98, and largest step 1.47 and 1.58 between drawings (passes, where
+frame-by-frame cell steps of 2.41 and 3.31 were refused). Under `--anchor motion-auto`, the
+side walk on twos cut at 0/24 reads 1.00 between drawings (2.10 frame by frame), and a second
+side walker on threes reads 0.75 (2.40 frame by frame). For a walker on threes with a big
+tail on its own beat, motion-auto's seam gate read tried two-step cuts at 3.81 to 4.07 frame
+by frame; between drawings the first tried reads 1.35, but it is out of phase by 4.3 frames,
+so the search's own cut stands. Jumps remain refused: a last drawing moved 10 px sideways
+reads 4.10 (twos) and 2.85 (threes) between drawings; on the sliding walk the ramp moves that
+jump into the loop, and the largest step between the cells' drawings is 5.52 and 2.45, so the
+refusal matches `--anchor none`. A ramp limitation also still refuses 3 of 24 cuts on threes
+sliding 0.2 to 0.3 px a frame: the ramp shifts cells by whole pixels, and where it moves the
+frames of one drawing apart, cells read as a drawing a frame, reading largest steps of 2.85
+to 2.99 on both the ramp rule and the step gate.
+
+Known limits (measured on the synthetic walk standing in place, cut from frame 0):
+- Between drawings, a wrap a few drawings off the stride reads as an ordinary step,
+ because one drawing step covers two or three frames of motion.
+- Cut length: drawn a frame each, cuts of 16 to 22, 28, and 30 frames of the 24-frame
+ stride are refused (2.38 to 4.07; 23 and 26 pass). On twos, cuts of 16 to 28 frames pass
+ (1.02 to 1.67) and 30 is refused (2.06). On threes, cuts of 16 to 30 frames all pass
+ (0.95 to 1.48).
+- Last drawing moved sideways: drawn a frame each, a last frame moved 2 px is refused
+ (3.05). On twos, a last drawing moved 2 px passes (1.66) and 3 px is refused (2.03). On
+ threes, it passes up to 4 px (1.73) and is refused from 6 px (2.14).
+- Sliding 0.2 px a frame with `--anchor body`, the ramp passes cuts of 16 to 28 frames on
+ twos (30 refused) and 16 to 30 on threes, a last drawing moved 2 px on twos (3 px refused)
+ and up to 6 px on threes (8 px refused).
+- The step gate, which already read between drawings before this change, passes the same
+ cuts (largest step 1.26 to 1.86); the frame-by-frame seam gate refused every such held
+ cut, closing ones included.
+- Synthetic motion has a fixed amplitude, so a cut off the stride stays within it; these
+ numbers do not translate directly into how visible such a cut is on a drawn walk.
+- The seam value is a mean over the whole frame, so the body and legs weigh most; on the
+ synthetic walk, the seam value between drawings alone does not see a small part (here
+ the arm) jumping at the wrap of a cut that skips a third of the cycle: on twos, the
+ 16-frame cut has the arm cross its whole swing in one drawing at the wrap (a step moves
+ a sixth) at seam 1.26, the 20-frame cut crossing half; on threes, the 22-frame cut has the
+ stride drawings with the last shown one frame instead of three, a beat slip it cannot see.
## Material for a vision-capable reviewer
diff --git a/sprite_gen/video/loop.py b/sprite_gen/video/loop.py
index 50c6ffc..569e558 100644
--- a/sprite_gen/video/loop.py
+++ b/sprite_gen/video/loop.py
@@ -65,7 +65,7 @@ ANALYSIS_SIZE = 96 # thumbnail edge for the distance matrix
STRIP_MAX_CELLS = 64 # upper bound on cells even when they are narrow
STRIP_MAX_WIDTH = 32000 # Chrome refuses images wider than ~32767 px; the cap is on PIXELS — a 650 px cell allows only 49 cells (2026-09-09 wolf idle: 64 cells = 41,664 px, unrenderable)
STRIP_MAX_HEIGHT = 520
-SEAM_RATIO_MAX = 2.0 # loop seam / mean adjacent distance inside the cycle
+SEAM_RATIO_MAX = 2.0 # loop seam / mean adjacent distance inside the cycle (a walk's or run's between its drawings, `seam_drawings`)
# A walk's or run's largest step between drawings as it plays, the wrap one of them, over their mean step
# (`drawing_steps`): past it the loop jumps inside, where the seam ratio, read at the wrap alone, does not look. Read
# between drawings, not frames: a loop held on twos or threes steps nothing and then two or three steps at every drawing.
@@ -295,7 +295,8 @@ def distance_matrix(files: list[Path]) -> np.ndarray:
def _seam_on_cells(cells: list[Image.Image]) -> tuple[float, float, np.ndarray]:
- """Cells as they play, on their analysis features: the mean step, the wrap (last -> first) and each step."""
+ """Cells as they play (a walk's each drawing's first, `seam_drawings`), on their analysis features: the mean step, the
+ wrap (last -> first) and each step."""
flat = np.stack([_small_features(im) for im in cells])
steps = np.abs(flat[1:] - flat[:-1])
return float(steps.mean()), float(np.abs(flat[-1] - flat[0]).mean()), steps.mean(axis=1)
@@ -1372,9 +1373,10 @@ def cell_features(frames: list[Image.Image], box: tuple[int, int, int, int] | No
def wrap_on_cells(frames: list[Image.Image]) -> float:
- """The seam gate's reading of a loop's frames as corrected: cropped to their union box, the wrap over the mean step
- on the analysis thumbnail — the rendered cells the gate reads, short of the strip's scale."""
- flat = cell_features(frames)
+ """The seam gate's reading of a walk's frames as corrected: cropped to their union box, the wrap over the mean step
+ on the analysis thumbnail, between the loop's drawings (`seam_drawings`) — the rendered cells the gate reads, short of
+ the strip's scale."""
+ flat = cell_features(frames)[seam_drawings(frames)[0]]
step = float(np.abs(flat[1:] - flat[:-1]).mean())
return float(np.abs(flat[-1] - flat[0]).mean()) / step if step > 0 else math.inf
@@ -1409,6 +1411,27 @@ def step_jitter(before: Image.Image, after: Image.Image, *, pixel: float, mean:
return {"move": [dx, dy], "ratio_moved_back": round(ratio, 4)} if ratio <= STEP_RATIO_MAX else None
+def drawing_firsts(cells: list[Image.Image]) -> tuple[list[int], int]:
+ """A loop's cells as they play, by drawing (`repair.flow_drawings`: a cell held on twos or threes shows its drawing
+ again): each drawing's first cell, in play order round the loop, and the hold. A loop drawn a frame each is every
+ cell, in order."""
+ runs, hold = repair_mod.flow_drawings(repair_mod.flow_states(cells))
+ return [run[0] for run in runs], hold
+
+
+def seam_drawings(cells: list[Image.Image]) -> tuple[list[int], dict[str, Any]]:
+ """The cells a walk's or run's seam is read on, in play order round the loop, and the reading (`seam_read`): each
+ drawing's first (`drawing_firsts`), as the step gate reads its steps. Read cell by cell, a loop held on twos or threes
+ steps nothing and then two or three steps at each drawing: a wrap between two drawings reads two or three times the
+ mean step where the loop closes, and a step into a drawing as much where nothing jumps. Every cell of a loop that
+ shows fewer than three drawings (`read: cells`), as the step gate skips it; a loop drawn a frame each is every cell
+ either way, and reads as it did."""
+ firsts, hold = drawing_firsts(cells)
+ if len(firsts) < 3:
+ return list(range(len(cells))), {"read": "cells", "why": "fewer than three drawings", "drawings": len(firsts), "hold": hold}
+ return firsts, {"read": "drawings", "drawings": len(firsts), "hold": hold}
+
+
def drawing_steps(cells: list[Image.Image], pixel: float = 1.0) -> dict[str, Any] | None:
"""A loop's cells as they play, read between their drawings (`repair.flow_drawings`: a cell held on twos or threes
shows its drawing again): each drawing's first cell on the analysis features (`_small_features`) and the step into the
@@ -1417,10 +1440,9 @@ def drawing_steps(cells: list[Image.Image], pixel: float = 1.0) -> dict[str, Any
(`largest_ratio`, from the cell `largest_from` into the cell `largest_into`, each a drawing's first), the steps over
STEP_RATIO_MAX that are one (`jitter`, larger first, where there are any), and the wrap's (`wrap_ratio`). None for a
loop of fewer than three drawings."""
- runs, hold = repair_mod.flow_drawings(repair_mod.flow_states(cells))
- if len(runs) < 3:
+ firsts, hold = drawing_firsts(cells)
+ if len(firsts) < 3:
return None
- firsts = [run[0] for run in runs]
flat = np.stack([_small_features(cells[k]) for k in firsts])
steps = np.abs(np.roll(flat, -1, axis=0) - flat).mean(axis=1)
mean = float(steps[:-1].mean())
@@ -1435,7 +1457,7 @@ def drawing_steps(cells: list[Image.Image], pixel: float = 1.0) -> dict[str, Any
if moved is None:
break
jitter.append({"from": firsts[largest], "into": into, "ratio": round(float(steps[largest]) / mean, 4), **moved})
- return {"read": "drawings", "drawings": len(runs), "hold": hold, "mean_step": round(mean, 6),
+ return {"read": "drawings", "drawings": len(firsts), "hold": hold, "mean_step": round(mean, 6),
"largest_ratio": round(float(steps[largest]) / mean, 4) if mean > 0 else None,
"largest_from": firsts[largest], "largest_into": into,
"wrap_ratio": round(float(steps[-1]) / mean, 4) if mean > 0 else None,
@@ -2206,9 +2228,18 @@ def run_loop(
idx = [min(L - 1, i2) for i2 in (round(k * L / n_out) for k in range(n_out))]
pick = resampled_cells(strip, strip_meta, idx, L)
seam_idx = [i + j for j in idx]
- resampled_adjacent = float(np.mean([D[seam_idx[k], seam_idx[k + 1]] for k in range(len(seam_idx) - 1)]))
- resampled_seam = float(D[seam_idx[-1], seam_idx[0]])
on_cells = report_base["seam_measurement"] == "rendered-cells"
+ # A walk's or run's seam is read between its drawings, as its steps are (`seam_drawings`), where the seam ratio gates
+ # the cut: not a pin or a cut played once. Any other loop's, and a walk drawn a frame each, on every frame.
+ by_drawing = prof.gait and cycle["kind"] not in ("pinned", *nonloop.KINDS)
+ seam_read = None
+ read_idx = seam_idx
+ if by_drawing and not on_cells:
+ # The source frames the distances were read on, each drawing's first.
+ firsts, seam_read = seam_drawings([gait_frames[j] for j in seam_idx])
+ read_idx = [seam_idx[k] for k in firsts]
+ resampled_adjacent = float(np.mean([D[read_idx[k], read_idx[k + 1]] for k in range(len(read_idx) - 1)]))
+ resampled_seam = float(D[read_idx[-1], read_idx[0]])
source_ratio = resampled_seam / resampled_adjacent if resampled_adjacent > 0 else math.inf
# The body anchor moved the cells to close a wrap the source frames refuse: the cells that play are read again. Where
# the seam ratio gates the cut, not a pin or a cut played once.
@@ -2216,8 +2247,10 @@ def run_loop(
and source_ratio > seam_max)
if on_cells or ramped:
# The actual corrected/repaired/resampled strip cells, with the same limit — a cell given way to the frame
- # beside it as filmed (`seam_as_filmed`), on the strip the cut makes with those frames.
- adjacent, wrap, steps = _seam_on_cells(resampled_cells(*strip_of(seam_frames), idx, L) if as_filmed else pick)
+ # beside it as filmed (`seam_as_filmed`), on the strip the cut makes with those frames; a walk's between its drawings.
+ cells = resampled_cells(*strip_of(seam_frames), idx, L) if as_filmed else pick
+ on, cells_read = seam_drawings(cells) if by_drawing else (list(range(len(cells))), None)
+ adjacent, wrap, steps = _seam_on_cells([cells[k] for k in on])
if ramped:
# The ramp spreads whatever offset the wrap shows over the loop: a jump of a few frames comes out moved into the
# loop, not closed. So the cells overrule the source frames only where their wrap and every step of the loop are
@@ -2227,13 +2260,18 @@ def run_loop(
"source_seam_ratio": round(source_ratio, 4) if math.isfinite(source_ratio) else None,
"seam_ratio": round(wrap / adjacent, 4) if adjacent > 0 else None,
"largest_step_ratio": round(float(steps[largest]) / adjacent, 4) if adjacent > 0 else None,
- "largest_step_into": idx[largest + 1],
+ "largest_step_into": idx[on[largest + 1]],
+ **(cells_read or {}),
}
if adjacent > 0 and wrap / adjacent <= seam_max and float(steps[largest]) / adjacent <= seam_max:
report_base["seam_measurement"] = "rendered-cells"
on_cells = True
if on_cells:
resampled_adjacent, resampled_seam = adjacent, wrap
+ seam_read = cells_read
+ if seam_read is not None:
+ # What the seam ratio below was read on: the drawings, as many as there are, and the hold.
+ report_base["seam_read"] = seam_read
seam_ratio = resampled_seam / resampled_adjacent if resampled_adjacent > 0 else math.inf
delay_ms = max(20, round(1000 * cycle_seconds / n_out))
gif_path = out_dir / f"{name}.gif"