Generate clean 2D game sprites & animation atlases — component-row pipeline: state rows, alpha cleanup, frame extraction, runtime atlases. Codex/Claude skill.
fix(held-fill): the read after the repairs keeps a run where the cut as it now plays reads drawn on twos or threes
Soohong Kim014e61d3011a
diff --git a/docs/loop-repair.md b/docs/loop-repair.mdindex 5808752..14e8016 100644--- a/docs/loop-repair.md+++ b/docs/loop-repair.md@@ -3443,7 +3443,7 @@ its drawings on its own cells, not on the clip's hold.### Read again after the repairs-The fill runs where it ran before: after the anchor and `source_projection`, before the ghost screen, the wrap blend, the part pop and the jump repair. The repairs that follow (the jump repair, the ghost RIFE frames, the eased retime, the overlapped wrap, the wrap blend, the part pop, the seam bridge) are unchanged: they keep the cut's cell count and beat and are not a fill. They can still leave a run the first fill did not see. So once they have run, the cut is read again for held cells, and a run a repair left is made again the same way, judged the same way, with the same keeps. This is `held_fill.again`, recorded as `held_fill.again` in the loop report and the strip metadata (`before`, `made`, `frames`, `cells`, `poses`, `held_runs`). Its `warning:` lines start with `read again after the repair:`.+The fill runs where it ran before: after the anchor and `source_projection`, before the ghost screen, the wrap blend, the part pop and the jump repair. The repairs that follow (the jump repair, the ghost RIFE frames, the eased retime, the overlapped wrap, the wrap blend, the part pop, the seam bridge) are unchanged: they keep the cut's cell count and beat and are not a fill. They can still leave a run the first fill did not see. So once they have run, the cut is read again for held cells, and a run a repair left is made again the same way, judged the same way, with the same keeps. This is `held_fill.again`, recorded as `held_fill.again` in the loop report and the strip metadata (`before`, `made`, `frames`, `cells`, `poses`, `held_runs`). Its `warning:` lines start with `read again after the repair:`. Where this read finds a run, it also reads the hold of the cut as it now plays, between its drawings: the same reading the seam and the step gate take (`drawing_firsts` in `video-loop`). The hold is read only where the read finds a run. Where that reading gives a hold of 2 or 3 and every run it found is that many cells long, the runs are kept as filmed, with the keep `drawn` (the same keep a cut drawn on twos or threes gets from the first fill), and listed in the strip's `holds`. This is why: a walk drawn on twos whose repeats are redrawn a pixel aside reads as a drawing a frame as filmed, so the first fill keeps nothing; once the anchor moves its frames back, a pair reads as one picture. Making that pair again turned the walk into frames drawn one by one, and the seam read on its cells then refused a loop that closes.A filmed ghost the repair gave way to the frame beside it (its frame between was already refused, `ghost_given_way`) is not tried again; its own warning already names it. `--fill-held off` turns the read-again off too.diff --git a/sprite_gen/video/held_fill.py b/sprite_gen/video/held_fill.pyindex 3aafb22..36f87f3 100644--- a/sprite_gen/video/held_fill.py+++ b/sprite_gen/video/held_fill.py@@ -50,7 +50,7 @@ docs/video-pipeline.md "Root motion")."""from __future__ import annotationsimport math-from collections.abc import Sequence+from collections.abc import Callable, Sequencefrom typing import Anyfrom PIL import Image, ImageFilter@@ -384,12 +384,15 @@ def intended(record: dict[str, Any]) -> list[dict[str, Any]]:def again(frames: list[Image.Image], interpolate: rife_mod.Interpolate | None, record: dict[str, Any], *, ring: bool,- mode: str = "auto", skip: Sequence[int] = ()) -> tuple[list[Image.Image], dict[str, Any] | None]:+ mode: str = "auto", skip: Sequence[int] = (),+ hold: Callable[[list[Image.Image]], int | None] | None = None) -> tuple[list[Image.Image], dict[str, Any] | None]:"""The cut read again once everything after the fill has run, each run of cells showing one picture that the filldid not leave (no kept run of `record` holds a cell of it, and no cell of it is in `skip`: cells a repair already gaveway to the frame beside it, its frame between refused) made again as the fill makes a run (`fill`, with the samerules): the frames, and the record of it, None where no such run was read. A cut drawn on twos or threes, or cut- with the fill off, is not read again."""+ with the fill off, is not read again. `hold` reads the held-drawings hold of the cut as it now plays, asked only+ where a run is read: a cut whose redrawn repeats read as drawings as filmed (a pixel aside each) and as held once+ the anchor moved them back is drawn on twos or threes all the same, and keeps them (`drawn`)."""if mode == "off" or "drawn" in record:return frames, Nonebefore = record["before"]@@ -410,7 +413,8 @@ def again(frames: list[Image.Image], interpolate: rife_mod.Interpolate | None, rfor r in new:for k in range(r["start"], r["start"] + r["length"] - 1):masked[k] = True- out, made = fill(frames, interpolate, ring=ring, same=masked, mode=mode, wrap=wrap)+ out, made = fill(frames, interpolate, ring=ring, same=masked, mode=mode, wrap=wrap,+ hold=hold(frames) if hold is not None else None)return out, madediff --git a/sprite_gen/video/loop.py b/sprite_gen/video/loop.pyindex 1c58877..3031d44 100644--- a/sprite_gen/video/loop.py+++ b/sprite_gen/video/loop.py@@ -1436,12 +1436,21 @@ def fill_cut(frames: list[Image.Image], interpolate: rife_mod.Interpolate | Nonereturn frames, record+def _playing_hold(cells: list[Image.Image]) -> int | None:+ """The hold of a loop's cells as they play (`drawing_firsts`), None for cells with no body to read."""+ try:+ return drawing_firsts(cells)[1]+ except ValueError:+ return None++def _fill_again(frames: list[Image.Image], interpolate: rife_mod.Interpolate | None, record: dict[str, Any], *, ring: bool,mode: str, skip: list[int]) -> tuple[list[Image.Image], dict[str, Any] | None]:- """`held_fill.again` on the cut, with RIFE located only once a frame is to be made, as `fill_cut` does."""+ """`held_fill.again` on the cut, with RIFE located only once a frame is to be made, as `fill_cut` does, the hold of+ the cut as it now plays read between its drawings as the seam and the step gate read it (`drawing_firsts`)."""made_by: list[dict[str, str]] = []lazy = _located(interpolate, made_by)- asked = partial(held_fill_mod.again, record=record, ring=ring, mode=mode, skip=skip)+ asked = partial(held_fill_mod.again, record=record, ring=ring, mode=mode, skip=skip, hold=_playing_hold)try:frames, again = asked(frames, lazy)except rife_mod.RifeNotInstalled as exc:diff --git a/tests/video/test_held_fill.py b/tests/video/test_held_fill.pyindex a2b72d1..ec8174a 100644--- a/tests/video/test_held_fill.py+++ b/tests/video/test_held_fill.py@@ -466,6 +466,26 @@ def test_a_hold_across_a_loop_s_wrap_longer_than_three_cells_is_kept_whole():assert record["before"]["wrap"]["joined"] == 4 and record["wrap_held"] is True+def test_a_cut_read_again_that_plays_on_twos_keeps_its_held_pair():+ # The read after the repairs keeps a run where the cells as they now play read drawn on twos or threes (`hold`, the+ # reading the seam and the step gate take): a walk on twos redrawn a pixel aside each repeat reads a drawing a frame as+ # filmed, so the fill keeps nothing, and the anchor brings a pair back to one picture. Read as a drawing a frame, the+ # pair is made again. The hold is asked only where a run is read.+ _, record = held_fill.fill([walk_at(t) for t in range(N)], None, ring=True)+ assert record["before"]["held_runs"] == []+ unread = [walk_at(t) for t in range(N)]+ assert held_fill.again(unread, None, record, ring=True, hold=lambda cells: pytest.fail("asked")) == (unread, None)+ frames = [walk_at(9 if t == 10 else t) for t in range(N)] # cell 10 shows cell 9's picture+ calls: list = []+ out, again = held_fill.again(frames, lambda a, b, t: calls.append(t) or a, record, ring=True, hold=lambda cells: 2)+ assert calls == [] and again["made"] == [] and again["drawn"] == 2+ assert [f.tobytes() for f in out] == [f.tobytes() for f in frames]+ assert [(h["from"], h["to"], h["kind"]) for h in held_fill.intended(again)] == [(9, 10, "drawn")]+ between = Between(walk_at, range(N), period=N)+ out, again = held_fill.again(frames, between, record, ring=True, hold=lambda cells: 1)+ assert again["made"] == [10] and "drawn" not in again and out[10].tobytes() == walk_at(10).tobytes()++def test_a_cut_played_once_does_not_read_a_wrap():frames = [walk_at(t) for t in [*range(N - 1), 0]]out, record = held_fill.fill(frames, lambda a, b, t: a, ring=False)