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): pixel's refusal of a frame pushed off the cell names the sides and how many went past each, and points at smooth when the side is the drawing's own border — in the bake and in the curator mirror (red)

Soohong Kimad229b7d2738
diff --git a/tests/effects/test_breathe.py b/tests/effects/test_breathe.py
index 56db892..acbe294 100644
--- a/tests/effects/test_breathe.py
+++ b/tests/effects/test_breathe.py
@@ -10,6 +10,8 @@
6. 행당 변형 상한 초과는 조용히 깎지 않고 멈춘다
"""
+import re
+
import numpy as np
import pytest
from PIL import Image
@@ -534,6 +536,59 @@ def test_clipping_the_cell_raises_instead_of_cropping_the_head() -> None:
assert "셀 밖으로" in str(err.value)
+def _cut_bust(touch: bool = True) -> Image.Image:
+ """화면 왼쪽 변에 잘린 흉상 — 소매가 바깥 열을 38px 덮는다(`touch`). 몸통 축이 소매 쪽으로 끌려 있어
+ pixel 의 가로 늘임이 축 왼쪽을 밖으로 밀고, 소매가 셀 밖으로 나간다. 머리 위와 오른쪽에는 여백이 있다.
+ `touch=False` 면 소매가 변에서 1px 떨어져 있다 — 같은 밀림이지만 그림 자체의 테두리가 아니다."""
+ im = Image.new("RGBA", (120, 130), (0, 0, 0, 0))
+ px = im.load()
+
+ def fill(x0, y0, x1, y1, color):
+ for y in range(y0, y1):
+ for x in range(x0, x1):
+ px[x, y] = color
+
+ fill(52, 8, 80, 40, (222, 184, 150, 255)) # 머리
+ fill(60, 40, 72, 50, (222, 184, 150, 255)) # 목 (병목)
+ fill(34, 50, 98, 130, (170, 120, 96, 255)) # 몸통 — 화면 아래 변에 닿는다
+ fill(0 if touch else 1, 62, 34, 100, (90, 110, 170, 255)) # 소매 — 왼쪽 변
+ return im
+
+
+def _clip_refusal(src: Image.Image) -> str:
+ with pytest.raises(SystemExit) as err:
+ bake_breathe_sequence([src] * 12, dict(CFG))
+ return str(err.value)
+
+
+def test_a_clip_on_the_drawings_own_border_points_at_smooth() -> None:
+ """화면에 잘린 그림(큰 일러·영상 칸)을 pixel 이 거절할 때 — 거절은 그대로, 문구는 어느 변으로 몇 개가
+ 나갔는지와, 그 변이 그림 자체의 테두리면(바깥 줄을 그 변 길이의 2 % 이상 덮으면, video-frames 와 같은
+ 판정) smooth 를 말한다. 여백을 붙여 굽고 잘라 내는 우회는 밀려 나간 만큼을 조용히 잃는다.
+ smooth 는 같은 그림을 거절 없이 굽고 그 변을 그대로 둔다."""
+ src = _cut_bust()
+ message = _clip_refusal(src)
+ clipped = int(re.search(r"불투명 픽셀 (\d+)개가 잘린다", message).group(1))
+ assert f"왼쪽 변 밖 {clipped}" in message, message
+ assert "위 변 밖" not in message and "오른쪽 변 밖" not in message, message
+ assert "왼쪽 변 바깥 줄 38 px" in message, message
+ assert "--mode smooth" in message and "잘라 내지 마라" in message, message
+
+ smooth = state_breathe({"states": {"idle": {"breathe": {"mode": "smooth", "breaths": 1}}}}, "idle")
+ frames, _ = bake_breathe_sequence([src] * 12, smooth)
+ edge = [src.getpixel((0, y)) for y in range(src.height)]
+ for i, frame in enumerate(frames):
+ assert [frame.getpixel((0, y)) for y in range(frame.height)] == edge, f"{i}번 칸: 왼쪽 변이 움직였다"
+
+
+def test_a_clip_off_the_drawings_border_keeps_the_margin_advice() -> None:
+ """변에 닿지 않은 그림이 밀려 나가면 여백이 모자란 것이다 — smooth 를 권하지 않는다."""
+ message = _clip_refusal(_cut_bust(touch=False))
+ assert re.search(r"왼쪽 변 밖 \d+", message), message
+ assert "--mode smooth" not in message, message
+ assert "셀 여백을 늘리거나 depth 를 낮춰라" in message, message
+
+
# ── 8. 얼굴이 몸통에 있는 실루엣 (목 없음) ─────────────────────────
def test_face_on_the_body_pushes_the_boundary_below_the_face() -> None:
diff --git a/tests/effects/test_breathe_js_mirror.py b/tests/effects/test_breathe_js_mirror.py
index be7ee64..e96da0e 100644
--- a/tests/effects/test_breathe_js_mirror.py
+++ b/tests/effects/test_breathe_js_mirror.py
@@ -14,6 +14,7 @@ skip 사유를 남긴다.
"""
import json
+import re
import shutil
import subprocess
import sys
@@ -28,8 +29,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, _outlined_figure, _small_outlined, # noqa: E402
- _winged)
+from tests.effects.test_breathe import (CFG, _cut_bust, _dome, _humanoid, _key, _outlined_figure, # noqa: E402
+ _small_outlined, _winged)
CURATOR_BREATHE = CURATOR_DIR / "src" / "breathe.js"
PHASES = [i / 12 for i in range(12)]
@@ -179,6 +180,45 @@ def test_the_mirror_refuses_exactly_what_the_bake_refuses(tmp_path):
assert got["refused"], f"BreatheRefused 가 아닌 예외로 죽었다: {got['message']}"
+def _wording(message: str) -> str:
+ """거절 문구에서 두 쪽이 같아야 하는 부분 — 굽기만 붙이는 머리말과 콘텐츠 상자를 뺀다."""
+ return re.sub(r" \(셀 [^)]*\)", "", message.removeprefix("breathe: "))
+
+
[email protected](shutil.which("node") is None, reason="node 가 없어 JS 미러를 실행할 수 없다")
[email protected]("touch", [True, False], ids=["border", "off-border"])
+def test_the_mirror_words_a_clip_as_the_bake_does(touch, tmp_path):
+ """미러의 거절 문구도 굽기와 같다 — 나간 변과 변별 개수, 그 변이 그림 자체의 테두리면 smooth 안내.
+ 큐레이터 미리보기가 굽기와 다른 까닭을 말하면 사용자는 둘 중 어느 말을 믿을지 모른다."""
+ src = _cut_bust(touch)
+ cfg = dict(CFG)
+ cfg["anatomy"] = freeze_anatomy(src, cfg, _key())
+ said = {}
+ for phase in PHASES:
+ try:
+ phase_frame(src, cfg, phase)
+ except SystemExit as exc:
+ said[phase] = str(exc)
+ assert said, "이 픽스처는 굽기가 거부하는 위상을 가져야 의미가 있다"
+
+ payload = {
+ "script": str(CURATOR_BREATHE), "width": src.width, "height": src.height,
+ "cfg": {"depth": cfg["depth"], "breaths": cfg["breaths"], "lag": cfg["lag"], "anatomy": cfg["anatomy"]},
+ "cases": [{"phase": p, "rgba": _rgba(src)} for p in said],
+ "out": str(tmp_path / "js.json"),
+ }
+ (tmp_path / "payload.json").write_text(json.dumps(payload), encoding="utf-8")
+ (tmp_path / "harness.cjs").write_text(HARNESS, encoding="utf-8")
+ proc = subprocess.run([shutil.which("node"), str(tmp_path / "harness.cjs"),
+ str(tmp_path / "payload.json")], capture_output=True, encoding="utf-8")
+ assert proc.returncode == 0, f"node 하네스 실패:\n{proc.stderr}"
+ js = json.loads((tmp_path / "js.json").read_text(encoding="utf-8"))
+ for (phase, message), got in zip(said.items(), js):
+ assert not got["ok"] and got["refused"], f"위상 {phase:.4f}: 굽기는 거부했는데 미러는 {got}"
+ assert _wording(got["message"]) == _wording(message), f"위상 {phase:.4f}"
+ assert ("--mode smooth" in message) == touch
+
+
@pytest.mark.skipif(shutil.which("node") is None, reason="node 가 없어 JS 미러를 실행할 수 없다")
def test_the_mirror_matches_on_frames_other_than_the_frozen_one(tmp_path):
"""줄의 **다른** 프레임에서도 굽기와 미러가 같아야 한다.