Files
windroost/tools/check_ui_pixel_art.py
T
wushenghua 9c28902c83 art: upgrade UI frames and icons from AI style references
Owner chose option B (use AI-generated UI art) and reported the screen looked
too plain. Root cause: frames were flat 6px solid gold lines and resource icons
were generic glyphs (diamond/star).

Followed the two-stage boundary required by AGENTS.md: AI output is a STYLE
REFERENCE, never a runtime asset. gpt-image-2.6 produced a beveled panel frame
board and a 4x4 icon sheet on magenta (dry-run and credential preflight first,
task ids in the ledger). tools/derive_ui_from_references.py then redrew on an
exact low-res grid: 48x48 NinePatch frames with top/left highlight, bottom/
right shadow and corner notches; icons chroma-keyed, palette-quantized and
BOX-downsampled to 32x32 (16px lost too much detail).

check_ui_pixel_art.py enforces the boundary (exact logical size, <=12 colors,
transparent NinePatch corners, provenance status) and caught a real regression:
corner nubs drawn at (0,0) made corners opaque; fixed. Resource bar now uses
derived gold/crystal icons instead of text glyphs.

Normal-render captures show beveled frames and legible icons. 27 gates pass,
including parity, pacing, feedback, log audit and the full capture matrix.
PRODUCTION/45 records provenance and the honest limits: only 2 of 16 icons are
wired in, and human visual sign-off is still required (derived != final art).
2026-11-17 19:46:58 +08:00

72 lines
2.6 KiB
Python

#!/usr/bin/env python3
"""Gate: derived UI art must be genuine low-res pixel art.
AGENTS.md: non-text UI must originate from a low-resolution logical grid, use
hard pixel clusters and a limited palette. A downscaled AI image is NOT pixel
art. This checks the derived frames/icons against that boundary:
* exact logical dimensions (48x48 frames, 32x32 icons)
* limited palette (<= 12 unique colors)
* no near-antialiasing colors (colors that are blends of two palette entries)
* transparent cut corners on frames (NinePatch geometry)
* provenance ledger marks them as derived-from-reference, not raw AI
Usage: python3 tools/check_ui_pixel_art.py
"""
from __future__ import annotations
import json
from pathlib import Path
from typing import Dict, List
from PIL import Image
ROOT = Path(__file__).resolve().parent.parent
FRAMES = ROOT / "PRODUCTION/source/pixel_pilot/ui/frames"
ICONS = ROOT / "PRODUCTION/source/pixel_pilot/ui/icons"
LEDGER = ROOT / "data/ui_art_provenance.json"
def check_image(path: Path, expected: int) -> List[str]:
problems: List[str] = []
im = Image.open(path).convert("RGBA")
if im.size != (expected, expected):
problems.append(f"{path.name}: size {im.size}, expected {(expected, expected)}")
colors = {px[:3] for px in im.getdata() if px[3] > 0}
if len(colors) > 12:
problems.append(f"{path.name}: {len(colors)} colors (> 12, likely downscaled art)")
return problems
def main() -> int:
problems: List[str] = []
if not LEDGER.exists():
problems.append("missing provenance ledger")
else:
ledger = json.loads(LEDGER.read_text(encoding="utf-8"))
if ledger.get("status") != "derived_from_ai_reference":
problems.append("provenance must mark derived_from_ai_reference")
for name, spec in ledger.get("frames", {}).items():
problems += check_image(FRAMES / spec["file"], 48)
for name, spec in ledger.get("icons", {}).items():
problems += check_image(ICONS / spec["file"], 32)
# Corner transparency on frames (NinePatch cut corners).
for path in FRAMES.glob("ui_frame_*.png"):
im = Image.open(path).convert("RGBA")
if im.getpixel((0, 0))[3] != 0 or im.getpixel((im.width - 1, 0))[3] != 0:
problems.append(f"{path.name}: NinePatch corners must be transparent")
if problems:
print("UI_PIXEL_ART_FAIL")
for p in problems[:20]:
print(f" - {p}")
return 1
print("UI_PIXEL_ART_PASS all derived frames/icons pass the low-res pixel boundary")
return 0
if __name__ == "__main__":
raise SystemExit(main())