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-pipeline's decontam edges paragraph and the three Sway subsections on a cycle's frames, on the breath and on a flat region with a gain across keep what each accepts, refuses and records — the version notes ("in this release", "before: off", the 2.45.3 bytes), the keying time and memory figures, the synthetic-scene measurements, the safe-side margins, the formulas and the internal function names leave, as the docs cleanup did for the paragraphs around them; the decontam method and figures stay in chroma-alpha.md and the CHANGELOG, the Sway formulas in the code and tests

Soohong Kim801fe199c0d5
diff --git a/docs/video-pipeline.md b/docs/video-pipeline.md
index 7639e78..2cd1eee 100644
--- a/docs/video-pipeline.md
+++ b/docs/video-pipeline.md
@@ -311,9 +311,9 @@ character that *is* green keeps its colour. Tiny accents or dark, edge-only mate
### Edges: `--decontam`
-`--spill` fixes key colour painted into the subject, but strands and outlines at its edge are a different problem: H.264 4:2:0 chroma mixes the key into anything one to three pixels wide, leaving an olive rim on red hair or turning it orange under despill. In this release, `video-frames` and `video-set` default to `--decontam auto` (before: `off`), which re-explains each edge pixel as a blend of the local key background with colours the subject owns and writes that colour at the pixel's observed luma, using the video fit and one palette per clip learned on the first frame. The video fit recovers no coverage on keyed pixels, examining band pixels only; across frames in a clip, near-threshold choices are held, changes of call are blended over frames, and still pixels are settled toward the fit to eliminate edge sparkle. Where `auto` cannot run (a white key or a subject with no interior deeper than 6 px) and under `--alpha-mode brightness`, it leaves frames exactly as keyed and records the reason in the report. On stderr, `video-frames` prints a one-line warning (and `video-set` lists it under `warnings`) when `auto` did not run on any frame, skipped frames, found key-coloured subject material, or triggered the key-coloured part guard.
+`--spill` fixes key colour painted into the subject; strands and outlines at its edge are a different problem: H.264 4:2:0 chroma mixes the key into anything one to three pixels wide, leaving an olive rim on red hair or turning it orange under despill. `video-frames` and `video-set` default to `--decontam auto`, which re-explains each edge pixel as a blend of the local key background with colours the subject owns and writes that colour at the pixel's observed luma. Where `auto` cannot run (a white key, or a subject with no interior deeper than 6 px) and under `--alpha-mode brightness`, it leaves frames exactly as keyed and records the reason in the report. On stderr, `video-frames` prints a one-line warning (and `video-set` lists it under `warnings`) when `auto` did not run on any frame, skipped frames, found key-coloured subject material, or kept edge pixels beside a small key-coloured part as the matte keyed them.
-Two video guards keep the matte's bytes for edge pixels beside small key-coloured parts and for pixels matching the material right behind them. Pass `--decontam off` to keep the matte as it is and return 2.45.3 bytes exactly. Keying time rises from 1.14 s to 3.36 s a frame on an Intel i5-7500 at 1080x1920, and peak memory rises from about 400 MB to 1155 MB, about 365 MB more than `off` per megapixel of frame. Method, guards and measurements: [chroma-alpha.md](chroma-alpha.md#decontam--give-the-edge-the-subjects-own-colour-back).
+Pass `--decontam off` to keep the matte as it is. Method, guards and measurements: [chroma-alpha.md](chroma-alpha.md#decontam--give-the-edge-the-subjects-own-colour-back).
## 3b. Canvas shape for raised limbs and wide costumes
@@ -559,7 +559,7 @@ sprite-gen video-sway --frames set/front-idle/loop/cycle --out swayed --region c
at the centre and 0 at the rim (cos²), sampled as premultiplied bilinear colour; outside it no
pixel changes. A move so large that the weight's slope folds the picture over
(offset × π / (2 · radius) ≥ 1) is refused: lower `--gain` or give the region larger radii.
- A cell in which every region's offset is 0 is copied byte for byte, including colour under clear pixels; this holds for every sway, including `--gain 0`. A move clears that colour because the WebP check refuses it.
+ A cell in which every region's offset is 0 is copied byte for byte, including colour under clear pixels; this holds for every sway, including `--gain 0`. A move clears that colour.
- **`--on-fold lower`** lowers the gain for you instead of refusing, region by region. No region goes under 1, the
mass as measured: one that would have to is **held** — it does not move at all, so a
follow-through is never quietly weaker than the motion it answers — and named, on stderr and in
@@ -597,23 +597,23 @@ held or refused as the cut is.
#### A cycle's frames at their own size: `--frames <folder> --out <new folder>`
-A loop's strip holds at most 64 cells and 32,000 px across. Cells 960 px wide allow 33 of them, so a cycle of large frames must be cut down to fit. The strip stays the delivery format; `video-sway --frames <folder> --out <new folder> [--fps F]` sways the full cycle before that cut.
+A loop's strip holds at most 64 cells and 32,000 px across, so a cycle of large frames is cut down to fit it. The strip stays the delivery format; `video-sway --frames <folder> --out <new folder> [--fps F]` sways the full cycle before that cut.
- **The frames** are PNGs in name order, all one size, from a `video-loop` `cycle/` folder or the output of `sprite-gen breathe`. Regions are given in frame pixels. `--frames` and `--loop-dir` are alternatives, and one is required.
-- **The output** contains the moved frames under their original names and `sway.json` beside them. The folder checks and whole writing are the same as `sprite-gen breathe`: real paths rule out an output equal to, inside, or containing the frames folder; the output must be new or empty; and unequal frame sizes are refused before anything is made. The command writes in a staging folder beside the output and renames it into place when complete. A failed run leaves nothing, and the frames folder is only read.
-- **The move** uses `solve_cells` for both paths. A strip cut from these frames at scale 1, with no cell left out and each region moved by the crop origin `source_rect`, moves cell for cell exactly as the frames path does, byte for byte once cut back, at the frame time written in the strip meta. `--fps F` uses `round(1000 / F, 2)` milliseconds: 24 fps is 41.67 ms. The exact `1000/24` ms gives another sway.
-- **The time** comes from `--fps` or, for a whole `video-loop` `cycle/`, from the loop strip meta's `cycle_seconds` and `cycle_frames`. A conflicting `--fps` is refused. The damped mass requires a frame time, so other frames folders need `--fps` unless `--breathe` supplies the drive. `--read-on` is refused with `--frames`; `--frames` requires `--out`; `--out` and `--fps` are refused with `--loop-dir`.
-- **The record** in `sway.json` has `frames`, `frame_ms` (null on the breath), and the same record as the loop's `follow`, with `source` naming the frames folder. Body motion is read at the frames' full size by `body_motion`. Reducing them changes that reading and its offsets. On large frames, reading can take minutes. The old name `video-follow --frames ...` writes the same bytes.
+- **The output** contains the moved frames under their original names, with `sway.json` beside them. The output must be new or empty, and may not be equal to, inside, or containing the frames folder (compared as real paths); unequal frame sizes are refused before anything is made. A failed run leaves nothing, and the frames folder is only read.
+- **The time** comes from `--fps` or, for a whole `video-loop` `cycle/`, from the loop's strip meta. A conflicting `--fps` is refused. Other frames folders need `--fps` unless `--breathe` supplies the drive. `--read-on` is refused with `--frames`; `--frames` requires `--out`; `--out` and `--fps` are refused with `--loop-dir`.
+- **The record** in `sway.json` has `frames`, `frame_ms` (null on the breath), and the same record as the loop's `follow`, with `source` naming the frames folder. Body motion is read at the frames' full size: frames reduced first give other offsets, and on large frames reading can take minutes. The old name `video-follow --frames ...` writes the same bytes.
#### On the breath: `--breathe <breathe.json>`
-A breathing idle can move its body only a pixel or two while its head stays still. Reading the outline turns that motion into whole-pixel steps; the damped mass answers those steps, so the part barely moves at its default settings or sways to the steps when pushed further. `--breathe <breathe.json>` drives the part from the Breathe layer's breath instead.
+On a breathing idle the body moves only a pixel or two while the head stays still; the outline turns that into whole-pixel steps, and the damped mass answers those steps, so the part barely moves at its default settings or sways to the steps when pushed further. `--breathe <breathe.json>` drives the part from the Breathe layer's breath instead.
-- **The record** is the `breathe.json` written beside breathed frames. It supplies config, phases and `resolved.anatomy`. Its config's `inhale` is the in-breath share; a record without the key, as every record written before the key existed, reads as the default 0.40, as a sidecar that leaves it out does, so it sways exactly as before. Its config's `start_cell` and `loop_cells` say which cells of which loop the frames are: a record without the keys, as every record written before them, reads as the loop itself from its first cell and sways exactly as before. Only `mode: smooth` is accepted; a pixel breath is refused because its travelling wave moves the first cell. The config passes `state_breathe` checks, `fit_breathe_pattern` recomputes the phases at the record's share, start cell and loop cells and compares them with the record, so `breath_peaks` phases written at another share are accepted when they match, and `frames`, the phase count and the swayed cell count must agree. A hand written record is checked the same way and can state the in-breath share of a breath made elsewhere.
-- **The drive** uses the Breathe layer's own functions. Chest lift is `lift x w`, where `w` is `smooth_wave` at the record's in-breath share, from 0 at rest to 1 at the in-breath peak, and `lift = depth x (anatomy height - basis_row)` is given by `breathe.smooth_lift`. The part follows the late curve `w_late = smooth_shoulder_wave` at the same share, whose time is warped by `t - lag x sin(π t)`. Its offset is `gain x lift x (w - w_late)`, against the chest's rise in the record's `chest_dir`; 0 points straight up, so that offset points straight down.
-- **The rest** has `w = w_late = 0`, so the first cell, rests between breaths and the close have zero offset. On a synthetic loop, the step across the close is 3-4% of the largest inner step. The body's outline still determines each cell's carried ellipse.
-- **The lag** is a share of one breath, above 0 and below `1/π`; its default is 0.15. At `1/π` warped time stops, and beyond it runs backwards. On a synthetic 144-cell loop at 24 fps with two breaths, lags 0.1, 0.15 and 0.2 reach 0.28, 0.44 and 0.59 of lift at gain 1. The part peaks 7, 11 and 14 cells late, or 0.29, 0.46 and 0.58 s. Reach depends on lag rather than breath length.
-- **A stretch of a loop** is a breathed row whose record carries `loop_cells` and `start_cell`: a way out of the loop or a way in, breathed on the loop's beat. An offset depends on its phase alone, so the stretch's cell i is offset exactly as the loop's cell (start_cell + i) mod loop_cells is, from the stretch's first cell on. Nothing has to be wound up before the stretch starts. The fold rule (`--on-fold`) and `--stretch-floor` read the loop's whole breath, every phase of the loop, not only the phases the stretch carries, so a stretch moves by the same gain as its loop and the seams between them do not jump. The record's `reach_px`, its `fold` block and the floor's `least_cell` are then the loop's; `least_cell` is a cell of the loop. `--reference FRAME.png` names the frame the regions were read on when it is not the first of the frames, normally the loop set's first cell. Each frame's body motion is read with that frame laid first, and the regions are carried from it, as on the loop's own cells. `body_px` and `body_worn_px` come from it, `body_bob_px` spans it too, and `sway.json` records `reference` with the file's `path` and `sha256`. The frame must be the same size as the frames, or it is refused. Without it the regions are read on the first frame, as before.
+- **The record** is the `breathe.json` written beside breathed frames; it supplies config, phases and `resolved.anatomy`. Its config's `inhale` is the in-breath share; a record without it reads as the default 0.40. Its config's `start_cell` and `loop_cells` say which cells of which loop the frames are; a record without them reads as the loop itself from its first cell. Only `mode: smooth` is accepted; a pixel breath is refused because its travelling wave moves the first cell. The config must pass the Breathe layer's checks, the phases are recomputed at the record's share, start cell and loop cells and must match the record (so `breath_peaks` phases written at another share are accepted when they match), and `frames`, the phase count and the swayed cell count must agree. A hand-written record is checked the same way and can state the in-breath share of a breath made elsewhere.
+- **The drive** uses the Breathe layer's own breath curve at the record's in-breath share. The part follows the chest's rise late, by `--lag` of a breath, and is moved by `gain` times the gap between the chest's lift and that late lift, against the chest's rise in the record's `chest_dir`; 0 points straight up, so that offset points straight down.
+- **The rest**: the first cell, rests between breaths and the close have zero offset. Each cell's ellipse is still carried by the body's outline.
+- **The lag** is a share of one breath, above 0 and below `1/π`; default 0.15. A longer lag reaches further and peaks later; reach depends on lag rather than breath length.
+- **A stretch of a loop** is a breathed row whose record carries `loop_cells` and `start_cell`: a way out of the loop or a way in, breathed on the loop's beat. The stretch's cell i is offset exactly as the loop's cell (start_cell + i) mod loop_cells is, from the stretch's first cell on. The fold rule (`--on-fold`) and `--stretch-floor` read the loop's whole breath, every phase of the loop, not only the phases the stretch carries, so a stretch moves by the same gain as its loop and the seams between them do not jump. The record's `reach_px`, its `fold` block and the floor's `least_cell` are then the loop's; `least_cell` is a cell of the loop.
+- **The reference frame**: `--reference FRAME.png` names the frame the regions were read on when it is not the first of the frames, normally the loop set's first cell; the regions are carried from it, as on the loop's own cells. `body_px` and `body_worn_px` come from it, `body_bob_px` spans it too, and `sway.json` records `reference` with the file's `path` and `sha256`. A frame of another size than the frames is refused. Without it the regions are read on the first frame.
- **The settings and record** use a default `--gain` of 1 on the breath, against 2.5 on body motion. `--freq` and `--zeta` are refused with `--breathe`; `--fps` is refused with `--breathe --frames`; `--lag` requires `--breathe`; `--reference` is refused with `--loop-dir`. The record's `drive` carries `kind: breath`, `breathe_sha256`, `lag`, `lift_px`, `heading_deg`, `inhale`, `start_cell`, `loop_cells`, and `breaths` or `breath_peaks` in place of `freq_hz`, `zeta` and `harmonics`. Its way is `common-lay/breath-late/cos2-bilinear/1`. `--loop-dir` also accepts this drive when its strip has one cell per phase.
```bash
@@ -625,11 +625,11 @@ sprite-gen video-sway --frames way-out-breathed --out way-out-swayed --breathe w
#### A region moved whole, and across apart from down: `cx,cy,rx,ry,flat`, `--gain-across G`
-`--region cx,cy,rx,ry[,flat]` gives a region an optional fifth number, `flat`, from 0 to 0.9. It is the share of the way from centre to rim that moves in full. Over the remaining distance the weight falls from 1 to 0 by cos², using the Breathe layer's `breathe.flat_cos2`. A large region weighted by cos² alone presses its outer part inward; one flat region can move the part whole instead of laying many small circles over it. On a synthetic chest, one flat region gave a least part weight of 0.82 and a mean of 0.99, against 0.84 and 0.97 for 112 circles, at a fifth of the move time.
+`--region cx,cy,rx,ry[,flat]` gives a region an optional fifth number, `flat`, from 0 to 0.9: the share of the way from centre to rim that moves in full; over the rest of the way the weight falls from 1 to 0 by cos². A large region weighted by cos² alone presses its outer part inward; one flat region can move the part whole instead of laying many small circles over it.
-The fold rule reads the radius left after the flat centre: the smaller radius x `(1 - flat)`. It folds at `offset x π / (2 x radius x (1 - flat)) >= 1`. `--stretch-floor` reads the least area as `1 - (π/2)/(1 - flat) x hypot(ox/rx, oy/ry)`. Both closed forms stay on the safe side of measured values by 0.004 to 0.013. The record's `fold.regions[i].radius_px` is that reduced radius. A `flat` of 0, or one left out, gives the four-number region's strip, record and inspection byte for byte. Values outside the range are refused.
+The fold rule and `--stretch-floor` read the radius left after the flat centre, the smaller radius x `(1 - flat)`, and the record's `fold.regions[i].radius_px` is that reduced radius. A `flat` of 0, or one left out, gives the four-number region's strip, record and inspection byte for byte. Values outside the range are refused.
-`--gain-across G` sets the gain across independently; `--gain` then sets the gain down. Without it, across uses `--gain` as before, byte for byte. When `--on-fold lower` or the floor lowers a region's gain, its across move falls in the same proportion. The existing area rule reads moves with different across and down components and stays on the safe side by 0.0004 to 0.008. `--gain 0` with 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.
+`--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.
### Inspecting a sway — `video-sway-inspect`