mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 17:36:18 +03:00
Added support for top right and bottom right orientations
This commit is contained in:
parent
24f0bbf5ec
commit
fc90a9285a
BIN
Tests/images/rgb32rle_bottom_right.tga
Normal file
BIN
Tests/images/rgb32rle_bottom_right.tga
Normal file
Binary file not shown.
BIN
Tests/images/rgb32rle_top_right.tga
Normal file
BIN
Tests/images/rgb32rle_top_right.tga
Normal file
Binary file not shown.
|
@ -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:
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
||||
#
|
||||
# --------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue
Block a user