Skip to content

Commit 87a08e2

Browse files
authored
Merge pull request #6457 from REDxEYE/ATI1-2_support
Add support for ATI1/2(BC4/BC5) DDS files
2 parents ce7af49 + cf9e2ae commit 87a08e2

File tree

5 files changed

+36
-0
lines changed

5 files changed

+36
-0
lines changed

Tests/images/ati1.dds

2.83 KB
Binary file not shown.

Tests/images/ati1.png

969 Bytes
Loading

Tests/images/ati2.dds

85.5 KB
Binary file not shown.

Tests/test_file_dds.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
TEST_FILE_DXT1 = "Tests/images/dxt1-rgb-4bbp-noalpha_MipMaps-1.dds"
1111
TEST_FILE_DXT3 = "Tests/images/dxt3-argb-8bbp-explicitalpha_MipMaps-1.dds"
1212
TEST_FILE_DXT5 = "Tests/images/dxt5-argb-8bbp-interpolatedalpha_MipMaps-1.dds"
13+
TEST_FILE_ATI1 = "Tests/images/ati1.dds"
14+
TEST_FILE_ATI2 = "Tests/images/ati2.dds"
1315
TEST_FILE_DX10_BC5_TYPELESS = "Tests/images/bc5_typeless.dds"
1416
TEST_FILE_DX10_BC5_UNORM = "Tests/images/bc5_unorm.dds"
1517
TEST_FILE_DX10_BC5_SNORM = "Tests/images/bc5_snorm.dds"
@@ -62,6 +64,32 @@ def test_sanity_dxt5():
6264
assert_image_equal_tofile(im, TEST_FILE_DXT5.replace(".dds", ".png"))
6365

6466

67+
def test_sanity_ati1():
68+
"""Check ATI1 images can be opened"""
69+
70+
with Image.open(TEST_FILE_ATI1) as im:
71+
im.load()
72+
73+
assert im.format == "DDS"
74+
assert im.mode == "L"
75+
assert im.size == (64, 64)
76+
77+
assert_image_equal_tofile(im, TEST_FILE_ATI1.replace(".dds", ".png"))
78+
79+
80+
def test_sanity_ati2():
81+
"""Check ATI2 images can be opened"""
82+
83+
with Image.open(TEST_FILE_ATI2) as im:
84+
im.load()
85+
86+
assert im.format == "DDS"
87+
assert im.mode == "RGB"
88+
assert im.size == (256, 256)
89+
90+
assert_image_equal_tofile(im, TEST_FILE_DX10_BC5_UNORM.replace(".dds", ".png"))
91+
92+
6593
@pytest.mark.parametrize(
6694
("image_path", "expected_path"),
6795
(

src/PIL/DdsImagePlugin.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,14 @@ def _open(self):
156156
elif fourcc == b"DXT5":
157157
self.pixel_format = "DXT5"
158158
n = 3
159+
elif fourcc == b"ATI1":
160+
self.pixel_format = "BC4"
161+
n = 4
162+
self.mode = "L"
163+
elif fourcc == b"ATI2":
164+
self.pixel_format = "BC5"
165+
n = 5
166+
self.mode = "RGB"
159167
elif fourcc == b"BC5S":
160168
self.pixel_format = "BC5S"
161169
n = 5

0 commit comments

Comments
 (0)