Generate clean 2D game sprites & animation atlases — component-row pipeline: state rows, alpha cleanup, frame extraction, runtime atlases. Codex/Claude skill.
fix(video-loop): the rank reading judges only between outlined drawings; art painted without a line keeps the dark line
Soohong Kim5e4c94969199
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 7e5f5b8..c76cecb 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -4,8 +4,8 @@ All notable public changes to `sprite-gen` are recorded here. Versions track the## Unreleased-- **Behavior change: a frame the jump repair or the cycle alignment makes loses its outline only where it is lighter than its neighbours' edge rank by rank, too.** The fault `outline` read the made frame's edge against one dark line (a solid pixel under 70/255 within 2 px, `outline_loss` over 5 %), so art outlined in a mid tone — a brown or a painted line whose tone lies about 70/255 — had its line on the near side of the line in the drawings and on the far side wherever the flow softened it by a few tones: every frame made between two such drawings read as melted, and the repair and `--between auto` refused it. `rife.outline_shift(made, a, b)` reads the same edge, each pixel by how dark the darkest solid pixel within 2 px of it is, in order, against the lighter neighbour's edge at the same rank, and counts it where it is lighter by more than 50/255 (`rife.OUTLINE_SHIFT`). The fault `outline` now needs both over 5 %: a softened line is lighter by less at every rank and is kept, whatever tone the art outlines in; a line gone to the fill beside it is lighter by its whole contrast and is lost. Art outlined near-black reads the same on both, and art outlined lighter than 70/255 is still not judged by the outline. On the two-tone walker of the tests, the drawing between with its line 20 to 45 tones lighter reads `outline_loss` 57 % and `outline_shift` 0 (refused before, kept now); with its legs' line turned to fill, 24 % and 48 % (refused). A line less than 50/255 darker than the fill it melts into is not read as lost. The jump repair's proposals and the alignment's `smear` rows carry `outline_shift`, and the alignment's warning line names it; `video-loop-compare` and `video-loop-repair` keep their versioned measures, `rife.smear` alone, and judge the outline on the dark line as before ([loop-repair](docs/loop-repair.md) section 4).-- **Tests** — `tests/video/test_outline_shift.py` (a mid-tone line drawn lighter is kept and one gone to fill is lost; the versioned measures judge on the dark line alone; art outlined near-black reads the same on both; a frame with no edge reads 0; the jump repair takes a lighter line and refuses one gone to fill; the alignment keeps the one and takes the nearer frame for the other; through RIFE, a short step of two-tone legs keeps its outline and legs crossing far lose it on both), `tests/video/test_cycle_align.py` (the stand-in melt takes the dark foot into a pale fill: into the body's blue, 42/255 lighter, it is no further than a softened line).+- **Behavior change: a frame the jump repair or the cycle alignment makes between outlined drawings loses its outline only where it is lighter than its neighbours' edge rank by rank, too.** The fault `outline` read the made frame's edge against one dark line (a solid pixel under 70/255 within 2 px, `outline_loss` over 5 %), so art outlined in a mid tone — a brown or a painted line whose tone lies about 70/255 — had its line on the near side of the line in the drawings and on the far side wherever the flow softened it by a few tones: every frame made between two such drawings read as melted, and the repair and `--between auto` refused it. `rife.outline_shift(made, a, b)` reads the same edge, each pixel by how dark the darkest solid pixel within 2 px of it is, in order, against the lighter neighbour's edge at the same rank, and counts it where it is lighter by more than 50/255 (`rife.OUTLINE_SHIFT`). The fault `outline` now needs both over 5 %: a softened line is lighter by less at every rank and is kept, whatever tone the art outlines in; a line gone to the fill beside it is lighter by its whole contrast and is lost. Art outlined near-black reads the same on both, and art outlined lighter than 70/255 is still not judged by the outline. On the two-tone walker of the tests, the drawing between with its line 20 to 45 tones lighter reads `outline_loss` 57 % and `outline_shift` 0 (refused before, kept now); with its legs' line turned to fill, 24 % and 48 % (refused). A line less than 50/255 darker than the fill it melts into is not read as lost. The rank reading is read only between outlined drawings: `rife.outlined(frame)` is the share of a frame's edge whose line, the darkest solid pixel within 2 px, is darker than its fill, its colour from twice the bleed's depth inside (`rife.LINE_DEPTH`), by more than 50/255, and both neighbours must read at least 75 % (`rife.OUTLINED`); elsewhere `outline_shift` is `null` and the dark line judges alone, as before. Art painted without a line has no line to lose, and a part the flow melts there — a boot washed pale — can come out lighter by less than 50/255 at every rank: read rank by rank it would be kept and delivered, where refused it is replaced by the nearer filmed frame. On the walker of the tests painted without a line (outlined on 4 % of its edge), the drawing between with its near boot washed 40 tones lighter reads `outline_loss` 7.8 % and, rank by rank, 0: refused. The 75 % is set on frames made between drawn walks and judged by eye so that no frame seen as broken that the dark line alone refused is kept. The jump repair's proposals and the alignment's `smear` rows carry `outline_shift`, and the alignment's warning line names it where it was read; `video-loop-compare` and `video-loop-repair` keep their versioned measures, `rife.smear` alone, and judge the outline on the dark line as before ([loop-repair](docs/loop-repair.md) section 4).+- **Tests** — `tests/video/test_outline_shift.py` (a mid-tone line drawn lighter is kept and one gone to fill is lost; the versioned measures judge on the dark line alone, and so does a measure whose rank reading was not read; art outlined near-black reads the same on both; a frame with no edge reads 0 and neighbours with none are not read; the jump repair takes a lighter line and refuses one gone to fill; the alignment keeps the one and takes the nearer frame for the other; on the walker painted without a line, a boot washed 40 tones lighter is refused by the jump repair and replaced by the alignment, and the two-tone and black walkers read outlined on all their edge; through RIFE, a short step of two-tone legs keeps its outline and legs crossing far lose it on both).- **Behavior change: every RIFE call runs the binary's test-time augmentation, `-x -z` (`rife.TTA`).** `-x` runs the pair as its eight flips and transposes and `-z` both ways in time, and the results are averaged, so a frame made from a to b is the one made from b to a. Neither rife-ncnn-vulkan nor Practical-RIFE has released a model since 2024; the model stays `rife-v4.6`. On the synthetic pairs of `tests/video/test_rife.py`, `-x -z` is the one setting of the four (none, `-x`, `-z`, both) that makes legs crossing far the same both ways with no ghost, and it keeps the most of a short step's outline. On the Mac's GPU it adds a tenth to half a second a frame; on Modal's CPU it costs 15 to 19 times a plain call's CPU — 12 to 30 s a 280 × 520 frame on two cores, 44 to 61 s a 960 × 960 frame. `SPRITE_GEN_RIFE_TTA` names another (`-x`, `-z`, both, or empty for none; anything else is refused before a frame is asked for), for a CPU-only machine that aligns sets. The interpolator a report names (`jump_repair.interpolator`, the alignment's `interpolator`) carries `tta`. A call past 600 s (120 s before) is stopped and reported as a RIFE that failed, where it used to end in Python's own timeout ([loop-repair](docs/loop-repair.md) section 1, "Which setting").- **Tests** — `tests/video/test_rife.py` (every call asks for `-x -z` and never `-g`; `SPRITE_GEN_RIFE_TTA` names either mode, both or none, and anything else is refused; a call past its time is a RIFE that failed; the real-RIFE pairs read with the augmentation: legs crossing far melt the same both ways and leave no ghost, a short step stays outlined, legs walking through each other add no dark where they cross; a refused repair names its faults whole, not by the first of a sorted list), `tests/conftest.py` (every test runs the engine's own augmentation, whatever the calling shell sets).- **New: the flow reading of a walk loop (`repair.flow_scores`, `repair.flow_targets`) — the frames that leave the way a part is going, by direction and speed, not by the size of a step.** Each frame is a point of the loop's path, its coverage and shading blurred by 3 % of the body height, read in nine windows of the union box: how far it lies off the straight line between its neighbours (the second difference, the acceleration), in that window's usual steps. A clip filmed on twos or threes is read on its drawings, the hold `held.measure`'s. `flow_targets` takes the worst frame at or over 3.0 first and names the fewest frames around it — one, then two — whose straight in-between brings every frame it touches under 3.0, never made from a frame taken before; what two cannot bring under is `unfixed`. On the synthetic walks an ordinary loop reads at most 1.65 where the jump score names 8 to 18 steps, and a tail flung 5 % of the body height against its sway reads 2.8 to 4.1. The methods weighed beside it — interpolation error with RIFE, optical flow, a periodic fit, a Kalman predictor, Savitzky–Golay, a Hampel test — and their sources are in docs/loop-repair.md section 2, "The flow reading".diff --git a/docs/loop-repair.md b/docs/loop-repair.mdindex 7ad41af..3a7edbb 100644--- a/docs/loop-repair.md+++ b/docs/loop-repair.md@@ -284,7 +284,8 @@ never tried again in that run, and nothing is made from or beside it. The circuladjacency rule and the call budget hold across the wrap. The shared `interpolation_quality` policyis the same one used by cycle alignment: `dark_excess > 0.001`, or `outline_loss` and`outline_shift` both over 0.05 (an outline lost by the dark line and lighter than the neighbours'-edge rank by rank, section 4), rejects a proposal, and so does a proposal that is a ghost on its own+edge rank by rank, read between outlined neighbours; between neighbours painted without a line,+`outline_loss` alone, section 4), rejects a proposal, and so does a proposal that is a ghost on its owncoverage (`ghost` over 0.003, read where the loop's ghost screen reads it, section 4). An emptyproposal is also rejected. One made frame at fault refuses its whole group. A proposal thatcross-fades two drawings inside its silhouette (`crossfade` over 0.015, section 4) is taken all the@@ -794,14 +795,14 @@ sprite-gen video-cycle-align --loop-dir set/front-walk/loop --loop-dir set/side-counts), the share with no dark solid pixel within 2 px, beyond the less outlinedneighbour's, as a fraction of its edge. Legs that crossed too far for the flow melt into oneshape of fill and lose their outline where they meet the air; a limb left as a ghost has none.- Over 5 % it is the fault `outline` — where `outline_shift` is over 5 % too (below). A step the- flow follows keeps its outline; a figure drawn without outlines loses none against neighbours+ Over 5 % it is the fault `outline` — where `outline_shift` is read, over 5 % too (below). A step+ the flow follows keeps its outline; a figure drawn without outlines loses none against neighboursthat have none, and is not judged by it.- `outline_shift` (`rife.outline_shift`): the same edge read against the neighbours rank by rank —each pixel of the frame's coverage edge by how dark the darkest solid pixel within 2 px of it is,in order, against the lighter neighbour's edge at the same rank, counted where it is lighter by- more than **50/255** (`rife.OUTLINE_SHIFT`), as a fraction of its edge. The fault `outline` needs- both readings over 5 %. The dark line alone reads an art outlined in a mid tone — a brown or a+ more than **50/255** (`rife.OUTLINE_SHIFT`), as a fraction of its edge. Where it is read, the+ fault `outline` needs both readings over 5 %. The dark line alone reads an art outlined in a mid tone — a brown or apainted line whose tone lies about 70/255 — as lost wherever the flow softened it: a line a fewtones lighter falls on the far side of 70/255 all along the figure, and a frame made between twosuch drawings reads as melted however cleanly the flow followed them. Rank by rank the softened line is lighter by less than 50/255@@ -816,7 +817,27 @@ sprite-gen video-cycle-align --loop-dir set/front-walk/loop --loop-dir set/side-softened line takes and the lift of a line gone to fill, and a frame near either is worth a look.What it does not see: a line less than 50/255 darker than the fill it melts into (a dark greyshoe on a mid blue) is no further from its neighbours' than a softened line, and is not read as- lost.+ lost — on art outlined elsewhere; art with no darker line on most of its edge is not read this+ way at all (below).+ It is read only between **outlined** neighbours (`rife.outlined`; `null` otherwise, and the dark+ line judges alone): on each, the line of at least **75 %** (`rife.OUTLINED`) of its coverage+ edge — the darkest solid pixel within 2 px — darker by more than the same 50/255 than its fill,+ its colour from `rife.LINE_DEPTH` inside, pushed out over the edge as the colour around the body+ is pushed out for RIFE (section 1). Art painted without a line has no line to lose: its edge is+ its fill, and a part the flow melts — a boot washed pale, a shin left a ghost — comes out lighter+ by less than 50/255 at every rank where its tones run close together, so read rank by rank it+ would be kept. There the dark line judges alone, as it did before this reading: a frame it+ refuses is replaced by the nearer filmed one, a little less smooth, where a melted frame kept+ would be delivered. On the synthetic walkers of+ `tests/video/test_outline_shift.py`, the two-tone walker and the walker outlined in black read+ outlined on all their edge; the walker painted without a line (skin legs, dark boots, a body of+ one mid tone) reads 4 %, and its drawing between with the near boot washed 40 tones lighter reads+ `outline_loss` 7.8 % and, rank by rank, 0 — refused on the dark line, where the rank reading+ alone kept it. The 75 % is a reference, set on frames made between drawn walks and judged by+ eye: with it, no frame seen as broken that the dark line alone refused is kept.+ `rife.LINE_DEPTH` is twice the bleed's depth (`rife.BLEED_DEPTH`): the walkers of the tests,+ outlined 2 px on a figure 153 px tall, read about half their edge outlined at the bleed's depth,+ whose core still takes the line's inner pixel, and all of it at twice that.The jump repair (section 2) and the alignment read it on every frame they make; the versionedmeasures of `video-loop-compare` and `video-loop-repair` do not, and judge the outline on thedark line alone, as before.diff --git a/sprite_gen/video/align.py b/sprite_gen/video/align.pyindex 8e289c7..4cb474b 100644--- a/sprite_gen/video/align.py+++ b/sprite_gen/video/align.py@@ -738,9 +738,9 @@ def _fault_line(name: str, m: dict[str, Any], ghost: dict[str, Any] | None = Nonother a filmed ghost too (`_ghost_line` names both)."""what = [*([f"has {100 * m['dark_excess']:.2f} % more dark pixels inside the body than either source frame beside it — a smear"]if "smear" in m["faults"] else []),- *([f"lost its outline on {100 * m['outline_loss']:.2f} % of its edge beyond either source frame beside it, "- f"{100 * m['outline_shift']:.2f} % lighter than theirs at the same rank — a melted or ghost limb"]- if "outline" in m["faults"] else []),+ *([f"lost its outline on {100 * m['outline_loss']:.2f} % of its edge beyond either source frame beside it"+ + ("" if m["outline_shift"] is None else f", {100 * m['outline_shift']:.2f} % lighter than theirs at the same rank")+ + " — a melted or ghost limb"] if "outline" in m["faults"] else []),*([f"carries {_ghost_words(m['ghost'])} — a ghost"] if "ghost" in m["faults"] else [])]if m["method"] == "nearest":return (f"{name}: frame {m['at']}: RIFE's frame " + "; ".join(what)diff --git a/sprite_gen/video/interpolation_quality.py b/sprite_gen/video/interpolation_quality.pyindex 6f51fb5..ebff04e 100644--- a/sprite_gen/video/interpolation_quality.py+++ b/sprite_gen/video/interpolation_quality.py@@ -31,13 +31,16 @@ CROSSFADE_LOOK = 0.015def faults(measure: dict[str, float | None]) -> list[str]:"""Smear inside the body or outline loss beyond both neighbours, and a ghost on the frame'sown coverage where the measure carries its reading (`ghost`; None where the screen does not- read the loop, `ghost_screen`). Where the measure also carries `outline_shift` (the frames the- jump repair and the cycle alignment make), an outline is lost only where both readings say so:- a line outlined in a mid tone, which the dark line (`rife.DARK_LUMA`) reads as lost wherever the- flow softened it, is kept unless its edge went lighter than the neighbours' by more than- `rife.OUTLINE_SHIFT` (docs/loop-repair.md section 4). The versioned measures of- `video-loop-compare` and `video-loop-repair` carry `rife.smear` alone and judge as before."""- outline = min(measure["outline_loss"], measure.get("outline_shift", measure["outline_loss"]))+ read the loop, `ghost_screen`). Where the measure also carries an `outline_shift` (the frames the+ jump repair and the cycle alignment make between outlined neighbours, `rife.outlined`), an outline+ is lost only where both readings say so: a line outlined in a mid tone, which the dark line+ (`rife.DARK_LUMA`) reads as lost wherever the flow softened it, is kept unless its edge went+ lighter than the neighbours' by more than `rife.OUTLINE_SHIFT` (docs/loop-repair.md section 4).+ Where it is None (art painted without a line) and in the versioned measures of+ `video-loop-compare` and `video-loop-repair`, which carry `rife.smear` alone, the dark line+ judges alone."""+ shift = measure.get("outline_shift")+ outline = measure["outline_loss"] if shift is None else min(measure["outline_loss"], shift)return ([*(["smear"] if measure["dark_excess"] > SMEAR_WARN else []),*(["outline"] if outline > OUTLINE_WARN else []),*(["ghost"] if (measure.get("ghost") or 0.0) > GHOST_WARN else [])])diff --git a/sprite_gen/video/rife.py b/sprite_gen/video/rife.pyindex 44e85d3..496069a 100644--- a/sprite_gen/video/rife.py+++ b/sprite_gen/video/rife.py@@ -11,10 +11,10 @@ black a frame premultiplied over black put under it (2.24 and before: a black smcrossing legs). Inside the coverage the colour is the frame's own, outline included.`smear` measures what a made frame has that neither neighbour has, and the outline it lost wherethe flow failed and melted a limb into the fill; `outline_shift` reads that edge against the-neighbours' rank by rank, so a mid-tone line the flow only softened is not read as lost; `ghost`-reads a band of part coverage on a frame alone, filmed or made; `crossfade` reads two drawings-cross-faded inside a whole silhouette, a reading to look at, not a fault (docs/loop-repair.md-section 4).+neighbours' rank by rank, so a mid-tone line the flow only softened is not read as lost — where the+neighbours are outlined (`outlined`), and not on art painted without a line; `ghost` reads a band of+part coverage on a frame alone, filmed or made; `crossfade` reads two drawings cross-faded inside a+whole silhouette, a reading to look at, not a fault (docs/loop-repair.md section 4).The binary's own CPU path (`-g -1`) returns a wrong frame with rife-v4.6 on both macOS andLinux (measured 2026-10-03: mean error 39 against 3.3 through Vulkan), so it is never passed;@@ -72,6 +72,15 @@ OUTLINE_REACH = 2# lighter than the lighter neighbour's at the same rank by more than this (luma, 0..1). A line the flow keeps# and softens comes out lighter by less; a line gone to the fill beside it, by the line's own contrast.OUTLINE_SHIFT = 50 / 255+# `outlined`: a frame's fill is read this far inside its solid edge (a share of the body's height, at least a+# pixel) and pushed out over the edge, as `bleed` pushes the colour from BLEED_DEPTH: twice as deep, so the fill+# read beside a line is past it where the line is twice as wide as the one `bleed` reads past.+LINE_DEPTH = 2 * BLEED_DEPTH+# `outline_shift` reads a pair only where both neighbours are outlined on at least this share of their coverage+# edge (`outlined`). Under it — art painted without a line, or lined in a tone near its fill — a line gone to fill+# is lighter by less than OUTLINE_SHIFT, or there is no line to lose, and the dark line judges alone: a frame+# refused there is replaced by a filmed one, a melted frame kept would be delivered (docs/loop-repair.md section 4).+OUTLINED = 0.75# `ghost`: part-covered pixels count where they make a region at least this many pixels thick. An# antialiased edge or a keyed strand of hair is a pixel or two wide and erodes away; the band a video# model leaves between two drawings, or a flow carries from it, does not.@@ -206,20 +215,25 @@ def _push_pull(rgb: np.ndarray, known: np.ndarray) -> np.ndarray:return np.where(known[..., None] > 0, rgb, up)-def bleed(frame: np.ndarray) -> np.ndarray:- """The colour image of an RGBA frame (0..1) RIFE is given: the frame's own colour wherever it- has coverage, and around it the colour from BLEED_DEPTH inside its solid edge, pushed out."""- alpha = frame[..., 3]- solid = alpha >= 0.5+def _core_fill(frame: np.ndarray, depth: float) -> np.ndarray | None:+ """The colour of an RGBA frame (0..1) from `depth` (a share of its solid body's height, at least a pixel)+ inside its solid edge, pushed out over every pixel outside that core; None where nothing is solid."""+ solid = frame[..., 3] >= 0.5rows = np.nonzero(solid.any(axis=1))[0]if rows.size == 0:- return np.where(alpha[..., None] > 0, frame[..., :3], 0.0)- depth = max(1, round((rows[-1] - rows[0] + 1) * BLEED_DEPTH))- core = np.asarray(Image.fromarray(np.uint8(solid) * 255).filter(ImageFilter.MinFilter(2 * depth + 1))) > 0+ return None+ px = max(1, round((rows[-1] - rows[0] + 1) * depth))+ core = _square_min(solid, px, mode="edge") # PIL's MinFilter, which repeats the edge pixels outwardif not core.any(): # a body thinner than its outline: read at its edgecore = solid- fill = _push_pull(frame[..., :3], core.astype(np.float32))- return np.where(alpha[..., None] > 0, frame[..., :3], fill)+ return _push_pull(frame[..., :3], core.astype(np.float32))+++def bleed(frame: np.ndarray) -> np.ndarray:+ """The colour image of an RGBA frame (0..1) RIFE is given: the frame's own colour wherever it+ has coverage, and around it the colour from BLEED_DEPTH inside its solid edge, pushed out."""+ fill = _core_fill(frame, BLEED_DEPTH)+ return np.where(frame[..., 3:] > 0, frame[..., :3], 0.0 if fill is None else fill)def between(a: Image.Image, b: Image.Image, t: float, *, binary: Path, model: Path, tmp: Path) -> Image.Image:@@ -240,13 +254,26 @@ def _mask(mask: np.ndarray, size: int, op: type) -> np.ndarray:return np.asarray(Image.fromarray(np.uint8(mask) * 255).filter(op(size))) > 0+def _square_min(a: np.ndarray, r: int, **pad) -> np.ndarray:+ """Per pixel, the minimum over the square 2r+1 wide around it, one axis at a time, outside the frame as+ `np.pad` fills it with `pad`."""+ out = np.pad(a, r, **pad)+ for axis in (0, 1):+ out = np.lib.stride_tricks.sliding_window_view(out, 2 * r + 1, axis=axis).min(axis=-1)+ return out+++def _luma(x: np.ndarray) -> np.ndarray:+ return x[..., 0] * 0.299 + x[..., 1] * 0.587 + x[..., 2] * 0.114++def _smear_counts(frame: Image.Image) -> tuple[int, int, int, int, int]:"""(dark pixels inside the solid body, one pixel in from its edge; solid pixels; part-coveredpixels; pixels on the coverage's edge; those of them with no outline within OUTLINE_REACH)."""x = np.asarray(frame.convert("RGBA"), dtype=np.float32) / 255.0solid = x[..., 3] >= 0.5inner = _mask(solid, 3, ImageFilter.MinFilter)- luma = x[..., 0] * 0.299 + x[..., 1] * 0.587 + x[..., 2] * 0.114+ luma = _luma(x)lo, hi = PARTIAL_ALPHAcovered = x[..., 3] >= loedge = covered & ~_mask(covered, 3, ImageFilter.MinFilter)@@ -271,28 +298,46 @@ def smear(made: Image.Image, a: Image.Image, b: Image.Image) -> dict[str, float]"outline_loss": round((um - max(ua, ub)) / max(1, em), 5)}-def _edge_darkness(frame: Image.Image) -> np.ndarray:- """Per pixel of the coverage edge (alpha from PARTIAL_ALPHA's floor, as `smear` reads it), the luma of the- darkest solid pixel within OUTLINE_REACH of it, 1 where there is none."""- x = np.asarray(frame.convert("RGBA"), dtype=np.float32) / 255.0+def _edge_line(x: np.ndarray) -> tuple[np.ndarray, np.ndarray]:+ """The coverage edge of an RGBA frame (0..1; alpha from PARTIAL_ALPHA's floor, as `smear` reads it) and, per+ pixel, its line: the luma of the darkest solid pixel within OUTLINE_REACH, 1 where there is none."""covered = x[..., 3] >= PARTIAL_ALPHA[0]edge = covered & ~_mask(covered, 3, ImageFilter.MinFilter)- luma = x[..., 0] * 0.299 + x[..., 1] * 0.587 + x[..., 2] * 0.114- near = np.pad(np.where(x[..., 3] >= 0.5, luma, 1.0), OUTLINE_REACH, constant_values=1.0)- width = 2 * OUTLINE_REACH + 1- for axis in (0, 1): # a square window's minimum, one axis at a time- near = np.lib.stride_tricks.sliding_window_view(near, width, axis=axis).min(axis=-1)- return near[edge]+ return edge, _square_min(np.where(x[..., 3] >= 0.5, _luma(x), 1.0), OUTLINE_REACH, constant_values=1.0)+++def _edge_darkness(frame: Image.Image) -> np.ndarray:+ """Per pixel of the coverage edge, its line (`_edge_line`)."""+ edge, line = _edge_line(np.asarray(frame.convert("RGBA"), dtype=np.float32) / 255.0)+ return line[edge]+++def outlined(frame: Image.Image) -> float:+ """The share of a frame's coverage edge outlined against its fill: where its line, the darkest solid pixel+ within OUTLINE_REACH, is darker than the colour from LINE_DEPTH inside, pushed out over the edge, by more than+ OUTLINE_SHIFT — so a line there gone to that fill reads lost rank by rank (`outline_shift`). Art outlined all+ round reads most of its edge; art painted without a line, whose edge is its fill, or lined in a tone near+ it, little. 0 where it has no edge (docs/loop-repair.md section 4)."""+ x = np.asarray(frame.convert("RGBA"), dtype=np.float32) / 255.0+ edge, line = _edge_line(x)+ fill = _core_fill(x, LINE_DEPTH)+ if fill is None or not edge.any():+ return 0.0+ return round(float(np.mean((_luma(fill) - line)[edge] > OUTLINE_SHIFT)), 5)-def outline_shift(made: Image.Image, a: Image.Image, b: Image.Image) -> float:+def outline_shift(made: Image.Image, a: Image.Image, b: Image.Image) -> float | None:"""The edge of a made frame that lost its line, read against its two neighbours rank by rank: each pixelof its coverage edge by how dark the darkest solid pixel within OUTLINE_REACH is, in order, against thelighter of the two neighbours' edges at the same rank (their quantiles), and counted where it is lighterby more than OUTLINE_SHIFT — as a fraction of its edge. A line drawn in a mid tone and softened by theflow reads lighter by less at every rank and is not counted, whatever tone the art outlines in; a line- gone to the fill beside it (legs melted into one shape, a pale ghost limb) is. 0 where nothing is lighter- (docs/loop-repair.md section 4)."""+ gone to the fill beside it (legs melted into one shape, a pale ghost limb) is. 0 where nothing is lighter.+ None where either neighbour is outlined on less than OUTLINED of its edge (`outlined`): there a part can+ melt with no line to lose, lighter by less at every rank, and the dark line (`smear`'s `outline_loss`)+ judges alone (docs/loop-repair.md section 4)."""+ if min(outlined(a), outlined(b)) < OUTLINED:+ return Nonedm, da, db = (_edge_darkness(f) for f in (made, a, b))if not (dm.size and da.size and db.size):return 0.0diff --git a/tests/video/test_cycle_align.py b/tests/video/test_cycle_align.pyindex d0c0f5e..97425ff 100644--- a/tests/video/test_cycle_align.py+++ b/tests/video/test_cycle_align.py@@ -374,12 +374,10 @@ def test_a_made_frame_darker_than_both_neighbours_is_named_in_the_warnings(tmp_pdef _melt(a: Image.Image, b: Image.Image, t: float) -> Image.Image:"""A stand-in RIFE that lost the dark foot: the frame between drawn whole, its dark grey taken- into a pale fill — the outline around the foot gone, nothing darker added. (Taken into the body's- blue, 42/255 lighter than the grey, it would be no further from the grey than a softened line and- not read as lost, `rife.OUTLINE_SHIFT`.)"""+ into the body's blue — the outline around the foot gone, nothing darker added."""made = np.asarray(Image.blend(a, b, t)).copy()made[..., 3] = np.where(made[..., 3] >= 64, 255, 0)- made[(made[..., 3] > 0) & (made[..., :3].max(axis=-1) < 130)] = (200, 200, 235, 255)+ made[(made[..., 3] > 0) & (made[..., :3].max(axis=-1) < 130)] = (90, 90, 200, 255)return Image.fromarray(made, "RGBA")diff --git a/tests/video/test_outline_shift.py b/tests/video/test_outline_shift.pyindex 3da13cf..9e83112 100644--- a/tests/video/test_outline_shift.py+++ b/tests/video/test_outline_shift.py@@ -3,12 +3,14 @@coverage edge against its two neighbours' at the same rank, and the fault `outline` of the frames the jumprepair and the cycle alignment make needs it over the line as well as `outline_loss`. A line outlined in amid tone, either side of the dark line (70/255), and drawn a little lighter by the flow is kept; a line gone-to the fill is lost, whatever tone the art outlines in. The versioned measures, which carry `rife.smear`-alone, judge the outline on the dark line as before.+to the fill is lost, whatever tone the art outlines in. It is read only where both neighbours are outlined+(`rife.outlined`): art painted without a line is judged on the dark line alone, as the versioned measures,+which carry `rife.smear` alone, judge every frame.The fixtures are synthetic: the walker of tests/video/test_rife.py twice the size, outlined in bands of twobrowns either side of 70/255 (luma 57 and 77), the frame between drawn with its line lighter or its legs'-line turned to fill. The one real-RIFE case runs where RIFE is installed."""+line turned to fill; and the same walker painted without a line, the frame between with a boot washed+lighter. The one real-RIFE case runs where RIFE is installed."""from __future__ import annotations@@ -23,6 +25,7 @@ from tests.video.test_rife import _walkerTONES = ((80, 50, 35), (105, 68, 48)) # luma 57 and 77: the dark line falls between themFAR, NEAR = ((20, -20), (-5, 5)), ((10, -10), (4, -4))+SKIN, BOOT, BODY = (240, 205, 185), (70, 40, 30), (130, 120, 80) # luma 213, 48 and 118, no line between themdef _two_tone(front: float, back: float, *, lift: int = 0, s: int = 2) -> Image.Image:@@ -49,6 +52,24 @@ def _two_tone(front: float, back: float, *, lift: int = 0, s: int = 2) -> Image.return Image.fromarray(x, "RGBA")+def _painted(front: float, back: float, *, wash: int = 0, s: int = 2) -> Image.Image:+ """The walker painted without a line: skin legs swung from the hip, a dark boot over the last third of+ each and a body of one mid tone; the near boot `wash` tones lighter."""+ w, h = 128 * s, 192 * s+ im = Image.new("RGBA", (w, h), (0, 0, 0, 0))+ d = ImageDraw.Draw(im)+ hip, length, r = (w // 2, int(h * 0.55)), int(h * 0.36), int(w * 0.09)+ for angle, lift in ((back, 0), (front, wash)):+ a = np.radians(angle)+ knee, foot = ((hip[0] + k * length * np.sin(a), hip[1] + k * length * np.cos(a)) for k in (0.65, 1.0))+ boot = tuple(min(255, c + lift) for c in BOOT) + (255,)+ d.line([hip, foot], fill=SKIN + (255,), width=2 * r)+ d.line([knee, foot], fill=boot, width=2 * r)+ d.ellipse([foot[0] - r, foot[1] - r, foot[0] + r, foot[1] + r], fill=boot)+ d.ellipse([w * 0.25, h * 0.15, w * 0.75, h * 0.62], fill=BODY + (255,))+ return im++def _legs_to_fill(frame: Image.Image, below: float = 0.57) -> Image.Image:"""`frame` with the line of everything below this share of its height turned to the leg's fill."""x = np.asarray(frame).copy()@@ -79,10 +100,12 @@ def test_a_mid_tone_line_drawn_lighter_is_kept_and_one_gone_to_fill_is_lost():def test_the_versioned_measures_judge_the_outline_on_the_dark_line_alone():"""`rife.smear` alone — what `video-loop-compare` and `video-loop-repair` read — carries no- `outline_shift`, and the lighter line is the fault `outline` there, as before."""+ `outline_shift`, and the lighter line is the fault `outline` there, as before; so is a measure whose+ `outline_shift` was not read (None, neighbours not outlined)."""a, b = (_two_tone(*p) for p in FAR)assert faults(rife.smear(_two_tone(8, -8, lift=20), a, b)) == ["outline"]assert faults({"dark_excess": 0.0, "outline_loss": 0.3, "outline_shift": 0.0}) == []+ assert faults({"dark_excess": 0.0, "outline_loss": 0.3, "outline_shift": None}) == ["outline"]assert faults({"dark_excess": 0.0, "outline_loss": 0.3, "outline_shift": 0.3}) == ["outline"]assert faults({"dark_excess": 0.0, "outline_loss": 0.0, "outline_shift": 0.3}) == []@@ -103,10 +126,10 @@ def test_art_outlined_near_black_reads_the_same_on_both():assert m["outline_loss"] <= 0.01 and m["outline_shift"] == 0-def test_a_frame_with_no_edge_and_neighbours_without_one_read_zero():+def test_a_frame_with_no_edge_reads_zero_and_neighbours_without_one_are_not_read():blank = Image.new("RGBA", (64, 64), (0, 0, 0, 0))a, b = (_two_tone(*p, s=1) for p in FAR)- assert rife.outline_shift(blank, a, b) == 0 and rife.outline_shift(a, blank, blank) == 0+ assert rife.outline_shift(blank, a, b) == 0 and rife.outlined(blank) == 0 and rife.outline_shift(a, blank, blank) is Nonedef test_jump_repair_takes_a_lighter_line_and_refuses_one_gone_to_fill(monkeypatch):@@ -134,6 +157,27 @@ def test_alignment_keeps_a_lighter_line_and_takes_the_nearer_frame_for_one_gone_assert facts["nearest_at"] == [1, 3] and all(m["faults"] == ["outline"] for m in facts["smear"])+def test_a_boot_washed_lighter_on_art_painted_without_a_line_is_refused_on_the_dark_line(monkeypatch):+ """Painted without a line, the walker's edge is its fill, and its neighbours are not outlined: the frame+ between with its near boot washed 40 tones lighter — no further from the boot than a softened line at any+ rank, so read rank by rank nothing is lost — is the dark line's fault `outline`. The jump repair refuses it+ and the alignment takes the nearer frame; the frame between drawn whole is kept. The two-tone and the black+ walker are outlined on all their edge and the painted one on a few % of it."""+ frames = [_painted(20, -20), _painted(30, -30), _painted(-5, 5), _painted(10, -10)]+ washed = _painted(8, -8, wash=40)+ forced_flow_group(monkeypatch, [1], (0, 2), [0.5])+ out, record = repair.repair_jumps(frames, lambda x, y, t: washed)+ assert record["rounds"][0]["outcome"] == "rejected" and record["rounds"][0]["faults"] == ["outline"] and out[1] is frames[1]+ a, b = (_painted(*p) for p in FAR)+ out, facts = align.resample([a, b], 4, lambda x, y, t: washed)+ assert facts["nearest_at"] == [1, 3] and all(m["outline_shift"] is None and m["faults"] == ["outline"] for m in facts["smear"])+ assert faults(_measure(_painted(8, -8), a, b)) == [] and _measure(washed, a, b)["outline_loss"] > OUTLINE_WARN+ with monkeypatch.context() as patched: # read as outlined art, its edge is lighter by less than 50/255 everywhere+ patched.setattr(rife, "OUTLINED", 0.0)+ assert rife.outline_shift(washed, a, b) == 0+ assert max(rife.outlined(a), rife.outlined(b)) < 0.1 and min(rife.outlined(_two_tone(*FAR[0])), rife.outlined(_walker(20, -20))) > 0.99++@pytest.mark.real_rifedef test_real_rife_keeps_a_mid_tone_line_through_a_short_step_and_loses_it_crossing_far():"""Through RIFE, the two-tone legs of a short step come out outlined on the rank reading at every