Generate clean 2D game sprites & animation atlases — component-row pipeline: state rows, alpha cleanup, frame extraction, runtime atlases. Codex/Claude skill.
fix(video): a walk's cut is read on its top line on the screen and over its feet, its word the first either says, so a walk leaning further on its feet as it goes is witnessed a cycle where the line over its feet held it
Soohong Kim1155ae1cece8
diff --git a/sprite_gen/video/local_cycle.py b/sprite_gen/video/local_cycle.pyindex a1749e9..9aa6c37 100644--- a/sprite_gen/video/local_cycle.py+++ b/sprite_gen/video/local_cycle.py@@ -48,8 +48,11 @@ CUE_FLOOR = 0.5# interval on, and a flow left over is as it was at both. A line left whose range is under BOB_FLOOR of the body's# median height, or under BOB_ROWS pixel rows (a line read in whole rows rounds a row up and down as the picture# drifts), does not rise and fall, and witnesses nothing. A walk's cut, read whole as it is cut (`cut_word`), is read so-# on the top line over its feet (`over_feet`): at the cut's length a picture swaying once a cut is left whole, and on-# the screen it would hide the body's rise and fall twice the cut; the feet move with it.+# on two lines (CUT_LINES), and its word is the first either says: the top line on the screen, and the top line over its+# feet (`over_feet`). At the cut's length a picture swaying once a cut is left whole, and on the screen it hides the+# body's rise and fall twice the cut, where the feet move with it; a walk leaning further on its feet as it goes tilts+# the ground under them, and the line over its feet takes in the two feet's heights by turns, where the screen line+# has none of them.# The picture moving up and down moves the line as the body does, on any beat — shaken twice an interval it is pixel for# pixel a body carried up and down whole, feet and all — and the picture zoomed in and out lifts and lowers it too. So the# line's rise and fall twice an interval (`twice_an_interval`) is read against the body's own lowest row and head@@ -67,6 +70,10 @@ BOB_ROWS = 2BOB_OWN = 0.3BOB_SCALE = 0.6BEAT_FRAMES = 8 # a rise and fall twice an interval is fitted (`twice_an_interval`) to no fewer frames+# The lines a walk's cut is read on (`cut_word`), and where each reads the body's top line: on the screen, and over its+# feet (`over_feet`). Each says its own word; the cut's is the first either says, in CUT_WORDS' order.+CUT_LINES = {'screen': 'on the screen', 'feet': 'over its feet'}+CUT_WORDS = ('two steps', 'four steps', 'one step', None)SIDE_VIEW = 'side' # from the side the legs a step on are one silhouette, as near as a cycle on: asked only where a pass hides# A loop whose clip one interval on is the same picture, as a walk whose feet meet once a cycle draws it, with nothing# to witness whether they do (`read_cycles`): its crossings stay on steps, so its two steps may be two cycles. Named on@@ -751,35 +758,71 @@ def read_cycles(reading, distances, *, view=None, cue=None, cue_step=None, signareturn said+def _cut_line(signals, length, *, feet):+ """One line's word on a walk's cut `length` frames long (`cut_word`): the body's top line on the screen, or over+ its feet (`feet`), read by `bob_word` on the cut, on half of it and on twice it — the first it rises and falls+ twice on says two steps, four steps or one step; None where it does on none, with why (the reading on the cut).+ Returns {'says', 'bob': the reading on the cut, 'on': the reading that said four steps or one step, with its+ `interval`, 'why' where None}."""+ bob = bob_word(signals, length, feet=feet)+ if bob['says'] == 'cycles':+ return {'says': 'two steps', 'bob': bob}+ for says, span in (('four steps', length/2), ('one step', 2*length)):+ word = bob_word(signals, span, feet=feet)+ if word['says'] == 'cycles':+ return {'says': says, 'bob': bob, 'on': {'interval': round(span, 2), **word}}+ return {'says': None, 'bob': bob, 'why': bob['why']}+++def _feet_mark(signals, length, over):+ """Whether a walk's cut `length` frames long that stands (`cut_word`) is marked: its lowest row — the one its line+ over the feet is read over (`over`) — rises and falls twice the cut more than its top line does on the screen+ (`own_beat`). The line over the feet is then the feet's as much as the body's: a foot hidden behind the other+ shakes it so once a cycle, and stood a cut of two cycles on it as one. A mark, not a hold. Returns {'over', 'feet',+ 'beat'}, in rows up and down to two places (as `bob_word`'s `body`), where it is so; None where not, or not read."""+ beat = own_beat(signals, length)+ if beat is None:+ return None+ feet, top = round(beat['sole' if over == 'sole' else 'lowest'], 2), round(beat['beat'], 2)+ return {'over': over, 'feet': feet, 'beat': top} if feet > top else None++def cut_word(signals, length):"""The body's word on a walk's cut `length` frames long as it is about to be cut, whichever way it was chosen — thepixel search's, the step count's crossings read or not read (loop `_witnessed`). Legs drawn alike loop as well onone step as on two, and crossings read off feet that slide, or off a shadow under them on a picture that moves, cancount half steps: the legs cannot say the cut is a cycle, and the body's own rise and fall, once a step, is read- instead (`bob_word`, off `signals`: `legs.strike_signals` with `legs.body_signals`), its top line read over its- feet (`feet`): a picture moving once a cut, as a slow sway or drift whose turn is a cycle long does, is left whole- by the flow taken out at the cut's length and would hide the rise and fall twice it, and the feet move with it.- It `says`:+ instead (`bob_word`, off `signals`: `legs.strike_signals` with `legs.body_signals`), its top line read on two lines+ (CUT_LINES, `_cut_line`): on the screen, and over its feet (`feet`). A picture moving once a cut, as a slow sway or+ drift whose turn is a cycle long does, is left whole by the flow taken out at the cut's length and hides the rise+ and fall twice it on the screen, where the feet move with it; a walk leaning further on its feet as it goes tilts+ the ground under them, and the line over its feet takes in the two feet's heights by turns, where the screen line+ has none of them. Each line says its own word; the cut's is the first either says (CUT_WORDS):- `two steps` where it rises and falls twice the cut (`bob_word` on the cut says cycles): the cut is a cycle;- `four steps` where it does so twice half the cut: the cut is two cycles;- `one step` where it does so twice two cuts — once the cut: the cut is one step of a walk, or a whole cycle of abody that rises and falls once a cycle (a limp, a body with no legs that bounces as it goes); the body cannottell which, and it witnesses no cycle;- - None where none of these is read: nothing witnesses the cut whole cycles (`why`, the reading on the cut).+ - None where neither line reads any of these: nothing witnesses the cut whole cycles (`why`, each line's reading+ on the cut).- Returns {'says', 'bob': the reading on the cut, 'on': the reading that said four steps or one step, with its- `interval`, 'why' where None}."""+ Where the cut stands (two steps or four) and its lowest row rises and falls twice it more than its top line does on+ the screen, the word carries a mark (`mark`, `_feet_mark`), and nothing more. Returns {'says', 'by': the lines that+ said it (where it says), 'lines': each line's own word (`_cut_line`), 'on': the first such line's reading that said+ four steps or one step, with its `line` and `interval`, 'why' where None, 'mark' where marked}."""if not signals:return {'says': None, 'why': 'no top line read: a frame has no solid body'}- bob = bob_word(signals, length, feet=True)- if bob['says'] == 'cycles':- return {'says': 'two steps', 'bob': bob}- for says, span in (('four steps', length/2), ('one step', 2*length)):- word = bob_word(signals, span, feet=True)- if word['says'] == 'cycles':- return {'says': says, 'bob': bob, 'on': {'interval': round(span, 2), **word}}- return {'says': None, 'bob': bob, 'why': bob['why']}+ lines = {line: _cut_line(signals, length, feet=line == 'feet') for line in CUT_LINES}+ says = min((word['says'] for word in lines.values()), key=CUT_WORDS.index)+ if says is None:+ return {'says': None, 'lines': lines, 'why': '; '.join(dict.fromkeys(word['why'] for word in lines.values()))}+ by = [line for line, word in lines.items() if word['says'] == says]+ said = {'says': says, 'by': by, 'lines': lines}+ if says != 'two steps':+ said['on'] = {'line': by[0], **lines[by[0]]['on']}+ mark = None if says == 'one step' else _feet_mark(signals, length, lines['feet']['bob']['over'])+ return {**said, **({'mark': mark} if mark else {})}def unwitnessed(cycle):@@ -984,7 +1027,7 @@ def step_verdict(cycle):def held_verdict(cycle):"""The body's word on the cut, where it holds it (`cut_witness`, loop `_witnessed`), in words: a cut nothingwitnesses whole cycles, or one the body rises and falls once in — one step of a walk, or a whole cycle of a body- that does so once a cycle — kept as it was chosen. Each names UNWITNESSED."""+ that does so once a cycle — kept as it was chosen, each line's reading named (CUT_LINES). Each names UNWITNESSED."""said = cycle.get('cut_witness') or {}if said.get('held') != 'unwitnessed':return []@@ -998,8 +1041,11 @@ def held_verdict(cycle):f"walk's legs are drawn alike, a step loops as a cycle does, and the loop may be half its cycle "f"({UNWITNESSED})"]on = said['on']- return [f"nothing that reads no leg witnesses the cut {s}/{L} whole cycles: the body's top line rises and falls of its "- f"own once in it ({on['half']:+.2f} a cut on, {on['quarter']:+.2f} half a cut on) — one step of a walk whose "- f"legs are drawn alike, half its cycle, or a whole cycle of a body that rises and falls once a cycle (a limp, "- f"a body with no legs that bounces as it goes) — and {basis}. The cut is kept as chosen: cut again two long, "- f"it would loop two of such a body's cycles ({UNWITNESSED})"]+ where = ' and '.join(CUT_LINES[line] for line in said['by'])+ rest = ''.join(f", and {CUT_LINES[line]} it says nothing ({word['why']})" for line, word in said['lines'].items()+ if line not in said['by'])+ return [f"nothing that reads no leg witnesses the cut {s}/{L} whole cycles: the body's top line {where} rises and falls "+ f"of its own once in it ({on['half']:+.2f} a cut on, {on['quarter']:+.2f} half a cut on){rest} — one step of a "+ f"walk whose legs are drawn alike, half its cycle, or a whole cycle of a body that rises and falls once a cycle "+ f"(a limp, a body with no legs that bounces as it goes) — and {basis}. The cut is kept as chosen: cut again two "+ f"long, it would loop two of such a body's cycles ({UNWITNESSED})"]diff --git a/sprite_gen/video/loop.py b/sprite_gen/video/loop.pyindex bf04888..d2a4544 100644--- a/sprite_gen/video/loop.py+++ b/sprite_gen/video/loop.py@@ -1788,12 +1788,14 @@ def _counted(cycle: dict[str, Any], steps: int, *, window: CutWindow, D: np.ndardef _witnessed(cycle: dict[str, Any], *, frames: list[Image.Image]) -> dict[str, Any]:"""The cut a walk's search and step count chose (`_by_steps`), held to one word before it is cut whichever way itwas chosen — the search's, two steps by the clip's crossings, crossings read or not: the body's- (`local_cycle.cut_word`), recorded `cut_witness`. Legs drawn alike loop as well on one step as on two, and- crossings read off feet that slide, or off a shadow under them on a picture that moves, count half steps.+ (`local_cycle.cut_word`: its top line on the screen and over its feet, the first word either says), recorded+ `cut_witness`. Legs drawn alike loop as well on one step as on two, and crossings read off feet that slide, or off+ a shadow under them on a picture that moves, count half steps.- Its own rise and fall twice the cut, or four times: the cut is a cycle, or two, and stands. Cut two cycles, itsstrip still counts two steps where the crossings counted them, and `video-set` leaves it out of its state's cycle- alignment (local_cycle.FOUR_STEPS, `local_cycle.four_steps`).+ alignment (local_cycle.FOUR_STEPS, `local_cycle.four_steps`). Where its lowest row rises and falls twice the cut+ more than its top line on the screen, the record carries a mark (`mark`), and nothing is held on it.- Else nothing witnesses the cut handed out whole cycles, and it is held (`held: unwitnessed`): kept — two of theclip's crossing intervals where it counted them, else as the search chose it — and named(local_cycle.UNWITNESSED, `held_verdict`); `video-set` leaves it out of its state's cycle alignment@@ -2873,7 +2875,7 @@ def run(**kwargs: object) -> int:counted = payload["cycle"]["step_count"]summary["cycle"]["step_count"] = {k: counted[k] for k in ("mode", "readable", "chosen_by", "cut", "why") if k in counted}if "cut_witness" in payload["cycle"]:- summary["cycle"]["cut_witness"] = {k: payload["cycle"]["cut_witness"][k] for k in ("cut", "says", "held")+ summary["cycle"]["cut_witness"] = {k: payload["cycle"]["cut_witness"][k] for k in ("cut", "says", "by", "held", "mark")if k in payload["cycle"]["cut_witness"]}if payload.get("ghost_screen", {}).get("ghosts") or payload.get("ghost_screen", {}).get("reads") is False:summary["ghost_screen"] = payload["ghost_screen"]diff --git a/tests/video/test_one_step_cut.py b/tests/video/test_one_step_cut.pyindex 7f23cf1..4a5ad55 100644--- a/tests/video/test_one_step_cut.py+++ b/tests/video/test_one_step_cut.py@@ -112,8 +112,9 @@ def test_a_walk_cut_one_step_long_is_named_by_the_step_screen(slow):assert screen["depth"] >= loop.PERIODICITY_MIN and screen["pairs"] == FRAMES - screen["lag"]assert screen["coverage"] == round((FRAMES - screen["lag"]) / screen["lag"], 4)# Nothing is cut on it, and nothing else claims steps: no `steps`. The one other word is the cut witness's: the walker- # is carried whole on its legs, so nothing over its feet rises and falls to witness the cut whole cycles, and the cut- # is held as the search chose it, named (`cycle-unwitnessed`); `video-set` leaves it out of its cycle alignment.+ # is carried whole on its legs, so nothing over its feet rises and falls, and on the screen its top line rises and+ # falls with its feet: nothing witnesses the cut whole cycles, and the cut is held as the search chose it, named+ # (`cycle-unwitnessed`); `video-set` leaves it out of its cycle alignment.witness, said = cycle["cut_witness"], [line for line in report["jolt"]["warnings"] if "step" in line]assert "steps" not in cycle and witness["held"] == "unwitnessed" and local_cycle.unwitnessed(cycle), witnessassert said == local_cycle.held_verdict(cycle) and said[0].endswith(f"({local_cycle.UNWITNESSED})"), saiddiff --git a/tests/video/test_walk_steps.py b/tests/video/test_walk_steps.pyindex 226cfc5..68d61d6 100644--- a/tests/video/test_walk_steps.py+++ b/tests/video/test_walk_steps.py@@ -1129,12 +1129,15 @@ def test_a_cut_is_witnessed_by_how_often_the_body_rises_and_falls_in_it(beat, sa"""`cut_word` on a cut 16 frames long, the body 100 rows tall on feet that stay on the ground, its top line risingand falling 3 rows either way every `beat` frames: twice the cut is two steps, a cycle; four times, two cycles;once, one step — or a whole cycle of a body that rises and falls once a cycle, which the word cannot tell from it;- held still, nothing witnesses the cut whole cycles."""+ held still, nothing witnesses the cut whole cycles. The feet on the ground, the top line reads alike on the screen+ and over the feet: both lines say the word, and where neither says one, each says why."""word = local_cycle.cut_word(_bob(beat), 16)- assert word["says"] == says+ assert word["says"] == says and [line["says"] for line in word["lines"].values()] == [says, says]if says is None:- assert word["bob"]["says"] is None and word["why"] == word["bob"]["why"]- elif says != "two steps":+ assert "by" not in word and all(line["why"] in word["why"] for line in word["lines"].values())+ else:+ assert word["by"] == list(local_cycle.CUT_LINES)+ if says in ("four steps", "one step"):assert word["on"]["says"] == "cycles" and word["on"]["interval"] == {"four steps": 8, "one step": 32}[says]@@ -1283,17 +1286,20 @@ def test_a_walk_on_a_picture_moved_every_two_thirds_of_a_step_is_never_cut_a_thidef test_a_still_walk_over_a_shadow_on_the_screen_on_a_picture_shaken_twice_a_step_is_never_witnessed(tmp_path):"""The wide walker held still on its legs (crossings its steps, 23 frames), over a shadow drawn on the screentouching its soles, on a picture shaken 6 px up and down twice a step: the step count reads no feet, and the search- cuts 23 frames — one step. The top line rises and falls twice the cut with the picture, and the lowest solid row is- the shadow, holding still: read over it alone, the picture's moving is the body's own and witnesses two steps.- Over the lowest opaque row, the feet's, the top line holds still: held, named."""+ cuts 23 frames — one step. On the screen the top line rises and falls twice the cut with the picture, and the+ lowest opaque row, the feet's, with it: the picture's moving, not the body's own. The lowest solid row is the+ shadow, holding still: read over it alone, the picture's moving is the body's own and witnesses two steps. Over the+ lowest opaque row the top line holds still. Neither line witnesses the cut: held, named."""shaken = _shadowed(lambda k: _alike(k, **_STEPS, bob=0), _shake((0.5, 6, math.pi / 2), 23), shadow="touch", screen=True)report = _cut(tmp_path / "out", _keyed(tmp_path, shaken))_not_silent(report, 46)assert report["cycle"]["step_count"]["readable"] is Falsesaid = _held(report)- bob = said["bob"]+ screen, feet = (said["lines"][line]["bob"] for line in ("screen", "feet"))assert abs(said["cut"][1] - 23) <= 1 and said["says"] is None- assert bob["over"] == "sole" and bob["rows"] < local_cycle.BOB_ROWS and "does not rise and fall" in said["why"]+ assert screen["half"] >= local_cycle.BOB_TWICE and screen["quarter"] <= -local_cycle.BOB_TWICE+ assert screen["body"]["sole"] > screen["body"]["lowest"] and "its lowest row rises and falls with it" in said["why"]+ assert feet["over"] == "sole" and feet["rows"] < local_cycle.BOB_ROWS and "does not rise and fall" in said["why"]frames = [shaken(k) for k in range(FRAMES)]signals = {**legs.strike_signals(frames), **legs.body_signals(frames)}assert local_cycle.cut_word({**signals, "sole": signals["reach"]}, said["cut"][1])["says"] == "two steps"@@ -1307,16 +1313,47 @@ def test_a_walk_rising_on_its_legs_on_a_picture_swaying_once_a_cycle_or_slower_ia cycle or slower — 12 px either way every 46 frames or 24 px every 69 (the wide walker with its legs drawn alike,its crossings its steps every 23 frames), 24 px every 40 (the walker whose far foot passes hidden, 20 frames a cycleon twos): a slow motion of the whole picture, not the walk's. The cut is a cycle. Taken out at the cut's length,- the flow leaves the sway whole, and the top line on the screen rises and falls with it once the cut: read so, the- body's rise and fall twice the cut is hidden and the cycle held. Over its feet, which move with the picture, the- top line rises and falls twice the cut: two steps, witnessed, nothing named."""+ the flow leaves the sway whole, and the top line on the screen rises and falls with it once the cut: read there+ alone, the body's rise and fall twice the cut is hidden and the cycle held. Over its feet, which move with the+ picture, the top line rises and falls twice the cut: two steps, witnessed, nothing named."""draw, d = {"steps": (lambda k: _alike(k, **_STEPS), 23), "behind": (lambda k: _behind(k, cycle=20, hold=2), 20)}[walker]report = _cut(tmp_path / "out", _keyed(tmp_path, _carried(draw, _shake(sway, d))))_not_silent(report, cycle)c = report["cycle"]said = c["cut_witness"]assert report["status"] == "passed" and abs(c["length"] - cycle) <= 1.5 and said["cut"] == [c["start"], c["length"]]- assert said["says"] == "two steps" and said["bob"]["over"] in ("reach", "sole") and "held" not in said+ assert said["says"] == "two steps" and "feet" in said["by"] and "held" not in said+ assert said["lines"]["feet"]["bob"]["over"] in ("reach", "sole")+ assert not local_cycle.unwitnessed(c) and not any(local_cycle.UNWITNESSED in w for w in report["jolt"]["warnings"])+++def _leaning(draw, degrees: float):+ """`draw`'s walker turned about its feet `degrees` over the clip, k/72 of it in frame k (bilinear): a lean+ changing slowly on its feet, on a canvas 60 px taller either side."""++ def frame(k: int) -> Image.Image:+ im = draw(k)+ out = Image.new("RGBA", (im.width, im.height + 120))+ out.paste(im.rotate(degrees * k / (FRAMES - 1), resample=Image.BILINEAR, center=(104, GROUND + 3)), (0, 60))+ return out+ return frame+++def test_a_walk_leaning_further_on_its_feet_as_it_goes_is_witnessed_one_cycle(tmp_path):+ """The walker whose far foot passes hidden behind the near one, its legs drawn alike, its feet meeting once a cycle+ (17.5 frames), rising and falling on its legs once a step, turned 15 degrees about its feet over the clip: a lean+ changing slowly, on its feet. The search cuts a cycle. The lean tilts the ground under the feet, and the line over+ them takes in the two feet's heights by turns: it does not rise and fall twice the cut, nor four times, nor once —+ read there alone the cycle is held. On the screen the top line, less its flow, rises and falls of its own twice the+ cut: two steps, witnessed, nothing named."""+ report = _cut(tmp_path / "out", _keyed(tmp_path, _leaning(lambda k: _behind(k, cycle=17.5, hold=1, alike=True), -15)))+ _not_silent(report, 17.5)+ c = report["cycle"]+ said = c["cut_witness"]+ assert report["status"] == "passed" and abs(c["length"] - 17.5) <= 1 and said["cut"] == [c["start"], c["length"]]+ assert said["says"] == "two steps" and said["by"] == ["screen"] and "held" not in said+ assert said["lines"]["feet"]["says"] is None and "does not rise and fall twice an interval" in said["lines"]["feet"]["why"]assert not local_cycle.unwitnessed(c) and not any(local_cycle.UNWITNESSED in w for w in report["jolt"]["warnings"])