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
Binary file added Tests/images/rgb32rle_bottom_right.tga
Binary file not shown.
Binary file added Tests/images/rgb32rle_top_right.tga
Binary file not shown.
9 changes: 9 additions & 0 deletions Tests/test_file_tga.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,15 @@ def test_save_orientation(tmp_path):
assert test_im.info["orientation"] == 1


def test_horizontal_orientations():
# These images have been manually hexedited to have the relevant orientations
with Image.open("Tests/images/rgb32rle_top_right.tga") as im:
assert im.load()[90, 90][:3] == (0, 0, 0)

with Image.open("Tests/images/rgb32rle_bottom_right.tga") as im:
assert im.load()[90, 90][:3] == (0, 255, 0)


def test_save_rle(tmp_path):
test_file = "Tests/images/rgb32rle.tga"
with Image.open(test_file) as im:
Expand Down
9 changes: 7 additions & 2 deletions src/PIL/TgaImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,10 @@ def _open(self):

# orientation
orientation = flags & 0x30
if orientation == 0x20:
self._flip_horizontally = orientation in [0x10, 0x30]
if orientation in [0x20, 0x30]:
orientation = 1
elif not orientation:
elif orientation in [0, 0x10]:
orientation = -1
else:
raise SyntaxError("unknown TGA orientation")
Expand Down Expand Up @@ -149,6 +150,10 @@ def _open(self):
except KeyError:
pass # cannot decode

def load_end(self):
if self._flip_horizontally:
self.im = self.im.transpose(Image.FLIP_LEFT_RIGHT)


#
# --------------------------------------------------------------------
Expand Down