From 7206be535e89bedef2fbed03d58801335816de8b Mon Sep 17 00:00:00 2001 From: wiredfool Date: Sat, 3 Oct 2015 22:46:01 +0100 Subject: [PATCH] Flatten sampleformat to initial value, fixes #1466 --- PIL/TiffImagePlugin.py | 9 +++++++-- Tests/images/copyleft.tiff | Bin 0 -> 7926 bytes Tests/test_file_tiff.py | 5 +++++ 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 Tests/images/copyleft.tiff diff --git a/PIL/TiffImagePlugin.py b/PIL/TiffImagePlugin.py index 1f974226c..a84d01755 100644 --- a/PIL/TiffImagePlugin.py +++ b/PIL/TiffImagePlugin.py @@ -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 = ( diff --git a/Tests/images/copyleft.tiff b/Tests/images/copyleft.tiff new file mode 100644 index 0000000000000000000000000000000000000000..d8b7f730c0dfcb7653299737a26946117c501d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