tools/client/compare_game_capture.py (1195B)
1 """Compare chat glyph pixels between stock and rebuilt 14.9.1 BB captures.""" 2 3 import hashlib 4 import json 5 import pathlib 6 7 import PIL.Image 8 9 10 root = pathlib.Path(__file__).resolve().parents[2] 11 masks = [] 12 captures = [] 13 for filename in ['bronto-burger-14.9.1.png', 'bronto-burger-14.9.1-rebuilt.png']: 14 path = root / 'docs/images' / filename 15 screenshot = PIL.Image.open(path).convert('RGB') 16 assert screenshot.size == (1024, 768) 17 18 # Compare the same three chat lines without smoothing or alignment changes. 19 mask = bytes(1 if pixel == (255, 255, 255) else 2 if pixel == (255, 0, 0) else 0 20 for pixel in screenshot.crop((0, 690, 250, 750)).get_flattened_data()) 21 assert 1 in mask and 2 in mask 22 masks.append(mask) 23 captures.append({'file': filename, 'image_sha256': hashlib.sha256(path.read_bytes()).hexdigest(), 24 'text_mask_sha256': hashlib.sha256(mask).hexdigest()}) 25 26 report = {'captures': captures, 'different_text_pixels': sum(a != b for a, b in zip(*masks))} 27 output = root / 'local/client/game-14.9.1/font-comparison.json' 28 output.write_text(json.dumps(report, indent=2) + '\n', encoding='ascii') 29 print(json.dumps(report, indent=2))