Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for reading ATI1/ATI2 (BC4/BC5) DDS images #6457

Merged
merged 6 commits into from Jul 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Binary file added Tests/images/ati1.dds
Binary file not shown.
Binary file added Tests/images/ati1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Tests/images/ati2.dds
Binary file not shown.
28 changes: 28 additions & 0 deletions Tests/test_file_dds.py
Expand Up @@ -10,6 +10,8 @@
TEST_FILE_DXT1 = "Tests/images/dxt1-rgb-4bbp-noalpha_MipMaps-1.dds"
TEST_FILE_DXT3 = "Tests/images/dxt3-argb-8bbp-explicitalpha_MipMaps-1.dds"
TEST_FILE_DXT5 = "Tests/images/dxt5-argb-8bbp-interpolatedalpha_MipMaps-1.dds"
TEST_FILE_ATI1 = "Tests/images/ati1.dds"
TEST_FILE_ATI2 = "Tests/images/ati2.dds"
TEST_FILE_DX10_BC5_TYPELESS = "Tests/images/bc5_typeless.dds"
TEST_FILE_DX10_BC5_UNORM = "Tests/images/bc5_unorm.dds"
TEST_FILE_DX10_BC5_SNORM = "Tests/images/bc5_snorm.dds"
Expand Down Expand Up @@ -62,6 +64,32 @@ def test_sanity_dxt5():
assert_image_equal_tofile(im, TEST_FILE_DXT5.replace(".dds", ".png"))


def test_sanity_ati1():
"""Check ATI1 images can be opened"""

with Image.open(TEST_FILE_ATI1) as im:
im.load()

assert im.format == "DDS"
assert im.mode == "L"
assert im.size == (64, 64)

assert_image_equal_tofile(im, TEST_FILE_ATI1.replace(".dds", ".png"))


def test_sanity_ati2():
"""Check ATI2 images can be opened"""

with Image.open(TEST_FILE_ATI2) as im:
im.load()

assert im.format == "DDS"
assert im.mode == "RGB"
assert im.size == (256, 256)

assert_image_equal_tofile(im, TEST_FILE_DX10_BC5_UNORM.replace(".dds", ".png"))


@pytest.mark.parametrize(
("image_path", "expected_path"),
(
Expand Down
8 changes: 8 additions & 0 deletions src/PIL/DdsImagePlugin.py
Expand Up @@ -156,6 +156,14 @@ def _open(self):
elif fourcc == b"DXT5":
self.pixel_format = "DXT5"
n = 3
elif fourcc == b"ATI1":
self.pixel_format = "BC4"
n = 4
self.mode = "L"
elif fourcc == b"ATI2":
self.pixel_format = "BC5"
n = 5
self.mode = "RGB"
elif fourcc == b"BC5S":
self.pixel_format = "BC5S"
n = 5
Expand Down