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): video-cycle-align refuses a loop whose strip as cut is missing, by name, before any loop is touched

Soohong Kim8a70705c2588
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4ce8c93..0ba1da4 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.42.0)
+
+- **Fix: `video-cycle-align` refuses a loop whose strip as cut is missing, by name, before any loop of the set is touched.** Since 2.41.0 a loop's first alignment reads its strip as cut (`<name>.strip.png`, or `follow.source.png` where a follow-through moved it) to record `cycle_align.origin`. A loop directory holding `cycle/` and its `strip.json` without that PNG ended in a `FileNotFoundError` traceback, with no report and `cycle.source/` already copied into every loop of the set. It is now refused as a loop cut before `cell_height_cap` was recorded is: `video-cycle-align: <loop dir>: no <name>.strip.png — …`, exit 1, every loop of the set file for file as it was (under `video-set`, that state's alignment fails and its loops stay as cut). It is still not aligned without its origin, which `video-follow --read-on` carries regions by: put the strip back, or cut the loop again. A loop aligned before keeps the origin it recorded and is aligned again without its strip, as before. [docs/loop-repair.md](docs/loop-repair.md) section 4.
+- **`tests/video/test_cycle_align.py`** takes the strip out of one loop of a synthetic set: the refusal names it, and both loop directories are as they were, with no `cycle.source/` and no report. A loop aligned once is aligned again without its strip, its origin kept.
+
## v2.41.0 - Regions read on the cut follow the loop aligned from it, cell for cell; a floor on the stretch, by direction and never above the fold rule; the bend and the seam written down
- **New `video-follow --read-on <sha256>`: the strip the regions were read on, and the reading carried from it.** The regions of a follow-through are where somebody looked, in the first cell of the strip they were read on. `video-cycle-align` turns a loop to start on a foot strike, so its first cell is another, and `video-follow` given the same regions read the motion again from that cell 0: the regions landed on another place of the body, and a stretched loop moved them by a motion read anew. `--read-on` names the strip they were read on by its file's sha256 (as cut, before any follow-through). This loop's own strip as cut is `same`: the follow-through is the one without the flag, byte for byte. The cut this loop was aligned from is `transported`: each cell is carried by the cut's reading of the cut's cell it is, the regions stay on the cut's cell 0, and the damped mass is solved on the loop's own order, length and frame time — a turned loop gives the cut's follow-through cell for cell, a loop stretched by the nearer frame the new cycle's offsets on the cut's motion. A cell made between two frames of the cut, or one that is not the cut's cell pixel for pixel (a crop or a scale changed and nothing records how, or a cell drawn again), is refused `uncertain`: a made cell has no reading of its own, and none is taken from the nearer frame by rounding (a cut made before its strip recorded its crop is judged by its cells' pixels alone). Any other strip is refused `no-match`. Without `--read-on` nothing of this is read or written and the record holds no new key; with it the record carries `read_on` (`sha256`, `relation`, and for `transported` its `policy` and `cut_cells`). `video-follow-inspect` takes it too. [docs/video-pipeline.md](docs/video-pipeline.md#regions-read-on-the-cut-followed-on-the-aligned-loop----read-on).
diff --git a/docs/loop-repair.md b/docs/loop-repair.md
index 7acf6e0..42263af 100644
--- a/docs/loop-repair.md
+++ b/docs/loop-repair.md
@@ -736,7 +736,12 @@ sprite-gen video-cycle-align --loop-dir set/front-walk/loop --loop-dir set/side-
regions were read on the cut be carried to the aligned loop (`video-follow --read-on`,
docs/video-pipeline.md section 6). Neither record changes a pixel of the strip, GIF or WebP.
- Loops at different frame rates are refused (one length in frames would mean different
- durations), and so is a loop cut before `cell_height_cap` was recorded (cut it again).
+ durations), and so is a loop cut before `cell_height_cap` was recorded (cut it again). So is a
+ loop never aligned whose strip as cut is missing — its `<name>.strip.png`, or `follow.source.png`
+ where a follow-through moved it: the first alignment reads `cycle_align.origin` there, and no
+ later one could. It is named before any loop of the set is touched, `cycle.source/` included; put
+ the strip back or cut the loop again. A loop aligned before keeps the origin it recorded and
+ needs no strip.
`video-set` runs this after its loops are cut, once per walk or run state filmed in two or more
directions (`--align-cycles auto`, default; `off` keeps each loop's own length). Its report
diff --git a/sprite_gen/video/align.py b/sprite_gen/video/align.py
index 9195fa5..ca6325b 100644
--- a/sprite_gen/video/align.py
+++ b/sprite_gen/video/align.py
@@ -31,7 +31,9 @@ of `cycle.source/` (`{"source": i}`, as many times as it is taken) or a frame ma
`follow.cut_origin`: its sha256, cell size, scale and crop origin, its cells, and the body's motion as
`video-follow` reads it there), and every later one keeps it: regions somebody located on the cut's
first cell are carried to the aligned loop by these two (`video-follow --read-on`), not read again on a
-first cell that is another. Neither changes a pixel of the strip, the GIF or the WebP.
+first cell that is another. Neither changes a pixel of the strip, the GIF or the WebP. A loop never aligned whose
+strip as cut is not there (`cut_strip`) is refused by name before any loop of the set is touched: no later
+alignment could record its origin.
Resampling to one length assumes every loop holds one cycle. A loop that holds two (a cut that
took two strides as one) would come out walking twice as fast as the rest, and pixels cannot tell
@@ -553,6 +555,11 @@ def _loop_files(loop_dir: Path) -> tuple[Path, dict[str, Any]]:
for key in ("cycle_frames", "cycle_seconds", "cell_height_cap", "kind"):
if key not in meta:
raise ValueError(f"{metas[0]}: no `{key}` — cut the loop again with this sprite-gen (video-loop) before aligning it")
+ strip = cut_strip(loop_dir, metas[0], meta)
+ if strip is not None and not strip.is_file():
+ raise ValueError(f"{loop_dir}: no {strip.name} — a first alignment reads the strip as cut to record where its cells are from "
+ "(cycle_align.origin, which video-follow --read-on carries regions by); put the loop's strip back, or cut "
+ "the loop again with video-loop, before aligning it")
return metas[0], meta
@@ -573,15 +580,22 @@ def _source_frames(loop_dir: Path) -> list[Image.Image]:
return [Image.open(f).convert("RGBA") for f in files]
-def origin_of(loop_dir: Path, meta_path: Path, meta: dict[str, Any]) -> dict[str, Any] | None:
- """The strip as cut that this loop is aligned from (`follow.cut_origin`), read before anything is rewritten: on a
- loop never aligned its strip now (`follow.source.png` where a follow-through moved it); on a loop aligned before,
- the origin its first alignment recorded, kept as it is — None where that alignment recorded none (the cut is no
- longer there to read)."""
+def cut_strip(loop_dir: Path, meta_path: Path, meta: dict[str, Any]) -> Path | None:
+ """The file `origin_of` reads the strip as cut from: on a loop never aligned its strip now (`follow.source.png` where a
+ follow-through moved it); None on a loop aligned before, whose origin its first alignment recorded."""
if "cycle_align" in meta:
- return meta["cycle_align"].get("origin")
+ return None
source = loop_dir / loop_mod.FOLLOW_SOURCE
- strip = source if source.exists() else loop_dir / f"{meta_path.name[: -len('.strip.json')]}.strip.png"
+ return source if source.exists() else loop_dir / f"{meta_path.name[: -len('.strip.json')]}.strip.png"
+
+
+def origin_of(loop_dir: Path, meta_path: Path, meta: dict[str, Any]) -> dict[str, Any] | None:
+ """The strip as cut that this loop is aligned from (`follow.cut_origin`), read before anything is rewritten from
+ `cut_strip`; on a loop aligned before, the origin its first alignment recorded, kept as it is — None where that
+ alignment recorded none (the cut is no longer there to read)."""
+ strip = cut_strip(loop_dir, meta_path, meta)
+ if strip is None:
+ return meta["cycle_align"].get("origin")
return follow_mod.cut_origin(strip.read_bytes(), meta)