Merge pull request #7426 from radarhere/dds_palette

This commit is contained in:
Hugo van Kemenade 2023-09-30 14:40:17 -06:00 committed by GitHub
commit c2f7ea59b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 42 additions and 6 deletions

BIN
Tests/images/palette.dds Normal file

Binary file not shown.

View File

@ -298,6 +298,11 @@ def test_dxt5_colorblock_alpha_issue_4142():
assert px[2] != 0
def test_palette():
with Image.open("Tests/images/palette.dds") as im:
assert_image_equal_tofile(im, "Tests/images/transparent.gif")
def test_unimplemented_pixel_format():
with pytest.raises(NotImplementedError):
with Image.open("Tests/images/unimplemented_pixel_format.dds"):

View File

@ -63,8 +63,35 @@ DDS
^^^
DDS is a popular container texture format used in video games and natively supported
by DirectX. Uncompressed RGB and RGBA can be read, and (since 8.3.0) written. DXT1,
DXT3 (since 3.4.0) and DXT5 pixel formats can be read, only in ``RGBA`` mode.
by DirectX.
DXT1 and DXT5 pixel formats can be read, only in ``RGBA`` mode.
.. versionadded:: 3.4.0
DXT3 images can be read in ``RGB`` mode and DX10 images can be read in
``RGB`` and ``RGBA`` mode.
.. versionadded:: 6.0.0
Uncompressed ``RGBA`` images can be read.
.. versionadded:: 8.3.0
BC5S images can be opened in ``RGB`` mode, and uncompressed ``RGB`` images
can be read. Uncompressed data can also be saved to image files.
.. versionadded:: 9.3.0
ATI1 images can be opened in ``L`` mode and ATI2 images can be opened in
``RGB`` mode.
.. versionadded:: 9.4.0
Uncompressed ``L`` ("luminance") and ``LA`` images can be opened and saved.
.. versionadded:: 10.1.0
BC5U can be read in ``RGB`` mode, and 8-bit color indexed images can be read
in ``P`` mode.
DIB
^^^

View File

@ -54,7 +54,7 @@ TODO
Other Changes
=============
TODO
^^^^
Added support for DDS 8-bit color indexed images
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TODO
Support has been added to read PALETTEINDEXED8 DDS files as P mode images.

View File

@ -13,7 +13,7 @@ Full text of the CC0 license:
import struct
from io import BytesIO
from . import Image, ImageFile
from . import Image, ImageFile, ImagePalette
from ._binary import o32le as o32
# Magic ("DDS ")
@ -157,6 +157,10 @@ class DdsImageFile(ImageFile.ImageFile):
rawmode += masks[0xFF0000] + masks[0xFF00] + masks[0xFF]
self.tile = [("raw", (0, 0) + self.size, 0, (rawmode[::-1], 0, 1))]
elif pfflags & DDPF_PALETTEINDEXED8:
self._mode = "P"
self.palette = ImagePalette.raw("RGBA", self.fp.read(1024))
self.tile = [("raw", (0, 0) + self.size, 0, "L")]
else:
data_start = header_size + 4
n = 0