Nacre/tools/check-shots.py
astar76 1a1c386e43 S008: every nacre:// page smoke and blank-shot checker
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-12 11:19:54 -06:00

22 lines
886 B
Python
Executable file

#!/usr/bin/env python3
"""Fail if a smoke screenshot looks blank: usage `tools/check-shots.py <outdir> [prefix]` (checks <prefix>*.png).
A shot is blank when its window area has fewer than 8 distinct colours or one colour covers over 99.5 % of it."""
import sys
from collections import Counter
from pathlib import Path
from PIL import Image
out = Path(sys.argv[1])
prefix = sys.argv[2] if len(sys.argv) > 2 else ""
bad = 0
shots = sorted(out.glob(prefix + "*.png"))
for shot in shots:
image = Image.open(shot).convert("RGB")
colours = Counter(image.getdata())
top = colours.most_common(1)[0][1] / (image.width * image.height)
blank = len(colours) < 8 or top > 0.995
print(f"{'BLANK' if blank else 'ok '} {shot.name}: {len(colours)} colours, {top:.1%} one colour")
bad += blank
print(f"{len(shots)} shots, {bad} blank")
sys.exit(1 if bad or not shots else 0)