From 0e954b17cbef3666da6145b01ea9cf33a1c044f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Fri, 30 Oct 2026 18:03:46 +0100 Subject: [PATCH] adhoc_session.py: A reference image's alpha channel masks what until compares For text over a moving background: only the opaque pixels count. Co-Authored-By: Claude Opus 5.5 --- Tools/adhoc_session.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Tools/adhoc_session.py b/Tools/adhoc_session.py index 81b3af17e3..ee38d87fe4 100644 --- a/Tools/adhoc_session.py +++ b/Tools/adhoc_session.py @@ -396,10 +396,14 @@ def screen_matches(args, image): want = bytes.fromhex(args.color) have = image.convert("RGB").getpixel((x, y)) return max(abs(a - b) for a, b in zip(have, want)) <= args.tolerance - ref = Image.open(script_path(args, args.ref)).convert("RGB") + ref = Image.open(script_path(args, args.ref)) + # A reference with an alpha channel is compared only where it's opaque: text over a moving + # background, say, with only the letters kept. + mask = ref.getchannel("A").point(lambda a: 255 if a >= 128 else 0) if "A" in ref.getbands() else None + ref = ref.convert("RGB") x, y = parse_ints(args.box, 2)[:2] if args.box else (0, 0) region = image.convert("RGB").crop((x, y, x + ref.width, y + ref.height)) - diff = ImageStat.Stat(ImageChops.difference(region, ref)).mean + diff = ImageStat.Stat(ImageChops.difference(region, ref), mask).mean return sum(diff) / len(diff) <= args.tolerance