Skip to content

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

test(video): a loop aligned to more cells than its cut says where each is from, and --read-on-cut reads the cut's own record, refusing a cell made between; the docs and the changelog say a walk's cut is read after the clip two lengths on; text by the writing hand-off

Soohong Kimb922d5bcedf2
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 755f698..613ea3f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,7 +11,7 @@ All notable public changes to `sprite-gen` are recorded here. Versions track the
- **New: walk start-stop retake reporting (`loop.stand_retake`, `crossings.Reading.stands`).** In gap mode, runs where the feet stay together longer than `run_limit` (√2 times the median whole pass run) are recorded in `Reading.stands`. Where a clip shows its steps, contains `stands`, and the cut kept does not count two steps (`verdict` is not `two`) with no two-step cut closing between the standing frames, `loop.stand_retake` emits a `retake` report (`reason: "start-stop"`, `remedy: "retake"`), keeping the cut as cut without refusal under `--unfixed refuse`. Where a part also pops, one `retake` names both (`loop.retakes`): the first reason's record, `reasons: ["part-pop", "start-stop"]`, and each reason's numbers under its own key (`part_pop`, `start_stop`).
- **Changed: `video-set` defaults gait anchoring to `motion-auto` (`batch.anchor_for`).** Without an explicit `--anchor`, `video-set` cuts each walk and run item whose loop is searched (`cycle_for` returns `auto` or `periodic`) with `motion-auto`, and assigns `none` to idle, attack, once-hold, lifetime, and once-return items; explicit `--anchor` options are applied to every item as before. `video-set` passes each item's view to `video-loop`. Any item whose loop names a retake carries `loop.retake`, appears in the set's `warnings`, and appends ` (film again: <reasons>)` to `table.md`.
- **Changed: cycle alignment leaves out start-stop retake, cycle-unwitnessed and cycle-four-steps loops (`batch.align_gaits`, `video-set --align-cycles auto`, `local_cycle.four_steps`).** Takes flagged with `start-stop` retakes loop no two steps, loops whose cut nothing witnesses whole cycles (`cycle-unwitnessed`: crossings left on steps unwitnessed, or a cut the cut witness held) may hold half a cycle or two, and the warning says so, and loops whose cut witness says four steps (`cycle-four-steps`) hold two cycles where their strip counts two steps (`steps: 2`, which `video-cycle-align` reads as one cycle) and would play twice as fast if aligned as one cycle; all are excluded from gait cycle alignment, keeping their loops as cut while aligning the remaining directions. Excluded items are recorded under `left_out` (`{item: reasons}`, listing `["start-stop"]`, `["cycle-unwitnessed"]`, `["cycle-four-steps"]`, or `["start-stop", "cycle-unwitnessed"]`) with a stderr warning and a set warning; if fewer than two directions remain, alignment is skipped (`applied: false`, `why: "fewer than two directions left to align"`). A left-out loop whose step screen suspects one step is told in its warning what settles it (`video-loop --steps 1`), as `video-cycle-align` says when it stops on such a loop, and `batch.left_out_why` takes `one_step`.
-- **New: a walk's cut is held to its body's word before it is cut (`loop._witnessed`, `local_cycle.cut_word`, `local_cycle.unwitnessed`, `local_cycle.held_verdict`).** In `video-loop --anchor motion-auto` (`--cycle auto` or `periodic`), after `loop._by_steps` chooses the cut and before frames are cut, `loop._witnessed(cycle, frames=...)` holds the cut s/L to `local_cycle.cut_word(signals, length)`, which reads `local_cycle.bob_word` on two lines, `local_cycle.CUT_LINES` (`'screen'` on the screen, less its flow, and `'feet'` over its feet with `local_cycle.over_feet`, `feet=True`), at length L, L/2 and 2L (a picture swaying up and down once a cut or slower hides the body's rise and fall twice the cut on the screen, where the line over the feet reads it; a walk whose lean changes slowly on its feet tilts the ground under them, so the line over the feet takes in the two feet's heights by turns and reads no rise and fall, where the line on the screen reads it) and says the first either line says in `local_cycle.CUT_WORDS`: `"two steps"` (a cycle), `"four steps"` (two cycles), `"one step"` (once in the cut), or null. On two steps or four steps the cut stands (`{cut: [s, L], ...cut_word's record}`; where the cut stands and its lowest row rises and falls twice the cut more than its top line on the screen, the record carries `mark`; it holds nothing), and a cut of four steps (two cycles), its strip still counting two steps, makes `local_cycle.four_steps(cycle)` true, and `video-set` leaves the item out of cycle alignment (`left_out` `["cycle-four-steps"]`); anything else is held exactly as chosen (two clip crossing intervals where counted, else the search's cut), setting `cut_witness.held` to `"unwitnessed"`, warning `cycle-unwitnessed` (`local_cycle.held_verdict(cycle)` via `local_cycle.step_verdict`), and marking `local_cycle.unwitnessed(cycle)` true so `video-set` leaves the item out of cycle alignment (`left_out` `["cycle-unwitnessed"]`), while cuts the step count already held record `held: "step count"`. A reading of `"one step"` is held and never cut again two long because a body rising and falling once in the cut cannot be distinguished between half a cycle of legs drawn alike and a full cycle of a limp or bouncing legless body without reading legs, and the witness never lengthens or shortens a cut; walks whose body rises once a cycle, legless bodies bouncing once in the cut, and walks carried whole with no rise of their own are held and named even where a cut is a whole cycle.
+- **New: a walk's cut is held to its body's word before it is cut (`loop._witnessed`, `local_cycle.cut_word`, `local_cycle.unwitnessed`, `local_cycle.held_verdict`).** In `video-loop --anchor motion-auto` (`--cycle auto` or `periodic`), after `loop._by_steps` chooses the cut and before frames are cut, `loop._witnessed(cycle, frames=...)` holds the cut s/L to `local_cycle.cut_word(signals, length)`, which reads `local_cycle.bob_word` on two lines, `local_cycle.CUT_LINES` (`'screen'` on the screen, less its flow, and `'feet'` over its feet with `local_cycle.over_feet`, `feet=True`), at length L, L/2 and 2L (a picture swaying up and down once a cut or slower hides the body's rise and fall twice the cut on the screen, where the line over the feet reads it; a walk whose lean changes slowly on its feet tilts the ground under them, so the line over the feet takes in the two feet's heights by turns and reads no rise and fall, where the line on the screen reads it) and says the first either line says in `local_cycle.CUT_WORDS`: `"two steps"` (a cycle), `"four steps"` (two cycles), `"one step"` (once in the cut), or null. On two steps or four steps the cut stands (`{cut: [s, L], ...cut_word's record}`; where the cut stands and its lowest row rises and falls twice the cut more than its top line on the screen, the record carries `mark`; it holds nothing), and a cut of four steps (two cycles), its strip still counting two steps, makes `local_cycle.four_steps(cycle)` true, and `video-set` leaves the item out of cycle alignment (`left_out` `["cycle-four-steps"]`); anything else is held exactly as chosen (two clip crossing intervals where counted, else the search's cut), setting `cut_witness.held` to `"unwitnessed"`, warning `cycle-unwitnessed` (`local_cycle.held_verdict(cycle)` via `local_cycle.step_verdict`), and marking `local_cycle.unwitnessed(cycle)` true so `video-set` leaves the item out of cycle alignment (`left_out` `["cycle-unwitnessed"]`), while cuts the step count already held record `held: "step count"`. A reading of `"one step"` is held and never cut again two long because a body rising and falling once in the cut cannot be distinguished between half a cycle of legs drawn alike and a full cycle of a limp or bouncing legless body without reading legs, and the witness never lengthens or shortens a cut; walks whose body rises once a cycle, legless bodies bouncing once in the cut, and walks carried whole with no rise of their own are held and named even where a cut is a whole cycle. It now reads the cut `_two_lengths` handed it, so what it reads is the cut that will play: a cut made two lengths long is read at that length, and it stands, or is held and named, as any other cut.
- **Changed: the body's own rise and fall is read against the lowest opaque row as well (`legs.body_signals` `sole`, `legs.OPAQUE`, `local_cycle.own_beat`).** `legs.body_signals(frames)` now returns `sole` per frame, taking the lowest row with an alpha of `legs.OPAQUE` (255) or the lowest solid row where none is opaque. `local_cycle.own_beat(signals, interval)` reads `sole` with `twice_an_interval` and takes `less_lowest` as the top line's rise and fall less the lowest solid row's or less the lowest opaque row's, whichever leaves less, returning `sole` as rows up and down. This prevents a translucent shadow drawn fixed on the screen under the feet from acting as the lowest solid row and registering picture shake twice an interval as the body's own rise against it, since opaque feet move with the picture.
- **New: the order the feet are drawn in witnesses a walk's steps (`legs.feet_order`, `legs.CONTACT`, `local_cycle.order_word`, `ORDER_ROWS`, `ORDER_TRAVEL`, `ORDER_SWAY`, `ORDER_REACH`, `ORDER_SLACK`, `ORDER_WORDS`).** `legs.feet_order` tracks which foot is drawn lower in each frame, and `local_cycle.order_word` gates side changes to witness one, two, or four steps across a span from non-side views. From the front, the back, or a diagonal, the foot nearer the viewer is drawn lower, and the nearer foot changes sides once a step, twice a cycle. The view's label is not taken for it, because a generated walk's label may be wrong: the clip must show that its two sides of feet are its two legs, or nothing is witnessed. `read_cycles` and `cut_word` read the foot drawing order when body cues do not witness crossings or cuts, and search cuts that failed to close are held unwitnessed rather than stood by foot order. A diagonal walk whose feet pass each other on the screen, one foot always drawn lower and the other passing it on either side, shows the same changes a side walk does, and the order does not witness it; a side walk is never read on the order. Before its gates, `local_cycle.order_word` leaves out frames whose contacts touch no column of anything standing on the lowest row in any frame, recorded in `off_ground`, so a dipping tail is not read as a foot and changing sides to count half a cycle as a whole, at the cost of leaving out feet lifted over columns where nothing ever stands. As a named limit, a tail hanging over the columns the feet stand on is still read as a foot, held only by the gates after the reading (the sliding check, the ground travelled, and the upper body's sway).
- **Changed: standalone `video-cycle-align` stops on held or four-step cuts (`align.held_cut`).** `video-cycle-align` run on its own reads the cut report beside each loop through `align.held_cut(loop_dir, meta_path, meta)`. Where nothing witnessed the cut whole cycles (`cycle-unwitnessed`) or the cut spans four steps (`cycle-four-steps`), the loop is named under `held` and the aligner stops under `--multi-cycle fail` before rewriting any files, adding "and nothing witnessed some of the cuts whole cycles". Under `--multi-cycle warn` it aligns the loop with a warning, matching `video-set` instead of aligning held loops as one cycle without a word.
@@ -78,6 +78,7 @@ All notable public changes to `sprite-gen` are recorded here. Versions track the
- **Tests**: `tests/video/test_cycle_suspects.py` and `tests/video/test_loop_prop_seam_held.py` cover standalone `video-cycle-align` on loops whose cut reports hold their cuts:
- three synthetic loops in `tests/video/test_cycle_suspects.py` (S and E one stride of 24 frames each, NE two strides of 15 frames, 30 frames held on twos, as a two-cycle cut leaves it, with NE's cut report beside it as `video-loop` writes it holding its cut because nothing witnesses it whole cycles): stopping the set, run twice, names NE with its report beside it both for what the report holds (`held`, reason `cycle-unwitnessed`, with the report's path: it may hold half a cycle, one or two, and the message names `video-loop` to cut it again if it is one step) and for its return at 15 frames (it may also hold 2 cycles of 15 frames), while with the report removed (a loop cut by other means) it is named only for its return with no `held` and no mention of `video-loop`, both offering settle `=1` and `=2` with nothing rewritten (previously one run, NE named only for its return, and the message never named `video-loop`); `--multi-cycle warn` aligns the set as it is, NE's warning starting with nothing having witnessed its cut whole cycles and adding that it may also hold 2 cycles (previously the warning started with it may hold 2 cycles); the command line (`align.main`) without a count exits naming the held cut and the return at 15 frames, and with `--cycles NE=2` aligns as before (previously the exit named only the return).
- two synthetic loops in `tests/video/test_loop_prop_seam_held.py` (one cut two steps long, one cycle, strip `steps: 2`, and one cut one cycle with no `steps`, neither walker's body rising and falling and its feet never passing, so both reports hold their cuts, nothing witnessing either whole cycles): on copies whose reports the test rewrites to witness their cuts (`cut_witness` saying "two steps" by the screen, nothing held), the aligner works as before: the two-step loop returns half way at its second step, which is no suspect (`status` "steps", `steps` 2, candidates `[2]`), and both loops are resampled to the median of their lengths as cut, nothing kept twice as long, the strip of the two-step copy still saying `steps: 2`, the other none; on the loops as cut, `video-cycle-align` stops on both, each named `held` with reason `cycle-unwitnessed`; a count of one cycle for each (`cycles`, the caller's word) aligns them as they are, to the same median length, each suspect `status` "counted"; a count of 2 for the two-step loop (and 1 for the other) still takes one half out of it, and its strip no longer says `steps`; two copies of the loop with no held part, aligned with a count of one cycle each, are written as before: no `cycles_kept` and no `steps` in their rows, their strip metadata with the same keys, and the cut's source (`source_cut`) as the cut wrote it (previously both aligned with no count, the two-step loop's return read as its steps).
+ - the synthetic cut of 13 cells with its record of its cells, aligned by `video-cycle-align` to 17 cells, in `tests/video/test_sway_read_on_recut.py` (with `--between rife` (a blend standing in for RIFE) the aligned strip record holds no `cell_record`, `cycle_align.cells_from` gives 17 cells, each `{"source": i}` cell is cell i of the cut pixel for pixel and each `{"between": [i, j], "t": t}` cell is a copy of no cell of the cut, `cycle.source/run.strip.json` is the cut's record with 13 cells, source frames 1 to 13, and `video-sway --read-on-cut` is refused `uncertain` on the pair the kept record gives (source frame 4), naming the first made cell, the loop as it was; with `--between nearest` every one of the 17 cells is one of the cut's, and `--read-on-cut` pairs source frame 4 with the cut's cell 3 at shift (3, 2) and carries it through, `cut_cells` equal to the `cells_from` sources).
## v3.11.0 - Sway regions laid over the figure (--region-over), rims widened for shear (--region-shear), figure membranes (--region-membrane), and recut strip pairing by cell records (--read-on-cut)
diff --git a/docs/loop-repair.md b/docs/loop-repair.md
index 6f027c1..88637fd 100644
--- a/docs/loop-repair.md
+++ b/docs/loop-repair.md
@@ -1760,11 +1760,14 @@ step count counted them, else the search's cut), `cut_witness.held` is `"unwitne
half a cycle or two, and, where its step screen suspects the cut is one step, adds what settles that
(`video-loop --steps 1`); a cut the step count had already held (crossings left on steps,
`step_count.cycles.unwitnessed`) is recorded `{cut, held: "step count"}` and named as before.
-`"one step"` is held, never cut again two of its lengths long: a body that rises and falls once in the cut may be
-one step of a walk whose legs are drawn alike (half its cycle), or a whole cycle of a body that rises and falls
-once a cycle: a limp, or a legless body bouncing as it goes (the walk window already admits a legless body's fast
-bounce); nothing that reads no leg tells the two apart, and cutting again two long would loop two cycles of the
-second. The warning of a cut held on one step names the line or lines its body's top line rose and fell once on
+A cut two lengths long comes only from the picture read before this step (`loop._two_lengths`,
+docs/video-pipeline.md), and the cut read here is the one that step handed on, so `"one step"` is held,
+never cut again two of its lengths long: a body that rises and falls once in the cut may be one step of a
+walk whose legs are drawn alike (half its cycle), or a whole cycle of a body that rises and falls once a
+cycle: a limp, or a legless body bouncing as it goes (the walk window already admits a legless body's fast
+bounce); nothing that reads no leg tells the two apart, and cutting again two long would loop two cycles of
+the second.
+The warning of a cut held on one step names the line or lines its body's top line rose and fell once on
("the body's top line on the screen", "over its feet", or "on the screen and over its feet") and, for the other
line, that it says nothing, with that line's why. `local_cycle.held_verdict` refuses by name, with a `ValueError`,
a cut held on one step whose record names no line it was read on (no `by` or `lines`), and `step_verdict` with it;
diff --git a/docs/video-pipeline.md b/docs/video-pipeline.md
index 883601d..949c09c 100644
--- a/docs/video-pipeline.md
+++ b/docs/video-pipeline.md
@@ -464,6 +464,8 @@ distances: the analysis canvas moves every frame by the drift it reads, one vert
and a slope tilted by frames that open higher moves frames two steps apart further than one step apart
where the body runs in place, so two lengths on read no nearer there. A drift the clip does walk only
makes two lengths on read farther: it keeps a cut one step, never doubles one.
+The cut so chosen then goes to the cut's witness like any other (`loop._witnessed`, docs/loop-repair.md
+section 3, "The step count").
A cut the clip gives no two — two lengths on no nearer, one length on the same picture, no window to
cut, a gate that would not pass it — and a cut under any other anchor are kept as cut, recorded in
diff --git a/tests/video/test_sway_read_on_recut.py b/tests/video/test_sway_read_on_recut.py
index d358aba..29cfb29 100644
--- a/tests/video/test_sway_read_on_recut.py
+++ b/tests/video/test_sway_read_on_recut.py
@@ -31,7 +31,8 @@ from PIL import Image
from sprite_gen import cli
from sprite_gen.video import align, loop, motion_anchor, sway
-from tests.video.test_follow_read_on import H, N, PATCH, SHIFT, W, aligned, cells_of, copy, cut, files, meta_of, runner, sha
+from tests.video.test_follow_read_on import (Blend, H, N, PATCH, SHIFT, W, aligned, cells_of, copy, cut, files, meta_of, runner,
+ sha)
from tests.video.test_gait_fallback import walking_away
from tests.video.test_ghost_given_way import _cut as ghost_cut, _keyed as ghost_keyed
from tests.video.test_loop_repair import _no_rife
@@ -342,6 +343,43 @@ def test_a_loop_aligned_from_a_cut_whose_kept_record_does_not_give_the_frame_as_
region)
+def test_a_loop_aligned_to_more_cells_says_where_each_is_from_and_read_on_cut_reads_the_cut_s_own_record(tmp_path):
+ # video-cycle-align stretching the cut (13 cells to 17, as a set stretches a loop of 18 to its 24). The aligned strip is
+ # another strip of another length: its record holds no record of the cut's cells to go stale; the alignment's record
+ # gives each of its cells, the frame of the cut it is or the two it is made between, and the cut's own record is kept
+ # as it was beside the frames as filmed, 13 cells, for --read-on-cut to read.
+ b, a, _, region, mask = aligned_cut(tmp_path)
+ kw = dict(region_mask=mask, read_on=sha(a/'run.strip.png'), read_on_cut=a/'run.strip.png', **KW)
+ made = aligned(b, tmp_path/'made', length=17, between='rife', interpolate=Blend())
+ meta, cells = meta_of(made), cells_of(made)
+ cells_from, cut_cells = meta['cycle_align']['cells_from'], cells_of(b)
+ kept = json.loads((made/loop.CYCLE_SOURCE_DIR/'run.strip.json').read_text())
+ assert len(cells) == len(cells_from) == 17 and CR not in meta
+ assert kept == meta_of(b) and [c['source_frame'] for c in kept[CR]['cells']] == list(range(1, 1+N))
+ between = [k for k, entry in enumerate(cells_from) if 'between' in entry]
+ assert 0 < len(between) < 17
+ for k, entry in enumerate(cells_from):
+ if k in between: # a frame of its own, a copy of no cell of the cut
+ assert not any(np.array_equal(cells[k], cell) for cell in cut_cells)
+ else:
+ assert np.array_equal(cells[k], cut_cells[entry['source']])
+ # A cell made between has no cell of the cut, and the reading is not carried: refused on the pair the kept record gives.
+ before = files(made)
+ with pytest.raises(SystemExit, match=rf"paired at source frame 4 with the cut this loop was aligned from \(.*\), but "
+ rf"uncertain: cell {between[0]} is made between the cut's frames"):
+ sway.sway_loop(made, [region], **kw)
+ assert files(made) == before
+ # Stretched by the cut's own cells, shown again, every cell is one of the cut's, and the pair is carried through.
+ shown = aligned(b, tmp_path/'shown', length=17)
+ entries = meta_of(shown)['cycle_align']['cells_from']
+ assert len(entries) == 17 and all('source' in entry for entry in entries) and CR not in meta_of(shown)
+ read_on = sway.sway_loop(shown, [region], **kw)['read_on']
+ assert read_on['relation'] == 'recut' and read_on['shift_px'] == [3, 2]
+ assert read_on['source_frame'] == 4 and read_on['cut_cell'] == 3
+ assert read_on['cut_cells'] == [entry['source'] for entry in entries]
+ assert read_on['base_cell'] == read_on['cut_cells'].index(3)
+
+
# ---------------------------------------------------------------- the frame where each cut's anchor moved it
def test_two_cuts_at_anchor_body_pair_the_frame_where_each_ramp_moved_it(tmp_path):