Skip to content

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

docs(video-sway): --read-on-cut reads each step a cut's report says as video-loop writes it, and refuses a report that does not say it so, in docs/video-pipeline.md section 6 and the CHANGELOG's Unreleased

Soohong Kimfc7788a8a670
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6769fc8..3f54d9f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -27,7 +27,7 @@ All notable public changes to `sprite-gen` are recorded here. Versions track the
- **New: holding pixels through banded sway (`--hold-mask`).** `--hold-mask MASK.png|DIR` leaves pixels as they are while a band moves its regions round them, requiring `--band` and off by default, byte for byte as before when not given. The mask is a PNG drawn on the cell the regions were read on (holding pixels where alpha is 128 or more; where the PNG has no alpha, grey 128 or more) or a folder of PNGs giving one mask per cell in file-name order. One mask is split into 8-connected pieces, each carried into every cell by its own solid pixels within `CARRY_SEARCH` (9) px by least squared difference of premultiplied colour and parabolic fitting (reverting to body lay with a warning on stderr when uncertain or covering no solid pixel), then grown by `HOLD_GROW` (3) px. Each cell keeps byte for byte the mask pixels, soft edges, and air within `ceil(reach) + HOLD_EDGE` (2) px. Other pixels are read short of kept pixels along the move direction by `f = min(s, h)` px, where `h` is `HOLD_SLOPE` (0.5) times free distance to kept or margin pixels (`HOLD_MARGIN` of 1 px), bounded to rise by at most `HOLD_SLOPE` per pixel (`read_share`). Reads touching forbidden pixels are renormalised or walked back by 1/`HOLD_STEPS` (1/16) of their move. Metadata gains `follow.hold` (and `sway.json` gains `hold` for `--frames`), while stdout JSON gains `hold` with `pieces`, `lay_cells`, and `read_folded_px_max`.
- **New: a region given as a mask (`--region-mask`, `--region-rim`, `--region-shrink`, `--region-crease`).** `--region-mask MASK.png|DIR` gives the region as a mask of the part's own pixels instead of the ellipse's weight, moving the part while holding every visible pixel outside it and its soft edge in every cell, off by default and byte for byte as before when not given. The mask is a PNG drawn on the cell the regions were read on (alpha 128 or more, or grey 128 or more where it has no alpha) or a folder of PNGs giving one mask per cell in file-name order. When requested, `--region-crease` aligns the mask's lower edge to the median darkest row from `CREASE_UP` (5) rows above to `CREASE_DOWN` (3) rows below over `CREASE_SPAN` (2) columns either way, and `--region-shrink PX` (default `SHRINK_DEFAULT`, 2) wears the mask in by 4-neighbour steps. With `--region-crease`, after the mask is worn in, each column the crease ended where the worn mask still holds a pixel is filled back down to the crease row with the mask's pixels before wear (`crease_kept`), leaving the crease edge where it is while wearing in the rest of the mask; the record's `mask.box` now ends on the crease row. One mask is carried into each cell by its own solid pixels within `CARRY_SEARCH` (9) px by least squared difference of premultiplied colour, searching round the cell before and the body's lay, keeping the carry of the cell before when neither settles. The region and its soft edge (pixels not opaque within `REGION_SOFT`, 2, px of the region, not beside another solid pixel) move, and the air (clear pixels within `ceil(reach) + REGION_AIR`, 2, px of the region) is where they may move into; every other visible pixel is held. Inside the region, its soft edge and the air, weight rises by `sin²(pi/2 x d)` from 0 at held pixels to 1 across a rim scaled by `--region-rim SCALE` (default `RIM_DEFAULT`, 1.0) and widened until slope is at most `RIM_SLOPE` (0.9), preventing folding. With `--band-up`, weight is the lesser of the rim and the upper yield. Strip metadata gains `follow.region_mask` (and `sway.json` gains `region_mask` for `--frames`), while stdout JSON gains `region_mask` with `kept_cells`, `rim_px`, `move_most_px`, and `walked_px_max`. See [video-pipeline](docs/video-pipeline.md) section 6.
- **New: laying a region over the figure and widening the rim for shear (`--region-over`, `--region-shear`).** `--region-over` lays the region over the figure under it instead of pinning its lower edge, freeing held pixels under the edge (solid or not), moving the band within reach, drawing the layer over band and air pixels by alpha, and showing the figure under the region in its own column where it lifts. Its soft edge moves with the region (except under the lower edge where touching a solid pixel outside keeps it in the band), its solid outline against air goes with the layer, and `--hold-mask` leaves pixels out of the layer and band. `--region-shear S` widens the rim across and down so a move one way rises across the rim the other way by at most S px per px (`shear_floor`), preventing tears along the sides. With either option, the ledger records move steps between neighbouring pixels, still strips left standing, and tip outline shapes, and `--region-over` records `lifted_px`. Both require `--region-mask`, are off by default, and leave strips, frames, and records byte for byte what they were when not given. See [video-pipeline](docs/video-pipeline.md) section 6.
-- **New: solid under-edges, round rims, figure membranes, and recut strip pairing (`--region-over-solid`, `--region-rim-round`, `--region-membrane`, `--read-on-cut`).** `--region-over-solid` frees only solid pixels (alpha 128 or more) under the lower edge into the band while keeping softer pixels as anchors, and carries the region's soft edge with it under the lower edge. `--region-rim-round` holds the rim round beside the region across the wider of its two widths (`max(Lx, Ly)`), preventing steep downward steps below corners where the lower edge runs lower. `--region-membrane N` moves the figure under the lower edge within N + 1 px as a membrane by solving 4-neighbour figure means with conjugate gradients so the figure stretches rather than slides, drawing membrane pixels by their move and reporting membrane-specific fold refusals. `--read-on-cut STRIP` pairs regions read on another cut of the same clip by matching source frame numbers and applying a whole-pixel shift across crops on unaligned and aligned loops alike. The shift is taken on the frame as filmed, less where each cut's body or motion anchor moved that frame. It pairs a frame only where each cut's report beside its strip says that frame is in the cut as filmed. A run is refused if a report is missing or is another cut's, if frames were scaled by the size hold or gait fallback, or if the frame was altered by jump repair, seam bridges, overlap, or wrap blending. All four options are off by default and leave strips, frames, and records byte for byte what they were when not given. See [video-pipeline](docs/video-pipeline.md) section 6.
+- **New: solid under-edges, round rims, figure membranes, and recut strip pairing (`--region-over-solid`, `--region-rim-round`, `--region-membrane`, `--read-on-cut`).** `--region-over-solid` frees only solid pixels (alpha 128 or more) under the lower edge into the band while keeping softer pixels as anchors, and carries the region's soft edge with it under the lower edge. `--region-rim-round` holds the rim round beside the region across the wider of its two widths (`max(Lx, Ly)`), preventing steep downward steps below corners where the lower edge runs lower. `--region-membrane N` moves the figure under the lower edge within N + 1 px as a membrane by solving 4-neighbour figure means with conjugate gradients so the figure stretches rather than slides, drawing membrane pixels by their move and reporting membrane-specific fold refusals. `--read-on-cut STRIP` pairs regions read on another cut of the same clip by matching source frame numbers and applying a whole-pixel shift across crops on unaligned and aligned loops alike. The shift is taken on the frame as filmed, less where each cut's body or motion anchor moved that frame. It pairs a frame only where each cut's report beside its strip says that frame is in the cut as filmed. A run is refused if a report is missing or is another cut's, if frames were scaled by the size hold or gait fallback, or if the frame was altered by jump repair, seam bridges, overlap, or wrap blending. Each step's record is now read as `video-loop` writes it, and the run is refused where a report lacks a record `video-loop` always writes, where the report's strip does not say the cut's anchor, kind or state that tells, where a record is not a JSON object or a field of one is missing or not of its kind, or where `applied` is not borne out by its list. All four options are off by default and leave strips, frames, and records byte for byte what they were when not given. See [video-pipeline](docs/video-pipeline.md) section 6.
- Python callers: `sway_loop`, `sway_frames`, `read_request`, and `read_ask` accept `band`, `band_margin`, and `band_up` (`band_up` as `(flat, px_or_"auto")` or command-line string). New in `sprite_gen.video.sway`: `band_weight`, `band_shapes`, `carry_match`, `carry_own`, `band_steepest`, `steepest_gain`, `band_ledger`, `band_notes`, and `jacobian` (moved from `sway_inspect`, which retains it under the same name); constants `BAND_POLICY`, `CARRY_BASIS_BAND`, `CARRY_SEARCH`, `HANG_PAST`, `PRESSED`, `STRETCHED`, `MOVED_PX`, and `AUTO`; and methods `Answer.band_field(k, xx, yy)` and `Answer.band_record()`. `sway_loop`, `sway_frames`, `read_request`, and `read_ask` accept `hold_mask` (a Path to a PNG or folder; None: off); new in `sprite_gen.video.sway`: `Hold`, `read_hold`, `Held`, `hold_sets`, `free_back`, `read_share`, `draw_held`, `hold_ledger`, `hold_notes`, and `carry_mask`; constants `HOLD_POLICY`, `HOLD_GROW`, `HOLD_EDGE`, `HOLD_MARGIN`, `HOLD_SLOPE`, `HOLD_ROUND`, and `HOLD_STEPS`; `Ask.hold`, `Answer.hold`, `Answer.held_cell(k)`, and `Answer.hold_record()`; and `carry_own` now calls `carry_mask` (same behaviour).
- Python callers: `sway_loop`, `sway_frames`, `read_request`, and `read_ask` accept `region_mask` (a Path to a PNG or a folder; None: off), `region_rim` (float; None: 1.0), `region_shrink` (int; None: 2), and `region_crease` (bool); new in `sprite_gen.video.sway`: `RegionMask`, `Masked`, `crease_of`, `carry_region`, `rim_bands`, `rim_distance`, `region_sets`, `region_ledger`, and `region_notes`; constants `REGION_POLICY`, `RIM_SLOPE`, `RIM_DEFAULT`, `SHRINK_DEFAULT`, `REGION_SOFT`, `REGION_AIR`, `CREASE_UP`, `CREASE_DOWN`, and `CREASE_SPAN`; `Ask.mask`, `Answer.mask`, `Answer.mask_field(k, xx, yy)`, `Answer.masked_cell(k)`, and `Answer.mask_record()`; and `draw_held` gains `short` (default true; false reads every pixel at its whole move).
- Python callers: `sway_loop`, `sway_frames`, `read_request` and `read_ask` accept `region_over` (bool; default False) and `region_shear` (float; None: off). New in `sprite_gen.video.sway`: `crease_kept`, `shear_floor`, `layer_sets`, `lay_over`, `cover_depth`, `still_strip`, `tip_shape` and `move_steps`; constants `OVER_POLICY`, `TIP_COLS`, `TIP_AIR`, `TIP_RING`, `TIP_OFF` and `TIP_SEARCH`; `RegionMask` gains `over`, `shear`, `hold` and `edges()`; `Masked` gains `sheared`, `left_out` and `left_out_in(k)`; `rim_bands` gains `floor` (None: as before).
@@ -118,6 +118,9 @@ All notable public changes to `sprite-gen` are recorded here. Versions track the
- a cut with no report beside its strip, and a cut whose report beside it is the same cut's of another take, each on the cut `--read-on-cut` names and on this loop's, are refused with two distinct reasons;
- the seam bridge, the overlapped wrap, the wrap blend, the gait fallback, a report that does not say what the jump repair made, and frames not named as whole frames are each refused saying which;
- the walk away from the camera of the gait fallback tests, cut twice by `video-loop` as a walk with the size hold on for one cut, for the other, and for both, is refused, leaving the loop as it was;
+ - a report that does not say what a step did as `video-loop` writes it, on the cut `--read-on-cut` names or on this loop's, is refused naming the field and leaving the loop as it was; the cases: a step's record that is not a JSON object, a field of one missing or not of its kind, no `size_hold` record on a walk cut given with `--cycle fixed` or on a cut at `--anchor motion-auto`, no `wrap_blend` record on a pinned cut, a strip that does not say its anchor, kind or state where that tells, and an `applied` its list does not bear out;
+ - what `video-loop` writes of a step that did not run, in both cuts' reports, leaves the frame paired as before, the mask landing on the patch there;
+ - the walk away from the camera of the gait fallback tests, cut by `video-loop` with the size hold on, its report changed so that it no longer says the cut was held (`size_hold.applied` or the whole `size_hold` record removed on either cut), is refused;
- the command line reads the relation `recut`.
`tests/video/test_follow_inspect.py` now names `--region-over-solid`, `--region-membrane`, `--read-on-cut` and `--region-rim-round` among the arguments `video-sway` takes and `video-sway-inspect` does not.
diff --git a/docs/video-pipeline.md b/docs/video-pipeline.md
index 99532f8..27c97ad 100644
--- a/docs/video-pipeline.md
+++ b/docs/video-pipeline.md
@@ -694,31 +694,44 @@ lowercase hexadecimal digits; anything else is refused before anything is read):
(`gait_fallback.scale_undone`) held cut frames to one size before cutting, which refuses the whole
cut whatever frame is paired. It also occurs if `jump_repair` omits what jump repair made, if the
paired frame is in `jump_repair.replaced`, `wrap_overlap.frames`, or `wrap_blend.cells`, or if one
- of those three lists does not name its frames as whole frames. The refusal names whose records do
- not give that frame as filmed (the cut's, given by `--read-on-cut`, or this loop's), and why. The
- regions' centres, a `--region-mask` PNG, and a single `--hold-mask` PNG are moved pixel for pixel
- onto cell j by the whole pixel shift derived from their crops and cell sizes taken on the frame as
- filmed, provided every pixel lands within `RECUT_DRIFT` (1.0 px) of that shift. Each cut's crop is
- its `source_rect` less where its anchor moved that frame before the crop. The anchor moves nothing
- at `--anchor none`, moves frame k of a cut L frames long across by round(`wrap_dx_px` x k / L) px
- at `--anchor body`, and lays frame k at the left and top of `padding_ltrb` plus that frame's entry
- of `shifts_xy` at `--anchor motion` and `--anchor motion-auto`. On an unaligned loop the regions
- are read on cell j and carried from there, while on an aligned loop they sit on the aligned cell
- matching cut cell j and are carried as `transported` carries them. A run is refused no-match if
- the clips differ, if either cut lacks recorded source frames, if this loop does not hold that
- source frame, if a record does not give where its anchor moved the frame, or if the strip
- `--read-on-cut` names is a loop aligned from its cut (`cycle_align`), whose cells are not the
- cut's frames in order, and refused uncertain if a cut records no crop, if crops, scales and
- anchors set pixels more than 1 px off one whole shift, or if an aligned loop holds no cell for cut
- cell j. `STRIP` is that cut's strip PNG, whose bytes must have the sha256 `--read-on` names, with
- its record beside it as `video-loop` writes one using the same file name ending `.json` instead of
- `.png`, refusing with "--read-on-cut names the strip --read-on names by its sha256; it needs
- --read-on" when `--read-on` is not given and "wants the strip's PNG and its record beside it" when
- either file is missing. Masks are moved by the shift alone with no polygon grown and no scaling,
- while a mask pixel that would leave the cell refuses the run, and a folder of masks (one per cell)
- is refused under `--read-on-cut` with "regions read on another cut (--read-on-cut) are drawn on
- its cell 0 alone: give one PNG". `video-sway` takes `--read-on-cut` on `--loop-dir` only, and
- `video-sway-inspect` does not take it.
+ of those three lists does not name its frames as whole frames. Each step's record in each cut's
+ report is read as `video-loop` writes it, and a missing record or field is never taken for a step
+ that did not run. `video-loop` writes the `jump_repair` record of every cut, the `size_hold`
+ record of every cut at `--anchor motion-auto` and of every walk or run cut given with
+ `--cycle fixed`, and the `wrap_blend` record of every pinned cut, whether the step ran or not, but
+ the `gait_fallback` and `wrap_overlap` records only where the step ran or was asked; the report's
+ strip tells those cuts by its `foot_anchor`, `kind` and `state`. The run is also refused no-match
+ if a report lacks a record `video-loop` always writes of that cut, if the report's strip does not
+ say the anchor, kind or state that tells, if a step's record is not a JSON object or a field of
+ one is missing or not of its kind (`size_hold.applied`, `gait_fallback.scale_undone`,
+ `jump_repair.applied` and `wrap_blend.applied` must be true or false), or if an `applied` is not
+ borne out by its list (true with no frame named, or false with one named). What `video-loop`
+ writes of a step that did not run still pairs: `applied` false with no list or an empty one, an
+ empty `wrap_overlap.frames`, and no `gait_fallback` or `wrap_overlap` record. The refusal names
+ whose records do not give that frame as filmed (the cut's, given by `--read-on-cut`, or this
+ loop's), and why. The regions' centres, a `--region-mask` PNG, and a single `--hold-mask` PNG are
+ moved pixel for pixel onto cell j by the whole pixel shift derived from their crops and cell sizes
+ taken on the frame as filmed, provided every pixel lands within `RECUT_DRIFT` (1.0 px) of that
+ shift. Each cut's crop is its `source_rect` less where its anchor moved that frame before the
+ crop. The anchor moves nothing at `--anchor none`, moves frame k of a cut L frames long across by
+ round(`wrap_dx_px` x k / L) px at `--anchor body`, and lays frame k at the left and top of
+ `padding_ltrb` plus that frame's entry of `shifts_xy` at `--anchor motion` and
+ `--anchor motion-auto`. On an unaligned loop the regions are read on cell j and carried from
+ there, while on an aligned loop they sit on the aligned cell matching cut cell j and are carried
+ as `transported` carries them. A run is refused no-match if the clips differ, if either cut lacks
+ recorded source frames, if this loop does not hold that source frame, if a record does not give
+ where its anchor moved the frame, or if the strip `--read-on-cut` names is a loop aligned from its
+ cut (`cycle_align`), whose cells are not the cut's frames in order, and refused uncertain if a cut
+ records no crop, if crops, scales and anchors set pixels more than 1 px off one whole shift, or if
+ an aligned loop holds no cell for cut cell j. `STRIP` is that cut's strip PNG, whose bytes must
+ have the sha256 `--read-on` names, with its record beside it as `video-loop` writes one using the
+ same file name ending `.json` instead of `.png`, refusing with "--read-on-cut names the strip
+ --read-on names by its sha256; it needs --read-on" when `--read-on` is not given and "wants the
+ strip's PNG and its record beside it" when either file is missing. Masks are moved by the shift
+ alone with no polygon grown and no scaling, while a mask pixel that would leave the cell refuses
+ the run, and a folder of masks (one per cell) is refused under `--read-on-cut` with "regions read
+ on another cut (--read-on-cut) are drawn on its cell 0 alone: give one PNG". `video-sway` takes
+ `--read-on-cut` on `--loop-dir` only, and `video-sway-inspect` does not take it.
- **`no-match`**, refused: neither — another clip, another cut no record pairs with this one
(`--read-on-cut` names the cut that one does), a strip nothing here was cut or aligned from.
Locate the regions again on this strip.