Skip to content

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 the in-place and whole-figure readings give the source frames takes no pair, and a group every hole of which can pair is paired whole — rife.hole passes rife._paired only the made frame's holes those two readings leave (its `first` argument and the branch it fed in rife._taken and rife._searched, which made such holes pair before the rest, are gone), so a hole kept in place no longer takes the only pair of a hole moving beside it; each group of triples is searched first for a set pairing every hole (rife._whole: depth first from the hole with the fewest free triples, cut where a hole left has none or where the holes left cannot each keep a hole of a, or of b, of their own, rife._matched), and, where there is none or that search runs past rife.HOLE_PAIR_STEPS, for the set pairing the most, then of least cost, as before (rife._searched); the fifth checkpoint validator's hole kept in place beside a hole moving 70.8 px is kept as made, as are a column whose middle hole one source frame shuts, a row standing still or carried whole with one hole more midway and a narrow gap's twin within its way, holes definition (a) gives the source frames, while a hole more among the holes left still gives way

Soohong Kim7aed833f9b30
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5cfc675..f05fce7 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 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 explains one hole of the made frame, and no hole of any frame is in two pairs taken. Every hole the first two readings already give that has a pair must be paired: of sets pairing those holes, the set taken pairs the most of the other holes, and of those, the one with least summed cost; so a hole kept where it was explains no other, and alike holes moving together each keep their own two. Where no set pairs every one of the holes the first two readings give, one of them is a hole more than the source frames have, and none of the other holes in that group is paired. An exact search finds the set within groups of pairs sharing a hole, taking at most 5000 steps per group (`rife.HOLE_PAIR_STEPS`, 5000), past which a group pairs none of its holes and the frame gives way to the nearer source frame. 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.
+- **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: no hole of any frame is in two pairs taken, so each source frame's hole explains one of the holes paired. A hole of the made frame that the first two readings give the source frames takes no pair, being theirs already, and the pairing reads only the holes those readings leave: of the sets of pairs that can be taken together, the set taken pairs the most holes, and of those, has the least summed cost (the same frames always giving the same set), so alike holes moving together each keep their own two. Pairs sharing a hole form a group, read apart: an exact search first asks whether one set pairs every hole of the group, cutting branches where the holes left cannot each keep a hole of each source frame of their own; where it finds one, every hole of the group is paired, and where there is none, a second exact search finds the set pairing the most. Each search takes at most 5000 steps per group (`rife.HOLE_PAIR_STEPS`, 5000): where the first runs past them, the second runs; a group whose second search runs past them pairs none of its holes, and the frame gives way to the nearer source frame. 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_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), `rife.HOLE_COLOUR` (0.12), and `rife.HOLE_PAIR_STEPS` (5000); 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. Figure 9: on the same striped body, a plate with a row of two, three or four holes 8 px square, 12 px apart, moving on a curved way, int(40 t + 20 t (1 - t)) px across and int(32 t) px down at time t, the plate moving with the holes or staying while they move through it (with two holes it is the fourth checkpoint validator's frame): the frame between drawn exactly reads `hole` 0 and is delivered as in 3.1.0, both made cells byte for byte, for two, three and four holes, the plate moving or staying; with one hole more before the row, or with the row's last hole shut in the second source frame, it reads 0.10 % and gives way to the nearer source frame. Figure 10: on the same striped body, a plate 40 by 90 px with a column of three holes 8 px square, 24 px apart, moving 32 px down, the middle hole shut in the second source frame: the frame between drawn exactly (one hole more than the second source frame has) reads `hole` 0.10 % and gives way to the nearer source frame, where 3.1.0 delivered it. 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. Figure 9: the striped body (240 by 260 px that stays, stripes 3 px wide every 6 px) with a plate on it and a row of two, three or four holes 8 px square, 12 px apart, through the plate, moving on a curved way from one source frame to the next, int(40 t + 20 t (1 - t)) px across and int(32 t) px down at time t; the plate moves with the holes or stays while they move through it. With two holes it is the fourth checkpoint validator's frame. One test checks that, resampled to four, the frame between drawn exactly keeps both made frames as made, for two, three and four holes, the plate moving or staying. Figure 10: the same striped body with a plate 40 by 90 px on it and a column of three holes 8 px square, 24 px apart, through the plate, the plate moving 32 px down from one source frame to the next. A boundary test checks that, with two and four holes, the plate moving or staying, a frame between with one hole more before the row, and a frame between whose second source frame has the row's last hole shut, give both made cells way to the nearer source frame with `hole` among their faults; that the frame between of figure 10, with the middle hole shut in the second source frame, gives both made cells way to the nearer source frame with `hole` among their faults; and that with `rife.HOLE_PAIR_STEPS` set to one step, the frame between of two holes gives both made cells way as well.
+- Output changes: an alignment whose made frame has an enclosed hole 5 px thick or more that neither source frame beside it has within 4 px, in place, carried by the whole figure's motion, or paired with one hole of each source frame as above, now delivers the nearer source frame at that cell instead of the made frame, and counts it in `replaced` and `nearest_at` rather than `made_by_rife` and `made_at`. Made frames without such a hole, and frames whose holes the source frames have, in place, carried or paired, are delivered as in 3.1.0 with the same bytes; the report gains `hole` on every made frame. Synthetic numbers (the figure of the tests below): the frame between with a band 8 px wide and 40 px tall through its far leg reads `outline_loss` 0, `outline_shift` 11.3 % (so no `outline` fault, which needs both over 5 %), `ghost` 0, and `hole` 2.69 %; in 3.1.0 it is kept, now the nearer source frame is taken. The frame drawn between, the same with the arm's gap moved 3 px, and the same with a pinhole 3 px wide through the leg read `hole` 0 and are kept. A frame whose hole both source frames have, carried by a part (moving over a body that stays, plain or patterned, turning, growing, sheared or swinging within reach), is delivered as in 3.1.0 with the same bytes. Figure 5: a body that stays, patterned, with a part on it and a hole through the part's middle, the part moved from one source frame to the next, each frame between drawn exactly at its place. (i) The checkpoint validator's frame: a body 200 by 180 px with stripes 3 px wide every 6 px (a lighter colour by 40 levels), on a 260 by 220 px canvas, a part 24 px square with a hole 10 px square, moved 32 px across: the in-place reading leaves the hole whole, 100 pixels or 0.28 % of the body, and the whole figure's motion is 0; it is one hole of each source frame, alike and on its way, so it is paired: `hole` 0, and both made cells are kept as made, byte for byte. (ii) A body 240 by 260 px on a 300 by 300 px canvas in five patterns (stripes 3, 2 and 6 px wide every 6, 4 and 12 px running up and down; stripes 3 px wide every 6 px running across; checks 4 px square) at contrasts 15, 40 and 120, parts 24, 40 and 60 px square with holes 10, 17 and 25 px square: moved 32 and 48 px across and diagonally at t 0.5 (the moves listed in the test), these frames, and the same three parts moved 16, 32 and 48 px across and diagonally at t 0.25 and 0.75 over the 3 px stripes at contrast 40, every one read `hole` 0. Resampled to eight frames (t 0.25, 0.5 and 0.75 each way), parts of 24, 40 and 60 px moved 32 px diagonally and the 24 px part moved 48 px over stripes at contrast 120 keep every made frame, byte for byte. Figure 6: a torso 120 by 260 px that stays, patterned in blocks 4 px square each lighter by its own whole number up to 200 levels, with an arm beside its right edge: the upper arm and the forearm lie along that edge and are joined by the arm's outer side, so the gap between arm and torso, 16 by 12 px, has the torso's edge on its left and the arm on its other three sides; the arm reaches 48 px above and 52 px below the gap and moves 40 px down from one source frame to the next. The gap lies where the arm covers it in the other source frame, so the in-place reading leaves it, and the whole figure's motion is 0; it is one gap of each source frame, alike and on the arm's way, so it is paired: `hole` 0 at t 0.25, 0.5 and 0.75, and resampled to eight every made frame is kept, byte for byte. A frame with a gap only one source frame opens, on a part moving over a body that stays, plain or patterned, which neither the in-place reading nor the whole figure's motion carries and which has no hole in the other source frame to pair with, gives way to the nearer source frame where 3.1.0 kept it. The boundary, pinned by a test: a part 30 px square moving 32 px across a body that stays, a hole 14 px square open through it in one source frame and closed in the other, 8 px square in the frame between (half open): over a plain body and over the 3 px stripes alike it reads `hole` 0.10 % (its 64 pixels) and both made cells are given way to the nearer source frame, with `faults: ["hole"]`. Figure 7: the plate of the tests (a body 240 by 260 px that stays, striped or plain, with a plate on it and a gap through the plate, 11 by 31 px, each frame between drawn exactly at its place). The third checkpoint validator's frame, the plate turning 60 degrees as it moves 48 px over the stripes, reads `hole` 0 and is delivered as in 3.1.0, both made cells byte for byte, resampled to four and to eight; so are the plate turned 90 degrees, grown 2 times and sheared by 0.6 as it moves 48 px, and swung 45 degrees, over the stripes, and 125 such frames read `hole` 0. A frame between with a hole unlike both source frames' (the gap drawn 16 by 40 px: `hole` 1.04 %; drawn 18 by 18 px: 0.52 %; the plate growing 2.2 times as it moves 48 px, the source frames' gaps more than 4 times apart in area: 0.55 %), off its way (the plate drawn 12 px across it: 0.55 %; drawn where it is at t 0.8 in a frame made at t 0.5: 0.30 %), or out of reach (the plate swung 60 degrees, its centre moving 100 px, where 77.5 px is let through on this body: 0.55 %; the plate moving 80 px: 0.55 %) gives way to the nearer source frame with `hole` among its faults. Figure 8: the plate 120 by 40 px with a row of four holes 8 px square, 24 px apart, moving 32 px down: the frame between drawn exactly, and with the row a pixel taller, read `hole` 0 and are delivered as in 3.1.0; with one hole more (midway between two, between the last two, past the end, or one of the row moved to a midway) it reads 0.10 % and gives way to the nearer source frame. Figure 9: on the same striped body, a plate with a row of two, three or four holes 8 px square, 12 px apart, moving on a curved way, int(40 t + 20 t (1 - t)) px across and int(32 t) px down at time t, the plate moving with the holes or staying while they move through it (with two holes it is the fourth checkpoint validator's frame): the frame between drawn exactly reads `hole` 0 and is delivered as in 3.1.0, both made cells byte for byte, for two, three and four holes, the plate moving or staying; with one hole more before the row, or with the row's last hole shut in the second source frame, it reads 0.10 % and gives way to the nearer source frame. Figure 10: on the same striped body, a plate 40 by 90 px with a column of three holes 8 px square, 24 px apart, moving 32 px down, the middle hole shut in the second source frame: the frame between drawn exactly reads `hole` 0 and is delivered as in 3.1.0: its middle hole, one more than the second source frame has, lies against holes of both source frames and the in-place reading takes it for theirs; the last hole pairs with its own two. Figure 11: on the same striped body, a plate 105 px square with a hole 8 px square that the first source frame and the frame between have in place and the second source frame shuts, beside a hole moving 52 px across and 48 px down, drawn at its exact midpoint 10 px from the first (the fifth checkpoint validator's frame): the frame between reads `hole` 0 and is delivered as in 3.1.0, both made cells byte for byte, and so with the hole in place kept by the second source frame instead. Figure 12: a body 200 by 260 px outlined in black on a 400 by 400 px canvas, moving whole, with holes through it; what the reading does not tell: the body moving 32 px down with a row of four holes 8 px square, 24 px apart, and one hole more midway between the middle two reads `hole` 0 and is delivered as in 3.1.0 (so is figure 8's row standing still, drawn a pixel taller, with one hole more midway); moving 48 px across and 48 px down with a gap 5 by 30 px and one gap more 10 px beside it in the frame between, it reads `hole` 0 and gives way for `outline`, as in 3.1.0; with the gap more 11 px beside, and a gap 8 px wide with its twin 13 px beside it, they read `hole` 0.29 % and 0.45 % and give way as in 3.1.0, now with `hole` among their faults besides `outline`. The jump repair of `video-loop`, its eased retime and overlapped wrap, `video-loop-compare`, and `video-loop-repair` do not read `hole`; their measures and outputs are as in 3.1.0. A `--between-cache` directory written by 3.1.0 is not taken from by this version: the code of `rife.py` is part of what a kept frame is keyed by, so those frames are made again.
+- **Tests**: new `tests/video/test_inbetween_hole.py`, synthetic only: figure 1 (a 160 by 200 px figure of rectangles outlined in black, legs filled darker than 70/255, the near leg drawn over the far one, an arm joined to the body above and below with an 8 px gap between them in every frame; one source frame with its legs side by side, the other with a gap between them) checks that the band through the far leg reads as a hole over exactly its own 320 pixels as a share of the solid body, and the drawn frame, the arm's gap, that gap moved 3 px, a 3 px pinhole and an empty frame read 0; that the readings before this one pass the band (`outline_loss` 0, `outline_shift` over 5 %, `dark_excess` below 0, `ghost` 0, `partial_excess` 0, no fault) and that with `hole` the fault is `["hole"]`; that resampling the two frames to four under `--between auto` takes the nearer source frame at both made cells (cells 1 and 3) with the fault named in the warning words, while `--between rife` keeps them named; and that the clean frame and the frame with the moved arm gap are delivered as the very frame made. Figure 2 (a body 120 by 180 px of one colour with a gap 8 by 40 px through it, on a 240 by 220 px canvas, moved whole from one source frame to the next by 0, 4, 8, 12, 24 and 32 px, across and diagonally) checks that at every move it is resampled to four with both made cells delivered as the very frame made, no fault, and reads `hole` 0, each source frame moved half the way giving the frame between byte for byte. Figure 3 (a body 90 px wide over two legs 24 px wide, each standing in a boot that reaches under the other leg, so a gap a step opens between the legs is closed by the boots below; in one source frame the legs touch, in the other they are parted), still and moving 30 px between source frames, is kept the same way and reads 0; and moving with an 8 by 40 px band through its body, it reads exactly its 320 pixels as a share of the solid body, in either order of the source frames, with both made cells given way to the nearer source frame and `hole` among their faults. Figure 4 (a body 200 by 180 px of one colour that stays, with a part on it 40 px square and a hole 14 px square through the part, the part moving 32 px from one source frame to the next) is kept the same way and reads 0. Figure 5 (a body that stays, patterned, with a part on it and a hole through the part's middle, the part moved from one source frame to the next, each frame between drawn exactly at its place: the checkpoint validator's frame with a body 200 by 180 px with stripes 3 px wide every 6 px, a lighter colour by 40 levels, on a 260 by 220 px canvas, a part 24 px square with a hole 10 px square, moved 32 px across; and a body 240 by 260 px on a 300 by 300 px canvas in five patterns, stripes 3, 2 and 6 px wide every 6, 4 and 12 px running up and down, stripes 3 px wide every 6 px running across, and checks 4 px square, at contrasts 15, 40 and 120, parts 24, 40 and 60 px square with holes 10, 17 and 25 px square): figure 5's validator frame resampled to four, and its parts of 24, 40 and 60 px moved 32 px diagonally and the 24 px part moved 48 px over stripes at contrast 120 resampled to eight, keep every made frame as made; the wide grid of figure 5 (every pattern and contrast at each listed move at t 0.5, and the three parts moved 16, 32 and 48 px at t 0.25 and 0.75) reads `hole` 0 and is marked slow, so it runs with `pytest --full`. Figure 6 (a torso 120 by 260 px that stays, patterned in blocks 4 px square each lighter by its own whole number up to 200 levels, with an arm beside its right edge: the upper arm and the forearm lie along that edge and are joined by the arm's outer side, so the gap between arm and torso, 16 by 12 px, has the torso's edge on its left and the arm on its other three sides; the arm reaches 48 px above and 52 px below the gap and moves 40 px down from one source frame to the next) reads `hole` 0 at t 0.25, 0.5 and 0.75 and keeps every made frame resampled to eight. The boundary test (a part 30 px square moving 32 px across a body that stays, a hole 14 px square open through it in one source frame and closed in the other, 8 px square in the frame between) checks that the half-open gap on the moving part, over a plain body and over the stripes, reads its 64 pixels as a share of the body and gives both made cells way to the nearer source frame with `faults: ["hole"]`. Figure 7: a body 240 by 260 px on a 300 by 300 px canvas that stays, in stripes 3 px wide every 6 px (lighter by 40 levels) or plain, with a plate on it (|u| < 24 and |v| < 28 px in its own axes) and a gap through the plate (|u| < 6, |v| < 16), each frame between drawn exactly at its place in one motion: the plate's centre moving across as the plate turns, grows or is sheared about it, or the plate swinging from a point 100 px above its centre. One test checks that the third checkpoint validator's frame (the plate turning 60 degrees as it moves 48 px over the stripes), resampled to four, keeps both made frames as made, and resampled to eight (t 0.25, 0.5 and 0.75 each way) every one; that the plate turned 90 degrees, grown 2 times and sheared by 0.6 as it moves 48 px, and swung 45 degrees, resampled to four over the stripes, keep both made frames; and that over the plain body each of these reads `hole` 0. A test marked slow (it runs with `pytest --full`) checks that 125 frames read `hole` 0: the plate turned 0 to 90 degrees, grown 1.1 to 2 times or sheared by 0.15 to 0.6 as it moves 0, 24 or 48 px, or swung 10 to 45 degrees, over both bodies at t 0.5, and turned as it moves over the stripes at t 0.25. A boundary test checks that, on the plate over either body, a frame between with its gap drawn 16 by 40 px or 18 by 18 px, with the plate drawn 12 px across its way or where it is at t 0.8 in a frame made at t 0.5, with the plate growing 2.2 times as it moves 48 px (the source frames' gaps more than 4 times apart in area), with the plate moving 80 px, and with the plate swung 60 degrees, gives both made cells way to the nearer source frame with `hole` among their faults. Figure 8: the same body with a plate 120 by 40 px on it and a row of four holes 8 px square, 24 px apart, through the plate. Its test checks that, the plate moving 32 px down over either body, the frame between drawn exactly and the same with the row a pixel taller keep both made frames as made; that with one hole more midway between two of the row's, between the last two, past the row's end, or with one of the row's moved 12 px to a midway, both made cells give way to the nearer source frame with `hole` among their faults; and that, the plate standing still, the row drawn a pixel taller keeps both made frames. Figure 9: the striped body (240 by 260 px that stays, stripes 3 px wide every 6 px) with a plate on it and a row of two, three or four holes 8 px square, 12 px apart, through the plate, moving on a curved way from one source frame to the next, int(40 t + 20 t (1 - t)) px across and int(32 t) px down at time t; the plate moves with the holes or stays while they move through it. With two holes it is the fourth checkpoint validator's frame. One test checks that, resampled to four, the frame between drawn exactly keeps both made frames as made, for two, three and four holes, the plate moving or staying. Figure 10: the same striped body with a plate 40 by 90 px on it and a column of three holes 8 px square, 24 px apart, through the plate, the plate moving 32 px down from one source frame to the next. A boundary test checks that, with two and four holes, the plate moving or staying, a frame between with one hole more before the row, and a frame between whose second source frame has the row's last hole shut, give both made cells way to the nearer source frame with `hole` among their faults; and that with `rife.HOLE_PAIR_STEPS` set to one step, both searches (the search for a set pairing every hole, and the search for the set pairing the most) run past it and the frame between of two holes gives both made cells way as well. Figure 11: the striped body with a plate 105 px square on it, through it a hole 8 px square that the first source frame and the frame between have in place and the second source frame shuts, beside a hole moving 52 px across and 48 px down, drawn at its exact midpoint 10 px from the first; the fifth checkpoint validator's frame. Its test checks that, resampled to four, both made frames are kept as made, and so with the hole in place kept by the second source frame instead. Figure 12: a body 200 by 260 px outlined in black on a 400 by 400 px canvas, moving whole, with holes through it. Its test pins what the reading does not tell: it checks that the body moving 32 px down with a row of four holes 8 px square, 24 px apart, and one hole more midway between the middle two keeps both made frames as made, and so do figure 8's row standing still, drawn a pixel taller, with one hole more midway, and figure 10's frame with the middle hole shut in the second source frame; that, the body moving 48 px across and 48 px down with a gap 5 by 30 px, one gap more 10 px beside it in the frame between reads `hole` 0 from either source frame to the other; and that the gap more 11 px beside, and a gap 8 px wide with its twin 13 px beside it, give both made cells way with `hole` among their faults. The test on triples alone: twenty alike holes, each with its own two holes and up to five more pairs near its own at seeded random costs. It checks that all twenty are paired, and that none is where the search for a set pairing every hole runs past the steps (the search for the set pairing the most runs past them on this group).
## v3.1.0 - Walk and run loop gates for held animation and seam pops, size hold for fixed cuts, talking face layer and default chroma decontamination
diff --git a/docs/loop-repair.md b/docs/loop-repair.md
index 38cc4d7..95efab6 100644
--- a/docs/loop-repair.md
+++ b/docs/loop-repair.md
@@ -1518,36 +1518,45 @@ sprite-gen video-cycle-align --loop-dir set/front-walk/loop --loop-dir set/side-
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. No hole of any frame is in two pairs taken; every hole of
- the made frame that the first two readings (in place, and carried with the whole figure) already
- give the source frames, and that has a pair at all, must be paired too. Of all sets pairing
- those holes, the set taken pairs the most of the other holes; of those, the one with the least
+ centroid of a's hole to that of b's. The pairing reads only the made frame's holes that the
+ first two readings (in place, and carried with the whole figure) leave, that is, holes keeping a
+ pixel those two readings do not give the source frames. A hole every pixel of which those two
+ readings give the source frames takes no pair: it is theirs already, whichever of their holes it
+ lies by. Pairs are taken one to one: no hole of the made frame, of a or of b is in two pairs
+ taken, so each source frame's hole explains one of the holes paired. Of all sets of pairs that
+ can be taken together, the set taken pairs the most holes; of those, the one with the least
summed cost. The same frames always give the same set. The cost of a pair is the sum of: the
logarithm of how far the made frame's hole's area is out of the range of the two source frames'
holes' areas, 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. So a hole the made frame
- keeps where it was explains no other hole, since it must be paired itself; and alike holes
- moving together each keep their own two holes, however near their ways run. Pairs that share a
- hole form a group, searched apart by an exact depth first search from the hole with the fewest
- pairs still free, trying each pair, cheapest first (or leaving a hole not given by the first two
- readings unpaired); groups whose holes the first two readings already give are not searched,
- branches leaving one of those holes unpaired or unable to beat the best set found are cut, and
- the search stops at a set pairing every hole. At most 5000 steps are taken per group
- (`rife.HOLE_PAIR_STEPS`, 5000), past which a group pairs none of its holes and the frame gives
- way to the nearer source frame; a row or grid of alike holes that all pair takes about a step
- per hole (a grid of 100 holes, 101 to 106 steps), and on the synthetic frames only grids of 16
- to 100 holes, 16 px apart, with one hole shut in one source frame, run past it, which give way
- in any case. Where no set pairs every hole the first two readings give, one of the first two
- readings' holes is then a hole more than the source frames have, which those readings took for
- theirs because it lies within 4 px of where another hole is; then none of the other holes in
- that group is paired (figure 10). 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.
+ 0.12, and the two source frames' holes' distance over what it may be. So alike holes moving
+ together each keep their own two holes, however near their ways run. Pairs that share a hole,
+ directly or through other pairs, form a group, searched apart. First an exact depth first search
+ asks whether one set pairs every hole of the group: from the hole with the fewest pairs still
+ free, it tries each of that hole's free pairs, cheapest first, and leaves no hole unpaired; it
+ cuts a branch where a hole left has no free pair, or where the holes left cannot each keep a
+ hole of a, or a hole of b, of its own among the holes their free pairs hold (a bipartite
+ matching, checked for each source frame). Where it finds such a set, every hole of the group is
+ paired. Where that search ends without such a set, a second exact depth first search finds the
+ set pairing the most: from the hole with the fewest pairs still free, it tries each free pair
+ cheapest first and then leaving the hole unpaired; it cuts branches that cannot pair more holes
+ than the best set found, or as many at no less cost, and stops at a set pairing every hole. Each
+ search takes at most 5000 steps per group (`rife.HOLE_PAIR_STEPS`, 5000). Where the first runs
+ past them, the second runs; a group whose second search runs past them pairs none of its holes,
+ and the frame gives way to the nearer source frame. Where every hole of a row or grid of alike
+ holes pairs, the first search takes one step per hole and one more (a grid of 196 holes, 197
+ steps). On the synthetic frames no group runs past 5000 steps; the most taken is 258, by the
+ second search, on a grid of 36 holes 24 px apart one of whose holes a source frame shuts (that
+ frame gives way in any case). On random groups of 8 to 96 alike holes, each with its own two
+ holes and up to five more pairs within three places of its own, at random costs, the second
+ search alone runs past 5000 steps before finding a set pairing all of them on 651 of 4000
+ groups, and such a frame would give way though every hole has its own two; with the first search
+ before it, on 17. That remaining case is a named bound of the reading. 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
@@ -1572,28 +1581,45 @@ sprite-gen video-cycle-align --loop-dir set/front-walk/loop --loop-dir set/side-
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
+ four holes 8 px square, 24 px apart, on a plate moving 32 px along the row); and in a column of
+ three holes 8 px square, 24 px apart, on a plate moving 32 px down, the middle hole shut in the
+ second source frame, in the frame between the middle hole lies against holes of both source
+ frames, so the in-place reading reads it as theirs, though it is one hole more than the second
+ source frame has (the last hole pairs with its own two; the frame between is kept: figure 10). 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.
+ source frame's gap into a limb: both show one source frame's gap and nothing in the other. The
+ pairing reads only the holes the first two readings leave. Among them each source frame's hole
+ explains one: a hole more than the source frames have among them gives way, as a hole more in a
+ row of holes moving with their plate, midway between two of them or past the row's end, or one
+ of the row moved to a midway (figure 8). A hole more than the source frames have, left by the
+ first two readings, is read as theirs where it pairs with one source frame's hole and the
+ other's alike hole whose own holes in the frame between the first two readings already give the
+ source frames (those holes take no pair, so their source holes are free for it). One more midway
+ between two holes of a row standing still, or of a row the whole figure carries, lies where one
+ source frame's hole and the other's next one put it, and pairs with them (figure 12; and figure
+ 8's row standing still, drawn a pixel taller, with one hole more midway). A twin of a gap the
+ whole figure carries pairs with the gap's own two where it lies within the gap's way; being 5 px
+ or more from the gap (or the second reading would take it for the gap), it needs the gap's width
+ and 5 px to be within 4 px and 0.1 of how far the gap moves, so only a narrow gap moving far has
+ one: a gap 5 px wide moving 67.9 px (48 px across and 48 down), its twin 10 px beside it; 11 px
+ beside, it gives way, and a gap 8 px wide with its twin 13 px beside it gives way (figure 12).
+ On that frame the outline readings give the frame way, readings of their own. 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 the
versioned measures of `video-loop-compare` and `video-loop-repair`.
@@ -1602,121 +1628,160 @@ sprite-gen video-cycle-align --loop-dir set/front-walk/loop --loop-dir set/side-
with a gap between them) has the frame between with a band 8 px wide and 40 px tall through its
far 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); 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 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 (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 pairing takes the set that
- pairs the most holes, so each hole keeps 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. In figure 9 (the same body with a plate on it and a row of two,
- three or four holes 8 px square through the plate, 12 px apart, moving on a curved way from one
- source frame (t 0) to the next (t 1): int(40 t + 20 t (1 - t)) px across and int(32 t) px down
- at time t, the plate moving with the holes, or staying while the holes move through it; with two
- holes it is the fourth checkpoint validator's frame), the frame between is drawn exactly, at t
- 0.5: each of its holes lies 5 px beside the midpoint of where the two source frames have that
- hole; 4 px and 0.1 of their distance (51 px), 9.1 px in all, are let through. The first hole
- lies 1 px from the midpoint of the second hole in the first source frame and the first hole in
- the second source frame: that pair of source holes is the cheaper for it, and taken, it would
- leave the second hole with nothing to pair with. The set of pairs taken pairs the most holes, so
- each hole keeps its own two: the frame between reads `hole` 0, and resampled to four frames,
- both made cells are kept, byte for byte. This holds for two, three and four holes, the plate
- moving or staying (with three and four holes, each hole but the last is likewise cheaper with
- the next one's hole in the first source frame). Boundaries, pinned by a test, with two and four
- holes, the plate moving or staying: with one hole more before the row, on the first hole's way
- (it could take the first hole's two, but then the first and the second cannot both keep theirs:
- each source frame's holes pair as many of the made frame's holes as they number, and no more),
- the frame between reads `hole` 0.10 % (the 64 pixels of one hole) and gives way to the nearer
- source frame; with the row's last hole shut in the second source frame (it has nothing there to
- pair with), it reads 0.10 % and gives way. With the search limited to one step
- (`rife.HOLE_PAIR_STEPS` set to 1), no set is found within it, so neither hole of the two-hole
- frame is paired: it reads `hole` 0.21 % (both holes, 128 pixels) and gives way. In figure 10
- (the same body with a plate 40 by 90 px on it and a column of three holes 8 px square through
- the plate, 24 px apart, moving 32 px down, the middle hole shut in the second source frame), the
- frame between is drawn at t 0.5, its holes 16 px down. Each lies against the next hole down in
- the first source frame and the hole before it in the second: the in-place reading gives the
- first and middle holes to the source frames, leaves of the first only a strip 4 px high, which
- does not count, and leaves the last hole whole. The first hole pairs only with its own two and
- the middle only with the first source frame's last hole and the second's first; sharing that
- hole, no set pairs both, so one is a hole more than the second source frame has, none of the
- other holes is paired, and the frame between reads `hole` 0.10 % and gives way to the nearer
- source frame.
+ readings shows a gap where the band lay; the only enclosed hole both source frames have is the
+ gap between the arm and the body (320 pixels), which the made frame keeps where it was, so the
+ in-place reading gives the made frame's arm gap to the source frames, and it takes no pair; the
+ band is left by the first two readings, and its only possible pair, the two source frames' arm
+ gaps, does not fit: the band lies 25 times farther from the point at t 0.5 between those gaps
+ than its way lets through, and the colour round it differs from theirs 6 times as much as is let
+ through, so the band has no pair and 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 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 (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 pairing takes the set that pairs the most holes, so each hole keeps
+ 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, the in-place reading gives the row's holes to the
+ source frames, and the frame between reads `hole` 0 and is kept as made; the frame with one hole
+ more midway is described with figure 12. In figure 9 (the same body with a plate on it and a row
+ of two, three or four holes 8 px square through the plate, 12 px apart, moving on a curved way
+ from one source frame (t 0) to the next (t 1): int(40 t + 20 t (1 - t)) px across and int(32 t)
+ px down at time t, the plate moving with the holes, or staying while the holes move through it;
+ with two holes it is the fourth checkpoint validator's frame), the frame between is drawn
+ exactly, at t 0.5: each of its holes lies 5 px beside the midpoint of where the two source
+ frames have that hole; 4 px and 0.1 of their distance (51 px), 9.1 px in all, are let through.
+ The first hole lies 1 px from the midpoint of the second hole in the first source frame and the
+ first hole in the second source frame: that pair of source holes is the cheaper for it, and
+ taken, it would leave the second hole with nothing to pair with. The set of pairs taken pairs
+ the most holes, so each hole keeps its own two: the frame between reads `hole` 0, and resampled
+ to four frames, both made cells are kept, byte for byte. This holds for two, three and four
+ holes, the plate moving or staying (with three and four holes, each hole but the last is
+ likewise cheaper with the next one's hole in the first source frame). Boundaries, pinned by a
+ test, with two and four holes, the plate moving or staying: with one hole more before the row,
+ on the first hole's way (it could take the first hole's two, but then the first and the second
+ cannot both keep theirs: each source frame's holes pair as many of the made frame's holes as
+ they number, and no more), the frame between reads `hole` 0.10 % (the 64 pixels of one hole) and
+ gives way to the nearer source frame; with the row's last hole shut in the second source frame
+ (it has nothing there to pair with), it reads 0.10 % and gives way. With both searches limited
+ to one step (`rife.HOLE_PAIR_STEPS` set to 1), neither finds a set within it, so neither hole of
+ figure 9's two-hole frame is paired: it reads `hole` 0.21 % (both holes, 128 pixels) and gives
+ way. In figure 10 (the same body with a plate 40 by 90 px on it and a column of three holes 8 px
+ square through the plate, 24 px apart, the plate moving 32 px down from one source frame to the
+ next; the middle hole shut in the second source frame), the frame between is drawn exactly at t
+ 0.5, its holes 16 px down. Each of its holes lies against the next hole down in the first source
+ frame and the hole before it in the second: the in-place reading gives the frame between's first
+ and middle holes to the source frames (of the first it leaves only a strip 4 px high, thinner
+ than 5 px, which does not count; the middle one lies against the first source frame's last hole
+ and the second source frame's first hole), and leaves the last hole whole, which lies against
+ nothing in the second source frame, where the middle hole is shut. Those two take no pair; the
+ last hole pairs with its own two holes (the last hole of each source frame), and the frame
+ between reads `hole` 0 and is kept as made. The middle hole is one hole more than the second
+ source frame has, which the in-place reading takes for theirs because it lies within 4 px of
+ their holes: what the reading does not tell (see figure 12 and the sub-item on what it does not
+ read), pinned by a test. In figure 11 (the same body with a plate 105 px square on it; through
+ the plate a hole 8 px square that the first source frame and the frame between have in place and
+ the second source frame shuts, and beside it a hole 8 px square moving from (100, 100) to (152,
+ 148), 52 px across and 48 px down; it is the fifth checkpoint validator's frame), the frame
+ between is drawn at t 0.5, the moving hole at its exact midpoint, 10 px from the hole in place:
+ within the moving hole's way (4 px and 0.1 of its 70.8 px, 11.1 px in all). The in-place reading
+ gives the hole in place to the source frames, so it takes no pair, and the moving hole pairs
+ with its own two; the frame between reads `hole` 0, and resampled to four frames both made cells
+ are kept, byte for byte; so are they with the hole in place kept by the second source frame
+ instead (open in the frame between and the second source frame, shut in the first). Figure 12 (a
+ body 200 by 260 px outlined in black on a 400 by 400 px canvas, moving whole from one source
+ frame to the next, with holes through it) pins what the reading does not tell: with a row of
+ four holes 8 px square, 24 px apart, the body moving 32 px down, and one hole more midway
+ between the middle two in the frame between, the second reading carries the row's holes to the
+ source frames without pairs, and the hole more pairs with one source frame's hole and the
+ other's next one, whose midpoint it is, reading `hole` 0 and kept as made (so is figure 8's row
+ standing still, drawn a pixel taller, with one hole more midway, where the in-place reading
+ gives the row to the source frames and the hole more pairs the same way, and figure 10's
+ column); with a gap 5 by 30 px, moving 48 px across and 48 px down (67.9 px), and an alike gap
+ 10 px beside it in the frame between (5 px of the body between them), the second reading carries
+ the gap, while the gap more lies 10 px from the point at t 0.5 between the source gaps, within 4
+ px and 0.1 of their 67.9 px (10.8 px), pairing to read `hole` 0 either way, though outline
+ readings give this frame way to the nearer source frame; a gap more 11 px beside is off that
+ way, reading `hole` 0.29 % and giving way with `hole` among its faults, as does an 8 px wide gap
+ with its twin 13 px beside it (5 px of the body between them again), at 0.45 %. In the test on
+ triples alone (no frame), twenty alike holes, each with its own two holes and up to five more
+ pairs with holes of the source frames within three places of its own at seeded random costs,
+ have one set pairing every hole: each group of pairs sharing a hole is searched first for a set
+ pairing every hole, then, where there is none, for the set pairing the most, each search at most
+ 5000 steps (`rife.HOLE_PAIR_STEPS`); the search for the set pairing the most, cheapest first,
+ runs past 5000 steps and would pair none, whereas the search for a set pairing every hole finds
+ one in 29 steps, pairing all twenty; where that search too runs past the steps, the other
+ answers, and here pairs none.
- **What `auto` costs**: a frame replaced shows the nearer source frame, so the motion there
steps as filmed, up to half a frame off its time, and the loop shows fewer distinct drawings a
second than `rife` — but no melted one. A clip drawn on twos has a long step between drawings
diff --git a/sprite_gen/video/rife.py b/sprite_gen/video/rife.py
index 2043919..be762d0 100644
--- a/sprite_gen/video/rife.py
+++ b/sprite_gen/video/rife.py
@@ -117,21 +117,20 @@ HOLE_TRAVEL = 0.2
HOLE_COARSE = 24
# 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
+# enclosed holes the first two readings leave (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`); a hole those readings give the neighbours takes no pair, being
+# theirs already. 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: of the sets of such triples that can stand together
-# and pair every one of the made frame's holes the first two readings give the neighbours, the one taken pairs the most
-# of the rest, then is the alikest and nearest (`_taken`) — a neighbour's hole the made frame keeps where it was
-# explains no other, and alike holes moving together each keep their own two, however near their ways run. Where no
-# set pairs all of those, one of them is a hole more than the neighbours have that the first two readings took for
-# theirs, and none of the rest pairs. An exact search finds the set, each group of triples sharing holes apart, in at
-# most HOLE_PAIR_STEPS steps (a row or grid of alike holes that all pair takes about a step a hole); a group whose
-# search runs past them pairs none of its holes.
+# other. Each neighbour's hole explains one of the holes paired: of the sets of such triples that can stand together,
+# the one taken pairs the most, then is the alikest and nearest (`_taken`), so alike holes moving together each keep
+# their own two, however near their ways run. An exact search finds it, each group of triples sharing holes apart: first
+# whether one set pairs every hole of the group (`_whole`), then, where none does, which set pairs the most
+# (`_searched`), each in at most HOLE_PAIR_STEPS steps (a row or grid of alike holes that all pair takes about a step a
+# hole); where the first runs past them the second answers, and a group the second runs past pairs none of its holes.
HOLE_SOURCE_THICK = 3
HOLE_PAIR_AREA = 4.0
HOLE_PAIR_SHAPE = 2.0
@@ -629,19 +628,18 @@ def _holes(pre: np.ndarray, thick: int) -> tuple[list[tuple[tuple[slice, slice],
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 outside `first` (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
+def _paired(made: np.ndarray, a: np.ndarray, b: np.ndarray, t: float, reach: int) -> list[int]:
+ """Which of the made frame's holes (rows of `_holes`: those the first two readings leave; 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. Its cost, how far the three are
from alike and near: the logarithm of how far the made frame's 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. The triples taken are one to one and pair every hole
- `first` names (`_taken`)."""
+ neighbours' two holes' distance over what it may be, summed. The triples taken are one to one (`_taken`)."""
if not (len(made) and len(a) and len(b)):
return []
A, B = a[:, None], b[None, :]
@@ -665,17 +663,15 @@ def _paired(made: np.ndarray, a: np.ndarray, b: np.ndarray, t: float, reach: int
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((i, int(j[p]), int(k[p]), float(cost[p])))
- return _taken(triples, [bool(x) for x in first])
+ return _taken(triples)
-def _taken(triples: list[tuple[int, int, int, float]], first: list[bool]) -> list[int]:
- """The made frame's holes outside `first` that the triples taken pair, one to one: no hole of any frame in two of
- them. Each hole `first` names, the neighbours' already, is one hole of each neighbour's too: of the sets of
- `triples` (the made frame's hole, a's, b's and the cost; `_paired`) that can stand together and pair every one of
- those, the one taken pairs the most of the rest, then has the least summed cost. So a neighbour's hole the made
- frame keeps where it was explains no other, and alike holes moving together each keep their own two, however near
- their ways run. Triples sharing a hole, directly or through others, make one group, read apart from the rest
- (`_searched`); a group with no hole outside `first` changes nothing and is not read."""
+def _taken(triples: list[tuple[int, int, int, float]]) -> list[int]:
+ """The made frame's holes the triples taken pair, one to one: no hole of any frame in two of them. Of the sets of
+ `triples` (the made frame's hole, a's, b's and the cost; `_paired`) that can stand together, the one taken pairs the
+ most holes, then has the least summed cost, so alike holes moving together each keep their own two, however near
+ their ways run. Triples sharing a hole, directly or through others, make one group, read apart from the rest: all
+ its holes pair where one set pairs them all (`_whole`), and otherwise those of the set `_searched` finds."""
owner: dict[tuple[int, int], tuple[int, int]] = {}
def root(x: tuple[int, int]) -> tuple[int, int]:
@@ -692,62 +688,102 @@ def _taken(triples: list[tuple[int, int, int, float]], first: list[bool]) -> lis
groups.setdefault(root((0, i)), {}).setdefault(i, []).append((cost, 1 << j, 1 << k))
taken: list[int] = []
for cands in groups.values():
- if not all(first[i] for i in cands):
- taken += _searched(cands, first)
+ taken += list(cands) if _whole(cands) else _searched(cands)
return sorted(taken)
-def _searched(cands: dict[int, list[tuple[float, int, int]]], first: list[bool]) -> list[int]:
+def _whole(cands: dict[int, list[tuple[float, int, int]]]) -> bool | None:
+ """Whether one set of a group's triples (each of its made frame's holes with its triples, cheapest first: the cost,
+ and a's hole and b's as bits; `_taken`), one to one, pairs every hole of the group: True or False, or None where the
+ search runs past HOLE_PAIR_STEPS steps. Depth first from the made frame's hole with the fewest triples still free
+ (holding no hole a triple taken holds), each of those cheapest first, no hole left unpaired; a branch is cut where a
+ hole left has no free triple, or where the holes left cannot each keep a hole of a, or of b, of its own among those
+ its free triples hold (`_matched`)."""
+ stack = [(tuple(sorted(cands)), 0, 0)]
+ for _ in range(HOLE_PAIR_STEPS):
+ if not stack:
+ return False
+ holes, used_a, used_b = stack.pop()
+ if not holes:
+ return True
+ free = {i: [x for x in cands[i] if not (used_a & x[1] or used_b & x[2])] for i in holes}
+ if not all(free.values()) or not (_matched(free, 1) and _matched(free, 2)):
+ continue
+ h = min(holes, key=lambda i: (len(free[i]), i))
+ others = tuple(i for i in holes if i != h)
+ stack.extend((others, used_a | ja, used_b | kb) for _, ja, kb in reversed(free[h]))
+ return None if stack else False
+
+
+def _matched(free: dict[int, list[tuple[float, int, int]]], side: int) -> bool:
+ """Whether each of the made frame's holes `free` names can keep a hole of one neighbour (`side` 1, a; 2, b) of its
+ own among those its free triples hold there: an augmenting path for each in turn (Kuhn's matching)."""
+ held = dict.fromkeys(free, 0)
+ for i, f in free.items():
+ for x in f:
+ held[i] |= x[side]
+ owner: dict[int, int] = {} # a neighbour's hole, as its bit: the made frame's hole keeping it
+ for start in free:
+ seen, path = 0, [[start, held[start], 0]] # a made frame's hole, the holes it has yet to try, the one it keeps
+ while path:
+ step = path[-1]
+ untried = step[1] & ~seen
+ if not untried:
+ path.pop()
+ continue
+ x = untried & -untried
+ step[1], seen = untried ^ x, seen | x
+ if x in owner:
+ path.append([owner[x], held[owner[x]], x])
+ continue
+ for i, _, kept in reversed(path): # the last takes x, and each before it the one the next gives up
+ owner[x], x = i, kept
+ break
+ else:
+ return False
+ return True
+
+
+def _searched(cands: dict[int, list[tuple[float, int, int]]]) -> list[int]:
"""Of one group of triples (each of its made frame's holes with its triples, cheapest first: the cost, and a's hole
- and b's as bits; `_taken`), the holes outside `first` the set taken pairs, by an exact search, depth first: from the
- made frame's hole with the fewest triples still free (holding no hole a triple taken holds), each of those,
- cheapest first, then, for a hole outside `first`, the hole left unpaired. The most a branch could still pair: each
- hole left with a free triple, and in each neighbour no more than the holes the free triples hold there. A branch is
- cut where that leaves a hole `first` names unpaired, or pairs fewer of the rest than the best set found, or as many
- with no less cost than the best's, even were each hole of `first` and each of as many of the rest as it takes, the
- cheapest, paired by its cheapest free triple. The search ends at a set pairing every hole, since every such set
- pairs the same holes. Where no set pairs every hole `first` names, one of them is a hole more than the neighbours
- have that the first two readings took for theirs, and none of the rest is paired; nor where the search runs past
- HOLE_PAIR_STEPS steps (docs/loop-repair.md section 4)."""
- owed = sum(first[i] for i in cands)
+ and b's as bits; `_taken`), the holes the set taken pairs, by an exact search, depth first: from the made frame's
+ hole with the fewest triples still free (holding no hole a triple taken holds), each of those, cheapest first, then
+ the hole left unpaired. The most a branch could still pair: each hole left with a free triple, and in each neighbour
+ no more than the holes the free triples hold there. A branch is cut where that pairs fewer holes than the best set
+ found, or as many with no less cost than the best's, even were each of as many as it takes, the cheapest, paired by
+ its cheapest free triple. The search ends at a set pairing every hole, since every such set pairs the same holes.
+ Where it runs past HOLE_PAIR_STEPS steps none of the group's holes is paired (docs/loop-repair.md section 4)."""
best: tuple[int, float, tuple[int, ...]] = (-1, 0.0, ())
- stack = [(tuple(sorted(cands)), 0, 0, 0, 0, 0.0, ())]
+ stack = [(tuple(sorted(cands)), 0, 0, 0, 0.0, ())]
for _ in range(HOLE_PAIR_STEPS):
if not stack:
break
- holes, used_a, used_b, got_first, got_rest, cost, pairs = stack.pop()
- free, cheapest, held = {}, ([], []), [0, 0, 0, 0] # held: a's and b's holes as bits, `first`'s, the rest's
+ holes, used_a, used_b, got, cost, pairs = stack.pop()
+ free, cheapest, held_a, held_b = {}, [], 0, 0
for i in holes:
if f := [x for x in cands[i] if not (used_a & x[1] or used_b & x[2])]:
free[i] = f
- side = 2 * (not first[i])
- cheapest[side // 2].append(f[0][0])
+ cheapest.append(f[0][0])
for _, ja, kb in f:
- held[side] |= ja
- held[side + 1] |= kb
- in_a, in_b = (held[0] | held[2]).bit_count(), (held[1] | held[3]).bit_count()
- more_first = min(len(cheapest[0]), held[0].bit_count(), held[1].bit_count(), in_a, in_b)
- more_rest = min(len(cheapest[1]), held[2].bit_count(), held[3].bit_count(), in_a - more_first,
- in_b - more_first)
- could = got_rest + more_rest
- if got_first + more_first < owed or could < best[0] or could == best[0] and (
- cost + sum(cheapest[0]) + sum(sorted(cheapest[1])[:more_rest]) >= best[1]):
+ held_a |= ja
+ held_b |= kb
+ more = min(len(cheapest), held_a.bit_count(), held_b.bit_count())
+ if got + more < best[0] or got + more == best[0] and cost + sum(sorted(cheapest)[:more]) >= best[1]:
continue
if not free:
- best = (got_rest, cost, pairs)
- if got_first + got_rest == len(cands):
+ best = (got, cost, pairs)
+ if got == len(cands):
break
continue
h = min(free, key=lambda i: (len(free[i]), i))
others = tuple(i for i in free if i != h)
- if not first[h]:
- stack.append((others, used_a, used_b, got_first, got_rest, cost, pairs))
- stack.extend((others, used_a | ja, used_b | kb, got_first + first[h], got_rest + (not first[h]), cost + c,
- pairs + (h,)) for c, ja, kb in reversed(free[h]))
+ stack.append((others, used_a, used_b, got, cost, pairs))
+ stack.extend((others, used_a | ja, used_b | kb, got + 1, cost + c, pairs + (h,))
+ for c, ja, kb in reversed(free[h]))
else:
if stack:
return []
- return [i for i in best[2] if not first[i]]
+ return list(best[2])
def hole(made: Image.Image, a: Image.Image, b: Image.Image, t: float) -> float:
@@ -778,9 +814,9 @@ def hole(made: Image.Image, a: Image.Image, b: Image.Image, t: float) -> float:
left = _opened(left & ~(_moved(near_a, -ay, -ax) | _moved(near_b, -by, -bx)), HOLE_THICK)
if left.any():
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]
+ rest = [i for i, (window, mask) in enumerate(holes) if left[window][mask].any()]
+ for p in _paired(own[rest], _holes(pa, HOLE_SOURCE_THICK)[1], _holes(pb, HOLE_SOURCE_THICK)[1], t, reach):
+ window, mask = holes[rest[p]]
left[window] &= ~mask
left = _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.py
index 5ace4c8..3fd756a 100644
--- a/tests/video/test_inbetween_hole.py
+++ b/tests/video/test_inbetween_hole.py
@@ -8,12 +8,14 @@ all the line there is — the outline readings judge an outline, not a hole. A h
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: the holes the first two readings give them must all pair, and of the sets that pair them
-the one taken pairs the most of the rest, so alike holes whose ways run near each other each keep their own two. 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.
+hole a part carries over a body that stays, turned, grown, sheared or swung, is theirs. A hole the first two readings
+give the source frames takes no pair; of the holes they leave, each source frame's hole is one hole of the frame
+between, and of the sets of pairs the one taken pairs the most, so alike holes whose ways run near each other each keep
+their own two. A hole more than they have among the holes left 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. A hole more is read as theirs where it lies within 4 px of a hole of theirs, or where it pairs with one source
+frame's hole and the other's alike hole whose own holes the first two readings explain: what the reading does not tell.
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, the
@@ -22,12 +24,14 @@ a gap through it, moved whole; a figure whose legs part above boots that close t
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; a plate with a row of holes; a row of holes moving on a curved
-way; and a column of holes."""
+way; a column of holes; a plate with a hole one source frame keeps in place beside a hole moving between them; and a
+body moving whole with a gap or a row of holes through it."""
from __future__ import annotations
import itertools
import math
+import random
import numpy as np
import pytest
@@ -259,6 +263,35 @@ def _column(t: float, *, shut: tuple[int, ...] = ()) -> Image.Image:
return Image.fromarray(rgba, "RGBA")
+def _beside(t: float, *, kept_by: int = 0) -> Image.Image:
+ """The body that stays (`_still`) with a plate 105 px square on it, through it a hole 8 px square in place (rows 120
+ to 127, columns 112 to 119) that one source frame keeps and the other shuts — open while t < 1, so in the first source
+ frame and the frame between, or with `kept_by` 1 while t > 0 — and a hole 8 px square moving from (100, 100) to
+ (152, 148), drawn at t: at t 0.5 at its exact midpoint, 10 px from the hole in place. The fifth checkpoint
+ validator's frame."""
+ rgba = _still(False)
+ rgba[75:180, 75:180] = PART + (255,)
+ if (t < 1) if kept_by == 0 else (t > 0):
+ rgba[120:128, 112:120] = 0
+ cx, cy = int(100 + 52 * t), int(100 + 48 * t)
+ rgba[cy - 4:cy + 4, cx - 4:cx + 4] = 0
+ return Image.fromarray(rgba, "RGBA")
+
+
+def _moving(t: float, move: tuple[int, int], holes: tuple[tuple[int, int, int, int], ...],
+ more: tuple[tuple[int, int, int, int], ...] = ()) -> Image.Image:
+ """A body 200 x 260 px outlined in black on a 400 x 400 px canvas, moving whole move[0] px across and move[1] down
+ from t 0 to t 1 (its corner at (100, 70) at t 0.5), drawn at t, with holes through it at `holes` (x0, y0, x1, y1 from
+ its corner, the ends left out) and at `more`."""
+ rgba = np.zeros((400, 400, 4), np.uint8)
+ x0, y0 = 100 + int(round(move[0] * (t - 0.5))), 70 + int(round(move[1] * (t - 0.5)))
+ rgba[y0:y0 + 260, x0:x0 + 200] = LINE
+ rgba[y0 + 2:y0 + 258, x0 + 2:x0 + 198] = PART + (255,)
+ for bx0, by0, bx1, by1 in holes + more:
+ rgba[y0 + by0:y0 + by1, x0 + bx0:x0 + bx1] = 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))
@@ -553,9 +586,9 @@ def test_each_hole_of_a_source_frame_is_one_hole_of_the_frame_between():
frame and the next but one of the other have their midpoint as near each hole as its own two: only with its own two
is every hole of the row paired. 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. Standing
- still, the row drawn a pixel taller: the in-place reading gives the row its source frames' holes, and every hole of
- the row must pair, which leaves one more hole midway none, so it still gives way."""
+ midway, it gives way to the nearer source frame: of the holes the first two readings leave, each source frame's hole
+ is one hole of the frame between. Standing still, the row drawn a pixel taller is kept: the in-place reading gives
+ the row its source frames' holes."""
seen = {}
for plain in (False, True):
a, b = _row(0.0, plain=plain, dy=32), _row(1.0, plain=plain, dy=32)
@@ -568,7 +601,6 @@ def test_each_hole_of_a_source_frame_is_one_hole_of_the_frame_between():
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}
@@ -590,20 +622,81 @@ def test_holes_no_set_of_pairs_explains_together_give_way(monkeypatch):
row, on the first hole's way: it could take the first hole's two, but the first and the second cannot then both
keep theirs — each source frame's holes pair as many of the made frame's as they number and no more. And the row's
last hole shut in the second source frame: it has nothing there to pair with. Both give way to the nearer source
- frame with `hole` among their faults. So does a column of three holes moving down (`_column`), its middle hole shut
- in the second source frame: the in-place reading gives the frame between's first and middle holes to the source
- frames, but no set of pairs pairs both — the middle one's only pair, the holes it lies against, holds the second
- source frame's first hole, the first one's own — so one of them is a hole more than the second source frame has,
- and the last hole, which its own two would pair, is not paired. Searched no further than rife.HOLE_PAIR_STEPS
- steps, here one, the frame of the test above gives way too: a group of triples whose search runs past it pairs none
- of its holes."""
+ frame with `hole` among their faults. Searched no further than rife.HOLE_PAIR_STEPS steps, here one, the frame of the
+ test above gives way too: a group of triples both of whose searches run past it pairs none of its holes."""
seen = {}
for n, still in itertools.product((2, 4), (False, True)):
seen["one more before", n, still] = _given_way(_way(0.0, n, still=still), _way(0.5, n, still=still, more=(-1,)),
_way(1.0, n, still=still))
seen["the last only in the first", n, still] = _given_way(_way(0.0, n, still=still), _way(0.5, n, still=still),
_way(1.0, n, still=still, shut=(n - 1,)))
- seen["a column, its middle hole shut in the second"] = _given_way(_column(0.0), _column(0.5), _column(1.0, shut=(1,)))
monkeypatch.setattr(rife, "HOLE_PAIR_STEPS", 1)
seen["searched one step"] = _given_way(*(_way(s) for s in (0.0, 0.5, 1.0)))
assert seen == {k: True for k in seen}
+
+
+def _tangled(seed: int, n: int) -> list[tuple[int, int, int, float]]:
+ """Triples for `rife._taken`: n made holes, each paired by its own two (i, i, i) and by up to five more pairs of a's
+ and b's holes within three places of its own, at seeded random costs: one set pairs every hole."""
+ rng = random.Random(seed)
+ triples = {(i, i, i) for i in range(n)}
+ for i in range(n):
+ for _ in range(5):
+ triples.add((i, min(n - 1, max(0, i + rng.randint(-3, 3))), min(n - 1, max(0, i + rng.randint(-3, 3)))))
+ return [(i, j, k, round(rng.uniform(0.0, 3.0), 3)) for i, j, k in sorted(triples)]
+
+
+def test_a_group_every_hole_of_which_pairs_is_paired_whole_where_the_search_for_the_most_runs_long(monkeypatch):
+ """Twenty alike holes, each with its own two and up to five more pairs near its own at random costs (`_tangled`):
+ the search for the set pairing the most, cheapest first, wanders among the cheaper pairs and runs past
+ rife.HOLE_PAIR_STEPS here before it finds a set pairing all twenty. The search for a set pairing every hole, cut
+ wherever the holes left cannot each keep a hole of each source frame of their own, finds one in a few dozen steps,
+ and every hole is paired. Where that search runs past the steps too, the other answers, and here pairs none."""
+ triples = _tangled(3, 20)
+ assert rife._taken(triples) == list(range(20))
+ monkeypatch.setattr(rife, "_whole", lambda cands: None) # as though the search for a whole set ran past the steps
+ assert rife._taken(triples) == []
+
+
+def test_a_hole_the_first_two_readings_give_the_source_frames_takes_no_pair():
+ """The fifth checkpoint validator's frame (`_beside`): a hole 8 px square that the first source frame and the frame
+ between have in place and the second shuts, beside a hole moving 52 px across and 48 down, drawn at its exact
+ midpoint 10 px from the first (within the moving hole's way: 4 px and 0.1 of its 70.8 px). The in-place reading
+ gives the first hole to the source frames, so it takes no pair, and the moving hole keeps its own two: resampled to
+ four, both frames made are kept, byte for byte, and so are they with the hole in place kept by the second source
+ frame instead."""
+ assert {k: _resampled(*(_beside(s, kept_by=k) for s in (0.0, 0.5, 1.0))) for k in (0, 1)} == {0: KEPT, 1: KEPT}
+
+
+def test_a_hole_more_whose_pair_the_first_two_readings_leave_free_is_read_as_theirs():
+ """What the reading does not tell, pinned (docs/loop-repair.md section 4): a hole more than the source frames have
+ is theirs where it lies within 4 px of where they have a hole, or where it pairs with one source frame's hole and
+ the other's alike hole whose own holes in the frame between the first two readings explain. A column of three holes
+ moving down (`_column`), its middle hole shut in the second source frame: the in-place reading gives the frame
+ between's first and middle holes to the source frames, each lying against one of theirs, and the last pairs with
+ its own two. A row of four holes standing still (`_row`), drawn a pixel taller with one hole more midway: the
+ in-place reading gives the row's holes to the source frames, and the hole more pairs with one's hole and the
+ other's next one. A body moving whole 32 px down (`_moving`) with a row of four holes 8 px square, 24 px apart, and
+ one more midway between the middle two: the second reading carries the row, and the hole more pairs the same way.
+ Each is kept as made. And a twin: the body moving whole 48 px across and 48 down with a gap 5 x 30 px through it,
+ carried by the second reading, and one gap more 10 px beside it, 5 px of the body between them: it lies 10 px from
+ the point at t 0.5 between the source frames' gaps, within 4 px and 0.1 of their 67.9 px (10.8 px), and pairs with
+ them, so it reads `hole` 0 either way (the outline readings, readings of their own, give this frame way). A twin off
+ that way gives way for `hole`: 11 px beside the gap, or 13 px beside a gap 8 px wide (5 px of the body between them
+ again). A twin is let through only where the gap's width and 5 px are within 4 px and 0.1 of how far it moves."""
+ seen = {"column, its middle hole shut in the second": _resampled(_column(0.0), _column(0.5), _column(1.0, shut=(1,)))
+ == KEPT}
+ for plain in (False, True):
+ still = _row(0.0, plain=plain)
+ seen["still row, a pixel taller, one more midway", plain] = _resampled(
+ still, _row(0.5, plain=plain, taller=1, more=(0,)), still) == KEPT
+ row = tuple((100 + ox - 4, 126, 100 + ox + 4, 134) for ox in (-36, -12, 12, 36))
+ seen["row moving whole, one more midway"] = _resampled(
+ _moving(0.0, (0, 32), row), _moving(0.5, (0, 32), row, ((96, 126, 104, 134),)), _moving(1.0, (0, 32), row)) == KEPT
+ for width, off in ((5, 10), (5, 11), (8, 13)):
+ gap = (95, 100, 95 + width, 130)
+ a, b = _moving(0.0, (48, 48), (gap,)), _moving(1.0, (48, 48), (gap,))
+ made = _moving(0.5, (48, 48), (gap,), ((95 + off, 100, 95 + off + width, 130),))
+ seen["twin", width, off] = (rife.hole(made, a, b, 0.5) == rife.hole(made, b, a, 0.5) == 0) if off == 10 else (
+ _given_way(a, made, b))
+ assert seen == {k: True for k in seen}