nex_animation/reports/ui_evidence/nex-p23/pixdiff.py

33 lines
1.7 KiB
Python

#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""Pixel diff: phase 23 visualcheck90 shots vs phase 22 baseline (S-2 must be invisible)."""
import pathlib, sys, hashlib, os
from PIL import Image, ImageChops
A = pathlib.Path(sys.argv[1] if len(sys.argv) > 1 else "reports/ui_evidence/nex-p22/visualcheck90/shots")
B = pathlib.Path(sys.argv[2] if len(sys.argv) > 2 else "reports/ui_evidence/nex-p23/visualcheck90/shots")
a = {p.name: p for p in A.glob("*.png")}
b = {p.name: p for p in B.glob("*.png")}
print("baseline %d shots · current %d shots" % (len(a), len(b)))
only_a, only_b = sorted(set(a) - set(b)), sorted(set(b) - set(a))
if only_a: print("ONLY IN BASELINE:", ", ".join(only_a))
if only_b: print("ONLY IN CURRENT:", ", ".join(only_b))
same_bytes = diff = 0
worst = []
for n in sorted(set(a) & set(b)):
ha, hb = hashlib.sha256(a[n].read_bytes()).hexdigest(), hashlib.sha256(b[n].read_bytes()).hexdigest()
if ha == hb:
same_bytes += 1; continue
ia, ib = Image.open(a[n]).convert("RGB"), Image.open(b[n]).convert("RGB")
if ia.size != ib.size:
diff += 1; worst.append((n, "SIZE %s vs %s" % (ia.size, ib.size), -1, -1)); continue
d = ImageChops.difference(ia, ib)
bbox = d.getbbox()
nz = sum(1 for px in d.getdata() if px != (0, 0, 0))
mx = max(max(px) for px in d.getdata())
diff += 1; worst.append((n, "bbox=%s" % (bbox,), nz, mx))
print("bytes-identical %d · differs %d · total compared %d" % (same_bytes, diff, len(set(a) & set(b))))
for n, why, nz, mx in worst:
print(" DIFF %-42s %s nonzero_px=%s max_delta=%s" % (n, why, nz, mx))
print("PIXDIFF_SUMMARY identical=%d differs=%d compared=%d max_delta_overall=%s" % (same_bytes, diff, len(set(a) & set(b)), max([w[3] for w in worst] or [0])))