mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 01:46:18 +03:00
Use TIFF orientation
This commit is contained in:
parent
929c817014
commit
1b70a4c6b5
BIN
Tests/images/g4_orientation_1.tif
Executable file
BIN
Tests/images/g4_orientation_1.tif
Executable file
Binary file not shown.
BIN
Tests/images/g4_orientation_2.tif
Executable file
BIN
Tests/images/g4_orientation_2.tif
Executable file
Binary file not shown.
BIN
Tests/images/g4_orientation_3.tif
Executable file
BIN
Tests/images/g4_orientation_3.tif
Executable file
Binary file not shown.
BIN
Tests/images/g4_orientation_4.tif
Executable file
BIN
Tests/images/g4_orientation_4.tif
Executable file
Binary file not shown.
BIN
Tests/images/g4_orientation_5.tif
Executable file
BIN
Tests/images/g4_orientation_5.tif
Executable file
Binary file not shown.
BIN
Tests/images/g4_orientation_6.tif
Executable file
BIN
Tests/images/g4_orientation_6.tif
Executable file
Binary file not shown.
BIN
Tests/images/g4_orientation_7.tif
Executable file
BIN
Tests/images/g4_orientation_7.tif
Executable file
Binary file not shown.
BIN
Tests/images/g4_orientation_8.tif
Executable file
BIN
Tests/images/g4_orientation_8.tif
Executable file
Binary file not shown.
|
@ -831,3 +831,12 @@ class TestFileLibTiff(LibTiffTestCase):
|
||||||
self.assert_image_equal_tofile(
|
self.assert_image_equal_tofile(
|
||||||
im, "Tests/images/old-style-jpeg-compression.png"
|
im, "Tests/images/old-style-jpeg-compression.png"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_orientation(self):
|
||||||
|
base_im = Image.open("Tests/images/g4_orientation_1.tif")
|
||||||
|
|
||||||
|
for i in range(2, 9):
|
||||||
|
im = Image.open("Tests/images/g4_orientation_" + str(i) + ".tif")
|
||||||
|
im.load()
|
||||||
|
|
||||||
|
self.assert_image_similar(base_im, im, 0.7)
|
||||||
|
|
|
@ -1098,6 +1098,20 @@ class TiffImageFile(ImageFile.ImageFile):
|
||||||
return super(TiffImageFile, self).load()
|
return super(TiffImageFile, self).load()
|
||||||
|
|
||||||
def load_end(self):
|
def load_end(self):
|
||||||
|
if self._tile_orientation:
|
||||||
|
method = {
|
||||||
|
2: Image.FLIP_LEFT_RIGHT,
|
||||||
|
3: Image.ROTATE_180,
|
||||||
|
4: Image.FLIP_TOP_BOTTOM,
|
||||||
|
5: Image.TRANSPOSE,
|
||||||
|
6: Image.ROTATE_270,
|
||||||
|
7: Image.TRANSVERSE,
|
||||||
|
8: Image.ROTATE_90,
|
||||||
|
}.get(self._tile_orientation)
|
||||||
|
if method is not None:
|
||||||
|
self.im = self.im.transpose(method)
|
||||||
|
self._size = self.im.size
|
||||||
|
|
||||||
# allow closing if we're on the first frame, there's no next
|
# allow closing if we're on the first frame, there's no next
|
||||||
# This is the ImageFile.load path only, libtiff specific below.
|
# This is the ImageFile.load path only, libtiff specific below.
|
||||||
if not self._is_animated:
|
if not self._is_animated:
|
||||||
|
@ -1181,6 +1195,9 @@ class TiffImageFile(ImageFile.ImageFile):
|
||||||
|
|
||||||
self.tile = []
|
self.tile = []
|
||||||
self.readonly = 0
|
self.readonly = 0
|
||||||
|
|
||||||
|
self.load_end()
|
||||||
|
|
||||||
# libtiff closed the fp in a, we need to close self.fp, if possible
|
# libtiff closed the fp in a, we need to close self.fp, if possible
|
||||||
if self._exclusive_fp and not self._is_animated:
|
if self._exclusive_fp and not self._is_animated:
|
||||||
self.fp.close()
|
self.fp.close()
|
||||||
|
@ -1388,6 +1405,8 @@ class TiffImageFile(ImageFile.ImageFile):
|
||||||
palette = [o8(b // 256) for b in self.tag_v2[COLORMAP]]
|
palette = [o8(b // 256) for b in self.tag_v2[COLORMAP]]
|
||||||
self.palette = ImagePalette.raw("RGB;L", b"".join(palette))
|
self.palette = ImagePalette.raw("RGB;L", b"".join(palette))
|
||||||
|
|
||||||
|
self._tile_orientation = self.tag_v2.get(0x0112)
|
||||||
|
|
||||||
def _close__fp(self):
|
def _close__fp(self):
|
||||||
try:
|
try:
|
||||||
if self.__fp != self.fp:
|
if self.__fp != self.fp:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user