Generate clean 2D game sprites & animation atlases — component-row pipeline: state rows, alpha cleanup, frame extraction, runtime atlases. Codex/Claude skill.
docs(prop-plate): the plate found in each frame and erased there with the line its edge blends into the key, the frames report's rows and the two warnings, the palette learned without it, and CHANGELOG Unreleased (v4.1.0)
Soohong Kimc889b8544697
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 4294c37..e5c7a2f 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -2,6 +2,18 @@All notable public changes to `sprite-gen` are recorded here. Versions track the `version:` field in `SKILL.md` and `pyproject.toml`.+## Unreleased (v4.1.0) - Prop plate tracked and erased per frame across camera pans, with palette exclusion and contact warnings (video-frames --prop-plate)++**Upgrading from 4.0.0: runs without `--prop-plate` take the same code path as 4.0.0 (every new argument is `None`) and give the same keyed frames, frames report, stdout, and stderr byte for byte as 4.0.0, with `--decontam palette` and `--spill auto` as well as by default. Runs with `--prop-plate`: keyed frames and every cut from them change (the plate is erased in each frame where it is found, and the 3.12.0 median rule no longer erases anything), the frames report's `prop_plate` records per-frame tracking instead of a fixed box, and the edge pass learns the subject palette without the plate. The canvas side (`video-canvas --prop-plate`) is unchanged. No new dependency, no model call.**++- **Fix: `video-frames --prop-plate` tracks and erases the plate per frame on decoded frames instead of inside one fixed box.** In 4.0.0 and since 3.12.0, erasure was confined to the canvas report's `prop_plate.box` scaled to the frame plus a 3 px rim (`erase_box`). When camera pan or push-off turned the plate, it left that box after initial frames, leaving the plate in keyed frames and `video-loop` cuts (strip, GIF, WebP). The 3.12.0 whole-clip channel median rule (within 40) is removed because it assumed a stationary plate. Now, `start_box` maps the canvas box to frame coordinates rounded outward without a rim. Each frame searches within a window extending the plate's diagonal (on `start_box`) past the reference box on every side: `start_box` on frame 1, and the last found box on later frames (retained if not found). Plate pieces are connected components (joined side by side or at corners) within 48 of (255, 0, 255) on every channel (`PLATE_TOLERANCE`), each holding at least 1% of the frame's plate area (`PIECE_SHARE`); the plate spans all matching pixels within the pieces' bounding box, finding plates cut in two by the subject whole. Erasure applies within 4 px (`RIM`, was 3) each way and diagonally on decoded frames: a pixel goes if (a) red and blue lead green by more than 35 and are within 90 of each other (plate, edge, codec-tinted subject edge); (b) it sits on the plate-to-key blend line within 2 px (`BLEND_REACH`) of the key colour (each channel within 48 of key), Rec. 601 luma within 40 (`LUMA_SLACK`) of the plate-to-key luma span, and red and blue within 40 (`BLEND_BALANCE`) plus 0.35 (`BLEND_SLOPE`) of their mean's distance from green; or (c) it forms an opaque piece wholly within the rim, removing blue-grey codec ringing that colour rules cannot tell from denim. Foreground subjects keep their pixels: skin, cloth, and hair lie off the plate-to-key axis, dark outlines fall below the luma span, white exceeds it, and parts crossing the rim are not wholly inside it. Limits: subject grey touching the plate between plate and key goes with the blend line; subject fragments cut off wholly within the rim go with the plate; and frames where no plate is found (subject covers it or it moved further than its diagonal) keep visible plate pixels. Refused runs keep the plate in their refused folder; `video-loop` cuts of erased frames carry no plate; `video-set` does not paint or erase a plate.+- **Fix: the edge pass (`--decontam`) learns the subject palette without the plate.** In 4.0.0, the plate stood as opaque as the subject on the first frame, causing the edge pass (default `auto` in `video-frames`) to learn the plate's magenta as a subject colour. With `--prop-plate`, the first-frame plate region (its pixels and the 4 px rim) is excluded from the 32-colour subject palette sample and from the interior check deciding whether the palette is key-free. Without `--prop-plate`, the pass learns as before.+- **New: `--prop-plate` prints warning lines for undetected plates and subject contact.** A run prints `video-frames: warning: --prop-plate: no plate found in N frame(s) (...)` naming frames where no plate was found (nothing erased), and `video-frames: warning: --prop-plate: the plate meets the subject in N frame(s) (...)` naming frames where opaque pixels remain within the rim ("look at those frames"). Each lists the first six frames and counts the rest.+- The frames report records `prop_plate`: `canvas_report`, `start_box`, `rim` (4), `frames`, `frames_changed`, `erased_px`, `not_found`, `touching`, and `rows`. Replaces `erase_box` with `start_box` and per-frame entries in `rows`: `frame`, `found`, and where found `box` (frame px, right and bottom one past), `plate_px`, `tilt` (degrees the plate's long axis is turned from upright, clockwise on the frame positive), `erased_px`, and `touch_px`.+- Python callers: `sprite_gen.video.prop_plate`: new `find(files, plate)`, `region(row, size)`, `not_subject(row, size)`, `warnings(done)`; `erase(files, decoded, rows, plate)` (was `erase(files, plate)`); `frame_box` no longer adds the rim; new constants `KEY`, `BLEND_REACH`, `PLATE_TOLERANCE`, `PIECE_SHARE`, `LUMA_SLACK`, `BLEND_BALANCE`, `BLEND_SLOPE`, `NAMED`; `RIM` is 4; `STILL_TOLERANCE` removed. `sprite_gen.frames.decontam`: `not_applicable(..., not_subject=None)`, `subject_palette(..., not_subject=None)`, `decontaminate(..., not_subject=None)`. `sprite_gen.frames.extract.remove_chroma_background(..., decontam_not_subject=None)`; `sprite_gen.frames.cutout.cutout(..., decontam_not_subject=None)` and `extract_route(..., decontam_not_subject=None)`. `None` (the default) keeps 4.0.0's behaviour.+- **Docs**: [video-pipeline.md](docs/video-pipeline.md) "Prop plate: `--prop-plate`" subsection rewritten; [chroma-alpha.md](docs/chroma-alpha.md) decontam section points to it; `SKILL.md` plate guidance.+- **Tests**: `tests/video/test_prop_plate.py` (19 synthetic tests: fixed plate shifted 1 px in two frames; panned clip sliding 4 px a frame with one frame turned 12 degrees and one frame without the plate; crossing figure in both; clip with a pink patch on the figure). Verifies no plate or magenta pixels remain in keyed frames; each frame row (`box` within 2 px of drawn plate, `plate_px` within 5% and `tilt` within 1 degree in clear frames, `not_found`, `touching`); the two warning lines; crossing figure losing at most 2 codec-tinted pixels a frame; byte-identical frames away from the plate compared to runs without `--prop-plate` (edge pass off); search initialized from the canvas report box (unrelated box finds and erases nothing); direct image check where plate edge and blue-grey blend line go while a denim bar crossing the rim keeps all pixels; early refusal of canvas reports without plates; `frame_box` arithmetic; palette exclusion ensuring no palette colour within 48 of the plate and preserving pink within 24 (versus plate colour included without `--prop-plate`); and clean `video-loop` cuts. Red first on the 4.0.0 engine: 9 of 18 tests failed. The fixed clip kept 376 and 188 plate pixels across the two shifted frames; the panned clip kept the plate in 13 of 15 frames (up to 3572 px, the whole plate); the turned frame kept 667 px (404 magenta). The median rule erased 4, 89, 100, and 104 untinted figure pixels in four frames. The learned palette contained a colour 3 away from the plate. Under the new rules: without rule (c) the blue-grey line beside the bar remained (column 76); with a 3 px rim a line 4 px from the plate remained (column 56); with both, all 19 passed. When the plate region is not excluded from palette learning, the test fails by including a colour within 48 of the plate (nearest was 3 away on its farthest channel); with exclusion, it passes.+## v4.0.0 - Game features removed leaving only sprites, no picture shown again by default (`--fill-held off`) save meant holds, `inspect-holds` compares deliveries with hold lists, and `video-chain` plays keyed clip pieces as one timed move**Upgrading from 3.15.0: `sprite-gen sound`, `sprite-gen game-pack` and `sprite-gen ui-kit` are removed, with `gen --layout-guide ui-kit` and `background-tile --axis xy`.** These game-making features were added for building games. Making games is outside the scope of this engine, which makes sprites; features that belong to sprites stay. Files an earlier version wrote (sound folders, game packs, UI kit folders) stay on disk; nothing reads them.diff --git a/SKILL.md b/SKILL.mdindex 4ae6a22..f312149 100644--- a/SKILL.md+++ b/SKILL.md@@ -136,7 +136,7 @@ Two rules. When an asset will be shown at a fixed display rate above its clip'sA move played once (a jump, a vault: `once`, `once-return`, `one-shot`) carries its root motion in the strip sidecar by default, the cells unchanged: `root_motion` gives each cell's root (the body's mass centre, cell px), what it stands on, and each air's take-off, landing, seconds and apex; a game reads `root` to place each cell and moves the body on its own physics. A move cut out of a longer motion is named with `video-loop --cycle once --start S --length L`, a hand on something the clip does not draw with `--contact hand=A:B`, metres with `--meters-per-px`; a jump whose body crosses the canvas is named the same way, because it never comes back to a pose it left: the one-shot cut refuses it and its line names the closest return (`the closest return, frames A-B, is R of its departure away`), whose frames are where to start the range. To give the air its own length, gravity and speed, `--air-retime gravity=G,air=T,speed=V` redraws it on that parabola with RIFE's frames between; contacts and the take-off and landing stay as filmed. Tell the user each air in one line, its seconds and its apex (the summary's `air`, e.g. `air 0.42 s, apex 0.21 m`). Details in [video-pipeline](docs/video-pipeline.md#root-motion--a-cut-played-once-where-the-body-is-what-it-stands-on-its-air).-For a move over an obstacle that clears a low wall (such as a vault or a jump), paint a flat magenta plate on the green key with `video-canvas --prop-plate` (which requires `--report`), then pass that canvas report to `video-frames --prop-plate <canvas report json>` to erase the plate from keyed frames. The plate box lives in the canvas report, which `video-frames` reads directly to scale and position the erase box; there is no second copy. If the video model drew the plate off its place by even a single pixel, grey blend lines remain down its sides: tell the user if any keyed frame kept lines of the plate. Details in [video-pipeline](docs/video-pipeline.md#prop-plate---prop-plate).+For a move over an obstacle that clears a low wall (such as a vault or a jump), paint a flat magenta plate on the green key with `video-canvas --prop-plate` (which requires `--report`), then pass that canvas report to `video-frames --prop-plate <canvas report json>` to erase the plate from keyed frames. The plate box lives in the canvas report, with no second copy; `video-frames` starts from it and finds the plate again in every frame, so a plate the camera carried off or turned is erased too, and the edge pass learns the subject's colours without it. Read the two warning lines a run can print: frames where no plate was found keep whatever of it they show, and in frames where the plate meets the subject, look at the subject's edge there; tell the user what either names. Details in [video-pipeline](docs/video-pipeline.md#prop-plate---prop-plate).A pinned idle or attack whose last frame the video model drew again has its wrap blended by default (`video-loop --wrap-blend auto`, a redraw only; `off` cuts as filmed), with details in [loop repair](docs/loop-repair.md#6-the-redrawn-wrap-a-pinned-clip-whose-last-frame-the-model-drew-again).diff --git a/docs/chroma-alpha.md b/docs/chroma-alpha.mdindex 36e6975..bae7f86 100644--- a/docs/chroma-alpha.md+++ b/docs/chroma-alpha.md@@ -114,7 +114,7 @@ Licensing: the pass is plain numpy inside this Apache-2.0 repository and install**The frame edge.** A decoded frame's blur runs the subject on into the key as a smooth tail, and the pass reads that tail as a faint blend at every distance, on the keyed ring just past the flank as well as on the flank, so no floor tells a strand's side from it. The video fit now gives keyed pixels no coverage at all, so its frame-edge band holds by construction there. Along the frame's top, left and right edges it decides a clip: `video-frames` refuses one where any visible pixel in its edge band has key colour in the source, as the key surviving the matte, so a head a few pixels under the frame edge would pass with the pass off and fail with it on. `video-frames` therefore hands the pass its edge band (`decontam_edge_band`, the gate's `EDGE_ROWS`), and there a pixel the matte left transparent stays transparent. The still fit's flank keeps what it recovers.-Two fits. `still` chooses P per pixel. `video` chooses P on a 3x3 mean of the observation, whose chroma is blurred anyway, and averages the projection alpha with a luma-only alpha where P and B differ in luma. `video-frames` uses the video fit and learns one palette per clip on the first frame, so the colours an edge may take cannot change from frame to frame. In a clip, `video-frames` keeps a history across frames, so a frame's bytes depend on the frames before it in the order they were given. This stops the edge of a still subject sparkling from frame to frame when codec noise shifts pixels across the pass's tests and palette choices. With hold, each test keeps the outcome it had at that pixel in the previous frame until this frame's evidence passes the test's bar the other way by 16 (an RGB distance, `VIDEO_HOLD`), and the palette colour picked in the previous frame stays unless another palette colour's line passes closer by 16. With blend, every examined pixel mixes this frame's matte rendering, with its key hue capped, and this frame's fit rendering, moving toward this frame's call by at most 0.2 a frame (`VIDEO_BLEND`) and by less when the premultiplied output change would exceed 4 (`VIDEO_STEP`) plus 0.25 (`VIDEO_STEP_MOTION`) per unit its source moved in its 3x3 box. A still pixel whose mix moved, is still on its way to its call, or came into or left the band moves at most 4 a frame from its previous output; a pixel keyed in this frame stays transparent. With settle, a pixel written in both frames in the same palette colour, whose mix is at its call in both frames and whose source moved by at most 8 in any channel anywhere in its 3x3 box (`VIDEO_STILL`), moves a tenth of the way (`VIDEO_SETTLE` 0.1) from its previous value toward this frame's fit and stays within 12 per channel (`VIDEO_SETTLE_REACH`) of that fit, catching up at most 4 a frame where needed.+Two fits. `still` chooses P per pixel. `video` chooses P on a 3x3 mean of the observation, whose chroma is blurred anyway, and averages the projection alpha with a luma-only alpha where P and B differ in luma. `video-frames` uses the video fit and learns one palette per clip on the first frame, so the colours an edge may take cannot change from frame to frame; with `--prop-plate` it learns it without the plate's place on that frame ([prop plate](video-pipeline.md#prop-plate---prop-plate)). In a clip, `video-frames` keeps a history across frames, so a frame's bytes depend on the frames before it in the order they were given. This stops the edge of a still subject sparkling from frame to frame when codec noise shifts pixels across the pass's tests and palette choices. With hold, each test keeps the outcome it had at that pixel in the previous frame until this frame's evidence passes the test's bar the other way by 16 (an RGB distance, `VIDEO_HOLD`), and the palette colour picked in the previous frame stays unless another palette colour's line passes closer by 16. With blend, every examined pixel mixes this frame's matte rendering, with its key hue capped, and this frame's fit rendering, moving toward this frame's call by at most 0.2 a frame (`VIDEO_BLEND`) and by less when the premultiplied output change would exceed 4 (`VIDEO_STEP`) plus 0.25 (`VIDEO_STEP_MOTION`) per unit its source moved in its 3x3 box. A still pixel whose mix moved, is still on its way to its call, or came into or left the band moves at most 4 a frame from its previous output; a pixel keyed in this frame stays transparent. With settle, a pixel written in both frames in the same palette colour, whose mix is at its call in both frames and whose source moved by at most 8 in any channel anywhere in its 3x3 box (`VIDEO_STILL`), moves a tenth of the way (`VIDEO_SETTLE` 0.1) from its previous value toward this frame's fit and stays within 12 per channel (`VIDEO_SETTLE_REACH`) of that fit, catching up at most 4 a frame where needed.**Gold and yellow.** Gold sits between red and green, so a gold a little darker or yellower than the palette's own also fits as a warmer palette gold with some green mixed in. Up to v2.10.1 the still fit took that reading, and gold edges and small gold drops came out orange and partly see-through. Since v2.10.2 the still fit weighs the blend against the subject's own colour at the pixel's own light (the freedom the written colour already has), and a blend has to win by more than the subject's own spread: the 99th percentile of how far its confident interior sits from the palette, large for a textured gold and small for flat colour. A still's antialiased edge is at most two pixels deep, so deeper in the band a key share has to show as the key's hue: a pixel without it is the subject's own colour, and so is an edge pixel without it that has the colour of the material right behind it. Where the matte changed such a pixel, the source colour and coverage come back. The RGB matte (`cutout`'s default) needs that: it scores key tint on the channel average, which calls yellow green, so it unmixes gold as if it were a blend; the YCbCr matte (`gen`) does not. The video fit keeps its decisions, because a decoded frame's chroma is blurred and an edge pixel's colour is no evidence of what the subject is made of there.diff --git a/docs/video-pipeline.md b/docs/video-pipeline.mdindex edf9dae..541a822 100644--- a/docs/video-pipeline.md+++ b/docs/video-pipeline.md@@ -100,9 +100,17 @@ chroma key, the padding is the corner colour.A move over an obstacle (a vault, a jump over a low wall) needs something to clear. When asked in words for a wall in the background colour, a video model draws a black slab, and keying leaves that slab in the keyed frames. The obstacle is therefore painted into the still the clip is made from as a flat magenta plate, RGB (255, 0, 255), on the green key, which keying does not take and a later erase pass removes. `video-canvas --prop-plate` (off by default) paints this plate in front of the subject on the side it faces (`--facing`), standing on the subject's foot row (the plate's bottom row is the subject's bottom row). Sized from `canvas.subject_box` on the canvas whose background was normalized to the exact green key, its height is 0.49 of the subject height, its thickness is 0.20, and its near side is 0.84 of the subject height ahead of the subject's front. The flag requires a green key and `--report`. A run writes no canvas and refuses if the key is not green ("--prop-plate paints a magenta plate on a green key"), if `--report` is omitted, for state `effect` ("an effect keeps its source canvas; drop --prop-plate"), or if the plate falls past the canvas edge on the facing side ("frame the subject with room in front (--shape wide, --lead)"). The report records `prop_plate`: `box` (left, top, right, bottom in canvas pixels, right and bottom one past), `rgb`, `subject`, and `of_subject_height` (`height`, `width`, `gap`). This box is the single value used for painting and erasing; `video-frames` reads it from the report with no second copy.-`video-frames --prop-plate <canvas report json>` takes the canvas report path, joining the inputs a run never overwrites. It is checked before frame extraction and refused before keying if the file is not a canvas report or holds no plate ("holds no plate; the canvas was made without --prop-plate"). The box is scaled to the clip's frames by the ratio of frame size to canvas size rounded outward on each axis, then widened by a 3 px rim on each side (`erase_box`). On a run that passed, every keyed frame is erased inside `erase_box` before handover: a pixel becomes fully transparent when red and blue lead green by more than 35 and red and blue are within 90 of each other, or when each channel (with alpha as one of the channels) is within 40 of the median that pixel shows over the whole clip. The median represents the plate and its surroundings because the subject crosses for part of the clip only; checking alpha prevents transparent background pixels from reading as black, keeping the subject's dark outline intact across the rim. Refused runs keep the plate in their refused folder. The frames report adds `prop_plate` (`canvas_report`, `erase_box`, `rim`, `frames`, `frames_changed`, `erased_px`). `video-loop` cuts of erased frames carry no plate; `video-set` does not paint or erase a plate.+`video-frames --prop-plate <canvas report json>` takes the canvas report path, joining the inputs a run never overwrites. It is checked before frame extraction and refused before keying if the file is not a canvas report or holds no plate ("holds no plate; the canvas was made without --prop-plate").-The video model must keep the plate where the canvas has it. In a frame where the model draws the plate one pixel off, the plate's sides stay as the codec's grey blend of magenta and green about one pixel wide down each side, which neither erase rule takes (in synthetic tests, frames with the plate one pixel to the right keep 188 and 95 such pixels). Subject edge pixels tinted magenta by the codec are erased with the plate (2 pixels in each of two frames in synthetic tests). No other guard, retry, or measurement is added.+A video model told to keep the camera still can pan anyway, following the subject, and can turn the plate the subject pushes off, so after the first frames the plate is no longer where the canvas placed it. The plate is therefore found in each frame, on the frame as decoded. The canvas box is carried onto the frame by the ratio of frame size to canvas size, rounded outward on each axis (`start_box`). Each frame is searched in a window reaching the plate's diagonal (measured on `start_box`) past a box on every side: `start_box` on the first frame, and the box found last on every later frame. A frame where no plate is found leaves the last box as it was. The plate's pieces are the pixels within 48 of (255, 0, 255) on every channel, joined side by side or at corners, each holding at least 1% of the plate's area on the frame. The plate is every pixel of its colour in the box its pieces span, so a plate the subject in front of it cuts in two is found whole.++On a passing run, every keyed frame where the plate was found is erased before handover, within a 4 px rim (`rim`) around the plate's pixels, each way and diagonally. The erasure is evaluated on the frame as decoded, not on what the matte or the edge pass made of it. A pixel becomes fully transparent where red and blue lead green by more than 35 and are within 90 of each other (the plate, its edge, or a subject edge pixel the codec tinted magenta), or where it is the line the plate's edge blends into the key. The codec's 4:2:0 chroma leaves that line neither colour (a grey, a dark magenta, a pale green), so it is read by where and what it is: within 2 px of a pixel of the key's colour (each channel within 48 of the key), its luma (the Rec. 601 weights) within 40 of the span between the plate's luma and the key's, and its hue on the axis between them (red and blue within 40 plus 0.35 of how far their mean is from green). The codec can also ring a blue grey into that line, which no colour rule tells from denim, so what is left within the rim after the two rules goes as well when it lies in a piece (opaque pixels joined side by side or at corners) wholly within the rim. The subject in front of the plate keeps its pixels: its skin, cloth, and hair lie off the plate-to-key axis, its dark outline is darker than that luma span, its white is lighter, and a part of the subject reaching past the rim is not a piece wholly within it. Refused runs keep the plate in their refused folder.++The frames report adds `prop_plate`: `canvas_report`, `start_box`, `rim`, `frames`, `frames_changed`, `erased_px`, `not_found` (the frames no plate was found in), `touching` (the frames where opaque pixels stay within the rim: the plate meets the subject), and `rows`, one per frame, with `frame`, `found` and, where the plate was found, `box` (frame pixels, right and bottom one past), `plate_px`, `tilt` (degrees the plate's long axis is turned from upright, clockwise on the frame positive), `erased_px`, and `touch_px`. A run encountering such frames prints a warning line for each list, naming the first six frames and counting the rest: `--prop-plate: no plate found in N frame(s) (...)` (nothing was erased there, so any of the plate they show is still in them) and `--prop-plate: the plate meets the subject in N frame(s) (...)` (look at those frames).++The edge pass (`--decontam`, see [Chroma and alpha](chroma-alpha.md#decontam--give-the-edge-the-subjects-own-colour-back)) learns the subject's palette on the first frame it runs on, where the plate stands as opaque as the subject. With `--prop-plate`, the plate's place on that frame (its pixels and the 4 px rim around them) is left out of what the palette is learned from, and out of the interior whose key-hued share decides whether the palette is key-free, so the plate's magenta is not learned as a colour the subject owns. Without `--prop-plate` the pass learns as before. `video-loop` cuts of erased frames carry no plate; `video-set` does not paint or erase a plate.++What the erase leaves to the eye: a grey of the subject's own that lies between the plate and the key, against the plate, goes with the blended line, and a piece of the subject the plate cuts off wholly within the rim goes with the plate; a frame no plate was found in (the subject covers all of it, or it moved further than its own diagonal from the last frame) keeps whatever of the plate it shows. The warning lines name those frames. In synthetic tests (a clip whose plate slides a few pixels a frame with one frame turned 12 degrees and one frame without it, a fixed plate drawn one pixel off in two frames, and a figure crossing in front of it), no pixel of the plate's colour or of the magenta rule is left in any keyed frame, the figure loses only the pixels the codec tinted magenta where it crosses the plate (at most 2 a frame), and away from each frame's plate the frames are byte-identical to the frames keyed without `--prop-plate` (edge pass off). No other guard, retry, or measurement is added.```bashsprite-gen video-canvas --still still.png --out canvas.png --state jump --key green --facing right --prop-plate --report canvas.json