Skip to content

Commit

Permalink
Merge pull request python-pillow#8793 from radarhere/gd
Browse files Browse the repository at this point in the history
Fixed loading GD images
  • Loading branch information
hugovk authored Mar 3, 2025
2 parents a4f5fea + 51183c2 commit 7700293
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Tests/test_file_gd.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@

from PIL import GdImageFile, UnidentifiedImageError

from .helper import assert_image_similar_tofile

TEST_GD_FILE = "Tests/images/hopper.gd"


def test_sanity() -> None:
with GdImageFile.open(TEST_GD_FILE) as im:
assert im.size == (128, 128)
assert im.format == "GD"
assert_image_similar_tofile(im.convert("RGB"), "Tests/images/hopper.jpg", 14)


def test_bad_mode() -> None:
Expand Down
6 changes: 3 additions & 3 deletions src/PIL/GdImageFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def _open(self) -> None:
msg = "Not a valid GD 2.x .gd file"
raise SyntaxError(msg)

self._mode = "L" # FIXME: "P"
self._mode = "P"
self._size = i16(s, 2), i16(s, 4)

true_color = s[6]
Expand All @@ -68,14 +68,14 @@ def _open(self) -> None:
self.info["transparency"] = tindex

self.palette = ImagePalette.raw(
"XBGR", s[7 + true_color_offset + 4 : 7 + true_color_offset + 4 + 256 * 4]
"RGBX", s[7 + true_color_offset + 6 : 7 + true_color_offset + 6 + 256 * 4]
)

self.tile = [
ImageFile._Tile(
"raw",
(0, 0) + self.size,
7 + true_color_offset + 4 + 256 * 4,
7 + true_color_offset + 6 + 256 * 4,
"L",
)
]
Expand Down

0 comments on commit 7700293

Please sign in to comment.