1
0
mirror of synced 2025-01-31 12:13:49 +01:00

Support DXT5 image compression in ifs files.

This commit is contained in:
Jennifer Taylor 2021-05-24 17:37:47 +00:00
parent 88564ae11d
commit 64f8666590

View File

@ -5,6 +5,7 @@ import struct
from PIL import Image # type: ignore from PIL import Image # type: ignore
from typing import Callable, Dict, List, Optional, Tuple from typing import Callable, Dict, List, Optional, Tuple
from bemani.format.dxt import DXTBuffer
from bemani.protocol.binary import BinaryEncoding from bemani.protocol.binary import BinaryEncoding
from bemani.protocol.xml import XmlEncoding from bemani.protocol.xml import XmlEncoding
from bemani.protocol.lz77 import Lz77 from bemani.protocol.lz77 import Lz77
@ -190,7 +191,7 @@ class IFS:
if oldname in self.__files: if oldname in self.__files:
supported = False supported = False
if self.__decode_textures: if self.__decode_textures:
if textfmt in ["argb8888rev"]: if textfmt in ["argb8888rev", "dxt5"]:
# This is a supported file to decode # This is a supported file to decode
newname += ".png" newname += ".png"
supported = True supported = True
@ -309,9 +310,10 @@ class IFS:
crop = self.__uvsize[filename] crop = self.__uvsize[filename]
# Decode the image data itself. # Decode the image data itself.
width = img[1] - img[0]
height = img[3] - img[2]
if fmt == "argb8888rev": if fmt == "argb8888rev":
width = img[1] - img[0]
height = img[3] - img[2]
if len(filedata) < (width * height * 4): if len(filedata) < (width * height * 4):
left = (width * height * 4) - len(filedata) left = (width * height * 4) - len(filedata)
filedata = filedata + b'\x00' * left filedata = filedata + b'\x00' * left
@ -325,5 +327,25 @@ class IFS:
b = io.BytesIO() b = io.BytesIO()
png.save(b, format='PNG') png.save(b, format='PNG')
filedata = b.getvalue() 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 return filedata