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

Support reading BC4U and DX10 BC1 images #6486

Merged
merged 68 commits into from Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from 66 commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
f2d91fc
Add IntEnum/IntFlag for most of DDS members
REDxEYE Aug 6, 2022
de2b4be
Add Tile namedtuple for code readability.
REDxEYE Aug 6, 2022
3f77a9e
Remove unused constants
REDxEYE Aug 6, 2022
1988737
Add support for single channel textures
REDxEYE Aug 6, 2022
3602e35
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 6, 2022
429dc28
Remove unnecessary tuple creation
REDxEYE Aug 6, 2022
8e8a67e
Fix incorect file name
REDxEYE Aug 6, 2022
de8b89c
Add support for writing LA dds textures
REDxEYE Aug 7, 2022
a63fdc2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 7, 2022
3476073
Add missing LA test textures
REDxEYE Aug 7, 2022
d1b1f30
Fix file extensions in tests not matching real names
REDxEYE Aug 10, 2022
7c25e0b
Small refactor
REDxEYE Aug 24, 2022
91664c9
Small refactor
REDxEYE Aug 25, 2022
1c9a84d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 25, 2022
9369a48
Revert, i didn't meant to commit it
REDxEYE Aug 25, 2022
15c90ac
Simplified save code
REDxEYE Aug 26, 2022
b6b7a7b
Simplified test code
radarhere Oct 8, 2022
eda4192
Fixed typo
radarhere Oct 8, 2022
b87d4e0
Restored formatting
radarhere Oct 8, 2022
9a7bd0d
Fixed big-endian bug
radarhere Oct 8, 2022
78756cd
Simplified imports
radarhere Oct 8, 2022
cadac4a
Corrected error messages
radarhere Oct 18, 2022
bd48265
Removed INVALID enum
radarhere Oct 18, 2022
9165771
Add BC5U support. Seen in Amnesia: The Bunker
REDxEYE Jun 15, 2023
777c54a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 15, 2023
a5dde8b
Apply suggestion for PR
REDxEYE Oct 12, 2023
6dd565b
Merge remote-tracking branch 'pillow/main' into improved_dds
REDxEYE Oct 12, 2023
bc6c973
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 12, 2023
2a6bcc1
Add missing annotation import
REDxEYE Oct 12, 2023
69b922d
Replace self.mode with self._mode
REDxEYE Oct 12, 2023
5e9a2e3
Renamed "tile_args" to "args" for consistency with existing ImageFile…
radarhere Oct 17, 2023
51f7359
Loop over enums to create constants
radarhere Oct 17, 2023
f59c9ae
Merge pull request #4 from radarhere/improved_dds
REDxEYE Oct 17, 2023
935958c
Removed unnecessary casting to enums
radarhere Oct 18, 2023
a54d28a
Merge branch 'main' into improved_dds
radarhere Oct 21, 2023
4a4a1ee
Simplified tile creation
radarhere Oct 21, 2023
8fbb610
Derive bit count from number of modes
radarhere Oct 21, 2023
12e41e8
Simplified creating raw tiles
radarhere Oct 21, 2023
93e0f39
Removed "mode-" prefix from image names that are not modes
radarhere Oct 21, 2023
2ca9adb
Merge pull request #6 from radarhere/improved_dds
REDxEYE Oct 21, 2023
f58f410
ALPHA by itself does not mean bitcount is valid
radarhere Oct 25, 2023
8548522
Support RGB bitcount 8
radarhere Oct 25, 2023
0051fc9
Removed unnecessary seek
radarhere Oct 28, 2023
17be898
Added tests for unimplemented bitcount
radarhere Oct 28, 2023
e3ff5eb
Test BC1_UNORM and BC1_TYPELESS
radarhere Oct 30, 2023
4c635e4
Merge pull request #7 from radarhere/improved_dds
REDxEYE Oct 30, 2023
cb554c6
Update src/PIL/DdsImagePlugin.py
REDxEYE Oct 30, 2023
ee8c9c3
Removed unused test images
radarhere Oct 30, 2023
5fd3035
Removed duplicate test
radarhere Oct 30, 2023
8814610
Only unpack masks when necessary
radarhere Oct 30, 2023
ddcbfde
Test BC4U
radarhere Oct 30, 2023
940224e
Remove wrong test_save input
REDxEYE Oct 30, 2023
c7fbfdc
Removed test_open
radarhere Oct 30, 2023
e0a726b
Merge pull request #8 from radarhere/improved_dds
REDxEYE Oct 30, 2023
2f7caad
Merge pull request #9 from radarhere/test_open
REDxEYE Oct 30, 2023
49578f0
Merge branch 'main' into improved_dds
radarhere Dec 2, 2023
662cb22
Updated variable name to match tile
radarhere Nov 21, 2023
56b4822
args may be a string or None
radarhere Nov 21, 2023
ab96324
Removed support for RGB bitcount 8
radarhere Dec 1, 2023
5aadeb5
Moved _Tile to ImageFile
radarhere Dec 1, 2023
e072a12
Corrected constant values
radarhere Dec 2, 2023
9e5ff76
Merge pull request #10 from radarhere/improved_dds
REDxEYE Dec 2, 2023
2eddbc5
Updated docstrings
radarhere Dec 3, 2023
f2e478e
Merge branch 'main' into improved_dds
radarhere Dec 5, 2023
66c5e9a
Added release notes
radarhere Dec 5, 2023
9e6030f
Rename _420_OPAQUE to OPAQUE_420
REDxEYE Dec 5, 2023
00c6a89
Link to plugin
radarhere Dec 6, 2023
d1a2235
Added tilde prefix
radarhere Dec 6, 2023
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/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
54 changes: 54 additions & 0 deletions docs/releasenotes/10.2.0.rst
@@ -0,0 +1,54 @@
10.2.0
------

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

TODO
^^^^

TODO

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

TODO
^^^^

TODO

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

TODO
^^^^

TODO

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

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

``DDSD``, ``DDSCAPS``, ``DDSCAPS2``, ``DDPF``, ``DXGI_FORMAT`` and ``D3DFMT``
enums have been added to DdsImagePlugin.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
enums have been added to DdsImagePlugin.
enums have been added to py:class:`PIL.DdsImagePlugin`.

radarhere marked this conversation as resolved.
Show resolved Hide resolved

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