Skip to content

Generate clean 2D game sprites & animation atlases — component-row pipeline: state rows, alpha cleanup, frame extraction, runtime atlases. Codex/Claude skill.

test(breathe): a large pixel figure and two smooth busts keep their bytes, and `sprite-gen breathe` measures the anatomy and the smooth strain once per row (red)

Soohong Kim4560d5d3de14
diff --git a/tests/effects/test_breathe.py b/tests/effects/test_breathe.py
index 9d569a8..56db892 100644
--- a/tests/effects/test_breathe.py
+++ b/tests/effects/test_breathe.py
@@ -10,6 +10,7 @@
6. 행당 변형 상한 초과는 조용히 깎지 않고 멈춘다
"""
+import numpy as np
import pytest
from PIL import Image
@@ -195,6 +196,31 @@ def _small_outlined() -> Image.Image:
return im
+def _outlined_figure(h: int = 200) -> Image.Image:
+ """큰 도트 그림 — 둥근 머리, 목, 아래로 넓어지는 몸통, 옆으로 뻗은 팔, 1px 검은 외곽선, 눈.
+
+ 외곽선이 비스듬해 정수 행·열 사상이 곳곳을 2px 로 겹치고 다듬기가 실제로 지우고 옮긴다. 팔은
+ 부속이라 보호 가중이 켜진다. 다듬기·보호 가중·행 사상이 작은 픽스처보다 훨씬 많은 줄에서 돈다."""
+ w = int(h * 0.9)
+ pad = h // 10
+ tall = h - 2 * pad
+ yy, xx = np.mgrid[0:h, 0:w]
+ x, y = xx + 0.5 - w / 2.0, yy + 0.5 - pad
+ head = (x / (0.13 * tall)) ** 2 + ((y - 0.16 * tall) / (0.15 * tall)) ** 2 <= 1.0
+ neck = (np.abs(x) <= 0.05 * tall) & (y >= 0.29 * tall) & (y < 0.36 * tall)
+ torso = (y >= 0.34 * tall) & (y < tall) & (np.abs(x) <= (0.12 + 0.10 * (y - 0.34 * tall) / (0.66 * tall)) * tall)
+ arms = (y >= 0.40 * tall) & (y < 0.47 * tall) & (np.abs(x) <= 0.36 * tall)
+ figure = head | neck | torso | arms
+ inside = np.zeros_like(figure)
+ inside[1:-1, 1:-1] = figure[1:-1, 1:-1] & figure[:-2, 1:-1] & figure[2:, 1:-1] & figure[1:-1, :-2] & figure[1:-1, 2:]
+ a = np.zeros((h, w, 4), np.uint8)
+ a[figure] = (210, 185, 120, 255)
+ a[figure & ~inside] = (0, 0, 0, 255)
+ for ex in (-0.05 * tall, 0.05 * tall):
+ a[(np.abs(x - ex) <= 1.5) & (np.abs(y - 0.15 * tall) <= 1.5)] = (20, 20, 24, 255)
+ return Image.fromarray(a, "RGBA")
+
+
def test_side_outline_survives_every_phase() -> None:
"""가로 축소 위상에서도 좌우 1px 외곽선이 사라지지 않는다 (발끝 플리커 회귀, 2026-07-30).
diff --git a/tests/effects/test_breathe_js_mirror.py b/tests/effects/test_breathe_js_mirror.py
index 4552757..be7ee64 100644
--- a/tests/effects/test_breathe_js_mirror.py
+++ b/tests/effects/test_breathe_js_mirror.py
@@ -28,7 +28,8 @@ from sprite_gen.effects.breathe import (MAX_ROW_STRAIN, anatomy_fingerprint, #
row_strain)
from sprite_gen.frames.extract import solid_alpha_bbox # noqa: E402
from sprite_gen.serve.serve_curation import CURATOR_DIR # noqa: E402
-from tests.effects.test_breathe import CFG, _dome, _humanoid, _key, _small_outlined, _winged # noqa: E402
+from tests.effects.test_breathe import (CFG, _dome, _humanoid, _key, _outlined_figure, _small_outlined, # noqa: E402
+ _winged)
CURATOR_BREATHE = CURATOR_DIR / "src" / "breathe.js"
PHASES = [i / 12 for i in range(12)]
@@ -95,8 +96,11 @@ def _rgba(image):
(_dome, {"depth_x": 0.12}),
(_dome, {"depth": 0.10, "depth_x": 0.0}),
(_dome, {"depth": 0.10, "torso_half": 6}),
+ # 큰 도트 그림 — 다듬기·부속 보호·행 사상이 수백 줄에서 돈다. 굽기를 numpy 로 바꿔도 미러(바꾸지
+ # 않은 화소 순회)와 바이트가 같은지 여기서 본다.
+ (_outlined_figure, {}),
], ids=["humanoid", "winged", "small-outlined-thinning",
- "dome-depth-x", "dome-depth-x-zero", "dome-manual-band"])
+ "dome-depth-x", "dome-depth-x-zero", "dome-manual-band", "outlined-figure"])
def test_curator_mirror_is_byte_identical_to_the_bake(build, overrides, tmp_path):
src = build()
cfg = {**CFG, **overrides}
diff --git a/tests/effects/test_breathe_smooth.py b/tests/effects/test_breathe_smooth.py
index 30aeaaf..c2d0689 100644
--- a/tests/effects/test_breathe_smooth.py
+++ b/tests/effects/test_breathe_smooth.py
@@ -36,7 +36,7 @@ from sprite_gen.effects import breathe as B
from sprite_gen.effects.anatomy import analyze
from sprite_gen.frames.extract import solid_alpha_bbox
-from tests.effects.test_breathe import _dome, _humanoid, _winged
+from tests.effects.test_breathe import _dome, _humanoid, _outlined_figure, _winged
SKIN = (222, 184, 150, 255)
BODY = (170, 120, 96, 255)
@@ -279,15 +279,17 @@ def test_no_seam_or_tear_between_the_head_and_the_body(h: int) -> None:
# ── 7. pixel 기본은 바이트 같다 ─────────────────────────────────────
# 이 플랜 전(59b2738)의 굽기 결과 — breaths 2, 12칸. 기본 경로가 한 바이트라도 바뀌면 깨진다.
+# `_outlined_figure` 는 굽기를 numpy 로 바꾸기 전(17f7490)에 잰 값이다 — 다듬기가 실제로 지우고 옮기는 큰 그림.
PIXEL_GOLDEN = {
"_humanoid": "4f212002c8cec96f4b207b56eec5195b2549069bbc066511385e3a92c74c1fcc",
"_winged": "5bdf0c0997cf799bc7e3a82374dce16fb65db3545fb3a5f1f1df7b249fcbaf0d",
"_dome": "492db9827109db3cf48d655437d102f22b1db4843d7121c4f4c65ea3a9fee443",
+ "_outlined_figure": "3dbc6bb827eb3d7b2fdbe96e3f1a7a2c094cbb99e1880a523341ce1cbc627c63",
}
PIXEL_KEYS = ["anatomy", "axis_x", "breaths", "depth", "depth_x", "lag", "rigid_row", "torso_half"]
[email protected]("build", [_humanoid, _winged, _dome], ids=lambda b: b.__name__)
[email protected]("build", [_humanoid, _winged, _dome, _outlined_figure], ids=lambda b: b.__name__)
@pytest.mark.parametrize("mode", [None, "pixel"], ids=["mode-omitted", "mode-pixel"])
def test_the_default_pixel_mode_is_byte_identical_to_before(build, mode) -> None:
raw = {"depth": 0.06, "breaths": 2, "lag": 0.1}
@@ -386,6 +388,23 @@ def test_neutral_facing_values_bake_the_same_bytes(h, raw, digest, neutral) -> N
"몸 방향 값이 중립인데 smooth 굽기가 바뀌었다"
+# 굽기를 빠르게 하기 전(17f7490)의 smooth 굽기 — 12칸. 몸 방향 값을 다 쓴 가슴과, 양옆 변에 닿은 흉상.
+# 변위장을 움직이는 화소에서만 다시 풀어도 같은 바이트여야 한다.
+SMOOTH_SPEEDUP_GOLDEN = [
+ (dict(h=400), {"mode": "smooth", "breaths": 2, "chest_tilt": 20, "chest_bias": 0.4, "chest_dir": -15,
+ "chest_x": 0.1, "chest_bias_y": 0.2, "chest_flat": 0.2},
+ "48e6f8f1d976efceca3fb73857375dd1db232c62302de8768ade505008bf7c10"),
+ (dict(h=300, margin=0.0), {"mode": "smooth", "breaths": 1, "depth": 0.02},
+ "c233ec9c948663308bfe70f1b5e5affc5229c0ef2be4f982c9f5168b45389186"),
+]
+
+
[email protected]("bust,raw,digest", SMOOTH_SPEEDUP_GOLDEN, ids=["facing", "cut-at-the-sides"])
+def test_the_smooth_bake_keeps_its_bytes(bust, raw, digest) -> None:
+ frames, _ = B.bake_breathe_sequence([_bust(**bust)] * 12, _cfg(raw))
+ assert hashlib.sha256(b"".join(f.tobytes() for f in frames)).hexdigest() == digest, "smooth 굽기가 바뀌었다"
+
+
def _field(anat, cfg, x, y):
dx, dy = B.smooth_displacement(anat, cfg, np.array([float(x)]), np.array([float(y)]), 1.0, 0.0)
return float(dx[0]), float(dy[0])
@@ -674,6 +693,28 @@ def test_the_cli_bakes_what_the_curation_bake_bakes(tmp_path, raw, flags) -> Non
assert report["resolved"]["anatomy"]["rigid_row"] == analyze(frames[0]).rigid_row
+def test_the_cli_measures_the_row_once(tmp_path, monkeypatch) -> None:
+ """`sprite-gen breathe` 는 기준 칸을 한 번 잰다 — 보고와 굽기가 같은 해부를 쓴다. 행당 변형도 줄에 한 번
+ 잰다 — 해부와 설정에만 달린 값이다. 960 칸 하나에 해부가 약 0.5 초, 행당 변형이 약 0.03 초다."""
+ from sprite_gen import cli
+
+ calls = {"analyze": 0, "smooth_strain": 0}
+ for name in calls:
+ real = getattr(B, name)
+
+ def counted(*args, _real=real, _name=name, **kwargs):
+ calls[_name] += 1
+ return _real(*args, **kwargs)
+
+ monkeypatch.setattr(B, name, counted)
+ src = tmp_path / "loop"
+ src.mkdir()
+ for i, im in enumerate(_blinking()):
+ im.save(src / f"frame-{i:03d}.png")
+ assert cli.main(["breathe", str(src), str(tmp_path / "out"), "--mode", "smooth", "--breaths", "2"]) == 0
+ assert calls == {"analyze": 1, "smooth_strain": 1}
+
+
def test_the_cli_refuses_what_the_sidecar_refuses(tmp_path) -> None:
from sprite_gen import cli