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): the band — docs/video-pipeline.md section 6 "A region moved as one mass" and the CHANGELOG's Unreleased

Soohong Kimf236b58440bf
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 900ce27..7f70604 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,30 @@
All notable public changes to `sprite-gen` are recorded here. Versions track the `version:` field in `SKILL.md` and `pyproject.toml`.
+## 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.
+
+- **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.
+- 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()`.
+- 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`.
+- **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;
+ - a band narrower than the move needs is refused, or the gain lowered under `--on-fold lower`;
+ - a band narrower across its ring than its px (flat to a tenth of the radius above the centre) is refused by its steepest slope, or lowered to the largest gain whose slope stays under 1, every cell's least area over 0, while the same band without `--band-up` keeps the gain asked;
+ - `--band-up` stops the flat part over the centre and runs its band past the region's top: below the centre the cells are those of the band without it, above it the upper part gives;
+ - what cannot go with `--band` is refused with its reason (a flat share, `--stretch-floor`, `--band-margin` or `--band-up` alone) and leaves the loop as it was; a flat share of 0 is four numbers and takes a band;
+ - out-of-range values are refused by the command line with exit 2 and the flag's message;
+ - the flat part moves by the cell's offset itself, and past the band no byte changes, also just past its rim;
+ - a part that slides on the body is carried by its own pixels, not the lay;
+ - a part that slides 3 px a cell to 12 px from the lay, held there and back, is found around where the cell before had it and moved whole in every cell;
+ - cloth with no pattern, and a part that jumps further than the search from where the cell before had it, are carried by the lay and named in a warning;
+ - cloth dotted every 4 px is a tie and carried by the lay;
+ - the ledger's counts, boxes and warning lines;
+ - `--frames` gives the strip's cells, and a turned loop under `--read-on` is the cut's banded sway cell for cell.
+ `tests/video/test_follow_inspect.py` now names `--band`, `--band-margin` and `--band-up` 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 nothing
**Upgrading from 3.4.0: `video-set` now frames a walk or run filmed from the side on a square widened by the room its still lacks, and a background the chroma engine did not recognise, which used to come out with nothing removed, is now cut out.** A still that leaves less than `GAIT_ROOM` clear in front of its silhouette (0.15 of the silhouette's height) or behind it (0.25) gains the columns it lacks on that side; the square gains the same number of rows above the still. A still that leaves the room keeps its canvas to the byte. Every other state, a front, back or diagonal view, `--shape` and `--fit tight` are framed as before. Each side walk or run's `canvas.report.json`, and its item in `set.report.json`, gains `room`. `video-canvas` gains `--view` and reads the room only with `--view side`. Backgrounds the chroma engine already recognised key byte for byte as before. A pure or recognised magenta/green background still goes to the chroma engine and a bright achromatic one to the white matte, with the same bytes.
diff --git a/docs/video-pipeline.md b/docs/video-pipeline.md
index d87ef0b..e49b8d3 100644
--- a/docs/video-pipeline.md
+++ b/docs/video-pipeline.md
@@ -600,9 +600,11 @@ A clip model draws a walk's body moving, but a soft part hanging off it (a chest
```bash
sprite-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]
+ [--read-on <sha256>] [--stretch-floor D] [--gain-across G] \
+ [--band PX|auto] [--band-margin PX|auto] [--band-up FLAT[,PX|auto]]
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]
+ [--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]]
```
- **The region** is an ellipse over the part in the strip's first cell, in cell pixels
@@ -690,6 +692,24 @@ The fold rule and `--stretch-floor` read the radius left after the flat centre,
`--gain-across G` sets the gain across on its own, and `--gain` then sets the gain down; without it, across uses `--gain`. When `--on-fold lower` or the floor lowers a region's gain, its across move falls in the same proportion. `--gain 0` with a non-zero `--gain-across` is refused. The record carries `gain_across`, the across gain the strip's `gain` moved by, and carries `gain_across_requested` only when given.
+#### A region moved as one mass: `--band PX|auto`, `--band-margin`, `--band-up`
+
+Without `--band`, a region's weight is 1 at the ellipse's centre and falls to 0 at its rim by cos². On a large soft part (a chest), only the middle moves fully; the rest of the part is pressed in or stretched. The fifth region parameter `flat` moves a share of the way from the centre in full, but inside the same ellipse, so the part's own pixels still reach the falling slope when they move, and the fold rule then reads a small radius.
+
+`--band PX|auto` moves each region as one mass. It is off by default; when it is not given, nothing of it is read or written, and the strip, the record, and everything else remain byte for byte what they were. The weight is 1 over the region's ellipse grown by the margin on every side (the flat part), and falls from 1 to 0 by cos² over a band of `PX` px past it, measured along the ray from the region's centre. The outer ellipse's radii are the flat part's radii plus the band. Past the band the weight is 0. The whole part moves by the cell's offset, and only what is around it gives. Outside every region's band no pixel changes, byte for byte, including the colour under clear pixels.
+
+`--band-margin PX|auto` (default `auto`) controls how far past the ellipse the weight stays 1 in every direction. In `auto` mode, the margin is `ceil(reach) + 1`, which is the move's reach plus one pixel: a pixel of the part lands where the weight is still 1 only if the flat part reaches as far as the part moves. The move's reach at the requested gain (`--gain`) is read first, and the band and margin are then read off it in two stages. `--band auto` is `ceil(reach x pi / 2) + 1`, the narrowest band that the move does not fold.
+
+The fold rule reads each region by its narrowest band instead of its radius: a move folds where `reach x pi / (2 x band) >= 1`. When a move folds, `--on-fold lower` lowers the gain as before, and `--on-fold refuse` refuses with the message "folds a region's band of N px over itself; lower --gain or give a wider --band". The record's `fold.regions[i].radius_px` is the band. If a move passes the fold rule and still folds the picture in some cell (`jacobian_min` 0 or under), it is refused as the engine's fault and nothing is written.
+
+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: per unit of gain, the most that the move at gain `1`, dotted with the weight's gradient, reaches. A pixel moved by gain `g` keeps `1 - g x steepest` of its area, so the region folds where `g x steepest >= 1`. `--on-fold refuse` then refuses, naming the cell and the area a pixel keeps at the gain asked, and says to lower `--gain` or give a wider `--band` (or `--band-up`, when given). `--on-fold lower` lowers that region's gain to the largest whole number of `0.01` steps whose steepest slope stays under `1`; a region that would go under gain `1` is held, and the run is refused only when every region is held. The record's `follow.band.regions[i].steepest` holds `per_gain`, `cell` and `ratio` (the gain times `per_gain`, under `1` on any written strip). A move that passes the fold rule and still folds the picture in some cell (`jacobian_min` 0 or under) is refused as the engine's fault and nothing is written, staying as the last check after the steepest slope.
+
+`--band-up FLAT[,PX|auto]` gives the part above the region's centre its own shape. The flat part stops `FLAT` (over 0, at most 1) of the region's vertical radius above the centre, and above that the weight falls over `PX` px. When omitted or set to `auto`, `PX` is the band, or as far as `HANG_PAST` (3 px) above the region's top, whichever is further: the whole ellipse moves at least some, and nothing above it is left pressed. The upper part gives and the rest moves whole (for a chest that hangs from the shoulders, the shoulders stay put). Without `--band-up`, the shape above is the same as below. `--band-margin` and `--band-up` need `--band`; alone they are refused.
+
+With `--band`, each region is carried into each cell by its own pixels rather than by the lay of the body's outline. The solid pixels (alpha 128 or more) under the region's ellipse in the cell it was read on (the first cell; the reference frame with `--reference`; or under `--read-on` transported, the cut's first cell where the loop holds it) are searched in each cell in the loop's order from the cell the region was read on, within `CARRY_SEARCH` (9) whole pixels either way 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), by the least squared difference of premultiplied colour over those pixels, counting past the cell edge as clear. A parabola through the least difference and its neighbours across and down gives the subpixel position. Where that is uncertain (the least is on the 9 px search edge, tied with a place more than 1 px away, or the difference does not curve up across or down, such as unpatterned cloth), the region is carried by the body's lay in that cell. Each such cell is named in a warning line on stderr ending with the record key `follow.band.lay` on `--loop-dir` and `sway.json band.lay` on `--frames`, and the record's `carry_basis` reports `{"reading": "outline-lay", "region": "own-pixels"}`.
+
+Combining `--band` with a region's fifth number `flat` (other than 0, which counts as four numbers and is accepted) or with `--stretch-floor` is refused with a reason and a non-zero exit; nothing is written. Out-of-range values (a band of 0 or less, a negative margin, a `FLAT` of 0 or over 1, or text that is not a number or `auto`) are refused by the command line with exit 2. Only four ledger 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), ending with the record key: `follow.band.ledger.<key>` on `--loop-dir`, `sway.json band.ledger.<key>` on `--frames`. `jacobian_min` gives no warning. The option works on `--loop-dir` and on `--frames ... --out ...` alike, 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 `--band`.
+
### 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: