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(held-cut-repair): a held fixed cut is read from its source frames held again — the loop report records the move each frame of the cut was held by (size_hold.cut_frames: scale, foot_point_px, lift_px, exact floats; gait_fallback.frame_hold), and the source projection holds each source frame by it and padding_ltrb (gait_fallback.hold_frame, the move undo_scale makes) before the scrub, the ramp, the crop and the resample; it reads a held cut only with the moves and the hashes before repair, which prove every frame of the cut, a replaced cell's move included; a report without the moves (3.1.0) stays source-processing-unsupported, malformed moves are an error; the projection record gains size_hold on a held cut, unheld cuts keep their bytes. --size-hold help, video-pipeline §4 and loop-comparison's projection paragraph and tables say so (text by the writing hand-off)

Soohong Kimaa728bf352f1
diff --git a/docs/loop-comparison.md b/docs/loop-comparison.md
index 3a22155..0dbd995 100644
--- a/docs/loop-comparison.md
+++ b/docs/loop-comparison.md
@@ -267,7 +267,7 @@ application owns its deadline, attempted IDs and adoption transaction.
| `proposal_id`, `target` | Selected identity and zero-based cell; null for a no-op |
| `applied_cells` | Cells earlier requests restored, in order, as rebuilt from the origin |
| `origin_artifacts`, `baseline_artifacts`, `candidate_artifacts` | Exact five-file byte receipts (`sha256`, `bytes` per file) |
-| `source_artifacts`, `projection` | Source inputs, fixed transform, sample PTS and exact correspondence |
+| `source_artifacts`, `projection` | Source inputs, fixed transform, size hold applied on a held cut (`size_hold`: `padding_ltrb` and `cut_frames`), sample PTS and exact correspondence |
| `partial.copied`, `partial.capped`, `partial.protected` | The three masks of the target: `size`, `count`, row-major run lengths `rle` (the first run is clear) and `sha256` of the packed bits |
| `partial.alpha_equals_source` | Whether the output's coverage is the source's; `false` only with `protected-pixel-alpha-conflict` |
| `partial.capped_pixels` | `count`, and for the first 256 in row order (`listed`) `x`, `y`, `origin_rgba`, `source_rgba`, `output_rgba`, and `source_window` (`[left, top, right, bottom]`, inclusive, in the cropped source frame) |
@@ -287,11 +287,15 @@ reported as `no_change`.
The supported projection is scrub, small-component cleanup, optional integer
body ramp, one shared integer crop and the standard resampler. New loop reports
-also record hashes before repair. Legacy crops are bounded by the recorded
+also record hashes before repair. A held fixed cut is projected by first holding
+each source frame by its recorded move (`size_hold.cut_frames`, `padding_ltrb`).
+This needs the report's hashes before repair and checks every frame against
+them; a held cut without the recorded moves (3.1.0) stays unknown
+(`source-processing-unsupported`). Legacy crops are bounded by the recorded
scale recipe and canvas, with a search limit of 4096 hypotheses; multiple exact
matches remain unknown. Frame-specific alignment, different cuts, subsampling,
-size hold, motion anchoring, cycle alignment, or unproven follow warps are not
-accepted. Do not rerun follow on a restoration output.
+motion anchoring, cycle alignment, or unproven follow warps are not accepted.
+Do not rerun follow on a restoration output.
### The receipt and what a later request rebuilds
@@ -306,7 +310,7 @@ comparison reports, not in the loop report, which cannot hold its own digest.
| `operation`, `metric_version`, `policy_version` | This contract |
| `origin_artifacts` | The origin's five byte receipts |
| `source_artifacts`, `source` | Source input receipts and the ordered keyed sequence identity |
-| `projection` | Recipe, crop, cell, scale, wrap, samples, PTS, reference pixel hashes |
+| `projection` | Recipe, crop, cell, scale, wrap, size hold applied on a held cut (`size_hold`: `padding_ltrb` and `cut_frames`), samples, PTS, reference pixel hashes |
| `applied` | One entry per restored cell, in the order they were adopted; a cell appears once |
| `applied[].target`, `source_index` | The cell and its source frame |
| `applied[].copied`, `capped`, `protected` | The three masks, as in the repair report |
diff --git a/docs/video-pipeline.md b/docs/video-pipeline.md
index 7639e78..0d4a85e 100644
--- a/docs/video-pipeline.md
+++ b/docs/video-pipeline.md
@@ -365,7 +365,7 @@ and a true cycle half a drawing late are **the same picture**. So
**The size is held before the search or cut** (`--size-hold auto`, the default). A walk or run clip filmed from its first frame only often grows or shrinks as it plays, so the frame one cycle after the first is not the first's size and the loop pops at the wrap. Under `--size-hold auto`, a walk or run cut automatically with `--anchor motion-auto` (before the cycle search) or cut by hand with `--cycle fixed` under any anchor (before the cut is read, over the whole clip) is held at its first frame's size. When a clip's height changes by 1 % or more over the clip, read one cycle on, frames are scaled back to the first frame's size about their feet. Where the size is held and the feet climb or sink by 1 % of the first frame's height or more over the clip, frames are also shifted so their feet stand on the first frame's row. This stops a receding walk's jump at the wrap from moving into place: the motion anchor's fine search corrects a climb within 28 rows over the cut but leaves the cut uncorrected when feet climb further than that, and the body anchor moves frames sideways only.
-The cut's seam and step count are measured on the held frames. A fixed cut is held only where the cut itself shows the change, comparing each frame of the cut with the frame one cycle of the cut's length later, or, where the clip ends before that frame, with the frame one cycle earlier, and feet are moved only where the cut shows them move. Where the cut does not show the change, it is cut as filmed, and the report says why. The report records `size_hold` with `padding_ltrb`, and records `size_hold.feet` when size is held. Fixed cuts with `--anchor motion` record the shifted target boxes in `size_hold.anchor_regions`. Automatic searches under `--anchor body`, `feet`, or `none`, `--cycle pinned`, and cuts of states that are not a walk or run are not held. A held cut is not restored from its source frames by `video-loop-repair`.
+The cut's seam and step count are measured on the held frames. A fixed cut is held only where the cut itself shows the change, comparing each frame of the cut with the frame one cycle of the cut's length later, or, where the clip ends before that frame, with the frame one cycle earlier, and feet are moved only where the cut shows them move. Where the cut does not show the change, it is cut as filmed, and the report says why. The report records `size_hold` with `padding_ltrb`, records `size_hold.feet` when size is held, and also records `size_hold.cut_frames` on a held fixed cut. Fixed cuts with `--anchor motion` record the shifted target boxes in `size_hold.anchor_regions`. Automatic searches under `--anchor body`, `feet`, or `none`, `--cycle pinned`, and cuts of states that are not a walk or run are not held. `video-loop-repair` restores a held fixed cut from its source frames by holding them again by those moves (a report without them, from 3.1.0, is not restored).
Passing `--size-hold off` on a fixed cut keeps the filmed frames pixel for pixel and records `size_hold: {"applied": false, "why": "--size-hold off"}`. Under `--anchor motion-auto`, `--size-hold off` searches the filmed frames first, but if the first search finds no cycle, the gait fallback still scales back a size change of 3 % or more with feet left where filmed and searches again.
diff --git a/sprite_gen/video/gait_fallback.py b/sprite_gen/video/gait_fallback.py
index e42ce61..3807018 100644
--- a/sprite_gen/video/gait_fallback.py
+++ b/sprite_gen/video/gait_fallback.py
@@ -377,20 +377,29 @@ def undo_scale(frames: list[Image.Image], measured: dict, pad: tuple[int, int, i
a part scaled up past the frame's edge is kept. A crown carried above the frame was cut off
in every frame it reached. With no room needed the frames keep their size and bytes.
"""
- height, foot_x, foot_y = measured["height"], measured["foot_x"], measured["foot_y"]
- left, top, right, bottom = undo_padding(frames, measured, lift) if pad is None else pad
- out = []
- for k, frame in enumerate(frames):
- s = float(height[0] / height[k])
- ax, ay = float(foot_x[k]), float(foot_y[k])
- # Output (x, y) reads input anchor + (x - room - anchor) / s; held, y - room - anchor - lift.
- ry = ay * (1 - 1 / s) - top / s
- if lift is not None:
- ry -= float(lift[k]) / s
- inverse = (1 / s, 0.0, ax * (1 - 1 / s) - left / s, 0.0, 1 / s, ry)
- size = (frame.width + left + right, frame.height + top + bottom)
- out.append(transform_cell(frame, size, inverse))
- return out
+ pad = undo_padding(frames, measured, lift) if pad is None else pad
+ return [hold_frame(frame, frame_hold(k, measured, lift), pad) for k, frame in enumerate(frames)]
+
+
+def frame_hold(k: int, measured: dict, lift: np.ndarray | None = None) -> dict:
+ """How `undo_scale` moves frame `k`: `scale`d about its fitted foot point (`foot_point_px`, x and y), then
+ `lift_px` down (up, negative), None where the feet stay where they were filmed. Python floats, which JSON
+ carries exactly, so the move recorded is the move made again (`hold_frame`)."""
+ return {"scale": float(measured["height"][0] / measured["height"][k]),
+ "foot_point_px": [float(measured["foot_x"][k]), float(measured["foot_y"][k])],
+ "lift_px": None if lift is None else float(lift[k])}
+
+
+def hold_frame(frame: Image.Image, move: dict, pad: tuple[int, int, int, int]) -> Image.Image:
+ """One frame moved as `frame_hold` says, widened by `pad` (left, top, right, bottom): `undo_scale`'s frame."""
+ s, (ax, ay), lift = move["scale"], move["foot_point_px"], move["lift_px"]
+ left, top, right, bottom = pad
+ # Output (x, y) reads input anchor + (x - room - anchor) / s; held, y - room - anchor - lift.
+ ry = ay * (1 - 1 / s) - top / s
+ if lift is not None:
+ ry -= lift / s
+ inverse = (1 / s, 0.0, ax * (1 - 1 / s) - left / s, 0.0, 1 / s, ry)
+ return transform_cell(frame, (frame.width + left + right, frame.height + top + bottom), inverse)
def held_box(box: tuple[int, int, int, int], k: int, measured: dict, pad: tuple[int, int, int, int],
diff --git a/sprite_gen/video/loop.py b/sprite_gen/video/loop.py
index 4a51966..c789413 100644
--- a/sprite_gen/video/loop.py
+++ b/sprite_gen/video/loop.py
@@ -1720,7 +1720,8 @@ def _size_hold(frames: list[Image.Image], *, lo: int, hi: int,
settles into the walk is not taken for a body that shrinks, nor for feet that climb (gait_fallback.cycle_drift,
foot_drift). A cut the caller names (`cut`: start, length) is held only where it shows the change itself, a cycle
of its length apart (`gait_fallback.at_cut`), and its feet are moved only where it shows them move: a clip whose
- frames that are not the walk read a change the cut does not make is cut as filmed (`size_hold.at_cut`, `why`)."""
+ frames that are not the walk read a change the cut does not make is cut as filmed (`size_hold.at_cut`, `why`).
+ Held, its record carries the move each frame of the cut was held by (`size_hold.cut_frames`)."""
measured = gait_fallback.cycle_drift(frames, min_lag=lo, max_lag=hi)
hold: dict[str, Any] = {"applied": False, "min": gait_fallback.SIZE_HOLD_MIN,
**{k: measured[k] for k in ("height_first_px", "height_last_px", "drift", "method",
@@ -1741,6 +1742,10 @@ def _size_hold(frames: list[Image.Image], *, lo: int, hi: int,
pad = gait_fallback.undo_padding(frames, measured, lift)
held = gait_fallback.undo_scale(frames, measured, pad=pad, lift=lift)
hold.update(applied=True, padding_ltrb=list(pad), feet=feet)
+ if cut is not None:
+ # The move each frame of the cut was held by, exact (`gait_fallback.frame_hold`): `video-loop-repair` holds the
+ # cut's source frames by it again before it reads them (sprite_gen/video/source.py).
+ hold["cut_frames"] = [gait_fallback.frame_hold(k, measured, lift) for k in range(cut[0], cut[0] + cut[1])]
return held, hold, partial(gait_fallback.held_box, measured=measured, pad=pad, lift=lift)
@@ -2605,7 +2610,7 @@ def add_arguments(parser: argparse.ArgumentParser) -> None:
f"cut is gated by its pin. --seam-max does not lift it. off: no gate — over {repair_mod.SEAM_POP_REFERENCE:g} "
"is a warning line (docs/loop-repair.md section 3, \"The seam pop\")")
parser.add_argument("--facing", choices=FACINGS, default="right", help="which way the body faces in the frames (default right): the jolt index's hair, and the size reading video-loop-compare's jump guard reads, are behind it; the jump repair reads the flow either way")
- parser.add_argument("--size-hold", choices=SIZE_HOLD_MODES, default="auto", help="walk/run, --anchor motion-auto or --cycle fixed: auto (default) scales a clip whose height, read one cycle on, changes by 1 %% or more over the clip back to its first frame's size about its feet, and moves its feet to the first frame's row where they climb or sink by 1 %% of the height or more, applied before the cycle search or over the whole clip before a fixed cut is read (a fixed cut is held only where the cut itself shows the change a cycle of its length apart; recorded as size_hold; a held cut is not restored from source frames); off: the frames as filmed, except motion-auto's gait fallback, which after a first search that finds nothing still scales back a change of 3 %% or more by the same reading, its feet where they were filmed (recorded as gait_fallback)")
+ parser.add_argument("--size-hold", choices=SIZE_HOLD_MODES, default="auto", help="walk/run, --anchor motion-auto or --cycle fixed: auto (default) scales a clip whose height, read one cycle on, changes by 1 %% or more over the clip back to its first frame's size about its feet, and moves its feet to the first frame's row where they climb or sink by 1 %% of the height or more, applied before the cycle search or over the whole clip before a fixed cut is read (a fixed cut is held only where the cut itself shows the change a cycle of its length apart; recorded as size_hold, with each frame's move on a held fixed cut (size_hold.cut_frames), which video-loop-repair holds the source frames by again); off: the frames as filmed, except motion-auto's gait fallback, which after a first search that finds nothing still scales back a change of 3 %% or more by the same reading, its feet where they were filmed (recorded as gait_fallback)")
parser.add_argument("--steps", type=int, choices=STEPS, default=None,
help="--anchor motion-auto: how many steps the cut it takes without this holds, as counted by whoever looked "
"at the loop (how often each foot lands) — the report's `cycle.step_screen` names a cut that may be one "
diff --git a/sprite_gen/video/source.py b/sprite_gen/video/source.py
index c28fdec..d51107c 100644
--- a/sprite_gen/video/source.py
+++ b/sprite_gen/video/source.py
@@ -138,12 +138,32 @@ class Source:
class Projection:
frames: list[Image.Image]
record: dict[str, Any]
- cropped: list[Image.Image] # what each cell was resampled from: the cleaned, ramped source frame cut to the crop
+ cropped: list[Image.Image] # what each cell was resampled from: the held, cleaned, ramped source frame cut to the crop
+
+
+def _cut_moves(hold: dict[str, Any], n: int) -> tuple[list[dict[str, Any]], tuple[int, int, int, int]]:
+ """The move each frame of a held fixed cut was held by (`size_hold.cut_frames`, `gait_fallback.frame_hold`) and the
+ room every frame was widened by (`padding_ltrb`): one move per frame of the cut, in order."""
+ moves, pad = hold.get("cut_frames"), hold.get("padding_ltrb")
+
+ def number(v: Any) -> bool:
+ return type(v) in (int, float) and math.isfinite(v)
+
+ if (not isinstance(moves, list) or len(moves) != n or not isinstance(pad, list) or len(pad) != 4
+ or any(type(v) is not int or v < 0 for v in pad)
+ or any(not isinstance(move, dict) or set(move) != {"scale", "foot_point_px", "lift_px"}
+ or not number(move["scale"]) or move["scale"] <= 0
+ or not isinstance(move["foot_point_px"], list) or len(move["foot_point_px"]) != 2
+ or not all(number(v) for v in move["foot_point_px"])
+ or not (move["lift_px"] is None or number(move["lift_px"])) for move in moves)):
+ raise ValueError("invalid size_hold.cut_frames")
+ return moves, tuple(pad) # type: ignore[return-value]
def project(baseline: Any, source: Source) -> tuple[Projection | None, str | None]:
- """Prove one shared crop against all cells outside the recorded repair hints."""
- from sprite_gen.video import loop
+ """Prove one shared crop against all cells outside the recorded repair hints. A fixed cut held at its size
+ (`size_hold`) is read on its source frames held again, each by the move its report records for it."""
+ from sprite_gen.video import gait_fallback, loop
from sprite_gen.video.frames import drop_specks
m, report = baseline.meta, baseline.source_report
@@ -183,16 +203,22 @@ def project(baseline: Any, source: Source) -> tuple[Projection | None, str | Non
anchor = m.get("foot_anchor")
if anchor not in ("none", "body") or report.get("anchor") != anchor:
return None, "source-anchor-unsupported"
- if any(k in m for k in ("cycle_align", "motion_anchor", "wrap_blend")) or report.get("size_hold", {}).get("applied"):
+ hold = report.get("size_hold", {})
+ # A held cut is read again only where its report records each frame's move, and the cut's frames before repair to
+ # prove every one of them on (`source_projection`, the moves of the cells the repair replaced included).
+ held = bool(hold.get("applied"))
+ if (any(k in m for k in ("cycle_align", "motion_anchor", "wrap_blend"))
+ or held and ("cut_frames" not in hold or report.get("source_projection") is None)):
return None, "source-processing-unsupported"
+ moves, pad = _cut_moves(hold, n) if held else (None, None)
hints = (report.get("jump_repair") or {}).get("replaced", [])
if (not isinstance(hints, list) or any(type(k) is not int or not 0 <= k < n for k in hints)
or len(set(hints)) != len(hints) or len(hints) > n // 2):
return None, "repair-locations-unverified"
keep = [k for k in range(n) if k not in hints]
frames = []
- for frame in source.frames[start:start + n]:
- frame = frame.copy()
+ for j, frame in enumerate(source.frames[start:start + n]):
+ frame = gait_fallback.hold_frame(frame, moves[j], pad) if moves else frame.copy()
loop._scrub(frame)
frames.append(drop_specks(frame, alpha_over=16, diagonal=False, apart=0)[0])
dx = loop.body_wrap_offset(frames) if anchor == "body" else 0
@@ -254,6 +280,8 @@ def project(baseline: Any, source: Source) -> tuple[Projection | None, str | Non
"samples": list(range(start, start + n)), "pts_seconds": pts[start:start + n],
"unmodified_cells": keep, "repair_hints": hints, "exact_projections": 1,
"reference_pixels_sha256": [evidence.digest(f.tobytes()) for f in projected]}
+ if moves:
+ receipt["size_hold"] = {"padding_ltrb": list(pad), "cut_frames": moves}
return Projection(projected, receipt, cropped), None