#!/usr/bin/env python3 """Fail if a smoke screenshot looks blank: usage `tools/check-shots.py [prefix]` (checks *.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)