Generate clean 2D game sprites & animation atlases — component-row pipeline: state rows, alpha cleanup, frame extraction, runtime atlases. Codex/Claude skill.
docs(video-sway): the region mask — docs/video-pipeline.md section 6 "A region given as a mask" and the CHANGELOG's Unreleased
Soohong Kimf8c7911ca24c
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex a110b2e..f86d1f0 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -4,13 +4,16 @@ All notable public changes to `sprite-gen` are recorded here. Versions track the## Unreleased-**Upgrading from 3.5.0: `video-sway` can move each region as one mass with `--band`.** When `--band` is left out, strips, frames, and records remain byte for byte what they were. Passing `--band PX|auto` moves each region's ellipse and an outer margin at full weight, with the weight falling to 0 by cos² over a band of pixels around it, while carrying the region by its own pixels rather than the body's outline lay. The fifth region number `flat` and `--stretch-floor` are refused when `--band` is specified. In the strip's metadata, `follow` gains `band` (and `sway.json` gains `band` for `--frames`), while stdout JSON gains `band` with `band_px`, `margin_px`, and `lay_cells`. The legacy command name `video-follow` accepts the same flags. `video-sway --band` can now hold pixels with `--hold-mask`, leaving them as they are while regions move round them. It is off by default, and when not given, strips, frames, and records remain byte for byte as before.+**Upgrading from 3.5.0: `video-sway` can move each region as one mass with `--band`.** When `--band` is left out, strips, frames, and records remain byte for byte what they were. Passing `--band PX|auto` moves each region's ellipse and an outer margin at full weight, with the weight falling to 0 by cos² over a band of pixels around it, while carrying the region by its own pixels rather than the body's outline lay. The fifth region number `flat` and `--stretch-floor` are refused when `--band` is specified. In the strip's metadata, `follow` gains `band` (and `sway.json` gains `band` for `--frames`), while stdout JSON gains `band` with `band_px`, `margin_px`, and `lay_cells`. The legacy command name `video-follow` accepts the same flags. `video-sway --band` can now hold pixels with `--hold-mask`, leaving them as they are while regions move round them. It is off by default, and when not given, strips, frames, and records remain byte for byte as before. `video-sway` can now move a region's own pixels with `--region-mask`, holding every visible pixel outside it and its soft edge while the weight falls over an inner rim read off the move. It is off by default, and when not given, strips, frames, and records remain byte for byte what they were (with `--band`, with `--band` and `--hold-mask`, and with neither).- **New: banded sway moving regions as one mass (`--band`, `--band-margin`, `--band-up`).** `--band PX|auto` keeps the weight at 1 over each region's ellipse expanded by the margin in every direction (the flat part), falling from 1 to 0 by cos² over a band of `PX` px past it, leaving pixels outside the band unchanged byte for byte. `--band-margin PX|auto` (default `auto`, `ceil(reach) + 1`) sets how far past the ellipse the weight stays 1. `--band auto` sets the band to `ceil(reach x pi / 2) + 1`, the narrowest band that does not fold. Reach is evaluated first at the requested `--gain`, after which band and margin are determined in two stages. The fold rule reads the narrowest band instead of radius, refusing moves where `reach x pi / (2 x band) >= 1` or lowering gain under `--on-fold lower`. `--band-up FLAT[,PX|auto]` shapes the area above the centre separately, stopping the flat part `FLAT` of the vertical radius above the centre and falling over `PX` px (defaulting to the band or `HANG_PAST` of 3 px above the top, whichever is further) so upper regions yield while the rest moves whole. Where the flat ellipse and the outer one differ in shape (above the centre under `--band-up`, where the flat part is short and the band long), the band measured across its ring is narrower than its px, so the weight falls steeper than the fold rule reads. After the fold rule, each region's steepest slope along the move is read over every pixel of every cell (`band_steepest`: per unit of gain, the most of the move at gain 1 dotted with the weight's gradient, the gradient read between each pixel's neighbours, and the cell where it is). A pixel moved by gain `g` keeps `1 - g x steepest` of its area, so a region folds where `g x steepest >= 1`. Then `--on-fold refuse` refuses, saying that `--band`'s weight falls steeper than its px where the band is narrower across its ring, in which cell and what area a pixel keeps at the gain asked, and to lower `--gain` or give a wider `--band` (or `--band-up`, when it was given); `--on-fold lower` lowers that region's gain to the largest whole number of `0.01` steps, no more than the gain it had, whose steepest slope stays under 1 (`steepest_gain`); a region that would have to go under gain 1 is held, and the run is refused only when every region is held, as the fold rule does. Each region is carried across cells in the loop's order from the cell the region was read on by its own solid pixels under the ellipse within `CARRY_SEARCH` (9) px of where the cell before had the region's pixels (around the cell's own body lay only where the cell before was carried by the lay, or is the cell the region was read on; or, with `--reference`, for the first cell) using least squared difference of premultiplied colour and subpixel parabolic fitting; uncertain matches revert to the outline lay and warn on stderr. See [video-pipeline](docs/video-pipeline.md) section 6.- **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. 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.- 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).- Record fields: `follow.band` in strip metadata and `band` in `sway.json` record `policy` (`own-pixels/margin-band-cos2/1`), `asked` (`{band, margin, up}`), `reach_px`, `band_px`, and `margin_px`. They record per-region `flat_px` and `band_px` (across, above, below); per region in `follow.band.regions[i]`, `steepest`: `per_gain` (the slope per unit of gain), `cell`, and `ratio` (the region's gain times `per_gain`, under 1 on any written strip); `carry` with `search_px` (9) and per-cell, per-region `px`, `from` (`base`, `pixels`, or `lay`), `why` for lay, `least`, and `curvature`; `lay` entries for cells carried by lay; and `ledger` lists per cell (with `<key>_max` values) for `band_on_regions_px`, `pressed_px`, `stretched_px`, `pressed_box`, `stretched_box`, `area_least`, `area_most`, `outside_moved_px`, and `jacobian_min`. Only the four counts warn: `band_on_regions_px`, `pressed_px`, `stretched_px`, and `outside_moved_px`. For each that is not 0 in some cell, one warning line on stderr says in how many cells, up to how many px and in which cell (for `pressed_px` and `stretched_px` also the least or the most area and where), and ends with the record key: `follow.band.ledger.<key>` on `--loop-dir`, `sway.json band.ledger.<key>` on `--frames`. The lay warning names its record key the same way: `follow.band.lay` on `--loop-dir`, `sway.json band.lay` on `--frames`. `jacobian_min` (the least area of the source any pixel of a moved cell takes, per cell) gives no warning: it is recorded, and 0 or under in any cell refuses the run as the last check, named the engine's fault, nothing written. Command stdout JSON gains `band` containing `band_px`, `margin_px`, and `lay_cells`.- Record fields: `follow.hold` in strip metadata and `hold` in `sway.json` record `policy` (`own-pixels-grown/kept-edge-air/read-short-sloped/1`), `asked` (`per_cell`, and `sha256`: the file's, or a list per file for a folder), `grow_px` (3; null for a folder), `edge_px`, `margin_px` (1), `slope` (0.5), `round_px` (1), and `steps` (16). They record `pieces` with each piece's `px` and `box` (`x0`, `y0`, `x1`, `y1`) on the cell it was drawn on (empty for a folder); `carry` with `search_px` (9) and per-cell, per-piece `px`, `from` (`base`, `pixels`, or `lay`), `why` for lay, `least`, and `curvature` (null for a folder); `lay` entries (`{cell, piece, why}`) for pieces carried by lay; and `ledger` lists per cell (with `<key>_max` values) for `held_px`, `soft_px`, `air_px`, `short_px`, `renormalised_px`, `walked_px`, `read_folded_px`, `read_folded_edge_px`, `read_least`, `read_turn_folded_px`, and `read_turn_least`. Warning lines on stderr report a piece carried by the lay (in how many cells and why), ending with the record key: `follow.hold.lay` on `--loop-dir`, `sway.json hold.lay` on `--frames`. For `renormalised_px`, `walked_px`, and `read_folded_px`, when not 0 in some cell, one warning line on stderr says in how many cells, up to how many px and in which cell, ending with the record key: `follow.hold.ledger.<key>` on `--loop-dir`, `sway.json hold.ledger.<key>` on `--frames`. Command stdout JSON gains `hold` containing `pieces`, `lay_cells`, and `read_folded_px_max`.+- Record fields: `follow.region_mask` in strip metadata and `region_mask` in `sway.json` record `policy` (`own-pixels-mask/held-outside/rim-sin2/1`), `asked` (`per_cell`, `sha256`: the file's, or a list per file for a folder, `rim`: the scale, `shrink_px`, `crease`: true/false, and `up`: `{flat, band}` or null), `soft_px` (2), and `air_px` (`ceil(reach) + 2`). They record `rim` (`across_px` for Lx, `down_px` for Ly, `least_px`: the two bands it started at, `slope`: the steepest `(pi/2) x sqrt(...)` over the cells, and `slope_bound`: 0.9); `mask` (`px`: its pixel count as worn in, `box`, and `carried_by_px`: the solid pixels it was carried by; null for a folder); `crease` (per mask, `rows`: each column's row, keyed by column, and `free_columns`; null when not asked); `carry` (`search_px` of 9 and `cells`: per cell `px`, `from`: `base`, `pixels` or `before`, `guess`: `before` or `lay` where carried by its pixels, `why` where it kept the cell before's carry, `least`, and `curvature`; null for a folder); `kept` entries (`{cell, why}`) for cells keeping the carry of the cell before; `up` containing the upper yield's shape as a band's record (`reach_px`, `band_px`, `margin_px`, per region `flat_px`, `band_px` and `steepest`, its `carry` and `lay`; null without `--band-up`); and `ledger` lists per cell (with `<key>_max` values) for `region_px`, `soft_px`, `air_px`, `held_px`, `held_changed_px` (0), `move_most` ([px, x, y] of the region pixel that moves most; null where none moves) with `move_most_max`, `pressed_px`, `pressed_box`, `area_least`, `stretched_px`, `stretched_box`, `area_most`, `folded_px`, `jacobian_min`, `read_held_weight` ([weight, x, y]; null where none), `read_held_half_px`, `renormalised_px`, and `walked_px`. Warning lines on stderr report cells that kept the carry of the cell before (ending `follow.region_mask.kept`), a region whose `--band-up` yield was carried by the lay (ending `follow.region_mask.up.lay`), and for `held_changed_px`, `pressed_px`, `stretched_px`, `read_held_half_px`, `renormalised_px` and `walked_px` when not 0 in some cell, one line reports in how many cells and up to how many px (with area and location for pressed and stretched), ending with `follow.region_mask.ledger.<key>` on `--loop-dir` or `sway.json region_mask.ledger.<key>` on `--frames`. Command stdout JSON gains `region_mask` containing `kept_cells`, `rim_px` ([Lx, Ly]), `move_most_px`, and `walked_px_max`.- **Tests**: new file `tests/video/test_sway_band.py` covers these cases on synthetic figures. Each case first reads what a sway writes with or without the band (its cells, its fold, whether it refuses, what it says on stderr) and the band's own record after, so a release without the band fails on what comes out:- without `--band`, the strip and the record are as before (no `band`, no `carry_basis`);- `auto` reads the margin and the band off the move's reach at the gain asked, and the fold rule reads the band;@@ -38,6 +41,25 @@ All notable public changes to `sprite-gen` are recorded here. Versions track the- each refusal leaves the loop as it was;- a piece on cloth with no pattern is carried by the lay, held all the same, and the record, the warning line, the stdout JSON and the ledger keys say so.`tests/video/test_follow_inspect.py` now names `--hold-mask` among the arguments `video-sway` takes and `video-sway-inspect` does not.+- **Tests**: new file `tests/video/test_sway_region.py` covers these cases on synthetic figures (a body whose striped part, round above and cut straight below, lies over its torso's right side and past it over the air, soft against the air, with a dark crease under it on the torso; the band tests' part on cloth with no pattern; the read-on tests' runner, cut and turned). Each case first reads what a sway writes with the mask (its cells, whether it refuses, what it says), so on a release without the mask the same input fails on what comes out; the record and the ledger are read after:+ - without `--region-mask` the sway is as before, plain and with `--band` (no `region_mask` in the record), from the command line and from Python;+ - every visible pixel outside the part keeps its bytes at gain 2.5, at 1.25 and at 6.0, while without the mask the outside changes;+ - inside its rim the part moves whole, and it moves into the air beside it and no further;+ - the part's soft edge moves with it, and a soft pixel beside the torso is held;+ - the mask is carried round where the cell before had it first (a part sliding on the body, and one ramping away from the lay), and the record says so;+ - a part whose body jumps further than the search is found round the lay;+ - where neither guess settles (cloth with no pattern), the carry of the cell before is kept, never the lay, and the record, the warning line and the stdout JSON say which cells and why;+ - the rim is read off the move and the weight is sin² of the distance to the held pixels, at gain 2.5 and 6.0: the fold rule reads no radius, nothing folds, no read is walked back and no read puts half its weight on a held pixel;+ - a wider rim (`--region-rim 1.5`) moves less of the part whole;+ - `--band-up` yields above the centre: the weight is the lesser of the rim's and the yield's, and below the centre it is the rim's;+ - a mask drawn 2 px large holds the belly once it is worn in by the default 2 px;+ - `--region-crease` ends the mask on the darkest row under it before it is worn in;+ - a folder of the carried masks moves the part as the one mask does;+ - `--frames` gives the strip's cells and the same record;+ - a loop turned from a cut and moved under `--read-on` on the cut's reading is the cut's, cell for cell;+ - each refusal leaves the loop as it was;+ - the ledger counts each cell, and the warning lines and the stdout JSON say what is in it.+ `tests/video/test_follow_inspect.py` now names `--region-mask`, `--region-rim`, `--region-shrink` and `--region-crease` among the arguments `video-sway` takes and `video-sway-inspect` does not.## v3.5.0 - Widened square canvas framing for side walk and run stride and trailing parts, measured background matte cutout for flat backgrounds of any colour, and failure when a cutout removes nothingdiff --git a/docs/video-pipeline.md b/docs/video-pipeline.mdindex dc59eaf..f96c3d3 100644--- a/docs/video-pipeline.md+++ b/docs/video-pipeline.md@@ -601,10 +601,12 @@ A clip model draws a walk's body moving, but a soft part hanging off it (a chestsprite-gen video-sway --loop-dir set/front-walk/loop --region 136,164,60,50 [--region ...] \[--gain 2.5] [--on-fold refuse|lower] [--freq 2.4] [--zeta 0.6] [--board follow.png] \[--read-on <sha256>] [--stretch-floor D] [--gain-across G] \- [--band PX|auto] [--band-margin PX|auto] [--band-up FLAT[,PX|auto]] [--hold-mask MASK.png|DIR]+ [--band PX|auto] [--band-margin PX|auto] [--band-up FLAT[,PX|auto]] [--hold-mask MASK.png|DIR] \+ [--region-mask MASK.png|DIR [--region-rim SCALE] [--region-shrink PX] [--region-crease]]sprite-gen video-sway --frames set/front-idle/loop/cycle --out swayed --region cx,cy,rx,ry[,flat] [--fps F] \[--breathe breathed/breathe.json [--lag 0.15]] [--reference FRAME.png] [--gain G] [--gain-across G] [--on-fold ...] [--stretch-floor D] \- [--band PX|auto] [--band-margin PX|auto] [--band-up FLAT[,PX|auto]] [--hold-mask MASK.png|DIR]+ [--band PX|auto] [--band-margin PX|auto] [--band-up FLAT[,PX|auto]] [--hold-mask MASK.png|DIR] \+ [--region-mask MASK.png|DIR [--region-rim SCALE] [--region-shrink PX] [--region-crease]]```- **The region** is an ellipse over the part in the strip's first cell, in cell pixels@@ -724,6 +726,28 @@ In strip metadata under `follow.hold` (and `hold` in `sway.json` on `--frames`),A run is refused with a non-zero exit, writing nothing and leaving the loop as it was, when `--hold-mask` is used without `--band`; when a mask is of another size than the cells ("--hold-mask is WxH, the cells are WxH: a mask is drawn on a cell, pixel for pixel"); when a mask holds no pixel ("holds no pixel (alpha 128 or more, or that light where it has no alpha)"); when a file is not read ("...: not read (...)"); when a folder count of PNGs does not match the count of cells ("--hold-mask holds N masks and there are M cells: a folder gives one mask per cell, in name order"); or when a folder has no PNG in it ("a folder of masks with no PNG in it"). The option works on `--loop-dir` and on `--frames ... --out ...` alike, and under `--read-on`. The alias `video-follow` takes the same flag. `video-sway-inspect` does not take `--hold-mask`.+#### A region given as a mask: `--region-mask`++With `--region` alone a region is an ellipse whose weight falls from its centre, and with `--band` an ellipse grown by a margin moves whole over a band of pixels outside it, so either way pixels near the part move with it: the belly or waist under a chest, an arm beside it. `--region-mask MASK.png|DIR` gives the region as a mask of the part's own pixels instead of the ellipse's weight: the part moves, and every visible pixel outside it and its soft edge keeps its bytes in every cell, at any gain. The ellipses (`--region`) are still required: they still say each region's gain (the fold rule's and `--on-fold`'s) and where `--band-up`'s shape sits. It is off by default; when it is not given nothing of it is read or written, and strips, frames and records are byte for byte what they were (with `--band`, with `--band` and `--hold-mask`, and with neither).++The mask is a PNG drawn on the cell the regions were read on (the first cell; the reference frame with `--reference`; or under `--read-on`, the cut's first cell where the loop holds it), pixel for pixel the cell's size. A pixel is in the mask where the PNG's alpha is 128 (`ALPHA_SOLID`) or more; where the PNG has no alpha, where its grey value is 128 or more (read exactly as `--hold-mask` reads its PNG). Alternatively, it takes a folder of PNGs, one per cell, in file-name order, where each is the region in its own cell as given (no carry). When `--region-crease` is passed (off by default), before it is worn in, the mask's lower edge is moved to the crease under it (`crease_of`): in each column of the mask's solid pixels whose lowest pixel has a solid pixel under it (the part lies on more of the figure there), the darkest solid pixel by luma (0.299 R + 0.587 G + 0.114 B) from `CREASE_UP` (5) rows above that lowest pixel to `CREASE_DOWN` (3) rows below it is found; the rows are then taken as the median over `CREASE_SPAN` (2) columns either way (5 columns), rounded down; the mask is cut under that row and filled down to it with the column's solid pixels, while a column whose lowest pixel has a clear pixel under it (the part's free edge, over the air) is left as it is. Under `--region-shrink PX` (default `SHRINK_DEFAULT`, 2; 0 keeps the mask as given; a whole number, 0 or more), the mask is worn in by PX 4-neighbour steps (a pixel stays where it and its 4 neighbours are all in the mask; past the cell's edge none is), so that a mask drawn a little large holds what lies just outside the part. Crease runs first, then shrink. One mask is carried into every cell by its own pixels (`carry_region`): the solid pixels (alpha 128 or more) of the mask as trimmed (before it is worn in) on the cell it was drawn on, matched by the band's search (`carry_match`: least squared difference of premultiplied colour within `CARRY_SEARCH`, 9 px, with a parabola for the subpixel position), in the loop's order from the cell it was drawn on. In each cell two guesses are searched round: first where the cell before had the region (from the cell it was drawn on, for the first one), second round the cell's own body lay (the outline's motion); of the guesses that settle (a sure match) the one with the lesser difference is taken (the cell before's on a tie), and the record says which ("before" or "lay"). Where neither settles (cloth with no pattern, the least on the search's edge), the cell keeps the carry of the cell before, never the lay alone, and the record and a warning line say which cell and why (for each guess, why it did not settle), because a part moves little from one cell to the next, and the lay can lie far off it where the outline changes. The worn-in mask is moved by that carry (read bilinear, the pixels it covers half or more of), and in each cell the region is those pixels that are solid in that cell.++In each cell, the pixels are partitioned into sets (`region_sets`). The region is the mask's pixels in that cell, as above. Its soft edge is every pixel not opaque (alpha over 0 and under 128) within `REGION_SOFT` (2) 4-neighbour steps of the region, not in it, and not beside (1 step) another solid pixel outside the region; it moves with the region. Held pixels are every other visible pixel (alpha over 0), and each keeps its bytes in every cell. The air is every clear pixel (alpha 0) within `ceil(reach) + REGION_AIR` (2 px) 8-neighbour steps of the region, where reach is the move's reach at the gain the regions move by; the region moves into it, while clear pixels further away stay clear.++Over the region, its soft edge and the air the weight is `sin²(pi/2 x d)`, where `d` is the distance to the nearest held pixel in rim units: an ellipse `Lx` px across and `Ly` px down, `d = min over held pixels q of sqrt(((x - qx)/Lx)² + ((y - qy)/Ly)²)`, and 1 where no held pixel is nearer (computed exactly, the least along each row then down each column, via `rim_distance`). Elsewhere the weight is 0. So the weight is 0 at the held pixels and rises to 1 (the whole move) inside the region, at least `Lx` across and `Ly` down from every held pixel. `Lx` and `Ly` are read off the move: each starts at the fold rule's least band for the largest move that way over the cells, `ceil(most x pi / 2) + 1`, times `--region-rim SCALE` (default `RIM_DEFAULT`, 1.0; 1 or more), rounded up; then both are widened together, a px at a time, until `(pi/2) x sqrt((dx/Lx)² + (dy/Ly)²)` is at most `RIM_SLOPE` (0.9) in every cell, where dx and dy are the cell's move across and down at the gain the regions move by (`rim_bands`). The move does not fold because `sin²(pi/2 x d)` rises at most `pi/2` per unit of `d`, and `d` rises at most `1/Lx` per px across and `1/Ly` per px down, so along the move a pixel keeps at least `1 - RIM_SLOPE` (0.1) of its area, and a move goes less far than the held pixels lie, so no read lands on a held pixel with half its weight. A wider `--region-rim` (1.5, say) makes a gentler rim: less of the part moves whole. Without `--band-up`, the fold rule reads no radius under `--region-mask` (the rim is read off the move instead), and no gain is lowered by it: in the record each region's fold entry has `radius_px` null, `ratio` 0 and `gain_limit` null. `--gain` sets how far the part moves, as before, and the ledger records the most any region pixel moves per cell.++With `--band-up FLAT[,PX|auto]`, the weight is the lesser of the rim's and the upper yield's, where the yield is the weight a band would give with `--band auto --band-margin auto --band-up FLAT[,PX|auto]` at the gain asked (each region's ellipse carried by its own pixels as a band carries it); so above the centre the part yields while below it the rim rules. The yield is checked as a band is: the fold rule reads its narrowest band, and then its steepest slope (under `--on-fold refuse` refused, saying to give `--band-up` a wider band, under `--on-fold lower` the gain lowered); the rim is then read off the move at the gain the regions move by. The yield's carry by the lay warns as under `--band`.++Every pixel of the region, its soft edge and the air is read at its whole move using premultiplied bilinear sampling (the band's sampling, `draw_held` with no short read). A read whose four pixels take a held pixel is read from the other three where they carry half its weight or more ("renormalised"), else walked back by 1/`HOLD_STEPS` (1/16) of its move at a time until they do ("walked"); the rim keeps reads from putting half their weight on held pixels, so the walked count is 0.++In strip metadata under `follow.region_mask` (and `region_mask` in `sway.json` on `--frames`), the record stores `policy` (`own-pixels-mask/held-outside/rim-sin2/1`), `asked` (`per_cell`, `sha256`: the file's, or a list per file for a folder, `rim`: the scale, `shrink_px`, `crease`: true/false, and `up`: `{flat, band}` or null), `soft_px` (2), and `air_px` (`ceil(reach) + 2`). It records `rim` (`across_px` for Lx, `down_px` for Ly, `least_px`: the two bands it started at, `slope`: the steepest `(pi/2) x sqrt(...)` over the cells, and `slope_bound`: 0.9); `mask` (`px`: its pixel count as worn in, `box`, and `carried_by_px`: the solid pixels it was carried by; null for a folder); `crease` (per mask, `rows`: each column's row, keyed by column, and `free_columns`; null when not asked); `carry` (`search_px` of 9 and `cells`: per cell `px`, `from`: `base`, `pixels` or `before`, `guess`: `before` or `lay` where carried by its pixels, `why` where it kept the cell before's carry, `least`, and `curvature`; null for a folder); `kept` (`{cell, why}` for each cell that kept the carry of the cell before); and `up` (the upper yield's shape as a band's record: `reach_px`, `band_px`, `margin_px`, per region `flat_px`, `band_px` and `steepest`, its `carry` and `lay`; null without `--band-up`). The strip's `carry_basis` is the band's (`CARRY_BASIS_BAND`).++The record's `ledger` lists per cell, with `<key>_max` beside each count: `region_px`, `soft_px`, `air_px`, `held_px`, `held_changed_px` (held pixels the drawn cell does not keep byte for byte; 0), `move_most` ([px, x, y] of the region pixel that moves most; null where none moves) with `move_most_max`, `pressed_px`, `pressed_box`, `area_least`, `stretched_px`, `stretched_box`, `area_most` (as the band's ledger counts them: solid moved pixels left under `PRESSED` 0.85 or over `STRETCHED` 1.15 of their area), `folded_px` (moved pixels whose move takes 0 or less of the source's area), `jacobian_min` (the least area any moved pixel takes; the move and the read are one field), `read_held_weight` ([weight, x, y]: the most weight a read's four pixels put on held pixels; null where none), `read_held_half_px` (reads that put half or more on them), `renormalised_px`, and `walked_px`. Warning lines on stderr, one each, report the cells that kept the carry of the cell before ("--region-mask keeps the carry of the cell before in N cells, its own pixels found surely neither round where that cell had them nor round the lay (cell k: why; ...)", ending `follow.region_mask.kept`); a region whose `--band-up` yield was carried by the lay (ending `follow.region_mask.up.lay`); and for `held_changed_px`, `pressed_px`, `stretched_px`, `read_held_half_px`, `renormalised_px` and `walked_px` when not 0 in some cell: "--region-mask: <what> in X of N cells, up to M px (cell k)" (for pressed and stretched also the least or the most area and where), ending `follow.region_mask.ledger.<key>` on `--loop-dir` and `sway.json region_mask.ledger.<key>` on `--frames`. Command stdout JSON gains `region_mask` with `kept_cells`, `rim_px` ([Lx, Ly]), `move_most_px` and `walked_px_max`.++As the last check, a run is refused, named the engine's fault, with nothing written if `jacobian_min` is 0 or under in any cell: "--region-mask's rim (Lx px across, Ly down) keeps a move of R px taking at most 0.9 of a pixel's area, and cell k's move folds the picture all the same (...); this is the engine's fault - nothing was written". A run is also refused with a non-zero exit, writing nothing and leaving the loop as it was: with `--band` ("--region-mask moves the region's own pixels and holds every visible pixel round it, the weight falling over a rim inside it; --band moves an ellipse over a band outside it: give one of them"); with `--band-margin` ("--band-margin shapes a band; with --region-mask the rim is read off the move (--region-rim)"); with a region's fifth number `flat` ("--region-mask gives the region as a mask, and a region's fifth number (flat, ...) shapes the ellipse's weight: give the region as cx,cy,rx,ry with --region-mask"); with `--stretch-floor` ("--stretch-floor reads the weight that falls from a region's centre; with --region-mask the rim is widened with the move"); with `--hold-mask` ("--region-mask holds every visible pixel outside the region already; --hold-mask is a band's"); when `--region-rim` is under 1 or not finite, such as `nan` ("--region-rim is how many times the fold rule's least band the rim starts at, 1 or more; got X"); when `--region-shrink` is negative, and, for Python callers, also for a `region_shrink` that is not a whole number ("--region-shrink is the px the mask is worn in by, a whole number, 0 or more; got X"); when `--region-rim`, `--region-shrink` or `--region-crease` is given without `--region-mask` ("--region-rim, --region-shrink and --region-crease shape a region mask; they need --region-mask"); when a mask is of another size than the cells ("--region-mask is WxH, the cells are WxH: a mask is drawn on a cell, pixel for pixel"); when a folder holds a count of PNGs that is not the cell count ("--region-mask holds N masks and there are M cells: a folder gives one mask per cell, in name order"); when a mask covers no solid pixel of the cell it was drawn on ("--region-mask holds no solid pixel of the cell it was drawn on: nothing of the region to carry"); when a shrink leaves nothing ("--region-shrink N wears the region mask away: no pixel of it is left to move"); and as `--hold-mask`'s PNG reading refuses: when a file is not read, when a mask holds no pixel, or when a folder has no PNG.++The option works on `--loop-dir` and on `--frames ... --out ...` alike (the frames get the strip's cells and the same record), with `--reference`, and under `--read-on`, where a turned loop carried from its cut is moved cell for cell as the cut is. The alias `video-follow` takes the same flags. `video-sway-inspect` does not take them.+### Inspecting a sway — `video-sway-inspect`The ellipse is given in the first cell, where somebody looked. Into every other cell it is carried by the body's motion, and there nobody looked: an arm that swings across a chest is inside the chest's ellipse in those cells and moves with it, and so does a sleeve of the chest's own colour, which no count of colours finds. The Sway layer does not read what a pixel belongs to. `video-sway-inspect` (old name `video-follow-inspect`) writes what somebody needs in order to look, and moves nothing: