Skip to content

Commit

Permalink
Merge pull request #6486 from REDxEYE/improved_dds
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Dec 6, 2023
2 parents f505eec + d1a2235 commit 7cc0482
Show file tree
Hide file tree
Showing 12 changed files with 538 additions and 195 deletions.
Binary file added Tests/images/bc1.dds
Binary file not shown.
Binary file added Tests/images/bc1_typeless.dds
Binary file not shown.
Binary file added Tests/images/bc4u.dds
Binary file not shown.
Binary file not shown.
Binary file added Tests/images/unsupported_bitcount_luminance.dds
Binary file not shown.
Binary file added Tests/images/unsupported_bitcount_rgb.dds
Binary file not shown.
62 changes: 48 additions & 14 deletions Tests/test_file_dds.py
Expand Up @@ -17,6 +17,9 @@
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"
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"
Expand All @@ -31,11 +34,20 @@
TEST_FILE_UNCOMPRESSED_RGB_WITH_ALPHA = "Tests/images/uncompressed_rgb.dds"


def test_sanity_dxt1():
"""Check DXT1 images can be opened"""
@pytest.mark.parametrize(
"image_path",
(
TEST_FILE_DXT1,
# hexeditted to use DX10 FourCC
TEST_FILE_DX10_BC1,
TEST_FILE_DX10_BC1_TYPELESS,
),
)
def test_sanity_dxt1_bc1(image_path):
"""Check DXT1 and BC1 images can be opened"""
with Image.open(TEST_FILE_DXT1.replace(".dds", ".png")) as target:
target = target.convert("RGBA")
with Image.open(TEST_FILE_DXT1) as im:
with Image.open(image_path) as im:
im.load()

assert im.format == "DDS"
Expand Down Expand Up @@ -71,10 +83,18 @@ 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"""
@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 and BC4U 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"
Expand Down Expand Up @@ -222,12 +242,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"),
[
Expand Down Expand Up @@ -326,9 +340,29 @@ def test_palette():
assert_image_equal_tofile(im, "Tests/images/transparent.gif")


def test_unimplemented_pixel_format():
@pytest.mark.parametrize(
"test_file",
(
"Tests/images/unsupported_bitcount_rgb.dds",
"Tests/images/unsupported_bitcount_luminance.dds",
),
)
def test_unsupported_bitcount(test_file):
with pytest.raises(OSError):
with Image.open(test_file):
pass


@pytest.mark.parametrize(
"test_file",
(
"Tests/images/unimplemented_dxgi_format.dds",
"Tests/images/unimplemented_pfflags.dds",
),
)
def test_not_implemented(test_file):
with pytest.raises(NotImplementedError):
with Image.open("Tests/images/unimplemented_pixel_format.dds"):
with Image.open(test_file):
pass


Expand Down
8 changes: 8 additions & 0 deletions docs/reference/plugins.rst
Expand Up @@ -33,6 +33,14 @@ Plugin reference
:undoc-members:
:show-inheritance:

:mod:`~PIL.DdsImagePlugin` Module
---------------------------------

.. automodule:: PIL.DdsImagePlugin
:members:
:undoc-members:
:show-inheritance:

:mod:`~PIL.EpsImagePlugin` Module
---------------------------------

Expand Down
56 changes: 56 additions & 0 deletions docs/releasenotes/10.2.0.rst
@@ -0,0 +1,56 @@
10.2.0
------

Backwards Incompatible Changes
==============================

TODO
^^^^

TODO

Deprecations
============

TODO
^^^^

TODO

API Changes
===========

TODO
^^^^

TODO

API Additions
=============

Added DdsImagePlugin enums
^^^^^^^^^^^^^^^^^^^^^^^^^^

:py:class:`~PIL.DdsImagePlugin.DDSD`, :py:class:`~PIL.DdsImagePlugin.DDSCAPS`,
:py:class:`~PIL.DdsImagePlugin.DDSCAPS2`, :py:class:`~PIL.DdsImagePlugin.DDPF`,
:py:class:`~PIL.DdsImagePlugin.DXGI_FORMAT` and :py:class:`~PIL.DdsImagePlugin.D3DFMT`
enums have been added to :py:class:`PIL.DdsImagePlugin`.

Security
========

TODO
^^^^

TODO

Other Changes
=============

Added DDS BC4U and DX10 BC1 and BC4 reading
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Support has been added to read the BC4U format of DDS images.

Support has also been added to read DX10 BC1 and BC4, whether UNORM or
TYPELESS.
1 change: 1 addition & 0 deletions docs/releasenotes/index.rst
Expand Up @@ -14,6 +14,7 @@ expected to be backported to earlier versions.
.. toctree::
:maxdepth: 2

10.2.0
10.1.0
10.0.1
10.0.0
Expand Down

0 comments on commit 7cc0482

Please sign in to comment.