Skip to content

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

perf(cycle-align): the fill at the end takes a frame between the loop's own resampling made, not RIFE again

Soohong Kim5dcc23ad2cd0
diff --git a/docs/loop-repair.md b/docs/loop-repair.md
index 14e8016..9e6f769 100644
--- a/docs/loop-repair.md
+++ b/docs/loop-repair.md
@@ -3453,7 +3453,7 @@ Measured on the tests' synthetic walker without a staff: its repairs left four r
`video-cycle-align` (and `video-set --align-cycles auto`) makes its frames between from frames as filmed, never from frames the fill made. A loop never aligned whose held cells `video-loop` made again (`held_fill.made`, or `held_fill.again.made`) is cut again from its frames with `--fill-held off`, using its report's `cut_args` (no provider call). That cut is kept as `cycle.source/` (its frames, strip and strip record) and aligned. `cycle_align.cut_again` records it: `report`, `fill_held` (`off`), `cells`, `made_before`. Where it cannot be cut again (no report beside it, a report from before cuts recorded their arguments, frames moved, the cut again took another window of frames), the alignment stops, names the loop and why, and says: cut it again with `video-loop --fill-held off` and align that.
-Then each loop as aligned is read for held cells and filled at the end (`--fill-held auto`, the default), as `video-loop` fills a loop: its first cell kept, a loop drawn on twos or threes and a hold longer than three cells kept, each frame made judged with the `held` fault among the others. This also catches a frame the alignment's own resampling took twice (`--between nearest`, or a frame made refused and the nearer source frame taken). The strip record's and the report row's `held_fill` say what was done; `holds` lists what was kept. `--fill-held off` delivers the aligned loops as they come out of the alignment. A set whose loops show no held cell is aligned as before, pinned by a picture digest measured on the engine before this change (commit 4f5ccd5).
+Then each loop as aligned is read for held cells and filled at the end (`--fill-held auto`, the default), as `video-loop` fills a loop: its first cell kept, a loop drawn on twos or threes and a hold longer than three cells kept, each frame made judged with the `held` fault among the others. This also catches a frame the alignment's own resampling took twice (`--between nearest`, or a frame made refused and the nearer source frame taken). The fill at the end can also ask for a frame between that the loop's own resampling already made for that loop and gave way, under `--between auto`. That frame is taken from what the resampling made, and RIFE is not run for it again. With `--between-cache`, such a frame is not asked of the directory a second time, so the report's `between_cache` counts each frame once. The strip record's and the report row's `held_fill` say what was done; `holds` lists what was kept. `--fill-held off` delivers the aligned loops as they come out of the alignment. A set whose loops show no held cell is aligned as before, pinned by a picture digest measured on the engine before this change (commit 4f5ccd5).
`--out-fps F` gives every loop of the set at F, above the loops' own rate, once aligned: each cell at its own time, made between the cells beside it, never a cell shown again, every loop the same number of cells. The strip metadata says `out_fps` and `source_fps`. A rate not above the loops' own is refused. A loop already aligned at a higher rate is aligned again from its `cycle.source/` at its source rate.
diff --git a/sprite_gen/video/align.py b/sprite_gen/video/align.py
index 8a4959f..798f441 100644
--- a/sprite_gen/video/align.py
+++ b/sprite_gen/video/align.py
@@ -96,6 +96,7 @@ the frames taken and made (`between_cache`). Nothing is kept without it.
from __future__ import annotations
import argparse
+import hashlib
import json
import math
import shutil
@@ -1492,20 +1493,30 @@ def align_set(loop_dirs: list[Path], *, length: int | None = None, interpolate:
lengths = [len(f) for f in sources]
target = length if length is not None else round(statistics.median(lengths))
located: list[dict[str, str]] = []
+ # The frames between made for the loop being aligned, by their two frames and time: the fill at the end asks again
+ # for a frame its resampling made and gave way (`--between auto`), and takes it here rather than run RIFE again.
+ made_here: dict[tuple[str, str, str, str, str], Image.Image] = {}
def lazy(a: Image.Image, b: Image.Image, t: float) -> Image.Image:
nonlocal interpolate
+ key = (a.mode, f"{a.size}", hashlib.sha256(a.tobytes()).hexdigest(), hashlib.sha256(b.tobytes()).hexdigest() + b.mode
+ + f"{b.size}", float(t).hex())
+ if key in made_here:
+ return made_here[key].copy()
if interpolate is None:
found = rife_mod.Rife()
located.append(found.describe())
interpolate = found
- return cache.frame(interpolate, a, b, t) if cache is not None else interpolate(a, b, t)
+ frame = cache.frame(interpolate, a, b, t) if cache is not None else interpolate(a, b, t)
+ made_here[key] = frame.copy()
+ return frame
# Every loop is resampled before any is rewritten: a loop that cannot be made leaves the set as it was. The cut
# each is aligned from is read first, while its strip is still the cut's.
origins = [origin_of(d, meta_path, meta) for d, meta_path, meta, _ in loops]
aligned = []
for i, ((d, *_), frames, view) in enumerate(zip(loops, sources, views or [None] * len(loops))):
+ made_here.clear()
# which frame of cycle.source/ each of `frames` is: all of them, or the one cycle `--cycles` took out
index = ([(taken[i]["start"] + k) % taken[i]["from"] for k in range(taken[i]["length"])] if i in taken
else list(range(len(frames))))