Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Tests/test_file_tga.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,15 @@ def roundtrip(original_im):
roundtrip(original_im)


def test_palette_depth_16():
def test_palette_depth_16(tmp_path):
with Image.open("Tests/images/p_16.tga") as im:
assert_image_equal_tofile(im.convert("RGB"), "Tests/images/p_16.png")

out = str(tmp_path / "temp.png")
im.save(out)
with Image.open(out) as reloaded:
assert_image_equal_tofile(reloaded.convert("RGB"), "Tests/images/p_16.png")


def test_id_field():
# tga file with id field
Expand Down
3 changes: 2 additions & 1 deletion src/PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ def load(self):
arr = bytes(
value for (index, value) in enumerate(arr) if index % 4 != 3
)
self.im.putpalette(mode, arr)
palette_length = self.im.putpalette(mode, arr)
self.palette.dirty = 0
self.palette.rawmode = None
if "transparency" in self.info:
Expand All @@ -841,6 +841,7 @@ def load(self):
self.palette.mode = "RGBA"
else:
self.palette.mode = "RGB"
self.palette.palette = self.im.getpalette()[: palette_length * 3]

if self.im:
if cffi and USE_CFFI_ACCESS:
Expand Down
3 changes: 1 addition & 2 deletions src/_imaging.c
Original file line number Diff line number Diff line change
Expand Up @@ -1663,8 +1663,7 @@ _putpalette(ImagingObject *self, PyObject *args) {

unpack(self->image->palette->palette, palette, palettesize * 8 / bits);

Py_INCREF(Py_None);
return Py_None;
return PyLong_FromLong(palettesize * 8 / bits);
}

static PyObject *
Expand Down