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-loop): the redrawn wrap — what the wrap blend fixes, its rules and reasons, the synthetic readings, the cost, the limits and the record

Soohong Kim43ce848a7b09
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e6346c5..15d26dc 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,56 @@
All notable public changes to `sprite-gen` are recorded here. Versions track the `version:` field in `SKILL.md` and `pyproject.toml`.
+## Unreleased
+
+**Upgrading from 2.45.3: Existing outputs change bytes for some clips.**
+This affects only cuts made with `--anchor none` using:
+`video-loop --cycle pinned`
+whose pin the gate passes and whose pinned last frame redraws the first.
+This is how `video-set` cuts idle and attack clips filmed with their first frame as the last.
+A redraw occurs when the first cell differs from the pinned frame by more than `--seam-max` (default 2.0) times the cut's median step at full size.
+Only these cuts now give different `cycle/` cells (the last half second), strip, GIF and WebP.
+Every other cut gives the same bytes as 2.45.3:
+a pinned cut whose pinned frame draws the first as it is,
+every non-pinned cut (walk, run, auto, periodic, fixed, one-shot, once, once-return, lifetime),
+a body-anchored pinned cut,
+and anything cut with `--wrap-blend off`.
+A pinned clip whose pin the gate refuses fails as before with the same message.
+A source projection reads a blended strip as `source-processing-unsupported`.
+No restoration schema changes.
+
+- **Changed (default):** A video model given the first frame as the last draws that frame again (softer or sharper, another tone, hair strands a pixel over).
+ The pin gate reads the pose and passes.
+ The drawing stays, so the loop's wrap shows one jump in sharpness where every other step shows the motion.
+ Over the cut's last half second (K = min(round(0.5 s x fps), floor(L / 4)) cells, 12 at 24 fps), wrap blending adds back j/(K+1) of the redraw's difference (first cell minus pinned frame, premultiplied) on the j-th cell.
+ Each pose stays the cell's own, and its drawing turns into the first cell's by the wrap.
+ Only a redraw is ramped.
+ A pixel is held where the two ends hold a part, a line or a dot in different places, and where a ramp cell does not stand where the pinned frame stands.
+ This check applies after one softness match of at most 0.7 px.
+ A pixel is held if it is more than 12 levels outside what the other end holds within 1 px on a 7x7 mean or a 7 px run, over black and over white.
+ It is also held if its value is more than 12 outside the other end's 1 px range where the other end has under half this end's range there, in any direction, length or width.
+ Held pixels are widened 3 px and the weight feathered 7x7.
+ A pixel of weight 0 is the filmed byte.
+ A ramp that steps more than the cut already does, or that does not shrink the wrap, is not used: the cut is written as filmed and a `warning:` line says so.
+ A wrap still over `--seam-max` after blending also gets a `warning:` line.
+ New flag (default `auto`, and `video-set` takes the default):
+ `video-loop --wrap-blend auto|off`
+ New report key `wrap_blend` on every pinned cut (`applied`, `why`, `K`, `cells`, `residual_ratio`, `wrap_ratio_before`, `wrap_ratio_after`, `ramp_step_max_ratio`, `bound_ratio`, `pose_share`, `presence_share`, `never_settled`, `equalize`, `after_check`, `seconds`).
+ `wrap_blend: {cells, K}` appears in the strip metadata where it applied, and in the CLI summary.
+ [loop repair](docs/loop-repair.md#6-the-redrawn-wrap-a-pinned-clip-whose-last-frame-the-model-drew-again)
+- **Tests**: `tests/video/test_wrap_blend.py` on synthetic clips:
+ a redraw of tone and 0.5 px softness has its wrap brought from 7.31x to 0.57x the median step and only the ramp's cells, strip, GIF and WebP differ from off;
+ an arm still coming down in the ramp stays the filmed arm;
+ a part moved 2 to 64 px, or present at one end only, is never drawn twice (the 14 px part on a flat figure is cut as filmed with a warning);
+ 1 px lines moved 2 to 32 px on a flat figure are byte for byte;
+ stripes swinging inside the ramp keep their swing;
+ a strand against the silhouette is held over white where black alone lets it through;
+ the softness match blurs the sharper end, never past 0.7 px;
+ the idle-still fixture gives every output byte for byte;
+ fixed cuts, body-anchored pinned cuts and refused pins are not touched;
+ a ramp that steps past the cut is refused with a warning;
+ a 1 px line at slope 1/3 moved 8 px is held line for line, thin structures change by at most 2 levels and busier quiet grounds by at most 3, strands off the silhouette by none.
+
## v2.45.3 - The seam check reads the frames that play when the body anchor spreads a sideways slide; such a cut passes again, as it did in 2.44.0
**Upgrading from 2.45.2: Every cut 2.45.2 passed, and every `--anchor motion-auto` run, gives the same bytes as 2.45.2.** Only `--anchor body` cuts that 2.45.2 refused because of the walk sliding sideways before the anchor can now pass, read on the frames that play. Refused cuts print the same error line as before, the report's `producer` field names the new version, and there are no restoration schema changes.
diff --git a/SKILL.md b/SKILL.md
index 7d86996..fde107b 100644
--- a/SKILL.md
+++ b/SKILL.md
@@ -152,6 +152,8 @@ Use existing automatic pipeline stages for background removal, extraction, align
For attack repeat coverage, observed one-shot returns and structured loop failure reports, follow [video-pipeline](docs/video-pipeline.md#one-shot-actions--cycle-autoperiodicone-shot).
+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).
+
Scene creation consumes finished assets and remains optional. Asset metadata owns frames, native durations and anchors; scene specs own placement, scale, playback rate, planes, camera and light. Measure stride only with declared same-foot contact and an isolated foot ROI; unknown contact stays unverified. Apply only a verified report for the exact selected asset with an explicit scene direction. Never infer walking direction from the bottommost silhouette, reverse frames or change source assets to make a scene work.
## 실행 인터프리터
diff --git a/docs/loop-repair.md b/docs/loop-repair.md
index 5b903d2..37978f9 100644
--- a/docs/loop-repair.md
+++ b/docs/loop-repair.md
@@ -1,6 +1,6 @@
# Loop repair — RIFE in-betweens for jump frames, the jolt index, one cycle per set
-> Owns: Where RIFE runs and what it costs, which model and augmentation it runs with, how it is installed and what runs without it, jump-frame repair in `video-loop`, the flow reading (frames off a walk's way), the eased retime (a part that rushes on its way), the jolt index and its gate, cycle alignment across a direction set · Index: [docs/README.md](README.md)
+> Owns: Where RIFE runs and what it costs, which model and augmentation it runs with, how it is installed and what runs without it, jump-frame repair in `video-loop`, the flow reading (frames off a walk's way), the eased retime (a part that rushes on its way), the jolt index and its gate, cycle alignment across a direction set, the redrawn wrap of a pinned clip (`--wrap-blend`) · Index: [docs/README.md](README.md)
A walk loop cut from a generated clip can look right in every still and still hitch when it
plays: the video model redraws thin hair a little differently every frame, and now and then
@@ -1659,6 +1659,63 @@ this set.
A side-by-side video of the takes as filmed and as this engine leaves them, the numbers, and the
scripts that made them are kept with the experiment's material in the maintainer's notes.
+## 6. The redrawn wrap: a pinned clip whose last frame the model drew again
+
+When `video-loop --cycle pinned` cuts a clip generated with its first frame given to the video model as the last frame too, the cut retains every frame except the last. The pin gate checks that the last frame lands near the first on a small thumbnail and passes, because the pinned last frame holds the first frame's pose. The video model draws that frame again: softer or sharper, in another tone, or with hair strands a pixel over. Because the redraw remains, the wrap from the last cell back to the first shows this redraw as a single jump in sharpness, whereas every other step in the loop shows motion.
+
+The wrap blend (`video-loop --wrap-blend auto`, the default) takes the first frame's drawing back over the cut's last half second, applying only where the two ends differ by a redraw. Passing `--wrap-blend off` cuts as before with identical bytes. The step is implemented in `sprite_gen/video/wrap_blend.py` (`measure`, `gate`, `blend`, `apply`) and called from `loop.run_loop`. It runs on the frames as filmed after the anchor and after `source_projection`, before any repair reads the wrap, and before `cycle/`, the strip, the GIF and the WebP are written.
+
+| Rule | Value | Why |
+|---|---|---|
+| When | `--cycle pinned`, `--anchor none`, the pin gate passes, `--wrap-blend auto` | Idle and attack clips that `video-set` films pinned are cut this way. An anchor that moves the cells (`--anchor body`) puts them off the place the pinned frame holds, so they are not blended and the report says why. A pin the gate refuses fails the clip whatever its wrap shows, so it is not tried (the cut is written as filmed and the failure message is unchanged). Other cuts (auto, periodic, fixed, one-shot, once, once-return, lifetime) are not read and their report has no `wrap_blend`. |
+| The ruler (`measure`) | The first cell against the pinned last frame (the pinned frame cleaned as the cut's frames are: RGB under alpha 0 scrubbed, detached specks dropped), at full size, over the first cell's opaque inside (alpha 250 and up, eroded 3 px), composited on a dark ground (RGB 20, 16, 28), the mean of the largest channel difference; divided by the cut's median step read the same way (the wrap left out). This is the residual ratio. | The difference between the two drawings of one pose is the redraw itself; a sharpness measure such as the variance of the Laplacian does not separate this jump from the clip's own frame to frame changes in sharpness. The ruler reads one frame at a time, so a long cut at full size is never held whole. |
+| Not a redraw | Residual ratio at most `--seam-max` (default 2.0) | Nothing is done, the bytes are the same as `off`, and `wrap_blend.why` says so, because a pin that draws the first frame as it is needs nothing. |
+| The ramp | The last K cells, K = min(round(0.5 s x fps), floor(L / 4)) for a cut of L cells (12 at 24 fps); K under 2: nothing | Half a second takes the jump over a dozen ordinary steps; a short cut keeps three quarters of itself as filmed. |
+| The shape (`blend`) | The residual ramp: the difference e = first cell minus pinned frame, premultiplied RGBA, is added to the ramp cells: j/(K+1) of e on the j-th ramp cell (j = 1..K). Per pixel the ramp starts from the first ramp cell on which the pixel stands through to the end, and ramps over the cells left. | Each pose stays the cell's own; its drawing turns into the first cell's by the wrap. Mixing the ramp cells toward the first cell moves the pose as well as the drawing, producing ghost copies of moving parts. |
+| What the two ends hold apart (`gate`, the two ends) | Never ramped: a pixel is held where (a) after one softness match for the clip, the values one end holds lie more than 12 levels outside what the other end holds within 1 px, on a 7x7 mean or along a 7 px run (across, down or along either diagonal), over black or over white; or (b) presence: a value one end holds lies more than 12 outside the other end's 1 px range while the other end's own 1 px range is under half (kappa 0.5) of this end's, in any of seven channels (premultiplied RGBA and RGB over white), raw values, no window. The softness match (`equalize`) blurs the sharper end by 0, 0.35, 0.5 or 0.7 px, whichever brings the two ends nearest over the figure. | A ramp of the difference draws whatever the two ends hold in different places a second time. A redraw (a line drawn softer or half a pixel over) keeps a share of its range in the other frame; a line, a dot or a part moved 2 px or more does not, whatever its direction, length, spacing or width. The presence test has no window and no list of directions because an earlier gate with only (a) let a 1 px line at slope 1/3 through, thinning under 12 in the 7x7 mean and in every one of the four runs, and drew it twice. |
+| Over black and over white | Gate evaluated over both black and white grounds | A sprite lands on any ground. Over black alone, a silhouette's transparent neighbour (0, 0, 0, 0) puts every dark value in range: a dark strand against the silhouette that moved out on the transparent ground would be drawn twice. |
+| Ramp cell standing where pin stands (`gate`, each ramp cell) | Cell 7x7 mean difference to the pinned frame is within 1.5 x the redraw's + 2, and tests (a) without the softness match and (b) hold against the pinned frame; a pixel that does not stand on a ramp cell is not ramped on it | A part that is still moving inside the last half second (an arm coming down, a blink) is the filmed part. |
+| Widen and feather | What is held is widened 3 px and the weight is feathered with a 7x7 mean; a pixel whose weight is 0 is the filmed pixel, byte for byte | The 3 px widening is exactly the feather's reach (a 7x7 mean reaches 3 px), so a pixel the gate holds keeps weight 0 under the feather and no ramp seeps into it; the feather then lets the ramp fade out at the edge of what is held instead of stopping in a hard edge. |
+| The after check | The blend is used only where every step into and through the ramp is within the larger of the cut's own largest step and `--seam-max` x the median step, and the wrap shrinks. Otherwise the cut is written as filmed, `wrap_blend.after_check` is "refused", and a `video-loop: warning:` line says the wrap blend was not used, why, with the numbers. | A blend that steps more than the cut does trades the wrap's jump for a jump inside the loop. |
+| Wrap still over `--seam-max` after blend | Blended, and a `warning:` line says so with the share of the figure held as filmed | The blend passed the after check (no step past the cut's own, the wrap smaller), so it is kept; what the two ends hold apart is filmed and still jumps at the wrap, which the line names so a person looks at the wrap. |
+| Order in `video-loop` | After the anchor and after `source_projection` (which records the cut before the blend), on the frames as filmed, before any repair reads the wrap, and before `cycle/`, the strip, the GIF and the WebP are written | The blend reads where each cell stands against the pinned frame, so it runs on the frames as filmed, after the anchor has placed them; `source_projection` keeps the record of the cut before it; any repair that reads the wrap then reads the wrap the blend leaves, not the redraw's jump; `cycle/`, the strip, the GIF and the WebP all carry the same blended cells. |
+
+Mixing the ramp cells toward the first cell (the conventional wrap blend) moves the pose as well as the drawing, so a part that moves inside the ramp receives a translucent second copy. On a synthetic attack whose arm is raised until four frames before the pin, mixing toward the first cell lays a resting-arm ghost over the raised arm (128 levels from the ideal frame), and a synthetic eye blink near the end gives an eye ghost (133 levels). Adding only the residual difference e (first cell minus pinned frame) as j/(K+1) ensures each pose stays the cell's own while its drawing turns into the first frame's drawing by the wrap.
+
+The test character in `tests/video/test_wrap_blend.py` is a synthetic pinned idle of 73 frames (72 cells and the pin, K = 12 at 24 fps), 160 x 224, whose frames after the first are the model's drawing of it (another cloth texture, hair strands up to 0.6 px over, 0.5 px softer, another tone), so the pin, the ruler and the after check pass and the gate alone stands between a structure on it and the ramp. A flat figure has no redraw, so its cases are read on the gate and the ramp alone.
+
+| Case | Reading |
+|---|---|
+| Tone and 0.5 px softness redrawn, the character breathing 6 px | residual 7.24x the median step; wrap 7.31x to 0.57x; largest ramp step 1.56x against the bound 2.0x; only the 12 ramp cells, the strip, the GIF and the WebP differ from `off` |
+| The whole redraw, with a 1 px line of contrast 24 at slope 1/3 moved 8 px on a flat patch of the torso | wrap 19.90x to 4.26x; the line's pixels are the filmed bytes |
+| An arm raised until four frames before the pin | where the arm is 40 degrees or more from the pin's it is the filmed arm; on the last cell (20 degrees off) its fringe changes by 1 level at most |
+| A 14x14 part moved 2 to 64 px on the flat figure, or only in the first frame, or only from frame 6 | byte for byte |
+| A 10x10 part moved 2 to 32 px on the redrawn character, or only in one end | byte for byte, the rest blended |
+| The 14x14 part (contrast 120) moved 16 px on the flat figure, nothing else redrawn | residual 2.34x; the gate holds the part, the ramp does not shrink the wrap: cut as filmed, warning line |
+| A 1 px line of contrast 24, 48, 96 moved 2, 8, 32 px on the flat figure | byte for byte |
+| Stripes every 5 px redrawn 0.8 px over and swinging 3 px inside the ramp | the swing is filmed |
+| A dark strand against the silhouette moved 7 px out on the transparent ground | byte for byte; over black alone it would be ramped |
+| Dots of 1 to 3 px, dotted lines, a ring, a wave, a cross, an anti-aliased, a light and a one-channel line moved 8 px on a flat patch, a line only in the first frame or only from frame 6 | 2 levels at most (0 for most; 1 for the ring and the wave; 2 for the anti-aliased line) |
+| The slope 1/3 line over decode noise of 4 levels on every frame, a 4 level/px gradient, the widest softness match (0.7 px), static grain of 3, a 1 px checker of plus or minus 4 | 3 levels at most (0 or 1 measured); with the noise the median step rises and the ruler alone keeps that clip as filmed (residual 1.44x) |
+| A strand on the transparent ground off the silhouette moved 3 and 8 px | byte for byte |
+| The character sliding into the model's drawing over the whole clip (each step a 72nd of the redraw) | largest ramp step 6.66x against the bound 3.37x: not used, cut as filmed, warning line |
+| The idle-still fixture, whose pin draws the first frame as it is | residual 0.0x: nothing done, every output the same bytes |
+
+Cost: On a synthetic cut of 145 frames at 800 x 1120 (the test character scaled 5x), on an Apple M4 Max under a 1-minute load of about 15: the whole step takes 6.3 to 7.1 s, of which the ruler (every step of the cut at full size) takes 2.9 s. The pinned frame's grounds and 1 px ranges are computed once a clip; the K ramp cells are held as float RGBA (15 MB each at that size), one 7-channel ground and its 1 px range taking three 26 MB arrays a frame. No interpolator is called.
+
+Limits (what the gate reads as a redraw, and so ramps):
+1. A structure of contrast 12 or less, or one that does not stand 12 above its ground's own 1 px range: a faint part of contrast 8 changes by 7, of 11 by 10; a contrast 12 line by 11; on a 1 px checker of plus or minus 6 a contrast 24 line by 9 and a dotted line by 22.
+2. A move under 1 px in both x and y: a 14x14 part moved 1 px changes its edge column by 111; a 45 degree line moved (1, -1) by 22.
+3. Masking: where the other end has drawing of its own within 1 px of at least half this end's range (texture, an edge, a crossing structure): a 1 px line moved on the textured cloth keeps up to 36 levels (contrast 24), 7 (48), 3 (96), mostly hidden in the texture.
+4. Steep gradients: on 8 levels/px a contrast 24 line changes by 5 to 9, on 12 levels/px by 22.
+5. Noise only on the frames after a clean first frame (6 levels): 8 to 10 on a line. The pipeline does not make this case: the cut's first frame is the clip's own decoded first frame.
+6. The softness match blurs 0.7 px at most: a line moved on a redraw 1.0 px softer than the first frame keeps 8.6 (contrast 24), 1.9 (48), 0.6 (96).
+7. Redrawn hair strands are held by the presence test, so the wrap shrinks less than a ramp of everything would: on the synthetic idle the wrap ends at 7.35x where ramping all but the window test's holds would end at 2.2x.
+
+The loop report records `wrap_blend` on every pinned cut: `applied`, `why`, `K`, `cells` (the cells changed), `residual_ratio`, `wrap_ratio_before`, `wrap_ratio_after`, `ramp_step_max_ratio`, `bound_ratio` (all over the median step), `pose_share` (the share of the figure the two ends hold apart), `presence_share` (of the figure, what the presence test holds), `never_settled` (the share of the figure that never stands where the pin stands in the ramp), `equalize` (`sigma`, `blurred`: "still", "pin" or "none"), `after_check` ("passed" or "refused"), and `seconds`. Where it was not tried, `applied` is false and `why` records the reason ("--wrap-blend off", "--anchor body moves the cells off the place the pinned frame holds", or "the pin does not close: the clip is refused on it"). Other cuts (auto, periodic, fixed, one-shot, once, once-return, lifetime) are not read and their report has no `wrap_blend`. Strip metadata (`<name>.strip.json`) carries `wrap_blend: {cells, K}` where it applied, and the CLI summary carries `wrap_blend` (`applied`, `why`, `residual_ratio`, `wrap_ratio_before`, `wrap_ratio_after`). Because `source_projection` records the cut before the blend, reading a strip whose cells were changed by the blend is reported as processing that cannot be reproduced (`source-processing-unsupported`).
+
+A `video-loop: warning:` line is emitted under two conditions. When the after check refuses the blend because a step into or through the ramp exceeds the bound or the wrap does not shrink, the cut is written as filmed, `wrap_blend.after_check` is set to "refused", and the warning states that the wrap blend was not used, why, and the measured numbers. When the wrap remains over `--seam-max` after blending because the two ends hold a part apart, the blend is applied anyway and a warning line reports that condition along with the share of the figure held as filmed.
+
## Related
- [video-pipeline.md](video-pipeline.md) — the pipeline these repairs run inside
diff --git a/docs/video-pipeline.md b/docs/video-pipeline.md
index 5fede81..8d0aaae 100644
--- a/docs/video-pipeline.md
+++ b/docs/video-pipeline.md
@@ -1023,7 +1023,7 @@ last frame has to land within `max(seam_max x the mean step, PIN_NOISE_MAX)` of
the analysis thumbnail. A near-still clip moves so little per frame that the ratio reads the
re-render noise of the pinned frame as a jump; a clip that ends in another pose still fails,
with its own message (`the pinned clip does not end on its first frame`). The report says
-`kind = "pinned"` and records `pin_error` and `pin_tolerance`.
+`kind = "pinned"` and records `pin_error` and `pin_tolerance`. Where the pinned frame redraws the first, `--wrap-blend auto` (the default) takes the first frame's drawing back over the last half second, a redraw only, recorded as `wrap_blend`. Passing `--wrap-blend off` cuts as before with identical bytes. See [loop repair](loop-repair.md#6-the-redrawn-wrap-a-pinned-clip-whose-last-frame-the-model-drew-again) for the gating and blending rules.
`--cycle once-return` is for a clip pinned to end on its first frame that plays once (`video-set
--play once-return`, [play modes](#play-modes)). It keeps every frame, the last too, so the strip
diff --git a/sprite_gen/video/wrap_blend.py b/sprite_gen/video/wrap_blend.py
index c325869..4860634 100644
--- a/sprite_gen/video/wrap_blend.py
+++ b/sprite_gen/video/wrap_blend.py
@@ -27,8 +27,8 @@ What fails is widened 3 px and the ramp is feathered 7x7; a pixel whose weight i
pixel. A ramp that steps more than the cut already does, or does not shrink the wrap, is not used
(the after check): the cut is delivered as filmed, with a warning line.
-The values are the diagnosis's (plan sprite-gen/seam-sharpness-blend-1021); changing one is measuring
-the tables again.
+The values are the ones docs/loop-repair.md section 6 records with its synthetic readings and limits;
+changing one is measuring them again.
"""
from __future__ import annotations