mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-26 09:14:27 +03:00
Add support for ATI1/2(BC4/BC5) DDS files
This commit adds support for loading DDS with ATI1 and ATI2 fourcc pixel format
This commit is contained in:
parent
446446f579
commit
ad2c6a20fe
BIN
Tests/images/ati2.dds
Normal file
BIN
Tests/images/ati2.dds
Normal file
Binary file not shown.
BIN
Tests/images/ati2.png
Normal file
BIN
Tests/images/ati2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 28 KiB |
|
@ -10,6 +10,7 @@ from .helper import assert_image_equal, assert_image_equal_tofile, hopper
|
|||
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_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"
|
||||
|
@ -62,6 +63,19 @@ def test_sanity_dxt5():
|
|||
assert_image_equal_tofile(im, TEST_FILE_DXT5.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 == (128, 128)
|
||||
|
||||
assert_image_equal_tofile(im, TEST_FILE_ATI2.replace(".dds", ".png"))
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("image_path", "expected_path"),
|
||||
(
|
||||
|
|
|
@ -82,7 +82,6 @@ DDS_CUBEMAP_NEGATIVEY = DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEY
|
|||
DDS_CUBEMAP_POSITIVEZ = DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEZ
|
||||
DDS_CUBEMAP_NEGATIVEZ = DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEZ
|
||||
|
||||
|
||||
# DXT1
|
||||
DXT1_FOURCC = 0x31545844
|
||||
|
||||
|
@ -193,6 +192,14 @@ class DdsImageFile(ImageFile.ImageFile):
|
|||
raise NotImplementedError(
|
||||
f"Unimplemented DXGI format {dxgi_format}"
|
||||
)
|
||||
elif fourcc == b"ATI1":
|
||||
self.pixel_format = "BC4"
|
||||
n = 4
|
||||
self.mode = "RGB"
|
||||
elif fourcc == b"ATI2":
|
||||
self.pixel_format = "BC5"
|
||||
n = 5
|
||||
self.mode = "RGB"
|
||||
else:
|
||||
raise NotImplementedError(f"Unimplemented pixel format {repr(fourcc)}")
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user