mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-11-16 19:13:40 +01:00
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 <noreply@anthropic.com>
This commit is contained in:
1 parent
958d76ea77
commit
0e954b17cb
1 file changed
+6
-2
@@ -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
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user