diff --git a/Tests/images/bc4u.dds b/Tests/images/bc4u.dds new file mode 100644 index 00000000000..7f9f050b6f1 Binary files /dev/null and b/Tests/images/bc4u.dds differ diff --git a/Tests/images/unimplemented_fourcc.dds b/Tests/images/unimplemented_fourcc.dds deleted file mode 100755 index 4795573646b..00000000000 Binary files a/Tests/images/unimplemented_fourcc.dds and /dev/null differ diff --git a/Tests/images/unknown_fourcc.dds b/Tests/images/unknown_fourcc.dds deleted file mode 100755 index 41a34388615..00000000000 Binary files a/Tests/images/unknown_fourcc.dds and /dev/null differ diff --git a/Tests/test_file_dds.py b/Tests/test_file_dds.py index def548a34c5..b33c01a203a 100644 --- a/Tests/test_file_dds.py +++ b/Tests/test_file_dds.py @@ -17,6 +17,7 @@ TEST_FILE_DX10_BC5_SNORM = "Tests/images/bc5_snorm.dds" TEST_FILE_DX10_BC1 = "Tests/images/bc1.dds" TEST_FILE_DX10_BC1_TYPELESS = "Tests/images/bc1_typeless.dds" +TEST_FILE_BC4U = "Tests/images/bc4u.dds" TEST_FILE_BC5S = "Tests/images/bc5s.dds" TEST_FILE_BC5U = "Tests/images/bc5u.dds" TEST_FILE_BC6H = "Tests/images/bc6h.dds" @@ -80,10 +81,18 @@ def test_sanity_dxt5(): assert_image_equal_tofile(im, TEST_FILE_DXT5.replace(".dds", ".png")) -def test_sanity_ati1(): +@pytest.mark.parametrize( + "image_path", + ( + TEST_FILE_ATI1, + # hexeditted to use BC4U FourCC + TEST_FILE_BC4U, + ), +) +def test_sanity_ati1_bc4u(image_path): """Check ATI1 images can be opened""" - with Image.open(TEST_FILE_ATI1) as im: + with Image.open(image_path) as im: im.load() assert im.format == "DDS" @@ -210,12 +219,6 @@ def test_dx10_r8g8b8a8_unorm_srgb(): ) -def test_unimplemented_dxgi_format(): - with pytest.raises(NotImplementedError): - with Image.open("Tests/images/unimplemented_dxgi_format.dds"): - pass - - @pytest.mark.parametrize( ("mode", "size", "test_file"), [ diff --git a/src/PIL/DdsImagePlugin.py b/src/PIL/DdsImagePlugin.py index 581e60a3f08..30f021b7dc5 100644 --- a/src/PIL/DdsImagePlugin.py +++ b/src/PIL/DdsImagePlugin.py @@ -345,11 +345,11 @@ def _open(self): # pixel format pfsize, pfflags, fourcc, bitcount = struct.unpack("<4I", header.read(16)) - masks = struct.unpack("<4I", header.read(16)) n = 0 rawmode = None if pfflags & DDPF.RGB: # 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"