Skip to content

Commit

Permalink
Support RGB bitcount 8
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Oct 25, 2023
1 parent f58f410 commit c509876
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
Binary file added Tests/images/rgb8.dds
Binary file not shown.
6 changes: 6 additions & 0 deletions Tests/test_file_dds.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,12 @@ def test_open(mode, test_file):
assert_image_equal_tofile(im, test_file.replace(".dds", ".png"))


def test_open_rgb8():
with Image.open("Tests/images/rgb8.dds") as im:
assert im.mode == "L"
assert_image_equal_tofile(im, "Tests/images/mode-l.png")


@pytest.mark.parametrize(
("mode", "test_file"),
[
Expand Down
13 changes: 7 additions & 6 deletions src/PIL/DdsImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,21 +353,22 @@ def _open(self):
if pfflags & DDPF.RGB:
# Texture contains uncompressed RGB data
masks = {mask: ["R", "G", "B", "A"][i] for i, mask in enumerate(masks)}
if bitcount == 24:
if bitcount == 8:
self._mode = "L"
elif bitcount == 24:
self._mode = "RGB"
rawmode = masks[0x00FF0000] + masks[0x0000FF00] + masks[0x000000FF]
rawmode = masks[0x000000FF] + masks[0x0000FF00] + masks[0x00FF0000]
elif bitcount == 32 and pfflags & DDPF.ALPHAPIXELS:
self._mode = "RGBA"
rawmode = (
masks[0x000000FF] +
masks[0x0000FF00] +
masks[0x00FF0000] +
masks[0xFF000000]
+ masks[0x00FF0000]
+ masks[0x0000FF00]
+ masks[0x000000FF]
)
else:
msg = f"Unsupported bitcount {bitcount} for {pfflags}"
raise OSError(msg)
rawmode = rawmode[::-1]
elif pfflags & DDPF.LUMINANCE:
if bitcount == 8:
self._mode = "L"
Expand Down

0 comments on commit c509876

Please sign in to comment.