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 hole a made frame shows is its source frames' own where it is one hole of each, whatever carried it — after the in-place reading and the whole figure's motion, rife.hole pairs each enclosed hole of the made frame one to one with an enclosed hole of each source frame alike in area, shape (second moments over area, kept by turning and growing) and the colour round it, on its way between theirs (rife.HOLE_SOURCE_THICK 3, HOLE_PAIR_AREA 4, HOLE_PAIR_SHAPE 2, HOLE_COLOUR 0.12, HOLE_AREA 0.25, HOLE_SHAPE 1.3, HOLE_PATH 0.1, the pair within sqrt(2) times the reach); the box round each piece and the every-motion reading (_carried, HOLE_CARRY, HOLE_AGREE) are gone; the third checkpoint validator's plate turning 60 degrees as it moves 48 px and 125 frames of a plate turned, grown, sheared or swung within reach are kept as made, while a hole unlike its source frames', off its way, out of reach or more than they have is given way, as the band through a leg is
Soohong Kim45d831aac74b
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex a16efbb..57fc4de 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -15,11 +15,11 @@ All notable public changes to `sprite-gen` are recorded here. Versions track the**Upgrading from 3.1.0: `video-cycle-align` now gives way to the nearer source frame on made frames with enclosed limb holes under `--between auto`, changing only alignment outputs with such holes 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 `hole` 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, `hole` ("a hole through a limb"). Under `--between auto` (the default) a made frame with this fault gives way to the nearer source frame, like the other faults (`smear`, `outline`, `ghost`); under `--between rife` the frame is kept and named in the warnings. `video-set --align-cycles auto` runs the same alignment. RIFE runs a frame's colour and its coverage as two separate runs. Where a step opens a gap between the legs in one source frame and not the other, the coverage run can carry that gap into a leg the colour run keeps whole: the made frame shows a transparent band through the leg with the leg's fill on both sides. Nothing is added (no `smear`), there is no part coverage (no `ghost`), and the leg's own fill is the only line round the band. The fault `outline` needs both outline readings: the dark line (`outline_loss`) counts a fill darker than 70/255 (dark tights, a boot) as outline, and the rank reading (`outline_shift`) reads the band's edge as lost only where it is 50/255 lighter than the source frames' lines at the same rank, which light lines elsewhere on the art (fur, hair drawn without a dark line) can hide; so such a frame passes every fault and is delivered. The reading `rife.hole(made, a, b, t)` measures pixels under solid (alpha under 0.5) that the outside of the picture cannot reach without crossing its solid body (enclosed holes). A pixel of a made frame's hole is the source frames' own when either source frame is under solid within 4 px (`rife.HOLE_REACH`, a square neighbourhood) of where that pixel lay at that frame's time, read three ways: in place (the background, still, and a gap kept, or opened by a step where the frame that shows it open has it); carried with the whole figure along the motion the two source frames show for the whole figure; and carried with what lies round the hole along the motion the two source frames show round each piece of hole the first two leave. Where a made frame sits at fraction `t` of the way from source frame a to source frame b, a pixel of it lay in a at `t` of the motion back and lies in b at `1 - t` of it on (rounded so the two are the whole motion apart). Motions are measured only from the two source frames, never from the made frame and never from RIFE's own flow. Each pixel of a box in made frame coordinates is read in a where it lay and in b where it lies for a candidate motion; the motion whose mean absolute difference of premultiplied colour and coverage over the box is least is the motion there, with ties going to the smaller motion. The whole figure's motion is read over the box round all three frames' solid bodies. Each remaining piece's motion is read over the box round the piece, widened each way by `max(t, 1 - t)` of the farthest motion followed, so the box holds a gap the source frames carried there. A fourth reading runs only on a frame that still keeps a piece of hole after the third reading, and only on the pieces the first three leave (a frame the first three readings leave no piece of hole on reads what they give), added because one motion per box lets a patterned body that stays outweigh a small part moving over it. Over the box round the part's hole the body's stillness (or a motion that matches the stripes to themselves) fits better than the part's motion, so the third reading alone would miss a hole both source frames have and the part carries, and give a correct frame way. The fourth reading judges every motion in that range (every whole-pixel motion from minus to plus the reach on each axis) instead of one motion per box, reading a piece as the source frames' where both source frames carry it by one motion within the same reach of 20 % of the body's height each way (`rife.HOLE_TRAVEL`). For a motion, each source frame is moved by its share of it, and each moved source frame must (a) have at least 90 % of the piece (`rife.HOLE_CARRY`, 0.9) within 4 px (`rife.HOLE_REACH`) of its own pixels under solid, and (b) cover the band round the piece, the pixels from 5 to 8 px out from it (from `rife.HOLE_REACH` + 1 to twice `rife.HOLE_REACH`, a square neighbourhood), as the made frame covers it (solid meaning alpha 0.5 and over), differing on at most 5 % of the band (`rife.HOLE_AGREE`, 0.05). Of the motions that pass for both source frames, the one whose worse source frame differs least over the band is taken (then the one that carries more of the piece, then the smaller motion); the piece's pixels within 4 px of where either source frame has pixels under solid along that motion are the source frames', as in the other readings. The made frame is used only to judge each motion by its own coverage round its own hole; it is never used to measure a motion, RIFE's flow is never read, and the counts for every motion are computed at once per source frame by FFT correlation, rounded to whole counts. A motion is followed up to 20 % of the body's height each way (`rife.HOLE_TRAVEL`, 0.2). The search is coarse to fine: the whole range is searched on a level pooled in square blocks of a power of two, the smallest power for which the range is at most 24 px each way (`rife.HOLE_COARSE`, 24), then within 2 px of twice the coarser motion on each finer level, down to the pixel. Motions are measured only on frames that keep a hole after the in-place reading; a frame with no hole in place is read as before. The regions at least 5 px thick (`rife.HOLE_THICK`, opened by a 5 px square, so a pinhole or an antialiased crevice a pixel or two wide is not counted) are taken after each step, as a fraction of the made frame's solid pixels, or 0 where the frame has no solid body. The fault `hole` is any reading over 0 (`interpolation_quality.HOLE_WARN`, 0.0). A band cut through a leg's edge, reaching the outside, is not an enclosed hole and is left to the outline readings as before.+- **New: `video-cycle-align` now reads a new `hole` 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, `hole` ("a hole through a limb"). Under `--between auto` (the default) a made frame with this fault gives way to the nearer source frame, like the other faults (`smear`, `outline`, `ghost`); under `--between rife` the frame is kept and named in the warnings. `video-set --align-cycles auto` runs the same alignment. RIFE runs a frame's colour and its coverage as two separate runs. Where a step opens a gap between the legs in one source frame and not the other, the coverage run can carry that gap into a leg the colour run keeps whole: the made frame shows a transparent band through the leg with the leg's fill on both sides. Nothing is added (no `smear`), there is no part coverage (no `ghost`), and the leg's own fill is the only line round the band. The fault `outline` needs both outline readings: the dark line (`outline_loss`) counts a fill darker than 70/255 (dark tights, a boot) as outline, and the rank reading (`outline_shift`) reads the band's edge as lost only where it is 50/255 lighter than the source frames' lines at the same rank, which light lines elsewhere on the art (fur, hair drawn without a dark line) can hide; so such a frame passes every fault and is delivered. The reading `rife.hole(made, a, b, t)` measures pixels under solid (alpha under 0.5) that the outside of the picture cannot reach without crossing its solid body (enclosed holes). A pixel of a made frame's hole is the source frames' own when either source frame is under solid within 4 px (`rife.HOLE_REACH`, a square neighbourhood) of where that pixel lay at that frame's time, read in place (the background, still, and a gap kept, or opened by a step where the frame that shows it open has it) and carried with the whole figure along the motion the two source frames show for the whole figure. Where a made frame sits at fraction `t` of the way from source frame a to source frame b, a pixel of it lay in a at `t` of the motion back and lies in b at `1 - t` of it on (rounded so the two are the whole motion apart). The motion is measured only from the two source frames, never from the made frame and never from RIFE's own flow: over the box round all three frames' solid bodies, each pixel is read in a where it lay and in b where it lies for a candidate motion; the motion whose mean absolute difference of premultiplied colour and coverage over the box is least is the motion there, ties going to the smaller motion. It is followed up to 20 % of the body's height each way (`rife.HOLE_TRAVEL`, 0.2), coarse to fine: the whole range on a level pooled in square blocks of a power of two, the smallest for which the range is at most 24 px each way (`rife.HOLE_COARSE`, 24), then within 2 px of twice the coarser motion on each finer level, down to the pixel. A hole those two readings leave is the source frames' own, whatever carried it (a part moving over a body that stays, plain or patterned, turning, growing, sheared or swinging), where it is one hole of each source frame. A hole is an 8-connected piece of a frame's enclosed pixels: the made frame's count where they keep a pixel opened by a 5 px square, a source frame's where they keep one opened by a 3 px square (`rife.HOLE_SOURCE_THICK`, 3). Each is read for its area, its centroid, its shape (the logarithms of its pixels' two principal second moments, each plus 1/12, over its area, which turning and growing keep) and the colour round it (the mean premultiplied colour of the frame's solid pixels 5 to 8 px out). The two source frames' holes: areas within 4 times of each other (`rife.HOLE_PAIR_AREA`, 4.0), shapes within 2 times on each moment (`rife.HOLE_PAIR_SHAPE`, 2.0), colours within 0.12 on each channel (`rife.HOLE_COLOUR`, 0.12), centroids at most sqrt(2) times the reach and 4 px apart. The made frame's hole: area within a quarter of their range (`rife.HOLE_AREA`, 0.25), shape within 1.3 times of theirs (`rife.HOLE_SHAPE`, 1.3), colour within 0.12 of each, and centroid within 4 px and 0.1 of their distance (`rife.HOLE_PATH`, 0.1) of the point at `t` on the line between theirs. Pairs are taken one to one, each source frame's hole explaining one hole of the made frame: the made frame's holes the first two readings already give the source frames first, then the rest, each the alikest and nearest first. So a hole the made frame keeps where it was explains no other, and in a row of alike holes moving, each takes its own two. The made frame is never used to measure a motion, and RIFE's flow is never read. The motion is read only on frames that keep a hole after the in-place reading, and the pairing only on frames that keep one after the whole figure's motion; a frame with no hole in place is read with no further cost. The regions at least 5 px thick (`rife.HOLE_THICK`, opened by a 5 px square, so a pinhole or an antialiased crevice a pixel or two wide is not counted) are taken after each step, as a fraction of the made frame's solid pixels, or 0 where the frame has no solid body. The fault `hole` is any reading over 0 (`interpolation_quality.HOLE_WARN`, 0.0). A band cut through a leg's edge, reaching the outside, is not an enclosed hole and is left to the outline readings as before.- Report fields: each row of a loop's `smear` list in the `video-cycle-align` report (and in `cycle_align` in `strip.json`) gains `hole`. A frame given way for it carries `faults: ["hole"]` and `method: "nearest"`, and gets a line in `warnings`; the line says the frame opened a transparent hole inside its outline over the given share of its body, at least 5 px thick, where neither source frame beside it has one, a gap through a limb, and that the nearer source frame was taken there. The `--between` help says the same.-- Python callers: new `rife.hole(made, a, b, t)`, `rife.HOLE_TRAVEL` (0.2), `rife.HOLE_COARSE` (24), `rife.HOLE_REACH` (4), `rife.HOLE_THICK` (5), `rife.HOLE_CARRY` (0.9), and `rife.HOLE_AGREE` (0.05); new `interpolation_quality.HOLE_WARN` (0.0); `interpolation_quality.faults(measure)` returns `"hole"` where the measure carries a `hole` reading over `HOLE_WARN`, and measures without a `hole` key are judged as before.-- 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 or carried by the motions 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 or carried, 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 over a patterned body that stays, 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 first three readings leave the hole whole, 100 pixels or 0.28 % of the body (the whole figure's motion is 0 and the box round the hole fits a motion that lays the stripes on themselves); the fourth carries it: `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), the first three readings leave a hole in 59 of these 105 frames (0.16 % to 0.47 %); moved 16, 32 and 48 px across and diagonally at t 0.25 and 0.75 over the 3 px stripes at contrast 40, none. With the fourth reading every one reads `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 over the box round it the torso's stillness fits better than the arm's motion: the first three readings read 0.28 %, 0.55 % and 0.28 % at t 0.25, 0.5 and 0.75. The fourth carries it: `hole` 0, 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 the first readings do not carry, 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"]`. 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"]`.+- Python callers: new `rife.hole(made, a, b, t)`, `rife.HOLE_TRAVEL` (0.2), `rife.HOLE_COARSE` (24), `rife.HOLE_REACH` (4), `rife.HOLE_THICK` (5), `rife.HOLE_SOURCE_THICK` (3), `rife.HOLE_PAIR_AREA` (4.0), `rife.HOLE_PAIR_SHAPE` (2.0), `rife.HOLE_AREA` (0.25), `rife.HOLE_SHAPE` (1.3), `rife.HOLE_PATH` (0.1), and `rife.HOLE_COLOUR` (0.12); new `interpolation_quality.HOLE_WARN` (0.0); `interpolation_quality.faults(measure)` returns `"hole"` where the measure carries a `hole` reading over `HOLE_WARN`, and measures without a `hole` key are judged as before.+- 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. 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, while with one hole more midway as well both give way.## 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 decontaminationdiff --git a/docs/loop-repair.md b/docs/loop-repair.mdindex fa6a917..2c9e812 100644--- a/docs/loop-repair.md+++ b/docs/loop-repair.md@@ -1484,84 +1484,101 @@ sprite-gen video-cycle-align --loop-dir set/front-walk/loop --loop-dir set/side-only where it is 50/255 lighter than the source frames' lines at the same rank, which light lineselsewhere on the art (fur, hair drawn without a dark line) hide; the fault `outline` needs both.Neither reading is about a hole.- - `hole`: of the made frame's pixels under solid (alpha under 0.5) that the outside of the- picture cannot reach without crossing its solid body (enclosed holes), those with no pixel- under solid in either source frame within **4 px** (`rife.HOLE_REACH`, a square neighbourhood)- of where that pixel lay at that frame's time, read three ways: in place (the background,- still, and a gap kept, or opened by a step where the frame showing it open has it); carried- with the whole figure along the motion the two source frames show for the whole figure; and- carried with what lies round the hole along the motion the two source frames show round each- piece of hole the first two leave. Where the made frame sits at fraction `t` from source frame a- to source frame b, a pixel of it lay in a at `t` of the motion back and lies in b at `1 - t` of- it on (rounded so the two are the whole motion apart). Motions are measured only from the two- source frames, never from the made frame or RIFE's flow: for each candidate motion over a box- in made frame coordinates, each pixel is read in a where it lay and in b where it lies, taking- the motion with least mean absolute difference of premultiplied colour and coverage (ties- going to smaller motion). The whole figure's motion is read over the box round all three- frames' solid bodies. Each remaining piece's motion is read over the box round the piece,- widened each way by `max(t, 1 - t)` of the farthest motion followed. A motion is followed up to- 20 % of the body's height each way (`rife.HOLE_TRAVEL`, 0.2), searched coarse to fine: pooled- in square blocks of a power of two where the range is at most 24 px each way- (`rife.HOLE_COARSE`, 24), then within 2 px of twice the coarser motion on each finer level down- to the pixel. A fourth reading is run only on a frame that still keeps a piece of hole after the- third reading, and only on those pieces (a frame keeping no piece of hole after the third- reading has the value the first three readings give): a piece is the source frames' where both- source frames carry it by one motion within the same reach (20 % of the body's height each way,- `rife.HOLE_TRAVEL`). Every motion in that range is judged (every whole-pixel motion from minus- to plus the reach on each axis), not one motion per box. Each source frame is moved by its share- of the motion, as above. Each moved source frame must (a) have at least 90 % of the piece- (`rife.HOLE_CARRY`, 0.9) within 4 px (`rife.HOLE_REACH`) of its own pixels under solid, and (b)- cover the band round the piece, the pixels from 5 to 8 px out from it (from `rife.HOLE_REACH` + 1- to twice `rife.HOLE_REACH`, a square neighbourhood), as the made frame covers it (solid meaning- alpha 0.5 and over), differing on at most 5 % of the band (`rife.HOLE_AGREE`, 0.05). Of the- motions that pass for both source frames, the one whose worse source frame differs least over the- band is taken (then the one that carries more of the piece, then the smaller motion); the piece's- pixels within 4 px of where either source frame has pixels under solid along that motion are the- source frames', as in the other readings. The made frame is used only to judge each motion, by- its own coverage round its own hole; it is never used to measure a motion, and RIFE's flow is- never read. The counts for every motion are computed at once per source frame by FFT correlation,- rounded to whole counts. Motions are measured only on frames keeping a hole after the in-place- reading. Regions at least **5 px** thick (`rife.HOLE_THICK`, opened by a square that wide: a- pinhole or an antialiased crevice a pixel or two wide opens away) are taken after each step, as a- fraction of its solid pixels.+ - `hole`: of the made frame's pixels under solid (alpha under 0.5) that the outside of the picture+ cannot reach without crossing its solid body (enclosed holes), a pixel is the source frames' own+ in either of two readings, where either source frame has a pixel under solid within **4 px**+ (`rife.HOLE_REACH`, a square neighbourhood) of where that pixel lay at that frame's time: in+ place (the background, still, and a gap kept, or opened by a step where the frame showing it+ open has it); or carried with the whole figure along the motion the two source frames show for+ the whole figure. Where the made frame sits at fraction `t` from source frame a to source frame+ b, a pixel of it lay in a at `t` of the motion back and lies in b at `1 - t` of it on (rounded+ so the two are the whole motion apart). The whole figure's motion is measured only from the two+ source frames, never from the made frame or RIFE's flow: over the box round all three frames'+ solid bodies, each pixel of the box is read in a where it lay and in b where it lies, and the+ motion with the least mean absolute difference of premultiplied colour and coverage is taken+ (ties going to the smaller motion). It is followed up to 20 % of the body's height each way+ (`rife.HOLE_TRAVEL`, 0.2), searched coarse to fine: pooled in square blocks of a power of two+ where the range is at most 24 px each way (`rife.HOLE_COARSE`, 24), then within 2 px of twice+ the coarser motion on each finer level down to the pixel. Third, whatever carried it, a hole+ those two readings leave is the source frames' own, all its pixels, where it is one hole of each+ source frame: the pairing. It reads holes, not a motion. A hole here is one 8-connected piece of+ a frame's enclosed pixels: the made frame's count where they keep a pixel when opened by a 5 px+ square (`rife.HOLE_THICK`); a source frame's where they keep one opened by a 3 px square+ (`rife.HOLE_SOURCE_THICK`, 3), since a gap can be a little thinner at a source frame's time.+ Each hole is read for its area (its pixels), its centroid, its shape (the logarithms of its+ pixels' two principal second moments, each plus 1/12, over its area, so turning and growing+ leave it as it is) and the colour round it (the mean premultiplied colour of that frame's solid+ pixels from 5 to 8 px out). A hole of the made frame is paired with a hole of a and a hole of b+ where the two source frames' holes have areas within 4 times of each other+ (`rife.HOLE_PAIR_AREA`, 4.0), shapes within 2 times on each moment (`rife.HOLE_PAIR_SHAPE`, 2.0)+ and colours round them within 0.12 on each channel (`rife.HOLE_COLOUR`, 0.12, on 0 to 1), and+ their centroids lie at most sqrt(2) times the reach the figure's motion is followed (20 % of the+ body's height each way, so diagonally) plus 4 px apart; and where the made frame's hole has its+ area within 25 % of their range (`rife.HOLE_AREA`, 0.25: at least 0.75 times the smaller, at+ most 1.25 times the larger), its shape within 1.3 times of theirs on each moment+ (`rife.HOLE_SHAPE`, 1.3), the colour round it within 0.12 of each, and its centroid within 4 px+ plus 0.1 of their distance (`rife.HOLE_PATH`, 0.1) of the point at `t` on the line from the+ centroid of a's hole to that of b's. Pairs are taken one to one: each source frame's hole+ explains one hole of the made frame. The made frame's holes the first two readings already give+ the source frames are paired first, then the rest; within each, the alikest and nearest first,+ by the sum of: the logarithm of how far the made frame's hole's area is out of the range, its+ distance from the point at `t` over what it may be, how far its shape is out, the colour+ differences of the made frame's hole and of the two source frames' holes each over 0.12, and the+ two source frames' holes' distance over what it may be; ties go by the made frame's hole, then+ a's, then b's, in reading order. So a hole the made frame keeps where it was explains no other+ hole, and in a row of alike holes moving, each hole of the made frame takes the two its own way+ brings rather than a hole of one source frame and the next but one of the other, whose midpoint+ lies as near. The made frame is never used to measure a motion and RIFE's flow is never read.+ The motion and the pairing are read only on frames keeping a hole after the in-place reading,+ and the pairing only on frames keeping one after the second reading. Regions at least **5 px**+ thick (`rife.HOLE_THICK`, opened by a square that wide: a pinhole or an antialiased crevice a+ pixel or two wide opens away) are taken after each step, as a fraction of its solid pixels.- Over **0** (`interpolation_quality.HOLE_WARN`) the frame has a hole through a limb: the fault`hole`, and `auto` takes the nearer source frame there, with a line in `warnings` (it says the- frame opened a transparent hole inside its outline over the given share of its body, at least- 5 px thick, where neither source frame beside it has one, a gap through a limb, and that the+ frame opened a transparent hole inside its outline over the given share of its body, at least 5+ px thick, where neither source frame beside it has one, a gap through a limb, and that thenearer source frame was taken there); `rife` keeps it, named. A gap both source frames have,carried by the body's motion, lies in the frame between on the way from where one source framehas it to where the other has it; moved far enough it lies 5 px and more from where either- source frame has it in place, and a reading in place alone would take it for a hole and give- a correct frame way. A gap one source frame has, half open in the frame between while the figure- moves, lies beside where that frame has it in the same way. A hole both source frames have,- carried by a part over a patterned body that stays, is kept by the fourth reading: one motion- per box lets a patterned body that stays outweigh a small part moving over it (over the box round- the part's hole the body's stillness, or a motion that matches the stripes to themselves, fits- better than the part's motion, so the third reading alone would miss such a hole and give a- correct frame way), whereas the fourth reading judges every motion, and the part's motion carries- the hole in both source frames with the made frame covered round it as they are. Following the- motions keeps those gaps as the source frames' own; a gap the flow opens through a lock of hair- is read the same way as one through a leg.- - What it does not read: a band cut through a leg's edge rather than inside it reaches the- outside and is no hole (the outline readings read its edge as before); a hole within 4 px of a- gap a source frame has, in place or where the first three readings' motion carries it, is read- as that gap. A motion farther than 20 % of the body's height each way is not followed: a gap- both source frames have, carried farther between them, reads as a hole. In the first three- readings, one motion is read per box: the whole figure's, then one per piece of hole. Where- parts in the box move different ways, the motion read is the one that agrees best over the box;- a hole lying where that motion carries a gap either source frame has is read as that gap, and a- gap carried by a part that the rest of the box outweighs is left to the fourth reading, which- keeps it only where both source frames carry it and the made frame is covered round it as they- are. The fourth reading keeps only what both source frames carry. A gap only one source frame- opens (closed in the other, half open in the frame between), on a part that moves over a body- that stays, far enough that the in-place reading misses it, is given way to the nearer source- frame, whether the body is plain or patterned: the whole figure stays; the box round the gap- fits a motion that does not carry it (on a plain body, a motion that lays the box on the body- away from the part; on a patterned body, the body's stillness); and no one motion carries it in- both source frames. The reading cannot tell such a gap from a band the coverage run carried out- of one source frame's gap into a limb: at one motion both are the same shape (one source frame- open, the made frame narrower), so both are given way. A half-open gap the whole figure carries- (figure 3) is kept by the second reading.+ source frame has it in place, and a reading in place alone would take it for a hole and give a+ correct frame way. A gap one source frame has, half open in the frame between while the figure+ moves, lies beside where that frame has it in the same way. A hole both source frames have that+ a part carries, while the figure's motion does not, is kept by the pairing: a part moving over a+ body that stays, plain or patterned, a part turning, growing, sheared or swinging. No motion of+ the whole figure carries it: the body that stays outweighs the small part, and a turned or grown+ gap lies where no motion of the whole picture puts it. It is one hole of each source frame,+ alike in area, shape and the colour round it, and it lies on its way between theirs, so whatever+ carried it, it is theirs. The pairing tells the hole by what it is, not by where a motion takes+ it. Following the whole figure's motion and pairing the holes keep those gaps as the source+ frames' own; a gap the flow opens through a lock of hair is read the same way as one through a+ leg.+ - What it does not read: a band cut through a leg's edge rather than inside it reaches the outside+ and is no hole (the outline readings read its edge as before); a hole within 4 px of a hole a+ source frame has, in place or where the whole figure's motion carries it, is read as that hole,+ whatever it is: in a row of alike holes moving along the row about as far as they are apart, a+ hole more lies within 4 px of a source frame's hole in place and is read as theirs (a row of+ four holes 8 px square, 24 px apart, on a plate moving 32 px along the row). A hole the+ pairing's bounds let through is the source frames' own: one moved off its way by no more than 4+ px and 0.1 of the distance between the two source frames' holes (6 px across and 6 px along the+ way of a plate moving 48 px is 8.5 px, where 8.8 px is let through), or one larger or smaller+ than both of theirs by up to a quarter. The pairing's bounds are where a hole stops being+ theirs, and past them the frame gives way to the nearer source frame: a hole unlike both source+ frames' holes (its area more than a quarter out of the range of theirs, or its shape more than+ 1.3 times out of theirs); a hole off its way between theirs (farther from the point at `t` than+ 4 px and 0.1 of their distance, as a plate drawn 12 px across its way, or drawn where it is at t+ 0.8 in a frame made at t 0.5); two source frames' holes farther apart than sqrt(2) times the+ reach and 4 px (77.5 px on a body 260 px high: a plate whose centre moves 80 px, or one swung 60+ degrees from a point 100 px above it, its centre moving 100 px); and two source frames' holes+ whose areas differ more than 4 times (a plate grown 2.2 times as it moves). A gap only one+ source frame has, that neither the in-place reading nor the whole figure's motion carries, has+ nothing to pair with and gives way: a gap only one source frame opens (closed in the other, half+ open in the frame between) on a part moving over a body that stays, plain or patterned (pinned+ by a test). The reading cannot tell such a gap from a band the coverage run carried out of one+ source frame's gap into a limb: both show one source frame's gap and nothing in the other. Each+ source frame's hole explains one hole of the made frame: a hole more than the source frames have+ gives way, as a hole more in a row of holes, midway between two of them or past the row's end,+ or one of the row moved to a midway (figure 8). A half-open gap the whole figure carries (figure+ 3) is kept by the second reading.- Read only on the frames the alignment makes (`hole` 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 theversioned measures of `video-loop-compare` and `video-loop-repair`.@@ -1569,47 +1586,91 @@ sprite-gen video-cycle-align --loop-dir set/front-walk/loop --loop-dir set/side-in black, legs filled darker than 70/255, one source frame with legs side by side and the otherwith a gap between them) has the frame between with a band 8 px wide and 40 px tall through itsfar leg read `outline_loss` 0, `outline_shift` 11.3 %, `ghost` 0, and `hole` 2.69 % (its own 320- pixels as a share of the body); whole figure motion is 0 and the band box shows 5 px, neither- showing a gap where the band lay, so the band is read whole. The drawn frame, the arm gap moved- 3 px, a pinhole 3 px wide, and an empty frame read `hole` 0. In figure 2 (a 120 by 180 px body- with an 8 by 40 px gap, moved 0 to 32 px across and diagonally), the gap from 24 px on lies- 5 px and more from where either source frame has it in place (1.50 % in place alone), but whole- figure motion carries it: `hole` 0. In figure 3 (a body 90 px wide on legs in boots closing the- gap below), a half-open gap when moving 30 px lies 8 px and more beside where the parted frame- has it (300 px in place), but whole figure motion carries it: `hole` 0; with an 8 by 40 px band- cut through the moving body it reads `hole` 2.88 % (320 pixels) and- `faults: ["outline", "hole"]`. In figure 4 (a 200 by 180 px still body with a 40 px square part- and 14 px square hole moving 32 px), whole figure motion is 0, but motion round the hole is- 32 px, carrying it: `hole` 0. In 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 first three readings leave- the hole whole, 100 pixels or 0.28 % of the body (the whole figure's motion is 0 and the box- round the hole fits a motion that lays the stripes on themselves); the fourth carries it:- `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), the first three readings- leave a hole in 59 of these 105 frames (0.16 % to 0.47 %); moved 16, 32 and 48 px across and- diagonally at `t` 0.25 and 0.75 over the 3 px stripes at contrast 40, none. With the fourth- reading every one reads `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. In figure 6 (a torso 120 by 260 px that+ pixels as a share of the body); the whole figure's motion is 0, so neither of the first two+ readings shows a gap where the band lay; the only hole both source frames have is the gap+ between the arm and the body, which the made frame keeps where it was, so it is paired with the+ made frame's own arm gap and explains nothing else; the band is read whole. The drawn frame, the+ arm gap moved 3 px, a pinhole 3 px wide, and an empty frame read `hole` 0. In figure 2 (a 120 by+ 180 px body with an 8 by 40 px gap, moved 0 to 32 px across and diagonally), the gap from 24 px+ on lies 5 px and more from where either source frame has it in place (1.50 % in place alone),+ but whole figure motion carries it: `hole` 0. In figure 3 (a body 90 px wide on legs in boots+ closing the gap below), a half-open gap when moving 30 px lies 8 px and more beside where the+ parted frame has it (300 px in place), but whole figure motion carries it: `hole` 0; with an 8+ by 40 px band cut through the moving body it reads `hole` 2.88 % (320 pixels) and `faults:+ ["outline", "hole"]`. In figure 4 (a 200 by 180 px still body with a 40 px square part and 14 px+ square hole moving 32 px), the whole figure's motion is 0, so the first two readings leave the+ hole; it is one hole of each source frame, alike and on its way 32 px between theirs, so it is+ paired: `hole` 0. In 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 whole figure's motion is 0 and+ the in-place reading leaves the hole whole, 100 pixels or 0.28 % of the body (a motion read over+ the box round the hole would take one that lays the stripes on themselves); the hole 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, and 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 of these frames reads `hole` 0 (the moves listed in the test are those+ where a motion read over the box round the hole takes the body's stillness, or the stripes laid+ on themselves, on some pattern). 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. In figure 6 (a torso 120 by 260 px thatstays, 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 arejoined by the arm's outer side, so the gap between arm and torso, 16 by 12 px, has the torso'sedge on its left and the arm on its other three sides; the arm reaches 48 px above and 52 pxbelow 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 over the box- round it the torso's stillness fits better than the arm's motion: the first three readings read- 0.28 %, 0.55 % and 0.28 % at `t` 0.25, 0.5 and 0.75. The fourth carries it: `hole` 0, and- resampled to eight every made frame is kept, byte for byte. 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"]`.+ arm covers it in the other source frame, so the in-place reading leaves it, and the whole+ figure's motion is 0 (a motion read over the box round it would take the torso's stillness); 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. 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"]`; the second source frame has no hole on the part to pair it with. In 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 (a lighter+ colour 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, so 11 by 31 px on whole pixels); each frame between+ drawn exactly at its place in one motion from one source frame to the next: the plate's centre+ moves across, and the plate turns, grows or is sheared about it, or the plate swings from a+ point 100 px above its centre), (i) the third checkpoint validator's frame: the plate turns 60+ degrees as it moves 48 px over the stripes. No motion of the whole figure carries the turned+ gap, and the in-place reading leaves it whole, 0.55 % of the body; it is one hole of each source+ frame, alike and on its way, so it is paired: `hole` 0, and resampled to four, and to eight (`t`+ 0.25, 0.5 and 0.75 each way), every made frame is kept, byte for byte. The plate turned 90+ degrees, grown 2 times and sheared by 0.6 as it moves 48 px, and swung 45 degrees (its centre+ moving 76.5 px, within sqrt(2) times 52 plus 4, or 77.5 px, on this body), are kept the same way+ over the stripes; over the plain body each reads `hole` 0 (plain, the plate swung 45 degrees is+ given way for `smear`, a reading of its own). (ii) 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 the stripes and over the plain body at `t` 0.5, and turned as it moves over the stripes at+ `t` 0.25: all 125 frames read `hole` 0. (iii) The boundaries, over either body: the plate moving+ 48 px, drawn with its gap 16 by 40 px (1.9 times their area, where a quarter more is let+ through) it reads `hole` 1.04 %; with its gap 18 by 18 px (its larger moment 2.8 times smaller+ over its area, where 1.3 times is let through), 0.52 %; the plate drawn 12 px across its way,+ 0.55 %; the plate drawn where it is at `t` 0.8 in a frame made at `t` 0.5 (14.4 px along its+ way, where 8.8 px is let through), 0.30 %; the plate growing 2.2 times as it moves 48 px (the+ source frames' gaps more than 4 times apart in area, where 4 times is let through), 0.55 %; the+ plate moving 80 px (its centre 80 px from one source frame to the next, where 77.5 px is let+ through on this body), 0.55 %; and the plate swung 60 degrees, its centre moving 100 px, 0.55 %.+ Each frame gives way to the nearer source frame, with `hole` among its faults. In figure 8 (the+ same body with a plate 120 by 40 px on it and a row of four holes 8 px square through the plate,+ 24 px apart, the plate moving 32 px down from one source frame to the next), the frame between+ drawn exactly reads `hole` 0 and is kept as made; so is the frame between with the row drawn a+ pixel taller, where a hole of one source frame and the next but one of the other have their+ midpoint as near each of the made frame's holes as its own two: the nearer pair is taken first,+ so each hole takes its own two. Drawn with one hole more, midway between two of the row's holes,+ or between the last two, or past the row's end, or with one of the row's holes moved 12 px to a+ midway, the frame between reads `hole` 0.10 % (the 64 pixels of one hole) and gives way to the+ nearer source frame: each source frame's hole explains one hole of the made frame. Standing+ still, with the row drawn a pixel taller in the frame between, it is kept; with one hole more+ midway as well, it reads 0.10 % and gives way: the in-place reading gives the row's holes to the+ source frames, and they are paired first, so the source frames' holes are taken by the holes+ they are.- **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 07d20d0..4e2b8f5 100644--- a/sprite_gen/video/align.py+++ b/sprite_gen/video/align.py@@ -239,8 +239,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 its- silhouette that neither source frame has there, in place or carried by the motion the two show- (`rife.hole`), and judged (`faults`); `between`+ silhouette 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`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` withdiff --git a/sprite_gen/video/interpolation_quality.py b/sprite_gen/video/interpolation_quality.pyindex ee61428..79ba7f0 100644--- a/sprite_gen/video/interpolation_quality.py+++ b/sprite_gen/video/interpolation_quality.py@@ -33,10 +33,11 @@ CROSSFADE_LOOK = 0.015# passes — the overlapped wrap's frames (docs/loop-repair.md sections 2 and 4).TORN_WARN = 0.21# A made frame whose `rife.hole` is over this has a hole through a limb: a transparent hole inside its silhouette at-# least rife.HOLE_THICK pixels thick that neither neighbour has there, in place or carried by the motion the two show.-# Any is one: a gap a step opens between two legs lies where the neighbour that shows it open has it, and a gap the two-# have moved with the body lies on its way between them; both are theirs. Read only where the measure carries it — the-# frames the cycle alignment makes (docs/loop-repair.md section 4).+# least rife.HOLE_THICK pixels thick that neither neighbour has there, in place, carried by the whole figure's motion, or+# as one hole of each, alike and on its way. Any is one: a gap a step opens between two legs lies where the neighbour that+# shows it open has it, a gap the two have moved with the body lies on its way between them, and a hole each has that a+# 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.0diff --git a/sprite_gen/video/rife.py b/sprite_gen/video/rife.pyindex c0d0931..c01a192 100644--- a/sprite_gen/video/rife.py+++ b/sprite_gen/video/rife.py@@ -15,9 +15,9 @@ neighbours' rank by rank, so a mid-tone line the flow only softened is not readneighbours are outlined (`outlined`), and not on art painted without a line; `ghost` reads a band ofpart coverage on a frame alone, filmed or made; `crossfade` reads two drawings cross-faded inside awhole silhouette, a reading to look at, not a fault; `hole` reads a transparent hole a made frame opened-inside its silhouette that neither neighbour has there, in place or carried by a motion the two show —-the whole figure's, the one round the hole, or any that carries it in both and fits the made frame's-coverage round it — where the two runs disagree inside a limb (docs/loop-repair.md section 4). `passes` runs+inside 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` 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.@@ -61,7 +61,6 @@ import PILfrom PIL import Image, ImageFilter, PngImagePluginfrom sprite_gen._deps import np-from sprite_gen.video.auto_motion import _correlatefrom sprite_gen.video.frames import _components, _nearBINARY = "rife-ncnn-vulkan"@@ -106,25 +105,35 @@ OUTLINED = 0.75GHOST_THICK = 5# `hole`: a pixel under solid (alpha under 0.5) that the outside of the picture cannot reach without crossing the solid# body is a hole; a made frame's is its neighbours' where either of them is under solid within HOLE_REACH pixels of where-# it lay at that neighbour's time — in place, carried with the whole figure, or carried with what lies round it (a gap-# between an arm and the body or between two legs, kept, opened by a step or moved with them) — and counts where it makes-# a region at least HOLE_THICK pixels thick: a pinhole a pixel or two wide, an antialiased crevice, is opened away. Each-# motion is the one the two neighbours alone show (`_travel`), never the flow's, so a frame the flow got wrong is not-# judged by the flow that made it; it is followed up to HOLE_TRAVEL of the body's height, searched whole on the level-# pooled coarsely enough that this reach is at most HOLE_COARSE pixels each way, then refined down to the pixel.+# it lay at that neighbour's time — in place, or carried with the whole figure (a gap between an arm and the body or+# between two legs, kept, opened by a step or moved with them) — and counts where it makes a region at least HOLE_THICK+# pixels thick: a pinhole a pixel or two wide, an antialiased crevice, is opened away. The figure's motion is the one the+# two neighbours alone show (`_travel`), never the flow's, so a frame the flow got wrong is not judged by the flow that+# made it; it is followed up to HOLE_TRAVEL of the body's height, searched whole on the level pooled coarsely enough that+# this reach is at most HOLE_COARSE pixels each way, then refined down to the pixel.HOLE_REACH = 4HOLE_THICK = 5HOLE_TRAVEL = 0.2HOLE_COARSE = 24-# A piece of hole those motions leave is the neighbours' where both carry it by one motion within that reach, every motion-# judged (`_carried`): one motion per box lets a patterned body that stays outweigh a small part moving over it, its hole-# carried with it. Each neighbour, moved by its share of the motion, has HOLE_CARRY of the piece within HOLE_REACH of its-# transparency and covers the band HOLE_REACH + 1 to 2 HOLE_REACH pixels round the piece as the made frame covers it, all-# but HOLE_AGREE of the band; the made frame says only which motion fits round its own hole. A gap one neighbour alone-# has fits no motion in both, so it stays: a band the coverage run carried out of one neighbour's gap into a limb, and as-# well a gap only one neighbour opens, narrower in the made frame, on a part the first motions do not follow.-HOLE_CARRY = 0.9-HOLE_AGREE = 0.05+# A hole those two leave is still the neighbours' where it is one hole of each, whatever carried it — a part moving over a+# body that stays, turning, growing, sheared, swinging: told by what it is, not by a motion. Each of the made frame's+# enclosed holes (a piece of them keeping a pixel opened by HOLE_THICK) is paired with one of each neighbour's (keeping a+# pixel opened by HOLE_SOURCE_THICK, a gap a little thinner at a neighbour's time) where the three are alike and lie on+# one way (`_paired`). The neighbours' two: areas within HOLE_PAIR_AREA times of each other, shapes within HOLE_PAIR_SHAPE+# times (`_holes`: second moments over area, which turning and growing keep), the colour round them within HOLE_COLOUR,+# and no farther apart than the figure's motion reaches, diagonally, and HOLE_REACH. The made frame's: its area within+# HOLE_AREA of their range, its shape within HOLE_SHAPE times of it, the colour round it within HOLE_COLOUR of each, and+# its centroid within HOLE_REACH and HOLE_PATH of their distance of the point at its time on the line from one to the+# other. Each neighbour's hole explains one of the made frame's, the alikest and nearest taken first, and the made frame's+# holes the first two readings give the neighbours before the rest: a neighbour's hole the made frame keeps where it was+# explains no other.+HOLE_SOURCE_THICK = 3+HOLE_PAIR_AREA = 4.0+HOLE_PAIR_SHAPE = 2.0+HOLE_AREA = 0.25+HOLE_SHAPE = 1.3+HOLE_PATH = 0.1+HOLE_COLOUR = 0.12# `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'@@ -513,15 +522,6 @@ def _pooled(x: np.ndarray, f: int) -> np.ndarray:return x.reshape(x.shape[0] // f, f, x.shape[1] // f, f, x.shape[2]).mean(axis=(1, 3))-def _padded(x: np.ndarray, box: tuple[int, int, int, int], pad: int) -> np.ndarray:- """`x` over `box` (y0, y1, x0, x1) and `pad` pixels round it each way; past the picture, zero."""- y0, y1, x0, x1 = box- out = np.zeros((y1 - y0 + 2 * pad, x1 - x0 + 2 * pad) + x.shape[2:], dtype=x.dtype)- sy0, sy1, sx0, sx1 = max(0, y0 - pad), min(x.shape[0], y1 + pad), max(0, x0 - pad), min(x.shape[1], x1 + pad)- out[sy0 - y0 + pad:sy1 - y0 + pad, sx0 - x0 + pad:sx1 - x0 + pad] = x[sy0:sy1, sx0:sx1]- return out--def _apart(v: int, t: float) -> tuple[int, int]:"""Along one axis, for a motion of v pixels from a to b: where a pixel of the frame at fraction t lay in a and liesin b, from it — t of the motion back and 1 - t of it on, rounded so the two are v apart."""@@ -538,7 +538,12 @@ def _match(pa: np.ndarray, pb: np.ndarray, t: float, box: tuple[int, int, int, iy0, y1, x0, x1 = boxpad = max(abs(centre[0]), abs(centre[1])) + radius + 1h, w = y1 - y0, x1 - x0- crops = [_padded(x, box, pad) for x in (pa, pb)]+ crops = []+ for x in (pa, pb):+ crop = np.zeros((h + 2 * pad, w + 2 * pad, x.shape[2]), dtype=x.dtype)+ sy0, sy1, sx0, sx1 = max(0, y0 - pad), min(x.shape[0], y1 + pad), max(0, x0 - pad), min(x.shape[1], x1 + pad)+ crop[sy0 - y0 + pad:sy1 - y0 + pad, sx0 - x0 + pad:sx1 - x0 + pad] = x[sy0:sy1, sx0:sx1]+ crops.append(crop)best: tuple[float, int, int, int] | None = Nonefor vy in range(centre[0] - radius, centre[0] + radius + 1):ay, by = _apart(vy, t)@@ -578,82 +583,105 @@ def _moved(mask: np.ndarray, dy: int, dx: int) -> np.ndarray:return out-def _bounds(mask: np.ndarray, margin: int = 0) -> tuple[int, int, int, int]:- """The rows and columns `mask` spans (y0, y1, x0, x1), `margin` further each way inside the picture."""+def _bounds(mask: np.ndarray) -> tuple[int, int, int, int]:+ """The rows and columns `mask` spans (y0, y1, x0, x1)."""ys, xs = np.nonzero(mask)- return (max(0, int(ys.min()) - margin), min(mask.shape[0], int(ys.max()) + 1 + margin),- max(0, int(xs.min()) - margin), min(mask.shape[1], int(xs.max()) + 1 + margin))---def _pieces(mask: np.ndarray) -> list[np.ndarray]:- """The 8-connected pieces of `mask`, each a mask of its own."""- ys, starts, stops, pieces, _ = _components(mask, diagonal=True)- out = []- for piece in np.unique(pieces):- part = np.zeros_like(mask)- for y, x0, x1 in zip(ys[pieces == piece], starts[pieces == piece], stops[pieces == piece]):- part[y, x0:x1] = True- out.append(part)- return out---def _alike(box: tuple[int, int, int, int], part: np.ndarray, band: np.ndarray, solid: np.ndarray, near: np.ndarray,- covered: np.ndarray, offsets: np.ndarray) -> tuple[np.ndarray, np.ndarray]:- """One neighbour moved by each pair of `offsets` (rows, columns: where a pixel of the made frame lay in it), as a grid- over the two: the share of `part` within HOLE_REACH of its transparency (`near`), and the share of `band` where its- coverage (`covered`) is not the made frame's (`solid`). `part`, `band` and `solid` are the made frame's over `box`;- `near` and `covered` the neighbour's whole picture, past which it is neither. Each count is one correlation over- every offset at once (`_correlate`), rounded to the whole number it is."""- k = int(np.abs(offsets).max())- near_k, covered_k = (_padded(x, box, k).astype(np.float64) for x in (near, covered))- p, on, off = (x.astype(np.float64) for x in (part, band & solid, band & ~solid))- n = 2 * k + 1- carried = np.rint(_correlate(near_k, p, n, n))- differs = on.sum() - np.rint(_correlate(covered_k, on, n, n)) + np.rint(_correlate(covered_k, off, n, n))- at = np.ix_(offsets + k, offsets + k)- return carried[at] / p.sum(), differs[at] / max(1.0, on.sum() + off.sum())---def _carried(part: np.ndarray, solid: np.ndarray, a: tuple[np.ndarray, np.ndarray], b: tuple[np.ndarray, np.ndarray],- t: float, reach: int) -> tuple[int, int] | None:- """The motion (rows, columns) within `reach` each way by which both neighbours carry `part`, a piece of the hole of a- made frame at fraction `t` whose solid pixels are `solid`; each neighbour given as its pixels within HOLE_REACH of its- transparency and its solid pixels. Moved by its share of the motion (`_apart`), each neighbour has HOLE_CARRY of the- piece within HOLE_REACH of its transparency and covers the band HOLE_REACH + 1 to 2 HOLE_REACH pixels round the- piece as the made frame does, all but HOLE_AGREE of it (`_alike`). Of those motions, the one whose worse neighbour- differs least over the band, then carries more of the piece, then is the smallest; None where there is none."""- box = _bounds(part, 2 * HOLE_REACH)- window = (slice(box[0], box[1]), slice(box[2], box[3]))- inside = part[window]- band = _near(inside, 2 * HOLE_REACH) & ~_near(inside, HOLE_REACH)- v = np.arange(-reach, reach + 1)- lay, lie = np.array([_apart(int(x), t) for x in v]).T # per motion along an axis, where a pixel lay in a and lies in b- (ca, da), (cb, db) = (_alike(box, inside, band, solid[window], near, covered, offsets)- for (near, covered), offsets in ((a, lay), (b, lie)))- carry, differs = np.minimum(ca, cb), np.maximum(da, db)- iy, ix = np.nonzero((carry >= HOLE_CARRY) & (differs <= HOLE_AGREE))- if iy.size == 0:- return None- k = np.lexsort((v[iy] ** 2 + v[ix] ** 2, -carry[iy, ix], differs[iy, ix]))[0]- return int(v[iy[k]]), int(v[ix[k]])+ return int(ys.min()), int(ys.max()) + 1, int(xs.min()), int(xs.max()) + 1+++def _holes(pre: np.ndarray, thick: int) -> tuple[list[tuple[tuple[slice, slice], np.ndarray]], np.ndarray]:+ """A frame's enclosed holes (`_enclosed`, 8-connected pieces of them) that keep a pixel opened by a square `thick`+ pixels wide, its premultiplied colour and coverage given (`_premultiplied`): each hole's window, the hole's pixels+ in it and 2 HOLE_REACH + 1 pixels round them, and a row of what `_paired` reads of it — its area (pixels), its+ centroid (rows, columns), its shape (the logarithms of its pixels' two principal second moments, larger first, each+ plus a pixel's own 1/12 and over the area: turning and growing keep it) and the colour round it (the mean+ premultiplied colour of the frame's solid pixels from HOLE_REACH + 1 to 2 HOLE_REACH out, 0 where there are none)."""+ solid = pre[..., 3] >= 0.5+ enclosed = _enclosed(solid)+ ys, starts, stops, pieces, _ = _components(enclosed, diagonal=True)+ opened = np.pad(np.cumsum(_opened(enclosed, thick), axis=1, dtype=np.int64), ((0, 0), (1, 0)))+ order = np.argsort(pieces, kind="stable")+ margin = 2 * HOLE_REACH + 1+ windows, rows = [], []+ for runs in np.split(order, np.unique(pieces[order], return_index=True)[1][1:]):+ if not (opened[ys[runs], stops[runs]] > opened[ys[runs], starts[runs]]).any():+ continue+ y0, y1 = max(0, int(ys[runs].min()) - margin), min(solid.shape[0], int(ys[runs].max()) + 1 + margin)+ x0, x1 = max(0, int(starts[runs].min()) - margin), min(solid.shape[1], int(stops[runs].max()) + margin)+ mask = np.zeros((y1 - y0, x1 - x0), dtype=bool)+ for y, s0, s1 in zip(ys[runs], starts[runs], stops[runs]):+ mask[y - y0, s0 - x0:s1 - x0] = True+ window = (slice(y0, y1), slice(x0, x1))+ py, px = np.nonzero(mask)+ py, px, n = py + y0, px + x0, len(py)+ moments = (np.sort(np.linalg.eigvalsh(np.cov(np.vstack([py, px]).astype(np.float64))))[::-1] if n > 2+ else np.zeros(2))+ ring = _near(mask, 2 * HOLE_REACH) & ~_near(mask, HOLE_REACH) & solid[window]+ colour = pre[window][ring][:, :3].mean(axis=0) if ring.any() else np.zeros(3)+ windows.append((window, mask))+ rows.append([n, py.mean(), px.mean(), *np.log((moments + 1 / 12) / n), *colour])+ return windows, np.array(rows, dtype=np.float64).reshape(-1, 8)+++def _paired(made: np.ndarray, a: np.ndarray, b: np.ndarray, t: float, reach: int, first: np.ndarray) -> list[int]:+ """Which of the made frame's holes (rows of `_holes`; the frame at fraction `t` from `a` to `b`, the neighbours'+ holes) are one hole of each neighbour's. A triple is one of the made frame's holes and one of each neighbour's where+ the neighbours' two have areas within HOLE_PAIR_AREA times of each other, shapes within HOLE_PAIR_SHAPE times (on+ each moment) and the colours round them within HOLE_COLOUR (on each channel), their centroids at most sqrt(2)+ `reach` + HOLE_REACH apart (`reach`: how far the figure's motion is followed each way); and the made frame's has its+ area within HOLE_AREA of their range, its shape within HOLE_SHAPE times of theirs on each moment, the colour round it+ within HOLE_COLOUR of each, and its centroid within HOLE_REACH + HOLE_PATH of their distance of the point at `t` on+ the line from theirs in a to theirs in b. Triples are taken one to one: those of the holes `first` names before the+ rest, the alikest and nearest first — the logarithm of how far its area is out of their range, its distance from that+ point over what it may be, how far its shape is out of theirs, the two colour differences over HOLE_COLOUR and the+ neighbours' two holes' distance over what it may be, summed — then by the made frame's hole, then a's, then b's, in+ order: of a row of alike holes moving, each of the made frame's takes the two its own way brings, not a hole of one+ neighbour and the next but one of the other, whose midpoint is as near."""+ if not (len(made) and len(a) and len(b)):+ return []+ A, B = a[:, None], b[None, :]+ apart = np.hypot(B[..., 1] - A[..., 1], B[..., 2] - A[..., 2])+ near = apart / (np.sqrt(2) * reach + HOLE_REACH)+ colour = np.abs(A[..., 5:] - B[..., 5:]).max(axis=-1)+ j, k = np.nonzero((np.maximum(A[..., 0], B[..., 0]) <= HOLE_PAIR_AREA * np.minimum(A[..., 0], B[..., 0]))+ & (np.abs(A[..., 3:5] - B[..., 3:5]).max(axis=-1) <= np.log(HOLE_PAIR_SHAPE))+ & (colour <= HOLE_COLOUR) & (near <= 1))+ A, B, apart, near, colour = a[j], b[k], apart[j, k], near[j, k], colour[j, k]+ lo, hi = np.minimum(A[:, 0], B[:, 0]), np.maximum(A[:, 0], B[:, 0])+ narrow, wide = np.minimum(A[:, 3:5], B[:, 3:5]), np.maximum(A[:, 3:5], B[:, 3:5])+ at = (1 - t) * A[:, 1:3] + t * B[:, 1:3]+ triples = []+ for i, c in enumerate(made):+ area = np.where(c[0] < lo, c[0] / lo, np.where(c[0] > hi, c[0] / hi, 1.0))+ path = np.hypot(c[1] - at[:, 0], c[2] - at[:, 1]) / (HOLE_REACH + HOLE_PATH * apart)+ shape = np.maximum(0.0, np.maximum(narrow - c[3:5], c[3:5] - wide)).max(axis=-1)+ alike = np.maximum(np.abs(c[5:] - A[:, 5:]).max(axis=-1), np.abs(c[5:] - B[:, 5:]).max(axis=-1))+ cost = np.abs(np.log(area)) + path + shape + alike / HOLE_COLOUR + colour / HOLE_COLOUR + near+ for p in np.nonzero((area >= 1 - HOLE_AREA) & (area <= 1 + HOLE_AREA) & (path <= 1)+ & (shape <= np.log(HOLE_SHAPE)) & (alike <= HOLE_COLOUR))[0]:+ triples.append((not first[i], float(cost[p]), i, int(j[p]), int(k[p])))+ used: tuple[set[int], set[int], set[int]] = (set(), set(), set())+ for _, _, *triple in sorted(triples):+ if all(x not in seen for x, seen in zip(triple, used)):+ for x, seen in zip(triple, used):+ seen.add(x)+ return sorted(used[0])def hole(made: Image.Image, a: Image.Image, b: Image.Image, t: float) -> float:"""A hole a made frame at fraction `t` from `a` to `b` opened inside its silhouette that neither neighbour has there:of its pixels under solid that the outside cannot reach without crossing its solid body, those where neither- neighbour is under solid within HOLE_REACH of where the pixel lay at that neighbour's time — in place, carried with- the whole figure, or carried with what lies round the piece of hole — in regions at least HOLE_THICK pixels thick- (opened by a square that wide), as a fraction of its solid pixels. Each motion is the one the two neighbours alone- show (`_travel`, followed up to HOLE_TRAVEL of the body's height): over the box round all three frames' solid bodies,- then over the box round each piece of hole that one leaves, widened each way by as far as the piece can have lain in- the farther neighbour (max(t, 1 - t) of that reach), so the box holds a gap the neighbours carried there. A piece- those leave is theirs where both carry it by any one motion within that reach that the made frame's coverage round- the piece fits (`_carried`): a part moving over a patterned body that stays, which outweighs it in the box.+ neighbour is under solid within HOLE_REACH of where the pixel lay at that neighbour's time — in place, or carried+ with the whole figure along the motion the two neighbours alone show (`_travel`, over the box round all three+ frames' solid bodies, followed up to HOLE_TRAVEL of the body's height) — and in no hole of the made frame that is+ one of each neighbour's, whatever carried it (`_holes`, `_paired`), in regions at least HOLE_THICK pixels thick+ (opened by a square that wide), as a fraction of its solid pixels.The coverage run can carry a gap one neighbour has between two legs into a leg the colour run keeps whole: the frameshows the leg's fill on both sides of a transparent band, with no line round it, and nothing added and no part- coverage to read — and wherever the band's pixels lay, both neighbours show the leg there. A gap the neighbours have- — between an arm and the body or between two legs, kept, opened by a step, or moved with the body or the arm — is- theirs. 0 where the frame has no solid body (docs/loop-repair.md section 4)."""+ coverage to read — and wherever the band's pixels lay, both neighbours show the leg there, and neither has a hole+ like it on its way. A gap the neighbours have — between an arm and the body or between two legs, kept, opened by a+ step, or moved with the body — is theirs, and so is a hole each has, carried by a part however it moves within+ reach. 0 where the frame has no solid body (docs/loop-repair.md section 4)."""m, fa, fb = (np.asarray(f.convert("RGBA").getchannel("A"), dtype=np.float32) / 255.0 for f in (made, a, b))solid = m >= 0.5if not solid.any():@@ -664,21 +692,14 @@ def hole(made: Image.Image, a: Image.Image, b: Image.Image, t: float) -> float:pa, pb = _premultiplied(a), _premultiplied(b)rows = np.nonzero(solid.any(axis=1))[0]reach = max(1, int(round(HOLE_TRAVEL * int(rows[-1] - rows[0] + 1))))-- def theirs(v: tuple[int, int]) -> np.ndarray:- (ay, by), (ax, bx) = _apart(v[0], t), _apart(v[1], t)- return _moved(near_a, -ay, -ax) | _moved(near_b, -by, -bx)-- left = _opened(left & ~theirs(_travel(pa, pb, t, _bounds(solid | (fa >= 0.5) | (fb >= 0.5)), reach)), HOLE_THICK)- margin = int(np.ceil(max(t, 1 - t) * reach))- for part in _pieces(left):- left &= ~(part & theirs(_travel(pa, pb, t, _bounds(part, margin), reach)))- left = _opened(left, HOLE_THICK)+ (ay, by), (ax, bx) = (_apart(v, t) for v in _travel(pa, pb, t, _bounds(solid | (fa >= 0.5) | (fb >= 0.5)), reach))+ left = _opened(left & ~(_moved(near_a, -ay, -ax) | _moved(near_b, -by, -bx)), HOLE_THICK)if left.any():- for part in _pieces(left):- v = _carried(part, solid, (near_a, fa >= 0.5), (near_b, fb >= 0.5), t, reach)- if v is not None:- left &= ~(part & theirs(v))+ holes, own = _holes(_premultiplied(made), HOLE_THICK)+ first = np.array([not left[window][mask].any() for window, mask in holes], dtype=bool)+ for i in _paired(own, _holes(pa, HOLE_SOURCE_THICK)[1], _holes(pb, HOLE_SOURCE_THICK)[1], t, reach, first):+ window, mask = holes[i]+ left[window] &= ~maskleft = _opened(left, HOLE_THICK)return round(float(left.sum()) / int(solid.sum()), 5)diff --git a/tests/video/test_inbetween_hole.py b/tests/video/test_inbetween_hole.pyindex 548eb02..5b0fc23 100644--- a/tests/video/test_inbetween_hole.py+++ b/tests/video/test_inbetween_hole.py@@ -1,26 +1,30 @@# SPDX-License-Identifier: Apache-2.0"""A hole through a limb (docs/loop-repair.md section 4): `rife.hole` reads the transparent holes a made frame opened-inside its silhouette that neither source frame beside it has there, in place or carried by the motion the two show, and-the cycle alignment gives such a frame way to the nearer source frame (`--between auto`). RIFE runs a frame's colour and-its coverage apart, and the coverage run can carry the gap one source frame has between two legs into a leg the colour-run keeps whole: a transparent band through the leg with its fill on both sides. Nothing is added, no part coverage is-left, and around the band the leg's own fill is all the line there is — the outline readings judge an outline, not a-hole. A gap the source frames have is theirs wherever the motion between them carries it: kept, moved with the body or-with a part of it, or opened by a step between two legs — and a hole both source frames have, carried by a part over a-patterned body that stays, is theirs too, though the body's stillness fits the box round it better than the part's-motion. A gap only one source frame opens, on such a part, is given way: the reading does not tell it from a band the-coverage run carried out of one source frame's gap.+inside its silhouette that neither source frame beside it has there, and the cycle alignment gives such a frame way to+the nearer source frame (`--between auto`). RIFE runs a frame's colour and its coverage apart, and the coverage run can+carry the gap one source frame has between two legs into a leg the colour run keeps whole: a transparent band through the+leg with its fill on both sides. Nothing is added, no part coverage is left, and around the band the leg's own fill is+all the line there is — the outline readings judge an outline, not a hole. A hole of the frame between is the source+frames' own where either has a pixel under solid within 4 px of where it lay, in place or carried by the whole figure's+motion — a gap kept, moved with the body, or opened by a step between two legs — or where it is, whatever carried it,+one hole of each source frame: alike in area, in shape and in the colour round it, and on its way between theirs. So a+hole a part carries over a body that stays, turned, grown, sheared or swung, is theirs. Each source frame's hole is one+hole of the frame between: a hole more than they have is given way, and so is a hole unlike theirs, off its way or+farther than the figure's motion is followed, and a gap only one source frame opens on a part the figure's motion does+not carry, which the reading does not tell from a band the coverage run carried out of one source frame's gap.The fixtures are synthetic: a figure of rectangles outlined in black, legs filled dark (under the dark line, 70/255,as dark tights or boots are), the near leg over the far one; the first source frame with its legs side by side, thesecond with a gap between them, as a step opens it; a gap between the arm and the body in every frame. Then a body witha gap through it, moved whole; a figure whose legs part above boots that close the gap below, still and moving; a body-that stays with a part on it, a hole through the part, moved; the same over a body patterned in stripes or checks; and-a torso patterned in blocks with an arm beside it, the gap between them moving with the arm."""+that stays with a part on it, a hole through the part, moved; the same over a body patterned in stripes or checks; a+torso patterned in blocks with an arm beside it, the gap between them moving with the arm; a plate with a gap through it,+turned, grown, sheared or swung over a body that stays; and a plate with a row of holes."""from __future__ import annotationsimport itertools+import mathimport numpy as npimport pytest@@ -38,8 +42,8 @@ MOVES = (0, 4, 8, 12, 24, 32) # px the body with a gap moves from one source frDIM, PART = (45, 55, 60), (150, 90, 60) # the patterned body's darker colour (lighter by its contrast) and the part'sPATTERNS = ((3, 6, "v"), (2, 4, "v"), (6, 12, "v"), (3, 6, "h"), (4, 8, "c")) # stripes wide, their period, which wayCONTRASTS = (15, 40, 120)-# A part's side, its hole's, the px it moves and whether diagonally: the moves at t 0.5 where one motion per box gives the-# body's stillness the part's hole on some pattern above.+# A part's side, its hole's, the px it moves and whether diagonally: the moves at t 0.5 where a motion read over the box+# round the part's hole takes the body's stillness, or the stripes laid on themselves, on some pattern above.OUTWEIGHED = (((24, 10), 32, 0), ((24, 10), 32, 1), ((24, 10), 48, 0), ((24, 10), 48, 1), ((40, 17), 32, 0),((40, 17), 32, 1), ((60, 25), 32, 1))@@ -167,6 +171,58 @@ def _arm(dy: int) -> Image.Image:return im+def _still(plain: bool) -> np.ndarray:+ """A body that stays, 240 x 260 px on a 300 x 300 px canvas (RGBA), in stripes 3 px wide every 6 px lighter by 40,+ or plain DIM."""+ x = np.mgrid[:300, :300][1]+ rgba = np.zeros((300, 300, 4), np.uint8)+ lift = np.zeros_like(x) if plain else (x % 6 < 3) * 40+ rgba[20:280, 30:270, :3] = (np.array(DIM) + lift[..., None])[20:280, 30:270]+ rgba[20:280, 30:270, 3] = 255+ return rgba+++def _plate(t: float, *, plain: bool = False, d: float = 0.0, turn: float = 0.0, grow: float = 1.0, shear: float = 0.0,+ swing: float = 0.0, off: float = 0.0) -> Image.Image:+ """The body that stays (`_still`) with a plate on it (|u| < 24, |v| < 28 px in its own axes) and a gap through the+ plate (|u| < 6, |v| < 16), drawn exactly at time t of one motion from t 0 to t 1, half of it before t 0.5 and half+ after: the plate's centre moves d px across, and the plate turns `turn` degrees, grows `grow` times and is sheared by+ `shear` about it; or, with `swing`, the plate hangs from a point 100 px above its centre at t 0.5 and turns `swing`+ degrees about that point; `off` px lower than its way. Turned 60 degrees and moved 48 px over the stripes, it is the+ third checkpoint validator's frame."""+ y, x = np.mgrid[:300, :300].astype(np.float64)+ rgba = _still(plain)+ s = t - 0.5+ if swing:+ phi = math.radians(swing * s)+ cx, cy, theta = 150 + 100 * math.sin(phi), 40 + 100 * math.cos(phi), -phi+ else:+ cx, cy, theta = 150 + d * s, 140 + off, math.radians(turn * s)+ u = (x - cx) * math.cos(theta) + (y - cy) * math.sin(theta)+ v = -(x - cx) * math.sin(theta) + (y - cy) * math.cos(theta)+ u, v = (u - shear * s * v) / grow ** s, v / grow ** s+ rgba[(np.abs(u) < 24) & (np.abs(v) < 28)] = PART + (255,)+ rgba[(np.abs(u) < 6) & (np.abs(v) < 16)] = 0+ return Image.fromarray(rgba, "RGBA")+++def _row(t: float, *, plain: bool = False, d: int = 0, dy: int = 0, more: tuple[int, ...] = (), taller: int = 0,+ filled: tuple[int, ...] = ()) -> Image.Image:+ """The body that stays (`_still`) with a plate 120 x 40 px on it and a row of four holes 8 px square through it, 24 px+ apart (at -36, -12, 12 and 36 px from its centre), the plate moving d px across and dy px down from t 0 to t 1,+ drawn at t: the row's holes `taller` rows taller at their foot, those at the columns in `filled` left solid, and holes+ 8 px square more at the columns in `more`."""+ rgba = _still(plain)+ cx, cy = int(round(150 + d * (t - 0.5))), int(round(140 + dy * (t - 0.5)))+ rgba[cy - 20:cy + 20, cx - 60:cx + 60] = PART + (255,)+ for ox in (-36, -12, 12, 36):+ if ox not in filled:+ rgba[cy - 4:cy + 4 + taller, cx + ox - 4:cx + ox + 4] = 0+ for ox in more:+ rgba[cy - 4:cy + 4, cx + ox - 4:cx + ox + 4] = 0+ return Image.fromarray(rgba, "RGBA")++def _holed(frame: Image.Image, box: tuple[int, int, int, int]) -> Image.Image:out = frame.copy()ImageDraw.Draw(out).rectangle([box[0], box[1], box[2] - 1, box[3] - 1], fill=(0, 0, 0, 0))@@ -300,8 +356,8 @@ def test_a_gap_one_source_frame_has_half_open_between_is_theirs():def test_a_gap_moved_with_a_part_while_the_body_stays_is_theirs():"""A part with a hole through it moves 32 px across a body that stays, the frame between drawn with the parthalfway: the hole lies 5 px and more from where either source frame has it, on the way the part moves. The body- outweighs the part in the whole figure, which stays; the hole is carried with what lies round it, and the frame is- kept as made."""+ outweighs the part in the whole figure, which stays; the hole is one hole of each source frame, alike and on its way+ between theirs, and the frame is kept as made."""a, made, b = _ring(-16), _ring(0), _ring(16)assert _resampled(a, made, b) == KEPT and rife.hole(made, a, b, 0.5) == 0@@ -322,10 +378,10 @@ def test_a_hole_through_a_moving_body_is_still_read():def test_a_hole_a_part_carries_over_a_patterned_body_that_stays_is_kept_as_made():"""A part with a hole through it moves over a striped body that stays, each frame between drawn exactly at itsplace: the hole is both source frames', carried with the part. Over the box round it the body's stillness fits- better than the part's motion, which alone misses it; every motion within reach is judged, and the part's carries- the hole in both source frames with the frame between covered round it as they are. The checkpoint validator's own- frame (its 24 px part moved 32 px), resampled to four, and parts of 24, 40 and 60 px moved diagonally 32 px (and the- 24 px part 48 px) over stripes at contrast 120, resampled to eight, keep every frame made, byte for byte."""+ better than the part's motion, so a motion read there misses it; told by what it is, it is one hole of each source+ frame, alike and on its way between theirs. The checkpoint validator's own frame (its 24 px part moved 32 px),+ resampled to four, and parts of 24, 40 and 60 px moved diagonally 32 px (and the 24 px part 48 px) over stripes at+ contrast 120, resampled to eight, keep every frame made, byte for byte."""assert _resampled(_validators(-16), _validators(0), _validators(16)) == KEPTfor (part, gap), move in (((24, 10), 32), ((24, 10), 48), ((40, 17), 32), ((60, 25), 32)):@@ -355,8 +411,8 @@ def test_every_pattern_contrast_and_move_reads_no_hole_where_a_part_carries_it()def test_the_gap_between_an_arm_and_a_patterned_torso_that_stays_is_theirs():"""An arm moves 40 px down beside a torso that stays, patterned in blocks: the gap between them, carried with the arm,lies where the arm covers it in the other source frame, and over the box round it the torso's stillness fits better- than the arm's motion. Both source frames carry it on the arm's way: at t 0.25, 0.5 and 0.75 the frames between read- no hole and are kept as made."""+ than the arm's motion. It is one gap of each source frame, alike and on the arm's way between theirs: at t 0.25, 0.5+ and 0.75 the frames between read no hole and are kept as made."""assert {t: rife.hole(_arm(0), _arm(-int(np.floor(t * 40 + 0.5))), _arm(40 - int(np.floor(t * 40 + 0.5))), t)for t in (0.25, 0.5, 0.75)} == {0.25: 0.0, 0.5: 0.0, 0.75: 0.0}assert _quarters(lambda s: _arm(round(s * 40) - 20)) == QUARTERS@@ -365,13 +421,116 @@ def test_the_gap_between_an_arm_and_a_patterned_torso_that_stays_is_theirs():def test_a_gap_only_one_source_frame_opens_on_a_part_over_a_body_that_stays_is_given_way():"""The boundary: a part 30 px square moves 32 px over a body that stays, a hole 14 px square open through it in thefirst source frame and closed in the second, half open (8 px) in the frame between. The hole lies 5 px and more from- where the first frame has it in place; the whole figure stays; the box round it fits a motion that does not carry it- (over a plain body, one that lays the box on the body away from the part; over the validator's stripes, the body's- stillness); and no motion carries it in both source frames — as none carries a band the coverage run took out of one- source frame's gap into a limb. Plain or striped, the frame gives way to the nearer source frame."""+ where the first frame has it in place; the whole figure stays; and the second source frame has no hole to pair it+ with — as neither has one to pair with a band the coverage run took out of one source frame's gap into a limb. Plain+ or striped, the frame gives way to the nearer source frame."""for contrast in (0, 40):a, made, b = (_over(dx, 0, part=30, gap=gap, contrast=contrast) for dx, gap in ((-16, 14), (0, 8), (16, 0)))out, facts = align.resample([a, b], 4, lambda x, y, t: made)assert facts["made_at"] == [] and facts["nearest_at"] == [1, 3] and out[1] is b and out[3] is aassert all(m["faults"] == ["hole"] for m in facts["smear"])assert rife.hole(made, a, b, 0.5) == round(8 * 8 / int((np.asarray(made)[..., 3] >= 128).sum()), 5)+++# The third checkpoint validator's motion of the plate (`_plate`): turned 60 degrees as it moves 48 px.+TURNED = {"turn": 60, "d": 48}+# Motions of the plate whose gap no motion of the figure carries, over a body that stays: turned 90 degrees, grown twice+# and sheared by 0.6 as it moves 48 px, and swung 45 degrees, its centre moving 76.5 px — within the reach of a body+# 260 px high (sqrt(2) x 52 + 4 = 77.5 px).+MOTIONS = ({"turn": 90, "d": 48}, {"grow": 2.0, "d": 48}, {"shear": 0.6, "d": 48}, {"swing": 45})+++def test_a_hole_both_source_frames_have_on_a_turning_plate_is_kept_as_made():+ """The third checkpoint validator's frame: the plate turns 60 degrees as it moves 48 px over the stripes, the frame+ between drawn exactly halfway. No motion of the figure carries the gap, turned as it is; it is one hole of each source+ frame, alike in area, in shape and in the colour round it, and on its way between theirs. Resampled to four, both+ frames made are kept, byte for byte, and to eight (t 0.25, 0.5 and 0.75 each way) every one; so are the plate's+ other motions in MOTIONS over the stripes, and over a plain body as well each reads no hole (plain, the plate swung+ 45 degrees is given way for `smear`, a reading of its own)."""+ assert _resampled(*(_plate(s, **TURNED) for s in (0.0, 0.5, 1.0))) == KEPT+ assert _quarters(lambda s: _plate(s, **TURNED)) == QUARTERS+ assert {tuple(m.items()): _resampled(*(_plate(s, **m) for s in (0.0, 0.5, 1.0))) for m in MOTIONS} == {+ tuple(m.items()): KEPT for m in MOTIONS}+ assert {tuple(m.items()): rife.hole(_plate(0.5, plain=True, **m), _plate(0.0, plain=True, **m), _plate(1.0, plain=True, **m), 0.5)+ for m in MOTIONS} == {tuple(m.items()): 0.0 for m in MOTIONS}+++def test_every_motion_of_a_plate_within_reach_reads_no_hole():+ """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 stripes and over a plain body at t 0.5, and turned as it moves over the stripes at+ t 0.25: every frame between reads no hole."""+ motions = ([{"turn": r, "d": d} for r in (0, 10, 20, 30, 45, 60, 90) for d in (0, 24, 48)]+ + [{"grow": g, "d": d} for g in (1.1, 1.2, 1.35, 1.5, 2.0) for d in (0, 24, 48)]+ + [{"shear": h, "d": d} for h in (0.15, 0.3, 0.45, 0.6) for d in (0, 24, 48)]+ + [{"swing": w} for w in (10, 20, 30, 45)])+ seen = {}+ for m, plain in itertools.product(motions, (False, True)):+ a, made, b = (_plate(s, plain=plain, **m) for s in (0.0, 0.5, 1.0))+ seen[tuple(m.items()), plain, 0.5] = rife.hole(made, a, b, 0.5)+ for r, d in itertools.product((0, 10, 20, 30, 45, 60, 90), (0, 24, 48)):+ a, made, b = (_plate(s, turn=r, d=d) for s in (0.0, 0.25, 1.0))+ seen[(("turn", r), ("d", d)), False, 0.25] = rife.hole(made, a, b, 0.25)+ assert len(seen) == 125 and {k: v for k, v in seen.items() if v} == {}+++def _gap_drawn(plain: bool, rows: tuple[int, int], cols: tuple[int, int]) -> Image.Image:+ """The plate moving 48 px (`_plate`) drawn halfway with its gap filled and a gap cut at `rows` and `cols` instead."""+ out = np.asarray(_plate(0.5, plain=plain, d=48)).copy()+ out[124:156, 144:156] = PART + (255,)+ out[rows[0]:rows[1], cols[0]:cols[1]] = 0+ return Image.fromarray(out, "RGBA")+++def _given_way(a: Image.Image, made: Image.Image, b: Image.Image) -> bool:+ """Resampled to four, both frames made at t 0.5 are `made`, given way to the nearer source frame with `hole` among+ their faults."""+ out, facts = align.resample([a, b], 4, lambda x, y, t: made)+ return (facts["made_at"] == [] and facts["nearest_at"] == [1, 3] and out[1] is b and out[3] is a+ and all("hole" in m["faults"] and m["hole"] > 0 for m in facts["smear"]))+++def test_a_hole_unlike_the_source_frames_or_off_its_way_or_out_of_reach_is_given_way():+ """The boundaries, on the plate moving 48 px over a body that stays, plain or striped, its gap 11 x 31 px in both+ source frames: the frame between gives way to the nearer source frame where its gap is unlike theirs — drawn 16 x 40 px+ (1.9 times their area; rife.HOLE_AREA lets it be a quarter larger) or 18 x 18 px (its larger moment 2.8 times smaller+ over its area; rife.HOLE_SHAPE lets it be 1.3 times) — or off its way between theirs: the plate drawn 12 px across it,+ or where it is at t 0.8 in a frame made at t 0.5, 14.4 px along it (rife.HOLE_REACH + rife.HOLE_PATH of their 48 px+ apart lets it be 8.8 px); where the source frames' gaps are unlike each other, the plate growing 2.2 times as it+ moves (their areas more than rife.HOLE_PAIR_AREA, 4 times, apart); and where they lie farther apart than the figure's+ motion is followed (sqrt(2) x 52 + 4 = 77.5 px on a body 260 px high), the plate moving 80 px, or swinging 60 degrees,+ its centre moving 100 px."""+ seen = {}+ for plain in (False, True):+ a, b = _plate(0.0, plain=plain, d=48), _plate(1.0, plain=plain, d=48)+ for name, made in (("area", _gap_drawn(plain, (120, 160), (142, 158))), ("shape", _gap_drawn(plain, (131, 149), (141, 159))),+ ("across", _plate(0.5, plain=plain, d=48, off=12)), ("along", _plate(0.8, plain=plain, d=48))):+ seen[name, plain] = _given_way(a, made, b)+ for name, motion in (("pair area", {"grow": 2.2, "d": 48}), ("reach", {"d": 80}), ("swing", {"swing": 60})):+ seen[name, plain] = _given_way(*(_plate(s, plain=plain, **motion) for s in (0.0, 0.5, 1.0)))+ assert seen == {k: True for k in seen}+++def test_each_hole_of_a_source_frame_is_one_hole_of_the_frame_between():+ """A plate with a row of four holes (`_row`) moves 32 px down over a body that stays, plain or striped: the frame+ between drawn exactly is kept as made, and so is one with the row drawn a pixel taller, where a hole of one source+ frame and the next but one of the other have their midpoint as near each hole as its own two: the nearer pair is+ taken first. Drawn with one hole more midway between two of the row's — where one source frame's hole and the next+ one of the other would put it — or past the row's end, or with one of the row's moved 12 px to a midway, it gives way+ to the nearer source frame: each source frame's hole is one hole of the frame between, and each of the row's is taken+ by the hole it is. Standing still, the row drawn a pixel taller: the in-place reading gives the row its source frames'+ holes, which are paired with it before the hole more, so one more hole midway still gives way."""+ seen = {}+ for plain in (False, True):+ a, b = _row(0.0, plain=plain, dy=32), _row(1.0, plain=plain, dy=32)+ seen["row", plain] = _resampled(a, _row(0.5, plain=plain, dy=32), b) == KEPT+ seen["a pixel taller", plain] = _resampled(a, _row(0.5, plain=plain, dy=32, taller=1), b) == KEPT+ for name, made in (("midway", _row(0.5, plain=plain, dy=32, more=(0,))),+ ("between the last two", _row(0.5, plain=plain, dy=32, more=(24,))),+ ("past the end", _row(0.5, plain=plain, dy=32, more=(54,))),+ ("moved to a midway", _row(0.5, plain=plain, dy=32, more=(0,), filled=(12,)))):+ seen[name, plain] = _given_way(a, made, b)+ still = _row(0.0, plain=plain)+ seen["still, a pixel taller", plain] = _resampled(still, _row(0.5, plain=plain, taller=1), still) == KEPT+ seen["still, a pixel taller, one more midway", plain] = _given_way(still, _row(0.5, plain=plain, taller=1, more=(0,)), still)+ assert seen == {k: True for k in seen}