From ff147a37b10863c20ec7ce05cb8b68c2921dddbb Mon Sep 17 00:00:00 2001 From: Jennifer Taylor Date: Mon, 23 Nov 2020 20:55:00 +0000 Subject: [PATCH] Support an additional texture format found in updated BishiBashi JP data, document mapping to D3D9 structures. --- bemani/utils/afputils.py | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/bemani/utils/afputils.py b/bemani/utils/afputils.py index 74770f7..e79626a 100644 --- a/bemani/utils/afputils.py +++ b/bemani/utils/afputils.py @@ -459,7 +459,7 @@ class AFPFile: raise Exception("Unexpected texture format!") if fmt == 0x0B: - # 16-bit 565 color RGB format. + # 16-bit 565 color RGB format. Game references D3D9 texture format 23 (R5G6B5). newdata = [] for i in range(width * height): pixel = struct.unpack( @@ -476,11 +476,31 @@ class AFPFile: 'RGB', (width, height), b''.join(newdata), 'raw', 'RGB', ) elif fmt == 0x0E: - # RGB image, no alpha. + # RGB image, no alpha. Game references D3D9 texture format 22 (R8G8B8). img = Image.frombytes( 'RGB', (width, height), raw_data[64:], 'raw', 'RGB', ) - # 0x10 = Seems to be some sort of RGB with color swapping. + elif fmt == 0x10: + # Seems to be some sort of RGB with color swapping. + pass + elif fmt == 0x13: + # Some 16-bit texture format. Game references D3D9 texture format 25 (A1R5G5B5). + newdata = [] + for i in range(width * height): + pixel = struct.unpack( + f"{self.endian}H", + raw_data[(64 + (i * 2)):(66 + (i * 2))], + )[0] + alpha = 255 if ((pixel >> 15) & 0x1) != 0 else 0 + red = ((pixel >> 0) & 0x1F) << 3 + green = ((pixel >> 5) & 0x1F) << 3 + blue = ((pixel >> 10) & 0x1F) << 3 + newdata.append( + struct.pack("