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): a cut that did not record its crop is judged by its cells' pixels, not refused for it

Soohong Kim17b92924d25c
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 05bd2a1..4ce8c93 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,7 +4,7 @@ All notable public changes to `sprite-gen` are recorded here. Versions track the
## 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. 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).
+- **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).
- **Output change: `video-cycle-align` records the cut it aligns from and where every cell is from.** `cycle_align.cells_from` holds, per cell of the rebuilt strip, `{"source": i}` (frame i of `cycle.source/`, as many times as it is taken) or `{"between": [i, j], "t": t}` (a frame made between two); the report's loop rows carry it too. The first alignment of a loop also records the strip as cut, read before anything is rewritten (`cycle_align.origin`: its file's sha256 — `follow.source.png`'s where a follow-through had moved it —, cell size, scale, crop origin, `sample_indices`, each cell's pixels by sha256, and the body's motion as `video-follow` reads it there), and every later alignment keeps it as it is. The strip, cycle frames, GIF and WebP are unchanged; the aligned meta gains these two keys. A loop aligned before this release has no origin and gets none: its cut is no longer there to read. [docs/loop-repair.md](docs/loop-repair.md).
- **New `video-follow --stretch-floor D`: a least area every moved pixel keeps, read by the way the region moves.** The fold rule keeps a region from folding and so lets its steepest pixel take nearly nothing of the source. A move (ox, oy) of a cos² region leaves 1 − (π/2)·hypot(ox/rx, oy/ry) of a pixel's area; each region takes the largest gain, in steps of 0.01, that keeps D in every cell, and never one above the fold rule's — where the direction would allow more (a region moving along its long axis) the fold rule's gain stands, so the floor only lowers. Under it the fold rule's handling stands: a region taken under 1 is held and named, every region held is refused, and `--on-fold refuse` refuses a move under the floor. It is opt-in with no default value: without it the fold rule alone decides, byte for byte, and a floor the move already keeps draws the same strip, GIF and WebP. The record carries `stretch` (`policy`, `floor`, per region `per_gain`, `least_cell`, `rule_gain`, `floor_gain`, `gain`, `held`, `least_area`, `under_measured`), and stderr names what lowered a region, the fold or the floor. On an aligned loop, with `--read-on`, the floor is read on the cut's motion, so a turned loop is lowered, held or refused as the cut is. [docs/video-pipeline.md](docs/video-pipeline.md#a-least-area-each-move-leaves----stretch-floor-d).
- **Output change: `video-follow-inspect` writes schema 2 — the bend and the seams beside the least area.** A move stretches the picture (`jacobian_min`, D), tilts a line by its steepest slope, |offset|·π/(2·smaller radius) (`bend`, G, with `bend_deg` = atan G; the same number as `fold_ratio`, named for what it does — at 1 a line tilts 45°), and where two regions overlap bends it where the larger move changes hands. `cells[k].seams` and the record's `seams` give, per pair of moving regions that meet, the largest jump of the move's gradient on that curve and its angle (`jump`, `deg`, the point `at`, the `cell`); a held region has none. `regions[i]` adds the largest `bend` and `bend_deg`. `inputs.settings` adds `read_on` and `stretch_floor`, `inputs.policy` the names of the ways a reading is carried and a floor kept, both in `input_id`; and `carry_basis` says what carries a region (`outline-lay`) and that whose pixels it holds is `unverified`. `video-follow`'s own record changes only where a new flag is given, and then also carries `carry_basis`. [docs/video-pipeline.md](docs/video-pipeline.md#inspecting-a-follow-through--video-follow-inspect).
diff --git a/docs/video-pipeline.md b/docs/video-pipeline.md
index bb9a162..a12cd56 100644
--- a/docs/video-pipeline.md
+++ b/docs/video-pipeline.md
@@ -1208,7 +1208,9 @@ lowercase hexadecimal digits; anything else is refused before anything is read):
- **`uncertain`**, refused: the cut is the one, but a cell was made between two of its frames
(RIFE, or any `between`), or a cell is not the cut's cell pixel for pixel — a crop or a scale
changed and nothing records how, or a cell was drawn again since. A made cell has no reading of
- its own, and none is taken from the nearer frame by rounding.
+ its own, and none is taken from the nearer frame by rounding. A cut made before its strip
+ recorded its crop (`source_rect`) says nothing of where it was cropped; there the cells' pixels
+ decide alone, as they do for every cell anyway.
- **`no-match`**, refused: neither — another clip, another cut, a strip nothing here was cut or
aligned from. Locate the regions again on this strip.
diff --git a/sprite_gen/video/follow.py b/sprite_gen/video/follow.py
index 2ba5931..4345871 100644
--- a/sprite_gen/video/follow.py
+++ b/sprite_gen/video/follow.py
@@ -364,7 +364,9 @@ def transported_motion(meta: dict[str, Any], cells: list[Image.Image], read_on:
(w, h), rect = cells[0].size, meta.get("source_rect")
now = (w, h, meta.get("scale"), None if rect is None else list(rect[:2]))
then = (origin["w"], origin["h"], origin["scale"], origin["crop_origin"])
- if now != then:
+ # A cut made before the strip recorded its crop says nothing of where it was cropped: there the cells' pixels
+ # below are the whole test, as they are for every cell anyway.
+ if now[:3] != then[:3] or (then[3] is not None and now[3] != then[3]):
raise uncertain(f"the cut's crop or scale changed (cells {then[0]}x{then[1]} at scale {then[2]} from {then[3]}, now "
f"{w}x{h} at scale {now[2]} from {now[3]}) and no transform is recorded")
frames, digests = origin["sample_indices"], origin["cells_sha256"]