Support RGB bitcount 8

This commit is contained in:
Andrew Murray 2023-10-25 16:24:00 +11:00
parent f58f410b21
commit 85485229e3
3 changed files with 13 additions and 6 deletions

BIN
Tests/images/rgb8.dds Normal file

Binary file not shown.

View File

@ -340,6 +340,12 @@ def test_open(mode, test_file):
assert_image_equal_tofile(im, test_file.replace(".dds", ".png"))
def test_open_rgb8():
with Image.open("Tests/images/rgb8.dds") as im:
assert im.mode == "L"
assert_image_equal_tofile(im, "Tests/images/mode-l.png")
@pytest.mark.parametrize(
("mode", "test_file"),
[

View File

@ -353,21 +353,22 @@ class DdsImageFile(ImageFile.ImageFile):
if pfflags & DDPF.RGB:
# Texture contains uncompressed RGB data
masks = {mask: ["R", "G", "B", "A"][i] for i, mask in enumerate(masks)}
if bitcount == 24:
if bitcount == 8:
self._mode = "L"
elif bitcount == 24:
self._mode = "RGB"
rawmode = masks[0x00FF0000] + masks[0x0000FF00] + masks[0x000000FF]
rawmode = masks[0x000000FF] + masks[0x0000FF00] + masks[0x00FF0000]
elif bitcount == 32 and pfflags & DDPF.ALPHAPIXELS:
self._mode = "RGBA"
rawmode = (
masks[0xFF000000]
+ masks[0x00FF0000]
masks[0x000000FF]
+ masks[0x0000FF00]
+ masks[0x000000FF]
+ masks[0x00FF0000]
+ masks[0xFF000000]
)
else:
msg = f"Unsupported bitcount {bitcount} for {pfflags}"
raise OSError(msg)
rawmode = rawmode[::-1]
elif pfflags & DDPF.LUMINANCE:
if bitcount == 8:
self._mode = "L"