diff --git a/Tests/images/rgb8.dds b/Tests/images/rgb8.dds deleted file mode 100644 index 8193e8e5ac6..00000000000 Binary files a/Tests/images/rgb8.dds and /dev/null differ diff --git a/Tests/images/rgb8.png b/Tests/images/rgb8.png deleted file mode 100644 index 9d22a26a446..00000000000 Binary files a/Tests/images/rgb8.png and /dev/null differ diff --git a/Tests/test_file_dds.py b/Tests/test_file_dds.py index da7260cbf3b..e0f9fe7de15 100644 --- a/Tests/test_file_dds.py +++ b/Tests/test_file_dds.py @@ -41,7 +41,7 @@ TEST_FILE_DX10_BC1_TYPELESS, ), ) -def test_sanity_bc1(image_path): +def test_sanity_dxt1_bc1(image_path): """Check DXT1 images can be opened""" with Image.open(TEST_FILE_DXT1.replace(".dds", ".png")) as target: target = target.convert("RGBA") @@ -350,12 +350,6 @@ def test_save_unsupported_mode(tmp_path): im.save(out) -def test_open_rgb8(): - with Image.open("Tests/images/rgb8.dds") as im: - assert im.mode == "L" - assert_image_equal_tofile(im, "Tests/images/rgb8.png") - - @pytest.mark.parametrize( ("mode", "test_file"), [ diff --git a/src/PIL/DdsImagePlugin.py b/src/PIL/DdsImagePlugin.py index 30f021b7dc5..c09a8db3b9c 100644 --- a/src/PIL/DdsImagePlugin.py +++ b/src/PIL/DdsImagePlugin.py @@ -9,6 +9,7 @@ Full text of the CC0 license: https://creativecommons.org/publicdomain/zero/1.0/ """ + import io import struct import sys @@ -183,8 +184,8 @@ class DXGI_FORMAT(IntEnum): P208 = 130 V208 = 131 V408 = 132 - SAMPLER_FEEDBACK_MIN_MIP_OPAQUE = 133 - SAMPLER_FEEDBACK_MIP_REGION_USED_OPAQUE = 134 + SAMPLER_FEEDBACK_MIN_MIP_OPAQUE = 189 + SAMPLER_FEEDBACK_MIP_REGION_USED_OPAQUE = 190 class D3DFMT(IntEnum): @@ -351,9 +352,7 @@ def _open(self): # Texture contains uncompressed RGB data masks = struct.unpack("<4I", header.read(16)) masks = {mask: ["R", "G", "B", "A"][i] for i, mask in enumerate(masks)} - if bitcount == 8: - self._mode = "L" - elif bitcount == 24: + if bitcount == 24: self._mode = "RGB" rawmode = masks[0x000000FF] + masks[0x0000FF00] + masks[0x00FF0000] elif bitcount == 32 and pfflags & DDPF.ALPHAPIXELS: @@ -379,7 +378,7 @@ def _open(self): self._mode = "P" self.palette = ImagePalette.raw("RGBA", self.fp.read(1024)) elif pfflags & DDPF.FOURCC: - data_offs = header_size + 4 + offset = header_size + 4 if fourcc == D3DFMT.DXT1: self._mode = "RGBA" self.pixel_format = "DXT1" @@ -405,7 +404,7 @@ def _open(self): self.pixel_format = "BC5" n = 5 elif fourcc == D3DFMT.DX10: - data_offs += 20 + offset += 20 # ignoring flags which pertain to volume textures and cubemaps (dxgi_format,) = struct.unpack(" 0: fp.seek(offset)