diff --git a/Tests/images/rgb32rle_bottom_right.tga b/Tests/images/rgb32rle_bottom_right.tga new file mode 100644 index 000000000..bd4609e9c Binary files /dev/null and b/Tests/images/rgb32rle_bottom_right.tga differ diff --git a/Tests/images/rgb32rle_top_right.tga b/Tests/images/rgb32rle_top_right.tga new file mode 100644 index 000000000..78f9dc5df Binary files /dev/null and b/Tests/images/rgb32rle_top_right.tga differ diff --git a/Tests/test_file_tga.py b/Tests/test_file_tga.py index 3450c9274..e2351d723 100644 --- a/Tests/test_file_tga.py +++ b/Tests/test_file_tga.py @@ -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: diff --git a/src/PIL/TgaImagePlugin.py b/src/PIL/TgaImagePlugin.py index 5e5d52d1a..ed63da95f 100644 --- a/src/PIL/TgaImagePlugin.py +++ b/src/PIL/TgaImagePlugin.py @@ -93,9 +93,10 @@ class TgaImageFile(ImageFile.ImageFile): # 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") @@ -149,6 +150,10 @@ class TgaImageFile(ImageFile.ImageFile): except KeyError: pass # cannot decode + def load_end(self): + if self._flip_horizontally: + self.im = self.im.transpose(Image.FLIP_LEFT_RIGHT) + # # --------------------------------------------------------------------