import sys from PIL import Image BOX = (8, 52, 648, 531) # the DOSBox client area = the gauge framebuffer SHIPPED = "shipped.png" def load(p): return Image.open(p).convert("RGB").crop(BOX) def magenta(p): return p[0] > 150 and p[2] > 150 and p[1] < 140 def score(path): a, b = load(SHIPPED), load(path) if a.size != b.size: return "%-10s SIZE MISMATCH %s vs %s" % (path, a.size, b.size) pa, pb = a.load(), b.load() w, h = a.size same = lit_ship = lit_both = mag = 0 for y in range(h): for x in range(w): s, o = pa[x, y], pb[x, y] if s == o: same += 1 if sum(s) > 60: lit_ship += 1 if sum(o) > 60: lit_both += 1 if 0 <= x < 200 and 0 <= y < 60 and magenta(o): mag += 1 n = w * h return "%-10s identical %5.1f%% coverage %3d%% title-band magenta %4d" % ( path, 100.0 * same / n, round(100.0 * lit_both / max(lit_ship, 1)), mag) for p in sys.argv[1:]: print(score(p))