We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Image.show() on image with mode LA does not show transparency
When I use `Image.show()` on an image with mode `LA`, transparency is not shown.  When I use `.save(...)`, the resulting image has transparency included correctly.  With mode `RGBA`, transparency is correctly displayed on `.show()` (and correctly written on `.save(...)`).

### What did you do?

I used `.show()` on an image with mode `LA`.

### What did you expect to happen?

I expected it to display an image with transparency:

![im1](https://user-images.githubusercontent.com/500246/58331700-faf35f00-7e39-11e9-973a-d1d2dd1414cf.png)

### What actually happened?

It showed an image without transparency:

![tmplevyr9u2](https://user-images.githubusercontent.com/500246/58331737-0fcff280-7e3a-11e9-9179-baf3a324f971.PNG)

### What are your OS, Python and Pillow versions?

* OS: openSUSE 15.0
* Python: 3.7.3
* Pillow: 6.0.0

```python
from numpy import linspace, block, concatenate, zeros, full
from PIL import Image

L = linspace(0, 255, 200*200, dtype="u1").reshape(200, 200, 1)
A = block([[zeros((100, 100), "u1"),             full((100, 100), 255, "u1")],
            [full((100, 100), 255, "u1"),
            zeros((100, 100), "u1")]]).reshape(200, 200, 1)
im1 = Image.fromarray((concatenate((L, A), 2)), mode="LA")
im2 = Image.fromarray((concatenate((L, L, L, A), 2)), mode="RGBA")
im1.show()
im2.show()
```


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `src/PIL/ImageMode.py`
Content:
```
1 #
2 # The Python Imaging Library.
3 # $Id$
4 #
5 # standard mode descriptors
6 #
7 # History:
8 # 2006-03-20 fl   Added
9 #
10 # Copyright (c) 2006 by Secret Labs AB.
11 # Copyright (c) 2006 by Fredrik Lundh.
12 #
13 # See the README file for information on usage and redistribution.
14 #
15 
16 # mode descriptor cache
17 _modes = None
18 
19 
20 class ModeDescriptor(object):
21     """Wrapper for mode strings."""
22 
23     def __init__(self, mode, bands, basemode, basetype):
24         self.mode = mode
25         self.bands = bands
26         self.basemode = basemode
27         self.basetype = basetype
28 
29     def __str__(self):
30         return self.mode
31 
32 
33 def getmode(mode):
34     """Gets a mode descriptor for the given mode."""
35     global _modes
36     if not _modes:
37         # initialize mode cache
38 
39         from . import Image
40 
41         modes = {}
42         # core modes
43         for m, (basemode, basetype, bands) in Image._MODEINFO.items():
44             modes[m] = ModeDescriptor(m, bands, basemode, basetype)
45         # extra experimental modes
46         modes["RGBa"] = ModeDescriptor("RGBa", ("R", "G", "B", "a"), "RGB", "L")
47         modes["LA"] = ModeDescriptor("LA", ("L", "A"), "L", "L")
48         modes["La"] = ModeDescriptor("La", ("L", "a"), "L", "L")
49         modes["PA"] = ModeDescriptor("PA", ("P", "A"), "RGB", "L")
50         # mapping modes
51         modes["I;16"] = ModeDescriptor("I;16", "I", "L", "L")
52         modes["I;16L"] = ModeDescriptor("I;16L", "I", "L", "L")
53         modes["I;16B"] = ModeDescriptor("I;16B", "I", "L", "L")
54         # set global mode cache atomically
55         _modes = modes
56     return _modes[mode]
57
```

Path: `src/PIL/ImageShow.py`
Content:
```
1 #
2 # The Python Imaging Library.
3 # $Id$
4 #
5 # im.show() drivers
6 #
7 # History:
8 # 2008-04-06 fl   Created
9 #
10 # Copyright (c) Secret Labs AB 2008.
11 #
12 # See the README file for information on usage and redistribution.
13 #
14 
15 from __future__ import print_function
16 
17 from PIL import Image
18 import os
19 import sys
20 import subprocess
21 import tempfile
22 
23 if sys.version_info.major >= 3:
24     from shlex import quote
25 else:
26     from pipes import quote
27 
28 _viewers = []
29 
30 
31 def register(viewer, order=1):
32     try:
33         if issubclass(viewer, Viewer):
34             viewer = viewer()
35     except TypeError:
36         pass  # raised if viewer wasn't a class
37     if order > 0:
38         _viewers.append(viewer)
39     elif order < 0:
40         _viewers.insert(0, viewer)
41 
42 
43 def show(image, title=None, **options):
44     r"""
45     Display a given image.
46 
47     :param image: An image object.
48     :param title: Optional title.  Not all viewers can display the title.
49     :param \**options: Additional viewer options.
50     :returns: True if a suitable viewer was found, false otherwise.
51     """
52     for viewer in _viewers:
53         if viewer.show(image, title=title, **options):
54             return 1
55     return 0
56 
57 
58 class Viewer(object):
59     """Base class for viewers."""
60 
61     # main api
62 
63     def show(self, image, **options):
64 
65         # save temporary image to disk
66         if image.mode[:4] == "I;16":
67             # @PIL88 @PIL101
68             # "I;16" isn't an 'official' mode, but we still want to
69             # provide a simple way to show 16-bit images.
70             base = "L"
71             # FIXME: auto-contrast if max() > 255?
72         else:
73             base = Image.getmodebase(image.mode)
74         if base != image.mode and image.mode != "1" and image.mode != "RGBA":
75             image = image.convert(base)
76 
77         return self.show_image(image, **options)
78 
79     # hook methods
80 
81     format = None
82     options = {}
83 
84     def get_format(self, image):
85         """Return format name, or None to save as PGM/PPM"""
86         return self.format
87 
88     def get_command(self, file, **options):
89         raise NotImplementedError
90 
91     def save_image(self, image):
92         """Save to temporary file, and return filename"""
93         return image._dump(format=self.get_format(image), **self.options)
94 
95     def show_image(self, image, **options):
96         """Display given image"""
97         return self.show_file(self.save_image(image), **options)
98 
99     def show_file(self, file, **options):
100         """Display given file"""
101         os.system(self.get_command(file, **options))
102         return 1
103 
104 
105 # --------------------------------------------------------------------
106 
107 
108 if sys.platform == "win32":
109 
110     class WindowsViewer(Viewer):
111         format = "BMP"
112 
113         def get_command(self, file, **options):
114             return (
115                 'start "Pillow" /WAIT "%s" '
116                 "&& ping -n 2 127.0.0.1 >NUL "
117                 '&& del /f "%s"' % (file, file)
118             )
119 
120     register(WindowsViewer)
121 
122 elif sys.platform == "darwin":
123 
124     class MacViewer(Viewer):
125         format = "PNG"
126         options = {"compress_level": 1}
127 
128         def get_command(self, file, **options):
129             # on darwin open returns immediately resulting in the temp
130             # file removal while app is opening
131             command = "open -a /Applications/Preview.app"
132             command = "(%s %s; sleep 20; rm -f %s)&" % (
133                 command,
134                 quote(file),
135                 quote(file),
136             )
137             return command
138 
139         def show_file(self, file, **options):
140             """Display given file"""
141             fd, path = tempfile.mkstemp()
142             with os.fdopen(fd, "w") as f:
143                 f.write(file)
144             with open(path, "r") as f:
145                 subprocess.Popen(
146                     [
147                         "im=$(cat);"
148                         "open -a /Applications/Preview.app $im;"
149                         "sleep 20;"
150                         "rm -f $im"
151                     ],
152                     shell=True,
153                     stdin=f,
154                 )
155             os.remove(path)
156             return 1
157 
158     register(MacViewer)
159 
160 else:
161 
162     # unixoids
163 
164     def which(executable):
165         path = os.environ.get("PATH")
166         if not path:
167             return None
168         for dirname in path.split(os.pathsep):
169             filename = os.path.join(dirname, executable)
170             if os.path.isfile(filename) and os.access(filename, os.X_OK):
171                 return filename
172         return None
173 
174     class UnixViewer(Viewer):
175         format = "PNG"
176         options = {"compress_level": 1}
177 
178         def get_command(self, file, **options):
179             command = self.get_command_ex(file, **options)[0]
180             return "(%s %s; rm -f %s)&" % (command, quote(file), quote(file))
181 
182         def show_file(self, file, **options):
183             """Display given file"""
184             fd, path = tempfile.mkstemp()
185             with os.fdopen(fd, "w") as f:
186                 f.write(file)
187             with open(path, "r") as f:
188                 command = self.get_command_ex(file, **options)[0]
189                 subprocess.Popen(
190                     ["im=$(cat);" + command + " $im;" "rm -f $im"], shell=True, stdin=f
191                 )
192             os.remove(path)
193             return 1
194 
195     # implementations
196 
197     class DisplayViewer(UnixViewer):
198         def get_command_ex(self, file, **options):
199             command = executable = "display"
200             return command, executable
201 
202     if which("display"):
203         register(DisplayViewer)
204 
205     class EogViewer(UnixViewer):
206         def get_command_ex(self, file, **options):
207             command = executable = "eog"
208             return command, executable
209 
210     if which("eog"):
211         register(EogViewer)
212 
213     class XVViewer(UnixViewer):
214         def get_command_ex(self, file, title=None, **options):
215             # note: xv is pretty outdated.  most modern systems have
216             # imagemagick's display command instead.
217             command = executable = "xv"
218             if title:
219                 command += " -name %s" % quote(title)
220             return command, executable
221 
222     if which("xv"):
223         register(XVViewer)
224 
225 if __name__ == "__main__":
226 
227     if len(sys.argv) < 2:
228         print("Syntax: python ImageShow.py imagefile [title]")
229         sys.exit()
230 
231     print(show(Image.open(sys.argv[1]), *sys.argv[2:]))
232
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/src/PIL/ImageMode.py b/src/PIL/ImageMode.py
--- a/src/PIL/ImageMode.py
+++ b/src/PIL/ImageMode.py
@@ -48,9 +48,17 @@
         modes["La"] = ModeDescriptor("La", ("L", "a"), "L", "L")
         modes["PA"] = ModeDescriptor("PA", ("P", "A"), "RGB", "L")
         # mapping modes
-        modes["I;16"] = ModeDescriptor("I;16", "I", "L", "L")
-        modes["I;16L"] = ModeDescriptor("I;16L", "I", "L", "L")
-        modes["I;16B"] = ModeDescriptor("I;16B", "I", "L", "L")
+        for i16mode in (
+            "I;16",
+            "I;16S",
+            "I;16L",
+            "I;16LS",
+            "I;16B",
+            "I;16BS",
+            "I;16N",
+            "I;16NS",
+        ):
+            modes[i16mode] = ModeDescriptor(i16mode, ("I",), "L", "L")
         # set global mode cache atomically
         _modes = modes
     return _modes[mode]
diff --git a/src/PIL/ImageShow.py b/src/PIL/ImageShow.py
--- a/src/PIL/ImageShow.py
+++ b/src/PIL/ImageShow.py
@@ -63,16 +63,12 @@
     def show(self, image, **options):
 
         # save temporary image to disk
-        if image.mode[:4] == "I;16":
-            # @PIL88 @PIL101
-            # "I;16" isn't an 'official' mode, but we still want to
-            # provide a simple way to show 16-bit images.
-            base = "L"
-            # FIXME: auto-contrast if max() > 255?
-        else:
+        if not (
+            image.mode in ("1", "RGBA") or (self.format == "PNG" and image.mode == "LA")
+        ):
             base = Image.getmodebase(image.mode)
-        if base != image.mode and image.mode != "1" and image.mode != "RGBA":
-            image = image.convert(base)
+            if image.mode != base:
+                image = image.convert(base)
 
         return self.show_image(image, **options)

{"golden_diff": "diff --git a/src/PIL/ImageMode.py b/src/PIL/ImageMode.py\n--- a/src/PIL/ImageMode.py\n+++ b/src/PIL/ImageMode.py\n@@ -48,9 +48,17 @@\n         modes[\"La\"] = ModeDescriptor(\"La\", (\"L\", \"a\"), \"L\", \"L\")\n         modes[\"PA\"] = ModeDescriptor(\"PA\", (\"P\", \"A\"), \"RGB\", \"L\")\n         # mapping modes\n-        modes[\"I;16\"] = ModeDescriptor(\"I;16\", \"I\", \"L\", \"L\")\n-        modes[\"I;16L\"] = ModeDescriptor(\"I;16L\", \"I\", \"L\", \"L\")\n-        modes[\"I;16B\"] = ModeDescriptor(\"I;16B\", \"I\", \"L\", \"L\")\n+        for i16mode in (\n+            \"I;16\",\n+            \"I;16S\",\n+            \"I;16L\",\n+            \"I;16LS\",\n+            \"I;16B\",\n+            \"I;16BS\",\n+            \"I;16N\",\n+            \"I;16NS\",\n+        ):\n+            modes[i16mode] = ModeDescriptor(i16mode, (\"I\",), \"L\", \"L\")\n         # set global mode cache atomically\n         _modes = modes\n     return _modes[mode]\ndiff --git a/src/PIL/ImageShow.py b/src/PIL/ImageShow.py\n--- a/src/PIL/ImageShow.py\n+++ b/src/PIL/ImageShow.py\n@@ -63,16 +63,12 @@\n     def show(self, image, **options):\n \n         # save temporary image to disk\n-        if image.mode[:4] == \"I;16\":\n-            # @PIL88 @PIL101\n-            # \"I;16\" isn't an 'official' mode, but we still want to\n-            # provide a simple way to show 16-bit images.\n-            base = \"L\"\n-            # FIXME: auto-contrast if max() > 255?\n-        else:\n+        if not (\n+            image.mode in (\"1\", \"RGBA\") or (self.format == \"PNG\" and image.mode == \"LA\")\n+        ):\n             base = Image.getmodebase(image.mode)\n-        if base != image.mode and image.mode != \"1\" and image.mode != \"RGBA\":\n-            image = image.convert(base)\n+            if image.mode != base:\n+                image = image.convert(base)\n \n         return self.show_image(image, **options)\n", "issue": "Image.show() on image with mode LA does not show transparency\nWhen I use `Image.show()` on an image with mode `LA`, transparency is not shown.  When I use `.save(...)`, the resulting image has transparency included correctly.  With mode `RGBA`, transparency is correctly displayed on `.show()` (and correctly written on `.save(...)`).\r\n\r\n### What did you do?\r\n\r\nI used `.show()` on an image with mode `LA`.\r\n\r\n### What did you expect to happen?\r\n\r\nI expected it to display an image with transparency:\r\n\r\n![im1](https://user-images.githubusercontent.com/500246/58331700-faf35f00-7e39-11e9-973a-d1d2dd1414cf.png)\r\n\r\n### What actually happened?\r\n\r\nIt showed an image without transparency:\r\n\r\n![tmplevyr9u2](https://user-images.githubusercontent.com/500246/58331737-0fcff280-7e3a-11e9-9179-baf3a324f971.PNG)\r\n\r\n### What are your OS, Python and Pillow versions?\r\n\r\n* OS: openSUSE 15.0\r\n* Python: 3.7.3\r\n* Pillow: 6.0.0\r\n\r\n```python\r\nfrom numpy import linspace, block, concatenate, zeros, full\r\nfrom PIL import Image\r\n\r\nL = linspace(0, 255, 200*200, dtype=\"u1\").reshape(200, 200, 1)\r\nA = block([[zeros((100, 100), \"u1\"),             full((100, 100), 255, \"u1\")],\r\n            [full((100, 100), 255, \"u1\"),\r\n            zeros((100, 100), \"u1\")]]).reshape(200, 200, 1)\r\nim1 = Image.fromarray((concatenate((L, A), 2)), mode=\"LA\")\r\nim2 = Image.fromarray((concatenate((L, L, L, A), 2)), mode=\"RGBA\")\r\nim1.show()\r\nim2.show()\r\n```\r\n\n", "before_files": [{"content": "#\n# The Python Imaging Library.\n# $Id$\n#\n# standard mode descriptors\n#\n# History:\n# 2006-03-20 fl   Added\n#\n# Copyright (c) 2006 by Secret Labs AB.\n# Copyright (c) 2006 by Fredrik Lundh.\n#\n# See the README file for information on usage and redistribution.\n#\n\n# mode descriptor cache\n_modes = None\n\n\nclass ModeDescriptor(object):\n    \"\"\"Wrapper for mode strings.\"\"\"\n\n    def __init__(self, mode, bands, basemode, basetype):\n        self.mode = mode\n        self.bands = bands\n        self.basemode = basemode\n        self.basetype = basetype\n\n    def __str__(self):\n        return self.mode\n\n\ndef getmode(mode):\n    \"\"\"Gets a mode descriptor for the given mode.\"\"\"\n    global _modes\n    if not _modes:\n        # initialize mode cache\n\n        from . import Image\n\n        modes = {}\n        # core modes\n        for m, (basemode, basetype, bands) in Image._MODEINFO.items():\n            modes[m] = ModeDescriptor(m, bands, basemode, basetype)\n        # extra experimental modes\n        modes[\"RGBa\"] = ModeDescriptor(\"RGBa\", (\"R\", \"G\", \"B\", \"a\"), \"RGB\", \"L\")\n        modes[\"LA\"] = ModeDescriptor(\"LA\", (\"L\", \"A\"), \"L\", \"L\")\n        modes[\"La\"] = ModeDescriptor(\"La\", (\"L\", \"a\"), \"L\", \"L\")\n        modes[\"PA\"] = ModeDescriptor(\"PA\", (\"P\", \"A\"), \"RGB\", \"L\")\n        # mapping modes\n        modes[\"I;16\"] = ModeDescriptor(\"I;16\", \"I\", \"L\", \"L\")\n        modes[\"I;16L\"] = ModeDescriptor(\"I;16L\", \"I\", \"L\", \"L\")\n        modes[\"I;16B\"] = ModeDescriptor(\"I;16B\", \"I\", \"L\", \"L\")\n        # set global mode cache atomically\n        _modes = modes\n    return _modes[mode]\n", "path": "src/PIL/ImageMode.py"}, {"content": "#\n# The Python Imaging Library.\n# $Id$\n#\n# im.show() drivers\n#\n# History:\n# 2008-04-06 fl   Created\n#\n# Copyright (c) Secret Labs AB 2008.\n#\n# See the README file for information on usage and redistribution.\n#\n\nfrom __future__ import print_function\n\nfrom PIL import Image\nimport os\nimport sys\nimport subprocess\nimport tempfile\n\nif sys.version_info.major >= 3:\n    from shlex import quote\nelse:\n    from pipes import quote\n\n_viewers = []\n\n\ndef register(viewer, order=1):\n    try:\n        if issubclass(viewer, Viewer):\n            viewer = viewer()\n    except TypeError:\n        pass  # raised if viewer wasn't a class\n    if order > 0:\n        _viewers.append(viewer)\n    elif order < 0:\n        _viewers.insert(0, viewer)\n\n\ndef show(image, title=None, **options):\n    r\"\"\"\n    Display a given image.\n\n    :param image: An image object.\n    :param title: Optional title.  Not all viewers can display the title.\n    :param \\**options: Additional viewer options.\n    :returns: True if a suitable viewer was found, false otherwise.\n    \"\"\"\n    for viewer in _viewers:\n        if viewer.show(image, title=title, **options):\n            return 1\n    return 0\n\n\nclass Viewer(object):\n    \"\"\"Base class for viewers.\"\"\"\n\n    # main api\n\n    def show(self, image, **options):\n\n        # save temporary image to disk\n        if image.mode[:4] == \"I;16\":\n            # @PIL88 @PIL101\n            # \"I;16\" isn't an 'official' mode, but we still want to\n            # provide a simple way to show 16-bit images.\n            base = \"L\"\n            # FIXME: auto-contrast if max() > 255?\n        else:\n            base = Image.getmodebase(image.mode)\n        if base != image.mode and image.mode != \"1\" and image.mode != \"RGBA\":\n            image = image.convert(base)\n\n        return self.show_image(image, **options)\n\n    # hook methods\n\n    format = None\n    options = {}\n\n    def get_format(self, image):\n        \"\"\"Return format name, or None to save as PGM/PPM\"\"\"\n        return self.format\n\n    def get_command(self, file, **options):\n        raise NotImplementedError\n\n    def save_image(self, image):\n        \"\"\"Save to temporary file, and return filename\"\"\"\n        return image._dump(format=self.get_format(image), **self.options)\n\n    def show_image(self, image, **options):\n        \"\"\"Display given image\"\"\"\n        return self.show_file(self.save_image(image), **options)\n\n    def show_file(self, file, **options):\n        \"\"\"Display given file\"\"\"\n        os.system(self.get_command(file, **options))\n        return 1\n\n\n# --------------------------------------------------------------------\n\n\nif sys.platform == \"win32\":\n\n    class WindowsViewer(Viewer):\n        format = \"BMP\"\n\n        def get_command(self, file, **options):\n            return (\n                'start \"Pillow\" /WAIT \"%s\" '\n                \"&& ping -n 2 127.0.0.1 >NUL \"\n                '&& del /f \"%s\"' % (file, file)\n            )\n\n    register(WindowsViewer)\n\nelif sys.platform == \"darwin\":\n\n    class MacViewer(Viewer):\n        format = \"PNG\"\n        options = {\"compress_level\": 1}\n\n        def get_command(self, file, **options):\n            # on darwin open returns immediately resulting in the temp\n            # file removal while app is opening\n            command = \"open -a /Applications/Preview.app\"\n            command = \"(%s %s; sleep 20; rm -f %s)&\" % (\n                command,\n                quote(file),\n                quote(file),\n            )\n            return command\n\n        def show_file(self, file, **options):\n            \"\"\"Display given file\"\"\"\n            fd, path = tempfile.mkstemp()\n            with os.fdopen(fd, \"w\") as f:\n                f.write(file)\n            with open(path, \"r\") as f:\n                subprocess.Popen(\n                    [\n                        \"im=$(cat);\"\n                        \"open -a /Applications/Preview.app $im;\"\n                        \"sleep 20;\"\n                        \"rm -f $im\"\n                    ],\n                    shell=True,\n                    stdin=f,\n                )\n            os.remove(path)\n            return 1\n\n    register(MacViewer)\n\nelse:\n\n    # unixoids\n\n    def which(executable):\n        path = os.environ.get(\"PATH\")\n        if not path:\n            return None\n        for dirname in path.split(os.pathsep):\n            filename = os.path.join(dirname, executable)\n            if os.path.isfile(filename) and os.access(filename, os.X_OK):\n                return filename\n        return None\n\n    class UnixViewer(Viewer):\n        format = \"PNG\"\n        options = {\"compress_level\": 1}\n\n        def get_command(self, file, **options):\n            command = self.get_command_ex(file, **options)[0]\n            return \"(%s %s; rm -f %s)&\" % (command, quote(file), quote(file))\n\n        def show_file(self, file, **options):\n            \"\"\"Display given file\"\"\"\n            fd, path = tempfile.mkstemp()\n            with os.fdopen(fd, \"w\") as f:\n                f.write(file)\n            with open(path, \"r\") as f:\n                command = self.get_command_ex(file, **options)[0]\n                subprocess.Popen(\n                    [\"im=$(cat);\" + command + \" $im;\" \"rm -f $im\"], shell=True, stdin=f\n                )\n            os.remove(path)\n            return 1\n\n    # implementations\n\n    class DisplayViewer(UnixViewer):\n        def get_command_ex(self, file, **options):\n            command = executable = \"display\"\n            return command, executable\n\n    if which(\"display\"):\n        register(DisplayViewer)\n\n    class EogViewer(UnixViewer):\n        def get_command_ex(self, file, **options):\n            command = executable = \"eog\"\n            return command, executable\n\n    if which(\"eog\"):\n        register(EogViewer)\n\n    class XVViewer(UnixViewer):\n        def get_command_ex(self, file, title=None, **options):\n            # note: xv is pretty outdated.  most modern systems have\n            # imagemagick's display command instead.\n            command = executable = \"xv\"\n            if title:\n                command += \" -name %s\" % quote(title)\n            return command, executable\n\n    if which(\"xv\"):\n        register(XVViewer)\n\nif __name__ == \"__main__\":\n\n    if len(sys.argv) < 2:\n        print(\"Syntax: python ImageShow.py imagefile [title]\")\n        sys.exit()\n\n    print(show(Image.open(sys.argv[1]), *sys.argv[2:]))\n", "path": "src/PIL/ImageShow.py"}], "after_files": [{"content": "#\n# The Python Imaging Library.\n# $Id$\n#\n# standard mode descriptors\n#\n# History:\n# 2006-03-20 fl   Added\n#\n# Copyright (c) 2006 by Secret Labs AB.\n# Copyright (c) 2006 by Fredrik Lundh.\n#\n# See the README file for information on usage and redistribution.\n#\n\n# mode descriptor cache\n_modes = None\n\n\nclass ModeDescriptor(object):\n    \"\"\"Wrapper for mode strings.\"\"\"\n\n    def __init__(self, mode, bands, basemode, basetype):\n        self.mode = mode\n        self.bands = bands\n        self.basemode = basemode\n        self.basetype = basetype\n\n    def __str__(self):\n        return self.mode\n\n\ndef getmode(mode):\n    \"\"\"Gets a mode descriptor for the given mode.\"\"\"\n    global _modes\n    if not _modes:\n        # initialize mode cache\n\n        from . import Image\n\n        modes = {}\n        # core modes\n        for m, (basemode, basetype, bands) in Image._MODEINFO.items():\n            modes[m] = ModeDescriptor(m, bands, basemode, basetype)\n        # extra experimental modes\n        modes[\"RGBa\"] = ModeDescriptor(\"RGBa\", (\"R\", \"G\", \"B\", \"a\"), \"RGB\", \"L\")\n        modes[\"LA\"] = ModeDescriptor(\"LA\", (\"L\", \"A\"), \"L\", \"L\")\n        modes[\"La\"] = ModeDescriptor(\"La\", (\"L\", \"a\"), \"L\", \"L\")\n        modes[\"PA\"] = ModeDescriptor(\"PA\", (\"P\", \"A\"), \"RGB\", \"L\")\n        # mapping modes\n        for i16mode in (\n            \"I;16\",\n            \"I;16S\",\n            \"I;16L\",\n            \"I;16LS\",\n            \"I;16B\",\n            \"I;16BS\",\n            \"I;16N\",\n            \"I;16NS\",\n        ):\n            modes[i16mode] = ModeDescriptor(i16mode, (\"I\",), \"L\", \"L\")\n        # set global mode cache atomically\n        _modes = modes\n    return _modes[mode]\n", "path": "src/PIL/ImageMode.py"}, {"content": "#\n# The Python Imaging Library.\n# $Id$\n#\n# im.show() drivers\n#\n# History:\n# 2008-04-06 fl   Created\n#\n# Copyright (c) Secret Labs AB 2008.\n#\n# See the README file for information on usage and redistribution.\n#\n\nfrom __future__ import print_function\n\nfrom PIL import Image\nimport os\nimport sys\nimport subprocess\nimport tempfile\n\nif sys.version_info.major >= 3:\n    from shlex import quote\nelse:\n    from pipes import quote\n\n_viewers = []\n\n\ndef register(viewer, order=1):\n    try:\n        if issubclass(viewer, Viewer):\n            viewer = viewer()\n    except TypeError:\n        pass  # raised if viewer wasn't a class\n    if order > 0:\n        _viewers.append(viewer)\n    elif order < 0:\n        _viewers.insert(0, viewer)\n\n\ndef show(image, title=None, **options):\n    r\"\"\"\n    Display a given image.\n\n    :param image: An image object.\n    :param title: Optional title.  Not all viewers can display the title.\n    :param \\**options: Additional viewer options.\n    :returns: True if a suitable viewer was found, false otherwise.\n    \"\"\"\n    for viewer in _viewers:\n        if viewer.show(image, title=title, **options):\n            return 1\n    return 0\n\n\nclass Viewer(object):\n    \"\"\"Base class for viewers.\"\"\"\n\n    # main api\n\n    def show(self, image, **options):\n\n        # save temporary image to disk\n        if not (\n            image.mode in (\"1\", \"RGBA\") or (self.format == \"PNG\" and image.mode == \"LA\")\n        ):\n            base = Image.getmodebase(image.mode)\n            if image.mode != base:\n                image = image.convert(base)\n\n        return self.show_image(image, **options)\n\n    # hook methods\n\n    format = None\n    options = {}\n\n    def get_format(self, image):\n        \"\"\"Return format name, or None to save as PGM/PPM\"\"\"\n        return self.format\n\n    def get_command(self, file, **options):\n        raise NotImplementedError\n\n    def save_image(self, image):\n        \"\"\"Save to temporary file, and return filename\"\"\"\n        return image._dump(format=self.get_format(image), **self.options)\n\n    def show_image(self, image, **options):\n        \"\"\"Display given image\"\"\"\n        return self.show_file(self.save_image(image), **options)\n\n    def show_file(self, file, **options):\n        \"\"\"Display given file\"\"\"\n        os.system(self.get_command(file, **options))\n        return 1\n\n\n# --------------------------------------------------------------------\n\n\nif sys.platform == \"win32\":\n\n    class WindowsViewer(Viewer):\n        format = \"BMP\"\n\n        def get_command(self, file, **options):\n            return (\n                'start \"Pillow\" /WAIT \"%s\" '\n                \"&& ping -n 2 127.0.0.1 >NUL \"\n                '&& del /f \"%s\"' % (file, file)\n            )\n\n    register(WindowsViewer)\n\nelif sys.platform == \"darwin\":\n\n    class MacViewer(Viewer):\n        format = \"PNG\"\n        options = {\"compress_level\": 1}\n\n        def get_command(self, file, **options):\n            # on darwin open returns immediately resulting in the temp\n            # file removal while app is opening\n            command = \"open -a /Applications/Preview.app\"\n            command = \"(%s %s; sleep 20; rm -f %s)&\" % (\n                command,\n                quote(file),\n                quote(file),\n            )\n            return command\n\n        def show_file(self, file, **options):\n            \"\"\"Display given file\"\"\"\n            fd, path = tempfile.mkstemp()\n            with os.fdopen(fd, \"w\") as f:\n                f.write(file)\n            with open(path, \"r\") as f:\n                subprocess.Popen(\n                    [\n                        \"im=$(cat);\"\n                        \"open -a /Applications/Preview.app $im;\"\n                        \"sleep 20;\"\n                        \"rm -f $im\"\n                    ],\n                    shell=True,\n                    stdin=f,\n                )\n            os.remove(path)\n            return 1\n\n    register(MacViewer)\n\nelse:\n\n    # unixoids\n\n    def which(executable):\n        path = os.environ.get(\"PATH\")\n        if not path:\n            return None\n        for dirname in path.split(os.pathsep):\n            filename = os.path.join(dirname, executable)\n            if os.path.isfile(filename) and os.access(filename, os.X_OK):\n                return filename\n        return None\n\n    class UnixViewer(Viewer):\n        format = \"PNG\"\n        options = {\"compress_level\": 1}\n\n        def get_command(self, file, **options):\n            command = self.get_command_ex(file, **options)[0]\n            return \"(%s %s; rm -f %s)&\" % (command, quote(file), quote(file))\n\n        def show_file(self, file, **options):\n            \"\"\"Display given file\"\"\"\n            fd, path = tempfile.mkstemp()\n            with os.fdopen(fd, \"w\") as f:\n                f.write(file)\n            with open(path, \"r\") as f:\n                command = self.get_command_ex(file, **options)[0]\n                subprocess.Popen(\n                    [\"im=$(cat);\" + command + \" $im;\" \"rm -f $im\"], shell=True, stdin=f\n                )\n            os.remove(path)\n            return 1\n\n    # implementations\n\n    class DisplayViewer(UnixViewer):\n        def get_command_ex(self, file, **options):\n            command = executable = \"display\"\n            return command, executable\n\n    if which(\"display\"):\n        register(DisplayViewer)\n\n    class EogViewer(UnixViewer):\n        def get_command_ex(self, file, **options):\n            command = executable = \"eog\"\n            return command, executable\n\n    if which(\"eog\"):\n        register(EogViewer)\n\n    class XVViewer(UnixViewer):\n        def get_command_ex(self, file, title=None, **options):\n            # note: xv is pretty outdated.  most modern systems have\n            # imagemagick's display command instead.\n            command = executable = \"xv\"\n            if title:\n                command += \" -name %s\" % quote(title)\n            return command, executable\n\n    if which(\"xv\"):\n        register(XVViewer)\n\nif __name__ == \"__main__\":\n\n    if len(sys.argv) < 2:\n        print(\"Syntax: python ImageShow.py imagefile [title]\")\n        sys.exit()\n\n    print(show(Image.open(sys.argv[1]), *sys.argv[2:]))\n", "path": "src/PIL/ImageShow.py"}]}