Merge pull request #1467 from wiredfool/sampleformat

Flatten sampleformat to initial value, fixes #1466
This commit is contained in:
wiredfool 2015-10-05 01:43:03 -07:00
commit 23631302a9
3 changed files with 12 additions and 2 deletions

View File

@ -180,8 +180,6 @@ OPEN_INFO = {
(MM, 2, (1,), 1, (8, 8, 8, 8), (2,)): ("RGBA", "RGBA"),
(II, 2, (1,), 1, (8, 8, 8, 8), (999,)): ("RGBA", "RGBA"), # Corel Draw 10
(MM, 2, (1,), 1, (8, 8, 8, 8), (999,)): ("RGBA", "RGBA"), # Corel Draw 10
(II, 2, (1, 1, 1, 1), 1, (8, 8, 8, 8), (1,)): ("RGBA", "RGBA"), # OSX Grab
(MM, 2, (1, 1, 1, 1), 1, (8, 8, 8, 8), (1,)): ("RGBA", "RGBA"), # OSX Grab
(II, 3, (1,), 1, (1,), ()): ("P", "P;1"),
(MM, 3, (1,), 1, (1,), ()): ("P", "P;1"),
(II, 3, (1,), 2, (1,), ()): ("P", "P;1R"),
@ -967,6 +965,13 @@ class TiffImageFile(ImageFile.ImageFile):
print("- size:", self.size)
format = self.tag_v2.get(SAMPLEFORMAT, (1,))
if len(format) > 1 and max(format) == min(format) == 1:
# SAMPLEFORMAT is properly per band, so an RGB image will
# be (1,1,1). But, we don't support per band pixel types,
# and anything more than one band is a uint8. So, just
# take the first element. Revisit this if adding support
# for more exotic images.
format = (1,)
# mode: check photometric interpretation and bits per pixel
key = (

BIN
Tests/images/copyleft.tiff Normal file

Binary file not shown.

View File

@ -70,6 +70,11 @@ class TestFileTiff(PillowTestCase):
])
im.load()
def test_sampleformat(self):
# https://github.com/python-pillow/Pillow/issues/1466
im = Image.open("Tests/images/copyleft.tiff")
self.assertEqual(im.mode, 'RGB')
def test_xyres_tiff(self):
from PIL.TiffImagePlugin import X_RESOLUTION, Y_RESOLUTION
filename = "Tests/images/pil168.tif"