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

TGA color map entry size is only 1 byte #5396

Merged
merged 1 commit into from
Apr 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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/200x32_p_bl_raw_origin.tga
Binary file not shown.
10 changes: 9 additions & 1 deletion Tests/test_file_tga.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from PIL import Image

from .helper import assert_image_equal, hopper
from .helper import assert_image_equal, assert_image_equal_tofile, hopper

_TGA_DIR = os.path.join("Tests", "images", "tga")
_TGA_DIR_COMMON = os.path.join(_TGA_DIR, "common")
Expand Down Expand Up @@ -112,6 +112,14 @@ def test_save_wrong_mode(tmp_path):
im.save(out)


def test_save_mapdepth():
# This image has been manually hexedited from 200x32_p_bl_raw.tga
# to include an origin
test_file = "Tests/images/200x32_p_bl_raw_origin.tga"
with Image.open(test_file) as im:
assert_image_equal_tofile(im, "Tests/images/tga/common/200x32_p.png")


def test_save_id_section(tmp_path):
test_file = "Tests/images/rgb32rle.tga"
with Image.open(test_file) as im:
Expand Down
2 changes: 1 addition & 1 deletion src/PIL/TgaImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def _open(self):

if colormaptype:
# read palette
start, size, mapdepth = i16(s, 3), i16(s, 5), i16(s, 7)
start, size, mapdepth = i16(s, 3), i16(s, 5), s[7]
if mapdepth == 16:
self.palette = ImagePalette.raw(
"BGR;16", b"\0" * 2 * start + self.fp.read(2 * size)
Expand Down