From 6768b1417f010d589457e9f257a570538f00f247 Mon Sep 17 00:00:00 2001 From: Jennifer Taylor Date: Mon, 21 Dec 2020 23:40:43 +0000 Subject: [PATCH] Better 1555/565/4444 color extraction that scales colors to full 8-bit range. --- bemani/utils/afputils.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/bemani/utils/afputils.py b/bemani/utils/afputils.py index 65172d5..166f5c4 100644 --- a/bemani/utils/afputils.py +++ b/bemani/utils/afputils.py @@ -585,9 +585,17 @@ class AFPFile: f"{self.endian}H", raw_data[(64 + (i * 2)):(66 + (i * 2))], )[0] + + # Extract the raw values red = ((pixel >> 0) & 0x1F) << 3 green = ((pixel >> 5) & 0x3F) << 2 blue = ((pixel >> 11) & 0x1F) << 3 + + # Scale the colors so they fill the entire 8 bit range. + red = red | (red >> 5) + green = green | (green >> 6) + blue = blue | (blue >> 5) + newdata.append( struct.pack("> 15) & 0x1) != 0 else 0 red = ((pixel >> 0) & 0x1F) << 3 green = ((pixel >> 5) & 0x1F) << 3 blue = ((pixel >> 10) & 0x1F) << 3 + + # Scale the colors so they fill the entire 8 bit range. + red = red | (red >> 5) + green = green | (green >> 5) + blue = blue | (blue >> 5) + newdata.append( struct.pack("> 0) & 0xF) << 4 green = ((pixel >> 4) & 0xF) << 4 red = ((pixel >> 8) & 0xF) << 4 alpha = ((pixel >> 12) & 0xF) << 4 + + # Scale the colors so they fill the entire 8 bit range. + red = red | (red >> 4) + green = green | (green >> 4) + blue = blue | (blue >> 4) + alpha = alpha | (alpha >> 4) + newdata.append( struct.pack("