"""Pixel-diff two screenshot dirs (matching filenames). Usage: python3 audit/appshell_pixdiff.py DIR_A DIR_B [label_a label_b] Prints per-file diff pixel counts + max channel delta; PIXDIFF-ZERO if every shared file matches bit-for-bit. Also flags size mismatches.""" import os, sys from PIL import Image, ImageChops A, B = sys.argv[1], sys.argv[2] la, lb = (sys.argv[3:5] or ['A', 'B']) fa = sorted(f for f in os.listdir(A) if f.endswith('.png')) fb = sorted(f for f in os.listdir(B) if f.endswith('.png')) missing = set(fa) - set(fb) if missing: print('FILES MISSING IN', lb, ':', sorted(missing)) zero, n = True, 0 for f in fa: if f not in fb: continue n += 1 ia, ib = Image.open(os.path.join(A, f)), Image.open(os.path.join(B, f)) if ia.size != ib.size: print(f'{f}: SIZE DIFF {ia.size} vs {ib.size}') zero = False continue d = ImageChops.difference(ia.convert('RGB'), ib.convert('RGB')) bbox = d.getbbox() if bbox is None: print(f'{f}: 0 px diff (identical)') else: hist = d.convert('L').histogram() ndiff = sum(hist[1:]) mx = max(i for i, c in enumerate(hist) if c) pct = ndiff / (ia.size[0] * ia.size[1]) * 100 print(f'{f}: {ndiff} px diff ({pct:.4f}%), bbox {bbox}, maxdelta {mx}') zero = False if n == 0: print('no shared files!') zero = False print('PIXTDIFF-ZERO' if zero else 'PIXTDIFF-NONZERO') sys.exit(0 if zero else 1)