From 64f866659081c327b9d12395dc706390f23ce481 Mon Sep 17 00:00:00 2001 From: Jennifer Taylor Date: Mon, 24 May 2021 17:37:47 +0000 Subject: [PATCH] Support DXT5 image compression in ifs files. --- bemani/format/ifs.py | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/bemani/format/ifs.py b/bemani/format/ifs.py index 3d14a18..2b3ae51 100644 --- a/bemani/format/ifs.py +++ b/bemani/format/ifs.py @@ -5,6 +5,7 @@ import struct from PIL import Image # type: ignore from typing import Callable, Dict, List, Optional, Tuple +from bemani.format.dxt import DXTBuffer from bemani.protocol.binary import BinaryEncoding from bemani.protocol.xml import XmlEncoding from bemani.protocol.lz77 import Lz77 @@ -190,7 +191,7 @@ class IFS: if oldname in self.__files: supported = False if self.__decode_textures: - if textfmt in ["argb8888rev"]: + if textfmt in ["argb8888rev", "dxt5"]: # This is a supported file to decode newname += ".png" supported = True @@ -309,9 +310,10 @@ class IFS: crop = self.__uvsize[filename] # Decode the image data itself. + width = img[1] - img[0] + height = img[3] - img[2] + if fmt == "argb8888rev": - width = img[1] - img[0] - height = img[3] - img[2] if len(filedata) < (width * height * 4): left = (width * height * 4) - len(filedata) filedata = filedata + b'\x00' * left @@ -325,5 +327,25 @@ class IFS: b = io.BytesIO() png.save(b, format='PNG') filedata = b.getvalue() + elif fmt == "dxt5": + dxt = DXTBuffer(width, height) + png = Image.frombuffer( + 'RGBA', + (width, height), + dxt.DXT5Decompress(filedata, swap=True), + 'raw', + 'RGBA', + 0, + 1, + ) + png = png.crop(( + crop[0] - img[0], + crop[2] - img[2], + crop[1] - img[0], + crop[3] - img[2], + )) + b = io.BytesIO() + png.save(b, format='PNG') + filedata = b.getvalue() return filedata