mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-09-22 03:49:03 +03:00
Add BC5U support. Seen in Amnesia: The Bunker
This commit is contained in:
parent
bd4826591b
commit
9165771d5e
|
@ -254,6 +254,7 @@ class D3DFMT(IntEnum):
|
||||||
DXT5 = i32(b"DXT5")
|
DXT5 = i32(b"DXT5")
|
||||||
DX10 = i32(b"DX10")
|
DX10 = i32(b"DX10")
|
||||||
BC5S = i32(b"BC5S")
|
BC5S = i32(b"BC5S")
|
||||||
|
BC5U = i32(b"BC5U")
|
||||||
ATI1 = i32(b"ATI1")
|
ATI1 = i32(b"ATI1")
|
||||||
ATI2 = i32(b"ATI2")
|
ATI2 = i32(b"ATI2")
|
||||||
MULTI2_ARGB8 = i32(b"MET1")
|
MULTI2_ARGB8 = i32(b"MET1")
|
||||||
|
@ -325,7 +326,8 @@ class DdsImageFile(ImageFile.ImageFile):
|
||||||
try:
|
try:
|
||||||
fourcc = D3DFMT(fourcc_)
|
fourcc = D3DFMT(fourcc_)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise NotImplementedError(f"Unimplemented pixel format {repr(fourcc_)}")
|
msg = f"Unimplemented pixel format {repr(fourcc_)}"
|
||||||
|
raise NotImplementedError(msg)
|
||||||
if fourcc == D3DFMT.DXT1:
|
if fourcc == D3DFMT.DXT1:
|
||||||
self.mode = "RGBA"
|
self.mode = "RGBA"
|
||||||
self.pixel_format = "DXT1"
|
self.pixel_format = "DXT1"
|
||||||
|
@ -346,6 +348,10 @@ class DdsImageFile(ImageFile.ImageFile):
|
||||||
self.mode = "RGB"
|
self.mode = "RGB"
|
||||||
self.pixel_format = "BC5S"
|
self.pixel_format = "BC5S"
|
||||||
tile = Image.Tile("bcn", extents, data_offs, (5, self.pixel_format))
|
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:
|
elif fourcc == D3DFMT.ATI2:
|
||||||
self.mode = "RGB"
|
self.mode = "RGB"
|
||||||
self.pixel_format = "BC5"
|
self.pixel_format = "BC5"
|
||||||
|
@ -407,7 +413,8 @@ class DdsImageFile(ImageFile.ImageFile):
|
||||||
|
|
||||||
def _save(im, fp, filename):
|
def _save(im, fp, filename):
|
||||||
if im.mode not in ("RGB", "RGBA", "L", "LA"):
|
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
|
pixel_flags = DDPF.RGB
|
||||||
if im.mode == "RGB":
|
if im.mode == "RGB":
|
||||||
|
|
|
@ -546,8 +546,7 @@ def _encode_tile(im, fp, tile: List[Image.Tile], bufsize, fh, exc=None):
|
||||||
# slight speedup: compress to real file object
|
# slight speedup: compress to real file object
|
||||||
errcode = encoder.encode_to_file(fh, bufsize)
|
errcode = encoder.encode_to_file(fh, bufsize)
|
||||||
if errcode < 0:
|
if errcode < 0:
|
||||||
msg =
|
msg = f"encoder error {errcode} when writing image file"
|
||||||
f"encoder error {errcode} when writing image file"
|
|
||||||
raise OSError(msg) from exc
|
raise OSError(msg) from exc
|
||||||
finally:
|
finally:
|
||||||
encoder.cleanup()
|
encoder.cleanup()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user