Skip to content

Commit

Permalink
Flatten sampleformat to initial value, fixes python-pillow#1466
Browse files Browse the repository at this point in the history
  • Loading branch information
wiredfool committed Oct 3, 2015
1 parent 087a7fd commit 074bb16
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
9 changes: 7 additions & 2 deletions PIL/TiffImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,6 @@
(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"),
Expand Down Expand Up @@ -967,6 +965,13 @@ def _setup(self):
print("- size:", self.size)

format = self.tag_v2.get(SAMPLEFORMAT, (1,))
if len(format) > 1 and format[0] == 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 = (
Expand Down
Binary file added Tests/images/copyleft.tiff
Binary file not shown.
5 changes: 5 additions & 0 deletions Tests/test_file_tiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ def test_gimp_tiff(self):
])
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"
Expand Down

0 comments on commit 074bb16

Please sign in to comment.