Add BC5U support. Seen in Amnesia: The Bunker

This commit is contained in:
REDxEYE 2023-06-15 03:08:04 +03:00
parent bd4826591b
commit 9165771d5e
2 changed files with 10 additions and 4 deletions

View File

@ -254,6 +254,7 @@ class D3DFMT(IntEnum):
DXT5 = i32(b"DXT5")
DX10 = i32(b"DX10")
BC5S = i32(b"BC5S")
BC5U = i32(b"BC5U")
ATI1 = i32(b"ATI1")
ATI2 = i32(b"ATI2")
MULTI2_ARGB8 = i32(b"MET1")
@ -325,7 +326,8 @@ class DdsImageFile(ImageFile.ImageFile):
try:
fourcc = D3DFMT(fourcc_)
except ValueError:
raise NotImplementedError(f"Unimplemented pixel format {repr(fourcc_)}")
msg = f"Unimplemented pixel format {repr(fourcc_)}"
raise NotImplementedError(msg)
if fourcc == D3DFMT.DXT1:
self.mode = "RGBA"
self.pixel_format = "DXT1"
@ -346,6 +348,10 @@ class DdsImageFile(ImageFile.ImageFile):
self.mode = "RGB"
self.pixel_format = "BC5S"
tile = Image.Tile("bcn", extents, data_offs, (5, self.pixel_format))
elif fourcc == D3DFMT.BC5U:
self.mode = "RGB"
self.pixel_format = "BC5U"
tile = Image.Tile("bcn", extents, data_offs, (5, self.pixel_format))
elif fourcc == D3DFMT.ATI2:
self.mode = "RGB"
self.pixel_format = "BC5"
@ -407,7 +413,8 @@ class DdsImageFile(ImageFile.ImageFile):
def _save(im, fp, filename):
if im.mode not in ("RGB", "RGBA", "L", "LA"):
raise OSError(f"cannot write mode {im.mode} as DDS")
msg = f"cannot write mode {im.mode} as DDS"
raise OSError(msg)
pixel_flags = DDPF.RGB
if im.mode == "RGB":

View File

@ -546,8 +546,7 @@ def _encode_tile(im, fp, tile: List[Image.Tile], bufsize, fh, exc=None):
# slight speedup: compress to real file object
errcode = encoder.encode_to_file(fh, bufsize)
if errcode < 0:
msg =
f"encoder error {errcode} when writing image file"
msg = f"encoder error {errcode} when writing image file"
raise OSError(msg) from exc
finally:
encoder.cleanup()