Generate clean 2D game sprites & animation atlases — component-row pipeline: state rows, alpha cleanup, frame extraction, runtime atlases. Codex/Claude skill.
fix(cycle-align): a frame made between two source frames that leaves a line one of them draws at part strength in its own place, beside the line it drew, gives way to the nearer source frame — rife.doubled reads, where all three frames are solid, the pixels of one source frame's line (its solid pixels darker by more than OUTLINE_SHIFT than its luma closed over DOUBLED_WIDE 0.025 of the body high) that the other draws no line within DOUBLED_SHARED 4 px of and is lighter at by more than OUTLINE_SHIFT, and that the made frame is darker than the other at by more than OUTLINE_SHIFT but by no more than DOUBLED_PART 0.8 of the line's contrast, there and at its darkest within OUTLINE_REACH; opened by DOUBLED_THICK 3 px, pieces within 3 px of each other one run, the longest run's length (sqrt(12) times the root of its larger second moment) over the body height; the fault doubled (interpolation_quality.DOUBLED_WARN 0.03) is the nearer source frame under --between auto and a named frame kept under rife; every smear row records doubled and the warning says it (a double outline); a line both draw, a line carried at its own strength, the soft edge of a line the flow moved, a line left under 50/255, a dark patch wider than the closing, a short run, and clean, soft or source-drawn frames keep their bytes; the jump repair, eased retime, overlapped wrap, video-loop-compare and video-loop-repair do not read it
Soohong Kim104292781b3e
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex f05fce7..66205d9 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -21,6 +21,14 @@ All notable public changes to `sprite-gen` are recorded here. Versions track the- Output changes: an alignment whose made frame has an enclosed hole 5 px thick or more that neither source frame beside it has within 4 px, in place, carried by the whole figure's motion, or paired with one hole of each source frame as above, now delivers the nearer source frame at that cell instead of the made frame, and counts it in `replaced` and `nearest_at` rather than `made_by_rife` and `made_at`. Made frames without such a hole, and frames whose holes the source frames have, in place, carried or paired, are delivered as in 3.1.0 with the same bytes; the report gains `hole` on every made frame. Synthetic numbers (the figure of the tests below): the frame between with a band 8 px wide and 40 px tall through its far leg reads `outline_loss` 0, `outline_shift` 11.3 % (so no `outline` fault, which needs both over 5 %), `ghost` 0, and `hole` 2.69 %; in 3.1.0 it is kept, now the nearer source frame is taken. The frame drawn between, the same with the arm's gap moved 3 px, and the same with a pinhole 3 px wide through the leg read `hole` 0 and are kept. A frame whose hole both source frames have, carried by a part (moving over a body that stays, plain or patterned, turning, growing, sheared or swinging within reach), is delivered as in 3.1.0 with the same bytes. Figure 5: a body that stays, patterned, with a part on it and a hole through the part's middle, the part moved from one source frame to the next, each frame between drawn exactly at its place. (i) The checkpoint validator's frame: a body 200 by 180 px with stripes 3 px wide every 6 px (a lighter colour by 40 levels), on a 260 by 220 px canvas, a part 24 px square with a hole 10 px square, moved 32 px across: the in-place reading leaves the hole whole, 100 pixels or 0.28 % of the body, and the whole figure's motion is 0; it is one hole of each source frame, alike and on its way, so it is paired: `hole` 0, and both made cells are kept as made, byte for byte. (ii) A body 240 by 260 px on a 300 by 300 px canvas in five patterns (stripes 3, 2 and 6 px wide every 6, 4 and 12 px running up and down; stripes 3 px wide every 6 px running across; checks 4 px square) at contrasts 15, 40 and 120, parts 24, 40 and 60 px square with holes 10, 17 and 25 px square: moved 32 and 48 px across and diagonally at t 0.5 (the moves listed in the test), these frames, and the same three parts moved 16, 32 and 48 px across and diagonally at t 0.25 and 0.75 over the 3 px stripes at contrast 40, every one read `hole` 0. Resampled to eight frames (t 0.25, 0.5 and 0.75 each way), parts of 24, 40 and 60 px moved 32 px diagonally and the 24 px part moved 48 px over stripes at contrast 120 keep every made frame, byte for byte. Figure 6: a torso 120 by 260 px that stays, patterned in blocks 4 px square each lighter by its own whole number up to 200 levels, with an arm beside its right edge: the upper arm and the forearm lie along that edge and are joined by the arm's outer side, so the gap between arm and torso, 16 by 12 px, has the torso's edge on its left and the arm on its other three sides; the arm reaches 48 px above and 52 px below the gap and moves 40 px down from one source frame to the next. The gap lies where the arm covers it in the other source frame, so the in-place reading leaves it, and the whole figure's motion is 0; it is one gap of each source frame, alike and on the arm's way, so it is paired: `hole` 0 at t 0.25, 0.5 and 0.75, and resampled to eight every made frame is kept, byte for byte. A frame with a gap only one source frame opens, on a part moving over a body that stays, plain or patterned, which neither the in-place reading nor the whole figure's motion carries and which has no hole in the other source frame to pair with, gives way to the nearer source frame where 3.1.0 kept it. The boundary, pinned by a test: a part 30 px square moving 32 px across a body that stays, a hole 14 px square open through it in one source frame and closed in the other, 8 px square in the frame between (half open): over a plain body and over the 3 px stripes alike it reads `hole` 0.10 % (its 64 pixels) and both made cells are given way to the nearer source frame, with `faults: ["hole"]`. Figure 7: the plate of the tests (a body 240 by 260 px that stays, striped or plain, with a plate on it and a gap through the plate, 11 by 31 px, each frame between drawn exactly at its place). The third checkpoint validator's frame, the plate turning 60 degrees as it moves 48 px over the stripes, reads `hole` 0 and is delivered as in 3.1.0, both made cells byte for byte, resampled to four and to eight; so are the plate turned 90 degrees, grown 2 times and sheared by 0.6 as it moves 48 px, and swung 45 degrees, over the stripes, and 125 such frames read `hole` 0. A frame between with a hole unlike both source frames' (the gap drawn 16 by 40 px: `hole` 1.04 %; drawn 18 by 18 px: 0.52 %; the plate growing 2.2 times as it moves 48 px, the source frames' gaps more than 4 times apart in area: 0.55 %), off its way (the plate drawn 12 px across it: 0.55 %; drawn where it is at t 0.8 in a frame made at t 0.5: 0.30 %), or out of reach (the plate swung 60 degrees, its centre moving 100 px, where 77.5 px is let through on this body: 0.55 %; the plate moving 80 px: 0.55 %) gives way to the nearer source frame with `hole` among its faults. Figure 8: the plate 120 by 40 px with a row of four holes 8 px square, 24 px apart, moving 32 px down: the frame between drawn exactly, and with the row a pixel taller, read `hole` 0 and are delivered as in 3.1.0; with one hole more (midway between two, between the last two, past the end, or one of the row moved to a midway) it reads 0.10 % and gives way to the nearer source frame. Figure 9: on the same striped body, a plate with a row of two, three or four holes 8 px square, 12 px apart, moving on a curved way, int(40 t + 20 t (1 - t)) px across and int(32 t) px down at time t, the plate moving with the holes or staying while they move through it (with two holes it is the fourth checkpoint validator's frame): the frame between drawn exactly reads `hole` 0 and is delivered as in 3.1.0, both made cells byte for byte, for two, three and four holes, the plate moving or staying; with one hole more before the row, or with the row's last hole shut in the second source frame, it reads 0.10 % and gives way to the nearer source frame. Figure 10: on the same striped body, a plate 40 by 90 px with a column of three holes 8 px square, 24 px apart, moving 32 px down, the middle hole shut in the second source frame: the frame between drawn exactly reads `hole` 0 and is delivered as in 3.1.0: its middle hole, one more than the second source frame has, lies against holes of both source frames and the in-place reading takes it for theirs; the last hole pairs with its own two. Figure 11: on the same striped body, a plate 105 px square with a hole 8 px square that the first source frame and the frame between have in place and the second source frame shuts, beside a hole moving 52 px across and 48 px down, drawn at its exact midpoint 10 px from the first (the fifth checkpoint validator's frame): the frame between reads `hole` 0 and is delivered as in 3.1.0, both made cells byte for byte, and so with the hole in place kept by the second source frame instead. Figure 12: a body 200 by 260 px outlined in black on a 400 by 400 px canvas, moving whole, with holes through it; what the reading does not tell: the body moving 32 px down with a row of four holes 8 px square, 24 px apart, and one hole more midway between the middle two reads `hole` 0 and is delivered as in 3.1.0 (so is figure 8's row standing still, drawn a pixel taller, with one hole more midway); moving 48 px across and 48 px down with a gap 5 by 30 px and one gap more 10 px beside it in the frame between, it reads `hole` 0 and gives way for `outline`, as in 3.1.0; with the gap more 11 px beside, and a gap 8 px wide with its twin 13 px beside it, they read `hole` 0.29 % and 0.45 % and give way as in 3.1.0, now with `hole` among their faults besides `outline`. The jump repair of `video-loop`, its eased retime and overlapped wrap, `video-loop-compare`, and `video-loop-repair` do not read `hole`; their measures and outputs are as in 3.1.0. A `--between-cache` directory written by 3.1.0 is not taken from by this version: the code of `rife.py` is part of what a kept frame is keyed by, so those frames are made again.- **Tests**: new `tests/video/test_inbetween_hole.py`, synthetic only: figure 1 (a 160 by 200 px figure of rectangles outlined in black, legs filled darker than 70/255, the near leg drawn over the far one, an arm joined to the body above and below with an 8 px gap between them in every frame; one source frame with its legs side by side, the other with a gap between them) checks that the band through the far leg reads as a hole over exactly its own 320 pixels as a share of the solid body, and the drawn frame, the arm's gap, that gap moved 3 px, a 3 px pinhole and an empty frame read 0; that the readings before this one pass the band (`outline_loss` 0, `outline_shift` over 5 %, `dark_excess` below 0, `ghost` 0, `partial_excess` 0, no fault) and that with `hole` the fault is `["hole"]`; that resampling the two frames to four under `--between auto` takes the nearer source frame at both made cells (cells 1 and 3) with the fault named in the warning words, while `--between rife` keeps them named; and that the clean frame and the frame with the moved arm gap are delivered as the very frame made. Figure 2 (a body 120 by 180 px of one colour with a gap 8 by 40 px through it, on a 240 by 220 px canvas, moved whole from one source frame to the next by 0, 4, 8, 12, 24 and 32 px, across and diagonally) checks that at every move it is resampled to four with both made cells delivered as the very frame made, no fault, and reads `hole` 0, each source frame moved half the way giving the frame between byte for byte. Figure 3 (a body 90 px wide over two legs 24 px wide, each standing in a boot that reaches under the other leg, so a gap a step opens between the legs is closed by the boots below; in one source frame the legs touch, in the other they are parted), still and moving 30 px between source frames, is kept the same way and reads 0; and moving with an 8 by 40 px band through its body, it reads exactly its 320 pixels as a share of the solid body, in either order of the source frames, with both made cells given way to the nearer source frame and `hole` among their faults. Figure 4 (a body 200 by 180 px of one colour that stays, with a part on it 40 px square and a hole 14 px square through the part, the part moving 32 px from one source frame to the next) is kept the same way and reads 0. Figure 5 (a body that stays, patterned, with a part on it and a hole through the part's middle, the part moved from one source frame to the next, each frame between drawn exactly at its place: the checkpoint validator's frame with a body 200 by 180 px with stripes 3 px wide every 6 px, a lighter colour by 40 levels, on a 260 by 220 px canvas, a part 24 px square with a hole 10 px square, moved 32 px across; and a body 240 by 260 px on a 300 by 300 px canvas in five patterns, stripes 3, 2 and 6 px wide every 6, 4 and 12 px running up and down, stripes 3 px wide every 6 px running across, and checks 4 px square, at contrasts 15, 40 and 120, parts 24, 40 and 60 px square with holes 10, 17 and 25 px square): figure 5's validator frame resampled to four, and its parts of 24, 40 and 60 px moved 32 px diagonally and the 24 px part moved 48 px over stripes at contrast 120 resampled to eight, keep every made frame as made; the wide grid of figure 5 (every pattern and contrast at each listed move at t 0.5, and the three parts moved 16, 32 and 48 px at t 0.25 and 0.75) reads `hole` 0 and is marked slow, so it runs with `pytest --full`. Figure 6 (a torso 120 by 260 px that stays, patterned in blocks 4 px square each lighter by its own whole number up to 200 levels, with an arm beside its right edge: the upper arm and the forearm lie along that edge and are joined by the arm's outer side, so the gap between arm and torso, 16 by 12 px, has the torso's edge on its left and the arm on its other three sides; the arm reaches 48 px above and 52 px below the gap and moves 40 px down from one source frame to the next) reads `hole` 0 at t 0.25, 0.5 and 0.75 and keeps every made frame resampled to eight. The boundary test (a part 30 px square moving 32 px across a body that stays, a hole 14 px square open through it in one source frame and closed in the other, 8 px square in the frame between) checks that the half-open gap on the moving part, over a plain body and over the stripes, reads its 64 pixels as a share of the body and gives both made cells way to the nearer source frame with `faults: ["hole"]`. Figure 7: a body 240 by 260 px on a 300 by 300 px canvas that stays, in stripes 3 px wide every 6 px (lighter by 40 levels) or plain, with a plate on it (|u| < 24 and |v| < 28 px in its own axes) and a gap through the plate (|u| < 6, |v| < 16), each frame between drawn exactly at its place in one motion: the plate's centre moving across as the plate turns, grows or is sheared about it, or the plate swinging from a point 100 px above its centre. One test checks that the third checkpoint validator's frame (the plate turning 60 degrees as it moves 48 px over the stripes), resampled to four, keeps both made frames as made, and resampled to eight (t 0.25, 0.5 and 0.75 each way) every one; that the plate turned 90 degrees, grown 2 times and sheared by 0.6 as it moves 48 px, and swung 45 degrees, resampled to four over the stripes, keep both made frames; and that over the plain body each of these reads `hole` 0. A test marked slow (it runs with `pytest --full`) checks that 125 frames read `hole` 0: the plate turned 0 to 90 degrees, grown 1.1 to 2 times or sheared by 0.15 to 0.6 as it moves 0, 24 or 48 px, or swung 10 to 45 degrees, over both bodies at t 0.5, and turned as it moves over the stripes at t 0.25. A boundary test checks that, on the plate over either body, a frame between with its gap drawn 16 by 40 px or 18 by 18 px, with the plate drawn 12 px across its way or where it is at t 0.8 in a frame made at t 0.5, with the plate growing 2.2 times as it moves 48 px (the source frames' gaps more than 4 times apart in area), with the plate moving 80 px, and with the plate swung 60 degrees, gives both made cells way to the nearer source frame with `hole` among their faults. Figure 8: the same body with a plate 120 by 40 px on it and a row of four holes 8 px square, 24 px apart, through the plate. Its test checks that, the plate moving 32 px down over either body, the frame between drawn exactly and the same with the row a pixel taller keep both made frames as made; that with one hole more midway between two of the row's, between the last two, past the row's end, or with one of the row's moved 12 px to a midway, both made cells give way to the nearer source frame with `hole` among their faults; and that, the plate standing still, the row drawn a pixel taller keeps both made frames. Figure 9: the striped body (240 by 260 px that stays, stripes 3 px wide every 6 px) with a plate on it and a row of two, three or four holes 8 px square, 12 px apart, through the plate, moving on a curved way from one source frame to the next, int(40 t + 20 t (1 - t)) px across and int(32 t) px down at time t; the plate moves with the holes or stays while they move through it. With two holes it is the fourth checkpoint validator's frame. One test checks that, resampled to four, the frame between drawn exactly keeps both made frames as made, for two, three and four holes, the plate moving or staying. Figure 10: the same striped body with a plate 40 by 90 px on it and a column of three holes 8 px square, 24 px apart, through the plate, the plate moving 32 px down from one source frame to the next. A boundary test checks that, with two and four holes, the plate moving or staying, a frame between with one hole more before the row, and a frame between whose second source frame has the row's last hole shut, give both made cells way to the nearer source frame with `hole` among their faults; and that with `rife.HOLE_PAIR_STEPS` set to one step, both searches (the search for a set pairing every hole, and the search for the set pairing the most) run past it and the frame between of two holes gives both made cells way as well. Figure 11: the striped body with a plate 105 px square on it, through it a hole 8 px square that the first source frame and the frame between have in place and the second source frame shuts, beside a hole moving 52 px across and 48 px down, drawn at its exact midpoint 10 px from the first; the fifth checkpoint validator's frame. Its test checks that, resampled to four, both made frames are kept as made, and so with the hole in place kept by the second source frame instead. Figure 12: a body 200 by 260 px outlined in black on a 400 by 400 px canvas, moving whole, with holes through it. Its test pins what the reading does not tell: it checks that the body moving 32 px down with a row of four holes 8 px square, 24 px apart, and one hole more midway between the middle two keeps both made frames as made, and so do figure 8's row standing still, drawn a pixel taller, with one hole more midway, and figure 10's frame with the middle hole shut in the second source frame; that, the body moving 48 px across and 48 px down with a gap 5 by 30 px, one gap more 10 px beside it in the frame between reads `hole` 0 from either source frame to the other; and that the gap more 11 px beside, and a gap 8 px wide with its twin 13 px beside it, give both made cells way with `hole` among their faults. The test on triples alone: twenty alike holes, each with its own two holes and up to five more pairs near its own at seeded random costs. It checks that all twenty are paired, and that none is where the search for a set pairing every hole runs past the steps (the search for the set pairing the most runs past them on this group).+**Upgrading from 3.1.0: `video-cycle-align` now gives way to the nearer source frame on made frames with double outlines under `--between auto`, changing only alignment outputs with such outlines while made frames without them and all outputs from `video-loop`, `video-loop-compare`, and `video-loop-repair` keep their bytes.**++- **New: `video-cycle-align` now reads a new `doubled` fault on frames RIFE makes between source frames and gives way to the nearer source frame.** On every frame RIFE makes between two source frames, `video-cycle-align` reads a new fault, `doubled` ("a double outline"). Under `--between auto` (the default) a made frame with this fault gives way to the nearer source frame; under `--between rife` the frame is kept and named. `video-set --align-cycles auto` runs the same alignment. Where RIFE's flow does not follow a line (the top of a boot one source frame tilts and the other plants), it can fade the line out in place instead of moving it, and the made frame shows that source frame's line, lighter, in its own place, beside the line the frame drew: a double outline. Its coverage is whole (no `ghost`), nothing darker is added (no `smear`), the line is inside the body and the edge keeps its line (no `outline`), and there is no hole; the cross-fade reading (`crossfade`) only names frames to look at. So such a frame passed every fault and was delivered. The reading `rife.doubled(made, a, b)`: a frame's line is its solid pixels darker by more than 50/255 than its own luma closed by a square 2.5 % of the made frame's body height wide (`rife.DOUBLED_WIDE`, 0.025; a stroke narrower than that is a line, a dark fill wider is not). A pixel of one source frame's line is left at part strength where the three frames are solid, the other source frame draws no line within 4 px (`rife.DOUBLED_SHARED`, 4) and is lighter there by more than 50/255, and the made frame is darker than the other by more than 50/255 (still seen) but by no more than 0.8 of the line's contrast (`rife.DOUBLED_PART`, 0.8), there and at its darkest pixel within 2 px (no line at full strength beside it). Such pixels count in regions 3 px thick (`rife.DOUBLED_THICK`, 3); widened by 3 px, those that touch make one run; the reading is the longest run's length (sqrt(12) times the root of its pixels' larger second moment) over the made frame's body height. The fault `doubled` is a reading over 0.03 (`interpolation_quality.DOUBLED_WARN`). Kept as the source frames' own: a line both draw within 4 px of each other, at any strength; a line carried at more than 0.8 of its contrast (the source frame's own drawing); the soft edge of a line the flow moved (the full line lies within 2 px); a line left less than 50/255 darker than the other source frame there (not seen); a dark patch wider than the closing; a run of 3 % of the body or less. A line only one source frame draws (a crease that comes or goes), left at part strength, is a double outline too.+- Report fields: each row of a loop's `smear` list in the `video-cycle-align` report (and in `cycle_align` in `strip.json`) gains `doubled`. A frame given way for it carries `"doubled"` in `faults` and `method: "nearest"`, and gets a line in `warnings` with these words: "left a line one source frame beside it draws at part strength in its own place, over a run 10.21 % of its body high, a double outline, so the nearer source frame was taken there (--between auto)". The `--between` help names it.+- Python callers: new `rife.doubled(made, a, b)`, `rife.DOUBLED_WIDE` (0.025), `rife.DOUBLED_SHARED` (4), `rife.DOUBLED_PART` (0.8), `rife.DOUBLED_THICK` (3); new `interpolation_quality.DOUBLED_WARN` (0.03); `interpolation_quality.faults(measure)` returns `"doubled"` where the measure carries a `doubled` reading over `DOUBLED_WARN`, and measures without a `doubled` key are judged as before.+- Output changes: an alignment whose made frame shows a double outline over 3 % of its body height now delivers the nearer source frame at that cell instead, counted in `replaced` and `nearest_at` rather than `made_by_rife` and `made_at`. Other made frames are delivered as before with the same bytes; the report gains `doubled` on every made frame. A frame RIFE cross-fades so that both drawings' lines stay at part strength inside the silhouette over a long enough run now gives way too, still named to look at for its cross-fade (`look`); such frames were kept before because the cross-fade reading is no fault (it also reads over its line on a clean drawing between far-apart drawings, which reads no double outline and is kept). Synthetic numbers (the figure of the tests): a coat over two legs in boots outlined 3 px in near-black, the near boot lifted 18 px in one source frame and planted in the other; the frame drawn between with the first source frame's near-boot lines laid over it at 0.45 of their strength reads `outline_loss` 0, `outline_shift` 0, `ghost` 0, `hole` 0, `crossfade` 0 and `doubled` 0.102; in 3.1.0 it is kept, now the nearer source frame is taken. The frame drawn between, blurred, or smeared along the step, a hand moving 60 px over the coat, boots drawn with a second line, a hem drawn with two lines and softened, and a light crease carried at its own strength read `doubled` 0 and are kept. The jump repair of `video-loop`, its eased retime and overlapped wrap, `video-loop-compare`, and `video-loop-repair` do not read `doubled`; their measures and outputs are as before. A `--between-cache` directory written before this version is not taken from: the code of `rife.py` is part of what a kept frame is keyed by, so those frames are made again.+- **Tests**: new `tests/video/test_inbetween_doubled.py`, synthetic only: the figure above; checks that the line left at 0.45 passes every earlier reading and reads `doubled` 0.102, as do both source frames' lines left at half and the colour blended inside the drawing's coverage; that resampling two frames to four under `--between auto` takes the nearer source frame at both made cells with the fault in the warning's words, while `--between rife` keeps them named; that a crease only one source frame draws, left at 0.3 to 0.6, gives way, left at 0.25 reads 0, and the frames that draw it or not keep their bytes; that nine clean, soft or source-drawn frames read 0 and are delivered as the very frame made; that the walker of `tests/video/test_crossfade.py` keeps its drawing between far-apart legs (16 to 3 degrees) in grey and black outlines, reading 0, while its cross-fade gives way, and its 10 to 5 degree cross-fade reads 0.0195 and is kept; and where each bound turns (seen at 0.30 of the line's contrast, not at 0.28; part strength up to 0.80, not 0.82; a boot moved 9 px, not 8; a stroke 3 px wide, not a patch 10 px square; a run over 7 columns, 0.0343, not 6, 0.0294), and that a hand smeared back over a source frame's line reads as that line left (0.063). `tests/video/test_crossfade.py`: the alignment test of the cross-fading stand-in now expects its frames across the legs' long steps to give way under `auto` as double outlines, still named to look at, and to be kept and named to look at under `--between rife`; its 10 to 5 degree cross-fade under `auto` is kept with `doubled` under the line.+## v3.1.0 - Walk and run loop gates for held animation and seam pops, size hold for fixed cuts, talking face layer and default chroma decontamination**Upgrading from 3.0.0: Fixed walk or run cuts and clips whose feet climb or sink now hold size and feet before cutting, changing bytes when size changes by 1 % or more.** Application scan numbers change for held clips, and held fixed cuts are not restored by `video-loop-repair`. Loops cut with `--size-hold off`, clips changing size by under 1 %, held `motion-auto` cuts on one row, and non-walk cuts keep their bytes. The report records `size_hold` on fixed walk or run cuts, `size_hold.feet` when size is held, `size_hold.anchor_regions` under `--anchor motion`, and `size_hold.at_cut` on fixed cuts; `producer` names the new version.diff --git a/docs/loop-repair.md b/docs/loop-repair.mdindex 95efab6..a4f1d04 100644--- a/docs/loop-repair.md+++ b/docs/loop-repair.md@@ -1280,11 +1280,12 @@ sprite-gen video-cycle-align --loop-dir set/front-walk/loop --loop-dir set/side-`--align-between`. `auto` runs RIFE for every frame between two source frames, as `rife` does,and needs it installed the same way.- **Smear and melt, per made frame**: `cycle_align.smear` lists every frame RIFE made, with its- `method` — `rife` (kept) or `nearest` (a source frame beside it taken instead) — its `faults`,- its own ghost reading (`ghost`, below; `null` where the screen does not read the loop), its- cross-fade reading and what to `look` at (`crossfade`, below — named, never judged), the holes- it opened inside its silhouette that neither source frame has there (`hole`, below), and what- it has that neither source frame beside it has (`rife.smear`):+ `method` — `rife` (kept) or `nearest` (a source frame beside it taken instead) — its `faults`, its+ own ghost reading (`ghost`, below; `null` where the screen does not read the loop), its cross-fade+ reading and what to `look` at (`crossfade`, below — named, never judged), the holes it opened+ inside its silhouette that neither source frame has there (`hole`, below), the line one source+ frame draws that runs at part strength in its own place in the made frame as a double outline+ (`doubled`, below), and what it has that neither source frame beside it has (`rife.smear`):- `dark_excess`: dark pixels (luma under 70/255) inside the body beyond the darker neighbour'scount, as a fraction of its solid pixels — a black smear raises it, a dark part that onlymoved (a hat, a watch) does not. Over 0.1 % it is the fault `smear`.@@ -1432,7 +1433,18 @@ sprite-gen video-cycle-align --loop-dir set/front-walk/loop --loop-dir set/side-- Over **0.015** (`interpolation_quality.CROSSFADE_LOOK`) the frame is named to look at: its`smear` row's `look` is `["crossfade"]`, and a kept frame (`method: rife`) gets a line in`warnings` ("frame 14 (made by RIFE) may cross-fade two drawings inside its outline …; kept").- It is no fault: `auto` keeps it, it gives nothing way, and the retake rule does not count it.+ It is no fault: `auto` keeps it, it gives nothing way, and the retake rule does not count it. A+ cross-fade that leaves the two drawings' lines at part strength inside the silhouette over a+ long enough run is now a double outline (`doubled`, the bullet below), a fault of its own, and+ gives way for that; the cross-fade reading still only names it. Before the double outline was+ read, the alignment kept such frames because the cross-fade reading is no fault, for the reason+ in the next sub-bullet, which is about that reading and still holds; it was never a choice to+ keep frames with doubled lines. The clean drawing between far-apart drawings, which the+ cross-fade reading reads over its line, reads no double outline (0 in grey and in black+ outlines) and is kept; separately, on the synthetic legs of `tests/video/test_crossfade.py`, the+ frames a RIFE stand-in cross-fades across the legs' long steps (its colour run blends, its+ coverage run is the union) now give way under `auto`, each still named to look at; under `rife`+ they are kept and named.- Why a reading and not a fault: checked against frames labelled by eye, it does not part them.On drawn walks the frame seen cross-faded read well over the line and the frames seen cleanunder it; on synthetic legs (the walker of `tests/video/test_crossfade.py`, its palette varied@@ -1782,6 +1794,103 @@ sprite-gen video-cycle-align --loop-dir set/front-walk/loop --loop-dir set/side-runs past 5000 steps and would pair none, whereas the search for a set pairing every hole findsone in 29 steps, pairing all twenty; where that search too runs past the steps, the otheranswers, and here pairs none.+- **A double outline, per made frame** (`rife.doubled`): Where RIFE's flow does not follow a line+ (on drawn art, the top of a boot that one source frame tilts, showing the oval of its opening, and+ the other plants flat, showing a straight band), it can fade the line out in place instead of+ moving it. The made frame then shows that source frame's line, lighter, in the source frame's own+ place, beside the line the made frame drew: a double outline. Its coverage is whole, so the ghost+ screen (part coverage, alpha 0.1 to 0.9, in regions **5 px** thick) reads nothing; the faded line+ is lighter than 70/255, so the dark count (`dark_excess`) adds nothing; the line is inside the+ body, not on the coverage edge, so both outline readings (`outline_loss`, `outline_shift`, which+ read the coverage edge) pass it; it has no enclosed transparent pixels, so `hole` reads 0. The+ cross-fade reading names whole drawings blended where the made frame keeps under 60 % of the+ source frames' strong edges in a window; a frame that moved most of a part and left one line faded+ keeps its edges, and the cross-fade reading is a reading to look at, never a fault, in any case.+ - `doubled`: `rife.doubled(made, a, b)` takes the made frame between source frame a and source+ frame b, with no fraction needed. A frame's line is its solid pixels (alpha 0.5 and over) darker+ by more than 50/255 (`rife.OUTLINE_SHIFT`, the same contrast the rank outline reading uses) than+ its own luma closed by a square 2.5 % of the made frame's body height wide (`rife.DOUBLED_WIDE`,+ 0.025; off the solid body the luma counts as white). A dark stroke narrower than that window+ goes in the closing and is a line; a dark fill wider than it stays and is no line. A pixel of+ one source frame's line is left at part strength in the made frame when all of these hold: the+ three frames are solid there; the other source frame draws no line within **4 px** of it+ (`rife.DOUBLED_SHARED`, 4, a square neighbourhood): a line both draw is theirs at any strength;+ the other source frame is lighter there than this line by more than 50/255; the made frame is+ darker there than the other source frame by more than 50/255 (the line is still seen); and the+ made frame is darker than the other by no more than 0.8 of the line's contrast (the line's+ contrast is how much lighter the other source frame is than the line there; `rife.DOUBLED_PART`,+ 0.8), both at the pixel and at its darkest pixel within **2 px** (`rife.OUTLINE_REACH`, 2): no+ line at full strength beside it, as there is beside the soft edge of a line the flow moved. Such+ pixels count where they make a region **3 px** thick (opened by a 3 px square,+ `rife.DOUBLED_THICK`, 3). Widened by **3 px**, those that touch make one run. A run's length is+ sqrt(12) times the square root of the larger second moment of its pixels, which is a straight+ run's own length. The reading is the longest run's length as a share of the made frame's body+ height: 0 where the made frame has no solid body, or where the two source frames nowhere differ+ by more than 50/255 inside all three bodies. It is read inside the box round where the source+ frames differ, padded so that every pixel there reads as in the whole frame.+ - Over **0.03** (`interpolation_quality.DOUBLED_WARN`, 0.03 of the body's height) the frame shows+ a double outline: the fault `doubled`. `auto` takes the nearer source frame there and writes a+ line in `warnings`; the line says the made frame left a line one source frame beside it draws at+ part strength in its own place, over a run of the given share of its body high, a double+ outline, and that the nearer source frame was taken there (`--between auto`). `rife` keeps it,+ named. The report's `smear` rows carry `doubled` on every made frame.+ - What is the source frames' own, kept (each a named bound): a line both source frames draw within+ **4 px** of each other is theirs, at any strength in the made frame (a static line the flow+ softened, a hem both draw with two lines); a line the made frame carries at more than 0.8 of its+ contrast is that source frame's own drawing there (a light crease one source frame draws,+ carried at its own strength, is kept); the soft edge of a line the flow moved lies within **2+ px** of the line at full strength, so it is not read; a line left less than 50/255 darker than+ what the other source frame shows there is not seen and not read; a dark patch wider than the+ closing window is no line; a run 3 % of the body high or shorter is not a fault; and only pixels+ where all three frames are solid are read, as part coverage is the ghost screen's.+ - A line only one source frame draws, with no line of the other's within **4 px** (a crease that+ comes or goes, an eyelid's line, a line a passing leg covers or uncovers), left at part+ strength, is read the same way and is a double outline: the flow did not follow it and faded it.+ This is a fault by the definition, not an exception. What the reading does not tell: a part the+ made frame draws smeared along its way, where the smear reaches back over a line one source+ frame draws there at part strength, reads as that line left. And lines left where one source+ frame is not solid (on the silhouette's edge) are not read, so a cross-fade whose doubled lines+ lie mostly on the silhouette's edge can read under the line.+ - Where **0.03** sits: set by eye on drawn walks, between the frames seen with a line doubled (a+ boot's top faded out where one source frame tilts it, beside the top the frame drew), which read+ over it, and the frames seen as clean or only soft, which read under it. It is a reference, not+ a measured optimum, and a frame near it is worth a look.+ - Read only on the frames the alignment makes (`doubled` in each `smear` row). The jump repair of+ `video-loop`, its eased retime and overlapped wrap (section 2) do not read it, and neither do+ the versioned measures of `video-loop-compare` and `video-loop-repair`.+ - Synthetic numbers (`tests/video/test_inbetween_doubled.py`): a figure on a 200 by 260 px canvas,+ a coat over two legs in boots, outlined **3 px** in near-black, a hand beside the coat; the near+ boot lifted 18 px in the first source frame and planted in the second. The boot's line is 0.69+ darker than the boot's fill. The frame drawn between, with the first source frame's near-boot+ lines laid over it at 0.45 of their strength: `outline_loss` 0, `outline_shift` 0, `ghost` 0,+ `hole` 0, `crossfade` 0, no fault before; `doubled` 0.102 (the run's own length is the boot's+ width). Resampled from two frames to four under `auto`, both made cells (1 and 3) take the+ nearer source frame; under `rife` they are kept, named. The same with both source frames' lines+ at half, and the frame whose colour is the plain blend of the two inside the drawing's coverage,+ read over the line too. A crease the first source frame draws across the still near boot and the+ second does not: left at 0.3, 0.45 or 0.6 of its contrast it reads `doubled` and gives way; left+ at 0.25 it is lighter than 50/255 under the boot and reads 0; the frame that draws it, and the+ frame that does not, read 0 and keep their bytes. Read 0 and delivered as the very frame made:+ the drawing between; the same blurred (radius 1.5 px) or smeared along the step; a hand moving+ 60 px over the coat, drawn, blurred or smeared along its way (t 0.35 to 0.65); boots both source+ frames draw with a second line; a hem both draw with two lines, softened to 60 % in the frame+ between; a light crease one source frame draws, carried at its own strength. The bounds, where+ each turns: left at 0.28 of its contrast the made frame there is 0.1960 darker than the boot,+ just under 50/255, which is 0.1961, and reads 0; at 0.30 it is 0.2076 darker and is read; at+ 0.80 it reads, at 0.82 it is the source frame's own line and reads 0; with the boot moved 8 px,+ the pixels of its old line that the reading keeps are too thin to hold a 3 px square, so the+ opening by 3 px removes them and it reads 0; moved 9 px they hold one and it reads (0.092); a+ dark patch 10 px square one source frame draws is no line, a stroke **3 px** wide is; left over+ 6 columns the run is 0.0294 of the body, under the line, over 7 columns 0.0343, over it. What it+ does not tell: the hand smeared along its way from t 0.3 to 0.7 of its 60 px move reaches back+ over the line the first source frame draws there and reads 0.063. The walker of+ `tests/video/test_crossfade.py`, legs closing from 16 to 3 degrees: its drawing between, which+ the cross-fade reading reads over its line in grey (the reason that reading is no fault), reads+ `doubled` 0 in grey and in black outlines and keeps its bytes; its colour blended inside the+ drawing's coverage reads 0.098 in grey and 0.37 in black and gives way. Legs closing from 10 to+ 5 degrees, the cross-fade's lines left inside all three silhouettes run 0.0195 of the body (the+ rest of its doubled edge lies on the silhouette, where one source frame is not solid): under the+ line, kept.- **What `auto` costs**: a frame replaced shows the nearer source frame, so the motion theresteps as filmed, up to half a frame off its time, and the loop shows fewer distinct drawings asecond than `rife` — but no melted one. A clip drawn on twos has a long step between drawingsdiff --git a/sprite_gen/video/align.py b/sprite_gen/video/align.pyindex 4e2b8f5..f6ace97 100644--- a/sprite_gen/video/align.py+++ b/sprite_gen/video/align.py@@ -7,7 +7,8 @@ to be the same number of frames and to start on the same step. So every loop ofresampled to the set's median length L*: frame k of the new loop is the source loop at timek·L/L* (cyclic, offset 0), so a time that lands on a source frame takes that frame as filmedand only the times between two frames are made by RIFE — each kept unless it smeared, lost its-outline, carries a ghost or opened a hole through a limb that neither source frame beside it has,+outline, carries a ghost, opened a hole through a limb that neither source frame beside it has or+shows a double outline (a line one of them draws, left at part strength in its own place),where the nearer source frame is taken instead (`--between auto`, thedefault; `rife` keeps every made frame and warns, `nearest` makes none); a made frame kept thatcross-fades two drawings inside its silhouette is named to look at. Every frame delivered,@@ -240,7 +241,8 @@ def resample(frames: list[Image.Image], length: int, interpolate: rife_mod.InterA time between two source frames is made by `interpolate`, with what it added and the outline itlost measured (`rife.smear`), its own ghost read (`rife.ghost`), the holes it opened inside itssilhouette that neither source frame has there, in place, carried by the whole figure's motion, or- one hole of each source frame, alike and on its way (`rife.hole`), and judged (`faults`); `between`+ one hole of each source frame, alike and on its way (`rife.hole`), how far a line one source frame+ draws runs at part strength in its own place (`rife.doubled`), and judged (`faults`); `between`auto keeps a made frame with no fault and takes the nearer source frame where it has one, rifekeeps every made frame, nearest makes none and takes the nearer source frame (the motion keeps thefilmed frames at up to half a frame off their time). Every made frame is listed in `smear` with@@ -296,7 +298,8 @@ def resample(frames: list[Image.Image], length: int, interpolate: rife_mod.Intermade = interpolate(a, b, frac)measure = {**rife_mod.smear(made, a, b), "outline_shift": rife_mod.outline_shift(made, a, b),"ghost": rife_mod.ghost(made) if screen["reads"] else None,- "crossfade": rife_mod.crossfade(made, a, b, frac), "hole": rife_mod.hole(made, a, b, frac)}+ "crossfade": rife_mod.crossfade(made, a, b, frac), "hole": rife_mod.hole(made, a, b, frac),+ "doubled": rife_mod.doubled(made, a, b)}wrong = faults(measure)keep = between == "rife" or not wrongtaken = ({"between": [i % count, (i + 1) % count], "t": round(frac, 4)} if keep@@ -753,7 +756,9 @@ def _fault_line(name: str, m: dict[str, Any], ghost: dict[str, Any] | None = Non*([f"carries {_ghost_words(m['ghost'])} — a ghost"] if "ghost" in m["faults"] else []),*([f"opened a transparent hole inside its outline over {100 * m['hole']:.2f} % of its body, at least "f"{rife_mod.HOLE_THICK} px thick, where neither source frame beside it has one — a gap through a limb"]- if "hole" in m["faults"] else [])]+ if "hole" in m["faults"] else []),+ *([f"left a line one source frame beside it draws at part strength in its own place, over a run {100 * m['doubled']:.2f} % "+ "of its body high — a double outline"] if "doubled" in m["faults"] else [])]if m["method"] == "nearest":return (f"{name}: frame {m['at']}: RIFE's frame " + "; ".join(what)+ (", so the nearer source frame was taken there (--between auto)" if ghost is None else@@ -1029,8 +1034,9 @@ def add_arguments(parser: argparse.ArgumentParser) -> None:"its gait floor is the shortest cycle the screen looks for")parser.add_argument("--between", choices=BETWEEN, default=DEFAULT_BETWEEN,help="a time between two source frames: auto (default) makes that frame with RIFE and keeps it unless it smeared, "- "lost its outline (a melted limb), carries a ghost (a part-covered band) or opened a hole through a limb "- "(a transparent gap inside its outline neither source frame beside it has), where the nearer source frame is "+ "lost its outline (a melted limb), carries a ghost (a part-covered band), opened a hole through a limb "+ "(a transparent gap inside its outline neither source frame beside it has) or shows a double outline (a line "+ "one source frame beside it draws, left at part strength in its own place), where the nearer source frame is ""taken and named in the warnings; rife keeps every made frame and warns on those; nearest takes the nearer ""source frame — nothing made, no RIFE needed, the motion up to half a frame off its time. Every made frame is ""measured in the report (`smear`); under auto and nearest a filmed ghost frame gives way to a clean source "diff --git a/sprite_gen/video/interpolation_quality.py b/sprite_gen/video/interpolation_quality.pyindex 79ba7f0..43c7929 100644--- a/sprite_gen/video/interpolation_quality.py+++ b/sprite_gen/video/interpolation_quality.py@@ -1,11 +1,12 @@# SPDX-License-Identifier: Apache-2.0"""The shared acceptance policy for the frames repair and cycle alignment deliver.-Measurements live in ``rife`` (``smear``, ``outline_shift``, ``ghost``, ``crossfade``, ``torn``, ``hole``); these are the-existing alignment bounds, also applied before replacing a filmed middle frame during jump repair, the ghost screen-every frame a loop path delivers passes, filmed or made, the clean frame a filmed ghost gives way+Measurements live in ``rife`` (``smear``, ``outline_shift``, ``ghost``, ``crossfade``, ``torn``, ``hole``, ``doubled``);+these are the existing alignment bounds, also applied before replacing a filmed middle frame during jump repair, the ghost+screen every frame a loop path delivers passes, filmed or made, the clean frame a filmed ghost gives wayto, and the cross-fade a made frame is named for, kept; the torn part a frame of the overlapped wrap-is refused for; and the hole through a limb a frame the alignment makes gives way for (docs/loop-repair.md section 4).+is refused for; and the hole through a limb and the double outline a frame the alignment makes gives way for+(docs/loop-repair.md section 4)."""from collections.abc import Container@@ -39,6 +40,12 @@ TORN_WARN = 0.21# part carried, turned or grown, is one hole of each; all are theirs. Read only where the measure carries it — the frames# the cycle alignment makes (docs/loop-repair.md section 4).HOLE_WARN = 0.0+# A made frame whose `rife.doubled` is over this shows a double outline: a line one neighbour draws, left at part strength+# in its own place, over a run longer than this share of its body height. Set by eye on drawn walks, between the frames+# seen with a line doubled (a boot's top faded out where one neighbour tilts it, beside the top the frame drew), which read+# over it, and the frames seen as clean or only soft, which read under it. Read only where the measure carries it — the+# frames the cycle alignment makes (docs/loop-repair.md section 4).+DOUBLED_WARN = 0.03def faults(measure: dict[str, float | None]) -> list[str]:@@ -54,14 +61,16 @@ def faults(measure: dict[str, float | None]) -> list[str]:judges alone. A part torn where the measure carries how far the frame's passes disagree(`torn`, the overlapped wrap's frames: `rife.passes`, `rife.torn`). A hole through a limb whereit carries the holes the frame opened that neither neighbour has (`hole`, the cycle alignment's- frames: `rife.hole`)."""+ frames: `rife.hole`). A double outline where it carries how far a line one neighbour draws runs at+ part strength in its own place (`doubled`, the cycle alignment's frames: `rife.doubled`)."""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 []),*(["torn"] if (measure.get("torn") or 0.0) > TORN_WARN else []),- *(["hole"] if (measure.get("hole") or 0.0) > HOLE_WARN else [])])+ *(["hole"] if (measure.get("hole") or 0.0) > HOLE_WARN else []),+ *(["doubled"] if (measure.get("doubled") or 0.0) > DOUBLED_WARN else [])])def looks(measure: dict[str, float | None]) -> list[str]:diff --git a/sprite_gen/video/rife.py b/sprite_gen/video/rife.pyindex be762d0..7ffa26a 100644--- a/sprite_gen/video/rife.py+++ b/sprite_gen/video/rife.py@@ -17,7 +17,8 @@ part coverage on a frame alone, filmed or made; `crossfade` reads two drawings cwhole silhouette, a reading to look at, not a fault; `hole` reads a transparent hole a made frame openedinside its silhouette that neither neighbour has there — in place, carried by the whole figure's motion,or, whatever carried it, one of each neighbour's holes, alike and on its way — where the two runs-disagree inside a limb (docs/loop-repair.md section 4). `passes` runs+disagree inside a limb; `doubled` reads a line one neighbour draws that a made frame left at part strength in its own+place, a double outline where the flow faded a line out instead of moving it (docs/loop-repair.md section 4). `passes` runsthe sixteen single passes the binary's augmentation combines inside one call, one at a time, and`torn` reads where they disagree: a small part RIFE drags apart beside a large one moving far.@@ -139,6 +140,21 @@ HOLE_SHAPE = 1.3HOLE_PATH = 0.1HOLE_COLOUR = 0.12HOLE_PAIR_STEPS = 5000+# `doubled`: a line one neighbour draws, left at part strength in its own place in a made frame — where the flow could not+# follow a line and faded it out instead, the frame shows it beside the line it drew: a double outline (a boot's top as one+# neighbour tilts it and the other plants it). A frame's line is its solid pixels darker by more than OUTLINE_SHIFT than its+# own luma, white off its solid body, closed by a square DOUBLED_WIDE of the made frame's body height wide: a dark stroke+# narrower than that goes in the closing, a dark fill wider stays and is no line. A pixel of one neighbour's line is left+# where the three frames are solid, the other neighbour draws no line within DOUBLED_SHARED px of it (a line both draw is+# theirs, at any strength) and is lighter there by more than OUTLINE_SHIFT, and the made frame is darker than the other+# there by more than OUTLINE_SHIFT (a line still seen) yet by no more than DOUBLED_PART of the line's contrast, there and+# at its darkest within OUTLINE_REACH (no line at full strength beside it, as at the soft edge of a line the flow moved).+# Such pixels count where they make a region DOUBLED_THICK px thick; widened by DOUBLED_THICK px, those that touch make one+# run, and a run's length is sqrt(12) times the root of its pixels' larger second moment (a straight run's own length).+DOUBLED_WIDE = 0.025+DOUBLED_SHARED = 4+DOUBLED_PART = 0.8+DOUBLED_THICK = 3# `crossfade`: an edge's local range is read over this many pixels, wider than RIFE's blur, so a# softened edge keeps its height and a cross-faded one does not; strong edges are counted in windows# this share of the body's height; a window that kept under CROSSFADE_KEEP of its source frames'@@ -883,6 +899,61 @@ def crossfade(made: Image.Image, a: Image.Image, b: Image.Image, t: float) -> flreturn round(lost / max(1, int(solid.sum())), 5)+def _lines(x: np.ndarray, r: int) -> np.ndarray:+ """An RGBA frame's (0..1) lines (`doubled`): its solid pixels darker by more than OUTLINE_SHIFT than its luma, white off+ its solid body, closed by a square 2 r + 1 wide."""+ solid = x[..., 3] >= 0.5+ luma = np.where(solid, _luma(x), 1.0)+ closed = _square_min(-_square_min(-luma, r, mode="edge"), r, mode="edge")+ return solid & (closed - luma > OUTLINE_SHIFT)+++def doubled(made: Image.Image, a: Image.Image, b: Image.Image) -> float:+ """A line one neighbour draws, left at part strength in its own place in a made frame: the longest run of such pixels+ (DOUBLED_* above), as a share of the made frame's body height. RIFE can fade out a line its flow does not follow — the+ top of a boot one neighbour tilts and the other plants — and the frame shows it, lighter, beside the line it drew: a+ double outline, its coverage whole (no part coverage for `ghost`), nothing darker added (`smear`) and its edge outlined+ (`outline_shift`). Read on the made frame's pixels against each neighbour's: a line both neighbours draw is theirs at+ any strength, a line the made frame carries at its neighbour's strength is that neighbour's drawing, and the soft edge+ of a line the flow moved lies beside the line at full strength. 0 where the frame has no solid body, or where the+ neighbours nowhere differ by a line's contrast (docs/loop-repair.md section 4)."""+ m, fa, fb = (np.asarray(f.convert("RGBA"), dtype=np.float32) / 255.0 for f in (made, a, b))+ rows = np.nonzero((m[..., 3] >= 0.5).any(axis=1))[0]+ if rows.size == 0:+ return 0.0+ height = int(rows[-1] - rows[0] + 1)+ lm, la, lb = (_luma(x) for x in (m, fa, fb))+ both = (m[..., 3] >= 0.5) & (fa[..., 3] >= 0.5) & (fb[..., 3] >= 0.5)+ differ = both & (np.abs(la - lb) > OUTLINE_SHIFT)+ if not differ.any():+ return 0.0+ r = max(1, round(DOUBLED_WIDE * height / 2))+ # read in the box round where they differ, wide enough that every pixel there reads as in the whole frame+ y0, y1, x0, x1 = _bounds(differ)+ pad = 2 * r + DOUBLED_SHARED + OUTLINE_REACH + DOUBLED_THICK+ box = (slice(max(0, y0 - pad), y1 + pad), slice(max(0, x0 - pad), x1 + pad))+ m, fa, fb, lm, la, lb, both = (v[box] for v in (m, fa, fb, lm, la, lb, both))+ line_a, line_b = _lines(fa, r), _lines(fb, r)+ darkest = _square_min(np.where(m[..., 3] >= 0.5, lm, 1.0), OUTLINE_REACH, constant_values=1.0)+ left = np.zeros(both.shape, dtype=bool)+ for line, other, own, there in ((line_a, line_b, la, lb), (line_b, line_a, lb, la)):+ part = DOUBLED_PART * (there - own)+ left |= (both & line & ~_near(other, DOUBLED_SHARED) & (there - own > OUTLINE_SHIFT)+ & (there - lm > OUTLINE_SHIFT) & (there - lm <= part) & (there - darkest <= part))+ left = _opened(left, DOUBLED_THICK)+ if not left.any():+ return 0.0+ ys, starts, stops, pieces, _ = _components(_near(left, DOUBLED_THICK), diagonal=True)+ run = np.zeros(left.shape, dtype=np.int64)+ for y, s0, s1, p in zip(ys, starts, stops, pieces):+ run[y, s0:s1] = p+ py, px = np.nonzero(left)+ ids = run[py, px]+ longest = max(float(np.linalg.eigvalsh(np.cov(np.vstack([py[ids == i], px[ids == i]]).astype(np.float64)))[-1])+ for i in np.unique(ids))+ return round(float(np.sqrt(12 * max(longest, 0.0))) / height, 5)++def torn(apart: np.ndarray, made: Image.Image) -> float:"""A part torn in a made frame, read on how far its single passes disagree (`passes`): of the pixels where they aremore than TORN_LEVEL apart, those in regions at least TORN_THICK pixels thick, and of them the largest share of adiff --git a/tests/video/test_crossfade.py b/tests/video/test_crossfade.pyindex 9f1fa08..d9c973a 100644--- a/tests/video/test_crossfade.py+++ b/tests/video/test_crossfade.py@@ -4,7 +4,9 @@ the near and far boots of two drawings both at part strength where the flow founthe coverage whole — so no part-covered band for the ghost screen, and an outline the outline rulereads only where the art outlines in near-black. `rife.crossfade` reads it relative to the sourceframes' own edges; it is a reading to look at, named in a warning, never a fault: on these legs a-clean drawing between two far-apart drawings outlined in grey reads over the line too.+clean drawing between two far-apart drawings outlined in grey reads over the line too. The lines such+a frame leaves at part strength inside the silhouette are read apart, and where they run long they+are a double outline, a fault of its own (`rife.doubled`, tests/video/test_inbetween_doubled.py).The fixtures are synthetic: outlined legs with boots (tests/video/test_rife.py `_walker`, three timesthe size, a palette per case — the outline's and the boots' lightness varied), and RIFE stand-ins@@ -23,7 +25,7 @@ import pytestfrom PIL import Image, ImageDrawfrom sprite_gen.video import align, repair, rife-from sprite_gen.video.interpolation_quality import CROSSFADE_LOOK, faults, looks+from sprite_gen.video.interpolation_quality import CROSSFADE_LOOK, DOUBLED_WARN, faults, looksfrom tests.video.test_ghost_screen import _band, _block_walker, _cutfrom tests.video.test_loop_repair import forced_flow_group@@ -127,6 +129,8 @@ def test_a_clean_drawing_between_far_drawings_outlined_in_grey_reads_over_the_li@pytest.mark.slowdef test_auto_keeps_a_crossfaded_frame_and_names_it_to_look_at():+ """Legs 10 to 5 degrees: the lines the cross-fade leaves inside every silhouette run under the+ double outline's line (the rest of its doubled edge lies on the silhouette), so it is kept, named."""sa, sb = (10, -10), (5, -5)a, b, _, there = _inside(sa, sb, 0.5)_, _, _, back = _inside(sb, sa, 0.5)@@ -135,7 +139,7 @@ def test_auto_keeps_a_crossfaded_frame_and_names_it_to_look_at():out, facts = align.resample([a, b], 4, lambda x, y, t: made[(id(x), id(y))], between=between) # times 0, .5, 1, 1.5assert [m["at"] for m in facts["smear"]] == [1, 3]assert all(m["method"] == "rife" and m["faults"] == [] and m["look"] == ["crossfade"] for m in facts["smear"])- assert all(m["crossfade"] > CROSSFADE_LOOK for m in facts["smear"])+ assert all(m["crossfade"] > CROSSFADE_LOOK and m["doubled"] < DOUBLED_WARN for m in facts["smear"])assert out[1] is there and out[3] is back and facts["made_by_rife"] == 2a, b, _, there = _inside(sa, sb, 0.5, outline=BLACK, boot=None)_, _, _, back = _inside(sb, sa, 0.5, outline=BLACK, boot=None)@@ -156,18 +160,27 @@ def _keyed(tmp_path: Path, name: str, length: int) -> Path:@pytest.mark.slow-def test_alignment_warns_on_a_crossfaded_frame_it_keeps(tmp_path, capsys):+def test_alignment_gives_a_crossfaded_frame_way_as_a_double_outline_and_names_it_to_look_at(tmp_path, capsys):"""Resampled 8 to 12 through a RIFE whose colour run blends and whose coverage run is the union:- the frames it makes across the legs' long steps are kept, each named in a warning line."""+ every frame it makes across the legs' long steps leaves both drawings' lines at half inside the+ silhouette, a double outline (`rife.doubled`, tests/video/test_inbetween_doubled.py), so auto gives+ it way, each named in a warning line, and names it to look at all the same. Before the double+ outline was read they were kept: the cross-fade reading names and never judges, as a clean drawing+ between far-apart drawings reads over it too, and it still does. Under rife they are kept, each+ named in a warning line to look at."""_cut(_keyed(tmp_path, "E", 8), tmp_path / "E", 8)report = align.align_set([tmp_path / "E"], length=12, interpolate=lambda a, b, t: _made(a, b, t, _union), multi_cycle="warn")- row = report["loops"][0]- looked = [m for m in row["smear"] if m["look"]]+ looked = [m for m in report["loops"][0]["smear"] if m["look"]]assert looked and all(m["look"] == ["crossfade"] and m["crossfade"] > CROSSFADE_LOOK for m in looked)- assert all(m["method"] == "rife" for m in looked if not m["faults"]) # the reading gives nothing way- kept = [m for m in looked if m["method"] == "rife"]+ assert all(m["method"] == "nearest" and "doubled" in m["faults"] for m in looked)+ assert all(any(f"frame {m['at']}: RIFE's frame" in w and "a double outline" in w for w in report["warnings"]) for m in looked)+ _cut(_keyed(tmp_path, "R", 8), tmp_path / "R", 8)+ report = align.align_set([tmp_path / "R"], length=12, interpolate=lambda a, b, t: _made(a, b, t, _union), multi_cycle="warn",+ between="rife")+ kept = [m for m in report["loops"][0]["smear"] if m["look"]]named = [w for w in report["warnings"] if "may cross-fade two drawings inside its outline" in w]- assert kept and len(named) == len(kept) and all(any(f"frame {m['at']} (made by RIFE)" in w for w in named) for m in kept)+ assert kept and all(m["method"] == "rife" for m in kept)+ assert len(named) == len(kept) and all(any(f"frame {m['at']} (made by RIFE)" in w for w in named) for m in kept)def test_jump_repair_takes_a_crossfaded_proposal_and_names_it(monkeypatch):diff --git a/tests/video/test_inbetween_doubled.py b/tests/video/test_inbetween_doubled.pynew file mode 100644index 0000000..b841de6--- /dev/null+++ b/tests/video/test_inbetween_doubled.py@@ -0,0 +1,258 @@+# SPDX-License-Identifier: Apache-2.0+"""A double outline (docs/loop-repair.md section 4): `rife.doubled` reads a line one source frame draws that a made frame+left at part strength in its own place, and the cycle alignment gives such a frame way to the nearer source frame+(`--between auto`). Where RIFE's flow does not follow a line — the top of a boot one source frame tilts and the other+plants — it can fade the line out instead of moving it, and the frame shows it, lighter, beside the line it drew. Its+coverage is whole, nothing darker is added and its edge keeps its line, so the ghost screen, the smear and both outline+readings pass it; the cross-fade reading names whole drawings blended, and is no fault. A line both source frames draw+within 4 px is theirs, at any strength; a line the made frame carries at its source frame's own strength is that frame's+drawing; the soft edge of a line the flow moved lies beside the line at full strength; a line left less than 50/255+darker than the other source frame shows there is not seen; a run shorter than 3 % of the body is not read. A line only+one source frame draws — a crease that comes and goes — is read the same way: left at part strength, it is a double+outline too.++The fixtures are synthetic: a coat over two legs in boots, outlined 3 px in near-black, with a hand beside the coat; the+near boot lifted 18 px in the first source frame and planted in the second. The frame drawn between, and the same with a+source frame's near-boot lines laid over it at part strength; blurred, smeared along the step; a hand moving 60 px over+the coat; boots drawn with a second line; a hem drawn with two lines and softened; a crease one source frame draws. And+the walker of tests/video/test_crossfade.py: its drawing between far-apart drawings, and its cross-fades."""++from __future__ import annotations++import numpy as np+import pytest+from PIL import Image, ImageDraw, ImageFilter++from sprite_gen.video import align, rife+from sprite_gen.video.interpolation_quality import CROSSFADE_LOOK, DOUBLED_WARN, faults, looks+from tests.video.test_crossfade import BLACK, _inside++W, H = 200, 260+LINE = (20, 16, 12, 255)+COAT, LEG, BOOT = (250, 240, 235, 255), (190, 120, 80, 255), (240, 200, 40, 255)+LIGHT = (150, 120, 60, 255) # a light crease: 72 levels darker than the boot, under 50/255 once faded to half+LIFTED, PLANTED = 176, 194 # the near boot's top: lifted in the first source frame, planted in the second+NEAR = np.zeros((H, W), dtype=bool)+NEAR[:, 100:150] = True # the near boot's columns+++def _figure(near: float, *, hand: float | None = 150, over: float | None = None, cuff: bool = False, hem: bool = False,+ crease: tuple[int, ...] | None = None) -> Image.Image:+ """A coat over two legs in boots, the far boot's top at 200 and the near boot's at `near`, lines 3 px; a hand beside+ the coat at column `hand`, or over it at column `over`. `cuff`: a second line 5 px under each boot's top; `hem`: the+ coat's hem drawn with two lines; `crease`: a line of that colour across the near boot, 14 px under its top."""+ im = Image.new("RGBA", (W, H), (0, 0, 0, 0))+ d = ImageDraw.Draw(im)++ def box(x0: float, y0: float, x1: float, y1: float, fill: tuple[int, ...], r: int = 0) -> None:+ d.rounded_rectangle([x0, y0, x1, y1], radius=r, fill=LINE)+ d.rounded_rectangle([x0 + 3, y0 + 3, x1 - 3, y1 - 3], radius=max(0, r - 3), fill=fill)++ for x, top in ((62, 200), (108, near)):+ box(x + 4, 140, x + 30, top + 6, LEG)+ box(x, top, x + 34, top + 46, BOOT, r=8)+ if cuff:+ d.rectangle([x + 3, top + 8, x + 31, top + 10], fill=LINE)+ if crease is not None and x == 108:+ d.rectangle([x + 3, top + 14, x + 31, top + 16], fill=crease)+ box(50, 40, 150, 150, COAT, r=10)+ if hem:+ d.rectangle([53, 138, 147, 140], fill=LINE)+ if hand is not None:+ box(int(hand) - 14, 110, int(hand) + 14, 136, LEG, r=10)+ if over is not None:+ box(over - 14, 70, over + 14, 96, LEG, r=10)+ return im+++def _step(t: float, **kw) -> Image.Image:+ """The figure at fraction t of the step: the near boot from lifted to planted."""+ return _figure(LIFTED + t * (PLANTED - LIFTED), **kw)+++def _lines(im: Image.Image) -> np.ndarray:+ x = np.asarray(im, dtype=np.float32) / 255+ return (x[..., 3] >= 0.5) & (x[..., 0] * 0.299 + x[..., 1] * 0.587 + x[..., 2] * 0.114 < 0.2)+++def _left(drawn: Image.Image, source: Image.Image, k: float, region: np.ndarray = NEAR) -> Image.Image:+ """`drawn` with the lines of `source` it has not got laid over it at strength k, where it is solid inside `region`:+ a line RIFE faded out in its source frame's place instead of moving it."""+ x = np.asarray(drawn, dtype=np.float32).copy()+ m = _lines(source) & ~_lines(drawn) & (x[..., 3] >= 128) & region+ x[m, :3] = (1 - k) * x[m, :3] + k * np.asarray(source, dtype=np.float32)[m, :3]+ return Image.fromarray(np.uint8(x + 0.5), "RGBA")+++def _pre(im: Image.Image) -> np.ndarray:+ x = np.asarray(im, dtype=np.float32) / 255+ return np.dstack([x[..., :3] * x[..., 3:], x[..., 3:]])+++def _unpre(p: np.ndarray) -> Image.Image:+ a = p[..., 3:]+ return Image.fromarray(np.uint8(np.clip(np.dstack([p[..., :3] / np.maximum(a, 1e-6), a]), 0, 1) * 255 + 0.5), "RGBA")+++def _soft(im: Image.Image, radius: float) -> Image.Image:+ """`im` blurred, premultiplied: a soft frame."""+ p = _pre(im)+ return _unpre(np.dstack([np.asarray(Image.fromarray(np.uint8(np.clip(p[..., c], 0, 1) * 255 + 0.5)).filter(+ ImageFilter.GaussianBlur(radius)), dtype=np.float32) / 255 for c in range(4)]))+++def _smeared(make, t: float, spread: float, n: int = 7) -> Image.Image:+ """The figure at t smeared along its way: the mean of n drawings from t - spread to t + spread."""+ return _unpre(np.mean([_pre(make(t + spread * (2 * j / (n - 1) - 1))) for j in range(n)], axis=0))+++def _hand(t: float) -> Image.Image:+ """A hand moving 60 px across the coat, over it, the boots still."""+ return _figure(185, hand=None, over=75 + 60 * t)+++def _readings(made: Image.Image, a: Image.Image, b: Image.Image, t: float = 0.5) -> dict[str, float | None]:+ """Every reading the alignment judges a made frame by but the double outline's."""+ return {**rife.smear(made, a, b), "outline_shift": rife.outline_shift(made, a, b), "ghost": rife.ghost(made),+ "crossfade": rife.crossfade(made, a, b, t), "hole": rife.hole(made, a, b, t)}+++def _resampled(a: Image.Image, b: Image.Image, there: Image.Image, back: Image.Image, between: str = "auto"):+ """The two source frames resampled to four (times 0, .5, 1, 1.5), RIFE's frames `there` (a to b) and `back` (b to a)."""+ made = {(id(a), id(b)): there, (id(b), id(a)): back}+ return align.resample([a, b], 4, lambda x, y, t: made[(id(x), id(y))], between=between)+++def test_a_line_left_at_part_strength_is_a_double_outline_that_every_reading_before_passes():+ """The near boot's old top faded out at 0.45 beside the top the frame drew: coverage whole, no part coverage, nothing+ darker, its edge outlined — no fault before; `doubled` reads the run of the line left, 0.102 of the body's height+ (its own length, the boot's width). The same with both source frames' lines left at half, and the frame whose colour+ is the plain blend of the two inside the drawing's coverage, read the same."""+ a, b, between = _step(0), _step(1), _step(0.5)+ made = _left(between, a, 0.45)+ measure = _readings(made, a, b)+ assert faults(measure) == [] and looks(measure) == []+ assert measure["ghost"] == 0 and measure["hole"] == 0 and measure["crossfade"] < CROSSFADE_LOOK+ assert rife.doubled(made, a, b) == pytest.approx(0.1022, abs=5e-4)+ assert faults({**measure, "doubled": rife.doubled(made, a, b)}) == ["doubled"]+ assert rife.doubled(between, a, b) == 0 and rife.doubled(a, a, b) == 0 and rife.doubled(b, a, b) == 0+ assert rife.doubled(_left(_left(between, a, 0.5), b, 0.5), a, b) > DOUBLED_WARN+ blend = (_pre(a) + _pre(b)) / 2+ inside = np.asarray(between, dtype=np.float32)[..., 3:] / 255+ faded = _unpre(np.dstack([blend[..., :3] / np.maximum(blend[..., 3:], 1e-6) * inside, inside]))+ assert faults(_readings(faded, a, b)) == [] and rife.doubled(faded, a, b) > DOUBLED_WARN+++def test_auto_gives_a_frame_with_a_double_outline_way_to_the_nearer_source_frame():+ """Resampled two to four, each frame RIFE made leaving its first source frame's near-boot lines at 0.45: auto takes the+ nearer source frame at both (cells 1 and 3, half way rounding up), the fault named in the warning's words; rife+ keeps both, named."""+ a, b = _step(0), _step(1)+ there, back = _left(_step(0.5), a, 0.45), _left(_step(0.5), b, 0.45)+ out, facts = _resampled(a, b, there, back)+ assert [m["at"] for m in facts["smear"]] == [1, 3] and facts["nearest_at"] == [1, 3] and facts["made_by_rife"] == 0+ assert all(m["method"] == "nearest" and m["faults"] == ["doubled"] and m["doubled"] > DOUBLED_WARN for m in facts["smear"])+ assert out[1] is b and out[3] is a+ line = align._fault_line("walk", facts["smear"][0])+ assert "at part strength in its own place" in line and "a double outline" in line and "(--between auto)" in line+ out, facts = _resampled(a, b, there, back, between="rife")+ assert out[1] is there and out[3] is back and all(m["method"] == "rife" and m["faults"] == ["doubled"] for m in facts["smear"])+++def test_a_line_only_one_source_frame_draws_left_at_part_strength_is_a_double_outline():+ """A crease the first source frame draws across the still near boot and the second does not — a line that comes or+ goes, with no line of the other's to pair it within 4 px: left at 0.3 to 0.8 of its contrast it is a double outline+ and gives way; the frame that draws it, or does not, keeps its bytes; left at 0.25 it is lighter than 50/255 under+ the boot and not seen."""+ a, b, plain = _figure(185, crease=LINE), _figure(185), _figure(185)+ for k in (0.3, 0.45, 0.6):+ assert rife.doubled(_left(plain, a, k), a, b) > DOUBLED_WARN+ assert rife.doubled(_left(plain, a, 0.25), a, b) == 0 and rife.doubled(a, a, b) == 0 and rife.doubled(b, a, b) == 0+ out, facts = _resampled(a, b, _left(plain, a, 0.45), _left(plain, b, 0.45))+ assert facts["smear"][0]["faults"] == ["doubled"] and out[1] is b+ out, facts = _resampled(a, b, a, b)+ assert facts["made_by_rife"] == 2 and out[1] is a and out[3] is b+++def _clean() -> dict[str, tuple[Image.Image, Image.Image, Image.Image]]:+ """(first source frame, second, the frame made at t 0.5) of frames that keep their bytes."""+ lit = _figure(LIFTED, crease=LIGHT)+ own = np.asarray(_step(0.5), dtype=np.float32).copy()+ drawn = (np.abs(np.asarray(lit, dtype=np.float32) - np.asarray(_figure(LIFTED), dtype=np.float32)).sum(-1) > 0) & (own[..., 3] >= 128)+ own[drawn, :3] = np.asarray(lit, dtype=np.float32)[drawn, :3]+ hem = np.asarray(_step(0.5, hem=True), dtype=np.float32).copy()+ lines = _lines(_step(0.5, hem=True))+ lines[:134] = lines[146:] = False+ hem[lines, :3] = 0.4 * hem[lines, :3] + 0.6 * np.array(COAT[:3])+ return {+ "drawn between": (_step(0), _step(1), _step(0.5)),+ "drawn between, soft": (_step(0), _step(1), _soft(_step(0.5), 1.5)),+ "drawn between, smeared along the step": (_step(0), _step(1), _smeared(_step, 0.5, 0.15)),+ "a hand moving 60 px over the coat": (_hand(0), _hand(1), _hand(0.5)),+ "the hand, soft": (_hand(0), _hand(1), _soft(_hand(0.5), 1.5)),+ "the hand, smeared along its way": (_hand(0), _hand(1), _smeared(_hand, 0.5, 0.15)),+ "boots drawn with a second line": (_step(0, cuff=True), _step(1, cuff=True), _step(0.5, cuff=True)),+ "a hem both draw with two lines, softened": (_step(0, hem=True), _step(1, hem=True), Image.fromarray(np.uint8(hem + 0.5), "RGBA")),+ "a light crease carried at its own strength": (lit, _figure(PLANTED), Image.fromarray(np.uint8(own + 0.5), "RGBA")),+ }++[email protected]("name", list(_clean()))+def test_a_clean_soft_or_source_drawn_frame_reads_no_double_outline_and_keeps_its_bytes(name):+ """The drawing between, blurred, or smeared along the step; a hand moving fast over the coat, drawn, soft or smeared;+ boots both source frames draw with two lines; a hem both draw with two lines, softened to 60 % in the frame between (a+ line both draw is theirs at any strength); a light crease one draws, carried at its own strength: each reads 0, passes+ every fault and is delivered as the very frame made."""+ a, b, made = _clean()[name]+ assert rife.doubled(made, a, b) == 0+ out, facts = _resampled(a, b, made, made) # each made half way, the same drawing either way+ assert all(m["faults"] == [] and m["method"] == "rife" for m in facts["smear"]) and out[1] is made and out[3] is made+++def test_the_walkers_drawing_between_keeps_its_bytes_and_its_cross_fade_gives_way_where_its_lines_left_run_long():+ """The walker of tests/video/test_crossfade.py, legs closing 16 to 3 degrees: the drawing between, which the cross-fade+ reading reads over its line in grey (why that reading names and never judges), reads no double outline in grey or+ black and keeps its bytes; the colour blended inside its coverage leaves both drawings' lines at half and gives way.+ Legs closing 10 to 5 degrees, their cross-fade's lines left inside every silhouette run 0.0195 of the body — the rest+ of its doubled edge lies on the silhouette, where one source frame is not solid — under the line, and it is kept."""+ for kw in ({}, {"outline": BLACK, "boot": None}):+ a, b, drawn, faded = _inside((16, -16), (3, -3), 0.5, **kw)+ assert rife.doubled(drawn, a, b) == 0+ _, _, back, _ = _inside((3, -3), (16, -16), 0.5, **kw)+ out, facts = _resampled(a, b, drawn, back)+ assert all(m["method"] == "rife" and m["faults"] == [] for m in facts["smear"]) and out[1] is drawn and out[3] is back+ assert rife.doubled(faded, a, b) > DOUBLED_WARN and "doubled" in faults({**_readings(faded, a, b), "doubled": rife.doubled(faded, a, b)})+ a, b, _, faded = _inside((10, -10), (5, -5), 0.5)+ assert rife.doubled(faded, a, b) == pytest.approx(0.0195, abs=5e-4)+++def test_the_double_outlines_named_bounds():+ """Where each bound turns, on the boot's old top left in the frame drawn between (its line 0.69 darker than the boot):+ seen — left at 0.28 of its contrast it is 0.1960 darker than the boot, just under 50/255 (0.1961), and not read; at+ 0.30, 0.2076, read. Part strength — at 0.80, read; at 0.82, more than 0.8 of its contrast, it is the source frame's own+ line. Moved — the boot moved 8 px, the pixels of its old line the reading keeps are too thin to hold a 3 px square,+ and are not read; moved 9 px, read. Width — a dark patch 10 px square one source frame draws is no line (the closing, 2.5 %+ of the body high, keeps it), where a stroke 3 px wide is. Length — left over 6 columns the run is 0.0294 of the body,+ under 3 %; over 7, 0.0343. And what the reading does not tell: a hand drawn smeared along its way, back over the line+ one source frame draws there (t 0.3 to 0.7 of a 60 px move), reads as that line left."""+ a, b, between = _step(0), _step(1), _step(0.5)+ reads = lambda made, x=a, y=b: rife.doubled(made, x, y)+ assert reads(_left(between, a, 0.28)) == 0 and reads(_left(between, a, 0.30)) > DOUBLED_WARN+ assert reads(_left(between, a, 0.80)) > DOUBLED_WARN and reads(_left(between, a, 0.82)) == 0+ for moved, read in ((8, False), (9, True)):+ x, y = _figure(LIFTED), _figure(LIFTED + moved)+ assert (reads(_left(_figure(LIFTED + moved / 2), x, 0.45), x, y) > DOUBLED_WARN) is read++ def patched(shape: list[int]) -> Image.Image:+ im = _figure(185)+ ImageDraw.Draw(im).rectangle(shape, fill=LINE)+ return im++ for shape, read in (([120, 205, 129, 214], False), ([114, 208, 137, 210], True)):+ x = patched(shape)+ assert (reads(_left(_figure(185), x, 0.45, np.ones((H, W), dtype=bool)), x, _figure(185)) > DOUBLED_WARN) is read+ for columns, value in ((6, 0.0294), (7, 0.0343)):+ region = np.zeros((H, W), dtype=bool)+ region[170:182, 120:120 + columns] = True+ assert reads(_left(between, a, 0.45, region)) == pytest.approx(value, abs=5e-4)+ assert reads(_smeared(_hand, 0.5, 0.2), _hand(0), _hand(1)) > DOUBLED_WARN