mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-02-03 21:24:31 +03:00
Add support for single channel textures
This commit is contained in:
parent
3f77a9e235
commit
19887374ae
|
@ -309,6 +309,7 @@ def test_save_unsupported_mode(tmp_path):
|
|||
("LA", "Tests/images/uncompressed_la.png"),
|
||||
("RGB", "Tests/images/hopper.png"),
|
||||
("RGBA", "Tests/images/pil123rgba.png"),
|
||||
("L", "Tests/images/ATI1.dds"),
|
||||
],
|
||||
)
|
||||
def test_save(mode, test_file, tmp_path):
|
||||
|
|
|
@ -321,12 +321,18 @@ class DdsImageFile(ImageFile.ImageFile):
|
|||
elif pfflags & DDPF.RGB:
|
||||
# Texture contains uncompressed RGB data
|
||||
masks = {mask: ["R", "G", "B", "A"][i] for i, mask in enumerate(masks)}
|
||||
rawmode = ""
|
||||
if bitcount == 32:
|
||||
rawmode += masks[0xFF000000]
|
||||
else:
|
||||
if bitcount == 8:
|
||||
self.mode = "L"
|
||||
rawmode = "L"
|
||||
elif bitcount == 24:
|
||||
self.mode = "RGB"
|
||||
rawmode += masks[0xFF0000] + masks[0xFF00] + masks[0xFF]
|
||||
rawmode = masks[0xFF0000] + masks[0xFF00] + masks[0xFF]
|
||||
elif bitcount == 32:
|
||||
self.mode = "RGBA"
|
||||
rawmode = masks[0xFF000000] + masks[0xFF0000] + masks[0xFF00] + masks[0xFF]
|
||||
else:
|
||||
raise OSError(f'Unsupported bitcount {bitcount} for DDS texture')
|
||||
|
||||
|
||||
self.tile = [("raw", (0, 0) + self.size, 0, (rawmode[::-1], 0, 1))]
|
||||
elif pfflags & DDPF.FOURCC:
|
||||
|
@ -404,6 +410,8 @@ class DdsImageFile(ImageFile.ImageFile):
|
|||
|
||||
|
||||
def _save(im, fp, filename):
|
||||
if im.mode not in ("RGB", "RGBA", "L"):
|
||||
raise OSError(f"cannot write mode {im.mode} as DDS")
|
||||
if im.mode not in ("RGB", "RGBA", "L", "LA"):
|
||||
msg = f"cannot write mode {im.mode} as DDS"
|
||||
raise OSError(msg)
|
||||
|
|
Loading…
Reference in New Issue
Block a user