Repository: python-pillow/Pillow

Problem statement:
Fails to open OME-TIFF example data files
[OME-TIFF](https://www.openmicroscopy.org/site/support/ome-model/ome-tiff/index.html) is a TIFF format that embeds some microscopy-specific metadata as an XML comment embedded in the TIFF header.  Sample data is available at https://www.openmicroscopy.org/site/support/ome-model/ome-tiff/data.html, but PIL fails to open `single-channel.ome.tiff` (throwing `OSError: cannot identify image file 'single-channel.ome.tiff'`).



Hints:
I'm not at a computer to test, but just to confirm: does this happen with Pillow (the PIL fork)? Which version of Pillow do you have?

Yes, this is with Pillow 2.5.0, Python 3.4.  I actually haven't tested this with PIL.

The actual problem with that file is that it is specified as a bigendian 8-bit signed integer format, which we don't have listed in the formats that we support. This past includes a mode line that will read the format and store it in an unsigned integer. Visual inspection of the image looks okay. The XML from the OME format shows up in the tags directory. 

```diff
diff --git a/PIL/TiffImagePlugin.py b/PIL/TiffImagePlugin.py
index 2e49931..d96542a 100644
--- a/PIL/TiffImagePlugin.py
+++ b/PIL/TiffImagePlugin.py
@@ -185,6 +185,7 @@ OPEN_INFO = {
     (MM, 1, 1, 1, (1,), ()): ("1", "1"),
     (MM, 1, 1, 2, (1,), ()): ("1", "1;R"),
     (MM, 1, 1, 1, (8,), ()): ("L", "L"),
+    (MM, 1, 2, 1, (8,), ()): ("L", "L"), #signed 8 bit???
     (MM, 1, 1, 1, (8,8), (2,)): ("LA", "LA"),
     (MM, 1, 1, 2, (8,), ()): ("L", "L;R"),
     (MM, 1, 1, 1, (16,), ()): ("I;16B", "I;16B"),
```

The [Image file formats](http://pillow.readthedocs.org/en/latest/handbook/image-file-formats.html#tiff) doc does not mention this limitation.  Is this a non-standard TIFF format?  (I don't know.)

There are many combinations, we support 60 or more of them. See lines ~145->212 of TiffImagePlugin for the combinations.  I've never seen a signed 8bit image before, so if it's not rare, it's not exactly common either. 

We don't have a specific mode for signed 8 bit images, so while we can read the image, we don't actually report the bytes correctly. (we'd return 0-255, not -127->127). 

Just a direct link to the sample image - https://downloads.openmicroscopy.org/images/OME-TIFF/2016-06/bioformats-artificial/single-channel.ome.tiff
I've created PR #7111 to resolve this.

Patch:
diff --git a/src/PIL/TiffImagePlugin.py b/src/PIL/TiffImagePlugin.py
--- a/src/PIL/TiffImagePlugin.py
+++ b/src/PIL/TiffImagePlugin.py
@@ -170,6 +170,8 @@
     (MM, 0, (1,), 2, (8,), ()): ("L", "L;IR"),
     (II, 1, (1,), 1, (8,), ()): ("L", "L"),
     (MM, 1, (1,), 1, (8,), ()): ("L", "L"),
+    (II, 1, (2,), 1, (8,), ()): ("L", "L"),
+    (MM, 1, (2,), 1, (8,), ()): ("L", "L"),
     (II, 1, (1,), 2, (8,), ()): ("L", "L;R"),
     (MM, 1, (1,), 2, (8,), ()): ("L", "L;R"),
     (II, 1, (1,), 1, (12,), ()): ("I;16", "I;12"),


Test patch:
diff --git a/Tests/images/8bit.s.tif b/Tests/images/8bit.s.tif
new file mode 100644
Binary files /dev/null and b/Tests/images/8bit.s.tif differ
diff --git a/Tests/test_file_tiff.py b/Tests/test_file_tiff.py
--- a/Tests/test_file_tiff.py
+++ b/Tests/test_file_tiff.py
@@ -198,6 +198,12 @@ def test_save_unsupported_mode(self, tmp_path):
         with pytest.raises(OSError):
             im.save(outfile)
 
+    def test_8bit_s(self):
+        with Image.open("Tests/images/8bit.s.tif") as im:
+            im.load()
+            assert im.mode == "L"
+            assert im.getpixel((50, 50)) == 184
+
     def test_little_endian(self):
         with Image.open("Tests/images/16bit.cropped.tif") as im:
             assert im.getpixel((0, 0)) == 480